1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesPlugin_Validators.h"
23 #include "FeaturesPlugin_Boolean.h"
24 #include "FeaturesPlugin_BooleanFuse.h"
25 #include "FeaturesPlugin_BooleanCommon.h"
26 #include "FeaturesPlugin_BooleanSmash.h"
27 #include "FeaturesPlugin_Pipe.h"
28 #include "FeaturesPlugin_Union.h"
30 #include <Events_InfoMessage.h>
32 #include <ModelAPI_Attribute.h>
33 #include <ModelAPI_AttributeInteger.h>
34 #include <ModelAPI_AttributeSelectionList.h>
35 #include <ModelAPI_AttributeString.h>
36 #include <ModelAPI_AttributeReference.h>
37 #include <ModelAPI_AttributeRefList.h>
38 #include <ModelAPI_Feature.h>
39 #include <ModelAPI_ResultBody.h>
40 #include <ModelAPI_ResultConstruction.h>
41 #include <ModelAPI_Tools.h>
43 #include <GeomValidators_BodyShapes.h>
44 #include <GeomValidators_Face.h>
45 #include <GeomValidators_FeatureKind.h>
46 #include <GeomValidators_ShapeType.h>
48 #include <GeomAPI_DataMapOfShapeShape.h>
49 #include <GeomAPI_Lin.h>
50 #include <GeomAPI_PlanarEdges.h>
51 #include <GeomAPI_Pln.h>
52 #include <GeomAPI_ShapeExplorer.h>
53 #include <GeomAPI_ShapeIterator.h>
55 #include <GeomAlgoAPI_CompoundBuilder.h>
56 #include <GeomAlgoAPI_ShapeBuilder.h>
57 #include <GeomAlgoAPI_ShapeTools.h>
58 #include <GeomAlgoAPI_WireBuilder.h>
60 #define _USE_MATH_DEFINES
63 //==================================================================================================
64 bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
65 const std::list<std::string>& theArguments,
66 Events_InfoMessage& theError) const
68 AttributeSelectionPtr aPathAttrSelection =
69 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
70 if(!aPathAttrSelection.get()) {
71 theError = "Error: This validator can only work with path selector in \"Pipe\" feature.";
75 GeomShapePtr aPathShape = aPathAttrSelection->value();
76 ResultPtr aContext = aPathAttrSelection->context();
78 theError = "Error: Empty context.";
81 GeomShapePtr aContextShape = aContext->shape();
82 if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE &&
83 !aPathShape->isEqual(aContextShape)) {
84 theError = "Error: Local selection of wires not allowed.";
91 //==================================================================================================
92 bool FeaturesPlugin_ValidatorPipeLocations::isValid(const AttributePtr& theAttribute,
93 const std::list<std::string>& theArguments,
94 Events_InfoMessage& theError) const
96 AttributeSelectionListPtr anAttrSelectionList =
97 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
98 if(!anAttrSelectionList.get()) {
100 "Error: This validator can only work with selection list attributes in \"Pipe\" feature.";
103 std::shared_ptr<FeaturesPlugin_Pipe> aFeature =
104 std::dynamic_pointer_cast<FeaturesPlugin_Pipe>(theAttribute->owner());
106 AttributeSelectionPtr aPathSelection = aFeature->selection(FeaturesPlugin_Pipe::PATH_OBJECT_ID());
107 if (!aPathSelection.get()) {
108 theError = "Error: Path not selected.";
112 GeomShapePtr aPathShape = aPathSelection->value();
113 if (!aPathShape.get()) {
114 ResultPtr aContext = aPathSelection->context();
115 if (!aContext.get()) {
116 FeaturePtr aContFeat = aPathSelection->contextFeature();
117 if (!aContFeat.get() || !aContFeat->results().size()) {
118 theError = "Error: Empty selection context.";
122 aPathShape = aContext->shape();
125 if (!aPathShape.get()) {
126 theError = "Error: Empty path shape.";
130 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
131 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
132 if (!anAttrSelection.get()) {
133 theError = "Error: Empty attribute selection.";
136 ResultPtr aContext = anAttrSelection->context();
137 if (!aContext.get()) {
138 FeaturePtr aContFeat = anAttrSelection->contextFeature();
139 if (!aContFeat.get() || !aContFeat->results().size()) {
140 theError = "Error: Empty selection context.";
144 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
145 if (!aShape.get() && aContext.get()) {
146 GeomShapePtr aContextShape = aContext->shape();
147 aShape = aContextShape;
150 theError = "Error: Empty shape.";
154 if (!aPathShape->isSubShape(aShape)) {
155 theError = "Error: Location should be a vertex subshape from path shape.";
163 //==================================================================================================
164 bool FeaturesPlugin_ValidatorPipeLocationsNumber::isValid(
165 const std::shared_ptr<ModelAPI_Feature>& theFeature,
166 const std::list<std::string>& theArguments,
167 Events_InfoMessage& theError) const
169 static const std::string aCreationMethodID = "creation_method";
170 static const std::string aBaseObjectsID = "base_objects";
171 static const std::string aLocationsID = "locations_objects";
173 if(theFeature->getKind() != "Pipe") {
174 theError = "Error: Feature \"%1\" does not supported by this validator.";
175 theError.arg(theFeature->getKind());
179 AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);
180 if(!aCreationMethodAttr.get()) {
181 theError = "Error: Could not get \"%1\" attribute.";
182 theError.arg(aCreationMethodID);
186 if(aCreationMethodAttr->value() != "locations") {
190 AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);
191 if(!aBaseObjectsSelectionList.get()) {
192 theError = "Error: Could not get \"%1\" attribute.";
193 theError.arg(aBaseObjectsID);
197 AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);
198 if(!aLocationsSelectionList.get()) {
199 theError = "Error: Could not get \"%1\" attribute.";
200 theError.arg(aBaseObjectsID);
204 if(aLocationsSelectionList->size() > 0 &&
205 aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
206 theError = "Error: Number of locations should be the same as base objects.";
213 //==================================================================================================
214 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
215 const std::list<std::string>& theArguments,
216 Events_InfoMessage& theError) const
218 if(theArguments.empty()) {
219 theError = "Error: Validator parameters is empty.";
223 // Checking attribute.
224 if(!isValidAttribute(theAttribute, theArguments, theError)) {
225 if(theError.empty()) {
226 theError = "Error: Attribute contains unacceptable shape.";
231 GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
232 std::string anAttributeType = theAttribute->attributeType();
233 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
234 AttributeSelectionListPtr aListAttr =
235 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
236 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
237 AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
238 ResultPtr aContext = aSelectionAttr->context();
239 if(!aContext.get() && !aSelectionAttr->contextFeature().get()) {
240 theError = "Error: Empty context.";
244 ResultConstructionPtr aResultConstruction =
245 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
246 if(!aResultConstruction.get()) {
247 // It is not a result construction.
248 // If shape is compound check that it contains only faces and edges.
249 GeomShapePtr aShape = aSelectionAttr->value();
251 if (aContext.get()) {
252 aShape = aContext->shape();
254 theError = "Error: Empty context.";
259 if(aShape->shapeType() == GeomAPI_Shape::COMPOUND) {
260 for(GeomAPI_ShapeIterator anIt(aShape); anIt.more(); anIt.next()) {
261 GeomShapePtr aSubShape = anIt.current();
262 if(aSubShape->shapeType() != GeomAPI_Shape::EDGE
263 && aSubShape->shapeType() != GeomAPI_Shape::FACE) {
264 theError = "Error: Compound should contain only faces and edges.";
273 GeomShapePtr aShape = aSelectionAttr->value();
274 GeomShapePtr aContextShape = aResultConstruction->shape();
276 // Whole sketch selected.
279 // Object from sketch selected.
280 for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
281 GeomShapePtr aWire = anExp.current();
282 if(aWire->orientation() != GeomAPI_Shape::FORWARD) {
283 theError = "Error: Wire with wrong orientation selected.";
287 if(aSelectedWiresFromObjects.isBound(aWire)) {
289 "Error: Objects with such wire already selected. Don't allow to select this object.";
293 aSelectedWiresFromObjects.bind(aWire, aWire);
302 //==================================================================================================
303 bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid(
304 const std::shared_ptr<ModelAPI_Feature>& theFeature,
305 const std::list<std::string>& theArguments,
306 Events_InfoMessage& theError) const
308 const std::string aBaseObjectsID = theArguments.front();
310 AttributeSelectionListPtr aListAttr = theFeature->selectionList(aBaseObjectsID);
311 if(!aListAttr.get()) {
312 theError = "Error: Could not get \"%1\" attribute.";
313 theError.arg(aBaseObjectsID);
317 std::set<ResultConstructionPtr> aSelectedSketches;
318 std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
320 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
321 AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
322 ResultPtr aContext = aSelectionAttr->context();
323 if(!aContext.get()) {
324 FeaturePtr aFeature = aSelectionAttr->contextFeature();
325 if (!aFeature.get() || aFeature->results().empty()) {
326 theError = "Error: Empty context.";
329 aContext = aFeature->firstResult();
333 ResultConstructionPtr aResultConstruction =
334 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
335 if(!aResultConstruction.get()) {
336 // It is not a result construction.
340 GeomShapePtr aShape = aSelectionAttr->value();
341 GeomShapePtr aContextShape = aResultConstruction->shape();
343 // Whole sketch selected.
344 aSelectedSketches.insert(aResultConstruction);
346 // Object from sketch selected.
347 aSelectedSketchesFromObjects.insert(aResultConstruction);
352 for(std::set<ResultConstructionPtr>::const_iterator anIt = aSelectedSketches.cbegin();
353 anIt != aSelectedSketches.cend();
355 ResultConstructionPtr aResultConstruction = *anIt;
356 if(aSelectedSketchesFromObjects.find(aResultConstruction) !=
357 aSelectedSketchesFromObjects.cend()) {
358 theError = "Sketch and objects from it can not be selected at the same time.";
366 //==================================================================================================
367 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
368 const std::list<std::string>& theArguments,
369 Events_InfoMessage& theError) const
371 if(!theAttribute.get()) {
372 theError = "Error: Empty attribute.";
376 std::string anAttributeType = theAttribute->attributeType();
377 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
378 AttributeSelectionListPtr aListAttr =
379 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
380 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
381 // If at least one attribute is invalid, the result is false.
382 if(!isValidAttribute(aListAttr->value(anIndex), theArguments, theError)) {
386 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
388 AttributeSelectionPtr anAttr =
389 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
390 ResultPtr aContext = anAttr->context();
391 if(!aContext.get() && !anAttr->contextFeature().get()) {
392 theError = "Error: Attribute have empty context.";
396 GeomShapePtr aShape = anAttr->value();
397 GeomShapePtr aContextShape;
398 if(!aShape.get() && aContext.get()) {
399 aContextShape = aContext->shape();
400 aShape = aContextShape;
403 theError = "Error: Empty shape selected";
407 ResultConstructionPtr aConstruction;
408 if (!aContext.get() && anAttr->contextFeature()->results().size() == 1) {
409 aContext = anAttr->contextFeature()->firstResult();
412 aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
413 if(aConstruction.get()) {
414 // Construciotn selected. Check that is is not infinite.
415 if(aConstruction->isInfinite()) {
416 theError = "Error: Infinite constructions is not allowed as base.";
420 GeomShapePtr aContextShape = aContext->shape();
421 if(aShape->isEqual(aContextShape)) {
422 // Whole construction selected. Check that it have faces.
423 if(aConstruction->facesNum() > 0) {
427 // Shape on construction selected. Check that it is a face or wire.
428 if(aShape->shapeType() == GeomAPI_Shape::WIRE ||
429 aShape->shapeType() == GeomAPI_Shape::FACE) {
437 if(aContextShape.get() && !aShape->isEqual(aContextShape)) {
438 // Local selection on body does not allowed.
440 "Error: Selected shape is in the local selection. Only global selection is allowed.";
444 // Check that object is a shape with allowed type.
445 GeomValidators_ShapeType aShapeTypeValidator;
446 if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
447 theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or "
448 "wires on sketch, whole sketch(if it has at least one face), "
449 "and whole objects with shape types: %1";
450 std::string anArgumentString;
451 for(auto anIt = theArguments.cbegin(); anIt != theArguments.cend(); ++anIt) {
452 if (!anArgumentString.empty())
453 anArgumentString += ", ";
454 anArgumentString += *anIt;
456 theError.arg(anArgumentString);
461 theError = "Error: Attribute \"%1\" does not supported by this validator.";
462 theError.arg(anAttributeType);
469 //==================================================================================================
470 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
471 const std::list<std::string>& theArguments,
472 Events_InfoMessage& theError) const
474 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
475 theError = "Error: The attribute with the %1 type is not processed";
476 theError.arg(theAttribute->attributeType());
479 if (theArguments.size() != 2) {
480 theError = "Error: Wrong parameters in XML definition for %1 type";
481 theError.arg(theAttribute->attributeType());
484 // first argument is for the base attribute, second - for skipping feature kind
485 std::list<std::string>::const_iterator anIt = theArguments.begin();
486 std::string aBaseAttributeId = *anIt;
487 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
488 AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
489 if (!aBaseAttribute.get()) {
490 theError = "Wrong parameters in XML definition for %1 type";
491 theError.arg(theAttribute->attributeType());
494 if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
495 // this validator is not necessary anymore
499 std::string aFeatureAttributeKind = *anIt;
500 GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
501 // check whether the selection is on the sketch
502 std::list<std::string> anArguments;
503 anArguments.push_back(aFeatureAttributeKind);
505 bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);
506 bool aPlanarFace = false;
507 // check if selection has Face selected
508 GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
510 anArguments.push_back("face");
511 aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);
513 bool aValid = !aFeatureKind && aPlanarFace;
517 //==================================================================================================
518 bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
519 const std::shared_ptr<ModelAPI_Feature>& theFeature,
520 const std::list<std::string>& theArguments,
521 Events_InfoMessage& theError) const
523 if(theArguments.size() != 2) {
524 theError = "Error: Validator should be used with 2 parameters for extrusion.";
528 std::list<std::string>::const_iterator
529 anArgsIt = theArguments.begin(), aLast = theArguments.end();
531 AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
534 GeomShapePtr aDirShape;
535 AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
537 aDirShape = aSelAttr->value();
538 if(!aDirShape.get()) {
539 ResultPtr aContext = aSelAttr->context();
540 if(!aContext.get()) {
541 FeaturePtr aFeature = aSelAttr->contextFeature();
542 if (aFeature.get() && !aFeature->results().empty()) {
543 aContext = aFeature->firstResult();
548 aDirShape = aContext->shape();
551 if (aDirShape.get() && aDirShape->isCompound()) {
552 GeomAPI_ShapeIterator anIt(aDirShape);
553 aDirShape = anIt.current();
558 if(!aDirShape.get()) {
559 // Check that dir can be empty.
560 if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
561 theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" "
562 "can not be used with default value. Select direction for extrusion.";
563 theError.arg(*anArgsIt);
570 std::shared_ptr<GeomAPI_Edge> aDirEdge(new GeomAPI_Edge(aDirShape));
572 // If faces selected check that direction not parallel with them.
573 AttributeSelectionListPtr aListAttr =
574 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aCheckAttribute);
575 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
576 AttributeSelectionPtr anAttr = aListAttr->value(anIndex);
577 GeomShapePtr aShapeInList = anAttr->value();
578 if(!aShapeInList.get()) {
579 aShapeInList = anAttr->context()->shape();
581 bool isParallel = true;
582 if(aShapeInList->shapeType() == GeomAPI_Shape::FACE ||
583 aShapeInList->shapeType() == GeomAPI_Shape::SHELL) {
584 for(GeomAPI_ShapeExplorer
585 anExp(aShapeInList, GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
586 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(anExp.current()));
587 isParallel = GeomAlgoAPI_ShapeTools::isParallel(aDirEdge, aFace);
592 } else if(aShapeInList->shapeType() == GeomAPI_Shape::COMPOUND) {
593 std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges =
594 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapeInList);
595 if(aPlanarEdges.get()) {
596 std::shared_ptr<GeomAPI_Dir> aSketchDir = aPlanarEdges->norm();
597 if(aDirEdge->isLine()) {
598 std::shared_ptr<GeomAPI_Dir> aDir = aDirEdge->line()->direction();
599 isParallel = fabs(aSketchDir->angle(aDir) - M_PI / 2.0) < 10e-7;
611 "Error: Direction is parallel to one of the selected face or face on selected shell.";
619 //==================================================================================================
620 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
621 Events_InfoMessage& theError) const
623 if(!theAttribute.get()) {
627 std::string anAttributeType = theAttribute->attributeType();
628 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
629 AttributeSelectionListPtr aListAttr =
630 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
631 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
632 // If at least one attribute is invalid, the result is false.
633 if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) {
637 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
639 AttributeSelectionPtr anAttr =
640 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
641 ResultPtr aContext = anAttr->context();
642 if(!aContext.get() && !anAttr->contextFeature().get()) {
646 GeomShapePtr aShape = anAttr->value();
647 if(!aShape.get() && aContext.get()) {
648 GeomShapePtr aContextShape = aContext->shape();
649 aShape = aContextShape;
655 if(aShape->shapeType() == GeomAPI_Shape::VERTEX ||
656 aShape->shapeType() == GeomAPI_Shape::EDGE ||
657 !aShape->isPlanar()) {
667 //==================================================================================================
668 bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
669 const std::list<std::string>& theArguments,
670 Events_InfoMessage& theError) const
672 AttributeSelectionListPtr anAttrSelectionList =
673 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
674 if(!anAttrSelectionList.get()) {
676 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
679 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
680 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theAttribute->owner());
681 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
683 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
684 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
685 if(!anAttrSelection.get()) {
686 theError = "Error: Empty attribute selection.";
689 ResultPtr aContext = anAttrSelection->context();
690 if(!aContext.get()) {
691 FeaturePtr aContFeat = anAttrSelection->contextFeature();
692 if (!aContFeat.get() || !aContFeat->results().size()) {
693 theError = "Error: Empty selection context.";
697 ResultConstructionPtr aResultConstruction =
698 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
699 if(aResultConstruction.get()) {
700 if (anOperationType != FeaturesPlugin_Boolean::BOOL_FILL
701 || theAttribute->id() != FeaturesPlugin_Boolean::TOOL_LIST_ID()) {
702 theError = "Error: Result construction not allowed for selection.";
706 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
707 if(!aShape.get() && aContext.get()) {
708 GeomShapePtr aContextShape = aContext->shape();
709 aShape = aContextShape;
712 theError = "Error: Empty shape.";
715 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
716 theError = "Error: Local selection not allowed.";
720 GeomAPI_Shape::ShapeType aShapeType = aShape->shapeType();
721 std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
722 if(anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE) {
723 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
724 anAllowedTypes.insert(GeomAPI_Shape::FACE);
725 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
726 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
727 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
728 } else if (anOperationType == FeaturesPlugin_Boolean::BOOL_FILL
729 || anOperationType == FeaturesPlugin_Boolean::BOOL_CUT)
731 anAllowedTypes.insert(GeomAPI_Shape::VERTEX);
732 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
733 anAllowedTypes.insert(GeomAPI_Shape::WIRE);
734 anAllowedTypes.insert(GeomAPI_Shape::FACE);
735 anAllowedTypes.insert(GeomAPI_Shape::SHELL);
736 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
737 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
738 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
740 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
741 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
742 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
745 if(anAllowedTypes.find(aShapeType) == anAllowedTypes.end()
746 || (aResultConstruction.get() && aShapeType != GeomAPI_Shape::FACE)) {
747 theError = "Error: Selected shape has the wrong type.";
756 //==================================================================================================
757 bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAttribute,
758 const std::list<std::string>& theArguments,
759 Events_InfoMessage& theError) const
761 AttributeSelectionListPtr anAttrSelectionList =
762 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
763 if(!anAttrSelectionList.get()) {
765 "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
769 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
770 // Check all selected entities are sub-shapes of single solid
771 GeomShapePtr aBaseSolid;
772 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
773 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
774 if(!anAttrSelection.get()) {
775 theError = "Error: Empty attribute selection.";
778 ResultPtr aContext = anAttrSelection->context();
779 if(!aContext.get()) {
780 FeaturePtr aContFeat = anAttrSelection->contextFeature();
781 if (!aContFeat.get() || !aContFeat->results().size() ||
782 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
783 theError = "Error: Empty selection context.";
786 if (aContFeat->results().size() == 1)
787 aContext = aContFeat->firstResult();
789 theError = "Error: Too many shapes selected.";
794 ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext);
795 GeomShapePtr anOwner = aContextOwner.get() ? aContextOwner->shape() : aContext->shape();
798 theError = "Error: wrong feature is selected.";
802 if (anOwner->shapeType() != GeomAPI_Shape::SOLID &&
803 anOwner->shapeType() != GeomAPI_Shape::COMPSOLID) {
804 theError = "Error: Not all selected shapes are sub-shapes of solids.";
809 aBaseSolid = anOwner;
810 else if (!aBaseSolid->isEqual(anOwner)) {
811 theError = "Error: Sub-shapes of different solids have been selected.";
819 //==================================================================================================
820 bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,
821 const std::list<std::string>& theArguments,
822 Events_InfoMessage& theError) const
824 AttributeSelectionListPtr anAttrSelectionList =
825 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
826 if(!anAttrSelectionList.get()) {
827 theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
831 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
832 AttributeSelectionPtr aSelectAttr = anAttrSelectionList->value(anIndex);
834 //GeomValidators_BodyShapes aBodyValidator;
835 //if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
839 GeomValidators_FeatureKind aFeatureKindValidator;
840 if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
844 ResultPtr aContext = aSelectAttr->context();
845 ResultConstructionPtr aResultConstruction =
846 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
847 if(aResultConstruction.get()) {
848 theError = "Error: Only body shapes and construction planes are allowed for selection.";
852 ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
853 if(aResultBody.get()) {
856 FeaturePtr aResultFeature = aSelectAttr->contextFeature();
857 if(aResultFeature.get()) {
859 std::list<ResultPtr>::const_iterator aFRes = aResultFeature->results().cbegin();
860 for(; aFRes != aResultFeature->results().cend() && !aOkRes; aFRes++) {
861 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aFRes);
862 if (aBody.get() && !aBody->isDisabled())
869 theError = "Error: Only body shapes and construction planes are allowed for selection.";
877 //==================================================================================================
878 bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
879 const std::list<std::string>& theArguments,
880 Events_InfoMessage& theError) const
882 AttributeSelectionListPtr aSubShapesAttrList =
883 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
884 if(!aSubShapesAttrList.get()) {
886 "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
890 static const std::string aBaseShapeID = "base_shape";
891 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
892 AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
894 if(!aShapeAttrSelection.get()) {
895 theError = "Error: Could not get \"%1\" attribute.";
896 theError.arg(aBaseShapeID);
900 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
901 ResultPtr aContext = aShapeAttrSelection->context();
902 if(!aContext.get()) {
903 theError = "Error: Empty context.";
906 if(!aBaseShape.get()) {
907 aBaseShape = aContext->shape();
909 if(!aBaseShape.get()) {
910 theError = "Error: Empty base shape.";
914 std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
915 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
916 bool isSameFound = false;
917 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
918 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
919 for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt)
921 if ((*anIt)->isEqual(aShapeToAdd)) {
927 theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
935 //==================================================================================================
936 bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
937 const std::shared_ptr<ModelAPI_Feature>& theFeature,
938 const std::list<std::string>& theArguments,
939 Events_InfoMessage& theError) const
941 static const std::string aBaseShapeID = "base_shape";
942 static const std::string aSubShapesID = "subshapes_to_keep";
944 if(theFeature->getKind() != "Remove_SubShapes") {
945 theError = "Error: Feature \"%1\" does not supported by this validator.";
946 theError.arg(theFeature->getKind());
950 AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
951 if(!aShapeAttrSelection.get()) {
952 theError = "Error: Could not get \"%1\" attribute.";
953 theError.arg(aBaseShapeID);
957 AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
958 if(!aSubShapesAttrList.get()) {
959 theError = "Error: Could not get \"%1\" attribute.";
960 theError.arg(aSubShapesID);
965 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
966 if(!aBaseShape.get()) {
967 theError = "Error: Base shape is empty.";
970 GeomShapePtr aResultShape = aBaseShape->emptyCopied();
972 if (aSubShapesAttrList->size() == 0) {
973 theError = "Error: Resulting shape is not valid.";
977 // Copy sub-shapes from list to new shape.
978 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
979 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
980 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
981 GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
985 if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {
986 theError = "Error: Resulting shape is not valid.";
993 //==================================================================================================
994 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
995 const std::list<std::string>& theArguments,
996 Events_InfoMessage& theError) const
998 AttributeSelectionListPtr aBaseObjectsAttrList =
999 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1000 if(!aBaseObjectsAttrList.get()) {
1001 theError = "Error: This validator can only work with selection list in \"%1\" feature.";
1002 theError.arg(FeaturesPlugin_Union::ID());
1006 for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
1007 bool isSameFound = false;
1008 AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
1009 ResultPtr aContext = anAttrSelectionInList->context();
1010 if (!aContext.get()) {
1011 theError = "Error: selection is invalid.";
1015 ResultConstructionPtr aConstruction =
1016 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1017 if(aConstruction.get()) {
1018 theError = "Error: Result construction not allowed for selection.";
1022 GeomShapePtr aShape = anAttrSelectionInList->value();
1023 GeomShapePtr aContextShape = aContext->shape();
1024 if (aShape.get() && aContextShape.get() && !aContextShape->isEqual(aShape)) {
1025 theError = "Error: Local selection not allowed.";
1029 ResultBodyPtr aResult =
1030 std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
1031 if(!aResult.get()) {
1035 if(aResult->numberOfSubs() > 0) {
1036 theError = "Error: Whole compsolids not allowed for selection.";
1044 //==================================================================================================
1045 bool FeaturesPlugin_ValidatorUnionArguments::isValid(
1046 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1047 const std::list<std::string>& theArguments,
1048 Events_InfoMessage& theError) const
1050 // Check feature kind.
1051 if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
1052 theError = "Error: This validator supports only \"%1\" feature.";
1053 theError.arg(FeaturesPlugin_Union::ID());
1057 // Get base objects attribute list.
1058 AttributeSelectionListPtr aBaseObejctsAttrList =
1059 theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1060 if(!aBaseObejctsAttrList.get()) {
1061 theError = "Error: Could not get \"%1\" attribute.";
1062 theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1067 GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPSOLID;
1068 ListOfShape aBaseShapesList;
1069 for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
1070 AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
1071 GeomShapePtr aShape = anAttrSelectionInList->value();
1072 if (!aShape.get()) {
1075 aBaseShapesList.push_back(aShape);
1076 aType = aShape->shapeType() == GeomAPI_Shape::FACE ? GeomAPI_Shape::SHELL :
1077 GeomAPI_Shape::COMPSOLID;
1080 // Make compound and find connected.
1081 GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
1082 ListOfShape aCombined, aFree;
1083 GeomAlgoAPI_ShapeTools::combineShapes(
1089 if(aFree.size() > 0 || aCombined.size() > 1) {
1090 theError = "Error: Not all shapes have shared topology.";
1097 bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute,
1098 const std::list<std::string>& theArguments,
1099 Events_InfoMessage& theError) const
1101 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1102 theError = "Error: The attribute with the %1 type is not processed";
1103 theError.arg(theAttribute->attributeType());
1107 AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeReference>
1109 ObjectPtr aRefObject = aRefAttribute->value();
1110 if (!aRefObject.get()) {
1111 theError = "Error: Empty feature.";
1115 FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aRefObject);
1116 if (!aRefFeature.get()) {
1117 theError = "Error: Empty feature.";
1120 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
1121 ModelAPI_Tools::getConcealedResults(aRefFeature, aResults);
1123 size_t aConcealedResults = aResults.size();
1124 if (!aConcealedResults && !theArguments.empty()) {
1125 // find if these results are touched by the feature in another attribute
1126 std::list<std::string>::const_iterator anIt = theArguments.begin();
1127 std::string aRecoveredList = *anIt;
1128 if (!aRecoveredList.empty()) {
1129 std::shared_ptr<ModelAPI_AttributeRefList> aParameterList =
1130 theAttribute->owner()->data()->reflist(aRecoveredList);
1131 if (aParameterList.get())
1132 aConcealedResults = aParameterList->size();
1136 if (aConcealedResults == 0)
1137 theError = "Error: No concealed results.";
1139 return theError.empty();
1142 bool FeaturesPlugin_ValidatorCircular::isValid(const AttributePtr& theAttribute,
1143 const std::list<std::string>& theArguments,
1144 Events_InfoMessage& theError) const
1146 static std::list<std::string> aEdgeArg(1, "circle");
1147 static std::list<std::string> aFaceArg(1, "cylinder");
1149 Events_InfoMessage aError;
1150 bool isValid = GeomValidators_ShapeType().isValid(theAttribute, aEdgeArg, aError);
1152 isValid = GeomValidators_Face().isValid(theAttribute, aFaceArg, aError);
1154 theError = "The shape neither circle nor cylinder";
1159 //=================================================================================================
1160 bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
1161 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1162 const std::list<std::string>& theArguments,
1163 Events_InfoMessage& theError) const
1165 if (theArguments.size() != 2)
1167 theError = "Wrong number of arguments (expected 2).";
1171 int anObjectsNb = 0, aToolsNb = 0;
1172 //int anOperationType = 0;
1174 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1176 bool isAllInSameCompSolid = true;
1177 ResultBodyPtr aCompSolid;
1179 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1182 anObjectsNb = anAttrSelList->size();
1183 for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex)
1185 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1186 ResultPtr aContext = anAttr->context();
1187 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1188 if (aResCompSolidPtr.get())
1190 if (aCompSolid.get())
1192 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1196 aCompSolid = aResCompSolidPtr;
1201 isAllInSameCompSolid = false;
1209 anAttrSelList = theFeature->selectionList(*anIt);
1212 aToolsNb = anAttrSelList->size();
1213 if (isAllInSameCompSolid)
1215 for (int anIndex = 0; anIndex < aToolsNb; ++anIndex)
1217 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1218 ResultPtr aContext = anAttr->context();
1219 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1220 if (aResCompSolidPtr.get())
1222 if (aCompSolid.get())
1224 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1228 aCompSolid = aResCompSolidPtr;
1233 isAllInSameCompSolid = false;
1241 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
1242 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theFeature);
1243 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
1245 if (anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE)
1248 if (anObjectsNb + aToolsNb < 2)
1250 theError = "Not enough arguments for Fuse operation.";
1253 else if (isAllInSameCompSolid)
1255 theError = "Operations only between sub-shapes of the same shape not allowed.";
1261 if (anObjectsNb < 1)
1263 theError = "Objects not selected.";
1268 theError = "Tools not selected.";
1271 if (isAllInSameCompSolid)
1273 theError = "Operations only between sub-shapes of the same shape not allowed.";
1281 //=================================================================================================
1282 bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFeature,
1283 std::string theAttribute)
1285 if (theAttribute == "main_objects" || theAttribute == "tool_objects")
1293 //==================================================================================================
1294 bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
1295 const AttributePtr& theAttribute,
1296 const std::list<std::string>& theArguments,
1297 Events_InfoMessage& theError) const
1299 std::shared_ptr<FeaturesPlugin_BooleanSmash> aFeature =
1300 std::dynamic_pointer_cast<FeaturesPlugin_BooleanSmash>(theAttribute->owner());
1302 AttributeSelectionListPtr anAttrSelectionList =
1303 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1304 if (!aFeature.get() || !anAttrSelectionList.get()) {
1306 "Error: Validator used in wrong feature or attribute";
1310 AttributeSelectionListPtr anOtherAttrSelectionList;
1311 if (theAttribute->id() == FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID()) {
1312 anOtherAttrSelectionList =
1313 aFeature->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
1315 anOtherAttrSelectionList =
1316 aFeature->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
1319 GeomAPI_Shape::ShapeType aSelectedShapesType = GeomAPI_Shape::SHAPE;
1320 GeomAPI_DataMapOfShapeShape aSelectedCompSolidsInOtherList;
1321 GeomPlanePtr aFacesPln;
1323 for (int anIndex = 0; anIndex < anOtherAttrSelectionList->size(); ++anIndex) {
1324 AttributeSelectionPtr anAttrSelection = anOtherAttrSelectionList->value(anIndex);
1326 if (anAttrSelection->contextFeature().get()) {
1327 theError = "Error: Features not allowed for selection.";
1331 ResultPtr aContext = anAttrSelection->context();
1332 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1333 GeomShapePtr aContextShape = aContext->shape();
1334 if (!aShape.get()) {
1335 aShape = aContextShape;
1338 if (aShape->isSolid() || aShape->isCompSolid()) {
1339 aSelectedShapesType = GeomAPI_Shape::SOLID;
1340 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1341 if (aResCompSolidPtr.get()) {
1342 GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
1343 aSelectedCompSolidsInOtherList.bind(aCompSolidShape, aCompSolidShape);
1346 aSelectedShapesType = GeomAPI_Shape::FACE;
1347 GeomAPI_Face aFace(aShape);
1348 aFacesPln = aFace.getPlane();
1353 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1354 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1355 if (!anAttrSelection.get()) {
1356 theError = "Error: Empty attribute selection.";
1360 if (anAttrSelection->contextFeature().get()) {
1361 theError = "Error: Features not allowed for selection.";
1365 ResultPtr aContext = anAttrSelection->context();
1366 if(!aContext.get()) {
1367 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1368 if (!aContFeat.get() || !aContFeat->results().size() ||
1369 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1370 theError = "Error: Empty selection context.";
1374 ResultConstructionPtr aResultConstruction =
1375 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1376 if (aResultConstruction.get()) {
1377 theError = "Error: Result construction not allowed for selection.";
1380 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1381 GeomShapePtr aContextShape = aContext->shape();
1382 if (!aShape.get()) {
1383 aShape = aContextShape;
1385 if (!aShape.get()) {
1386 theError = "Error: Empty shape.";
1389 if (!aShape->isEqual(aContextShape)) {
1390 theError = "Error: Local selection not allowed.";
1394 if (aSelectedShapesType == GeomAPI_Shape::SHAPE) {
1395 // Other list is empty.
1396 if (aShape->isSolid() || aShape->isCompSolid()) {
1397 aSelectedShapesType = GeomAPI_Shape::SOLID;
1399 aSelectedShapesType = GeomAPI_Shape::FACE;
1400 GeomAPI_Face aFace(aShape);
1401 aFacesPln = aFace.getPlane();
1403 if (!aFacesPln.get()) {
1404 theError = "Error: Only planar faces allowed.";
1410 } else if (aSelectedShapesType == GeomAPI_Shape::SOLID) {
1411 if (!aShape->isSolid() && !aShape->isCompSolid()) {
1412 theError = "Error: Selected shapes should have the same type.";
1416 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1417 if (aResCompSolidPtr.get()) {
1418 GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
1419 if (aSelectedCompSolidsInOtherList.isBound(aCompSolidShape)) {
1420 theError = "Error: Solids from compsolid in other list not allowed.";
1425 GeomAPI_Face aFace(aShape);
1426 GeomPlanePtr aPln = aFace.getPlane();
1429 theError = "Error: Only planar faces allowed.";
1433 if (!aFacesPln->isCoincident(aPln)) {
1434 theError = "Error: Only coincident faces allowed.";
1443 //==================================================================================================
1444 bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
1445 const std::list<std::string>& theArguments,
1446 Events_InfoMessage& theError) const
1448 if (!theAttribute.get()) {
1449 theError = "Error: empty selection.";
1452 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
1453 AttributeSelectionListPtr anAttrSelectionList =
1454 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1455 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1456 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1457 if (!anAttrSelection.get()) {
1458 theError = "Error: empty attribute selection.";
1461 ResultPtr aContext = anAttrSelection->context();
1462 if(!aContext.get()) {
1463 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1464 if (!aContFeat.get() || !aContFeat->results().size() ||
1465 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1466 theError = "Error: Empty selection context.";
1470 FeaturePtr aFeature = anAttrSelection->contextFeature().get() ?
1471 anAttrSelection->contextFeature() : ModelAPI_Feature::feature(aContext);
1472 if (!aFeature.get()) {
1473 theError = "Error: empty feature.";
1476 std::string aFeatureKind = aFeature->getKind();
1477 if (aFeatureKind == "Sketch" ||
1478 aFeatureKind == "Plane" ||
1479 aFeatureKind == "Axis") {
1480 theError = "Error: %1 shape is not allowed for selection.";
1481 theError.arg(aFeatureKind);
1484 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1485 if (!aShape.get()) {
1486 GeomShapePtr aContextShape = aContext->shape();
1487 aShape = aContextShape;
1489 if (!aShape.get()) {
1490 theError = "Error: empty shape.";
1493 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1494 theError = "Error: Local selection not allowed.";
1498 int aShapeType = aShape->shapeType();
1499 // Allow to select edges, faces and solids.
1500 if (aShapeType != GeomAPI_Shape::EDGE &&
1501 aShapeType != GeomAPI_Shape::FACE &&
1502 aShapeType != GeomAPI_Shape::SOLID &&
1503 aShapeType != GeomAPI_Shape::COMPSOLID &&
1504 aShapeType != GeomAPI_Shape::COMPOUND) {
1505 theError = "Error: selected shape has the wrong type.";
1513 //==================================================================================================
1514 bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid(
1515 const AttributePtr& theAttribute,
1516 const std::list<std::string>& theArguments,
1517 Events_InfoMessage& theError) const
1519 AttributeSelectionListPtr anAttrSelectionList =
1520 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1521 if (!anAttrSelectionList.get()) {
1523 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1527 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1528 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1529 if (!anAttrSelection.get()) {
1530 theError = "Error: Empty attribute selection.";
1533 ResultPtr aContext = anAttrSelection->context();
1534 if(!aContext.get()) {
1535 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1536 if (!aContFeat.get() || !aContFeat->results().size() ||
1537 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1538 theError = "Error: Empty selection context.";
1542 ResultConstructionPtr aResultConstruction =
1543 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1544 if (aResultConstruction.get()) {
1545 theError = "Error: Result construction not allowed for selection.";
1548 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1549 if (!aShape.get()) {
1550 GeomShapePtr aContextShape = aContext->shape();
1551 aShape = aContextShape;
1553 if (!aShape.get()) {
1554 theError = "Error: Empty shape.";
1557 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1558 theError = "Error: Local selection not allowed.";
1566 //=================================================================================================
1567 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
1568 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1569 const std::list<std::string>& theArguments,
1570 Events_InfoMessage& theError) const
1572 if (theArguments.size() != 2) {
1573 theError = "Wrong number of arguments (expected 2).";
1577 std::shared_ptr<FeaturesPlugin_BooleanFuse> aFeature =
1578 std::dynamic_pointer_cast<FeaturesPlugin_BooleanFuse>(theFeature);
1580 int anObjectsNb = 0, aToolsNb = 0;
1582 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1584 bool isAllInSameCompSolid = true;
1585 ResultBodyPtr aCompSolid;
1587 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1588 if (anAttrSelList) {
1589 anObjectsNb = anAttrSelList->size();
1590 for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
1591 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1592 ResultPtr aContext = anAttr->context();
1593 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1594 if (aResCompSolidPtr.get()) {
1595 if (aCompSolid.get()) {
1596 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1598 aCompSolid = aResCompSolidPtr;
1601 isAllInSameCompSolid = false;
1608 if (aFeature->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD())->value()
1609 == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
1610 anAttrSelList = theFeature->selectionList(*anIt);
1611 if (anAttrSelList) {
1612 aToolsNb = anAttrSelList->size();
1613 if (isAllInSameCompSolid) {
1614 for (int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
1615 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1616 ResultPtr aContext = anAttr->context();
1617 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1618 if (aResCompSolidPtr.get()) {
1619 if (aCompSolid.get()) {
1620 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1622 aCompSolid = aResCompSolidPtr;
1625 isAllInSameCompSolid = false;
1635 if (anObjectsNb + aToolsNb < 2) {
1636 theError = "Not enough arguments for Fuse operation.";
1638 } else if (isAllInSameCompSolid) {
1639 theError = "Operations only between sub-shapes of the same shape not allowed.";
1646 //=================================================================================================
1647 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory(
1648 std::string theFeature,
1649 std::string theAttribute)
1651 if (theAttribute == "main_objects" || theAttribute == "tool_objects") {
1658 //==================================================================================================
1659 bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
1660 const AttributePtr& theAttribute,
1661 const std::list<std::string>& theArguments,
1662 Events_InfoMessage& theError) const
1664 AttributeSelectionListPtr anAttrSelectionList =
1665 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1666 if (!anAttrSelectionList.get()) {
1668 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1672 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1673 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1674 if (!anAttrSelection.get()) {
1675 theError = "Error: Empty attribute selection.";
1678 ResultPtr aContext = anAttrSelection->context();
1679 if (!aContext.get() && !anAttrSelection->contextFeature().get()) {
1680 theError = "Error: Empty selection context.";
1683 ResultConstructionPtr aResultConstruction =
1684 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1685 if (aResultConstruction.get()) {
1686 if (theAttribute->id() != FeaturesPlugin_BooleanCommon::TOOL_LIST_ID()) {
1687 theError = "Error: Result construction not allowed for selection.";
1691 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1692 GeomShapePtr aContextShape;
1693 if (aContext.get()) {
1694 aContextShape = aContext->shape();
1696 if (!aShape.get()) {
1697 aShape = aContextShape;
1699 if (!aShape.get()) {
1700 theError = "Error: Empty shape.";
1703 if (aContextShape.get() && !aShape->isEqual(aContextShape)) {
1704 theError = "Error: Local selection not allowed.";
1708 if (aResultConstruction.get() && aShape->shapeType() != GeomAPI_Shape::FACE) {
1709 theError = "Error: Result construction should be plane.";
1717 //=================================================================================================
1718 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
1719 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1720 const std::list<std::string>& theArguments,
1721 Events_InfoMessage& theError) const
1723 if (theArguments.size() != 2) {
1724 theError = "Wrong number of arguments (expected 2).";
1728 std::shared_ptr<FeaturesPlugin_BooleanCommon> aFeature =
1729 std::dynamic_pointer_cast<FeaturesPlugin_BooleanCommon>(theFeature);
1731 int anObjectsNb = 0, aToolsNb = 0;
1733 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1735 bool isAllInSameCompSolid = true;
1736 ResultBodyPtr aCompSolid;
1738 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1739 if (anAttrSelList) {
1740 anObjectsNb = anAttrSelList->size();
1743 bool isSimpleMode = aFeature->string(FeaturesPlugin_BooleanCommon::CREATION_METHOD())->value()
1744 == FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE();
1746 if (!isSimpleMode) {
1747 anAttrSelList = theFeature->selectionList(*anIt);
1748 if (anAttrSelList) {
1749 aToolsNb = anAttrSelList->size();
1753 if ((isSimpleMode && anObjectsNb < 2)
1754 || (!isSimpleMode && (anObjectsNb == 0 || aToolsNb == 0))) {
1755 theError = "Not enough arguments for Fuse operation.";
1761 //=================================================================================================
1762 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isNotObligatory(
1763 std::string theFeature,
1764 std::string theAttribute)