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
77
78PlugIn_AIS_Target* Create_PI_AIS_Target(AisTargetData* ptarget);
79
80class OCPN_MsgEvent : public wxEvent {
81public:
82 OCPN_MsgEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
83
84 OCPN_MsgEvent(const OCPN_MsgEvent& event)
85 : wxEvent(event),
86 m_MessageID(event.m_MessageID),
87 m_MessageText(event.m_MessageText) {}
88
90
91 // accessors
92 wxString GetID() { return m_MessageID; }
93 wxString GetJSONText() { return m_MessageText; }
94
95 void SetID(const wxString& string) { m_MessageID = string; }
96 void SetJSONText(const wxString& string) { m_MessageText = string; }
97
98 // required for sending with wxPostEvent()
99 wxEvent* Clone() const;
100
101private:
102 wxString m_MessageID;
103 wxString m_MessageText;
104};
105
106extern const wxEventType wxEVT_OCPN_MSG;
107
108enum ActionVerb {
109 NOP = 0,
110 UPGRADE_TO_MANAGED_VERSION,
111 UPGRADE_INSTALLED_MANAGED_VERSION,
112 REINSTALL_MANAGED_VERSION,
113 DOWNGRADE_INSTALLED_MANAGED_VERSION,
114 UNINSTALL_MANAGED_VERSION,
115 INSTALL_MANAGED_VERSION,
116 UPDATE_IMPORTED_VERSION
117};
118
120public:
121 wxMenuItem* pmenu_item;
122 opencpn_plugin* m_pplugin;
123 bool b_viz;
124 bool b_grey;
125 int id;
126 wxString m_in_menu;
127 bool extended;
128};
129
130// Define an array of PlugIn MenuItem Containers
131WX_DEFINE_ARRAY_PTR(PlugInMenuItemContainer*, ArrayOfPlugInMenuItems);
132
134public:
137
138 opencpn_plugin* m_pplugin;
139 int id;
140 wxString label;
141 wxBitmap* bitmap_day;
142 wxBitmap* bitmap_dusk;
143 wxBitmap* bitmap_night;
144 wxBitmap* bitmap_Rollover_day;
145 wxBitmap* bitmap_Rollover_dusk;
146 wxBitmap* bitmap_Rollover_night;
147
148 wxItemKind kind;
149 wxString shortHelp;
150 wxString longHelp;
151 wxObject* clientData;
152 int position;
153 bool b_viz;
154 bool b_toggle;
155 int tool_sel;
156 wxString pluginNormalIconSVG;
157 wxString pluginRolloverIconSVG;
158 wxString pluginToggledIconSVG;
159};
160
161// Define an array of PlugIn ToolbarTool Containers
162WX_DEFINE_ARRAY_PTR(PlugInToolbarToolContainer*, ArrayOfPlugInToolbarTools);
163
164//-----------------------------------------------------------------------------------------------------
165//
166// The PlugIn Manager Specification
167//
168//-----------------------------------------------------------------------------------------------------
169
170class BlacklistUI;
171
172class PlugInManager : public wxEvtHandler {
173public:
175 virtual ~PlugInManager();
176
177 bool RenderAllCanvasOverlayPlugIns(ocpnDC& dc, const ViewPort& vp,
178 int canvasIndex, int priority);
179 bool RenderAllGLCanvasOverlayPlugIns(wxGLContext* pcontext,
180 const ViewPort& vp, int canvasIndex,
181 int priority);
182 // void SendCursorLatLonToAllPlugIns(double lat, double lon);
183 void SendViewPortToRequestingPlugIns(ViewPort& vp);
184 void PrepareAllPluginContextMenus();
185
186 void NotifySetupOptions();
187 void ClosePlugInPanel(const PlugInContainer* pic, int ix);
188 void CloseAllPlugInPanels(int);
189
190 ArrayOfPlugInToolbarTools& GetPluginToolbarToolArray() {
191 return m_PlugInToolbarTools;
192 }
193 int AddToolbarTool(wxString label, wxBitmap* bitmap, wxBitmap* bmpRollover,
194 wxItemKind kind, wxString shortHelp, wxString longHelp,
195 wxObject* clientData, int position, int tool_sel,
196 opencpn_plugin* pplugin);
197
198 void RemoveToolbarTool(int tool_id);
199 void SetToolbarToolViz(int tool_id, bool viz);
200 void SetToolbarItemState(int tool_id, bool toggle);
201 void SetToolbarItemBitmaps(int item, wxBitmap* bitmap, wxBitmap* bmpDisabled);
202
203 int AddToolbarTool(wxString label, wxString SVGfile, wxString SVGRolloverfile,
204 wxString SVGToggledfile, wxItemKind kind,
205 wxString shortHelp, wxString longHelp,
206 wxObject* clientData, int position, int tool_sel,
207 opencpn_plugin* pplugin);
208
209 void SetToolbarItemBitmaps(int item, wxString SVGfile,
210 wxString SVGfileRollover, wxString SVGfileToggled);
211
212 opencpn_plugin* FindToolOwner(const int id);
213 wxString GetToolOwnerCommonName(const int id);
214 void ShowDeferredBlacklistMessages();
215
216 ArrayOfPlugInMenuItems& GetPluginContextMenuItemArray() {
217 return m_PlugInMenuItems;
218 }
219 int AddCanvasContextMenuItemPIM(wxMenuItem* pitem, opencpn_plugin* pplugin,
220 const char* name = "",
221 bool is_extended = false);
222 void RemoveCanvasContextMenuItem(int item, const char* name = "");
223 void SetCanvasContextMenuItemViz(int item, bool viz, const char* name = "");
224 void SetCanvasContextMenuItemGrey(int item, bool grey, const char* name = "");
225
226 bool UpDateChartDataTypes();
227 void FinalizePluginLoadall();
228
229 bool UpdateConfig();
230 void SendResizeEventToAllPlugIns(int x, int y);
231 void SetColorSchemeForAllPlugIns(ColorScheme cs);
232 void NotifyAuiPlugIns(void);
233 bool CallLateInit(void);
234
235 bool IsAnyPlugInChartEnabled();
236
237 void SendBaseConfigToAllPlugIns();
238 void SendS52ConfigToAllPlugIns(bool bReconfig = false);
239 void SendSKConfigToAllPlugIns();
240
241 void UpdateManagedPlugins();
242 bool CheckBlacklistedPlugin(const PluginMetadata plugin);
243
244 void InitCommListeners(void);
252 void HandleN0183(std::shared_ptr<const Nmea0183Msg> n0183_msg);
260 void HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg);
261
262 wxArrayString GetPlugInChartClassNameArray(void);
263 opencpn_plugin* GetProvidingPlugin(const wxString& ChartClassName);
264
265 ListOfPI_S57Obj* GetPlugInObjRuleListAtLatLon(ChartPlugInWrapper* target,
266 float zlat, float zlon,
267 float SelectRadius,
268 const ViewPort& vp);
269 wxString CreateObjDescriptions(ChartPlugInWrapper* target,
270 ListOfPI_S57Obj* rule_list);
271
272 wxString GetLastError();
273 AbstractTopFrame* GetParentFrame() { return m_parent; }
274
275 void DimeWindow(wxWindow* win);
276 pluginUtilHandler* GetUtilHandler() { return m_utilHandler; }
277 void SetListPanelPtr(PluginListPanel* ptr) { m_listPanel = ptr; }
278
279 ListOfPI_S57Obj* GetLightsObjRuleListVisibleAtLatLon(
280 ChartPlugInWrapper* target, float zlat, float zlon, const ViewPort& vp);
281
282private:
283 bool CheckBlacklistedPlugin(wxString name, int major, int minor);
284 bool CheckBlacklistedPlugin(opencpn_plugin* plugin);
285 void OnNewMessageType();
286
287 ObservableListener evt_ais_json_listener;
288 ObservableListener evt_blacklisted_plugin_listener;
289 ObservableListener evt_download_failed_listener;
290 ObservableListener evt_download_ok_listener;
291 ObservableListener evt_load_directory_listener;
292 ObservableListener evt_load_plugin_listener;
293 ObservableListener evt_plugin_loadall_finalize_listener;
294 ObservableListener evt_pluglist_change_listener;
295 ObservableListener evt_update_chart_types_listener;
296 ObservableListener evt_json_to_all_plugins_listener;
297 ObservableListener evt_routeman_json_listener;
298 ObservableListener evt_routeman_leginfo_listener;
299
300 ObservableListener m_listener_SignalK;
301
302 ObsListener m_new_msgtype_lstnr;
303
304 ObsListener m_on_msg_sent_listener;
305
306 std::unordered_map<std::string, ObsListener> m_0183_listeners;
307
308 wxBitmap* BuildDimmedToolBitmap(wxBitmap* pbmp_normal,
309 unsigned char dim_ratio);
310
311 void ProcessLateInit(const PlugInContainer* pic);
312 void OnPluginActivate(const PlugInContainer* pic);
313 void OnPluginDeactivate(const PlugInContainer* pic);
314 void HandlePluginLoaderEvents();
315 void HandlePluginHandlerEvents();
316
317 AbstractTopFrame* m_parent;
318 std::unique_ptr<BlacklistUI> m_blacklist_ui;
319
320 wxString m_last_error_string;
321
322 ArrayOfPlugInMenuItems m_PlugInMenuItems;
323 ArrayOfPlugInToolbarTools m_PlugInToolbarTools;
324
325 wxString m_plugin_location;
326
327 int m_plugin_tool_id_next;
328 int m_plugin_menu_item_id_next;
329 wxBitmap m_cached_overlay_bm;
330
331 wxArrayString m_plugin_order;
332 void SetPluginOrder(wxString serialized_names);
333 wxString GetPluginOrder();
334
335 pluginUtilHandler* m_utilHandler;
336 PluginListPanel* m_listPanel;
337 std::unique_ptr<AbstractBlacklist> m_blacklist;
338
339#ifndef __ANDROID__
340#ifdef OCPN_USE_CURL
341
342public:
343 wxCurlDownloadThread* m_pCurlThread;
344 // The libcurl handle being re used for the transfer.
345 std::shared_ptr<wxCurlBase> m_pCurl;
346
347 // returns true if the error can be ignored
348 bool HandleCurlThreadError(wxCurlThreadError err, wxCurlBaseThread* p,
349 const wxString& url = wxEmptyString);
350 void OnEndPerformCurlDownload(wxCurlEndPerformEvent& ev);
351 void OnCurlDownload(wxCurlDownloadEvent& ev);
352
353 wxEvtHandler* m_download_evHandler;
354 long* m_downloadHandle;
355 bool m_last_online;
356 long m_last_online_chk;
357#endif
358#endif
359
360 DECLARE_EVENT_TABLE()
361};
362
363WX_DEFINE_ARRAY_PTR(PluginPanel*, ArrayOfPluginPanel);
364
365/*
366 * Panel with a single + sign which opens the "Add/download plugins" dialog.
367 */
368class AddPluginPanel : public wxPanel {
369public:
370 AddPluginPanel(wxWindow* parent);
371 void OnClick(wxMouseEvent& event);
373
374protected:
375 wxBitmap m_bitmap;
376 wxStaticBitmap* m_staticBitmap;
377 wxWindow* m_parent;
378};
379
380/*
381 * Panel with buttons to control plugin catalog management.
382 */
383class CatalogMgrPanel : public wxPanel {
384public:
385 CatalogMgrPanel(wxWindow* parent);
387 void OnUpdateButton(wxCommandEvent& event);
388 void SetListPanelPtr(PluginListPanel* listPanel) {
389 m_PluginListPanel = listPanel;
390 }
391 void OnTarballButton(wxCommandEvent& event);
392 void OnPluginSettingsButton(wxCommandEvent& event);
393
394protected:
395 wxString GetCatalogText(bool);
396 void SetUpdateButtonLabel();
397 wxString GetImportInitDir();
398
399 wxButton *m_updateButton, *m_advancedButton, *m_tarballButton;
400 wxButton* m_adv_button;
401 wxStaticText* m_catalogText;
402 wxWindow* m_parent;
403 PluginListPanel* m_PluginListPanel;
404 ObservableListener catalog_listener;
405};
406
407#define ID_CMD_BUTTON_PERFORM_ACTION 27663
408
409class PluginListPanel : public wxScrolledWindow {
410 DECLARE_EVENT_TABLE()
411
412public:
413 PluginListPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos,
414 const wxSize& size);
416
417 void SelectPlugin(PluginPanel* pi);
418 void MoveUp(PluginPanel* pi);
419 void MoveDown(PluginPanel* pi);
420 void UpdateSelections();
421 void UpdatePluginsOrder();
422
424 void ReloadPluginPanels();
425 void SelectByName(wxString& name);
426
427private:
428 void AddPlugin(const PlugInData& pd);
429 void AddPlugin(const std::string& name);
430 int ComputePluginSpace(ArrayOfPluginPanel plugins, wxBoxSizer* sizer);
431 // void Clear();
432
433 ArrayOfPluginPanel m_PluginItems;
434 PluginPanel* m_PluginSelected;
435 wxString m_selectedName;
436 int m_pluginSpacer;
437 std::atomic_flag m_is_loading;
438};
439
441class WebsiteButton : public wxPanel {
442public:
443 WebsiteButton(wxWindow* parent, const char* url);
444 ~WebsiteButton() {};
445 void SetURL(std::string url) { m_url = url; }
446
447protected:
448 std::string m_url;
449};
450
451class PluginPanel : public wxPanel {
452 DECLARE_EVENT_TABLE()
453
454
455public:
457 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
458 const wxSize& size, const PlugInData plugin);
459
461 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
462 const wxSize& size, PluginMetadata plugin);
463
465 PluginPanel(wxPanel* parent, const std::string& name);
466
467 ~PluginPanel();
468
469 void OnPluginSelected(wxMouseEvent& event);
470 void OnPluginSelectedUp(wxMouseEvent& event);
471 void DoPluginSelect();
472
473 void SetSelected(bool selected);
474 void OnPluginPreferences(wxCommandEvent& event);
475 void OnPluginEnableToggle(wxCommandEvent& event);
476 void OnPluginAction(wxCommandEvent& event);
477 void OnPluginUninstall(wxCommandEvent& event);
478 void OnPluginUp(wxCommandEvent& event);
479 void OnPluginDown(wxCommandEvent& event);
480 void SetEnabled(bool enabled);
481 bool GetSelected() { return m_bSelected; }
482 const PlugInData* GetPluginPtr() { return &m_plugin; };
483 void SetActionLabel(wxString& label);
484 ActionVerb GetAction() { return m_action; }
485 const PlugInData* GetPlugin() { return &m_plugin; }
486 void OnPaint(wxPaintEvent& event);
487
488private:
489 PluginListPanel* m_PluginListPanel;
490 bool m_bSelected;
491 const PlugInData m_plugin;
492 wxStaticText* m_pName;
493 wxStaticText* m_pVersion;
494 wxStaticText* m_pDescription;
495 wxBoxSizer* m_pButtons;
496 wxStaticBitmap* m_itemStaticBitmap;
497 wxStaticBitmap* m_itemStatusIconBitmap;
498 wxButton* m_pButtonPreferences;
499 wxButton *m_pButtonAction, *m_pButtonUninstall;
500
501 wxCheckBox* m_cbEnable;
502 WebsiteButton* m_info_btn;
503 ActionVerb m_action;
504 int m_penWidthUnselected, m_penWidthSelected;
505 bool m_is_safe_panel;
506};
507
508// API 1.11 adds access to S52 Presentation library
509// These are some wrapper conversion utilities
510
512public:
514 bBBObj_valid = false;
515 bCS_Added = false;
516 bFText_Added = false;
517 CSrules = NULL;
518 FText = NULL;
519 ChildRazRules = NULL;
520 MPSRulesList = NULL;
521 LUP = NULL;
522 };
523
524 ~S52PLIB_Context() {};
525
526 BoundingBox BBObj; // lat/lon BBox of the rendered object
527 bool bBBObj_valid; // set after the BBObj has been calculated once.
528
529 Rules* CSrules; // per object conditional symbology
530 int bCS_Added;
531
532 S52_TextC* FText;
533 int bFText_Added;
534 wxRect rText;
535
536 LUPrec* LUP;
537 ObjRazRules* ChildRazRules;
538 mps_container* MPSRulesList;
539};
540
541void CreateCompatibleS57Object(PI_S57Obj* pObj, S57Obj* cobj,
542 chart_context* pctx);
543void UpdatePIObjectPlibContext(PI_S57Obj* pObj, S57Obj* cobj);
544
545#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
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.