How to select a View in a script?
-
Topic authorselden
- Developer
- Posts: 10192
- Joined: 04.09.2002
- With us: 22 years 2 months
- Location: NY, USA
How to select a View in a script?
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.
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.
Selden
-
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
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.
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.
@+
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
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
-
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
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...
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...
@+
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
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 authorselden
- Developer
- Posts: 10192
- Joined: 04.09.2002
- With us: 22 years 2 months
- Location: NY, USA
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.
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.
Selden
-
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
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:
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)
@+
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
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
-
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
As another example, here a script that displays the speed value in ly/s for each observer:
Just click the different views and change the speed with the 'A'/'Z' keys...
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...
@+
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
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
-
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
selden wrote:Vincent,
Thanks!
Selden,
You're welcome !
Is there still a need for adding the set/getactiveview methods to celx scripting ?
@+
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
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
-
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
Selden,
You can already get the current active view in celx.
As an example, the following script displays the current active view:
Do you have an example of situation where setting the active view from celx would be useful ?
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 ?
@+
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
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 authorselden
- Developer
- Posts: 10192
- Joined: 04.09.2002
- With us: 22 years 2 months
- Location: NY, USA
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]
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]
Selden
-
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
Yes, I Agree. The setactiveview method would be a useful addition.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.
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")
@+
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
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
-
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
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:
Then, I don't think that adding a getactiveview() method would be useful since
already returns the current active observer (and yet, the current active view).
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).
Last edited by Vincent on 15.06.2007, 19:21, edited 1 time in total.
@+
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
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
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