-aSession = ModelAPI_Session.get()
-aDocument = aSession.moduleDocument()
-#=========================================================================
-# Creation of a sketch
-#=========================================================================
-aSession.startOperation()
-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()
-#=========================================================================
-# Create two lines
-#=========================================================================
-aSession.startOperation()
-# line A
-aSketchLineA = aSketchFeature.addFeature("SketchLine")
-aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
-aSketchLineB = aSketchFeature.addFeature("SketchLine")
-aLineAStartPoint.setValue(0., 25)
-aLineAEndPoint.setValue(85., 25)
-# line B
-aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
-aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
-aLineBStartPoint.setValue(0., 50)
-aLineBEndPoint.setValue(80., 75)
-aSession.finishOperation()
-#=========================================================================
-# Link lines with collinear constraint
-#=========================================================================
-aSession.startOperation()
-aParallelConstraint = aSketchFeature.addFeature("SketchConstraintCollinear")
-refattrA = aParallelConstraint.refattr("ConstraintEntityA")
-refattrB = aParallelConstraint.refattr("ConstraintEntityB")
-refattrA.setObject(aSketchLineA.firstResult())
-refattrB.setObject(aSketchLineB.firstResult())
-aParallelConstraint.execute()
-aSession.finishOperation()
-checkCollinear(aSketchLineA, aSketchLineB)
-#=========================================================================
-# Check values and move one constrainted object
-#=========================================================================
-deltaX = deltaY = 10.
-# rotate line, check that reference's line points are moved also
-aLineBStartPointPrev = (aLineBStartPoint.x(), aLineBStartPoint.y())
-aLineBEndPointPrev = (aLineBEndPoint.x(), aLineBEndPoint.y())
-aSession.startOperation()
-aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX,
- aLineAStartPoint.y() + deltaY)
-aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX,
- aLineAEndPoint.y() - deltaY)
-aSession.finishOperation()
-checkCollinear(aSketchLineA, aSketchLineB)
+ theLine1.endPoint().setValue(theLine1.endPoint().x() - deltaX, theLine1.endPoint().y() - deltaY)
+ model.do()
+ self.checkLineCollinearity(theLine1, theLine2)
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ def test_collinear_base(self):
+ """ Test 1. Collinearity two independent lines
+ """
+ aSketchLineA = self.mySketch.addLine(0., 25., 85., 25.)
+ aSketchLineB = self.mySketch.addLine(0., 50., 80., 75.)
+ self.myDOF += 8
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+ self.mySketch.setCollinear(aSketchLineA, aSketchLineB)
+ self.myDOF -= 2
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ self.checkLineCollinearity(aSketchLineA, aSketchLineB)
+ self.moveLineAndCheckCollinearity(aSketchLineA, aSketchLineB)
+
+ def test_collinear_connected_lines(self):
+ """ Test 2. Collinearity of two lines in polyline
+ """
+ aSketchLineA = self.mySketch.addLine(10., 20., 30., 40.)
+ aSketchLineB = self.mySketch.addLine(30., 40., 30., 70.)
+ self.myDOF += 8
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+ self.mySketch.setCoincident(aSketchLineA.endPoint(), aSketchLineB.startPoint())
+ self.myDOF -= 2
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ self.mySketch.setCollinear(aSketchLineA, aSketchLineB)
+ self.myDOF -= 1
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ self.checkLineCollinearity(aSketchLineA, aSketchLineB)
+ self.moveLineAndCheckCollinearity(aSketchLineA, aSketchLineB)
+
+ def test_collinear_point_on_line(self):
+ """ Test 3. Collinearity for line which extremity is coincident with other line
+ """
+ aSketchLineA = self.mySketch.addLine(10., 20., 30., 40.)
+ aSketchLineB = self.mySketch.addLine(20., 40., 30., 70.)
+ self.myDOF += 8
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+ self.mySketch.setCoincident(aSketchLineA.result(), aSketchLineB.startPoint())
+ self.myDOF -= 1
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ self.mySketch.setCollinear(aSketchLineA, aSketchLineB)
+ self.myDOF -= 1
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ self.checkLineCollinearity(aSketchLineA, aSketchLineB)
+ self.moveLineAndCheckCollinearity(aSketchLineA, aSketchLineB)
+
+ def test_already_collinear(self):
+ """ Test 4. Collinearity two lines connected by extremities to each other
+ """
+ aSketchLineA = self.mySketch.addLine(10., 20., 40., 50.)
+ aSketchLineB = self.mySketch.addLine(20., 40., 40., 70.)
+ self.myDOF += 8
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+ self.mySketch.setCoincident(aSketchLineA.result(), aSketchLineB.startPoint())
+ self.mySketch.setCoincident(aSketchLineA.endPoint(), aSketchLineB.result())
+ self.myDOF -= 2
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ aCollinear = self.mySketch.setCollinear(aSketchLineA, aSketchLineB)
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ # check error message and remove non valid constraint
+ self.assertNotEqual(self.mySketch.solverError().value(), "")
+ self.myDocument.removeFeature(aCollinear.feature())
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ def test_already_collinear2(self):
+ """ Test 5. Collinearity of two lines when one line is fully on other
+ """
+ aSketchLineA = self.mySketch.addLine(10., 20., 30., 40.)
+ aSketchLineB = self.mySketch.addLine(20., 40., 30., 70.)
+ self.myDOF += 8
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+ self.mySketch.setCoincident(aSketchLineA.result(), aSketchLineB.startPoint())
+ self.mySketch.setCoincident(aSketchLineA.result(), aSketchLineB.endPoint())
+ self.myDOF -= 2
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ aCollinear = self.mySketch.setCollinear(aSketchLineA, aSketchLineB)
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+ # check error message and remove non valid constraint
+ self.assertNotEqual(self.mySketch.solverError().value(), "")
+ self.myDocument.removeFeature(aCollinear.feature())
+ model.do()
+ self.assertEqual(model.dof(self.mySketch), self.myDOF)
+
+if __name__ == "__main__":
+ test_program = unittest.main(exit=False)
+ assert test_program.result.wasSuccessful(), "Test failed"