From 4a44a0f787639beca368d0d1b4eb83db93658ae2 Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Thu, 23 Jul 2020 16:02:09 +0300 Subject: [PATCH] Task #3236: Generalization of extrusion Allow to use wires and shells as an argument of the Extrusion --- .../FeaturesPlugin_CompositeSketch.cpp | 1 + src/FeaturesPlugin/FeaturesPlugin_Tools.cpp | 13 ++++++--- .../FeaturesPlugin_Validators.cpp | 29 +++++++++++++++++-- .../GeomValidators_ShapeType.cpp | 2 +- src/GeomValidators/GeomValidators_ShapeType.h | 3 +- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index bdda2db8b..ab0d12b7d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -51,6 +51,7 @@ void FeaturesPlugin_CompositeSketch::initCompositeSketchAttribtues(const int the if(theInitFlags & InitBaseObjectsList) { data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId()); myCurrentSelectionType = selectionList(BASE_OBJECTS_ID())->selectionType(); + selectionList(BASE_OBJECTS_ID())->setWholeResultAllowed(true); } } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp b/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp index 7277bfe0f..44068e383 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp @@ -31,6 +31,8 @@ #include #include +#include + //================================================================================================== void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody, const ListOfShape& theBaseShapes, @@ -201,15 +203,18 @@ bool FeaturesPlugin_Tools::getShape(const AttributeSelectionListPtr theSelection theError = "Error: Selected sketches does not have results."; return false; } - int aFacesNum = aConstruction->facesNum(); + GeomValidators_ShapeType::TypeOfShape aSelType = + GeomValidators_ShapeType::shapeType(theSelectionList->selectionType()); + int aFacesNum = 0; + if (aSelType != GeomValidators_ShapeType::Vertex && + aSelType != GeomValidators_ShapeType::Edge) + aFacesNum = aConstruction->facesNum(); if(aFacesNum == 0) { // Probably it can be construction. aBaseShape = aConstruction->shape(); if(aBaseShape.get() && !aBaseShape->isNull()) { GeomAPI_Shape::ShapeType aST = aBaseShape->shapeType(); - if(aST != GeomAPI_Shape::VERTEX && aST != GeomAPI_Shape::EDGE && - aST != GeomAPI_Shape::WIRE && - aST != GeomAPI_Shape::FACE && aST != GeomAPI_Shape::SHELL) { + if(aST == GeomAPI_Shape::SOLID || aST == GeomAPI_Shape::COMPSOLID) { theError = "Error: Selected shapes has unsupported type."; return false; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index c8b96f144..6c3c1d9f7 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -61,6 +61,8 @@ #include #include +#include + #define _USE_MATH_DEFINES #include @@ -399,9 +401,29 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast(theAttribute); + + const std::string& aSelType = aListAttr->selectionType(); + std::list anApplicableTypes; + switch (GeomValidators_ShapeType::shapeType(aSelType)) { + case GeomValidators_ShapeType::Vertex: + anApplicableTypes.push_back("vertex"); + break; + case GeomValidators_ShapeType::Edge: + anApplicableTypes.push_back("edge"); + anApplicableTypes.push_back("wire"); + break; + case GeomValidators_ShapeType::Face: + anApplicableTypes.push_back("face"); + anApplicableTypes.push_back("shell"); + break; + default: + anApplicableTypes = theArguments; + break; + } + for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) { // If at least one attribute is invalid, the result is false. - if(!isValidAttribute(aListAttr->value(anIndex), theArguments, theError)) { + if(!isValidAttribute(aListAttr->value(anIndex), anApplicableTypes, theError)) { return false; } } @@ -441,8 +463,9 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute aContextShape = aContext->shape(); if(aShape->isEqual(aContextShape)) { - // Whole construction selected. Check that it have faces. - if(aConstruction->facesNum() > 0) { + // Whole construction selected. Check that it has faces. + if((theArguments.front() == "face" && aConstruction->facesNum() > 0) || + theArguments.front() == "edge") { return true; } } else { diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index 4b81b7eec..146837e7a 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -69,7 +69,7 @@ GeomValidators_ShapeType::TypeOfShape return MyShapeTypes[aType]; // LCOV_EXCL_START - Events_InfoMessage("Shape type defined in XML is not implemented!").send(); + //Events_InfoMessage("Shape type defined in XML is not implemented!").send(); return AnyShape; // LCOV_EXCL_STOP } diff --git a/src/GeomValidators/GeomValidators_ShapeType.h b/src/GeomValidators/GeomValidators_ShapeType.h index cc0b1c5b8..3f581bc79 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.h +++ b/src/GeomValidators/GeomValidators_ShapeType.h @@ -63,11 +63,12 @@ class GeomValidators_ShapeType : public ModelAPI_AttributeValidator GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const; -protected: + /// Convert string to TypeOfShape value /// \param theType a string value GEOMVALIDATORS_EXPORT static TypeOfShape shapeType(const std::string& theType); +protected: /// Returns true if the attibute's object type satisfies the argument value /// \param[in] theAttribute a checked attribute /// \param[in] theShapeType a type of shape -- 2.39.2