]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue 19101: Sketch in error when running a dumped study
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Sun, 17 May 2020 20:35:53 +0000 (23:35 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Sun, 17 May 2020 20:35:53 +0000 (23:35 +0300)
Eliminate projection of a point lying in the same sketch.

src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/Test/Test19101.py [new file with mode: 0644]

index 23e34d4d5bee873c4b365b3bba698479941cdb44..0a4a01218f701def724beb73a58fc4fdd1eeb0be 100644 (file)
@@ -227,6 +227,7 @@ ADD_UNIT_TESTS(
   Test3154.py
   Test3170.py
   Test19089.py
+  Test19101.py
   TestArcBehavior.py
   TestBSplineAddPole.py
   TestChangeSketchPlane1.py
index b4463445b872b31ae33eb0a11fd67735a96a596b..d6c7d5d93c44ce8dfa1ef6e2f8f96b324673c652 100644 (file)
@@ -1161,20 +1161,21 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
 
   AttributeSelectionPtr aFeatureAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  std::shared_ptr<GeomAPI_Vertex> aVertex;
   std::shared_ptr<GeomAPI_Edge> anEdge;
   std::shared_ptr<SketchPlugin_Feature> aSketchFeature;
   if (aFeatureAttr.get()) {
     GeomShapePtr aVal = aFeatureAttr->value();
     ResultPtr aRes = aFeatureAttr->context();
     if (aVal && aVal->isVertex())
-      return true; // vertex is always could be projected
-    if (aVal && aVal->isEdge()) {
-      anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->value()));
+      aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aVal));
+    else if (aVal && aVal->isEdge()) {
+      anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aVal));
     } else if(aRes && aRes->shape()) {
       if (aRes->shape()->isVertex())
-        return true; // vertex is always could be projected
+        aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aRes->shape()));
       else if (aRes->shape()->isEdge())
-        anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->context()->shape()));
+        anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aRes->shape()));
     }
 
     // try to convert result to sketch feature
@@ -1183,7 +1184,7 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
         std::dynamic_pointer_cast<SketchPlugin_Feature>(ModelAPI_Feature::feature(aRes));
     }
   }
-  if (!anEdge) {
+  if (!aVertex && !anEdge) {
     theError = "The attribute %1 should be an edge or vertex";
     theError.arg(theAttribute->id());
     return false;
@@ -1215,7 +1216,9 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
   std::shared_ptr<GeomAPI_Pnt> anOrigin = aPlane->location();
 
   bool aValid = true;
-  if (anEdge->isLine()) {
+  if (aVertex)
+    aValid = true; // vertex is always could be projected
+  else if (anEdge->isLine()) {
     std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
     std::shared_ptr<GeomAPI_Dir> aLineDir = aLine->direction();
     double aDot = fabs(aNormal->dot(aLineDir));
diff --git a/src/SketchPlugin/Test/Test19101.py b/src/SketchPlugin/Test/Test19101.py
new file mode 100644 (file)
index 0000000..a44bbc8
--- /dev/null
@@ -0,0 +1,44 @@
+# 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()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Top"))
+SketchLine_1 = Sketch_1.addLine(3.455185109181585, 2.504529791754867, 6.714574768930328, 7.155950452021305)
+SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Right][Box_1_1/Top]"), True)
+SketchPoint_1 = SketchProjection_1.createdFeature()
+SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), True)
+SketchLine_2 = SketchProjection_2.createdFeature()
+SketchProjection_3 = Sketch_1.addProjection(model.selection("EDGE", "Sketch_1/SketchLine_1"), True)
+SketchProjection_4 = Sketch_1.addProjection(model.selection("VERTEX", "Sketch_1/SketchLine_1_EndVertex"), True)
+model.do()
+
+model.end()
+
+from ModelAPI import *
+validators = ModelAPI_Session.get().validators()
+assert(validators.validate(SketchProjection_1.feature()))
+assert(validators.validate(SketchProjection_2.feature()))
+assert(not validators.validate(SketchProjection_3.feature()))
+assert(not validators.validate(SketchProjection_4.feature()))