]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'BR_ADVANCED_CURRENT_FEATURE_MANAGEMENT' into Dev_1.5.0
authormpv <mpv@opencascade.com>
Mon, 12 Oct 2015 08:58:19 +0000 (11:58 +0300)
committermpv <mpv@opencascade.com>
Mon, 12 Oct 2015 08:58:19 +0000 (11:58 +0300)
1  2 
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h

index 7458ae9fd27d996e1a27f2579905555c36f18a2d,97388529154b9daeb80fc0da22bc1e3d7e1b9b62..c6762043e1d8796f78cbf4725c80ee9200dc101f
@@@ -26,6 -26,7 +26,7 @@@
  #include <ModelAPI_Object.h>
  #include <ModelAPI_Validator.h>
  #include <ModelAPI_Session.h>
+ #include <ModelAPI_Tools.h>
  
  #include <GeomAPI_Pnt2d.h>
  
@@@ -78,6 -79,9 +79,9 @@@ void ModuleBase_OperationFeature::start
    if (!aFeature.get() || !isEditOperation())
      return;
  
+   if (aFeature.get() && isEditOperation())
+     aFeature->setStable(false);
    myVisualizedObjects.clear();
    // store hidden result features
    std::list<ResultPtr> aResults = aFeature->results();
@@@ -179,6 -183,7 +183,7 @@@ void ModuleBase_OperationFeature::start
    }
    ModelAPI_Session::get()->startOperation(anId.toStdString());
  
+   emit beforeStarted();
    startOperation();
  
    if (!myIsEditing) {
        return;
      }
    }
