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.11 2000/09/02 16:40:36 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 ******************************************************************************/
28 // For compilers that support precompilation, includes "wx/wx.h".
29 #include "wx/wxprec.h"
39 #if !wxUSE_DOC_VIEW_ARCHITECTURE
40 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
43 #include "wx/docview.h"
48 #include "ctsupport.h"
49 #if defined(HAVE_CONFIG_H)
52 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
56 static const char* rcsindent = "$Id: ctsim.cpp,v 1.11 2000/09/02 16:40:36 kevin Exp $";
58 class CTSimApp* theApp = NULL;
60 struct option CTSimApp::ctsimOptions[] =
62 {"help", 0, 0, O_HELP},
63 {"version", 0, 0, O_VERSION},
67 IMPLEMENT_APP(CTSimApp)
69 CTSimApp::CTSimApp(void)
70 : m_docManager(NULL), m_pFrame(NULL)
75 #ifdef HAVE_SYS_TIME_H
79 #ifdef HAVE_SYS_RESOURCE_H
80 #include <sys/resource.h>
84 CTSimApp::OnInit(void)
86 #ifdef HAVE_SETPRIORITY
87 setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority
92 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
98 cout << rcsindent << endl;
110 m_docManager = new wxDocManager;
112 (void) new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile doc", "ImageFile View", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
114 (void) new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile doc", "ProjectionFile View", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
116 (void) new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "Phantom doc", "Phantom View", CLASSINFO(PhantomDocument), CLASSINFO(PhantomView));
118 //// Create the main frame window
119 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
122 wxMenu *file_menu = new wxMenu;
124 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
125 file_menu->Append(wxID_OPEN, "&Open...");
127 file_menu->AppendSeparator();
128 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
130 // A nice touch: a history of files visited. Use this menu.
131 m_docManager->FileHistoryUseMenu(file_menu);
133 wxMenu *help_menu = new wxMenu;
134 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
135 help_menu->AppendSeparator();
136 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
138 wxMenuBar *menu_bar = new wxMenuBar;
140 menu_bar->Append(file_menu, "&File");
141 menu_bar->Append(help_menu, "&Help");
143 m_pFrame->SetMenuBar(menu_bar);
145 SetTopWindow (m_pFrame);
146 m_pFrame->Centre(wxBOTH);
148 m_pFrame->Show(true);
150 for (int i = optind + 1; i <= argc; i++) {
151 wxString filename = argv [i - 1];
152 m_docManager->CreateDocument (filename, wxDOC_SILENT);
159 CTSimApp::usage(const char* program)
161 cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
162 cout << "Computed Tomography Simulator (Graphical Shell)\n";
164 cout << " --version Display version\n";
165 cout << " --help Display this help message\n";
169 CTSimApp::OnExit(void)
179 CTSimApp::getUntitledFilename(void)
181 static int untitledNumber = 1;
183 wxString filename ("Untitled");
184 filename << untitledNumber++;
190 // Top-level window for CTSim
192 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
194 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
195 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
196 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
197 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
198 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
202 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
203 : wxDocParentFrame(manager, frame, id, title, pos, size, type), m_pLog(NULL)
206 m_pLog = new wxTextCtrl (this, -1, "Log Window\n", wxPoint(0, 250), wxSize(100,50), wxTE_MULTILINE | wxTE_READONLY);
207 wxLog::SetActiveTarget(new wxLogTextCtrl(m_pLog));
208 SetStatusText ("Welcome to CTSim");
212 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
214 wxMessageBox("CTSim\nAuthor: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]", "About CTSim", wxOK | wxICON_INFORMATION, this);
218 MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event))
220 DialogGetPhantom dialogPhantom (this, Phantom::PHM_HERMAN);
221 int dialogReturn = dialogPhantom.ShowModal();
222 if (dialogReturn == wxID_OK) {
223 wxString selection (dialogPhantom.getPhantom());
224 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
225 wxString filename = selection + ".phm";
226 theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT);
232 MainFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event) )
234 wxMessageBox("No help available, refer to man pages of command-line tools");
238 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )