Board index FlightGear Development Canvas

Custom MapStructure widget FLTSink not displaying

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.

Custom MapStructure widget FLTSink not displaying

Postby benih » Fri Jun 04, 2021 11:28 am

Hello, i struggle with the MapStructure API.

Background/Context:
as follow-up on the Thermal spawning, ridge wind and weather configuration thread discussing soaring and learning to fly thermals, I fiddled around with Nasal and the Canvas Map API to create a simple moving map, showing the experienced sinkrate as a color-coded plotted flight path on the map.

This way, so the basic idea, the glider pilot can explore the thermal he is in, but it's not outright cheaty because we only use real information available to the pilot at hand.
But, it would greatly help in detecting where the different downdrafts/thermal updrafts are located, and helps centering them. Mots importantly (to me), it provides visual information on the various thermal sizes, so I can play around with how weather settings affect them. Finally it may prove useful as debugging tool when developing things regarding/affecting the weather system.

The sinkrate visualizers code is public at github: https://github.com/hbeni/fgfs-sinkrateVisualizer (and nonfunctional as of commit 228bdf7666)

The Problems:
1. Recoloring the line segments and faster update this
The current code (228bdf7666) successfully opens a map, and seems to also load the custom modules.
But the custom FLTsink widget does not display anything. If I change the loaded widget back to the default FLT one, the flight path displays.
I changed my widgets color to random, and it shows. however the update rate is so slow, it seems to be depending on the distance, and the color stays the same for all segments.
This leaves me with two problems:
a) how can I ramp up the update rate?
b) how can I dynamically recolor the legs based on some property (the recoloring-segments is the problem, not to get the values-mappings)?

I assume a problem somewhere in the widgets code, or it's initialization; shortly speaking, I think the problem is my lack of understanding of the MapStructure API somewhere.
The current FLTSink module is expected to behave exactly the same as the copy-sourced FLT one, which i wanted to use as a starter to get me going.
How can i get this to be working? And what do i need to do in order to change the color of the plotted segments (i suspect this is something the FLTSink.symbol needs to define, but how?)?

2.Changing GRID styling / spacing of cell lat/lon lines
I just added a GRID layer, so we see the Map is actually moving. But how can i change the grid cell size?

I already wrote complex stuff in nasal, and have a programming background, if that matters.
User avatar
benih
 
Posts: 1679
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Custom MapStructure widget FLTSink not displaying

Postby Hooray » Fri Jun 04, 2021 2:46 pm

To be honest, it's been a few years since we came up with that code, so off the top of my heads some comments:

- I would suggest to always look at related layers, i.e. layers that have similar functionality and then "harvest" useful code there (like you did already with the flight path/leg layer)
- sometimes different layers have different parts of code that may come in handy
- it may help to run "grep" to search for useful bits
- for instance, the flight path layer (FLT) is using the history() API currently and it needs to use an aircraft's position - so it's using something like "aircraftpos.controller" in $FG_ROOT/Nasal/canvas/map
- this is yet another layer of abstraction, basically this encapsulates all related calls - that way, it's possible to use a different positional source (for instance, MapStructure maps/layers are designed to work with arbitrary position sources, including MP/AI traffic but also instant replay) - that way it's possible to easily debug/stress test MapStructure layers, for instance by hooking up a map (or even a full ND) to an existing AI/MP node in the property tree (think AI traffic like the tanker or an actual MP pilot flying at any given moment in time)
- we used this extensively during development of the framework, because we needed a way to easily iterate, without having to startup an aircraft or perform takeoffs and landings etc
- there may be remaining hard-coded getprop() calls referring to /position in some layers - but in general, these are intended to be replaced by the code in aircraftpos.controller - it's a simple hash actually.
- there you will also find hard-coded assumptions about layers that must be updated permanently or "quickly" - this is a vector of layer names that are regularly updated, i.e. that don't update based on some condition (like the other layers)
- look specifically for this:
Code: Select all
# Layers which get updated every frame
var update_instant = [
        "APS",
];
# Update at a slightly lower rate, but still
# unconditionally
var update_quickly = [
        "TFC", "FLT",
];



Basically this file contains the highest level logic to control a map and its associated layers and MVC components.

Note however, this all predates the addon framework, so we don't currently have an API to append new layers to the controller.
But that should be fairly easy to add (and it would be a good idea too).

