Salome HOME
Issue #1330 selection lost correction: rectangle, fillet, select a point(the line...
[modules/shaper.git] / src / ModuleBase / ModuleBase_OperationFeature.cpp
index ca34bc942de059db29023c2e57affb7bcdea1f54..950a20efa66a48108f84326212c7ac4af5920d19 100755 (executable)
@@ -49,6 +49,36 @@ ModuleBase_OperationFeature::~ModuleBase_OperationFeature()
   clearPreselection();
 }
 
+void ModuleBase_OperationFeature::setEditOperation(const bool& isEditState
+                                                   /*const bool theRestartTransaction*/)
+{
+  bool isCurrentEditState = isEditOperation();
+  if (isCurrentEditState == isEditState)
+    return;
+
+  /*
+  // this case is obsolete as it was not approved for reentrant sketch operation
+  // it was implemented when isEditState did not exist and only edit operation can be set
+  if (theRestartTransaction) {
+    // finsh previous create operation
+    emit beforeCommitted();
+    SessionPtr aMgr = ModelAPI_Session::get();
+    ModelAPI_Session::get()->finishOperation();
+
+    // start new edit operation
+    myIsEditing = true;
+    QString anId = getDescription()->operationId();
+    if (myIsEditing) {
+      anId = anId.append(EditSuffix());
+    }
+    ModelAPI_Session::get()->startOperation(anId.toStdString());
+    emit beforeStarted();
+  } else*/
+  myIsEditing = isEditState;
+
+  propertyPanel()->setEditingMode(isEditOperation());
+}
+
 FeaturePtr ModuleBase_OperationFeature::feature() const
 {
   return myFeature;
@@ -60,17 +90,9 @@ bool ModuleBase_OperationFeature::isValid() const
     return true; // rename operation
   if (myFeature->isAction())
     return true;
-  //Get validators for the Id
-  SessionPtr aMgr = ModelAPI_Session::get();
-  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-  bool aValid = aFactory->validate(myFeature);
 
-  // the feature exec state should be checked in order to do not apply features, which result can not
-  // be built. E.g. extrusion on sketch, where the "to" is a perpendicular plane to the sketch
-  bool isDone = ( myFeature->data()->execState() == ModelAPI_StateDone
-               || myFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
-
-  return aValid && isDone;
+  std::string anError = ModelAPI_Tools::getFeatureError(myFeature);
+  return anError.empty();
 }
 
 void ModuleBase_OperationFeature::startOperation()
@@ -174,7 +196,7 @@ bool ModuleBase_OperationFeature::isDisplayedOnStart(ObjectPtr theObject)
   return myVisualizedObjects.find(theObject) != myVisualizedObjects.end();
 }
 
-void ModuleBase_OperationFeature::start()
+bool ModuleBase_OperationFeature::start()
 {
   setIsModified(false);
   QString anId = getDescription()->operationId();
@@ -194,12 +216,12 @@ void ModuleBase_OperationFeature::start()
       // in order to update commands status in the workshop, to be exact the feature action
       // to be unchecked
       abort();
-      return;
+      return false;
     }
   }
   //Already called startOperation();
   emit started();
-
+  return true;
 }
 
 void ModuleBase_OperationFeature::abort()
@@ -242,7 +264,15 @@ void ModuleBase_OperationFeature::abort()
 
 bool ModuleBase_OperationFeature::commit()
 {
+  ModuleBase_IPropertyPanel* aPanel = propertyPanel();
+  if (aPanel) {
+    ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+    if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
+      anActiveWidget->storeValue();
+    }
+  }
   if (canBeCommitted()) {
+    emit beforeCommitted();
     // the widgets of property panel should not process any events come from data mode
     // after commit clicked. Some signal such as redisplay/create influence on content
     // of the object browser and viewer context. Therefore it influence to the current
@@ -257,7 +287,6 @@ bool ModuleBase_OperationFeature::commit()
     SessionPtr aMgr = ModelAPI_Session::get();
     /// Set current feature and remeber old current feature
 
-    emit beforeCommitted();
     commitOperation();
     aMgr->finishOperation();