Salome HOME
Task #3231: Sketcher Offset of a curve
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Offset.h
1 // Copyright (C) 2020  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
32 /**\class SketchPlugin_Offset
33  * \ingroup Plugins
34  * \brief Builds offset curves in the sketch.
35  */
36 class SketchPlugin_Offset : public SketchPlugin_ConstraintBase
37 {
38 public:
39   /// Offset macro feature kind
40   inline static const std::string& ID()
41   {
42     static const std::string ID("SketchOffset");
43     return ID;
44   }
45
46   /// Returns the kind of a feature
47   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
48   {
49     static std::string MY_KIND = SketchPlugin_Offset::ID();
50     return MY_KIND;
51   }
52
53   /// list of offset edges
54   inline static const std::string& EDGES_ID()
55   {
56     static const std::string ID("segments");
57     return ID;
58   }
59
60   /// attribute to store the offset value
61   inline static const std::string& VALUE_ID()
62   {
63     static const std::string ID("offset_value");
64     return ID;
65   }
66
67   /// attribute to store the reversed offset direction
68   inline static const std::string& REVERSED_ID()
69   {
70     static const std::string ID("reversed");
71     return ID;
72   }
73
74   /// name for add wire action
75   inline static const std::string& ADD_WIRE_ACTION_ID()
76   {
77     static const std::string ID("add_wire");
78     return ID;
79   }
80
81   /// Called on change of any argument-attribute of this object
82   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
83
84   /// Creates a new part document if needed
85   SKETCHPLUGIN_EXPORT virtual void execute();
86
87   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return true; }
88
89   /// Find edges connected by coincident boundary constraint and composing a wire with
90   /// the already selected segments. It means that not more than 2 edges can be connected
91   /// with the coincident point.
92   /// \param[in] theActionId action key id (in following form: Action#Index)
93   /// \return \c false in case the action not performed.
94   SKETCHPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId);
95
96   /// Returns the AIS preview
97   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
98
99   /// Use plugin manager for features creation.
100   SketchPlugin_Offset();
101
102 protected:
103   /// \brief Initializes attributes of derived class.
104   virtual void initAttributes();
105
106 private:
107   /// Find all wires connected with the selected edges
108   bool findWires();
109
110   /// Create sketch feature for each edge of the offset result,
111   /// and store it in ENTITY_B(). Original edges are copied to ENTITY_A() to update
112   /// correctly if original selection is modified.
113   void addToSketch (const std::list< std::shared_ptr<GeomAlgoAPI_MakeShape> >& theOffsetAlgos);
114
115   /// Create BSpline or BSplinePeriodic sketch feature from theEdge
116   void mkBSpline (FeaturePtr& theResult, const GeomEdgePtr& theEdge,
117                   std::list<ObjectPtr>& thePoolOfFeatures);
118
119   /// Update existent feature by the parameters of the given edge or create a new feature.
120   /// \param[in]     theShape          a shape to be converted to sketch feature
121   /// \param[in,out] theFeature        sketch feature to be updated or created from scratch
122   /// \param[in,out] thePoolOfFeatures list of features to be removed (may be used as a new feature)
123   void updateExistentOrCreateNew (const GeomShapePtr& theShape, FeaturePtr& theFeature,
124                                   std::list<ObjectPtr>& thePoolOfFeatures);
125
126   /// Find edges that prolongate theEdgeFeature (in a chain) at theEndPoint
127   /// Recursive method.
128   /// \param[in] theFirstEdge Start edge of wire searching
129   /// \param[in] theEdge Current edge
130   /// \param[in] theEndPoint Point of the Current edge, not belonging to a previous edge
131   /// \param[in/out] theEdgesSet All edges to find among. If empty, all sketch edges assumed.
132   /// \param[in/out] theProcessedEdgesSet Already processed (put in chains) edges.
133   /// \param[in/out] theChain Resulting edges
134   /// \param[in] isPrepend if true, push new found edges to theChain front, else to the back
135   /// \return \c true if the chain is closed
136   bool findWireOneWay (const FeaturePtr& theFirstEdge,
137                        const FeaturePtr& theEdge,
138                        const std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint,
139                        std::set<FeaturePtr>& theEdgesSet,
140                        std::set<FeaturePtr>& theProcessedEdgesSet,
141                        std::list<FeaturePtr>& theChain,
142                        const bool isPrepend = false);
143 };
144
145 #endif