Salome HOME
Add SketchAPI_Point
authorspo <sergey.pokhodenko@opencascade.com>
Wed, 15 Jun 2016 08:47:47 +0000 (11:47 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:09 +0000 (14:41 +0300)
src/PythonAPI/Test/TestSketcherAddPoint.py
src/SketchAPI/CMakeLists.txt
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Point.cpp [new file with mode: 0644]
src/SketchAPI/SketchAPI_Point.h [new file with mode: 0644]
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchAPI/SketchAPI_swig.h

index 284d377641ee2c6f425d309e3421d9bea9d953eb..8adf1574d2b9920470ca8bd980830b03e9070043 100644 (file)
@@ -2,24 +2,19 @@ import unittest
 import model
 from TestSketcher import SketcherTestCase
 
-class SketcherAddPoint(SketcherTestCase):    
+class SketcherAddPoint(SketcherTestCase):
     def test_add_point(self):
         point = self.sketch.addPoint(0, 1)
         model.do()
-        self.assertEqual(point.pointData().x(), 0.0)        
-        self.assertEqual(point.pointData().y(), 1.0)
-        
+        self.assertEqual(point.coordinates().x(), 0.0)
+        self.assertEqual(point.coordinates().y(), 1.0)
+
     def test_modify_point(self):
         point = self.sketch.addPoint(0, 1)
-        point.setValue(1, 2)
+        point.setCoordinates(1, 2)
         model.do()
-        self.assertEqual(point.pointData().x(), 1.0)        
-        self.assertEqual(point.pointData().y(), 2.0)
-        
-    def test_empty_args(self):
-        with self.assertRaises(TypeError):
-            self.sketch.addPoint()
-        
-    
+        self.assertEqual(point.coordinates().x(), 1.0)
+        self.assertEqual(point.coordinates().y(), 2.0)
+
 if __name__ == "__main__":
     unittest.main(verbosity=2)
\ No newline at end of file
index 206eee1c1b0f221924eb663fb9ad7b36f6f84122..57792bb13bab5bbd004b035aa754ffe931d0b933 100644 (file)
@@ -9,6 +9,7 @@ SET(PROJECT_HEADERS
   SketchAPI_Line.h
   SketchAPI_Sketch.h
   SketchAPI_SketchEntity.h
+  SketchAPI_Point.h
 )
 
 SET(PROJECT_SOURCES
@@ -17,6 +18,7 @@ SET(PROJECT_SOURCES
   SketchAPI_Line.cpp
   SketchAPI_Sketch.cpp
   SketchAPI_SketchEntity.cpp
+  SketchAPI_Point.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 7aad3d4de37c8d81d5df052cf338570f69200919..7cbd61f4c14e0874281591957b2205e9e3f406f5 100644 (file)
@@ -25,6 +25,7 @@
 %shared_ptr(SketchAPI_Line)
 %shared_ptr(SketchAPI_Sketch)
 %shared_ptr(SketchAPI_SketchEntity)
+%shared_ptr(SketchAPI_Point)
 
 // fix compilarion error: ‘res2’ was not declared in this scope
 %typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
   }
 }
 
-// all supported interfaces (the order is very important: base class first)
+// all supported interfaces (the order is very important according dependencies: base class first)
 %include "SketchAPI_SketchEntity.h"
-%include "SketchAPI_Arc.h"
-%include "SketchAPI_Circle.h"
+%include "SketchAPI_Point.h"
 %include "SketchAPI_Line.h"
+%include "SketchAPI_Circle.h"
+%include "SketchAPI_Arc.h"
 %include "SketchAPI_Sketch.h"
diff --git a/src/SketchAPI/SketchAPI_Point.cpp b/src/SketchAPI/SketchAPI_Point.cpp
new file mode 100644 (file)
index 0000000..c133a74
--- /dev/null
@@ -0,0 +1,98 @@
+// Name   : SketchAPI_Point.cpp
+// Purpose: 
+//
+// History:
+// 15/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI_Point.h"
+//--------------------------------------------------------------------------------------
+#include <GeomAPI_Pnt2d.h>
+//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+//--------------------------------------------------------------------------------------
+SketchAPI_Point::SketchAPI_Point(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: SketchAPI_SketchEntity(theFeature)
+{
+  initialize();
+}
+
+SketchAPI_Point::SketchAPI_Point(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature,
+    double theX, double theY)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setCoordinates(theX, theY);
+  }
+}
+
+SketchAPI_Point::SketchAPI_Point(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature,
+    const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setCoordinates(thePoint);
+  }
+}
+
+SketchAPI_Point::SketchAPI_Point(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature,
+    const ModelHighAPI_Selection & theExternal )
+: SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setByExternal(theExternal);
+  }
+}
+
+SketchAPI_Point::SketchAPI_Point(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature,
+    const std::string & theExternalName )
+: SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setByExternalName(theExternalName);
+  }
+}
+
+SketchAPI_Point::~SketchAPI_Point()
+{
+
+}
+
+//--------------------------------------------------------------------------------------
+void SketchAPI_Point::setCoordinates(
+    double theX, double theY)
+{
+  fillAttribute(coordinates(), theX, theY);
+
+  execute();
+}
+
+void SketchAPI_Point::setCoordinates(
+    const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
+{
+  fillAttribute(thePoint, coordinates());
+
+  execute();
+}
+
+void SketchAPI_Point::setByExternal(const ModelHighAPI_Selection & theExternal)
+{
+  fillAttribute(theExternal, external());
+
+  execute();
+}
+
+void SketchAPI_Point::setByExternalName(const std::string & theExternalName)
+{
+  fillAttribute(ModelHighAPI_Selection("VERTEX", theExternalName), external());
+
+  execute();
+}
+
+//--------------------------------------------------------------------------------------
diff --git a/src/SketchAPI/SketchAPI_Point.h b/src/SketchAPI/SketchAPI_Point.h
new file mode 100644 (file)
index 0000000..1596b0f
--- /dev/null
@@ -0,0 +1,78 @@
+// Name   : SketchAPI_Point.h
+// Purpose: 
+//
+// History:
+// 15/06/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_SKETCHAPI_SKETCHAPI_POINT_H_
+#define SRC_SKETCHAPI_SKETCHAPI_POINT_H_
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI.h"
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <SketchPlugin_Point.h>
+
+#include "SketchAPI_SketchEntity.h"
+//--------------------------------------------------------------------------------------
+class ModelHighAPI_Selection;
+//--------------------------------------------------------------------------------------
+/**\class SketchAPI_Point
+ * \ingroup CPPHighAPI
+ * \brief Interface for Point feature
+ */
+class SketchAPI_Point : public SketchAPI_SketchEntity
+{
+public:
+  /// Constructor without values
+  SKETCHAPI_EXPORT
+  explicit SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+  /// Constructor with values
+  SKETCHAPI_EXPORT
+  SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                 double theX, double theY);
+  /// Constructor with values
+  SKETCHAPI_EXPORT
+  SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
+  /// Constructor with values
+  SKETCHAPI_EXPORT
+  SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                 const ModelHighAPI_Selection & theExternal);
+  /// Constructor with values
+  SKETCHAPI_EXPORT
+  SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                 const std::string & theExternalName);
+  /// Destructor
+  SKETCHAPI_EXPORT
+  virtual ~SketchAPI_Point();
+
+  INTERFACE_2(SketchPlugin_Point::ID(),
+              coordinates, SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D, /** Point coordinates */,
+              external, SketchPlugin_Point::EXTERNAL_ID(), ModelAPI_AttributeSelection, /** External */
+  )
+
+  /// Set by coordinates
+  SKETCHAPI_EXPORT
+  void setCoordinates(double theX, double theY);
+
+  /// Set by points
+  SKETCHAPI_EXPORT
+  void setCoordinates(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
+
+  /// Set by external
+  SKETCHAPI_EXPORT
+  void setByExternal(const ModelHighAPI_Selection & theExternal);
+
+  /// Set by external name
+  SKETCHAPI_EXPORT
+  void setByExternalName(const std::string & theExternalName);
+};
+
+//! Pointer on Point object
+typedef std::shared_ptr<SketchAPI_Point> PointPtr;
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_SKETCHAPI_SKETCHAPI_POINT_H_ */
index 8d24c1534e739f54b875adf7050afd6981f2fdec..cdac5d4c5912966298d2224773e8fa8f351caf56 100644 (file)
@@ -34,6 +34,7 @@
 #include "SketchAPI_Arc.h"
 #include "SketchAPI_Circle.h"
 #include "SketchAPI_Line.h"
