- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# Tools/Utils/Progress.hh

    00001 /*===========================================================================*\
    00002  *                                                                           *
    00003  *                               OpenMesh                                    *
    00004  *      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen      *
    00005  *                           www.openmesh.org                                *
    00006  *                                                                           *
    00007  *---------------------------------------------------------------------------*
    00008  *                                                                           *
    00009  *                                License                                    *
    00010  *                                                                           *
    00011  *  This library is free software; you can redistribute it and/or modify it  *
    00012  *  under the terms of the GNU Library General Public License as published   *
    00013  *  by the Free Software Foundation, version 2.                              *
    00014  *                                                                           *
    00015  *  This library is distributed in the hope that it will be useful, but      *
    00016  *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
    00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
    00018  *  Library General Public License for more details.                         *
    00019  *                                                                           *
    00020  *  You should have received a copy of the GNU Library General Public        *
    00021  *  License along with this library; if not, write to the Free Software      *
    00022  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
    00023  *                                                                           *
    00024 \*===========================================================================*/
    00025
    00026 #ifndef OPENMESH_PROGRESS_HH
    00027 #define OPENMESH_PROGRESS_HH
    00028
    00029
    00030 //== INCLUDES =================================================================
    00031
    00032 #include <OpenMesh/Tools/Utils/Timer.hh>
    00033 #include <set>
    00034
    00035
    00036 //== FORWARDDECLARATIONS ======================================================
    00037
    00038 class ProgressHandler;
    00039
    00040
    00041 //== CLASS DEFINITION =========================================================
    00042
    00043
    00044 class ProgressManager
    00045 {
    00046 public:
    00047
    00048   ProgressManager()  {}
    00049   ~ProgressManager() {}
    00050
    00051   void connect(ProgressHandler* _ph)     { handlers_.insert(_ph); }
    00052   void disconnect(ProgressHandler* _ph)  { handlers_.erase(_ph); }
    00053
    00054   void set_steps(unsigned int _nsteps, const char* _label);
    00055   bool step(unsigned int _steps=1);
    00056   bool set_progress(unsigned int _progress);
    00057   void finish();
    00058
    00059   bool is_active() const { return active_; }
    00060   bool was_cancelled() const { return cancelled_; }
    00061
    00062
    00063 private:
    00064
    00065   std::set<ProgressHandler*>  handlers_;
    00066   unsigned int                steps_, progress_, percentage_;
    00067   bool                        active_, cancelled_;
    00068   OpenMesh::Utils::Timer      timer_;
    00069 };
    00070
    00071
    00072 ProgressManager&  Progress();
    00073
    00074
    00075
    00076 //== CLASS DEFINITION =========================================================
    00077
    00078
    00079 class ProgressHandler
    00080 {
    00081 public:
    00082
    00083   ProgressHandler() { Progress().connect(this); }
    00084   virtual ~ProgressHandler() { Progress().disconnect(this); }
    00085
    00086   virtual void set_steps(unsigned int _steps, const char* _label) = 0;
    00087   virtual bool set_progress(unsigned int _progress) = 0;
    00088   virtual void finish() = 0;
    00089 };
    00090
    00091
    00092 //=============================================================================
    00093 #endif // OPENMESH_PROGRESS_HH defined
    00094 //=============================================================================
    00095