]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
Salome HOME
Meet the coding style (line length <= 100)
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index c4d7cb6717d052a930753e94a8b1c91c0aa58a99..01f5e623390e69387d636e67d1bd2afd66b5af59 100644 (file)
@@ -142,8 +142,6 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
     return false;
   }
 
-  std::set<ResultConstructionPtr> aSelectedSketches;
-  std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
   GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
   std::string anAttributeType = theAttribute->attributeType();
   if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
@@ -184,26 +182,10 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
       GeomShapePtr aShape = aSelectionAttr->value();
       GeomShapePtr aContextShape = aResultConstruction->shape();
       if(!aShape.get()) {
-        // For possibility to select whole sketch from ObjectBrowser when
-        // Extrusion already has sub-element of this sketch, the next check
-        // is commented
         // Whole sketch selected.
-        /*if(aSelectedSketchesFromObjects.find(aResultConstruction) !=
-            aSelectedSketchesFromObjects.cend()) {
-          theError = "Error: Object from this sketch is already selected. "
-                     "Sketch is not allowed for selection.";
-          return false;
-        }*/
-
-        aSelectedSketches.insert(aResultConstruction);
+        continue;
       } else {
         // Object from sketch selected.
-        if(aSelectedSketches.find(aResultConstruction) != aSelectedSketches.cend()) {
-          theError = "Error: Whole sketch with this object is already selected. "
-                     "Don't allow to select this object.";
-          return false;
-        }
-
         for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
           GeomShapePtr aWire = anExp.current();
           if(aWire->orientation() != GeomAPI_Shape::FORWARD) {
@@ -218,7 +200,6 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
           }
 
           aSelectedWiresFromObjects.bind(aWire, aWire);
-          aSelectedSketchesFromObjects.insert(aResultConstruction);
         }
       }
     }
@@ -227,6 +208,73 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
   return true;
 }
 
+//==================================================================================================
+bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
+{
+  const std::string aBaseObjectsID = theArguments.front();
+
+  AttributeSelectionListPtr aListAttr = theFeature->selectionList(aBaseObjectsID);
+  if(!aListAttr.get()) {
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseObjectsID);
+    return false;
+  }
+
+  std::set<ResultConstructionPtr> aSelectedSketches;
+  std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
+
+  for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
+    AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
+    ResultPtr aContext = aSelectionAttr->context();
+    if(!aContext.get()) {
+      theError = "Error: Empty context.";
+      return false;
+    }
+
+    ResultConstructionPtr aResultConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if(!aResultConstruction.get()) {
+      // It is not a result construction.
+      continue;
+    }
+
+    GeomShapePtr aShape = aSelectionAttr->value();
+    GeomShapePtr aContextShape = aResultConstruction->shape();
+    if(!aShape.get()) {
+      // Whole sketch selected.
+      aSelectedSketches.insert(aResultConstruction);
+    } else {
+      // Object from sketch selected.
+      aSelectedSketchesFromObjects.insert(aResultConstruction);
+    }
+  }
+
+
+  for(std::set<ResultConstructionPtr>::const_iterator anIt = aSelectedSketches.cbegin();
+      anIt != aSelectedSketches.cend();
+      ++anIt) {
+    ResultConstructionPtr aResultConstruction = *anIt;
+    if(aSelectedSketchesFromObjects.find(aResultConstruction) !=
+        aSelectedSketchesFromObjects.cend()) {
+      theError = "Sketch and objects from it can not be selected at the same time.";
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isNotObligatory(
+    std::string theFeature,
+    std::string theAttribute)
+{
+  return false;
+}
+
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,