Salome HOME
Fix for crash in Object Browser when object was deleted but message not sent
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintMirror.py
index de1c0870e0a1596151c28c6ef768dce3c5b00538..43d2c45bb3fc2a1c32010e6c692219b7ecc7718d 100644 (file)
@@ -4,9 +4,9 @@
         
     SketchPlugin_ConstraintMirror
         static const std::string MY_CONSTRAINT_MIRROR_ID("SketchConstraintMirror");
-        data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
-        data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefListAttr::type());
-        data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefListAttr::type());
+        data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
+        data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefListAttr::typeId());
+        data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefListAttr::typeId());
 
 """
 from GeomDataAPI import *
@@ -25,13 +25,11 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+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)
-diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
-diry.setValue(0, 1, 0)
 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
@@ -122,5 +120,37 @@ aRefListB.append(aSketchLine2)
 aMirror.execute()
 aSession.finishOperation()
 #=========================================================================
+# Verify the simmetricity of all mirrored objects
+#=========================================================================
+aRefListC = aMirror.reflist("ConstraintEntityC")
+aListSize = aRefListB.size()
+aLineDirX = aLineEndPoint.x() - aLineStartPoint.x()
+aLineDirY = aLineEndPoint.y() - aLineStartPoint.y()
+
+for ind in range(0, aListSize):
+  aFeatureB = modelAPI_Feature(aRefListB.object(ind))
+  aFeatureC = modelAPI_Feature(aRefListC.object(ind))
+  assert(aFeatureB is not None)
+  assert(aFeatureC is not None)
+  assert(aFeatureB.getKind() == aFeatureC.getKind())
+  anAttributes = {}
+  print aFeatureB.getKind()
+  if (aFeatureB.getKind() == "SketchLine"):
+    anAttributes = {'StartPoint':'StartPoint', 'EndPoint':'EndPoint'}
+  elif (aFeatureB.getKind() == "SketchArc"):
+    anAttributes = {'ArcCenter':'ArcCenter', 'ArcStartPoint':'ArcEndPoint', 'ArcEndPoint':'ArcStartPoint'}
+
+  for key in anAttributes:
+    aPointB = geomDataAPI_Point2D(aFeatureB.attribute(key))
+    aPointC = geomDataAPI_Point2D(aFeatureC.attribute(anAttributes[key]))
+    aDirX = aPointC.x() - aPointB.x()
+    aDirY = aPointC.y() - aPointB.y()
+    aDot = aLineDirX * aDirX + aLineDirY * aDirY
+    assert(math.fabs(aDot) < 1.e-10)
+    aDirX = aLineEndPoint.x() - 0.5 * (aPointB.x() + aPointC.x())
+    aDirY = aLineEndPoint.y() - 0.5 * (aPointB.y() + aPointC.y())
+    aCross = aLineDirX * aDirY - aLineDirY * aDirX
+    assert(math.fabs(aCross) < 1.e-10)
+#=========================================================================
 # End of test
 #=========================================================================