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.8 2000/07/22 15:45:33 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)
57 class CTSimApp* theApp = NULL;
59 struct option CTSimApp::ctsimOptions[] =
61 {"help", 0, 0, O_HELP},
65 IMPLEMENT_APP(CTSimApp)
67 CTSimApp::CTSimApp(void)
68 : m_docManager(NULL), m_pFrame(NULL)
74 CTSimApp::OnInit(void)
78 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
93 m_docManager = new wxDocManager;
95 (void) new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile doc", "ImageFile View", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
97 (void) new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile doc", "ProjectionFile View", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
99 (void) new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "Phantom doc", "Phantom View", CLASSINFO(PhantomDocument), CLASSINFO(PhantomView));
101 //// Create the main frame window
102 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
105 wxMenu *file_menu = new wxMenu;
107 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
108 file_menu->Append(wxID_OPEN, "&Open...");
110 file_menu->AppendSeparator();
111 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
113 // A nice touch: a history of files visited. Use this menu.
114 m_docManager->FileHistoryUseMenu(file_menu);
116 wxMenu *help_menu = new wxMenu;
117 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
118 help_menu->AppendSeparator();
119 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
121 wxMenuBar *menu_bar = new wxMenuBar;
123 menu_bar->Append(file_menu, "&File");
124 menu_bar->Append(help_menu, "&Help");
126 m_pFrame->SetMenuBar(menu_bar);
128 SetTopWindow (m_pFrame);
129 m_pFrame->Centre(wxBOTH);
131 m_pFrame->Show(true);
133 for (int i = optind + 1; i <= argc; i++) {
134 wxString filename = argv [i - 1];
135 m_docManager->CreateDocument (filename, wxDOC_SILENT);
142 CTSimApp::usage(const char* program)
144 cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
145 cout << "Computed Tomography Simulator (Graphical Shell)\n";
147 cout << " --help Display this help message\n";
151 CTSimApp::OnExit(void)
158 CTSimApp::getUntitledFilename(void)
160 static int untitledNumber = 1;
162 wxString filename ("Untitled");
163 filename << untitledNumber++;
169 // Top-level window for CTSim
171 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
173 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
174 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
175 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
176 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
177 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
181 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
182 : wxDocParentFrame(manager, frame, id, title, pos, size, type), m_pLog(NULL)
185 m_pLog = new wxTextCtrl (this, -1, "Log Window\n", wxPoint(0, 250), wxSize(100,50), wxTE_MULTILINE | wxTE_READONLY);
186 wxLog::SetActiveTarget(new wxLogTextCtrl(m_pLog));
187 SetStatusText ("Welcome to CTSim");
191 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
193 wxMessageBox("CTSim\nAuthor: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]", "About CTSim", wxOK | wxICON_INFORMATION, this);
197 MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event))
199 DialogGetPhantom dialogPhantom (this, Phantom::PHM_HERMAN);
200 int dialogReturn = dialogPhantom.ShowModal();
201 if (dialogReturn == wxID_OK) {
202 wxString selection (dialogPhantom.getPhantom());
203 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
204 wxString filename = selection + ".phm";
205 theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT);
211 MainFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event) )
213 wxMessageBox("No help available, refer to man pages of command-line tools");
217 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )