def bottom_body():
# Create XOY sketch
- sketch = model.addSketch(part, "Extrusion_1_1/LateralFace_2")
+ sketch = model.addSketch(part, "Extrusion_1_1/LateralFace_4")
# Create base polygon
points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
sketch.setEqual(top.result(), bottom.result())
sketch.setEqual(h1.result(), h2.result())
- sketch.setLength(top.result(), "P")
- sketch.setLength(right.result(), 16)
- sketch.setLength(v1.result(), 16)
- sketch.setLength(h2.result(), 20)
-
sketch.setCoincident(arc.center(), v1.result())
sketch.setCoincident(arc.startPoint(), h2.endPoint())
sketch.setCoincident(arc.endPoint(), h1.startPoint())
# Binding
- left_e = sketch.addLine("Extrusion_1_1/LateralFace_2&Extrusion_1_1/ToFace_1")
+ left_e = sketch.addLine("Extrusion_1_1/LateralFace_4&Extrusion_1_1/ToFace_1")
sketch.setCoincident(left_e.startPoint(), left.endPoint())
sketch.setCoincident(left_e.endPoint(), left.startPoint())
model.do() #!!!
+ # Dimensions
+ sketch.setLength(v1.result(), 16)
+ sketch.setLength(h2.result(), 20)
+ sketch.setLength(right.result(), 16)
+ sketch.setLength(top.result(), "P")
+ model.do()
+
# Create extrusion
body = model.addExtrusion(part, sketch.selectFace(), "-E")
def body_3():
# Create XOZ sketch
- sketch = model.addSketch(part, "Boolean_1_1/Modified_3")
+ sketch = model.addSketch(part, "Boolean_1_1/Modified_4")
# Create base polygon
H, L, l, r = 28, 40, 8, 12
sketch.setRadius(arc.result(), r)
# Binding
- bottom_e = sketch.addLine("Boolean_1_1/Modified_1&Boolean_1_1/Modified_3")
+ bottom_e = sketch.addLine("Boolean_1_1/Modified_1&Boolean_1_1/Modified_4")
sketch.setCoincident(bottom_e.result(), bottom.startPoint())
sketch.setCoincident(bottom_e.startPoint(), bottom.endPoint())
def body_4():
# Create XOZ 2nd sketch
- sketch = model.addSketch(part, "Boolean_2_1/Modified_7")
+ sketch = model.addSketch(part, "Boolean_2_1/Modified_8")
# Create base polygon
points = [(0, 0), (0, 1), (1, 0)]
sketch.setCoincident(bottom_e.endPoint(), bottom.startPoint())
sketch.setCoincident(bottom_e.startPoint(), left.startPoint())
- left_e = sketch.addLine("Boolean_2_1/Modified_3&Boolean_2_1/Modified_2")
+ left_e = sketch.addLine("Boolean_2_1/Modified_4&Boolean_2_1/Modified_2")
sketch.setCoincident(left_e.startPoint(), left.endPoint())
model.do() #!!!
"""
from GeomDataAPI import *
from ModelAPI import *
+import math
#=========================================================================
# Initialization of the test
#=========================================================================
__updated__ = "2014-10-28"
+TOLERANCE = 1.e-7
+
+#=========================================================================
+# Auxiliary functions
+#=========================================================================
+def checkPointOnLine(point, line):
+ aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
+ aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
+ aDirX = aEnd.x() - aStart.x()
+ aDirY = aEnd.y() - aStart.y()
+ aVecX = point.x() - aStart.x()
+ aVecY = point.y() - aStart.y()
+ assert (math.fabs(aDirX * aVecY - aDirY * aVecX) <= TOLERANCE)
+
+def checkPointOnCircle(point, circle):
+ aCenter = geomDataAPI_Point2D(circle.attribute("CircleCenter"))
+ aRadius = circle.real("CircleRadius").value()
+ aDist = math.hypot(point.x() - aCenter.x(), point.y() - aCenter.y())
+ assert (math.fabs(aDist - aRadius) <= TOLERANCE)
+
+def checkPointOnArc(point, arc):
+ aStart = geomDataAPI_Point2D(arc.attribute("ArcStartPoint"))
+ aCenter = geomDataAPI_Point2D(arc.attribute("ArcCenter"))
+ aRadius = math.hypot(aStart.x() - aCenter.x(), aStart.y() - aCenter.y())
+ aDist = math.hypot(point.x() - aCenter.x(), point.y() - aCenter.y())
+ assert (math.fabs(aDist - aRadius) <= TOLERANCE)
+
+
+#=========================================================================
+# Start of test
+#=========================================================================
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
+# add an origin
+aSession.startOperation()
+aFeature = aDocument.addFeature("Point")
+aFeature.real("x").setValue(0.)
+aFeature.real("y").setValue(0.)
+aFeature.real("z").setValue(0.)
+anOriginName = aFeature.name()
+aSession.finishOperation()
#=========================================================================
# Creation of a sketch
#=========================================================================
aSession.startOperation()
-aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch"))
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
deltaX = deltaY = 40.
# move line
aSession.startOperation()
-anArcStartPoint.setValue(aLineStartPoint.x() + deltaX,
+aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
aLineStartPoint.y() + deltaY)
-anArcEndPoint.setValue(aLineEndPoint.x() + deltaX,
+aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
aLineEndPoint.y() + deltaY)
aSession.finishOperation()
# check that arc's points are moved also
assert (anArcEndPoint.x() == aLineStartPoint.x())
assert (anArcEndPoint.y() == aLineStartPoint.y())
#=========================================================================
-# TODO: improve test
-# 1. remove constraint, move line to check that constraint are not applied
-# 2. make a new constraint when the points are distanced from each other,
-# check that one from constrainted objects has moved
+# Remove coincidence and move the line
+#=========================================================================
+aSession.startOperation()
+aDocument.removeFeature(aConstraint)
+aSession.finishOperation()
+aSession.startOperation()
+aLineStartPoint.setValue(70., 0.)
+aSession.finishOperation()
+assert (anArcEndPoint.x() != aLineStartPoint.x() or anArcEndPoint.y() != aLineStartPoint.y())
+
+#=========================================================================
+# Add constraint point-on-line
+#=========================================================================
+aSession.startOperation()
+aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
+reflistA.setAttr(anArcStartPoint)
+reflistB.setObject(aSketchLine.lastResult())
+aConstraint.execute()
+aSession.finishOperation()
+checkPointOnLine(anArcStartPoint, aSketchLine)
+#=========================================================================
+# Add constraint point-on-circle
+#=========================================================================
+aSession.startOperation()
+# create circle with center coincident with origin
+aSketchCircle = aSketchFeature.addFeature("SketchCircle")
+aCircleCenter = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
+aCircleRadius = aSketchCircle.real("CircleRadius")
+aCircleCenter.setValue(10., 10.)
+aCircleRadius.setValue(25.)
+aSession.finishOperation()
+# create origin
+aSession.startOperation()
+anOrigRes = modelAPI_Result(aDocument.objectByName("Construction", anOriginName))
+assert (anOrigRes)
+anOrigShape = anOrigRes.shape()
+assert (anOrigShape)
+anOrigin = aSketchFeature.addFeature("SketchPoint")
+anOriginCoord = geomDataAPI_Point2D(anOrigin.attribute("PointCoordindates"))
+anOriginCoord.setValue(0., 0.)
+anOrigin.selection("External").setValue(anOrigRes, anOrigShape)
+aSession.finishOperation()
+# coincidence between center of circle and the origin
+aSession.startOperation()
+aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
+reflistA.setAttr(aCircleCenter)
+reflistB.setObject(anOrigin.lastResult())
+aSession.finishOperation()
+# point-on-circle
+aSession.startOperation()
+aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
+reflistA.setObject(aSketchCircle.lastResult())
+reflistB.setAttr(aLineEndPoint)
+aConstraint.execute()
+aSession.finishOperation()
+checkPointOnCircle(aLineEndPoint, aSketchCircle)
+#=========================================================================
+# Add constraint point-on-arc
+#=========================================================================
+aSession.startOperation()
+aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
+reflistA.setAttr(aCircleCenter)
+reflistB.setObject(aSketchArc.lastResult())
+aConstraint.execute()
+aSession.finishOperation()
+checkPointOnArc(aCircleCenter, aSketchArc)
+#=========================================================================
+# Check center of circle is still in origin
#=========================================================================
+assert (aCircleCenter.x() == 0. and aCircleCenter.y() == 0.)
#=========================================================================
# End of test
#=========================================================================
__updated__ = "2015-03-16"
+#=========================================================================
+# Auxiliary functions
+#=========================================================================
+def externalSketch(theDoc):
+ aSketchFeature = featureToCompositeFeature(theDoc.addFeature("Sketch"))
+ 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)
+ # add circle
+ circle = aSketchFeature.addFeature("SketchCircle")
+ circleCenter = geomDataAPI_Point2D(circle.attribute("CircleCenter"))
+ circleRadius = circle.real("CircleRadius")
+ circleCenter.setValue(-50., 50.)
+ circleRadius.setValue(10.)
+ # add line
+ line = aSketchFeature.addFeature("SketchLine")
+ lineStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
+ lineEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
+ lineStart.setValue(-40., 35.)
+ lineEnd.setValue(-60., 25.)
+
+def lineLength(theLine):
+ aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint"))
+ aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint"))
+ aVecX = aLineStart.x() - aLineEnd.x()
+ aVecY = aLineStart.y() - aLineEnd.y()
+ return math.hypot(aVecX, aVecY)
+
+
+#=========================================================================
+# Start of test
+#=========================================================================
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
#=========================================================================
+# Creation external sketch
+#=========================================================================
+aSession.startOperation()
+externalSketch(aDocument)
+aSession.finishOperation()
+#=========================================================================
# Creation of a sketch
#=========================================================================
aSession.startOperation()
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
aCircleRadius = aSketchCircle.real("CircleRadius")
-anCircleCentr.setValue(-25., -25)
+anCircleCentr.setValue(-25., -25.)
aCircleRadius.setValue(25.)
aSession.finishOperation()
#=========================================================================
aConstraintEqRad.execute()
aSession.finishOperation()
aCircRadius = aCircleRadius.value();
-anArcVecX = anArcStartPoint.x() - anArcCentr.x();
-anArcVecY = anArcStartPoint.y() - anArcCentr.y();
+anArcVecX = anArcStartPoint.x() - anArcCentr.x()
+anArcVecY = anArcStartPoint.y() - anArcCentr.y()
anArcRadius = math.sqrt(anArcVecX**2 + anArcVecY**2)
assert (math.fabs(aCircRadius - anArcRadius) <= 1.e-10)
+#=========================================================================
+# A constraint to make equal radii of arc and external circle
+#=========================================================================
+aSession.startOperation()
+anExtCircRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchCircle_1"))
+assert(anExtCircRes)
+anExtCircShape = anExtCircRes.shape()
+assert(anExtCircShape)
+anExtCircle = aSketchFeature.addFeature("SketchCircle")
+anExtCircleCenter = geomDataAPI_Point2D(anExtCircle.attribute("CircleCenter"))
+anExtCircleRadius = anExtCircle.real("CircleRadius")
+anExtCircleCenter.setValue(-50., 50.)
+anExtCircleRadius.setValue(10.)
+anExtCircle.selection("External").setValue(anExtCircRes, anExtCircShape)
+aSession.finishOperation()
+aSession.startOperation()
+aConstraintEqRad2 = aSketchFeature.addFeature("SketchConstraintEqual")
+aRefObjectA = aConstraintEqRad2.refattr("ConstraintEntityA")
+aRefObjectB = aConstraintEqRad2.refattr("ConstraintEntityB")
+aRefObjectA.setObject(aSketchCircle.lastResult())
+aRefObjectB.setObject(anExtCircle.lastResult())
+aSession.finishOperation()
+assert (math.fabs(anExtCircleRadius.value() - aCircleRadius.value()) < 1.e-10)
+anArcVecX = anArcStartPoint.x() - anArcCentr.x()
+anArcVecY = anArcStartPoint.y() - anArcCentr.y()
+anArcRadius = math.sqrt(anArcVecX**2 + anArcVecY**2)
+assert (math.fabs(anExtCircleRadius.value() - anArcRadius) <= 1.e-10)
+
#=========================================================================
# Creation of two different lines
#=========================================================================
aRefObjectB.setObject(aResultB)
aConstraintEqLen.execute()
aSession.finishOperation()
-aVecX = aLine1StartPoint.x() - aLine1EndPoint.x();
-aVecY = aLine1StartPoint.y() - aLine1EndPoint.y();
-aLine1Len = math.sqrt(anArcVecX * anArcVecX + anArcVecY * anArcVecY)
-aVecX = aLine2StartPoint.x() - aLine2EndPoint.x();
-aVecY = aLine2StartPoint.y() - aLine2EndPoint.y();
-aLine2Len = math.sqrt(anArcVecX**2 + anArcVecY**2)
-assert (aLine1Len == aLine2Len)
+aLine1Len = lineLength(aSketchLine1)
+aLine2Len = lineLength(aSketchLine2)
+assert (math.fabs(aLine1Len - aLine2Len) < 1.e-10)
+#=========================================================================
+# A constraint to make equal length of line with external line
+#=========================================================================
+aSession.startOperation()
+anExtLineRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchLine_1"))
+assert(anExtLineRes)
+anExtLineShape = anExtLineRes.shape()
+assert(anExtLineShape)
+anExtLine = aSketchFeature.addFeature("SketchLine")
+anExtLineStart = geomDataAPI_Point2D(anExtLine.attribute("StartPoint"))
+anExtLineEnd = geomDataAPI_Point2D(anExtLine.attribute("EndPoint"))
+anExtLineStart.setValue(-40., 35.)
+anExtLineEnd.setValue(-60., 25.)
+anExtLine.selection("External").setValue(anExtLineRes, anExtLineShape)
+anExtLineLen = lineLength(anExtLine)
+aSession.finishOperation()
+aSession.startOperation()
+aConstraintEqLen2 = aSketchFeature.addFeature("SketchConstraintEqual")
+aRefObjectA = aConstraintEqLen2.refattr("ConstraintEntityA")
+aRefObjectB = aConstraintEqLen2.refattr("ConstraintEntityB")
+aRefObjectA.setObject(anExtLine.lastResult())
+aRefObjectB.setObject(aSketchLine2.lastResult())
+aSession.finishOperation()
+aLine1Len = lineLength(aSketchLine1)
+aLine2Len = lineLength(aSketchLine2)
+assert (math.fabs(aLine1Len - anExtLineLen) < 1.e-10)
+assert (math.fabs(aLine2Len - anExtLineLen) < 1.e-10)
#=========================================================================
# End of test
#=========================================================================
__updated__ = "2015-03-17"
+#=========================================================================
+# Auxiliary functions
+#=========================================================================
+def checkMirror(theListInit, theListMirr, theMirrorLine):
+ TOL = 1.e-8
+ aListSize = theListInit.size()
+
+ aLineStartPoint = geomDataAPI_Point2D(theMirrorLine.attribute("StartPoint"))
+ aLineEndPoint = geomDataAPI_Point2D(theMirrorLine.attribute("EndPoint"))
+ aLineDirX = aLineEndPoint.x() - aLineStartPoint.x()
+ aLineDirY = aLineEndPoint.y() - aLineStartPoint.y()
+
+ for ind in range(0, aListSize):
+ aFeatureB = ModelAPI_Feature.feature(theListInit.object(ind))
+ aFeatureC = ModelAPI_Feature.feature(theListMirr.object(ind))
+ assert(aFeatureB is not None)
+ assert(aFeatureC is not None)
+ assert(aFeatureB.getKind() == aFeatureC.getKind())
+
+ anAttributes = {}
+ 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) < TOL, "aDot = {0}".format(aDot)
+ 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) < TOL, "aCross = {0}".format(aCross)
+
+
+#=========================================================================
+# Start of test
+#=========================================================================
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
#=========================================================================
aMirror = aSketchFeature.addFeature("SketchConstraintMirror")
aRefObjectA = aMirror.refattr("ConstraintEntityA")
aRefObjectA.setObject(modelAPI_ResultConstruction(aMirrorLine.firstResult()))
-aRefListB = aMirror.reflist("ConstraintEntityB")
-aRefListB.append(aSketchArc1)
-aRefListB.append(aSketchLine1)
-aRefListB.append(aSketchLine2)
+aRefListInitial = aMirror.reflist("ConstraintMirrorList")
+aRefListInitial.append(aSketchArc1.lastResult())
+aRefListInitial.append(aSketchLine1.lastResult())
+aRefListInitial.append(aSketchLine2.lastResult())
aMirror.execute()
aSession.finishOperation()
#=========================================================================
# Verify the simmetricity of all mirrored objects
#=========================================================================
+aRefListB = aMirror.reflist("ConstraintEntityB")
aRefListC = aMirror.reflist("ConstraintEntityC")
-aListSize = aRefListB.size()
-aLineDirX = aLineEndPoint.x() - aLineStartPoint.x()
-aLineDirY = aLineEndPoint.y() - aLineStartPoint.y()
+assert (aRefListB.size() == 3)
+assert (aRefListC.size() == 3)
+checkMirror(aRefListB, aRefListC, aMirrorLine)
-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'}
+#=========================================================================
+# Remove object from mirror
+#=========================================================================
+aSession.startOperation()
+aRefListInitial.remove(aSketchLine2.lastResult())
+aSession.finishOperation()
+assert (aRefListB.size() == 2)
+assert (aRefListC.size() == 2)
+checkMirror(aRefListB, aRefListC, aMirrorLine)
- 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)
+#=========================================================================
+# Clear list of mirrored features
+#=========================================================================
+aSession.startOperation()
+aRefListInitial.clear()
+assert (aRefListB.size() == 0)
+assert (aRefListC.size() == 0)
+# add arc once again
+aRefListInitial.append(aSketchArc1.lastResult())
+aSession.finishOperation()
+assert (aRefListB.size() == 1)
+assert (aRefListC.size() == 1)
+checkMirror(aRefListB, aRefListC, aMirrorLine)
#=========================================================================
# End of test
#=========================================================================