From: vsv Date: Tue, 30 Sep 2014 11:53:02 +0000 (+0400) Subject: Exclude ModuleBase_IOperation class. X-Git-Tag: V_0.5~121^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b9217e2590e05ae2b4d5de741e7e6bd5ff0e1d1;p=modules%2Fshaper.git Exclude ModuleBase_IOperation class. --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 860e34094..92a73fce8 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -3,7 +3,6 @@ SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS ModuleBase.h - ModuleBase_IOperation.h ModuleBase_IModule.h ModuleBase_Operation.h ModuleBase_OperationDescription.h @@ -31,7 +30,6 @@ SET(PROJECT_HEADERS ) SET(PROJECT_SOURCES - ModuleBase_IOperation.cpp ModuleBase_Operation.cpp ModuleBase_OperationDescription.cpp ModuleBase_ModelWidget.cpp diff --git a/src/ModuleBase/ModuleBase_IOperation.cpp b/src/ModuleBase/ModuleBase_IOperation.cpp deleted file mode 100644 index f9fb72b87..000000000 --- a/src/ModuleBase/ModuleBase_IOperation.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * ModuleBase_IOperation.cpp - * - * Created on: May 5, 2014 - * Author: nds - */ - -#include "ModuleBase_IOperation.h" -#include "ModuleBase_OperationDescription.h" -#include "ModuleBase_ModelWidget.h" - -#include -#include - -#ifdef _DEBUG -#include -#endif - -ModuleBase_IOperation::ModuleBase_IOperation(const QString& theId, QObject* theParent) - : QObject(theParent), - myIsEditing(false), - myIsModified(false) -{ - myDescription = new ModuleBase_OperationDescription(theId); -} - -ModuleBase_IOperation::~ModuleBase_IOperation() -{ - delete myDescription; -} - -ModuleBase_OperationDescription* ModuleBase_IOperation::getDescription() const -{ - return myDescription; -} - -bool ModuleBase_IOperation::canBeCommitted() const -{ - return true; -} - -/*void ModuleBase_IOperation::setModelWidgets(const std::string& theXmlRepresentation, - QList theWidgets) - { - QList::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end(); - for (; anIt != aLast; anIt++) { - QObject::connect(*anIt, SIGNAL(valuesChanged()), this, SLOT(storeCustomValue())); - } - getDescription()->setModelWidgets(theXmlRepresentation, theWidgets); - }*/ - -boost::shared_ptr ModuleBase_IOperation::document() const -{ - return ModelAPI_Session::get()->moduleDocument(); -} - -void ModuleBase_IOperation::start() -{ - ModelAPI_Session::get()->startOperation(); - - startOperation(); - emit started(); -} - -void ModuleBase_IOperation::resume() -{ - emit resumed(); -} - -void ModuleBase_IOperation::abort() -{ - abortOperation(); - emit aborted(); - - stopOperation(); - - ModelAPI_Session::get()->abortOperation(); - emit stopped(); -} - -bool ModuleBase_IOperation::commit() -{ - if (canBeCommitted()) { - commitOperation(); - emit committed(); - - stopOperation(); - - ModelAPI_Session::get()->finishOperation(); - emit stopped(); - - afterCommitOperation(); - return true; - } - return false; -} - -void ModuleBase_IOperation::setRunning(bool theState) -{ - if (!theState) { - abort(); - } -} diff --git a/src/ModuleBase/ModuleBase_IOperation.h b/src/ModuleBase/ModuleBase_IOperation.h deleted file mode 100644 index 583f8ece4..000000000 --- a/src/ModuleBase/ModuleBase_IOperation.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * ModuleBase_IOperation.h - * - * Created on: May 5, 2014 - * Author: nds - */ - -#ifndef ModuleBase_IOperation_H -#define ModuleBase_IOperation_H - -#include - -#include -#include -#include -#include - -#include - -class ModelAPI_Document; -class ModuleBase_OperationDescription; -//class ModuleBase_ModelWidget; - -/*! - \class ModuleBase_IOperation - * \brief Base class for all operations - * - * Base class for all operations. If you perform an action it is reasonable to create - * operation intended for this. This is a base class for all operations which provides - * mechanism for correct starting operations, starting operations above already started - * ones, committing operations and so on. To create own operation it is reasonable to - * inherit it from this class and redefines virtual methods to provide own behavior - * Main virtual methods are - * - virtual bool isReadyToStart(); - * - virtual void startOperation(); - * - virtual void abortOperation(); - * - virtual void commitOperation(); - */ - -class MODULEBASE_EXPORT ModuleBase_IOperation : public QObject -{ -Q_OBJECT - - public: - /// Constructor - /// Constructs an empty operation. Constructor should work very fast because many - /// operators may be created after starting workshop but only several from them - /// may be used. As result this constructor stores given workshop in myApp field - /// and set Waiting status. - /// \param theId the operation identifier - /// \param theParent the QObject parent - ModuleBase_IOperation(const QString& theId = "", QObject* theParent = 0); - /// Destructor - virtual ~ModuleBase_IOperation(); - - /// Returns the operation description - /// /returns the instance of the description class - ModuleBase_OperationDescription* getDescription() const; - - /** - * Must return true if this operation can be launched as nested for any current operation - * and it is not necessary to check this operation on validity. By default - * the operation is not granted. - * The method has to be redefined for granted operations. - */ - virtual bool isGranted(ModuleBase_IOperation* theOperation) const { return false; } - - /** - * Must return True if the operation's feature is valid. - * Since IOperation does not have any feature returns false. - */ - virtual bool isValid() const { return false; } - - /// Sets a list of model widgets, according to the operation feature xml definition - /// \param theXmlRepresentation an xml feature definition - /// \param theWidgets a list of widgets - //void setModelWidgets(const std::string& theXmlRepresentation, - // QList theWidgets); - - /// Returns True if data of its feature was modified during operation - virtual bool isModified() const - { - return myIsModified; - } - - /// Returns True id the current operation is launched in editing mode - bool isEditOperation() const - { - return myIsEditing; - } - - /// Returns list of nested features - QStringList nestedFeatures() const { return myNestedFeatures; } - - /// Sets list of nested features - void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; } - -signals: - void started(); /// the operation is started - void aborted(); /// the operation is aborted - void committed(); /// the operation is committed - void stopped(); /// the operation is aborted or committed - void resumed(); /// the operation is resumed - - public slots: - /// Starts operation - /// Public slot. Verifies whether operation can be started and starts operation. - /// This slot is not virtual and cannot be redefined. Redefine startOperation method - /// to change behavior of operation. There is no point in using this method. It would - /// be better to inherit own operator from base one and redefine startOperation method - /// instead. - void start(); - /// Resumes operation - /// Public slot. Verifies whether operation can be started and starts operation. - /// This slot is not virtual and cannot be redefined. Redefine startOperation method - /// to change behavior of operation. There is no point in using this method. It would - /// be better to inherit own operator from base one and redefine startOperation method - /// instead. - void resume(); - /// Aborts operation - /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined. - /// Redefine abortOperation method to change behavior of operation instead - void abort(); - /// Commits operation - /// Public slot. Commits operation. This slot is not virtual and cannot be redefined. - /// Redefine commitOperation method to change behavior of operation instead - bool commit(); - - /// Alias for start/abort slots - /// Public slot. Aborts operation if false, else does nothing. - /// Provided for S/S compatibility with QAction's toggle(bool) - /// \param theState th flag to abort, if it is true, do nothing, overwise abort - void setRunning(bool theState); - - // Data model methods. - /// Stores a custom value in model. - virtual void storeCustomValue() = 0; - - protected: - /// Virtual method called when operation started (see start() method for more description) - /// Default impl calls corresponding slot and commits immediately. - virtual void startOperation() = 0; - - /// Virtual method called when operation stopped - committed or aborted. - virtual void stopOperation() = 0; - - /// Virtual method called when operation aborted (see abort() method for more description) - virtual void abortOperation() = 0; - - /// Virtual method called when operation committed (see commit() method for more description) - virtual void commitOperation() = 0; - - /// Virtual method called after operation committed (see commit() method for more description) - /// it is important that the method is called after the stop() signal is emitted - virtual void afterCommitOperation() = 0; - - /// Verifies whether this operator can be commited. - /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled - virtual bool canBeCommitted() const; - - /// Returns pointer to the root document. - boost::shared_ptr document() const; - - /// Editing feature flag - bool myIsEditing; - - /// Modified feature flag - bool myIsModified; - - private: - ModuleBase_OperationDescription* myDescription; /// the container to have the operation description - - QStringList myNestedFeatures; -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index fd0724f28..ec6c0e1e6 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -26,12 +26,16 @@ #endif ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent) - : ModuleBase_IOperation(theId, theParent) + : QObject(theParent), + myIsEditing(false), + myIsModified(false) { + myDescription = new ModuleBase_OperationDescription(theId); } ModuleBase_Operation::~ModuleBase_Operation() { + delete myDescription; } QString ModuleBase_Operation::id() const @@ -104,26 +108,7 @@ void ModuleBase_Operation::afterCommitOperation() bool ModuleBase_Operation::canBeCommitted() const { - if (ModuleBase_IOperation::canBeCommitted()) { - /* FeaturePtr aFeature = feature(); - std::string aId = aFeature->getKind(); - - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::list aValidators; - aFactory->validators(aId, aValidators); - std::list::const_iterator aIt; - for (aIt = aValidators.cbegin(); aIt != aValidators.cend(); ++aIt) { - const ModuleBase_FeatureValidator* aFValidator = - dynamic_cast(*aIt); - if (aFValidator) { - if (!aFValidator->isValid(aFeature)) - return false; - } - }*/ - return true; - } - return false; + return true; } void ModuleBase_Operation::flushUpdated() @@ -184,3 +169,57 @@ bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const return false; } + +boost::shared_ptr ModuleBase_Operation::document() const +{ + return ModelAPI_Session::get()->moduleDocument(); +} + + +void ModuleBase_Operation::start() +{ + ModelAPI_Session::get()->startOperation(); + + startOperation(); + emit started(); +} + +void ModuleBase_Operation::resume() +{ + emit resumed(); +} + +void ModuleBase_Operation::abort() +{ + abortOperation(); + emit aborted(); + + stopOperation(); + + ModelAPI_Session::get()->abortOperation(); + emit stopped(); +} + +bool ModuleBase_Operation::commit() +{ + if (canBeCommitted()) { + commitOperation(); + emit committed(); + + stopOperation(); + + ModelAPI_Session::get()->finishOperation(); + emit stopped(); + + afterCommitOperation(); + return true; + } + return false; +} + +void ModuleBase_Operation::setRunning(bool theState) +{ + if (!theState) { + abort(); + } +} diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 17be4cba4..b73ba4726 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -9,17 +9,18 @@ #define ModuleBase_Operation_H #include -#include #include #include #include +#include #include class ModelAPI_Document; class ModuleBase_ModelWidget; +class ModuleBase_OperationDescription; class QKeyEvent; @@ -39,7 +40,7 @@ class QKeyEvent; * - virtual void commitOperation(); */ -class MODULEBASE_EXPORT ModuleBase_Operation : public ModuleBase_IOperation +class MODULEBASE_EXPORT ModuleBase_Operation : public QObject { Q_OBJECT @@ -51,13 +52,48 @@ Q_OBJECT /// Destructor virtual ~ModuleBase_Operation(); + /// Returns the operation description + /// /returns the instance of the description class + ModuleBase_OperationDescription* getDescription() const { return myDescription; } + + /** + * Must return true if this operation can be launched as nested for any current operation + * and it is not necessary to check this operation on validity. By default + * the operation is not granted. + * The method has to be redefined for granted operations. + */ + virtual bool isGranted(ModuleBase_Operation* theOperation) const { return false; } + + /// Sets a list of model widgets, according to the operation feature xml definition + /// \param theXmlRepresentation an xml feature definition + /// \param theWidgets a list of widgets + //void setModelWidgets(const std::string& theXmlRepresentation, + // QList theWidgets); + + /// Returns True if data of its feature was modified during operation + virtual bool isModified() const { return myIsModified; } + + /// Returns True id the current operation is launched in editing mode + bool isEditOperation() const { return myIsEditing; } + + /// Returns list of nested features + QStringList nestedFeatures() const { return myNestedFeatures; } + + /// Sets list of nested features + void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; } + + // Returns operations Id from it's description QString id() const; + /// Returns the operation feature /// \return the feature FeaturePtr feature() const; - /// Returns true is feature of operation is valid. + /** + * Must return True if the operation's feature is valid. + * Since IOperation does not have any feature returns false. + */ virtual bool isValid() const; /// Returns whether the nested operations are enabled. @@ -65,10 +101,6 @@ Q_OBJECT /// \return enabled state virtual bool isNestedOperationsEnabled() const; - // Data model methods. - /// Stores a custom value in model. - void storeCustomValue(); - /// Sets the operation feature void setEditingFeature(FeaturePtr theFeature); @@ -83,26 +115,69 @@ Q_OBJECT /// then this method has to return True virtual bool hasPreview() const { return false; } - public slots: - /// Slots which listen the mode widget activation - /// \param theWidget the model widget - virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget); - signals: + void started(); /// the operation is started + void aborted(); /// the operation is aborted + void committed(); /// the operation is committed + void stopped(); /// the operation is aborted or committed + void resumed(); /// the operation is resumed + /// Signals about the activating of the next widget /// \param theWidget the previous active widget void activateNextWidget(ModuleBase_ModelWidget* theWidget); + public slots: + /// Starts operation + /// Public slot. Verifies whether operation can be started and starts operation. + /// This slot is not virtual and cannot be redefined. Redefine startOperation method + /// to change behavior of operation. There is no point in using this method. It would + /// be better to inherit own operator from base one and redefine startOperation method + /// instead. + void start(); + /// Resumes operation + /// Public slot. Verifies whether operation can be started and starts operation. + /// This slot is not virtual and cannot be redefined. Redefine startOperation method + /// to change behavior of operation. There is no point in using this method. It would + /// be better to inherit own operator from base one and redefine startOperation method + /// instead. + void resume(); + /// Aborts operation + /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined. + /// Redefine abortOperation method to change behavior of operation instead + void abort(); + /// Commits operation + /// Public slot. Commits operation. This slot is not virtual and cannot be redefined. + /// Redefine commitOperation method to change behavior of operation instead + bool commit(); + + /// Alias for start/abort slots + /// Public slot. Aborts operation if false, else does nothing. + /// Provided for S/S compatibility with QAction's toggle(bool) + /// \param theState th flag to abort, if it is true, do nothing, overwise abort + void setRunning(bool theState); + + // Data model methods. + /// Stores a custom value in model. + virtual void storeCustomValue(); + + /// Slots which listen the mode widget activation + /// \param theWidget the model widget + virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget); + protected: /// Virtual method called when operation started (see start() method for more description) /// Default impl calls corresponding slot and commits immediately. virtual void startOperation(); + /// Virtual method called when operation stopped - committed or aborted. virtual void stopOperation(); + /// Virtual method called when operation aborted (see abort() method for more description) virtual void abortOperation(); + /// Virtual method called when operation committed (see commit() method for more description) virtual void commitOperation(); + /// Virtual method called after operation committed (see commit() method for more description) virtual void afterCommitOperation(); @@ -116,7 +191,6 @@ signals: /// \returns the created feature virtual FeaturePtr createFeature(const bool theFlushMessage = true); - protected: /// Sets the operation feature void setFeature(FeaturePtr theFeature); @@ -124,8 +198,25 @@ signals: /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled virtual bool canBeCommitted() const; + /// Returns pointer to the root document. + boost::shared_ptr document() const; + + protected: FeaturePtr myFeature; /// the operation feature to be handled + + /// the container to have the operation description + ModuleBase_OperationDescription* myDescription; + + /// Editing feature flag + bool myIsEditing; + + /// Modified feature flag + bool myIsModified; + + /// List of nested operations IDs + QStringList myNestedFeatures; + }; #endif diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 72338efff..2a320bc69 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -252,7 +252,7 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) } -bool PartSet_OperationSketch::isGranted(ModuleBase_IOperation* theOperation) const +bool PartSet_OperationSketch::isGranted(ModuleBase_Operation* theOperation) const { PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); return aPreviewOp != NULL; diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 862c6a4bf..3e99e86fa 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -38,7 +38,7 @@ Q_OBJECT virtual ~PartSet_OperationSketch(); /// Returns True if the given operation is a Sketcher operation - virtual bool isGranted(ModuleBase_IOperation* theOperation) const; + virtual bool isGranted(ModuleBase_Operation* theOperation) const; /// Returns the operation local selection mode