Board index FlightGear Development Canvas

TUT layer in the canvas map

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

TUT layer in the canvas map

Postby ludomotico » Thu Oct 01, 2015 1:47 pm

The TUT layer for the MapStructure doesn't seem to be implemented yet (http://wiki.flightgear.org/Canvas_MapStructure_Layers). Hence, I'm trying to familiarize myself with the canvas map by implementing this layer. Unfortunately, there is an error I can't understand. This layer should show the "targets" of a tutorial on a map.

I'm using this TUT.lcontroller. It is copied from APT.lcontroller, and searchCmd() is the only change. TUT.symbol is the same than APT.symbol.

Code: Select all
# See: http://wiki.flightgear.org/MapStructure
# Class things:
var name = 'TUT';
var parents = [SymbolLayer.Controller];
var __self__ = caller(0)[0];
SymbolLayer.Controller.add(name, __self__);
SymbolLayer.add(name, {
   parents: [MultiSymbolLayer],
   type: name, # Symbol type
   df_controller: __self__, # controller to use by default -- this one
   df_style: {
      line_width: 3,
      scale_factor: 1,
      debug: 1,
      color_default: [0,0.6,0.85],
      label_font_color:[0,0.6,0.85],
      label_font_size: 28,
      text_offset: [17,35],
      svg_path: nil
   },

});
var a_instance = nil;
var new = func(layer) {
   var m = {
      parents: [__self__],
      layer: layer,
      map: layer.map,
      listeners: [],
   };
   m.addVisibilityListener();

   return m;
};
var del = func() {
   #print(name,".lcontroller.del()");
   foreach (var l; me.listeners)
      removelistener(l);
};

var searchCmd = func {
   #print("Running query:", name);
   var range = me.map.getRange();
   if (range == nil) return;
   return [
          geo.Coord.new().set_latlon(45.83490744, 9.08522898),
          geo.Coord.new().set_latlon(45.87612889, 9.14321644)
        ];
};


(The coordinates are hard-coded just for debugging)

Then, I run this code to load the TUT layer:

Code: Select all
var temp = {};
  temp.dlg = canvas.Window.new([600,400],"dialog");
  temp.canvas = temp.dlg.createCanvas().setColorBackground(1,1,1,0.5);
  temp.root = temp.canvas.createGroup();
  var TestMap = temp.root.createChild("map");
  TestMap.setController("Aircraft position");
  TestMap.setRange(25);
 
  TestMap.setTranslation(
                           temp.canvas.get("view[0]")/2,
                           temp.canvas.get("view[1]")/2
                        );
 var r = func(name,vis=1,zindex=nil) return caller(0)[0];
 foreach(var type; [r('TUT'),r('APT'), r('APS') ] )
        TestMap.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: type.zindex,);


This code throws this error:

Code: Select all
Fatal error in Nasal call: Can not convert to 'Positioned": not a derived hash:
at ...../geo.nas (line 382)
called from: .../MapStructure.nas line 1045
...


Must searchCmd() return an array of FGPositioned objects? Can I create a FGPositioned object in Nasal? Is there any way for searchCmd() to return an array of Coords? Am I extending the wrong Layer (MultiSymbolLayer)?

Thanks!
User avatar
ludomotico
 
Posts: 1269
Joined: Tue Apr 24, 2012 2:01 pm
Version: nightly
OS: Windows 10

Re: TUT layer in the canvas map

Postby Philosopher » Thu Oct 01, 2015 5:51 pm

Sorry, I'm half-afk right now, so I can't look up precise details on how I did it, but it looks like you need a equals method. (Okay, I admit this is pretty dumb, but I don't have time right now to change it to work for broader use-cases automatically.)
Philosopher
 
Posts: 1593
Joined: Sun Aug 12, 2012 7:29 pm

Re: TUT layer in the canvas map

Postby Hooray » Thu Oct 01, 2015 6:39 pm

actually, we did have a working "TUT" layer, and it was kinda straightforward/trivial, too.
It just seems that this never got committed to fgdata, and also may not have survived the gitorious transition.
Regarding the "equals" method, you can refer to the MapStructure article on the wiki which has all the details.

Concerning FGPositioned: you can just return a geo.Coord() instead - which works just as well.
Please refer to the MapStructure article, which really does cover all this stuff specifically.

I suggest to search for "geo.Coord" and "equals" there - but to also look at the surrounding context
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: TUT layer in the canvas map

Postby ludomotico » Thu Oct 01, 2015 6:53 pm

Hooray wrote in Thu Oct 01, 2015 6:39 pm:Concerning FGPositioned: you can just return a geo.Coord() instead - which works just as well.


Actually, I'm returning a vector of geo.Coord() in the code cited above, but it seems the MapStructure does not support this type of data.

I'll check providing an "equals" funtion.
User avatar
ludomotico
 
Posts: 1269
Joined: Tue Apr 24, 2012 2:01 pm
Version: nightly
OS: Windows 10

Re: TUT layer in the canvas map

Postby Hooray » Thu Oct 01, 2015 6:57 pm

yes, vector is correct - and this should/does work properly, it's been a while, but that is how the code is structured IIRC - but the de-facto reference really is the MapStructure article.


If in doubt, I would suggest to review other layers doing similar things - i.e. cd $FG_ROOT && grep -nr "Coord" *.lcontroller

I also think that Red Leader's TGT layer was using the same approach (it is even documented on the forum, including code snippets)

viewtopic.php?f=71&t=23299&hilit=
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: TUT layer in the canvas map

Postby Hooray » Thu Oct 01, 2015 7:09 pm

cd $FG_ROOT/Nasal/canvas/map && grep -nr Coord *.lcontroller

Code: Select all
APS.lcontroller:16:   var __model = layer.map.getPosCoord();
APT.lcontroller:45:   return positioned.findAirportsWithinRange(me.map.getPosCoord(), range);
HOLD.lcontroller:55:            parents: [geo.Coord],
HOLD.lcontroller:81:            parents: [geo.Coord],
TFC.lcontroller:43:         parents: [TrafficModel, geo.Coord, node], # note we don't implement a full geo.Coord API
TFC.lcontroller:52:   latlon: func() { # this makes sure to look like a geo.Coord to MapStructure, but will internally use the AI/MP traffic properties instead
WXR.lcontroller:54:      var stormGeo = geo.Coord.new();
WXR.lcontroller:55:      var acGeo = geo.Coord.new();
WXR.lcontroller:65:         var tmp = geo.Coord.new();
WXR_live.lcontroller:55:   var result = geo.Coord.new();



So given this code, I am pretty sure that geo.Coord() support is still working correctly - unless the other layers also don't work anymore ?
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: TUT layer in the canvas map

Postby Hooray » Thu Oct 01, 2015 7:48 pm

As per the wiki, here's the original screen shot (and code) implementing a simple demo layer (note how this is just returning a vector of geo.Coord objects):

http://wiki.flightgear.org/Canvas_Radar ... ry_Objects
Image
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: TUT layer in the canvas map

Postby Hooray » Fri Oct 02, 2015 8:35 pm

is this still working correctly or not, any updates ?
If you are getting stuck, please post all your code using a pastebin (or the wiki) - e.g. we could turn this into a Canvas/MapStructure article on creating a new layer. I would then make sure to post working code snippets, and maybe you could help document the whole journey ?
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: TUT layer in the canvas map

Postby Hooray » Sun Oct 04, 2015 3:16 pm

FYI: I have begun documenting the required steps and added everything to the MapStructure article (untested for now) - any comments/help, code snippets, testing/review would be appreciated: http://wiki.flightgear.org/Canvas_MapSt ... _Layer_TUT
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: TUT layer in the canvas map

Postby Hooray » Wed Oct 07, 2015 5:30 pm

Here's a screen shot showing the updated/working TUT layer, using the NDB symbol for tutorial targets - at KLVK with the c172p "taxiing" tutorial selected:

http://wiki.flightgear.org/Canvas_MapSt ... _Layer_TUT
Image

(primarily, this only required the addition of an equals method for comparison - and a default style, as per NDB.lcontroller-otherwise, it's basically ludomotico's code, including the snippets I posted on the wiki)
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Canvas

Who is online

Users browsing this forum: No registered users and 6 guests