Salome HOME
Merge branch 'V9_11_BR'
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Offset.h
index 482a752457f0774aa98a0f844f7e0ba261247103..a865ba483b28d62038fe4b11ddc9bde1ba399a6b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020  CEA/DEN, EDF R&D
+// Copyright (C) 2020-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
 #define SketchPlugin_Offset_H_
 
 #include <SketchPlugin.h>
-#include <SketchPlugin_SketchEntity.h>
+#include <SketchPlugin_ConstraintBase.h>
 
 #include <GeomDataAPI_Point2D.h>
 
 #include <GeomAPI_Edge.h>
-#include <GeomAPI_IPresentable.h>
+
+class GeomAlgoAPI_MakeShape;
+class GeomAlgoAPI_Offset;
+class GeomAlgoAPI_WireBuilder;
 
 /**\class SketchPlugin_Offset
  * \ingroup Plugins
  * \brief Builds offset curves in the sketch.
  */
-class SketchPlugin_Offset : public SketchPlugin_SketchEntity, public GeomAPI_IPresentable
+class SketchPlugin_Offset : public SketchPlugin_ConstraintBase
 {
 public:
   /// Offset macro feature kind
@@ -49,6 +52,34 @@ public:
     return MY_KIND;
   }
 
+  /// Type of joint
+  inline static const std::string& JOINT_ID()
+  {
+    static const std::string ID("offset_joint");
+    return ID;
+  }
+
+  /// Keep distance joint (add arcs where needed)
+  inline static const std::string& JOINT_KEEP_DISTANCE()
+  {
+    static const std::string ID("KeepDistance");
+    return ID;
+  }
+
+  /// Arcs joint (make fillets on all straight lines intersections)
+  inline static const std::string& JOINT_ARCS()
+  {
+    static const std::string ID("Arcs");
+    return ID;
+  }
+
+  /// Lines joint (do not add new arcs, prolongate and intersect adjacent lines)
+  inline static const std::string& JOINT_LINES()
+  {
+    static const std::string ID("Lines");
+    return ID;
+  }
+
   /// list of offset edges
   inline static const std::string& EDGES_ID()
   {
@@ -70,10 +101,10 @@ public:
     return ID;
   }
 
-  /// attribute to store the created objects
-  inline static const std::string& CREATED_ID()
+  /// attribute to approx by segments and arcs
+  inline static const std::string& APPROX_ID()
   {
-    static const std::string ID("created");
+    static const std::string ID("approx");
     return ID;
   }
 
@@ -90,11 +121,6 @@ public:
   /// Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
-  /// Reimplemented from ModelAPI_Feature::isMacro().
-  /// \returns true
-  //SKETCHPLUGIN_EXPORT virtual bool isMacro() const { return false; }
-
-  //SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return true; }
 
   /// Find edges connected by coincident boundary constraint and composing a wire with
@@ -112,37 +138,50 @@ public:
 
 protected:
   /// \brief Initializes attributes of derived class.
-  virtual void initDerivedClassAttributes();
+  virtual void initAttributes();
 
 private:
   /// Find all wires connected with the selected edges
   bool findWires();
 
-  // Create sketch feature for each edge of theOffsetResult,
-  // and store it in CREATED_ID()
-  void addToSketch (const std::shared_ptr<GeomAPI_Shape>& theOffsetResult);
-
-  // Remove created features
-  void removeCreated ();
-
-  // Create BSpline or BSplinePeriodic sketch feature from theEdge
-  void mkBSpline (FeaturePtr& theResult, const GeomEdgePtr& theEdge);
-
-  // Find edges that prolongate theEdgeFeature (in a chain) at theEndPoint
-  // Recursive method.
-  // \param[in] theFirstEdge Start edge of wire searching
-  // \param[in] theEdge Current edge
-  // \param[in] theEndPoint Point of the Current edge, not belonging to a previous edge
-  // \param[in/out] theEdgesSet All edges to find among. If empty, all sketch edges assumed.
-  // \param[in/out] theChain Resulting edges
-  // \param[in] isPrepend if true, push new found edges to theChain front, else to the back
+  /// Create sketch feature for each edge of the offset result,
+  /// and store it in ENTITY_B(). Original edges are copied to ENTITY_A() to update
+  /// correctly if original selection is modified.
+  void addToSketch (const std::list< std::shared_ptr<GeomAlgoAPI_MakeShape> >& theOffsetAlgos);
+
+  /// Create BSpline or BSplinePeriodic sketch feature from theEdge
+  void mkBSpline (FeaturePtr& theResult, const GeomEdgePtr& theEdge,
+                  std::list<ObjectPtr>& thePoolOfFeatures);
+
+  /// Update existent feature by the parameters of the given edge or create a new feature.
+  /// \param[in]     theShape          a shape to be converted to sketch feature
+  /// \param[in,out] theFeature        sketch feature to be updated or created from scratch
+  /// \param[in,out] thePoolOfFeatures list of features to be removed (may be used as a new feature)
+  void updateExistentOrCreateNew (const GeomShapePtr& theShape, FeaturePtr& theFeature,
+                                  std::list<ObjectPtr>& thePoolOfFeatures);
+
+  /// Find edges that prolongate theEdgeFeature (in a chain) at theEndPoint
+  /// Recursive method.
+  /// \param[in] theFirstEdge Start edge of wire searching
+  /// \param[in] theEdge Current edge
+  /// \param[in] theEndPoint Point of the Current edge, not belonging to a previous edge
+  /// \param[in/out] theEdgesSet All edges to find among. If empty, all sketch edges assumed.
+  /// \param[in/out] theProcessedEdgesSet Already processed (put in chains) edges.
+  /// \param[in/out] theChain Resulting edges
+  /// \param[in] isPrepend if true, push new found edges to theChain front, else to the back
   /// \return \c true if the chain is closed
   bool findWireOneWay (const FeaturePtr& theFirstEdge,
                        const FeaturePtr& theEdge,
                        const std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint,
                        std::set<FeaturePtr>& theEdgesSet,
+                       std::set<FeaturePtr>& theProcessedEdgesSet,
                        std::list<FeaturePtr>& theChain,
                        const bool isPrepend = false);
+
+  void makeFillet (const double theValue,
+                   const std::shared_ptr<GeomAlgoAPI_WireBuilder>&,
+                   const std::shared_ptr<GeomAlgoAPI_Offset>&,
+                   std::list< std::shared_ptr<GeomAlgoAPI_MakeShape> >& theOffsetAlgos);
 };
 
 #endif