Salome HOME
CPP API for SketchPlugin_Circle
authordbv <dbv@opencascade.com>
Thu, 9 Jun 2016 15:55:37 +0000 (18:55 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:06 +0000 (14:41 +0300)
src/FeaturesAPI/CMakeLists.txt
src/SketchAPI/CMakeLists.txt
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Circle.cpp [new file with mode: 0644]
src/SketchAPI/SketchAPI_Circle.h [new file with mode: 0644]
src/SketchAPI/SketchAPI_swig.h
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Circle.h

index 1bf3b9f6c74460608b057fd92006ed91352623f9..440b777d8fd4b31cb182751cefaaef08cb63eca9 100644 (file)
@@ -34,6 +34,7 @@ INCLUDE_DIRECTORIES(
 INCLUDE_DIRECTORIES(
   ${PROJECT_SOURCE_DIR}/src/GeomAPI
   ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
+  ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
   ${PROJECT_SOURCE_DIR}/src/FeaturesPlugin
 )
 
index 4a62c018a4648fe540394c7ba9d3aaf48313f269..261c4e4dbe6e67f98554a012ff0488c8807973bc 100644 (file)
@@ -4,12 +4,14 @@ INCLUDE(Common)
 
 SET(PROJECT_HEADERS
   SketchAPI.h
+  SketchAPI_Circle.h
   SketchAPI_Line.h
   SketchAPI_Sketch.h
   SketchAPI_SketchEntity.h
 )
 
 SET(PROJECT_SOURCES
+  SketchAPI_Circle.cpp
   SketchAPI_Line.cpp
   SketchAPI_Sketch.cpp
   SketchAPI_SketchEntity.cpp
index 854d74fbd4d3ac52760d349351efeeb2ef02fe65..d0d566de42b2ec404c6252653e3f3d43af95a8de 100644 (file)
 %include "std_shared_ptr.i"
 
 // shared pointers
+%shared_ptr(SketchAPI_Circle)
 %shared_ptr(SketchAPI_Line)
 %shared_ptr(SketchAPI_Sketch)
 %shared_ptr(SketchAPI_SketchEntity)
 
 // all supported interfaces
+%include "SketchAPI_Circle.h"
 %include "SketchAPI_Line.h"
 %include "SketchAPI_Sketch.h"
 %include "SketchAPI_SketchEntity.h"
diff --git a/src/SketchAPI/SketchAPI_Circle.cpp b/src/SketchAPI/SketchAPI_Circle.cpp
new file mode 100644 (file)
index 0000000..e05e767
--- /dev/null
@@ -0,0 +1,237 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SketchAPI_Circle.cpp
+// Created:     09 June 2016
+// Author:      Dmitry Bobylev
+
+#include "SketchAPI_Circle.h"
+
+#include <GeomAPI_Pnt2d.h>
+
+#include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: SketchAPI_SketchEntity(theFeature)
+{
+  initialize();
+}
+
+//==================================================================================================
+SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                   double theCenterX,
+                                   double theCenterY,
+                                   double theRadius)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if(initialize()) {
+    setByCenterAndRadius(theCenterX, theCenterY, theRadius);
+  }
+}
+
+//==================================================================================================
+SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                   const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                                   double theRadius)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if(initialize()) {
+    setByCenterAndRadius(theCenter, theRadius);
+  }
+}
+
+//==================================================================================================
+SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                   double theX1, double theY1,
+                                   double theX2, double theY2,
+                                   double theX3, double theY3)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3);
+  }
+}
+
+//==================================================================================================
+SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setByThreePoints(thePoint1, thePoint2, thePoint3);
+  }
+}
+
+//==================================================================================================
+SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                   const ModelHighAPI_Selection& theExternal)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setByExternal(theExternal);
+  }
+}
+
+//==================================================================================================
+SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                   const std::string& theExternalName)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setByExternalName(theExternalName);
+  }
+}
+
+//==================================================================================================
+SketchAPI_Circle::~SketchAPI_Circle()
+{
+
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
+  fillAttribute(center(), theCenterX, theCenterY);
+  fillAttribute(ModelHighAPI_Double(theRadius), myradius);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                                            double theRadius)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
+  fillAttribute(theCenter, mycenter);
+  fillAttribute(ModelHighAPI_Double(theRadius), myradius);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setByThreePoints(double theX1, double theY1,
+                                        double theX2, double theY2,
+                                        double theX3, double theY3)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
+  fillAttribute(firstPoint(), theX1, theY1);
+  fillAttribute(secondPoint(), theX2, theY2);
+  fillAttribute(thirdPoint(), theX3, theY3);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
+  fillAttribute(thePoint1, myfirstPoint);
+  fillAttribute(thePoint2, mysecondPoint);
+  fillAttribute(thePoint3, mythirdPoint);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal)
+{
+  fillAttribute(theExternal, external());
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setByExternalName(const std::string & theExternalName)
+{
+  fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setCenter(double theX, double theY)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
+  fillAttribute(center(), theX, theY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
+  fillAttribute(theCenter, mycenter);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setRadius(double theRadius)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
+  fillAttribute(ModelHighAPI_Double(theRadius), myradius);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setFirstPoint(double theX, double theY)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
+  fillAttribute(firstPoint(), theX, theY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
+  fillAttribute(thePoint, myfirstPoint);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setSecondPoint(double theX, double theY)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
+  fillAttribute(secondPoint(), theX, theY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
+  fillAttribute(thePoint, mysecondPoint);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setThirdPoint(double theX, double theY)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
+  fillAttribute(thirdPoint(), theX, theY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
+  fillAttribute(thePoint, mythirdPoint);
+
+  execute();
+}
diff --git a/src/SketchAPI/SketchAPI_Circle.h b/src/SketchAPI/SketchAPI_Circle.h
new file mode 100644 (file)
index 0000000..70af08f
--- /dev/null
@@ -0,0 +1,147 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SketchAPI_Circle.h
+// Created:     09 June 2016
+// Author:      Dmitry Bobylev
+
+#ifndef SketchAPI_Circle_H_
+#define SketchAPI_Circle_H_
+
+#include "SketchAPI.h"
+#include "SketchAPI_SketchEntity.h"
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <SketchPlugin_Circle.h>
+
+class ModelHighAPI_Selection;
+
+/// \class FeaturesAPI_Boolean
+/// \ingroup CPPHighAPI
+/// \brief Interface for Circle feature.
+class SketchAPI_Circle: public SketchAPI_SketchEntity
+{
+public:
+  /// Constructor without values.
+  SKETCHAPI_EXPORT
+  explicit SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                   double theCenterX,
+                   double theCenterY,
+                   double theRadius);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                   const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                   double theRadius);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                   double theX1, double theY1,
+                   double theX2, double theY2,
+                   double theX3, double theY3);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                   const ModelHighAPI_Selection& theExternal);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                   const std::string& theExternalName);
+
+  /// Destructor.
+  SKETCHAPI_EXPORT
+  virtual ~SketchAPI_Circle();
+
+  INTERFACE_7(SketchPlugin_Circle::ID(),
+              circleType, SketchPlugin_Circle::CIRCLE_TYPE(), ModelAPI_AttributeString, /** Circle type */,
+              center, SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D, /** Center point */,
+              radius, SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble, /** Radius */,
+              firstPoint, SketchPlugin_Circle::FIRST_POINT_ID(), GeomDataAPI_Point2D, /** First point */,
+              secondPoint, SketchPlugin_Circle::SECOND_POINT_ID(), GeomDataAPI_Point2D, /** Second point */,
+              thirdPoint, SketchPlugin_Circle::THIRD_POINT_ID(), GeomDataAPI_Point2D, /** Third point */,
+              external, SketchPlugin_Circle::EXTERNAL_ID(), ModelAPI_AttributeSelection, /** External */)
+
+  /// Set by center and radius.
+  SKETCHAPI_EXPORT
+  void setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius);
+
+  /// Set by center and radius.
+  SKETCHAPI_EXPORT
+  void setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter, double theRadius);
+
+  /// 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 by external.
+  SKETCHAPI_EXPORT
+  void setByExternal(const ModelHighAPI_Selection& theExternal);
+
+  /// Set by external name.
+  SKETCHAPI_EXPORT
+  void setByExternalName(const std::string& theExternalName);
+
+  /// Set center.
+  SKETCHAPI_EXPORT
+  void setCenter(double theX, double theY);
+
+  /// Set center.
+  SKETCHAPI_EXPORT
+  void setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter);
+
+  /// Set radius.
+  SKETCHAPI_EXPORT
+  void setRadius(double theRadius);
+
+  /// 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.
+typedef std::shared_ptr<SketchAPI_Circle> CirclePtr;
+
+#endif // SketchAPI_Circle_H_
index 67b27257f432b96b4682685b70ebd2a9c02c24b4..c8829b3c55fc5c9e2cb315f20feea7ca9ea2096b 100644 (file)
@@ -10,6 +10,7 @@
   #include <ModelHighAPI_swig.h>
 
   #include "SketchAPI.h"
