r1956: *** empty log message ***
[ctsim.git] / src / views.cpp
index 3aca5d4d1ff979ef68a63cb11c6974e2aeaa4292..5c3c0d095e5ffea4249bcd9ea9b8ce06c798aa66 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.150 2002/05/01 15:17:36 kevin Exp $
+**  $Id: views.cpp,v 1.155 2002/05/05 14:22:44 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
@@ -58,6 +58,8 @@
 #include <sstream_subst>
 #endif
 
+// Used to reduce calls to progress bar update function
+const short int ITER_PER_UPDATE = 10;
 
 // ImageFileCanvas
 
@@ -408,9 +410,8 @@ ImageFileView::OnCompare (wxCommandEvent& event)
         pDifferenceImage->labelAdd (os.str().c_str());
         if (theApp->getAskDeleteNewDocs())
           pDifferenceDoc->Modify (true);
-        pDifferenceDoc->UpdateAllViews (this);
-        pDifferenceDoc->getView()->OnUpdate (this, NULL);
-        pDifferenceDoc->getView()->getFrame()->Show(true);
+        pDifferenceDoc->UpdateAllViews(this);
+       pDifferenceDoc->getView()->setInitialClientSize();
         pDifferenceDoc->Activate();
       }
       wxMessageBox(os.str().c_str(), "Image Comparison");
@@ -513,7 +514,7 @@ ImageFileView::OnAdd (wxCommandEvent& event)
       if (theApp->getAskDeleteNewDocs())
         pNewDoc->Modify (true);
       pNewDoc->UpdateAllViews (this);
-      pNewDoc->getView()->getFrame()->Show(true);
+      pNewDoc->getView()->setInitialClientSize();
       pNewDoc->Activate();
     }
   }
@@ -554,7 +555,7 @@ ImageFileView::OnSubtract (wxCommandEvent& event)
       if (theApp->getAskDeleteNewDocs())
         pNewDoc->Modify (true);
       pNewDoc->UpdateAllViews (this);
-      pNewDoc->getView()->getFrame()->Show(true);
+      pNewDoc->getView()->setInitialClientSize();
       pNewDoc->Activate();
     }
   }
@@ -595,7 +596,7 @@ ImageFileView::OnMultiply (wxCommandEvent& event)
       if (theApp->getAskDeleteNewDocs())
         pNewDoc->Modify (true);
       pNewDoc->UpdateAllViews (this);
-      pNewDoc->getView()->getFrame()->Show(true);
+      pNewDoc->getView()->setInitialClientSize();
       pNewDoc->Activate();
     }
   }
@@ -636,7 +637,7 @@ ImageFileView::OnDivide (wxCommandEvent& event)
       if (theApp->getAskDeleteNewDocs())
         pNewDoc->Modify (true);
       pNewDoc->UpdateAllViews (this);
-      pNewDoc->getView()->getFrame()->Show(true);
+      pNewDoc->getView()->setInitialClientSize();
       pNewDoc->Activate();
     }
   }
@@ -1042,14 +1043,26 @@ ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
   return true;
 }
 
+void 
+ImageFileView::setInitialClientSize ()
+{
+  if (m_pFrame && m_pCanvas) {
+    wxSize bestSize = m_pCanvas->GetBestSize();
+
+    if (bestSize.x > 800)
+      bestSize.x = 800;
+    if (bestSize.y > 800)
+      bestSize.y = 800;
+    
+    m_pFrame->SetClientSize (bestSize);
+    m_pFrame->Show (true);
+    m_pFrame->SetFocus();
+  }
+}  
+
 void 
 ImageFileView::OnDraw (wxDC* dc)
 {
-  wxSize sizeWindow = m_pFrame->GetClientSize();
-  wxSize sizeBest = m_pCanvas->GetBestSize();
-  if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
-    m_pFrame->SetClientSize (sizeBest);
-  
   if (m_bitmap.Ok())
     dc->DrawBitmap(m_bitmap, 0, 0, false);
   
@@ -1103,10 +1116,6 @@ ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
     wxImage image (nx, ny, imageData, true);
     m_bitmap = image.ConvertToBitmap();
     delete imageData;
-    int xSize = nx;
-    int ySize = ny;
-    ySize = clamp (ySize, 0, 800);
-    //    m_pFrame->SetClientSize (xSize, ySize); // KMR
     m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
     m_pCanvas->SetBackgroundColour(*wxWHITE);
   } 
