+void
+MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
+{
+ int iPos = 0;
+ wxList& rListDocs = theApp->getDocManager()->GetDocuments();
+ wxNode* pNode = rListDocs.GetFirst();
+ while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
+ wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
+ wxString strFilename = pDoc->GetFilename();
+ if (iPos < 10) {
+ strFilename += "\tCtrl-";
+ strFilename += static_cast<char>('0' + iPos);
+ }
+ static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
+ m_apWindowMenuData[iPos] = pDoc;
+ m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
+ iPos++;
+ pNode = pNode->GetNext();
+ }
+ for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
+ m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
+ static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
+ m_apWindowMenuData[i] = NULL;
+ }
+
+}
+
+#ifdef CTSIM_CUSTOM_MRU
+void
+MainFrame::OnMRUFile (wxCommandEvent& event)
+{
+ wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
+ if (fileName != "")
+ theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
+}
+#endif
+
+void
+MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
+{
+ if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
+ wxString strFilename = pDoc->GetFilename();
+ const wxView* pView = pDoc->GetFirstView();
+ if (pView) {
+ wxFrame* pFrame = pView->GetFrame();
+ pFrame->SetFocus();
+ pFrame->Raise();
+ }
+ }
+}
+
+void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
+{ DoWindowMenu (0, event); }
+
+void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
+{ DoWindowMenu (1, event); }
+
+void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
+{ DoWindowMenu (2, event); }
+
+void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
+{ DoWindowMenu (3, event); }
+
+void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
+{ DoWindowMenu (4, event); }
+
+void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
+{ DoWindowMenu (5, event); }
+
+void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
+{ DoWindowMenu (6, event); }
+
+void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
+{ DoWindowMenu (7, event); }
+
+void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
+{ DoWindowMenu (8, event); }
+
+void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
+{ DoWindowMenu (9, event); }
+
+void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
+{ DoWindowMenu (10, event); }
+
+void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
+{ DoWindowMenu (11, event); }
+
+void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
+{ DoWindowMenu (12, event); }
+
+void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
+{ DoWindowMenu (13, event); }
+
+void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
+{ DoWindowMenu (14, event); }
+
+void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
+{ DoWindowMenu (15, event); }
+
+void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
+{ DoWindowMenu (16, event); }
+
+void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
+{ DoWindowMenu (17, event); }
+
+void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
+{ DoWindowMenu (18, event); }
+
+void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
+{ DoWindowMenu (19, event); }
+
+
+class BitmapControl : public wxPanel
+{
+private:
+ DECLARE_DYNAMIC_CLASS (BitmapControl)
+ DECLARE_EVENT_TABLE ()
+ wxBitmap* m_pBitmap;
+
+public:
+ BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = wxSTATIC_BORDER,
+ const wxValidator& validator = wxDefaultValidator,
+ const wxString& name = "BitmapCtrl");
+
+
+ virtual ~BitmapControl();
+
+ virtual wxSize GetBestSize() const;
+
+ wxBitmap* getBitmap()
+ { return m_pBitmap; }
+
+ void OnPaint(wxPaintEvent& event);
+};
+
+
+BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
+EVT_PAINT(BitmapControl::OnPaint)
+END_EVENT_TABLE()
+
+IMPLEMENT_CLASS(BitmapControl, wxPanel)
+
+
+BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
+ long style, const wxValidator& validator, const wxString& name)
+ : m_pBitmap(pBitmap)
+{
+ Create(parent, id, pos, size, style, name);
+
+ SetSize (GetBestSize());
+}
+
+wxSize
+BitmapControl::GetBestSize () const
+{
+ if (m_pBitmap)
+ return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
+ else
+ return wxSize(0,0);
+}
+
+BitmapControl::~BitmapControl()
+{}
+
+void
+BitmapControl::OnPaint (wxPaintEvent& event)
+{
+ wxPaintDC dc(this);
+ if (m_pBitmap)
+ dc.DrawBitmap (*m_pBitmap, 0, 0);
+}
+
+
+class BitmapDialog : public wxDialog {
+private:
+ BitmapControl* m_pBitmapCtrl;
+
+public:
+ BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
+ virtual ~BitmapDialog();
+};
+
+BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
+: wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
+{
+ wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
+
+ pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
+
+ wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
+ wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
+ pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
+
+ pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
+
+ SetAutoLayout (true);
+ SetSizer (pTopSizer);
+ pTopSizer->Fit (this);
+ pTopSizer->SetSizeHints (this);
+}
+
+BitmapDialog::~BitmapDialog()
+{}
+
+
+#include "./splash.xpm"
+void
+MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
+{
+ wxBitmap bmp (splash);
+ if (bmp.Ok()) {
+ BitmapDialog dlg (&bmp, "About CTSim");
+ dlg.Show(true);
+ } else {
+ wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
+#ifdef CTSIMVERSION
+ msg += "Version ";
+ msg += CTSIMVERSION;
+ msg += "\n\n";
+#elif defined(VERSION)
+ msg << "Version: " << VERSION << "\n\n";
+#endif
+ msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
+
+ wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
+ }
+}
+
+
+ProjectionFileDocument*
+CTSimApp::newProjectionDoc()
+{
+ wxString strFilename (getUntitledFilename());
+ strFilename += ".pj";
+
+ ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (strFilename));
+ if (newDoc) {
+ ProjectionFileView* pView = newDoc->getView();
+ if (pView) {
+ wxFrame* pFrame = pView->getFrame();
+ if (pFrame)
+ pFrame->SetSize(0,0);
+ }
+ newDoc->SetDocumentName(strFilename);
+ newDoc->SetFilename(strFilename);
+ newDoc->SetDocumentTemplate(m_pDocTemplProjection);
+ newDoc->SetTitle(strFilename);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+ImageFileDocument*
+CTSimApp::newImageDoc()
+{
+ wxString strFilename (getUntitledFilename());
+ strFilename += ".pj";
+
+ ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (strFilename));
+ if (newDoc) {
+ ImageFileView* pView = newDoc->getView();
+ if (pView) {
+ wxFrame* pFrame = pView->getFrame();
+ if (pFrame)
+ pFrame->SetSize(0,0);
+ }
+ newDoc->SetDocumentName(strFilename);
+ newDoc->SetFilename(strFilename);
+ newDoc->SetDocumentTemplate(m_pDocTemplImage);
+ newDoc->SetTitle(strFilename);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+PlotFileDocument*
+CTSimApp::newPlotDoc()
+{
+ wxString strFilename (getUntitledFilename());
+ strFilename += ".plt";
+
+ PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (strFilename));
+ if (newDoc) {
+ PlotFileView* pView = newDoc->getView();
+ if (pView) {
+ wxFrame* pFrame = pView->getFrame();
+ if (pFrame)
+ pFrame->SetSize(0,0);
+ }
+ newDoc->SetDocumentName(strFilename);
+ newDoc->SetFilename(strFilename);
+ newDoc->SetDocumentTemplate(m_pDocTemplPlot);
+ newDoc->SetTitle(strFilename);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+
+TextFileDocument*
+CTSimApp::newTextDoc()
+{
+ wxString strFilename (getUntitledFilename());
+ strFilename += ".txt";
+
+ TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (strFilename));
+ if (newDoc) {
+ TextFileView* pView = newDoc->getView();
+ if (pView) {
+ wxFrame* pFrame = pView->getFrame();
+ if (pFrame)
+ pFrame->SetSize(0,0);
+ }
+ newDoc->SetDocumentName(strFilename);
+ newDoc->SetFilename(strFilename);
+ newDoc->SetDocumentTemplate(m_pDocTemplText);
+ newDoc->SetTitle(strFilename);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+
+PhantomFileDocument*
+CTSimApp::newPhantomDoc()
+{
+ wxString strFilename (getUntitledFilename());
+ strFilename += ".phm";
+
+ PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (strFilename));
+ if (newDoc) {
+ PhantomFileView* pView = newDoc->getView();
+ if (pView) {
+ wxFrame* pFrame = pView->getFrame();
+ if (pFrame)
+ pFrame->SetSize(0,0);
+ }
+ newDoc->SetDocumentName(strFilename);
+ newDoc->SetFilename(strFilename);
+ newDoc->SetDocumentTemplate(m_pDocTemplPhantom);
+ newDoc->SetTitle(strFilename);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}