]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Unit tests:
authorazv <azv@opencascade.com>
Fri, 5 Feb 2016 13:02:48 +0000 (16:02 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:36 +0000 (17:04 +0300)
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
src/PythonAPI/model/tools.py
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/Test/TestConstraintEqual.py
src/SketchPlugin/Test/TestConstraintTangent.py

index 9dabe0a9df299d520accd21d387f99117c5a1d45..5303f7df5c335e67554367d39c8ebc4241666953 100644 (file)
@@ -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
index 5081261863a166b52a4fd0c36d9cc4cf5288543a..cde3e64bff00c02d05527e91e42706416b2f41bb 100644 (file)
@@ -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)
index b9c73ef85ebcac8b00fe9e58b0ad2c7d41caa52d..d505350cbba5751fb8e75abac023fc50b5208514 100644 (file)
@@ -382,8 +382,13 @@ static inline void calculatePassedPoint(
       theStartPoint->xy()->decreased(theCenter->xy())));
   std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
       theEndPoint->xy()->decreased(theCenter->xy())));
-  std::shared_ptr<GeomAPI_Dir2d> aMidDir(new GeomAPI_Dir2d(
-      aStartDir->xy()->added(aEndDir->xy())));
+  std::shared_ptr<GeomAPI_XY> 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<GeomAPI_Dir2d> aMidDir(new GeomAPI_Dir2d(aMidDirXY));
   if ((aStartDir->cross(aMidDir) > 0) ^ !theArcReversed)
     aMidDir->reverse();
 
index cd3fb37ca6b0f06d08d3526037e8e939a754d135..d4176eebd4449fcbb7dd8496b5291832a5a5c8b8 100644 (file)
@@ -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"))
index e83d85716529d7f66b30a8c4bb8105fcf00321ac..5329c5de22416a42ca456a9d1ba6b54cc06d86a6 100644 (file)
@@ -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
 #=========================================================================