Salome HOME
Fix for the issue #910: never fully remove the results, just make them disabled when...
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.cpp
index 0bea2148a29ec20002f796e62c54e3d36e8b3332..b4cf246eac2e7827d57f60dcd9e7cbe781d99850 100644 (file)
@@ -11,9 +11,6 @@
 #include "PartSet_Tools.h"
 #include "PartSet_WidgetSketchLabel.h"
 
-#include <ModuleBase_WidgetEditor.h>
-#include <ModuleBase_ModelWidget.h>
-
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_Workshop.h>
 #include <XGUI_ViewerProxy.h>
 #include <XGUI_OperationMgr.h>
 
+#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_ISelection.h>
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IViewWindow.h>
+#include <ModuleBase_ModelWidget.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationFeature.h>
-#include <ModuleBase_ISelection.h>
-#include <ModuleBase_IPropertyPanel.h>
 #include <ModuleBase_Operation.h>
+#include <ModuleBase_WidgetEditor.h>
 
 #include <GeomDataAPI_Point2D.h>
 
@@ -70,6 +69,7 @@
 
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_AttributeString.h>
 
 #include <QMouseEvent>
 #include <QApplication>
@@ -192,7 +192,9 @@ void PartSet_SketcherMgr::onEnterViewPort()
   // redisplayed before this update, the feature presentation jumps from reset value to current.
   myIsMouseOverWindow = true;
   myIsResetCurrentValue = false;
-  operationMgr()->onValidateOperation();
+  // it is important to validate operation here only if sketch entity create operation is active
+  // because at this operation we reacts to the mouse leave/enter view port
+  //operationMgr()->onValidateOperation();
 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
   qDebug(QString("onEnterViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
 #endif
@@ -203,6 +205,8 @@ void PartSet_SketcherMgr::onEnterViewPort()
 
   if (!isNestedCreateOperation(getCurrentOperation()))
     return;
+    operationMgr()->onValidateOperation();
+
   // we need change displayed state of the current operation feature
   // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
   // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
@@ -223,7 +227,9 @@ void PartSet_SketcherMgr::onLeaveViewPort()
 {
   myIsMouseOverViewProcessed = false;
   myIsMouseOverWindow = false;
-  operationMgr()->onValidateOperation();
+  // it is important to validate operation here only if sketch entity create operation is active
+  // because at this operation we reacts to the mouse leave/enter view port
+  //operationMgr()->onValidateOperation();
 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
   qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
 #endif
@@ -239,6 +245,8 @@ void PartSet_SketcherMgr::onLeaveViewPort()
   if (myIsPopupMenuActive)
     return;
 
+  operationMgr()->onValidateOperation();
+
   // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
@@ -267,6 +275,8 @@ void PartSet_SketcherMgr::onLeaveViewPort()
 
 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
 {
+  myIsResetCurrentValue = false;
+
   if (isNestedCreateOperation(getCurrentOperation()))
     return;
   // it is necessary to save current selection in order to restore it after the values are modifed
@@ -302,7 +312,7 @@ void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
     return;
 
   // visualize the current operation feature
-  myIsResetCurrentValue = false;
+  //myIsResetCurrentValue = false;
   operationMgr()->onValidateOperation();
   // the feature is to be erased here, but it is correct to call canDisplayObject because
   // there can be additional check (e.g. editor widget in distance constraint)
@@ -657,6 +667,17 @@ void PartSet_SketcherMgr::launchEditing()
   }
 }
 
+bool PartSet_SketcherMgr::sketchSolverError()
+{
+  bool anError = false;
+  CompositeFeaturePtr aSketch = activeSketch();
+  if (aSketch.get()) {
+    AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
+    anError = !aAttributeString->value().empty();
+  }
+  return anError;
+}
+
 
 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
 {
@@ -796,7 +817,7 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
     aConnector->activateModuleSelectionModes();
 }
 
-void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation*/* theOperation*/)
+void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* /* theOperation*/)
 {
   myIsMouseOverWindow = false;
   myIsConstraintsShown = true;
@@ -907,6 +928,28 @@ bool PartSet_SketcherMgr::canCommitOperation() const
   return aCanCommit;
 }
 
+bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
+{
+  bool aCanErase = true;
+  // when the sketch operation is active, results of sketch sub-feature can not be hidden
+  if (myCurrentSketch.get()) {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    if (aResult.get()) {
+      // Display sketcher objects
+      for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
+
+        FeaturePtr aFeature = myCurrentSketch->subFeature(i);
+        std::list<ResultPtr> aResults = aFeature->results();
+        std::list<ResultPtr>::const_iterator anIt;
+        for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
+          aCanErase = *anIt != aResult;
+        }
+      }
+    }
+  }
+  return aCanErase;
+}
+
 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
 {
   bool aCanDisplay = true;