Salome HOME
Fix for the issue #2115
authormpv <mpv@opencascade.com>
Mon, 10 Apr 2017 08:00:18 +0000 (11:00 +0300)
committermpv <mpv@opencascade.com>
Mon, 10 Apr 2017 08:00:18 +0000 (11:00 +0300)
src/GeomAPI/GeomAPI_XYZ.cpp
src/GeomAPI/GeomAPI_XYZ.h
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/Test/Test2115.py [new file with mode: 0644]

index 22588c1ed63e303885758c2868472c2e5cd9635b..b20cbf741d277531a6247a79d5d205fb1ab7f93c 100644 (file)
@@ -86,3 +86,7 @@ double GeomAPI_XYZ::distance(const std::shared_ptr<GeomAPI_XYZ>& theOther) const
   return aResult.Modulus();
 }
 
+double GeomAPI_XYZ::squareModulus() const
+{
+  return MY_XYZ->SquareModulus();
+}
index de2f98903498a80650b3988df8350232e3e9a57d..fdd43d9fe4f6229cfe25122d84a0c0227dffdcb1 100644 (file)
@@ -62,6 +62,9 @@ class GeomAPI_XYZ : public GeomAPI_Interface
   /// Distance between two triplets
   GEOMAPI_EXPORT
   double distance(const std::shared_ptr<GeomAPI_XYZ>& theOther) const;
+
+  /// Square length of triplet from the origin
+  GEOMAPI_EXPORT double squareModulus() const;
 };
 
 #endif
index 8058fa5852acb12e0594f734d130c6f783098b7d..cc0ec81699027436d963779c7ea8fb2ce71eede3 100644 (file)
@@ -302,7 +302,7 @@ std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCen
                                                                    double thePassedY)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
-    compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+    compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
   return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
                                                             thePassedX, thePassedY));
 }
@@ -312,7 +312,7 @@ std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
     const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
-    compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+    compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
   return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
 }
 
@@ -321,7 +321,7 @@ std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1,
                                                                    double theX3, double theY3)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
-    compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+    compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
   return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
                                                             theX2, theY2,
                                                             theX3, theY3));
@@ -333,7 +333,7 @@ std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
     const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
-    compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+    compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
   return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
 }
 
@@ -384,7 +384,7 @@ std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(double theStartX, d
                                                         double thePassedX, double thePassedY)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
-    compositeFeature()->addFeature(SketchPlugin_Arc::ID());
+    compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
   return MacroArcPtr(new SketchAPI_MacroArc(aFeature,
                                        theStartX, theStartY,
                                        theEndX, theEndY,
@@ -397,7 +397,7 @@ std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
                                                 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
-    compositeFeature()->addFeature(SketchPlugin_Arc::ID());
+    compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
   return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed));
 }
 
@@ -407,7 +407,7 @@ std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
                                                 bool theInversed)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
-    compositeFeature()->addFeature(SketchPlugin_Arc::ID());
+    compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
   return MacroArcPtr(new SketchAPI_MacroArc(
     aFeature, theTangentPoint, theEndX, theEndY, theInversed));
 }
@@ -418,7 +418,7 @@ std::shared_ptr<SketchAPI_MacroArc> SketchAPI_Sketch::addArc(
                                               bool theInversed)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
-    compositeFeature()->addFeature(SketchPlugin_Arc::ID());
+    compositeFeature()->addFeature(SketchPlugin_MacroArc::ID());
   return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed));
 }
 
index d9aa0c5dadc288890e78120859c019649ed80c3c..1d18e369d568ec9870959279337c8ca678f3457c 100644 (file)
@@ -165,6 +165,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py
                Test1966.py
                Test1967.py
                Test2095.py
+               Test2115.py
                TestTrimArc01.py
                TestTrimArc02.py
                TestTrimArc03.py
