Salome HOME
compilation on Linux
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.h
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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
23 #ifndef HYDROData_Tool_HeaderFile
24 #define HYDROData_Tool_HeaderFile
25
26 #include "HYDROData.h"
27 #include "HYDROData_Entity.h"
28
29 #include <Precision.hxx>
30
31 #include <TopAbs_ShapeEnum.hxx>
32
33 #include <QString>
34 #include <QStringList>
35 #include <gp_XY.hxx>
36 #include <TopoDS_Face.hxx>
37
38 class QFile;
39 class TopoDS_Shape;
40 class TopTools_SequenceOfShape;
41 class Handle(HYDROData_Document);
42
43 class HYDRODATA_EXPORT HYDROData_Tool {
44
45 public:
46
47   static void                           WriteStringsToFile( QFile&             theFile,
48                                                             const QStringList& theStrings,
49                                                             const QString&     theSep = "\n" );
50
51   /**
52    * Enables "MustBeUpdated" flag for objects that are depended on "MustBeUpdated" objects.
53    * \param theDoc document where this operation is performed
54    */
55   static void                           SetMustBeUpdatedObjects( const Handle(HYDROData_Document)& theDoc );
56
57   /**
58    * \brief Generate name for new object.
59    * \param theDoc document
60    * \param thePrefix name prefix
61    * \param theUsedNames list of already used names
62    * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
63    * \return generated name
64    */
65   static QString                        GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
66                                                             const QString&                    thePrefix,
67                                                             const QStringList&                theUsedNames = QStringList(),
68                                                             const bool                        theIsTryToUsePurePrefix = false );
69
70   /**
71    * \brief Checks the type of object.
72    * \param theObject object to check
73    * \return true if object is geometry object
74    */
75   static bool                           IsGeometryObject( const Handle(HYDROData_Entity)& theObject );
76
77   /**
78    * \brief Updates the child object name.
79    * \param theOldStr old father object name
80    * \param theNewStr new father object name
81    * \param theObject object to update
82    */
83   static void                           UpdateChildObjectName( const QString&                  theOldStr,
84                                                                const QString&                  theNewStr,
85                                                                const Handle(HYDROData_Entity)& theObject );
86
87
88   /**
89    * \brief Generate name for new object in python environment.
90    * \param theTreatedObjects objects which was alredy created by dump operation
91    * \param thePrefix name prefix
92    * \return generated name
93    */
94   static QString                        GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
95                                                                const QString&             thePrefix );
96  /**
97   * Computes Point State from TopAbs (simplified & limited method).
98   */
99
100  static TopAbs_State                    ComputePointState( const gp_XY& thePnt2d, 
101                                                                const TopoDS_Face& theFace );
102 };
103
104 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
105 {
106   return theFirst > ( theSecond - Precision::Confusion() ) &&
107          theFirst < ( theSecond + Precision::Confusion() );
108 }
109
110 inline bool ValuesMoreEquals( const double& theFirst, const double& theSecond )
111 {
112   return theFirst >= theSecond || ValuesEquals( theFirst, theSecond );
113 }
114
115 inline  bool ValuesLessEquals( const double& theFirst, const double& theSecond )
116 {
117   return theFirst <= theSecond || ValuesEquals( theFirst, theSecond );
118 }
119
120
121
122
123 #endif
124
125