Page 1 of 2

start.cel -> start.celx with "layers"

Posted: 31.07.2008, 17:05
by Cham
I'm starting an important topic on "layers" in Celestia. To me, this is vital for classroom and public presentations.

Firstly, I'm advocating the official change from start.cel to start.celx since it allows MUCH more freedom and customization than with a CEL script only, and I don't see any disadvantage of using a CELX script instead. In this case, we only have to edit the line in the config file (celestia.cfg) to point to the start.celx file, instead of a start.cel file.

Then, we need to make the start.celx file itself. This was already done by Vincent, on my request a long time ago. The content of that new CELX start file looks like this (I'm using parts of my own start.celx file as an example) :

Code: Select all

-- start.celx

celestia:setlabelcolor("stars",            0.500, 0.500, 1.000)
celestia:setlabelcolor("planets",          0.150, 0.740, 1.000)
celestia:setlabelcolor("moons",            0.450, 0.576, 0.612)
celestia:setlabelcolor("asteroids",        0.460, 0.440, 0.360)
celestia:setlabelcolor("comets",           0.840, 0.620, 0.280)
celestia:setlabelcolor("spacecraft",       0.750, 0.740, 0.670)
celestia:setlabelcolor("locations",        0.220, 0.940, 0.440)
celestia:setlabelcolor("galaxies",         0.190, 0.850, 0.710)
celestia:setlabelcolor("nebulae",          0.850, 0.350, 0.290)
celestia:setlabelcolor("openclusters",     0.620, 0.480, 0.540)
celestia:setlabelcolor("constellations",   0.385, 0.280, 0.567)
celestia:setlabelcolor("dwarfplanets",     0.350, 0.400, 0.600)
celestia:setlabelcolor("minormoons",       0.400, 0.612, 0.576)
celestia:setlabelcolor("planetographicgrid", 0.200, 0.900, 1.000)
celestia:setlabelcolor("equatorialgrid",   0.318, 0.439, 0.361)
celestia:setlabelcolor("galacticgrid",     0.360, 0.360, 0.150)
celestia:setlabelcolor("eclipticgrid",     0.500, 0.220, 0.300)
celestia:setlabelcolor("horizontalgrid",   0.318, 0.361, 0.439)

celestia:setlinecolor ("starorbits",       0.500, 0.500, 0.800)
celestia:setlinecolor ("planetorbits",     0.000, 0.360, 0.900)
celestia:setlinecolor ("moonorbits",       0.220, 0.330, 0.400)
celestia:setlinecolor ("asteroidorbits",   0.280, 0.240, 0.216)
celestia:setlinecolor ("cometorbits",      0.520, 0.320, 0.128)
celestia:setlinecolor ("spacecraftorbits", 0.360, 0.360, 0.360)
celestia:setlinecolor ("constellations",   0.234, 0.090, 0.576)
celestia:setlinecolor ("boundaries",       0.192, 0.079, 0.151)
celestia:setlinecolor("dwarfplanetorbits", 0.098, 0.195, 0.439)
celestia:setlinecolor("minormoonorbits",   0.130, 0.260, 0.215)
celestia:setlinecolor("planetographicgrid", 0.150, 0.525, 0.525)
celestia:setlinecolor("planetequator",     0.400, 0.900, 1.000)
celestia:setlinecolor ("equatorialgrid",   0.192, 0.248, 0.184)
celestia:setlinecolor ("galacticgrid",     0.200, 0.200, 0.000)
celestia:setlinecolor ("eclipticgrid",     0.300, 0.050, 0.100)
celestia:setlinecolor ("horizontalgrid",   0.192, 0.184, 0.248)

***** REPLACE THIS LINE WITH CUSTOM FUNCTIONS.  SEE THE EXAMPLE BELOW *****

function CEL(source)
   local script = celestia:createcelscript(source)
   while script:tick() do
      wait(0)
   end
end


CEL([[
{

# ... Beginning of standard CEL script

***** REPLACE THIS LINE WITH THE CONTENT OF YOUR USUAL START.CEL FILE *****

# End of standard CEL script...
}


]])

-- end


Now, we can add some custom functions to the first line above beginning with *****. Personally, I'm using the "Fast GoTo" function defined below by Vincent (in my opinion, this should be made hard coded in Celestia's code. It's really usefull when you need to save time !). The second function defined below allows the first "layer" I want to talk about :

Code: Select all

function fastgoto()
    sel = celestia:getselection()
    obs = celestia:getobserver()
    if sel and obs then
        obs:goto(sel, 0.001)
    end
end

objects_t = {
      "Sol/Earth/Tectonic Plates",
      "Sol/Earth/Borders"
   }

for k, object in pairs(objects_t) do
  obj = celestia:find(object)
  obj:setvisible(false)
end

function toggleObj()
  for k, object in pairs(objects_t) do
    obj = celestia:find(object)
    obj:setvisible(not obj:visible())
  end
end

keyhandlers =
{
   G = fastgoto,
   T = toggleObj
}

function handlekey(k)
    handler = keyhandlers[k.char]
    if (handler ~= nil) then
        handler()
        return true
    else
        return false
    end
end

celestia:registereventhandler("key", handlekey)


Then, after you start Celestia, using shift-g (or "G") will bring you instantaneously to the selected object. This is the "Fast GoTo" function. Using shift-t (or "T") will switch ON/OFF the layer which includes two models (in the exemple presented above) : "Tectonic Plates" and "Borders" around the Earth.

We can now define in a similar way several "layers", with any number of models declared in some SSC file. We can even edit the script to add some textual information to be displayed each time the layer is activated or desactivated. For example :

Code: Select all

if obj:visible() then
      celestia:print("Tectonic Plates activated.\nEmpirical model from Peter Bird (2003)", 4)
   else
      celestia:print("Tectonic Plates desactivated.", 2)
   end


The only constraint is the access to the keyboard, in such a way that we can use a key switch. Currently, we only have access to simple keys in a CELX script (a, A, b, B, c, C, ... etc), and we need to be carefull to not use a key which is already used by Celestia. Personally, I need to toggle ON/OFF several layers independently of each other (up to 9 layers : Political borders, tectonic plates, magnetic field, charged particle paths in the magnetic field, ... etc), so currently I'm in trouble with Celestia's keyboard ! I asked Chris to add the ability to use combos like "ctrl-1", "ctrl-2", ... "alt-1", "alt-2", ... That way, we could define 10 or even 20 layers, which should be enough for most users.

Actually, I think that "layers" are so important, that it should be HARD CODED into Celestia (to simplify the user's life), so we only have to define the lists of objects in the start.celx file. My suggestion is to declare something like this, in the start.celx :

Code: Select all

 Layer1 = {
      "Sol/Earth/Tectonic Plates"
   }

Layer2 = {
      "Sol/Earth/Borders",
      "Sol/Earth/Quebec"
   }

Layer3 = {
      "Sol/Earth/Magnetic Field"
   }

Layer4 = {
      "Sol/Earth/Charged Particle Path 1",
      "Sol/Earth/Charged Particle Path 2",
      "Sol/Earth/Charged Particle Path 3"
   }

etc ...


The key combo could be hard coded so that "ctrl-1" is automatically associated to the first list (Layer1), etc. By default, ALL layers are set to OFF when we start Celestia. The user has to use the key combo to activate a given layer, if he placed something in his/her start file (the official start version should have empty lists : {}, with some brief comments to show to the novice how to use the layers). Of course, for this simple suggestion we wont be able to add a onscreen comment when we toggle ON/OFF the layer.

Re: start.cel -> start.celx with "layers"

Posted: 31.07.2008, 17:35
by ElChristou
Cham, apparently the addon manager will do lot of what you need. I don't know if Chris do already have a clear idea on how it will work but apart loading on the fly addons, we can imagine the possibility to bound shortcuts to play with them. What I have not clear at all is how we could "pack" several data set under a same addon; an example is your tectonic plates addon made of a cmod with its ssc and a locs file...

Re: start.cel -> start.celx with "layers"

Posted: 31.07.2008, 17:39
by Cham
I don't think an addon manager will ever do the trick. Addons aren't the same as "layers".

It will be slow, complicated and inefficient. I simply don't believe in this.

Re: start.cel -> start.celx with "layers"

Posted: 31.07.2008, 17:40
by ElChristou
I'm not sure to understand what makes you say such thing... :?

Re: start.cel -> start.celx with "layers"

Posted: 31.07.2008, 18:26
by ElChristou
Cham wrote:...Addons aren't the same as "layers"...

The "layers" you took as example are actually addons, or not? Now from a conceptual point of view, what you call "layers" is indeed interesting. Perso as I persist in thinking that the contextual menu should be develop much more, I was thinking in some kind of "slots" that one would be able to fill with whatever he need. A slot would be like an addon with a tag to define what kind of info is represented (alternate surface, guide, locations, spacecraft, whatever...) Once you define a slot, a log is written to keep in memory what is listed in each body's contextual menu. Slots would be automatically listed in the submenu in its subcategory and be available by click or by shortcuts if define via another specific tag...

Re: start.cel -> start.celx with "layers"

Posted: 02.08.2008, 21:19
by Cham
Chris added the possibility to use the Control key in a CELX script. The "layers" are now a reality, in Celestia :D . I've edited my start.celx script to define up to ten independant layers which can be toggle ON/OFF freely, using the keyboard only (ctrl-0, ctrl-1, ..., ctrl-9). Here's an example :
layers.jpg

The upper-left picture is the Earth, after I started Celestia (and turned OFF the cloud texture). I then use ctrl-1, and I get the political borders (second picture). Then, turning OFF the borders, I'm turning ON the tectonic plates using ctrl-2 (upper-right picture). Using ctrl-3 activates the dipolar magnetic field and the polar aurora (lower-left picture). I turn ON a charged particle path, and turn OFF the magnetic field (last picture). We can turn ON everything at once, if we want to, etc...

Isn't that beautifull for a classroom presentation !? Look M'ma ! No menus, no buttons, no windows and no checkboxes ! 8)

Re: start.cel -> start.celx with "layers"

Posted: 02.08.2008, 22:05
by ElChristou
And where is the script??

Re: start.cel -> start.celx with "layers"

Posted: 02.08.2008, 22:12
by Cham
ElChristou wrote:And where is the script??

Here's a part of my start.celx file, which defines ten layers. Fill in the empty slots, in the first 10 "objects" lists, and also the empty onscreen comments defined below (celestia:print(" ", 2)). If you're using accents, don't forget to save the file under the UTF-8 format :

Code: Select all

-- Layers definitions -----------------

objects1_t = {
      
   }

objects2_t = {
      
   }

objects3_t = {
      
   }

objects4_t = {
      
   }

objects5_t = {
      
   }

objects6_t = {
      
   }

objects7_t = {
      
   }

objects8_t = {
      
   }

objects9_t = {
      
   }

objects0_t = {
      
   }

-- Layer 1 ----------------------------
for k, object in pairs(objects1_t) do
  obj1 = celestia:find(object)
  obj1:setvisible(false)
end

function toggleObj1()
  for k, object in pairs(objects1_t) do
    obj1 = celestia:find(object)
    obj1:setvisible(not obj1:visible())

   if obj1:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end

-- Layer 2 ----------------------------
for k, object in pairs(objects2_t) do
  obj2 = celestia:find(object)
  obj2:setvisible(false)
end

function toggleObj2()
  for k, object in pairs(objects2_t) do
    obj2 = celestia:find(object)
    obj2:setvisible(not obj2:visible())
   if obj2:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end

-- Layer 3 ----------------------------
for k, object in pairs(objects3_t) do
  obj3 = celestia:find(object)
  obj3:setvisible(false)
end

function toggleObj3()
  for k, object in pairs(objects3_t) do
    obj3 = celestia:find(object)
    obj3:setvisible(not obj3:visible())
   if obj3:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end

-- Layer 4 ----------------------------
for k, object in pairs(objects4_t) do
  obj4 = celestia:find(object)
  obj4:setvisible(false)
end

function toggleObj4()
  for k, object in pairs(objects4_t) do
    obj4 = celestia:find(object)
    obj4:setvisible(not obj4:visible())
   if obj4:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end

-- Layer 5 ----------------------------
for k, object in pairs(objects5_t) do
  obj5 = celestia:find(object)
  obj5:setvisible(false)
end

function toggleObj5()
  for k, object in pairs(objects5_t) do
    obj5 = celestia:find(object)
    obj5:setvisible(not obj5:visible())
   if obj5:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end

-- Layer 6 ----------------------------
for k, object in pairs(objects6_t) do
  obj6 = celestia:find(object)
  obj6:setvisible(false)
end

function toggleObj6()
  for k, object in pairs(objects6_t) do
    obj6 = celestia:find(object)
    obj6:setvisible(not obj6:visible())
   if obj6:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end

-- Layer 7 ----------------------------
for k, object in pairs(objects7_t) do
  obj7 = celestia:find(object)
  obj7:setvisible(false)
end

function toggleObj7()
  for k, object in pairs(objects7_t) do
    obj7 = celestia:find(object)
    obj7:setvisible(not obj7:visible())
   if obj7:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end

-- Layer 8 ----------------------------
for k, object in pairs(objects8_t) do
  obj8 = celestia:find(object)
  obj8:setvisible(false)
end

function toggleObj8()
  for k, object in pairs(objects8_t) do
    obj8 = celestia:find(object)
    obj8:setvisible(not obj8:visible())
   if obj8:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end

-- Layer 9 ----------------------------
for k, object in pairs(objects9_t) do
  obj9 = celestia:find(object)
  obj9:setvisible(false)
end

function toggleObj9()
  for k, object in pairs(objects9_t) do
    obj9 = celestia:find(object)
    obj9:setvisible(not obj9:visible())
   if obj9:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end

-- Layer 0 ----------------------------
for k, object in pairs(objects0_t) do
  obj0 = celestia:find(object)
  obj0:setvisible(false)
end

function toggleObj0()
  for k, object in pairs(objects0_t) do
    obj0 = celestia:find(object)
    obj0:setvisible(not obj0:visible())
   if obj0:visible() then
      celestia:print(" ", 2)
   else
      celestia:print(" ", 2)
   end
  end
end
---------------------------------------

keyhandlers =
{
   ["C-1"] = toggleObj1,
   ["C-2"] = toggleObj2,
   ["C-3"] = toggleObj3,
   ["C-4"] = toggleObj4,
   ["C-5"] = toggleObj5,
   ["C-6"] = toggleObj6,
   ["C-7"] = toggleObj7,
   ["C-8"] = toggleObj8,
   ["C-9"] = toggleObj9,
   ["C-0"] = toggleObj0
}

function handlekey(k)
    handler = keyhandlers[k.char]
    if (handler ~= nil) then
        handler()
        return true
    else
        return false
    end
end

celestia:registereventhandler("key", handlekey)


I suggest to replace the official start.cel file with a new start.celx file to include this code. If empty, the object lists 1, 2, 3, ..., will simply do nothing after starting Celestia. If filled properly, they can be very usefull to the users.

EDIT : Of course, this code is only working with the latest SVN version of Celestia.

About the locations, the script may be edited to allow some labels toggling. I'll see this later with Vincent.

Re: start.cel -> start.celx with "layers"

Posted: 02.08.2008, 22:18
by ElChristou
One can build from SVN or it's still experimental? What about the locations? (No way to turn them on/off at once with the cmods?)

Re: start.cel -> start.celx with "layers"

Posted: 02.08.2008, 22:23
by Cham
Sorry, I've edited my previous post while you were responding, ElChristou. See the bottom of the previous message. Maybe I should add some comments, inside the previous script, so the user could learn how to use it.

Also, I'm wondering if some parts could be simplified a bit (especially the "for k, object in pairs(objects4_t) do ..." parts).

Re: start.cel -> start.celx with "layers"

Posted: 02.08.2008, 22:34
by BobHegwood
As much as I personally dislike CELX, this is an interesting and useful feature that Cham is advocating here. Can see lots of neat uses for a start script like this.
I have experimented a bit using SVN 4389, and it works fine for me. Of course, I haven't quite figured out what to do with all of this new capability, but does seem
to be very useful. :wink:

Also, Steve (Cartrite) continues to update his site HERE with the latest compiled versions of Celestia, so it really is an easy way to keep up to date with
the newest features. I believe that the latest version is 4391. Many thanks to Steve for continuing to do this for us Brain-Dead types too. :wink:

Great going here Martin. Good ideas and great add-ons too. Thanks a lot from the Brain-Dead. :)

Re: start.cel -> start.celx with "layers"

Posted: 03.08.2008, 08:06
by ElChristou
On osX, Ctrl 1,2, 3 etc is a bit problematic; first I have to change the setting of spaces in my controls (it was switching the work spaces -> this is a osX function)), second, Ctrl 1 work great but not Ctrl 2, 4 and 8 (those are reacting like the num pad 2, 4, 8 ). Ctrl 6 don't work at all...

What can be wrong?

Re: start.cel -> start.celx with "layers"

Posted: 03.08.2008, 13:21
by Cham
ElChristou wrote:On osX, Ctrl 1,2, 3 etc is a bit problematic; first I have to change the setting of spaces in my controls (it was switching the work spaces -> this is a osX function)), second, Ctrl 1 work great but not Ctrl 2, 4 and 8 (those are reacting like the num pad 2, 4, 8). Ctrl 6 don't work at all...

What can be wrong?

Did you checked in your OS X preferences ? Many keyboard settings there...

Re: start.cel -> start.celx with "layers"

Posted: 03.08.2008, 13:33
by ElChristou
So Ctrl 2, 4 and 6 just work fine for you?

Re: start.cel -> start.celx with "layers"

Posted: 03.08.2008, 13:37
by Cham
ElChristou wrote:So Ctrl 2, 4 and 6 just work fine for you?

