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()) {
72 theError = "Error: This validator can only work with path selector in \"Pipe\" feature.";
77 GeomShapePtr aPathShape = aPathAttrSelection->value();
78 ResultPtr aContext = aPathAttrSelection->context();
80 theError = "Error: Empty context.";
83 GeomShapePtr aContextShape = aContext->shape();
84 if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE &&
85 !aPathShape->isEqual(aContextShape)) {
86 theError = "Error: Local selection of wires not allowed.";
93 //==================================================================================================
94 bool FeaturesPlugin_ValidatorPipeLocations::isValid(const AttributePtr& theAttribute,
95 const std::list<std::string>& theArguments,
96 Events_InfoMessage& theError) const
98 AttributeSelectionListPtr anAttrSelectionList =
99 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
100 if(!anAttrSelectionList.get()) {
103 "Error: This validator can only work with selection list attributes in \"Pipe\" feature.";
107 std::shared_ptr<FeaturesPlugin_Pipe> aFeature =
108 std::dynamic_pointer_cast<FeaturesPlugin_Pipe>(theAttribute->owner());
110 AttributeSelectionPtr aPathSelection = aFeature->selection(FeaturesPlugin_Pipe::PATH_OBJECT_ID());
111 if (!aPathSelection.get()) {
113 theError = "Error: Path not selected.";
118 GeomShapePtr aPathShape = aPathSelection->value();
119 if (!aPathShape.get()) {
120 ResultPtr aContext = aPathSelection->context();
121 if (!aContext.get()) {
122 FeaturePtr aContFeat = aPathSelection->contextFeature();
123 if (!aContFeat.get() || !aContFeat->results().size()) {
124 theError = "Error: Empty selection context.";
128 aPathShape = aContext->shape();
131 if (!aPathShape.get()) {
132 theError = "Error: Empty path shape.";
136 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
137 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
138 if (!anAttrSelection.get()) {
139 theError = "Error: Empty attribute selection.";
142 ResultPtr aContext = anAttrSelection->context();
143 if (!aContext.get()) {
144 FeaturePtr aContFeat = anAttrSelection->contextFeature();
145 if (!aContFeat.get() || !aContFeat->results().size()) {
146 theError = "Error: Empty selection context.";
150 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
151 if (!aShape.get() && aContext.get()) {
152 GeomShapePtr aContextShape = aContext->shape();
153 aShape = aContextShape;
156 theError = "Error: Empty shape.";
160 if (!aPathShape->isSubShape(aShape)) {
161 theError = "Error: Location should be a vertex subshape from path shape.";
169 //==================================================================================================
171 bool FeaturesPlugin_ValidatorPipeLocationsNumber::isValid(
172 const std::shared_ptr<ModelAPI_Feature>& theFeature,
173 const std::list<std::string>& theArguments,
174 Events_InfoMessage& theError) const
176 static const std::string aCreationMethodID = "creation_method";
177 static const std::string aBaseObjectsID = "base_objects";
178 static const std::string aLocationsID = "locations_objects";
180 if(theFeature->getKind() != "Pipe") {
181 theError = "Error: Feature \"%1\" does not supported by this validator.";
182 theError.arg(theFeature->getKind());
186 AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);
187 if(!aCreationMethodAttr.get()) {
188 theError = "Error: Could not get \"%1\" attribute.";
189 theError.arg(aCreationMethodID);
193 if(aCreationMethodAttr->value() != "locations") {
197 AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);
198 if(!aBaseObjectsSelectionList.get()) {
199 theError = "Error: Could not get \"%1\" attribute.";
200 theError.arg(aBaseObjectsID);
204 AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);
205 if(!aLocationsSelectionList.get()) {
206 theError = "Error: Could not get \"%1\" attribute.";
207 theError.arg(aBaseObjectsID);
211 if(aLocationsSelectionList->size() > 0 &&
212 aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
213 theError = "Error: Number of locations should be the same as base objects.";
221 //==================================================================================================
222 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
223 const std::list<std::string>& theArguments,
224 Events_InfoMessage& theError) const
227 if(theArguments.empty()) {
228 theError = "Error: Validator parameters is empty.";
233 // Checking attribute.
234 if(!isValidAttribute(theAttribute, theArguments, theError)) {
235 if(theError.empty()) {
236 theError = "Error: Attribute contains unacceptable shape.";
241 GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
242 std::string anAttributeType = theAttribute->attributeType();
243 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
244 AttributeSelectionListPtr aListAttr =
245 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
246 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
247 AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
248 ResultPtr aContext = aSelectionAttr->context();
249 if(!aContext.get() && !aSelectionAttr->contextFeature().get()) {
250 theError = "Error: Empty context.";
254 ResultConstructionPtr aResultConstruction =
255 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
256 if(!aResultConstruction.get()) {
257 // It is not a result construction.
258 // If shape is compound check that it contains only faces and edges.
259 GeomShapePtr aShape = aSelectionAttr->value();
261 if (aContext.get()) {
262 aShape = aContext->shape();
264 theError = "Error: Empty context.";
269 if(aShape->shapeType() == GeomAPI_Shape::COMPOUND) {
270 for(GeomAPI_ShapeIterator anIt(aShape); anIt.more(); anIt.next()) {
271 GeomShapePtr aSubShape = anIt.current();
272 if(aSubShape->shapeType() != GeomAPI_Shape::EDGE
273 && aSubShape->shapeType() != GeomAPI_Shape::FACE) {
274 theError = "Error: Compound should contain only faces and edges.";
283 GeomShapePtr aShape = aSelectionAttr->value();
284 GeomShapePtr aContextShape = aResultConstruction->shape();
286 // Whole sketch selected.
289 // Object from sketch selected.
290 for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
291 GeomShapePtr aWire = anExp.current();
292 if(aWire->orientation() != GeomAPI_Shape::FORWARD) {
293 theError = "Error: Wire with wrong orientation selected.";
297 if(aSelectedWiresFromObjects.isBound(aWire)) {
299 "Error: Objects with such wire already selected. Don't allow to select this object.";
303 aSelectedWiresFromObjects.bind(aWire, aWire);
312 //==================================================================================================
313 bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid(
314 const std::shared_ptr<ModelAPI_Feature>& theFeature,
315 const std::list<std::string>& theArguments,
316 Events_InfoMessage& theError) const
318 const std::string aBaseObjectsID = theArguments.front();
320 AttributeSelectionListPtr aListAttr = theFeature->selectionList(aBaseObjectsID);
321 if(!aListAttr.get()) {
323 theError = "Error: Could not get \"%1\" attribute.";
324 theError.arg(aBaseObjectsID);
329 std::set<ResultConstructionPtr> aSelectedSketches;
330 std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
332 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
333 AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
334 ResultPtr aContext = aSelectionAttr->context();
335 if(!aContext.get()) {
336 FeaturePtr aFeature = aSelectionAttr->contextFeature();
337 if (!aFeature.get() || aFeature->results().empty()) {
338 theError = "Error: Empty context.";
341 aContext = aFeature->firstResult();
345 ResultConstructionPtr aResultConstruction =
346 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
347 if(!aResultConstruction.get()) {
348 // It is not a result construction.
352 GeomShapePtr aShape = aSelectionAttr->value();
353 GeomShapePtr aContextShape = aResultConstruction->shape();
355 // Whole sketch selected.
356 aSelectedSketches.insert(aResultConstruction);
358 // Object from sketch selected.
359 aSelectedSketchesFromObjects.insert(aResultConstruction);
364 for(std::set<ResultConstructionPtr>::const_iterator anIt = aSelectedSketches.cbegin();
365 anIt != aSelectedSketches.cend();
367 ResultConstructionPtr aResultConstruction = *anIt;
368 if(aSelectedSketchesFromObjects.find(aResultConstruction) !=
369 aSelectedSketchesFromObjects.cend()) {
370 theError = "Sketch and objects from it can not be selected at the same time.";
378 //==================================================================================================
379 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
380 const std::list<std::string>& theArguments,
381 Events_InfoMessage& theError) const
383 if(!theAttribute.get()) {
385 theError = "Error: Empty attribute.";
390 std::string anAttributeType = theAttribute->attributeType();
391 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
392 AttributeSelectionListPtr aListAttr =
393 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
394 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
395 // If at least one attribute is invalid, the result is false.
396 if(!isValidAttribute(aListAttr->value(anIndex), theArguments, theError)) {
400 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
402 AttributeSelectionPtr anAttr =
403 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
404 ResultPtr aContext = anAttr->context();
405 if(!aContext.get() && !anAttr->contextFeature().get()) {
406 theError = "Error: Attribute have empty context.";
410 GeomShapePtr aShape = anAttr->value();
411 GeomShapePtr aContextShape;
412 if(!aShape.get() && aContext.get()) {
413 aContextShape = aContext->shape();
414 aShape = aContextShape;
417 theError = "Error: Empty shape selected";
421 ResultConstructionPtr aConstruction;
422 if (!aContext.get() && anAttr->contextFeature()->results().size() == 1) {
423 aContext = anAttr->contextFeature()->firstResult();
426 aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
427 if(aConstruction.get()) {
428 // Construction selected. Check that it is not infinite.
429 if(aConstruction->isInfinite()) {
430 theError = "Error: Infinite constructions is not allowed as base.";
434 GeomShapePtr aContextShape = aContext->shape();
435 if(aShape->isEqual(aContextShape)) {
436 // Whole construction selected. Check that it have faces.
437 if(aConstruction->facesNum() > 0) {
441 // Shape on construction selected. Check that it is a face or wire.
442 if(aShape->shapeType() == GeomAPI_Shape::WIRE ||
443 aShape->shapeType() == GeomAPI_Shape::FACE) {
450 if(aContextShape.get() && !aShape->isEqual(aContextShape)) {
451 // Local selection on body does not allowed.
453 "Error: Selected shape is in the local selection. Only global selection is allowed.";
457 // Check that object is a shape with allowed type.
458 GeomValidators_ShapeType aShapeTypeValidator;
459 if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
460 theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or "
461 "wires on sketch, whole sketch(if it has at least one face), "
462 "and whole objects with shape types: %1";
463 std::string anArgumentString;
464 for(auto anIt = theArguments.cbegin(); anIt != theArguments.cend(); ++anIt) {
465 if (!anArgumentString.empty())
466 anArgumentString += ", ";
467 anArgumentString += *anIt;
469 theError.arg(anArgumentString);
475 theError = "Error: Attribute \"%1\" does not supported by this validator.";
476 theError.arg(anAttributeType);
484 //==================================================================================================
486 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
487 const std::list<std::string>& theArguments,
488 Events_InfoMessage& theError) const
490 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
491 theError = "Error: The attribute with the %1 type is not processed";
492 theError.arg(theAttribute->attributeType());
495 if (theArguments.size() != 2) {
496 theError = "Error: Wrong parameters in XML definition for %1 type";
497 theError.arg(theAttribute->attributeType());
500 // first argument is for the base attribute, second - for skipping feature kind
501 std::list<std::string>::const_iterator anIt = theArguments.begin();
502 std::string aBaseAttributeId = *anIt;
503 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
504 AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
505 if (!aBaseAttribute.get()) {
506 theError = "Wrong parameters in XML definition for %1 type";
507 theError.arg(theAttribute->attributeType());
510 if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
511 // this validator is not necessary anymore
515 std::string aFeatureAttributeKind = *anIt;
516 GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
517 // check whether the selection is on the sketch
518 std::list<std::string> anArguments;
519 anArguments.push_back(aFeatureAttributeKind);
521 bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);
522 bool aPlanarFace = false;
523 // check if selection has Face selected
524 GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
526 anArguments.push_back("face");
527 aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);
529 bool aValid = !aFeatureKind && aPlanarFace;
534 //==================================================================================================
535 bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
536 const std::shared_ptr<ModelAPI_Feature>& theFeature,
537 const std::list<std::string>& theArguments,
538 Events_InfoMessage& theError) const
540 if(theArguments.size() != 2) {
542 theError = "Error: Validator should be used with 2 parameters for extrusion.";
547 std::list<std::string>::const_iterator
548 anArgsIt = theArguments.begin(), aLast = theArguments.end();
550 AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
553 GeomShapePtr aDirShape;
554 AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
556 aDirShape = aSelAttr->value();
557 if(!aDirShape.get()) {
558 ResultPtr aContext = aSelAttr->context();
559 if(!aContext.get()) {
560 FeaturePtr aFeature = aSelAttr->contextFeature();
561 if (aFeature.get() && !aFeature->results().empty()) {
562 aContext = aFeature->firstResult();
567 aDirShape = aContext->shape();
570 if (aDirShape.get() && aDirShape->isCompound()) {
571 GeomAPI_ShapeIterator anIt(aDirShape);
572 aDirShape = anIt.current();
577 if(!aDirShape.get() || aDirShape->isNull() ||
578 aDirShape->shapeType() != GeomAPI_Shape::EDGE) {
579 // Check that dir can be empty.
580 if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
581 theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" "
582 "can not be used with default value. Select direction for extrusion.";
583 theError.arg(*anArgsIt);
590 std::shared_ptr<GeomAPI_Edge> aDirEdge(new GeomAPI_Edge(aDirShape));
592 // If faces selected check that direction not parallel with them.
593 AttributeSelectionListPtr aListAttr =
594 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aCheckAttribute);
595 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
596 AttributeSelectionPtr anAttr = aListAttr->value(anIndex);
597 GeomShapePtr aShapeInList = anAttr->value();
598 if(!aShapeInList.get()) {
599 aShapeInList = anAttr->context()->shape();
601 bool isParallel = true;
602 if(aShapeInList->shapeType() == GeomAPI_Shape::FACE ||
603 aShapeInList->shapeType() == GeomAPI_Shape::SHELL) {
604 for(GeomAPI_ShapeExplorer
605 anExp(aShapeInList, GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
606 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(anExp.current()));
607 isParallel = GeomAlgoAPI_ShapeTools::isParallel(aDirEdge, aFace);
612 } else if(aShapeInList->shapeType() == GeomAPI_Shape::COMPOUND) {
613 std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges =
614 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapeInList);
615 if(aPlanarEdges.get()) {
616 std::shared_ptr<GeomAPI_Dir> aSketchDir = aPlanarEdges->norm();
617 if(aDirEdge->isLine()) {
618 std::shared_ptr<GeomAPI_Dir> aDir = aDirEdge->line()->direction();
619 isParallel = fabs(aSketchDir->angle(aDir) - M_PI / 2.0) < 10e-7;
631 "Error: Direction is parallel to one of the selected face or face on selected shell.";
639 //==================================================================================================
640 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
641 Events_InfoMessage& theError) const
644 if(!theAttribute.get()) {
649 std::string anAttributeType = theAttribute->attributeType();
650 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
651 AttributeSelectionListPtr aListAttr =
652 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
653 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
654 // If at least one attribute is invalid, the result is false.
655 if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) {
659 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
661 AttributeSelectionPtr anAttr =
662 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
663 ResultPtr aContext = anAttr->context();
664 if(!aContext.get() && !anAttr->contextFeature().get()) {
668 GeomShapePtr aShape = anAttr->value();
669 if(!aShape.get() && aContext.get()) {
670 GeomShapePtr aContextShape = aContext->shape();
671 aShape = aContextShape;
677 if(aShape->shapeType() == GeomAPI_Shape::VERTEX ||
678 aShape->shapeType() == GeomAPI_Shape::EDGE ||
679 !aShape->isPlanar()) {
689 //==================================================================================================
690 bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
691 const std::list<std::string>& theArguments,
692 Events_InfoMessage& theError) const
694 AttributeSelectionListPtr anAttrSelectionList =
695 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
696 if(!anAttrSelectionList.get()) {
699 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
703 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
704 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theAttribute->owner());
705 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
707 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
708 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
709 if(!anAttrSelection.get()) {
710 theError = "Error: Empty attribute selection.";
713 ResultPtr aContext = anAttrSelection->context();
714 if(!aContext.get()) {
715 FeaturePtr aContFeat = anAttrSelection->contextFeature();
716 if (!aContFeat.get() || !aContFeat->results().size()) {
717 theError = "Error: Empty selection context.";
721 ResultConstructionPtr aResultConstruction =
722 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
723 if(aResultConstruction.get()) {
724 if (anOperationType != FeaturesPlugin_Boolean::BOOL_FILL
725 || theAttribute->id() != FeaturesPlugin_Boolean::TOOL_LIST_ID()) {
726 theError = "Error: Result construction not allowed for selection.";
730 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
731 if(!aShape.get() && aContext.get()) {
732 GeomShapePtr aContextShape = aContext->shape();
733 aShape = aContextShape;
736 theError = "Error: Empty shape.";
739 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
740 theError = "Error: Local selection not allowed.";
744 GeomAPI_Shape::ShapeType aShapeType = aShape->shapeType();
745 std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
746 if(anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE) {
747 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
748 anAllowedTypes.insert(GeomAPI_Shape::FACE);
749 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
750 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
751 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
752 } else if (anOperationType == FeaturesPlugin_Boolean::BOOL_FILL
753 || anOperationType == FeaturesPlugin_Boolean::BOOL_CUT)
755 anAllowedTypes.insert(GeomAPI_Shape::VERTEX);
756 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
757 anAllowedTypes.insert(GeomAPI_Shape::WIRE);
758 anAllowedTypes.insert(GeomAPI_Shape::FACE);
759 anAllowedTypes.insert(GeomAPI_Shape::SHELL);
760 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
761 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
762 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
764 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
765 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
766 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
769 if(anAllowedTypes.find(aShapeType) == anAllowedTypes.end()
770 || (aResultConstruction.get() && aShapeType != GeomAPI_Shape::FACE)) {
771 theError = "Error: Selected shape has the wrong type.";
780 //==================================================================================================
781 bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAttribute,
782 const std::list<std::string>& theArguments,
783 Events_InfoMessage& theError) const
785 AttributeSelectionListPtr anAttrSelectionList =
786 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
787 if(!anAttrSelectionList.get()) {
790 "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
795 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
796 // Check all selected entities are sub-shapes of single solid
797 GeomShapePtr aBaseSolid;
798 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
799 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
800 if(!anAttrSelection.get()) {
801 theError = "Error: Empty attribute selection.";
804 ResultPtr aContext = anAttrSelection->context();
805 if(!aContext.get()) {
806 FeaturePtr aContFeat = anAttrSelection->contextFeature();
807 if (!aContFeat.get() || !aContFeat->results().size() ||
808 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
809 theError = "Error: Empty selection context.";
812 if (aContFeat->results().size() == 1)
813 aContext = aContFeat->firstResult();
815 theError = "Error: Too many shapes selected.";
820 ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext);
821 GeomShapePtr anOwner = aContextOwner.get() ? aContextOwner->shape() : aContext->shape();
824 theError = "Error: wrong feature is selected.";
828 if (anOwner->shapeType() != GeomAPI_Shape::SOLID &&
829 anOwner->shapeType() != GeomAPI_Shape::COMPSOLID) {
830 theError = "Error: Not all selected shapes are sub-shapes of solids.";
835 aBaseSolid = anOwner;
836 else if (!aBaseSolid->isEqual(anOwner)) {
837 theError = "Error: Sub-shapes of different solids have been selected.";
845 //==================================================================================================
846 bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,
847 const std::list<std::string>& theArguments,
848 Events_InfoMessage& theError) const
850 AttributeSelectionListPtr anAttrSelectionList =
851 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
852 if(!anAttrSelectionList.get()) {
854 theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
859 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
860 AttributeSelectionPtr aSelectAttr = anAttrSelectionList->value(anIndex);
862 //GeomValidators_BodyShapes aBodyValidator;
863 //if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
867 GeomValidators_FeatureKind aFeatureKindValidator;
868 if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
872 ResultPtr aContext = aSelectAttr->context();
873 ResultConstructionPtr aResultConstruction =
874 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
875 if(aResultConstruction.get()) {
876 theError = "Error: Only body shapes and construction planes are allowed for selection.";
880 ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
881 if(aResultBody.get()) {
884 FeaturePtr aResultFeature = aSelectAttr->contextFeature();
885 if(aResultFeature.get()) {
887 std::list<ResultPtr>::const_iterator aFRes = aResultFeature->results().cbegin();
888 for(; aFRes != aResultFeature->results().cend() && !aOkRes; aFRes++) {
889 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aFRes);
890 if (aBody.get() && !aBody->isDisabled())
897 theError = "Error: Only body shapes and construction planes are allowed for selection.";
905 //==================================================================================================
906 bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
907 const std::list<std::string>& theArguments,
908 Events_InfoMessage& theError) const
910 AttributeSelectionListPtr aSubShapesAttrList =
911 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
912 if(!aSubShapesAttrList.get()) {
915 "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
920 static const std::string aBaseShapeID = "base_shape";
921 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
922 AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
924 if(!aShapeAttrSelection.get()) {
926 theError = "Error: Could not get \"%1\" attribute.";
927 theError.arg(aBaseShapeID);
932 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
933 ResultPtr aContext = aShapeAttrSelection->context();
934 if(!aContext.get()) {
935 theError = "Error: Empty context.";
938 if(!aBaseShape.get()) {
939 aBaseShape = aContext->shape();
941 if(!aBaseShape.get()) {
942 theError = "Error: Empty base shape.";
946 std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
947 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
948 bool isSameFound = false;
949 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
950 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
951 for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt)
953 if ((*anIt)->isEqual(aShapeToAdd)) {
959 theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
967 //==================================================================================================
968 bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
969 const std::shared_ptr<ModelAPI_Feature>& theFeature,
970 const std::list<std::string>& theArguments,
971 Events_InfoMessage& theError) const
973 static const std::string aBaseShapeID = "base_shape";
974 static const std::string aSubShapesID = "subshapes_to_keep";
977 if(theFeature->getKind() != "Remove_SubShapes") {
978 theError = "Error: Feature \"%1\" does not supported by this validator.";
979 theError.arg(theFeature->getKind());
983 AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
984 if(!aShapeAttrSelection.get()) {
985 theError = "Error: Could not get \"%1\" attribute.";
986 theError.arg(aBaseShapeID);
990 AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
991 if(!aSubShapesAttrList.get()) {
992 theError = "Error: Could not get \"%1\" attribute.";
993 theError.arg(aSubShapesID);
999 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
1000 if(!aBaseShape.get()) {
1001 theError = "Error: Base shape is empty.";
1004 GeomShapePtr aResultShape = aBaseShape->emptyCopied();
1006 if (aSubShapesAttrList->size() == 0) {
1007 theError = "Error: Resulting shape is not valid.";
1011 // Copy sub-shapes from list to new shape.
1012 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
1013 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
1014 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
1015 GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
1019 if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {
1020 theError = "Error: Resulting shape is not valid.";
1027 //==================================================================================================
1029 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
1030 const std::list<std::string>& theArguments,
1031 Events_InfoMessage& theError) const
1033 AttributeSelectionListPtr aBaseObjectsAttrList =
1034 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1035 if(!aBaseObjectsAttrList.get()) {
1036 theError = "Error: This validator can only work with selection list in \"%1\" feature.";
1037 theError.arg(FeaturesPlugin_Union::ID());
1041 for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
1042 bool isSameFound = false;
1043 AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
1044 ResultPtr aContext = anAttrSelectionInList->context();
1045 if (!aContext.get()) {
1046 theError = "Error: selection is invalid.";
1050 ResultConstructionPtr aConstruction =
1051 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1052 if(aConstruction.get()) {
1053 theError = "Error: Result construction not allowed for selection.";
1057 GeomShapePtr aShape = anAttrSelectionInList->value();
1058 GeomShapePtr aContextShape = aContext->shape();
1059 if (aShape.get() && aContextShape.get() && !aContextShape->isEqual(aShape)) {
1060 theError = "Error: Local selection not allowed.";
1064 ResultBodyPtr aResult =
1065 std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
1066 if(!aResult.get()) {
1070 if(aResult->numberOfSubs() > 0) {
1071 theError = "Error: Whole compsolids not allowed for selection.";
1080 //==================================================================================================
1081 bool FeaturesPlugin_ValidatorUnionArguments::isValid(
1082 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1083 const std::list<std::string>& theArguments,
1084 Events_InfoMessage& theError) const
1087 // Check feature kind.
1088 if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
1089 theError = "Error: This validator supports only \"%1\" feature.";
1090 theError.arg(FeaturesPlugin_Union::ID());
1094 // Get base objects attribute list.
1095 AttributeSelectionListPtr aBaseObejctsAttrList =
1096 theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1097 if(!aBaseObejctsAttrList.get()) {
1098 theError = "Error: Could not get \"%1\" attribute.";
1099 theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1105 GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPSOLID;
1106 ListOfShape aBaseShapesList;
1107 for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
1108 AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
1109 GeomShapePtr aShape = anAttrSelectionInList->value();
1110 if (!aShape.get()) {
1113 aBaseShapesList.push_back(aShape);
1114 aType = aShape->shapeType() == GeomAPI_Shape::FACE ? GeomAPI_Shape::SHELL :
1115 GeomAPI_Shape::COMPSOLID;
1118 // Make compound and find connected.
1119 GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
1120 ListOfShape aCombined, aFree;
1121 GeomAlgoAPI_ShapeTools::combineShapes(
1127 if(aFree.size() > 0 || aCombined.size() > 1) {
1128 theError = "Error: Not all shapes have shared topology.";
1135 bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute,
1136 const std::list<std::string>& theArguments,
1137 Events_InfoMessage& theError) const
1139 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1141 theError = "Error: The attribute with the %1 type is not processed";
1142 theError.arg(theAttribute->attributeType());
1147 AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeReference>
1149 ObjectPtr aRefObject = aRefAttribute->value();
1150 if (!aRefObject.get()) {
1151 theError = "Error: Empty feature.";
1155 FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aRefObject);
1156 if (!aRefFeature.get()) {
1157 theError = "Error: Empty feature.";
1160 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
1161 ModelAPI_Tools::getConcealedResults(aRefFeature, aResults);
1163 size_t aConcealedResults = aResults.size();
1164 if (!aConcealedResults && !theArguments.empty()) {
1165 // find if these results are touched by the feature in another attribute
1166 std::list<std::string>::const_iterator anIt = theArguments.begin();
1167 std::string aRecoveredList = *anIt;
1168 if (!aRecoveredList.empty()) {
1169 std::shared_ptr<ModelAPI_AttributeRefList> aParameterList =
1170 theAttribute->owner()->data()->reflist(aRecoveredList);
1171 if (aParameterList.get())
1172 aConcealedResults = aParameterList->size();
1176 if (aConcealedResults == 0)
1177 theError = "Error: No concealed results.";
1179 return theError.empty();
1182 bool FeaturesPlugin_ValidatorCircular::isValid(const AttributePtr& theAttribute,
1183 const std::list<std::string>& theArguments,
1184 Events_InfoMessage& theError) const
1186 static std::list<std::string> aEdgeArg(1, "circle");
1187 static std::list<std::string> aFaceArg(1, "cylinder");
1189 Events_InfoMessage aError;
1190 bool isValid = GeomValidators_ShapeType().isValid(theAttribute, aEdgeArg, aError);
1192 isValid = GeomValidators_Face().isValid(theAttribute, aFaceArg, aError);
1194 theError = "The shape neither circle nor cylinder";
1199 //=================================================================================================
1200 bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
1201 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1202 const std::list<std::string>& theArguments,
1203 Events_InfoMessage& theError) const
1206 if (theArguments.size() != 2)
1208 theError = "Wrong number of arguments (expected 2).";
1213 int anObjectsToolsNb[2] = { 0, 0 };
1215 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1217 bool isAllInSameCompSolid = true;
1218 ResultBodyPtr aCompSolid;
1220 for (int* anArgNbIt = anObjectsToolsNb; anIt != aLast; ++anIt, ++anArgNbIt) {
1221 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1224 *anArgNbIt = anAttrSelList->size();
1225 if (isAllInSameCompSolid) {
1226 for (int anIndex = 0; anIndex < *anArgNbIt; ++anIndex)
1228 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1229 ResultPtr aContext = anAttr->context();
1230 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1231 if (aResCompSolidPtr.get())
1233 if (aCompSolid.get())
1235 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1239 aCompSolid = aResCompSolidPtr;
1244 isAllInSameCompSolid = false;
1252 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
1253 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theFeature);
1254 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
1256 if (anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE)
1259 if (anObjectsToolsNb[0] + anObjectsToolsNb[1] < 2)
1261 theError = "Not enough arguments for Fuse operation.";
1264 else if (isAllInSameCompSolid)
1266 theError = "Operations only between sub-shapes of the same shape not allowed.";
1272 if (anObjectsToolsNb[0] < 1) // check number of objects
1274 theError = "Objects not selected.";
1277 if (anObjectsToolsNb[1] < 1) // check number of tools
1279 theError = "Tools not selected.";
1282 if (isAllInSameCompSolid)
1284 theError = "Operations only between sub-shapes of the same shape not allowed.";
1292 //=================================================================================================
1294 bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFeature,
1295 std::string theAttribute)
1297 if (theAttribute == "main_objects" || theAttribute == "tool_objects")
1306 //==================================================================================================
1307 bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
1308 const AttributePtr& theAttribute,
1309 const std::list<std::string>& theArguments,
1310 Events_InfoMessage& theError) const
1312 std::shared_ptr<FeaturesPlugin_BooleanSmash> aFeature =
1313 std::dynamic_pointer_cast<FeaturesPlugin_BooleanSmash>(theAttribute->owner());
1315 AttributeSelectionListPtr anAttrSelectionList =
1316 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1317 if (!aFeature.get() || !anAttrSelectionList.get()) {
1320 "Error: Validator used in wrong feature or attribute";
1325 AttributeSelectionListPtr anOtherAttrSelectionList;
1326 if (theAttribute->id() == FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID()) {
1327 anOtherAttrSelectionList =
1328 aFeature->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
1330 anOtherAttrSelectionList =
1331 aFeature->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
1334 GeomAPI_Shape::ShapeType aSelectedShapesType = GeomAPI_Shape::SHAPE;
1335 GeomAPI_DataMapOfShapeShape aSelectedCompSolidsInOtherList;
1336 GeomPlanePtr aFacesPln;
1338 for (int anIndex = 0; anIndex < anOtherAttrSelectionList->size(); ++anIndex) {
1339 AttributeSelectionPtr anAttrSelection = anOtherAttrSelectionList->value(anIndex);
1341 if (anAttrSelection->contextFeature().get()) {
1342 theError = "Error: Features not allowed for selection.";
1346 ResultPtr aContext = anAttrSelection->context();
1347 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1348 GeomShapePtr aContextShape = aContext->shape();
1349 if (!aShape.get()) {
1350 aShape = aContextShape;
1353 if (aShape->isSolid() || aShape->isCompSolid()) {
1354 aSelectedShapesType = GeomAPI_Shape::SOLID;
1355 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1356 if (aResCompSolidPtr.get()) {
1357 GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
1358 aSelectedCompSolidsInOtherList.bind(aCompSolidShape, aCompSolidShape);
1361 aSelectedShapesType = GeomAPI_Shape::FACE;
1362 GeomAPI_Face aFace(aShape);
1363 aFacesPln = aFace.getPlane();
1368 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1369 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1370 if (!anAttrSelection.get()) {
1371 theError = "Error: Empty attribute selection.";
1375 if (anAttrSelection->contextFeature().get()) {
1376 theError = "Error: Features not allowed for selection.";
1380 ResultPtr aContext = anAttrSelection->context();
1381 if(!aContext.get()) {
1382 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1383 if (!aContFeat.get() || !aContFeat->results().size() ||
1384 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1385 theError = "Error: Empty selection context.";
1389 ResultConstructionPtr aResultConstruction =
1390 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1391 if (aResultConstruction.get()) {
1392 theError = "Error: Result construction not allowed for selection.";
1395 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1396 GeomShapePtr aContextShape = aContext->shape();
1397 if (!aShape.get()) {
1398 aShape = aContextShape;
1400 if (!aShape.get()) {
1401 theError = "Error: Empty shape.";
1404 if (!aShape->isEqual(aContextShape)) {
1405 theError = "Error: Local selection not allowed.";
1409 if (aSelectedShapesType == GeomAPI_Shape::SHAPE) {
1410 // Other list is empty.
1411 if (aShape->isSolid() || aShape->isCompSolid()) {
1412 aSelectedShapesType = GeomAPI_Shape::SOLID;
1414 aSelectedShapesType = GeomAPI_Shape::FACE;
1415 GeomAPI_Face aFace(aShape);
1416 aFacesPln = aFace.getPlane();
1418 if (!aFacesPln.get()) {
1419 theError = "Error: Only planar faces allowed.";
1425 } else if (aSelectedShapesType == GeomAPI_Shape::SOLID) {
1426 if (!aShape->isSolid() && !aShape->isCompSolid()) {
1427 theError = "Error: Selected shapes should have the same type.";
1431 GeomAPI_Face aFace(aShape);
1432 GeomPlanePtr aPln = aFace.getPlane();
1435 theError = "Error: Only planar faces allowed.";
1439 if (!aFacesPln->isCoincident(aPln)) {
1440 theError = "Error: Only coincident faces allowed.";
1449 //==================================================================================================
1451 bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
1452 const std::list<std::string>& theArguments,
1453 Events_InfoMessage& theError) const
1455 if (!theAttribute.get()) {
1456 theError = "Error: empty selection.";
1459 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
1460 AttributeSelectionListPtr anAttrSelectionList =
1461 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1462 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1463 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1464 if (!anAttrSelection.get()) {
1465 theError = "Error: empty attribute selection.";
1468 ResultPtr aContext = anAttrSelection->context();
1469 if(!aContext.get()) {
1470 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1471 if (!aContFeat.get() || !aContFeat->results().size() ||
1472 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1473 theError = "Error: Empty selection context.";
1477 FeaturePtr aFeature = anAttrSelection->contextFeature().get() ?
1478 anAttrSelection->contextFeature() : ModelAPI_Feature::feature(aContext);
1479 if (!aFeature.get()) {
1480 theError = "Error: empty feature.";
1483 std::string aFeatureKind = aFeature->getKind();
1484 if (aFeatureKind == "Sketch" ||
1485 aFeatureKind == "Plane" ||
1486 aFeatureKind == "Axis") {
1487 theError = "Error: %1 shape is not allowed for selection.";
1488 theError.arg(aFeatureKind);
1491 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1492 if (!aShape.get()) {
1493 GeomShapePtr aContextShape = aContext->shape();
1494 aShape = aContextShape;
1496 if (!aShape.get()) {
1497 theError = "Error: empty shape.";
1500 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1501 theError = "Error: Local selection not allowed.";
1505 int aShapeType = aShape->shapeType();
1506 // Allow to select edges, faces and solids.
1507 if (aShapeType != GeomAPI_Shape::EDGE &&
1508 aShapeType != GeomAPI_Shape::FACE &&
1509 aShapeType != GeomAPI_Shape::SOLID &&
1510 aShapeType != GeomAPI_Shape::COMPSOLID &&
1511 aShapeType != GeomAPI_Shape::COMPOUND) {
1512 theError = "Error: selected shape has the wrong type.";
1521 //==================================================================================================
1523 bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid(
1524 const AttributePtr& theAttribute,
1525 const std::list<std::string>& theArguments,
1526 Events_InfoMessage& theError) const
1528 AttributeSelectionListPtr anAttrSelectionList =
1529 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1530 if (!anAttrSelectionList.get()) {
1532 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1536 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1537 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1538 if (!anAttrSelection.get()) {
1539 theError = "Error: Empty attribute selection.";
1542 ResultPtr aContext = anAttrSelection->context();
1543 if(!aContext.get()) {
1544 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1545 if (!aContFeat.get() || !aContFeat->results().size() ||
1546 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1547 theError = "Error: Empty selection context.";
1551 ResultConstructionPtr aResultConstruction =
1552 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1553 if (aResultConstruction.get()) {
1554 theError = "Error: Result construction not allowed for selection.";
1557 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1558 if (!aShape.get()) {
1559 GeomShapePtr aContextShape = aContext->shape();
1560 aShape = aContextShape;
1562 if (!aShape.get()) {
1563 theError = "Error: Empty shape.";
1566 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1567 theError = "Error: Local selection not allowed.";
1576 //=================================================================================================
1577 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
1578 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1579 const std::list<std::string>& theArguments,
1580 Events_InfoMessage& theError) const
1583 if (theArguments.size() != 2) {
1584 theError = "Wrong number of arguments (expected 2).";
1589 std::shared_ptr<FeaturesPlugin_BooleanFuse> aFeature =
1590 std::dynamic_pointer_cast<FeaturesPlugin_BooleanFuse>(theFeature);
1592 int anObjectsNb = 0, aToolsNb = 0;
1594 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1596 bool isAllInSameCompSolid = true;
1597 ResultBodyPtr aCompSolid;
1599 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1600 if (anAttrSelList) {
1601 anObjectsNb = anAttrSelList->size();
1602 for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
1603 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1604 ResultPtr aContext = anAttr->context();
1605 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1606 if (aResCompSolidPtr.get()) {
1607 if (aCompSolid.get()) {
1608 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1610 aCompSolid = aResCompSolidPtr;
1613 isAllInSameCompSolid = false;
1620 if (aFeature->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD())->value()
1621 == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
1622 anAttrSelList = theFeature->selectionList(*anIt);
1623 if (anAttrSelList) {
1624 aToolsNb = anAttrSelList->size();
1625 if (isAllInSameCompSolid) {
1626 for (int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
1627 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1628 ResultPtr aContext = anAttr->context();
1629 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1630 if (aResCompSolidPtr.get()) {
1631 if (aCompSolid.get()) {
1632 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1634 aCompSolid = aResCompSolidPtr;
1637 isAllInSameCompSolid = false;
1647 if (anObjectsNb + aToolsNb < 2) {
1648 theError = "Not enough arguments for Fuse operation.";
1650 } else if (isAllInSameCompSolid) {
1651 theError = "Operations only between sub-shapes of the same shape not allowed.";
1658 //=================================================================================================
1660 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory(
1661 std::string theFeature,
1662 std::string theAttribute)
1664 if (theAttribute == "main_objects" || theAttribute == "tool_objects") {
1672 //==================================================================================================
1674 bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
1675 const AttributePtr& theAttribute,
1676 const std::list<std::string>& theArguments,
1677 Events_InfoMessage& theError) const
1679 AttributeSelectionListPtr anAttrSelectionList =
1680 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1681 if (!anAttrSelectionList.get()) {
1683 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1687 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1688 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1689 if (!anAttrSelection.get()) {
1690 theError = "Error: Empty attribute selection.";
1693 ResultPtr aContext = anAttrSelection->context();
1694 if (!aContext.get() && !anAttrSelection->contextFeature().get()) {
1695 theError = "Error: Empty selection context.";
1698 ResultConstructionPtr aResultConstruction =
1699 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1700 if (aResultConstruction.get()) {
1701 if (theAttribute->id() != FeaturesPlugin_BooleanCommon::TOOL_LIST_ID()) {
1702 theError = "Error: Result construction not allowed for selection.";
1706 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1707 GeomShapePtr aContextShape;
1708 if (aContext.get()) {
1709 aContextShape = aContext->shape();
1711 if (!aShape.get()) {
1712 aShape = aContextShape;
1714 if (!aShape.get()) {
1715 theError = "Error: Empty shape.";
1718 if (aContextShape.get() && !aShape->isEqual(aContextShape)) {
1719 theError = "Error: Local selection not allowed.";
1723 if (aResultConstruction.get() && aShape->shapeType() != GeomAPI_Shape::FACE) {
1724 theError = "Error: Result construction should be plane.";
1733 //=================================================================================================
1734 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
1735 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1736 const std::list<std::string>& theArguments,
1737 Events_InfoMessage& theError) const
1739 if (theArguments.size() != 2) {
1741 theError = "Wrong number of arguments (expected 2).";
1746 std::shared_ptr<FeaturesPlugin_BooleanCommon> aFeature =
1747 std::dynamic_pointer_cast<FeaturesPlugin_BooleanCommon>(theFeature);
1749 int anObjectsNb = 0, aToolsNb = 0;
1751 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1753 bool isAllInSameCompSolid = true;
1754 ResultBodyPtr aCompSolid;
1756 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1757 if (anAttrSelList) {
1758 anObjectsNb = anAttrSelList->size();
1761 bool isSimpleMode = aFeature->string(FeaturesPlugin_BooleanCommon::CREATION_METHOD())->value()
1762 == FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE();
1764 if (!isSimpleMode) {
1765 anAttrSelList = theFeature->selectionList(*anIt);
1766 if (anAttrSelList) {
1767 aToolsNb = anAttrSelList->size();
1771 if ((isSimpleMode && anObjectsNb < 2)
1772 || (!isSimpleMode && (anObjectsNb == 0 || aToolsNb == 0))) {
1773 theError = "Not enough arguments for Fuse operation.";
1779 //=================================================================================================
1781 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isNotObligatory(
1782 std::string theFeature,
1783 std::string theAttribute)