1 // Copyright (C) 2020 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;
32 /**\class SketchPlugin_Offset
34 * \brief Builds offset curves in the sketch.
36 class SketchPlugin_Offset : public SketchPlugin_ConstraintBase
39 /// Offset macro feature kind
40 inline static const std::string& ID()
42 static const std::string ID("SketchOffset");
46 /// Returns the kind of a feature
47 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
49 static std::string MY_KIND = SketchPlugin_Offset::ID();
53 /// list of offset edges
54 inline static const std::string& EDGES_ID()
56 static const std::string ID("segments");
60 /// attribute to store the offset value
61 inline static const std::string& VALUE_ID()
63 static const std::string ID("offset_value");
67 /// attribute to store the reversed offset direction
68 inline static const std::string& REVERSED_ID()
70 static const std::string ID("reversed");
74 /// name for add wire action
75 inline static const std::string& ADD_WIRE_ACTION_ID()
77 static const std::string ID("add_wire");
81 /// Called on change of any argument-attribute of this object
82 SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
84 /// Creates a new part document if needed
85 SKETCHPLUGIN_EXPORT virtual void execute();
87 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return true; }
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);
96 /// Returns the AIS preview
97 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
99 /// Use plugin manager for features creation.
100 SketchPlugin_Offset();
103 /// \brief Initializes attributes of derived class.
104 virtual void initAttributes();
107 /// Find all wires connected with the selected edges
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);
115 /// Create BSpline or BSplinePeriodic sketch feature from theEdge
116 void mkBSpline (FeaturePtr& theResult, const GeomEdgePtr& theEdge,
117 std::list<ObjectPtr>& thePoolOfFeatures);
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);
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);