From 180173d1e6a5463c4962721c1213a47794dd0974 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 18 Dec 2018 07:23:40 +0300 Subject: [PATCH] [Code coverage ConstructionAPI]: Improve coverage --- src/ConstructionAPI/Test/TestAxis.py | 90 +++++++++++++++---- .../ConstructionPlugin_Axis.cpp | 22 +++-- 2 files changed, 88 insertions(+), 24 deletions(-) diff --git a/src/ConstructionAPI/Test/TestAxis.py b/src/ConstructionAPI/Test/TestAxis.py index b2764e573..9494dd447 100644 --- a/src/ConstructionAPI/Test/TestAxis.py +++ b/src/ConstructionAPI/Test/TestAxis.py @@ -19,30 +19,90 @@ ## import unittest - -import ModelAPI -import ConstructionAPI from salome.shaper import model +from GeomAPI import * +from ModelAPI import * class AxisTestCase(unittest.TestCase): def setUp(self): - self.session = ModelAPI.ModelAPI_Session.get() - self.doc = self.session.moduleDocument() - self.session.startOperation() - self.feature = self.doc.addFeature("Axis") - self.feature.execute() - self.session.finishOperation() + self.doc = model.moduleDocument() def tearDown(self): + model.end() assert(model.checkPythonDump()) - self.session.closeAll() + ModelAPI_Session.get().closeAll() + + def checkAxis(self, axis, x1, y1, z1, x2, y2, z2): + edge = GeomAPI_Edge(axis.results()[0].resultSubShapePair()[0].shape()) + self.assertTrue(edge.isLine()) + + p1 = edge.firstPoint() + self.assertAlmostEqual(p1.x(), x1, 6) + self.assertAlmostEqual(p1.y(), y1, 6) + self.assertAlmostEqual(p1.z(), z1, 6) + + p2 = edge.lastPoint() + self.assertAlmostEqual(p2.x(), x2, 6) + self.assertAlmostEqual(p2.y(), y2, 6) + self.assertAlmostEqual(p2.z(), z2, 6) + + + def test_axis_by_dimensions(self): + """ Test 1. Create axis starting from Origin with the given dimensions + """ + axis = model.addAxis(self.doc, 10, 50, 100) + self.checkAxis(axis, 0, 0, 0, 10, 50, 100) + + def test_axis_by_points(self): + """ Test 2. Create axis between pair of points + """ + model.addPoint(self.doc, 10, 0, 0) + axis = model.addAxis(self.doc, model.selection("VERTEX", "Origin"), model.selection("VERTEX", "Point_2")) + self.checkAxis(axis, 0, 0, 0, 10, 0, 0) + + def test_axis_by_point_and_plane(self): + """ Test 3. Create axis orthogonal to a plane and passing through a point + """ + model.addPoint(self.doc, 10, 0, 0) + axis = model.addAxis(self.doc, model.selection("FACE", "YOZ"), model.selection("VERTEX", "Point_2")) + self.checkAxis(axis, 10, 0, 0, 0, 0, 0) + + def test_axis_by_line(self): + """ Test 4. Create axis by edge on a box + """ + partDoc = model.addPart(self.doc).document() + model.addBox(partDoc, 10, 10, 10) + axis = model.addAxis(partDoc, model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Left]")) + self.checkAxis(axis, 10, 0, 0, 10, 0, 10) + + def test_axis_by_cylinder(self): + """ Test 5. Create axis by cylindrical face + """ + partDoc = model.addPart(self.doc).document() + model.addCylinder(partDoc, 5, 10) + axis = model.addAxis(partDoc, model.selection("FACE", "Cylinder_1_1/Face_1")) + self.checkAxis(axis, 0, 0, -1, 0, 0, 11) + + def test_axis_by_point_and_direction(self): + """ Test 6. Create axis starting from a point with a given direction + """ + model.addPoint(self.doc, 10, 0, 0) + axis = model.addAxis(self.doc, model.selection("VERTEX", "Point_2"), 10, 20, 30) + self.checkAxis(axis, 10, 0, 0, 20, 20, 30) + + def test_axis_by_planes(self): + """ Test 7. Create axis as intersection of two planes + """ + axis = model.addAxis(self.doc, model.selection("FACE", "XOZ"), model.selection("FACE", "YOZ")) + self.checkAxis(axis, 0, 0, 0, 0, 0, 100) + + axis = model.addAxis(self.doc, model.selection("FACE", "XOZ"), 10, False, model.selection("FACE", "YOZ")) + self.checkAxis(axis, 0, -10, 0, 0, -10, 100) + + axis = model.addAxis(self.doc, model.selection("FACE", "XOZ"), model.selection("FACE", "YOZ"), 10, False) + self.checkAxis(axis, 10, 0, 0, 10, 0, 100) - def test_ConstructorWithDimensions(self): - axis = ConstructionAPI.ConstructionAPI_Axis(self.feature, 10, 50, 100) - self.assertEqual(10,axis.xDimension().value()) - self.assertEqual(50,axis.yDimension().value()) - self.assertEqual(100,axis.zDimension().value()) if __name__ == "__main__": test_program = unittest.main(exit=False) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 857dfd739..6a68ae917 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -146,17 +146,21 @@ void ConstructionPlugin_Axis::createAxisByPointAndDirection() std::shared_ptr aVertex(new GeomAPI_Vertex(aXAttr->value(), aYAttr->value(), aZAttr->value())); - if (aShape1->isVertex() && (!aShape1->isEqual(aVertex))) { + if (aShape1->isVertex() && + (fabs(aXAttr->value()) > MINIMAL_LENGTH() || + fabs(aYAttr->value()) > MINIMAL_LENGTH() || + fabs(aZAttr->value()) > MINIMAL_LENGTH())) { std::shared_ptr aStart = GeomAlgoAPI_PointBuilder::point(aShape1); - std::shared_ptr anEnd = aVertex->point(); - if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) { - std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); + std::shared_ptr anEnd(new GeomAPI_Pnt(aStart->x() + aXAttr->value(), + aStart->y() + aYAttr->value(), + aStart->z() + aZAttr->value())); - ResultConstructionPtr aConstr = document()->createConstruction(data()); - aConstr->setInfinite(true); - aConstr->setShape(anEdge); - setResult(aConstr); - } + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); + + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); + aConstr->setShape(anEdge); + setResult(aConstr); } } } -- 2.39.2