Cruisers Forum
 

Go Back   Cruisers & Sailing Forums > Seamanship, Navigation & Boat Handling > OpenCPN
Cruiser Wiki Click Here to Login
Register Vendors FAQ Community Calendar Today's Posts Log in

Reply
  This discussion is proudly sponsored by:
Please support our sponsors and let them know you heard about their products on Cruisers Forums. Advertise Here
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 22-01-2024, 11:49   #1
Registered User

Join Date: Jan 2024
Posts: 4
External Drawing API? - Beginner to Plugins Intro

Hello All!

I'll introduce myself as someone who regularly uses this forum (and OpenCPN) in my sailing life and have found it to be an immensely valuable resource. In another world, I am involved as an engineer at a non-profit and am currently working on a project with the goal of reducing conflict between local fisheries and the endangered North Atlantic Right Whales. My technical background is mostly in embedded systems, linux, and python. I'm a little bit out of my element in this large C++ desktop application, especially pertaining to the plugin architecture.

I thought I would reach out to the knowledgeable and supportive community here to get pointed in the right direction.

What I am trying to do is relatively simple. I'd like to be able to draw some objects automatically on the chart. For now, it looks like the features of OpenCPN Draw should meet my initial requirements.
1. Draw polygonal zones on the map
2. Draw points connected by line segments
3. Remove or move either of the above

If I have a program that decides what objects need to be drawn and when, what is the easiest way to integrate with OpenCPN? Here are some ideas I have:
1. Generate a GPX file, load into OpenCPN (this currently appears to require user intervention to refresh which is not desirable)
2. Write or modify a plugin to accept a socket connection from my program and handle drawing and managing the objects in OpenCPN
3. Does Open CPN already support some kind of interprocess communication that could achieve this? Are there NMEA or SignalK messages I could commandeer for this purpose?

If I go down the plugin path, what are the communities thoughts about having a plugin that simply exposes the ODAPI over a socket connection to external processes? From my perspective, it would be great for me to be able to have my Python app just send a few JSON messages in order to manipulate objects on the chart plotter. Perhaps this could be useful for other people? I know a lot of peripherals already communicate over defined message interfaces such as NMEA0183, NMEA2000, or SignalK. This could provide an interface for prototyping or more experimental applications without needing to define new messages in those interfaces.

I would be grateful to any of the gurus on here if they could point me to a particular entry point or relevant examples in the source code.

Thanks!
eubalaena is offline   Reply With Quote
Old 22-01-2024, 12:41   #2
Registered User

Join Date: Feb 2010
Location: Tierra del Fuego
Boat: Phantom 19
Posts: 6,212
Re: External Drawing API? - Beginner to Plugins Intro

Doesn't https://github.com/jongough/ocpn_draw_pi already do everything you need except providing the socket? You can have a look at https://github.com/jongough/testplugin_pi to see how it manipulates the Draw plugin's objects externally, exposing a socket that would relay the JSON messages from and to the OpenCPN's plugin API is a few line of code job then.

If your answer to the above is "not good enough", we can have a look at what exactly is missing to cover your usecase and how to do it.
nohal is offline   Reply With Quote
Old 22-01-2024, 13:05   #3
Registered User

Join Date: Jan 2024
Posts: 4
Re: External Drawing API? - Beginner to Plugins Intro

Quote:
Originally Posted by nohal View Post
Doesn't https://github.com/jongough/ocpn_draw_pi already do everything you need except providing the socket? You can have a look at https://github.com/jongough/testplugin_pi to see how it manipulates the Draw plugin's objects externally, exposing a socket that would relay the JSON messages from and to the OpenCPN's plugin API is a few line of code job then.

If your answer to the above is "not good enough", we can have a look at what exactly is missing to cover your usecase and how to do it.
Yes, it essentially does. As you say, exposing the socket is just a few lines of code. I am just trying to get familiar enough with the project to be able to write them and compile and include the minimal plugin.

Thanks, I'll take a look at testplugin_pi as a starting point.
eubalaena is offline   Reply With Quote
Old 22-01-2024, 13:13   #4
Registered User

Join Date: Feb 2010
Location: Tierra del Fuego
Boat: Phantom 19
Posts: 6,212
Re: External Drawing API? - Beginner to Plugins Intro

Basically all you need to do except creating the socket is to hook up to https://github.com/OpenCPN/OpenCPN/b..._plugin.h#L466 to receive messsages from the API to relay over the socket and call https://github.com/OpenCPN/OpenCPN/b..._plugin.h#L772 when you want to send one that you received from the outside over it.
nohal is offline   Reply With Quote
Old 23-01-2024, 02:43   #5
Registered User

Join Date: May 2012
Posts: 1,207
Re: External Drawing API? - Beginner to Plugins Intro

