Activate only one Constelation

All about writing scripts for Celestia in Lua and the .cel system
Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 8 months
Location: Montreal

Post #81by Cham » 03.03.2008, 14:38

This "mistake" is crashing Celestia ? IMHO, it shouldn't happen. This is probably a bug in the code (not just in the script). Celestia shouldn't crash because of an error in a script.

Celestia should say something to the user, when a script isn't right. Chris, is that possible ?
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 3 months
Location: Rome, ITALY

Post #82by ANDREA » 03.03.2008, 15:04

Cham wrote:This "mistake" is crashing Celestia ? IMHO, it shouldn't happen. This is probably a bug in the code (not just in the script). Celestia shouldn't crash because of an error in a script.
Celestia should say something to the user, when a script isn't right. Chris, is that possible ?

Cham, "crash" is my (wrong) way to say that it makes Celestia stop working but, as I told, giving the message "Bad Parameter Error", so I should have given it as "error", not "crash". :oops:
My usual poor English, damn... :evil:
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 3 months
Location: Rome, ITALY

Post #83by ANDREA » 08.03.2008, 10:16

Hello m3ntol, I was thinking that due to the impressive work you did on cel script new commands, perhaps it could be a good idea to open here a Sticky thread named e.g. :
"New .cel script commands added from Celestia 1.5.0 on",
where to put a brief description and examples of the many commands you added recently.
What do you think on this?

As a frequent user of cel scripts, I found that normally new commands receive a very small attention from the users, because they are normally embedded within different threads, with no link to this subject, while new celx commands, thanks to Vincent?€™s effort, have their specific thread:
"New .celx commands available in Celestia 1.5.0",
giving all the available commands, as they become available.

And about cel commands, there is a very nice celx command

(multiview, that we can equally obtained by pressing:
Ctrl+R : Split view vertically
Ctrl+U : Split view horizontally
TAB : Cycle active view
DEL : Delete active view
Ctrl+D : Delete all views except active one)


Alas, the splitview, or multiview, is (up to now?) unavailable in cel scripts.
I think celx commands are:

observers = celestia:getobservers()
observers[1]:splitview("h", 0.666)
this splits horizontally, at 2/3 of the screen, IMHO,
observers = celestia:getobservers()
for i = 1,3 do
observers[i]:splitview("v", 0.5)
this splits vertically the screen halfway, IMHO,

but as I told many times, my knowledge of celx is close to zero, so may be I'm wrong here. :oops:
Do you think this could migrate in cel scripts, too?
I would like, e.g, to show how the atmosphere looks from the surface of different planets, showing three of them horizontally on the screen at the same time, or the relative dimensions of moons, e.g. all four Jupiter?€™s Galilean moons on the screen, as seen at the same distance, in a four view screen.
And so on, surely a lot of applications, IMHO. :wink:
Thanks a lot for all your patience and efforts, always highly appreciated.
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 8 months
Location: Nancy, France

Re: Activate only one Constelation

Post #84by Vincent » 06.05.2008, 17:48

I just checked in a change that permits visibility to be assigned to individual constellations
in celx scripts too. The celestia:showconstellations/hideconstellations methods accept
a single table argument. If no argument is passed, all constellations will be shown/hidden.

Example:

Code: Select all

-- Hide all constellations
celestia:hideconstellations()
wait(3)

-- Show Virgo only
celestia:showconstellations{"Virgo"}

-- Show zodiacal constellations only
zodiac = {"Pisces", "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpius", "Ophiuchus", "Sagittarius", "Capricornus", "Aquarius"}
celestia:showconstellations(zodiac)
wait(3)

-- Show all constellations
celestia:showconstellations()
wait(3)

-- Hide Virgo
celestia:hideconstellations{"Virgo"}
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 8 months
Location: Nancy, France

Re:

Post #85by Vincent » 24.05.2008, 10:00

chris wrote:Examples:

Code: Select all

-- make all constellations blue
celestia:setconstellationcolor(0.0, 0.0, 1.0)

-- ...except Orion is red
celestia:setconstellationcolor(1.0, 0.0, 0.0, "Orion")

-- set all constellation colors back to the default
celestia:unsetconstellationcolor()
The following patch adds the celestia:setconstellationcolor and celestia:unsetconstellationcolor methods to celx scripting:
http://vincent.gian.club.fr/celestia/co ... olor.patch

I made one change WRT Chris has suggested above, though: to keep consistent with the show/hideconstallation methods,
the fourth argument -- the list of constellation names -- must be a table.

Examples:

Code: Select all

-- Make all constellations blue
celestia:setconstellationcolor(0, 0, 1)

