Update to wx3.0, add SSE optimizations based on target_cpu, fix compile warnings
[ctsim.git] / src / dlgezplot.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          dlgezplot.cpp
5 **   Purpose:       EZPlot Dialog
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  Jan 2001
8 **
9 **  This is part of the CTSim program
10 **  Copyright (c) 1983-2009 Kevin Rosenberg
11 **
12 **  This program is free software; you can redistribute it and/or modify
13 **  it under the terms of the GNU General Public License (version 2) as
14 **  published by the Free Software Foundation.
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 Free Software
23 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24 ******************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #ifdef HAVE_WXWINDOWS
31
32 // For compilers that support precompilation, includes "wx.h".
33 #include "wx/wxprec.h"
34
35 #ifndef WX_PRECOMP
36 #include "wx/utils.h"
37 #include "wx/frame.h"
38 #include "wx/button.h"
39 #include "wx/stattext.h"
40 #include "wx/layout.h"
41 #include "wx/event.h"
42 #include "wx/intl.h"
43 #include "wx/settings.h"
44 #include "wx/dcclient.h"
45 #include "wx/timer.h"
46 #endif
47
48 #include "ct.h"
49 #include "../src/ctsim.h"
50 #include "dlgezplot.h"
51
52
53 static const int LAYOUT_X_MARGIN = 4;
54 static const int LAYOUT_Y_MARGIN = 4;
55
56 BEGIN_EVENT_TABLE(EZPlotControl, wxPanel)
57 EVT_PAINT(EZPlotControl::OnPaint)
58 END_EVENT_TABLE()
59
60 IMPLEMENT_CLASS(EZPlotControl, wxPanel)
61
62
63 EZPlotControl::EZPlotControl (wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
64                               long style, const wxValidator& validator, const wxString& name)
65      : m_pEZPlot(0), m_pSGPDriver(0), m_pSGP(0), m_pDC(0)
66 {
67   Create(parent, id, pos, size, style, name);
68
69   SetSize (GetBestSize());
70
71   m_pEZPlot = new EZPlot;
72 }
73
74 wxSize
75 EZPlotControl::GetBestSize () const
76 {
77   return wxSize (500,500);
78 }
79
80 EZPlotControl::~EZPlotControl()
81 {
82   delete m_pEZPlot;
83   delete m_pSGP;
84   delete m_pSGPDriver;
85   delete m_pDC;
86 }
87
88 void
89 EZPlotControl::OnPaint (wxPaintEvent& event)
90 {
91   wxPaintDC dc(this);
92   GetClientSize (&m_iClientX, &m_iClientY);
93   m_pSGPDriver = new SGPDriver (&dc, m_iClientX, m_iClientY);
94   m_pSGP = new SGP (*m_pSGPDriver);
95   m_pSGP->setTextPointSize(10);
96 //  m_pSGP->setViewport (0, 0, 1., 0.5);  // for debugging testing only
97   if (m_pEZPlot && m_pSGP) {
98     m_pSGP->eraseWindow();
99     m_pEZPlot->plot (m_pSGP);
100   }
101 }
102
103
104 wxEZPlotDialog::wxEZPlotDialog (wxWindow *parent, bool bCancelButton)
105 : wxDialog((parent ? parent : theApp->getMainFrame()), -1, _T("EZPlot"), wxDefaultPosition, wxDefaultSize),
106   m_parentTop(0)
107 {
108   if (! parent)
109     parent = theApp->getMainFrame();
110
111   m_parentTop = parent;
112   while ( m_parentTop && m_parentTop->GetParent() )
113     m_parentTop = m_parentTop->GetParent();
114
115   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
116
117   pTopSizer->Add (m_pEZPlotCtrl = new EZPlotControl (this), 0, wxALIGN_CENTER | wxALL, 5);
118
119   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
120   wxButton* pButtonOk = new wxButton (this, wxID_OK, _T("Ok"));
121   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
122   if (bCancelButton) {
123     wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, _T("Cancel"));
124     pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
125   }
126   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
127
128   SetAutoLayout (true);
129   SetSizer (pTopSizer);
130   pTopSizer->Fit (this);
131   pTopSizer->SetSizeHints (this);
132 }
133
134
135
136 EZPlotDialog::EZPlotDialog(wxWindow* parent, bool bCancelButton)
137     : m_pDialog(new wxEZPlotDialog(parent, bCancelButton))
138 {
139 }
140
141 EZPlot*
142 EZPlotDialog::getEZPlot()
143 { return m_pDialog->getEZPlot(); }
144
145 int
146 EZPlotDialog::ShowModal()
147 { return m_pDialog->ShowModal(); }
148
149 wxEZPlotDialog::~wxEZPlotDialog()
150 {
151   if ( m_parentTop )
152     m_parentTop->Enable(TRUE);
153 }
154
155
156
157 #endif // HAVE_WXWINDOWS