Speaking in general your code is really looking good, and I am looking forward to seeing your layer in action.
Please do keep us posted, and do feel free to add your addon/MapStructure layer to the newsletter or the list of MapStructure layers.

As a matter of fact, it would actually be cool to see a dedicated tutorial about creating new MapStructure layers like this one from scratch, that also goes into the details that we omitted when we wrote the original docs (several years ago!).

Before I forget it, to recolor individual legs, you either need to keep a vector of active legs (as canvas elements/objects) or use a dedicated "symbol controller", I think you could implement this by using a "Model" wrapper (MVC) to keep track of all your legs (one leg per model) and then you can implement custom heuristics for coloring/recoloring or styling in general.
I don't remember if we have animated symbols in the main repo or not - but basically, it's the same method: keep track of the canvas element (path element) that resembles a leg, and then hook it up to some heuristic to apply a color palette. We had this working long ago, including blinking symbols and symbols that would permanently scale up/down - but I believe that might have been one of those prototype layers rather than something useful enough to get committed to the official repo (?)

I also think that there are other addon developers that might be interested in learning how to use MapStructure to add custom functionality.

For instance, ThomasS created the "GroundServices" addon that adds a dedicated layer for ground networks - so that might be another useful piece of code to look at.

And please feel free to get in touch if there are remaining questions or if this answer isn't yet addressing all your questions.

I am not sure if you have fgdata commit access or not, but if you find that some stuff in MapStructure.nas needs to be extended for your use-case, I'd suggest to reach out to Stuart (developer of the FG1000 and pretty familiar with MapStructure) or Richard (also familiar with the code) - alternatively, look up who's recently been making canvas related fgdata additions to $FG_ROOT/Nasal/canvas via "git log" to find an active maintainer (jsb would seem like another potential candidate to help with getting changes integrated).


PS: In GRID.lcontroller (written by Stuart IIRC) you should find a hash called df_options (for default options) that should contain stuff that can be overridden by passing different options (e.g. granularity of the GRID)
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: Custom MapStructure widget FLTSink not displaying

Postby benih » Fri Jun 04, 2021 4:24 pm

Hi and thanks for the bits!
That’s much too chew on, so please be patient for my responses.

For the howto idea: in the wiki there is already such a thing, describing the tutorials markers, and that helped me to get to where i am now.

For the GRID reference i already have seen the options, but found no way how to override them (even trying to set it directly into the hash did not work, so i assume i did not do it correctly - help much apprechiated)
User avatar
benih
 
Posts: 1679
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Custom MapStructure widget FLTSink not displaying

Postby Hooray » Sun Jun 06, 2021 2:57 pm

Again, the short answer is: Take a look at $FG_ROOT/Nasal/canvas/map/aircraftpos.controller

That file hold the top-level management routines for most maps, i.e. how to get the current position etc

For the time being (well for a number of years now), this also contains heuristics that determine how some of the more special layers are to be updated (frequency).

To take a brief look, see: https://sourceforge.net/p/flightgear/fg ... controller

Once you add your own layers to that file, everything should work properly.

However, like I said, when we came up with that code, the addon framework didn't yet exist - and the use-case you're exploring currently is a new one, which is to say: we probably don't have an API currently to access such internals. While you could append() your layers to the corresponding vectors, my suggestion would be to add corresponding helper functions to do exactly that, and get those committed by someone familiar with Canvas/MapStructure (e.g. Stuart or Richard)

At that point, addons should be able to more easily register new MapStructures layers. Even though, like I said, my suggestion/preference would be to eventually get useful layers merged back into the main repository, so that other aircraft/addons can use such work, without requiring separate addons to be downloaded/installed and activated. Then again, for prototyping purposes, the use-case is certainly perfectly valid.
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: Custom MapStructure widget FLTSink not displaying

Postby benih » Sun Jun 06, 2021 3:54 pm

Thank you very much hooray!
I will explore that.

And maybe when starting fiddling with the core, it might even be easier, if we just add styling options to the existing FLT layer, with the possibility to let it be aware of a callback for the coloring…

I will report back, but this will surely take some time for me to learn.
User avatar
benih
 
Posts: 1679
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Custom MapStructure widget FLTSink not displaying

Postby Hooray » Sun Jun 06, 2021 4:10 pm

right, that's exactly how the current design evolved originally: First we coded up something functional, and then we looked at different use-cases and their requirements. At that point, we turned everything that needed to be flexible into a variable, or a hash (for multiple variables) or a function (delegate) or a class - so that calling code can pass in its own settings to override our defaults.

