]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h
Salome HOME
Fix for the issue #2854 : Group of faces in error after modification of a sketch...
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef GeomAlgoAPI_ShapeTools_H_
22 #define GeomAlgoAPI_ShapeTools_H_
23
24 #include "GeomAlgoAPI.h"
25
26 #include <GeomAPI_Shape.h>
27 #include <GeomAPI_Vertex.h>
28
29 #include <map>
30 #include <set>
31
32 class GeomAPI_Ax1;
33 class GeomAPI_Edge;
34 class GeomAPI_Dir;
35 class GeomAPI_Face;
36 class GeomAPI_PlanarEdges;
37 class GeomAPI_Pln;
38 class GeomAPI_Pnt;
39 class GeomAPI_Wire;
40 class GeomDataAPI_Point2D;
41 class ModelAPI_Object;
42
43 /// \class GeomAlgoAPI_ShapeTools
44 /// \ingroup DataAlgo
45 /// \brief Useful tools for working with shapes.
46 class GeomAlgoAPI_ShapeTools
47 {
48 public:
49   /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
50   GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
51
52   /// \return the total area of the faces of the current shape or 0.0 if it can be computed.
53   GEOMALGOAPI_EXPORT static double area(const std::shared_ptr<GeomAPI_Shape> theShape);
54
55   /// \return the centre of mass of the current face.
56   /// The coordinates returned for the center of mass
57   /// are expressed in the absolute Cartesian coordinate system.
58   /// (This function works only for surfaces).
59   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt>
60     centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
61
62   /// \brief Obtain radius of cylindrical face.
63   ///        Return negative value if the face is not a cylinder
64   GEOMALGOAPI_EXPORT static double radius(const std::shared_ptr<GeomAPI_Face>& theCylinder);
65
66   /// \brief Calculate minimal distance between shapes
67   GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
68                                                    const GeomShapePtr& theShape2);
69
70   /// \brief Combines faces with common edges to shells, or solids to compsolids.
71   /// \param[in] theCompound compound of shapes.
72   /// \param[in] theType type of combine.
73   /// \param[out] theResults resulting shapes.
74   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(
75     const std::shared_ptr<GeomAPI_Shape> theCompound,
76     const GeomAPI_Shape::ShapeType theType, ListOfShape& theResults);
77
78   /// \brief Groups shapes with shared topology to compounds.
79   /// \param[in] theCompound compound of shapes.
80   /// \return compound of compounds with shared topology.
81   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape>
82     groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
83
84   /// \brief Calculates bounding box for theShapes
85   /// \return list of eight points.
86   /// \param[in] theShapes list of shapes.
87   /// \param[in] theEnlarge enlarges bounding box size.
88   GEOMALGOAPI_EXPORT static
89     std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes,
90                                                             const double theEnlarge = 0.0);
91
92   /// \brief Enlarges or reduces plane to fit bounding box.
93   /// \return plane that fits to bounding box.
94   /// \param[in] thePlane base plane.
95   /// \param[in] thePoints bounding box points (shoud be eight).
96   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Face> fitPlaneToBox(
97     const std::shared_ptr<GeomAPI_Shape> thePlane,
98     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
99
100   /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
101   /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
102   /// Edge : theV1 is start and theV2 is end vertex;\n
103   /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
104   /// contains no edges theV1 and theV2 are nullified.\n
105   /// If none of the above theV1 and theV2 are nullified.
106   GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
107                                             std::shared_ptr<GeomAPI_Vertex>& theV1,
108                                             std::shared_ptr<GeomAPI_Vertex>& theV2);
109
110   /// \brief Creates faces with holes from wires.
111   /// \param[in] theWires base wires.
112   /// \param[out] theFaces resulting faces.
113   GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
114                                                 const std::shared_ptr<GeomAPI_Dir> theDirection,
115                                                 const ListOfShape& theWires,
116                                                 ListOfShape& theFaces);
117
118   /// \brief Return a plane for list of shapes if they are all planar.
119   /// \param[in] theShapes shapes to find plane.
120   /// \return plane where all shapes lie or empty ptr if they not planar.
121   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
122
123   /// \brief Checks that vertex/edge is inside face or vertext inside wire.
124   /// \param[in] theSubShape shape that should be inside.
125   /// \param[in] theBaseShape base shape.
126   /// \return true if edge inside the face.
127   GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(
128     const std::shared_ptr<GeomAPI_Shape> theSubShape,
129     const std::shared_ptr<GeomAPI_Shape> theBaseShape);
130
131   /// \return true if theShape is valid.
132   GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
133
134   /// \return outer wire for face. If theShape has different type returns empty pointer.
135   GEOMALGOAPI_EXPORT static
136     std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
137
138   /// \return true if edge is parallel to face.
139   GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
140                                             const std::shared_ptr<GeomAPI_Face> theFace);
141
142   // Computes intersection point between the edge curve and a face surface (only one point, with
143   // preferences to point that belongs to edge and face boundaries.
144   /// \returns null if there is no intersection
145   GEOMALGOAPI_EXPORT static std::list<std::shared_ptr<GeomAPI_Vertex> > intersect(
146     const std::shared_ptr<GeomAPI_Edge> theEdge, const std::shared_ptr<GeomAPI_Face> theFace,
147     const bool thePointsOutsideFace);
148
149   typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
150                    std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
151                              std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
152   /// \brief Performs the split of the shape by points.
153   /// \param[in] theBaseShape shape that should be splitted.
154   /// \param[in] thePoints container of points to split
155   /// \param[out] theShapes container of shapes after split
156   GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
157                                       const PointToRefsMap& thePointsInfo,
158                                       std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
159
160   /// \brief Performs the split of the shape by points.
161   /// \param[in] theBaseShape shape that should be splitted.
162   /// \param[in] thePoints container of points to split
163   /// \param[out] theShapes container of shapes after split
164   GEOMALGOAPI_EXPORT static void splitShape_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
165                                       const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
166                                       std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
167
168   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
169                                     const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
170                                     const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
171
172 #ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS
173   /// \brief Returns a dir from a shape and an axis.
174   /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir.
175   /// \param[in] theAxis axis that serves as a direction for the dir
176   /// \return dir that builds from center of mass of the base shape and the axis
177   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Dir> buildDirFromAxisAndShape(
178                                     const std::shared_ptr<GeomAPI_Shape> theBaseShape,
179                                     const std::shared_ptr<GeomAPI_Ax1> theAxis);
180 #endif
181
182   /// \brief Reapproximate a wire to build a single edge
183   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Edge> wireToEdge(
184       const std::shared_ptr<GeomAPI_Wire>& theWire);
185
186   /// \brief Get non-composite sub-shapes of the given shape.
187   /// \param[in] theShape shape that should be exploded
188   /// \return list of sub-shapes (vertices, edges, faces, solids)
189   GEOMALGOAPI_EXPORT static ListOfShape getLowLevelSubShapes(const GeomShapePtr& theShape);
190 };
191
192 #endif