]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Tool.h
Salome HOME
refs #649: land cover data object
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.h
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #ifndef HYDROData_Tool_HeaderFile
20 #define HYDROData_Tool_HeaderFile
21
22 #include "HYDROData.h"
23 #include "HYDROData_Entity.h"
24
25 #include <Precision.hxx>
26
27 #include <TopAbs_ShapeEnum.hxx>
28
29 #include <QString>
30 #include <QStringList>
31 #include <gp_XY.hxx>
32 #include <TopoDS_Face.hxx>
33
34 class QFile;
35 class TopoDS_Shape;
36 class TopTools_SequenceOfShape;
37 class Handle(HYDROData_Document);
38 class TopoDS_Edge;
39 class TopoDS_Wire;
40
41 class HYDRODATA_EXPORT HYDROData_Tool {
42
43 public:
44
45   static void                           WriteStringsToFile( QFile&             theFile,
46                                                             const QStringList& theStrings,
47                                                             const QString&     theSep = "\n" );
48
49   /**
50    * Enables "MustBeUpdated" flag for objects that are depended on "MustBeUpdated" objects.
51    * \param theDoc document where this operation is performed
52    */
53   static void                           SetMustBeUpdatedObjects( const Handle(HYDROData_Document)& theDoc );
54
55   /**
56    * \brief Generate name for new object.
57    * \param theDoc document
58    * \param thePrefix name prefix
59    * \param theUsedNames list of already used names
60    * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
61    * \return generated name
62    */
63   static QString                        GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
64                                                             const QString&                    thePrefix,
65                                                             const QStringList&                theUsedNames = QStringList(),
66                                                             const bool                        theIsTryToUsePurePrefix = false );
67
68   /**
69    * \brief Checks the type of object.
70    * \param theObject object to check
71    * \return true if object is geometry object
72    */
73   static bool                           IsGeometryObject( const Handle(HYDROData_Entity)& theObject );
74
75   /**
76    * \brief Updates the child object name.
77    * \param theOldStr old father object name
78    * \param theNewStr new father object name
79    * \param theObject object to update
80    */
81   static void                           UpdateChildObjectName( const QString&                  theOldStr,
82                                                                const QString&                  theNewStr,
83                                                                const Handle(HYDROData_Entity)& theObject );
84
85
86   /**
87    * \brief Generate name for new object in python environment.
88    * \param theTreatedObjects objects which was alredy created by dump operation
89    * \param thePrefix name prefix
90    * \return generated name
91    */
92   static QString                        GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
93                                                                const QString&             thePrefix );
94  /**
95   * Computes Point State from TopAbs (simplified & limited method).
96   */
97
98  static TopAbs_State                    ComputePointState( const gp_XY& thePnt2d, 
99                                                                const TopoDS_Face& theFace );
100
101   static double GetAltitudeForEdge( const TopoDS_Edge& theEdge,
102                                     const gp_XY& thePoint,
103                                     double theParameterTolerance,
104                                     double theSquareDistanceTolerance,
105                                     double theInvalidAltitude );
106   static double GetAltitudeForWire( const TopoDS_Wire& theWire,
107                                     const gp_XY& thePoint,
108                                     double theParameterTolerance,
109                                     double theSquareDistanceTolerance,
110                                     double theInvalidAltitude );
111
112   /**
113    * \brief Returns the first shape from the group.
114    * \param theGroups the list of groups
115    * \param theGroupId the group id
116    */
117   static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
118                                               const int                          theGroupId );
119
120   static TCollection_ExtendedString toExtString( const QString& );
121   static QString                    toQString( const TCollection_ExtendedString& );
122 };
123
124 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
125 {
126   return theFirst > ( theSecond - Precision::Confusion() ) &&
127          theFirst < ( theSecond + Precision::Confusion() );
128 }
129
130 inline bool ValuesMoreEquals( const double& theFirst, const double& theSecond )
131 {
132   return theFirst >= theSecond || ValuesEquals( theFirst, theSecond );
133 }
134
135 inline  bool ValuesLessEquals( const double& theFirst, const double& theSecond )
136 {
137   return theFirst <= theSecond || ValuesEquals( theFirst, theSecond );
138 }
139
140
141
142
143 #endif
144
145