r574: no message
[ctsim.git] / src / threadrecon.h
index 53368fa94fd496724ede052095c63984e8e976ca..e9ab35ee508f627b5ef3b96d56469d05f3b7be6e 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2001 Kevin Rosenberg
 **
-**  $Id: threadrecon.h,v 1.1 2001/02/22 11:05:38 kevin Exp $
+**  $Id: threadrecon.h,v 1.4 2001/02/23 02:06:02 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 <wx/progdlg.h>
 #include "timer.h"
 
+// This thread creates a BackgroundTask event handler object
+// The thread is detached and terminates when BackgroundTask terminates
+class BackgroundTaskThread : public wxThread {
+private:
+
+public:
+  BackgroundTaskThread();
+
+  virtual wxThread::ExitCode Entry();
+
+  // called when the thread exits - whether it terminates normally or is stopped with Delete()
+  virtual void OnExit();
+};
+
+
+class BackgroundTask : public wxEvtHandler {
+private:
+  bool m_bDone;
+
+public:
+  BackgroundTask()
+    : m_bDone(false), wxEvtHandler()
+  {}
+
+  virtual ~BackgroundTask()
+  {}
+
+  virtual void cancel() = 0;
+  virtual bool start() = 0;
+  virtual bool testDone() = 0;
+
+  bool isDone() const {return m_bDone;}
+  void setDone() { m_bDone = true; }
+};
 
 class Reconstructor;
 class ImageFile;
@@ -40,7 +74,7 @@ class ProjectionFileDocument;
 class ReconstructionThread;
 class ProjectionFileView;
 
-class ThreadedReconstructor : public wxEvtHandler {
+class ThreadedReconstructor : public BackgroundTask {
 private:
   DECLARE_DYNAMIC_CLASS(ThreadedReconstructor)
 
@@ -49,6 +83,7 @@ private:
   std::vector<ReconstructionThread*> m_vecpThread;
   ProjectionFileView* m_pProjView;
   wxProgressDialog* m_pDialogProgress;
+  wxGauge* m_pGauge;
   
   volatile bool m_bFail;
   int m_iNumThreads;
@@ -57,12 +92,11 @@ private:
   volatile int m_iRunning;
   volatile unsigned int m_iViewsDone;
   volatile unsigned int m_iTotalViews;
-  wxCriticalSection m_criticalSection;
+  //wxCriticalSection m_criticalSection;
   wxString m_strLabel;
   Timer* m_pTimer;
   bool m_bCancelled;
   bool m_bCancelling;
-  bool m_bDone;
 
 public:
    ThreadedReconstructor (ProjectionFileView* pProjView, 
@@ -71,21 +105,21 @@ public:
    const char* pszBackprojectName, const char* const pszLabel);
 
    ThreadedReconstructor ()
-     : m_bFail(true), m_iNumThreads(0), m_iImageNX(0), m_iImageNY(0), m_iTotalViews(0)
+     : m_bFail(true), m_iNumThreads(0), m_iImageNX(0), m_iImageNY(0), m_iTotalViews(0), BackgroundTask()
    {}
 
    ~ThreadedReconstructor ();
 
   void OnThreadEvent (wxCommandEvent& event);
-  bool testDone();
   void cancel();
 
   void onDone();
   bool start();
   bool fail() const {return m_bFail;}
-  bool getDone() const {return m_bDone;}
+  bool testDone();
+  void cleanUp();
 
-  ImageFile* getImageFile() const;
+  ImageFile* getImageFile();
 
   DECLARE_EVENT_TABLE()
 };
@@ -106,9 +140,8 @@ public:
 
   virtual wxThread::ExitCode Entry();      // thread execution starts here
 
-    // called when the thread exits - whether it terminates normally or is
-    // stopped with Delete() (but not when it is Kill()ed!)
-    virtual void OnExit();
+  // called when the thread exits - whether it terminates normally or is stopped with Delete()
+  virtual void OnExit();
 };