X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fctsim.cpp;h=c7db0f0501a1ba70c9091d1828646c91d1dfd50b;hp=0f7bc4e5490aabe4a5362b22cfebf97dd8a2c1b3;hb=e4c1f7f8eb87558c3abf3bf1d20732361f425351;hpb=ebe18bbc459204f8bf89880459804cc643a32f24 diff --git a/src/ctsim.cpp b/src/ctsim.cpp index 0f7bc4e..c7db0f0 100644 --- a/src/ctsim.cpp +++ b/src/ctsim.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctsim.cpp,v 1.4 2000/07/13 07:01:59 kevin Exp $ +** $Id: ctsim.cpp,v 1.5 2000/07/15 08:36:13 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -41,34 +41,62 @@ #endif #include "wx/docview.h" - +#include "ct.h" #include "ctsim.h" #include "docs.h" #include "views.h" +class CTSimApp* theApp = NULL; + +struct option CTSimApp::ctsimOptions[] = +{ + {"help", 0, 0, O_HELP}, + {0, 0, 0, 0} +}; + IMPLEMENT_APP(CTSimApp) CTSimApp::CTSimApp(void) : m_docManager(NULL), m_pFrame(NULL) { + theApp = this; } bool CTSimApp::OnInit(void) { + // process options + while (1) { + int c = getopt_long (argc, argv, "", ctsimOptions, NULL); + if (c == -1) + break; + + switch (c) { + case O_HELP: + case '?': + usage (argv[0]); + exit (0); + default: + usage (argv[0]); + exit (1); + } + } + m_docManager = new wxDocManager; (void) new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile doc", "ImageFile View", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView)); (void) new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile doc", "ProjectionFile View", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView)); + (void) new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "Phantom doc", "Phantom View", CLASSINFO(PhantomDocument), CLASSINFO(PhantomView)); + //// Create the main frame window m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE); //// Make a menubar wxMenu *file_menu = new wxMenu; - // file_menu->Append(wxID_NEW, "&New..."); + file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "&Create Phantom..."); file_menu->Append(wxID_OPEN, "&Open..."); file_menu->AppendSeparator(); @@ -78,6 +106,8 @@ CTSimApp::OnInit(void) m_docManager->FileHistoryUseMenu(file_menu); wxMenu *help_menu = new wxMenu; + help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents"); + help_menu->AppendSeparator(); help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); wxMenuBar *menu_bar = new wxMenuBar; @@ -87,13 +117,28 @@ CTSimApp::OnInit(void) m_pFrame->SetMenuBar(menu_bar); + SetTopWindow (m_pFrame); m_pFrame->Centre(wxBOTH); + m_pFrame->Show(true); - - SetTopWindow (m_pFrame); + + for (int i = optind + 1; i <= argc; i++) { + wxString filename = argv [i - 1]; + m_docManager->CreateDocument (filename, wxDOC_SILENT); + } + return true; } +void +CTSimApp::usage(const char* program) +{ + cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n"; + cout << "Computed Tomography Simulator (Graphical Shell)\n"; + cout << "\n"; + cout << " --help Display this help message\n"; +} + int CTSimApp::OnExit(void) { @@ -101,26 +146,76 @@ CTSimApp::OnExit(void) return 0; } +wxString +CTSimApp::getUntitledFilename(void) +{ + static int untitledNumber = 1; + + wxString filename ("Untitled"); + filename << untitledNumber++; + + return (filename); +} + // Top-level window for CTSim IMPLEMENT_CLASS(MainFrame, wxDocParentFrame) + BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame) - EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout) - EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit) + EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout) + EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents) + EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom) + EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit) END_EVENT_TABLE() + MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type) - : wxDocParentFrame(manager, frame, id, title, pos, size, type) + : wxDocParentFrame(manager, frame, id, title, pos, size, type), m_pLog(NULL) { CreateStatusBar(); + m_pLog = new wxTextCtrl (this, -1, "Log Window\n", wxPoint(0, 250), wxSize(100,50), wxTE_MULTILINE | wxTE_READONLY); + wxLog::SetActiveTarget(new wxLogTextCtrl(m_pLog)); SetStatusText ("Welcome to CTSim"); } void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) { - wxMessageBox("CTSim\nAuthor: Kevin Rosenberg \nUsage: ctsim", "About CTSim", wxOK | wxICON_INFORMATION, this); + wxMessageBox("CTSim\nAuthor: Kevin Rosenberg \nUsage: ctsim [files-to-open..] [--help]", "About CTSim", wxOK | wxICON_INFORMATION, this); +} + +void +MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event)) +{ + wxString choiceStringList [5]; + choiceStringList[0] = Phantom::PHM_HERMAN_STR; + choiceStringList[1] = Phantom::PHM_BHERMAN_STR; + choiceStringList[2] = Phantom::PHM_ROWLAND_STR;; + choiceStringList[3] = Phantom::PHM_BROWLAND_STR; + choiceStringList[4] = Phantom::PHM_UNITPULSE_STR; + wxString choiceTitleList [5]; + choiceTitleList[0] = "Herman Head"; + choiceTitleList[1] = "Herman Head Bordered"; + choiceTitleList[2] = "Rowland Head"; + choiceTitleList[3] = "Rowland Head Bordered"; + choiceTitleList[4] = "Unit Pulse"; + wxSingleChoiceDialog dialog (this, "Select phantom", "Phantom Selection", 5, choiceTitleList, NULL, wxOK|wxCANCEL|wxCENTRE); + + int dialogReturn = dialog.ShowModal(); + if (dialogReturn == wxID_OK) { + int selection = dialog.GetSelection(); + *theApp->getLog() << "Selected phantom " << selection << "\n"; + wxString filename = choiceStringList[selection] + ".phm"; + theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT); + } + +} + +void +MainFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event) ) +{ + wxMessageBox("No help available, refer to man pages of command-line tools"); } void