Salome HOME
Issue #2998: Add help description for automatic creation of constraints
[modules/shaper.git] / src / ModuleBase / ModuleBase_OperationFeature.cpp
old mode 100755 (executable)
new mode 100644 (file)
index a2c03e0..aa2d464
@@ -1,11 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-/*
- * ModuleBase_OperationFeature.cpp
- *
- *  Created on: Apr 2, 2014
- *      Author: sbh
- */
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// 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
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "ModuleBase_OperationFeature.h"
 
@@ -49,8 +59,8 @@
 #endif
 
 ModuleBase_OperationFeature::ModuleBase_OperationFeature(const QString& theId, QObject* theParent)
-: ModuleBase_Operation(theId, theParent),
-  myIsEditing(false)
+: ModuleBase_Operation(theId, theParent), myIsEditing(false), myNeedToBeAborted(false),
+myRestartTransactionOnResume(false)
 {
 }
 
@@ -177,10 +187,10 @@ FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage
      }*/
   }
 
-  if (theFlushMessage) {
-    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-  }
+  //if (theFlushMessage) {
+  //  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  //  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  //}
   return myFeature;
 }
 
@@ -196,13 +206,9 @@ bool ModuleBase_OperationFeature::hasObject(ObjectPtr theObj) const
   if (aFeature) {
     if (aFeature == theObj)
       return true;
-    std::list<ResultPtr> aResults;
-    ModelAPI_Tools::allResults(aFeature, aResults);
-    std::list<ResultPtr>::const_iterator aIt;
-    for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
-      ResultPtr aResult = *aIt;
-      if (theObj == aResult)
-         return true;
+    ResultPtr anObjRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
+    if (anObjRes.get() && aFeature == aFeature->document()->feature(anObjRes)) {
+      return true;
     }
 #ifdef DEBUG_DO_NOT_ACTIVATE_SUB_FEATURE
     if (aFeature->isMacro()) {
@@ -331,6 +337,7 @@ bool ModuleBase_OperationFeature::commit()
     if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
       anActiveWidget->storeValue();
     }
+    aPanel->onAcceptData();
   }
   if (canBeCommitted()) {
     emit beforeCommitted();
@@ -345,24 +352,25 @@ bool ModuleBase_OperationFeature::commit()
 
     myFeature->setStable(true);
 
-    SessionPtr aMgr = ModelAPI_Session::get();
-    /// Set current feature and remeber old current feature
-
     commitOperation();
-    aMgr->finishOperation();
 
     stopOperation();
+
+    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
-  qDebug("ModuleBase_OperationFeature::commit -- end : IMPOSSIBLE to commit");
+  qDebug("ModuleBase_OperationFeature::commit -- end");
 #endif
     return true;
   }
 #ifdef DEBUG_OPERATION_START
-  qDebug("ModuleBase_OperationFeature::commit -- end");
+  qDebug("ModuleBase_OperationFeature::commit -- end : IMPOSSIBLE to commit");
 #endif
   return false;
 }
@@ -516,3 +524,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;
+  }
+}