Board index FlightGear Support Flying

View Positions  Topic is solved

Controlling your aircraft, using the autopilot etc.

Re: View Positions

Postby specksavers » Thu Aug 15, 2013 2:09 pm

Philosopher wrote in Thu Aug 15, 2013 12:45 pm:How are you exiting from FG? I think it worked for me, but when doing things like that I make sure to use the menubar or the escape dialog to exit so that the fgcommand is called. If not, nothing happens.


Ill try this out, sometimes I Cmd-Q and sometimes I use the menu bar.
European Air Force - Head of the Air Defence Operations Component.
User avatar
specksavers
 
Posts: 135
Joined: Thu Dec 13, 2012 9:27 pm
Callsign: EAF023
Version: 2.10
OS: Mac OS X

Re: View Positions

Postby macnab » Thu Aug 15, 2013 3:01 pm

Using File Quit works. I will log a bug report that using the window close icon does not work.
macnab
 
Posts: 886
Joined: Tue Aug 02, 2011 7:20 am
Location: Johannesburg, South Africa
Callsign: ZS-ILH
Version: Git
OS: Win7Pro 64bit SP1

Re: View Positions

Postby Hooray » Thu Aug 15, 2013 3:04 pm

good idea, we would need to register the equivalent of an atexit() handler at the OSG level, to make sure that the fgcommand("exit") listener is first executed so that all subsystems can clean up properly.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11377
Joined: Tue Mar 25, 2008 8:40 am

Re: View Positions

Postby macnab » Thu Aug 15, 2013 3:28 pm

In Windows there is a message, which can be trapped, QueryExit. This is where where exit code should be handled. It is called regardless of the method used to close the window. They will understand this from the bug report.

Currently it is obviously only handled from the menu File --> Quit.

I would assume the other OSs have something similar.
macnab
 
Posts: 886
Joined: Tue Aug 02, 2011 7:20 am
Location: Johannesburg, South Africa
Callsign: ZS-ILH
Version: Git
OS: Win7Pro 64bit SP1

Re: View Positions

Postby specksavers » Thu Aug 15, 2013 3:39 pm

Yes, It will only save if you exit from the menu bar. Thanks again :)
European Air Force - Head of the Air Defence Operations Component.
User avatar
specksavers
 
Posts: 135
Joined: Thu Dec 13, 2012 9:27 pm
Callsign: EAF023
Version: 2.10
OS: Mac OS X

Re: View Positions

Postby rominet » Fri Aug 14, 2015 10:22 am

Hello,

This code is extremely useful, I have been using it for a long time without any problem. Thank you so much, Philosopher!

Here is a very slightly modified version with tooltips for visual feedback when saving or recalling a view. It is in patch form with DEP-3-style headers. Save it to customizable-persistent-views.patch and apply it with:
Code: Select all
patch -p1 <customizable-persistent-views.patch

People using Git may apply it to fgdata with:
Code: Select all
git apply customizable-persistent-views.patch

but you would need to do that on your personal branch, otherwise you would have problems on the next 'git pull' unless using 'git reset --hard' (which would restore the branch to "official state", hence without the patch).

Here is the patch:
Code: Select all
Description: User-customizable views that persist across sessions
 A custom view is defined with super-F1 through super-F10 and restored with the
 corresponding ctrl-F<n> shortcut. Saving of the defined views to the
 filesystem (in $FG_HOME/aircraft-data/<aircraft-name>-views.xml) is performed
 when FlightGear exits.
Author: Philosopher on the FlightGear forum
Origin: other, http://forum.flightgear.org/viewtopic.php?f=25&t=20547#p188253
Forwarded: no

Patch based on fgdata commit 454fa8df8f82fba1e7a98a3137dd02756506567
(branch 'next', dated Wed Aug 12 11:31:05 2015 +0300)

diff --git a/keyboard.xml b/keyboard.xml
index 3ae9c88..e08db93 100644
--- a/keyboard.xml
+++ b/keyboard.xml
@@ -35,6 +35,20 @@ top down before the key bindings are parsed.
           }
       }
 
+      var custom_views = {}; # for saving view positions
+      var node = io.read_properties(getprop("/sim/fg-home") ~ "/aircraft-data/"
+                                    ~ getprop("/sim/aircraft") ~ "-views.xml");
+      if (node != nil)
+          foreach (var n; node.getChildren("view-config"))
+              custom_views[n.getIndex()] = n;
+      setlistener("sim/signals/exit", func {
+          var node = props.Node.new();
+          foreach (var i; keys(custom_views))
+              props.copy(custom_views[i], node.getChild("view-config",i,1));
+          io.write_properties(getprop("/sim/fg-home") ~ "/aircraft-data/"
+                              ~ getprop("/sim/aircraft") ~ "-views.xml", node);
+      });
+
       ## uncomment this line to get keycode reports printed to the terminal window
       #setlistener("devices/status/keyboard/event", func(n) debug.dump(n.getValues()));
   </script>
@@ -1458,6 +1472,268 @@ top down before the key bindings are parsed.
   </binding>
  </key>
 
+<!-- Custom additions: save and restore views. Heavily inspired from
+     <http://forum.flightgear.org/viewtopic.php?f=25&t=20547#p188253>
+-->
+
+ <key n="257">
+   <name>F1</name>
+   <mod-ctrl>
+     <desc>Reset to view default/custom view 1</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         if (custom_views[0] == nil)
+           view.resetView();
+         else
+           view.point.move(custom_views[0], 0.1);
+       </script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 1</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 1", 2);
+         custom_views[0] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="258">
+   <name>F2</name>
+   <mod-ctrl>
+     <desc>Restore custom view 2</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[1], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 2</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 2", 2);
+         custom_views[1] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="259">
+   <name>F3</name>
+   <mod-ctrl>
+     <desc>Restore custom view 3</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         view.point.move(custom_views[2], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 3</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 3", 2);
+         custom_views[2] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="260">
+   <name>F4</name>
+   <mod-ctrl>
+     <desc>Restore custom view 4</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[3], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 4</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 4", 2);
+         custom_views[3] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="261">
+   <name>F5</name>
+   <mod-ctrl>
+     <desc>Restore custom view 5</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[4], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 5</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 5", 2);
+         custom_views[4] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="262">
+   <name>F6</name>
+   <mod-ctrl>
+     <desc>Restore custom view 6</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[5], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 6</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 6", 2);
+         custom_views[5] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="263">
+   <name>F7</name>
+   <mod-ctrl>
+     <desc>Restore custom view 7</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[6], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 7</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 7", 2);
+         custom_views[6] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="264">
+   <name>F8</name>
+   <mod-ctrl>
+     <desc>Restore custom view 8</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[7], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 8</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 8", 2);
+         custom_views[7] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="265">
+   <name>F9</name>
+   <mod-ctrl>
+     <desc>Restore custom view 9</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[8], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 9</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 9", 2);
+         custom_views[8] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="266">
+   <name>F10</name>
+   <mod-ctrl>
+     <desc>Restore custom view 10</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[9], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 10</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 10", 2);
+         custom_views[9] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="267">
+   <name>F11</name>
+   <mod-ctrl>
+     <desc>Restore custom view 11</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[10], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 11</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 11", 2);
+         custom_views[10] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
+ <key n="268">
+   <name>F12</name>
+   <mod-ctrl>
+     <desc>Restore custom view 12</desc>
+     <binding>
+       <command>nasal</command>
+       <script>view.point.move(custom_views[11], 0.1)</script>
+     </binding>
+   </mod-ctrl>
+   <mod-super>
+     <desc>Save custom view 12</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         gui.popupTip("Saving custom view 12", 2);
+         custom_views[11] = view.point.save();
+       </script>
+     </binding>
+   </mod-super>
+ </key>
+
 </PropertyList>
 
 <!-- end of keyboard.xml -->


The only improvement I can think of would be to immediately save the view instead of deferring that to FG exit time, because it is annoying to lose carefully-prepared views because of an FG crash. However, sometimes it happens to be convenient when you accidentally overwrite an already-saved view. In such a case, one just has to kill FlightGear in order not to lose the already-saved view. :wink:

PS: to respond to the other (oldish) messages, the "save-at-exit" code works fine for me.
rominet
 
Posts: 557
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Previous

Return to Flying

Who is online

Users browsing this forum: No registered users and 1 guest