]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Tool.h
Salome HOME
refs #673: Strickler coefficient should be written for Telemac instead of Strickler...
[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 <QStringList>
24 #include <Precision.hxx>
25
26 class Handle_HYDROData_Document;
27 class Handle_HYDROData_Entity;
28 class HYDROData_SequenceOfObjects;
29 class MapOfTreatedObjects;
30 class gp_XY;
31 class QColor;
32 class QFile;
33 class TCollection_ExtendedString;
34 #ifdef WIN32
35   enum TopAbs_State;
36 #else
37   #include <TopAbs_State.hxx>
38 #endif
39 class TopoDS_Edge;
40 class TopoDS_Face;
41 class TopoDS_Shape;
42 class TopoDS_Wire;
43 class TopTools_SequenceOfShape;
44 class Quantity_Color;
45
46 class HYDRODATA_EXPORT HYDROData_Tool {
47
48 public:
49
50   static void                           WriteStringsToFile( QFile&             theFile,
51                                                             const QStringList& theStrings,
52                                                             const QString&     theSep = "\n" );
53
54   /**
55    * \brief Generate name for new object.
56    * \param theDoc document
57    * \param thePrefix name prefix
58    * \param theUsedNames list of already used names
59    * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
60    * \return generated name
61    */
62   static QString                        GenerateObjectName( const Handle_HYDROData_Document& theDoc,
63                                                             const QString&                   thePrefix,
64                                                             const QStringList&               theUsedNames = QStringList(),
65                                                             const bool                       theIsTryToUsePurePrefix = false );
66
67   /**
68    * \brief Checks the type of object.
69    * \param theObject object to check
70    * \return true if object is geometry object
71    */
72   static bool                           IsGeometryObject( const Handle_HYDROData_Entity& theObject );
73
74   /**
75    * \brief Updates the child object name.
76    * \param theOldStr old father object name
77    * \param theNewStr new father object name
78    * \param theObject object to update
79    */
80   static void                           UpdateChildObjectName( const QString&                  theOldStr,
81                                                                const QString&                  theNewStr,
82                                                                const Handle_HYDROData_Entity& theObject );
83
84
85   /**
86    * \brief Generate name for new object in python environment.
87    * \param theTreatedObjects objects which was alredy created by dump operation
88    * \param thePrefix name prefix
89    * \return generated name
90    */
91   static QString                        GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
92                                                                const QString&             thePrefix );
93  /**
94   * Computes Point State from TopAbs (simplified & limited method).
95   */
96
97  static TopAbs_State                    ComputePointState( const gp_XY& thePnt2d, 
98                                                                const TopoDS_Face& theFace );
99
100   static double GetAltitudeForEdge( const TopoDS_Edge& theEdge,
101                                     const gp_XY& thePoint,
102                                     double theParameterTolerance,
103                                     double theSquareDistanceTolerance,
104                                     double theInvalidAltitude );
105   static double GetAltitudeForWire( const TopoDS_Wire& theWire,
106                                     const gp_XY& thePoint,
107                                     double theParameterTolerance,
108                                     double theSquareDistanceTolerance,
109                                     double theInvalidAltitude );
110
111   /**
112    * \brief Returns the first shape from the group.
113    * \param theGroups the list of groups
114    * \param theGroupId the group id
115    */
116   static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
117                                               const int                          theGroupId );
118
119   static TCollection_ExtendedString toExtString( const QString& );
120   static QString                    toQString( const TCollection_ExtendedString& );
121
122   static Quantity_Color toOccColor( const QColor& );
123   static QColor toQtColor( const Quantity_Color& );
124 };
125
126 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
127 {
128   return theFirst > ( theSecond - Precision::Confusion() ) &&
129          theFirst < ( theSecond + Precision::Confusion() );
130 }
131
132 inline bool ValuesMoreEquals( const double& theFirst, const double& theSecond )
133 {
134   return theFirst >= theSecond || ValuesEquals( theFirst, theSecond );
135 }
136
137 inline  bool ValuesLessEquals( const double& theFirst, const double& theSecond )
138 {
139   return theFirst <= theSecond || ValuesEquals( theFirst, theSecond );
140 }
141
142 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QString& theText );
143 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QColor& theText );
144 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape );
145 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace );
146 HYDRODATA_EXPORT bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 );
147 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY );
148
149 #endif
150
151