r186: *** empty log message ***
[ctsim.git] / src / ctsim.cpp
index bc3e0ba32ea07c2ba4781d087680e07dc1d2a8a4..385fbee15445f120343b24bf7830efb62d649474 100644 (file)
-#include <ct.h>
-#include <iostream>
+/*****************************************************************************
+** FILE IDENTIFICATION
+**
+**   Name:          ctsim.cpp
+**   Purpose:       Top-level routines of CTSim program
+**   Programmer:    Kevin Rosenberg
+**   Date Started:  July 2000
+**
+**  This is part of the CTSim program
+**  Copyright (C) 1983-2000 Kevin Rosenberg
+**
+**  $Id: ctsim.cpp,v 1.10 2000/08/31 08:38:58 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
+**  published by the Free Software Foundation.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+**
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+******************************************************************************/
+
+// For compilers that support precompilation, includes "wx/wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include "wx/wx.h"
+#endif
+
+#if !wxUSE_DOC_VIEW_ARCHITECTURE
+#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
+#endif
+
+#include "wx/docview.h"
+#include "ctsim.h"
+#include "docs.h"
+#include "views.h"
+#include "dialogs.h"
+#include "ctsupport.h"
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
+#if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
+#include <getopt.h>
+#endif
+
+static const char* rcsindent = "$Id: ctsim.cpp,v 1.10 2000/08/31 08:38:58 kevin Exp $";
+
+class CTSimApp* theApp = NULL;
+
+struct option CTSimApp::ctsimOptions[] = 
+{
+    {"help", 0, 0, O_HELP},
+    {"version", 0, 0, O_VERSION},
+    {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_VERSION:
+         cout << rcsindent << endl;
+         exit(0);
+      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(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
+    file_menu->Append(wxID_OPEN, "&Open...");
+    
+    file_menu->AppendSeparator();
+    file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
+    
+    // A nice touch: a history of files visited. Use this menu.
+    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;
+    
+    menu_bar->Append(file_menu, "&File");
+    menu_bar->Append(help_menu, "&Help");
+    
+    m_pFrame->SetMenuBar(menu_bar);
+    
+    SetTopWindow (m_pFrame);
+    m_pFrame->Centre(wxBOTH);
+
+    m_pFrame->Show(true);
+
+    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 << "  --version Display version\n";
+    cout << "  --help    Display this help message\n";
+}
 
 int
-main (int argc, char **argv)
+CTSimApp::OnExit(void)
+{
+    delete m_docManager;
+#ifdef HAVE_DMALLOC
+    dmalloc_shutdown();
+#endif
+    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_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), m_pLog(NULL)
 {
-  cout << "Hello, CTSim!" << endl;
+    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");
+}
 
-  return (0);
+void 
+MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
+{
+    wxMessageBox("CTSim\nAuthor: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]", "About CTSim", wxOK | wxICON_INFORMATION, this);
 }
+
+void 
+MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event))
+{
+    DialogGetPhantom dialogPhantom (this, Phantom::PHM_HERMAN);
+    int dialogReturn = dialogPhantom.ShowModal();
+    if (dialogReturn == wxID_OK) {
+      wxString selection (dialogPhantom.getPhantom());
+      *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
+      wxString filename = 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 
+MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
+{
+    Close(true);
+}
+