Quote:
Originally Posted by eubalaena View Post
Hello All!
working on a project with the goal of reducing conflict between local fisheries and the endangered North Atlantic Right Whales.
https://github.com/cynsky/ais-areano..._imo_001_22.py

Have you thought of generating an AIS area notice? OpenCPN is able to read these directly.
Rasbats is offline   Reply With Quote
Old 03-03-2024, 19:47   #6
Registered User

Join Date: Jan 2024
Posts: 4
Re: External Drawing API? - Beginner to Plugins Intro

Quote:
Originally Posted by Rasbats View Post
https://github.com/cynsky/ais-areano..._imo_001_22.py

Have you thought of generating an AIS area notice? OpenCPN is able to read these directly.
So I've finally had a chance to mess around with this again and took a look at this approach. Only the circle areas appear to be working for me. I've tried digging through the OpenCPN code and haven't yet been able to verify whether the lines or rectangles should be working. It very well could be an error on my end in generating the messages.

Do you have any personal experience using either the rectangle or polyline area notices?
eubalaena is offline   Reply With Quote
Old 04-03-2024, 02:45   #7
Registered User

Join Date: May 2012
Posts: 1,207
Re: External Drawing API? - Beginner to Plugins Intro

eubalaena ...

You are correct. Only the circle is working in OpenCPN 5.8.4. My PR has been accepted for 5.9.x which draws a rectangular area notice.

https://github.com/OpenCPN/OpenCPN/pull/3656

The PR contains a VDR file for testing rectangles.

Work is still needed for lines and polygons.

If you could PM me with your email address I can send a link to a recent Windows build of OpenCPN 5.9.x that can demonstrate a rectangular area notice.

Mike
Rasbats is offline   Reply With Quote
Old 04-03-2024, 04:19   #8
Registered User

Join Date: May 2012
Posts: 1,207
Re: External Drawing API? - Beginner to Plugins Intro

eubalaena ...

Wrong - polygons are working in both OpenCPN 5.8.4 and OpenCPN 5.9.x.

Remove the .pdf from the attached for a file to use with VDR_pi.

The polygon starts at 54.5N, 4.25E.

Mike
Attached Files
File Type: pdf ais8_1_22_polygon.txt.pdf (2.0 KB, 10 views)
Rasbats is offline   Reply With Quote
Old 04-03-2024, 05:59   #9
Registered User

Join Date: Feb 2010
Location: Tierra del Fuego
Boat: Phantom 19
Posts: 6,212
Re: External Drawing API? - Beginner to Plugins Intro

One note to this. The area notices are a mess as there is documentation and samples for both the in-force 8/1/22 IMO format (https://www.e-navigation.nl/content/area-notice-0) and deprecated 8/366/22 US format (https://www.e-navigation.nl/content/area-notice-1)

OpenCPN supports only the former.
nohal is offline   Reply With Quote
Old 04-03-2024, 06:03   #10
Registered User

Join Date: Jan 2024
Posts: 4
Re: External Drawing API? - Beginner to Plugins Intro

Thank you for your help with this. Your polygon example indeed works with my copy of 5.8.4

I'll make sure I can also generate working AIVDM messages for the polygons.

If I'm understanding the code here correctly: https://github.com/OpenCPN/OpenCPN/b...c/ais.cpp#L361

The polyline option does not appear to draw anything in itself but is used in conjunction with the polygon to draw the polygon. Is that correct? I had thought maybe I could use it to draw a line. But that isn't necessary. A polygon or rectangle are equally suitable.
eubalaena is offline   Reply With Quote
Old 05-03-2024, 02:36   #11
Registered User

Join Date: May 2012
Posts: 1,207
Re: External Drawing API? - Beginner to Plugins Intro

Quote:
Originally Posted by eubalaena View Post
The polyline option does not appear to draw anything in itself but is used in conjunction with the polygon to draw the polygon. Is that correct?
No ... the polyline is a separate type within ais8_1_22 (sub-area type 3). With this your lines can be drawn.

We have been updating the base code for 5.9.x to cater for this and add the sector type (2) as well.

Mike
Rasbats is offline   Reply With Quote
Reply

Tags
plug, plugin


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
external chainplates - external hex key bolt heads? theller Construction, Maintenance & Refit 2 05-08-2022 05:27
Map API - WMS Support? moyd OpenCPN 15 17-01-2017 07:16
Technical: API to query heading(s)? bushtor OpenCPN 4 03-06-2013 07:38
Installateur de plugins, Install software for plugins. Gilletarom OpenCPN 3 30-04-2013 05:57
Plugin api coding rooiedirk OpenCPN 6 03-04-2013 08:49

Advertise Here


All times are GMT -7. The time now is 08:16.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.