OpenCPN Partial API docs
Loading...
Searching...
No Matches
pluginmanager.h
1/***************************************************************************
2 *
3 *
4 * Project: OpenCPN
5 * Purpose: PlugIn Manager Object
6 * Author: David Register
7 *
8 ***************************************************************************
9 * Copyright (C) 2010 by David S. Register *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 **************************************************************************/
26
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};
127
128// Define an array of PlugIn MenuItem Containers
129WX_DEFINE_ARRAY_PTR(PlugInMenuItemContainer*, ArrayOfPlugInMenuItems);
130
132public:
135
136 opencpn_plugin* m_pplugin;
137 int id;
138 wxString label;
139 wxBitmap* bitmap_day;
140 wxBitmap* bitmap_dusk;
141 wxBitmap* bitmap_night;
142 wxBitmap* bitmap_Rollover_day;
143 wxBitmap* bitmap_Rollover_dusk;
144 wxBitmap* bitmap_Rollover_night;
145
146 wxItemKind kind;
147 wxString shortHelp;
148 wxString longHelp;
149 wxObject* clientData;
150 int position;
151 bool b_viz;
152 bool b_toggle;
153 int tool_sel;
154 wxString pluginNormalIconSVG;
155 wxString pluginRolloverIconSVG;
156 wxString pluginToggledIconSVG;
157};
158
159// Define an array of PlugIn ToolbarTool Containers
160WX_DEFINE_ARRAY_PTR(PlugInToolbarToolContainer*, ArrayOfPlugInToolbarTools);
161
162//-----------------------------------------------------------------------------------------------------
163//
164// The PlugIn Manager Specification
165//
166//-----------------------------------------------------------------------------------------------------
167
168class BlacklistUI;
169
170class PlugInManager : public wxEvtHandler {
171public:
172 PlugInManager(MyFrame* parent);
173 virtual ~PlugInManager();
174
175 bool RenderAllCanvasOverlayPlugIns(ocpnDC& dc, const ViewPort& vp,
176 int canvasIndex, int priority);
177 bool RenderAllGLCanvasOverlayPlugIns(wxGLContext* pcontext,
178 const ViewPort& vp, int canvasIndex,
179 int priority);
180 // void SendCursorLatLonToAllPlugIns(double lat, double lon);
181 void SendViewPortToRequestingPlugIns(ViewPort& vp);
182 void PrepareAllPluginContextMenus();
183
184 void NotifySetupOptions();
185 void ClosePlugInPanel(const PlugInContainer* pic, int ix);
186 void CloseAllPlugInPanels(int);
187
188 ArrayOfPlugInToolbarTools& GetPluginToolbarToolArray() {
189 return m_PlugInToolbarTools;
190 }
191 int AddToolbarTool(wxString label, wxBitmap* bitmap, wxBitmap* bmpRollover,
192 wxItemKind kind, wxString shortHelp, wxString longHelp,
193 wxObject* clientData, int position, int tool_sel,
194 opencpn_plugin* pplugin);
195
196 void RemoveToolbarTool(int tool_id);
197 void SetToolbarToolViz(int tool_id, bool viz);
198 void SetToolbarItemState(int tool_id, bool toggle);
199 void SetToolbarItemBitmaps(int item, wxBitmap* bitmap, wxBitmap* bmpDisabled);
200
201 int AddToolbarTool(wxString label, wxString SVGfile, wxString SVGRolloverfile,
202 wxString SVGToggledfile, wxItemKind kind,
203 wxString shortHelp, wxString longHelp,
204 wxObject* clientData, int position, int tool_sel,
205 opencpn_plugin* pplugin);
206
207 void SetToolbarItemBitmaps(int item, wxString SVGfile,
208 wxString SVGfileRollover, wxString SVGfileToggled);
209
210 opencpn_plugin* FindToolOwner(const int id);
211 wxString GetToolOwnerCommonName(const int id);
212 void ShowDeferredBlacklistMessages();
213
214 ArrayOfPlugInMenuItems& GetPluginContextMenuItemArray() {
215 return m_PlugInMenuItems;
216 }
217 int AddCanvasContextMenuItem(wxMenuItem* pitem, opencpn_plugin* pplugin,
218 const char* name = "");
219 void RemoveCanvasContextMenuItem(int item, const char* name = "");
220 void SetCanvasContextMenuItemViz(int item, bool viz, const char* name = "");
221 void SetCanvasContextMenuItemGrey(int item, bool grey, const char* name = "");
222
223 bool UpDateChartDataTypes();
224 void FinalizePluginLoadall();
225
226 bool UpdateConfig();
227 void SendResizeEventToAllPlugIns(int x, int y);
228 void SetColorSchemeForAllPlugIns(ColorScheme cs);
229 void NotifyAuiPlugIns(void);
230 bool CallLateInit(void);
231
232 bool IsAnyPlugInChartEnabled();
233
234 void SendBaseConfigToAllPlugIns();
235 void SendS52ConfigToAllPlugIns(bool bReconfig = false);
236 void SendSKConfigToAllPlugIns();
237
238 void UpdateManagedPlugins();
239 bool CheckBlacklistedPlugin(const PluginMetadata plugin);
240
241 void InitCommListeners(void);
249 void HandleN0183(std::shared_ptr<const Nmea0183Msg> n0183_msg);
257 void HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg);
258
259 wxArrayString GetPlugInChartClassNameArray(void);
260
261 ListOfPI_S57Obj* GetPlugInObjRuleListAtLatLon(ChartPlugInWrapper* target,
262 float zlat, float zlon,
263 float SelectRadius,
264 const ViewPort& vp);
265 wxString CreateObjDescriptions(ChartPlugInWrapper* target,
266 ListOfPI_S57Obj* rule_list);
267
268 wxString GetLastError();
269 MyFrame* GetParentFrame() { return pParent; }
270
271 void DimeWindow(wxWindow* win);
272 pluginUtilHandler* GetUtilHandler() { return m_utilHandler; }
273 void SetListPanelPtr(PluginListPanel* ptr) { m_listPanel = ptr; }
274
275 ListOfPI_S57Obj* GetLightsObjRuleListVisibleAtLatLon(
276 ChartPlugInWrapper* target, float zlat, float zlon, const ViewPort& vp);
277
278private:
279 bool CheckBlacklistedPlugin(wxString name, int major, int minor);
280 bool CheckBlacklistedPlugin(opencpn_plugin* plugin);
281
282 ObservableListener evt_ais_json_listener;
283 ObservableListener evt_blacklisted_plugin_listener;
284 ObservableListener evt_download_failed_listener;
285 ObservableListener evt_download_ok_listener;
286 ObservableListener evt_load_directory_listener;
287 ObservableListener evt_load_plugin_listener;
288 ObservableListener evt_plugin_loadall_finalize_listener;
289 ObservableListener evt_pluglist_change_listener;
290 ObservableListener evt_update_chart_types_listener;
291 ObservableListener evt_json_to_all_plugins_listener;
292 ObservableListener evt_routeman_json_listener;
293 ObservableListener evt_routeman_leginfo_listener;
294
295 ObservableListener m_listener_N0183_all;
296 ObservableListener m_listener_SignalK;
297
298 ObsListener m_on_msg_sent_listener;
299
300 wxBitmap* BuildDimmedToolBitmap(wxBitmap* pbmp_normal,
301 unsigned char dim_ratio);
302
303 void ProcessLateInit(const PlugInContainer* pic);
304 void OnPluginDeactivate(const PlugInContainer* pic);
305 void HandlePluginLoaderEvents();
306 void HandlePluginHandlerEvents();
307
308 MyFrame* pParent;
309 std::unique_ptr<BlacklistUI> m_blacklist_ui;
310
311 wxString m_last_error_string;
312
313 ArrayOfPlugInMenuItems m_PlugInMenuItems;
314 ArrayOfPlugInToolbarTools m_PlugInToolbarTools;
315
316 wxString m_plugin_location;
317
318 int m_plugin_tool_id_next;
319 int m_plugin_menu_item_id_next;
320 wxBitmap m_cached_overlay_bm;
321
322 wxArrayString m_plugin_order;
323 void SetPluginOrder(wxString serialized_names);
324 wxString GetPluginOrder();
325
326 pluginUtilHandler* m_utilHandler;
327 PluginListPanel* m_listPanel;
328 std::unique_ptr<AbstractBlacklist> m_blacklist;
329
330#ifndef __OCPN__ANDROID__
331#ifdef OCPN_USE_CURL
332
333public:
334 wxCurlDownloadThread* m_pCurlThread;
335 // The libcurl handle being re used for the transfer.
336 std::shared_ptr<wxCurlBase> m_pCurl;
337
338 // returns true if the error can be ignored
339 bool HandleCurlThreadError(wxCurlThreadError err, wxCurlBaseThread* p,
340 const wxString& url = wxEmptyString);
341 void OnEndPerformCurlDownload(wxCurlEndPerformEvent& ev);
342 void OnCurlDownload(wxCurlDownloadEvent& ev);
343
344 wxEvtHandler* m_download_evHandler;
345 long* m_downloadHandle;
346 bool m_last_online;
347 long m_last_online_chk;
348#endif
349#endif
350
351 DECLARE_EVENT_TABLE()
352};
353
354WX_DEFINE_ARRAY_PTR(PluginPanel*, ArrayOfPluginPanel);
355
356/*
357 * Panel with a single + sign which opens the "Add/download plugins" dialog.
358 */
359class AddPluginPanel : public wxPanel {
360public:
361 AddPluginPanel(wxWindow* parent);
362 void OnClick(wxMouseEvent& event);
364
365protected:
366 wxBitmap m_bitmap;
367 wxStaticBitmap* m_staticBitmap;
368 wxWindow* m_parent;
369};
370
371/*
372 * Panel with buttons to control plugin catalog management.
373 */
374class CatalogMgrPanel : public wxPanel {
375public:
376 CatalogMgrPanel(wxWindow* parent);
378 void OnUpdateButton(wxCommandEvent& event);
379 void SetListPanelPtr(PluginListPanel* listPanel) {
380 m_PluginListPanel = listPanel;
381 }
382 void OnTarballButton(wxCommandEvent& event);
383 void OnPluginSettingsButton(wxCommandEvent& event);
384
385protected:
386 wxString GetCatalogText(bool);
387 void SetUpdateButtonLabel();
388 wxString GetImportInitDir();
389
390 wxButton *m_updateButton, *m_advancedButton, *m_tarballButton;
391 wxButton* m_adv_button;
392 wxStaticText* m_catalogText;
393 wxWindow* m_parent;
394 PluginListPanel* m_PluginListPanel;
395 ObservableListener catalog_listener;
396};
397
398#define ID_CMD_BUTTON_PERFORM_ACTION 27663
399
400class PluginListPanel : public wxScrolledWindow {
401 DECLARE_EVENT_TABLE()
402
403public:
404 PluginListPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos,
405 const wxSize& size);
407
408 void SelectPlugin(PluginPanel* pi);
409 void MoveUp(PluginPanel* pi);
410 void MoveDown(PluginPanel* pi);
411 void UpdateSelections();
412 void UpdatePluginsOrder();
413
415 void ReloadPluginPanels();
416 void SelectByName(wxString& name);
417
418private:
419 void AddPlugin(const PlugInData& pd);
420 void AddPlugin(const std::string& name);
421 int ComputePluginSpace(ArrayOfPluginPanel plugins, wxBoxSizer* sizer);
422 // void Clear();
423
424 ArrayOfPluginPanel m_PluginItems;
425 PluginPanel* m_PluginSelected;
426 wxString m_selectedName;
427 int m_pluginSpacer;
428 std::atomic_flag m_is_loading;
429};
430
432class WebsiteButton : public wxPanel {
433public:
434 WebsiteButton(wxWindow* parent, const char* url);
435 ~WebsiteButton() {};
436 void SetURL(std::string url) { m_url = url; }
437
438protected:
439 std::string m_url;
440};
441
442class PluginPanel : public wxPanel {
443 DECLARE_EVENT_TABLE()
444
445
446public:
448 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
449 const wxSize& size, const PlugInData plugin);
450
452 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
453 const wxSize& size, PluginMetadata plugin);
454
456 PluginPanel(wxPanel* parent, const std::string& name);
457
458 ~PluginPanel();
459
460 void OnPluginSelected(wxMouseEvent& event);
461 void OnPluginSelectedUp(wxMouseEvent& event);
462 void DoPluginSelect();
463
464 void SetSelected(bool selected);
465 void OnPluginPreferences(wxCommandEvent& event);
466 void OnPluginEnableToggle(wxCommandEvent& event);
467 void OnPluginAction(wxCommandEvent& event);
468 void OnPluginUninstall(wxCommandEvent& event);
469 void OnPluginUp(wxCommandEvent& event);
470 void OnPluginDown(wxCommandEvent& event);
471 void SetEnabled(bool enabled);
472 bool GetSelected() { return m_bSelected; }
473 const PlugInData* GetPluginPtr() { return &m_plugin; };
474 void SetActionLabel(wxString& label);
475 ActionVerb GetAction() { return m_action; }
476 const PlugInData* GetPlugin() { return &m_plugin; }
477 void OnPaint(wxPaintEvent& event);
478
479private:
480 PluginListPanel* m_PluginListPanel;
481 bool m_bSelected;
482 const PlugInData m_plugin;
483 wxStaticText* m_pName;
484 wxStaticText* m_pVersion;
485 wxStaticText* m_pDescription;
486 wxBoxSizer* m_pButtons;
487 wxStaticBitmap* m_itemStaticBitmap;
488 wxStaticBitmap* m_itemStatusIconBitmap;
489 wxButton* m_pButtonPreferences;
490 wxButton *m_pButtonAction, *m_pButtonUninstall;
491
492 wxCheckBox* m_cbEnable;
493 WebsiteButton* m_info_btn;
494 ActionVerb m_action;
495 int m_penWidthUnselected, m_penWidthSelected;
496 bool m_is_safe_panel;
497};
498
499// API 1.11 adds access to S52 Presentation library
500// These are some wrapper conversion utilities
501
503public:
505 bBBObj_valid = false;
506 bCS_Added = false;
507 bFText_Added = false;
508 CSrules = NULL;
509 FText = NULL;
510 ChildRazRules = NULL;
511 MPSRulesList = NULL;
512 LUP = NULL;
513 };
514
515 ~S52PLIB_Context() {};
516
517 BoundingBox BBObj; // lat/lon BBox of the rendered object
518 bool bBBObj_valid; // set after the BBObj has been calculated once.
519
520 Rules* CSrules; // per object conditional symbology
521 int bCS_Added;
522
523 S52_TextC* FText;
524 int bFText_Added;
525 wxRect rText;
526
527 LUPrec* LUP;
528 ObjRazRules* ChildRazRules;
529 mps_container* MPSRulesList;
530};
531
532void CreateCompatibleS57Object(PI_S57Obj* pObj, S57Obj* cobj,
533 chart_context* pctx);
534void UpdatePIObjectPlibContext(PI_S57Obj* pObj, S57Obj* cobj);
535
536#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:228
Keeps listening over it's lifespan, removes itself on destruction.
Definition observable.h:131
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.
PlugIn Object Definition/API.
Low level code to load plugins from disk, notably the PluginLoader class.
Plugin metadata, reflects the xml format directly.