Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Offset.h
1 // Copyright (C) 2020-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SketchPlugin_Offset_H_
21 #define SketchPlugin_Offset_H_
22
23 #include <SketchPlugin.h>
24 #include <SketchPlugin_ConstraintBase.h>
25
26 #include <GeomDataAPI_Point2D.h>
27
28 #include <GeomAPI_Edge.h>
29
30 class GeomAlgoAPI_MakeShape;
31 class GeomAlgoAPI_Offset;
32 class GeomAlgoAPI_WireBuilder;
33
34 /**\class SketchPlugin_Offset
35  * \ingroup Plugins
36  * \brief Builds offset curves in the sketch.
37  */
38 class SketchPlugin_Offset : public SketchPlugin_ConstraintBase
39 {
40 public:
41   /// Offset macro feature kind
42   inline static const std::string& ID()
43   {
44     static const std::string ID("SketchOffset");
45     return ID;
46   }
47
48   /// Returns the kind of a feature
49   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
50   {
51     static std::string MY_KIND = SketchPlugin_Offset::ID();
52     return MY_KIND;
53   }
54
55   /// Type of joint
56   inline static const std::string& JOINT_ID()
57   {
58     static const std::string ID("offset_joint");
59     return ID;
60   }
61
62   /// Keep distance joint (add arcs where needed)
63   inline static const std::string& JOINT_KEEP_DISTANCE()
64   {
65     static const std::string ID("KeepDistance");
66     return ID;
67   }
68
69   /// Arcs joint (make fillets on all straight lines intersections)
70   inline static const std::string& JOINT_ARCS()
71   {
72     static const std::string ID("Arcs");
73     return ID;
74   }
75
76   /// Lines joint (do not add new arcs, prolongate and intersect adjacent lines)
77   inline static const std::string& JOINT_LINES()
78   {
79     static const std::string ID("Lines");
80     return ID;
81   }
82
83   /// list of offset edges
84   inline static const std::string& EDGES_ID()
85   {
86     static const std::string ID("segments");
87     return ID;
88   }
89
90   /// attribute to store the offset value
91   inline static const std::string& VALUE_ID()
92   {
93     static const std::string ID("offset_value");
94     return ID;
95   }
96
97   /// attribute to store the reversed offset direction
98   inline static const std::string& REVERSED_ID()
99   {
100     static const std::string ID("reversed");
101     return ID;
102   }
103
104   /// name for add wire action
105   inline static const std::string& ADD_WIRE_ACTION_ID()
106   {
107     static const std::string ID("add_wire");
108     return ID;
109   }
110
111   /// Called on change of any argument-attribute of this object
112   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
113
114   /// Creates a new part document if needed
115   SKETCHPLUGIN_EXPORT virtual void execute();
116
117   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return true; }
118
119   /// Find edges connected by coincident boundary constraint and composing a wire with
120   /// the already selected segments. It means that not more than 2 edges can be connected
121   /// with the coincident point.
122   /// \param[in] theActionId action key id (in following form: Action#Index)
123   /// \return \c false in case the action not performed.
124   SKETCHPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId);
125
126   /// Returns the AIS preview
127   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
128
129   /// Use plugin manager for features creation.
130   SketchPlugin_Offset();
131
132 protected:
133   /// \brief Initializes attributes of derived class.
134   virtual void initAttributes();
135
136 private:
137   /// Find all wires connected with the selected edges
138   bool findWires();
139
140   /// Create sketch feature for each edge of the offset result,
141   /// and store it in ENTITY_B(). Original edges are copied to ENTITY_A() to update
142   /// correctly if original selection is modified.
143   void addToSketch (const std::list< std::shared_ptr<GeomAlgoAPI_MakeShape> >& theOffsetAlgos);
144
145   /// Create BSpline or BSplinePeriodic sketch feature from theEdge
146   void mkBSpline (FeaturePtr& theResult, const GeomEdgePtr& theEdge,
147                   std::list<ObjectPtr>& thePoolOfFeatures);
148
149   /// Update existent feature by the parameters of the given edge or create a new feature.
150   /// \param[in]     theShape          a shape to be converted to sketch feature
151   /// \param[in,out] theFeature        sketch feature to be updated or created from scratch
152   /// \param[in,out] thePoolOfFeatures list of features to be removed (may be used as a new feature)
153   void updateExistentOrCreateNew (const GeomShapePtr& theShape, FeaturePtr& theFeature,
154                                   std::list<ObjectPtr>& thePoolOfFeatures);
155
156   /// Find edges that prolongate theEdgeFeature (in a chain) at theEndPoint
157   /// Recursive method.
158   /// \param[in] theFirstEdge Start edge of wire searching
159   /// \param[in] theEdge Current edge
160   /// \param[in] theEndPoint Point of the Current edge, not belonging to a previous edge
161   /// \param[in/out] theEdgesSet All edges to find among. If empty, all sketch edges assumed.
162   /// \param[in/out] theProcessedEdgesSet Already processed (put in chains) edges.
163   /// \param[in/out] theChain Resulting edges
164   /// \param[in] isPrepend if true, push new found edges to theChain front, else to the back
165   /// \return \c true if the chain is closed
166   bool findWireOneWay (const FeaturePtr& theFirstEdge,
167                        const FeaturePtr& theEdge,
168                        const std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint,
169                        std::set<FeaturePtr>& theEdgesSet,
170                        std::set<FeaturePtr>& theProcessedEdgesSet,
171                        std::list<FeaturePtr>& theChain,
172                        const bool isPrepend = false);
173
174   void makeFillet (const double theValue,
175                    const std::shared_ptr<GeomAlgoAPI_WireBuilder>&,
176                    const std::shared_ptr<GeomAlgoAPI_Offset>&,
177                    std::list< std::shared_ptr<GeomAlgoAPI_MakeShape> >& theOffsetAlgos);
178 };
179
180 #endif