Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_OperationFeature.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 5ec2646..108f1df
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ModuleBase_OperationFeature.h"
@@ -60,7 +59,8 @@
 #endif
 
 ModuleBase_OperationFeature::ModuleBase_OperationFeature(const QString& theId, QObject* theParent)
-: ModuleBase_Operation(theId, theParent), myIsEditing(false), myNeedToBeAborted(false)
+: ModuleBase_Operation(theId, theParent), myIsEditing(false), myNeedToBeAborted(false),
+myRestartTransactionOnResume(false)
 {
 }
 
@@ -175,22 +175,6 @@ FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage
     std::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_Session::get()->activeDocument();
     myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
   }
-  if (myFeature) {  // TODO: generate an error if feature was not created
-    setIsModified(true);
-    // Model update should call "execute" of a feature.
-    //myFeature->execute();
-    // Init default values
-    /*QList<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
-     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
-     for (; anIt != aLast; anIt++) {
-     (*anIt)->storeValue(aFeature);
-     }*/
-  }
-
-  //if (theFlushMessage) {
-  //  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-  //  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-  //}
   return myFeature;
 }
 
@@ -225,10 +209,10 @@ bool ModuleBase_OperationFeature::hasObject(ObjectPtr theObj) const
         std::shared_ptr<ModelAPI_AttributeRefList> aCurSelList =
                                std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anIt);
         for (int i = 0, aNb = aCurSelList->size(); i < aNb && !aFoundObject; i++) {
-          ObjectPtr anObject = aCurSelList->object(i);
-          FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
-          if (aFeature.get()) {
-            aFoundObject = anObjectFeature == aFeature;
+          ObjectPtr aCurObj = aCurSelList->object(i);
+          FeaturePtr aCurFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aCurObj);
+          if (aCurFeat.get()) {
+            aFoundObject = anObjectFeature == aCurFeat;
           }
         }
       }
@@ -249,7 +233,6 @@ bool ModuleBase_OperationFeature::start()
 #ifdef DEBUG_OPERATION_START
   qDebug("ModuleBase_OperationFeature::start -- begin");
 #endif
-  setIsModified(false);
   QString anId = getDescription()->operationId();
   if (myIsEditing) {
     anId = anId.append(EditSuffix());
@@ -295,6 +278,12 @@ void ModuleBase_OperationFeature::abort()
       new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
   Events_Loop::loop()->send(aMsg);
 
+  if (myFeature.get())
+  {
+    static const Events_ID anEvent = Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES);
+    ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent);
+  }
+
   // the widgets of property panel should not process any events come from data mode
   // after abort clicked. Some signal such as redisplay/create influence on content
   // of the object browser and viewer context. Therefore it influence to the current
@@ -355,13 +344,13 @@ bool ModuleBase_OperationFeature::commit()
     commitOperation();
 
     stopOperation();
-    emit stopped();
-    emit committed();
 
-    // finishOperation has to be after commited because in signal commited
-    // there is a modification of attribures (color)
     SessionPtr aMgr = ModelAPI_Session::get();
     aMgr->finishOperation();
+    // Finish operation has to be before stopped because stopped caused update of Object browser
+    // If it will be done before of cleaning of obsolete objects it will cause crash
+    emit stopped();
+    emit committed();
 
     afterCommitOperation();
 #ifdef DEBUG_OPERATION_START
@@ -410,20 +399,16 @@ ModuleBase_ModelWidget* ModuleBase_OperationFeature::activateByPreselection(
         }
       }
       else {
-        bool isSet = false;
         // 1. apply the selection to controls
         for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
           aWgt = (*aWIt);
           if (!aWgt->canAcceptFocus())
             continue;
           aPropertyPanel->setPreselectionWidget(aWgt);
-          if (myPreSelection.empty() || !aWgt->setSelection(myPreSelection, true)) {
-            isSet = false;
+          if (myPreSelection.empty() || !aWgt->setSelection(myPreSelection, true))
             break;
-          } else {
-            isSet = true;
+          else
             aFilledWgt = aWgt;
-          }
         }
       }
       aPropertyPanel->setPreselectionWidget(NULL);
@@ -524,3 +509,11 @@ void ModuleBase_OperationFeature::setPropertyPanel(ModuleBase_IPropertyPanel* th
       theProp->setFocusOnOkButton();
   }
 }
+
+void ModuleBase_OperationFeature::resumeOperation()
+{
+  if (myRestartTransactionOnResume) {
+    ModelAPI_Session::get()->startOperation(this->id().toStdString(), true);
+    myRestartTransactionOnResume = false;
+  }
+}