@@ -1304,7 +1313,7 @@ ImageFileView::OnScaleSize (wxCommandEvent& event)
     if (theApp->getAskDeleteNewDocs())
       pScaledDoc->Modify (true);
     pScaledDoc->UpdateAllViews (this);
-    pScaledDoc->getView()->getFrame()->Show(true);
+    pScaledDoc->getView()->setInitialClientSize();
     pScaledDoc->Activate();
   }
 }
@@ -1978,8 +1987,9 @@ PhantomCanvas::GetBestSize() const
 #ifdef CTSIM_MDI
   ySize = xSize = (xSize / 4);
 #else
-  ySize = xSize;
+  xSize = ySize = ySize * .7;
 #endif
+
   return wxSize (xSize, ySize);
 }
 
@@ -2148,10 +2158,11 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
       for (int i = 0; i < pProj->nView(); i++) {
         //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
         theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
-        if (! dlgProgress.Update (i+1)) {
-          delete pProj;
-          return;
-        }
+       if ((i + 1) % ITER_PER_UPDATE == 0)
+         if (! dlgProgress.Update (i+1)) {
+           delete pProj;
+           return;
+         }
       }
     }
   }
@@ -2166,21 +2177,10 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
     return;
   }
   pProjectionDoc->setProjections (pProj);
-  ProjectionFileView* projView = pProjectionDoc->getView();
-  if (projView) {
-    projView->OnUpdate (projView, NULL);
-    if (projView->getCanvas())
-      projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
-    if (wxFrame* pFrame = projView->getFrame()) {
-      pFrame->Show(true);
-      pFrame->SetFocus();
-      pFrame->Raise();
-    }
-    GetDocumentManager()->ActivateView (projView, true, false);
-  }
   if (theApp->getAskDeleteNewDocs())
     pProjectionDoc-> Modify(true);
   pProjectionDoc->UpdateAllViews (this);
+  pProjectionDoc->getView()->setInitialClientSize();
   pProjectionDoc->Activate();
 }
 
@@ -2226,15 +2226,21 @@ PhantomFileView::OnRasterize (wxCommandEvent& event)
   {
     ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
 
-    wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), 
-                 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
+    wxProgressDialog dlgProgress (wxString("Rasterize"), 
+                                 wxString("Rasterization Progress"), 
+                                 pImageFile->nx() + 1,
+                                 getFrameForChild(), 
+                                 wxPD_CAN_ABORT );
     Timer timer;
     for (unsigned int i = 0; i < pImageFile->nx(); i++) {
-      rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
-      if (! dlgProgress.Update (i+1)) {
-       delete pImageFile;
-       return;
-      }
+      rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, 
+                                  m_iDefaultRasterNSamples, Trace::TRACE_NONE,
+                                  i, 1, true);
+      if ((i + 1) % ITER_PER_UPDATE == 0) 
+       if (! dlgProgress.Update (i+1)) {
+         delete pImageFile;
+         return;
+       }
     }
     
     ImageFileDocument* pRasterDoc = theApp->newImageDoc();
@@ -2248,14 +2254,9 @@ PhantomFileView::OnRasterize (wxCommandEvent& event)
     *theApp->getLog() << os.str().c_str() << "\n";
     pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
 
-    if (ImageFileView* rasterView = pRasterDoc->getView()) {
-      rasterView->getFrame()->Show(true);
-      rasterView->getFrame()->SetFocus();
-      rasterView->OnUpdate (rasterView, NULL);
-    }
-    // Causes loss of frame in wxGTK 
-    // pRasterDoc->UpdateAllViews (this); 
-    // pRasterDoc->Activate();
+    pRasterDoc->UpdateAllViews(this);
+    pRasterDoc->getView()->setInitialClientSize();
+    pRasterDoc->Activate();
   }
 }
 
@@ -2349,15 +2350,8 @@ 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 ("PhantomFileView");
-  
-#ifdef __X__
-  int x, y;  // X requires a forced resize
-  m_pFrame->GetSize(&x, &y);
-  m_pFrame->SetSize(-1, -1, x, y);
-#endif
-  
+
   m_pFrame->Show(true);
   Activate(true);
   
@@ -2435,6 +2429,9 @@ wxSize
 ProjectionFileCanvas::GetBestSize () const
 {
   wxSize best (0, 0);
+  if (! m_pView)
+    return best;
+
   if (m_pView) {
     Projections& rProj = m_pView->GetDocument()->getProjections();
     best.Set (rProj.nDet(), rProj.nView());
@@ -2543,8 +2540,8 @@ ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
   pIF->labelAdd (os.str().c_str());
   if (theApp->getAskDeleteNewDocs())
     pRectDoc->Modify (true);
-  pRectDoc->getView()->getFrame()->Show(true);
-  pRectDoc->UpdateAllViews ();
+  pRectDoc->UpdateAllViews();
+  pRectDoc->getView()->setInitialClientSize();
   pRectDoc->Activate();
 }
 
@@ -2584,8 +2581,8 @@ ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
     pIF->labelAdd (os.str().c_str());
     if (theApp->getAskDeleteNewDocs())
       pPolarDoc->Modify (true);
-    pPolarDoc->getView()->getFrame()->Show(true);
     pPolarDoc->UpdateAllViews ();
+    pPolarDoc->getView()->setInitialClientSize();
     pPolarDoc->Activate();
   }
 }
@@ -2625,8 +2622,8 @@ ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
     pIF->labelAdd (os.str().c_str());
     if (theApp->getAskDeleteNewDocs())
       pPolarDoc->Modify (true);
-    pPolarDoc->getView()->getFrame()->Show(true);
-    pPolarDoc->UpdateAllViews ();
+    pPolarDoc->UpdateAllViews (this);
+    pPolarDoc->getView()->setInitialClientSize();
     pPolarDoc->Activate();
   }
 }
@@ -2774,6 +2771,7 @@ ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
   if (theApp->getAskDeleteNewDocs())
     pProjDocNew-> Modify(true);
   pProjDocNew->UpdateAllViews (this);
+  pProjDocNew->getView()->setInitialClientSize();
   pProjDocNew->Activate();
 }
 
@@ -2818,8 +2816,8 @@ ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
     pIF->labelAdd (os.str().c_str());
     if (theApp->getAskDeleteNewDocs())
       pPolarDoc->Modify (true);
-    pPolarDoc->getView()->getFrame()->Show(true);
     pPolarDoc->UpdateAllViews ();
+    pPolarDoc->getView()->setInitialClientSize();
     pPolarDoc->Activate();
   }
 }
@@ -2936,10 +2934,11 @@ ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToPar
       
       for (int iView = 0; iView < rProj.nView(); iView++) {
         pReconstructor->reconstructView (iView, 1);
-        if (! dlgProgress.Update (iView + 1)) {
-          delete pReconstructor;
-          return; // don't make new window, thread will do this
-        }
+       if ((iView + 1) % ITER_PER_UPDATE == 0) 
+         if (! dlgProgress.Update (iView + 1)) {
+           delete pReconstructor;
+           return; // don't make new window, thread will do this
+         }
       }
       pReconstructor->postProcessing();
       delete pReconstructor;
@@ -2950,22 +2949,16 @@ ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToPar
     sys_error (ERR_SEVERE, "Unable to create image file");
     return;
   }
-  pReconDoc->setImageFile (pImageFile);
-  if (theApp->getAskDeleteNewDocs())
-    pReconDoc->Modify (true);
   *theApp->getLog() << os.str().c_str() << "\n";
   pImageFile->labelAdd (rProj.getLabel());
   pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());    
 
-  //  if (ImageFileView* rasterView = pReconDoc->getView()) {
-  //    rasterView->getFrame()->Show(true);
-  //    rasterView->getFrame()->SetFocus();
-  //    rasterView->OnUpdate (rasterView, NULL);
-  //  }
-  // causes loss of frame in wxGTK
-  pReconDoc->GetFirstView()->GetFrame()->Show(true);
-  pReconDoc->UpdateAllViews ();
-  // pReconDoc->Activate();
+  pReconDoc->setImageFile (pImageFile);
+  if (theApp->getAskDeleteNewDocs())
+    pReconDoc->Modify (true);
+  pReconDoc->UpdateAllViews();
+  pReconDoc->getView()->setInitialClientSize();
+  pReconDoc->Activate();
 }
 
 
