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.16 2001/01/04 21:28: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),
72 m_pSGPDriver(NULL), m_pSGP(NULL), m_iTrace(iTrace), m_pDC(NULL), m_btnAbort(0), m_btnPause(0), m_btnStep(0)
77 while ( m_parentTop && m_parentTop->GetParent() )
78 m_parentTop = m_parentTop->GetParent();
80 m_btnAbort = new wxButton(this, wxID_CANCEL, _("Cancel"));
81 wxLayoutConstraints* c = new wxLayoutConstraints;
82 c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
83 c->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
85 wxSize sizeBtn = wxButton::GetDefaultSize();
86 c->width.Absolute(sizeBtn.x);
87 c->height.Absolute(sizeBtn.y);
89 m_btnAbort->SetConstraints(c);
91 m_btnPause = new wxButton (this, ID_BTN_PAUSE, wxString("Pause"));
92 wxLayoutConstraints* cPause = new wxLayoutConstraints;
93 cPause->right.SameAs(this, wxRight, 3*LAYOUT_X_MARGIN + sizeBtn.x);
94 cPause->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
95 cPause->width.Absolute(sizeBtn.x);
96 cPause->height.Absolute(sizeBtn.y);
97 m_btnPause->SetConstraints(cPause);
99 m_btnStep = new wxButton (this, ID_BTN_STEP, wxString("Step"));
100 wxLayoutConstraints* cStep = new wxLayoutConstraints;
101 cStep->right.SameAs(this, wxRight, 5*LAYOUT_X_MARGIN + sizeBtn.x * 2);
102 cStep->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
103 cStep->width.Absolute(sizeBtn.x);
104 cStep->height.Absolute(sizeBtn.y);
105 m_btnStep->SetConstraints(cStep);
110 wxSize sizeDlg (500,500);
111 if (sizeDlg.x != sizeDlg.y) {
112 sizeDlg.x = max(sizeDlg.x,sizeDlg.y);
113 sizeDlg.y = max(sizeDlg.x,sizeDlg.y);
115 if (m_iTrace >= Trace::TRACE_PLOT)
118 m_iClientX = sizeDlg.x;
119 m_iClientY = sizeDlg.y;
120 SetClientSize(sizeDlg);
122 Centre(wxCENTER_FRAME | wxBOTH);
125 m_parentTop->Enable(FALSE);
128 Enable(TRUE); // enable this window
130 m_bitmap.Create (m_iClientX, m_iClientY); // save a copy of screen
131 m_pDC = dynamic_cast<wxDC*> (new wxClientDC (this));
133 this->GetClientSize(&x, &y);
134 m_pSGPDriver = new SGPDriver (m_pDC, x, y);
135 m_pSGP = new SGP (*m_pSGPDriver);
137 wxYield(); // Update the display
139 m_pSGP->setTextPointSize(10);
141 MacUpdateImmediately();
146 ProjectionsDialog::showView (int iViewNumber)
148 if ( iViewNumber < m_rProjections.nView() ) {
149 m_iLastView = iViewNumber;
150 ::wxYield(); // update the display
151 m_pSGP->eraseWindow();
152 m_btnPause->Refresh();
153 m_btnStep->Refresh();
154 m_btnAbort->Refresh();
156 if (m_iTrace >= Trace::TRACE_PLOT)
157 m_pSGP->setViewport (0, 0, 0.66, 1);
158 ::wxYield(); // update the display
159 m_rScanner.collectProjections (m_rProjections, m_rPhantom, iViewNumber, 1, true, m_iTrace, m_pSGP);
160 ::wxYield(); // update the display
161 if (m_iTrace >= Trace::TRACE_PLOT) {
162 const DetectorArray& detArray = m_rProjections.getDetectorArray (iViewNumber);
163 const DetectorValue* detValues = detArray.detValues();
164 double* detPos = new double [detArray.nDet()];
165 for (int i = 0; i < detArray.nDet(); i++)
168 ezplot.ezset ("grid");
169 ezplot.ezset ("box");
170 ezplot.ezset ("yticks left");
171 ezplot.addCurve (detValues, detPos, detArray.nDet());
172 m_pSGP->setViewport (0.67, 0.1, 1., 1.);
173 ezplot.plot (m_pSGP);
180 ProjectionsDialog::projectView (int iViewNumber)
182 if (iViewNumber <= m_iLastView) // already done this view
185 if (iViewNumber < m_rProjections.nView()) {
186 showView (iViewNumber);
187 wxYield(); // update the display
188 if (m_iTrace >= Trace::TRACE_PLOT) {
192 m_state = Finished; // so that we return TRUE below and
193 // that [Cancel] handler knew what to do
197 MacUpdateImmediately();
200 return m_state != Cancelled;
206 void ProjectionsDialog::OnCancel (wxCommandEvent& event)
208 if ( m_state == Finished ) {
209 // this means that the count down is already finished and we're being
210 // shown as a modal dialog - so just let the default handler do the job
213 // request to cancel was received, the next time Update() is called we
217 // update the button state immediately so that the user knows that the
218 // request has been noticed
219 m_btnAbort->Disable();
225 ProjectionsDialog::OnPause (wxCommandEvent& event)
227 if ( m_state == Finished ) {
229 } else if (m_state == Continue) {
230 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
231 m_pSGP->setDC (&m_memoryDC);
232 showView (m_iLastView);
234 m_btnPause->SetLabel (wxString("Resume"));
235 m_pSGP->setDC (m_pDC);
236 m_memoryDC.SelectObject(wxNullBitmap);
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 showView (m_iLastView);
252 // m_rScanner.collectProjections (m_rProjections, m_rPhantom, m_iLastView, 1, true, m_iTrace, m_pSGP);
254 m_btnPause->SetLabel (wxString("Resume"));
255 m_pSGP->setDC (m_pDC);
256 m_memoryDC.SelectObject(wxNullBitmap);
258 } else if (m_state == Paused) {
259 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
260 m_pSGP->setDC (&m_memoryDC);
261 projectView (m_iLastView + 1);
262 m_pSGP->setDC (m_pDC);
263 m_memoryDC.SelectObject(wxNullBitmap);
268 void ProjectionsDialog::OnClose(wxCloseEvent& event)
270 if ( m_state == Uncancellable )
271 event.Veto(TRUE); // can't close this dialog
272 else if ( m_state == Finished )
273 event.Skip(); // let the default handler close the window as we already terminated
275 m_state = Cancelled; // next Update() will notice it
279 ProjectionsDialog::OnPaint (wxPaintEvent& event)
281 wxPaintDC paintDC (this);
282 if (m_state == Paused) {
283 paintDC.DrawBitmap (m_bitmap, 0, 0, false);
288 /////////////////////////////////////////////////////
291 ProjectionsDialog::~ProjectionsDialog()
294 m_parentTop->Enable(TRUE);