Board index FlightGear Development

[closed] Flightgear plotter updated.

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Re: Flightgear plotter updated.

Postby kuifje09 » Thu May 23, 2013 4:37 pm

Hello Hooray,

I just used the complete code you provided as a few posts above with the name fgplot in it.
the line that gives the error from flightgear was only in the post, it would only double the text.

The complains are with the : var dlg = canvas.Window.new([400,300]);

( I wish I could get the code for the canvas-demo with the plane in it )
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Thu May 23, 2013 5:12 pm

The following code works for me (just tested again):
Code: Select all
var module_name = "fgplot"; # should be saved in $FG_ROOT/Nasal/fgplot/fgplot.nas

var setup = func( root ) {

var text = root.createChild("text")
.setText("Hello world from "~ module_name~" !")
.setTranslation(10, 30)
.setAlignment("left-top")
.setFontSize(14)
.setFont("LiberationFonts/LiberationSans-Regular.ttf")
.set("max-width", 380)
.setColor(0,0,0);

var graph = root.createChild("group");

var x_axis = graph.createChild("path", "x-axis")
.moveTo(10, 150)
.lineTo(380, 150)
.setColor(1,0,0)
.setStrokeLineWidth(3);

var y_axis = graph.createChild("path", "y-axis")
.moveTo(10, 30)
.lineTo(10, 250)
.setColor(1,0,0)
.setStrokeLineWidth(3);

var plot = graph.createChild("path", "data")
.setStrokeLineWidth(2)
.setColor(0,0,1)
.moveTo(10,150); # origin

var samples = [ # absolute coordinates
 [50, 150], [100,140], [200,110], [270, 55]
 ];

foreach(var set; samples)
plot.lineTo( set[0], set[1] );

} # end of setup  routine

var init = func() {
removelistener( listener_id );
var dlg = canvas.Window.new([400,300]);
var my_canvas = dlg.createCanvas().setColorBackground(0,0,0,0);
var root = my_canvas.createGroup();
var title_bar = root.createChild("group");
title_bar.addEventListener("drag", func(e) { dlg.move(e.deltaX, e.deltaY); });
var x = 0;
var y = 0;
var rx = 8;
var ry = 8;
var w = 400;
var h = 20;
title_bar.createChild("path")
.moveTo(x + w - rx, y)
.arcSmallCWTo(rx, ry, 0, x + w, y + ry)
.vertTo(y + h)
.horizTo(x)
.vertTo(y + ry)
.arcSmallCWTo(rx, ry, 0, x + rx, y)
.close()
.setColorFill(0.25,0.24,0.22)
.setStrokeLineWidth(0);
y = 20;
h = 280;
root.createChild("path")
.moveTo(x + w, y)
.vertTo(y + h)
.horizTo(x)
.vertTo(y)
.setColorFill(1,1,1)
.setColor(0,0,0);
x = 8;
y = 5;
w = 10;
h = 10;
title_bar.createChild("path", "icon-close")
.moveTo(x, y)
.lineTo(x + w, y + h)
.moveTo(x + w, y)
.lineTo(x, y + h)
.setColor(1,0,0)
.setStrokeLineWidth(3)
.addEventListener("click", func dlg.del());
title_bar.createChild("text", "dialog-caption")
.setText( module_name )
.setTranslation(x + w + 8, 4)
.setAlignment("left-top")
.setFontSize(14)
.setFont("LiberationFonts/LiberationSans-Bold.ttf")
.setColor(1,1,1);

setup( root ); # pass our root canvas to the setup routine (could be anything, even the whole env using closure() )
}
var listener_id = _setlistener("/nasal/"~module_name~"/loaded", init );


There are some subtle issues because of copying/pasting things between the forum and the wiki, where some of the markup got lost and illegal characters were introduced, I only just realized that when copying the code into a new file. In case of doubt, see: http://codepad.org/j1cRXlVY/raw.txt
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Thu May 23, 2013 5:31 pm

Allright, I tested again, did a new copy of the code.. but.
I get the same error :
Nasal runtime error: No such member: Window
at /usr/share/games/flightgear/Nasal/fgplot/fgplot.nas, line 44

Can it be I miss something else ? I have here ubuntu running and the ubuntu distributed version of flightgear ...
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Thu May 23, 2013 5:38 pm

