1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: FeaturesPlugin_Validators.cpp
4 // Created: 22 March 2016
5 // Author: Dmitry Bobylev
7 #include "FeaturesPlugin_Validators.h"
9 #include "FeaturesPlugin_Union.h"
11 #include <ModelAPI_Attribute.h>
12 #include <ModelAPI_AttributeInteger.h>
13 #include <ModelAPI_AttributeSelectionList.h>
14 #include <ModelAPI_AttributeString.h>
15 #include <ModelAPI_AttributeReference.h>
16 #include <ModelAPI_Feature.h>
17 #include <ModelAPI_ResultCompSolid.h>
18 #include <ModelAPI_ResultConstruction.h>
20 #include <GeomValidators_BodyShapes.h>
21 #include <GeomValidators_FeatureKind.h>
22 #include <GeomValidators_ShapeType.h>
24 #include <GeomAPI_DataMapOfShapeShape.h>
25 #include <GeomAPI_Lin.h>
26 #include <GeomAPI_PlanarEdges.h>
27 #include <GeomAPI_ShapeExplorer.h>
28 #include <GeomAPI_ShapeIterator.h>
30 #include <GeomAlgoAPI_CompoundBuilder.h>
31 #include <GeomAlgoAPI_ShapeBuilder.h>
32 #include <GeomAlgoAPI_ShapeTools.h>
33 #include <GeomAlgoAPI_WireBuilder.h>
35 #define _USE_MATH_DEFINES
38 //==================================================================================================
39 bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
40 const std::list<std::string>& theArguments,
41 std::string& theError) const
43 AttributeSelectionPtr aPathAttrSelection = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
44 if(!aPathAttrSelection.get()) {
45 theError = "Error: This validator can only work with path selector in \"Pipe\" feature.";
49 GeomShapePtr aPathShape = aPathAttrSelection->value();
50 ResultPtr aContext = aPathAttrSelection->context();
52 theError = "Error: Empty context.";
55 GeomShapePtr aContextShape = aContext->shape();
56 if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE && !aPathShape->isEqual(aContextShape)) {
57 theError = "Error: Local selection of wires not allowed.";
64 //==================================================================================================
65 bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
66 const std::list<std::string>& theArguments,
67 std::string& theError) const
69 static const std::string aCreationMethodID = "creation_method";
70 static const std::string aBaseObjectsID = "base_objects";
71 static const std::string aLocationsID = "locations_objects";
73 if(theFeature->getKind() != "Pipe") {
74 theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
78 AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);
79 if(!aCreationMethodAttr.get()) {
80 theError = "Error: Could not get \"" + aCreationMethodID + "\" attribute.";
84 if(aCreationMethodAttr->value() != "locations") {
88 AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);
89 if(!aBaseObjectsSelectionList.get()) {
90 theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
94 AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);
95 if(!aLocationsSelectionList.get()) {
96 theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
100 if(aLocationsSelectionList->size() > 0 && aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
101 theError = "Error: Number of locations should be the same as base objects.";
108 //==================================================================================================
109 bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature, std::string theAttribute)
114 //==================================================================================================
115 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
116 const std::list<std::string>& theArguments,
117 std::string& theError) const
119 if(theArguments.empty()) {
120 theError = "Error: Validator parameters is empty.";
124 // Checking attribute.
125 if(!isValidAttribute(theAttribute, theArguments, theError)) {
126 if(theError.empty()) {
127 theError = "Error: Attribute contains unacceptable shape.";
132 std::set<ResultConstructionPtr> aSelectedSketches;
133 std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
134 GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
135 std::string anAttributeType = theAttribute->attributeType();
136 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
137 AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
138 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
139 AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
140 ResultPtr aContext = aSelectionAttr->context();
141 if(!aContext.get()) {
142 theError = "Error: Empty context.";
146 ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
147 if(!aResultConstruction.get()) {
148 // It is not a result construction. If shape is compound check that it contains only faces and edges.
149 GeomShapePtr aShape = aSelectionAttr->value();
151 aShape = aContext->shape();
154 if(aShape->shapeType() == GeomAPI_Shape::COMPOUND) {
155 for(GeomAPI_ShapeIterator anIt(aShape); anIt.more(); anIt.next()) {
156 GeomShapePtr aSubShape = anIt.current();
157 if(aSubShape->shapeType() != GeomAPI_Shape::EDGE
158 && aSubShape->shapeType() != GeomAPI_Shape::FACE) {
159 theError = "Error: Compound should contain only faces and edges.";
168 GeomShapePtr aShape = aSelectionAttr->value();
169 GeomShapePtr aContextShape = aResultConstruction->shape();
171 // Whole sketch selected.
172 if(aSelectedSketchesFromObjects.find(aResultConstruction) != aSelectedSketchesFromObjects.cend()) {
173 theError = "Error: Object from this sketch is already selected. Sketch is not allowed for selection.";
177 aSelectedSketches.insert(aResultConstruction);
179 // Object from sketch selected.
180 if(aSelectedSketches.find(aResultConstruction) != aSelectedSketches.cend()) {
181 theError = "Error: Whole sketch with this object is already selected. Don't allow to select this object.";
185 for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
186 GeomShapePtr aWire = anExp.current();
187 if(aWire->orientation() != GeomAPI_Shape::FORWARD) {
188 theError = "Error: Wire with wrong orientation selected.";
192 if(aSelectedWiresFromObjects.isBound(aWire)) {
193 theError = "Error: Objects with such wire already selected. Don't allow to select this object.";
197 aSelectedWiresFromObjects.bind(aWire, aWire);
198 aSelectedSketchesFromObjects.insert(aResultConstruction);
207 //==================================================================================================
208 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
209 const std::list<std::string>& theArguments,
210 std::string& theError) const
212 if(!theAttribute.get()) {
213 theError = "Error: Empty attribute.";
217 std::string anAttributeType = theAttribute->attributeType();
218 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
219 AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
220 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
221 // If at least one attribute is invalid, the result is false.
222 if(!isValidAttribute(aListAttr->value(anIndex), theArguments, theError)) {
226 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
228 AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
229 ResultPtr aContext = anAttr->context();
230 if(!aContext.get()) {
231 theError = "Error: Attribute have empty context.";
235 GeomShapePtr aShape = anAttr->value();
236 GeomShapePtr aContextShape = aContext->shape();
238 aShape = aContextShape;
241 theError = "Error: Empty shape selected";
245 ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
246 if(aConstruction.get()) {
247 // Construciotn selected. Check that is is not infinite.
248 if(aConstruction->isInfinite()) {
249 theError = "Error: Infinite constructions is not allowed as base.";
253 if(aShape->isEqual(aContextShape)) {
254 // Whole construction selected. Check that it have faces.
255 if(aConstruction->facesNum() > 0) {
259 // Shape on construction selected. Check that it is a face or wire.
260 if(aShape->shapeType() == GeomAPI_Shape::WIRE || aShape->shapeType() == GeomAPI_Shape::FACE) {
268 if(!aShape->isEqual(aContextShape)) {
269 // Local selection on body does not allowed.
270 theError = "Error: Selected shape is in the local selection. Only global selection is allowed.";
274 // Check that object is a shape with allowed type.
275 GeomValidators_ShapeType aShapeTypeValidator;
276 if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
277 theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, "
278 "whole sketch(if it has at least one face), and whole objects with shape types: ";
279 std::list<std::string>::const_iterator anIt = theArguments.cbegin();
281 for(++anIt; anIt != theArguments.cend(); ++anIt) {
282 theError += ", " + *anIt;
288 theError = "Error: Attribute \"" + anAttributeType + "\" does not supported by this validator.";
295 //==================================================================================================
296 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
297 const std::list<std::string>& theArguments,
298 std::string& theError) const
300 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
301 theError = "Error: The attribute with the " + theAttribute->attributeType() + " type is not processed";
304 if (theArguments.size() != 2) {
305 theError = "Error: Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
308 // first argument is for the base attribute, second - for skipping feature kind
309 std::list<std::string>::const_iterator anIt = theArguments.begin();
310 std::string aBaseAttributeId = *anIt;
311 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
312 AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
313 if (!aBaseAttribute.get()) {
314 theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
317 if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
318 // this validator is not necessary anymore
322 std::string aFeatureAttributeKind = *anIt;
323 GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
324 // check whether the selection is on the sketch
325 std::list<std::string> anArguments;
326 anArguments.push_back(aFeatureAttributeKind);
328 bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);
329 bool aPlanarFace = false;
330 // check if selection has Face selected
331 GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
333 anArguments.push_back("face");
334 aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);
336 bool aValid = !aFeatureKind && aPlanarFace;
340 //==================================================================================================
341 bool FeaturesPlugin_ValidatorExtrusionDir::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
342 const std::list<std::string>& theArguments,
343 std::string& theError) const
345 if(theArguments.size() != 2) {
346 theError = "Error: Validator should be used with 2 parameters for extrusion.";
350 std::list<std::string>::const_iterator anArgsIt = theArguments.begin(), aLast = theArguments.end();
352 AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
355 GeomShapePtr aDirShape;
356 AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
358 aDirShape = aSelAttr->value();
359 if(!aDirShape.get()) {
360 ResultPtr aContext = aSelAttr->context();
362 aDirShape = aContext->shape();
367 if(!aDirShape.get()) {
368 // Check that dir can be empty.
369 if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
370 theError = "Error: Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
371 + "\" can not be used with default value. Select direction for extrusion.";
378 std::shared_ptr<GeomAPI_Edge> aDirEdge(new GeomAPI_Edge(aDirShape));
380 // If faces selected check that direction not parallel with them.
381 AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aCheckAttribute);
382 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
383 AttributeSelectionPtr anAttr = aListAttr->value(anIndex);
384 GeomShapePtr aShapeInList = anAttr->value();
385 if(!aShapeInList.get()) {
386 aShapeInList = anAttr->context()->shape();
388 bool isParallel = true;
389 if(aShapeInList->shapeType() == GeomAPI_Shape::FACE || aShapeInList->shapeType() == GeomAPI_Shape::SHELL) {
390 for(GeomAPI_ShapeExplorer anExp(aShapeInList, GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
391 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(anExp.current()));
392 isParallel = GeomAlgoAPI_ShapeTools::isParallel(aDirEdge, aFace);
397 } else if(aShapeInList->shapeType() == GeomAPI_Shape::COMPOUND) {
398 std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapeInList);
399 if(aPlanarEdges.get()) {
400 std::shared_ptr<GeomAPI_Dir> aSketchDir = aPlanarEdges->norm();
401 if(aDirEdge->isLine()) {
402 std::shared_ptr<GeomAPI_Dir> aDir = aDirEdge->line()->direction();
403 isParallel = abs(aSketchDir->angle(aDir) - M_PI / 2.0) < 10e-7;
414 theError = "Error: Direction is parallel to one of the selected face or face on selected shell.";
422 //==================================================================================================
423 bool FeaturesPlugin_ValidatorExtrusionDir::isNotObligatory(std::string theFeature, std::string theAttribute)
428 //==================================================================================================
429 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
430 std::string& theError) const
432 if(!theAttribute.get()) {
436 std::string anAttributeType = theAttribute->attributeType();
437 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
438 AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
439 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
440 // If at least one attribute is invalid, the result is false.
441 if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) {
445 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
447 AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
448 ResultPtr aContext = anAttr->context();
449 if(!aContext.get()) {
453 GeomShapePtr aShape = anAttr->value();
454 GeomShapePtr aContextShape = aContext->shape();
456 aShape = aContextShape;
462 if(aShape->shapeType() == GeomAPI_Shape::VERTEX ||
463 aShape->shapeType() == GeomAPI_Shape::EDGE ||
464 !aShape->isPlanar()) {
474 //==================================================================================================
475 bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
476 const std::list<std::string>& theArguments,
477 std::string& theError) const
479 AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
480 if(!anAttrSelectionList.get()) {
481 theError = "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
484 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
485 int anOperationType = aFeature->integer("bool_type")->value();
487 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
488 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
489 if(!anAttrSelection.get()) {
490 theError = "Error: Empty attribute selection.";
493 ResultPtr aContext = anAttrSelection->context();
494 if(!aContext.get()) {
495 theError = "Error: Empty selection context.";
498 ResultConstructionPtr aResultConstruction =
499 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
500 if(aResultConstruction.get()) {
501 theError = "Error: Result construction not allowed for selection.";
504 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
506 aShape = aContext->shape();
509 theError = "Error: Empty shape.";
512 int aShapeType = aShape->shapeType();
513 if(anOperationType == 1) {
514 // Fuse operation. Allow to select edges, faces and solids.
515 if(aShapeType != GeomAPI_Shape::EDGE &&
516 aShapeType != GeomAPI_Shape::FACE &&
517 aShapeType != GeomAPI_Shape::SOLID &&
518 aShapeType != GeomAPI_Shape::COMPSOLID &&
519 aShapeType != GeomAPI_Shape::COMPOUND) {
520 theError = "Error: Selected shape has the wrong type.";
524 if(aShapeType != GeomAPI_Shape::SOLID &&
525 aShapeType != GeomAPI_Shape::COMPSOLID &&
526 aShapeType != GeomAPI_Shape::COMPOUND) {
527 theError = "Error: Selected shape has the wrong type.";
536 //==================================================================================================
537 bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,
538 const std::list<std::string>& theArguments,
539 std::string& theError) const
541 AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
542 if(!anAttrSelectionList.get()) {
543 theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
547 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
548 AttributeSelectionPtr aSelectAttr = anAttrSelectionList->value(anIndex);
550 //GeomValidators_BodyShapes aBodyValidator;
551 //if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
555 GeomValidators_FeatureKind aFeatureKindValidator;
556 if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
560 ResultPtr aContext = aSelectAttr->context();
561 ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
562 if(aResultConstruction.get()) {
563 theError = "Error: Only body shapes and construction planes are allowed for selection.";
567 ResultCompSolidPtr aResultCompsolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
568 if(aResultCompsolid.get()) {
572 theError = "Error: Only body shapes and construction planes are allowed for selection.";
580 //==================================================================================================
581 bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
582 const std::list<std::string>& theArguments,
583 std::string& theError) const
585 AttributeSelectionListPtr aSubShapesAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
586 if(!aSubShapesAttrList.get()) {
587 theError = "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
591 static const std::string aBaseShapeID = "base_shape";
592 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
593 AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
595 if(!aShapeAttrSelection.get()) {
596 theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
600 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
601 ResultPtr aContext = aShapeAttrSelection->context();
602 if(!aContext.get()) {
603 theError = "Error: Empty context.";
606 if(!aBaseShape.get()) {
607 aBaseShape = aContext->shape();
609 if(!aBaseShape.get()) {
610 theError = "Error: Empty base shape.";
614 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
615 bool isSameFound = false;
616 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
617 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
618 for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
619 if(anIt.current()->isEqual(aShapeToAdd)) {
625 theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
633 //==================================================================================================
634 bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
635 const std::list<std::string>& theArguments,
636 std::string& theError) const
638 static const std::string aBaseShapeID = "base_shape";
639 static const std::string aSubShapesID = "subshapes";
641 if(theFeature->getKind() != "Remove_SubShapes") {
642 theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
646 AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
647 if(!aShapeAttrSelection.get()) {
648 theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
652 AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
653 if(!aSubShapesAttrList.get()) {
654 theError = "Error: Could not get \"" + aSubShapesID + "\" attribute.";
659 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
660 if(!aBaseShape.get()) {
661 theError = "Error: Base shape is empty.";
664 GeomShapePtr aResultShape = aBaseShape->emptyCopied();
666 // Copy sub-shapes from list to new shape.
667 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
668 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
669 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
670 GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
674 if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {
675 theError = "Error: Resulting shape is not valid.";
682 //==================================================================================================
683 bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string theFeature,
684 std::string theAttribute)
689 //==================================================================================================
690 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
691 const std::list<std::string>& theArguments,
692 std::string& theError) const
694 AttributeSelectionListPtr aBaseObjectsAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
695 if(!aBaseObjectsAttrList.get()) {
696 theError = "Error: This validator can only work with selection list in \"" + FeaturesPlugin_Union::ID() + "\" feature.";
700 for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
701 bool isSameFound = false;
702 AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
703 ResultCompSolidPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anAttrSelectionInList->context());
707 if(aResult->numberOfSubs() > 0) {
708 theError = "Error: Whole compsolids not allowed for selection.";
716 //==================================================================================================
717 bool FeaturesPlugin_ValidatorUnionArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
718 const std::list<std::string>& theArguments,
719 std::string& theError) const
721 // Check feature kind.
722 if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
723 theError = "Error: This validator supports only \"" + FeaturesPlugin_Union::ID() + "\" feature.";
727 // Get base objects attribute list.
728 AttributeSelectionListPtr aBaseObejctsAttrList = theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
729 if(!aBaseObejctsAttrList.get()) {
730 theError = "Error: Could not get \"" + FeaturesPlugin_Union::BASE_OBJECTS_ID() + "\" attribute.";
735 ListOfShape aBaseShapesList;
736 for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
737 AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
738 GeomShapePtr aShape = anAttrSelectionInList->value();
739 aBaseShapesList.push_back(aShape);
742 // Make componud and find connected.
743 GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
744 ListOfShape aCombined, aFree;
745 GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCombined, aFree);
747 if(aFree.size() > 0 || aCombined.size() > 1) {
748 theError = "Error: Not all shapes have shared topology.";
755 //==================================================================================================
756 bool FeaturesPlugin_ValidatorUnionArguments::isNotObligatory(std::string theFeature,
757 std::string theAttribute)