21#include <wx/dcclient.h>
23#include <wx/clipbrd.h>
24#include <wx/dataobj.h>
26#include <wx/scrolwin.h>
27#include <wx/artprov.h>
31#include <mgl2/canvas_wnd.h>
34#include "../common/datastructures.h"
35#include "../kernel/core/ui/language.hpp"
40#include "icons/addtext.xpm"
41#include "icons/addline.xpm"
42#include "icons/addrect.xpm"
43#include "icons/addcirc.xpm"
44#include "icons/rotate_new.xpm"
45#include "icons/zoom_new.xpm"
46#include "icons/newstart1.xpm"
47#include "icons/newstop1.xpm"
64 void Window(
int argc,
char **argv,
int (*draw)(mglBase *
gr,
void *p),
const char *title,
65 void *par=NULL,
void (*reload)(
void *p)=NULL,
bool maximize=
false);
94BEGIN_EVENT_TABLE(
wxMGL, wxWindow)
139wxMGL::
wxMGL(wxWindow* parent, wxWindowID
id, const wxPoint& pos, const wxSize& size,
long style,
bool frameless, const wxString&
name) : wxWindow(parent,
id, pos, size, style,
name)
161 SetOwnBackgroundColour(*wxWHITE);
183 int nWidths[] = {-2,-1,-1};
220 if (
gr->GetNumFrame() <= 1)
229 wxString slidescount;
230 slidescount.Printf(
"%d / %d",
gr->GetNumFrame(),
gr->GetNumFrame());
231 statusbar->SetStatusText(slidescount, 2);
246 return double(mgl_get_width(
gr->Self())) / mgl_get_height(
gr->Self());
267 wxBitmap bm_rotate(rotate_new_xpm);
269 wxBitmap bm_zoom(zoom_new_xpm);
276 wxBitmap bm_run(newstart1_xpm);
278 wxBitmap bm_stop(newstop1_xpm);
283 wxBitmap bm_addline(addline);
285 wxBitmap bm_addrect(addrect);
287 wxBitmap bm_addcirc(addcirc);
289 wxBitmap bm_addtext(addtext);
312 static const wxString fileFilter =
"PNG (*.png)|*.png|JPG (*.jpg)|*.jpg;*.jpeg|EPS (*.eps)|*.eps|SVG (*.svg)|*.svg";
316 wxFileDialog dlg(
this,
_guilang.
get(
"GUI_DLG_SAVEAS"), path,
"graph", fileFilter, wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxFD_CHANGE_DIR);
319 if (dlg.ShowModal() != wxID_OK)
324 fileName = wxFileName(dlg.GetPath());
326 if (fileName.GetExt() ==
"png")
328 else if (fileName.GetExt() ==
"jpg")
330 else if (fileName.GetExt() ==
"eps")
332 else if (fileName.GetExt() ==
"svg")
353 dc.SetBackground(wxBrush(*wxWHITE));
363 dc.DrawBitmap(
pic, 0, 0,
false);
366 dc.SetBrush(*wxTRANSPARENT_BRUSH);
367 dc.SetPen(*wxBLACK_DASHED_PEN);
418 wxSize ev =
event.GetSize();
423 wxWindow::SetSize(ev);
429 if (mgl_get_width(
gr->Self()) == ev.GetWidth() && mgl_get_height(
gr->Self()) == ev.GetHeight())
433 if (
AutoResize && ev.GetWidth() > 0 && ev.GetHeight() > 0)
435 gr->SetSize(ev.GetWidth(), ev.GetHeight(),
false);
439 SetSize(mgl_get_width(
gr->Self()), mgl_get_height(
gr->Self()));
533 SetCursor(wxCursor(wxCURSOR_MAGNIFIER));
559 SetCursor(wxCursor(wxCURSOR_HAND));
587 SetCursor(wxCursor(wxCURSOR_ARROW));
589 SetCursor(wxCursor(wxCURSOR_IBEAM));
591 SetCursor(wxCursor(wxCURSOR_CROSS));
640 mglPoint endPoint =
gr->CalcXYZ(end_x, end_y);
643 std::string style =
styling->GetLineText(0).ToStdString();
649 gr->Line(startPoint, endPoint, style.c_str());
653 gr->Circle(startPoint, hypot(endPoint.x - startPoint.x, endPoint.y - startPoint.y), style.c_str());
657 gr->Face(startPoint, mglPoint(startPoint.x, endPoint.y), mglPoint(endPoint.x, startPoint.y), endPoint, style.c_str());
662 wxTextEntryDialog dialog(
this,
_guilang.
get(
"GUI_DLG_DRAWTEXT_QUESTION"),
_guilang.
get(
"GUI_DLG_DRAWTEXT"), wxEmptyString, wxOK | wxCANCEL | wxCENTRE);
664 if (dialog.ShowModal() == wxID_OK)
666 text = dialog.GetValue();
667 gr->Puts(startPoint, text.ToStdString().c_str(), style.c_str());
707 double w_off = 2.0*x/double(GetSize().GetWidth())-1.0, h_off = -2.0*y/double(GetSize().GetHeight())+1.0;
731 double w_off = 2.0*x/double(GetSize().GetWidth())-1.0, h_off = -2.0*y/double(GetSize().GetHeight())+1.0;
769 const char *buf = mgl_get_mess(
gr->Self());
773 wxMessageDialog dlg(
this, wxString(buf,wxConvLocal),
appName, wxOK);
778 else if (mgl_get_num_frame(
gr->Self())>0)
780 mgl_set_alpha(
gr->Self(),
alpha);
781 mgl_set_light(
gr->Self(),
light);
782 mgl_get_frame(
gr->Self(),0);
801 const unsigned char *bb = mgl_get_rgb(
gr->Self());
802 int w = mgl_get_width(
gr->Self());
803 int h = mgl_get_height(
gr->Self());
804 unsigned char *tmp = (
unsigned char*)malloc(3*w*h);
805 memcpy(tmp, bb, 3*w*h);
806 return wxImage(w, h, tmp);
838 wxSize sz = GetSize();
842 if (
pic.GetWidth() != sz.GetWidth() ||
pic.GetHeight() != sz.GetHeight())
861 long x=ev.GetX(), y=ev.GetY();
885 wxMouseEvent event(ev);
886 m_parent->GetEventHandler()->ProcessEvent(event);
931 int w1 = GetSize().GetWidth(), h1 = GetSize().GetHeight();
932 mreal _x1, _x2, _y1, _y2;
967 gr->SetQuality(MGL_DRAW_NORM);
993 PopupMenu(
popup, ev.GetPosition());
997 gr->SetQuality(MGL_DRAW_NORM);
1025 long w = GetSize().GetWidth(), h = GetSize().GetHeight();
1033 MousePos.Printf(wxT(
"[%.4g, %.4g] --> [%.4g, %.4g]"), start.x, start.y, p.x, p.y);
1038 MousePos.Printf(wxT(
"[%.4g, %.4g] --> [%.4g, %.4g]"), start.x, start.y, p.x, p.y);
1041 MousePos.Printf(wxT(
"[%.4g, %.4g]"), p.x, p.y);
1047 gr->SetQuality(MGL_DRAW_DOTS);
1051 if (ev.ButtonIsDown(wxMOUSE_BTN_LEFT))
1053 mreal ff = 240/sqrt(mreal(w*h));
1071 if (ev.ButtonIsDown(wxMOUSE_BTN_RIGHT))
1089 if (ev.ButtonIsDown(wxMOUSE_BTN_MIDDLE))
1091 mreal ff = 1./sqrt(mreal(w*h));
1142 gr->SetQuality(MGL_DRAW_NORM);
1166 if (event.GetKeyCode() == WXK_ESCAPE)
1170 if (event.GetKeyCode() ==
' ')
1172 if (
timer->IsRunning())
1179 if (event.GetKeyCode() == WXK_RIGHT || event.GetKeyCode() == WXK_DOWN)
1183 if (event.GetKeyCode() == WXK_LEFT || event.GetKeyCode() == WXK_UP)
1206 if (event.GetDirection())
1224 switch (event.GetId())
1330 if (fname.find(
'.') == std::string::npos)
1331 return fname +
"." + ext;
1343 if (fname.IsEmpty())
1345 if (fname.IsEmpty())
1346 wxMessageBox(
appName, wxT(
"No filename."),wxOK|wxICON_ERROR ,
this);
1353 if (fname.IsEmpty())
1355 if (fname.IsEmpty())
1356 wxMessageBox(
appName, wxT(
"No filename."),wxOK|wxICON_ERROR ,
this);
1364 if (fname.IsEmpty())
1366 if (fname.IsEmpty())
1367 wxMessageBox(
appName, wxT(
"No filename."),wxOK|wxICON_ERROR ,
this);
1376 if(fname.IsEmpty()) wxMessageBox(
appName, wxT(
"No filename."),wxOK|wxICON_ERROR ,
this);
1379 setlocale(LC_ALL,
"C");
1381 setlocale(LC_ALL,
"");
1390 wxMessageBox(
appName, wxT(
"No filename."),wxOK|wxICON_ERROR ,
this);
1393 setlocale(LC_ALL,
"C");
1396 setlocale(LC_ALL,
"");
1405 wxMessageBox(
appName, wxT(
"No filename."),wxOK|wxICON_ERROR ,
this);
1408 setlocale(LC_ALL,
"C");
1411 setlocale(LC_ALL,
"");
1417 if (wxTheClipboard->Open())
1419 wxTheClipboard->SetData(
new wxBitmapDataObject(
pic) );
1420 wxTheClipboard->Close();
1426 gr->SetSize(w, h,
false);
1427 wxWindow::SetSize(w, h);
1433 wxSize sz=GetSize();
1434 gr->SetSize(sz.GetWidth(), sz.GetHeight(),
false);
1448 if (
gr->GetNumFrame() > 1)
1468 wxString slidescount;
1470 statusbar->SetStatusText(slidescount, 2);
1487 if (
gr->GetNumFrame() > 1)
1498 wxString slidescount;
1500 statusbar->SetStatusText(slidescount, 2);
1519 if (!
gr ||
gr->GetNumFrame() <= 1)
1596 return wxString::Format(
"{%.12g,%.12g}", p.x, p.y);
This class handles the internal language system and returns the language strings of the selected lang...
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
wxScrolledWindow * scroll
Scrolling area.
wxMenu * popup
Popup menu.
int sshow
Current state of animation switch (toggle button)
void Adjust()
Adjust size of bitmap to window size.
void ToggleRotate()
Switch on/off rotation by mouse.
void ToggleZoom()
Switch on/off zooming by mouse.
void Animation()
Run animation (I'm too lasy to change it)
void MakeMenu()
Create menu, toolbar and popup menu.
void ToggleAlpha()
Switch on/off transparency (do not overwrite switches in user drawing function)
wxWindow * Wnd
Pointer to window.
void Window(int argc, char **argv, int(*draw)(mglBase *gr, void *p), const char *title, void *par=NULL, void(*reload)(void *p)=NULL, bool maximize=false)
Create a window for plotting. Now implemeted only for GLUT.
void GotoFrame(int d)
Show arbitrary frame (use relative step)
void Update()
Update picture by calling user drawing function.
void ToggleLight()
Switch on/off lighting (do not overwrite switches in user drawing function)
wxMGL * WMGL
Control which draw graphics.
void ToggleNo()
Switch off all zooming and rotation.
Class is Wx widget which display MathGL graphics.
wxString getClickedCoords()
Return the clicked coordinates as a parsable string. This is used by the custom GUI event handler.
wxBitmap pic
Pixmap for drawing (changed by update)
void SetSize(int w, int h)
Set popup menu pointer.
double dPerspective
Value of perspective ( must be in [0,1) )
wxString MousePos
Last mouse position.
double GetRatio()
This member function returns the image aspect ratio.
void PrevSlide()
Show previous slide.
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...
void OnSize(wxSizeEvent &event)
This member function is the resizing event handler.
void OnNextSlide(wxTimerEvent &evt)
Show next slide.
void OnMouseDown(wxMouseEvent &ev)
This member function is the event handling function applied, when the user presses any of the other m...
int mouse_y1
Temporary variables for mouse.
mreal start_y
start coordinates for drawing
void OnMouseLeftDown(wxMouseEvent &ev)
This member function is the event handling function applied, when the user presses the left mouse but...
void Repaint()
Get mouse rotation state.
void SetRotate(bool r)
Switch on/off mouse rotation.
bool AutoResize
Allow auto resizing (default is false)
wxImage ConvertFromGraph()
This member function converts the RGB image created by the mglGraph object into a platform-independen...
bool alpha
Transparency state.
std::vector< wxImage > vAnimationBuffer
bool bRotatingMode
Mouse rotation state.
void OnLeave(wxMouseEvent &event)
Event handler for leaving the window. Will change the drawing mode to normal and redraw the windows c...
void OnMouseMove(wxMouseEvent &ev)
This member function is the event handling function applied, when the user moves the mouse.
void OnExport()
This member function displays the file dialog during exporting the current image displayed in the win...
void SetZoom(bool z)
Switch on/off mouse zooming.
void OnEraseBackground(wxEraseEvent &event)
This member function handles the background erasing process. It is disabled to avoid flickering (kind...
mglGraph * gr
pointer to grapher
void UpdateTools()
This member function dis- or enables the animation tools depending on whether an animation is availab...
void InitializeToolbar()
This member function initializes the toolbar of the GraphViewer Window.
double dAzimutalViewPoint
Rotation angles.
void OnKeyDown(wxKeyEvent &event)
This member function is the event handling function applied, when the user presses a key.
void OnEnter(wxMouseEvent &event)
This member function is the event handling function applied, when the user moves the mouse in the win...
void SetPhi(int p)
Set Phi-angle value.
wxString appName
Application name for message boxes.
void OnNavigationKey(wxNavigationKeyEvent &event)
This member function is the event handling function applied, when the user presses a navigation key.
bool bZoomingMode
Mouse zoom state.
void Animation(bool st=true)
Start animation.
int(* draw_func)(mglBase *gr, void *par)
Drawing function for window procedure. It should return the number of frames.
void ExportBPS(wxString fname=L"")
export to bitmap EPS file
virtual ~wxMGL()
Destructor: stops the timer, if it is running and deletes the referenced drawing class.
void ExportEPS(wxString fname=L"")
export to vector EPS file
mreal zoom_y1
Zoom in region.
wxTimer * timer
Timer for animation.
void OnMenuEvent(wxCommandEvent &event)
This member function is the event handling function for any events emitted by the toolbar.
bool drawModeActive
Flag, if the current draw mode is active => mouse down.
void ZoomIn(int x, int y)
Zoom in graphics.
void ExportJPG(wxString fname=L"")
export to JPEG file
void OnMouseRightUp(wxMouseEvent &ev)
This member function is the event handling function applied, when the user releases the right mouse b...
wxMenu * popup
Pointer to pop-up menu.
void SetPer(int p)
Set perspective value.
void Restore()
Restore zoom and rotation to default values.
void OnPaint(wxPaintEvent &event)
This member function is the redrawing and painting event handler. It will display the bitmap currentl...
void ZoomOut(int x, int y)
Zoom out graphics.
void ExportPNG(wxString fname=L"")
export to PNG file
void SetTet(int t)
Set Theta-angle value.
void Adjust()
Adjust plot size to fill entire window.
void Update()
Update picture.
void setBitmap()
This function sets the current bitmap either by explicit conversion from the RGB data in the mglGraph...
int drawMode
Stores the current draw mode.
void OnMouseLeftUp(wxMouseEvent &ev)
This member function is the event handling function applied, when the user releases the left mouse bu...
void SetDrawMode(int dm)
This member function selects the current drawing mode by dis- and enabling the tools and the other mo...
void OnClose(wxCloseEvent &event)
This member function is the event handling function applied, when the window is closed.
bool light
Lightning state.
void Copy()
copy graphics to clipboard
void ExportSVG(wxString fname=L"")
export to SVG file
void ExportPNGs(wxString fname=L"")
export to PNG file (no transparency)
mreal l_y1
start coordinates for line
void NextSlide()
Show next slide.
EVT_ERASE_BACKGROUND(wxTreeListHeaderWindow::OnEraseBackground) void wxTreeListHeaderWindow
wxString mglSetExtension(const wxString &fname, const wxString &ext)
This function is used to append the extension to the filename, if needed.
const char * mglw_str(const wxString &str)
const wxString ScriptName(L"default")