That looks like your $FG_ROOT/FGDATA (base package) may not have the corresponding Nasal/Canvas code for the Window class yet. Check $FG_ROOT/Nasal/canvas/gui.nas against gitorious/mapserver: http://mapserver.flightgear.org/git/?p= ... 94;hb=HEAD

I believe it should be part of 2.10, but according to the commit history, the class was previously named "Dialog", not "Window" (if you still have the old code, you would have to use Dialog instead of Window).
Alternatively, you could try manually updating $FG_ROOT/Nasal/canvas by downloading the code from the repo (back up the original folder first).

On the other hand, there's no need to use a dedicated Window for this, you could also use a PUI/Canvas widget, the canvas code will remain the same - it's just a different render target (placement mode).

You can simply add a conventional XML dialog to $FG_ROOT/gui/dialogs - name it fgplot.xml
That dialog can then have an embedded canvas. And both, the dialog itself AND the canvas support embedded Nasal sections.
Last edited by Hooray on Thu May 23, 2013 5:53 pm, edited 1 time in total.
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Thu May 23, 2013 5:42 pm

Thats what I was afrait of too, My version is 2.10.0 but maybe incomplete ...
I must say, the c172p-canvas do work. I have the rotating text i.e in the grey frame on the yoke.
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Thu May 23, 2013 5:45 pm

yes, I think, the canvas itself is definitely available - the Nasal wrappers have just different names, which is why my example doesn't work for you.
But that's not a real problem - like I said earlier, you can either use the old "canvas.Dialog" instead of canvas.Window - or simply use a canvas embedded in a dialog. All the drawing etc will remain the same - it's just a different rendering target.

For the sake of simplicity, check first if canvas.Dialog works for you (i.e. using the Nasal console, paste/run):
Code: Select all
<?xml version="1.0"?>
<PropertyList>
  <name>fgplot</name>
  <modal>false</modal>
  <layout>vbox</layout>

  <text>
    <label>FGPlot</label>
  </text>

  <group>
    <layout>hbox</layout>
    <halign>fill</halign>
    <default-padding>10</default-padding>
    <empty><stretch>true</stretch></empty>

    <empty><stretch>true</stretch></empty>

<canvas>
               <name>fgplot</name>
               <valign>fill</valign>
               <halign>fill</halign>
               <stretch>true</stretch>
               <pref-width>600</pref-width>
               <pref-height>400</pref-height>
<nasal>     
<!--
     this is the Nasal/canvas section where you can run your own Nasal code
     to access the canvas section
-->
<load><![CDATA[
# you can add your canvas-specific code here
var my_canvas = canvas.get( cmdarg() ); # this will get a handle to the parent canvas:

var root = my_canvas.createGroup();
var text = root.createChild("text")
.setText("Hello world from FGPlot v. 0.1 !")
.setTranslation(10, 30)
.setAlignment("left-top")
.setFontSize(20)
.setFont("LiberationFonts/LiberationSans-Regular.ttf")
.set("max-width", 380)
.setColor(1,0,0);


var graph = root.createChild("group");

var x_axis = graph.createChild("path", "x-axis")
.moveTo(10, 150)
.lineTo(380, 150)
.setColor(1,0,0)
.setStrokeLineWidth(3);

var y_axis = graph.createChild("path", "y-axis")
.moveTo(10, 30)
.lineTo(10, 250)
.setColor(1,0,0)
.setStrokeLineWidth(3);

var plot = graph.createChild("path", "data")
.setStrokeLineWidth(2)
.setColor(0,0,1)
.moveTo(10,150); # origin

var samples = [ # absolute coordinates
[50, 150], [100,140], [200,110], [270, 55]
];

foreach(var set; samples)
plot.lineTo( set[0], set[1] );



print("Hello world from the embedded canvas section!\n");

]]>
</load>
</nasal>
</canvas>

    <button>
      <legend>Exit</legend>
      <equal>true</equal>
      <key>Esc</key>
      <binding>
        <command>dialog-close</command>
      </binding>
    </button>

    <empty><stretch>true</stretch></empty>
  </group>
</PropertyList>
Last edited by Hooray on Thu May 23, 2013 6:44 pm, edited 1 time in total.
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Thu May 23, 2013 5:58 pm

Hi Hooray, I checked the gui.nas and they do differ a lot ! 121 lines against 1449 lines.

