Salome HOME
d25ade9a641554c632ff68695f05ab30a76c18a0
[modules/shaper.git] / src / GeomAPI / GeomAPI_Shape.h
1 // Copyright (C) 2014-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 GeomAPI_Shape_H_
21 #define GeomAPI_Shape_H_
22
23 #include "GeomAPI_Dir.h"
24
25 #include <GeomAPI_Interface.h>
26 #include <memory>
27 #include <list>
28
29 class GeomAPI_Pnt;
30 class GeomAPI_Vertex;
31 class GeomAPI_Edge;
32 class GeomAPI_Wire;
33 class GeomAPI_Face;
34 class GeomAPI_Shell;
35 class GeomAPI_Solid;
36 class GeomAPI_Trsf;
37
38 /**\class GeomAPI_Shape
39  * \ingroup DataModel
40  * \brief Interface to the topological shape object
41  */
42 class GeomAPI_Shape : public GeomAPI_Interface
43 {
44 public:
45   /// Shape type enum
46   enum ShapeType {
47     COMPOUND, COMPSOLID, SOLID, SHELL,
48     FACE, WIRE, EDGE, VERTEX,
49     SHAPE
50   };
51
52   /// Shape orientation
53   enum Orientation {
54     FORWARD,
55     REVERSED,
56     INTERNAL,
57     EXTERNAL
58   };
59
60  public:
61   /// Creation of empty (null) shape
62   GEOMAPI_EXPORT
63   GeomAPI_Shape();
64
65   /// \return a new Shape with the same Orientation and Location and a new TShape with the same
66   ///         geometry and no sub-shapes.
67   GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Shape> emptyCopied() const;
68
69   /// Returns true if the underlied shape is null
70   GEOMAPI_EXPORT
71   bool isNull() const;
72
73   /// Returns whether the shapes are equal
74   GEOMAPI_EXPORT
75   virtual bool isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const;
76
77   /// Returns whether the shapes are same
78   GEOMAPI_EXPORT
79   virtual bool isSame(const std::shared_ptr<GeomAPI_Shape> theShape) const;
80
81   /// Returns \c true if shapes have same underlying geometry
82   GEOMAPI_EXPORT
83   virtual bool isSameGeometry(const std::shared_ptr<GeomAPI_Shape> theShape) const;
84
85   /// Returns whether the shape is a vertex
86   GEOMAPI_EXPORT
87   virtual bool isVertex() const;
88
89   /// Returns whether the shape is an edge
90   GEOMAPI_EXPORT
91   virtual bool isEdge() const;
92
93   /// Returns whether the shape is a wire
94   GEOMAPI_EXPORT
95   virtual bool isWire() const;
96
97   /// Returns whether the shape is a face
98   GEOMAPI_EXPORT
99   virtual bool isFace() const;
100
101   /// Returns whether the shape is a shell
102   GEOMAPI_EXPORT
103   virtual bool isShell() const;
104
105   /// Returns whether the shape is a compound
106   GEOMAPI_EXPORT
107   virtual bool isCompound() const;
108
109   /// Returns whether the shape is a compound of solids
110   GEOMAPI_EXPORT
111   virtual bool isCompoundOfSolids() const;
112
113   /// Returns true, if the shape contains only solids, compsolids
114   /// and compounds of solids and compsolids of any nesting depth
115   GEOMAPI_EXPORT
116   virtual bool isCollectionOfSolids() const;
117
118   /// Returns whether the shape is a compound where all elements are topologically connected
119   GEOMAPI_EXPORT
120   virtual bool isConnectedTopology() const;
121
122   /// Returns whether the shape is a solid
123   GEOMAPI_EXPORT
124   virtual bool isSolid() const;
125
126   /// Returns whether the shape is a compsolid
127   GEOMAPI_EXPORT
128   virtual bool isCompSolid() const;
129
130   /// Returns whether the shape is planar
131   GEOMAPI_EXPORT
132   virtual bool isPlanar() const;
133
134   /// Returns vertex or empty shape
135   GEOMAPI_EXPORT
136   std::shared_ptr<GeomAPI_Vertex> vertex() const;
137
138   /// Returns edge or empty shape
139   GEOMAPI_EXPORT
140   std::shared_ptr<GeomAPI_Edge> edge() const;
141
142   /// Returns wire or empty shape
143   GEOMAPI_EXPORT
144   std::shared_ptr<GeomAPI_Wire> wire() const;
145
146   /// Returns face or empty shape
147   GEOMAPI_EXPORT
148   std::shared_ptr<GeomAPI_Face> face() const;
149
150   /// Returns shell or empty shape
151   GEOMAPI_EXPORT
152   std::shared_ptr<GeomAPI_Shell> shell() const;
153
154   /// Returns solid or empty shape
155   GEOMAPI_EXPORT
156   std::shared_ptr<GeomAPI_Solid> solid() const;
157
158   /// Returns list of sub-shapes of the given type
159   /// \param theSubShapeType type of sub-shapes to search.
160   /// \param theOnlyUnique set it to \c true to omit subsequent
161   ///        inclusions of the same sub-shape. By default it is \c false.
162   GEOMAPI_EXPORT
163   std::list< std::shared_ptr<GeomAPI_Shape> > subShapes(const ShapeType theSubShapeType,
164                                                         const bool theOnlyUnique = false) const;
165
166   /// Returns the shape type
167   GEOMAPI_EXPORT
168   virtual ShapeType shapeType() const;
169
170   /// Returns the type enumeration by the string-type
171   GEOMAPI_EXPORT static ShapeType shapeTypeByStr(std::string theType);
172
173   /// \return the shape type as string.
174   GEOMAPI_EXPORT
175   virtual std::string shapeTypeStr() const;
176
177   /// \return the shape orientation.
178   GEOMAPI_EXPORT virtual Orientation orientation() const;
179
180   /// Sets the shape orientation.
181   GEOMAPI_EXPORT virtual void setOrientation(const Orientation theOrientation);
182
183   /// Reverse shape
184   GEOMAPI_EXPORT virtual void reverse();
185
186   /// \return true if passed shape is a sub-shape of this shape.
187   /// \param theShape shape to search.
188   /// \param theCheckOrientation if false, returns true even if orientation of shape differs
189   GEOMAPI_EXPORT virtual bool isSubShape(const std::shared_ptr<GeomAPI_Shape> theShape,
190     const bool theCheckOrientation = true) const;
191
192   /// Computes boundary dimensions of the shape
193   /// Returns False if it is not possible
194   GEOMAPI_EXPORT
195   bool computeSize(double& theXmin, double& theYmin, double& theZmin,
196                    double& theXmax, double& theYmax, double& theZmax) const;
197
198   /// Return middle point on the shape
199   GEOMAPI_EXPORT
200   virtual std::shared_ptr<GeomAPI_Pnt> middlePoint() const;
201
202   /// Returns the shape as BRep stream
203   GEOMAPI_EXPORT
204   std::string getShapeStream(const bool theWithTriangulation = true) const;
205
206   /// Returns intersection of shapes
207   GEOMAPI_EXPORT
208   std::shared_ptr<GeomAPI_Shape> intersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
209
210   /// Returns true if min distance between shapes < tolerance.
211   GEOMAPI_EXPORT
212   bool isIntersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
213
214   /// Translates the shape along the direction for the given offset
215   GEOMAPI_EXPORT
216   void translate(const std::shared_ptr<GeomAPI_Dir> theDir, const double theOffset);
217
218   /// Moves the shape with the given transformation matrix.
219   GEOMAPI_EXPORT
220     void move(const std::shared_ptr<GeomAPI_Trsf> theTransformation);
221
222   /// Returns type of shapes in the compound.
223   // If shapes are of different type then it will return SHAPE type
224   GEOMAPI_EXPORT ShapeType typeOfCompoundShapes() const;
225
226   /// Returns true if shape have self-intersections.
227   /// \param[in] theLevelOfCheck defines which interferences will be checked:<br>
228   /// 0 - only V/V;<br>
229   /// 1 - V/V and V/E;<br>
230   /// 2 - V/V, V/E and E/E;<br>
231   /// 3 - V/V, V/E, E/E and V/F;<br>
232   /// 4 - V/V, V/E, E/E, V/F and E/F;<br>
233   /// 5 - V/V, V/E, E/E, V/F, E/F and F/F;<br>
234   /// 6 - V/V, V/E, E/E, V/F, E/F, F/F and V/S;<br>
235   /// 7 - V/V, V/E, E/E, V/F, E/F, F/F, V/S and E/S;<br>
236   /// 8 - V/V, V/E, E/E, V/F, E/F, F/F, V/S, E/S and F/S;<br>
237   /// 9 - V/V, V/E, E/E, V/F, E/F, F/F, V/S, E/S, F/S and S/S - all interferences (Default value)
238   GEOMAPI_EXPORT bool isSelfIntersected(const int theLevelOfCheck = 9) const;
239
240 public:
241   /// \brief Compare addresses of shapes
242   class Comparator
243   {
244   public:
245     /// Return \c true if the address of the first shape is less than the address of the second
246     GEOMAPI_EXPORT
247     bool operator ()(const std::shared_ptr<GeomAPI_Shape>& theShape1,
248                      const std::shared_ptr<GeomAPI_Shape>& theShape2) const;
249   };
250
251   /// \brief Compare addresses of shapes with respect to orientation of shapes.
252   ///        Same TShapes with opposite orientations will be treated as different.
253   class ComparatorWithOri
254   {
255   public:
256     /// Return \c true if the address of the first shape is less than the address of the second
257     GEOMAPI_EXPORT
258       bool operator ()(const std::shared_ptr<GeomAPI_Shape>& theShape1,
259                        const std::shared_ptr<GeomAPI_Shape>& theShape2) const;
260   };
261
262   /// \brief Hash code for the shape
263   class Hash
264   {
265   public:
266     /// Return Hash value according to the address of the shape
267     GEOMAPI_EXPORT
268     int operator ()(const std::shared_ptr<GeomAPI_Shape>& theShape) const;
269   };
270
271   /// \brief Compare addresses of shapes
272   class Equal
273   {
274   public:
275     /// Return \c true if the address of the shapes are equal
276     GEOMAPI_EXPORT
277     bool operator ()(const std::shared_ptr<GeomAPI_Shape>& theShape1,
278                      const std::shared_ptr<GeomAPI_Shape>& theShape2) const;
279   };
280 };
281
282 //! Pointer on list of shapes
283 typedef std::list<std::shared_ptr<GeomAPI_Shape> > ListOfShape;
284
285 //! Pointer on attribute object
286 typedef std::shared_ptr<GeomAPI_Shape> GeomShapePtr;
287
288 #endif