-   /// Set current feature and remeber old current feature
-   if (myIsEditing) {
-     SessionPtr aMgr = ModelAPI_Session::get();
-     DocumentPtr aDoc = aMgr->activeDocument();
-     // the parameter of current feature should be false, we should use all feature, not only visible
-     // in order to correctly save the previous feature of the nested operation, where the
-     // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
-     // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
-     // When sketch entity operation started, the sketch should be cashed here as the current.
-     // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
-     // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
-     // As a result the sketch disappears from the viewer. However after commit it is displayed back.
-     myPreviousCurrentFeature = aDoc->currentFeature(false);
-     aDoc->setCurrentFeature(feature(), false);
-   }
-   startOperation();
+   //Already called startOperation();
    emit started();
  
  }
  
  void ModuleBase_OperationFeature::abort()
  {
+   emit beforeAborted();
    // the viewer update should be blocked in order to avoid the features blinking before they are
    // hidden
    std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
    if (aPropertyPanel)
      aPropertyPanel->cleanContent();
  
-   SessionPtr aMgr = ModelAPI_Session::get();
-   if (myIsEditing) {
-     DocumentPtr aDoc = aMgr->activeDocument();
-     bool aIsOp = aMgr->isOperation();
-     if (!aIsOp)
-       aMgr->startOperation();
-     aDoc->setCurrentFeature(myPreviousCurrentFeature, true);
-     if (!aIsOp)
-       aMgr->finishOperation();
-     myPreviousCurrentFeature = FeaturePtr();
-   }
-   abortOperation();
+   myFeature->setStable(true);
  
+   abortOperation();
    stopOperation();
  
+   SessionPtr aMgr = ModelAPI_Session::get();
    aMgr->abortOperation();
    emit stopped();
    // the viewer update should be unblocked in order to avoid the features blinking before they are
@@@ -268,19 -250,13 +250,13 @@@ bool ModuleBase_OperationFeature::commi
      ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
      if (aPropertyPanel)
        aPropertyPanel->cleanContent();
+     
+     myFeature->setStable(true);
  
      SessionPtr aMgr = ModelAPI_Session::get();
      /// Set current feature and remeber old current feature
-     if (myIsEditing) {
-       DocumentPtr aDoc = aMgr->activeDocument();
-       bool aIsOp = aMgr->isOperation();
-       if (!aIsOp)
-         aMgr->startOperation();
-       aDoc->setCurrentFeature(myPreviousCurrentFeature, true);
-       if (!aIsOp)
-         aMgr->finishOperation();
-       myPreviousCurrentFeature = FeaturePtr();
-     }
+     emit beforeCommitted();
      commitOperation();
      aMgr->finishOperation();
  
@@@ -299,8 -275,6 +275,8 @@@ void ModuleBase_OperationFeature::activ
    if (myPreSelection.empty())
      return;
  
 +  ModuleBase_ISelection::filterPreselectionOnEqualPoints(myPreSelection);
 +
    ModuleBase_ModelWidget* aFilledWgt = 0;
    ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
    if (aPropertyPanel) {
@@@ -352,6 -326,16 +328,16 @@@ CompositeFeaturePtr ModuleBase_Operatio
    return myParentFeature;
  }
  
+ void ModuleBase_OperationFeature::setPreviousCurrentFeature(const FeaturePtr& theFeature)
+ {
+   myPreviousCurrentFeature = theFeature;
+ }
+ FeaturePtr ModuleBase_OperationFeature::previousCurrentFeature()
+ {
+   return myPreviousCurrentFeature;
+ }
  void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelection,
                                           ModuleBase_IViewer* theViewer)
  {
index 361547bbfad2fbb9bb492dbd8c7c8903127729e2,a643ef5a898c71f8b2190d9ffc4e45938aacbe52..8cf826404cc2daf701f87c03f6b84c349c7ed537
@@@ -116,9 -116,14 +116,14 @@@ bool XGUI_OperationMgr::startOperation(
      currentOperation()->postpone();
    myOperations.append(theOperation);
  
+   connect(theOperation, SIGNAL(beforeStarted()), SLOT(onBeforeOperationStarted()));
+   connect(theOperation, SIGNAL(beforeAborted()), SLOT(onBeforeOperationAborted()));
+   connect(theOperation, SIGNAL(beforeCommitted()), SLOT(onBeforeOperationCommitted()));
    connect(theOperation, SIGNAL(started()), SLOT(onOperationStarted()));
    connect(theOperation, SIGNAL(aborted()), SLOT(onOperationAborted()));
    connect(theOperation, SIGNAL(committed()), SLOT(onOperationCommitted()));
    connect(theOperation, SIGNAL(stopped()), SLOT(onOperationStopped()));
    connect(theOperation, SIGNAL(resumed()), SLOT(onOperationResumed()));
    ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
@@@ -260,7 -265,7 +265,7 @@@ bool XGUI_OperationMgr::isParentOperati
  bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation)
  {
    //in case of nested (sketch) operation no confirmation needed
 -  if (isGrantedOperation(theOperation))
 +  if (isGrantedOperation(theOperation->id()))
      return true;
    if (theOperation && theOperation->isModified()) {
      QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
@@@ -288,7 -293,7 +293,7 @@@ void XGUI_OperationMgr::resumeOperation
    theOperation->resume();
  }
  
 -bool XGUI_OperationMgr::isGrantedOperation(ModuleBase_Operation* theOperation)
 +bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
  {
    bool isGranted = false;
  
    ModuleBase_Operation* aPreviousOperation = 0;
    while (anIt.hasPrevious()) {
      ModuleBase_Operation* anOp = anIt.previous();
 -    if (anOp == theOperation) {
 +    if (anOp->id() == theId) {
        if (anIt.hasPrevious())
          aPreviousOperation = anIt.previous();
        break;
      }
    }
    if (aPreviousOperation)
 -    isGranted = aPreviousOperation->isGranted(theOperation->id());
 +    isGranted = aPreviousOperation->isGranted(theId);
  
    return isGranted;
  }
  
+ void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
+ {
+   SessionPtr aMgr = ModelAPI_Session::get();
+   DocumentPtr aDoc = aMgr->activeDocument();
+   bool aIsOp = aMgr->isOperation();
+   if (!aIsOp)
+     aMgr->startOperation();
+   aDoc->setCurrentFeature(theFeature, false);
+   if (!aIsOp)
+     aMgr->finishOperation();
+ }
  bool XGUI_OperationMgr::canStartOperation(const QString& theId, const bool isAdditionallyGranted)
  {
    bool aCanStart = true;
    ModuleBase_Operation* aCurrentOp = currentOperation();
    if (aCurrentOp) {
      bool aGranted = aCurrentOp->isGranted(theId) || isAdditionallyGranted;
 -    if (!aGranted) {
 -      if (canStopOperation(aCurrentOp)) {
 +    // the started operation is granted for the current one,
 +    // e.g. current - Sketch, started - Line
 +    if (aGranted) {
 +      aCanStart = true;
 +    }
 +    else {
 +      if (!isGrantedOperation(theId)) {
 +        // the operation is not granted in the current list of operations
 +        // e.g. Edit Parameter when Sketch, Line in Sketch is active.
 +        aCanStart = abortAllOperations();
 +      }
 +      else if (canStopOperation(aCurrentOp)) {
 +        // the started operation is granted in the parrent operation,
 +        // e.g. current - Line in Sketch, started Circle 
          if (myIsApplyEnabled && aCurrentOp->isModified())
            aCurrentOp->commit();
          else
@@@ -374,6 -379,32 +391,32 @@@ void XGUI_OperationMgr::onAbortOperatio
    }
  }
  
+ void XGUI_OperationMgr::onBeforeOperationStarted()
+ {
+   ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
+   if (!aCurrentOperation)
+     return;
+   /// Set current feature and remeber old current feature
+   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
+   if (aFOperation) {
+     SessionPtr aMgr = ModelAPI_Session::get();
+     DocumentPtr aDoc = aMgr->activeDocument();
+     // the parameter of current feature should be false, we should use all feature, not only visible
+     // in order to correctly save the previous feature of the nested operation, where the
+     // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
+     // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
+     // When sketch entity operation started, the sketch should be cashed here as the current.
+     // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
+     // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
+     // As a result the sketch disappears from the viewer. However after commit it is displayed back.
+     aFOperation->setPreviousCurrentFeature(aDoc->currentFeature(false));
+     if (aFOperation->isEditOperation()) // it should be performed by the feature edit only
+       // in create operation, the current feature is changed by addFeature()
+       aDoc->setCurrentFeature(aFOperation->feature(), false);
+   }
+ }
  void XGUI_OperationMgr::onOperationStarted()
  {
    ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
    emit operationStarted(aSenderOperation);
  }
  
+ void XGUI_OperationMgr::onBeforeOperationAborted()
+ {
+   onBeforeOperationCommitted();
+ }
  void XGUI_OperationMgr::onOperationAborted()
  {
    ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
    emit operationAborted(aSenderOperation);
  }
  
+ void XGUI_OperationMgr::onBeforeOperationCommitted()
+ {
+   ModuleBase_Operation* aCurrentOperation = dynamic_cast<ModuleBase_Operation*>(sender());
+   if (!aCurrentOperation)
+     return;
+   /// Restore the previous current feature
+   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(aCurrentOperation);
+   if (aFOperation) {
+     if (aFOperation->isEditOperation()) {
+       /// Restore the previous current feature
+       setCurrentFeature(aFOperation->previousCurrentFeature());
+     }
+     else { // create operation
+       // the Top created feature should stays the current. In nested operations, like Line in the Sketch or
+       // Sketch in ExtrusionCut, a previous feature should be restored on commit. It is performed here
+       // in order to perform it in the current transaction without opening a new one.
+       if (myOperations.front() != aFOperation)
+         setCurrentFeature(aFOperation->previousCurrentFeature());
+     }
+   }
+ }
  void XGUI_OperationMgr::onOperationCommitted()
  {
    // apply state for all features from the stack of operations should be updated
index f6c25a87b439909f5e753dc154c41ac4d78ed4ab,4a9839b9a63865b8ff98e6ff75ede04a60892ee2..052aa86b5c9cd20e968337d7094251f750cdf298
@@@ -10,6 -10,7 +10,7 @@@
  #include "XGUI.h"
  
  #include <ModuleBase_Operation.h>
+ #include "ModelAPI_Feature.h"
  
  #include <QList>
  #include <QObject>
@@@ -170,10 -171,14 +171,14 @@@ protected: // TEMPORAR
    /// Returns whether the parameter operation is granted in relation to the previous operation
    /// in a stack of started operations. It is used in canStopOperation to avoid warning message
    /// when granted operation is aborted, e.g. SketchLine in Sketch
 -  /// \param theOperation the started operation
 +  /// \param theId id of the operation which is checked
    /// \return boolean result
 -  bool isGrantedOperation(ModuleBase_Operation* theOperation);
 +  bool isGrantedOperation(const QString& theId);
  
+   /// Sets the feature as a current in the document
+   /// \param theFeature a feature
+   void setCurrentFeature(const FeaturePtr& theFeature);
   public slots:
    /// SLOT, that is called by the key in the property panel is clicked.
    /// \param theEvent the mouse event
    /// If there is a suspended operation, restart it.
    void onOperationStopped();
  
-   /// Slot called on operation start
+   /// Slot called before operation started. Stores the previous current feature, set the feature
+   /// of the operation as a current in the document. The previous current feature should be restored
+   /// by the operation abort/commit
+   void onBeforeOperationStarted();
+   /// Slot called after operation started
    void onOperationStarted();
  
-   /// Slot called on operation abort
+   /// Slot called before operation aborted. Restore the previous current operation
+   void onBeforeOperationAborted();
+   /// Slot called after operation aborted
    void onOperationAborted();
  
-   /// Slot called on operation commit
+   /// Slot called before operation committed. Restore the previous current operation
+   void onBeforeOperationCommitted();
+   /// Slot called after operation committed
    void onOperationCommitted();
  
    /// Slot called on operation resume
@@@ -207,7 -223,6 +223,6 @@@ private
    /// Current workshop
    ModuleBase_IWorkshop* myWorkshop;
  
    /// Lock/Unlock access to Ok button in property panel
    bool myIsValidationLock;
    /// Lock/Unlock access to Ok button in property panel