Is this the right code to get updates from flightgear :
binary http://ppa.launchpad.net/saiarcot895/flightgear/ubuntu
source http://ppa.launchpad.net/saiarcot895/flightgear/ubuntu

I don't think they work, else I had already an update available I guess
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Thu May 23, 2013 6:04 pm

Like I said earlier, there were tons of changes - but it's really just a different placement mode that the example code is using. If you can update FG, that would be great obviously.

I don't think there's an updated version available yet - only the 2.10 release. Or you would have to build from source using brisa's script: http://wiki.flightgear.org/Scripted_Com ... ian/Ubuntu

Otherwise, I would just suggest to develop FGPlot as a conventional XML dialog with a <canvas> section for your rendering. All the canvas drawing stuff is supported there, too - and fgplot would be an XML file with embedded Nasal code.
Once you have a newer FG version, it will be easy to adapt the code to support the newer "Window" placement mode.

All the drawing, rendering etc is identical - it's just a different placement mode and some more GUI features (event handling).
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Thu May 23, 2013 6:08 pm

Alright, I go for this last option. I'll see howfar I can get with it. Thanks
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Thu May 23, 2013 6:27 pm

Just open an existing dialog from $FG_ROOT/gui/dialogs, copy a simple dialog like the exit/about dialog, and then customize it - i.e. by naming it "fgplot.xml" and removing stuff that you don't need, then add a new canvas widget to the dialog, like this:

http://wiki.flightgear.org/Howto:Adding ... GUI_dialog

Thread continued at: viewtopic.php?f=71&t=20024&p=184035#p184035
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Thu May 23, 2013 8:16 pm

Hi Hooray, you are fast...

I just did some like explained , I was using the map.xml.
One thing I don't get is why the "button" in the menubar.xml, I placed it above the map in the equipment-menu, does not show its name.
As soon as I use an existing name, say stopwatch, then stopwatch is visable in the menubar and clicking on it shows my fgplot . Silly but not good enough for me. What do I wrong.
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Thu May 23, 2013 8:25 pm

please just use my example - and invoke the dialog via the Nasal console and running gui.showDialog("fgplot"); for now.

As soon as I use an existing name, say stopwatch, then stopwatch is visable in the menubar and clicking on it shows my fgplot . Silly but not good enough for me. What do I wrong.


To explain what's going, note that there are some things to keep in mind:
  • dialog names must match the "name" tag in the PropertyList XML section (fgplot.xml => fgplot)
  • dialogs must be valid XML and PropertyList files, check the console for error messages or warnings - or use an XML validator
  • you can reload modified dialog files via the Debug menu (RELOAD GUI)
  • dialogs are addressed using their names (file name + internal name)
  • menu options are localized using properties for translations, see $FG_ROOT/Translations/en/menu.xml (you will want to add a FGPlot item there)
  • see README.gui and README.commands to learn more about GUI XML files in general

So when you use "FGPlot", FlightGear cannot find a matching translation string - when you use "Stopwatch" it finds one, and uses it - while still showing the correct dialog.

PS: map.xml does not yet use a canvas as far as I know, it uses a hard-coded "map" widget which is implemented in C++ (it predates the canvas system)
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Thu May 23, 2013 8:50 pm

Thanks Hooray.

Still refreshing my brains, but its going to work now.
Will scan some examples and read the manuals.

Hope to be back soon with some working example.
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Thu May 23, 2013 8:54 pm

The example I posted should work properly: http://wiki.flightgear.org/Howto:Adding ... GUI_dialog
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Sat May 25, 2013 12:39 pm

A little question about getting the debug values in a nasal script or in the property tree.
Because the debug values are only visible on the stdout of flightgear, as far as I know, I ask myself how to get those values in my fgplot.
There seems no nasal command to read from the network or url.
I thought of a work-around , creating a named pipe and read from the pipe like my xlib program. But, how would that work on windows.
Because it should work on "all" platforms I would prefere a real "flightgear solution" . I did search for a solution but I did not find.
Is there a way to get the debug values read-in into a nasal script. And that for about 50 times a second for all of them.

EDIT: Would it be an idea to have a debug node in the property tree for always. I mean, useable all times for all purposes.
Then it could be easily used in the fgplot. When you start the fgplot it shows immediately the posible "debug lines" which you can click on or off.
And you can view those values in a graph.
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

PreviousNext

Return to Development

Who is online

Users browsing this forum: No registered users and 2 guests