1 // Copyright (C) 2014-2021 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 GeomAPI_Shape_H_
21 #define GeomAPI_Shape_H_
23 #include "GeomAPI_Dir.h"
25 #include <GeomAPI_Interface.h>
38 /**\class GeomAPI_Shape
40 * \brief Interface to the topological shape object
42 class GeomAPI_Shape : public GeomAPI_Interface
47 COMPOUND, COMPSOLID, SOLID, SHELL,
48 FACE, WIRE, EDGE, VERTEX,
61 /// Creation of empty (null) shape
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;
69 /// Returns true if the underlied shape is null
73 /// Returns whether the shapes are equal
75 virtual bool isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const;
77 /// Returns whether the shapes are same
79 virtual bool isSame(const std::shared_ptr<GeomAPI_Shape> theShape) const;
81 /// Returns \c true if shapes have same underlying geometry
83 virtual bool isSameGeometry(const std::shared_ptr<GeomAPI_Shape> theShape) const;
85 /// Returns whether the shape is a vertex
87 virtual bool isVertex() const;
89 /// Returns whether the shape is an edge
91 virtual bool isEdge() const;
93 /// Returns whether the shape is a wire
95 virtual bool isWire() const;
97 /// Returns whether the shape is a face
99 virtual bool isFace() const;
101 /// Returns whether the shape is a shell
103 virtual bool isShell() const;
105 /// Returns whether the shape is a compound
107 virtual bool isCompound() const;
109 /// Returns whether the shape is a compound of solids
111 virtual bool isCompoundOfSolids() const;
113 /// Returns true, if the shape contains only solids, compsolids
114 /// and compounds of solids and compsolids of any nesting depth
116 virtual bool isCollectionOfSolids() const;
118 /// Returns whether the shape is a compound where all elements are topologically connected
120 virtual bool isConnectedTopology() const;
122 /// Returns whether the shape is a solid
124 virtual bool isSolid() const;
126 /// Returns whether the shape is a compsolid
128 virtual bool isCompSolid() const;
130 /// Returns whether the shape is planar
132 virtual bool isPlanar() const;
134 /// Returns vertex or empty shape
136 std::shared_ptr<GeomAPI_Vertex> vertex() const;
138 /// Returns edge or empty shape
140 std::shared_ptr<GeomAPI_Edge> edge() const;
142 /// Returns wire or empty shape
144 std::shared_ptr<GeomAPI_Wire> wire() const;
146 /// Returns face or empty shape
148 std::shared_ptr<GeomAPI_Face> face() const;
150 /// Returns shell or empty shape
152 std::shared_ptr<GeomAPI_Shell> shell() const;
154 /// Returns solid or empty shape
156 std::shared_ptr<GeomAPI_Solid> solid() const;
158 /// Returns list of sub-shapes of the given type
160 std::list<std::shared_ptr<GeomAPI_Shape> > subShapes(ShapeType theSubShapeType) const;
162 /// Returns the shape type
164 virtual ShapeType shapeType() const;
166 /// Returns the type enumeration by the string-type
167 GEOMAPI_EXPORT static ShapeType shapeTypeByStr(std::string theType);
169 /// \return the shape type as string.
171 virtual std::string shapeTypeStr() const;
173 /// \return the shape orientation.
174 GEOMAPI_EXPORT virtual Orientation orientation() const;
176 /// Sets the shape orientation.
177 GEOMAPI_EXPORT virtual void setOrientation(const Orientation theOrientation);
180 GEOMAPI_EXPORT virtual void reverse();
182 /// \return true if passed shape is a sub-shape of this shape.
183 /// \param theShape shape to search.
184 /// \param theCheckOrientation if false, returns true even if orientation of shape differs
185 GEOMAPI_EXPORT virtual bool isSubShape(const std::shared_ptr<GeomAPI_Shape> theShape,
186 const bool theCheckOrientation = true) const;
188 /// Computes boundary dimensions of the shape
189 /// Returns False if it is not possible
191 bool computeSize(double& theXmin, double& theYmin, double& theZmin,
192 double& theXmax, double& theYmax, double& theZmax) const;
194 /// Return middle point on the shape
196 virtual std::shared_ptr<GeomAPI_Pnt> middlePoint() const;
198 /// Returns the shape as BRep stream
200 std::string getShapeStream(const bool theWithTriangulation = true) const;
202 /// Returns intersection of shapes
204 std::shared_ptr<GeomAPI_Shape> intersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
206 /// Returns true if min distance between shapes < tolerance.
208 bool isIntersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
210 /// Translates the shape along the direction for the given offset
212 void translate(const std::shared_ptr<GeomAPI_Dir> theDir, const double theOffset);
214 /// Moves the shape with the given transformation matrix.
216 void move(const std::shared_ptr<GeomAPI_Trsf> theTransformation);
218 /// Returns type of shapes in the compound.
219 // If shapes are of different type then it will return SHAPE type
220 GEOMAPI_EXPORT ShapeType typeOfCompoundShapes() const;
222 /// Returns true if shape have self-intersections.
223 /// \param[in] theLevelOfCheck defines which interferences will be checked:<br>
224 /// 0 - only V/V;<br>
225 /// 1 - V/V and V/E;<br>
226 /// 2 - V/V, V/E and E/E;<br>
227 /// 3 - V/V, V/E, E/E and V/F;<br>
228 /// 4 - V/V, V/E, E/E, V/F and E/F;<br>
229 /// 5 - V/V, V/E, E/E, V/F, E/F and F/F;<br>
230 /// 6 - V/V, V/E, E/E, V/F, E/F, F/F and V/S;<br>
231 /// 7 - V/V, V/E, E/E, V/F, E/F, F/F, V/S and E/S;<br>
232 /// 8 - V/V, V/E, E/E, V/F, E/F, F/F, V/S, E/S and F/S;<br>
233 /// 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)
234 GEOMAPI_EXPORT bool isSelfIntersected(const int theLevelOfCheck = 9) const;
237 /// \brief Compare addresses of shapes
241 /// Return \c true if the address of the first shape is less than the address of the second
243 bool operator ()(const std::shared_ptr<GeomAPI_Shape>& theShape1,
244 const std::shared_ptr<GeomAPI_Shape>& theShape2) const;
247 /// \brief Compare addresses of shapes with respect to orientation of shapes.
248 /// Same TShapes with opposite orientations will be treated as different.
249 class ComparatorWithOri
252 /// Return \c true if the address of the first shape is less than the address of the second
254 bool operator ()(const std::shared_ptr<GeomAPI_Shape>& theShape1,
255 const std::shared_ptr<GeomAPI_Shape>& theShape2) const;
258 /// \brief Hash code for the shape
262 /// Return Hash value according to the address of the shape
264 int operator ()(const std::shared_ptr<GeomAPI_Shape>& theShape) const;
267 /// \brief Compare addresses of shapes
271 /// Return \c true if the address of the shapes are equal
273 bool operator ()(const std::shared_ptr<GeomAPI_Shape>& theShape1,
274 const std::shared_ptr<GeomAPI_Shape>& theShape2) const;
278 //! Pointer on list of shapes
279 typedef std::list<std::shared_ptr<GeomAPI_Shape> > ListOfShape;
281 //! Pointer on attribute object
282 typedef std::shared_ptr<GeomAPI_Shape> GeomShapePtr;