-- Make Leo and Virgo red
celestia:setconstellationcolor(1, 0, 0, {"Leo", "Virgo"})

-- Make zodiacal constellations green
zodiac = {"Pisces", "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpius", "Ophiuchus", "Sagittarius", "Capricornus", "Aquarius"}
celestia:setconstellationcolor(0, 1, 0, zodiac)

-- Set all constellation colors back to the default
celestia:unsetconstellationcolor()
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 8 months
Location: Nancy, France

Re: Activate only one Constelation

Post #86by Vincent » 04.06.2008, 12:02

On Chris' suggestion, I removed unsetconstellationcolor() and added instead getlinecolor() and getlabelcolor().
These functions both return a triple which corresponds to the r,g,b values of the current used color for the
specified lines and labels. Individual constellation colors can now be set to default using:

Code: Select all

-- Set all constellation colors back to the default
r, g, b = celestia:getlinecolor("constellations")
celestia:setconstellationcolor(r, g, b)

Code: Select all

-- or...
celestia:setconstellationcolor(celestia:getlinecolor("constellations"))

The change that adds setconstellationcolor, getlinecolor and getlabelcolor is in SVN.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
m3ntol
Posts: 29
Joined: 23.02.2008
With us: 16 years 7 months
Location: Madrid, Spain, Earth, Solar System, Milky Way, Virgo Cluster

Re: Activate only one Constelation

Post #87by m3ntol » 09.10.2008, 15:27

Hello, first of all, sorry for don't post in a long time, but I've been really bussy.

Now I've some free time and got back to make changes to Celestia. Sorry also because I don't sincronice my development with the team :oops: :oops: but anyway I think it could be usefull.

I was working on CELX (lua) to allow it show/hide constellations, labels and boundaries in different colors.

I've added the following celx commands:
setconstellations Allow to sow/hide asterism, the sintax is as follow
celestia:setconstellations{All = false}
celestia:setconstellations{Cassiopeia = true, Ursa_Major = true, Cepheus = true}

setconstellationscolor Assign a color to each asterism, the sintax is as follow
celestia:setconstellationscolor{All = "#FFFFFF"}
celestia:setconstellationscolor{Cassiopeia = "#0000FF", Ursa_Major = "#00FF00"}

setconstellationslabelcolor Assign a color to each asterisms label, the sintax is as follow
celestia:setconstellationslabelcolor{All = "#FFFFFF"}
celestia:setconstellationslabelcolor{Cassiopeia = "#FAFAFA"}

setboundaries Allow to sow/hide asterism boundaries, the sintax is as follow
celestia:setboundaries{All=false}
celestia:setboundaries{CAS = true, UMA = true, CEP = true, UMI=true, DRA=true}

setboundariescolor Assign a color to each asterisms boundarie, the sintax is as follow
celestia:setboundariescolor{All = "#FFFFFF"}
celestia:setboundariescolor{CAS = "#FF0000", UMA = "#0000FF", CEP = "#00FFFF"}

I don't know how to use the patch tool. If some one would like to explain me I can upload also the canges to the source code.

Here you can get the executable and an example.
http://www.astrohenares.org/upd/data/Celestia.rar
Image

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 8 months
Location: Nancy, France

Re: Activate only one Constelation

Post #88by Vincent » 09.10.2008, 16:13

Hi,

m3ntol wrote:I've added the following celx commands:
setconstellations Allow to sow/hide asterism
setconstellationscolor Assign a color to each asterism
I already added these commands. They're now part of Celestia 1.6 SVN.
The Celx section of the Celestia Wiki lists all the existing celx functions.

m3ntol wrote:setconstellationslabelcolor Assign a color to each asterisms label, the sintax is as follow
celestia:setconstellationslabelcolor{All = "#FFFFFF"}
celestia:setconstellationslabelcolor{Cassiopeia = "#FAFAFA"}
I'm not sure that we would need this command since setconstellationscolor already sets the corresponding
label(s) to the same color as the specified constellation(s). Do you have a situation where a constellation would
need a different color than its label?

m3ntol wrote:setboundaries Allow to sow/hide asterism boundaries, the sintax is as follow
celestia:setboundaries{All=false}
celestia:setboundaries{CAS = true, UMA = true, CEP = true, UMI=true, DRA=true}

setboundariescolor Assign a color to each asterisms boundarie, the sintax is as follow
celestia:setboundariescolor{All = "#FFFFFF"}
celestia:setboundariescolor{CAS = "#FF0000", UMA = "#0000FF", CEP = "#00FFFF"}
I agree that the show/hideboudaries and setboundariescolor functions could be useful.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
m3ntol
Posts: 29
Joined: 23.02.2008
With us: 16 years 7 months
Location: Madrid, Spain, Earth, Solar System, Milky Way, Virgo Cluster

