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& aSelType = aListAttr->selectionType();
406 std::list<std::string> anApplicableTypes;
407 switch (GeomValidators_ShapeType::shapeType(aSelType)) {
408 case GeomValidators_ShapeType::Vertex:
409 anApplicableTypes.push_back("vertex");
411 case GeomValidators_ShapeType::Edge:
412 anApplicableTypes.push_back("edge");
413 anApplicableTypes.push_back("wire");
415 case GeomValidators_ShapeType::Face:
416 anApplicableTypes.push_back("face");
417 anApplicableTypes.push_back("shell");
418 // wire should not be the first in this list to be able to check
419 // the type of selection when evaluating shape by shape
420 anApplicableTypes.push_back("wire");
423 anApplicableTypes = theArguments;
427 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
428 // If at least one attribute is invalid, the result is false.
429 if(!isValidAttribute(aListAttr->value(anIndex), anApplicableTypes, theError)) {
433 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
435 AttributeSelectionPtr anAttr =
436 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
437 ResultPtr aContext = anAttr->context();
438 if(!aContext.get() && !anAttr->contextFeature().get()) {
439 theError = "Error: Attribute have empty context.";
443 GeomShapePtr aShape = anAttr->value();
444 GeomShapePtr aContextShape;
445 if(!aShape.get() && aContext.get()) {
446 aContextShape = aContext->shape();
447 aShape = aContextShape;
450 theError = "Error: Empty shape selected";
454 ResultConstructionPtr aConstruction;
455 if (!aContext.get() && anAttr->contextFeature()->results().size() == 1) {
456 aContext = anAttr->contextFeature()->firstResult();
459 aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
460 if(aConstruction.get()) {
461 // Construction selected. Check that it is not infinite.
462 if(aConstruction->isInfinite() && !aConstruction->shape()->isVertex()) {
463 theError = "Error: Infinite constructions is not allowed as base.";
467 aContextShape = aContext->shape();
468 if(aShape->isEqual(aContextShape)) {
469 // Whole construction selected. Check that it has faces.
470 if((theArguments.front() == "face" && aConstruction->facesNum() > 0) ||
471 theArguments.front() == "edge") {
475 // CUT operation supports only FACE or WIRE as a tool base
476 std::shared_ptr<FeaturesPlugin_CompositeBoolean> aComposite =
477 std::dynamic_pointer_cast<FeaturesPlugin_CompositeBoolean>(
478 ModelAPI_Feature::feature(theAttribute->owner()));
480 aComposite->operationType() == FeaturesPlugin_CompositeBoolean::BOOL_CUT) {
481 return aShape->shapeType() == GeomAPI_Shape::WIRE ||
482 aShape->shapeType() == GeomAPI_Shape::FACE;
487 if(!aConstruction && aContextShape.get() && !aShape->isEqual(aContextShape)) {
488 // Local selection on body does not allowed.
490 "Error: Selected shape is in the local selection. Only global selection is allowed.";
494 // Check that object is a shape with allowed type.
495 GeomValidators_ShapeType aShapeTypeValidator;
496 if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
497 theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or "
498 "wires on sketch, whole sketch (if it has at least one face), "
499 "and whole objects with shape types: %1";
500 std::string anArgumentString;
501 for(auto anIt = theArguments.cbegin(); anIt != theArguments.cend(); ++anIt) {
502 if (!anArgumentString.empty())
503 anArgumentString += ", ";
504 anArgumentString += *anIt;
506 theError.arg(anArgumentString);
512 theError = "Error: Attribute \"%1\" does not supported by this validator.";
513 theError.arg(anAttributeType);
521 //==================================================================================================
523 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
524 const std::list<std::string>& theArguments,
525 Events_InfoMessage& theError) const
527 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
528 theError = "Error: The attribute with the %1 type is not processed";
529 theError.arg(theAttribute->attributeType());
532 if (theArguments.size() != 2) {
533 theError = "Error: Wrong parameters in XML definition for %1 type";
534 theError.arg(theAttribute->attributeType());
537 // first argument is for the base attribute, second - for skipping feature kind
538 std::list<std::string>::const_iterator anIt = theArguments.begin();
539 std::string aBaseAttributeId = *anIt;
540 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
541 AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
542 if (!aBaseAttribute.get()) {
543 theError = "Wrong parameters in XML definition for %1 type";
544 theError.arg(theAttribute->attributeType());
547 if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
548 // this validator is not necessary anymore
552 std::string aFeatureAttributeKind = *anIt;
553 GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
554 // check whether the selection is on the sketch
555 std::list<std::string> anArguments;
556 anArguments.push_back(aFeatureAttributeKind);
558 bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);
559 bool aPlanarFace = false;
560 // check if selection has Face selected
561 GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
563 anArguments.push_back("face");
564 aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);
566 bool aValid = !aFeatureKind && aPlanarFace;
571 //==================================================================================================
572 bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
573 const std::shared_ptr<ModelAPI_Feature>& theFeature,
574 const std::list<std::string>& theArguments,
575 Events_InfoMessage& theError) const
577 if(theArguments.size() != 2) {
579 theError = "Error: Validator should be used with 2 parameters for extrusion.";
584 std::list<std::string>::const_iterator anArgsIt = theArguments.begin();
586 AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
589 GeomShapePtr aDirShape;
590 AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
592 aDirShape = aSelAttr->value();
593 if(!aDirShape.get()) {
594 ResultPtr aContext = aSelAttr->context();
595 if(!aContext.get()) {
596 FeaturePtr aFeature = aSelAttr->contextFeature();
597 if (aFeature.get() && !aFeature->results().empty()) {
598 aContext = aFeature->firstResult();
603 aDirShape = aContext->shape();
606 if (aDirShape.get() && aDirShape->isCompound()) {
607 GeomAPI_ShapeIterator anIt(aDirShape);
608 aDirShape = anIt.current();
613 if(!aDirShape.get() || aDirShape->isNull() ||
614 aDirShape->shapeType() != GeomAPI_Shape::EDGE) {
615 // Check that dir can be empty.
616 if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
617 theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" "
618 "can not be used with default value. Select direction for extrusion.";
619 theError.arg(*anArgsIt);
626 std::shared_ptr<GeomAPI_Edge> aDirEdge(new GeomAPI_Edge(aDirShape));
628 // If faces selected check that direction not parallel with them.
629 AttributeSelectionListPtr aListAttr =
630 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aCheckAttribute);
631 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
632 AttributeSelectionPtr anAttr = aListAttr->value(anIndex);
633 GeomShapePtr aShapeInList = anAttr->value();
634 if(!aShapeInList.get()) {
635 aShapeInList = anAttr->context()->shape();
637 bool isParallel = true;
638 if(aShapeInList->shapeType() == GeomAPI_Shape::FACE ||
639 aShapeInList->shapeType() == GeomAPI_Shape::SHELL) {
640 for(GeomAPI_ShapeExplorer
641 anExp(aShapeInList, GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
642 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(anExp.current()));
643 isParallel = GeomAlgoAPI_ShapeTools::isParallel(aDirEdge, aFace);
648 } else if(aShapeInList->shapeType() == GeomAPI_Shape::COMPOUND) {
649 std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges =
650 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapeInList);
651 if(aPlanarEdges.get()) {
652 std::shared_ptr<GeomAPI_Dir> aSketchDir = aPlanarEdges->norm();
653 if(aDirEdge->isLine()) {
654 std::shared_ptr<GeomAPI_Dir> aDir = aDirEdge->line()->direction();
655 isParallel = fabs(aSketchDir->angle(aDir) - M_PI / 2.0) < 10e-7;
667 "Error: Direction is parallel to one of the selected face or face on selected shell.";
675 //==================================================================================================
676 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
677 Events_InfoMessage& theError) const
680 if(!theAttribute.get()) {
685 std::string anAttributeType = theAttribute->attributeType();
686 if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
687 AttributeSelectionListPtr aListAttr =
688 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
689 for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
690 // If at least one attribute is invalid, the result is false.
691 if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) {
695 } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
697 AttributeSelectionPtr anAttr =
698 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
699 ResultPtr aContext = anAttr->context();
700 if(!aContext.get() && !anAttr->contextFeature().get()) {
704 GeomShapePtr aShape = anAttr->value();
705 if(!aShape.get() && aContext.get()) {
706 GeomShapePtr aContextShape = aContext->shape();
707 aShape = aContextShape;
713 if(aShape->shapeType() == GeomAPI_Shape::VERTEX ||
714 aShape->shapeType() == GeomAPI_Shape::EDGE ||
715 !aShape->isPlanar()) {
725 //==================================================================================================
726 bool FeaturesPlugin_ValidatorExtrusionBoundaryFace::isValid(
727 const AttributePtr& theAttribute,
728 const std::list<std::string>& theArguments,
729 Events_InfoMessage& theError) const
731 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
733 // Collect all necessary attributes and try to build prism
736 AttributeSelectionListPtr aBaseShapeAttr =
737 aFeature->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
738 ListOfShape aBaseShapeList;
740 if (!FeaturesPlugin_Tools::getShape(aBaseShapeAttr, true, aBaseShapeList, anError)) {
746 AttributeSelectionPtr aSelection =
747 aFeature->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
748 GeomShapePtr aShape = aSelection->value();
749 if (!aShape.get() && aSelection->context().get())
750 aShape = aSelection->context()->shape();
754 if (aShape->isEdge())
755 anEdge = aShape->edge();
756 else if (aShape->isCompound()) {
757 GeomAPI_ShapeIterator anIt(aShape);
758 anEdge = anIt.current()->edge();
762 std::shared_ptr<GeomAPI_Dir> aDir;
763 if (anEdge.get() && anEdge->isLine())
764 aDir = anEdge->line()->direction();
767 GeomShapePtr aFromShape, aToShape;
768 aSelection = aFeature->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
769 if (aSelection.get()) {
770 aToShape = aSelection->value();
771 if (!aToShape.get() && aSelection->context().get())
772 aToShape = aSelection->context()->shape();
773 if (aToShape.get() && aToShape->isCompound()) {
774 GeomAPI_ShapeIterator anIt(aToShape);
775 aToShape = anIt.current();
777 if (aToShape.get() && !aToShape->isFace()) {
778 theError = "\"To\" shape is not a face";
782 aSelection = aFeature->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
783 if (aSelection.get()) {
784 aFromShape = aSelection->value();
785 if (!aFromShape.get() && aSelection->context().get())
786 aFromShape = aSelection->context()->shape();
787 if (aFromShape.get() && aFromShape->isCompound()) {
788 GeomAPI_ShapeIterator anIt(aFromShape);
789 aFromShape = anIt.current();
791 if (aFromShape.get() && !aFromShape->isFace()) {
792 theError = "\"From\" shape is not a face";
797 double aToSize = aFeature->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID())->value();
798 double aFromSize = aFeature->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID())->value();
801 for (ListOfShape::iterator anIt = aBaseShapeList.begin(); anIt != aBaseShapeList.end(); anIt++) {
802 std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIt;
804 std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(
805 new GeomAlgoAPI_Prism(aBaseShape, aDir, aToShape, aToSize, aFromShape, aFromSize));
806 bool isFailed = GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPrismAlgo,
807 FeaturesPlugin_Extrusion::ID(),
818 //==================================================================================================
819 bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
820 const std::list<std::string>& theArguments,
821 Events_InfoMessage& theError) const
823 AttributeSelectionListPtr anAttrSelectionList =
824 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
825 if(!anAttrSelectionList.get()) {
828 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
832 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
833 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theAttribute->owner());
834 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
836 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
837 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
838 if(!anAttrSelection.get()) {
839 theError = "Error: Empty attribute selection.";
842 ResultPtr aContext = anAttrSelection->context();
843 if(!aContext.get()) {
844 FeaturePtr aContFeat = anAttrSelection->contextFeature();
845 if (!aContFeat.get() || !aContFeat->results().size()) {
846 theError = "Error: Empty selection context.";
850 ResultConstructionPtr aResultConstruction =
851 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
852 if(aResultConstruction.get()) {
853 if (anOperationType != FeaturesPlugin_Boolean::BOOL_FILL
854 || theAttribute->id() != FeaturesPlugin_Boolean::TOOL_LIST_ID()) {
855 theError = "Error: Result construction not allowed for selection.";
859 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
860 if(!aShape.get() && aContext.get()) {
861 GeomShapePtr aContextShape = aContext->shape();
862 aShape = aContextShape;
865 theError = "Error: Empty shape.";
868 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
869 theError = "Error: Local selection not allowed.";
873 GeomAPI_Shape::ShapeType aShapeType = aShape->shapeType();
874 std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
875 if(anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE) {
876 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
877 anAllowedTypes.insert(GeomAPI_Shape::FACE);
878 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
879 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
880 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
881 } else if (anOperationType == FeaturesPlugin_Boolean::BOOL_FILL
882 || anOperationType == FeaturesPlugin_Boolean::BOOL_CUT)
884 anAllowedTypes.insert(GeomAPI_Shape::VERTEX);
885 anAllowedTypes.insert(GeomAPI_Shape::EDGE);
886 anAllowedTypes.insert(GeomAPI_Shape::WIRE);
887 anAllowedTypes.insert(GeomAPI_Shape::FACE);
888 anAllowedTypes.insert(GeomAPI_Shape::SHELL);
889 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
890 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
891 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
893 anAllowedTypes.insert(GeomAPI_Shape::SOLID);
894 anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
895 anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
898 if(anAllowedTypes.find(aShapeType) == anAllowedTypes.end()
899 || (aResultConstruction.get() && aShapeType != GeomAPI_Shape::FACE)) {
900 theError = "Error: Selected shape has the wrong type.";
909 //==================================================================================================
910 bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAttribute,
911 const std::list<std::string>& theArguments,
912 Events_InfoMessage& theError) const
914 AttributeSelectionListPtr anAttrSelectionList =
915 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
916 if(!anAttrSelectionList.get()) {
919 "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
924 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
925 // Check all selected entities are sub-shapes of single solid
926 GeomShapePtr aBaseSolid;
927 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
928 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
929 if(!anAttrSelection.get()) {
930 theError = "Error: Empty attribute selection.";
933 ResultPtr aContext = anAttrSelection->context();
934 if(!aContext.get()) {
935 FeaturePtr aContFeat = anAttrSelection->contextFeature();
936 if (!aContFeat.get() || !aContFeat->results().size() ||
937 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
938 theError = "Error: Empty selection context.";
941 if (aContFeat->results().size() == 1)
942 aContext = aContFeat->firstResult();
944 theError = "Error: Too many shapes selected.";
949 ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext, true);
950 GeomShapePtr anOwner = aContext->shape();
951 GeomShapePtr aTopLevelOwner = aContextOwner.get() ? aContextOwner->shape() : anOwner;
954 theError = "Error: wrong feature is selected.";
958 if (anOwner->shapeType() != GeomAPI_Shape::SOLID &&
959 anOwner->shapeType() != GeomAPI_Shape::COMPSOLID) {
960 theError = "Error: Not all selected shapes are sub-shapes of solids.";
965 aBaseSolid = aTopLevelOwner;
966 else if (!aBaseSolid->isEqual(aTopLevelOwner)) {
967 theError = "Error: Sub-shapes of different solids have been selected.";
976 //==================================================================================================
977 bool FeaturesPlugin_ValidatorFillet1DSelection::isValid(const AttributePtr& theAttribute,
978 const std::list<std::string>& theArguments,
979 Events_InfoMessage& theError) const
981 AttributeSelectionListPtr anAttrSelectionList =
982 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
983 if (!anAttrSelectionList.get()) {
986 "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
991 // check each selected vertex is a sharp corner between adjacent edges,
992 // and these edges are in the same plane
993 std::map<GeomShapePtr, MapShapeToShapes> aWireSubshapes;
994 int aNbSel = anAttrSelectionList->size();
995 for (int ind = 0; ind < aNbSel; ++ind) {
996 AttributeSelectionPtr aCurSel = anAttrSelectionList->value(ind);
997 GeomShapePtr aContext = aCurSel->context()->shape();
998 GeomShapePtr aVertex = aCurSel->value();
999 // check wire already processed, if not, store all vertices and edges, sharing them
1000 std::map<GeomShapePtr, MapShapeToShapes>::iterator aProcessed = aWireSubshapes.find(aContext);
1001 if (aProcessed == aWireSubshapes.end()) {
1002 if (aContext->shapeType() != GeomAPI_Shape::WIRE) {
1003 theError = "Selected vertex is not a wire corner";
1006 if (aVertex->shapeType() != GeomAPI_Shape::VERTEX) {
1007 theError = "Selected shape is not a vertex";
1011 GeomAlgoAPI_MapShapesAndAncestors aMapVE(aContext, GeomAPI_Shape::VERTEX,
1012 GeomAPI_Shape::EDGE);
1013 aWireSubshapes[aContext] = aMapVE.map();
1014 aProcessed = aWireSubshapes.find(aContext);
1018 MapShapeToShapes::iterator aFound = aProcessed->second.find(aVertex);
1019 if (aFound == aProcessed->second.end()) {
1020 theError = "Selected vertex does not exist in the wire";
1023 else if (aFound->second.size() != 2) {
1024 theError = "Vertex should be shared between 2 edges exactly";
1028 ListOfShape anEdges;
1029 anEdges.insert(anEdges.end(), aFound->second.begin(), aFound->second.end());
1030 GeomPlanePtr aPlane = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
1032 theError = "Error: Edges are not planar";
1036 GeomEdgePtr anEdge1(new GeomAPI_Edge(anEdges.front()));
1037 GeomEdgePtr anEdge2(new GeomAPI_Edge(anEdges.back()));
1038 GeomVertexPtr aSharedVertex(new GeomAPI_Vertex(aVertex));
1039 if (GeomAlgoAPI_ShapeTools::isTangent(anEdge1, anEdge2, aSharedVertex)) {
1040 theError = "Error: Edges are tangent";
1048 //==================================================================================================
1049 bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,
1050 const std::list<std::string>& theArguments,
1051 Events_InfoMessage& theError) const
1053 AttributeSelectionListPtr anAttrSelectionList =
1054 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1055 if(!anAttrSelectionList.get()) {
1057 theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
1062 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1063 AttributeSelectionPtr aSelectAttr = anAttrSelectionList->value(anIndex);
1065 //GeomValidators_BodyShapes aBodyValidator;
1066 //if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
1070 GeomValidators_FeatureKind aFeatureKindValidator;
1071 if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
1075 ResultPtr aContext = aSelectAttr->context();
1076 ResultConstructionPtr aResultConstruction =
1077 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1078 if(aResultConstruction.get()) {
1079 theError = "Error: Only body shapes and construction planes are allowed for selection.";
1083 ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
1084 if(aResultBody.get()) {
1087 FeaturePtr aResultFeature = aSelectAttr->contextFeature();
1088 if(aResultFeature.get()) {
1089 bool aOkRes = false;
1090 std::list<ResultPtr>::const_iterator aFRes = aResultFeature->results().cbegin();
1091 for(; aFRes != aResultFeature->results().cend() && !aOkRes; aFRes++) {
1092 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aFRes);
1093 if (aBody.get() && !aBody->isDisabled())
1100 theError = "Error: Only body shapes and construction planes are allowed for selection.";
1108 //==================================================================================================
1109 bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
1110 const std::list<std::string>& theArguments,
1111 Events_InfoMessage& theError) const
1113 AttributeSelectionListPtr aSubShapesAttrList =
1114 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1115 if(!aSubShapesAttrList.get()) {
1118 "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
1123 static const std::string aBaseShapeID = "base_shape";
1124 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
1125 AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
1127 if(!aShapeAttrSelection.get()) {
1129 theError = "Error: Could not get \"%1\" attribute.";
1130 theError.arg(aBaseShapeID);
1135 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
1136 ResultPtr aContext = aShapeAttrSelection->context();
1137 if(!aContext.get()) {
1138 theError = "Error: Empty context.";
1141 if(!aBaseShape.get()) {
1142 aBaseShape = aContext->shape();
1144 if(!aBaseShape.get()) {
1145 theError = "Error: Empty base shape.";
1149 std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
1150 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
1151 bool isSameFound = false;
1152 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
1153 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
1154 for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt)
1156 if ((*anIt)->isEqual(aShapeToAdd)) {
1162 theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
1170 //==================================================================================================
1171 bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
1172 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1173 const std::list<std::string>& theArguments,
1174 Events_InfoMessage& theError) const
1176 static const std::string aBaseShapeID = "base_shape";
1177 static const std::string aSubShapesID = "subshapes_to_keep";
1180 if(theFeature->getKind() != "Remove_SubShapes") {
1181 theError = "Error: Feature \"%1\" does not supported by this validator.";
1182 theError.arg(theFeature->getKind());
1186 AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
1187 if(!aShapeAttrSelection.get()) {
1188 theError = "Error: Could not get \"%1\" attribute.";
1189 theError.arg(aBaseShapeID);
1193 AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
1194 if(!aSubShapesAttrList.get()) {
1195 theError = "Error: Could not get \"%1\" attribute.";
1196 theError.arg(aSubShapesID);
1202 GeomShapePtr aBaseShape = aShapeAttrSelection->value();
1203 if(!aBaseShape.get()) {
1204 theError = "Error: Base shape is empty.";
1207 GeomShapePtr aResultShape = aBaseShape->emptyCopied();
1209 if (aSubShapesAttrList->size() == 0) {
1210 theError = "Error: Resulting shape is not valid.";
1214 // Copy sub-shapes from list to new shape.
1215 for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
1216 AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
1217 GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
1218 GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
1222 if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {
1223 theError = "Error: Resulting shape is not valid.";
1230 //==================================================================================================
1232 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
1233 const std::list<std::string>& theArguments,
1234 Events_InfoMessage& theError) const
1236 AttributeSelectionListPtr aBaseObjectsAttrList =
1237 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1238 if(!aBaseObjectsAttrList.get()) {
1239 theError = "Error: This validator can only work with selection list in \"%1\" feature.";
1240 theError.arg(FeaturesPlugin_Union::ID());
1244 for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
1245 AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
1246 ResultPtr aContext = anAttrSelectionInList->context();
1247 if (!aContext.get()) {
1248 theError = "Error: selection is invalid.";
1252 ResultConstructionPtr aConstruction =
1253 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1254 if(aConstruction.get()) {
1255 theError = "Error: Result construction not allowed for selection.";
1259 GeomShapePtr aShape = anAttrSelectionInList->value();
1260 GeomShapePtr aContextShape = aContext->shape();
1261 if (aShape.get() && aContextShape.get() && !aContextShape->isEqual(aShape)) {
1262 theError = "Error: Local selection not allowed.";
1266 ResultBodyPtr aResult =
1267 std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
1268 if(!aResult.get()) {
1272 if(aResult->numberOfSubs() > 0) {
1273 theError = "Error: Whole compsolids not allowed for selection.";
1282 //==================================================================================================
1283 bool FeaturesPlugin_ValidatorUnionArguments::isValid(
1284 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1285 const std::list<std::string>& theArguments,
1286 Events_InfoMessage& theError) const
1289 // Check feature kind.
1290 if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
1291 theError = "Error: This validator supports only \"%1\" feature.";
1292 theError.arg(FeaturesPlugin_Union::ID());
1296 // Get base objects attribute list.
1297 AttributeSelectionListPtr aBaseObejctsAttrList =
1298 theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1299 if(!aBaseObejctsAttrList.get()) {
1300 theError = "Error: Could not get \"%1\" attribute.";
1301 theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());
1307 GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPSOLID;
1308 ListOfShape aBaseShapesList;
1309 for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
1310 AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
1311 GeomShapePtr aShape = anAttrSelectionInList->value();
1312 if (!aShape.get()) {
1315 aBaseShapesList.push_back(aShape);
1316 aType = aShape->shapeType() == GeomAPI_Shape::FACE ? GeomAPI_Shape::SHELL :
1317 GeomAPI_Shape::COMPSOLID;
1320 // Make compound and find connected.
1321 GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
1322 ListOfShape aResults;
1323 GeomAlgoAPI_ShapeTools::combineShapes(aCompound, aType, aResults);
1325 if(aResults.size() > 1 || (aResults.size() == 1 && aResults.front()->shapeType() > aType)) {
1326 theError = "Error: Not all shapes have shared topology.";
1333 bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute,
1334 const std::list<std::string>& theArguments,
1335 Events_InfoMessage& theError) const
1337 if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
1339 theError = "Error: The attribute with the %1 type is not processed";
1340 theError.arg(theAttribute->attributeType());
1345 AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeReference>
1347 ObjectPtr aRefObject = aRefAttribute->value();
1348 if (!aRefObject.get()) {
1349 theError = "Error: Empty feature.";
1353 FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aRefObject);
1354 if (!aRefFeature.get()) {
1355 theError = "Error: Empty feature.";
1358 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
1359 ModelAPI_Tools::getConcealedResults(aRefFeature, aResults);
1361 size_t aConcealedResults = aResults.size();
1362 if (!aConcealedResults && !theArguments.empty()) {
1363 // find if these results are touched by the feature in another attribute
1364 std::list<std::string>::const_iterator anIt = theArguments.begin();
1365 std::string aRecoveredList = *anIt;
1366 if (!aRecoveredList.empty()) {
1367 std::shared_ptr<ModelAPI_AttributeRefList> aParameterList =
1368 theAttribute->owner()->data()->reflist(aRecoveredList);
1369 if (aParameterList.get())
1370 aConcealedResults = aParameterList->size();
1374 if (aConcealedResults == 0)
1375 theError = "Error: No concealed results.";
1377 return theError.empty();
1380 bool FeaturesPlugin_ValidatorCircular::isValid(const AttributePtr& theAttribute,
1381 const std::list<std::string>& theArguments,
1382 Events_InfoMessage& theError) const
1384 static std::list<std::string> aEdgeArg(1, "circle");
1385 static std::list<std::string> aFaceArg(1, "cylinder");
1387 Events_InfoMessage aError;
1388 bool isValid = GeomValidators_ShapeType().isValid(theAttribute, aEdgeArg, aError);
1390 isValid = GeomValidators_Face().isValid(theAttribute, aFaceArg, aError);
1392 theError = "The shape neither circle nor cylinder";
1397 //=================================================================================================
1398 bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
1399 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1400 const std::list<std::string>& theArguments,
1401 Events_InfoMessage& theError) const
1404 if (theArguments.size() != 2)
1406 theError = "Wrong number of arguments (expected 2).";
1411 int anObjectsToolsNb[2] = { 0, 0 };
1413 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
1415 bool isAllInSameCompSolid = true;
1416 ResultBodyPtr aCompSolid;
1418 for (int* anArgNbIt = anObjectsToolsNb; anIt != aLast; ++anIt, ++anArgNbIt) {
1419 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1422 *anArgNbIt = anAttrSelList->size();
1423 if (isAllInSameCompSolid) {
1424 for (int anIndex = 0; anIndex < *anArgNbIt; ++anIndex)
1426 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1427 ResultPtr aContext = anAttr->context();
1428 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1429 if (aResCompSolidPtr.get())
1431 if (aCompSolid.get())
1433 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1437 aCompSolid = aResCompSolidPtr;
1442 isAllInSameCompSolid = false;
1450 std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
1451 std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theFeature);
1452 FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
1454 if (anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE)
1457 if (anObjectsToolsNb[0] + anObjectsToolsNb[1] < 2)
1459 theError = "Not enough arguments for Fuse operation.";
1462 else if (isAllInSameCompSolid)
1464 theError = "Operations only between sub-shapes of the same shape not allowed.";
1470 if (anObjectsToolsNb[0] < 1) // check number of objects
1472 theError = "Objects not selected.";
1475 if (anObjectsToolsNb[1] < 1) // check number of tools
1477 theError = "Tools not selected.";
1480 if (isAllInSameCompSolid)
1482 theError = "Operations only between sub-shapes of the same shape not allowed.";
1490 //=================================================================================================
1492 bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFeature,
1493 std::string theAttribute)
1495 if (theAttribute == "main_objects" || theAttribute == "tool_objects")
1504 //==================================================================================================
1505 bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
1506 const AttributePtr& theAttribute,
1507 const std::list<std::string>& theArguments,
1508 Events_InfoMessage& theError) const
1510 std::shared_ptr<FeaturesPlugin_BooleanSmash> aFeature =
1511 std::dynamic_pointer_cast<FeaturesPlugin_BooleanSmash>(theAttribute->owner());
1513 AttributeSelectionListPtr anAttrSelectionList =
1514 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1515 if (!aFeature.get() || !anAttrSelectionList.get()) {
1518 "Error: Validator used in wrong feature or attribute";
1523 AttributeSelectionListPtr anOtherAttrSelectionList;
1524 if (theAttribute->id() == FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID()) {
1525 anOtherAttrSelectionList =
1526 aFeature->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
1528 anOtherAttrSelectionList =
1529 aFeature->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
1532 GeomAPI_Shape::ShapeType aSelectedShapesType = GeomAPI_Shape::SHAPE;
1533 GeomAPI_DataMapOfShapeShape aSelectedCompSolidsInOtherList;
1534 GeomPlanePtr aFacesPln;
1536 for (int anIndex = 0; anIndex < anOtherAttrSelectionList->size(); ++anIndex) {
1537 AttributeSelectionPtr anAttrSelection = anOtherAttrSelectionList->value(anIndex);
1539 if (anAttrSelection->contextFeature().get()) {
1540 theError = "Error: Features not allowed for selection.";
1544 ResultPtr aContext = anAttrSelection->context();
1545 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1546 if (!aShape.get()) {
1547 if (!aContext.get()) {
1548 theError = "Error: Empty selection.";
1551 aShape = aContext->shape();
1554 if (aShape->isSolid() || aShape->isCompSolid()) {
1555 aSelectedShapesType = GeomAPI_Shape::SOLID;
1556 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1557 if (aResCompSolidPtr.get()) {
1558 GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
1559 aSelectedCompSolidsInOtherList.bind(aCompSolidShape, aCompSolidShape);
1562 aSelectedShapesType = GeomAPI_Shape::FACE;
1563 GeomAPI_Face aFace(aShape);
1564 aFacesPln = aFace.getPlane();
1569 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1570 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1571 if (!anAttrSelection.get()) {
1572 theError = "Error: Empty attribute selection.";
1576 if (anAttrSelection->contextFeature().get()) {
1577 theError = "Error: Features not allowed for selection.";
1581 ResultPtr aContext = anAttrSelection->context();
1582 if(!aContext.get()) {
1583 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1584 if (!aContFeat.get() || !aContFeat->results().size() ||
1585 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1586 theError = "Error: Empty selection context.";
1590 ResultConstructionPtr aResultConstruction =
1591 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1592 if (aResultConstruction.get()) {
1593 theError = "Error: Result construction not allowed for selection.";
1596 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1597 GeomShapePtr aContextShape = aContext->shape();
1598 if (!aShape.get()) {
1599 aShape = aContextShape;
1601 if (!aShape.get()) {
1602 theError = "Error: Empty shape.";
1605 if (!aShape->isEqual(aContextShape)) {
1606 theError = "Error: Local selection not allowed.";
1610 if (aSelectedShapesType == GeomAPI_Shape::SHAPE) {
1611 // Other list is empty.
1612 if (aShape->isSolid() || aShape->isCompSolid()) {
1613 aSelectedShapesType = GeomAPI_Shape::SOLID;
1615 aSelectedShapesType = GeomAPI_Shape::FACE;
1616 GeomAPI_Face aFace(aShape);
1617 aFacesPln = aFace.getPlane();
1619 if (!aFacesPln.get()) {
1620 theError = "Error: Only planar faces allowed.";
1626 } else if (aSelectedShapesType == GeomAPI_Shape::SOLID) {
1627 if (!aShape->isSolid() && !aShape->isCompSolid()) {
1628 theError = "Error: Selected shapes should have the same type.";
1632 GeomAPI_Face aFace(aShape);
1633 GeomPlanePtr aPln = aFace.getPlane();
1636 theError = "Error: Only planar faces allowed.";
1640 if (!aFacesPln->isCoincident(aPln)) {
1641 theError = "Error: Only coincident faces allowed.";
1650 //==================================================================================================
1652 bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
1653 const std::list<std::string>& theArguments,
1654 Events_InfoMessage& theError) const
1656 if (!theAttribute.get()) {
1657 theError = "Error: empty selection.";
1660 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
1661 AttributeSelectionListPtr anAttrSelectionList =
1662 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1663 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1664 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1665 if (!anAttrSelection.get()) {
1666 theError = "Error: empty attribute selection.";
1669 ResultPtr aContext = anAttrSelection->context();
1670 if (aContext.get()) {
1671 aFeature = ModelAPI_Feature::feature(aContext);
1673 aFeature = anAttrSelection->contextFeature();
1674 if (!aFeature.get() || !aFeature->results().size() ||
1675 aFeature->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1676 theError = "Error: Empty selection context.";
1680 if (!aFeature.get()) {
1681 theError = "Error: empty feature.";
1684 std::string aFeatureKind = aFeature->getKind();
1685 if (aFeatureKind == "Sketch" ||
1686 aFeatureKind == "Plane" ||
1687 aFeatureKind == "Axis") {
1688 theError = "Error: %1 shape is not allowed for selection.";
1689 theError.arg(aFeatureKind);
1692 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1693 if (!aShape.get()) {
1694 GeomShapePtr aContextShape = aContext->shape();
1695 aShape = aContextShape;
1697 if (!aShape.get()) {
1698 theError = "Error: empty shape.";
1701 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1702 theError = "Error: Local selection not allowed.";
1706 int aShapeType = aShape->shapeType();
1707 // Allow to select edges, faces and solids.
1708 if (aShapeType != GeomAPI_Shape::EDGE &&
1709 aShapeType != GeomAPI_Shape::FACE &&
1710 aShapeType != GeomAPI_Shape::SOLID &&
1711 aShapeType != GeomAPI_Shape::COMPSOLID &&
1712 aShapeType != GeomAPI_Shape::COMPOUND) {
1713 theError = "Error: selected shape has the wrong type.";
1722 //==================================================================================================
1724 bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid(
1725 const AttributePtr& theAttribute,
1726 const std::list<std::string>& theArguments,
1727 Events_InfoMessage& theError) const
1729 AttributeSelectionListPtr anAttrSelectionList =
1730 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1731 if (!anAttrSelectionList.get()) {
1733 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1737 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1738 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1739 if (!anAttrSelection.get()) {
1740 theError = "Error: Empty attribute selection.";
1743 ResultPtr aContext = anAttrSelection->context();
1744 if(!aContext.get()) {
1745 FeaturePtr aContFeat = anAttrSelection->contextFeature();
1746 if (!aContFeat.get() || !aContFeat->results().size() ||
1747 aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
1748 theError = "Error: Empty selection context.";
1752 ResultConstructionPtr aResultConstruction =
1753 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1754 if (aResultConstruction.get()) {
1755 theError = "Error: Result construction not allowed for selection.";
1758 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1759 if (!aShape.get()) {
1760 GeomShapePtr aContextShape = aContext->shape();
1761 aShape = aContextShape;
1763 if (!aShape.get()) {
1764 theError = "Error: Empty shape.";
1767 if (aContext.get() && !aShape->isEqual(aContext->shape())) {
1768 theError = "Error: Local selection not allowed.";
1777 //=================================================================================================
1778 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
1779 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1780 const std::list<std::string>& theArguments,
1781 Events_InfoMessage& theError) const
1784 if (theArguments.size() != 2) {
1785 theError = "Wrong number of arguments (expected 2).";
1790 std::shared_ptr<FeaturesPlugin_BooleanFuse> aFeature =
1791 std::dynamic_pointer_cast<FeaturesPlugin_BooleanFuse>(theFeature);
1793 int anObjectsNb = 0, aToolsNb = 0;
1795 std::list<std::string>::const_iterator anIt = theArguments.begin();
1797 bool isAllInSameCompSolid = true;
1798 ResultBodyPtr aCompSolid;
1800 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1801 if (anAttrSelList) {
1802 anObjectsNb = anAttrSelList->size();
1803 for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
1804 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1805 ResultPtr aContext = anAttr->context();
1806 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1807 if (aResCompSolidPtr.get()) {
1808 if (aCompSolid.get()) {
1809 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1811 aCompSolid = aResCompSolidPtr;
1814 isAllInSameCompSolid = false;
1821 if (aFeature->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD())->value()
1822 == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
1823 anAttrSelList = theFeature->selectionList(*anIt);
1824 if (anAttrSelList) {
1825 aToolsNb = anAttrSelList->size();
1826 if (isAllInSameCompSolid) {
1827 for (int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
1828 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
1829 ResultPtr aContext = anAttr->context();
1830 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
1831 if (aResCompSolidPtr.get()) {
1832 if (aCompSolid.get()) {
1833 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
1835 aCompSolid = aResCompSolidPtr;
1838 isAllInSameCompSolid = false;
1846 if (anObjectsNb + aToolsNb < 2) {
1847 theError = "Not enough arguments for Fuse operation.";
1854 //=================================================================================================
1856 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory(
1857 std::string theFeature,
1858 std::string theAttribute)
1860 if (theAttribute == "main_objects" || theAttribute == "tool_objects") {
1868 //==================================================================================================
1870 bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
1871 const AttributePtr& theAttribute,
1872 const std::list<std::string>& theArguments,
1873 Events_InfoMessage& theError) const
1875 AttributeSelectionListPtr anAttrSelectionList =
1876 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1877 if (!anAttrSelectionList.get()) {
1879 "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
1883 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
1884 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
1885 if (!anAttrSelection.get()) {
1886 theError = "Error: Empty attribute selection.";
1889 ResultPtr aContext = anAttrSelection->context();
1890 if (!aContext.get() && !anAttrSelection->contextFeature().get()) {
1891 theError = "Error: Empty selection context.";
1894 ResultConstructionPtr aResultConstruction =
1895 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
1896 if (aResultConstruction.get()) {
1897 if (theAttribute->id() != FeaturesPlugin_BooleanCommon::TOOL_LIST_ID()) {
1898 theError = "Error: Result construction not allowed for selection.";
1902 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
1903 GeomShapePtr aContextShape;
1904 if (aContext.get()) {
1905 aContextShape = aContext->shape();
1907 if (!aShape.get()) {
1908 aShape = aContextShape;
1910 if (!aShape.get()) {
1911 theError = "Error: Empty shape.";
1914 if (aContextShape.get() && !aShape->isEqual(aContextShape)) {
1915 theError = "Error: Local selection not allowed.";
1919 if (aResultConstruction.get() && aShape->shapeType() != GeomAPI_Shape::FACE) {
1920 theError = "Error: Result construction should be plane.";
1929 //=================================================================================================
1930 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
1931 const std::shared_ptr<ModelAPI_Feature>& theFeature,
1932 const std::list<std::string>& theArguments,
1933 Events_InfoMessage& theError) const
1935 if (theArguments.size() != 2) {
1937 theError = "Wrong number of arguments (expected 2).";
1942 std::shared_ptr<FeaturesPlugin_BooleanCommon> aFeature =
1943 std::dynamic_pointer_cast<FeaturesPlugin_BooleanCommon>(theFeature);
1945 int anObjectsNb = 0, aToolsNb = 0;
1947 std::list<std::string>::const_iterator anIt = theArguments.begin();
1949 ResultBodyPtr aCompSolid;
1951 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
1952 if (anAttrSelList) {
1953 anObjectsNb = anAttrSelList->size();
1956 bool isSimpleMode = aFeature->string(FeaturesPlugin_BooleanCommon::CREATION_METHOD())->value()
1957 == FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE();
1959 if (!isSimpleMode) {
1960 anAttrSelList = theFeature->selectionList(*anIt);
1961 if (anAttrSelList) {
1962 aToolsNb = anAttrSelList->size();
1966 if ((isSimpleMode && anObjectsNb < 2)
1967 || (!isSimpleMode && (anObjectsNb == 0 || aToolsNb == 0))) {
1968 theError = "Not enough arguments for Fuse operation.";
1974 //=================================================================================================
1976 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isNotObligatory(
1977 std::string theFeature,
1978 std::string theAttribute)
1984 //==================================================================================================
1985 bool FeaturesPlugin_ValidatorDefeaturingSelection::isValid(
1986 const AttributePtr& theAttribute,
1987 const std::list<std::string>& theArguments,
1988 Events_InfoMessage& theError) const
1990 AttributeSelectionListPtr anAttrSelectionList =
1991 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
1992 if (!anAttrSelectionList.get()) {
1994 theError = "Error: This validator can only work with selection list attributes.";
1999 // Check selected entities are sub-shapes of solid or compsolid
2000 GeomShapePtr aBaseSolid;
2001 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
2002 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
2003 if (!anAttrSelection.get()) {
2004 theError = "Error: Empty attribute selection.";
2007 ResultPtr aContext = anAttrSelection->context();
2008 if (!aContext.get()) {
2009 theError = "Error: Empty selection context.";
2013 GeomShapePtr aContextShape = aContext->shape();
2014 if (aContextShape->shapeType() != GeomAPI_Shape::SOLID) {
2015 theError = "Error: Not all selected shapes are sub-shapes of solids.";