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 // Construction selected. Check that it 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) {
436 if(aContextShape.get() && !aShape->isEqual(aContextShape)) {
437 // Local selection on body does not allowed.
439 "Error: Selected shape is in the local selection. Only global selection is allowed.";
443 // Check that object is a shape with allowed type.
444 GeomValidators_ShapeType aShapeTypeValidator;
445 if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
446 theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or "
447 "wires on sketch, whole sketch(if it has at least one face), "
448 "and whole objects with shape types: %1";
449 std::string anArgumentString;
450 for(auto anIt = theArguments.cbegin(); anIt != theArguments.cend(); ++anIt) {
451 if (!anArgumentString.empty())
452 anArgumentString += ", ";
453 anArgumentString += *anIt;
455 theError.arg(anArgumentString);
460 theError = "Error: Attribute \"%1\" does not supported by this validator.";
461 theError.arg(anAttributeType);
468 //==================================================================================================
469 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
470 const std::list<std::string>& theArguments,
471 Events_InfoMessage& theError) const
473 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
474 theError = "Error: The attribute with the %1 type is not processed";
475 theError.arg(theAttribute->attributeType());
478 if (theArguments.size() != 2) {
479 theError = "Error: Wrong parameters in XML definition for %1 type";
480 theError.arg(theAttribute->attributeType());
483 // first argument is for the base attribute, second - for skipping feature kind
484 std::list<std::string>::const_iterator anIt = theArguments.begin();
485 std::string aBaseAttributeId = *anIt;
486 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
487 AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
488 if (!aBaseAttribute.get()) {
489 theError = "Wrong parameters in XML definition for %1 type";
490 theError.arg(theAttribute->attributeType());
493 if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
494 // this validator is not necessary anymore
498 std::string aFeatureAttributeKind = *anIt;
499 GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
500 // check whether the selection is on the sketch
501 std::list<std::string> anArguments;
502 anArguments.push_back(aFeatureAttributeKind);
504 bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);
505 bool aPlanarFace = false;
506 // check if selection has Face selected
507 GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
509 anArguments.push_back("face");
510 aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);
512 bool aValid = !aFeatureKind && aPlanarFace;
516 //==================================================================================================
517 bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
518 const std::shared_ptr<ModelAPI_Feature>& theFeature,
519 const std::list<std::string>& theArguments,
520 Events_InfoMessage& theError) const
522 if(theArguments.size() != 2) {
523 theError = "Error: Validator should be used with 2 parameters for extrusion.";
527 std::list<std::string>::const_iterator
528 anArgsIt = theArguments.begin(), aLast = theArguments.end();
530 AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
533 GeomShapePtr aDirShape;
534 AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
536 aDirShape = aSelAttr->value();
537 if(!aDirShape.get()) {
538 ResultPtr aContext = aSelAttr->context();
539 if(!aContext.get()) {
540 FeaturePtr aFeature = aSelAttr->contextFeature();
541 if (aFeature.get() && !aFeature->results().empty()) {
542 aContext = aFeature->firstResult();
547 aDirShape = aContext->shape();
550 if (aDirShape.get() && aDirShape->isCompound()) {
551 GeomAPI_ShapeIterator anIt(aDirShape);
552 aDirShape = anIt.current();
557 if(!aDirShape.get() || aDirShape->isNull() ||
558 aDirShape->shapeType() != GeomAPI_Shape::EDGE) {
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 anObjectsToolsNb[2] = { 0, 0 };
1173 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1175 bool isAllInSameCompSolid = true;
1176 ResultBodyPtr aCompSolid;
1178 for (int* anArgNbIt = anObjectsToolsNb; anIt != aLast; ++anIt, ++anArgNbIt) {
1179 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1182 *anArgNbIt = anAttrSelList->size();
1183 if (isAllInSameCompSolid) {
1184 for (int anIndex = 0; anIndex < *anArgNbIt; ++anIndex)
1186 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1187 ResultPtr aContext = anAttr->context();
1188 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1189 if (aResCompSolidPtr.get())
1191 if (aCompSolid.get())
1193 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1197 aCompSolid = aResCompSolidPtr;
1202 isAllInSameCompSolid = false;
1210 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
1211 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theFeature);
1212 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
1214 if (anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE)
1217 if (anObjectsToolsNb[0] + anObjectsToolsNb[1] < 2)
1219 theError = "Not enough arguments for Fuse operation.";
1222 else if (isAllInSameCompSolid)
1224 theError = "Operations only between sub-shapes of the same shape not allowed.";
1230 if (anObjectsToolsNb[0] < 1) // check number of objects
1232 theError = "Objects not selected.";
1235 if (anObjectsToolsNb[1] < 1) // check number of tools
1237 theError = "Tools not selected.";
1240 if (isAllInSameCompSolid)
1242 theError = "Operations only between sub-shapes of the same shape not allowed.";
1250 //=================================================================================================
1251 bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFeature,
1252 std::string theAttribute)
1254 if (theAttribute == "main_objects" || theAttribute == "tool_objects")
1262 //==================================================================================================
1263 bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
1264 const AttributePtr& theAttribute,
1265 const std::list<std::string>& theArguments,
1266 Events_InfoMessage& theError) const
1268 std::shared_ptr<FeaturesPlugin_BooleanSmash> aFeature =
1269 std::dynamic_pointer_cast<FeaturesPlugin_BooleanSmash>(theAttribute->owner());
1271 AttributeSelectionListPtr anAttrSelectionList =
1272 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1273 if (!aFeature.get() || !anAttrSelectionList.get()) {
1275 "Error: Validator used in wrong feature or attribute";
1279 AttributeSelectionListPtr anOtherAttrSelectionList;
1280 if (theAttribute->id() == FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID()) {
1281 anOtherAttrSelectionList =
1282 aFeature->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
1284 anOtherAttrSelectionList =
1285 aFeature->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
1288 GeomAPI_Shape::ShapeType aSelectedShapesType = GeomAPI_Shape::SHAPE;
1289 GeomAPI_DataMapOfShapeShape aSelectedCompSolidsInOtherList;
1290 GeomPlanePtr aFacesPln;
1292 for (int anIndex = 0; anIndex < anOtherAttrSelectionList->size(); ++anIndex) {
1293 AttributeSelectionPtr anAttrSelection = anOtherAttrSelectionList->value(anIndex);
1295 if (anAttrSelection->contextFeature().get()) {
1296 theError = "Error: Features not allowed for selection.";
1300 ResultPtr aContext = anAttrSelection->context();
1301 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1302 GeomShapePtr aContextShape = aContext->shape();
1303 if (!aShape.get()) {
1304 aShape = aContextShape;
1307 if (aShape->isSolid() || aShape->isCompSolid()) {
1308 aSelectedShapesType = GeomAPI_Shape::SOLID;
1309 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1310 if (aResCompSolidPtr.get()) {
1311 GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
1312 aSelectedCompSolidsInOtherList.bind(aCompSolidShape, aCompSolidShape);
1315 aSelectedShapesType = GeomAPI_Shape::FACE;
1316 GeomAPI_Face aFace(aShape);
1317 aFacesPln = aFace.getPlane();
1322 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1323 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1324 if (!anAttrSelection.get()) {
1325 theError = "Error: Empty attribute selection.";
1329 if (anAttrSelection->contextFeature().get()) {
1330 theError = "Error: Features not allowed for selection.";
1334 ResultPtr aContext = anAttrSelection->context();
1335 if(!aContext.get()) {
1336 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1337 if (!aContFeat.get() || !aContFeat->results().size() ||
1338 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1339 theError = "Error: Empty selection context.";
1343 ResultConstructionPtr aResultConstruction =
1344 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1345 if (aResultConstruction.get()) {
1346 theError = "Error: Result construction not allowed for selection.";
1349 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1350 GeomShapePtr aContextShape = aContext->shape();
1351 if (!aShape.get()) {
1352 aShape = aContextShape;
1354 if (!aShape.get()) {
1355 theError = "Error: Empty shape.";
1358 if (!aShape->isEqual(aContextShape)) {
1359 theError = "Error: Local selection not allowed.";
1363 if (aSelectedShapesType == GeomAPI_Shape::SHAPE) {
1364 // Other list is empty.
1365 if (aShape->isSolid() || aShape->isCompSolid()) {
1366 aSelectedShapesType = GeomAPI_Shape::SOLID;
1368 aSelectedShapesType = GeomAPI_Shape::FACE;
1369 GeomAPI_Face aFace(aShape);
1370 aFacesPln = aFace.getPlane();
1372 if (!aFacesPln.get()) {
1373 theError = "Error: Only planar faces allowed.";
1379 } else if (aSelectedShapesType == GeomAPI_Shape::SOLID) {
1380 if (!aShape->isSolid() && !aShape->isCompSolid()) {
1381 theError = "Error: Selected shapes should have the same type.";
1385 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1386 if (aResCompSolidPtr.get()) {
1387 GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
1388 if (aSelectedCompSolidsInOtherList.isBound(aCompSolidShape)) {
1389 theError = "Error: Solids from compsolid in other list not allowed.";
1394 GeomAPI_Face aFace(aShape);
1395 GeomPlanePtr aPln = aFace.getPlane();
1398 theError = "Error: Only planar faces allowed.";
1402 if (!aFacesPln->isCoincident(aPln)) {
1403 theError = "Error: Only coincident faces allowed.";
1412 //==================================================================================================
1413 bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
1414 const std::list<std::string>& theArguments,
1415 Events_InfoMessage& theError) const
1417 if (!theAttribute.get()) {
1418 theError = "Error: empty selection.";
1421 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
1422 AttributeSelectionListPtr anAttrSelectionList =
1423 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1424 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1425 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1426 if (!anAttrSelection.get()) {
1427 theError = "Error: empty attribute selection.";
1430 ResultPtr aContext = anAttrSelection->context();
1431 if(!aContext.get()) {
1432 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1433 if (!aContFeat.get() || !aContFeat->results().size() ||
1434 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1435 theError = "Error: Empty selection context.";
1439 FeaturePtr aFeature = anAttrSelection->contextFeature().get() ?
1440 anAttrSelection->contextFeature() : ModelAPI_Feature::feature(aContext);
1441 if (!aFeature.get()) {
1442 theError = "Error: empty feature.";
1445 std::string aFeatureKind = aFeature->getKind();
1446 if (aFeatureKind == "Sketch" ||
1447 aFeatureKind == "Plane" ||
1448 aFeatureKind == "Axis") {
1449 theError = "Error: %1 shape is not allowed for selection.";
1450 theError.arg(aFeatureKind);
1453 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1454 if (!aShape.get()) {
1455 GeomShapePtr aContextShape = aContext->shape();
1456 aShape = aContextShape;
1458 if (!aShape.get()) {
1459 theError = "Error: empty shape.";
1462 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1463 theError = "Error: Local selection not allowed.";
1467 int aShapeType = aShape->shapeType();
1468 // Allow to select edges, faces and solids.
1469 if (aShapeType != GeomAPI_Shape::EDGE &&
1470 aShapeType != GeomAPI_Shape::FACE &&
1471 aShapeType != GeomAPI_Shape::SOLID &&
1472 aShapeType != GeomAPI_Shape::COMPSOLID &&
1473 aShapeType != GeomAPI_Shape::COMPOUND) {
1474 theError = "Error: selected shape has the wrong type.";
1482 //==================================================================================================
1483 bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid(
1484 const AttributePtr& theAttribute,
1485 const std::list<std::string>& theArguments,
1486 Events_InfoMessage& theError) const
1488 AttributeSelectionListPtr anAttrSelectionList =
1489 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1490 if (!anAttrSelectionList.get()) {
1492 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1496 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1497 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1498 if (!anAttrSelection.get()) {
1499 theError = "Error: Empty attribute selection.";
1502 ResultPtr aContext = anAttrSelection->context();
1503 if(!aContext.get()) {
1504 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1505 if (!aContFeat.get() || !aContFeat->results().size() ||
1506 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1507 theError = "Error: Empty selection context.";
1511 ResultConstructionPtr aResultConstruction =
1512 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1513 if (aResultConstruction.get()) {
1514 theError = "Error: Result construction not allowed for selection.";
1517 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1518 if (!aShape.get()) {
1519 GeomShapePtr aContextShape = aContext->shape();
1520 aShape = aContextShape;
1522 if (!aShape.get()) {
1523 theError = "Error: Empty shape.";
1526 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1527 theError = "Error: Local selection not allowed.";
1535 //=================================================================================================
1536 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
1537 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1538 const std::list<std::string>& theArguments,
1539 Events_InfoMessage& theError) const
1541 if (theArguments.size() != 2) {
1542 theError = "Wrong number of arguments (expected 2).";
1546 std::shared_ptr<FeaturesPlugin_BooleanFuse> aFeature =
1547 std::dynamic_pointer_cast<FeaturesPlugin_BooleanFuse>(theFeature);
1549 int anObjectsNb = 0, aToolsNb = 0;
1551 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1553 bool isAllInSameCompSolid = true;
1554 ResultBodyPtr aCompSolid;
1556 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1557 if (anAttrSelList) {
1558 anObjectsNb = anAttrSelList->size();
1559 for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
1560 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1561 ResultPtr aContext = anAttr->context();
1562 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1563 if (aResCompSolidPtr.get()) {
1564 if (aCompSolid.get()) {
1565 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1567 aCompSolid = aResCompSolidPtr;
1570 isAllInSameCompSolid = false;
1577 if (aFeature->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD())->value()
1578 == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
1579 anAttrSelList = theFeature->selectionList(*anIt);
1580 if (anAttrSelList) {
1581 aToolsNb = anAttrSelList->size();
1582 if (isAllInSameCompSolid) {
1583 for (int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
1584 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1585 ResultPtr aContext = anAttr->context();
1586 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1587 if (aResCompSolidPtr.get()) {
1588 if (aCompSolid.get()) {
1589 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1591 aCompSolid = aResCompSolidPtr;
1594 isAllInSameCompSolid = false;
1604 if (anObjectsNb + aToolsNb < 2) {
1605 theError = "Not enough arguments for Fuse operation.";
1607 } else if (isAllInSameCompSolid) {
1608 theError = "Operations only between sub-shapes of the same shape not allowed.";
1615 //=================================================================================================
1616 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory(
1617 std::string theFeature,
1618 std::string theAttribute)
1620 if (theAttribute == "main_objects" || theAttribute == "tool_objects") {
1627 //==================================================================================================
1628 bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
1629 const AttributePtr& theAttribute,
1630 const std::list<std::string>& theArguments,
1631 Events_InfoMessage& theError) const
1633 AttributeSelectionListPtr anAttrSelectionList =
1634 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1635 if (!anAttrSelectionList.get()) {
1637 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1641 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1642 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1643 if (!anAttrSelection.get()) {
1644 theError = "Error: Empty attribute selection.";
1647 ResultPtr aContext = anAttrSelection->context();
1648 if (!aContext.get() && !anAttrSelection->contextFeature().get()) {
1649 theError = "Error: Empty selection context.";
1652 ResultConstructionPtr aResultConstruction =
1653 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1654 if (aResultConstruction.get()) {
1655 if (theAttribute->id() != FeaturesPlugin_BooleanCommon::TOOL_LIST_ID()) {
1656 theError = "Error: Result construction not allowed for selection.";
1660 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1661 GeomShapePtr aContextShape;
1662 if (aContext.get()) {
1663 aContextShape = aContext->shape();
1665 if (!aShape.get()) {
1666 aShape = aContextShape;
1668 if (!aShape.get()) {
1669 theError = "Error: Empty shape.";
1672 if (aContextShape.get() && !aShape->isEqual(aContextShape)) {
1673 theError = "Error: Local selection not allowed.";
1677 if (aResultConstruction.get() && aShape->shapeType() != GeomAPI_Shape::FACE) {
1678 theError = "Error: Result construction should be plane.";
1686 //=================================================================================================
1687 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
1688 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1689 const std::list<std::string>& theArguments,
1690 Events_InfoMessage& theError) const
1692 if (theArguments.size() != 2) {
1693 theError = "Wrong number of arguments (expected 2).";
1697 std::shared_ptr<FeaturesPlugin_BooleanCommon> aFeature =
1698 std::dynamic_pointer_cast<FeaturesPlugin_BooleanCommon>(theFeature);
1700 int anObjectsNb = 0, aToolsNb = 0;
1702 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1704 bool isAllInSameCompSolid = true;
1705 ResultBodyPtr aCompSolid;
1707 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1708 if (anAttrSelList) {
1709 anObjectsNb = anAttrSelList->size();
1712 bool isSimpleMode = aFeature->string(FeaturesPlugin_BooleanCommon::CREATION_METHOD())->value()
1713 == FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE();
1715 if (!isSimpleMode) {
1716 anAttrSelList = theFeature->selectionList(*anIt);
1717 if (anAttrSelList) {
1718 aToolsNb = anAttrSelList->size();
1722 if ((isSimpleMode && anObjectsNb < 2)
1723 || (!isSimpleMode && (anObjectsNb == 0 || aToolsNb == 0))) {
1724 theError = "Not enough arguments for Fuse operation.";
1730 //=================================================================================================
1731 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isNotObligatory(
1732 std::string theFeature,
1733 std::string theAttribute)