+ AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
+ if(!aShapeAttrSelection.get()) {
+ theError = "Error: Could not get \"%1\" attribute.";
+ theError.arg(aBaseShapeID);
+ return false;
+ }
+
+ AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
+ if(!aSubShapesAttrList.get()) {
+ theError = "Error: Could not get \"%1\" attribute.";
+ theError.arg(aSubShapesID);
+ return false;
+ }
+
+ // Copy base shape.
+ GeomShapePtr aBaseShape = aShapeAttrSelection->value();
+ if(!aBaseShape.get()) {
+ theError = "Error: Base shape is empty.";
+ return false;
+ }
+ GeomShapePtr aResultShape = aBaseShape->emptyCopied();
+
+ // Copy sub-shapes from list to new shape.
+ for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
+ GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
+ GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
+ }
+
+ // Check new shape.
+ if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {
+ theError = "Error: Resulting shape is not valid.";
+ return false;
+ }
+
+ return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string theFeature,
+ std::string theAttribute)
+{
+ return false;
+}
+
+//==================================================================================================
+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.";