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-2001 Kevin Rosenberg
12 ** $Id: dlgprojections.cpp,v 1.22 2001/01/30 05:05: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.ezset ("xticks major 5");
172 ezplot.ezset ("yticks major 10");
173 ezplot.addCurve (detValues, detPos, detArray.nDet());
175 ezplot.ezset ("xporigin 0.67");
176 ezplot.ezset ("yporigin 0.10");
177 ezplot.ezset ("xlength 0.33");
178 ezplot.ezset ("ylength 0.90");
179 m_pSGP->setViewport (0., 0., 1., 1.);
181 m_pSGP->setViewport (0.67, 0.1, 1., 1.);
183 ezplot.plot (m_pSGP);
190 ProjectionsDialog::projectView (int iViewNumber)
192 if (iViewNumber <= m_iLastView) // already done this view
195 if (iViewNumber < m_rProjections.nView()) {
196 showView (iViewNumber);
197 wxYield(); // update the display
198 if (m_iTrace >= Trace::TRACE_PLOT) {
202 m_state = Finished; // so that we return TRUE below and
203 // that [Cancel] handler knew what to do
207 MacUpdateImmediately();
210 return m_state != Cancelled;
216 void ProjectionsDialog::OnCancel (wxCommandEvent& event)
218 if ( m_state == Finished ) {
219 // this means that the count down is already finished and we're being
220 // shown as a modal dialog - so just let the default handler do the job
223 // request to cancel was received, the next time Update() is called we
227 // update the button state immediately so that the user knows that the
228 // request has been noticed
229 m_btnAbort->Disable();
235 ProjectionsDialog::OnPause (wxCommandEvent& event)
237 if ( m_state == Finished ) {
239 } else if (m_state == Continue) {
240 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
241 m_pSGP->setDC (&m_memoryDC);
242 showView (m_iLastView);
244 m_btnPause->SetLabel (wxString("Resume"));
245 m_pSGP->setDC (m_pDC);
246 m_memoryDC.SelectObject(wxNullBitmap);
247 } else if (m_state == Paused) {
249 m_btnPause->SetLabel (wxString("Pause"));
254 ProjectionsDialog::OnStep (wxCommandEvent& event)
256 if ( m_state == Finished ) {
258 } else if (m_state == Continue) {
259 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
260 m_pSGP->setDC (&m_memoryDC);
261 showView (m_iLastView);
262 // m_rScanner.collectProjections (m_rProjections, m_rPhantom, m_iLastView, 1, true, m_iTrace, m_pSGP);
264 m_btnPause->SetLabel (wxString("Resume"));
265 m_pSGP->setDC (m_pDC);
266 m_memoryDC.SelectObject(wxNullBitmap);
268 } else if (m_state == Paused) {
269 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
270 m_pSGP->setDC (&m_memoryDC);
271 projectView (m_iLastView + 1);
272 m_pSGP->setDC (m_pDC);
273 m_memoryDC.SelectObject(wxNullBitmap);
278 void ProjectionsDialog::OnClose(wxCloseEvent& event)
280 if ( m_state == Uncancellable )
281 event.Veto(TRUE); // can't close this dialog
282 else if ( m_state == Finished )
283 event.Skip(); // let the default handler close the window as we already terminated
285 m_state = Cancelled; // next Update() will notice it
289 ProjectionsDialog::OnPaint (wxPaintEvent& event)
291 wxPaintDC paintDC (this);
292 if (m_state == Paused) {
293 paintDC.DrawBitmap (m_bitmap, 0, 0, false);
298 /////////////////////////////////////////////////////
301 ProjectionsDialog::~ProjectionsDialog()
304 m_parentTop->Enable(TRUE);