Page 1 of 1

How to select a View in a script?

Posted: 13.06.2007, 11:45
by selden
After dividing Celestia's window into several Views, how can one select a particular View to manipulate?

Alternatively, how can a CELX script specify which View is to be Active?

(Note that these two questions are NOT the same. The Active View, the one with which the user's interactive commands are associated, should not necessarily be the same as the View that a CELX script is manipulating.)

As best I can tell, most operations (goto, etc) manipulate only the [edit]View which was active at the time of the call to getobserver()[/edit], and the Active View can only be specified by the user clicking in it. Associating a CELX command with a different "observer" does NOT cause it to manipulate the View for which that observer was defined.

For example, if obs1 is the observer associated with the 1st view, and obs2 is the observer associated with the 2nd view,
obs2:goto(target)
goes to the specified target in the [edit] view active at the time of the most recent getobserver() call[/edit]; it does not goto the target in the 2nd View. Comparably,
obs1:deleteview()
deletes the [edit] view active at the time of the most recent getobserver() call[/edit]; it does not delete the 1st View.

This problem has come up in my current Pointing Hubble Addon. I need to be able to manipulate the viewpoint of the View which was created at the beginning of the script, after creating several other Views.

Maybe I'm just misunderstanding how the observers and Views are interrelated. An example of code which manipulates the contents of multiple Views would be greatly appreciated.

Posted: 13.06.2007, 12:33
by Vincent
Selden,

AFAIK, there's unfortunately no way to set the active view from celx/lua...
I've also spent quite a few hours trying to do this in one of my scripts, but came with the conclusion that it is not possible other than with a mouse click...

If this is effectively the case (maybe Hank can confirm), I'll have a look at the code and try to add the set/getactiveview methods to celx scripting.

Posted: 13.06.2007, 12:57
by Vincent
Selden,

Please see http://celestiaproject.net/forum/viewtopic.php?t=7322
That confirms that there's no way in celx to set the active view.
However, it seems to be possible in celx to act on each observer independently...

Posted: 13.06.2007, 13:43
by selden
Vincent,

Thanks for investigating. Being able to set/get active view would help a lot.

Unfortunately, my attempts to set/get the observer environment are not producing consistent results :(

Posted: 13.06.2007, 14:04
by selden
A related issue:

obs:splitview()
does not return a value corresponding to the new observer. It should.

Having to discover the new view's observer environment by calling getobserver() is not appropriate. getobserver() returns an observer supposedly corresponding to the currently active view, which is not necessarily the same. The user might already have changed the active view by the time getobserver has been called.

Posted: 13.06.2007, 14:52
by Vincent
Selden,

observers = celestia:getobservers()
will return a table with all observers in use.
This will allow you to control each view/observer.

As an example, here's a script that set a different speed value to each observer:

Code: Select all

obs = celestia:getobserver()
obs:singleview()
obs:setspeed(0)
obs:splitview("v")

observers = celestia:getobservers()
observers[1]:setspeed(1)
observers[2]:setspeed(2)

Posted: 13.06.2007, 15:09
by Vincent
As another example, here a script that displays the speed value in ly/s for each observer:

Code: Select all

-- Display the speed value in ly/s for each observer

obs = celestia:getobserver()
obs:singleview()
obs:setspeed(0)
obs:splitview("v")

speed = {}

while true do
   observers = celestia:getobservers()
   speed[1] = observers[1]:getspeed()
   speed[2] = observers[2]:getspeed()
   speed_str = "obs 1: "..string.format("%g", speed[1]*1e-6).." ly/s".."\n".."obs 2: "..string.format("%g", speed[2]*1e-6).." ly/s"
   celestia:print(speed_str)
   wait(0)
end


Just click the different views and change the speed with the 'A'/'Z' keys...

Posted: 13.06.2007, 18:48
by selden
Vincent,

Thanks!

Posted: 15.06.2007, 15:45
by Vincent
selden wrote:Vincent,

Thanks!

Selden,

You're welcome !

Is there still a need for adding the set/getactiveview methods to celx scripting ?

Posted: 15.06.2007, 16:08
by selden
Vincent,

Yes, I think there is.

(I still seem to be getting inconsistent view selections for some operations, but I haven't had the time to clarify to myself exactly what is happening.)

Posted: 15.06.2007, 16:50
by Vincent
Selden,

You can already get the current active view in celx.
As an example, the following script displays the current active view:

Code: Select all

-- Display the current active view.

getActiveView = function ()
   observers = celestia:getobservers()
   activeObs = celestia:getobserver()
   for view, obs in pairs(observers) do
      if obs == activeObs then
         activeView = view
      end
   end
   return activeView
end

obs = celestia:getobserver()
obs:singleview()
obs:splitview("v")

observers = celestia:getobservers()
observers[2]:splitview("h")

while true do
   active_view = getActiveView()
   celestia:print("Active View: "..string.format("%i", active_view))
   wait(0)
end

Do you have an example of situation where setting the active view from celx would be useful ?

Posted: 15.06.2007, 17:10
by selden
Vincent,

If I can manage to control the views in the ways I want by using an appropriate obs prefix (of which I am not yet convinced) then the primary use of setting a particular view active would be to ensure that the user of a script doesn't mess up the states of the other views.

In an educational situation, to pick one example, one would like to ensure that the object of interest stays visible so that the student is looking at something appropriate.

[edit]
Another would be when one wants the user to be modifying selections and viewpoints in one view while the script changes the other views to match. At the moment, the active view is always the last one "split". Being able to specify which view is active would greatly simplify how one has to design the view splitting.
[/edit]

Posted: 15.06.2007, 17:43
by Vincent
selden wrote:Vincent,

If I can manage to control the views in the ways I want by using an appropriate obs prefix (of which I am not yet convinced) then the primary use of setting a particular view active would be to ensure that the user of a script doesn't mess up the states of the other views.

In an educational situation, to pick one example, one would like to ensure that the object of interest stays visible so that the student is looking at something appropriate.
Yes, I Agree. The setactiveview method would be a useful addition.


selden wrote:At the moment, the active view is always the last one "split". Being able to specify which view is active would greatly simplify how one has to design the view splitting.

In my last example above, the active view is not the last one split, but the first view.
And I could choose which view to split (the second one in my example) using:

Code: Select all

observers = celestia:getobservers()
observers[2]:splitview("h")

Posted: 15.06.2007, 18:17
by Vincent
OK, I've added the setactive() method to observer in my "experimental" Celestia built, and it seems to work fine. One will be able to set the active view using the following celx/Lua code:

Code: Select all

-- Get all observers/views in use.
observers = celestia:getobservers()

-- Set observer/view #2 as the active observer/view.
observers[2]:setactive()


Then, I don't think that adding a getactiveview() method would be useful since

Code: Select all

obs = celestia:getobserver()

already returns the current active observer (and yet, the current active view).

Posted: 15.06.2007, 19:04
by hank
selden wrote:Vincent,

If I can manage to control the views in the ways I want by using an appropriate obs prefix (of which I am not yet convinced) then the primary use of setting a particular view active would be to ensure that the user of a script doesn't mess up the states of the other views.

In an educational situation, to pick one example, one would like to ensure that the object of interest stays visible so that the student is looking at something appropriate.

Another would be when one wants the user to be modifying selections and viewpoints in one view while the script changes the other views to match. At the moment, the active view is always the last one "split". Being able to specify which view is active would greatly simplify how one has to design the view splitting.

Maybe what you really need is the ability to "lock" a view (or views) so the user can't change it?

- Hank

Posted: 15.06.2007, 20:23
by selden
Hank,

That sounds like a reasonable additional feature, yes!

Posted: 02.08.2007, 18:41
by immersive
I am working on a project that would greatly benefit from this command. Has anything been done on this?? if so where can I find it?