869d451dc906d025c486864ab5494b19a08a5160
[ctsim.git] / libctgraphics / 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.3 2001/01/19 22:53:56 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   if (m_pEZPlot && m_pSGP) {
107     m_pSGP->eraseWindow();
108     m_pEZPlot->plot (m_pSGP);
109   }
110 }
111
112
113 EZPlotDialog::EZPlotDialog (wxWindow *parent)
114 : wxDialog((parent ? parent : theApp->getMainFrame()), -1, wxString("EZPlot"), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL),
115   m_parentTop(0)
116 {
117   if (! parent)
118     parent = theApp->getMainFrame();
119
120   m_parentTop = parent;
121   while ( m_parentTop && m_parentTop->GetParent() )
122     m_parentTop = m_parentTop->GetParent();
123     
124   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
125
126   pTopSizer->Add (m_pEZPlotCtrl = new EZPlotControl (this), 0, wxALIGN_CENTER | wxALL, 5);
127   
128   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
129   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
130   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
131   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
132   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
133   
134   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
135   
136   SetAutoLayout (true);
137   SetSizer (pTopSizer);
138   pTopSizer->Fit (this);
139   pTopSizer->SetSizeHints (this);
140 }
141
142
143
144 /////////////////////////////////////////////////////
145 // destruction
146
147 EZPlotDialog::~EZPlotDialog()
148 {
149   if ( m_parentTop )
150     m_parentTop->Enable(TRUE);
151 }
152
153
154 #endif // HAVE_WXWINDOWS