From 163192afd6eaa35db5c8b961e924962644e4f9dc Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 5 Feb 2016 16:02:48 +0300 Subject: [PATCH] Unit tests: 1. Changed unit tests to make 3 points creation of arc and circle. 2. Fixed the problem in Platine unit test. --- src/PythonAPI/model/sketcher/sketch.py | 2 +- src/PythonAPI/model/tools.py | 10 +++++++ src/SketchPlugin/SketchPlugin_Arc.cpp | 9 ++++-- src/SketchPlugin/Test/TestConstraintEqual.py | 10 +++---- .../Test/TestConstraintTangent.py | 30 ++++++++++++++++++- 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/PythonAPI/model/sketcher/sketch.py b/src/PythonAPI/model/sketcher/sketch.py index 9dabe0a9d..5303f7df5 100644 --- a/src/PythonAPI/model/sketcher/sketch.py +++ b/src/PythonAPI/model/sketcher/sketch.py @@ -320,7 +320,7 @@ class Sketch(Interface): constraint.data().reflist("ConstraintEntityB").append(line_2) elif len(args) == 2: point, radius = args - self._fillAttribute(constraint.refattr("ConstraintEntityA"), point) + self._fillAttribute(constraint.data().refattrlist("ConstraintEntityA"), [point]) self._fillAttribute(constraint.real("ConstraintValue"), radius) self.execute() return constraint diff --git a/src/PythonAPI/model/tools.py b/src/PythonAPI/model/tools.py index 508126186..cde3e64bf 100644 --- a/src/PythonAPI/model/tools.py +++ b/src/PythonAPI/model/tools.py @@ -100,6 +100,16 @@ def fill_attribute(attribute, value): assert(isinstance(item, ModelAPI.ModelAPI_Object)) attribute.append(item) + elif isinstance(attribute, ModelAPI.ModelAPI_AttributeRefAttrList): + attribute.clear() + if not value: + return + + assert(isinstance(value, collections.Iterable)) + for item in value: + assert(isinstance(item, ModelAPI.ModelAPI_Attribute)) + attribute.append(item) + elif isinstance(attribute, ModelAPI.ModelAPI_AttributeSelection): if value is None: attribute.setValue(None, None) diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index b9c73ef85..d505350cb 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -382,8 +382,13 @@ static inline void calculatePassedPoint( theStartPoint->xy()->decreased(theCenter->xy()))); std::shared_ptr aEndDir(new GeomAPI_Dir2d( theEndPoint->xy()->decreased(theCenter->xy()))); - std::shared_ptr aMidDir(new GeomAPI_Dir2d( - aStartDir->xy()->added(aEndDir->xy()))); + std::shared_ptr aMidDirXY = aStartDir->xy()->added(aEndDir->xy()); + if (aMidDirXY->dot(aMidDirXY) < tolerance * tolerance) { + // start and end directions are opposite, so middle direction will be orthogonal + aMidDirXY->setX(-aStartDir->y()); + aMidDirXY->setY(aStartDir->x()); + } + std::shared_ptr aMidDir(new GeomAPI_Dir2d(aMidDirXY)); if ((aStartDir->cross(aMidDir) > 0) ^ !theArcReversed) aMidDir->reverse(); diff --git a/src/SketchPlugin/Test/TestConstraintEqual.py b/src/SketchPlugin/Test/TestConstraintEqual.py index cd3fb37ca..d4176eebd 100644 --- a/src/SketchPlugin/Test/TestConstraintEqual.py +++ b/src/SketchPlugin/Test/TestConstraintEqual.py @@ -28,12 +28,12 @@ def externalSketch(theDoc): dirx.setValue(1, 0, 0) norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) norm.setValue(0, 0, 1) - # add circle + # add circle defined by 3 points circle = aSketchFeature.addFeature("SketchCircle") - circleCenter = geomDataAPI_Point2D(circle.attribute("CircleCenter")) - circleRadius = circle.real("CircleRadius") - circleCenter.setValue(-50., 50.) - circleRadius.setValue(10.) + circle.string("CircleType").setValue("ThreePoints") + geomDataAPI_Point2D(circle.attribute("FirstPoint")).setValue(-40., 50.) + geomDataAPI_Point2D(circle.attribute("SecondPoint")).setValue(-50., 60.) + geomDataAPI_Point2D(circle.attribute("ThirdPoint")).setValue(-60., 50.) # add line line = aSketchFeature.addFeature("SketchLine") lineStart = geomDataAPI_Point2D(line.attribute("StartPoint")) diff --git a/src/SketchPlugin/Test/TestConstraintTangent.py b/src/SketchPlugin/Test/TestConstraintTangent.py index e83d85716..5329c5de2 100644 --- a/src/SketchPlugin/Test/TestConstraintTangent.py +++ b/src/SketchPlugin/Test/TestConstraintTangent.py @@ -148,12 +148,14 @@ aSession.finishOperation() # Arc 2 aSession.startOperation() aSketchArc2 = aSketchFeature.addFeature("SketchArc") +aSketchArc2.string("ArcType").setValue("ThreePoints") anArc2Centr = geomDataAPI_Point2D(aSketchArc2.attribute("ArcCenter")) -anArc2Centr.setValue(-10., 10.) anArc2StartPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcStartPoint")) anArc2StartPoint.setValue(0., 50.) anArc2EndPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcEndPoint")) anArc2EndPoint.setValue(-50., 0.) +anArc2PassedPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcPassedPoint")) +anArc2PassedPoint.setValue(-40., 40.) aSession.finishOperation() #========================================================================= # Link points of arcs by the coincidence constraint @@ -225,6 +227,32 @@ assert(aLine2EndPointNew == aLine2EndPointPrev) assert(anArc2CenterNew == anArc2CenterPrev) assert(anArc2StartPointNew == anArc2StartPointPrev) assert(anArc2EndPointNew == anArc2EndPointPrev) +aSession.startOperation() +aSketchFeature.removeFeature(aTangency) +aSession.finishOperation() + +#========================================================================= +# TEST 4. Creating of tangency arc by the option of the SketchArc feature +#========================================================================= +aSession.startOperation() +aSketchArc3 = aSketchFeature.addFeature("SketchArc") +aSketchArc3.string("ArcType").setValue("Tangent") +anArc3Start = aSketchArc3.refattr("ArcTangentPoint") +anArc3Start.setAttr(anArc1StartPoint) +anArc3EndPoint = geomDataAPI_Point2D(aSketchArc3.attribute("ArcEndPoint")) +anArc3EndPoint.setValue(100., 0.) +aSession.finishOperation() +anArc3Center = geomDataAPI_Point2D(aSketchArc2.attribute("ArcCenter")) +anArc3StartPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcStartPoint")) + +anArc1VecX = anArc1EndPoint.x() - anArc1Centr.x() +anArc1VecY = anArc1EndPoint.y() - anArc1Centr.y() +aLen = math.sqrt(anArc1VecX**2 + anArc1VecY**2) +anArc3VecX = anArc3StartPoint.x() - anArc3Center.x() +anArc3VecY = anArc3StartPoint.y() - anArc3Center.y() +aLen = aLen * math.sqrt(anArc3VecX**2 + anArc3VecY**2) +aCross = anArc1VecX * anArc3VecY - anArc1VecY * anArc3VecX +assert math.fabs(aCross) <= 2.e-6 * aLen, "Observed cross product: {0}".format(aCross) #========================================================================= # End of test #========================================================================= -- 2.39.2