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
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 ******************************************************************************/
28 #include "wx/wxprec.h"
33 #include "wx/button.h"
34 #include "wx/stattext.h"
35 #include "wx/layout.h"
38 #include "wx/settings.h"
39 #include "wx/dcclient.h"
43 #include "dlgprojections.h"
47 static const int LAYOUT_X_MARGIN = 4;
48 static const int LAYOUT_Y_MARGIN = 4;
50 BEGIN_EVENT_TABLE(ProjectionsDialog, wxDialog)
51 EVT_BUTTON(wxID_CANCEL, ProjectionsDialog::OnCancel)
52 EVT_BUTTON(ProjectionsDialog::ID_BTN_PAUSE, ProjectionsDialog::OnPause)
53 EVT_BUTTON(ProjectionsDialog::ID_BTN_STEP, ProjectionsDialog::OnStep)
54 EVT_CLOSE(ProjectionsDialog::OnClose)
55 EVT_PAINT(ProjectionsDialog::OnPaint)
58 IMPLEMENT_CLASS(ProjectionsDialog, wxDialog)
61 ProjectionsDialog::ProjectionsDialog (Scanner& rScanner, Projections& rProj, const Phantom& rPhantom, const int iTrace, wxWindow *parent)
62 : wxDialog(parent, -1, "Collect Projections", wxDefaultPosition), m_rScanner(rScanner), m_rProjections(rProj), m_rPhantom(rPhantom),
63 m_pSGPDriver(NULL), m_pSGP(NULL), m_iTrace(iTrace), m_pDC(NULL), m_btnAbort(0), m_btnPause(0), m_btnStep(0)
68 while ( m_parentTop && m_parentTop->GetParent() )
69 m_parentTop = m_parentTop->GetParent();
71 m_btnAbort = new wxButton(this, wxID_CANCEL, _("Cancel"));
72 wxLayoutConstraints* c = new wxLayoutConstraints;
73 c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
74 c->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
76 wxSize sizeBtn = wxButton::GetDefaultSize();
77 c->width.Absolute(sizeBtn.x);
78 c->height.Absolute(sizeBtn.y);
80 m_btnAbort->SetConstraints(c);
82 m_btnPause = new wxButton (this, ID_BTN_PAUSE, wxString("Pause"));
83 wxLayoutConstraints* cPause = new wxLayoutConstraints;
84 cPause->right.SameAs(this, wxRight, 3*LAYOUT_X_MARGIN + sizeBtn.x);
85 cPause->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
86 cPause->width.Absolute(sizeBtn.x);
87 cPause->height.Absolute(sizeBtn.y);
88 m_btnPause->SetConstraints(cPause);
90 m_btnStep = new wxButton (this, ID_BTN_STEP, wxString("Step"));
91 wxLayoutConstraints* cStep = new wxLayoutConstraints;
92 cStep->right.SameAs(this, wxRight, 5*LAYOUT_X_MARGIN + sizeBtn.x * 2);
93 cStep->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
94 cStep->width.Absolute(sizeBtn.x);
95 cStep->height.Absolute(sizeBtn.y);
96 m_btnStep->SetConstraints(cStep);
101 wxSize sizeDlg (500,500);
102 if (sizeDlg.x != sizeDlg.y) {
103 sizeDlg.x = imax(sizeDlg.x,sizeDlg.y);
104 sizeDlg.y = imax(sizeDlg.x,sizeDlg.y);
106 if (m_iTrace >= Trace::TRACE_PLOT)
109 m_iClientX = sizeDlg.x;
110 m_iClientY = sizeDlg.y;
111 SetClientSize(sizeDlg);
113 Centre(wxCENTER_FRAME | wxBOTH);
116 m_parentTop->Enable(FALSE);
119 Enable(TRUE); // enable this window
121 m_bitmap.Create (m_iClientX, m_iClientY); // save a copy of screen
122 m_pDC = dynamic_cast<wxDC*> (new wxClientDC (this));
124 this->GetClientSize(&x, &y);
125 m_pSGPDriver = new SGPDriver (m_pDC, x, y);
126 m_pSGP = new SGP (*m_pSGPDriver);
128 wxYield(); // Update the display
130 m_pSGP->setTextPointSize(10);
132 MacUpdateImmediately();
137 ProjectionsDialog::showView (int iViewNumber)
139 if ( iViewNumber < m_rProjections.nView() ) {
140 m_iLastView = iViewNumber;
141 ::wxYield(); // update the display
142 m_pSGP->eraseWindow();
143 m_btnPause->Refresh();
144 m_btnStep->Refresh();
145 m_btnAbort->Refresh();
147 if (m_iTrace >= Trace::TRACE_PLOT)
148 m_pSGP->setViewport (0, 0, 0.66, 1);
149 ::wxYield(); // update the display
150 m_rScanner.collectProjections (m_rProjections, m_rPhantom, iViewNumber, 1, m_rScanner.offsetView(), true, m_iTrace, m_pSGP);
151 ::wxYield(); // update the display
152 if (m_iTrace >= Trace::TRACE_PLOT) {
153 const DetectorArray& detArray = m_rProjections.getDetectorArray (iViewNumber);
154 const DetectorValue* detValues = detArray.detValues();
155 double* detPos = new double [detArray.nDet()];
156 for (int i = 0; i < detArray.nDet(); i++)
159 ezplot.ezset ("grid");
160 ezplot.ezset ("box");
161 ezplot.ezset ("yticks left");
162 ezplot.ezset ("xticks major 5");
163 ezplot.ezset ("yticks major 10");
164 ezplot.addCurve (detValues, detPos, detArray.nDet());
166 ezplot.ezset ("xporigin 0.67");
167 ezplot.ezset ("yporigin 0.10");
168 ezplot.ezset ("xlength 0.33");
169 ezplot.ezset ("ylength 0.90");
170 m_pSGP->setViewport (0., 0., 1., 1.);
172 m_pSGP->setViewport (0.67, 0.1, 1., 1.);
174 ezplot.plot (m_pSGP);
181 ProjectionsDialog::projectView (int iViewNumber)
183 if (iViewNumber <= m_iLastView) // already done this view
186 if (iViewNumber < m_rProjections.nView()) {
187 showView (iViewNumber);
188 wxYield(); // update the display
189 if (m_iTrace >= Trace::TRACE_PLOT) {
193 m_state = Finished; // so that we return TRUE below and
194 // that [Cancel] handler knew what to do
198 MacUpdateImmediately();
201 return m_state != Cancelled;
207 void ProjectionsDialog::OnCancel (wxCommandEvent& event)
209 if ( m_state == Finished ) {
210 // this means that the count down is already finished and we're being
211 // shown as a modal dialog - so just let the default handler do the job
214 // request to cancel was received, the next time Update() is called we
218 // update the button state immediately so that the user knows that the
219 // request has been noticed
220 m_btnAbort->Disable();
226 ProjectionsDialog::OnPause (wxCommandEvent& event)
228 if ( m_state == Finished ) {
230 } else if (m_state == Continue) {
231 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
232 m_pSGP->setDC (&m_memoryDC);
233 showView (m_iLastView);
235 m_btnPause->SetLabel (wxString("Resume"));
236 m_pSGP->setDC (m_pDC);
237 m_memoryDC.SelectObject(wxNullBitmap);
238 } else if (m_state == Paused) {
240 m_btnPause->SetLabel (wxString("Pause"));
245 ProjectionsDialog::OnStep (wxCommandEvent& event)
247 if ( m_state == Finished ) {
249 } else if (m_state == Continue) {
250 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
251 m_pSGP->setDC (&m_memoryDC);
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);
257 m_memoryDC.SelectObject(wxNullBitmap);
259 } else if (m_state == Paused) {
260 m_memoryDC.SelectObject (m_bitmap); // in memoryDC
261 m_pSGP->setDC (&m_memoryDC);
262 projectView (m_iLastView + 1);
263 m_pSGP->setDC (m_pDC);
264 m_memoryDC.SelectObject(wxNullBitmap);
269 void ProjectionsDialog::OnClose(wxCloseEvent& event)
271 if ( m_state == Uncancellable )
272 event.Veto(TRUE); // can't close this dialog
273 else if ( m_state == Finished )
274 event.Skip(); // let the default handler close the window as we already terminated
276 m_state = Cancelled; // next Update() will notice it
280 ProjectionsDialog::OnPaint (wxPaintEvent& event)
282 wxPaintDC paintDC (this);
283 if (m_state == Paused) {
284 paintDC.DrawBitmap (m_bitmap, 0, 0, false);
289 /////////////////////////////////////////////////////
292 ProjectionsDialog::~ProjectionsDialog()
295 m_parentTop->Enable(TRUE);