1 /*****************************************************************************
5 ** Purpose: Header file for 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.5 2000/07/15 08:36:13 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"
49 class CTSimApp* theApp = NULL;
51 struct option CTSimApp::ctsimOptions[] =
53 {"help", 0, 0, O_HELP},
57 IMPLEMENT_APP(CTSimApp)
59 CTSimApp::CTSimApp(void)
60 : m_docManager(NULL), m_pFrame(NULL)
66 CTSimApp::OnInit(void)
70 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
85 m_docManager = new wxDocManager;
87 (void) new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile doc", "ImageFile View", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
89 (void) new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile doc", "ProjectionFile View", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
91 (void) new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "Phantom doc", "Phantom View", CLASSINFO(PhantomDocument), CLASSINFO(PhantomView));
93 //// Create the main frame window
94 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
97 wxMenu *file_menu = new wxMenu;
99 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "&Create Phantom...");
100 file_menu->Append(wxID_OPEN, "&Open...");
102 file_menu->AppendSeparator();
103 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
105 // A nice touch: a history of files visited. Use this menu.
106 m_docManager->FileHistoryUseMenu(file_menu);
108 wxMenu *help_menu = new wxMenu;
109 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
110 help_menu->AppendSeparator();
111 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
113 wxMenuBar *menu_bar = new wxMenuBar;
115 menu_bar->Append(file_menu, "&File");
116 menu_bar->Append(help_menu, "&Help");
118 m_pFrame->SetMenuBar(menu_bar);
120 SetTopWindow (m_pFrame);
121 m_pFrame->Centre(wxBOTH);
123 m_pFrame->Show(true);
125 for (int i = optind + 1; i <= argc; i++) {
126 wxString filename = argv [i - 1];
127 m_docManager->CreateDocument (filename, wxDOC_SILENT);
134 CTSimApp::usage(const char* program)
136 cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
137 cout << "Computed Tomography Simulator (Graphical Shell)\n";
139 cout << " --help Display this help message\n";
143 CTSimApp::OnExit(void)
150 CTSimApp::getUntitledFilename(void)
152 static int untitledNumber = 1;
154 wxString filename ("Untitled");
155 filename << untitledNumber++;
161 // Top-level window for CTSim
163 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
165 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
166 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
167 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
168 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
169 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
173 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
174 : wxDocParentFrame(manager, frame, id, title, pos, size, type), m_pLog(NULL)
177 m_pLog = new wxTextCtrl (this, -1, "Log Window\n", wxPoint(0, 250), wxSize(100,50), wxTE_MULTILINE | wxTE_READONLY);
178 wxLog::SetActiveTarget(new wxLogTextCtrl(m_pLog));
179 SetStatusText ("Welcome to CTSim");
183 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
185 wxMessageBox("CTSim\nAuthor: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]", "About CTSim", wxOK | wxICON_INFORMATION, this);
189 MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event))
191 wxString choiceStringList [5];
192 choiceStringList[0] = Phantom::PHM_HERMAN_STR;
193 choiceStringList[1] = Phantom::PHM_BHERMAN_STR;
194 choiceStringList[2] = Phantom::PHM_ROWLAND_STR;;
195 choiceStringList[3] = Phantom::PHM_BROWLAND_STR;
196 choiceStringList[4] = Phantom::PHM_UNITPULSE_STR;
197 wxString choiceTitleList [5];
198 choiceTitleList[0] = "Herman Head";
199 choiceTitleList[1] = "Herman Head Bordered";
200 choiceTitleList[2] = "Rowland Head";
201 choiceTitleList[3] = "Rowland Head Bordered";
202 choiceTitleList[4] = "Unit Pulse";
203 wxSingleChoiceDialog dialog (this, "Select phantom", "Phantom Selection", 5, choiceTitleList, NULL, wxOK|wxCANCEL|wxCENTRE);
205 int dialogReturn = dialog.ShowModal();
206 if (dialogReturn == wxID_OK) {
207 int selection = dialog.GetSelection();
208 *theApp->getLog() << "Selected phantom " << selection << "\n";
209 wxString filename = choiceStringList[selection] + ".phm";
210 theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT);
216 MainFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event) )
218 wxMessageBox("No help available, refer to man pages of command-line tools");
222 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )