Board index FlightGear Development Canvas

createChild with a SVG object

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.

createChild with a SVG object

Postby www2 » Thu Nov 27, 2014 5:28 pm

Hi i have a problem when i wand use a svg object use for a MapStructure with createChild i get the No such member: createChild error.
Is this the correct method or i need to chance this?

Code: Select all
#########################################
# MAPSTRUTURE ON SVG TEST
#########################################
var MapStructure_demo = func() {
  var temp = {};
  temp.dlg = canvas.Window.new([512,512],"dialog");
  temp.canvas = temp.dlg.createCanvas().setColorBackground(1,1,1,0.5);
  temp.root = temp.canvas.createGroup();
  canvas.parsesvg(temp.root, "Aircraft/map.svg");
  maps = temp.root.getElementById("MAP");
  var TestMap = maps.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('TFC'),r('APT'), r('APS') ] )
    TestMap.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: type.zindex,);
}; # MapStructure_demo
MapStructure_demo();


Map.svg:
Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="512"
   height="512"
   id="svg2"
   version="1.1"
   inkscape:version="0.48.4 r9939"
   sodipodi:docname="Nieuw document 1">
  <defs
     id="defs4" />
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="1.4"
     inkscape:cx="473.27062"
     inkscape:cy="164.12858"
     inkscape:document-units="px"
     inkscape:current-layer="layer1"
     showgrid="false"
     inkscape:window-width="1855"
     inkscape:window-height="1056"
     inkscape:window-x="1745"
     inkscape:window-y="24"
     inkscape:window-maximized="1" />
  <metadata
     id="metadata7">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Laag 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(0,-540.36218)">
    <rect
       style="fill:#000000;fill-opacity:1;stroke:none"
       id="MAP"
       width="337.85715"
       height="337.85715"
       x="19.285715"
       y="697.36218"
       inkscape:label="#rect2987" />
  </g>
</svg>
www2
 
Posts: 319
Joined: Thu Apr 16, 2009 2:58 pm
OS: Ubuntu

Re: createChild with a SVG object

Postby Hooray » Thu Nov 27, 2014 5:39 pm

without any error checking involved, you may not be getting the correct objects, so that those methods are not available either.
In this case, it's the createChild() line where your assumption about the type of the variable is not matching what the Nasal engine is seeing.
If in doubt, you can use debug.dump() to inspect your variables (root, maps) etc.

Also, depending on what you want do, such custom code should probably be added to a custom layer, and not the top-level code calling MapStructure.
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: createChild with a SVG object

Postby www2 » Thu Nov 27, 2014 6:56 pm

Thaks i see that createChild not exist in maps.
For what i wand, i wand to use MapStructure as a texture in svg eliment with ID: MAP
www2
 
Posts: 319
Joined: Thu Apr 16, 2009 2:58 pm
OS: Ubuntu

Re: createChild with a SVG object

Postby Hooray » Thu Nov 27, 2014 7:10 pm

createChild() should be available for any valid canvas group - thus, your report would suggest that the element returned from parsesvg() is not what you are expecting.
According to your code it seems that you want to display a MapStructure map inside some kind of SVG overlay, is that correct ?
Depending on your OS, you may be unaware of any parse errors returned by parsesvg - parsesvg is a relatively simple Nasal module that only supports a tiny subset of SVG by mapping it to the corresponding Canvas/OpenVG primitives - it's a clever piece of code actually, but obviously there's a plethora of SVG features that are not supported by this Nasal module - thus, you should watch out for any errors/warnings, and if necessary revisit your SVG file, i.e. by converting some constructs and/or exporting the SVG to a simplified version.
You will however only be able to treat a SVG file as a canvas group if the file could be processed successfully.
I am not sure if those errors only show up in the console (startup window) or also the startup log file in $FG_HOME - if you're on some kind of OS that doesn't show a startup window, I'd suggest to check out the log file - or for the sake of simplicity, the Nasal Console (see the debug menu) which contains a dedicated Nasal-specific loglist widget, where all Nasal errors should up, too.
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 3 guests