1 // Copyright (C) 2020-2023 CEA/DEN, EDF R&D
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 /// name for add wire action
105 inline static const std::string& ADD_WIRE_ACTION_ID()
107 static const std::string ID("add_wire");
111 /// Called on change of any argument-attribute of this object
112 SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
114 /// Creates a new part document if needed
115 SKETCHPLUGIN_EXPORT virtual void execute();
117 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return true; }
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);
126 /// Returns the AIS preview
127 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
129 /// Use plugin manager for features creation.
130 SketchPlugin_Offset();
133 /// \brief Initializes attributes of derived class.
134 virtual void initAttributes();
137 /// Find all wires connected with the selected edges
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);
145 /// Create BSpline or BSplinePeriodic sketch feature from theEdge
146 void mkBSpline (FeaturePtr& theResult, const GeomEdgePtr& theEdge,
147 std::list<ObjectPtr>& thePoolOfFeatures);
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);
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);
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);