From 12acc7eb85277c1635857742a781cd2889f36e05 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 10 Apr 2017 11:00:18 +0300 Subject: [PATCH] Fix for the issue #2115 --- src/GeomAPI/GeomAPI_XYZ.cpp | 4 ++ src/GeomAPI/GeomAPI_XYZ.h | 3 ++ src/SketchAPI/SketchAPI_Sketch.cpp | 16 +++--- src/SketchPlugin/CMakeLists.txt | 1 + src/SketchPlugin/SketchPlugin_Validators.cpp | 10 ++++ src/SketchPlugin/Test/Test2115.py | 51 ++++++++++++++++++++ 6 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 src/SketchPlugin/Test/Test2115.py diff --git a/src/GeomAPI/GeomAPI_XYZ.cpp b/src/GeomAPI/GeomAPI_XYZ.cpp index 22588c1ed..b20cbf741 100644 --- a/src/GeomAPI/GeomAPI_XYZ.cpp +++ b/src/GeomAPI/GeomAPI_XYZ.cpp @@ -86,3 +86,7 @@ double GeomAPI_XYZ::distance(const std::shared_ptr& theOther) const return aResult.Modulus(); } +double GeomAPI_XYZ::squareModulus() const +{ + return MY_XYZ->SquareModulus(); +} diff --git a/src/GeomAPI/GeomAPI_XYZ.h b/src/GeomAPI/GeomAPI_XYZ.h index de2f98903..fdd43d9fe 100644 --- a/src/GeomAPI/GeomAPI_XYZ.h +++ b/src/GeomAPI/GeomAPI_XYZ.h @@ -62,6 +62,9 @@ class GeomAPI_XYZ : public GeomAPI_Interface /// Distance between two triplets GEOMAPI_EXPORT double distance(const std::shared_ptr& theOther) const; + + /// Square length of triplet from the origin + GEOMAPI_EXPORT double squareModulus() const; }; #endif diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 8058fa585..cc0ec8169 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -302,7 +302,7 @@ std::shared_ptr SketchAPI_Sketch::addCircle(double theCen double thePassedY) { std::shared_ptr 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_Sketch::addCircle( const std::shared_ptr& thePassedPoint) { std::shared_ptr 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_Sketch::addCircle(double theX1, double theX3, double theY3) { std::shared_ptr 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_Sketch::addCircle( const std::shared_ptr& thePoint3) { std::shared_ptr 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_Sketch::addArc(double theStartX, d double thePassedX, double thePassedY) { std::shared_ptr 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_Sketch::addArc( const std::shared_ptr& thePassed) { std::shared_ptr 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_Sketch::addArc( bool theInversed) { std::shared_ptr 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_Sketch::addArc( bool theInversed) { std::shared_ptr aFeature = - compositeFeature()->addFeature(SketchPlugin_Arc::ID()); + compositeFeature()->addFeature(SketchPlugin_MacroArc::ID()); return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed)); } diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index d9aa0c5da..1d18e369d 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -165,6 +165,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py Test1966.py Test1967.py Test2095.py + Test2115.py TestTrimArc01.py TestTrimArc02.py TestTrimArc03.py diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index a441c6f65..37caf1214 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -1214,8 +1214,18 @@ static bool isOnSameSide(const std::shared_ptr& theLine, static const double aTolerance = 1.e-7; std::shared_ptr aLineDir = theLine->direction(); std::shared_ptr aLineLoc = theLine->location()->xyz(); + + std::shared_ptr aVec1 = thePoint1->xyz()->decreased(aLineLoc); + // the first point is on the line + if (aVec1->squareModulus() < aTolerance * aTolerance) + return false; std::shared_ptr aDirP1L(new GeomAPI_Dir(thePoint1->xyz()->decreased(aLineLoc))); + std::shared_ptr aVec2 = thePoint1->xyz()->decreased(aLineLoc); + // the second point is on the line + if (aVec2->squareModulus() < aTolerance * aTolerance) + return false; std::shared_ptr 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 index 000000000..3f7defa9e --- /dev/null +++ b/src/SketchPlugin/Test/Test2115.py @@ -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() -- 2.30.2