So your idea is really good and perfectly in line with how we originally MapStructure to be adopted and used/extended by people over time.
We didn't quire foresee that people would "copy" layers into their own aircraft and customize those instead - while we cannot stop people from doing so, that's against our own goals for the framework and for how it could be extended over time, so that all end-users would automatically benefit from enhancements to the framework.

For instance, you said you have a coding background: MapStructure uses a handful of abstraction mechanisms to encapsulate (hide) stuff - that makes it sometimes a bit tedious to access the framework, but at the same time, it's much easier for fgdata developers or core developers to easily improve/optimize MapStructure, while aircraft (or dialogs) using it, would not even need to be aware of such improvements.

For example, let's suppose the FIX layer is too slow (too many targets to display) - given the way MapStructure is structured, we could re-implement portions of it in C++ space and front-end code (e.g. a ND) would not even need to be updated. This happened in fact: we took a Nasal routine and ported it to C++ to benefit from better performance, and all aircraft using MapStructure benefited automatically.

At the time, our goal was also to encourage wider/better collaboration among people working on different aircraft, who often didn't realize that they had shared/overlapping work and requirements ahead. Back then, one of the best developed cockpits was developed solely for the Extra500 - and it contained awesome MFDs/avionics, but the corresponding developers stated on several occasions that their code wasn't sufficiently generic to be reused elsewhere, despite other developers wanting such functionality too - often with different styling/behavior or appearance.

But again, while MapStructure is part of fgdata, it's not generally considered a "core" component at all - you can make improvements/fixes and get those reviewed/committed without having to touch any C++ code.

Adding support for a coloring-callback should not be too difficult - not sure if you have looked at the "MapStructure" article on the wiki, but it should have a section or two on "symbol controllers". Again, most of this was harvested from several places and discussions several years ago, and I believe we wrote most of the code over 5 years ago, so I still find myself looking at the wiki every now and then to read up on how this stuff works (despite having written quite a bit of it originally).

Either way, if you cannot reach Stuart or Richard to take a look, I'd suggest to reach out to jsb, who's been doing most Canvas related work recently.
And even if you do have commit access already, it's a good idea to get your changes reviewed/tested by others using the framework, in order not to break things.

One thing I used to do at some point was adding a combo box to a PUI dialog to test different MapStructure layers more easily - since adding more and more checkboxes for ALL layers makes the map dialog rather bloated:

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: Custom MapStructure widget FLTSink not displaying

Postby benih » Mon Jun 07, 2021 2:45 pm

Ooof i think i need to give up.
I managed to recolor the entire path for every update, but somehow i don't have access to the "next" segment.
The entire path seems to be redrawn with each update, and for some reason it takes the color of the last statement.

And still the updates are way too slow (despite overloading TestMap.update_quickly = ["FLTsink"];).

I assume i need to focus on other things more to my nature...
User avatar
benih
 
Posts: 1679
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Custom MapStructure widget FLTSink not displaying

Postby Hooray » Mon Jun 07, 2021 6:17 pm

And still the updates are way too slow (despite overloading TestMap.update_quickly = ["FLTsink"];).


I don't think that is doing what you think it is doing, i.e. is this having an effect at all ?

update_quickly would be a member of the controller object of the map as far as I can tell.

Again, it might be better to approach this step by step, i.e. by editing aircraftpos.controller directly and then take it from there.

Regarding next vs last statement, that sounds like it's either an off-by-one error or simply due to being processed in a different frame than you think ?

Like I said, last I checked, your code was looking pretty good actually.

I think the setController() implementation is now to be found in $FG_ROOT/Nasal/canvas/api/map.nas - I believe that was part of some refactoring that jsb completed a while ago
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: Custom MapStructure widget FLTSink not displaying

Postby Hooray » Tue Jun 08, 2021 6:26 pm

Ok, I took another look at the FLT layer that you're using as a template - given your requirements of 1) using different colors for different segments and 2) running heuristics to determine straight & level/climb/sink, I would suggest to modify the FLT.lcontroller file and add your heuristics to the searchCmd function:

This will invoke the append() method to append new legs to the vector - and that is also where you can add optional meta information to each model (hash).

For starters, you could randomize the color there and modify the append() method to handle the coloring or run the heuristics.

For the heuristics (per model) you could accept a "colorization" callback that processes the corresponding legs.
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: Custom MapStructure widget FLTSink not displaying