Re: Activate only one Constelation

Post #89by m3ntol » 10.10.2008, 09:30

Ok,
the boundaries commands are supported in this two files:
boundaries.c
boundaries.h
you can download it from http://www.astrohenares.org/upd/data/boundaries.rar

And also, you should add the parsing in the celx.cpp file. The lines to add are this two functions:

Code: Select all

static int celestia_setboundaries(lua_State* l)
{
    checkArgs(l, 2, 2, "One argument expected for celestia:setboundaries()");
    CelestiaCore* appCore = this_celestia(l);
    if (!lua_istable(l, 2))
    {
        doError(l, "Argument to celestia:setboundaries() must be a table");
    }

    lua_pushnil(l);
    while (lua_next(l, -2) != 0)
    {
        string key;
        bool value = false;
        if (lua_isstring(l, -2))
        {
            key = lua_tostring(l, -2);
        }
        else
        {
            doError(l, "Keys in table-argument to celestia:setboundaries() must be strings");
        }
        if (lua_isboolean(l, -1))
        {
            value = lua_toboolean(l, -1) != 0;
        }
        else
        {
            doError(l, "Values in table-argument to celestia:setboundaries() must be boolean");
        }
      
      for(int j=0; j<key.size(); j++)
         if(key[j]=='_')
            key[j]=' ';

      Universe* u = getAppCore(l, AllErrors)->getSimulation()->getUniverse();
      if (u != NULL)
      {
         ConstellationBoundaries* boundaries = u->getBoundaries();
         for (vector<consChain*>::iterator iter = boundaries->chains.begin(); iter != boundaries->chains.end(); iter++)
         {
            consChain* chain = *iter;
            if(compareIgnoringCase(key,"all") ==0 ) {
               chain->active=(value)?1:0;
            }
            else if(compareIgnoringCase(key,chain->cons) ==0 ) {
                  chain->active=(value)?1:0;
                  break;
            }
         }
      }
       
        lua_pop(l,1);
    }
   
    return 0;
}


static int celestia_setboundariescolor(lua_State* l)
{
    checkArgs(l, 2, 2, "One argument expected for celestia:setboundariescolor()");
    CelestiaCore* appCore = this_celestia(l);
    if (!lua_istable(l, 2))
    {
        doError(l, "Argument to celestia:setboundariescolor() must be a table");
    }

    lua_pushnil(l);
    while (lua_next(l, -2) != 0)
    {
        string key;
        string value;
        if (lua_isstring(l, -2))
        {
            key = lua_tostring(l, -2);
        }
        else
        {
            doError(l, "Keys in table-argument to celestia:setboundariescolor() must be strings");
        }
        if (lua_isstring(l, -1))
        {
            value = lua_tostring(l, -1);
        }
        else
        {
            doError(l, "Values in table-argument to celestia:setboundariescolor() must be strings");
        }
      
      for(int j=0; j<key.size(); j++)
         if(key[j]=='_')
            key[j]=' ';

      Color consColor(1.0f, 0.0f, 0.0f);
      Color::parse(value.c_str(), consColor);
      

      Universe* u = getAppCore(l, AllErrors)->getSimulation()->getUniverse();
      if (u != NULL)
      {
         ConstellationBoundaries* boundaries = u->getBoundaries();
         for (vector<consChain*>::iterator iter = boundaries->chains.begin(); iter != boundaries->chains.end(); iter++)
         {
            consChain* chain = *iter;
            if(compareIgnoringCase(key,"all") ==0 ) {
               chain->ConstellationColor[0]=consColor.red();
               chain->ConstellationColor[1]=consColor.green();
               chain->ConstellationColor[2]=consColor.blue();
               chain->useColor=1;
            }
            else if(compareIgnoringCase(key,chain->cons) ==0 ) {
               chain->ConstellationColor[0]=consColor.red();
               chain->ConstellationColor[1]=consColor.green();
               chain->ConstellationColor[2]=consColor.blue();
               chain->useColor=1;
               break;
            }
         }
      }
       
        lua_pop(l,1);
    }
   
    return 0;
}


And register it on the CreateCelestiaMetaTable funtions by adding this.

Code: Select all

   RegisterMethod(l, "setboundaries", celestia_setboundaries);
   RegisterMethod(l, "setboundariescolor", celestia_setboundariescolor);


Return to “Scripting”