1 /******************************************************************************
2  *
3  * Project:  OpenCPN
4  * Purpose:  GRIB Plugin
5  * Author:   David Register
6  *
7  ***************************************************************************
8  *   Copyright (C) 2010 by David S. Register   *
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program; if not, write to the                         *
22  *   Free Software Foundation, Inc.,                                       *
23  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.             *
24  ***************************************************************************
25  */
26 
27 #ifndef _GRIBPI_H_
28 #define _GRIBPI_H_
29 
30 #include "wx/wxprec.h"
31 
32 #ifndef  WX_PRECOMP
33   #include "wx/wx.h"
34   #include <wx/glcanvas.h>
35 #endif //precompiled headers
36 
37 #define     PLUGIN_VERSION_MAJOR    4
38 #define     PLUGIN_VERSION_MINOR    1
39 
40 #define     MY_API_VERSION_MAJOR    1
41 #define     MY_API_VERSION_MINOR    16
42 
43 #include "../../../include/ocpn_plugin.h"
44 
45 #include "wx/jsonreader.h"
46 #include "wx/jsonwriter.h"
47 
48 #include "GribSettingsDialog.h"
49 #include "GribOverlayFactory.h"
50 #include "GribUIDialog.h"
51 
52 class GribPreferencesDialog;
53 
54 //----------------------------------------------------------------------------------------------------------
55 //    The PlugIn Class Definition
56 //----------------------------------------------------------------------------------------------------------
57 
58 #define GRIB_TOOL_POSITION    -1          // Request default positioning of ToolBar tool
59 #define STARTING_STATE_STYLE  9999        // style option undifined
60 #define ATTACHED               0          // dialog are attached
61 #define SEPARATED              1          // dialog are separated
62 #define ATTACHED_HAS_CAPTION   0          // dialog attached  has a caption
63 #define ATTACHED_NO_CAPTION    1          // dialog attached don't have caption
64 #define SEPARATED_HORIZONTAL   2          // dialog separated shown honrizontaly
65 #define SEPARATED_VERTICAL     3          // dialog separated shown vaerticaly
66 
67 class grib_pi : public opencpn_plugin_116
68 {
69 public:
70       grib_pi(void *ppimgr);
71       ~grib_pi(void);
72 
73 //    The required PlugIn Methods
74       int Init(void);
75       bool DeInit(void);
76 
77       int GetAPIVersionMajor();
78       int GetAPIVersionMinor();
79       int GetPlugInVersionMajor();
80       int GetPlugInVersionMinor();
81       wxBitmap *GetPlugInBitmap();
82       wxString GetCommonName();
83       wxString GetShortDescription();
84       wxString GetLongDescription();
85 
86 //    The override PlugIn Methods
87       bool MouseEventHook( wxMouseEvent &event);
88       bool RenderOverlay(wxDC &dc, PlugIn_ViewPort *vp);
89       bool RenderOverlayMultiCanvas(wxDC &dc, PlugIn_ViewPort *vp, int canvasIndex);
90       void SetCursorLatLon(double lat, double lon);
91       void OnContextMenuItemCallback(int id);
92       void SetPluginMessage(wxString &message_id, wxString &message_body);
93       bool RenderGLOverlay(wxGLContext *pcontext, PlugIn_ViewPort *vp);
94       bool RenderGLOverlayMultiCanvas(wxGLContext *pcontext, PlugIn_ViewPort *vp, int canvasIndex);
95       void SendTimelineMessage(wxDateTime time);
96       void SetDefaults(void);
97       int GetToolBarToolCount(void);
98       void ShowPreferencesDialog( wxWindow* parent );
99       void OnToolbarToolCallback(int id);
100       bool QualifyCtrlBarPosition( wxPoint position, wxSize size );
101 	  void MoveDialog(wxDialog *dialog, wxPoint position);
102 
103 // Other public methods
SetCtrlBarXY(wxPoint p)104       void SetCtrlBarXY   (wxPoint p){ m_CtrlBarxy = p;}
SetCursorDataXY(wxPoint p)105       void SetCursorDataXY    (wxPoint p){ m_CursorDataxy = p;}
SetCtrlBarSizeXY(wxSize p)106       void SetCtrlBarSizeXY(wxSize p){ m_CtrlBar_Sizexy = p;}
107       void SetColorScheme(PI_ColorScheme cs);
108       void SetDialogFont( wxWindow *window, wxFont *font = OCPNGetFont(_("Dialog"), 10) );
SetCurrentViewPort(PlugIn_ViewPort & vp)109       void SetCurrentViewPort(PlugIn_ViewPort &vp) { m_current_vp = vp; }
GetCurrentViewPort()110       PlugIn_ViewPort &GetCurrentViewPort() { return m_current_vp; }
111 
112       void OnGribCtrlBarClose();
113 
GetCtrlBarXY()114       wxPoint GetCtrlBarXY() { return m_CtrlBarxy; }
GetCursorDataXY()115       wxPoint GetCursorDataXY() { return m_CursorDataxy; }
GetTimeZone()116       int  GetTimeZone() { return m_bTimeZone; }
117       void SetTimeZone(int tz);
GetStartOptions()118       int  GetStartOptions() { return m_bStartOptions; }
GetCopyFirstCumRec()119       bool GetCopyFirstCumRec() { return  m_bCopyFirstCumRec; }
GetCopyMissWaveRec()120       bool GetCopyMissWaveRec() { return  m_bCopyMissWaveRec; }
121 
122       GRIBOverlayFactory *m_pGRIBOverlayFactory;
GetGRIBOverlayFactory()123       GRIBOverlayFactory *GetGRIBOverlayFactory(){ return m_pGRIBOverlayFactory; }
124 
125       void UpdatePrefs(GribPreferencesDialog *Pref);
126 
127       int   m_MenuItem;
128       bool  m_DialogStyleChanged;
129 
130       wxSize           m_coreToolbarSize;
131       wxPoint          m_coreToolbarPosn;
132 
133 private:
134       bool LoadConfig(void);
135       bool SaveConfig(void);
136 
137       bool DoRenderGLOverlay(wxGLContext *pcontext, PlugIn_ViewPort *vp, int canvasIndex);
138       bool DoRenderOverlay(wxDC &dc, PlugIn_ViewPort *vp, int canvasIndex);
139 
140       wxFileConfig     *m_pconfig;
141       wxWindow         *m_parent_window;
142 
143       GRIBUICtrlBar     *m_pGribCtrlBar;
144 
145       int              m_display_width, m_display_height;
146       int              m_leftclick_tool_id;
147 
148       wxPoint          m_CtrlBarxy, m_CursorDataxy;
149       wxSize           m_CtrlBar_Sizexy;
150 
151       //    Controls added to Preferences panel
152       wxCheckBox              *m_pGRIBUseHiDef;
153       wxCheckBox              *m_pGRIBUseGradualColors;
154 
155       GribTimelineRecordSet *m_pLastTimelineSet;
156 
157       // preference data
158       bool              m_bGRIBUseHiDef;
159       bool              m_bGRIBUseGradualColors;
160       bool              m_bDrawBarbedArrowHead;
161       bool              m_bZoomToCenterAtInit;
162       int              m_bTimeZone;
163       bool             m_bCopyFirstCumRec;
164       bool             m_bCopyMissWaveRec;
165       int              m_bLoadLastOpenFile;
166       int              m_bStartOptions;
167       wxString         m_RequestConfig;
168       wxString         m_bMailToAddresses;
169       wxString         m_bMailFromAddress;
170       wxString         m_ZyGribLogin;
171       wxString         m_ZyGribCode;
172       double           m_GUIScaleFactor;
173 
174       bool             m_bGRIBShowIcon;
175 
176       bool        m_bShowGrib;
177       PlugIn_ViewPort  m_current_vp;
178       wxBitmap         m_panelBitmap;
179 };
180 
181 //----------------------------------------------------------------------------------------
182 // Preference dialog definition
183 //----------------------------------------------------------------------------------------
184 
185 class GribPreferencesDialog : public GribPreferencesDialogBase
186 {
187 public:
GribPreferencesDialog(wxWindow * pparent)188     GribPreferencesDialog( wxWindow *pparent)
189     : GribPreferencesDialogBase(pparent) {}
~GribPreferencesDialog()190     ~GribPreferencesDialog() {}
191 
192     void OnOKClick(wxCommandEvent& event);
193 
194 private:
195     void OnStartOptionChange(wxCommandEvent& event);
196 };
197 #endif
198