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