r153: *** empty log message ***
[ctsim.git] / src / dialogs.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          dialogs.cpp
5 **   Purpose:       Dialog routines for CTSim program
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  July 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: dialogs.cpp,v 1.2 2000/07/18 14:51:06 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
30 #endif
31
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
34
35 #ifdef __BORLANDC__
36 #pragma hdrstop
37 #endif
38
39 #ifndef WX_PRECOMP
40 #include "wx/wx.h"
41 #endif
42
43 #if !wxUSE_DOC_VIEW_ARCHITECTURE
44 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
45 #endif
46
47 #include "wx/statline.h"
48 #include "wx/sizer.h"
49 #include "dialogs.h"
50 #include <sstream>
51 #include "ctsupport.h"
52 #include "scanner.h"
53
54 DialogGetImageMinMax::DialogGetImageMinMax (wxFrame* pParent, const ImageFile& rImagefile, double dDefaultMin = 0., double dDefaultMax = 0.)
55     : wxDialog (pParent, -1, "Set Image Display Minimum & Maximum", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION)
56 {
57   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
58
59   pTopSizer->Add (new wxStaticText (this, -1, "Set Image Display Minimum and Maximum"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5);
60                    
61   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
62
63   ostringstream os;
64   os << dDefaultMin;
65   m_pTextCtrlMin = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
66   ostringstream osMax;
67   osMax << dDefaultMax;
68   m_pTextCtrlMax = new wxTextCtrl (this, -1, osMax.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
69
70   wxGridSizer *pGridSizer = new wxGridSizer (2, 2, 5);
71   pGridSizer->Add (new wxStaticText (this, -1, "Minimum"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
72   pGridSizer->Add (m_pTextCtrlMin, 0, wxALIGN_CENTER_VERTICAL);
73   pGridSizer->Add (new wxStaticText (this, -1, "Maximum"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
74   pGridSizer->Add (m_pTextCtrlMax, 0, wxALIGN_CENTER_VERTICAL);
75   pTopSizer->Add (pGridSizer, 1, wxALL, 10);
76
77   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
78
79   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
80   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
81   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
82   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
83   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
84
85   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
86
87   SetAutoLayout (true);
88   SetSizer (pTopSizer);
89   pTopSizer->Fit (this);
90   pTopSizer->SetSizeHints (this);
91 }
92
93 DialogGetImageMinMax::~DialogGetImageMinMax (void)
94 {
95 #if 0
96   delete m_pTextCtrlMin;
97   delete m_pTextCtrlMax;
98 #endif
99 }
100
101 double
102 DialogGetImageMinMax::getMinimum (void)
103 {
104     wxString strCtrl = m_pTextCtrlMin->GetValue();
105     double dValue;
106     if (strCtrl.ToDouble (&dValue))
107         return dValue;
108     else
109         return (m_dDefaultMin);
110 }
111
112 double
113 DialogGetImageMinMax::getMaximum (void)
114 {
115     wxString strCtrl = m_pTextCtrlMax->GetValue();
116     double dValue;
117     if (strCtrl.ToDouble (&dValue))
118         return dValue;
119     else
120         return (m_dDefaultMax);
121 }
122
123
124 /////////////////////////////////////////////////////////////////////
125 // CLASS IDENTIFICATION
126 //
127 // DialogGetRasterParameters
128 /////////////////////////////////////////////////////////////////////
129
130 DialogGetRasterParameters::DialogGetRasterParameters (wxFrame* pParent, int iDefaultXSize = 0, int iDefaultYSize = 0, int iDefaultNSamples = 1)
131     : wxDialog (pParent, -1, "Set Rasterization Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION)
132 {
133   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
134
135   pTopSizer->Add (new wxStaticText (this, -1, "Set Rasterization Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5);
136                    
137   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
138
139   ostringstream os;
140   os << iDefaultXSize;
141   m_pTextCtrlXSize = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
142   ostringstream osYSize;
143   osYSize << iDefaultYSize;
144   m_pTextCtrlYSize = new wxTextCtrl (this, -1, osYSize.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
145   ostringstream osNSamples;
146   osNSamples << iDefaultNSamples;
147   m_pTextCtrlNSamples = new wxTextCtrl (this, -1, osNSamples.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
148
149   wxGridSizer *pGridSizer = new wxGridSizer (2, 3, 5);
150   pGridSizer->Add (new wxStaticText (this, -1, "X Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
151   pGridSizer->Add (m_pTextCtrlXSize, 0, wxALIGN_CENTER_VERTICAL);
152   pGridSizer->Add (new wxStaticText (this, -1, "Y Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
153   pGridSizer->Add (m_pTextCtrlYSize, 0, wxALIGN_CENTER_VERTICAL);
154   pGridSizer->Add (new wxStaticText (this, -1, "Samples per Pixel"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
155   pGridSizer->Add (m_pTextCtrlNSamples, 0, wxALIGN_CENTER_VERTICAL);
156   pTopSizer->Add (pGridSizer, 1, wxALL, 10);
157
158   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
159
160   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
161   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
162   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
163   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
164   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
165
166   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
167
168   SetAutoLayout (true);
169   SetSizer (pTopSizer);
170   pTopSizer->Fit (this);
171   pTopSizer->SetSizeHints (this);
172 }
173
174 DialogGetRasterParameters::~DialogGetRasterParameters (void)
175 {
176 }
177
178
179 unsigned int
180 DialogGetRasterParameters::getXSize (void)
181 {
182     wxString strCtrl = m_pTextCtrlXSize->GetValue();
183     unsigned long lValue;
184     if (strCtrl.ToULong (&lValue))
185         return lValue;
186     else
187         return (m_iDefaultXSize);
188 }
189
190 unsigned int
191 DialogGetRasterParameters::getYSize (void)
192 {
193     wxString strCtrl = m_pTextCtrlYSize->GetValue();
194     unsigned long lValue;
195     if (strCtrl.ToULong (&lValue))
196         return lValue;
197     else
198         return (m_iDefaultYSize);
199 }
200
201
202 unsigned int
203 DialogGetRasterParameters::getNSamples (void)
204 {
205     wxString strCtrl = m_pTextCtrlNSamples->GetValue();
206     unsigned long lValue;
207     if (strCtrl.ToULong (&lValue))
208         return lValue;
209     else
210         return (m_iDefaultNSamples);
211 }
212
213
214
215 /////////////////////////////////////////////////////////////////////
216 // CLASS IDENTIFICATION
217 //
218 // DialogGetProjectionsParameters
219 /////////////////////////////////////////////////////////////////////
220
221 DialogGetProjectionParameters::DialogGetProjectionParameters (wxFrame* pParent, int iDefaultNDet = 0, int iDefaultNView = 0, int iDefaultNSamples = 1, double dDefaultRotAngle = 1., const char* szDefaultGeometry = NULL)
222     : wxDialog (pParent, -1, "Set Projection Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION)
223 {
224   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
225
226   pTopSizer->Add (new wxStaticText (this, -1, "Set Projection Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5);
227                    
228   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
229
230   ostringstream os;
231   os << iDefaultNDet;
232   m_pTextCtrlNDet = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
233   ostringstream osNView;
234   osNView << iDefaultNView;
235   m_pTextCtrlNView = new wxTextCtrl (this, -1, osNView.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
236   ostringstream osNSamples;
237   osNSamples << iDefaultNSamples;
238   m_pTextCtrlNSamples = new wxTextCtrl (this, -1, osNSamples.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
239   ostringstream osRotAngle;
240   osRotAngle << dDefaultRotAngle;
241   m_pTextCtrlRotAngle = new wxTextCtrl (this, -1, osRotAngle.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
242
243   wxGridSizer *pGridSizer = new wxGridSizer (2, 4, 5);
244   pGridSizer->Add (new wxStaticText (this, -1, "Detectors"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
245   pGridSizer->Add (m_pTextCtrlNDet, 0, wxALIGN_CENTER_VERTICAL);
246   pGridSizer->Add (new wxStaticText (this, -1, "Views"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
247   pGridSizer->Add (m_pTextCtrlNView, 0, wxALIGN_CENTER_VERTICAL);
248   pGridSizer->Add (new wxStaticText (this, -1, "Samples per Detector"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
249   pGridSizer->Add (m_pTextCtrlNSamples, 0, wxALIGN_CENTER_VERTICAL);
250   pGridSizer->Add (new wxStaticText (this, -1, "Rotation Angle (PI units)"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
251   pGridSizer->Add (m_pTextCtrlRotAngle, 0, wxALIGN_CENTER_VERTICAL);
252   pTopSizer->Add (pGridSizer, 1, wxALL, 10);
253   m_sDefaultGeometry = szDefaultGeometry;
254
255   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
256
257   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
258   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
259   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
260   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
261   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
262
263   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
264
265   SetAutoLayout (true);
266   SetSizer (pTopSizer);
267   pTopSizer->Fit (this);
268   pTopSizer->SetSizeHints (this);
269 }
270
271 DialogGetProjectionParameters::~DialogGetProjectionParameters (void)
272 {
273 }
274
275
276 unsigned int
277 DialogGetProjectionParameters::getNDet (void)
278 {
279     wxString strCtrl = m_pTextCtrlNDet->GetValue();
280     unsigned long lValue;
281     if (strCtrl.ToULong (&lValue))
282         return lValue;
283     else
284         return (m_iDefaultNDet);
285 }
286
287 unsigned int
288 DialogGetProjectionParameters::getNView (void)
289 {
290     wxString strCtrl = m_pTextCtrlNView->GetValue();
291     unsigned long lValue;
292     if (strCtrl.ToULong (&lValue))
293         return lValue;
294     else
295         return (m_iDefaultNView);
296 }
297
298
299 unsigned int
300 DialogGetProjectionParameters::getNSamples (void)
301 {
302     wxString strCtrl = m_pTextCtrlNSamples->GetValue();
303     unsigned long lValue;
304     if (strCtrl.ToULong (&lValue))
305         return lValue;
306     else
307         return (m_iDefaultNSamples);
308 }
309
310 double
311 DialogGetProjectionParameters::getRotAngle (void)
312 {
313     wxString strCtrl = m_pTextCtrlRotAngle->GetValue();
314     double dValue;
315     if (strCtrl.ToDouble (&dValue))
316         return (dValue * PI);
317     else
318       return (m_dDefaultRotAngle);
319 }
320
321 const string&
322 DialogGetProjectionParameters::getGeometry (void)
323 {
324   return m_sDefaultGeometry;
325 }