Salome HOME
[Code coverage SketchAPI]: Remove unnecessary code. Add more unit-tests to improve...
authorazv <azv@opencascade.com>
Tue, 18 Dec 2018 06:59:17 +0000 (09:59 +0300)
committerazv <azv@opencascade.com>
Tue, 18 Dec 2018 10:28:17 +0000 (13:28 +0300)
src/SketchAPI/SketchAPI_MacroArc.h
src/SketchAPI/SketchAPI_MacroCircle.cpp
src/SketchAPI/SketchAPI_MacroCircle.h
src/SketchAPI/SketchAPI_Projection.cpp
src/SketchAPI/Test/TestSketch.py

index 12bf0f98e7d48f2b88811fbf664608ef1a11c4d3..37f83ed08f816aec24138b7bf626a839686d59e9 100644 (file)
@@ -89,10 +89,6 @@ public:
   SKETCHAPI_EXPORT
   virtual ~SketchAPI_MacroArc();
 
-  void test() {
-    SketchPlugin_MacroArc::ID();
-  }
-
   INTERFACE_12(SketchPlugin_MacroArc::ID(),
                arcType, SketchPlugin_MacroArc::ARC_TYPE(),
                ModelAPI_AttributeString, /** Arc type */,
index 694b0231f2b0e8c6852f67536fc1092281f3ce6c..2d60de4254155b0d2704635ddf2287c1555c9938 100644 (file)
@@ -137,93 +137,3 @@ void SketchAPI_MacroCircle::setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d
 
   execute();
 }
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setCenterPoint(double theX, double theY)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
-  fillAttribute(centerPoint(), theX, theY);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setCenterPoint(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
-  fillAttribute(theCenterPoint, mycenterPoint);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setPassedPoint(double theX, double theY)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
-  fillAttribute(passedPoint(), theX, theY);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setPassedPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
-  fillAttribute(thePassedPoint, mypassedPoint);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setFirstPoint(double theX, double theY)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
-  fillAttribute(firstPoint(), theX, theY);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
-  fillAttribute(thePoint, myfirstPoint);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setSecondPoint(double theX, double theY)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
-  fillAttribute(secondPoint(), theX, theY);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
-  fillAttribute(thePoint, mysecondPoint);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setThirdPoint(double theX, double theY)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
-  fillAttribute(thirdPoint(), theX, theY);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_MacroCircle::setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
-  fillAttribute(thePoint, mythirdPoint);
-
-  execute();
-}
index 39d06daf00d9fb1309a300cd14467896f39856a3..40bd819835fe0032d59b2f30716cdc1fb6c58e75 100644 (file)
@@ -84,67 +84,24 @@ public:
               thirdPoint, SketchPlugin_MacroCircle::THIRD_POINT_ID(),
               GeomDataAPI_Point2D, /** Third point */)
 
+private:
   /// Set by center and passed points.
-  SKETCHAPI_EXPORT
   void setByCenterAndPassedPoints(double theCenterX, double theCenterY,
                                   double thePassedX, double thePassedY);
 
   /// Set by center and passed points.
-  SKETCHAPI_EXPORT
   void setByCenterAndPassedPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
 
   /// Set by three points.
-  SKETCHAPI_EXPORT
   void setByThreePoints(double theX1, double theY1,
                         double theX2, double theY2,
                         double theX3, double theY3);
 
   /// Set by three points.
-  SKETCHAPI_EXPORT
   void setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
-
-  /// Set center point.
-  SKETCHAPI_EXPORT
-  void setCenterPoint(double theX, double theY);
-
-  /// Set center point.
-  SKETCHAPI_EXPORT
-  void setCenterPoint(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint);
-
-  /// Set passed point.
-  SKETCHAPI_EXPORT
-  void setPassedPoint(double theX, double theY);
-
-  /// Set passed point.
-  SKETCHAPI_EXPORT
-  void setPassedPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
-
-  /// Set first point.
-  SKETCHAPI_EXPORT
-  void setFirstPoint(double theX, double theY);
-
-  /// Set first point.
-  SKETCHAPI_EXPORT
-  void setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
-  /// Set second point.
-  SKETCHAPI_EXPORT
-  void setSecondPoint(double theX, double theY);
-
-  /// Set second point.
-  SKETCHAPI_EXPORT
-  void setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
-  /// Set third point.
-  SKETCHAPI_EXPORT
-  void setThirdPoint(double theX, double theY);
-
-  /// Set third point.
-  SKETCHAPI_EXPORT
-  void setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
 };
 
 /// Pointer on Circle object.
index 6d82651e93c7f0383fe2629a1f8cf7fefd6c98e4..8be4c7a2380f089b64a8a1c3f1cf7394d9bed1ec 100644 (file)
@@ -75,9 +75,7 @@ void SketchAPI_Projection::setExternalFeature(const ModelHighAPI_Selection & the
 
 void SketchAPI_Projection::setByExternalName(const std::string& theExternalName)
 {
-  fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
-
-  execute(true);
+  setExternalFeature(ModelHighAPI_Selection("EDGE", theExternalName));
 }
 
 void SketchAPI_Projection::setIncludeToResult(bool theKeepResult)
index 8cd95163f0a3b3456fd04d9c278dbeb9459cceb1..732ef739ad70ef9ce0501748afcbe2a8530f0d4e 100644 (file)
@@ -34,6 +34,7 @@ class SketchTestCase(unittest.TestCase):
         aPartSet = self.session.moduleDocument()
         self.doc = model.addPart(aPartSet).document()
         model.addCylinder(self.doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+        model.addCylinder(self.doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 10, 90)
         self.sketch = model.addSketch(self.doc, model.defaultPlane("XOY"))
 
     def tearDown(self):
@@ -57,7 +58,7 @@ class SketchTestCase(unittest.TestCase):
         self.checkPoint(aCircle.center(), point)
 
     def test_circle_by_external(self):
-        """ Test 2. Create point circle by external features
+        """ Test 2. Create point and circle by external features
         """
         aPoint = self.sketch.addPoint("PartSet/Origin")
         aCircle = self.sketch.addCircle("[Cylinder_1_1/Face_1][Cylinder_1_1/Face_3]")
@@ -141,6 +142,45 @@ class SketchTestCase(unittest.TestCase):
         self.checkPoint(anArc.center(), aCenter)
         self.assertAlmostEqual(anArc.radius().value(), aRadius, 6)
 
+    def test_arc_by_external(self):
+        """ Test 7. Create arc by external feature
+        """
+        anArc = self.sketch.addArc(model.selection("EDGE", "[Cylinder_2_1/Face_1][Cylinder_2_1/Face_3]"))
+        model.do()
+        point = geom.Pnt2d(0., 0.)
+        self.checkPoint(anArc.center(), point)
+        self.assertAlmostEqual(anArc.radius().value(), 10, 6)
+
+    def test_arc_by_name(self):
+        """ Test 8. Create arc by external feature
+        """
+        anArc = self.sketch.addArc("[Cylinder_2_1/Face_1][Cylinder_2_1/Face_3]")
+        model.do()
+        point = geom.Pnt2d(0., 0.)
+        self.checkPoint(anArc.center(), point)
+        self.assertAlmostEqual(anArc.radius().value(), 10, 6)
+
+    def test_point_by_intersection(self):
+        """ Test 9. Create point as intersection with external edge given by a name
+        """
+        self.sketch.addIntersectionPoint("[Cylinder_2_1/Face_1][Cylinder_2_1/Face_4]")
+        model.do()
+        aPoint = SketchAPI.SketchAPI_Point(model.lastSubFeature(self.sketch, "SketchPoint"))
+
+        point = geom.Pnt2d(10., 0.)
+        self.checkPoint(aPoint.coordinates(), point)
+
+    def test_arc_by_projection(self):
+        """ Test 10. Create arc by projection of external feature
+        """
+        self.sketch.addProjection("[Cylinder_2_1/Face_1][Cylinder_2_1/Face_3]")
+        model.do()
+        anArc = SketchAPI.SketchAPI_Arc(model.lastSubFeature(self.sketch, "SketchArc"))
+
+        point = geom.Pnt2d(0., 0.)
+        self.checkPoint(anArc.center(), point)
+        self.assertAlmostEqual(anArc.radius().value(), 10, 6)
+
 
 if __name__ == "__main__":
     test_program = unittest.main(exit=False)