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