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.9 2000/07/23 01:49:03 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";
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)
76 CTSimApp::OnInit(void)
80 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
86 cout << rcsindent << endl;
98 m_docManager = new wxDocManager;
100 (void) new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile doc", "ImageFile View", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
102 (void) new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile doc", "ProjectionFile View", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
104 (void) new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "Phantom doc", "Phantom View", CLASSINFO(PhantomDocument), CLASSINFO(PhantomView));
106 //// Create the main frame window
107 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
110 wxMenu *file_menu = new wxMenu;
112 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
113 file_menu->Append(wxID_OPEN, "&Open...");
115 file_menu->AppendSeparator();
116 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
118 // A nice touch: a history of files visited. Use this menu.
119 m_docManager->FileHistoryUseMenu(file_menu);
121 wxMenu *help_menu = new wxMenu;
122 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
123 help_menu->AppendSeparator();
124 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
126 wxMenuBar *menu_bar = new wxMenuBar;
128 menu_bar->Append(file_menu, "&File");
129 menu_bar->Append(help_menu, "&Help");
131 m_pFrame->SetMenuBar(menu_bar);
133 SetTopWindow (m_pFrame);
134 m_pFrame->Centre(wxBOTH);
136 m_pFrame->Show(true);
138 for (int i = optind + 1; i <= argc; i++) {
139 wxString filename = argv [i - 1];
140 m_docManager->CreateDocument (filename, wxDOC_SILENT);
147 CTSimApp::usage(const char* program)
149 cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
150 cout << "Computed Tomography Simulator (Graphical Shell)\n";
152 cout << " --version Display version\n";
153 cout << " --help Display this help message\n";
157 CTSimApp::OnExit(void)
167 CTSimApp::getUntitledFilename(void)
169 static int untitledNumber = 1;
171 wxString filename ("Untitled");
172 filename << untitledNumber++;
178 // Top-level window for CTSim
180 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
182 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
183 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
184 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
185 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
186 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
190 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
191 : wxDocParentFrame(manager, frame, id, title, pos, size, type), m_pLog(NULL)
194 m_pLog = new wxTextCtrl (this, -1, "Log Window\n", wxPoint(0, 250), wxSize(100,50), wxTE_MULTILINE | wxTE_READONLY);
195 wxLog::SetActiveTarget(new wxLogTextCtrl(m_pLog));
196 SetStatusText ("Welcome to CTSim");
200 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
202 wxMessageBox("CTSim\nAuthor: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]", "About CTSim", wxOK | wxICON_INFORMATION, this);
206 MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event))
208 DialogGetPhantom dialogPhantom (this, Phantom::PHM_HERMAN);
209 int dialogReturn = dialogPhantom.ShowModal();
210 if (dialogReturn == wxID_OK) {
211 wxString selection (dialogPhantom.getPhantom());
212 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
213 wxString filename = selection + ".phm";
214 theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT);
220 MainFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event) )
222 wxMessageBox("No help available, refer to man pages of command-line tools");
226 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )