]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
Salome HOME
Issue #1343. Improvement of Extrusion and Revolution operations: sketch creator setSe...
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index 0c0e893ba24e1eed4fa20274f3baf6e204a439b6..2230d9eb2458939a525a01b8937d849a06be5e27 100644 (file)
@@ -10,7 +10,9 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeReference.h>
 
+#include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_ShapeType.h>
 
 //=================================================================================================
@@ -175,23 +177,44 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA
                                                         const std::list<std::string>& theArguments,
                                                         std::string& theError) const
 {
-  FeaturesPlugin_ValidatorBaseForGeneration aBaseValidator;
-
-  if(aBaseValidator.isValid(theAttribute, theArguments, theError)) {
-    return true;
+  if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+  if (theArguments.size() != 2) {
+    theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
+    return false;
+  }
+  // first argument is for the base attribute, second - for skipping feature kind
+  std::list<std::string>::const_iterator anIt = theArguments.begin();
+  std::string aBaseAttributeId = *anIt;
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+  AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
+  if (!aBaseAttribute.get()) {
+    theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
+    return false;
   }
+  if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
+    // this validator is not necessary anymore
+    return true;
 
-  // Check that face selected.
-  GeomValidators_ShapeType aShapeType;
+  anIt++;
+  std::string aFeatureAttributeKind = *anIt;
+  GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
+  // check whether the selection is on the sketch
   std::list<std::string> anArguments;
-  anArguments.push_back("face");
-  if(aShapeType.isValid(theAttribute, anArguments, theError)) {
-    return true;
-  }
+  anArguments.push_back(aFeatureAttributeKind);
 
-  theError = "Selected shape is not suitable for this operation";
+  bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);
+  bool aPlanarFace = false;
+  // check if selection has Face selected
+  GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
+  anArguments.clear();
+  anArguments.push_back("face");
+  aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);
 
-  return false;
+  bool aValid = !aFeatureKind && aPlanarFace;
+  return aValid;
 }
 
 //=================================================================================================