antipole2 / JavaScript_pi

JavaScript plugin for OpenCPN
GNU General Public License v3.0
2 stars 4 forks source link

Idea: Create entry console into SignalK (for boat data and units) shared with other PI #65

Closed rgleason closed 5 months ago

rgleason commented 1 year ago
  1. Use a Javascript entry console to allow user entry (and changing) of essential boat data and unit preferences into a section of the signalK xml.
  2. Save that section of the SignalK xml uniquely named, to a single location in the opencpn support files.
  3. Provide access to this information by all plugins so enabled, via the API or some other means.
rgleason commented 1 year ago

FS#920 - UI UNITS Setting measurement units

Make the possibility of a global setting Units of measurement in OpenCPN. someone accustomed to use the metric system of measurement -

Distance: kilometers and meters, feet, yards, nautical miles, nautical miles and feet, nautical miles and yards, statute miles.
Spot soundings: feet, meters, fathoms.
Mast Height: meters, feet.
Speed​​: knots, kilometers per hour, miles per hour.
Bearing: Magnetic, true
Fuel: Gallons, Liters
Position: degrees minutes seconds, degrees and minutes, degrees.
Time: 12 hours, 24 hours
Date Format: YYYY-MM-DD or mm-dd-yyyy
Temperature: Fahrenheit, Celsius.
Wind speed: knots, kilometers per hour, meters per second.
Pressure: mBar, mmHg, Pa.
Current Velocity: knots, kilometers per hour, miles per hour.
Displacement: lbs, kg, short ton (2000lbs),  metric long ton (2240lb), etc.

Also NOTE: Related but separate OwnShip Settings FS#1102

Consider this note requesting Small distance units FS#2407

FS#1102 - UI Option Ship Tab Boat Data- Draft, Speed, Clearance, Displacement

Consolidated List -Parameters adjustable should be:

Name (from AIS, if available)
Clearance (aerial)
Draft (underwater)
Draft safety distance (from bottom of keel)
Beam
Overall length LOA -done
Waterline length
Displacement
Max Hull speed
Average Hull speed
Minimum Sailing speed (change to power)
Keel type [Full,Fin,Bulb,Canting]
GPS Position (from the bow and from centerline) -done
Radar Position & Height (from the bow and from centerline)
AIS Position & Height (from the bow and from centerline)
AIS standard ship shapes
AIS minimum size to show the 'custom shape' (to ensure a correct display of it) otherwise, display the standard shape.

Plugin API access to these values, so they can be used and edited.

NOTE: See related but separate UI UNITS Setting

FS#2407 - UI Small distance units

E.g. Nobeltec Admiral has own unit for small distances - less than 0.2 nm. It is easier to understand distance 250 m than 0.13 nm specially below 100 m distances. Possible choices should be the same as for distance, but I think feet should be included for US.

FS#515 - UI UNITS Allow routes, measurements to be in statute miles Allow routes and measurements to be in statute miles as well as nautical miles. This request is similar to the current request for kilometers. The Great Lakes charts are in statute miles and need to provide vessel traffic services with statute miles (and times derived from statute miles).

antipole2 commented 1 year ago

Rick... if you want to write .xml files, have a look at my TracksToKML utility in the shared scripts library.

Here I am outputting tracks in KML. The tracks part is not what you are wanting but it does write KML, which gives you a lead on writing XML.

antipole2 commented 1 year ago

Rick... I don't think I will be putting effort in here, but you should be able to do what you want. If you feel the plugin lacks something you need, raise it as an enhancement request in this issues list.

Note there is an example in the User Guide (Demonstration Scripts A) of saving preferences and loading them back. You could use this to save your data input and return to it to update. Or you could parse the XML output and repopulate the dialogue.

Note too that the plugin can send/receive OCPN messages to OCPN or another plugin.

rgleason commented 1 year ago

This is useful

  1. "Note too that the plugin can send/receive OCPN messages to OCPN or another plugin."
  2. Are you suggesting that it would be better to just have a JSON database or use XML?
  3. Is there a way to use Javascript_pi to edit, update and change the XML/JSON and save it back out.
  4. Then perhaps develop a standard program module (used in all plugins that use this system) that can only read the xml data file that would be located under the plugins directory or in OpenCPN support files. This way, the javascript plugin would not have to be involved in messaging all the time?
  5. I am not a programmer skilled enough to do all of this but I can give it a try at some point.
  6. I understand what you said about not putting in effort here...
  7. Just trying to scope out the best way to do it right now.
antipole2 commented 1 year ago

Rick... I suggest you create your data as a JS object, like

config.mastHeight = 17
config.draft = 2.5

Then printing the whole object is easy; print(config, "\n"); or prettily in JSON print(JSON.stringify(config, null, "\t"), "\n"); Saving and restoring in a JSON file is trivial. See my earlier comment. Writing it out in XML is not trivial but straightforward. See my earlier ref to the shared scripts as an example. Reading it back from XML is doable but would need some work. You would need to parse the XML. Most JavaScript solutions for parsing XML assume you are in a web browser and use the built-in parser. Not applicable here. An interesting bit of programming, for which you will need to learn how to use JavaScript pattern-matching.

rgleason commented 1 year ago

As a start have tried just using the console entry without making a JS object, which would be the next step.

Boat-Data.js.txt

I did something wrong because VS debugger threw and exception. How would I add scrolling and two columns?

What resource should I use for looking commands up.

Found this https://github.com/antipole2/JavaScripts-shared/blob/main/library/library_index.adoc

antipole2 commented 1 year ago

Your script runs OK by me. onDialogue does not support scrolling of the dialogue or two columns. There is no such thing in wxDialog which it uses. The scrollong you see in the JS consoles is within the text fields, not the whole widlow.

With a large dialogue, keeping track of the index in order to readback becomes tricky and brittle. If you add a line, it wold screw up the indexes. So I tend to constrauct the dialogue, noting the index at each step, viz:

dl = [
    {type:"caption", value:"Selector"},
    ]
boundaryIndex = dl.length;
dl.push({type:"radio", label:"Select boundary to use", value:boundaryNames});
inOutIndex = dl.length;
dl.push({type:"radio", label:"Inside or outside boundary", value:["Inside", "Outside"]});
crossIndex = dl.length;
dl.push({type:"tick", value:["Include routes crossing boundary"]});

Here I am noting the index I will need to access the value of the item.

What resource should I use for looking commands up.

Don't understand question.

rgleason commented 1 year ago

Thanks, Would this be a good reference? https://javascript.info/

antipole2 commented 5 months ago

@rgleason Are you OK to close this?