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, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
27#ifndef _PLUGINMGR_H_
28#define _PLUGINMGR_H_
29
30#include <atomic>
31#include <memory>
32#include <string>
33
34#include "config.h"
35
36#include <wx/wx.h>
37#include <wx/bmpcbox.h>
38#include <wx/choice.h>
39#include <wx/dynarray.h>
40#include <wx/dynlib.h>
41#include <wx/hyperlink.h>
42#include <wx/json_defs.h>
43#include <wx/jsonwriter.h>
44#include <wx/tglbtn.h>
45
46#ifndef __OCPN__ANDROID__
47#ifdef OCPN_USE_CURL
48#include <wx/curl/http.h>
49#include <wx/curl/dialog.h>
50#endif
51#endif
52
53#include "model/ais_target_data.h"
55#include "model/comm_navmsg.h"
56#include "model/plugin_blacklist.h"
57#include "model/plugin_loader.h"
58#include "model/semantic_vers.h"
59#include "chartimg.h"
60#include "observable.h"
61#include "ocpndc.h"
62#include "ocpn_plugin.h"
63#include "OCPN_Sound.h"
64#include "s57chart.h" // for Object list
65
66// Assorted static helper routines
67
68PlugIn_AIS_Target* Create_PI_AIS_Target(AisTargetData* ptarget);
69
70class PluginListPanel;
71class PluginPanel;
73class MyFrame;
74
75//----------------------------------------------------------------------------
76// PlugIn Messaging scheme Event
77//----------------------------------------------------------------------------
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 OnPluginDeactivate(const PlugInContainer* pic);
311 void HandlePluginLoaderEvents();
312 void HandlePluginHandlerEvents();
313
314 MyFrame* pParent;
315 std::unique_ptr<BlacklistUI> m_blacklist_ui;
316
317 wxString m_last_error_string;
318
319 ArrayOfPlugInMenuItems m_PlugInMenuItems;
320 ArrayOfPlugInToolbarTools m_PlugInToolbarTools;
321
322 wxString m_plugin_location;
323
324 int m_plugin_tool_id_next;
325 int m_plugin_menu_item_id_next;
326 wxBitmap m_cached_overlay_bm;
327
328 wxArrayString m_plugin_order;
329 void SetPluginOrder(wxString serialized_names);
330 wxString GetPluginOrder();
331
332 pluginUtilHandler* m_utilHandler;
333 PluginListPanel* m_listPanel;
334 std::unique_ptr<AbstractBlacklist> m_blacklist;
335
336#ifndef __OCPN__ANDROID__
337#ifdef OCPN_USE_CURL
338
339public:
340 wxCurlDownloadThread* m_pCurlThread;
341 // The libcurl handle being re used for the transfer.
342 std::shared_ptr<wxCurlBase> m_pCurl;
343
344 // returns true if the error can be ignored
345 bool HandleCurlThreadError(wxCurlThreadError err, wxCurlBaseThread* p,
346 const wxString& url = wxEmptyString);
347 void OnEndPerformCurlDownload(wxCurlEndPerformEvent& ev);
348 void OnCurlDownload(wxCurlDownloadEvent& ev);
349
350 wxEvtHandler* m_download_evHandler;
351 long* m_downloadHandle;
352 bool m_last_online;
353 long m_last_online_chk;
354#endif
355#endif
356
357 DECLARE_EVENT_TABLE()
358};
359
360WX_DEFINE_ARRAY_PTR(PluginPanel*, ArrayOfPluginPanel);
361
362/*
363 * Panel with a single + sign which opens the "Add/download plugins" dialog.
364 */
365class AddPluginPanel : public wxPanel {
366public:
367 AddPluginPanel(wxWindow* parent);
368 void OnClick(wxMouseEvent& event);
370
371protected:
372 wxBitmap m_bitmap;
373 wxStaticBitmap* m_staticBitmap;
374 wxWindow* m_parent;
375};
376
377/*
378 * Panel with buttons to control plugin catalog management.
379 */
380class CatalogMgrPanel : public wxPanel {
381public:
382 CatalogMgrPanel(wxWindow* parent);
384 void OnUpdateButton(wxCommandEvent& event);
385 void SetListPanelPtr(PluginListPanel* listPanel) {
386 m_PluginListPanel = listPanel;
387 }
388 void OnTarballButton(wxCommandEvent& event);
389 void OnPluginSettingsButton(wxCommandEvent& event);
390
391protected:
392 wxString GetCatalogText(bool);
393 void SetUpdateButtonLabel();
394 wxString GetImportInitDir();
395
396 wxButton *m_updateButton, *m_advancedButton, *m_tarballButton;
397 wxButton* m_adv_button;
398 wxStaticText* m_catalogText;
399 wxWindow* m_parent;
400 PluginListPanel* m_PluginListPanel;
401 ObservableListener catalog_listener;
402};
403
404#define ID_CMD_BUTTON_PERFORM_ACTION 27663
405
406class PluginListPanel : public wxScrolledWindow {
407 DECLARE_EVENT_TABLE()
408
409public:
410 PluginListPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos,
411 const wxSize& size);
413
414 void SelectPlugin(PluginPanel* pi);
415 void MoveUp(PluginPanel* pi);
416 void MoveDown(PluginPanel* pi);
417 void UpdateSelections();
418 void UpdatePluginsOrder();
419
421 void ReloadPluginPanels();
422 void SelectByName(wxString& name);
423
424private:
425 void AddPlugin(const PlugInData& pd);
426 void AddPlugin(const std::string& name);
427 int ComputePluginSpace(ArrayOfPluginPanel plugins, wxBoxSizer* sizer);
428 // void Clear();
429
430 ArrayOfPluginPanel m_PluginItems;
431 PluginPanel* m_PluginSelected;
432 wxString m_selectedName;
433 int m_pluginSpacer;
434 std::atomic_flag m_is_loading;
435};
436
438class WebsiteButton : public wxPanel {
439public:
440 WebsiteButton(wxWindow* parent, const char* url);
441 ~WebsiteButton() {};
442 void SetURL(std::string url) { m_url = url; }
443
444protected:
445 std::string m_url;
446};
447
448class PluginPanel : public wxPanel {
449 DECLARE_EVENT_TABLE()
450
451
452public:
454 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
455 const wxSize& size, const PlugInData plugin);
456
458 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
459 const wxSize& size, PluginMetadata plugin);
460
462 PluginPanel(wxPanel* parent, const std::string& name);
463
464 ~PluginPanel();
465
466 void OnPluginSelected(wxMouseEvent& event);
467 void OnPluginSelectedUp(wxMouseEvent& event);
468 void DoPluginSelect();
469
470 void SetSelected(bool selected);
471 void OnPluginPreferences(wxCommandEvent& event);
472 void OnPluginEnableToggle(wxCommandEvent& event);
473 void OnPluginAction(wxCommandEvent& event);
474 void OnPluginUninstall(wxCommandEvent& event);
475 void OnPluginUp(wxCommandEvent& event);
476 void OnPluginDown(wxCommandEvent& event);
477 void SetEnabled(bool enabled);
478 bool GetSelected() { return m_bSelected; }
479 const PlugInData* GetPluginPtr() { return &m_plugin; };
480 void SetActionLabel(wxString& label);
481 ActionVerb GetAction() { return m_action; }
482 const PlugInData* GetPlugin() { return &m_plugin; }
483 void OnPaint(wxPaintEvent& event);
484
485private:
486 PluginListPanel* m_PluginListPanel;
487 bool m_bSelected;
488 const PlugInData m_plugin;
489 wxStaticText* m_pName;
490 wxStaticText* m_pVersion;
491 wxStaticText* m_pDescription;
492 wxBoxSizer* m_pButtons;
493 wxStaticBitmap* m_itemStaticBitmap;
494 wxStaticBitmap* m_itemStatusIconBitmap;
495 wxButton* m_pButtonPreferences;
496 wxButton *m_pButtonAction, *m_pButtonUninstall;
497
498 wxCheckBox* m_cbEnable;
499 WebsiteButton* m_info_btn;
500 ActionVerb m_action;
501 int m_penWidthUnselected, m_penWidthSelected;
502 bool m_is_safe_panel;
503};
504
505// API 1.11 adds access to S52 Presentation library
506// These are some wrapper conversion utilities
507
509public:
511 bBBObj_valid = false;
512 bCS_Added = false;
513 bFText_Added = false;
514 CSrules = NULL;
515 FText = NULL;
516 ChildRazRules = NULL;
517 MPSRulesList = NULL;
518 LUP = NULL;
519 };
520
521 ~S52PLIB_Context() {};
522
523 BoundingBox BBObj; // lat/lon BBox of the rendered object
524 bool bBBObj_valid; // set after the BBObj has been calculated once.
525
526 Rules* CSrules; // per object conditional symbology
527 int bCS_Added;
528
529 S52_TextC* FText;
530 int bFText_Added;
531 wxRect rText;
532
533 LUPrec* LUP;
534 ObjRazRules* ChildRazRules;
535 mps_container* MPSRulesList;
536};
537
538void CreateCompatibleS57Object(PI_S57Obj* pObj, S57Obj* cobj,
539 chart_context* pctx);
540void UpdatePIObjectPlibContext(PI_S57Obj* pObj, S57Obj* cobj);
541
542#endif // _PLUGINMGR_H_
Datatypes and methods to parse ocpn-plugins.xml XML data, either complete catalog or a single plugin.
Handle messages for blacklisted plugins.
Wrapper class for plugin-based charts.
Definition chartimg.h:392
Main application frame.
Definition ocpn_frame.h:136
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:81
Invokes client browser on plugin info_url when clicked.
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:64
Base class for OpenCPN plugins.
Raw, undecoded messages definitions.
General observable implementation with several specializations.
PlugIn Object Definition/API.
Low level code to load plugins from disk, notably the PluginLoader class.
Plugin metadata, reflects the xml format directly.