Board index FlightGear Development Canvas

Using a canvas map in the GUI

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.

Re: Using a canvas map in the GUI

Postby Hooray » Tue Sep 25, 2012 10:45 am

My own approach also is absolutely iterative, I am changing the design as I go, i.e. moving Nasal code from the XML dialog to the map.nas module etc. and copying/pasting and customizing things as needed.
All my design changes were based on refactoring the existing design and supporting additional use-cases.

BTW: I suggest not to review the merge request with the intention of merging it "as it" currently - just to look at the code from a design point of view, I have more changes here, and would rather push them first before you really want to review the code in order to commit it.

This is especially because my modified code is doing more than Stuart's original dialog, in that it shows multiple airports and also a navaid layer - which doesn't necessarily belong there, it was just intended to be a "proof of concept" - but this can now be easily disabled by removing a bunch of lines from an XML file that instantiates the map procedurally

Thus, I'd like to ask you not to start modifying the code until we have agreed on how to proceed, to avoid any wasted effort.
From my point of view, it would be great to just get feedback where we agree/disagree, so that I can provide a cleaned-up (and down-stripped) version to port Stuart's current dialog to the generalized design, so that all of us can work on different dialogs/instruments, and just implement workhorses as part of the underlying map.nas module.
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Using a canvas map in the GUI

Postby zakalawe » Thu Sep 27, 2012 9:19 am

I've had a look at the map code on Hooray's branch - it mostly seems fine (and maybe you have more to commit?), but the areas I have the most concern about, the MVC models (data providers), don't really exist yet, so it's hard to say. I don't feel I have enough experience of how this will evolve, to say if it's a good design or not yet.

So what's a sensible way to progress? I have some local mods to map.nas and the map dialog I could start to commit, but I'm avoiding that since it will create a merge problem. I think Stuart is doing the same. Hooray, do you have something ready to merge into fgdata, so we can continue hacking? I'm happy to keep working on code that will be thrown away, while i learn!
zakalawe
 
Posts: 1152
Joined: Sat Jul 19, 2008 4:48 pm
Location: Edinburgh, Scotland
Callsign: G-ZKLW
Version: next
OS: Mac

Re: Using a canvas map in the GUI

Postby Hooray » Thu Sep 27, 2012 10:33 am

Hi, thanks for taking a look at the code.
Yes, I do have more stuff here - in fact, some of the stuff that I pushed yesterday, wasn't meant to be pushed yet, because it contains some regressions at the moment.
So,I'd like to know, what version of the code you looked at - currently, I consider version #8 to be the most stable, #9 and #10 are currently work in progress.

Now regarding the code and its design, and I am also happy to throw away my code - really, there's nothing set in stone, I have been making all these modifications based on using the canvas in other dialogs, such as the route manager and Tom's original "map-canvas", which I have been adapting.
Eventually, I hope that these experiences will help us generalizing stuff and moving them to C++ space, where they should become a core part of the canvas system. From a performance point of view, that should definitely help us too - but for rapid prototyping, the Nasal code will at least help us come up with all requirements

I also don't want to prevent people from working on this, so after looking at my code: do you think you could merge/port your changes to use my code, or would you rather push your changes, so that I can do the merging?

Regarding the "Models" that you mentioned, yes - the Controller part is also just a stub currently, but I am filling in the details as I go, like you said earlier: iterating rapidly is the way to go here. However, obviously it would be great if I am not the only one who understands the Nasal code/design here, we already have some Nasal systems that are really only developed by a single developer, because nobody else can really understand how it's designed and how things "hang together" there - such as Thorsten's Advanced Weather system (been there, tried to do it...). So my primary focus is creating something that follows some basic coding standards and that is well-encapsulated, so that we don't need to read/understand all of the code to change something.

Now, if the intention is to merge something "soon", I'd suggest to look at version #8 of my merge request - but to see how I want to evolve things, take a look at #10, which is what I am currently working on, and which contains a first stab at implementing very basic "DataModels"/providers. For example, the "Navaids" data model experiment looks like this currently:

navaids.model:
Code: Select all
1       var NavaidModel = {};
2    NavaidModel.new = func make(LayerModel, NavaidModel);
3    NavaidModel.init = func {
4    var navaids = findNavaidsWithinRange(50);
5    foreach(var n; navaids)
6           me.push(n);
7    me.notifyView();
8   }


Just tell me if you think that you could merge in your changes into #8, or if you'd rather see me doing it here and pushing an updated merge request.
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Using a canvas map in the GUI

Postby Hooray » Thu Sep 27, 2012 3:04 pm

I am going to push an updated version that fixes some of the regressions that were introduced when I refactored things, it also fixes some things that Tom pointed out and helped me troubleshooting (thanks again!).

