bdb8cb7af9674318e522782f18a47a34a14f5739
[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.2 2001/01/12 21:53:27 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 __GNUG__
29 #pragma implementation "dlgezplot.h"
30 #endif
31
32 // For compilers that support precompilation, includes "wx.h".
33 #include "wx/wxprec.h"
34
35 #ifdef __BORLANDC__
36 #pragma hdrstop
37 #endif
38
39 #ifndef WX_PRECOMP
40 #include "wx/utils.h"
41 #include "wx/frame.h"
42 #include "wx/button.h"
43 #include "wx/stattext.h"
44 #include "wx/layout.h"
45 #include "wx/event.h"
46 #include "wx/intl.h"
47 #include "wx/settings.h"
48 #include "wx/dcclient.h"
49 #include "wx/timer.h"
50 #endif
51
52 #include "ct.h"
53 #include "ctsim.h"
54 #include "dlgezplot.h"
55
56
57 static const int LAYOUT_X_MARGIN = 4;
58 static const int LAYOUT_Y_MARGIN = 4;
59
60 BEGIN_EVENT_TABLE(EZPlotControl, wxPanel)
61 EVT_PAINT(EZPlotControl::OnPaint)
62 END_EVENT_TABLE()
63
64 IMPLEMENT_CLASS(EZPlotControl, wxPanel)
65
66
67 EZPlotControl::EZPlotControl (wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, 
68                        const wxValidator& validator, const wxString& name)
69      : m_pEZPlot(0), m_pSGPDriver(0), m_pSGP(0), m_pDC(0)
70 {
71   Create(parent, id, pos, size, style, name);
72
73   SetSize (GetBestSize());
74
75   m_pEZPlot = new EZPlot;
76 }
77
78 wxSize
79 EZPlotControl::GetBestSize () const
80 {
81   return wxSize (500,500);
82 }
83
84 EZPlotControl::~EZPlotControl()
85 {    
86   delete m_pEZPlot;
87   delete m_pSGP;
88   delete m_pSGPDriver;
89   delete m_pDC;
90 }
91
92 void
93 EZPlotControl::OnPaint (wxPaintEvent& event)
94 {
95   wxPaintDC dc(this);
96   GetClientSize (&m_iClientX, &m_iClientY);
97   m_pSGPDriver = new SGPDriver (&dc, m_iClientX, m_iClientY);
98   m_pSGP = new SGP (*m_pSGPDriver);
99   m_pSGP->setTextPointSize(10);
100   if (m_pEZPlot && m_pSGP) {
101     m_pSGP->eraseWindow();
102     m_pEZPlot->plot (m_pSGP);
103   }
104 }
105
106
107 EZPlotDialog::EZPlotDialog (wxWindow *parent)
108 : wxDialog((parent ? parent : theApp->getMainFrame()), -1, wxString("EZPlot"), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL),
109   m_parentTop(0)
110 {
111   if (! parent)
112     parent = theApp->getMainFrame();
113
114   m_parentTop = parent;
115   while ( m_parentTop && m_parentTop->GetParent() )
116     m_parentTop = m_parentTop->GetParent();
117     
118   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
119
120   pTopSizer->Add (m_pEZPlotCtrl = new EZPlotControl (this), 0, wxALIGN_CENTER | wxALL, 5);
121   
122   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
123   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
124   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
125   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
126   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
127   
128   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
129   
130   SetAutoLayout (true);
131   SetSizer (pTopSizer);
132   pTopSizer->Fit (this);
133   pTopSizer->SetSizeHints (this);
134 }
135
136
137
138 /////////////////////////////////////////////////////
139 // destruction
140
141 EZPlotDialog::~EZPlotDialog()
142 {
143   if ( m_parentTop )
144     m_parentTop->Enable(TRUE);
145 }
146