Fix all remaining compiler warnings
[ctsim.git] / src / views.cpp
index 72ba35a88e8035dff3cb91044566a11ab9224a49..7e6de1d411250a42918c0336e38a3667429935d6 100644 (file)
@@ -7,9 +7,7 @@
 **   Date Started:  July 2000
 **
 **  This is part of the CTSim program
-**  Copyright (c) 1983-2001 Kevin Rosenberg
-**
-**  $Id$
+**  Copyright (c) 1983-2009 Kevin Rosenberg
 **
 **  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
@@ -342,7 +340,7 @@ ImageFileView::OnScaleMinMax (wxCommandEvent& event)
 {
   const ImageFile& rIF = GetDocument()->getImageFile();
   double min, max;
-  if (! m_bMinSpecified && ! m_bMaxSpecified)
+  if (! m_bMinSpecified || ! m_bMaxSpecified)
     rIF.getMinMax (min, max);
 
   if (m_bMinSpecified)
@@ -1065,7 +1063,7 @@ ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
   m_pCanvas = CreateCanvas (m_pFrame);
   m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
   m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
-  m_pFrame->SetTitle(_T("ImageFileView"));
+  m_pFrame->SetTitle(doc->GetFilename());
 
   m_pFrame->Show(true);
   Activate(true);
@@ -1312,14 +1310,9 @@ ImageFileView::OnExport (wxCommandEvent& event)
         strWildcard = _T("Miscellaneous (*.*)|*.*");
       }
 
-#if WXWIN_COMPATIBILITY_2_4
-      const wxString& strFilename = wxFileSelector (_T("Export Filename"), _T(""),
-        _T(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
-#else
       const wxString& strFilename = wxFileSelector (_T("Export Filename"), _T(""),
-        _T(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxSAVE);
-#endif
-      if (strFilename) {
+                                                    _T(""), strExt, strWildcard, wxFD_OVERWRITE_PROMPT | wxFD_SAVE);
+      if (! strFilename.empty()) {
         rIF.exportImage (strFormatName.mb_str(wxConvUTF8), strFilename.mb_str(wxConvUTF8), 1, 1, m_dMinPixel, m_dMaxPixel);
         *theApp->getLog() << _T("Exported file ") << strFilename << _T("\n");
       }
@@ -1445,7 +1438,7 @@ ImageFileView::OnPlotRow (wxCommandEvent& event)
       }
       for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
         rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
-      os << " Plot of " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str();
+      os << ": plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
       *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
       rPlotFile.addDescription (os.str().c_str());
     }
@@ -1479,8 +1472,8 @@ ImageFileView::OnPlotCol (wxCommandEvent& event)
   int ny = rIF.ny();
 
   if (v != NULL && xCursor < nx) {
-    double* pX = new double [ny];
-    double* pYReal = new double [ny];
+    double* const pX = new double [ny];
+    double* const pYReal = new double [ny];
     double* pYImag = NULL;
     double* pYMag = NULL;
     if (rIF.isComplex()) {
@@ -1531,7 +1524,7 @@ ImageFileView::OnPlotCol (wxCommandEvent& event)
       }
       for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
         rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
-      os << " Plot of " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str();
+      os << " : plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
       *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
       rPlotFile.addDescription (os.str().c_str());
     }
@@ -1626,7 +1619,7 @@ ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
       rPlotFile.addColumn (3, pYMag);
       for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
         rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
-      os << " FFT Plot of " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str();
+      os << ": FFT plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
       *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
       rPlotFile.addDescription (os.str().c_str());
     }
@@ -1726,7 +1719,7 @@ ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
       rPlotFile.addColumn (3, pYMag);
       for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
         rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
-      os << " FFT Plot of " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str();
+      os << ": FFT plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
       *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
       rPlotFile.addDescription (os.str().c_str());
     }
@@ -1788,7 +1781,7 @@ ImageFileView::OnCompareCol (wxCommandEvent& event)
       } else {
         PlotFile& rPlotFile = pPlotDoc->getPlotFile();
         std::ostringstream os;
-        os << "Column " << xCursor << " Comparison";
+        os << "Column " << xCursor << ": Comparison";
         std::string title("title ");
         title += os.str();
         rPlotFile.addEzsetCommand (title.c_str());
@@ -1810,7 +1803,7 @@ ImageFileView::OnCompareCol (wxCommandEvent& event)
         unsigned int iL;
         for (iL = 0; iL < rIF.nLabels(); iL++) {
           std::ostringstream os;
-          os << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
+          os << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str();
           os << ": " << rIF.labelGet(iL).getLabelString();
           rPlotFile.addDescription (os.str().c_str());
         }
@@ -1821,8 +1814,8 @@ ImageFileView::OnCompareCol (wxCommandEvent& event)
           os << rCompareIF.labelGet(iL).getLabelString();
           rPlotFile.addDescription (os.str().c_str());
         }
-        os << " Between " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str() << " and "
-           << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().c_str();
+        os << " between " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8) << " and "
+           << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
         *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
         rPlotFile.addDescription (os.str().c_str());
       }
@@ -1882,7 +1875,7 @@ ImageFileView::OnCompareRow (wxCommandEvent& event)
       } else {
         PlotFile& rPlotFile = pPlotDoc->getPlotFile();
         std::ostringstream os;
-        os << "Row " << yCursor << " Comparison";
+        os << "Row " << yCursor << ": Comparison";
         std::string title("title ");
         title += os.str();
         rPlotFile.addEzsetCommand (title.c_str());
@@ -1914,8 +1907,8 @@ ImageFileView::OnCompareRow (wxCommandEvent& event)
              << rCompareIF.labelGet(iL).getLabelString();
           rPlotFile.addDescription (os.str().c_str());
         }
-        os << " Between " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8) << " and "
-           << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().c_str();
+        os << " between " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8) << " and "
+           << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
         *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
         rPlotFile.addDescription (os.str().c_str());
       }
@@ -1958,42 +1951,42 @@ ImageFileView::OnPlotHistogram (wxCommandEvent& event)
       pX[i] = dMin + (i + 0.5) * dBinWidth;
       pY[i] = 0;
     }
-    for (int ix = 0; ix < nx; ix++)
+    for (int ix = 0; ix < nx; ix++) {
       for (int iy = 0; iy < ny; iy++) {
         int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
         if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
           pY[iBin] += 1;
       }
-
-      PlotFile& rPlotFile = pPlotDoc->getPlotFile();
+    }
+    PlotFile& rPlotFile = pPlotDoc->getPlotFile();
+    std::ostringstream os;
+    os << "Histogram";
+    std::string title("title ");
+    title += os.str();
+    rPlotFile.addEzsetCommand (title.c_str());
+    rPlotFile.addEzsetCommand ("xlabel Pixel Value");
+    rPlotFile.addEzsetCommand ("ylabel Count");
+    rPlotFile.addEzsetCommand ("box");
+    rPlotFile.addEzsetCommand ("grid");
+    rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
+    rPlotFile.addColumn (0, pX);
+    rPlotFile.addColumn (1, pY);
+    for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
       std::ostringstream os;
-      os << "Histogram";
-      std::string title("title ");
-      title += os.str();
-      rPlotFile.addEzsetCommand (title.c_str());
-      rPlotFile.addEzsetCommand ("xlabel Pixel Value");
-      rPlotFile.addEzsetCommand ("ylabel Count");
-      rPlotFile.addEzsetCommand ("box");
-      rPlotFile.addEzsetCommand ("grid");
-      rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
-      rPlotFile.addColumn (0, pX);
-      rPlotFile.addColumn (1, pY);
-      for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
-        std::ostringstream os;
-        os << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
-        os << ": " << rIF.labelGet(iL).getLabelString();
-        rPlotFile.addDescription (os.str().c_str());
-      }
-      os << "  plot of " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str();
-      *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
+      os << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
+      os << ": " << rIF.labelGet(iL).getLabelString();
       rPlotFile.addDescription (os.str().c_str());
-      delete pX;
-      delete pY;
-      if (theApp->getAskDeleteNewDocs())
-        pPlotDoc->Modify (true);
-      pPlotDoc->getView()->getFrame()->Show(true);
-      pPlotDoc->UpdateAllViews ();
-      pPlotDoc->Activate();
+    }
+    os << " plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
+    *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
+    rPlotFile.addDescription (os.str().c_str());
+    delete pX;
+    delete pY;
+    if (theApp->getAskDeleteNewDocs())
+      pPlotDoc->Modify (true);
+    pPlotDoc->getView()->getFrame()->Show(true);
+    pPlotDoc->UpdateAllViews ();
+    pPlotDoc->Activate();
   }
 }
 
@@ -2145,18 +2138,18 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
   }
 
   std::ostringstream os;
-  os << "Projections for " << rPhantom.name()
-        << ": nDet=" << m_iDefaultNDet
-    << ", nView=" << m_iDefaultNView
-        << ", gantry offset=" << m_iDefaultOffsetView
-        << ", nSamples=" << m_iDefaultNSample
-    << ", RotAngle=" << m_dDefaultRotation
-        << ", FocalLengthRatio=" << m_dDefaultFocalLength
-    << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
-    << ", ViewRatio=" << m_dDefaultViewRatio
-        << ", ScanRatio=" << m_dDefaultScanRatio
-    << ", Geometry=" << sGeometry.c_str()
-        << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
+  os << "Projections for " << rPhantom.name().c_str()
+     << ": nDet=" << m_iDefaultNDet
+     << ", nView=" << m_iDefaultNView
+     << ", gantry offset=" << m_iDefaultOffsetView
+     << ", nSamples=" << m_iDefaultNSample
+     << ", RotAngle=" << m_dDefaultRotation
+     << ", FocalLengthRatio=" << m_dDefaultFocalLength
+     << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
+     << ", ViewRatio=" << m_dDefaultViewRatio
+     << ", ScanRatio=" << m_dDefaultScanRatio
+     << ", Geometry=" << sGeometry.mb_str(wxConvUTF8)
+     << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
 
   Timer timer;
   Projections* pProj = NULL;
@@ -2309,11 +2302,11 @@ PhantomFileView::OnRasterize (wxCommandEvent& event)
 PhantomCanvas*
 PhantomFileView::CreateCanvas (wxFrame *parent)
 {
-  PhantomCanvas* pCanvas = new PhantomCanvas (this, parent, wxPoint(-1,-1),
-                                              wxSize(-1,-1), 0);
+  PhantomCanvas* pCanvas =
+    new PhantomCanvas (this, parent, wxPoint(-1,-1),
+                       wxSize(-1,-1), wxFULL_REPAINT_ON_RESIZE);
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->ClearBackground();
-
   return pCanvas;
 }
 
@@ -2392,7 +2385,7 @@ PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
   m_pCanvas = CreateCanvas (m_pFrame);
   m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
   m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
-  m_pFrame->SetTitle (_T("PhantomFileView"));
+  m_pFrame->SetTitle (doc->GetFilename());
 
   m_pFrame->Show(true);
   Activate(true);
@@ -3135,7 +3128,7 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
   m_pCanvas = CreateCanvas (m_pFrame);
   m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
   m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
-  m_pFrame->SetTitle (_T("ProjectionFileView"));
+  m_pFrame->SetTitle (doc->GetFilename());
 
   m_pFrame->Show(true);
   Activate(true);
@@ -3256,7 +3249,9 @@ ProjectionFileView::OnClose (bool deleteWindow)
 
 
 // PlotFileCanvas
-PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
+PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame,
+                                const wxPoint& pos, const wxSize& size,
+                                const long style)
   : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
 {
 }
@@ -3347,8 +3342,7 @@ void
 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
 {
   const PlotFile& rPlotFile = GetDocument()->getPlotFile();
-  double min;
-  double max;
+  double min, max;
 
   if (! m_bMinSpecified || ! m_bMaxSpecified) {
     if (! rPlotFile.getMinMax (1, min, max)) {
@@ -3377,11 +3371,9 @@ PlotFileView::OnScaleMinMax (wxCommandEvent& event)
 void
 PlotFileView::OnScaleFull (wxCommandEvent& event)
 {
-  if (m_bMinSpecified || m_bMaxSpecified) {
-    m_bMinSpecified = false;
-    m_bMaxSpecified = false;
-    OnUpdate (this, NULL);
-  }
+  m_bMinSpecified = false;
+  m_bMaxSpecified = false;
+  OnUpdate (this, NULL);
   GetDocument()->Activate();
 }
 
@@ -3391,7 +3383,8 @@ PlotFileView::CreateCanvas (wxFrame* parent)
 {
   PlotFileCanvas* pCanvas;
 
-  pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0);
+  pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1),
+                                wxFULL_REPAINT_ON_RESIZE);
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->ClearBackground();
 
@@ -3480,7 +3473,10 @@ PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
   m_pCanvas = CreateCanvas (m_pFrame);
   m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
   m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
-  m_pFrame->SetTitle (_T("Plot File"));
+  m_pFrame->SetTitle (_T("test"));
+  *theApp->getLog() << _T("Plot doc name: ") << doc->GetDocumentName() << _T("\n");
+  *theApp->getLog() << _T("Plot file name: ") << doc->GetFilename() << _T("\n");
+  m_pFrame->SetTitle (doc->GetFilename());
 
   m_pFrame->Show(true);
   Activate(true);
@@ -3568,8 +3564,9 @@ PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
     delete pdY;
   }
 
-  if (m_pCanvas)
+  if (m_pCanvas) {
     m_pCanvas->Refresh();
+  }
 }
 
 bool
@@ -3617,9 +3614,8 @@ bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
 
   int width, height;
   m_pFrame->GetClientSize(&width, &height);
-  m_pFrame->SetTitle(_T("TextFile"));
+  m_pFrame->SetTitle(doc->GetFilename());
   m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(-1,-1), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
-  m_pFrame->SetTitle(_T("Log"));
 
   m_pFrame->Show (true);
   Activate (true);