+#include "SketchAPI_Point.h"
 //--------------------------------------------------------------------------------------
 SketchAPI_Sketch::SketchAPI_Sketch(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
@@ -147,6 +148,30 @@ SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
   return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
 }
 
+//--------------------------------------------------------------------------------------
+std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
+    double theX, double theY)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
+  return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
+}
+std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
+    const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
+  return PointPtr(new SketchAPI_Point(aFeature, thePoint));
+}
+std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
+  return PointPtr(new SketchAPI_Point(aFeature, theExternal));
+}
+std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
+  return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
+}
+
 //--------------------------------------------------------------------------------------
 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
 {
index a1433e99e1d5cd969f883b88ed0482c72e5422b3..8108524abea2ec975e3fb05e4a0ad732ddb957f9 100644 (file)
@@ -25,6 +25,7 @@ class ModelHighAPI_Selection;
 class SketchAPI_Arc;
 class SketchAPI_Circle;
 class SketchAPI_Line;
+class SketchAPI_Point;
 //--------------------------------------------------------------------------------------
 /**\class SketchAPI_Sketch
  * \ingroup CPPHighAPI
@@ -66,7 +67,22 @@ public:
   SKETCHAPI_EXPORT
   void setExternal(const ModelHighAPI_Selection & theExternal);
 
-  // TODO(spo): addPoint
+  // TODO(spo): addIntersection
+
+  /// Add point
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Point> addPoint(
+      double theX, double theY);
+  /// Add point
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Point> addPoint(
+      const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
+  /// Add point
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
+  /// Add point
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Point> addPoint(const std::string & theExternalName);
 
   /// Add line
   SKETCHAPI_EXPORT
index 6ce00f715b5f073bcbdc4d612065e951ac92b429..32a60738efe8c822190f51f50c50c8145ed72933 100644 (file)
@@ -15,5 +15,6 @@
   #include "SketchAPI_Line.h"
   #include "SketchAPI_Sketch.h"
   #include "SketchAPI_SketchEntity.h"
+  #include "SketchAPI_Point.h"
 
 #endif /* SRC_SKETCHAPI_SKETCHAPI_SWIG_H_ */