Postby benih » Tue Jun 08, 2021 7:44 pm

This i already tried, with the result of the entire path being drawn in a new random color :(
User avatar
benih
 
Posts: 1679
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Custom MapStructure widget FLTSink not displaying

Postby Hooray » Tue Jun 08, 2021 8:00 pm

I think your code is fine, there might still be a misconception about Canvas.Path/OpenVG color handling - I would suggest to re-run your code, keep everything running/open and then open the property tree browser, navigate to the corresponding path element of your canvas map - and then copy the Canvas Path instruction, it's probably using the same color for all segments.

I haven't tried this, but we probably need to restore/clear the color - i.e. assuming OpenVG works like an OpenGL "state" (machine), the next segment will continue to be drawn using the previously selected color.

Inspecting/copying the path instruction from the property tree (or printing that to the console) should enable you to look at what your code is telling the Canvas to draw.
There are web based OpenVG debuggers available - once you have figured out how to draw a line with segments using different colors, we should also be able to adapt the FLT layer accordingly.

I believe some of the other layers may also contain helpful examples, your code looks pretty good to me - so I believe, this can only be a minor issue at this point.
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: Custom MapStructure widget FLTSink not displaying

Postby benih » Wed Jun 09, 2021 7:59 am

Thats good hints, i try to find something.
Uploading my mess to github :)
User avatar
benih
 
Posts: 1679
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Custom MapStructure widget FLTSink not displaying

Postby Hooray » Wed Jun 09, 2021 10:05 am

I usually take a look at an OpenVG reference/tutorial for some of the more sophisticated stuff - for instance, we're probably drawing a single line right now, which is probably not what we want once we want to deal with differently colored segments - e.g. referring to this (sounds familiar?):

https://community.khronos.org/t/how-to- ... olors/1692
Hey guys,

I am creating a path and drawing it n number of time by appending data to the same. i am calling vgDrawPath just once and cause of that all the line segments are of the same color. Is there a way to draw line segments of different colors and still use vgDrawPath just once?

Thanks
No. Use multiple paths (at least one per each color).
I suppose if your lines are in a very regular pattern and not touching, it might be possible to construct a linear gradient to color them differently, but I don’t see that scenario as likely.

Why are you determined to use only path anyways? It’s not like you’re saving any work to the display driver by submitting it all in one go.


In other words, your issue might be unrelated to Nasal and Canvas and has more to do with the way Canvas.Path/ShivaVG and specifically OpenVG works.
The current FLT layer was probably once implemented to create a single line using a single color, so has different requirements.

https://www.amanithvg.com/docs/tut/006-stroking.html
https://github.com/ileben/ShivaVG
* Paths:

vgCreatePath .......................... FULLY implemented
vgClearPath ........................... FULLY implemented
vgDestroyPath ......................... FULLY implemented
vgRemovePathCapabilities .............. FULLY implemented
vgGetPathCapabilities ................. FULLY implemented
vgAppendPath .......................... FULLY implemented
vgAppendPathData ...................... FULLY implemented
vgModifyPathCoords .................... FULLY implemented
vgTransformPath ....................... FULLY implemented
vgInterpolatePath ..................... FULLY implemented
vgPathLength .......................... NOT implemented
vgPointAlongPath ...................... NOT implemented
vgPathBounds .......................... FULLY implemented
vgPathTransformedBounds ............... FULLY implemented
vgDrawPath ............................ PARTIALLY implemented
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: Custom MapStructure widget FLTSink not displaying

Postby benih » Wed Jun 09, 2021 10:26 am

I could also imagine to just create a simple filled circle every second.
I just have no idea (yet) how to implement that, especially how to define that the update should run every second.
User avatar
benih
 
Posts: 1679
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Custom MapStructure widget FLTSink not displaying

Postby Hooray » Wed Jun 09, 2021 12:46 pm

right, I guess, this is the point where it makes sense to step back briefly and prototype the visuals using just a standalone GUI dialog, and once you have something that you are satisfied with, we can revisit porting that to come up with a corresponding MapStructure drawing routine (symbol file)

https://wiki.flightgear.org/Canvas_snip ... enVG_Paths
Image

(In the meantime it would also be great if you could help us by adding new examples to the "canvas snippets" article - no matter if you are going to use those for your FLTSink layer or not, you are undoubtedly going to experiment with different visuals)
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 2 guests