Board index FlightGear Development Canvas

Why does parsesvg not find an SVG file that is there ?  Topic is solved

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.

Why does parsesvg not find an SVG file that is there ?

Postby TheEagle » Fri Aug 27, 2021 8:49 pm

Hello, I'm trying to show an SVG icon in a Canvas dialog. I am getting this message:
Code: Select all
 1073.64 [ALRT]:nasal      Nasal runtime error: File not found: /home/user/fgfs-addons/LandingChallenge/gui/images/threshold-deviation.svg
 1073.64 [ALRT]:nasal        at /home/user/fgdata-2020.4.0/Nasal/canvas/svg.nas, line 23
 1073.64 [ALRT]:nasal        called from: /home/user/fgfs-addons/LandingChallenge/dataDialog.nas, line 16

The relevant code is:
Code: Select all
   canvas.parsesvg(deviationImageGroup, "/home/user/fgfs-addons/LandingChallenge/gui/images/threshold-deviation.svg");

The path was cop&pasted from my file browser. What could I have possibly done wrong ???
EDIT:
In case it matters, here is the content of the SVG image I'm trying to show:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg version="1.1" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
   <g id="runway" transform="matrix(1.16 0 0 1 -5.81 .00391)">
      <rect id="asphalt" x="5" width="55" height="64" fill="#070707"/>
      <path id="centerline" d="m32.5 0v64" fill="none" stroke="#fff" stroke-dasharray="6, 6"/>
   </g>
   <g id="airplane" transform="matrix(.728 0 0 .794 8.34 6.6)" fill="#fff">
      <ellipse id="body" cx="32.5" cy="32" rx="3" ry="13.5"/>
      <rect id="elevator" x="23" y="42" width="19" height="3"/>
      <rect id="wings" x="11" y="27" width="43" height="6"/>
   </g>
</svg>
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Why does parsesvg not find an SVG file that is there ?

Postby ludomotico » Fri Aug 27, 2021 9:29 pm

I'm not entirely sure, but I believe this is related to this message I posted yesterday:

ludomotico wrote in Thu Aug 26, 2021 1:39 pm:The last versions of FlightGear do have mechanisms in place to prevent this, namely "it cannot read or write data out of certain directories", which sometimes causes confusion and bug reports.


For security reasons, FlightGear only allows reading and writing files to/from some directories. It might be your issue here.

- try not using absolute paths, but relative to the .nas file or its subdirectories, do not try to go to the parent directory using "..":
- load a path relative to the .nas file: "gui/images/threshold-deviation.svg"
- move threshold-deviation.svg next to the .nas file and load "threshold-deviation.svg"

If this does not work, remember Linux is case sensitive. Check that the file does exists using "ls /home/user/fgfs-addons/LandingChallenge/gui/images/threshold-deviation.svg" in a console.
User avatar
ludomotico
 
Posts: 1269
Joined: Tue Apr 24, 2012 2:01 pm
Version: nightly
OS: Windows 10

Re: Why does parsesvg not find an SVG file that is there ?

Postby TheEagle » Fri Aug 27, 2021 9:51 pm

As I told you, the path has the right cases, it was copy pasted from the file manager.

I tried setting the image path to "gui/images/threshold-deviation.svg", and "threshold-deviation.svg". After the latter I copied that SVG file to the directory the Nasal file is in and to the working directory. Neither helped. The weirdest thing is that in another Nasal file in the same directory I am using a PNG icon, and that loads fine.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Why does parsesvg not find an SVG file that is there ?

Postby Hooray » Fri Aug 27, 2021 11:15 pm

ludomotico is correct; Nasal I/O goes through an extra security layer (previously via IORules, now hard-coded) - PNG files are loaded by OSG itself (libpng), so don't go through this Nasal layer.
So it's worth keeping in mind that the FlightGear Canvas does not have native SVG handling support, instead it will use a parser implemented in NAsal (svg.nas), you can open that file to see for yourself.

In other words, it expects a path in the form of /Nasal/canvas/map/Images/boeingAirplane.svg

Speaking in general and looking at your recent postings, maybe it might make sense to work through some tutorials/code snippets before continuing with the addon ? :wink:
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: Why does parsesvg not find an SVG file that is there ?

Postby TheEagle » Fri Aug 27, 2021 11:30 pm

Hooray wrote in Fri Aug 27, 2021 11:15 pm:In other words, it expects a path in the form of /Nasal/canvas/map/Images/boeingAirplane.svg