So that you can now have a look and see for yourself if you want to see this improved/merged or not.

Note that I am not at all "emotionally attached" to the code - I really don't mind throwing it out of the window once we have a better solution available.

However, for now, I want to come up with something that makes it easier for us to use the same backend code in different dialogs and instruments.
This code is an attempt at doing exactly that.

If we can come up with a consensus to review this and get it committed, I'll also volunteer to document the whole design once it stabilizes, so that people can easily create custom map layers. I have started doing that here: http://wiki.flightgear.org/Canvas_Map_API

For now, it would be important to me if you could check that the code doesn't break any existing behavior of the airport-selection dialog.
From a performance point of view, you'll probably appreciate that toggling features works now much faster than in the original code, because we don't re-draw each canvas group every time.

I have also started documenting a couple of things that we should better move to C++ space eventually, for the sake of performance - and because Nasal overhead may become pretty noticeable under certain circumstances - for details, you'll probably want to apply my "GooglePerfTools" patch and see for yourself how drawing is affected after Tom's latest optimizations, it uses an additional fgcommand to enable/disable the profiler for specific sections of the code.

Note that my latest version no longer draws just a single airport but all airports within a range of 10 nm - that's a simple change to revert, but Stuart mentioned that he was looking into this anyhow.

All that said, if you have anything that you'd like to see merged with this, please let me know, so that I can help you or do it myself.

Please find the updated code in the latest merge request (#11) and give it a thorough test, if you find any issues, let me know so that I can fix them.
EDIT: Version #11 is now pushed, so I'd ask Stuart and Zakalawe to provide feedback - but I'd also like to ask you NOT to merge/commit this before Tom has had a chance to look at the code and test things, because he's obviously the one most familiar with the Canvas system. We should only replace the current map.nas module once it has been extensively tested by all of us.

I have only briefly tested this using the c172p-canvas and doing 20 subsequent airport lookups in different places of the world:
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Using a canvas map in the GUI

Postby stuart » Thu Sep 27, 2012 10:04 pm

Hi Hooray,

I had a quick play with this before heading to bed after a days flying IRL, but didn't have the time to investigate anything further, look at the code, or review the APIs. A couple of quick things that jumped out at me:

1) Quite a few airports are no longer displayed. On my system the following come up blank: E46, OG00, 98GA, 7I6, 9M9. I've not been able to investigate why that is.
2) The airport dialog now displays all the airports visible in the view area. For this particular application I think that's overkill though obviously it's much more important for a moving map. I'd much prefer to display the selected airport as quickly and efficiently as possible, to keep the airport dialog responsive.
3) Moffett Federal AFLD (KNUQ) seems to take longer to display than it did before, though I haven't done a direct timing comparison. It always took a long time to display, during which FG hangs, but my perception is that it is slower than before. When I get the chance I'll double check it against the old code.

Apart from that, I think it looks good. I look forward to James/Tom adding panning function to the library so the airport dialog supports it withough any further coding :)

-Stuart
G-MWLX
User avatar
stuart
Moderator
 
Posts: 1469
Joined: Wed Nov 29, 2006 9:56 am
Location: Edinburgh
Callsign: G-MWLX

Re: Using a canvas map in the GUI

Postby Hooray » Thu Sep 27, 2012 10:16 pm

thanks for the feedback, will look into it!
EDIT: Regarding the airports you mentioned, I can confirm that they show up in the original dialog but won't show up currently - funnily, they do appear in the property tree in the right (and visible!) group ... puzzled - maybe the map isn't centered properly, will check!
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Using a canvas map in the GUI

Postby Hooray » Thu Sep 27, 2012 10:23 pm

Regarding KNUQ, there's benchmarking code which can be enabled by setting DEBUG=1 - IF it is even slower than before, that would suggest that the canvas groups come at a certain cost, I am using two more groups here (per airport!) than before (which was for debugging purposes, should be removed anyhow). That said, removing the groups and only showing a single airport, should speed up things again.

EDIT: lat/lon for the map's reference point are properly set up for the airports that don't show up, and their groups are also populated and visible ... :?:
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Using a canvas map in the GUI

Postby Hooray » Thu Sep 27, 2012 11:00 pm

Regarding KNUQ taxiways: That's also confirmed here: it was taking 2/3 more time than before (measured using systime() ), however it was also drawing 3 airports then (i.e. +2), including their taxiways at full detail - once I simplified the model to only return a single airport, and then the draw routine, to only use a single group, the time is identical now.
Overall, I agree with Zakalawe, that we need to look at using proper LOD here - so that such things shouldn't matter so much anymore


Still confused why 9M9 etc show up blank, even though the canvas tree does contain paths, is visible and properly centered.