@@ -3095,12 +3088,6 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
   m_pFrame->SetTitle ("ProjectionFileView");
   m_pCanvas = CreateCanvas (m_pFrame);
   
-#ifdef __X__
-  int x, y;  // X requires a forced resize
-  m_pFrame->GetSize(&x, &y);
-  m_pFrame->SetSize(-1, -1, x, y);
-#endif
-  
   m_pFrame->Show(true);
   Activate(true);
   
@@ -3110,17 +3097,26 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
 void 
 ProjectionFileView::OnDraw (wxDC* dc)
 {
-  wxSize clientSize = m_pFrame->GetClientSize();
-  wxSize bestSize = m_pCanvas->GetBestSize();
-  
-  if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
-    m_pFrame->SetClientSize (bestSize);
-  
   if (m_bitmap.Ok())
     dc->DrawBitmap (m_bitmap, 0, 0, false);
 }
 
 
+void 
+ProjectionFileView::setInitialClientSize ()
+{
+  wxSize bestSize = m_pCanvas->GetBestSize();
+
+  if (bestSize.x > 800)
+    bestSize.x = 800;
+  if (bestSize.y > 800)
+    bestSize.y = 800;
+
+  m_pFrame->SetClientSize (bestSize);
+  m_pFrame->Show (true);
+  m_pFrame->SetFocus();
+}  
+
 void 
 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
 {
@@ -3162,16 +3158,13 @@ ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)
     wxImage image (nDet, nView, imageData, true);
     m_bitmap = image.ConvertToBitmap();
     delete imageData;
-    int xSize = nDet;
-    int ySize = nView;
-    xSize = clamp (xSize, 0, 800);
-    ySize = clamp (ySize, 0, 800);
-    m_pFrame->SetClientSize (xSize, ySize);
-    m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
   }
   
-  if (m_pCanvas)
-    m_pCanvas->Refresh();
+    m_pCanvas->SetScrollbars(20, 20, nDet/20, nView/20);
+    m_pCanvas->SetBackgroundColour(*wxWHITE);
+
+    if (m_pCanvas)
+      m_pCanvas->Refresh();
 }
 
 bool 
@@ -3211,6 +3204,23 @@ PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint&
   m_pView = v;
 }
 
+wxSize
+PlotFileCanvas::GetBestSize() const
+{
+  if (! m_pView)
+    return wxSize(0,0);
+  
+  int xSize, ySize;
+  theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
+  xSize = maxValue<int> (xSize, ySize);
+#ifdef CTSIM_MDI
+  ySize = xSize = (xSize / 4);
+#else
+  ySize = xSize;
+#endif
+  return wxSize (xSize, ySize);
+}
+
 PlotFileCanvas::~PlotFileCanvas ()
 {
   m_pView = NULL;
@@ -3429,12 +3439,6 @@ PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
   m_pFrame->SetTitle ("Plot File");
   m_pCanvas = CreateCanvas (m_pFrame);
   
-#ifdef __X__
-  int x, y;  // X requires a forced resize
-  m_pFrame->GetSize(&x, &y);
-  m_pFrame->SetSize(-1, -1, x, y);
-#endif
-  
   m_pFrame->Show(true);
   Activate(true);
   
@@ -3562,13 +3566,6 @@ bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
   m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
   m_pFrame->SetTitle("Log");
   
-#ifdef __X__
-  // X seems to require a forced resize
-  int x, y;
-  frame->GetSize(&x, &y);
-  frame->SetSize(-1, -1, x, y);
-#endif
-  
   m_pFrame->Show (true);
   Activate (true);
   
@@ -3671,3 +3668,17 @@ TextFileCanvas::~TextFileCanvas ()
 {
   m_pView = NULL;
 }
+
+wxSize
+TextFileCanvas::GetBestSize() const
+{
+  int xSize, ySize;
+  theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
+  xSize = maxValue<int> (xSize, ySize);
+#ifdef CTSIM_MDI
+  ySize = xSize = (xSize / 4);
+#else
+  ySize = xSize;
+#endif
+  return wxSize (xSize, ySize);
+}