Wait, are you telling me that if the plugin path is /home/user/fgfs-addons/LandingChallenge, and the icon is located at /home/user//fgfs-addons/LandingChallenge/gui/images/threshold-deviation.svg, I have to specify /gui/images/threshold-deviation.svg as the icon's path ?? :shock:

Hooray wrote in Fri Aug 27, 2021 11:15 pm:Speaking in general and looking at your recent postings, maybe it might make sense to work through some tutorials/code snippets before continuing with the addon ? :wink:

You can believe me, I spent at least 20 hours reading API description's, code snippets, howtos and forum threads all about Canvas and Nasal - yet I did not stumble upon this :x IMHO your wiki is at least partly a mess. Half of the pages' content are quotes from the forum, some is outdated, some is missing completely … Sometimes, the best / only source for information on FlightGear is it's source code … Like that, it's easy to miss such things and bother you with basic noobs questions.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Why does parsesvg not find an SVG file that is there ?

Postby Hooray » Sat Aug 28, 2021 8:17 am

no, when you open svg.nas you'll see that it's using the resolvepath() API - which in turn means, it expects/supports a file/path relative to the addon's location: https://sourceforge.net/p/flightgear/fg ... as/svg.nas

https://wiki.flightgear.org/Nasal_libra ... path.28.29
https://wiki.flightgear.org/Resolving_Paths
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: Why does parsesvg not find an SVG file that is there ?

Postby TheEagle » Sat Aug 28, 2021 12:22 pm

Sorry for still bothering you, but - I just cannot seem to find the right path. I tried "/gui/images/threshold-deviation.svg", "gui/images/threshold-deviation.svg", "LandingChallenge/gui/images/threshold-deviation.svg", "/LandingChallenge/gui/images/threshold-deviation.svg" - none worked. If I look at an aircraft like the extra500, "/gui/images/threshold-deviation.svg" should work but it doesn't. Please just tell me the right path for accessing that icon, because, I can't find it … !
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Why does parsesvg not find an SVG file that is there ?

Postby Hooray » Sat Aug 28, 2021 12:36 pm

That looks right to me - but for resolvepath() to work for addons, you also need to start fgfs with the corresponding addon - so that the addon's folder can be added to the list paths to be searched, how are you starting fgfs and how are you testing/starting your addon ?
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: Why does parsesvg not find an SVG file that is there ?

Postby TheEagle » Sat Aug 28, 2021 12:47 pm

I am starting fgfs using the --launcher command line option. There in the launcher, I have added the folder "/home/user/fgfs-addons/LandingChallenge" to the list of addons, and I have also ensured that the entry is enabled. Then I click Fly, wait for FG to load. Then I go to the addon's menu entry and click "Debug show data dialog". This menu entry is associated with an fgcommand "show-landing-data-dialog", which is set to the function "showLandingDataDialog". And inside that function, I have
Code: Select all
canvas.parsesvg(deviationImageGroup, "gui/images/threshold-deviation.svg");

And from there I get
Code: Select all
  675.20 [ALRT]:nasal      Nasal runtime error: File not found: gui/images/threshold-deviation.svg
  675.20 [ALRT]:nasal        at /home/user/fgdata-2020.4.0/Nasal/canvas/svg.nas, line 23
  675.20 [ALRT]:nasal        called from: /home/user/fgfs-addons/LandingChallenge/dataDialog.nas, line 16

The location of the icon is "/home/user/fgfs-addons/LandingChallenge/gui/images/threshold-deviation.svg".
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Why does parsesvg not find an SVG file that is there ?

Postby TheEagle » Sat Aug 28, 2021 1:00 pm

Actually I've gotten somewhere after reading $FG_ROOT/Docs/Readme.addons - I renamed the LandingChallenge folder to the ID of the addon (org.flightgear.addons.landing-challenge) (it looks like this is not even necessary) changed the path to "[addon=org.flightgear.addons.landing-challenge]gui/images/threshold-deviation.svg", and now parsesvg finds the file. But I'm getting another error now :x :
Code: Select all
  655.31 [ALRT]:nasal      parsesvg: parse XML failed [path='/home/user/fgfs-addons/org.flightgear.addons.landing-challenge/gui/images/threshold-deviation.svg']
  655.31 [INFO]:nasal      non-objects have no members:
 at /home/user/fgdata-2020.4.0/Nasal/canvas/svg.nas, line 35
  655.31 [INFO]:nasal        called from: /home/user/fgdata-2020.4.0/Nasal/canvas/svg.nas, line 490
  655.31 [INFO]:nasal        called from: /home/user/fgdata-2020.4.0/Nasal/canvas/svg.nas, line 748
