From: Artem Zhidkov Date: Mon, 15 Jun 2020 20:49:22 +0000 (+0300) Subject: Issue #19471: Seg fault if edge for point creation is selected from object browser X-Git-Tag: V9_5_0rc1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=41a6df534f7e31e2c863399968e3d25d1bd428bf;p=modules%2Fshaper.git Issue #19471: Seg fault if edge for point creation is selected from object browser Prohibit the selection of a feature when constructing point on edge. --- diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index dfed17f15..11fd87eaf 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -98,4 +98,5 @@ ADD_UNIT_TESTS(TestAxisCreation.py TestPlane_ErrorMsg.py TestPlane_FaceValidator.py Test19207.py + Test19471.py ) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 96b6aee66..69e900fdc 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -53,6 +53,8 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() new ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes()); aFactory->registerValidator("ConstructionPlugin_ValidatorPointThreeNonParallelPlanes", new ConstructionPlugin_ValidatorPointThreeNonParallelPlanes()); + aFactory->registerValidator("ConstructionPlugin_ValidatorNotFeature", + new ConstructionPlugin_ValidatorNotFeature()); Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::DblSpin, PLANE_SIZE, "0", "1000"); diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp index b36b2bd51..aedbb5968 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp @@ -470,6 +470,29 @@ bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid( return true; } +//================================================================================================== +bool ConstructionPlugin_ValidatorNotFeature::isValid( + const AttributePtr& theAttribute, + const std::list& /*theArguments*/, + Events_InfoMessage& theError) const +{ + AttributeSelectionPtr aSelAttr = + std::dynamic_pointer_cast(theAttribute); + if (!aSelAttr) { + theError = "Wrong attribute"; + return false; + } + + FeaturePtr aContextFeature = aSelAttr->contextFeature(); + if (aContextFeature) { + theError = "Feature should not be selected"; + return false; + } + return true; +} + +//================================================================================================== + std::shared_ptr getEdge(const GeomShapePtr theShape) { GeomEdgePtr anEdge; diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.h b/src/ConstructionPlugin/ConstructionPlugin_Validators.h index c6c5be918..accbf1994 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.h @@ -127,4 +127,19 @@ public: Events_InfoMessage& theError) const; }; +/// \class ConstructionPlugin_ValidatorNotFeature +/// \ingroup Validators +/// \brief A validator for selection of a result but not a feature. +class ConstructionPlugin_ValidatorNotFeature : public ModelAPI_AttributeValidator +{ +public: + //! \return True if the attribute is valid. + //! \param[in] theAttribute the checked attribute. + //! \param[in] theArguments arguments of the attribute. + //! \param[out] theError error message. + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const; +}; + #endif \ No newline at end of file diff --git a/src/ConstructionPlugin/ConstructionPlugin_msg_en.ts b/src/ConstructionPlugin/ConstructionPlugin_msg_en.ts index d81fdc7b6..ecb0de35d 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_msg_en.ts +++ b/src/ConstructionPlugin/ConstructionPlugin_msg_en.ts @@ -308,6 +308,17 @@ Select an edge. + + Point:edge:ConstructionPlugin_ValidatorNotFeature + + Wrong attribute + Wrong attribute. + + + Feature should not be selected + Feature should not be selected. + + Point:edge_for_point_projection diff --git a/src/ConstructionPlugin/ConstructionPlugin_msg_fr.ts b/src/ConstructionPlugin/ConstructionPlugin_msg_fr.ts index e06b61c5f..21fa8315f 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_msg_fr.ts +++ b/src/ConstructionPlugin/ConstructionPlugin_msg_fr.ts @@ -797,6 +797,17 @@ Sélectionnez l'arête de référence. + + Point:edge:ConstructionPlugin_ValidatorNotFeature + + Wrong attribute + Attribut incorrect. + + + Feature should not be selected + La fonction ne doit pas être sélectionnée. + + Point:edge_for_point_projection diff --git a/src/ConstructionPlugin/Test/Test19471.py b/src/ConstructionPlugin/Test/Test19471.py new file mode 100644 index 000000000..04937e053 --- /dev/null +++ b/src/ConstructionPlugin/Test/Test19471.py @@ -0,0 +1,32 @@ +# Copyright (C) 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 +# 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 +# + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Point_2 = model.addPoint(Part_1_doc, 5, 0, 0) +Point_3 = model.addPoint(Part_1_doc, 20, 0, 0) +Edge_1 = model.addEdge(Part_1_doc, model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_2")) +Point_4 = model.addPoint(Part_1_doc, model.selection("EDGE", "all-in-Edge_1"), 10, False, False) +model.end() + +assert(Point_4.feature().error() != "") diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml index 450dadd33..1acb33893 100644 --- a/src/ConstructionPlugin/point_widget.xml +++ b/src/ConstructionPlugin/point_widget.xml @@ -16,6 +16,7 @@ icon="icons/Construction/edge.png" shape_types="edge"> +