r646: Reworked EZPlotDialog compilation
[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-2001 Kevin Rosenberg
11 **
12 **  $Id: dlgezplot.cpp,v 1.4 2001/03/29 21:25:50 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #ifdef HAVE_WXWINDOWS
33
34 #ifdef __GNUG__
35 #pragma implementation "dlgezplot.h"
36 #endif
37
38 // For compilers that support precompilation, includes "wx.h".
39 #include "wx/wxprec.h"
40
41 #ifdef __BORLANDC__
42 #pragma hdrstop
43 #endif
44
45 #ifndef WX_PRECOMP
46 #include "wx/utils.h"
47 #include "wx/frame.h"
48 #include "wx/button.h"
49 #include "wx/stattext.h"
50 #include "wx/layout.h"
51 #include "wx/event.h"
52 #include "wx/intl.h"
53 #include "wx/settings.h"
54 #include "wx/dcclient.h"
55 #include "wx/timer.h"
56 #endif
57
58 #include "ct.h"
59 #include "../src/ctsim.h"
60 #include "dlgezplot.h"
61
62
63 static const int LAYOUT_X_MARGIN = 4;
64 static const int LAYOUT_Y_MARGIN = 4;
65
66 BEGIN_EVENT_TABLE(EZPlotControl, wxPanel)
67 EVT_PAINT(EZPlotControl::OnPaint)
68 END_EVENT_TABLE()
69
70 IMPLEMENT_CLASS(EZPlotControl, wxPanel)
71
72
73 EZPlotControl::EZPlotControl (wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, 
74                               long style, const wxValidator& validator, const wxString& name)
75      : m_pEZPlot(0), m_pSGPDriver(0), m_pSGP(0), m_pDC(0)
76 {
77   Create(parent, id, pos, size, style, name);
78
79   SetSize (GetBestSize());
80
81   m_pEZPlot = new EZPlot;
82 }
83
84 wxSize
85 EZPlotControl::GetBestSize () const
86 {
87   return wxSize (500,500);
88 }
89
90 EZPlotControl::~EZPlotControl()
91 {    
92   delete m_pEZPlot;
93   delete m_pSGP;
94   delete m_pSGPDriver;
95   delete m_pDC;
96 }
97
98 void
99 EZPlotControl::OnPaint (wxPaintEvent& event)
100 {
101   wxPaintDC dc(this);
102   GetClientSize (&m_iClientX, &m_iClientY);
103   m_pSGPDriver = new SGPDriver (&dc, m_iClientX, m_iClientY);
104   m_pSGP = new SGP (*m_pSGPDriver);
105   m_pSGP->setTextPointSize(10);
106 //  m_pSGP->setViewport (0, 0, 1., 0.5);  // for debugging testing only
107   if (m_pEZPlot && m_pSGP) {
108     m_pSGP->eraseWindow();
109     m_pEZPlot->plot (m_pSGP);
110   }
111 }
112
113
114 wxEZPlotDialog::wxEZPlotDialog (wxWindow *parent, bool bCancelButton)
115 : wxDialog((parent ? parent : theApp->getMainFrame()), -1, wxString("EZPlot"), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL),
116   m_parentTop(0)
117 {
118   if (! parent)
119     parent = theApp->getMainFrame();
120
121   m_parentTop = parent;
122   while ( m_parentTop && m_parentTop->GetParent() )
123     m_parentTop = m_parentTop->GetParent();
124     
125   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
126
127   pTopSizer->Add (m_pEZPlotCtrl = new EZPlotControl (this), 0, wxALIGN_CENTER | wxALL, 5);
128   
129   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
130   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
131   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
132   if (bCancelButton) {
133     wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
134     pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
135   }  
136   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
137   
138   SetAutoLayout (true);
139   SetSizer (pTopSizer);
140   pTopSizer->Fit (this);
141   pTopSizer->SetSizeHints (this);
142 }
143
144
145
146 EZPlotDialog::EZPlotDialog(wxWindow* parent, bool bCancelButton)
147     : m_pDialog(new wxEZPlotDialog(parent, bCancelButton))
148 {
149 }
150
151 EZPlot*
152 EZPlotDialog::getEZPlot()
153 { return m_pDialog->getEZPlot(); }
154
155 int
156 EZPlotDialog::ShowModal()
157 { return m_pDialog->ShowModal(); }
158
159 wxEZPlotDialog::~wxEZPlotDialog()
160 {
161   if ( m_parentTop )
162     m_parentTop->Enable(TRUE);
163 }
164
165
166
167 #endif // HAVE_WXWINDOWS