EDIT:OKAY, found the BUG regarding 9M9 etc - it was a simple thing (in the model), but non-obvious ... related to using findAirportsWithinRange() (used to show multiple airports) which was NOT returning 9M9 when using 9M9 as the lookup position (which worked however fine when using KSFO etc)... removed the line and pushed a new version

So, we'll need at least two airport models then: single_airport and multiple_airports :D
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Using a canvas map in the GUI

Postby Hooray » Fri Sep 28, 2012 7:20 am

stuart wrote in Thu Sep 27, 2012 10:04 pm:I look forward to James/Tom adding panning function to the library so the airport dialog supports it withough any further coding :)


Actually, even with the current state of things, it's really trivial to support a simple form of panning - it's really just a handful of lines of Nasal. After all, you only need to call the setTranslation() method (or directly set the translation properties) and update the state with the values from texture/input/mouse-x and texture/input/mouse-y
I have that working here, in another branch, with 4 lines of Nasal

That said, it would probably make sense to support a more direct mode for maps, which could just as well expose a "repositioned" event, and then directly write the new lat/lon to the ref-lat/ref-lon properties
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Using a canvas map in the GUI

Postby stuart » Fri Sep 28, 2012 9:03 pm

Hi Hooray,

I pulled the latest version, and it looks much better - thanks!

I presume you are still waiting for Tom to review this before it's committed?

Once it's in, I've got a couple more features I want to add the dialog (none of which are canvas specific):
- A pop-up to display when searching for airports within 100nm. At present this is quite a slow operation, during which the sim is frozen. Should let users know that we're searching.
- A list of COM frequencies.

-Stuart
G-MWLX
User avatar
stuart
Moderator
 
Posts: 1469
Joined: Wed Nov 29, 2006 9:56 am
Location: Edinburgh
Callsign: G-MWLX

Re: Using a canvas map in the GUI

Postby Hooray » Fri Sep 28, 2012 11:29 pm

Actually, Tom already had a look yesterday and let me know that he didn't spot anything else. So, if nobody else (Zakalawe?) has found any regressions, I'd suggest to commit it now -- and I'll volunteer to handle any issues that may still arise, and handle porting/merging if you should need to revert anything.

That aside, the changes you list are not map.nas related, just dialog-specific, so they won't touch anything that we're working on.
In other words, please feel free to commit these changes now.
If you're facing open issues while working with the map.nas side of things now, let me know so that I can re-work the wiki docs to cover anything missing.

I assume most of us have some related local changes now, and the panning code could just as well be committted for now, until we have something better available

To port the map dialog/nav display, we'll need to add another airport model again, that provides more than just a single airport ... that's why I jus t commented out the relevant parts in the airports.model file

From my perspective, it would be perfect if all of us could now work on different dialogs and just augment/improve the map.nas module as necessary
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Using a canvas map in the GUI

Postby stuart » Sat Sep 29, 2012 8:21 pm

Hi Hooray,

This is now checked in. Thanks very much for your efforts here, and apologies for our misunderstanding earlier.

-Stuart
G-MWLX
User avatar
stuart
Moderator
 
Posts: 1469
Joined: Wed Nov 29, 2006 9:56 am
Location: Edinburgh
Callsign: G-MWLX

Re: Using a canvas map in the GUI

Postby Hooray » Sat Sep 29, 2012 8:23 pm

no problem, obviously we were all interested in making progress - we probably just weren't pulling into the same direction, so it's great that this has worked out now. So thanks for taking the time to clarify the situation ... it's telling that writing the code was probably less time-consuming than all the debating here ;-)

EDIT: Note that you didn't push the latest version of the merge request. Also, could you please uncomment the "map.cleanup_listeners" line in generic-canvas-map.xml?
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Using a canvas map in the GUI

Postby stuart » Sat Sep 29, 2012 10:12 pm

Hi Hooray,

As per my PM, my merging and you adding a new version crossed paths.

I've tried merging your latest version, but get errors on startup:

No such member: Path:
at /home/stuart/FlightGear/data/Nasal/canvas/map/taxiways.draw, line 1

I've tried changing the reference to canvas.Path (which IMO should be fine) to canvas.api.Path or api.Path without success.

-Stuart
G-MWLX
User avatar
stuart
Moderator
 
Posts: 1469
Joined: Wed Nov 29, 2006 9:56 am
Location: Edinburgh
Callsign: G-MWLX

Re: Using a canvas map in the GUI

Postby Hooray » Sat Sep 29, 2012 10:41 pm

You shouldn't need to modify anything, please see my updated merge request and check if this works for you or not, it's all rebased against origin/master now and works properly here.
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

PreviousNext

Return to Canvas

Who is online

Users browsing this forum: No registered users and 0 guests