+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ AttributeSelectionListPtr aBaseObjectsAttrList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if(!aBaseObjectsAttrList.get()) {
+ theError = "Error: This validator can only work with selection list in \"%1\" feature.";
+ theError.arg(FeaturesPlugin_Union::ID());
+ return false;
+ }
+
+ for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
+ bool isSameFound = false;
+ AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
+ ResultCompSolidPtr aResult =
+ std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anAttrSelectionInList->context());
+ if(!aResult.get()) {
+ continue;
+ }
+ if(aResult->numberOfSubs() > 0) {
+ theError = "Error: Whole compsolids not allowed for selection.";
+ return false;
+ }
+ }
+
+ return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorUnionArguments::isValid(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ // Check feature kind.
+ if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
+ theError = "Error: This validator supports only \"%1\" feature.";
+ theError.arg(FeaturesPlugin_Union::ID());
+ return false;
+ }
+
+ // Get base objects attribute list.
+ AttributeSelectionListPtr aBaseObejctsAttrList =
+ theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
+ if(!aBaseObejctsAttrList.get()) {
+ theError = "Error: Could not get \"%1\" attribute.";
+ theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());
+ return false;
+ }
+
+ // Get all shapes.
+ ListOfShape aBaseShapesList;
+ for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
+ GeomShapePtr aShape = anAttrSelectionInList->value();
+ aBaseShapesList.push_back(aShape);
+ }
+
+ // Make componud and find connected.
+ GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
+ ListOfShape aCombined, aFree;
+ GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCombined, aFree);
+
+ if(aFree.size() > 0 || aCombined.size() > 1) {
+ theError = "Error: Not all shapes have shared topology.";
+ return false;
+ }
+
+ return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorUnionArguments::isNotObligatory(std::string theFeature,
+ std::string theAttribute)
+{
+ return false;
+}
+
+bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
+ theError = "Error: The attribute with the %1 type is not processed";
+ theError.arg(theAttribute->attributeType());
+ return false;
+ }
+
+ AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeReference>
+ (theAttribute);
+ ObjectPtr aRefObject = aRefAttribute->value();
+ if (!aRefObject.get()) {
+ theError = "Error: Empty feature.";
+ return false;
+ }
+
+ FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aRefObject);
+ if (!aRefFeature.get()) {
+ theError = "Error: Empty feature.";
+ return false;
+ }
+ std::list<std::shared_ptr<ModelAPI_Result> > aResults;
+ ModelAPI_Tools::getConcealedResults(aRefFeature, aResults);
+
+ size_t aConcealedResults = aResults.size();
+ if (!aConcealedResults && !theArguments.empty()) {
+ // find if these results are touched by the feature in another attribute
+ std::list<std::string>::const_iterator anIt = theArguments.begin();
+ std::string aRecoveredList = *anIt;
+ if (!aRecoveredList.empty()) {
+ std::shared_ptr<ModelAPI_AttributeRefList> aParameterList =
+ theAttribute->owner()->data()->reflist(aRecoveredList);
+ if (aParameterList.get())
+ aConcealedResults = aParameterList->size();
+ }
+ }
+
+ if (aConcealedResults == 0)
+ theError = "Error: No concealed results.";
+
+ return theError.empty();
+}