Sequencer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef BASE_SEQUENCER_H
00025 #define BASE_SEQUENCER_H
00026 
00027 #include <vector>
00028 #include <memory>
00029 #include <CXX/Extensions.hxx>
00030 
00031 #include "Exception.h"
00032 
00033 namespace Base
00034 {
00035 
00036 class AbortException;
00037 class SequencerLauncher;
00038 
00115 class BaseExport SequencerBase
00116 {
00117     friend class SequencerLauncher;
00118 
00119 public:
00131     static SequencerBase& Instance();
00138     virtual bool isBlocking() const;
00143     bool setLocked(bool bLock);
00145     bool isLocked() const;
00147     bool isRunning() const;
00151     bool wasCanceled() const;
00152 
00153 protected:
00159     bool start(const char* pszStr, size_t steps);
00161     size_t numberOfSteps() const;
00163     int progressInPercent() const;
00174     bool next(bool canAbort = false);
00179     bool stop();
00185     virtual void pause();
00190     virtual void resume();
00195     void tryToCancel();
00201     void rejectCancel();
00202 
00203 protected:
00205     SequencerBase();
00207     virtual ~SequencerBase();
00212     virtual void setText (const char* pszTxt);
00217     virtual void startStep();
00224     virtual void nextStep(bool canAbort);
00228     virtual void setProgress(size_t);
00234     virtual void resetData();
00235 
00236 protected:
00237     size_t nProgress; 
00238     size_t nTotalSteps; 
00240 private:
00241     bool _bLocked; 
00242     bool _bCanceled; 
00243     int _nLastPercentage; 
00244 };
00245 
00249 class BaseExport EmptySequencer : public Base::SequencerBase
00250 {
00251 public:
00253     EmptySequencer();
00255     ~EmptySequencer();
00256 };
00257 
00261 class BaseExport ConsoleSequencer : public SequencerBase
00262 {
00263 public:
00265     ConsoleSequencer ();
00267     ~ConsoleSequencer ();
00268 
00269 protected:
00271     void startStep();
00273     void nextStep(bool canAbort);
00274 
00275 private:
00277     void setText (const char* pszTxt);
00279     void resetData();
00280 };
00281 
00364 class BaseExport SequencerLauncher
00365 {
00366 public:
00367     SequencerLauncher(const char* pszStr, size_t steps);
00368     ~SequencerLauncher();
00369     size_t numberOfSteps() const;
00370     void setText (const char* pszTxt);
00371     bool next(bool canAbort = false);
00372     void setProgress(size_t);
00373     bool wasCanceled() const;
00374 };
00375 
00377 inline SequencerBase& Sequencer ()
00378 {
00379     return SequencerBase::Instance();
00380 }
00381 
00382 class BaseExport ProgressIndicatorPy : public Py::PythonExtension<ProgressIndicatorPy>
00383 {
00384 public:
00385     static void init_type(void);    // announce properties and methods
00386 
00387     ProgressIndicatorPy();
00388     ~ProgressIndicatorPy();
00389 
00390     Py::Object repr();
00391 
00392     Py::Object start(const Py::Tuple&);
00393     Py::Object next(const Py::Tuple&);
00394     Py::Object stop(const Py::Tuple&);
00395 
00396 private:
00397     static PyObject *PyMake(struct _typeobject *, PyObject *, PyObject *);
00398 
00399 private:
00400     std::auto_ptr<SequencerLauncher> _seq;
00401 };
00402 
00403 } // namespace Base
00404 
00405 #endif // BASE_SEQUENCER_H

Generated on Wed Nov 23 19:00:37 2011 for FreeCAD by  doxygen 1.6.1