OpenCPN Partial API docs
Loading...
Searching...
No Matches
pluginmanager.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
25#ifndef _PLUGINMGR_H_
26#define _PLUGINMGR_H_
27
28#include <atomic>
29#include <memory>
30#include <string>
31
32#include "config.h"
33
34#include <wx/wx.h>
35#include <wx/bmpcbox.h>
36#include <wx/choice.h>
37#include <wx/dynarray.h>
38#include <wx/dynlib.h>
39#include <wx/hyperlink.h>
40#include <wx/json_defs.h>
41#include <wx/jsonwriter.h>
42#include <wx/tglbtn.h>
43
44#ifndef __ANDROID__
45#ifdef OCPN_USE_CURL
46#include <wx/curl/http.h>
47#include <wx/curl/dialog.h>
48#endif
49#endif
50
51#include "o_sound/o_sound.h"
52
55#include "model/comm_navmsg.h"
57#include "model/plugin_loader.h"
58#include "model/semantic_vers.h"
59
60#include "chartimg.h"
61#include "observable.h"
62#include "ocpndc.h"
63#include "ocpn_plugin.h"
64#include "s57chart.h" // for Object list
65#include "top_frame.h"
66
67//----------------------------------------------------------------------------
68// PlugIn Messaging scheme Event
69//----------------------------------------------------------------------------
70
71class PlugInManager; // forward
74class PluginListPanel; // forward
75class PluginPanel; // forward
76class pluginUtilHandler; // forward in .cpp file
77class MyFrame; // circular
78
79PlugIn_AIS_Target* Create_PI_AIS_Target(AisTargetData* ptarget);
80
81class OCPN_MsgEvent : public wxEvent {
82public:
83 OCPN_MsgEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
84
85 OCPN_MsgEvent(const OCPN_MsgEvent& event)
86 : wxEvent(event),
87 m_MessageID(event.m_MessageID),
88 m_MessageText(event.m_MessageText) {}
89
91
92 // accessors
93 wxString GetID() { return m_MessageID; }
94 wxString GetJSONText() { return m_MessageText; }
95
96 void SetID(const wxString& string) { m_MessageID = string; }
97 void SetJSONText(const wxString& string) { m_MessageText = string; }
98
99 // required for sending with wxPostEvent()
100 wxEvent* Clone() const;
101
102private:
103 wxString m_MessageID;
104 wxString m_MessageText;
105};
106
107extern const wxEventType wxEVT_OCPN_MSG;
108
109enum ActionVerb {
110 NOP = 0,
111 UPGRADE_TO_MANAGED_VERSION,
112 UPGRADE_INSTALLED_MANAGED_VERSION,
113 REINSTALL_MANAGED_VERSION,
114 DOWNGRADE_INSTALLED_MANAGED_VERSION,
115 UNINSTALL_MANAGED_VERSION,
116 INSTALL_MANAGED_VERSION,
117 UPDATE_IMPORTED_VERSION
118};
119
121public:
122 wxMenuItem* pmenu_item;
123 opencpn_plugin* m_pplugin;
124 bool b_viz;
125 bool b_grey;
126 int id;
127 wxString m_in_menu;
128 bool extended;
129};
130
131// Define an array of PlugIn MenuItem Containers
132WX_DEFINE_ARRAY_PTR(PlugInMenuItemContainer*, ArrayOfPlugInMenuItems);
133
135public:
138
139 opencpn_plugin* m_pplugin;
140 int id;
141 wxString label;
142 wxBitmap* bitmap_day;
143 wxBitmap* bitmap_dusk;
144 wxBitmap* bitmap_night;
145 wxBitmap* bitmap_Rollover_day;
146 wxBitmap* bitmap_Rollover_dusk;
147 wxBitmap* bitmap_Rollover_night;
148
149 wxItemKind kind;
150 wxString shortHelp;
151 wxString longHelp;
152 wxObject* clientData;
153 int position;
154 bool b_viz;
155 bool b_toggle;
156 int tool_sel;
157 wxString pluginNormalIconSVG;
158 wxString pluginRolloverIconSVG;
159 wxString pluginToggledIconSVG;
160};
161
162// Define an array of PlugIn ToolbarTool Containers
163WX_DEFINE_ARRAY_PTR(PlugInToolbarToolContainer*, ArrayOfPlugInToolbarTools);
164
165//-----------------------------------------------------------------------------------------------------
166//
167// The PlugIn Manager Specification
168//
169//-----------------------------------------------------------------------------------------------------
170
171class BlacklistUI;
172
173class PlugInManager : public wxEvtHandler {
174public:
176 virtual ~PlugInManager();
177
178 bool RenderAllCanvasOverlayPlugIns(ocpnDC& dc, const ViewPort& vp,
179 int canvasIndex, int priority);
180 bool RenderAllGLCanvasOverlayPlugIns(wxGLContext* pcontext,
181 const ViewPort& vp, int canvasIndex,
182 int priority);
183 // void SendCursorLatLonToAllPlugIns(double lat, double lon);
184 void SendViewPortToRequestingPlugIns(ViewPort& vp);
185 void PrepareAllPluginContextMenus();
186
187 void NotifySetupOptions();
188 void ClosePlugInPanel(const PlugInContainer* pic, int ix);
189 void CloseAllPlugInPanels(int);
190
191 ArrayOfPlugInToolbarTools& GetPluginToolbarToolArray() {
192 return m_PlugInToolbarTools;
193 }
194 int AddToolbarTool(wxString label, wxBitmap* bitmap, wxBitmap* bmpRollover,
195 wxItemKind kind, wxString shortHelp, wxString longHelp,
196 wxObject* clientData, int position, int tool_sel,
197 opencpn_plugin* pplugin);
198
199 void RemoveToolbarTool(int tool_id);
200 void SetToolbarToolViz(int tool_id, bool viz);
201 void SetToolbarItemState(int tool_id, bool toggle);
202 void SetToolbarItemBitmaps(int item, wxBitmap* bitmap, wxBitmap* bmpDisabled);
203
204 int AddToolbarTool(wxString label, wxString SVGfile, wxString SVGRolloverfile,
205 wxString SVGToggledfile, wxItemKind kind,
206 wxString shortHelp, wxString longHelp,
207 wxObject* clientData, int position, int tool_sel,
208 opencpn_plugin* pplugin);
209
210 void SetToolbarItemBitmaps(int item, wxString SVGfile,
211 wxString SVGfileRollover, wxString SVGfileToggled);
212
213 opencpn_plugin* FindToolOwner(const int id);
214 wxString GetToolOwnerCommonName(const int id);
215 void ShowDeferredBlacklistMessages();
216
217 ArrayOfPlugInMenuItems& GetPluginContextMenuItemArray() {
218 return m_PlugInMenuItems;
219 }
220 int AddCanvasContextMenuItemPIM(wxMenuItem* pitem, opencpn_plugin* pplugin,
221 const char* name = "",
222 bool is_extended = false);
223 void RemoveCanvasContextMenuItem(int item, const char* name = "");
224 void SetCanvasContextMenuItemViz(int item, bool viz, const char* name = "");
225 void SetCanvasContextMenuItemGrey(int item, bool grey, const char* name = "");
226
227 bool UpDateChartDataTypes();
228 void FinalizePluginLoadall();
229
230 bool UpdateConfig();
231 void SendResizeEventToAllPlugIns(int x, int y);
232 void SetColorSchemeForAllPlugIns(ColorScheme cs);
233 void NotifyAuiPlugIns(void);
234 bool CallLateInit(void);
235
236 bool IsAnyPlugInChartEnabled();
237
238 void SendBaseConfigToAllPlugIns();
239 void SendS52ConfigToAllPlugIns(bool bReconfig = false);
240 void SendSKConfigToAllPlugIns();
241
242 void UpdateManagedPlugins();
243 bool CheckBlacklistedPlugin(const PluginMetadata plugin);
244
245 void InitCommListeners(void);
253 void HandleN0183(std::shared_ptr<const Nmea0183Msg> n0183_msg);
261 void HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg);
262
263 wxArrayString GetPlugInChartClassNameArray(void);
264 opencpn_plugin* GetProvidingPlugin(const wxString& ChartClassName);
265
266 ListOfPI_S57Obj* GetPlugInObjRuleListAtLatLon(ChartPlugInWrapper* target,
267 float zlat, float zlon,
268 float SelectRadius,
269 const ViewPort& vp);
270 wxString CreateObjDescriptions(ChartPlugInWrapper* target,
271 ListOfPI_S57Obj* rule_list);
272
273 wxString GetLastError();
274 AbstractTopFrame* GetParentFrame() { return m_parent; }
275
276 void DimeWindow(wxWindow* win);
277 pluginUtilHandler* GetUtilHandler() { return m_utilHandler; }
278 void SetListPanelPtr(PluginListPanel* ptr) { m_listPanel = ptr; }
279
280 ListOfPI_S57Obj* GetLightsObjRuleListVisibleAtLatLon(
281 ChartPlugInWrapper* target, float zlat, float zlon, const ViewPort& vp);
282
283private:
284 bool CheckBlacklistedPlugin(wxString name, int major, int minor);
285 bool CheckBlacklistedPlugin(opencpn_plugin* plugin);
286 void OnNewMessageType();
287
288 ObservableListener evt_ais_json_listener;
289 ObservableListener evt_blacklisted_plugin_listener;
290 ObservableListener evt_download_failed_listener;
291 ObservableListener evt_download_ok_listener;
292 ObservableListener evt_load_directory_listener;
293 ObservableListener evt_load_plugin_listener;
294 ObservableListener evt_plugin_loadall_finalize_listener;
295 ObservableListener evt_pluglist_change_listener;
296 ObservableListener evt_update_chart_types_listener;
297 ObservableListener evt_json_to_all_plugins_listener;
298 ObservableListener evt_routeman_json_listener;
299 ObservableListener evt_routeman_leginfo_listener;
300
301 ObservableListener m_listener_SignalK;
302
303 ObsListener m_new_msgtype_lstnr;
304
305 ObsListener m_on_msg_sent_listener;
306
307 std::unordered_map<std::string, ObsListener> m_0183_listeners;
308
309 wxBitmap* BuildDimmedToolBitmap(wxBitmap* pbmp_normal,
310 unsigned char dim_ratio);
311
312 void ProcessLateInit(const PlugInContainer* pic);
313 void OnPluginActivate(const PlugInContainer* pic);
314 void OnPluginDeactivate(const PlugInContainer* pic);
315 void HandlePluginLoaderEvents();
316 void HandlePluginHandlerEvents();
317
318 AbstractTopFrame* m_parent;
319 std::unique_ptr<BlacklistUI> m_blacklist_ui;
320
321 wxString m_last_error_string;
322
323 ArrayOfPlugInMenuItems m_PlugInMenuItems;
324 ArrayOfPlugInToolbarTools m_PlugInToolbarTools;
325
326 wxString m_plugin_location;
327
328 int m_plugin_tool_id_next;
329 int m_plugin_menu_item_id_next;
330 wxBitmap m_cached_overlay_bm;
331
332 wxArrayString m_plugin_order;
333 void SetPluginOrder(wxString serialized_names);
334 wxString GetPluginOrder();
335
336 pluginUtilHandler* m_utilHandler;
337 PluginListPanel* m_listPanel;
338 std::unique_ptr<AbstractBlacklist> m_blacklist;
339
340#ifndef __ANDROID__
341#ifdef OCPN_USE_CURL
342
343public:
344 wxCurlDownloadThread* m_pCurlThread;
345 // The libcurl handle being re used for the transfer.
346 std::shared_ptr<wxCurlBase> m_pCurl;
347
348 // returns true if the error can be ignored
349 bool HandleCurlThreadError(wxCurlThreadError err, wxCurlBaseThread* p,
350 const wxString& url = wxEmptyString);
351 void OnEndPerformCurlDownload(wxCurlEndPerformEvent& ev);
352 void OnCurlDownload(wxCurlDownloadEvent& ev);
353
354 wxEvtHandler* m_download_evHandler;
355 long* m_downloadHandle;
356 bool m_last_online;
357 long m_last_online_chk;
358#endif
359#endif
360
361 DECLARE_EVENT_TABLE()
362};
363
364WX_DEFINE_ARRAY_PTR(PluginPanel*, ArrayOfPluginPanel);
365
366/*
367 * Panel with a single + sign which opens the "Add/download plugins" dialog.
368 */
369class AddPluginPanel : public wxPanel {
370public:
371 AddPluginPanel(wxWindow* parent);
372 void OnClick(wxMouseEvent& event);
374
375protected:
376 wxBitmap m_bitmap;
377 wxStaticBitmap* m_staticBitmap;
378 wxWindow* m_parent;
379};
380
381/*
382 * Panel with buttons to control plugin catalog management.
383 */
384class CatalogMgrPanel : public wxPanel {
385public:
386 CatalogMgrPanel(wxWindow* parent);
388 void OnUpdateButton(wxCommandEvent& event);
389 void SetListPanelPtr(PluginListPanel* listPanel) {
390 m_PluginListPanel = listPanel;
391 }
392 void OnTarballButton(wxCommandEvent& event);
393 void OnPluginSettingsButton(wxCommandEvent& event);
394
395protected:
396 wxString GetCatalogText(bool);
397 void SetUpdateButtonLabel();
398 wxString GetImportInitDir();
399
400 wxButton *m_updateButton, *m_advancedButton, *m_tarballButton;
401 wxButton* m_adv_button;
402 wxStaticText* m_catalogText;
403 wxWindow* m_parent;
404 PluginListPanel* m_PluginListPanel;
405 ObservableListener catalog_listener;
406};
407
408#define ID_CMD_BUTTON_PERFORM_ACTION 27663
409
410class PluginListPanel : public wxScrolledWindow {
411 DECLARE_EVENT_TABLE()
412
413public:
414 PluginListPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos,
415 const wxSize& size);
417
418 void SelectPlugin(PluginPanel* pi);
419 void MoveUp(PluginPanel* pi);
420 void MoveDown(PluginPanel* pi);
421 void UpdateSelections();
422 void UpdatePluginsOrder();
423
425 void ReloadPluginPanels();
426 void SelectByName(wxString& name);
427
428private:
429 void AddPlugin(const PlugInData& pd);
430 void AddPlugin(const std::string& name);
431 int ComputePluginSpace(ArrayOfPluginPanel plugins, wxBoxSizer* sizer);
432 // void Clear();
433
434 ArrayOfPluginPanel m_PluginItems;
435 PluginPanel* m_PluginSelected;
436 wxString m_selectedName;
437 int m_pluginSpacer;
438 std::atomic_flag m_is_loading;
439};
440
442class WebsiteButton : public wxPanel {
443public:
444 WebsiteButton(wxWindow* parent, const char* url);
445 ~WebsiteButton() {};
446 void SetURL(std::string url) { m_url = url; }
447
448protected:
449 std::string m_url;
450};
451
452class PluginPanel : public wxPanel {
453 DECLARE_EVENT_TABLE()
454
455
456public:
458 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
459 const wxSize& size, const PlugInData plugin);
460
462 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
463 const wxSize& size, PluginMetadata plugin);
464
466 PluginPanel(wxPanel* parent, const std::string& name);
467
468 ~PluginPanel();
469
470 void OnPluginSelected(wxMouseEvent& event);
471 void OnPluginSelectedUp(wxMouseEvent& event);
472 void DoPluginSelect();
473
474 void SetSelected(bool selected);
475 void OnPluginPreferences(wxCommandEvent& event);
476 void OnPluginEnableToggle(wxCommandEvent& event);
477 void OnPluginAction(wxCommandEvent& event);
478 void OnPluginUninstall(wxCommandEvent& event);
479 void OnPluginUp(wxCommandEvent& event);
480 void OnPluginDown(wxCommandEvent& event);
481 void SetEnabled(bool enabled);
482 bool GetSelected() { return m_bSelected; }
483 const PlugInData* GetPluginPtr() { return &m_plugin; };
484 void SetActionLabel(wxString& label);
485 ActionVerb GetAction() { return m_action; }
486 const PlugInData* GetPlugin() { return &m_plugin; }
487 void OnPaint(wxPaintEvent& event);
488
489private:
490 PluginListPanel* m_PluginListPanel;
491 bool m_bSelected;
492 const PlugInData m_plugin;
493 wxStaticText* m_pName;
494 wxStaticText* m_pVersion;
495 wxStaticText* m_pDescription;
496 wxBoxSizer* m_pButtons;
497 wxStaticBitmap* m_itemStaticBitmap;
498 wxStaticBitmap* m_itemStatusIconBitmap;
499 wxButton* m_pButtonPreferences;
500 wxButton *m_pButtonAction, *m_pButtonUninstall;
501
502 wxCheckBox* m_cbEnable;
503 WebsiteButton* m_info_btn;
504 ActionVerb m_action;
505 int m_penWidthUnselected, m_penWidthSelected;
506 bool m_is_safe_panel;
507};
508
509// API 1.11 adds access to S52 Presentation library
510// These are some wrapper conversion utilities
511
513public:
515 bBBObj_valid = false;
516 bCS_Added = false;
517 bFText_Added = false;
518 CSrules = NULL;
519 FText = NULL;
520 ChildRazRules = NULL;
521 MPSRulesList = NULL;
522 LUP = NULL;
523 };
524
525 ~S52PLIB_Context() {};
526
527 BoundingBox BBObj; // lat/lon BBox of the rendered object
528 bool bBBObj_valid; // set after the BBObj has been calculated once.
529
530 Rules* CSrules; // per object conditional symbology
531 int bCS_Added;
532
533 S52_TextC* FText;
534 int bFText_Added;
535 wxRect rText;
536
537 LUPrec* LUP;
538 ObjRazRules* ChildRazRules;
539 mps_container* MPSRulesList;
540};
541
542void CreateCompatibleS57Object(PI_S57Obj* pObj, S57Obj* cobj,
543 chart_context* pctx);
544void UpdatePIObjectPlibContext(PI_S57Obj* pObj, S57Obj* cobj);
545
546#endif // _PLUGINMGR_H_
AIS target definitions.
Datatypes and methods to parse ocpn-plugins.xml XML data, either complete catalog or a single plugin.
BSB chart management.
Handle messages for blacklisted plugins.
Wrapper class for plugin-based charts.
Definition chartimg.h:389
Main application frame.
Definition ocpn_frame.h:109
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:257
Keeps listening over its lifespan, removes itself on destruction.
Definition observable.h:155
Class representing an S-57 chart object.
Data for a loaded plugin, including dl-loaded library.
Basic data for a loaded plugin, trivially copyable.
void HandleN0183(std::shared_ptr< const Nmea0183Msg > n0183_msg)
Process incoming NMEA 0183 messages from the message bus.
void HandleSignalK(std::shared_ptr< const SignalkMsg > sK_msg)
Process incoming SignalK messages from the message bus.
AIS target information accessible to plugins.
void ReloadPluginPanels()
Complete reload from plugins array.
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:56
Invokes client browser on plugin info_url when clicked.
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:60
Base class for OpenCPN plugins.
Raw, undecoded messages definitions.
General observable implementation with several specializations.
PlugIn Object Definition/API.
Layer to use wxDC or opengl.
Plugin blacklist for plugins which can or should not be loaded.
Low level code to load plugins from disk, notably the PluginLoader class.
PlugInManager * g_pi_manager
Global instance.
S57 Chart Object.
Semantic version encode/decode object.
Plugin metadata, reflects the xml format directly.
Abstract gFrame/MyFrame interface.