]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMUtils/GEOMUtils.hxx
Salome HOME
d6b10816f2e446bd784d766eeac6dc8918432d44
[modules/geom.git] / src / GEOMUtils / GEOMUtils.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #ifndef _GEOMUtils_HXX_
23 #define _GEOMUtils_HXX_
24
25 #include <TopoDS_Shape.hxx>
26
27 #include <TopTools_ListOfShape.hxx>
28
29 #include <TopAbs.hxx>
30
31 #include <gp_Ax3.hxx>
32 #include <gp_Vec.hxx>
33
34 #include <NCollection_DataMap.hxx>
35
36 #include <functional>
37
38 inline Standard_Boolean IsEqual (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
39 {
40   return S1.IsSame(S2);
41 }
42
43 class GEOMUtils {
44
45  public:
46   /*!
47    * \brief Get Local Coordinate System, corresponding to the given shape.
48    *
49    * Origin of the LCS is situated at the shape's center of mass.
50    * Axes of the LCS are obtained from shape's location or,
51    * if the shape is a planar face, from position of its plane.
52    */
53   Standard_EXPORT static gp_Ax3 GetPosition (const TopoDS_Shape& theShape);
54
55   /*!
56    * \brief Get vector, defined by the given edge.
57    */
58   Standard_EXPORT static gp_Vec GetVector (const TopoDS_Shape& theShape);
59
60   /*!
61    * \brief Sort shapes in the list by their coordinates.
62    * \param SL The list of shapes to sort.
63    */
64   struct CompareShapes : public std::binary_function<TopoDS_Shape, TopoDS_Shape, bool>
65   {
66     CompareShapes (bool isOldSorting)
67       : myIsOldSorting(isOldSorting) {}
68
69     bool operator() (const TopoDS_Shape& lhs, const TopoDS_Shape& rhs);
70
71     typedef NCollection_DataMap<TopoDS_Shape, std::pair<double, double> > GEOMUtils_DataMapOfShapeDouble;
72     GEOMUtils_DataMapOfShapeDouble myMap;
73     bool myIsOldSorting;
74   };
75
76   /*!
77    * \brief Sort shapes by their centers of mass, using formula X*999 + Y*99 + Z*0.9
78    */
79   Standard_EXPORT static void SortShapes (TopTools_ListOfShape& SL,
80                                           const Standard_Boolean isOldSorting = Standard_True);
81
82   /*!
83    * \brief Convert TopoDS_COMPSOLID to TopoDS_COMPOUND.
84    *
85    * If the argument shape is not of type TopoDS_COMPSOLID, this method returns it as is.
86    *
87    * \param theCompsolid The compsolid to be converted.
88    * \retval TopoDS_Shape Returns the resulting compound.
89    */
90   Standard_EXPORT static TopoDS_Shape CompsolidToCompound (const TopoDS_Shape& theCompsolid);
91
92   /*!
93    * \brief Build a triangulation on \a theShape if it is absent.
94    * \param theShape The shape to check/build triangulation on.
95    * \retval bool Returns false if the shape has no faces, i.e. impossible to build triangulation.
96    */
97   Standard_EXPORT static bool CheckTriangulation (const TopoDS_Shape& theShape);
98
99   /*!
100    * \brief Return type of shape for explode. In case of compound it will be a type of its first sub shape.
101    * \param theShape The shape to get type of.
102    * \retval TopAbs_ShapeEnum Return type of shape for explode.
103    */
104   Standard_EXPORT static TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape);
105
106 };
107
108 #endif