1 // Copyright (C) 2020-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef SketchPlugin_Offset_H_
21 #define SketchPlugin_Offset_H_
23 #include <SketchPlugin.h>
24 #include <SketchPlugin_ConstraintBase.h>
26 #include <GeomDataAPI_Point2D.h>
28 #include <GeomAPI_Edge.h>
30 class GeomAlgoAPI_MakeShape;
31 class GeomAlgoAPI_Offset;
32 class GeomAlgoAPI_WireBuilder;
34 /**\class SketchPlugin_Offset
36 * \brief Builds offset curves in the sketch.
38 class SketchPlugin_Offset : public SketchPlugin_ConstraintBase
41 /// Offset macro feature kind
42 inline static const std::string& ID()
44 static const std::string ID("SketchOffset");
48 /// Returns the kind of a feature
49 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
51 static std::string MY_KIND = SketchPlugin_Offset::ID();
56 inline static const std::string& JOINT_ID()
58 static const std::string ID("offset_joint");
62 /// Keep distance joint (add arcs where needed)
63 inline static const std::string& JOINT_KEEP_DISTANCE()
65 static const std::string ID("KeepDistance");
69 /// Arcs joint (make fillets on all straight lines intersections)
70 inline static const std::string& JOINT_ARCS()
72 static const std::string ID("Arcs");
76 /// Lines joint (do not add new arcs, prolongate and intersect adjacent lines)
77 inline static const std::string& JOINT_LINES()
79 static const std::string ID("Lines");
83 /// list of offset edges
84 inline static const std::string& EDGES_ID()
86 static const std::string ID("segments");
90 /// attribute to store the offset value
91 inline static const std::string& VALUE_ID()
93 static const std::string ID("offset_value");
97 /// attribute to store the reversed offset direction
98 inline static const std::string& REVERSED_ID()
100 static const std::string ID("reversed");
104 /// attribute to approx by segments and arcs
105 inline static const std::string& APPROX_ID()
107 static const std::string ID("approx");
111 /// name for add wire action
112 inline static const std::string& ADD_WIRE_ACTION_ID()
114 static const std::string ID("add_wire");
118 /// Called on change of any argument-attribute of this object
119 SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
121 /// Creates a new part document if needed
122 SKETCHPLUGIN_EXPORT virtual void execute();
124 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return true; }
126 /// Find edges connected by coincident boundary constraint and composing a wire with
127 /// the already selected segments. It means that not more than 2 edges can be connected
128 /// with the coincident point.
129 /// \param[in] theActionId action key id (in following form: Action#Index)
130 /// \return \c false in case the action not performed.
131 SKETCHPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId);
133 /// Returns the AIS preview
134 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
136 /// Use plugin manager for features creation.
137 SketchPlugin_Offset();
140 /// \brief Initializes attributes of derived class.
141 virtual void initAttributes();
144 /// Find all wires connected with the selected edges
147 /// Create sketch feature for each edge of the offset result,
148 /// and store it in ENTITY_B(). Original edges are copied to ENTITY_A() to update
149 /// correctly if original selection is modified.
150 void addToSketch (const std::list< std::shared_ptr<GeomAlgoAPI_MakeShape> >& theOffsetAlgos);
152 /// Create BSpline or BSplinePeriodic sketch feature from theEdge
153 void mkBSpline (FeaturePtr& theResult, const GeomEdgePtr& theEdge,
154 std::list<ObjectPtr>& thePoolOfFeatures);
156 /// Update existent feature by the parameters of the given edge or create a new feature.
157 /// \param[in] theShape a shape to be converted to sketch feature
158 /// \param[in,out] theFeature sketch feature to be updated or created from scratch
159 /// \param[in,out] thePoolOfFeatures list of features to be removed (may be used as a new feature)
160 void updateExistentOrCreateNew (const GeomShapePtr& theShape, FeaturePtr& theFeature,
161 std::list<ObjectPtr>& thePoolOfFeatures);
163 /// Find edges that prolongate theEdgeFeature (in a chain) at theEndPoint
164 /// Recursive method.
165 /// \param[in] theFirstEdge Start edge of wire searching
166 /// \param[in] theEdge Current edge
167 /// \param[in] theEndPoint Point of the Current edge, not belonging to a previous edge
168 /// \param[in/out] theEdgesSet All edges to find among. If empty, all sketch edges assumed.
169 /// \param[in/out] theProcessedEdgesSet Already processed (put in chains) edges.
170 /// \param[in/out] theChain Resulting edges
171 /// \param[in] isPrepend if true, push new found edges to theChain front, else to the back
172 /// \return \c true if the chain is closed
173 bool findWireOneWay (const FeaturePtr& theFirstEdge,
174 const FeaturePtr& theEdge,
175 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint,
176 std::set<FeaturePtr>& theEdgesSet,
177 std::set<FeaturePtr>& theProcessedEdgesSet,
178 std::list<FeaturePtr>& theChain,
179 const bool isPrepend = false);
181 void makeFillet (const double theValue,
182 const std::shared_ptr<GeomAlgoAPI_WireBuilder>&,
183 const std::shared_ptr<GeomAlgoAPI_Offset>&,
184 std::list< std::shared_ptr<GeomAlgoAPI_MakeShape> >& theOffsetAlgos);