r7061: initial property settings
[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$
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 // For compilers that support precompilation, includes "wx.h".
35 #include "wx/wxprec.h"
36
37 #ifndef WX_PRECOMP
38 #include "wx/utils.h"
39 #include "wx/frame.h"
40 #include "wx/button.h"
41 #include "wx/stattext.h"
42 #include "wx/layout.h"
43 #include "wx/event.h"
44 #include "wx/intl.h"
45 #include "wx/settings.h"
46 #include "wx/dcclient.h"
47 #include "wx/timer.h"
48 #endif
49
50 #include "ct.h"
51 #include "../src/ctsim.h"
52 #include "dlgezplot.h"
53
54
55 static const int LAYOUT_X_MARGIN = 4;
56 static const int LAYOUT_Y_MARGIN = 4;
57
58 BEGIN_EVENT_TABLE(EZPlotControl, wxPanel)
59 EVT_PAINT(EZPlotControl::OnPaint)
60 END_EVENT_TABLE()
61
62 IMPLEMENT_CLASS(EZPlotControl, wxPanel)
63
64
65 EZPlotControl::EZPlotControl (wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, 
66                               long style, const wxValidator& validator, const wxString& name)
67      : m_pEZPlot(0), m_pSGPDriver(0), m_pSGP(0), m_pDC(0)
68 {
69   Create(parent, id, pos, size, style, name);
70
71   SetSize (GetBestSize());
72
73   m_pEZPlot = new EZPlot;
74 }
75
76 wxSize
77 EZPlotControl::GetBestSize () const
78 {
79   return wxSize (500,500);
80 }
81
82 EZPlotControl::~EZPlotControl()
83 {    
84   delete m_pEZPlot;
85   delete m_pSGP;
86   delete m_pSGPDriver;
87   delete m_pDC;
88 }
89
90 void
91 EZPlotControl::OnPaint (wxPaintEvent& event)
92 {
93   wxPaintDC dc(this);
94   GetClientSize (&m_iClientX, &m_iClientY);
95   m_pSGPDriver = new SGPDriver (&dc, m_iClientX, m_iClientY);
96   m_pSGP = new SGP (*m_pSGPDriver);
97   m_pSGP->setTextPointSize(10);
98 //  m_pSGP->setViewport (0, 0, 1., 0.5);  // for debugging testing only
99   if (m_pEZPlot && m_pSGP) {
100     m_pSGP->eraseWindow();
101     m_pEZPlot->plot (m_pSGP);
102   }
103 }
104
105
106 wxEZPlotDialog::wxEZPlotDialog (wxWindow *parent, bool bCancelButton)
107 : wxDialog((parent ? parent : theApp->getMainFrame()), -1, wxString("EZPlot"), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL),
108   m_parentTop(0)
109 {
110   if (! parent)
111     parent = theApp->getMainFrame();
112
113   m_parentTop = parent;
114   while ( m_parentTop && m_parentTop->GetParent() )
115     m_parentTop = m_parentTop->GetParent();
116     
117   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
118
119   pTopSizer->Add (m_pEZPlotCtrl = new EZPlotControl (this), 0, wxALIGN_CENTER | wxALL, 5);
120   
121   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
122   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
123   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
124   if (bCancelButton) {
125     wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
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 EZPlotDialog::EZPlotDialog(wxWindow* parent, bool bCancelButton)
139     : m_pDialog(new wxEZPlotDialog(parent, bCancelButton))
140 {
141 }
142
143 EZPlot*
144 EZPlotDialog::getEZPlot()
145 { return m_pDialog->getEZPlot(); }
146
147 int
148 EZPlotDialog::ShowModal()
149 { return m_pDialog->ShowModal(); }
150
151 wxEZPlotDialog::~wxEZPlotDialog()
152 {
153   if ( m_parentTop )
154     m_parentTop->Enable(TRUE);
155 }
156
157
158
159 #endif // HAVE_WXWINDOWS