1 // Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
20 #include "FeaturesPlugin_Validators.h"
22 #include "FeaturesPlugin_Boolean.h"
23 #include "FeaturesPlugin_BooleanFuse.h"
24 #include "FeaturesPlugin_BooleanCommon.h"
25 #include "FeaturesPlugin_BooleanSmash.h"
26 #include "FeaturesPlugin_CompositeBoolean.h"
27 #include "FeaturesPlugin_Extrusion.h"
28 #include "FeaturesPlugin_Pipe.h"
29 #include "FeaturesPlugin_Union.h"
31 #include <Events_InfoMessage.h>
33 #include <ModelAPI_Attribute.h>
34 #include <ModelAPI_AttributeDouble.h>
35 #include <ModelAPI_AttributeInteger.h>
36 #include <ModelAPI_AttributeSelectionList.h>
37 #include <ModelAPI_AttributeString.h>
38 #include <ModelAPI_AttributeReference.h>
39 #include <ModelAPI_AttributeRefList.h>
40 #include <ModelAPI_Feature.h>
41 #include <ModelAPI_ResultBody.h>
42 #include <ModelAPI_ResultConstruction.h>
43 #include <ModelAPI_Tools.h>
45 #include <GeomValidators_BodyShapes.h>
46 #include <GeomValidators_Face.h>
47 #include <GeomValidators_FeatureKind.h>
48 #include <GeomValidators_ShapeType.h>
50 #include <GeomAPI_DataMapOfShapeShape.h>
51 #include <GeomAPI_Lin.h>
52 #include <GeomAPI_PlanarEdges.h>
53 #include <GeomAPI_Pln.h>
54 #include <GeomAPI_ShapeExplorer.h>
55 #include <GeomAPI_ShapeIterator.h>
57 #include <GeomAlgoAPI_CompoundBuilder.h>
58 #include <GeomAlgoAPI_MapShapesAndAncestors.h>
59 #include <GeomAlgoAPI_Prism.h>
60 #include <GeomAlgoAPI_ShapeBuilder.h>
61 #include <GeomAlgoAPI_ShapeTools.h>
62 #include <GeomAlgoAPI_WireBuilder.h>
66 #define _USE_MATH_DEFINES
70 #pragma warning(disable: 4100)
73 //==================================================================================================
74 bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
75 const std::list<std::string>& theArguments,
76 Events_InfoMessage& theError) const
78 AttributeSelectionPtr aPathAttrSelection =
79 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
80 if(!aPathAttrSelection.get()) {
82 theError = "Error: This validator can only work with path selector in \"Pipe\" feature.";
87 GeomShapePtr aPathShape = aPathAttrSelection->value();
88 ResultPtr aContext = aPathAttrSelection->context();
90 theError = "Error: Empty context.";
93 GeomShapePtr aContextShape = aContext->shape();
94 if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE &&
95 !aPathShape->isEqual(aContextShape)) {
96 theError = "Error: Local selection of wires not allowed.";
103 //==================================================================================================
104 bool FeaturesPlugin_ValidatorPipeLocations::isValid(const AttributePtr& theAttribute,
105 const std::list<std::string>& theArguments,
106 Events_InfoMessage& theError) const
108 AttributeSelectionListPtr anAttrSelectionList =
109 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
110 if(!anAttrSelectionList.get()) {
113 "Error: This validator can only work with selection list attributes in \"Pipe\" feature.";
117 std::shared_ptr<FeaturesPlugin_Pipe> aFeature =
118 std::dynamic_pointer_cast<FeaturesPlugin_Pipe>(theAttribute->owner());
120 AttributeSelectionPtr aPathSelection = aFeature->selection(FeaturesPlugin_Pipe::PATH_OBJECT_ID());
121 if (!aPathSelection.get()) {
123 theError = "Error: Path not selected.";
128 GeomShapePtr aPathShape = aPathSelection->value();
129 if (!aPathShape.get()) {
130 ResultPtr aContext = aPathSelection->context();
131 if (!aContext.get()) {
132 FeaturePtr aContFeat = aPathSelection->contextFeature();
133 if (!aContFeat.get() || !aContFeat->results().size()) {
134 theError = "Error: Empty selection context.";
138 aPathShape = aContext->shape();
141 if (!aPathShape.get()) {
142 theError = "Error: Empty path shape.";
146 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
147 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
148 if (!anAttrSelection.get()) {
149 theError = "Error: Empty attribute selection.";
152 ResultPtr aContext = anAttrSelection->context();
153 if (!aContext.get()) {
154 FeaturePtr aContFeat = anAttrSelection->contextFeature();
155 if (!aContFeat.get() || !aContFeat->results().size()) {
156 theError = "Error: Empty selection context.";
160 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
161 if (!aShape.get() && aContext.get()) {
162 GeomShapePtr aContextShape = aContext->shape();
163 aShape = aContextShape;
166 theError = "Error: Empty shape.";
170 if (!aPathShape->isSubShape(aShape)) {
171 theError = "Error: Location should be a vertex subshape from path shape.";
179 //==================================================================================================
181 bool FeaturesPlugin_ValidatorPipeLocationsNumber::isValid(
182 const std::shared_ptr<ModelAPI_Feature>& theFeature,
183 const std::list<std::string>& theArguments,
184 Events_InfoMessage& theError) const
186 static const std::string aCreationMethodID = "creation_method";
187 static const std::string aBaseObjectsID = "base_objects";
188 static const std::string aLocationsID = "locations_objects";
190 if(theFeature->getKind() != "Pipe") {
191 theError = "Error: Feature \"%1\" does not supported by this validator.";
192 theError.arg(theFeature->getKind());
196 AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);
197 if(!aCreationMethodAttr.get()) {
198 theError = "Error: Could not get \"%1\" attribute.";
199 theError.arg(aCreationMethodID);
203 if(aCreationMethodAttr->value() != "locations") {
207 AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);
208 if(!aBaseObjectsSelectionList.get()) {
209 theError = "Error: Could not get \"%1\" attribute.";
210 theError.arg(aBaseObjectsID);
214 AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);
215 if(!aLocationsSelectionList.get()) {
216 theError = "Error: Could not get \"%1\" attribute.";
217 theError.arg(aBaseObjectsID);
221 if(aLocationsSelectionList->size() > 0 &&
222 aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
223 theError = "Error: Number of locations should be the same as base objects.";
231 //==================================================================================================
232 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
233 const std::list<std::string>& theArguments,
234 Events_InfoMessage& theError) const
237 if(theArguments.empty()) {
238 theError = "Error: Validator parameters is empty.";
243 // Checking attribute.
244 if(!isValidAttribute(theAttribute, theArguments, theError)) {
245 if(theError.empty()) {
246 theError = "Error: Attribute contains unacceptable shape.";
251 GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
252 std::string anAttributeType = theAttribute->attributeType();
253 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
254 AttributeSelectionListPtr aListAttr =
255 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
256 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
257 AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
258 ResultPtr aContext = aSelectionAttr->context();
259 if(!aContext.get() && !aSelectionAttr->contextFeature().get()) {
260 theError = "Error: Empty context.";
264 ResultConstructionPtr aResultConstruction =
265 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
266 if(!aResultConstruction.get()) {
267 // It is not a result construction.
268 // If shape is compound check that it contains only faces, edges or vertices.
269 GeomShapePtr aShape = aSelectionAttr->value();
271 if (aContext.get()) {
272 aShape = aContext->shape();
274 theError = "Error: Empty context.";
279 if(aShape->shapeType() == GeomAPI_Shape::COMPOUND) {
280 for(GeomAPI_ShapeIterator anIt(aShape); anIt.more(); anIt.next()) {
281 GeomShapePtr aSubShape = anIt.current();
282 if (aSubShape->shapeType() > GeomAPI_Shape::VERTEX ||
283 aSubShape->shapeType() < GeomAPI_Shape::FACE) {
284 theError = "Error: Compound should contain only faces, edges or vertices.";
293 GeomShapePtr aShape = aSelectionAttr->value();
294 GeomShapePtr aContextShape = aResultConstruction->shape();
296 // Whole sketch selected.
299 // Object from sketch selected.
300 for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
301 GeomShapePtr aWire = anExp.current();
302 if(aWire->orientation() != GeomAPI_Shape::FORWARD) {
303 theError = "Error: Wire with wrong orientation selected.";
307 if(aSelectedWiresFromObjects.isBound(aWire)) {
309 "Error: Objects with this wire already selected. Don't allow to select this object.";
313 aSelectedWiresFromObjects.bind(aWire, aWire);
322 //==================================================================================================
323 bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid(
324 const std::shared_ptr<ModelAPI_Feature>& theFeature,
325 const std::list<std::string>& theArguments,
326 Events_InfoMessage& theError) const
328 const std::string aBaseObjectsID = theArguments.front();
330 AttributeSelectionListPtr aListAttr = theFeature->selectionList(aBaseObjectsID);
331 if(!aListAttr.get()) {
333 theError = "Error: Could not get \"%1\" attribute.";
334 theError.arg(aBaseObjectsID);
339 std::set<ResultConstructionPtr> aSelectedSketches;
340 std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
342 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
343 AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
344 ResultPtr aContext = aSelectionAttr->context();
345 if(!aContext.get()) {
346 FeaturePtr aFeature = aSelectionAttr->contextFeature();
347 if (!aFeature.get() || aFeature->results().empty()) {
348 theError = "Error: Empty context.";
351 aContext = aFeature->firstResult();
355 ResultConstructionPtr aResultConstruction =
356 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
357 if(!aResultConstruction.get()) {
358 // It is not a result construction.
362 GeomShapePtr aShape = aSelectionAttr->value();
363 GeomShapePtr aContextShape = aResultConstruction->shape();
365 // Whole sketch selected.
366 aSelectedSketches.insert(aResultConstruction);
368 // Object from sketch selected.
369 aSelectedSketchesFromObjects.insert(aResultConstruction);
374 for(std::set<ResultConstructionPtr>::const_iterator anIt = aSelectedSketches.cbegin();
375 anIt != aSelectedSketches.cend();
377 ResultConstructionPtr aResultConstruction = *anIt;
378 if(aSelectedSketchesFromObjects.find(aResultConstruction) !=
379 aSelectedSketchesFromObjects.cend()) {
380 theError = "Sketch and objects from it can not be selected at the same time.";
388 //==================================================================================================
389 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
390 const std::list<std::string>& theArguments,
391 Events_InfoMessage& theError) const
393 if(!theAttribute.get()) {
395 theError = "Error: Empty attribute.";
400 std::string anAttributeType = theAttribute->attributeType();
401 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
402 AttributeSelectionListPtr aListAttr =
403 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
405 const std::string& aVersion = theAttribute->owner()->data()->version();
406 std::string aSelType;
407 if (!aVersion.empty())
408 aSelType = aListAttr->selectionType();
410 std::list<std::string> anApplicableTypes;
411 switch (GeomValidators_ShapeType::shapeType(aSelType)) {
412 case GeomValidators_ShapeType::Vertex:
413 anApplicableTypes.push_back("vertex");
415 case GeomValidators_ShapeType::Edge:
416 anApplicableTypes.push_back("edge");
417 anApplicableTypes.push_back("wire");
419 case GeomValidators_ShapeType::Face:
420 anApplicableTypes.push_back("face");
421 anApplicableTypes.push_back("shell");
422 // wire should not be the first in this list to be able to check
423 // the type of selection when evaluating shape by shape
424 anApplicableTypes.push_back("wire");
427 anApplicableTypes = theArguments;
431 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
432 // If at least one attribute is invalid, the result is false.
433 if(!isValidAttribute(aListAttr->value(anIndex), anApplicableTypes, theError)) {
437 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
439 AttributeSelectionPtr anAttr =
440 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
441 ResultPtr aContext = anAttr->context();
442 if(!aContext.get() && !anAttr->contextFeature().get()) {
443 theError = "Error: Attribute have empty context.";
447 GeomShapePtr aShape = anAttr->value();
448 GeomShapePtr aContextShape;
449 if(!aShape.get() && aContext.get()) {
450 aContextShape = aContext->shape();
451 aShape = aContextShape;
454 theError = "Error: Empty shape selected";
458 ResultConstructionPtr aConstruction;
459 if (!aContext.get() && anAttr->contextFeature()->results().size() == 1) {
460 aContext = anAttr->contextFeature()->firstResult();
463 aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
464 if(aConstruction.get()) {
465 // Construction selected. Check that it is not infinite.
466 if(aConstruction->isInfinite() && !aConstruction->shape()->isVertex()) {
467 theError = "Error: Infinite constructions is not allowed as base.";
471 aContextShape = aContext->shape();
472 if(aShape->isEqual(aContextShape)) {
473 // Whole construction selected. Check that it has faces.
474 if((theArguments.front() == "face" && aConstruction->facesNum() > 0) ||
475 theArguments.front() == "edge") {
479 // CUT operation supports only FACE or WIRE as a tool base
480 std::shared_ptr<FeaturesPlugin_CompositeBoolean> aComposite =
481 std::dynamic_pointer_cast<FeaturesPlugin_CompositeBoolean>(
482 ModelAPI_Feature::feature(theAttribute->owner()));
484 aComposite->operationType() == FeaturesPlugin_CompositeBoolean::BOOL_CUT) {
485 return aShape->shapeType() == GeomAPI_Shape::WIRE ||
486 aShape->shapeType() == GeomAPI_Shape::FACE;
491 if(!aConstruction && aContextShape.get() && !aShape->isEqual(aContextShape)) {
492 // Local selection on body does not allowed.
494 "Error: Selected shape is in the local selection. Only global selection is allowed.";
498 // Check that object is a shape with allowed type.
499 GeomValidators_ShapeType aShapeTypeValidator;
500 if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
501 theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or "
502 "wires on sketch, whole sketch (if it has at least one face), "
503 "and whole objects with shape types: %1";
504 std::string anArgumentString;
505 for(auto anIt = theArguments.cbegin(); anIt != theArguments.cend(); ++anIt) {
506 if (!anArgumentString.empty())
507 anArgumentString += ", ";
508 anArgumentString += *anIt;
510 theError.arg(anArgumentString);
516 theError = "Error: Attribute \"%1\" does not supported by this validator.";
517 theError.arg(anAttributeType);
525 //==================================================================================================
527 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
528 const std::list<std::string>& theArguments,
529 Events_InfoMessage& theError) const
531 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
532 theError = "Error: The attribute with the %1 type is not processed";
533 theError.arg(theAttribute->attributeType());
536 if (theArguments.size() != 2) {
537 theError = "Error: Wrong parameters in XML definition for %1 type";
538 theError.arg(theAttribute->attributeType());
541 // first argument is for the base attribute, second - for skipping feature kind
542 std::list<std::string>::const_iterator anIt = theArguments.begin();
543 std::string aBaseAttributeId = *anIt;
544 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
545 AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
546 if (!aBaseAttribute.get()) {
547 theError = "Wrong parameters in XML definition for %1 type";
548 theError.arg(theAttribute->attributeType());
551 if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
552 // this validator is not necessary anymore
556 std::string aFeatureAttributeKind = *anIt;
557 GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
558 // check whether the selection is on the sketch
559 std::list<std::string> anArguments;
560 anArguments.push_back(aFeatureAttributeKind);
562 bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);
563 bool aPlanarFace = false;
564 // check if selection has Face selected
565 GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
567 anArguments.push_back("face");
568 aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);
570 bool aValid = !aFeatureKind && aPlanarFace;
575 //==================================================================================================
576 bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
577 const std::shared_ptr<ModelAPI_Feature>& theFeature,
578 const std::list<std::string>& theArguments,
579 Events_InfoMessage& theError) const
581 if(theArguments.size() != 2) {
583 theError = "Error: Validator should be used with 2 parameters for extrusion.";
588 std::list<std::string>::const_iterator anArgsIt = theArguments.begin();
590 AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
593 GeomShapePtr aDirShape;
594 AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
596 aDirShape = aSelAttr->value();
597 if(!aDirShape.get()) {
598 ResultPtr aContext = aSelAttr->context();
599 if(!aContext.get()) {
600 FeaturePtr aFeature = aSelAttr->contextFeature();
601 if (aFeature.get() && !aFeature->results().empty()) {
602 aContext = aFeature->firstResult();
607 aDirShape = aContext->shape();
610 if (aDirShape.get() && aDirShape->isCompound()) {
611 GeomAPI_ShapeIterator anIt(aDirShape);
612 aDirShape = anIt.current();
617 if(!aDirShape.get() || aDirShape->isNull() ||
618 aDirShape->shapeType() != GeomAPI_Shape::EDGE) {
619 // Check that dir can be empty.
620 if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
621 theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" "
622 "can not be used with default value. Select direction for extrusion.";
623 theError.arg(*anArgsIt);
630 std::shared_ptr<GeomAPI_Edge> aDirEdge(new GeomAPI_Edge(aDirShape));
632 // If faces selected check that direction not parallel with them.
633 AttributeSelectionListPtr aListAttr =
634 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aCheckAttribute);
635 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
636 AttributeSelectionPtr anAttr = aListAttr->value(anIndex);
637 GeomShapePtr aShapeInList = anAttr->value();
638 if(!aShapeInList.get()) {
639 aShapeInList = anAttr->context()->shape();
641 bool isParallel = true;
642 if(aShapeInList->shapeType() == GeomAPI_Shape::FACE ||
643 aShapeInList->shapeType() == GeomAPI_Shape::SHELL) {
644 for(GeomAPI_ShapeExplorer
645 anExp(aShapeInList, GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
646 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(anExp.current()));
647 isParallel = GeomAlgoAPI_ShapeTools::isParallel(aDirEdge, aFace);
652 } else if(aShapeInList->shapeType() == GeomAPI_Shape::COMPOUND) {
653 std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges =
654 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapeInList);
655 if(aPlanarEdges.get()) {
656 std::shared_ptr<GeomAPI_Dir> aSketchDir = aPlanarEdges->norm();
657 if(aDirEdge->isLine()) {
658 std::shared_ptr<GeomAPI_Dir> aDir = aDirEdge->line()->direction();
659 isParallel = fabs(aSketchDir->angle(aDir) - M_PI / 2.0) < 10e-7;
671 "Error: Direction is parallel to one of the selected face or face on selected shell.";
679 //==================================================================================================
680 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
681 Events_InfoMessage& theError) const
684 if(!theAttribute.get()) {
689 std::string anAttributeType = theAttribute->attributeType();
690 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
691 AttributeSelectionListPtr aListAttr =
692 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
693 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
694 // If at least one attribute is invalid, the result is false.
695 if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) {
699 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
701 AttributeSelectionPtr anAttr =
702 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
703 ResultPtr aContext = anAttr->context();
704 if(!aContext.get() && !anAttr->contextFeature().get()) {
708 GeomShapePtr aShape = anAttr->value();
709 if(!aShape.get() && aContext.get()) {
710 GeomShapePtr aContextShape = aContext->shape();
711 aShape = aContextShape;
717 if(aShape->shapeType() == GeomAPI_Shape::VERTEX ||
718 aShape->shapeType() == GeomAPI_Shape::EDGE ||
719 !aShape->isPlanar()) {
729 //==================================================================================================
730 bool FeaturesPlugin_ValidatorExtrusionBoundaryFace::isValid(
731 const AttributePtr& theAttribute,
732 const std::list<std::string>& theArguments,
733 Events_InfoMessage& theError) const
735 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
737 // Collect all necessary attributes and try to build prism
740 AttributeSelectionListPtr aBaseShapeAttr =
741 aFeature->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
742 ListOfShape aBaseShapeList;
744 if (!FeaturesPlugin_Tools::getShape(aBaseShapeAttr, true, aBaseShapeList, anError)) {
750 AttributeSelectionPtr aSelection =
751 aFeature->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
752 GeomShapePtr aShape = aSelection->value();
753 if (!aShape.get() && aSelection->context().get())
754 aShape = aSelection->context()->shape();
758 if (aShape->isEdge())
759 anEdge = aShape->edge();
760 else if (aShape->isCompound()) {
761 GeomAPI_ShapeIterator anIt(aShape);
762 anEdge = anIt.current()->edge();
766 std::shared_ptr<GeomAPI_Dir> aDir;
767 if (anEdge.get() && anEdge->isLine())
768 aDir = anEdge->line()->direction();
771 GeomShapePtr aFromShape, aToShape;
772 aSelection = aFeature->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
773 if (aSelection.get()) {
774 aToShape = aSelection->value();
775 if (!aToShape.get() && aSelection->context().get())
776 aToShape = aSelection->context()->shape();
777 if (aToShape.get() && aToShape->isCompound()) {
778 GeomAPI_ShapeIterator anIt(aToShape);
779 aToShape = anIt.current();
781 if (aToShape.get() && !aToShape->isFace()) {
782 theError = "\"To\" shape is not a face";
786 aSelection = aFeature->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
787 if (aSelection.get()) {
788 aFromShape = aSelection->value();
789 if (!aFromShape.get() && aSelection->context().get())
790 aFromShape = aSelection->context()->shape();
791 if (aFromShape.get() && aFromShape->isCompound()) {
792 GeomAPI_ShapeIterator anIt(aFromShape);
793 aFromShape = anIt.current();
795 if (aFromShape.get() && !aFromShape->isFace()) {
796 theError = "\"From\" shape is not a face";
801 double aToSize = aFeature->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID())->value();
802 double aFromSize = aFeature->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID())->value();
805 for (ListOfShape::iterator anIt = aBaseShapeList.begin(); anIt != aBaseShapeList.end(); anIt++) {
806 std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIt;
808 std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(
809 new GeomAlgoAPI_Prism(aBaseShape, aDir, aToShape, aToSize, aFromShape, aFromSize));
810 bool isFailed = GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPrismAlgo,
811 FeaturesPlugin_Extrusion::ID(),
822 //==================================================================================================
823 bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
824 const std::list<std::string>& theArguments,
825 Events_InfoMessage& theError) const
827 AttributeSelectionListPtr anAttrSelectionList =
828 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
829 if(!anAttrSelectionList.get()) {
832 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
836 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
837 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theAttribute->owner());
838 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
840 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
841 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
842 if(!anAttrSelection.get()) {
843 theError = "Error: Empty attribute selection.";
846 ResultPtr aContext = anAttrSelection->context();
847 if(!aContext.get()) {
848 FeaturePtr aContFeat = anAttrSelection->contextFeature();
849 if (!aContFeat.get() || !aContFeat->results().size()) {
850 theError = "Error: Empty selection context.";
854 ResultConstructionPtr aResultConstruction =
855 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
856 if(aResultConstruction.get()) {
857 if (anOperationType != FeaturesPlugin_Boolean::BOOL_FILL
858 || theAttribute->id() != FeaturesPlugin_Boolean::TOOL_LIST_ID()) {
859 theError = "Error: Result construction not allowed for selection.";
863 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
864 if(!aShape.get() && aContext.get()) {
865 GeomShapePtr aContextShape = aContext->shape();
866 aShape = aContextShape;
869 theError = "Error: Empty shape.";
872 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
873 theError = "Error: Local selection not allowed.";
877 GeomAPI_Shape::ShapeType aShapeType = aShape->shapeType();
878 std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
879 if(anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE) {
880 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
881 anAllowedTypes.insert(GeomAPI_Shape::FACE);
882 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
883 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
884 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
885 } else if (anOperationType == FeaturesPlugin_Boolean::BOOL_FILL
886 || anOperationType == FeaturesPlugin_Boolean::BOOL_CUT)
888 anAllowedTypes.insert(GeomAPI_Shape::VERTEX);
889 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
890 anAllowedTypes.insert(GeomAPI_Shape::WIRE);
891 anAllowedTypes.insert(GeomAPI_Shape::FACE);
892 anAllowedTypes.insert(GeomAPI_Shape::SHELL);
893 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
894 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
895 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
897 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
898 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
899 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
902 if(anAllowedTypes.find(aShapeType) == anAllowedTypes.end()
903 || (aResultConstruction.get() && aShapeType != GeomAPI_Shape::FACE)) {
904 theError = "Error: Selected shape has the wrong type.";
913 //==================================================================================================
914 bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAttribute,
915 const std::list<std::string>& theArguments,
916 Events_InfoMessage& theError) const
918 AttributeSelectionListPtr anAttrSelectionList =
919 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
920 if(!anAttrSelectionList.get()) {
923 "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
928 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
929 // Check all selected entities are sub-shapes of single solid
930 GeomShapePtr aBaseSolid;
931 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
932 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
933 if(!anAttrSelection.get()) {
934 theError = "Error: Empty attribute selection.";
937 ResultPtr aContext = anAttrSelection->context();
938 if(!aContext.get()) {
939 FeaturePtr aContFeat = anAttrSelection->contextFeature();
940 if (!aContFeat.get() || !aContFeat->results().size() ||
941 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
942 theError = "Error: Empty selection context.";
945 if (aContFeat->results().size() == 1)
946 aContext = aContFeat->firstResult();
948 theError = "Error: Too many shapes selected.";
953 ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext, true);
954 GeomShapePtr anOwner = aContext->shape();
955 GeomShapePtr aTopLevelOwner = aContextOwner.get() ? aContextOwner->shape() : anOwner;
958 theError = "Error: wrong feature is selected.";
962 if (anOwner->shapeType() != GeomAPI_Shape::SOLID &&
963 anOwner->shapeType() != GeomAPI_Shape::COMPSOLID) {
964 theError = "Error: Not all selected shapes are sub-shapes of solids.";
969 aBaseSolid = aTopLevelOwner;
970 else if (!aBaseSolid->isEqual(aTopLevelOwner)) {
971 theError = "Error: Sub-shapes of different solids have been selected.";
980 //==================================================================================================
981 bool FeaturesPlugin_ValidatorFillet1DSelection::isValid(const AttributePtr& theAttribute,
982 const std::list<std::string>& theArguments,
983 Events_InfoMessage& theError) const
985 AttributeSelectionListPtr anAttrSelectionList =
986 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
987 if (!anAttrSelectionList.get()) {
990 "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
995 // check each selected vertex is a sharp corner between adjacent edges,
996 // and these edges are in the same plane
997 std::map<GeomShapePtr, MapShapeToShapes> aWireSubshapes;
998 int aNbSel = anAttrSelectionList->size();
999 for (int ind = 0; ind < aNbSel; ++ind) {
1000 AttributeSelectionPtr aCurSel = anAttrSelectionList->value(ind);
1001 GeomShapePtr aContext = aCurSel->context()->shape();
1002 GeomShapePtr aVertex = aCurSel->value();
1003 // check wire already processed, if not, store all vertices and edges, sharing them
1004 std::map<GeomShapePtr, MapShapeToShapes>::iterator aProcessed = aWireSubshapes.find(aContext);
1005 if (aProcessed == aWireSubshapes.end()) {
1006 if (aContext->shapeType() != GeomAPI_Shape::WIRE) {
1007 theError = "Selected vertex is not a wire corner";
1010 if (aVertex->shapeType() != GeomAPI_Shape::VERTEX) {
1011 theError = "Selected shape is not a vertex";
1015 GeomAlgoAPI_MapShapesAndAncestors aMapVE(aContext, GeomAPI_Shape::VERTEX,
1016 GeomAPI_Shape::EDGE);
1017 aWireSubshapes[aContext] = aMapVE.map();
1018 aProcessed = aWireSubshapes.find(aContext);
1022 MapShapeToShapes::iterator aFound = aProcessed->second.find(aVertex);
1023 if (aFound == aProcessed->second.end()) {
1024 theError = "Selected vertex does not exist in the wire";
1027 else if (aFound->second.size() != 2) {
1028 theError = "Vertex should be shared between 2 edges exactly";
1032 ListOfShape anEdges;
1033 anEdges.insert(anEdges.end(), aFound->second.begin(), aFound->second.end());
1034 GeomPlanePtr aPlane = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
1036 theError = "Error: Edges are not planar";
1040 GeomEdgePtr anEdge1(new GeomAPI_Edge(anEdges.front()));
1041 GeomEdgePtr anEdge2(new GeomAPI_Edge(anEdges.back()));
1042 GeomVertexPtr aSharedVertex(new GeomAPI_Vertex(aVertex));
1043 if (GeomAlgoAPI_ShapeTools::isTangent(anEdge1, anEdge2, aSharedVertex)) {
1044 theError = "Error: Edges are tangent";
1052 //==================================================================================================
1053 bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,
1054 const std::list<std::string>& theArguments,
1055 Events_InfoMessage& theError) const
1057 AttributeSelectionListPtr anAttrSelectionList =
1058 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1059 if(!anAttrSelectionList.get()) {
1061 theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
1066 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1067 AttributeSelectionPtr aSelectAttr = anAttrSelectionList->value(anIndex);
1069 //GeomValidators_BodyShapes aBodyValidator;
1070 //if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
1074 GeomValidators_FeatureKind aFeatureKindValidator;
1075 if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
1079 ResultPtr aContext = aSelectAttr->context();
1080 ResultConstructionPtr aResultConstruction =
1081 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1082 if(aResultConstruction.get()) {
1083 theError = "Error: Only body shapes and construction planes are allowed for selection.";
1087 ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
1088 if(aResultBody.get()) {
1091 FeaturePtr aResultFeature = aSelectAttr->contextFeature();
1092 if(aResultFeature.get()) {
1093 bool aOkRes = false;
1094 std::list<ResultPtr>::const_iterator aFRes = aResultFeature->results().cbegin();
1095 for(; aFRes != aResultFeature->results().cend() && !aOkRes; aFRes++) {
1096 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aFRes);
1097 if (aBody.get() && !aBody->isDisabled())
1104 theError = "Error: Only body shapes and construction planes are allowed for selection.";
1112 //==================================================================================================
1113 bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
1114 const std::list<std::string>& theArguments,
1115 Events_InfoMessage& theError) const
1117 AttributeSelectionListPtr aSubShapesAttrList =
1118 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1119 if(!aSubShapesAttrList.get()) {
1122 "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
1127 static const std::string aBaseShapeID = "base_shape";
1128 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
1129 AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
1131 if(!aShapeAttrSelection.get()) {
1133 theError = "Error: Could not get \"%1\" attribute.";
1134 theError.arg(aBaseShapeID);
1139 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
1140 ResultPtr aContext = aShapeAttrSelection->context();
1141 if(!aContext.get()) {
1142 theError = "Error: Empty context.";
1145 if(!aBaseShape.get()) {
1146 aBaseShape = aContext->shape();
1148 if(!aBaseShape.get()) {
1149 theError = "Error: Empty base shape.";
1153 std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
1154 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
1155 bool isSameFound = false;
1156 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
1157 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
1158 for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt)
1160 if ((*anIt)->isEqual(aShapeToAdd)) {
1166 theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
1174 //==================================================================================================
1175 bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
1176 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1177 const std::list<std::string>& theArguments,
1178 Events_InfoMessage& theError) const
1180 static const std::string aBaseShapeID = "base_shape";
1181 static const std::string aSubShapesID = "subshapes_to_keep";
1184 if(theFeature->getKind() != "Remove_SubShapes") {
1185 theError = "Error: Feature \"%1\" does not supported by this validator.";
1186 theError.arg(theFeature->getKind());
1190 AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
1191 if(!aShapeAttrSelection.get()) {
1192 theError = "Error: Could not get \"%1\" attribute.";
1193 theError.arg(aBaseShapeID);
1197 AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
1198 if(!aSubShapesAttrList.get()) {
1199 theError = "Error: Could not get \"%1\" attribute.";
1200 theError.arg(aSubShapesID);
1206 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
1207 if(!aBaseShape.get()) {
1208 theError = "Error: Base shape is empty.";
1211 GeomShapePtr aResultShape = aBaseShape->emptyCopied();
1213 if (aSubShapesAttrList->size() == 0) {
1214 theError = "Error: Resulting shape is not valid.";
1218 // Copy sub-shapes from list to new shape.
1219 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
1220 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
1221 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
1222 GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
1226 if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {
1227 theError = "Error: Resulting shape is not valid.";
1234 //==================================================================================================
1236 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
1237 const std::list<std::string>& theArguments,
1238 Events_InfoMessage& theError) const
1240 AttributeSelectionListPtr aBaseObjectsAttrList =
1241 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1242 if(!aBaseObjectsAttrList.get()) {
1243 theError = "Error: This validator can only work with selection list in \"%1\" feature.";
1244 theError.arg(FeaturesPlugin_Union::ID());
1248 for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
1249 AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
1250 ResultPtr aContext = anAttrSelectionInList->context();
1251 if (!aContext.get()) {
1252 theError = "Error: selection is invalid.";
1256 ResultConstructionPtr aConstruction =
1257 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1258 if(aConstruction.get()) {
1259 theError = "Error: Result construction not allowed for selection.";
1263 GeomShapePtr aShape = anAttrSelectionInList->value();
1264 GeomShapePtr aContextShape = aContext->shape();
1265 if (aShape.get() && aContextShape.get() && !aContextShape->isEqual(aShape)) {
1266 theError = "Error: Local selection not allowed.";
1270 ResultBodyPtr aResult =
1271 std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
1272 if(!aResult.get()) {
1276 if(aResult->numberOfSubs() > 0) {
1277 theError = "Error: Whole compsolids not allowed for selection.";
1286 //==================================================================================================
1287 bool FeaturesPlugin_ValidatorUnionArguments::isValid(
1288 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1289 const std::list<std::string>& theArguments,
1290 Events_InfoMessage& theError) const
1293 // Check feature kind.
1294 if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
1295 theError = "Error: This validator supports only \"%1\" feature.";
1296 theError.arg(FeaturesPlugin_Union::ID());
1300 // Get base objects attribute list.
1301 AttributeSelectionListPtr aBaseObejctsAttrList =
1302 theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1303 if(!aBaseObejctsAttrList.get()) {
1304 theError = "Error: Could not get \"%1\" attribute.";
1305 theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1311 GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPSOLID;
1312 ListOfShape aBaseShapesList;
1313 for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
1314 AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
1315 GeomShapePtr aShape = anAttrSelectionInList->value();
1316 if (!aShape.get()) {
1319 aBaseShapesList.push_back(aShape);
1320 aType = aShape->shapeType() == GeomAPI_Shape::FACE ? GeomAPI_Shape::SHELL :
1321 GeomAPI_Shape::COMPSOLID;
1324 // Make compound and find connected.
1325 GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
1326 ListOfShape aResults;
1327 GeomAlgoAPI_ShapeTools::combineShapes(aCompound, aType, aResults);
1329 if(aResults.size() > 1 || (aResults.size() == 1 && aResults.front()->shapeType() > aType)) {
1330 theError = "Error: Not all shapes have shared topology.";
1337 bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute,
1338 const std::list<std::string>& theArguments,
1339 Events_InfoMessage& theError) const
1341 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1343 theError = "Error: The attribute with the %1 type is not processed";
1344 theError.arg(theAttribute->attributeType());
1349 AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeReference>
1351 ObjectPtr aRefObject = aRefAttribute->value();
1352 if (!aRefObject.get()) {
1353 theError = "Error: Empty feature.";
1357 FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aRefObject);
1358 if (!aRefFeature.get()) {
1359 theError = "Error: Empty feature.";
1362 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
1363 ModelAPI_Tools::getConcealedResults(aRefFeature, aResults);
1365 size_t aConcealedResults = aResults.size();
1366 if (!aConcealedResults && !theArguments.empty()) {
1367 // find if these results are touched by the feature in another attribute
1368 std::list<std::string>::const_iterator anIt = theArguments.begin();
1369 std::string aRecoveredList = *anIt;
1370 if (!aRecoveredList.empty()) {
1371 std::shared_ptr<ModelAPI_AttributeRefList> aParameterList =
1372 theAttribute->owner()->data()->reflist(aRecoveredList);
1373 if (aParameterList.get())
1374 aConcealedResults = aParameterList->size();
1378 if (aConcealedResults == 0)
1379 theError = "Error: No concealed results.";
1381 return theError.empty();
1384 bool FeaturesPlugin_ValidatorCircular::isValid(const AttributePtr& theAttribute,
1385 const std::list<std::string>& theArguments,
1386 Events_InfoMessage& theError) const
1388 static std::list<std::string> aEdgeArg(1, "circle");
1389 static std::list<std::string> aFaceArg(1, "cylinder");
1391 Events_InfoMessage aError;
1392 bool isValid = GeomValidators_ShapeType().isValid(theAttribute, aEdgeArg, aError);
1394 isValid = GeomValidators_Face().isValid(theAttribute, aFaceArg, aError);
1396 theError = "The shape neither circle nor cylinder";
1401 //=================================================================================================
1402 bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
1403 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1404 const std::list<std::string>& theArguments,
1405 Events_InfoMessage& theError) const
1408 if (theArguments.size() != 2)
1410 theError = "Wrong number of arguments (expected 2).";
1415 int anObjectsToolsNb[2] = { 0, 0 };
1417 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1419 bool isAllInSameCompSolid = true;
1420 ResultBodyPtr aCompSolid;
1422 for (int* anArgNbIt = anObjectsToolsNb; anIt != aLast; ++anIt, ++anArgNbIt) {
1423 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1426 *anArgNbIt = anAttrSelList->size();
1427 if (isAllInSameCompSolid) {
1428 for (int anIndex = 0; anIndex < *anArgNbIt; ++anIndex)
1430 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1431 ResultPtr aContext = anAttr->context();
1432 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1433 if (aResCompSolidPtr.get())
1435 if (aCompSolid.get())
1437 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1441 aCompSolid = aResCompSolidPtr;
1446 isAllInSameCompSolid = false;
1454 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
1455 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theFeature);
1456 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
1458 if (anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE)
1461 if (anObjectsToolsNb[0] + anObjectsToolsNb[1] < 2)
1463 theError = "Not enough arguments for Fuse operation.";
1466 else if (isAllInSameCompSolid)
1468 theError = "Operations only between sub-shapes of the same shape not allowed.";
1474 if (anObjectsToolsNb[0] < 1) // check number of objects
1476 theError = "Objects not selected.";
1479 if (anObjectsToolsNb[1] < 1) // check number of tools
1481 theError = "Tools not selected.";
1484 if (isAllInSameCompSolid)
1486 theError = "Operations only between sub-shapes of the same shape not allowed.";
1494 //=================================================================================================
1496 bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFeature,
1497 std::string theAttribute)
1499 if (theAttribute == "main_objects" || theAttribute == "tool_objects")
1508 //==================================================================================================
1509 bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
1510 const AttributePtr& theAttribute,
1511 const std::list<std::string>& theArguments,
1512 Events_InfoMessage& theError) const
1514 std::shared_ptr<FeaturesPlugin_BooleanSmash> aFeature =
1515 std::dynamic_pointer_cast<FeaturesPlugin_BooleanSmash>(theAttribute->owner());
1517 AttributeSelectionListPtr anAttrSelectionList =
1518 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1519 if (!aFeature.get() || !anAttrSelectionList.get()) {
1522 "Error: Validator used in wrong feature or attribute";
1527 AttributeSelectionListPtr anOtherAttrSelectionList;
1528 if (theAttribute->id() == FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID()) {
1529 anOtherAttrSelectionList =
1530 aFeature->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
1532 anOtherAttrSelectionList =
1533 aFeature->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
1536 GeomAPI_Shape::ShapeType aSelectedShapesType = GeomAPI_Shape::SHAPE;
1537 GeomAPI_DataMapOfShapeShape aSelectedCompSolidsInOtherList;
1538 GeomPlanePtr aFacesPln;
1540 for (int anIndex = 0; anIndex < anOtherAttrSelectionList->size(); ++anIndex) {
1541 AttributeSelectionPtr anAttrSelection = anOtherAttrSelectionList->value(anIndex);
1543 if (anAttrSelection->contextFeature().get()) {
1544 theError = "Error: Features not allowed for selection.";
1548 ResultPtr aContext = anAttrSelection->context();
1549 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1550 if (!aShape.get()) {
1551 if (!aContext.get()) {
1552 theError = "Error: Empty selection.";
1555 aShape = aContext->shape();
1558 if (aShape->isSolid() || aShape->isCompSolid()) {
1559 aSelectedShapesType = GeomAPI_Shape::SOLID;
1560 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1561 if (aResCompSolidPtr.get()) {
1562 GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
1563 aSelectedCompSolidsInOtherList.bind(aCompSolidShape, aCompSolidShape);
1566 aSelectedShapesType = GeomAPI_Shape::FACE;
1567 GeomAPI_Face aFace(aShape);
1568 aFacesPln = aFace.getPlane();
1573 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1574 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1575 if (!anAttrSelection.get()) {
1576 theError = "Error: Empty attribute selection.";
1580 if (anAttrSelection->contextFeature().get()) {
1581 theError = "Error: Features not allowed for selection.";
1585 ResultPtr aContext = anAttrSelection->context();
1586 if(!aContext.get()) {
1587 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1588 if (!aContFeat.get() || !aContFeat->results().size() ||
1589 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1590 theError = "Error: Empty selection context.";
1594 ResultConstructionPtr aResultConstruction =
1595 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1596 if (aResultConstruction.get()) {
1597 theError = "Error: Result construction not allowed for selection.";
1600 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1601 GeomShapePtr aContextShape = aContext->shape();
1602 if (!aShape.get()) {
1603 aShape = aContextShape;
1605 if (!aShape.get()) {
1606 theError = "Error: Empty shape.";
1609 if (!aShape->isEqual(aContextShape)) {
1610 theError = "Error: Local selection not allowed.";
1614 if (aSelectedShapesType == GeomAPI_Shape::SHAPE) {
1615 // Other list is empty.
1616 if (aShape->isSolid() || aShape->isCompSolid()) {
1617 aSelectedShapesType = GeomAPI_Shape::SOLID;
1619 aSelectedShapesType = GeomAPI_Shape::FACE;
1620 GeomAPI_Face aFace(aShape);
1621 aFacesPln = aFace.getPlane();
1623 if (!aFacesPln.get()) {
1624 theError = "Error: Only planar faces allowed.";
1630 } else if (aSelectedShapesType == GeomAPI_Shape::SOLID) {
1631 if (!aShape->isSolid() && !aShape->isCompSolid()) {
1632 theError = "Error: Selected shapes should have the same type.";
1636 GeomAPI_Face aFace(aShape);
1637 GeomPlanePtr aPln = aFace.getPlane();
1640 theError = "Error: Only planar faces allowed.";
1644 if (!aFacesPln->isCoincident(aPln)) {
1645 theError = "Error: Only coincident faces allowed.";
1654 //==================================================================================================
1656 bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
1657 const std::list<std::string>& theArguments,
1658 Events_InfoMessage& theError) const
1660 if (!theAttribute.get()) {
1661 theError = "Error: empty selection.";
1664 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
1665 AttributeSelectionListPtr anAttrSelectionList =
1666 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
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()) {
1675 aFeature = ModelAPI_Feature::feature(aContext);
1677 aFeature = anAttrSelection->contextFeature();
1678 if (!aFeature.get() || !aFeature->results().size() ||
1679 aFeature->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1680 theError = "Error: Empty selection context.";
1684 if (!aFeature.get()) {
1685 theError = "Error: empty feature.";
1688 std::string aFeatureKind = aFeature->getKind();
1689 if (aFeatureKind == "Sketch" ||
1690 aFeatureKind == "Plane" ||
1691 aFeatureKind == "Axis") {
1692 theError = "Error: %1 shape is not allowed for selection.";
1693 theError.arg(aFeatureKind);
1696 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1697 if (!aShape.get()) {
1698 GeomShapePtr aContextShape = aContext->shape();
1699 aShape = aContextShape;
1701 if (!aShape.get()) {
1702 theError = "Error: empty shape.";
1705 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1706 theError = "Error: Local selection not allowed.";
1710 int aShapeType = aShape->shapeType();
1711 // Allow to select edges, faces and solids.
1712 if (aShapeType != GeomAPI_Shape::EDGE &&
1713 aShapeType != GeomAPI_Shape::FACE &&
1714 aShapeType != GeomAPI_Shape::SOLID &&
1715 aShapeType != GeomAPI_Shape::COMPSOLID &&
1716 aShapeType != GeomAPI_Shape::COMPOUND) {
1717 theError = "Error: selected shape has the wrong type.";
1726 //==================================================================================================
1728 bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid(
1729 const AttributePtr& theAttribute,
1730 const std::list<std::string>& theArguments,
1731 Events_InfoMessage& theError) const
1733 AttributeSelectionListPtr anAttrSelectionList =
1734 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1735 if (!anAttrSelectionList.get()) {
1737 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1741 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1742 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1743 if (!anAttrSelection.get()) {
1744 theError = "Error: Empty attribute selection.";
1747 ResultPtr aContext = anAttrSelection->context();
1748 if(!aContext.get()) {
1749 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1750 if (!aContFeat.get() || !aContFeat->results().size() ||
1751 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1752 theError = "Error: Empty selection context.";
1756 ResultConstructionPtr aResultConstruction =
1757 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1758 if (aResultConstruction.get()) {
1759 theError = "Error: Result construction not allowed for selection.";
1762 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1763 if (!aShape.get()) {
1764 GeomShapePtr aContextShape = aContext->shape();
1765 aShape = aContextShape;
1767 if (!aShape.get()) {
1768 theError = "Error: Empty shape.";
1771 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1772 theError = "Error: Local selection not allowed.";
1781 //=================================================================================================
1782 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
1783 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1784 const std::list<std::string>& theArguments,
1785 Events_InfoMessage& theError) const
1788 if (theArguments.size() != 2) {
1789 theError = "Wrong number of arguments (expected 2).";
1794 std::shared_ptr<FeaturesPlugin_BooleanFuse> aFeature =
1795 std::dynamic_pointer_cast<FeaturesPlugin_BooleanFuse>(theFeature);
1797 int anObjectsNb = 0, aToolsNb = 0;
1799 std::list<std::string>::const_iterator anIt = theArguments.begin();
1801 bool isAllInSameCompSolid = true;
1802 ResultBodyPtr aCompSolid;
1804 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1805 if (anAttrSelList) {
1806 anObjectsNb = anAttrSelList->size();
1807 for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
1808 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1809 ResultPtr aContext = anAttr->context();
1810 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1811 if (aResCompSolidPtr.get()) {
1812 if (aCompSolid.get()) {
1813 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1815 aCompSolid = aResCompSolidPtr;
1818 isAllInSameCompSolid = false;
1825 if (aFeature->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD())->value()
1826 == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
1827 anAttrSelList = theFeature->selectionList(*anIt);
1828 if (anAttrSelList) {
1829 aToolsNb = anAttrSelList->size();
1830 if (isAllInSameCompSolid) {
1831 for (int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
1832 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1833 ResultPtr aContext = anAttr->context();
1834 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1835 if (aResCompSolidPtr.get()) {
1836 if (aCompSolid.get()) {
1837 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1839 aCompSolid = aResCompSolidPtr;
1842 isAllInSameCompSolid = false;
1850 if (anObjectsNb + aToolsNb < 2) {
1851 theError = "Not enough arguments for Fuse operation.";
1858 //=================================================================================================
1860 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory(
1861 std::string theFeature,
1862 std::string theAttribute)
1864 if (theAttribute == "main_objects" || theAttribute == "tool_objects") {
1872 //==================================================================================================
1874 bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
1875 const AttributePtr& theAttribute,
1876 const std::list<std::string>& theArguments,
1877 Events_InfoMessage& theError) const
1879 AttributeSelectionListPtr anAttrSelectionList =
1880 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1881 if (!anAttrSelectionList.get()) {
1883 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1887 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1888 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1889 if (!anAttrSelection.get()) {
1890 theError = "Error: Empty attribute selection.";
1893 ResultPtr aContext = anAttrSelection->context();
1894 if (!aContext.get() && !anAttrSelection->contextFeature().get()) {
1895 theError = "Error: Empty selection context.";
1898 ResultConstructionPtr aResultConstruction =
1899 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1900 if (aResultConstruction.get()) {
1901 if (theAttribute->id() != FeaturesPlugin_BooleanCommon::TOOL_LIST_ID()) {
1902 theError = "Error: Result construction not allowed for selection.";
1906 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1907 GeomShapePtr aContextShape;
1908 if (aContext.get()) {
1909 aContextShape = aContext->shape();
1911 if (!aShape.get()) {
1912 aShape = aContextShape;
1914 if (!aShape.get()) {
1915 theError = "Error: Empty shape.";
1918 if (aContextShape.get() && !aShape->isEqual(aContextShape)) {
1919 theError = "Error: Local selection not allowed.";
1923 if (aResultConstruction.get() && aShape->shapeType() != GeomAPI_Shape::FACE) {
1924 theError = "Error: Result construction should be plane.";
1933 //=================================================================================================
1934 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
1935 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1936 const std::list<std::string>& theArguments,
1937 Events_InfoMessage& theError) const
1939 if (theArguments.size() != 2) {
1941 theError = "Wrong number of arguments (expected 2).";
1946 std::shared_ptr<FeaturesPlugin_BooleanCommon> aFeature =
1947 std::dynamic_pointer_cast<FeaturesPlugin_BooleanCommon>(theFeature);
1949 int anObjectsNb = 0, aToolsNb = 0;
1951 std::list<std::string>::const_iterator anIt = theArguments.begin();
1953 ResultBodyPtr aCompSolid;
1955 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1956 if (anAttrSelList) {
1957 anObjectsNb = anAttrSelList->size();
1960 bool isSimpleMode = aFeature->string(FeaturesPlugin_BooleanCommon::CREATION_METHOD())->value()
1961 == FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE();
1963 if (!isSimpleMode) {
1964 anAttrSelList = theFeature->selectionList(*anIt);
1965 if (anAttrSelList) {
1966 aToolsNb = anAttrSelList->size();
1970 if ((isSimpleMode && anObjectsNb < 2)
1971 || (!isSimpleMode && (anObjectsNb == 0 || aToolsNb == 0))) {
1972 theError = "Not enough arguments for Fuse operation.";
1978 //=================================================================================================
1980 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isNotObligatory(
1981 std::string theFeature,
1982 std::string theAttribute)
1988 //==================================================================================================
1989 bool FeaturesPlugin_ValidatorDefeaturingSelection::isValid(
1990 const AttributePtr& theAttribute,
1991 const std::list<std::string>& theArguments,
1992 Events_InfoMessage& theError) const
1994 AttributeSelectionListPtr anAttrSelectionList =
1995 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1996 if (!anAttrSelectionList.get()) {
1998 theError = "Error: This validator can only work with selection list attributes.";
2003 // Check selected entities are sub-shapes of solid or compsolid
2004 GeomShapePtr aBaseSolid;
2005 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
2006 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
2007 if (!anAttrSelection.get()) {
2008 theError = "Error: Empty attribute selection.";
2011 ResultPtr aContext = anAttrSelection->context();
2012 if (!aContext.get()) {
2013 theError = "Error: Empty selection context.";
2017 GeomShapePtr aContextShape = aContext->shape();
2018 if (aContextShape->shapeType() != GeomAPI_Shape::SOLID) {
2019 theError = "Error: Not all selected shapes are sub-shapes of solids.";