]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
SetCurrentFeature call is moved to operation manager to perform it in the commit...
authornds <nds@opencascade.com>
Fri, 9 Oct 2015 08:06:05 +0000 (11:06 +0300)
committernds <nds@opencascade.com>
Fri, 9 Oct 2015 08:06:43 +0000 (11:06 +0300)
src/ModuleBase/ModuleBase_Operation.h
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/ModuleBase/ModuleBase_OperationFeature.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h

index 9a34e6423d326db9d12ac3012448614579acda58..12e5ddb86a91ef2d4f581da500541337fb292c53 100644 (file)
@@ -91,12 +91,15 @@ Q_OBJECT
 
 signals:
   /// The operation is started
+  void beforeStarted();
   void started();
 
   /// The operation is aborted
+  void beforeAborted();
   void aborted();
 
   /// The operation is committed
+  void beforeCommitted();
   void committed();
 
   /// The operation is aborted or committed
index 82f6db270ae09966b8bd19e8afebe9fb66d37598..647455f46bed1265f2010644957ae102a3ee6a4e 100755 (executable)
@@ -120,16 +120,6 @@ void ModuleBase_OperationFeature::stopOperation()
     Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
 }
 
-void ModuleBase_OperationFeature::resumeOperation()
-{
-  ModuleBase_Operation::resumeOperation();
-  //if (!myIsEditing)
-    setCurrentFeature(feature());
-  //SessionPtr aMgr = ModelAPI_Session::get();
-  //DocumentPtr aDoc = aMgr->activeDocument();
-  //aDoc->setCurrentFeature(feature(), false);
-}
-
 FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage)
 {
   if (myParentFeature.get()) {
@@ -192,6 +182,7 @@ void ModuleBase_OperationFeature::start()
   }
   ModelAPI_Session::get()->startOperation(anId.toStdString());
 
+  emit beforeStarted();
   startOperation();
 
   if (!myIsEditing) {
@@ -205,22 +196,6 @@ void ModuleBase_OperationFeature::start()
       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();
   emit started();
 
@@ -228,6 +203,8 @@ void ModuleBase_OperationFeature::start()
 
 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>(
@@ -243,21 +220,10 @@ void ModuleBase_OperationFeature::abort()
   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, false);//true);
-    if (!aIsOp)
-      aMgr->finishOperation();
-    myPreviousCurrentFeature = FeaturePtr();
-  }
   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
@@ -285,24 +251,7 @@ bool ModuleBase_OperationFeature::commit()
     SessionPtr aMgr = ModelAPI_Session::get();
     /// Set current feature and remeber old current feature
 
-    if (myIsEditing) {
-      setCurrentFeature(myPreviousCurrentFeature);
-      /*DocumentPtr aDoc = aMgr->activeDocument();
-      bool aIsOp = aMgr->isOperation();
-      if (!aIsOp)
-        aMgr->startOperation();
-      aDoc->setCurrentFeature(myPreviousCurrentFeature, true);
-      if (!aIsOp)
-        aMgr->finishOperation();*/
-      myPreviousCurrentFeature = FeaturePtr();
-    }
-    else {
-      /*CompositeFeaturePtr aCompositeFeature = ModelAPI_Tools::compositeOwner(feature());
-      if (aCompositeFeature.get())
-        setCurrentFeature(aCompositeFeature);//myPreviousCurrentFeature);
-      //else
-      //  setCurrentFeature(feature());*/
-    }
+    emit beforeCommitted();
     commitOperation();
     aMgr->finishOperation();
 
@@ -316,18 +265,6 @@ bool ModuleBase_OperationFeature::commit()
   return false;
 }
 
-void ModuleBase_OperationFeature::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);//true);
-  if (!aIsOp)
-    aMgr->finishOperation();
-}
-
 void ModuleBase_OperationFeature::activateByPreselection()
 {
   if (myPreSelection.empty())
@@ -384,6 +321,16 @@ CompositeFeaturePtr ModuleBase_OperationFeature::parentFeature() const
   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 3e5da99146947bf83248bbfba91056d814163556..48c8506e12e6647a41d08c9ac966778f2fdcb79e 100755 (executable)
@@ -96,8 +96,6 @@ Q_OBJECT
   /// \return Currently installed property panel
   //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
 
-  void setCurrentFeature(const FeaturePtr& theFeature);
-
   /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
   virtual void activateByPreselection();
 
@@ -109,6 +107,14 @@ Q_OBJECT
   /// \return Installed parent feature (can be NULL)
   CompositeFeaturePtr parentFeature() const;
 
+  /// Stores the previous to the operation current feature
+  /// \set theFeature a feature
+  void setPreviousCurrentFeature(const FeaturePtr& theFeature);
+
+  /// Returns the previous to the operation current feature
+  /// \return theFeature a feature
+  FeaturePtr previousCurrentFeature();
+
 signals:
   /// The operation is filled with existing preselection
   void activatedByPreselection(); 
@@ -139,9 +145,6 @@ signals:
   /// Hide feature/results if they were hided on start
   virtual void stopOperation();
 
-  /// Virtual method called after operation resume (see resume() method for more description)
-  virtual void resumeOperation();
-
   /// Creates an operation new feature
   /// \param theFlushMessage the flag whether the create message should be flushed
   /// \returns the created feature
index 2d36b457593a9600dcfa37c0dbca6689b9216178..a643ef5a898c71f8b2190d9ffc4e45938aacbe52 100644 (file)
@@ -116,9 +116,14 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
     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*>
@@ -309,6 +314,18 @@ bool XGUI_OperationMgr::isGrantedOperation(ModuleBase_Operation* theOperation)
   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;
@@ -362,6 +379,32 @@ void XGUI_OperationMgr::onAbortOperation()
   }
 }
 
+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());
@@ -369,12 +412,40 @@ void XGUI_OperationMgr::onOperationStarted()
   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 5ea3af47cfd2b36fc3013142bbb1ad614f02a901..4a9839b9a63865b8ff98e6ff75ede04a60892ee2 100644 (file)
@@ -10,6 +10,7 @@
 #include "XGUI.h"
 
 #include <ModuleBase_Operation.h>
+#include "ModelAPI_Feature.h"
 
 #include <QList>
 #include <QObject>
@@ -174,6 +175,10 @@ protected: // TEMPORARY
   /// \return boolean result
   bool isGrantedOperation(ModuleBase_Operation* theOperation);
 
+  /// 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
@@ -184,13 +189,24 @@ protected: // TEMPORARY
   /// 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 @@ 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