1 /*****************************************************************************
4 ** Name: dlgprojections.cpp
5 ** Purpose: Projection Collection Animation Dialog
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: August 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: dlgprojections.cpp,v 1.13 2000/12/18 12:29:41 kevin Exp $
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.
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.
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 ******************************************************************************/
29 #pragma implementation "dlgprojections.h"
32 // For compilers that support precompilation, includes "wx.h".
33 #include "wx/wxprec.h"
42 #include "wx/button.h"
43 #include "wx/stattext.h"
44 #include "wx/layout.h"
47 #include "wx/settings.h"
48 #include "wx/dcclient.h"
52 #include "dlgprojections.h"
56 static const int LAYOUT_X_MARGIN = 4;
57 static const int LAYOUT_Y_MARGIN = 4;
59 BEGIN_EVENT_TABLE(ProjectionsDialog, wxDialog)
60 EVT_BUTTON(wxID_CANCEL, ProjectionsDialog::OnCancel)
61 EVT_BUTTON(ProjectionsDialog::ID_BTN_PAUSE, ProjectionsDialog::OnPause)
62 EVT_BUTTON(ProjectionsDialog::ID_BTN_STEP, ProjectionsDialog::OnStep)
63 EVT_CLOSE(ProjectionsDialog::OnClose)
64 EVT_PAINT(ProjectionsDialog::OnPaint)
67 IMPLEMENT_CLASS(ProjectionsDialog, wxDialog)
70 ProjectionsDialog::ProjectionsDialog (Scanner& rScanner, Projections& rProj, const Phantom& rPhantom, const int iTrace, wxWindow *parent)
71 : wxDialog(parent, -1, "Collect Projections", wxDefaultPosition), m_rScanner(rScanner), m_rProjections(rProj), m_rPhantom(rPhantom), m_pSGPDriver(NULL), m_pSGP(NULL), m_iTrace(iTrace), m_pDC(NULL), m_btnAbort(0), m_btnPause(0), m_btnStep(0)
76 while ( m_parentTop && m_parentTop->GetParent() )
77 m_parentTop = m_parentTop->GetParent();
79 m_btnAbort = new wxButton(this, wxID_CANCEL, _("Cancel"));
80 wxLayoutConstraints* c = new wxLayoutConstraints;
81 c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
82 c->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
84 wxSize sizeBtn = wxButton::GetDefaultSize();
85 c->width.Absolute(sizeBtn.x);
86 c->height.Absolute(sizeBtn.y);
88 m_btnAbort->SetConstraints(c);
90 m_btnPause = new wxButton (this, ID_BTN_PAUSE, wxString("Pause"));
91 wxLayoutConstraints* cPause = new wxLayoutConstraints;
92 cPause->right.SameAs(this, wxRight, 3*LAYOUT_X_MARGIN + sizeBtn.x);
93 cPause->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
94 cPause->width.Absolute(sizeBtn.x);
95 cPause->height.Absolute(sizeBtn.y);
96 m_btnPause->SetConstraints(cPause);
98 m_btnStep = new wxButton (this, ID_BTN_STEP, wxString("Step"));
99 wxLayoutConstraints* cStep = new wxLayoutConstraints;
100 cStep->right.SameAs(this, wxRight, 5*LAYOUT_X_MARGIN + sizeBtn.x * 2);
101 cStep->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
102 cStep->width.Absolute(sizeBtn.x);
103 cStep->height.Absolute(sizeBtn.y);
104 m_btnStep->SetConstraints(cStep);
109 wxSize sizeDlg (500,500);
110 if (sizeDlg.x != sizeDlg.y) {
111 sizeDlg.x = max(sizeDlg.x,sizeDlg.y);
112 sizeDlg.y = max(sizeDlg.x,sizeDlg.y);
114 if (m_iTrace >= Trace::TRACE_PLOT)
117 m_iClientX = sizeDlg.x;
118 m_iClientY = sizeDlg.y;
119 SetClientSize(sizeDlg);
121 Centre(wxCENTER_FRAME | wxBOTH);
124 m_parentTop->Enable(FALSE);
127 Enable(TRUE); // enable this window
129 m_bitmap.Create (m_iClientX, m_iClientY); // save a copy of screen
\r
130 m_pDC = dynamic_cast<wxDC*> (new wxClientDC (this));
132 this->GetClientSize(&x, &y);
133 m_pSGPDriver = new SGPDriver (m_pDC, x, y);
134 m_pSGP = new SGP (*m_pSGPDriver);
136 wxYield(); // Update the display
138 m_pSGPDriver->idWX()->SetFont(*wxSWISS_FONT);
140 MacUpdateImmediately();
145 ProjectionsDialog::showView (int iViewNumber)
147 if ( iViewNumber < m_rProjections.nView() ) {
148 m_iLastView = iViewNumber;
\r
149 ::wxYield(); // update the display
\r
150 m_pSGP->eraseWindow();
151 m_btnPause->Refresh();
152 m_btnStep->Refresh();
153 m_btnAbort->Refresh();
155 if (m_iTrace >= Trace::TRACE_PLOT)
156 m_pSGP->setViewport (0, 0, 0.66, 1);
157 ::wxYield(); // update the display
\r
158 m_rScanner.collectProjections (m_rProjections, m_rPhantom, iViewNumber, 1, true, m_iTrace, m_pSGP);
159 ::wxYield(); // update the display
160 if (m_iTrace >= Trace::TRACE_PLOT) {
161 const DetectorArray& detArray = m_rProjections.getDetectorArray (iViewNumber);
162 const DetectorValue* detValues = detArray.detValues();
163 double* detPos = new double [detArray.nDet()];
164 for (int i = 0; i < detArray.nDet(); i++)
166 EZPlot ezplot (*m_pSGP);
167 ezplot.ezset("grid");
168 ezplot.ezset("box");
\r
169 ezplot.ezset("yticks left");
170 ezplot.addCurve (detValues, detPos, detArray.nDet());
\r
171 m_pSGP->setViewport (0.67, 0.1, 1., 1.);
179 ProjectionsDialog::projectView (int iViewNumber)
181 if (iViewNumber <= m_iLastView) // already done this view
184 if (iViewNumber < m_rProjections.nView()) {
185 showView (iViewNumber);
186 wxYield(); // update the display
187 if (m_iTrace >= Trace::TRACE_PLOT) {
191 m_state = Finished; // so that we return TRUE below and
192 // that [Cancel] handler knew what to do
196 MacUpdateImmediately();
199 return m_state != Cancelled;
205 void ProjectionsDialog::OnCancel (wxCommandEvent& event)
207 if ( m_state == Finished ) {
208 // this means that the count down is already finished and we're being
209 // shown as a modal dialog - so just let the default handler do the job
212 // request to cancel was received, the next time Update() is called we
216 // update the button state immediately so that the user knows that the
217 // request has been noticed
218 m_btnAbort->Disable();
224 ProjectionsDialog::OnPause (wxCommandEvent& event)
226 if ( m_state == Finished ) {
228 } else if (m_state == Continue) {
229 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
230 m_pSGP->setDC (&m_memoryDC);
231 m_memoryDC.SetFont (*wxSWISS_FONT);
232 showView (m_iLastView);
234 m_btnPause->SetLabel (wxString("Resume"));
235 m_pSGP->setDC (m_pDC);
\r
236 m_memoryDC.SelectObject(wxNullBitmap);
\r
237 } else if (m_state == Paused) {
239 m_btnPause->SetLabel (wxString("Pause"));
244 ProjectionsDialog::OnStep (wxCommandEvent& event)
246 if ( m_state == Finished ) {
248 } else if (m_state == Continue) {
249 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
250 m_pSGP->setDC (&m_memoryDC);
251 m_memoryDC.SetFont (*wxSWISS_FONT);
\r
252 showView (m_iLastView);
253 // m_rScanner.collectProjections (m_rProjections, m_rPhantom, m_iLastView, 1, true, m_iTrace, m_pSGP);
255 m_btnPause->SetLabel (wxString("Resume"));
256 m_pSGP->setDC (m_pDC);
\r
257 m_memoryDC.SelectObject(wxNullBitmap);
\r
259 } else if (m_state == Paused) {
260 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
\r
261 m_pSGP->setDC (&m_memoryDC);
\r
262 m_memoryDC.SetFont (*wxSWISS_FONT);
\r
263 projectView (m_iLastView + 1);
264 m_pSGP->setDC (m_pDC);
\r
265 m_memoryDC.SelectObject(wxNullBitmap);
\r
270 void ProjectionsDialog::OnClose(wxCloseEvent& event)
272 if ( m_state == Uncancellable )
273 event.Veto(TRUE); // can't close this dialog
274 else if ( m_state == Finished )
275 event.Skip(); // let the default handler close the window as we already terminated
277 m_state = Cancelled; // next Update() will notice it
281 ProjectionsDialog::OnPaint (wxPaintEvent& event)
283 wxPaintDC paintDC (this);
\r
284 if (m_state == Paused) {
285 paintDC.DrawBitmap (m_bitmap, 0, 0, false);
290 /////////////////////////////////////////////////////
293 ProjectionsDialog::~ProjectionsDialog()
296 m_parentTop->Enable(TRUE);