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();
553 if(!aDirShape.get()) {
554 // Check that dir can be empty.
555 if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
556 theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" "
557 "can not be used with default value. Select direction for extrusion.";
558 theError.arg(*anArgsIt);
565 std::shared_ptr<GeomAPI_Edge> aDirEdge(new GeomAPI_Edge(aDirShape));
567 // If faces selected check that direction not parallel with them.
568 AttributeSelectionListPtr aListAttr =
569 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aCheckAttribute);
570 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
571 AttributeSelectionPtr anAttr = aListAttr->value(anIndex);
572 GeomShapePtr aShapeInList = anAttr->value();
573 if(!aShapeInList.get()) {
574 aShapeInList = anAttr->context()->shape();
576 bool isParallel = true;
577 if(aShapeInList->shapeType() == GeomAPI_Shape::FACE ||
578 aShapeInList->shapeType() == GeomAPI_Shape::SHELL) {
579 for(GeomAPI_ShapeExplorer
580 anExp(aShapeInList, GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
581 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(anExp.current()));
582 isParallel = GeomAlgoAPI_ShapeTools::isParallel(aDirEdge, aFace);
587 } else if(aShapeInList->shapeType() == GeomAPI_Shape::COMPOUND) {
588 std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges =
589 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapeInList);
590 if(aPlanarEdges.get()) {
591 std::shared_ptr<GeomAPI_Dir> aSketchDir = aPlanarEdges->norm();
592 if(aDirEdge->isLine()) {
593 std::shared_ptr<GeomAPI_Dir> aDir = aDirEdge->line()->direction();
594 isParallel = fabs(aSketchDir->angle(aDir) - M_PI / 2.0) < 10e-7;
606 "Error: Direction is parallel to one of the selected face or face on selected shell.";
614 //==================================================================================================
615 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
616 Events_InfoMessage& theError) const
618 if(!theAttribute.get()) {
622 std::string anAttributeType = theAttribute->attributeType();
623 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
624 AttributeSelectionListPtr aListAttr =
625 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
626 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
627 // If at least one attribute is invalid, the result is false.
628 if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) {
632 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
634 AttributeSelectionPtr anAttr =
635 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
636 ResultPtr aContext = anAttr->context();
637 if(!aContext.get() && !anAttr->contextFeature().get()) {
641 GeomShapePtr aShape = anAttr->value();
642 if(!aShape.get() && aContext.get()) {
643 GeomShapePtr aContextShape = aContext->shape();
644 aShape = aContextShape;
650 if(aShape->shapeType() == GeomAPI_Shape::VERTEX ||
651 aShape->shapeType() == GeomAPI_Shape::EDGE ||
652 !aShape->isPlanar()) {
662 //==================================================================================================
663 bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
664 const std::list<std::string>& theArguments,
665 Events_InfoMessage& theError) const
667 AttributeSelectionListPtr anAttrSelectionList =
668 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
669 if(!anAttrSelectionList.get()) {
671 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
674 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
675 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theAttribute->owner());
676 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
678 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
679 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
680 if(!anAttrSelection.get()) {
681 theError = "Error: Empty attribute selection.";
684 ResultPtr aContext = anAttrSelection->context();
685 if(!aContext.get()) {
686 FeaturePtr aContFeat = anAttrSelection->contextFeature();
687 if (!aContFeat.get() || !aContFeat->results().size()) {
688 theError = "Error: Empty selection context.";
692 ResultConstructionPtr aResultConstruction =
693 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
694 if(aResultConstruction.get()) {
695 if (anOperationType != FeaturesPlugin_Boolean::BOOL_FILL
696 || theAttribute->id() != FeaturesPlugin_Boolean::TOOL_LIST_ID()) {
697 theError = "Error: Result construction not allowed for selection.";
701 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
702 if(!aShape.get() && aContext.get()) {
703 GeomShapePtr aContextShape = aContext->shape();
704 aShape = aContextShape;
707 theError = "Error: Empty shape.";
710 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
711 theError = "Error: Local selection not allowed.";
715 GeomAPI_Shape::ShapeType aShapeType = aShape->shapeType();
716 std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
717 if(anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE) {
718 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
719 anAllowedTypes.insert(GeomAPI_Shape::FACE);
720 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
721 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
722 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
723 } else if (anOperationType == FeaturesPlugin_Boolean::BOOL_FILL
724 || anOperationType == FeaturesPlugin_Boolean::BOOL_CUT)
726 anAllowedTypes.insert(GeomAPI_Shape::VERTEX);
727 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
728 anAllowedTypes.insert(GeomAPI_Shape::WIRE);
729 anAllowedTypes.insert(GeomAPI_Shape::FACE);
730 anAllowedTypes.insert(GeomAPI_Shape::SHELL);
731 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
732 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
733 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
735 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
736 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
737 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
740 if(anAllowedTypes.find(aShapeType) == anAllowedTypes.end()
741 || (aResultConstruction.get() && aShapeType != GeomAPI_Shape::FACE)) {
742 theError = "Error: Selected shape has the wrong type.";
751 //==================================================================================================
752 bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAttribute,
753 const std::list<std::string>& theArguments,
754 Events_InfoMessage& theError) const
756 AttributeSelectionListPtr anAttrSelectionList =
757 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
758 if(!anAttrSelectionList.get()) {
760 "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
764 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
765 // Check all selected entities are sub-shapes of single solid
766 GeomShapePtr aBaseSolid;
767 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
768 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
769 if(!anAttrSelection.get()) {
770 theError = "Error: Empty attribute selection.";
773 ResultPtr aContext = anAttrSelection->context();
774 if(!aContext.get()) {
775 FeaturePtr aContFeat = anAttrSelection->contextFeature();
776 if (!aContFeat.get() || !aContFeat->results().size() ||
777 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
778 theError = "Error: Empty selection context.";
781 if (aContFeat->results().size() == 1)
782 aContext = aContFeat->firstResult();
784 theError = "Error: Too many shapes selected.";
789 ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext);
790 GeomShapePtr anOwner = aContextOwner.get() ? aContextOwner->shape() : aContext->shape();
793 theError = "Error: wrong feature is selected.";
797 if (anOwner->shapeType() != GeomAPI_Shape::SOLID &&
798 anOwner->shapeType() != GeomAPI_Shape::COMPSOLID) {
799 theError = "Error: Not all selected shapes are sub-shapes of solids.";
804 aBaseSolid = anOwner;
805 else if (!aBaseSolid->isEqual(anOwner)) {
806 theError = "Error: Sub-shapes of different solids have been selected.";
814 //==================================================================================================
815 bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,
816 const std::list<std::string>& theArguments,
817 Events_InfoMessage& theError) const
819 AttributeSelectionListPtr anAttrSelectionList =
820 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
821 if(!anAttrSelectionList.get()) {
822 theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
826 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
827 AttributeSelectionPtr aSelectAttr = anAttrSelectionList->value(anIndex);
829 //GeomValidators_BodyShapes aBodyValidator;
830 //if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
834 GeomValidators_FeatureKind aFeatureKindValidator;
835 if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
839 ResultPtr aContext = aSelectAttr->context();
840 ResultConstructionPtr aResultConstruction =
841 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
842 if(aResultConstruction.get()) {
843 theError = "Error: Only body shapes and construction planes are allowed for selection.";
847 ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
848 if(aResultBody.get()) {
851 FeaturePtr aResultFeature = aSelectAttr->contextFeature();
852 if(aResultFeature.get()) {
854 std::list<ResultPtr>::const_iterator aFRes = aResultFeature->results().cbegin();
855 for(; aFRes != aResultFeature->results().cend() && !aOkRes; aFRes++) {
856 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aFRes);
857 if (aBody.get() && !aBody->isDisabled())
864 theError = "Error: Only body shapes and construction planes are allowed for selection.";
872 //==================================================================================================
873 bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
874 const std::list<std::string>& theArguments,
875 Events_InfoMessage& theError) const
877 AttributeSelectionListPtr aSubShapesAttrList =
878 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
879 if(!aSubShapesAttrList.get()) {
881 "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
885 static const std::string aBaseShapeID = "base_shape";
886 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
887 AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
889 if(!aShapeAttrSelection.get()) {
890 theError = "Error: Could not get \"%1\" attribute.";
891 theError.arg(aBaseShapeID);
895 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
896 ResultPtr aContext = aShapeAttrSelection->context();
897 if(!aContext.get()) {
898 theError = "Error: Empty context.";
901 if(!aBaseShape.get()) {
902 aBaseShape = aContext->shape();
904 if(!aBaseShape.get()) {
905 theError = "Error: Empty base shape.";
909 std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
910 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
911 bool isSameFound = false;
912 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
913 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
914 for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt)
916 if ((*anIt)->isEqual(aShapeToAdd)) {
922 theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
930 //==================================================================================================
931 bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
932 const std::shared_ptr<ModelAPI_Feature>& theFeature,
933 const std::list<std::string>& theArguments,
934 Events_InfoMessage& theError) const
936 static const std::string aBaseShapeID = "base_shape";
937 static const std::string aSubShapesID = "subshapes_to_keep";
939 if(theFeature->getKind() != "Remove_SubShapes") {
940 theError = "Error: Feature \"%1\" does not supported by this validator.";
941 theError.arg(theFeature->getKind());
945 AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
946 if(!aShapeAttrSelection.get()) {
947 theError = "Error: Could not get \"%1\" attribute.";
948 theError.arg(aBaseShapeID);
952 AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
953 if(!aSubShapesAttrList.get()) {
954 theError = "Error: Could not get \"%1\" attribute.";
955 theError.arg(aSubShapesID);
960 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
961 if(!aBaseShape.get()) {
962 theError = "Error: Base shape is empty.";
965 GeomShapePtr aResultShape = aBaseShape->emptyCopied();
967 if (aSubShapesAttrList->size() == 0) {
968 theError = "Error: Resulting shape is not valid.";
972 // Copy sub-shapes from list to new shape.
973 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
974 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
975 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
976 GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
980 if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {
981 theError = "Error: Resulting shape is not valid.";
988 //==================================================================================================
989 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
990 const std::list<std::string>& theArguments,
991 Events_InfoMessage& theError) const
993 AttributeSelectionListPtr aBaseObjectsAttrList =
994 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
995 if(!aBaseObjectsAttrList.get()) {
996 theError = "Error: This validator can only work with selection list in \"%1\" feature.";
997 theError.arg(FeaturesPlugin_Union::ID());
1001 for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
1002 bool isSameFound = false;
1003 AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
1004 ResultPtr aContext = anAttrSelectionInList->context();
1005 if (!aContext.get()) {
1006 theError = "Error: selection is invalid.";
1010 ResultConstructionPtr aConstruction =
1011 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1012 if(aConstruction.get()) {
1013 theError = "Error: Result construction not allowed for selection.";
1017 GeomShapePtr aShape = anAttrSelectionInList->value();
1018 GeomShapePtr aContextShape = aContext->shape();
1019 if (aShape.get() && aContextShape.get() && !aContextShape->isEqual(aShape)) {
1020 theError = "Error: Local selection not allowed.";
1024 ResultBodyPtr aResult =
1025 std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
1026 if(!aResult.get()) {
1030 if(aResult->numberOfSubs() > 0) {
1031 theError = "Error: Whole compsolids not allowed for selection.";
1039 //==================================================================================================
1040 bool FeaturesPlugin_ValidatorUnionArguments::isValid(
1041 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1042 const std::list<std::string>& theArguments,
1043 Events_InfoMessage& theError) const
1045 // Check feature kind.
1046 if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
1047 theError = "Error: This validator supports only \"%1\" feature.";
1048 theError.arg(FeaturesPlugin_Union::ID());
1052 // Get base objects attribute list.
1053 AttributeSelectionListPtr aBaseObejctsAttrList =
1054 theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1055 if(!aBaseObejctsAttrList.get()) {
1056 theError = "Error: Could not get \"%1\" attribute.";
1057 theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1062 GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPSOLID;
1063 ListOfShape aBaseShapesList;
1064 for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
1065 AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
1066 GeomShapePtr aShape = anAttrSelectionInList->value();
1067 if (!aShape.get()) {
1070 aBaseShapesList.push_back(aShape);
1071 aType = aShape->shapeType() == GeomAPI_Shape::FACE ? GeomAPI_Shape::SHELL :
1072 GeomAPI_Shape::COMPSOLID;
1075 // Make compound and find connected.
1076 GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
1077 ListOfShape aCombined, aFree;
1078 GeomAlgoAPI_ShapeTools::combineShapes(
1084 if(aFree.size() > 0 || aCombined.size() > 1) {
1085 theError = "Error: Not all shapes have shared topology.";
1092 bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute,
1093 const std::list<std::string>& theArguments,
1094 Events_InfoMessage& theError) const
1096 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1097 theError = "Error: The attribute with the %1 type is not processed";
1098 theError.arg(theAttribute->attributeType());
1102 AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeReference>
1104 ObjectPtr aRefObject = aRefAttribute->value();
1105 if (!aRefObject.get()) {
1106 theError = "Error: Empty feature.";
1110 FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aRefObject);
1111 if (!aRefFeature.get()) {
1112 theError = "Error: Empty feature.";
1115 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
1116 ModelAPI_Tools::getConcealedResults(aRefFeature, aResults);
1118 size_t aConcealedResults = aResults.size();
1119 if (!aConcealedResults && !theArguments.empty()) {
1120 // find if these results are touched by the feature in another attribute
1121 std::list<std::string>::const_iterator anIt = theArguments.begin();
1122 std::string aRecoveredList = *anIt;
1123 if (!aRecoveredList.empty()) {
1124 std::shared_ptr<ModelAPI_AttributeRefList> aParameterList =
1125 theAttribute->owner()->data()->reflist(aRecoveredList);
1126 if (aParameterList.get())
1127 aConcealedResults = aParameterList->size();
1131 if (aConcealedResults == 0)
1132 theError = "Error: No concealed results.";
1134 return theError.empty();
1137 bool FeaturesPlugin_ValidatorCircular::isValid(const AttributePtr& theAttribute,
1138 const std::list<std::string>& theArguments,
1139 Events_InfoMessage& theError) const
1141 static std::list<std::string> aEdgeArg(1, "circle");
1142 static std::list<std::string> aFaceArg(1, "cylinder");
1144 Events_InfoMessage aError;
1145 bool isValid = GeomValidators_ShapeType().isValid(theAttribute, aEdgeArg, aError);
1147 isValid = GeomValidators_Face().isValid(theAttribute, aFaceArg, aError);
1149 theError = "The shape neither circle nor cylinder";
1154 //=================================================================================================
1155 bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
1156 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1157 const std::list<std::string>& theArguments,
1158 Events_InfoMessage& theError) const
1160 if (theArguments.size() != 2)
1162 theError = "Wrong number of arguments (expected 2).";
1166 int anObjectsNb = 0, aToolsNb = 0;
1167 //int anOperationType = 0;
1169 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1171 bool isAllInSameCompSolid = true;
1172 ResultBodyPtr aCompSolid;
1174 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1177 anObjectsNb = anAttrSelList->size();
1178 for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex)
1180 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1181 ResultPtr aContext = anAttr->context();
1182 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1183 if (aResCompSolidPtr.get())
1185 if (aCompSolid.get())
1187 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1191 aCompSolid = aResCompSolidPtr;
1196 isAllInSameCompSolid = false;
1204 anAttrSelList = theFeature->selectionList(*anIt);
1207 aToolsNb = anAttrSelList->size();
1208 if (isAllInSameCompSolid)
1210 for (int anIndex = 0; anIndex < aToolsNb; ++anIndex)
1212 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1213 ResultPtr aContext = anAttr->context();
1214 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1215 if (aResCompSolidPtr.get())
1217 if (aCompSolid.get())
1219 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1223 aCompSolid = aResCompSolidPtr;
1228 isAllInSameCompSolid = false;
1236 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
1237 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theFeature);
1238 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
1240 if (anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE)
1243 if (anObjectsNb + aToolsNb < 2)
1245 theError = "Not enough arguments for Fuse operation.";
1248 else if (isAllInSameCompSolid)
1250 theError = "Operations only between sub-shapes of the same shape not allowed.";
1256 if (anObjectsNb < 1)
1258 theError = "Objects not selected.";
1263 theError = "Tools not selected.";
1266 if (isAllInSameCompSolid)
1268 theError = "Operations only between sub-shapes of the same shape not allowed.";
1276 //=================================================================================================
1277 bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFeature,
1278 std::string theAttribute)
1280 if (theAttribute == "main_objects" || theAttribute == "tool_objects")
1288 //==================================================================================================
1289 bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
1290 const AttributePtr& theAttribute,
1291 const std::list<std::string>& theArguments,
1292 Events_InfoMessage& theError) const
1294 std::shared_ptr<FeaturesPlugin_BooleanSmash> aFeature =
1295 std::dynamic_pointer_cast<FeaturesPlugin_BooleanSmash>(theAttribute->owner());
1297 AttributeSelectionListPtr anAttrSelectionList =
1298 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1299 if (!aFeature.get() || !anAttrSelectionList.get()) {
1301 "Error: Validator used in wrong feature or attribute";
1305 AttributeSelectionListPtr anOtherAttrSelectionList;
1306 if (theAttribute->id() == FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID()) {
1307 anOtherAttrSelectionList =
1308 aFeature->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
1310 anOtherAttrSelectionList =
1311 aFeature->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
1314 GeomAPI_Shape::ShapeType aSelectedShapesType = GeomAPI_Shape::SHAPE;
1315 GeomAPI_DataMapOfShapeShape aSelectedCompSolidsInOtherList;
1316 GeomPlanePtr aFacesPln;
1318 for (int anIndex = 0; anIndex < anOtherAttrSelectionList->size(); ++anIndex) {
1319 AttributeSelectionPtr anAttrSelection = anOtherAttrSelectionList->value(anIndex);
1321 if (anAttrSelection->contextFeature().get()) {
1322 theError = "Error: Features not allowed for selection.";
1326 ResultPtr aContext = anAttrSelection->context();
1327 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1328 GeomShapePtr aContextShape = aContext->shape();
1329 if (!aShape.get()) {
1330 aShape = aContextShape;
1333 if (aShape->isSolid() || aShape->isCompSolid()) {
1334 aSelectedShapesType = GeomAPI_Shape::SOLID;
1335 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1336 if (aResCompSolidPtr.get()) {
1337 GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
1338 aSelectedCompSolidsInOtherList.bind(aCompSolidShape, aCompSolidShape);
1341 aSelectedShapesType = GeomAPI_Shape::FACE;
1342 GeomAPI_Face aFace(aShape);
1343 aFacesPln = aFace.getPlane();
1348 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1349 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1350 if (!anAttrSelection.get()) {
1351 theError = "Error: Empty attribute selection.";
1355 if (anAttrSelection->contextFeature().get()) {
1356 theError = "Error: Features not allowed for selection.";
1360 ResultPtr aContext = anAttrSelection->context();
1361 if(!aContext.get()) {
1362 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1363 if (!aContFeat.get() || !aContFeat->results().size() ||
1364 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1365 theError = "Error: Empty selection context.";
1369 ResultConstructionPtr aResultConstruction =
1370 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1371 if (aResultConstruction.get()) {
1372 theError = "Error: Result construction not allowed for selection.";
1375 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1376 GeomShapePtr aContextShape = aContext->shape();
1377 if (!aShape.get()) {
1378 aShape = aContextShape;
1380 if (!aShape.get()) {
1381 theError = "Error: Empty shape.";
1384 if (!aShape->isEqual(aContextShape)) {
1385 theError = "Error: Local selection not allowed.";
1389 if (aSelectedShapesType == GeomAPI_Shape::SHAPE) {
1390 // Other list is empty.
1391 if (aShape->isSolid() || aShape->isCompSolid()) {
1392 aSelectedShapesType = GeomAPI_Shape::SOLID;
1394 aSelectedShapesType = GeomAPI_Shape::FACE;
1395 GeomAPI_Face aFace(aShape);
1396 aFacesPln = aFace.getPlane();
1398 if (!aFacesPln.get()) {
1399 theError = "Error: Only planar faces allowed.";
1405 } else if (aSelectedShapesType == GeomAPI_Shape::SOLID) {
1406 if (!aShape->isSolid() && !aShape->isCompSolid()) {
1407 theError = "Error: Selected shapes should have the same type.";
1411 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1412 if (aResCompSolidPtr.get()) {
1413 GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
1414 if (aSelectedCompSolidsInOtherList.isBound(aCompSolidShape)) {
1415 theError = "Error: Solids from compsolid in other list not allowed.";
1420 GeomAPI_Face aFace(aShape);
1421 GeomPlanePtr aPln = aFace.getPlane();
1424 theError = "Error: Only planar faces allowed.";
1428 if (!aFacesPln->isCoincident(aPln)) {
1429 theError = "Error: Only coincident faces allowed.";
1438 //==================================================================================================
1439 bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
1440 const std::list<std::string>& theArguments,
1441 Events_InfoMessage& theError) const
1443 if (!theAttribute.get()) {
1444 theError = "Error: empty selection.";
1447 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
1448 AttributeSelectionListPtr anAttrSelectionList =
1449 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1450 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1451 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1452 if (!anAttrSelection.get()) {
1453 theError = "Error: empty attribute selection.";
1456 ResultPtr aContext = anAttrSelection->context();
1457 if(!aContext.get()) {
1458 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1459 if (!aContFeat.get() || !aContFeat->results().size() ||
1460 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1461 theError = "Error: Empty selection context.";
1465 FeaturePtr aFeature = anAttrSelection->contextFeature().get() ?
1466 anAttrSelection->contextFeature() : ModelAPI_Feature::feature(aContext);
1467 if (!aFeature.get()) {
1468 theError = "Error: empty feature.";
1471 std::string aFeatureKind = aFeature->getKind();
1472 if (aFeatureKind == "Sketch" ||
1473 aFeatureKind == "Plane" ||
1474 aFeatureKind == "Axis") {
1475 theError = "Error: %1 shape is not allowed for selection.";
1476 theError.arg(aFeatureKind);
1479 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1480 if (!aShape.get()) {
1481 GeomShapePtr aContextShape = aContext->shape();
1482 aShape = aContextShape;
1484 if (!aShape.get()) {
1485 theError = "Error: empty shape.";
1488 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1489 theError = "Error: Local selection not allowed.";
1493 int aShapeType = aShape->shapeType();
1494 // Allow to select edges, faces and solids.
1495 if (aShapeType != GeomAPI_Shape::EDGE &&
1496 aShapeType != GeomAPI_Shape::FACE &&
1497 aShapeType != GeomAPI_Shape::SOLID &&
1498 aShapeType != GeomAPI_Shape::COMPSOLID &&
1499 aShapeType != GeomAPI_Shape::COMPOUND) {
1500 theError = "Error: selected shape has the wrong type.";
1508 //==================================================================================================
1509 bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid(
1510 const AttributePtr& theAttribute,
1511 const std::list<std::string>& theArguments,
1512 Events_InfoMessage& theError) const
1514 AttributeSelectionListPtr anAttrSelectionList =
1515 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1516 if (!anAttrSelectionList.get()) {
1518 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1522 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1523 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1524 if (!anAttrSelection.get()) {
1525 theError = "Error: Empty attribute selection.";
1528 ResultPtr aContext = anAttrSelection->context();
1529 if(!aContext.get()) {
1530 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1531 if (!aContFeat.get() || !aContFeat->results().size() ||
1532 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1533 theError = "Error: Empty selection context.";
1537 ResultConstructionPtr aResultConstruction =
1538 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1539 if (aResultConstruction.get()) {
1540 theError = "Error: Result construction not allowed for selection.";
1543 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1544 if (!aShape.get()) {
1545 GeomShapePtr aContextShape = aContext->shape();
1546 aShape = aContextShape;
1548 if (!aShape.get()) {
1549 theError = "Error: Empty shape.";
1552 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1553 theError = "Error: Local selection not allowed.";
1561 //=================================================================================================
1562 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
1563 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1564 const std::list<std::string>& theArguments,
1565 Events_InfoMessage& theError) const
1567 if (theArguments.size() != 2) {
1568 theError = "Wrong number of arguments (expected 2).";
1572 std::shared_ptr<FeaturesPlugin_BooleanFuse> aFeature =
1573 std::dynamic_pointer_cast<FeaturesPlugin_BooleanFuse>(theFeature);
1575 int anObjectsNb = 0, aToolsNb = 0;
1577 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1579 bool isAllInSameCompSolid = true;
1580 ResultBodyPtr aCompSolid;
1582 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1583 if (anAttrSelList) {
1584 anObjectsNb = anAttrSelList->size();
1585 for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
1586 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1587 ResultPtr aContext = anAttr->context();
1588 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1589 if (aResCompSolidPtr.get()) {
1590 if (aCompSolid.get()) {
1591 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1593 aCompSolid = aResCompSolidPtr;
1596 isAllInSameCompSolid = false;
1603 if (aFeature->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD())->value()
1604 == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
1605 anAttrSelList = theFeature->selectionList(*anIt);
1606 if (anAttrSelList) {
1607 aToolsNb = anAttrSelList->size();
1608 if (isAllInSameCompSolid) {
1609 for (int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
1610 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1611 ResultPtr aContext = anAttr->context();
1612 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1613 if (aResCompSolidPtr.get()) {
1614 if (aCompSolid.get()) {
1615 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1617 aCompSolid = aResCompSolidPtr;
1620 isAllInSameCompSolid = false;
1630 if (anObjectsNb + aToolsNb < 2) {
1631 theError = "Not enough arguments for Fuse operation.";
1633 } else if (isAllInSameCompSolid) {
1634 theError = "Operations only between sub-shapes of the same shape not allowed.";
1641 //=================================================================================================
1642 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory(
1643 std::string theFeature,
1644 std::string theAttribute)
1646 if (theAttribute == "main_objects" || theAttribute == "tool_objects") {
1653 //==================================================================================================
1654 bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
1655 const AttributePtr& theAttribute,
1656 const std::list<std::string>& theArguments,
1657 Events_InfoMessage& theError) const
1659 AttributeSelectionListPtr anAttrSelectionList =
1660 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1661 if (!anAttrSelectionList.get()) {
1663 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1667 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1668 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1669 if (!anAttrSelection.get()) {
1670 theError = "Error: Empty attribute selection.";
1673 ResultPtr aContext = anAttrSelection->context();
1674 if (!aContext.get() && !anAttrSelection->contextFeature().get()) {
1675 theError = "Error: Empty selection context.";
1678 ResultConstructionPtr aResultConstruction =
1679 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1680 if (aResultConstruction.get()) {
1681 if (theAttribute->id() != FeaturesPlugin_BooleanCommon::TOOL_LIST_ID()) {
1682 theError = "Error: Result construction not allowed for selection.";
1686 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1687 GeomShapePtr aContextShape;
1688 if (aContext.get()) {
1689 aContextShape = aContext->shape();
1691 if (!aShape.get()) {
1692 aShape = aContextShape;
1694 if (!aShape.get()) {
1695 theError = "Error: Empty shape.";
1698 if (aContextShape.get() && !aShape->isEqual(aContextShape)) {
1699 theError = "Error: Local selection not allowed.";
1703 if (aResultConstruction.get() && aShape->shapeType() != GeomAPI_Shape::FACE) {
1704 theError = "Error: Result construction should be plane.";
1712 //=================================================================================================
1713 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
1714 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1715 const std::list<std::string>& theArguments,
1716 Events_InfoMessage& theError) const
1718 if (theArguments.size() != 2) {
1719 theError = "Wrong number of arguments (expected 2).";
1723 std::shared_ptr<FeaturesPlugin_BooleanCommon> aFeature =
1724 std::dynamic_pointer_cast<FeaturesPlugin_BooleanCommon>(theFeature);
1726 int anObjectsNb = 0, aToolsNb = 0;
1728 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1730 bool isAllInSameCompSolid = true;
1731 ResultBodyPtr aCompSolid;
1733 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1734 if (anAttrSelList) {
1735 anObjectsNb = anAttrSelList->size();
1738 bool isSimpleMode = aFeature->string(FeaturesPlugin_BooleanCommon::CREATION_METHOD())->value()
1739 == FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE();
1741 if (!isSimpleMode) {
1742 anAttrSelList = theFeature->selectionList(*anIt);
1743 if (anAttrSelList) {
1744 aToolsNb = anAttrSelList->size();
1748 if ((isSimpleMode && anObjectsNb < 2)
1749 || (!isSimpleMode && (anObjectsNb == 0 || aToolsNb == 0))) {
1750 theError = "Not enough arguments for Fuse operation.";
1756 //=================================================================================================
1757 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isNotObligatory(
1758 std::string theFeature,
1759 std::string theAttribute)