Last edited by TheEagle on Sat Aug 28, 2021 1:22 pm, edited 1 time in total.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Why does parsesvg not find an SVG file that is there ?  

Postby TheEagle » Sat Aug 28, 2021 1:03 pm

ARGH :evil: :x - that sneaky Inkscape SVG optimizer removed an "y='0'" from a rectangle ! I added that by hand, and now it works ! Thank you very much for all the help ! :D
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Why does parsesvg not find an SVG file that is there ?

Postby Hooray » Sat Aug 28, 2021 1:21 pm

Yes, our SVG parser is extremely basic - but it can be easily extended in Nasal space: https://wiki.flightgear.org/Howto:Exten ... SVG_module

If you don't need to manipulate the SVG image after rendering it, there is a better/faster -and much more complete alternative available- via OSG (no recompilation needed, this works transparently via the OSG DB plugins mechanism):

SVG parser performance (from Cessna C182T)

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: Why does parsesvg not find an SVG file that is there ?

Postby TheEagle » Sat Aug 28, 2021 1:23 pm

Hooray wrote in Sat Aug 28, 2021 1:21 pm:If you don't need to manipulate the SVG image after rendering it

I do need to move and rotate one of the objects ! But not change the SVG.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Why does parsesvg not find an SVG file that is there ?

Postby Hooray » Sat Aug 28, 2021 1:36 pm

librsvg is only relevant for complex SVGs, i.e. stuff that takes long to parse/process due to Nasal being slow/interpreted and due to it running in the main loop/thread.
librsvg is used by OSG using an OSG background thread, which is why it's blazingly fast to even load complex vector images.

In the case where you need to reference/manipulate single elements, it's best to load/treat them separately, so that you can get a handle to the parent matrix transform - like you can see in the original topic, Stuart and James agreed that fixing up svg.nas in scripting space seemed preferable over using librsvg:

SVG parser performance (from Cessna C182T)
stuart wrote:I had a quick chat with James about this. We suspect just shifting more of the svg.nas code into C++ would provide good enough "bang for the buck" to improve the load time without needing anything more complicated.

However this isn't something either of us see as a priority right now (WS3.0 and various other things being higher priority), so we're not going to spend any time investigating further or implementing an improvement. If anyone is interested, they would be welcome to submit a patch.

I also suspect that 15s compares favourably to the startup time for a G1000 :)

-Stuart
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: Why does parsesvg not find an SVG file that is there ?

Postby TheEagle » Sat Aug 28, 2021 2:17 pm

Yeah, I'll stay with the Nasal loader then - I've got to load only 6 very simple SVG elements ! But - I cannot find a way to show them in a HBoxLayout - do you know how to do that ? I looked through the FG1000 nasal code, but that didn't really help. I am loading my SVG icon into a group called "deviationImageGroup". I want to add that to the deviationBox (a VBoxLayout), which in turn gets added to orientationPositionBox, which is added to rootBox which is then set as a layout to the dialog. This is the code:
Code: Select all
var showLandingDataDialog = func() {
   var dialog = canvas.Window.new([1024, 512], "dialog").setTitle("Landing data");
   var dialogCanvas = dialog.getCanvas(1).set("background", "#ffffff");
   var rootGroup = dialogCanvas.createGroup();
   var rootBox = canvas.VBoxLayout.new();
   rootBox.setContentsMargin(10);
   dialog.setLayout(rootBox);
   
   orientationPositionLabel = canvas.gui.widgets.Label.new(rootGroup, canvas.style, {wordWrap: 1}).setText("Orientation and Position");
   rootBox.addItem(orientationPositionLabel);
   
   orientationPositionBox = canvas.HBoxLayout.new();
   orientationPositionBox.setContentsMargin(10);
   
   deviationBox = canvas.VBoxLayout.new();
   deviationImageGroup = rootGroup.createChild("group");
   canvas.parsesvg(deviationImageGroup, "[addon=org.flightgear.addons.landing-challenge]gui/images/threshold-deviation.svg");
   deviationImageGroup.setVisible(1);
   orientationPositionBox.addItem(deviationBox);
   
   rootBox.addItem(orientationPositionBox);
}

What am I missing ?
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Next

Return to Canvas

Who is online

Users browsing this forum: No registered users and 7 guests