Salome HOME
[EDF] (2023-T1) Sketch middle point constrain should create point if missing
[modules/shaper.git] / src / SketchAPI / SketchAPI_Sketch.h
index 216474474f66f55ecfd08bad78eec15f59446068..993e6ef901536e95e39316e17c17c648863da9bd 100644 (file)
@@ -1,9 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-// Name   : SketchAPI_Sketch.h
-// Purpose:
+// Copyright (C) 2014-2023  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// History:
-// 07/06/16 - Sergey POKHODENKO - Creation of the file
 
 #ifndef SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_
 #define SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_
 
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_SketchEntity.h>
+#include <SketchPlugin_Offset.h>
 
+#include <ModelHighAPI_Double.h>
 #include <ModelHighAPI_Interface.h>
 #include <ModelHighAPI_Macro.h>
+#include <ModelHighAPI_Selection.h>
 //--------------------------------------------------------------------------------------
 class ModelAPI_CompositeFeature;
 class ModelAPI_Object;
-class ModelHighAPI_Double;
 class ModelHighAPI_Integer;
 class ModelHighAPI_RefAttr;
 class ModelHighAPI_Reference;
-class ModelHighAPI_Selection;
 class SketchAPI_Arc;
+class SketchAPI_MacroArc;
 class SketchAPI_Circle;
+class SketchAPI_MacroCircle;
+class SketchAPI_Ellipse;
+class SketchAPI_MacroEllipse;
+class SketchAPI_EllipticArc;
+class SketchAPI_MacroEllipticArc;
+class SketchAPI_BSpline;
 class SketchAPI_IntersectionPoint;
 class SketchAPI_Line;
 class SketchAPI_Mirror;
+class SketchAPI_Offset;
 class SketchAPI_Point;
 class SketchAPI_Projection;
 class SketchAPI_Rectangle;
 class SketchAPI_Rotation;
 class SketchAPI_Translation;
+class SketchAPI_MacroMiddlePoint;
+
+//--------------------------------------------------------------------------------------
+typedef std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> PointOrReference;
 //--------------------------------------------------------------------------------------
 /**\class SketchAPI_Sketch
  * \ingroup CPPHighAPI
@@ -84,6 +109,11 @@ public:
   SKETCHAPI_EXPORT
   void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
 
+  /// Change sketch plane
+  SKETCHAPI_EXPORT
+  void setPlane(const ModelHighAPI_Selection & thePlane,
+                bool theRemoveExternalDependency = false);
+
   /// Set external
   SKETCHAPI_EXPORT
   void setExternal(const ModelHighAPI_Selection & theExternal);
@@ -92,6 +122,14 @@ public:
   SKETCHAPI_EXPORT
   void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
 
+  /// Change order of sketch results (faces)
+  SKETCHAPI_EXPORT
+  void changeFacesOrder(const std::list<std::list<ModelHighAPI_Selection> >& theFaces);
+
+  /// List points not connected by constraints with other sketch entitites
+  SKETCHAPI_EXPORT
+  std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
+
   /// Add point
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Point> addPoint(
@@ -105,16 +143,18 @@ public:
   std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
   /// Add point
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Point> addPoint(const std::string & theExternalName);
+  std::shared_ptr<SketchAPI_Point> addPoint(const std::wstring & theExternalName);
 
   /// Add intersection point
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_IntersectionPoint>
-    addIntersectionPoint(const ModelHighAPI_Selection & theExternal);
+    addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
+                         bool theKeepResult = false);
   /// Add point
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_IntersectionPoint>
-    addIntersectionPoint(const std::string & theExternalName);
+    addIntersectionPoint(const std::wstring & theExternalName,
+                         bool theKeepResult = false);
 
   /// Add line
   SKETCHAPI_EXPORT
@@ -130,7 +170,7 @@ public:
   std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
   /// Add line
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Line> addLine(const std::string & theExternalName);
+  std::shared_ptr<SketchAPI_Line> addLine(const std::wstring & theExternalName);
 
   /// Add rectangle
   SKETCHAPI_EXPORT
@@ -141,6 +181,11 @@ public:
   std::shared_ptr<SketchAPI_Rectangle> addRectangle(
       const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
       const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
+  /// Add rectangle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
+      const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCenter,
+      const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCorner);
 
   /// Add circle
   SKETCHAPI_EXPORT
@@ -154,13 +199,23 @@ public:
       double theRadius);
   /// Add circle
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Circle> addCircle(
+  std::shared_ptr<SketchAPI_MacroCircle> addCircle(
+      double theCenterX, double theCenterY,
+      double thePassedX, double thePassedY);
+  /// Add circle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_MacroCircle> addCircle(
+      const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+      const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+  /// Add circle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_MacroCircle> addCircle(
       double theX1, double theY1,
       double theX2, double theY2,
       double theX3, double theY3);
   /// Add circle
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Circle> addCircle(
+  std::shared_ptr<SketchAPI_MacroCircle> addCircle(
       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
@@ -169,7 +224,7 @@ public:
   std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
   /// Add circle
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Circle> addCircle(const std::string & theExternalName);
+  std::shared_ptr<SketchAPI_Circle> addCircle(const std::wstring & theExternalName);
 
   /// Add arc
   SKETCHAPI_EXPORT
@@ -189,31 +244,33 @@ public:
 
   /// Add arc
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Arc> addArc(
+  std::shared_ptr<SketchAPI_MacroArc> addArc(
       double theStartX, double theStartY,
       double theEndX, double theEndY,
       double thePassedX, double thePassedY);
 
   /// Add arc
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Arc> addArc(
+  std::shared_ptr<SketchAPI_MacroArc> addArc(
       const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
       const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
       const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
 
-  /// Add arc
+  /// Add transversal/tangent arc
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Arc> addArc(
-      const ModelHighAPI_RefAttr& theTangentPoint,
+  std::shared_ptr<SketchAPI_MacroArc> addArc(
+      const ModelHighAPI_RefAttr& theConnectedPoint,
       double theEndX, double theEndY,
-      bool theInversed);
+      bool theInversed,
+      bool theTransversal = false);
 
-  /// Add arc
+  /// Add transversal/tangent arc
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Arc> addArc(
-      const ModelHighAPI_RefAttr& theTangentPoint,
+  std::shared_ptr<SketchAPI_MacroArc> addArc(
+      const ModelHighAPI_RefAttr& theConnectedPoint,
       const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
-      bool theInversed);
+      bool theInversed,
+      bool theTransversal = false);
 
   /// Add arc
   SKETCHAPI_EXPORT
@@ -221,16 +278,96 @@ public:
 
   /// Add arc
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Arc> addArc(const std::string & theExternalName);
+  std::shared_ptr<SketchAPI_Arc> addArc(const std::wstring & theExternalName);
 
-  /// Add projection
+  /// Add ellipse
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Projection> addProjection(
-      const ModelHighAPI_Selection & theExternalFeature);
+  std::shared_ptr<SketchAPI_Ellipse> addEllipse(
+      double theCenterX, double theCenterY,
+      double theFocusX, double theFocusY,
+      double theMinorRadius);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Ellipse> addEllipse(
+      const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+      const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
+      double theRadius);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
+      double thePoint1X, double thePoint1Y,
+      double thePoint2X, double thePoint2Y,
+      double thePassedX, double thePassedY,
+      bool isPoint1Center = true);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
+      const PointOrReference& thePoint1,
+      const PointOrReference& thePoint2,
+      const PointOrReference& thePassedPoint,
+      bool isPoint1Center = true);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::wstring & theExternalName);
+
+  /// Add elliptic arc
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
+      double theCenterX, double theCenterY,
+      double theFocusX, double theFocusY,
+      double theStartX, double theStartY,
+      double theEndX, double theEndY,
+      bool theInversed = false);
+  /// Add elliptic arc
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
+      const PointOrReference& theCenter,
+      const PointOrReference& theMajorAxisPoint,
+      const PointOrReference& theStartPoint,
+      const PointOrReference& theEndPoint,
+      bool theInversed = false);
+  /// Add elliptic arc
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
+  /// Add elliptic arc
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::wstring & theExternalName);
+
+  /// Add B-spline
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_BSpline> addSpline(
+      const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
+      const int degree = -1,
+      const std::list<PointOrReference>& poles = std::list<PointOrReference>(),
+      const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
+      const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
+      const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
+      const bool periodic = false);
+
+  /// Add interpolation feature
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_BSpline> addInterpolation(
+      const std::list<ModelHighAPI_RefAttr>& points,
+      const bool periodic = false,
+      const bool closed = false);
+
+  /// Add approximation feature
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_BSpline> addApproximation(
+      const std::list<ModelHighAPI_RefAttr>& points,
+      const ModelHighAPI_Double& precision = ModelHighAPI_Double(1.e-3),
+      const bool periodic = false,
+      const bool closed = false);
 
   /// Add projection
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Projection> addProjection(const std::string & theExternalName);
+  std::shared_ptr<SketchAPI_Projection> addProjection(
+      const ModelHighAPI_Selection & theExternalFeature,
+      bool keepResult = false,
+      bool keepRefToOriginal = true);
 
   /// Add mirror
   SKETCHAPI_EXPORT
@@ -238,6 +375,15 @@ public:
       const ModelHighAPI_RefAttr & theMirrorLine,
       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
 
+  /// Add offset
+  SKETCHAPI_EXPORT
+    std::shared_ptr<SketchAPI_Offset> addOffset(
+      const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
+      const ModelHighAPI_Double & theValue,
+      const bool theReversed = false,
+      const std::string & theJointType = SketchPlugin_Offset::JOINT_KEEP_DISTANCE(),
+      const bool theApprox = false);
+
   /// Add translation
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Translation> addTranslation(
@@ -254,14 +400,14 @@ public:
       const ModelHighAPI_RefAttr & theCenter,
       const ModelHighAPI_Double & theAngle,
       const ModelHighAPI_Integer & theNumberOfObjects,
-      bool theFullValue = false);
+      bool theFullValue = false,
+      bool theReversed  = false);
 
   /// Add split
   SKETCHAPI_EXPORT
   std::shared_ptr<ModelHighAPI_Interface> addSplit(
       const ModelHighAPI_Reference& theFeature,
-      const ModelHighAPI_RefAttr& thePoint1,
-      const ModelHighAPI_RefAttr& thePoint2);
+      const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
 
   /// Add trim
   SKETCHAPI_EXPORT
@@ -274,7 +420,8 @@ public:
   std::shared_ptr<ModelHighAPI_Interface> setAngle(
       const ModelHighAPI_RefAttr & theLine1,
       const ModelHighAPI_RefAttr & theLine2,
-      const ModelHighAPI_Double & theValue);
+      const ModelHighAPI_Double & theValue,
+      const std::string& type = std::string());
 
   /// Set complementary angle
   SKETCHAPI_EXPORT
@@ -305,10 +452,39 @@ public:
   /// Set distance
   SKETCHAPI_EXPORT
   std::shared_ptr<ModelHighAPI_Interface> setDistance(
+      const ModelHighAPI_RefAttr & thePoint,
+      const ModelHighAPI_RefAttr & thePointOrLine,
+      const ModelHighAPI_Double & theValue,
+      bool isSigned = false);
+
+  /// Set signed distance
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
+      const ModelHighAPI_RefAttr & thePoint,
+      const ModelHighAPI_RefAttr & thePointOrLine,
+      const ModelHighAPI_Double & theValue);
+
+  /// Set unsigned distance
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
       const ModelHighAPI_RefAttr & thePoint,
       const ModelHighAPI_RefAttr & thePointOrLine,
       const ModelHighAPI_Double & theValue);
 
+  /// Set horizontal distance
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
+      const ModelHighAPI_RefAttr & thePoint1,
+      const ModelHighAPI_RefAttr & thePoint2,
+      const ModelHighAPI_Double & theValue);
+
+  /// Set vertical distance
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
+      const ModelHighAPI_RefAttr & thePoint1,
+      const ModelHighAPI_RefAttr & thePoint2,
+      const ModelHighAPI_Double & theValue);
+
   /// Set equal
   SKETCHAPI_EXPORT
   std::shared_ptr<ModelHighAPI_Interface> setEqual(
@@ -318,7 +494,12 @@ public:
   /// Set fillet
   SKETCHAPI_EXPORT
   std::shared_ptr<ModelHighAPI_Interface> setFillet(
-      const std::list<ModelHighAPI_RefAttr> & thePoints,
+      const ModelHighAPI_RefAttr & thePoint);
+
+  /// Set fillet with additional radius constraint
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
+      const ModelHighAPI_RefAttr & thePoint,
       const ModelHighAPI_Double & theRadius);
 
   /// Set fixed
@@ -343,6 +524,11 @@ public:
       const ModelHighAPI_RefAttr & thePoint,
       const ModelHighAPI_RefAttr & theLine);
 
+  /// Set middle
+  SKETCHAPI_EXPORT
+    std::shared_ptr<SketchAPI_MacroMiddlePoint> setMiddlePoint(
+      const ModelHighAPI_RefAttr& theLine);
+
   /// Set parallel
   SKETCHAPI_EXPORT
   std::shared_ptr<ModelHighAPI_Interface> setParallel(
@@ -378,6 +564,19 @@ public:
       const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
       const ModelHighAPI_Double & theValue);
 
+  /// Move point or sketch feature
+  SKETCHAPI_EXPORT
+  void move(const ModelHighAPI_RefAttr& theMovedEntity,
+            const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
+
+  /// Move point or sketch feature
+  SKETCHAPI_EXPORT
+  void move(const ModelHighAPI_RefAttr& theMovedEntity,
+            double theTargetX, double theTargetY);
+
+  SKETCHAPI_EXPORT
+  std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
+
   // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
   /// Select face
   SKETCHAPI_EXPORT
@@ -395,6 +594,8 @@ protected:
 //! Pointer on Sketch object
 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
 
+//--------------------------------------------------------------------------------------
+
 /**\ingroup CPPHighAPI
  * \brief Create Sketch feature
  */
@@ -414,7 +615,7 @@ SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
  */
 SKETCHAPI_EXPORT
 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
-                    const std::string & theExternalName);
+                    const std::wstring & theExternalName);
 
 /**\ingroup CPPHighAPI
  * \brief Create Sketch feature
@@ -424,5 +625,13 @@ SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
                     std::shared_ptr<ModelAPI_Object> thePlaneObject);
 
 //--------------------------------------------------------------------------------------
+
+/** \ingroup CPPHighAPI
+ *  \brief Copy sketch with all its sub-features
+ */
+SKETCHAPI_EXPORT
+SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
+                     const SketchPtr & theSketch);
+
 //--------------------------------------------------------------------------------------
 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */