]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for some problems in the arc inversion and added a unit test for it
authormpv <mpv@opencascade.com>
Wed, 14 Dec 2016 11:44:58 +0000 (14:44 +0300)
committermpv <mpv@opencascade.com>
Wed, 14 Dec 2016 11:44:58 +0000 (14:44 +0300)
src/ModelAPI/ModelAPI.i
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/Test/TestArcBehavior.py [new file with mode: 0644]

index 6fd73dedba08d1c0fc98e94f641159c4fd032477..29c049f7abf24aa7bb09faab741e9ec7cde5af48 100644 (file)
@@ -172,3 +172,6 @@ template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr
 %template(modelAPI_AttributeRefList)       shared_ptr_cast<ModelAPI_AttributeRefList, ModelAPI_Attribute>;
 %template(modelAPI_AttributeRefAttrList)   shared_ptr_cast<ModelAPI_AttributeRefAttrList, ModelAPI_Attribute>;
 %template(modelAPI_AttributeTables)        shared_ptr_cast<ModelAPI_AttributeTables, ModelAPI_Attribute>;
+
+// Geometry casts
+%template(shapeToEdge) shared_ptr_cast<GeomAPI_Edge, GeomAPI_Shape>;
index c0d06f3bfea910ff9dd9c922bf27c5ebae959d9d..dd373fe5a607d7aecc0eafb8b2301c8561c3913a 100644 (file)
@@ -142,4 +142,5 @@ ADD_UNIT_TESTS(TestSketchPointLine.py
                TestProjection.py
                TestSplit.py
                TestHighload.py
-               TestSnowflake.py)
+               TestSnowflake.py
+               TestArcBehavior.py )
index 90801362d927793da818c1628b5b191837e312f6..be7ad7dc72845ce56f0df6a86574181a88e2c311 100644 (file)
@@ -442,14 +442,12 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID)
     std::shared_ptr<GeomAPI_Circ2d> aCircleForArc(new GeomAPI_Circ2d(aCenter, aStart));
 
     data()->blockSendAttributeUpdated(true);
-    if (theID == END_ID() && isStable()) {
-      // The arc is under construction, so its end point projected
-      // on the circle formed by center and start points
-      std::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEnd);
-      if (aProjection && anEnd->distance(aProjection) > tolerance) {
-        anEndAttr->setValue(aProjection);
-        anEnd = aProjection;
-      }
+    // The Arc end point is projected
+    // on the circle formed by center and start points
+    std::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEnd);
+    if (aProjection && anEnd->distance(aProjection) > tolerance) {
+      anEndAttr->setValue(aProjection);
+      anEnd = aProjection;
     }
     // update all other attributes due to the base attributes values
     if (aTypeAttr->value() == ARC_TYPE_THREE_POINTS()) {
@@ -518,7 +516,7 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID)
     AttributeBooleanPtr isInversed =
         std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(attribute(INVERSED_ID()));
     double aParameterNew = aEndParam - aStartParam;
-    if (0 <= myParamBefore && myParamBefore <= PI / 2.0 &&
+    if (((0 <= myParamBefore && myParamBefore <= PI / 2.0) || myParamBefore == PI * 2.0) &&
         PI * 1.5 <= aParameterNew && aParameterNew <= PI * 2.0)
       isInversed->setValue(true);
     else if (PI * 1.5 <= myParamBefore && myParamBefore <= PI * 2.0 &&
diff --git a/src/SketchPlugin/Test/TestArcBehavior.py b/src/SketchPlugin/Test/TestArcBehavior.py
new file mode 100644 (file)
index 0000000..7498a37
--- /dev/null
@@ -0,0 +1,133 @@
+"""
+    TestArcBehavior.py
+
+    It tests behavior of the arc during the changing of parameters to avoid
+    regressions in this complicated part.
+
+"""
+
+#=========================================================================
+# of the test
+#=========================================================================
+from GeomDataAPI import *
+from ModelAPI import *
+import math
+
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+aSession.startOperation()
+#aSketchFeature = aDocument.addFeature("Sketch")
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSession.finishOperation()
+#=========================================================================
+# Test creation of arc and movements (of mouse coursor) of end point near to the start point:
+# edge must be the minimal length.
+#=========================================================================
+aSession.startOperation()
+aSketchArc = aSketchFeature.addFeature("SketchArc")
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr.setValue(0., 0.)
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint.setValue(0., 10.)
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint.setValue(1., 10.)
+aSession.finishOperation()
+# the arc must be small, not near to the whole circle
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 2.
+# move to the half-circle
+aSession.startOperation()
+anArcEndPoint.setValue(10., 0.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 16.
+aSession.startOperation()
+anArcEndPoint.setValue(0., -10.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 31.
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 32.
+aSession.startOperation()
+anArcEndPoint.setValue(-10., 0.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 47.
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 48.
+aSession.startOperation()
+anArcEndPoint.setValue(-1., 10.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 60.
+# move to the initial point at the right side: the edge must reset to the initial one
+aSession.startOperation()
+anArcEndPoint.setValue(1., 10.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 2.
+# move to the counterclockwise direction
+aSession.startOperation()
+anArcEndPoint.setValue(-1., 10.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 2.
+aSession.startOperation()
+anArcEndPoint.setValue(-10., 0.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 16.
+aSession.startOperation()
+anArcEndPoint.setValue(0., -10.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 31.
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 32.
+aSession.startOperation()
+anArcEndPoint.setValue(10., 0.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 47.
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 48.
+aSession.startOperation()
+anArcEndPoint.setValue(1., 10.)
+aSession.finishOperation()
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 60.
+# check from the scratch that from initial state to counterclockwise position also works
+aSession.startOperation()
+aSketchArc = aSketchFeature.addFeature("SketchArc")
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr.setValue(0., 0.)
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint.setValue(0., 10.)
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint.setValue(-1., 10.)
+aSession.finishOperation()
+# the arc must be small, not near to the whole circle
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 2.
+#=========================================================================
+# Test that movement of the center of arc does not change the orientation of the arc
+#=========================================================================
+aSession.startOperation()
+aSketchArc = aSketchFeature.addFeature("SketchArc")
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr.setValue(0., 0.)
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint.setValue(0., 10.)
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint.setValue(10, 0.)
+aSession.finishOperation()
+anInversed = aSketchArc.boolean("InversedArc").value()
+for aCenterCoords in range(1, 20):
+  aSession.startOperation()
+  anArcCentr.setValue(aCenterCoords, aCenterCoords/2) # move center
+  aSession.finishOperation()
+  assert aSketchArc.boolean("InversedArc").value() == anInversed
+for aCenterCoords in range(20, -20, -1):
+  aSession.startOperation()
+  anArcCentr.setValue(aCenterCoords, aCenterCoords/2) # move center
+  aSession.finishOperation()
+  assert aSketchArc.boolean("InversedArc").value() == anInversed
+for aCenterCoords in range(-20, 20):
+  aSession.startOperation()
+  anArcCentr.setValue(aCenterCoords, aCenterCoords/2) # move center
+  aSession.finishOperation()
+  assert aSketchArc.boolean("InversedArc").value() == anInversed