Salome HOME
Added option to create Construction Point by distance on edge. Fixed tests.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_ShapeTools.h
4 // Created:     3 August 2015
5 // Author:      Dmitry Bobylev
6
7 #ifndef GeomAlgoAPI_ShapeTools_H_
8 #define GeomAlgoAPI_ShapeTools_H_
9
10 #include "GeomAlgoAPI.h"
11
12 #include <GeomAPI_Shape.h>
13 #include <GeomAPI_Vertex.h>
14
15 class GeomAPI_Edge;
16 class GeomAPI_Dir;
17 class GeomAPI_Face;
18 class GeomAPI_PlanarEdges;
19 class GeomAPI_Pln;
20 class GeomAPI_Pnt;
21
22 /// \class GeomAlgoAPI_ShapeTools
23 /// \ingroup DataAlgo
24 /// \brief Useful tools for working with shapes.
25 class GeomAlgoAPI_ShapeTools
26 {
27 public:
28   /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
29   GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
30
31   /// \return the centre of mass of the current face. The coordinates returned for the center of mass
32   /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
33   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pnt> centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
34
35   /// \brief Combines faces with common edges to shells, or solids to compsolids.
36   /// \param[in] theCompound compound of shapes.
37   /// \param[in] theType type of combine.
38   /// \param[out] theCombinedShapes resulting shapes.
39   /// \param[out] theFreeShapes shapes that does not have common subshapes.
40   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
41                                                                          const GeomAPI_Shape::ShapeType theType,
42                                                                          ListOfShape& theCombinedShapes,
43                                                                          ListOfShape& theFreeShapes);
44
45   /// \brief Groups shapes with shared topology to compounds.
46   /// \param[in] theCompound compound of shapes.
47   /// \return compound of compounds with shared topology.
48   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound);
49
50   /// \brief Calculates bounding box for theShapes
51   /// \return list of eight points.
52   /// \param[in] theShapes list of shapes.
53   /// \param[in] theEnlarge enlarges bounding box size.
54   GEOMALGOAPI_EXPORT static std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge = 0.0);
55
56   /// \return infinite plane received from theFace plane.
57   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
58
59   /// \brief Enlarges or reduces plane to fit bounding box.
60   /// \return plane that fits to bounding box.
61   /// \param[in] thePlane base plane.
62   /// \param[in] thePoints bounding box points (shoud be eight).
63   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
64                                                                          const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
65
66   /// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
67   /// Vertex: theV1 and theV2 are the same and equal to theShape;\n
68   /// Edge : theV1 is start and theV2 is end vertex;\n
69   /// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
70   /// contains no edges theV1 and theV2 are nullified.\n
71   /// If none of the above theV1 and theV2 are nullified.
72   GEOMALGOAPI_EXPORT static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
73                                             std::shared_ptr<GeomAPI_Vertex>& theV1,
74                                             std::shared_ptr<GeomAPI_Vertex>& theV2);
75
76   /// \brief Creates faces with holes from wires.
77   /// \param[in] theWires base wires.
78   /// \param[out] theFaces resulting faces.
79   GEOMALGOAPI_EXPORT static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
80                                                     const std::shared_ptr<GeomAPI_Dir> theDirection,
81                                                     const ListOfShape& theWires,
82                                                     ListOfShape& theFaces);
83
84   /// \brief Return a plane for list of shapes if they are all planar.
85   /// \param[in] theShapes shapes to find plane.
86   /// \return plane where all shapes lie or empty ptr if they not planar.
87   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Pln> findPlane(const ListOfShape& theShapes);
88
89   /// \brief Checks that vertex/edge is inside face or vertext inside wire.
90   /// \param[in] theSubShape shape that should be inside.
91   /// \param[in] theBaseShape base shape.
92   /// \return true if edge inside the face.
93   GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
94                                                        const std::shared_ptr<GeomAPI_Shape> theBaseShape);
95
96   /// \return true if theShape is valid.
97   GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
98
99   /// \return outer wire for face. If theShape has different type returns empty pointer.
100   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace);
101
102   /// \return true if edge is parallel to face.
103   GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
104                                             const std::shared_ptr<GeomAPI_Face> theFace);
105
106   /// \brief Creates vertex by edge and distance on it.
107   /// \param[in] theEdge edge.
108   /// \param[in] theValue distance value.
109   /// \param[in] theIsPercent if true theValue will be treated as a percentage of theEdge total length.
110   /// \param[in] theIsReverse if true the distance will be measured from the edge end point.
111   /// \ return created vertex.
112   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Vertex> findVertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
113                                                                              const double theValue,
114                                                                              const bool theIsPercent = false,
115                                                                              const bool theIsReverse = false);
116
117 };
118
119 #endif