Fix plot initialization, improve frame titles
authorKevin Rosenberg <kevin@rosenberg.net>
Sun, 9 Aug 2009 01:21:06 +0000 (19:21 -0600)
committerKevin Rosenberg <kevin@rosenberg.net>
Sun, 9 Aug 2009 01:21:06 +0000 (19:21 -0600)
ChangeLog
libctgraphics/ezplot.cpp
src/ctsim.cpp
src/ctsim.h
src/docs.cpp
src/views.cpp

index 919da87360a7839057c110edba1ae8a43826227f..8fb1ba6941c6db22fe4c5bab1bd0efe360fc424a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 Aug 6, 2009  Version 5.0.6
        * Use wxWidgets command-line processing rather than existing
        native processing.
+       * ezset.cpp: Initialize scale settings in constructor
+       * Improve titles of frames
 
 Aug 3, 2009  Version 5.0.5
        * Fix plots when maximum plot value is the same as minimum
index cb4e0ece37358d9e6a15a0210936f18f9d787abc..4f32d63769a84413c23b69c9d45dc2e283691fc6 100644 (file)
@@ -215,6 +215,10 @@ EZPlot::initPlotSettings ()
   s_xlegend  = FALSE;
   s_ylegend  = FALSE;
   s_textsize = FALSE;
+  s_xmin     = FALSE;
+  s_xmax     = FALSE;
+  s_ymin     = FALSE;
+  s_ymax     = FALSE;
 
   clr_axis   = C_LTGRAY;                // set fixed colors
   clr_title  = C_RED;
@@ -479,15 +483,28 @@ EZPlot::plot (SGP* pSGP)
   double symheight = charheight * 0.3;       // size of symbol in NDC
   double symwidth = symheight;
 
-  const EZPlotCurve& firstCurve = *m_vecCurves[0];
+  if (m_vecCurves.size() < 1)
+    return; // can't plot if there are no curves to plot
 
-  double xmin = firstCurve.x[0];   // extent of curves in world coord
-  double xmax = xmin;
-  double ymin = firstCurve.y[0];
-  double ymax = ymin;
+  // find a curve with at least one point to get base point
+  double xmin, xmax, ymin, ymax;   // extent of curves in world coord
+  bool found = false;
 
-  unsigned int iCurve;
-  for (iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
+  for (unsigned int iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
+    const EZPlotCurve* const pCurve = m_vecCurves [iCurve];
+    if (pCurve->m_iPointCount > 0) {
+      xmin = pCurve->x[0];
+      xmax = xmin;
+      ymin = pCurve->y[0];
+      ymax = ymin;
+      found = true;
+      break;
+    }
+  }
+  if (! found)
+    return; // curve(s) are empty, so no plotting
+
+  for (unsigned int iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
     const EZPlotCurve* const pCurve = m_vecCurves [iCurve];
 
     for (int ip = 0; ip < pCurve->m_iPointCount; ip++) {
@@ -521,6 +538,7 @@ EZPlot::plot (SGP* pSGP)
   if (! axis_scale (xmin, xmax, o_xmajortick - 1, &xgw_min, &xgw_max, &x_nint) || ! axis_scale (ymin, ymax, o_ymajortick - 1, &ygw_min, &ygw_max, &y_nint))
     return;
 
+
   // check if user set x-axis extents
   if (s_xmin == TRUE) {
     xgw_min = v_xmin;
@@ -597,7 +615,7 @@ EZPlot::plot (SGP* pSGP)
   int max_leg = 0;                      // longest legend in characters
   int num_leg = 0;                      // number of legend titles
 
-  for (iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
+  for (unsigned int iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
     const std::string* pstrLegend = getLegend (iCurve);
 
     if (pstrLegend && pstrLegend->length() > 0) {
@@ -638,7 +656,7 @@ EZPlot::plot (SGP* pSGP)
 
     int iLegend = 0;                    // current legend position
 
-    for (iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
+    for (unsigned int iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
       const std::string* pstrLegend = getLegend (iCurve);
       if (! pstrLegend || pstrLegend->length() == 0)
         continue;
@@ -820,18 +838,13 @@ EZPlot::plot (SGP* pSGP)
 
 
 
-  for (iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
+  for (unsigned int iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
     const EZPlotCurve* const pCurve = m_vecCurves [iCurve];
 
-
     m_pSGP->setColor (getColor (iCurve));
-
     int iSym = getSymbol (iCurve);
-
     int iLS = getLinestyle (iCurve);
 
-
-
     if (iLS != SGP::LS_NOLINE) {
       m_pSGP->setLineStyle (iLS);
       double x1 = convertWorldToNDC_X (pCurve->x[0]);
index 9b7957966c5fbc06b5668510edf909e944be53c1..756f6205be1abe990193b2beed6170ebe85723b6 100644 (file)
@@ -347,18 +347,6 @@ CTSimApp::closeConfig()
 }
 
 
-wxString
-CTSimApp::getUntitledFilename()
-{
-  static int untitledNumber = 1;
-
-  wxString filename (_T("Untitled"));
-  filename << untitledNumber++;
-
-  return (filename);
-}
-
-
 // Top-level window for CTSim
 
 #if CTSIM_MDI
@@ -597,7 +585,6 @@ MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
       m_dDefaultFilterBandwidth
        << _T(", inputScale=") << m_dDefaultFilterInputScale << _T(", outputScale=") << m_dDefaultFilterOutputScale;
     *theApp->getLog() << os << _T("\n");
-    wxString filename = _T("untitled.if");
     ImageFileDocument* pFilterDoc = theApp->newImageDoc();
     pFilterDoc->setBadFileOpen();
     if (! pFilterDoc) {
@@ -973,13 +960,8 @@ MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
     return;
   }
 
-#if WXWIN_COMPATIBILITY_2_4
-  wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")),
-                                         wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
-#else
   wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")),
                                          wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxOPEN);
-#endif
 
   if (! strFilename.IsEmpty()) {
     if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
@@ -1084,11 +1066,15 @@ MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
 ProjectionFileDocument*
 CTSimApp::newProjectionDoc()
 {
-  ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (_T("")));
+  wxString fname;
+  m_docManager->MakeDefaultName(fname);
+  fname += _T(".pj");
+  ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (fname));
   if (newDoc) {
     newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
     newDoc->SetDocumentTemplate (m_pDocTemplProjection);
     newDoc->OnNewDocument();
+    newDoc->SetFilename(fname);
   }
 
   return newDoc;
@@ -1097,11 +1083,15 @@ CTSimApp::newProjectionDoc()
 ImageFileDocument*
 CTSimApp::newImageDoc()
 {
-  ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (_T("")));
+  wxString fname;
+  m_docManager->MakeDefaultName(fname);
+  fname += _T(".if");
+  ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (fname));
   if (newDoc) {
     newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
     newDoc->SetDocumentTemplate (m_pDocTemplImage);
     newDoc->OnNewDocument();
+    newDoc->SetFilename(fname);
   }
 
   return newDoc;
@@ -1110,11 +1100,15 @@ CTSimApp::newImageDoc()
 PlotFileDocument*
 CTSimApp::newPlotDoc()
 {
-  PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (_T("")));
+  wxString fname;
+  m_docManager->MakeDefaultName(fname);
+  fname += _T(".plt");
+  PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (fname));
   if (newDoc) {
     newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
     newDoc->SetDocumentTemplate (m_pDocTemplPlot);
     newDoc->OnNewDocument();
+    newDoc->SetFilename(fname);
   }
 
   return newDoc;
@@ -1124,14 +1118,16 @@ CTSimApp::newPlotDoc()
 TextFileDocument*
 CTSimApp::newTextDoc()
 {
-  wxString strFilename (getUntitledFilename());
-  strFilename += wxString(".txt", *wxConvCurrent);
+  wxString fname;
+  m_docManager->MakeDefaultName(fname);
+  fname += _T(".txt");
 
-  TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (_T("")));
+  TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (fname));
   if (newDoc) {
     newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
     newDoc->SetDocumentTemplate (m_pDocTemplText);
     newDoc->OnNewDocument();
+    newDoc->SetFilename (fname);
   }
 
   return newDoc;
@@ -1141,11 +1137,15 @@ CTSimApp::newTextDoc()
 PhantomFileDocument*
 CTSimApp::newPhantomDoc()
 {
-  PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (_T("")));
+  wxString fname;
+  m_docManager->MakeDefaultName(fname);
+  fname += _T(".phm");
+  PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (fname));
   if (newDoc) {
     newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
     newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
     newDoc->OnNewDocument();
+    newDoc->SetFilename(fname);
   }
 
   return newDoc;
@@ -1156,13 +1156,18 @@ CTSimApp::newPhantomDoc()
 Graph3dFileDocument*
 CTSimApp::newGraph3dDoc()
 {
-  Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (_T("")));
+  wxString fname;
+  m_docManager->MakeDefaultName(fname);
+  fname += _T(".3dif");
+  Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (fname));
   if (newDoc) {
     newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
     newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
     newDoc->OnNewDocument();
+    newDoc->SetFilename(fname);
   }
 
   return newDoc;
 }
+
 #endif
index a98faa29d9ae23d8c71aa588170fb833b0bb6594..435f26595dd7fb6e0b68ce1a43ca284f2eecdd0d 100644 (file)
@@ -233,8 +233,6 @@ public:
   wxDocManager* getDocManager()
   { return m_docManager; }
 
-  wxString getUntitledFilename();
-
   int getNumberCPU() const { return wxThread::GetCPUCount(); }
 
   EZPlotDialog* makeEZPlotDialog()
index 2bf3579d5bb32eb887c2573535d80bb1e6077ec8..a47d8d993fe4f952e93edace295168acef3098aa 100644 (file)
@@ -76,6 +76,7 @@ bool ImageFileDocument::OnOpenDocument(const wxString& filename)
   SetFilename(filename, true);
   Modify(false);
   getView()->setInitialClientSize();
+  this->SetFilename(filename, true);
   UpdateAllViews();
   m_bBadFileOpen = false;
 
index ead413d04ddca300cd6ff14d54dda90a1ce35df8..5f0d4d4a3d7cbf88b74909d68630d2ee94ef4c48 100644 (file)
@@ -1063,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);
@@ -1413,7 +1413,7 @@ ImageFileView::OnPlotRow (wxCommandEvent& event)
     } else {
       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
       std::ostringstream os;
-      os << "Row " << yCursor << ": ";
+      os << "Row " << yCursor;
       std::string title("title ");
       title += os.str();
       rPlotFile.addEzsetCommand (title.c_str());
@@ -1443,7 +1443,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 " << wxConvUTF8.cWX2MB(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());
     }
@@ -1499,7 +1499,7 @@ ImageFileView::OnPlotCol (wxCommandEvent& event)
     } else {
       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
       std::ostringstream os;
-      os << "Column " << xCursor << ": ";
+      os << "Column " << xCursor;
       std::string title("title ");
       title += os.str();
       rPlotFile.addEzsetCommand (title.c_str());
@@ -1529,7 +1529,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 " << wxConvUTF8.cWX2MB(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());
     }
@@ -1599,7 +1599,7 @@ ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
     } else {
       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
       std::ostringstream os;
-      os << "Row " << yCursor << ": ";
+      os << "Row " << yCursor;
       std::string title("title ");
       title += os.str();
       rPlotFile.addEzsetCommand (title.c_str());
@@ -1624,7 +1624,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 " << wxConvUTF8.cWX2MB(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());
     }