Absolutely ! I'm using 9 layers right now. I only have one empty slot (don't know what to put in it yet). Everything is running perfectly. 8)

Re: start.cel -> start.celx with "layers"

Posted: 03.08.2008, 14:15
by ElChristou
I don't understand. I tried with a fresh default build and get the same behavior. Ctrl 2, 4, 6 and 8 react as 2,4, 6 and 8 on the numpad... I don't see why osX would be guilty as the behavior in within Celestia... :|

Edit: Even switching to qwerty don't change this problem...

Re: start.cel -> start.celx with "layers"

Posted: 03.08.2008, 14:23
by Cham
ElChristou wrote:I don't understand. I tried with a fresh default build and get the same behavior. Ctrl 2, 4 and 6 react as 2,4 and 6 on the numpad... I don't see why osX would be guilty as the behavior in within Celestia... :|

Sorry, I have no clue. It may be related to the fact that you're using a portable. They often iron some special key combos because of the restriction of their keyboard. This is important. I'll have to buy a portable next year, so I'm also concerned with this problem.

Re: start.cel -> start.celx with "layers"

Posted: 03.08.2008, 14:29
by ElChristou
Cham wrote:
ElChristou wrote:I don't understand. I tried with a fresh default build and get the same behavior. Ctrl 2, 4 and 6 react as 2,4 and 6 on the numpad... I don't see why osX would be guilty as the behavior in within Celestia... :|

Sorry, I have no clue. It may be related to the fact that you're using a portable. They often iron some special key combos because of the restriction of their keyboard. This is important. I'll have to buy a portable next year, so I'm also concerned with this problem.

Nope, I'm actually on a iMac with full keyboard... (and still searching...)

Re: start.cel -> start.celx with "layers"

Posted: 03.08.2008, 17:00
by Vincent
The Ctrl key event is not working for me. I tried with Ctrl+1, Ctrl+a, Ctrl+A, but had success with none of these combinations.
I'm not sure whether this issue is related to the Windows version or my french AZERTY keyboard...

Re: start.cel -> start.celx with "layers"

Posted: 03.08.2008, 17:10
by ElChristou
Vincent wrote:The Ctrl key event is not working for me. I tried with Ctrl+1, Ctrl+a, Ctrl+A, but had success with none of these combinations.
I'm not sure whether this issue is related to the Windows version or my french AZERTY keyboard...

Mmh... would be nice to see if more french keyboards do have this kind of problems... Hey les gars, feedback is welcome! :wink: