r384: Added first vesion of EZPlotDialog
[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.1 2001/01/12 16:41: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 __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 "dlgezplot.h"
53 #include "ct.h"
54
55
56 static const int LAYOUT_X_MARGIN = 4;
57 static const int LAYOUT_Y_MARGIN = 4;
58
59 BEGIN_EVENT_TABLE(EZPlotDialog, wxDialog)
60 EVT_BUTTON(wxID_CANCEL, EZPlotDialog::OnCancel)
61 EVT_CLOSE(EZPlotDialog::OnClose)
62 EVT_PAINT(EZPlotDialog::OnPaint)
63 END_EVENT_TABLE()
64
65 IMPLEMENT_CLASS(EZPlotDialog, wxDialog)
66
67
68 EZPlotDialog::EZPlotDialog (wxWindow *parent)
69 : wxDialog(parent, -1, wxString("EZPlot"), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE), 
70   m_pEZPlot(0), m_pSGPDriver(0), m_pSGP(0), m_pDC(0)
71 {
72     m_parentTop = parent;
73     while ( m_parentTop && m_parentTop->GetParent() )
74         m_parentTop = m_parentTop->GetParent();
75     
76     wxLayoutConstraints* c = new wxLayoutConstraints;
77     c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
78     c->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
79         
80     wxSize sizeBtn = wxButton::GetDefaultSize();
81     c->width.Absolute(sizeBtn.x);
82     c->height.Absolute(sizeBtn.y);
83         
84     SetAutoLayout(TRUE);
85     Layout();
86         
87     wxSize sizeDlg (500,500);
88     if (sizeDlg.x != sizeDlg.y) {
89                 sizeDlg.x = max(sizeDlg.x,sizeDlg.y);
90                 sizeDlg.y = max(sizeDlg.x,sizeDlg.y);
91     }
92         
93     m_iClientX = sizeDlg.x;
94     m_iClientY = sizeDlg.y;
95     SetClientSize(sizeDlg);
96         
97     Centre(wxCENTER_FRAME | wxBOTH);
98         
99     if ( m_parentTop )
100                 m_parentTop->Enable(FALSE);
101         
102     Show(TRUE);
103     Enable(TRUE); // enable this window
104         
105     m_pDC = dynamic_cast<wxDC*> (new wxClientDC (this));
106     int x, y;
107     this->GetClientSize(&x, &y);
108     m_pSGPDriver = new SGPDriver (m_pDC, x, y);
109     m_pSGP = new SGP (*m_pSGPDriver);
110     m_pSGP->setTextPointSize(10);
111     m_pEZPlot = new EZPlot;
112     
113 #ifdef __WXMAC__
114     MacUpdateImmediately();
115 #endif
116 }
117
118
119 void EZPlotDialog::OnClose(wxCloseEvent& event)
120 {
121 }
122
123 void
124 EZPlotDialog::OnPaint (wxPaintEvent& event)
125 {
126   m_pEZPlot->plot (m_pSGP);
127 }
128
129
130 /////////////////////////////////////////////////////
131 // destruction
132
133 EZPlotDialog::~EZPlotDialog()
134 {
135         if ( m_parentTop )
136                 m_parentTop->Enable(TRUE);
137
138   delete m_pEZPlot;
139         delete m_pSGP;
140         delete m_pSGPDriver;
141         delete m_pDC;
142 }
143