@@ -1699,7 +1699,7 @@ ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
     } else {
       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
       std::ostringstream os;
-      os << "Column " << xCursor << ": ";
+      os << "Column " << xCursor;
       std::string title("title ");
       title += os.str();
       rPlotFile.addEzsetCommand (title.c_str());
@@ -1724,7 +1724,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 " << wxConvUTF8.cWX2MB(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());
     }
@@ -1965,7 +1965,7 @@ ImageFileView::OnPlotHistogram (wxCommandEvent& event)
 
       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
       std::ostringstream os;
-      os << "Histogram ";
+      os << "Histogram";
       std::string title("title ");
       title += os.str();
       rPlotFile.addEzsetCommand (title.c_str());
@@ -1982,7 +1982,7 @@ ImageFileView::OnPlotHistogram (wxCommandEvent& event)
         os << ": " << rIF.labelGet(iL).getLabelString();
         rPlotFile.addDescription (os.str().c_str());
       }
-      os << " Plot of " << wxConvUTF8.cWX2MB(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());
       delete pX;
@@ -2312,7 +2312,6 @@ PhantomFileView::CreateCanvas (wxFrame *parent)
                        wxSize(-1,-1), wxFULL_REPAINT_ON_RESIZE);
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->ClearBackground();
-
   return pCanvas;
 }
 
@@ -2391,7 +2390,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);
@@ -3134,7 +3133,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);
@@ -3255,7 +3254,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)
 {
 }
@@ -3375,14 +3376,8 @@ PlotFileView::OnScaleMinMax (wxCommandEvent& event)
 void
 PlotFileView::OnScaleFull (wxCommandEvent& event)
 {
-  const PlotFile& rPlotFile = GetDocument()->getPlotFile();
-  if (! rPlotFile.getMinMax (1, m_dMinPixel, m_dMaxPixel)) {
-    *theApp->getLog() << _T("Error: unable to find Min/Max\n");
-    return;
-  }
-
-  m_bMinSpecified = true;
-  m_bMaxSpecified = true;
+  m_bMinSpecified = false;
+  m_bMaxSpecified = false;
   OnUpdate (this, NULL);
   GetDocument()->Activate();
 }
@@ -3483,7 +3478,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);
@@ -3571,8 +3569,9 @@ PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
     delete pdY;
   }
 
-  if (m_pCanvas)
+  if (m_pCanvas) {
     m_pCanvas->Refresh();
+  }
 }
 
 bool
@@ -3620,9 +3619,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);