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
357
358/*
359 * Panel with a single + sign which opens the "Add/download plugins" dialog.
360 */
361class AddPluginPanel : public wxPanel {
362public:
363 AddPluginPanel(wxWindow* parent);
364 void OnClick(wxMouseEvent& event);
366
367protected:
368 wxBitmap m_bitmap;
369 wxStaticBitmap* m_staticBitmap;
370 wxWindow* m_parent;
371};
372
373/*
374 * Panel with buttons to control plugin catalog management.
375 */
376class CatalogMgrPanel : public wxPanel {
377public:
378 CatalogMgrPanel(wxWindow* parent);
380 void OnUpdateButton(wxCommandEvent& event);
381 void SetListPanelPtr(PluginListPanel* listPanel) {
382 m_PluginListPanel = listPanel;
383 }
384 void OnTarballButton(wxCommandEvent& event);
385 void OnPluginSettingsButton(wxCommandEvent& event);
386
387protected:
388 wxString GetCatalogText(bool);
389 void SetUpdateButtonLabel();
390 wxString GetImportInitDir();
391
392 wxButton *m_updateButton, *m_advancedButton, *m_tarballButton;
393 wxButton* m_adv_button;
394 wxStaticText* m_catalogText;
395 wxWindow* m_parent;
396 PluginListPanel* m_PluginListPanel;
397 ObservableListener catalog_listener;
398};
399
400#define ID_CMD_BUTTON_PERFORM_ACTION 27663
401
402class PluginListPanel : public wxScrolledWindow {
403 DECLARE_EVENT_TABLE()
404
405public:
406 PluginListPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos,
407 const wxSize& size);
409
410 void SelectPlugin(PluginPanel* pi);
411 void MoveUp(PluginPanel* pi);
412 void MoveDown(PluginPanel* pi);
413 void UpdateSelections();
414 void UpdatePluginsOrder();
415
417 void ReloadPluginPanels();
418 void SelectByName(wxString& name);
419
420private:
421 void AddPlugin(const PlugInData& pd);
422 void AddPlugin(const std::string& name);
423 int ComputePluginSpace(ArrayOfPluginPanel plugins, wxBoxSizer* sizer);
424 // void Clear();
425
426 ArrayOfPluginPanel m_PluginItems;
427 PluginPanel* m_PluginSelected;
428 wxString m_selectedName;
429 int m_pluginSpacer;
430 std::atomic_flag m_is_loading;
431};
432
434class WebsiteButton : public wxPanel {
435public:
436 WebsiteButton(wxWindow* parent, const char* url);
437 ~WebsiteButton() {};
438 void SetURL(std::string url) { m_url = url; }
439
440protected:
441 std::string m_url;
442};
443
444class PluginPanel : public wxPanel {
445 DECLARE_EVENT_TABLE()
446
447
448public:
450 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
451 const wxSize& size, const PlugInData plugin);
452
454 PluginPanel(wxPanel* parent, wxWindowID id, const wxPoint& pos,
455 const wxSize& size, PluginMetadata plugin);
456
458 PluginPanel(wxPanel* parent, const std::string& name);
459
460 ~PluginPanel();
461
462 void OnPluginSelected(wxMouseEvent& event);
463 void OnPluginSelectedUp(wxMouseEvent& event);
464 void DoPluginSelect();
465
466 void SetSelected(bool selected);
467 void OnPluginPreferences(wxCommandEvent& event);
468 void OnPluginEnableToggle(wxCommandEvent& event);
469 void OnPluginAction(wxCommandEvent& event);
470 void OnPluginUninstall(wxCommandEvent& event);
471 void OnPluginUp(wxCommandEvent& event);
472 void OnPluginDown(wxCommandEvent& event);
473 void SetEnabled(bool enabled);
474 bool GetSelected() { return m_bSelected; }
475 const PlugInData* GetPluginPtr() { return &m_plugin; };
476 void SetActionLabel(wxString& label);
477 ActionVerb GetAction() { return m_action; }
478 const PlugInData* GetPlugin() { return &m_plugin; }
479 void OnPaint(wxPaintEvent& event);
480
481private:
482 PluginListPanel* m_PluginListPanel;
483 bool m_bSelected;
484 const PlugInData m_plugin;
485 wxStaticText* m_pName;
486 wxStaticText* m_pVersion;
487 wxStaticText* m_pDescription;
488 wxBoxSizer* m_pButtons;
489 wxStaticBitmap* m_itemStaticBitmap;
490 wxStaticBitmap* m_itemStatusIconBitmap;
491 wxButton* m_pButtonPreferences;
492 wxButton *m_pButtonAction, *m_pButtonUninstall;
493
494 wxCheckBox* m_cbEnable;
495 WebsiteButton* m_info_btn;
496 ActionVerb m_action;
497 int m_penWidthUnselected, m_penWidthSelected;
498 bool m_is_safe_panel;
499};
500
501// API 1.11 adds access to S52 Presentation library
502// These are some wrapper conversion utilities
503
505public:
507 bBBObj_valid = false;
508 bCS_Added = false;
509 bFText_Added = false;
510 CSrules = NULL;
511 FText = NULL;
512 ChildRazRules = NULL;
513 MPSRulesList = NULL;
514 LUP = NULL;
515 };
516
517 ~S52PLIB_Context() {};
518
519 BoundingBox BBObj; // lat/lon BBox of the rendered object
520 bool bBBObj_valid; // set after the BBObj has been calculated once.
521
522 Rules* CSrules; // per object conditional symbology
523 int bCS_Added;
524
525 S52_TextC* FText;
526 int bFText_Added;
527 wxRect rText;
528
529 LUPrec* LUP;
530 ObjRazRules* ChildRazRules;
531 mps_container* MPSRulesList;
532};
533
534void CreateCompatibleS57Object(PI_S57Obj* pObj, S57Obj* cobj,
535 chart_context* pctx);
536void UpdatePIObjectPlibContext(PI_S57Obj* pObj, S57Obj* cobj);
537
538#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
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.
Dialog for downloading plugins.
void ReloadPluginPanels()
Complete reload from plugins array.
Represents the view port for chart display in OpenCPN.
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:64
Raw, undecoded messages definitions.
PlugIn Object Definition/API.
Plugin metadata, reflects the xml format directly.