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 <wx/wx.h>
31#include <wx/dynarray.h>
32#include <wx/dynlib.h>
33
34#include <memory>
35
36#include "config.h"
37
38#include "ocpn_plugin.h"
39//#include "chcanv.h" // for ViewPort
40#include "OCPN_Sound.h"
41#include "chartimg.h"
42#include "catalog_parser.h"
43#include "plugin_blacklist.h"
44#include "observable.h"
45#include "ais_target_data.h"
46#include "comm_navmsg.h"
47#include "s57chart.h" // for Object list
48#include "semantic_vers.h"
49
50// For widgets...
51#include <wx/hyperlink.h>
52#include <wx/choice.h>
53#include <wx/tglbtn.h>
54#include <wx/bmpcbox.h>
55
56#ifndef __OCPN__ANDROID__
57#ifdef OCPN_USE_CURL
58#include <wx/curl/http.h>
59#include <wx/curl/dialog.h>
60#endif
61#endif
62
63// Include wxJSON headers
64// We undefine MIN/MAX so avoid warning of redefinition coming from
65// json_defs.h
66// Definitions checked manually, and are identical
67#ifdef MIN
68#undef MIN
69#endif
70
71#ifdef MAX
72#undef MAX
73#endif
74
75#include <wx/json_defs.h>
76#include <wx/jsonwriter.h>
77#include "plugin_loader.h"
78
79// Assorted static helper routines
80
81PlugIn_AIS_Target *Create_PI_AIS_Target(AisTargetData *ptarget);
82
83class PluginListPanel;
84class PluginPanel;
86class MyFrame;
87
88//----------------------------------------------------------------------------
89// PlugIn Messaging scheme Event
90//----------------------------------------------------------------------------
91
92class OCPN_MsgEvent : public wxEvent {
93public:
94 OCPN_MsgEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
95
96 OCPN_MsgEvent(const OCPN_MsgEvent &event)
97 : wxEvent(event),
98 m_MessageID(event.m_MessageID),
99 m_MessageText(event.m_MessageText) {}
100
102
103 // accessors
104 wxString GetID() { return m_MessageID; }
105 wxString GetJSONText() { return m_MessageText; }
106
107 void SetID(const wxString &string) { m_MessageID = string; }
108 void SetJSONText(const wxString &string) { m_MessageText = string; }
109
110 // required for sending with wxPostEvent()
111 wxEvent *Clone() const;
112
113private:
114 wxString m_MessageID;
115 wxString m_MessageText;
116};
117
118extern const wxEventType wxEVT_OCPN_MSG;
119
120enum ActionVerb {
121 NOP = 0,
122 UPGRADE_TO_MANAGED_VERSION,
123 UPGRADE_INSTALLED_MANAGED_VERSION,
124 REINSTALL_MANAGED_VERSION,
125 DOWNGRADE_INSTALLED_MANAGED_VERSION,
126 UNINSTALL_MANAGED_VERSION,
127 INSTALL_MANAGED_VERSION
128};
129
130
132public:
133 wxMenuItem *pmenu_item;
134 opencpn_plugin *m_pplugin;
135 bool b_viz;
136 bool b_grey;
137 int id;
138 wxString m_in_menu;
139};
140
141// Define an array of PlugIn MenuItem Containers
142WX_DEFINE_ARRAY_PTR(PlugInMenuItemContainer *, ArrayOfPlugInMenuItems);
143
145public:
148
149 opencpn_plugin *m_pplugin;
150 int id;
151 wxString label;
152 wxBitmap *bitmap_day;
153 wxBitmap *bitmap_dusk;
154 wxBitmap *bitmap_night;
155 wxBitmap *bitmap_Rollover_day;
156 wxBitmap *bitmap_Rollover_dusk;
157 wxBitmap *bitmap_Rollover_night;
158
159 wxItemKind kind;
160 wxString shortHelp;
161 wxString longHelp;
162 wxObject *clientData;
163 int position;
164 bool b_viz;
165 bool b_toggle;
166 int tool_sel;
167 wxString pluginNormalIconSVG;
168 wxString pluginRolloverIconSVG;
169 wxString pluginToggledIconSVG;
170};
171
172// Define an array of PlugIn ToolbarTool Containers
173WX_DEFINE_ARRAY_PTR(PlugInToolbarToolContainer *, ArrayOfPlugInToolbarTools);
174
175//-----------------------------------------------------------------------------------------------------
176//
177// The PlugIn Manager Specification
178//
179//-----------------------------------------------------------------------------------------------------
180
181class BlacklistUI;
182
183class PlugInManager : public wxEvtHandler {
184public:
185 PlugInManager(MyFrame *parent);
186 virtual ~PlugInManager();
187
188 bool RenderAllCanvasOverlayPlugIns(ocpnDC &dc, const ViewPort &vp,
189 int canvasIndex, int priority);
190 bool RenderAllGLCanvasOverlayPlugIns(wxGLContext *pcontext,
191 const ViewPort &vp, int canvasIndex,
192 int priority);
193 void SendCursorLatLonToAllPlugIns(double lat, double lon);
194 void SendViewPortToRequestingPlugIns(ViewPort &vp);
195 void PrepareAllPluginContextMenus();
196
197 void NotifySetupOptions();
198 void ClosePlugInPanel(PlugInContainer *pic, int ix);
199 void CloseAllPlugInPanels(int);
200
201 ArrayOfPlugInToolbarTools &GetPluginToolbarToolArray() {
202 return m_PlugInToolbarTools;
203 }
204 int AddToolbarTool(wxString label, wxBitmap *bitmap, wxBitmap *bmpRollover,
205 wxItemKind kind, wxString shortHelp, wxString longHelp,
206 wxObject *clientData, int position, int tool_sel,
207 opencpn_plugin *pplugin);
208
209 void RemoveToolbarTool(int tool_id);
210 void SetToolbarToolViz(int tool_id, bool viz);
211 void SetToolbarItemState(int tool_id, bool toggle);
212 void SetToolbarItemBitmaps(int item, wxBitmap *bitmap, wxBitmap *bmpDisabled);
213
214 int AddToolbarTool(wxString label, wxString SVGfile, wxString SVGRolloverfile,
215 wxString SVGToggledfile, wxItemKind kind,
216 wxString shortHelp, wxString longHelp,
217 wxObject *clientData, int position, int tool_sel,
218 opencpn_plugin *pplugin);
219
220 void SetToolbarItemBitmaps(int item, wxString SVGfile,
221 wxString SVGfileRollover, wxString SVGfileToggled);
222
223 opencpn_plugin *FindToolOwner(const int id);
224 wxString GetToolOwnerCommonName(const int id);
225 void ShowDeferredBlacklistMessages();
226
227 ArrayOfPlugInMenuItems &GetPluginContextMenuItemArray() {
228 return m_PlugInMenuItems;
229 }
230 int AddCanvasContextMenuItem(wxMenuItem *pitem, opencpn_plugin *pplugin,
231 const char *name = "");
232 void RemoveCanvasContextMenuItem(int item, const char *name = "");
233 void SetCanvasContextMenuItemViz(int item, bool viz, const char *name = "");
234 void SetCanvasContextMenuItemGrey(int item, bool grey, const char *name = "");
235
236 void SendNMEASentenceToAllPlugIns(const wxString &sentence);
237 void SendPositionFixToAllPlugIns(GenericPosDatEx *ppos);
238 void SendActiveLegInfoToAllPlugIns(const ActiveLegDat *infos);
239 void SendAISSentenceToAllPlugIns(const wxString &sentence);
240 void SendJSONMessageToAllPlugins(const wxString &message_id, wxJSONValue v);
241 void SendMessageToAllPlugins(const wxString &message_id,
242 const wxString &message_body);
243 bool UpDateChartDataTypes();
244 void FinalizePluginLoadall();
245
246 int GetJSONMessageTargetCount();
247 bool UpdateConfig();
248 void SendResizeEventToAllPlugIns(int x, int y);
249 void SetColorSchemeForAllPlugIns(ColorScheme cs);
250 void NotifyAuiPlugIns(void);
251 bool CallLateInit(void);
252
253 bool IsAnyPlugInChartEnabled();
254
255 void SendVectorChartObjectInfo(const wxString &chart, const wxString &feature,
256 const wxString &objname, double &lat,
257 double &lon, double &scale, int &nativescale);
258
259 bool SendMouseEventToPlugins(wxMouseEvent &event);
260 bool SendKeyEventToPlugins(wxKeyEvent &event);
261
262 void SendBaseConfigToAllPlugIns();
263 void SendS52ConfigToAllPlugIns(bool bReconfig = false);
264 void SendSKConfigToAllPlugIns();
265
266 void UpdateManagedPlugins();
267 bool CheckBlacklistedPlugin(const PluginMetadata plugin);
268
269 void InitCommListeners(void);
270 void HandleN0183( std::shared_ptr <const Nmea0183Msg> n0183_msg );
271 void HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg);
272
273 wxArrayString GetPlugInChartClassNameArray(void);
274
275 ListOfPI_S57Obj *GetPlugInObjRuleListAtLatLon(ChartPlugInWrapper *target,
276 float zlat, float zlon,
277 float SelectRadius,
278 const ViewPort &vp);
279 wxString CreateObjDescriptions(ChartPlugInWrapper *target,
280 ListOfPI_S57Obj *rule_list);
281
282 wxString GetLastError();
283 MyFrame *GetParentFrame() { return pParent; }
284
285 void DimeWindow(wxWindow *win);
286 pluginUtilHandler *GetUtilHandler() { return m_utilHandler; }
287 void SetListPanelPtr(PluginListPanel *ptr) { m_listPanel = ptr; }
288
289 ListOfPI_S57Obj *GetLightsObjRuleListVisibleAtLatLon(
290 ChartPlugInWrapper *target, float zlat, float zlon, const ViewPort &vp);
291
292private:
293 bool CheckBlacklistedPlugin(wxString name, int major, int minor);
294 bool CheckBlacklistedPlugin(opencpn_plugin *plugin);
295
296 ObservableListener evt_ais_json_listener;
297 ObservableListener evt_blacklisted_plugin_listener;
298 ObservableListener evt_deactivate_plugin_listener;
299 ObservableListener evt_download_failed_listener;
300 ObservableListener evt_download_ok_listener;
301 ObservableListener evt_incompatible_plugin_listener;
302 ObservableListener evt_load_directory_listener;
303 ObservableListener evt_load_plugin_listener;
304 ObservableListener evt_plugin_loadall_finalize_listener;
305 ObservableListener evt_pluglist_change_listener;
306 ObservableListener evt_unreadable_plugin_listener;
307 ObservableListener evt_update_chart_types_listener;
308 ObservableListener evt_version_incompatible_listener;
309 ObservableListener evt_version_incompatible_plugin_listener;
310 ObservableListener evt_json_to_all_plugins_listener;
311 ObservableListener evt_routeman_json_listener;
312 ObservableListener evt_routeman_leginfo_listener;
313
314 ObservableListener m_listener_N0183_all;
315 ObservableListener m_listener_SignalK;
316
317 wxBitmap *BuildDimmedToolBitmap(wxBitmap *pbmp_normal,
318 unsigned char dim_ratio);
319
320 void ProcessLateInit(PlugInContainer *pic);
321 void OnPluginDeactivate(const PlugInContainer* pic);
322 void HandlePluginLoaderEvents();
323 void HandlePluginHandlerEvents();
324
325 MyFrame *pParent;
326 std::unique_ptr<BlacklistUI> m_blacklist_ui;
327
328 wxString m_last_error_string;
329
330 ArrayOfPlugInMenuItems m_PlugInMenuItems;
331 ArrayOfPlugInToolbarTools m_PlugInToolbarTools;
332
333 wxString m_plugin_location;
334
335 int m_plugin_tool_id_next;
336 int m_plugin_menu_item_id_next;
337 wxBitmap m_cached_overlay_bm;
338
339 wxArrayString m_plugin_order;
340 void SetPluginOrder(wxString serialized_names);
341 wxString GetPluginOrder();
342
343 pluginUtilHandler *m_utilHandler;
344 PluginListPanel *m_listPanel;
345 std::unique_ptr<AbstractBlacklist> m_blacklist;
346
347#ifndef __OCPN__ANDROID__
348#ifdef OCPN_USE_CURL
349
350public:
351 wxCurlDownloadThread *m_pCurlThread;
352 // The libcurl handle being re used for the transfer.
353 std::shared_ptr<wxCurlBase> m_pCurl;
354
355 // returns true if the error can be ignored
356 bool HandleCurlThreadError(wxCurlThreadError err, wxCurlBaseThread *p,
357 const wxString &url = wxEmptyString);
358 void OnEndPerformCurlDownload(wxCurlEndPerformEvent &ev);
359 void OnCurlDownload(wxCurlDownloadEvent &ev);
360
361 wxEvtHandler *m_download_evHandler;
362 long *m_downloadHandle;
363 bool m_last_online;
364 long m_last_online_chk;
365#endif
366#endif
367
368 DECLARE_EVENT_TABLE()
369};
370
371WX_DEFINE_ARRAY_PTR(PluginPanel *, ArrayOfPluginPanel);
372
374
375/*
376 * Panel with a single + sign which opens the "Add/download plugins" dialog.
377 */
378class AddPluginPanel : public wxPanel {
379public:
380 AddPluginPanel(wxWindow *parent);
381 void OnClick(wxMouseEvent &event);
383
384protected:
385 wxBitmap m_bitmap;
386 wxStaticBitmap *m_staticBitmap;
387 wxWindow *m_parent;
388};
389
390/*
391 * Panel with buttons to control plugin catalog management.
392 */
393class CatalogMgrPanel : public wxPanel {
394public:
395 CatalogMgrPanel(wxWindow *parent);
397 void OnUpdateButton(wxCommandEvent &event);
398 void SetListPanelPtr(PluginListPanel *listPanel) {
399 m_PluginListPanel = listPanel;
400 }
401 void OnTarballButton(wxCommandEvent &event);
402 void OnPluginSettingsButton(wxCommandEvent &event);
403
404protected:
405 wxString GetCatalogText(bool);
406 void SetUpdateButtonLabel();
407 wxString GetImportInitDir();
408
409 wxButton *m_updateButton, *m_advancedButton, *m_tarballButton;
410 wxButton *m_adv_button;
411 wxStaticText *m_catalogText;
412 wxWindow *m_parent;
413 PluginListPanel *m_PluginListPanel;
414 ObservableListener catalog_listener;
415};
416
417#define ID_CMD_BUTTON_PERFORM_ACTION 27663
418
419class PluginListPanel : public wxScrolledWindow {
420 DECLARE_EVENT_TABLE()
421
422public:
423 PluginListPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos,
424 const wxSize &size, ArrayOfPlugIns *pPluginArray);
426
427 void SelectPlugin(PluginPanel *pi);
428 void MoveUp(PluginPanel *pi);
429 void MoveDown(PluginPanel *pi);
430 void UpdateSelections();
431 void UpdatePluginsOrder();
432
434 void ReloadPluginPanels();
435 void SelectByName(wxString &name);
436
437private:
438 void AddPlugin(PlugInContainer *pic);
439 int ComputePluginSpace(ArrayOfPluginPanel plugins, wxBoxSizer *sizer);
440 // void Clear();
441
442 ArrayOfPlugIns *m_pPluginArray;
443 ArrayOfPluginPanel m_PluginItems;
444 PluginPanel *m_PluginSelected;
445 wxString m_selectedName;
446 int m_pluginSpacer;
447};
448
450class WebsiteButton : public wxPanel {
451public:
452 WebsiteButton(wxWindow *parent, const char *url);
453 ~WebsiteButton(){};
454 void SetURL(std::string url) { m_url = url; }
455
456protected:
457 std::string m_url;
458};
459
460class PluginPanel : public wxPanel {
461 DECLARE_EVENT_TABLE()
462
463public:
464 PluginPanel(wxPanel *parent, wxWindowID id, const wxPoint &pos,
465 const wxSize &size, PlugInContainer *p_plugin);
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 PlugInContainer *GetPluginPtr() { return m_pPlugin; };
482 void SetActionLabel(wxString &label);
483 ActionVerb GetAction() { return m_action; }
484 PlugInContainer *GetPlugin() { return m_pPlugin; }
485 void OnPaint(wxPaintEvent &event);
486
487private:
488 PluginListPanel *m_PluginListPanel;
489 bool m_bSelected;
490 PlugInContainer *m_pPlugin;
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};
505
506// API 1.11 adds access to S52 Presentation library
507// These are some wrapper conversion utilities
508
510public:
512 bBBObj_valid = false;
513 bCS_Added = false;
514 bFText_Added = false;
515 CSrules = NULL;
516 FText = NULL;
517 ChildRazRules = NULL;
518 MPSRulesList = NULL;
519 LUP = NULL;
520 };
521
523
524 BoundingBox BBObj; // lat/lon BBox of the rendered object
525 bool bBBObj_valid; // set after the BBObj has been calculated once.
526
527 Rules *CSrules; // per object conditional symbology
528 int bCS_Added;
529
530 S52_TextC *FText;
531 int bFText_Added;
532 wxRect rText;
533
534 LUPrec *LUP;
535 ObjRazRules *ChildRazRules;
536 mps_container *MPSRulesList;
537};
538
539void CreateCompatibleS57Object(PI_S57Obj *pObj, S57Obj *cobj,
540 chart_context *pctx);
541void UpdatePIObjectPlibContext(PI_S57Obj *pObj, S57Obj *cobj);
542
543#endif // _PLUGINMGR_H_
Handle messages for blacklisted plugins.
Keeps listening over it's lifespan, removes itself on destruction.
Definition: observable.h:143
void ReloadPluginPanels()
Complete reload from plugins array.
Invokes client browser on plugin info_url when clicked.
Definition: ocpndc.h:55
Plugin metadata, reflects the xml format directly.
Definition: Quilt.cpp:864