1 /*****************************************************************************
5 ** Purpose: Top-level routines of CTSim program
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: ctsim.cpp,v 1.23 2001/01/01 10:14:34 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 // For compilers that support precompilation, includes "wx/wx.h".
\r
30 #include "wx/wxprec.h"
\r
40 #if !wxUSE_DOC_VIEW_ARCHITECTURE
\r
41 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
\r
50 #if defined(HAVE_CONFIG_H)
54 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
64 static const char* rcsindent = "$Id: ctsim.cpp,v 1.23 2001/01/01 10:14:34 kevin Exp $";
66 class CTSimApp* theApp = NULL;
68 struct option CTSimApp::ctsimOptions[] =
70 {"help", 0, 0, O_HELP},
71 {"version", 0, 0, O_VERSION},
75 IMPLEMENT_APP(CTSimApp)
78 : m_docManager(NULL), m_pFrame(NULL)
83 #ifdef HAVE_SYS_TIME_H
87 #ifdef HAVE_SYS_RESOURCE_H
88 #include <sys/resource.h>
94 #ifdef HAVE_SETPRIORITY
95 setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority
100 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
106 std::cout << rcsindent << std::endl;
\r
107 #ifdef CTSIMVERSION
\r
108 std::cout << "Version: CTSIMVERSION" << std::endl;
\r
109 #elif defined(VERSION)
\r
110 std::cout << "Version: VERSION" << std::endl;
\r
123 m_docManager = new wxDocManager;
125 new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile doc", "ImageFile View", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
127 new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile doc", "ProjectionFile View", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
129 new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "Phantom doc", "Phantom View", CLASSINFO(PhantomDocument), CLASSINFO(PhantomView));
131 new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "Plot doc", "Plot View", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
133 //// Create the main frame window
134 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
136 SetTopWindow (m_pFrame);
137 m_pFrame->Centre(wxBOTH);
139 m_pFrame->Show(true);
141 for (int i = optind + 1; i <= argc; i++) {
142 wxString filename = argv [i - 1];
143 m_docManager->CreateDocument (filename, wxDOC_SILENT);
150 CTSimApp::usage(const char* program)
152 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
153 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
155 std::cout << " --version Display version\n";
156 std::cout << " --help Display this help message\n";
170 CTSimApp::getUntitledFilename()
172 static int untitledNumber = 1;
174 wxString filename ("Untitled");
175 filename << untitledNumber++;
181 // Top-level window for CTSim
183 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
185 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
186 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
187 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
188 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
\r
189 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
\r
190 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
191 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
192 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
193 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
194 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
195 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
196 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
197 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
198 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
199 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
200 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
201 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
202 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
203 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
204 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
205 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
206 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
207 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
208 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
209 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
210 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
211 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
216 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
217 : wxDocParentFrame(manager, frame, id, title, pos, size, type), m_pLog(NULL)
219 m_pLog = new wxTextCtrl (this, -1, "Log Window\n", wxPoint(0, 250), wxSize(100,50), wxTE_MULTILINE | wxTE_READONLY);
220 wxLog::SetActiveTarget(new wxLogTextCtrl(m_pLog));
222 SetStatusText ("Welcome to CTSim");
225 wxMenu *file_menu = new wxMenu;
227 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
\r
228 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
\r
229 file_menu->Append(wxID_OPEN, "&Open...");
231 file_menu->AppendSeparator();
232 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
234 // history of files visited
235 m_docManager->FileHistoryUseMenu(file_menu);
237 m_pWindowMenu = new wxMenu;
238 m_pWindowMenu->UpdateUI (this);
240 wxMenu* help_menu = new wxMenu;
241 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
242 help_menu->AppendSeparator();
243 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
245 wxMenuBar* menu_bar = new wxMenuBar;
247 menu_bar->Append(file_menu, "&File");
248 menu_bar->Append(m_pWindowMenu, "&Window");
249 menu_bar->Append(help_menu, "&Help");
251 SetMenuBar(menu_bar);
253 for (int i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
254 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("<Empty>"));
255 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
256 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
261 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
263 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
\r
264 #ifdef CTSIMVERSION
\r
266 msg += CTSIMVERSION;
\r
268 #elif defined(VERSION)
\r
269 msg << "Version: " << VERSION << "\n\n";
\r
271 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
\r
273 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
277 MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event))
\r
279 DialogGetPhantom dialogPhantom (this, Phantom::PHM_HERMAN);
\r
280 int dialogReturn = dialogPhantom.ShowModal();
\r
281 if (dialogReturn == wxID_OK) {
\r
282 wxString selection (dialogPhantom.getPhantom());
\r
283 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
\r
284 wxString filename = selection + ".phm";
\r
285 theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT);
\r
291 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
\r
293 DialogGetFilterParameters dialogFilter (this, 256, 256, SignalFilter::FILTER_BANDLIMIT, 1., 10., SignalFilter::DOMAIN_SPATIAL);
\r
294 int dialogReturn = dialogFilter.ShowModal();
\r
295 if (dialogReturn == wxID_OK) {
\r
296 wxString strFilter (dialogFilter.getFilterName());
\r
297 wxString strDomain (dialogFilter.getDomainName());
\r
298 unsigned int nx = dialogFilter.getXSize();
\r
299 unsigned int ny = dialogFilter.getYSize();
\r
300 double dBandwidth = dialogFilter.getBandwidth();
\r
301 double dFilterParam= dialogFilter.getFilterParam();
\r
302 *theApp->getLog() << "Selected filter " << strFilter.c_str() << ", domain " << strDomain.c_str() << ", filterParam " << dFilterParam << ", bandwidth " << dBandwidth << "\n";
\r
303 wxString filename = "untitled.if";
\r
304 ImageFileDocument* pFilterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument ("untitled.if", wxDOC_SILENT));
\r
305 if (! pFilterDoc) {
\r
306 sys_error (ERR_SEVERE, "Unable to create filter image");
\r
309 ImageFile& rIF = pFilterDoc->getImageFile();
\r
310 rIF.setArraySize (nx, ny);
\r
311 rIF.filterResponse (strDomain.c_str(), dBandwidth, strFilter.c_str(), dFilterParam);
\r
312 if (theApp->getSetModifyNewDocs())
\r
313 pFilterDoc->Modify (true);
\r
314 pFilterDoc->UpdateAllViews();
\r
315 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
\r
320 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
\r
322 const ImageFile& rIF = pIFDoc->getImageFile();
\r
323 unsigned int nx = rIF.nx();
\r
324 unsigned int ny = rIF.ny();
\r
325 wxList& rListDocs = m_docManager->GetDocuments();
\r
326 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
\r
327 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
\r
328 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
\r
329 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
\r
330 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
\r
331 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
\r
332 vecIF.push_back (pIFCompareDoc);
\r
338 MainFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event) )
340 wxMessageBox("No help available, refer to man pages of command-line tools");
344 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
350 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
353 wxList& rListDocs = m_docManager->GetDocuments();
354 wxNode* pNode = rListDocs.GetFirst();
355 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
356 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
357 wxString strFilename = pDoc->GetFilename();
358 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
359 m_apWindowMenuData[iPos] = pDoc;
360 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
362 pNode = pNode->GetNext();
364 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
365 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
366 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("<Empty>"));
367 m_apWindowMenuData[i] = NULL;
373 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
375 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
376 wxString strFilename = pDoc->GetFilename();
377 const wxView* pView = pDoc->GetFirstView();
379 wxFrame* pFrame = pView->GetFrame();
386 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
387 { DoWindowMenu (0, event); }
389 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
390 { DoWindowMenu (1, event); }
392 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
393 { DoWindowMenu (2, event); }
395 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
396 { DoWindowMenu (3, event); }
398 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
399 { DoWindowMenu (4, event); }
401 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
402 { DoWindowMenu (5, event); }
404 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
405 { DoWindowMenu (6, event); }
407 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
408 { DoWindowMenu (7, event); }
410 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
411 { DoWindowMenu (8, event); }
413 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
414 { DoWindowMenu (9, event); }
416 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
417 { DoWindowMenu (10, event); }
419 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
420 { DoWindowMenu (11, event); }
422 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
423 { DoWindowMenu (12, event); }
425 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
426 { DoWindowMenu (13, event); }
428 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
429 { DoWindowMenu (14, event); }
431 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
432 { DoWindowMenu (15, event); }
434 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
435 { DoWindowMenu (16, event); }
437 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
438 { DoWindowMenu (17, event); }
440 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
441 { DoWindowMenu (18, event); }
443 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
444 { DoWindowMenu (19, event); }