from SketchAPI import *
-import math
-
def checkRectangle(lines, center, corner, tolerance = 1.e-7):
dx = corner.x() - center.x()
dy = corner.y() - center.y()
ep_ref = points[i]
assert(ep.distance(ep_ref) <= tolerance)
+def checkRectangleL(lines, valref, tolerance = 1.e-5):
+ for i in range(0, 4):
+ line = SketchAPI_Line(lines[i])
+ #print (line.defaultResult().shape().edge().length())
+ #print (valref[i%2])
+ #print (abs(line.defaultResult().shape().edge().length()-valref[i%2]))
+ assert(abs(line.defaultResult().shape().edge().length()-valref[i%2]) <= tolerance)
model.begin()
partSet = model.moduleDocument()
# move center of rectangle
SHIFT = 1.0
center = SketchAPI_Line(lines_1[0]).startPoint().pnt()
-for i in range(0, 20):
+valref = [ \
+400.86931 , 200.78509 , \
+401.73886 , 201.57021 , \
+402.60865 , 202.35537 , \
+403.47866 , 203.14056 , \
+404.34890 , 203.92580 ]
+for i in range(0, 5):
center.setX(center.x() + SHIFT)
center.setY(center.y() + SHIFT)
model.begin()
sketch.move(SketchAPI_Line(lines_1[0]).startPoint(), center)
model.end()
- checkRectangle(lines_3, center, SketchAPI_Line(lines_2[0]).endPoint().pnt())
+ checkRectangleL(lines_3, valref[2*i:])
# move corner of rectangle
corner = SketchAPI_Line(lines_2[0]).endPoint().pnt()
-for i in range(0, 20):
+valref = [ \
+403.11209 , 202.95437 , \
+401.87551 , 201.98300 , \
+400.63915 , 201.01169 , \
+399.40301 , 200.04043 , \
+398.16710 , 199.06922 ]
+for i in range(0, 5):
corner.setX(corner.x() + SHIFT)
corner.setY(corner.y() + SHIFT)
model.begin()
sketch.move(SketchAPI_Line(lines_2[0]).endPoint(), corner)
model.end()
- checkRectangle(lines_3, SketchAPI_Line(lines_1[0]).startPoint().pnt(), corner)
+ checkRectangleL(lines_3, valref[2*i:])
assert(model.checkPythonDump())
aRefAttrA.setAttr(aPrevLine.attribute("EndPoint"))
aRefAttrB.setAttr(aLine.attribute("StartPoint"))
aStartPoints.append(aLine.attribute("StartPoint"))
- # Flags which show horizontal or vertical constraint is build for correponding line
- self.__isHV = [False, False, False, False]
+ # Flags which show perpendicular constraint is build for correponding line
+ self.__isPERP = [False, False, False]
# Update coordinates of created lines
self.updateLines()
# Create auxiliary diagonals in case of centered rectangle
aCoincidence = self.__sketch.addFeature("SketchConstraintCoincidence")
aCoincidence.refattr("ConstraintEntityA").setAttr(refPnt)
aCoincidence.refattr("ConstraintEntityB").setObject(line)
- # Add horizontal and vertical constraint for the lines which already have result
- for i in range (0, 4):
- if self.__isHV[i]:
+ # Perpendicular for the lines which already have result
+ for i in range (0, 3):
+ if self.__isPERP[i]:
continue
- aLine = ModelAPI.objectToFeature(aLinesList.object(i))
- aLineResult = aLine.lastResult()
- if aLineResult is None:
+ aLine_A = ModelAPI.objectToFeature(aLinesList.object(i))
+ aLineResult_A = aLine_A.lastResult()
+ if aLineResult_A is None:
+ continue
+ aLine_B = ModelAPI.objectToFeature(aLinesList.object(i+1))
+ aLineResult_B = aLine_B.lastResult()
+ if aLineResult_B is None:
continue
- aHVName = "SketchConstraintHorizontal"
- if i % 2 == 1:
- aHVName = "SketchConstraintVertical"
- aHVConstraint = self.__sketch.addFeature(aHVName)
- aRefAttrA = aHVConstraint.refattr("ConstraintEntityA")
- aRefAttrA.setObject(aLine.lastResult())
- self.__isHV[i] = True
+ aHVConstraint = self.__sketch.addFeature("SketchConstraintPerpendicular")
+ refattrA = aHVConstraint.refattr("ConstraintEntityA")
+ refattrA.setObject(aLine_A.lastResult())
+ refattrB = aHVConstraint.refattr("ConstraintEntityB")
+ refattrB.setObject(aLine_B.lastResult())
+ self.__isPERP[i] = True
def attributeChanged(self, theID):
if theID == self.START_ID() or theID == self.END_ID() or theID == self.CENTER_ID() or theID == self.CENTER_REF_ID() or theID == self.CORNER_ID():
Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
SketchRectangle_1 = Sketch_1.addRectangle(20., 20., 70., 50.)
[SketchLine_1, SketchLine_2, SketchLine_3, SketchLine_4] = SketchRectangle_1.lines()
+Sketch_1.setVertical(SketchLine_4.result())
firstPoint = SketchAPI_Line(SketchLine_2).startPoint()
secondPoint = SketchAPI_Line(SketchLine_3).endPoint()
model.do()
model.do()
# changing the parameter
-for param in range(-31, 30, 2):
+for param in range(11, 31, 2):
if param == 0:
continue
DistanceParam.setValue(param)
model.do()
# changing the parameter
-for param in range(-31, 30, 2):
+for param in range(11, 31, 2):
if param == 0:
continue
DistanceParam.setValue(param)
model.do()
# changing the parameter
-for param in range(-30, 31, 2):
+for param in range(11, 31, 2):
DistanceParam.setValue(param)
model.do()
if param < 0:
# leave distance constraint alive
model.end()
+
Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
Rectangle_1 = Sketch_1.addRectangle(0, 0, 200, 100)
[Line_1, Line_2, Line_3, Line_4] = Rectangle_1.lines()
+Sketch_1.setVertical(Line_4.result())
Origin = Sketch_1.addPoint(model.selection("VERTEX", "Origin"))
Sketch_1.setCoincident(SketchAPI_Line(Line_1).endPoint(), Origin.result())
Sketch_1.setLength(SketchAPI_Line(Line_1).result(), "w")
signedDist2 = model.signedDistancePointLine(Point_2, line)
# change rectangle width and check distances
-widthParam.setValue(2000)
+widthParam.setValue(300)
model.do()
curDist = model.signedDistancePointLine(Point_1, line)
assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
# revert rectangle width and check distances again
-widthParam.setValue(200)
+widthParam.setValue(300)
model.do()
curDist = model.signedDistancePointLine(Point_1, line)
assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
model.end()
+
Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
Rectangle_1 = Sketch_1.addRectangle(0, 0, 200, 100)
[Line_1, Line_2, Line_3, Line_4] = Rectangle_1.lines()
+Sketch_1.setVertical(Line_4.result())
Point_1 = Sketch_1.addPoint(model.selection("VERTEX", "Origin"))
Sketch_1.setCoincident(SketchAPI_Line(Line_1).endPoint(), Point_1.result())
Sketch_1.setLength(SketchAPI_Line(Line_1).result(), "w")
signedDist2 = model.signedDistancePointLine(center2, line)
# change rectangle width and check distances
-widthParam.setValue(2000)
+widthParam.setValue(300)
model.do()
curDist = model.signedDistancePointLine(center1, line)
assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
model.end()
+
Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
Rectangle_1 = Sketch_1.addRectangle(0, 0, 200, 100)
[Line_1, Line_2, Line_3, Line_4] = Rectangle_1.lines()
+Sketch_1.setVertical(Line_4.result())
Point_1 = Sketch_1.addPoint(model.selection("VERTEX", "Origin"))
Sketch_1.setCoincident(SketchAPI_Line(Line_1).endPoint(), Point_1.result())
Sketch_1.setLength(SketchAPI_Line(Line_1).result(), "w")
signedDist2 = model.signedDistancePointLine(end, line)
# change rectangle width and check distances
-widthParam.setValue(2000)
+widthParam.setValue(300)
model.do()
curDist = model.signedDistancePointLine(start, line)
assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
model.end()
+
Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
Rectangle_1 = Sketch_1.addRectangle(0, 0, 200, 100)
[Line_1, Line_2, Line_3, Line_4] = Rectangle_1.lines()
+Sketch_1.setVertical(Line_4.result())
Point_1 = Sketch_1.addPoint(model.selection("VERTEX", "Origin"))
Sketch_1.setCoincident(SketchAPI_Line(Line_1).endPoint(), Point_1.result())
Sketch_1.setLength(SketchAPI_Line(Line_1).result(), "w")
signedDist2 = model.signedDistancePointLine(end, line)
# change rectangle width and check distances
-widthParam.setValue(1000)
+widthParam.setValue(300)
model.do()
curDist = model.signedDistancePointLine(start, line)
assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
model.end()
+
Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
Rectangle_1 = Sketch_1.addRectangle(0, 0, 200, 100)
[Line_1, Line_2, Line_3, Line_4] = Rectangle_1.lines()
+Sketch_1.setVertical(Line_4.result())
Origin = Sketch_1.addPoint(model.selection("VERTEX", "Origin"))
Sketch_1.setCoincident(SketchAPI_Line(Line_1).endPoint(), Origin.result())
Sketch_1.setLength(SketchAPI_Line(Line_1).result(), "w")
signedDist25 = model.signedDistancePointLine(Point_2, line5)
# change rectangle width and check distances
-widthParam.setValue(2000)
+widthParam.setValue(300)
model.do()
curDist = model.signedDistancePointLine(Point_1, line4)
assert(math.fabs(signedDist14 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist14, curDist)
assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
model.end()
+
Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
SketchRectangle_1 = Sketch_2.addRectangle(20, 0, 100, 50)
[SketchLine_6, SketchLine_7, SketchLine_8, SketchLine_9] = SketchRectangle_1.lines()
+Sketch_2.setVertical(SketchLine_9.result())
SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Sketch_1/SketchLine_1"))
SketchLine_10 = SketchProjection_1.createdFeature()
SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_7).startPoint(), SketchAPI_Line(SketchLine_10).startPoint())
model.testResultsVolumes(ExtrusionFuse_1, [260653.824775497108930721879005432])
assert(model.checkPythonDump())
+
"""
TestRectangle.py
- Unit test of SketchPlugin_Ractangle class
+ Unit test of SketchPlugin_Rectangle class
"""
from GeomDataAPI import *
assert (isHorizontal(aLastLine) or isVertical(aLastLine))
aNbLines = aNbLines + 1
assert (aNbLines == 4)
-assert (model.dof(aSketchFeature) == 4)
+assert (model.dof(aSketchFeature) == 5)
#=========================================================================
# Move one of lines
#=========================================================================
aSession.startOperation()
aLineEnd = geomDataAPI_Point2D(aLastLine.attribute("EndPoint"))
-aLineEnd.setValue(50., 50.)
+aLineEnd.setValue(41., 30.)
aSession.finishOperation()
#=========================================================================
# Check the lines of rectangle are parallel to the axes
#=========================================================================
aNbSubs = aSketchFeature.numberOfSubs()
aNbLines = 0
+tolerance = 1.e-5
+valref = [28.47721, 1.3352780]
for i in range (0, aNbSubs):
aFeature = objectToFeature(aSketchFeature.subFeature(i))
if aFeature.getKind() == "SketchLine":
aLastLine = aFeature
- assert (isHorizontal(aLastLine) or isVertical(aLastLine))
+ #print (aLastLine.lastResult().shape().edge().length())
+ #print (valref[i%2])
+ #print (abs(aLastLine.lastResult().shape().edge().length()-valref[i%2]))
+ assert(abs(aLastLine.lastResult().shape().edge().length()-valref[i%2]) <= tolerance)
aNbLines = aNbLines + 1
assert (aNbLines == 4)
-assert (model.dof(aSketchFeature) == 4)
+assert (model.dof(aSketchFeature) == 5)
#=========================================================================
# End of test
#=========================================================================