r572: no message
[ctsim.git] / src / threadrecon.cpp
index aa9a7bb9cdbfa419f0b5cf372c4999757dc5f2d5..e43299a356cb925614cbe003a014a566f0420570 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2001 Kevin Rosenberg
 **
-**  $Id: threadrecon.cpp,v 1.1 2001/02/22 11:05:38 kevin Exp $
+**  $Id: threadrecon.cpp,v 1.2 2001/02/22 15:00:20 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
 #include "docs.h"
 #include "views.h"
 #include "threadrecon.h"
+#include "backgroundmgr.h"
 
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
 
 
-IMPLEMENT_DYNAMIC_CLASS(ThreadedReconstructor, wxEvtHandler)
-BEGIN_EVENT_TABLE(ThreadedReconstructor, wxEvtHandler)
+IMPLEMENT_DYNAMIC_CLASS(ThreadedReconstructor, BackgroundTask)
+BEGIN_EVENT_TABLE(ThreadedReconstructor, BackgroundTask)
 EVT_MENU(RECONSTRUCTION_THREAD_EVENT, ThreadedReconstructor::OnThreadEvent)
 END_EVENT_TABLE()
 
@@ -58,9 +59,9 @@ ThreadedReconstructor::ThreadedReconstructor (ProjectionFileView* pProjView,
    int iImageNX, int iImageNY, const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, 
    int iZeropad, const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam,
    const char* pszBackprojectName, const char* const pszLabel)
-    : m_pProjView(pProjView), m_pDialogProgress(NULL), m_bFail(false), m_iNumThreads(0), m_iImageNX(iImageNX), 
+    : m_pProjView(pProjView), m_pDialogProgress(NULL), m_pGauge(NULL), m_bFail(false), m_iNumThreads(0), m_iImageNX(iImageNX), 
     m_iImageNY(iImageNY), m_strLabel(pszLabel), m_pTimer(NULL), m_bCancelled(false), m_bCancelling(false), 
-    m_bDone(false), wxEvtHandler()
+    m_bDone(false), BackgroundTask()
 {
   m_iNumThreads = theApp->getNumberCPU();
 //  ++m_iNumThreads;
@@ -89,8 +90,6 @@ ThreadedReconstructor::ThreadedReconstructor (ProjectionFileView* pProjView,
     }
   }
 
-  m_pProjView->GetDocument()->addReconstructor (this);
-  // m_pDialogProgress = new wxProgressDialog (_T("Filtered Backprojection"), _T("Reconstruction Progress"), m_iTotalViews, pProjView->getFrame(), wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
 }
 
 
@@ -100,14 +99,18 @@ ThreadedReconstructor::start()
   if (m_bFail)
     return false;
 
-  // starting all threads
+  m_pProjView->GetDocument()->addReconstructor (this);
+  if (! theApp->getUseBackgroundTasks())
+    m_pDialogProgress = new wxProgressDialog (_T("Filtered Backprojection"), _T("Reconstruction Progress"), m_iTotalViews, m_pProjView->getFrame(), wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
+  else
+    m_pGauge = theApp->getBackgroundManager()->addTask (this, m_iTotalViews);
+
   m_iRunning = m_iNumThreads;
   m_iViewsDone = 0;
   m_pTimer = new Timer;
-//  theApp->addBackgroundTask (this, m_iTotalViews);
 
-  int i;
-  for (i = 0; i < m_iNumThreads; i++)
+  // starting all threads
+  for (int i = 0; i < m_iNumThreads; i++)
     m_vecpThread[i]->Run();
 
 
@@ -140,7 +143,7 @@ ThreadedReconstructor::cancel()
   m_pProjView->GetDocument()->removeReconstructor (this);
   m_bCancelled = true;
   m_bDone = true;
-  // theApp->removeBackgroundTask (this);
+  theApp->getBackgroundManager()->taskDone (this);
 }
 
 void
@@ -174,7 +177,7 @@ ThreadedReconstructor::onDone()
       wxIdleEvent event;
       theApp->OnIdle(event);
       m_bDone = true;
-      // theApp->removeBackgroundTask (this);
+   theApp->getBackgroundManager()->taskDone (this);
       // delete this;
 }
 
@@ -196,8 +199,10 @@ ThreadedReconstructor::OnThreadEvent (wxCommandEvent& event)
 
     if (m_pDialogProgress)
       m_bCancelling = ! m_pDialogProgress->Update (m_iViewsDone - 1);
-
-    // m_bCancelling = theApp->updateBackgroundTask (this, m_iViewsDone);
+    else if (m_pGauge) {
+      m_pGauge->SetValue (m_iViewsDone - 1);
+      m_bCancelling = theApp->getBackgroundManager()->isCancelling(this);
+    }
     if (m_iViewsDone == m_iTotalViews) {
       delete m_pDialogProgress;
       m_pDialogProgress = NULL;