index a441c6f658589c3413197c3e3db50146d900c08f..37caf12143bccc5901d129f3452eb7ec97140ff6 100755 (executable)
@@ -1214,8 +1214,18 @@ static bool isOnSameSide(const std::shared_ptr<GeomAPI_Lin>& theLine,
   static const double aTolerance = 1.e-7;
   std::shared_ptr<GeomAPI_Dir> aLineDir = theLine->direction();
   std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
+
+  std::shared_ptr<GeomAPI_XYZ> aVec1 = thePoint1->xyz()->decreased(aLineLoc);
+  // the first point is on the line
+  if (aVec1->squareModulus() < aTolerance * aTolerance)
+    return false;
   std::shared_ptr<GeomAPI_Dir> aDirP1L(new GeomAPI_Dir(thePoint1->xyz()->decreased(aLineLoc)));
+  std::shared_ptr<GeomAPI_XYZ> aVec2 = thePoint1->xyz()->decreased(aLineLoc);
+  // the second point is on the line
+  if (aVec2->squareModulus() < aTolerance * aTolerance)
+    return false;
   std::shared_ptr<GeomAPI_Dir> aDirP2L(new GeomAPI_Dir(thePoint2->xyz()->decreased(aLineLoc)));
+
   return aLineDir->cross(aDirP1L)->dot(aLineDir->cross(aDirP2L)) > -aTolerance;
 }
 
diff --git a/src/SketchPlugin/Test/Test2115.py b/src/SketchPlugin/Test/Test2115.py
new file mode 100644 (file)
index 0000000..3f7defa
--- /dev/null
@@ -0,0 +1,51 @@
+"""
+    Test1061.py
+    Test case for issue #1061 "Distance constraint using for points with equal coordinates"
+"""
+
+from salome.shaper import model
+from ModelAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+# Create a centered rectangle (from the 2115 issue description)
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(132.9002660287441, 132.9002660287441, -132.9002660287441, 132.9002660287441)
+SketchLine_2 = Sketch_1.addLine(-132.9002660287441, 132.9002660287441, -132.9002660287441, -132.9002660287441)
+SketchLine_3 = Sketch_1.addLine(-132.9002660287441, -132.9002660287441, 132.9002660287441, -132.9002660287441)
+SketchLine_4 = Sketch_1.addLine(132.9002660287441, -132.9002660287441, 132.9002660287441, 132.9002660287441)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
+SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
+SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
+SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
+SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
+SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
+SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
+SketchLine_5 = Sketch_1.addLine(-132.9002660287441, -132.9002660287441, 132.9002660287441, 132.9002660287441)
+SketchLine_5.setAuxiliary(True)
+SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_5.startPoint())
+SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_5.endPoint())
+SketchLine_6 = Sketch_1.addLine(-132.9002660287441, 132.9002660287441, 132.9002660287441, -132.9002660287441)
+SketchLine_6.setAuxiliary(True)
+SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_6.startPoint())
+SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_6.endPoint())
+SketchPoint_1 = Sketch_1.addPoint(model.selection("VERTEX", "PartSet/Origin"))
+SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchLine_5.result())
+SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchLine_6.result())
+SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_1.result(), SketchLine_2.result())
+
+# create a circle by 3 points of this rectangle (to make the last as a line later)
+circle = Sketch_1.addCircle(SketchLine_2.startPoint().pnt(), SketchLine_1.startPoint().pnt(), SketchLine_3.endPoint().pnt())
+
+# create by the real references
+circle.feature().refattr("first_point_ref").setAttr(SketchLine_2.startPoint())
+circle.feature().refattr("second_point_ref").setAttr(SketchLine_1.startPoint())
+circle.feature().refattr("third_point_ref").setObject(SketchLine_6.feature().firstResult())
+# here there was a crash in the issue (actually, sketch is overconstrained, so, assertion is not used, just call for validators)
+aFactory = ModelAPI_Session.get().validators()
+aFactory.validate(circle.feature())
+model.end()