Salome HOME
Update copyrights
[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 whether the shape is a vertex
81   GEOMAPI_EXPORT
82   virtual bool isVertex() const;
83
84   /// Returns whether the shape is an edge
85   GEOMAPI_EXPORT
86   virtual bool isEdge() const;
87
88   /// Returns whether the shape is a wire
89   GEOMAPI_EXPORT
90   virtual bool isWire() const;
91
92   /// Returns whether the shape is a face
93   GEOMAPI_EXPORT
94   virtual bool isFace() const;
95
96   /// Returns whether the shape is a shell
97   GEOMAPI_EXPORT
98   virtual bool isShell() const;
99
100   /// Returns whether the shape is a compound
101   GEOMAPI_EXPORT
102   virtual bool isCompound() const;
103
104   /// Returns whether the shape is a compound of solids
105   GEOMAPI_EXPORT
106   virtual bool isCompoundOfSolids() const;
107
108   /// Returns whether the shape is a compound where all elements are topologically connected
109   GEOMAPI_EXPORT
110   virtual bool isConnectedTopology() const;
111
112   /// Returns whether the shape is a solid
113   GEOMAPI_EXPORT
114   virtual bool isSolid() const;
115
116   /// Returns whether the shape is a compsolid
117   GEOMAPI_EXPORT
118   virtual bool isCompSolid() const;
119
120   /// Returns whether the shape is planar
121   GEOMAPI_EXPORT
122   virtual bool isPlanar() const;
123
124   /// Returns vertex or empty shape
125   GEOMAPI_EXPORT
126   std::shared_ptr<GeomAPI_Vertex> vertex() const;
127
128   /// Returns edge or empty shape
129   GEOMAPI_EXPORT
130   std::shared_ptr<GeomAPI_Edge> edge() const;
131
132   /// Returns wire or empty shape
133   GEOMAPI_EXPORT
134   std::shared_ptr<GeomAPI_Wire> wire() const;
135
136   /// Returns face or empty shape
137   GEOMAPI_EXPORT
138   std::shared_ptr<GeomAPI_Face> face() const;
139
140   /// Returns shell or empty shape
141   GEOMAPI_EXPORT
142   std::shared_ptr<GeomAPI_Shell> shell() const;
143
144   /// Returns solid or empty shape
145   GEOMAPI_EXPORT
146   std::shared_ptr<GeomAPI_Solid> solid() const;
147
148   /// Returns list of sub-shapes of the given type
149   GEOMAPI_EXPORT
150   std::list<std::shared_ptr<GeomAPI_Shape> > subShapes(ShapeType theSubShapeType) const;
151
152   /// Returns the shape type
153   GEOMAPI_EXPORT
154   virtual ShapeType shapeType() const;
155
156   /// Returns the type enumeration by the string-type
157   GEOMAPI_EXPORT static ShapeType shapeTypeByStr(std::string theType);
158
159   /// \return the shape type as string.
160   GEOMAPI_EXPORT
161   virtual std::string shapeTypeStr() const;
162
163   /// \return the shape orientation.
164   GEOMAPI_EXPORT virtual Orientation orientation() const;
165
166   /// Sets the shape orientation.
167   GEOMAPI_EXPORT virtual void setOrientation(const Orientation theOrientation);
168
169   /// Reverse shape
170   GEOMAPI_EXPORT virtual void reverse();
171
172   /// \return true if passed shape is a sub-shape of this shape.
173   /// \param theShape shape to search.
174   /// \param theCheckOrientation if false, returns true even if orientation of shape differs
175   GEOMAPI_EXPORT virtual bool isSubShape(const std::shared_ptr<GeomAPI_Shape> theShape,
176     const bool theCheckOrientation = true) const;
177
178   /// Computes boundary dimensions of the shape
179   /// Returns False if it is not possible
180   GEOMAPI_EXPORT
181   bool computeSize(double& theXmin, double& theYmin, double& theZmin,
182                    double& theXmax, double& theYmax, double& theZmax) const;
183
184   /// Return middle point on the shape
185   GEOMAPI_EXPORT
186   virtual std::shared_ptr<GeomAPI_Pnt> middlePoint() const;
187
188   /// Returns the shape as BRep stream
189   GEOMAPI_EXPORT
190   std::string getShapeStream() const;
191
192   /// Returns intersection of shapes
193   GEOMAPI_EXPORT
194   std::shared_ptr<GeomAPI_Shape> intersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
195
196   /// Returns true if min distance between shapes < tolerance.
197   GEOMAPI_EXPORT
198   bool isIntersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
199
200   /// Translates the shape along the direction for the given offset
201   GEOMAPI_EXPORT
202   void translate(const std::shared_ptr<GeomAPI_Dir> theDir, const double theOffset);
203
204   /// Returns type of shapes in the compound.
205   // If shapes are of different type then it will return SHAPE type
206   GEOMAPI_EXPORT ShapeType typeOfCompoundShapes() const;
207
208   /// Returns true if shape have self-intersections.
209   /// \param[in] theLevelOfCheck defines which interferences will be checked:<br>
210   /// 0 - only V/V;<br>
211   /// 1 - V/V and V/E;<br>
212   /// 2 - V/V, V/E and E/E;<br>
213   /// 3 - V/V, V/E, E/E and V/F;<br>
214   /// 4 - V/V, V/E, E/E, V/F and E/F;<br>
215   /// 5 - V/V, V/E, E/E, V/F, E/F and F/F;<br>
216   /// 6 - V/V, V/E, E/E, V/F, E/F, F/F and V/S;<br>
217   /// 7 - V/V, V/E, E/E, V/F, E/F, F/F, V/S and E/S;<br>
218   /// 8 - V/V, V/E, E/E, V/F, E/F, F/F, V/S, E/S and F/S;<br>
219   /// 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)
220   GEOMAPI_EXPORT bool isSelfIntersected(const int theLevelOfCheck = 9) const;
221 };
222
223 //! Pointer on list of shapes
224 typedef std::list<std::shared_ptr<GeomAPI_Shape> > ListOfShape;
225
226 //! Pointer on attribute object
227 typedef std::shared_ptr<GeomAPI_Shape> GeomShapePtr;
228
229 #endif