r185: *** empty log message ***
[ctsim.git] / src / dlgprojections.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          dlgprojections.cpp
5 **   Purpose:       Projection Collection Animation Dialog
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  August 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: dlgprojections.cpp,v 1.1 2000/08/27 20:32:55 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 "dlgprojections.h"
30 #endif
31
32 // For compilers that support precompilation, includes "wx.h".
33 #include "wx/wxprec.h"
34
35 #ifdef __BORLANDC__
36     #pragma hdrstop
37 #endif
38
39 #ifndef WX_PRECOMP
40     #include "wx/utils.h"
41     #include "wx/frame.h"
42     #include "wx/button.h"
43     #include "wx/stattext.h"
44     #include "wx/layout.h"
45     #include "wx/event.h"
46     #include "wx/intl.h"
47     #include "wx/settings.h"
48     #include "wx/dcclient.h"
49     #include "wx/timer.h"
50 #endif
51
52 #include "dlgprojections.h"
53 #include "ct.h"
54
55
56 static const int LAYOUT_X_MARGIN = 4;
57 static const int LAYOUT_Y_MARGIN = 4;
58
59 BEGIN_EVENT_TABLE(ProjectionsDialog, wxDialog)
60    EVT_BUTTON(wxID_CANCEL, ProjectionsDialog::OnCancel)
61    EVT_CLOSE(ProjectionsDialog::OnClose)
62 END_EVENT_TABLE()
63
64 IMPLEMENT_CLASS(ProjectionsDialog, wxDialog)
65
66
67 ProjectionsDialog::ProjectionsDialog (Scanner& rScanner, Projections& rProj, const Phantom& rPhantom, const int iTrace, wxWindow *parent)
68   : wxDialog(parent, -1, "Collect Projections"), m_rScanner(rScanner), m_rProjections(rProj), m_rPhantom(rPhantom), m_pSGPDriver(NULL), m_pSGP(NULL), m_iTrace(iTrace), m_pDC(NULL)
69 {
70     m_state = Continue;
71
72     m_parentTop = parent;
73     while ( m_parentTop && m_parentTop->GetParent() )
74         m_parentTop = m_parentTop->GetParent();
75     
76     m_btnAbort = new wxButton(this, wxID_CANCEL, _("Cancel"));
77     wxLayoutConstraints* c = new wxLayoutConstraints;
78     c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
79     c->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
80
81     wxSize sizeBtn = wxButton::GetDefaultSize();
82     c->width.Absolute(sizeBtn.x);
83     c->height.Absolute(sizeBtn.y);
84
85     m_btnAbort->SetConstraints(c);
86
87     SetAutoLayout(TRUE);
88     Layout();
89
90     wxSize sizeDlg (600,600);
91     if (sizeDlg.x != sizeDlg.y) {
92       sizeDlg.x = max(sizeDlg.x,sizeDlg.y);
93       sizeDlg.y = max(sizeDlg.x,sizeDlg.y);
94     }
95     SetClientSize(sizeDlg);
96
97     Centre(wxCENTER_FRAME | wxBOTH);
98
99     if ( m_parentTop )
100       m_parentTop->Enable(FALSE);
101
102     Show(TRUE);
103     Enable(TRUE); // enable this window
104
105     m_pDC = dynamic_cast<wxDC*> (new wxClientDC (this));
106     int x, y;
107     this->GetClientSize(&x, &y);
108     m_pSGPDriver = new SGPDriver (m_pDC, x, y);
109     m_pSGP = new SGP (*m_pSGPDriver);
110
111     wxYield();     // Update the display
112
113 #ifdef __WXMAC__
114     MacUpdateImmediately();
115 #endif
116 }
117
118 bool
119 ProjectionsDialog::projectView (int iViewNumber)
120 {
121     if ( iViewNumber < m_rProjections.nView() ) {
122       m_rScanner.collectProjections (m_rProjections, m_rPhantom, iViewNumber, 1, true, m_iTrace, m_pSGP);
123       wxYield();        // update the display
124     } else {
125       m_state = Finished;    // so that we return TRUE below and 
126                              // that [Cancel] handler knew what to do
127 #if 0
128       if ( m_btnAbort ) 
129         m_btnAbort->SetLabel(_("Close")); // tell the user what he should do...
130       wxYield();
131       
132       (void)ShowModal();
133 #endif
134     }
135       
136 #ifdef __WXMAC__
137     MacUpdateImmediately();
138 #endif
139
140     return m_state != Canceled;
141 }
142
143
144 // EVENT HANDLERS
145
146 void ProjectionsDialog::OnCancel (wxCommandEvent& event)
147 {
148   if ( m_state == Finished ) {
149     // this means that the count down is already finished and we're being
150     // shown as a modal dialog - so just let the default handler do the job
151     event.Skip();
152   } else {
153     // request to cancel was received, the next time Update() is called we
154     // will handle it
155     m_state = Canceled;
156
157     // update the button state immediately so that the user knows that the
158     // request has been noticed
159     m_btnAbort->Disable();
160   }
161 }
162
163 void ProjectionsDialog::OnClose(wxCloseEvent& event)
164 {
165     if ( m_state == Uncancelable )
166       event.Veto(TRUE);    // can't close this dialog
167     else if ( m_state == Finished )
168       event.Skip(); // let the default handler close the window as we already terminated
169     else
170       m_state = Canceled;          // next Update() will notice it
171 }
172
173
174 /////////////////////////////////////////////////////
175 // destruction
176
177 ProjectionsDialog::~ProjectionsDialog()
178 {
179   if ( m_parentTop )
180     m_parentTop->Enable(TRUE);
181
182   delete m_pSGP;
183   delete m_pSGPDriver;
184   delete m_pDC;
185 }
186