Salome HOME
#1119 Confirmation box for deleting parts
[modules/shaper.git] / src / PartSet / PartSet_Validators.cpp
index a53eb3596cd4e314138db36954cac113726a9ca7..163063bd0b514ba46ac4bb844ae5dc0701230762 100755 (executable)
@@ -7,6 +7,7 @@
 #include "PartSet_Validators.h"
 
 #include "PartSet_Tools.h"
+#include "PartSet_SketcherMgr.h"
 
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
@@ -92,14 +93,21 @@ std::shared_ptr<GeomAPI_Pln> sketcherPlane(ModuleBase_Operation* theOperation)
 bool isEmptySelectionValid(ModuleBase_Operation* theOperation)
 {
   ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+  // during the create operation empty selection is always valid
   if (!aFeatureOp->isEditOperation()) {
     return true;
   }
-  std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
-  if (aPlane.get())
-    return true;
-  else 
-    return false;
+  else {
+    if (PartSet_SketcherMgr::isSketchOperation(aFeatureOp)) {
+      std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+      if (aPlane.get())
+        return true;
+      else 
+        return false;
+    }
+    else// in edit operation an empty selection is always valid, performed for re-entrant operrations
+      return true;
+  }
 }
 
 bool PartSet_DistanceSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
@@ -205,8 +213,8 @@ bool PartSet_FilletSelection::isValid(const ModuleBase_ISelection* theSelection,
   if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
     return isEmptySelectionValid(theOperation);
   } else {
-    int aCount = shapesNbLines(theSelection);
-    return (aCount > 0) && (aCount < 3);
+    int aCount = shapesNbPoints(theSelection);
+    return aCount == 1;
   }
 }
 
@@ -306,6 +314,24 @@ bool PartSet_EqualSelection::isValid(const ModuleBase_ISelection* theSelection,
   }
 }
 
+bool PartSet_CollinearSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
+{
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    return isEmptySelectionValid(theOperation);
+  } else {
+    int aCount = shapesNbLines(theSelection);
+    return (aCount > 0) && (aCount < 3);
+  }
+}
+
+bool PartSet_MiddlePointSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
+{
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0)
+    return isEmptySelectionValid(theOperation);
+  else
+    return shapesNbLines(theSelection) == 1 && shapesNbPoints(theSelection) == 1;
+}
+
 
 std::string PartSet_DifferentObjectsValidator::errorMessage(
                          const PartSet_DifferentObjectsValidator::ErrorType& theType,
@@ -542,6 +568,21 @@ bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
       }
     }
   }
+  if (anAttributeType == ModelAPI_AttributeSelection::typeId()) {
+    AttributeSelectionPtr aSelectAttr = 
+                      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    ObjectPtr anObject = aSelectAttr->context();
+    // a context of the selection attribute is a feature result. It can be a case when the result
+    // of the feature is null, e.g. the feature is modified and has not been executed yet.
+    // The validator returns an invalid result here. The case is an extrusion built on a sketch
+    // feature. A new sketch element creation leads to an empty result.
+    if (!anObject.get())
+      isSketchEntities = false;
+    else {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+      isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+    }
+  }
   if (anAttributeType == ModelAPI_AttributeRefList::typeId()) {
     AttributeRefListPtr aRefListAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);