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
66//----------------------------------------------------------------------------
67// PlugIn Messaging scheme Event
68//----------------------------------------------------------------------------
69
70class PlugInManager; // forward
73class PluginListPanel; // forward
74class PluginPanel; // forward
75class pluginUtilHandler; // forward in .cpp file
76class MyFrame; // circular
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:
174 PlugInManager(MyFrame* parent);
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
264 ListOfPI_S57Obj* GetPlugInObjRuleListAtLatLon(ChartPlugInWrapper* target,
265 float zlat, float zlon,
266 float SelectRadius,
267 const ViewPort& vp);
268 wxString CreateObjDescriptions(ChartPlugInWrapper* target,
269 ListOfPI_S57Obj* rule_list);
270
271 wxString GetLastError();
272 MyFrame* GetParentFrame() { return pParent; }
273
274 void DimeWindow(wxWindow* win);
275 pluginUtilHandler* GetUtilHandler() { return m_utilHandler; }
276 void SetListPanelPtr(PluginListPanel* ptr) { m_listPanel = ptr; }
277
278 ListOfPI_S57Obj* GetLightsObjRuleListVisibleAtLatLon(
279 ChartPlugInWrapper* target, float zlat, float zlon, const ViewPort& vp);
280
281private:
282 bool CheckBlacklistedPlugin(wxString name, int major, int minor);
283 bool CheckBlacklistedPlugin(opencpn_plugin* plugin);
284 void OnNewMessageType();
285
286 ObservableListener evt_ais_json_listener;
287 ObservableListener evt_blacklisted_plugin_listener;
288 ObservableListener evt_download_failed_listener;
289 ObservableListener evt_download_ok_listener;
290 ObservableListener evt_load_directory_listener;
291 ObservableListener evt_load_plugin_listener;
292 ObservableListener evt_plugin_loadall_finalize_listener;
293 ObservableListener evt_pluglist_change_listener;
294 ObservableListener evt_update_chart_types_listener;
295 ObservableListener evt_json_to_all_plugins_listener;
296 ObservableListener evt_routeman_json_listener;
297 ObservableListener evt_routeman_leginfo_listener;
298
299 ObservableListener m_listener_SignalK;
300
301 ObsListener m_new_msgtype_lstnr;
302
303 ObsListener m_on_msg_sent_listener;
304
305 std::unordered_map<std::string, ObsListener> m_0183_listeners;
306
307 wxBitmap* BuildDimmedToolBitmap(wxBitmap* pbmp_normal,
308 unsigned char dim_ratio);
309
310 void ProcessLateInit(const PlugInContainer* pic);
311 void OnPluginActivate(const PlugInContainer* pic);
312 void OnPluginDeactivate(const PlugInContainer* pic);
313 void HandlePluginLoaderEvents();
314 void HandlePluginHandlerEvents();
315
316 MyFrame* pParent;
317 std::unique_ptr<BlacklistUI> m_blacklist_ui;
318
319 wxString m_last_error_string;
320
321 ArrayOfPlugInMenuItems m_PlugInMenuItems;
322 ArrayOfPlugInToolbarTools m_PlugInToolbarTools;
323
324 wxString m_plugin_location;
325
326 int m_plugin_tool_id_next;
327 int m_plugin_menu_item_id_next;
328 wxBitmap m_cached_overlay_bm;
329
330 wxArrayString m_plugin_order;
331 void SetPluginOrder(wxString serialized_names);
332 wxString GetPluginOrder();
333
334 pluginUtilHandler* m_utilHandler;
335 PluginListPanel* m_listPanel;
336 std::unique_ptr<AbstractBlacklist> m_blacklist;
337
338#ifndef __ANDROID__
339#ifdef OCPN_USE_CURL
340
341public:
342 wxCurlDownloadThread* m_pCurlThread;
343 // The libcurl handle being re used for the transfer.
344 std::shared_ptr<wxCurlBase> m_pCurl;
345
346 // returns true if the error can be ignored
347 bool HandleCurlThreadError(wxCurlThreadError err, wxCurlBaseThread* p,
348 const wxString& url = wxEmptyString);
349 void OnEndPerformCurlDownload(wxCurlEndPerformEvent& ev);
350 void OnCurlDownload(wxCurlDownloadEvent& ev);
351
352 wxEvtHandler* m_download_evHandler;
353 long* m_downloadHandle;
354 bool m_last_online;
355 long m_last_online_chk;
356#endif
357#endif
358
359 DECLARE_EVENT_TABLE()
360};
361
362WX_DEFINE_ARRAY_PTR(PluginPanel*, ArrayOfPluginPanel);
363
364/*
365 * Panel with a single + sign which opens the "Add/download plugins" dialog.
366 */
367class AddPluginPanel : public wxPanel {
368public:
369 AddPluginPanel(wxWindow* parent);
370 void OnClick(wxMouseEvent& event);
372
373protected:
374 wxBitmap m_bitmap;
375 wxStaticBitmap* m_staticBitmap;
376 wxWindow* m_parent;
377};
378
379/*
380 * Panel with buttons to control plugin catalog management.
381 */
382class CatalogMgrPanel : public wxPanel {
383public:
384 CatalogMgrPanel(wxWindow* parent);
386 void OnUpdateButton(wxCommandEvent& event);
387 void SetListPanelPtr(PluginListPanel* listPanel) {
388 m_PluginListPanel = listPanel;
389 }
390 void OnTarballButton(wxCommandEvent& event);
391 void OnPluginSettingsButton(wxCommandEvent& event);
392
393protected:
394 wxString GetCatalogText(bool);
395 void SetUpdateButtonLabel();
396 wxString GetImportInitDir();
397
398 wxButton *m_updateButton, *m_advancedButton, *m_tarballButton;
399 wxButton* m_adv_button;
400 wxStaticText* m_catalogText;
401 wxWindow* m_parent;
402 PluginListPanel* m_PluginListPanel;
403 ObservableListener catalog_listener;
404};
405
406#define ID_CMD_BUTTON_PERFORM_ACTION 27663
407
408class PluginListPanel : public wxScrolledWindow {
409 DECLARE_EVENT_TABLE()
410
411public:
412 PluginListPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos,
413 const wxSize& size);
415
416 void SelectPlugin(PluginPanel* pi);
417 void MoveUp(PluginPanel* pi);
418 void MoveDown(PluginPanel* pi);
419 void UpdateSelections();
420 void UpdatePluginsOrder();
421
423 void ReloadPluginPanels();
424 void SelectByName(wxString& name);
425
426private:
427 void AddPlugin(const PlugInData& pd);
428 void AddPlugin(const std::string& name);
429 int ComputePluginSpace(ArrayOfPluginPanel plugins, wxBoxSizer* sizer);
430 // void Clear();
431
432 ArrayOfPluginPanel m_PluginItems;
433 PluginPanel* m_PluginSelected;
434 wxString m_selectedName;
435 int m_pluginSpacer;
436 std::atomic_flag m_is_loading;
437};
438
440class WebsiteButton : public wxPanel {
441public:
442 WebsiteButton(wxWindow* parent, const char* url);
443 ~WebsiteButton() {};
444 void SetURL(std::string url) { m_url = url; }
445
446protected:
447 std::string m_url;
448};
449
450class PluginPanel : public wxPanel {
451 DECLARE_EVENT_TABLE()
452
453
454public:
456 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
457 const wxSize& size, const PlugInData plugin);
458
460 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
461 const wxSize& size, PluginMetadata plugin);
462
464 PluginPanel(wxPanel* parent, const std::string& name);
465
466 ~PluginPanel();
467
468 void OnPluginSelected(wxMouseEvent& event);
469 void OnPluginSelectedUp(wxMouseEvent& event);
470 void DoPluginSelect();
471
472 void SetSelected(bool selected);
473 void OnPluginPreferences(wxCommandEvent& event);
474 void OnPluginEnableToggle(wxCommandEvent& event);
475 void OnPluginAction(wxCommandEvent& event);
476 void OnPluginUninstall(wxCommandEvent& event);
477 void OnPluginUp(wxCommandEvent& event);
478 void OnPluginDown(wxCommandEvent& event);
479 void SetEnabled(bool enabled);
480 bool GetSelected() { return m_bSelected; }
481 const PlugInData* GetPluginPtr() { return &m_plugin; };
482 void SetActionLabel(wxString& label);
483 ActionVerb GetAction() { return m_action; }
484 const PlugInData* GetPlugin() { return &m_plugin; }
485 void OnPaint(wxPaintEvent& event);
486
487private:
488 PluginListPanel* m_PluginListPanel;
489 bool m_bSelected;
490 const PlugInData m_plugin;
491 wxStaticText* m_pName;
492 wxStaticText* m_pVersion;
493 wxStaticText* m_pDescription;
494 wxBoxSizer* m_pButtons;
495 wxStaticBitmap* m_itemStaticBitmap;
496 wxStaticBitmap* m_itemStatusIconBitmap;
497 wxButton* m_pButtonPreferences;
498 wxButton *m_pButtonAction, *m_pButtonUninstall;
499
500 wxCheckBox* m_cbEnable;
501 WebsiteButton* m_info_btn;
502 ActionVerb m_action;
503 int m_penWidthUnselected, m_penWidthSelected;
504 bool m_is_safe_panel;
505};
506
507// API 1.11 adds access to S52 Presentation library
508// These are some wrapper conversion utilities
509
511public:
513 bBBObj_valid = false;
514 bCS_Added = false;
515 bFText_Added = false;
516 CSrules = NULL;
517 FText = NULL;
518 ChildRazRules = NULL;
519 MPSRulesList = NULL;
520 LUP = NULL;
521 };
522
523 ~S52PLIB_Context() {};
524
525 BoundingBox BBObj; // lat/lon BBox of the rendered object
526 bool bBBObj_valid; // set after the BBObj has been calculated once.
527
528 Rules* CSrules; // per object conditional symbology
529 int bCS_Added;
530
531 S52_TextC* FText;
532 int bFText_Added;
533 wxRect rText;
534
535 LUPrec* LUP;
536 ObjRazRules* ChildRazRules;
537 mps_container* MPSRulesList;
538};
539
540void CreateCompatibleS57Object(PI_S57Obj* pObj, S57Obj* cobj,
541 chart_context* pctx);
542void UpdatePIObjectPlibContext(PI_S57Obj* pObj, S57Obj* cobj);
543
544#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.