]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[Code coverage ConstructionAPI]: Improve coverage
authorazv <azv@opencascade.com>
Tue, 18 Dec 2018 04:23:40 +0000 (07:23 +0300)
committerazv <azv@opencascade.com>
Tue, 18 Dec 2018 04:24:18 +0000 (07:24 +0300)
src/ConstructionAPI/Test/TestAxis.py
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp

index b2764e57394cf520c6eb663e967957171b42c838..9494dd447d0babd93eef4bf889040b717745bbd8 100644 (file)
 ##
 
 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)
index 857dfd739750cc0c309b42bdf6a9e50d0dce901e..6a68ae91776a141dad4c68f31a788696d8f34202 100644 (file)
@@ -146,17 +146,21 @@ void ConstructionPlugin_Axis::createAxisByPointAndDirection()
     std::shared_ptr<GeomAPI_Vertex> 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<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
-      std::shared_ptr<GeomAPI_Pnt> anEnd = aVertex->point();
-      if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
-        std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+      std::shared_ptr<GeomAPI_Pnt> 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<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+
+      ResultConstructionPtr aConstr = document()->createConstruction(data());
+      aConstr->setInfinite(true);
+      aConstr->setShape(anEdge);
+      setResult(aConstr);
     }
   }
 }