From 096c601a5a758d3084c77d6c32d15416efcd473a Mon Sep 17 00:00:00 2001 From: mzn Date: Fri, 20 Jul 2018 13:48:06 +0300 Subject: [PATCH] Issue #2559, 2560: use different shapes validator for points selector. --- src/BuildPlugin/Test/TestInterpolation.py | 12 +- src/BuildPlugin/Test/TestPolyline.py | 7 +- src/BuildPlugin/interpolation_widget.xml | 1 + src/BuildPlugin/polyline_widget.xml | 1 + src/GeomAPI/CMakeLists.txt | 2 + src/GeomAPI/GeomAPI_Tools.cpp | 51 +++++++++ src/GeomAPI/GeomAPI_Tools.h | 39 +++++++ .../GeomValidators_DifferentShapes.cpp | 103 ++++++++++++++++-- .../GeomValidators_DifferentShapes.h | 10 ++ 9 files changed, 205 insertions(+), 21 deletions(-) create mode 100644 src/GeomAPI/GeomAPI_Tools.cpp create mode 100644 src/GeomAPI/GeomAPI_Tools.h diff --git a/src/BuildPlugin/Test/TestInterpolation.py b/src/BuildPlugin/Test/TestInterpolation.py index a790170e8..805e6f97a 100644 --- a/src/BuildPlugin/Test/TestInterpolation.py +++ b/src/BuildPlugin/Test/TestInterpolation.py @@ -100,8 +100,7 @@ model.checkBooleansResult(Interpolation_5, model, 1, [0], [0], [0], [1], [2]) Interpolation_6 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_1], False, False) model.do() -# TODO uncomment -#model.testNbResults(Interpolation_6, 0) +model.testNbResults(Interpolation_6, 0) # ============================================================================= # Test 7. Try to create curve on a single point 3 @@ -161,11 +160,10 @@ Point_2 = model.addPoint(Part_4_doc, 0, 0, 0) P_1 = model.selection("VERTEX", "Point_1") P_2 = model.selection("VERTEX", "Point_2") -# TODO uncomment -#Interpolation_10 = model.addInterpolation(Part_4_doc, [P_1, P_2], -# False, False) -#model.do() -#model.testNbResults(Interpolation_10, 0) +Interpolation_10 = model.addInterpolation(Part_4_doc, [P_1, P_2], + False, False) +model.do() +model.testNbResults(Interpolation_10, 0) # ============================================================================= # Test 11. Check subshapes naming diff --git a/src/BuildPlugin/Test/TestPolyline.py b/src/BuildPlugin/Test/TestPolyline.py index 622523cfb..578da8db7 100644 --- a/src/BuildPlugin/Test/TestPolyline.py +++ b/src/BuildPlugin/Test/TestPolyline.py @@ -140,11 +140,10 @@ Point_2 = model.addPoint(Part_4_doc, 0, 0, 0) P_1 = model.selection("VERTEX", "Point_1") P_2 = model.selection("VERTEX", "Point_2") -# TODO uncomment -#Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False) -#model.do() +Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False) +model.do() -#model.testNbResults(Polyline_9, 0) +model.testNbResults(Polyline_9, 0) # ============================================================================= # Test 10. Check subshapes naming diff --git a/src/BuildPlugin/interpolation_widget.xml b/src/BuildPlugin/interpolation_widget.xml index 4c12f2ea9..e5d6071ad 100644 --- a/src/BuildPlugin/interpolation_widget.xml +++ b/src/BuildPlugin/interpolation_widget.xml @@ -25,6 +25,7 @@ email : webmaster.salome@opencascade.com + diff --git a/src/BuildPlugin/polyline_widget.xml b/src/BuildPlugin/polyline_widget.xml index 4ac398d02..6f45ba362 100644 --- a/src/BuildPlugin/polyline_widget.xml +++ b/src/BuildPlugin/polyline_widget.xml @@ -25,6 +25,7 @@ email : webmaster.salome@opencascade.com + diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index b75212b54..7cc297767 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -59,6 +59,7 @@ SET(PROJECT_HEADERS GeomAPI_Wire.h GeomAPI_Ellipse.h GeomAPI_Ellipse2d.h + GeomAPI_Tools.h ) SET(PROJECT_SOURCES @@ -96,6 +97,7 @@ SET(PROJECT_SOURCES GeomAPI_Wire.cpp GeomAPI_Ellipse.cpp GeomAPI_Ellipse2d.cpp + GeomAPI_Tools.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAPI/GeomAPI_Tools.cpp b/src/GeomAPI/GeomAPI_Tools.cpp new file mode 100644 index 000000000..082595768 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Tools.cpp @@ -0,0 +1,51 @@ +// Copyright (C) 2014-2017 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#include "GeomAPI_Tools.h" + +#include "GeomAPI_Vertex.h" +#include "GeomAPI_Edge.h" +#include "GeomAPI_Face.h" +#include "GeomAPI_Wire.h" + +//================================================================================================== +GeomShapePtr GeomAPI_Tools::getTypedShape(const GeomShapePtr& theShape) +{ + GeomShapePtr aTypedShape = theShape; + + GeomAPI_Shape::ShapeType aType = theShape->shapeType(); + + switch (theShape->shapeType()) { + case GeomAPI_Shape::VERTEX: + aTypedShape = GeomShapePtr(new GeomAPI_Vertex(theShape)); + break; + case GeomAPI_Shape::EDGE: + aTypedShape = GeomShapePtr(new GeomAPI_Edge(theShape)); + break; + case GeomAPI_Shape::FACE: + aTypedShape = GeomShapePtr(new GeomAPI_Face(theShape)); + break; + case GeomAPI_Shape::WIRE: + aTypedShape = GeomShapePtr(new GeomAPI_Wire(theShape)); + break; + } + + return aTypedShape; +} diff --git a/src/GeomAPI/GeomAPI_Tools.h b/src/GeomAPI/GeomAPI_Tools.h new file mode 100644 index 000000000..3ee2027c3 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Tools.h @@ -0,0 +1,39 @@ +// Copyright (C) 2014-2017 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#ifndef GeomAPI_Tools_H_ +#define GeomAPI_Tools_H_ + +#include "GeomAPI.h" +#include "GeomAPI_Shape.h" + +/// \class GeomAPI_Tools +/// \ingroup DataModel +/// \brief Provides auxiliary methods for shapes processing +class GeomAPI_Tools +{ +public: + /// \brief Returns typed shape. + /// \param[in] theShape the shape. + /// \return shape of the corresponding type + GEOMAPI_EXPORT static GeomShapePtr getTypedShape(const GeomShapePtr& theShape); +}; + +#endif \ No newline at end of file diff --git a/src/GeomValidators/GeomValidators_DifferentShapes.cpp b/src/GeomValidators/GeomValidators_DifferentShapes.cpp index 75f353500..985f7acf0 100644 --- a/src/GeomValidators/GeomValidators_DifferentShapes.cpp +++ b/src/GeomValidators/GeomValidators_DifferentShapes.cpp @@ -23,17 +23,76 @@ #include #include +#include #include "ModelAPI_Object.h" #include +#include +//================================================================================================= bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const { - FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + bool isValid = false; + + std::string anAttributeType = theAttribute->attributeType(); + bool isList = anAttributeType == ModelAPI_AttributeSelectionList::typeId(); + + std::list anAttrs; + if (isList) { + AttributeSelectionListPtr aListAttr = + std::dynamic_pointer_cast(theAttribute); + // get all selection attributes from the list + for (int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) { + anAttrs.push_back(aListAttr->value(anIndex)); + } + + isValid = checkEquals(anAttrs); + } + else { + // get all feature selection attributes + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId()); + + isValid = checkEqualToCurrent(anAttrs, theAttribute); + } + + if (!isValid) { + theError = isList ? "The selection list contains equal shapes." : + "The feature uses equal shapes."; + return false; + } + + return true; +} + +//================================================================================================= +bool GeomValidators_DifferentShapes::checkEquals(std::list& theAttributes) +{ + std::list::iterator anIt = theAttributes.begin(); + for (; anIt != theAttributes.end(); anIt++) { + AttributePtr anAttribute = *anIt; + + std::list::iterator anOthersIt = std::next(anIt); + for (; anOthersIt != theAttributes.end(); anOthersIt++) { + AttributePtr anOtherAttribute = *anOthersIt; + if (isAttrShapesEqual(anAttribute, anOtherAttribute)) { + return false; + } + } + } + + return true; +} + +//================================================================================================= +bool GeomValidators_DifferentShapes::checkEqualToCurrent(std::list& theAttributes, + const AttributePtr& theCurrentAttribute) +{ AttributeSelectionPtr aSelectionAttribute = - std::dynamic_pointer_cast(theAttribute); + std::dynamic_pointer_cast(theCurrentAttribute); + GeomShapePtr aShape = aSelectionAttribute->value(); if (!aShape.get()) { ResultPtr aResult = aSelectionAttribute->context(); @@ -41,13 +100,10 @@ bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute, aShape = aResult->shape(); } - std::string aCurrentAttributeId = theAttribute->id(); - // get all feature attributes - std::list anAttrs = - aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId()); - if (anAttrs.size() > 0 && aShape.get() != NULL) { - std::list::iterator anAttr = anAttrs.begin(); - for(; anAttr != anAttrs.end(); anAttr++) { + std::string aCurrentAttributeId = theCurrentAttribute->id(); + if (theAttributes.size() > 0 && aShape.get() != NULL) { + std::list::iterator anAttr = theAttributes.begin(); + for (; anAttr != theAttributes.end(); anAttr++) { AttributePtr anAttribute = *anAttr; // take into concideration only other attributes if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) { @@ -62,12 +118,39 @@ bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute, anAttrShape = aResult->shape(); } if (aShape->isEqual(anAttrShape)) { - theError = "The feature uses equal shapes."; return false; } } } } } + return true; } + +bool GeomValidators_DifferentShapes::isAttrShapesEqual(const AttributePtr& theAttribute, + const AttributePtr& theOtherAttribute) +{ + AttributeSelectionPtr aSelectionAttribute = + std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anOtherSelectionAttribute = + std::dynamic_pointer_cast(theOtherAttribute); + + GeomShapePtr aShape = aSelectionAttribute->value(); + if (!aShape.get()) { + ResultPtr aResult = aSelectionAttribute->context(); + if (aResult.get()) + aShape = aResult->shape(); + } + GeomShapePtr aTypedShape = GeomAPI_Tools::getTypedShape(aShape); + + GeomShapePtr anOtherShape = anOtherSelectionAttribute->value(); + if (!anOtherShape.get()) { + ResultPtr aResult = anOtherSelectionAttribute->context(); + if (aResult.get()) + anOtherShape = aResult->shape(); + } + GeomShapePtr aOtherTypedShape = GeomAPI_Tools::getTypedShape(anOtherShape); + + return aTypedShape->isEqual(aOtherTypedShape); +} \ No newline at end of file diff --git a/src/GeomValidators/GeomValidators_DifferentShapes.h b/src/GeomValidators/GeomValidators_DifferentShapes.h index 737a2f63d..f1d826cc4 100644 --- a/src/GeomValidators/GeomValidators_DifferentShapes.h +++ b/src/GeomValidators/GeomValidators_DifferentShapes.h @@ -40,6 +40,16 @@ public: GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const; + +private: + /// Check if the list contains equal shape selection. + static bool checkEquals(std::list& theAttributes); + /// Check if the list contains shape selection equal to the given one. + static bool checkEqualToCurrent(std::list& theAttributes, + const AttributePtr& theCurrentAttribute); + /// Check if shapes corresponding to the attributes are equal. + static bool isAttrShapesEqual(const AttributePtr& theAttribute, + const AttributePtr& theOtherAttribute); }; #endif -- 2.39.2