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