X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_ShapeType.cpp;h=146837e7abcf972e5294674c95217508100937ed;hb=eedc671e8a6e5dda61a69236f1029877e6ed02ef;hp=afb7dd0c93eb2c6a5bb6eefa2965bd750a5b698b;hpb=8a8b9b4ba20d4758dc2ae5ade0359b8bb2772986;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp old mode 100755 new mode 100644 index afb7dd0c9..146837e7a --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,16 +12,16 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "GeomValidators_ShapeType.h" #include "GeomValidators_Tools.h" #include +#include #include #include @@ -33,6 +33,7 @@ #include +#include #include #include @@ -46,25 +47,34 @@ GeomValidators_ShapeType::TypeOfShape if (MyShapeTypes.size() == 0) { MyShapeTypes["empty"] = Empty; MyShapeTypes["vertex"] = Vertex; + MyShapeTypes["vertices"] = Vertex; MyShapeTypes["edge"] = Edge; + MyShapeTypes["edges"] = Edge; MyShapeTypes["line"] = Line; MyShapeTypes["circle"] = Circle; MyShapeTypes["wire"] = Wire; MyShapeTypes["face"] = Face; + MyShapeTypes["faces"] = Face; MyShapeTypes["plane"] = Plane; MyShapeTypes["shell"] = Shell; MyShapeTypes["solid"] = Solid; + MyShapeTypes["solids"] = Solid; MyShapeTypes["compsolid"] = CompSolid; MyShapeTypes["compound"] = Compound; } std::string aType = std::string(theType.c_str()); + std::transform(aType.begin(), aType.end(), aType.begin(), + [](char c) { return static_cast(::tolower(c)); }); if (MyShapeTypes.find(aType) != MyShapeTypes.end()) return MyShapeTypes[aType]; - Events_InfoMessage("Shape type defined in XML is not implemented!").send(); +// LCOV_EXCL_START + //Events_InfoMessage("Shape type defined in XML is not implemented!").send(); return AnyShape; +// LCOV_EXCL_STOP } +// LCOV_EXCL_START std::string getShapeTypeDescription(const GeomValidators_ShapeType::TypeOfShape& theType) { std::string aValue = ""; @@ -72,14 +82,15 @@ std::string getShapeTypeDescription(const GeomValidators_ShapeType::TypeOfShape& if (MyShapeTypes.size() != 0) { std::map::const_iterator anIt = MyShapeTypes.begin(), aLast = MyShapeTypes.end(); - for (; anIt != aLast; anIt++) { - if (anIt->second == theType) + for (; anIt != aLast; anIt++) + if (anIt->second == theType) { aValue = anIt->first; break; - } + } } return aValue; } +// LCOV_EXCL_STOP bool GeomValidators_ShapeType::isValid(const AttributePtr& theAttribute, const std::list& theArguments, @@ -103,9 +114,8 @@ bool GeomValidators_ShapeType::isValid(const AttributePtr& theAttribute, } if (!aValid && theError.empty()) { std::string aTypes; - std::list::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); // returns true if the attribute satisfies at least one of given arguments - for (; anIt != aLast; anIt++) { + for (anIt = theArguments.begin(); anIt != aLast; anIt++) { if (!aTypes.empty()) aTypes += ", "; aTypes += *anIt; @@ -130,18 +140,27 @@ bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute std::dynamic_pointer_cast(theAttribute); GeomShapePtr aShape = anAttr->value(); if (aShape.get()) - aValid = isValidShape(aShape, theShapeType, theError); + aValid = isValidShape(aShape, theShapeType, anAttr->isGeometricalSelection(), theError); else { if (anAttr->context().get()) - aValid = isValidObject(anAttr->context(), theShapeType, theError); + aValid = isValidObject(anAttr->context(), + theShapeType, + anAttr->isGeometricalSelection(), + theError); else - aValid = isValidObject(anAttr->contextFeature(), theShapeType, theError); + aValid = isValidObject(anAttr->contextFeature(), + theShapeType, + anAttr->isGeometricalSelection(), + theError); } } else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) { AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); if (anAttr->isObject()) { - aValid = isValidObject(anAttr->object(), theShapeType, theError); + aValid = isValidObject(anAttr->object(), + theShapeType, + false, + theError); } else if (theShapeType == Vertex) { AttributePtr aRefAttr = anAttr->attr(); @@ -150,19 +169,23 @@ bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute theError = "It has reference to an empty attribute"; } else { - std::string anAttributeType = aRefAttr->attributeType(); - aValid = anAttributeType == GeomDataAPI_Point2D::typeId(); + std::string anAttrType = aRefAttr->attributeType(); + aValid = anAttrType == GeomDataAPI_Point2D::typeId(); if (!aValid) { +// LCOV_EXCL_START theError = "Shape type is \"%1\", it should be \"%2\""; - theError.arg(anAttributeType).arg(getShapeTypeDescription(theShapeType)); + theError.arg(anAttrType).arg(getShapeTypeDescription(theShapeType)); +// LCOV_EXCL_STOP } } } + else + aValid = false; } else if (anAttributeType == ModelAPI_AttributeReference::typeId()) { AttributeReferencePtr anAttr = std::dynamic_pointer_cast(theAttribute); - aValid = isValidObject(anAttr->value(), theShapeType, theError); + aValid = isValidObject(anAttr->value(), theShapeType, false, theError); } else if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { AttributeSelectionListPtr aListAttr = @@ -179,9 +202,11 @@ bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute } } else { +// LCOV_EXCL_START aValid = false; theError = "The attribute with the %1 type is not processed"; theError.arg(anAttributeType); +// LCOV_EXCL_STOP } if (aValid) theError = ""; @@ -190,6 +215,7 @@ bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject, const TypeOfShape theShapeType, + const bool theIsGeometricalSelection, Events_InfoMessage& theError) const { bool aValid = true; @@ -214,7 +240,7 @@ bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject, aValid = false; theError = "The result is empty"; } else { - aValid = isValidShape(aResult->shape(), theShapeType, theError); + aValid = isValidShape(aResult->shape(), theShapeType, theIsGeometricalSelection, theError); } } else { FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); @@ -231,6 +257,7 @@ bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject, bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape, const TypeOfShape theShapeType, + const bool theIsGeometricalSelection, Events_InfoMessage& theError) const { bool aValid = true; @@ -247,9 +274,21 @@ bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape, case Edge: aValid = theShape->isEdge(); break; - case Line: - aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isLine(); + case Line: { + if (theIsGeometricalSelection && theShape->isCompound()) { + aValid = true; + for (GeomAPI_ShapeIterator anIt(theShape); anIt.more(); anIt.next()) { + if (!anIt.current()->isEdge() || !GeomAPI_Curve(anIt.current()).isLine()) { + aValid = false; + break; + } + } + } + else { + aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isLine(); + } break; + } case Circle: aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isCircle(); break; @@ -262,6 +301,9 @@ bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape, case Shell: aValid = theShape->shapeType() == GeomAPI_Shape::SHELL; break; + case Plane: + aValid = theShape->isPlanar(); + break; case Solid: aValid = theShape->isSolid() || theShape->isCompSolid() || theShape->isCompoundOfSolids();