]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #19471: Seg fault if edge for point creation is selected from object browser
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Mon, 15 Jun 2020 20:49:22 +0000 (23:49 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Mon, 15 Jun 2020 20:49:44 +0000 (23:49 +0300)
Prohibit the selection of a feature when constructing point on edge.

src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/ConstructionPlugin/ConstructionPlugin_Validators.cpp
src/ConstructionPlugin/ConstructionPlugin_Validators.h
src/ConstructionPlugin/ConstructionPlugin_msg_en.ts
src/ConstructionPlugin/ConstructionPlugin_msg_fr.ts
src/ConstructionPlugin/Test/Test19471.py [new file with mode: 0644]
src/ConstructionPlugin/point_widget.xml

index dfed17f152c283e6b3c3241f7ba2789a664fef93..11fd87eaf0a2b1ce03e9f0982a85091ed5ac7af0 100644 (file)
@@ -98,4 +98,5 @@ ADD_UNIT_TESTS(TestAxisCreation.py
                TestPlane_ErrorMsg.py
                TestPlane_FaceValidator.py
                Test19207.py
+               Test19471.py
 )
index 96b6aee66dc80bf4d5b37bbbcc7a2dbe4dfe96bc..69e900fdc50dbc1a1ad715ed14da817521634c8b 100644 (file)
@@ -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");
index b36b2bd513f5ea04d340915aea2599359469d172..aedbb596803dc65902321fc22ff33050c6d5e4bf 100644 (file)
@@ -470,6 +470,29 @@ bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid(
   return true;
 }
 
+//==================================================================================================
+bool ConstructionPlugin_ValidatorNotFeature::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& /*theArguments*/,
+    Events_InfoMessage& theError) const
+{
+  AttributeSelectionPtr aSelAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(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<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
 {
   GeomEdgePtr anEdge;
index c6c5be91873c3ebbc99937ee428c4c7313398403..accbf19943f42eba68cca8bad9a3419f44e6a8a0 100644 (file)
@@ -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<std::string>& theArguments,
+                       Events_InfoMessage& theError) const;
+};
+
 #endif
\ No newline at end of file
index d81fdc7b65eaa461c2389020a6c38d3778d68162..ecb0de35dc81dba5384c511d2779133363163414 100644 (file)
       <translation>Select an edge.</translation>
     </message>
   </context>
+  <context>
+    <name>Point:edge:ConstructionPlugin_ValidatorNotFeature</name>
+    <message>
+      <source>Wrong attribute</source>
+      <translation>Wrong attribute.</translation>
+    </message>
+    <message>
+      <source>Feature should not be selected</source>
+      <translation>Feature should not be selected.</translation>
+    </message>
+  </context>
   <context>
     <name>Point:edge_for_point_projection</name>
     <message>
index e06b61c5f12b446f95e3a9dd9f360feb80e2d43c..21fa8315f62378e141438c94bcfdcb8f70c212cf 100644 (file)
       <translation>Sélectionnez l&apos;arête de référence.</translation>
     </message>
   </context>
+  <context>
+    <name>Point:edge:ConstructionPlugin_ValidatorNotFeature</name>
+    <message>
+      <source>Wrong attribute</source>
+      <translation>Attribut incorrect.</translation>
+    </message>
+    <message>
+      <source>Feature should not be selected</source>
+      <translation>La fonction ne doit pas être sélectionnée.</translation>
+    </message>
+  </context>
   <context>
     <name>Point:edge_for_point_projection</name>
     <message>
diff --git a/src/ConstructionPlugin/Test/Test19471.py b/src/ConstructionPlugin/Test/Test19471.py
new file mode 100644 (file)
index 0000000..04937e0
--- /dev/null
@@ -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() != "")
index 450dadd33f32adad79d5486b8294f719509deae9..1acb33893c524be2a192ec07d6c55c0a2962f295 100644 (file)
@@ -16,6 +16,7 @@
                       icon="icons/Construction/edge.png"
                       shape_types="edge">
         <validator id="GeomValidators_Finite"/>
+        <validator id="ConstructionPlugin_ValidatorNotFeature"/>
       </shape_selector>
       <radiobox id="offset_type">
         <radio id="offset_type_by_distance"