+  #include "SketchAPI_Circle.h"
   #include "SketchAPI_Line.h"
   #include "SketchAPI_Sketch.h"
   #include "SketchAPI_SketchEntity.h"
index ac719a70896d09a32dd73c589f808b71e8391c46..3329091847b73d26d0b6b39e9859acfaa2d75313 100644 (file)
 const double tolerance = 1e-7;
 
 namespace {
-  static const std::string& CIRCLE_TYPE_CENTER_AND_RADIUS()
-  {
-    static const std::string TYPE("CenterRadius");
-    return TYPE;
-  }
-  static const std::string& CIRCLE_TYPE_THREE_POINTS()
-  {
-    static const std::string TYPE("ThreePoints");
-    return TYPE;
-  }
-
-  static const std::string& FIRST_POINT_ID()
-  {
-    static const std::string FIRST_PNT("FirstPoint");
-    return FIRST_PNT;
-  }
-  static const std::string& SECOND_POINT_ID()
-  {
-    static const std::string SECOND_PNT("SecondPoint");
-    return SECOND_PNT;
-  }
-  static const std::string& THIRD_POINT_ID()
-  {
-    static const std::string THIRD_PNT("ThirdPoint");
-    return THIRD_PNT;
-  }
   static const std::string& POINT_ID(int theIndex)
   {
     switch (theIndex) {
-    case 1: return FIRST_POINT_ID();
-    case 2: return SECOND_POINT_ID();
-    case 3: return THIRD_POINT_ID();
+    case 1: return SketchPlugin_Circle::FIRST_POINT_ID();
+    case 2: return SketchPlugin_Circle::SECOND_POINT_ID();
+    case 3: return SketchPlugin_Circle::THIRD_POINT_ID();
     }
 
     static const std::string DUMMY;
index d931beb9a0087fe20dd13cc45b1ac37d315bedc5..e183384d83d15b3388c65c5e8c4b57dd2b42cc5b 100644 (file)
@@ -32,6 +32,20 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity, public GeomAPI_IPr
     return TYPE;
   }
 
+  /// Creation method by center and radius.
+  inline static const std::string& CIRCLE_TYPE_CENTER_AND_RADIUS()
+  {
+    static const std::string TYPE("CenterRadius");
+    return TYPE;
+  }
+
+  /// Creation method by three points.
+  inline static const std::string& CIRCLE_TYPE_THREE_POINTS()
+  {
+    static const std::string TYPE("ThreePoints");
+    return TYPE;
+  }
+
   /// 2D point - center of the circle
   inline static const std::string& CENTER_ID()
   {
@@ -46,6 +60,27 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity, public GeomAPI_IPr
     return MY_CIRCLE_RADIUS_ID;
   }
 
+  /// First point id.
+  inline static const std::string& FIRST_POINT_ID()
+  {
+    static const std::string FIRST_PNT("FirstPoint");
+    return FIRST_PNT;
+  }
+
+  /// Second point id.
+  inline static const std::string& SECOND_POINT_ID()
+  {
+    static const std::string SECOND_PNT("SecondPoint");
+    return SECOND_PNT;
+  }
+
+  /// Third point id.
+  inline static const std::string& THIRD_POINT_ID()
+  {
+    static const std::string THIRD_PNT("ThirdPoint");
+    return THIRD_PNT;
+  }
+
   /// Returns the kind of a feature
   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
   {