r423: Added splash screen for About box
[ctsim.git] / src / ctsim.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          ctsim.cpp
5 **   Purpose:       Top-level routines of CTSim program
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  July 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: ctsim.cpp,v 1.37 2001/01/19 22:53:57 kevin Exp $
13 **
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.
17 **
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.
22 **
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 ******************************************************************************/
27
28 #ifdef MSVC
29 #define strdup _strdup
30 #endif
31
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
34
35 #ifdef __BORLANDC__
36 #pragma hdrstop
37 #endif
38
39 #ifndef WX_PRECOMP
40 #include "wx/wx.h"
41 #endif
42
43 #include "wx/image.h"
44 #include "wx/filesys.h"
45 #include "wx/fs_zip.h"
46
47 #if !wxUSE_DOC_VIEW_ARCHITECTURE
48 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
49 #endif
50
51 #include "ct.h"
52 #include "ctsim.h"
53 #include "ctsim-map.h"
54 #include "docs.h"
55 #include "views.h"
56 #include "dialogs.h"
57
58 #if defined(HAVE_CONFIG_H)
59 #include "config.h"
60 #endif
61
62 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
63 #ifdef MSVC
64 #define __STDC__ 1
65 #endif
66 #include "getopt.h"
67 #ifdef MSVC
68 #undef __STDC__
69 #endif
70 #endif
71
72 static const char* rcsindent = "$Id: ctsim.cpp,v 1.37 2001/01/19 22:53:57 kevin Exp $";
73
74 struct option CTSimApp::ctsimOptions[] = 
75 {
76   {"help", 0, 0, O_HELP},
77   {"version", 0, 0, O_VERSION},
78   {0, 0, 0, 0}
79 };
80
81 IMPLEMENT_APP(CTSimApp)
82
83 CTSimApp::CTSimApp()
84 : m_docManager(NULL), m_pFrame(NULL)
85 {
86   theApp = this;
87 }
88
89 #ifdef HAVE_SYS_TIME_H
90 #include <sys/time.h>
91 #endif
92
93 #ifdef HAVE_SYS_RESOURCE_H
94 #include <sys/resource.h>
95 #endif
96
97 bool
98 CTSimApp::OnInit()
99 {
100 #ifdef HAVE_SETPRIORITY
101   setpriority (PRIO_PROCESS, 0, 15);  // set to low scheduling priority
102 #endif
103   
104   g_bRunningWXWindows = true;
105   // process options
106   while (1) {
107     int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
108     if (c == -1)
109       break;
110     
111     switch (c) {
112     case O_VERSION:
113       std::cout << rcsindent << std::endl;
114 #ifdef CTSIMVERSION
115       std::cout << "Version: CTSIMVERSION" << std::endl;
116 #elif defined(VERSION)
117       std::cout << "Version: VERSION" << std::endl;
118 #endif
119       exit(0);
120     case O_HELP:
121     case '?':
122       usage (argv[0]);
123       exit (0);
124     default:
125       usage (argv[0]);
126       exit (1);
127     }
128   }
129   
130   m_docManager = new wxDocManager;
131   
132   new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile doc", "ImageFile View", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
133   new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile doc", "ProjectionFile View", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
134   new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "Phantom doc", "Phantom View", CLASSINFO(PhantomDocument), CLASSINFO(PhantomView));
135   new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "Plot doc", "Plot View", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
136   
137 #if wxUSE_GIF
138   wxImage::AddHandler(new wxGIFHandler);     // Required for images in the online documentation
139 #endif
140   
141 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
142   wxFileSystem::AddHandler(new wxZipFSHandler);     // Required for advanced HTML help
143 #endif
144   
145   // Create the main frame window
146   m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
147   
148   SetTopWindow (m_pFrame);
149   m_pFrame->Centre(wxBOTH);
150   
151   m_pFrame->Show(true);
152   
153   for (int i = optind + 1; i <= argc; i++) {
154     wxString filename = argv [i - 1];
155     m_docManager->CreateDocument (filename, wxDOC_SILENT);
156   }
157   
158   setIconForFrame (m_pFrame);
159   
160   if (! m_pFrame->getHelpController().Initialize("ctsim"))
161     ::wxMessageBox ("Cannot initialize the help system", "Error");
162   
163   
164   return true;
165 }
166
167
168 #include "./ctsim.xpm"
169 void
170 CTSimApp::setIconForFrame(wxFrame* pFrame)
171 {
172   wxIcon iconApp (ctsim16_xpm);
173   
174   if (iconApp.Ok())
175     pFrame->SetIcon (iconApp);
176 }
177
178 void
179 CTSimApp::usage(const char* program)
180 {
181   std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
182   std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
183   std::cout << "\n";
184   std::cout << "  --version Display version\n";
185   std::cout << "  --help    Display this help message\n";
186 }
187
188 int
189 CTSimApp::OnExit()
190 {
191   delete m_docManager;
192 #ifdef HAVE_DMALLOC
193   dmalloc_shutdown();
194 #endif
195   return 0;
196 }
197
198 wxString
199 CTSimApp::getUntitledFilename()
200 {
201   static int untitledNumber = 1;
202   
203   wxString filename ("Untitled");
204   filename << untitledNumber++;
205   
206   return (filename);
207 }
208
209
210 // Top-level window for CTSim
211
212 #if CTSIM_MDI
213 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
214
215 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
216 #else
217 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
218
219 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
220 #endif
221
222 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
223 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
224 EVT_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
225 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
226 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
227 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
228 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
229 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
230 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
231 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
232 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
233 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
234 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
235 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
236 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
237 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
238 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
239 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
240 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
241 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
242 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
243 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
244 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
245 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
246 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
247 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
248 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
249 END_EVENT_TABLE()
250
251
252
253 #if CTSIM_MDI
254 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
255 : wxMDIParentFrame(NULL,  id, title, pos, size, type), m_pLog(NULL)
256 #else
257 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
258 : wxDocParentFrame(manager, frame, id, title, pos, size, type), m_pLog(NULL)
259 #endif
260 {
261   m_pLog = new wxTextCtrl (this, -1, "Log Window\n", wxPoint(0, 250), wxSize(100,50), wxTE_MULTILINE | wxTE_READONLY);
262   wxLog::SetActiveTarget(new wxLogTextCtrl(m_pLog));
263   CreateStatusBar();
264   SetStatusText ("Welcome to CTSim");
265   
266   //// Make a menubar
267   wxMenu *file_menu = new wxMenu;
268   
269   file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
270   file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
271   file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
272   
273   file_menu->AppendSeparator();
274   file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
275   
276   //  history of files visited
277   theApp->getDocManager()->FileHistoryUseMenu(file_menu);
278   
279   m_pWindowMenu = new wxMenu;
280   m_pWindowMenu->UpdateUI (this);
281   
282   wxMenu* help_menu = new wxMenu;
283   help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
284   help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
285   help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
286   
287   wxMenuBar* menu_bar = new wxMenuBar;
288   
289   menu_bar->Append(file_menu, "&File");
290   menu_bar->Append(m_pWindowMenu, "&Window");
291   menu_bar->Append(help_menu, "&Help");
292   
293   SetMenuBar(menu_bar);
294   
295   for (int i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
296     m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("<Empty>"));
297     m_pWindowMenu->Append (m_apWindowMenuItems[i]);
298     m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
299   }
300   
301   m_iDefaultPhantomID = Phantom::PHM_HERMAN;
302   m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
303   m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
304   m_iDefaultFilterXSize = 256;
305   m_iDefaultFilterYSize = 256;
306   m_dDefaultFilterParam = 1.;
307   m_dDefaultFilterBandwidth = 1.;
308   m_dDefaultFilterInputScale = 1.;
309   m_dDefaultFilterOutputScale = 1.;
310   
311   wxAcceleratorEntry accelEntries[14];
312   accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
313   accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
314   accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
315   accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
316   accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
317   for (i = 0; i < 10; i++)
318     accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
319   wxAcceleratorTable accelTable (16, accelEntries);
320   SetAcceleratorTable (accelTable);
321 }
322
323 void 
324 MainFrame::OnCreatePhantom(wxCommandEvent& event)
325 {
326   DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
327   int dialogReturn = dialogPhantom.ShowModal();
328   if (dialogReturn == wxID_OK) {
329     wxString selection (dialogPhantom.getPhantom());
330     *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
331     wxString filename = selection + ".phm";
332     m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
333     theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT);
334   }
335   
336 }
337
338 void 
339 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
340 {
341   DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
342   int dialogReturn = dialogFilter.ShowModal();
343   if (dialogReturn == wxID_OK) {
344     wxString strFilter (dialogFilter.getFilterName());
345     wxString strDomain (dialogFilter.getDomainName());
346     m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
347     m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
348     m_iDefaultFilterXSize = dialogFilter.getXSize();
349     m_iDefaultFilterYSize = dialogFilter.getYSize();
350     m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
351     m_dDefaultFilterParam= dialogFilter.getFilterParam();
352     m_dDefaultFilterInputScale = dialogFilter.getInputScale();
353     m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
354     std::ostringstream os;
355     os << "Generate Filter=" << strFilter.c_str() 
356       << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize) 
357       << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth 
358       << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
359     *theApp->getLog() << os.str().c_str() << "\n";
360     wxString filename = "untitled.if";
361     ImageFileDocument* pFilterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument ("untitled.if", wxDOC_SILENT));
362     if (! pFilterDoc) {
363       sys_error (ERR_SEVERE, "Unable to create filter image");
364       return;
365     }
366     ImageFile& rIF = pFilterDoc->getImageFile();
367     rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
368     rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
369     rIF.labelAdd (os.str().c_str());
370     if (theApp->getSetModifyNewDocs())
371       pFilterDoc->Modify (true);
372     pFilterDoc->UpdateAllViews();
373     pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
374   }
375 }
376
377 void
378 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
379 {
380   const ImageFile& rIF = pIFDoc->getImageFile();
381   unsigned int nx = rIF.nx();
382   unsigned int ny = rIF.ny();
383   wxList& rListDocs = m_docManager->GetDocuments();
384   for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
385     wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
386     ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
387     if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
388       const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
389       if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
390         vecIF.push_back (pIFCompareDoc);
391     }
392   }
393 }
394
395 void 
396 MainFrame::OnHelpTopics (wxCommandEvent& event)
397 {
398   showHelp (event.GetId());
399 }
400
401 void 
402 MainFrame::OnHelpContents (wxCommandEvent& event)
403 {
404   showHelp (event.GetId());
405 }
406
407 void
408 MainFrame::showHelp (int commandID)
409 {
410   m_help.LoadFile();
411   
412   switch (commandID) {
413   case MAINMENU_HELP_CONTENTS:
414     m_help.DisplayContents ();
415     break;
416   case MAINMENU_HELP_TOPICS:
417     m_help.DisplaySection (introduction);
418     break;
419     
420   default:
421     *getLog() << "Unknown help command # " << commandID << "\n";
422     break;
423   }
424 }
425
426 void 
427 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
428 {
429   Close(true);
430 }
431
432 void
433 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
434 {
435   int iPos = 0;
436   wxList& rListDocs = theApp->getDocManager()->GetDocuments();
437   wxNode* pNode = rListDocs.GetFirst();
438   while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
439     wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
440     wxString strFilename = pDoc->GetFilename();
441     if (iPos < 10) {
442       strFilename += "\tCtrl-";
443       strFilename += static_cast<char>('0' + iPos);
444     }
445     static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
446     m_apWindowMenuData[iPos] = pDoc;
447     m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
448     iPos++;
449     pNode = pNode->GetNext();
450   }
451   for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
452     m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
453     static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("<Empty>"));
454     m_apWindowMenuData[i] = NULL;
455   }
456   
457 }
458
459 void 
460 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
461 {
462   if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
463     wxString strFilename = pDoc->GetFilename();
464     const wxView* pView = pDoc->GetFirstView();
465     if (pView) {
466       wxFrame* pFrame = pView->GetFrame();
467       pFrame->SetFocus();
468       pFrame->Raise();
469     }
470   }
471 }
472
473 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
474 { DoWindowMenu (0, event); }
475
476 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
477 { DoWindowMenu (1, event); }
478
479 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
480 { DoWindowMenu (2, event); }
481
482 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
483 { DoWindowMenu (3, event); }
484
485 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
486 { DoWindowMenu (4, event); }
487
488 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
489 { DoWindowMenu (5, event); }
490
491 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
492 { DoWindowMenu (6, event); }
493
494 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
495 { DoWindowMenu (7, event); }
496
497 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
498 { DoWindowMenu (8, event); }
499
500 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
501 { DoWindowMenu (9, event); }
502
503 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
504 { DoWindowMenu (10, event); }
505
506 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
507 { DoWindowMenu (11, event); }
508
509 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
510 { DoWindowMenu (12, event); }
511
512 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
513 { DoWindowMenu (13, event); }
514
515 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
516 { DoWindowMenu (14, event); }
517
518 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
519 { DoWindowMenu (15, event); }
520
521 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
522 { DoWindowMenu (16, event); }
523
524 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
525 { DoWindowMenu (17, event); }
526
527 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
528 { DoWindowMenu (18, event); }
529
530 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
531 { DoWindowMenu (19, event); }
532
533
534 class BitmapControl : public wxPanel
535 {
536 private:  
537   DECLARE_DYNAMIC_CLASS (BitmapControl)
538     DECLARE_EVENT_TABLE ()
539     wxBitmap* m_pBitmap;
540   
541 public:
542   BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
543     const wxPoint& pos = wxDefaultPosition,
544     const wxSize& size = wxDefaultSize,
545     long style = wxSTATIC_BORDER,
546     const wxValidator& validator = wxDefaultValidator,
547     const wxString& name = "BitmapCtrl");
548   
549   
550   virtual ~BitmapControl();
551   
552   virtual wxSize GetBestSize() const;
553   
554   wxBitmap* getBitmap() 
555   { return m_pBitmap; }
556   
557   void OnPaint(wxPaintEvent& event);
558 };
559
560
561 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
562 EVT_PAINT(BitmapControl::OnPaint)
563 END_EVENT_TABLE()
564
565 IMPLEMENT_CLASS(BitmapControl, wxPanel)
566
567
568 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, 
569                               long style, const wxValidator& validator, const wxString& name)
570                               : m_pBitmap(pBitmap)
571 {
572   Create(parent, id, pos, size, style, name);
573   
574   SetSize (GetBestSize());
575 }
576
577 wxSize
578 BitmapControl::GetBestSize () const
579 {
580   if (m_pBitmap)
581     return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
582   else
583     return wxSize(0,0);
584 }
585
586 BitmapControl::~BitmapControl()
587 {}
588
589 void
590 BitmapControl::OnPaint (wxPaintEvent& event)
591 {
592   wxPaintDC dc(this);
593   if (m_pBitmap)
594     dc.DrawBitmap (*m_pBitmap, 0, 0);
595 }
596
597
598 class BitmapDialog : public wxDialog {
599 private:
600   BitmapControl* m_pBitmapCtrl;
601   
602 public:
603   BitmapDialog (wxBitmap* pBitmap);
604   virtual ~BitmapDialog();
605 };
606
607 BitmapDialog::BitmapDialog (wxBitmap* pBitmap)
608 : wxDialog(theApp->getMainFrame(), -1, wxString("About"), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL)
609 {
610   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
611   
612   pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
613   
614   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
615   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
616   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
617   
618   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
619   
620   SetAutoLayout (true);
621   SetSizer (pTopSizer);
622   pTopSizer->Fit (this);
623   pTopSizer->SetSizeHints (this);
624 }
625
626 BitmapDialog::~BitmapDialog()
627 {}
628
629 #include "./splash.xpm"
630
631 void 
632 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
633 {
634   //
635   //  wxImage image;
636   //  if (wxFile::image.LoadFile ("/splash.png")) {
637   wxBitmap bmp (splash);
638   if (bmp.Ok()) {
639     BitmapDialog dlg (&bmp);
640     dlg.Show(true);
641   } else {
642     wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
643 #ifdef CTSIMVERSION
644     msg += "Version ";
645     msg += CTSIMVERSION;
646     msg += "\n\n";
647 #elif defined(VERSION)
648     msg << "Version: " <<  VERSION << "\n\n";
649 #endif
650     msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
651     
652     wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
653   }
654 }
655