NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
wx.h
Go to the documentation of this file.
1/***************************************************************************
2 * wx.h.cpp is part of Math Graphic Library
3 * Copyright (C) 2007-2014 Alexey Balakin <mathgl.abalakin@gmail.ru> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License as *
7 * published by the Free Software Foundation; either version 3 of the *
8 * License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Library General Public *
16 * License along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20#ifndef MGL_WX_H
21#define MGL_WX_H
22//-----------------------------------------------------------------------------
23#include <mgl2/wnd.h>
24#include <wx/window.h>
25#include <wx/image.h>
26#include <wx/timer.h>
27#include <wx/bitmap.h>
28#include <wx/toolbar.h>
29#include <wx/statusbr.h>
30#include <wx/textctrl.h>
31#include <wx/cursor.h>
32
33#include <vector>
34
35class mglCanvas;
36//-----------------------------------------------------------------------------
38class wxMGL : public wxWindow
39{
40public:
41 wxString appName;
43
44 wxMGL(wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, bool frameless = false, const wxString& name = wxPanelNameStr);
45 virtual ~wxMGL();
46 double GetRatio();
47 void SetPopup(wxMenu *p) { popup = p; };
48 void SetSize(int w, int h);
49 void SetGraph(mglGraph* GR)
50 {
51 if (gr)
52 delete gr;
53 gr = GR;
55 }
56
57 inline HMGL GetGraph() { return (HMGL)gr; }
58
60 inline void SetDraw(int (*func)(mglBase *gr, void *par), void *par=0)
61 { draw_func = func; draw_par = par; }
62 inline void SetDraw(mglDraw *dr)
63 {
64 if (draw_cl)
65 {
66 delete draw_cl;
67 gr = nullptr;
68 }
69
70 draw_cl = dr;
71 }
72 inline void SetDraw(int (*draw)(mglGraph *gr))
73 { SetDraw(draw?mgl_draw_graph:0,(void*)draw); }
74 inline void ZoomRegion(mreal xx1,mreal xx2,mreal yy1, mreal yy2)
75 { zoom_x0=xx1; zoom_y0=yy1; zoom_x1=xx2; zoom_y1=yy2; }
76
77 int GetPer() {return dPerspective;};
78 int GetPhi() {return dAzimutalViewPoint;};
79 int GetTet() {return dPolarViewPoint;};
80 bool GetAlpha() {return alpha;};
81 bool GetLight() {return light;};
82 bool GetZoom() {return bZoomingMode;};
83 bool GetRotate() {return bRotatingMode;};
84
85 void Repaint();
86 void Update();
87 void Copy();
88 void Print();
89// void Stop(); ///< Stop execution
90 void SetPer(int p);
91 void SetPhi(int p);
92 void SetTet(int t);
93// void SetAlpha(bool a); ///< Switch on/off transparency
94// void SetLight(bool l); ///< Switch on/off lightning
95 void SetZoom(bool z);
96 void SetRotate(bool r);
97 void SetDrawMode(int dm);
98 void ZoomIn(int x, int y);
99 void ZoomOut(int x, int y);
100 void Restore();
101// void Reload(); ///< Reload data and execute script
102// void ShiftLeft(); ///< Shift graphics to left direction
103// void ShiftRight(); ///< Shift graphics to right direction
104// void ShiftUp(); ///< Shift graphics to up direction
105// void ShiftDown(); ///< Shift graphics to down direction
106 void DrawCurrentObject(int end_x, int end_y);
107 void ExportPNG(wxString fname = L"");
108 void ExportPNGs(wxString fname = L"");
109 void ExportJPG(wxString fname = L"");
110 void ExportBPS(wxString fname = L"");
111 void ExportEPS(wxString fname = L"");
112 void ExportSVG(wxString fname = L"");
113
114 void Adjust();
116 {
117 if (gr)
118 return gr->GetNumFrame();
119
120 return 0;
121 }
122 void NextSlide();
123 void PrevSlide();
124 void Animation(bool st=true);
126 {
127 CallAfter(&Animation, true);
128 }
129
131 {
136 DM_TEXT
137 };
138
139 wxString getClickedCoords();
140
141protected:
142 void InitializeToolbar();
143 void OnExport();
144 void OnPaint(wxPaintEvent& event);
145 void OnEraseBackground(wxEraseEvent& event);
146 void OnSize(wxSizeEvent& event);
147 void OnNextSlide(wxTimerEvent& evt);
148 void OnMouseLeftDown(wxMouseEvent &ev);
149 void OnMouseDown(wxMouseEvent &ev);
150 void OnMouseLeftUp(wxMouseEvent &ev);
151 void OnMouseRightUp(wxMouseEvent &ev);
152 void OnMouseMove(wxMouseEvent &ev);
153
154 void OnEnter(wxMouseEvent& event);
155 void OnLeave(wxMouseEvent& event);
156 void OnKeyDown(wxKeyEvent& event);
157 void OnNavigationKey(wxNavigationKeyEvent& event);
158 void OnMenuEvent(wxCommandEvent& event);
159 void OnClose(wxCloseEvent& event);
160
161 void setBitmap();
162 wxImage ConvertFromGraph();
163
164
165 mglGraph *gr;
166 void *draw_par;
168 int (*draw_func)(mglBase *gr, void *par);
169 mglDraw *draw_cl;
170
171 wxString MousePos;
172 wxBitmap pic;
175 bool alpha;
176 bool light;
185 mreal l_x1, l_y1;
189 wxMenu *popup;
190 wxTimer *timer;
192 std::vector<wxImage> vAnimationBuffer;
193
194 DECLARE_EVENT_TABLE()
195
196private:
197 void UpdateTools();
198
201 wxToolBar* toptoolbar;
202 wxStatusBar* statusbar;
203
204
205 wxTextCtrl* styling;
206};
207//-----------------------------------------------------------------------------
208#endif
Class is Wx widget which display MathGL graphics.
Definition: wx.h:39
wxString getClickedCoords()
Return the clicked coordinates as a parsable string. This is used by the custom GUI event handler.
Definition: wx.cpp:1591
wxBitmap pic
Pixmap for drawing (changed by update)
Definition: wx.h:172
void SetSize(int w, int h)
Set popup menu pointer.
Definition: wx.cpp:1424
double dPerspective
Value of perspective ( must be in [0,1) )
Definition: wx.h:174
wxString MousePos
Last mouse position.
Definition: wx.h:171
double GetRatio()
This member function returns the image aspect ratio.
Definition: wx.cpp:244
void PrevSlide()
Show previous slide.
Definition: wx.cpp:1485
void DrawCurrentObject(int end_x, int end_y)
This member function draws the drawing object selected by the toolbar after the user released the lef...
Definition: wx.cpp:636
void OnSize(wxSizeEvent &event)
This member function is the resizing event handler.
Definition: wx.cpp:416
HMGL GetGraph()
Definition: wx.h:57
void OnNextSlide(wxTimerEvent &evt)
Show next slide.
Definition: wx.cpp:452
void OnMouseDown(wxMouseEvent &ev)
This member function is the event handling function applied, when the user presses any of the other m...
Definition: wx.cpp:900
int getNumFrames()
Definition: wx.h:115
int mouse_y1
Temporary variables for mouse.
Definition: wx.h:199
wxMGL(wxWindow *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, bool frameless=false, const wxString &name=wxPanelNameStr)
wxMGL constructor.
Definition: wx.cpp:139
CurrentDrawMode
Definition: wx.h:131
@ DM_LINE
Definition: wx.h:133
@ DM_TEXT
Definition: wx.h:136
@ DM_CIRCLE
Definition: wx.h:135
@ DM_RECT
Definition: wx.h:134
@ DM_NONE
Definition: wx.h:132
mreal start_y
start coordinates for drawing
Definition: wx.h:186
int mouse_y0
Definition: wx.h:199
void OnMouseLeftDown(wxMouseEvent &ev)
This member function is the event handling function applied, when the user presses the left mouse but...
Definition: wx.cpp:859
wxToolBar * toptoolbar
Definition: wx.h:201
void SetGraph(mglGraph *GR)
Definition: wx.h:49
void SetDraw(int(*draw)(mglGraph *gr))
Definition: wx.h:72
int mouse_x1
Definition: wx.h:199
void Repaint()
Get mouse rotation state.
Definition: wx.cpp:818
void SetRotate(bool r)
Switch on/off mouse rotation.
Definition: wx.cpp:548
bool AutoResize
Allow auto resizing (default is false)
Definition: wx.h:42
wxImage ConvertFromGraph()
This member function converts the RGB image created by the mglGraph object into a platform-independen...
Definition: wx.cpp:799
mreal zoom_y0
Definition: wx.h:187
bool alpha
Transparency state.
Definition: wx.h:175
mreal start_x
Definition: wx.h:186
std::vector< wxImage > vAnimationBuffer
Definition: wx.h:192
wxTextCtrl * styling
Definition: wx.h:205
bool bRotatingMode
Mouse rotation state.
Definition: wx.h:178
bool showMessage
Flag for showing messages (enabled by each execute())
Definition: wx.h:188
int GetTet()
Get Phi-angle value.
Definition: wx.h:79
void OnLeave(wxMouseEvent &event)
Event handler for leaving the window. Will change the drawing mode to normal and redraw the windows c...
Definition: wx.cpp:1138
void OnMouseMove(wxMouseEvent &ev)
This member function is the event handling function applied, when the user moves the mouse.
Definition: wx.cpp:1020
void OnExport()
This member function displays the file dialog during exporting the current image displayed in the win...
Definition: wx.cpp:307
void SetZoom(bool z)
Switch on/off mouse zooming.
Definition: wx.cpp:522
void OnEraseBackground(wxEraseEvent &event)
This member function handles the background erasing process. It is disabled to avoid flickering (kind...
Definition: wx.cpp:402
mglGraph * gr
pointer to grapher
Definition: wx.h:165
int mouse_x0
Definition: wx.h:199
int nFramesToSkip
Definition: wx.h:182
void UpdateTools()
This member function dis- or enables the animation tools depending on whether an animation is availab...
Definition: wx.cpp:215
void InitializeToolbar()
This member function initializes the toolbar of the GraphViewer Window.
Definition: wx.cpp:257
double dAzimutalViewPoint
Rotation angles.
Definition: wx.h:173
void OnKeyDown(wxKeyEvent &event)
This member function is the event handling function applied, when the user presses a key.
Definition: wx.cpp:1158
void OnEnter(wxMouseEvent &event)
This member function is the event handling function applied, when the user moves the mouse in the win...
Definition: wx.cpp:1120
int skiprotate
Definition: wx.h:181
void SetPhi(int p)
Set Phi-angle value.
Definition: wx.cpp:486
wxString appName
Application name for message boxes.
Definition: wx.h:41
void OnNavigationKey(wxNavigationKeyEvent &event)
This member function is the event handling function applied, when the user presses a navigation key.
Definition: wx.cpp:1197
mglDraw * draw_cl
Definition: wx.h:169
bool bZoomingMode
Mouse zoom state.
Definition: wx.h:177
mreal zoom_x0
Definition: wx.h:187
void Animation(bool st=true)
Start animation.
Definition: wx.cpp:1517
int(* draw_func)(mglBase *gr, void *par)
Drawing function for window procedure. It should return the number of frames.
Definition: wx.h:168
void SetDraw(mglDraw *dr)
Definition: wx.h:62
void SetDraw(int(*func)(mglBase *gr, void *par), void *par=0)
Set drawing functions and its parameter.
Definition: wx.h:60
void ExportBPS(wxString fname=L"")
export to bitmap EPS file
Definition: wx.cpp:1373
virtual ~wxMGL()
Destructor: stops the timer, if it is running and deletes the referenced drawing class.
Definition: wx.cpp:196
void ExportEPS(wxString fname=L"")
export to vector EPS file
Definition: wx.cpp:1385
bool GetLight()
Get transparency state.
Definition: wx.h:81
wxStatusBar * statusbar
Definition: wx.h:202
mreal zoom_y1
Zoom in region.
Definition: wx.h:187
void ZoomRegion(mreal xx1, mreal xx2, mreal yy1, mreal yy2)
Definition: wx.h:74
wxTimer * timer
Timer for animation.
Definition: wx.h:190
void OnMenuEvent(wxCommandEvent &event)
This member function is the event handling function for any events emitted by the toolbar.
Definition: wx.cpp:1222
bool drawModeActive
Flag, if the current draw mode is active => mouse down.
Definition: wx.h:184
void ZoomIn(int x, int y)
Zoom in graphics.
Definition: wx.cpp:705
mreal zoom_x1
Definition: wx.h:187
wxFrame * m_parentFrame
Definition: wx.h:200
void ExportJPG(wxString fname=L"")
export to JPEG file
Definition: wx.cpp:1362
void SetPopup(wxMenu *p)
Definition: wx.h:47
void OnMouseRightUp(wxMouseEvent &ev)
This member function is the event handling function applied, when the user releases the right mouse b...
Definition: wx.cpp:990
bool animation
Definition: wx.h:180
wxMenu * popup
Pointer to pop-up menu.
Definition: wx.h:189
void SetPer(int p)
Set perspective value.
Definition: wx.cpp:467
int GetPhi()
Get perspective value.
Definition: wx.h:78
void Restore()
Restore zoom and rotation to default values.
Definition: wx.cpp:683
void OnPaint(wxPaintEvent &event)
This member function is the redrawing and painting event handler. It will display the bitmap currentl...
Definition: wx.cpp:347
void ZoomOut(int x, int y)
Zoom out graphics.
Definition: wx.cpp:729
void ExportPNG(wxString fname=L"")
export to PNG file
Definition: wx.cpp:1341
void SetTet(int t)
Set Theta-angle value.
Definition: wx.cpp:504
mreal l_x1
Definition: wx.h:185
bool GetRotate()
Get mouse zooming state.
Definition: wx.h:83
void Adjust()
Adjust plot size to fill entire window.
Definition: wx.cpp:1431
void Update()
Update picture.
Definition: wx.cpp:750
void setBitmap()
This function sets the current bitmap either by explicit conversion from the RGB data in the mglGraph...
Definition: wx.cpp:1303
int drawMode
Stores the current draw mode.
Definition: wx.h:183
bool zoomactive
Definition: wx.h:179
void Print()
Print plot.
void OnMouseLeftUp(wxMouseEvent &ev)
This member function is the event handling function applied, when the user releases the left mouse bu...
Definition: wx.cpp:917
int nFrameCounter
Definition: wx.h:191
double dPolarViewPoint
Definition: wx.h:173
void * draw_par
Definition: wx.h:166
void SetDrawMode(int dm)
This member function selects the current drawing mode by dis- and enabling the tools and the other mo...
Definition: wx.cpp:575
void OnClose(wxCloseEvent &event)
This member function is the event handling function applied, when the window is closed.
Definition: wx.cpp:1287
bool GetAlpha()
Get Theta-angle value.
Definition: wx.h:80
bool light
Lightning state.
Definition: wx.h:176
int GetPer()
Definition: wx.h:77
void AnimateAsynch()
Definition: wx.h:125
void Copy()
copy graphics to clipboard
Definition: wx.cpp:1415
void ExportSVG(wxString fname=L"")
export to SVG file
Definition: wx.cpp:1400
bool GetZoom()
Get lightning state.
Definition: wx.h:82
void ExportPNGs(wxString fname=L"")
export to PNG file (no transparency)
Definition: wx.cpp:1351
mreal l_y1
start coordinates for line
Definition: wx.h:185
void NextSlide()
Show next slide.
Definition: wx.cpp:1446
char name[32]
Definition: resampler.cpp:371
Resample_Real(* func)(Resample_Real t)
Definition: resampler.cpp:372