]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Tool.h
Salome HOME
Merge branch 'BR_H2018_2' of https://codev-tuleap.cea.fr/plugins/git/salome/hydro...
[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 #include <QVector>
26 #include <TopTools_SequenceOfShape.hxx>
27 #include <NCollection_IndexedDataMap.hxx>
28 #include <Message_ProgressIndicator.hxx>
29
30
31 class HYDROData_PolylineXY;
32 class HYDROData_Document;
33 class HYDROData_Entity;
34 class HYDROData_SequenceOfObjects;
35 class MapOfTreatedObjects;
36 class gp_XY;
37 class QColor;
38 class QFile;
39 class TCollection_ExtendedString;
40
41 #ifdef WIN32
42   enum TopAbs_State;
43 #else
44   #include <TopAbs_State.hxx>
45 #endif
46 class TopoDS_Edge;
47 class TopoDS_Face;
48 class TopoDS_Shape;
49 class TopoDS_Wire;
50 class Quantity_Color;
51 class QColor;
52
53 class HYDRODATA_EXPORT HYDROData_Tool {
54
55 public:
56   enum ExecStatus
57   {
58     None,
59     Running,
60     Finished
61   };
62
63 public:
64
65   static void                           WriteStringsToFile( QFile&             theFile,
66                                                             const QStringList& theStrings,
67                                                             const QString&     theSep = "\n" );
68
69   /**
70    * \brief Generate name for new object.
71    * \param theDoc document
72    * \param thePrefix name prefix
73    * \param theUsedNames list of already used names
74    * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
75    * \return generated name
76    */
77   static QString GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
78                                                             const QString&                   thePrefix,
79                                                             const QStringList&               theUsedNames = QStringList(),
80                                                             const bool                       theIsTryToUsePurePrefix = false );
81   
82
83   static bool ExtractGeneratedObjectName(const QString& theName, int& outValue, QString& thePrefName);
84
85   /**
86    * \brief Checks the type of object.
87    * \param theObject object to check
88    * \return true if object is geometry object
89    */
90   static bool                           IsGeometryObject( const Handle(HYDROData_Entity)& theObject );
91
92   /**
93    * \brief Updates the child object name.
94    * \param theOldStr old father object name
95    * \param theNewStr new father object name
96    * \param theObject object to update
97    */
98   static void                           UpdateChildObjectName( const QString&                  theOldStr,
99                                                                const QString&                  theNewStr,
100                                                                const Handle(HYDROData_Entity)& theObject );
101
102
103   /**
104    * \brief Generate name for new object in python environment.
105    * \param theTreatedObjects objects which was alredy created by dump operation
106    * \param thePrefix name prefix
107    * \return generated name
108    */
109   static QString                        GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
110                                                                const QString&             thePrefix );
111  /**
112   * Computes Point State from TopAbs (simplified & limited method).
113   */
114
115   static TopAbs_State                    ComputePointState( const gp_XY& thePnt2d, 
116                                                             const TopoDS_Face& theFace );
117
118   static double GetAltitudeForEdge( const TopoDS_Edge& theEdge,
119                                     const gp_XY& thePoint,
120                                     double theParameterTolerance,
121                                     double theSquareDistanceTolerance,
122                                     double theInvalidAltitude );
123   static double GetAltitudeForWire( const TopoDS_Wire& theWire,
124                                     const gp_XY& thePoint,
125                                     double theParameterTolerance,
126                                     double theSquareDistanceTolerance,
127                                     double theInvalidAltitude );
128
129   /**
130    * \brief Returns the first shape from the group.
131    * \param theGroups the list of groups
132    * \param theGroupId the group id
133    */
134   static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
135                                               const int                          theGroupId );
136
137   static TCollection_ExtendedString toExtString( const QString& );
138   static QString                    toQString( const TCollection_ExtendedString& );
139
140   static Quantity_Color toOccColor( const QColor& );
141   static QColor toQtColor( const Quantity_Color& );
142
143   static QColor GenerateRandColor();
144   static bool GenerateNonRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
145   static void GenerateRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
146
147   static bool IsNan( double theValue );
148   static bool IsInf( double theValue );
149
150   /**
151   Rebuilds shape container (like compound/compsolid/shell) which contains faces (shared or nonshared with each other)
152   */
153   static TopoDS_Shape RebuildCmp(const TopoDS_Shape& in);
154
155   static TopoDS_Shape PolyXY2Face(const Handle(HYDROData_PolylineXY)& aPolyline);
156
157   static void SetSIProgress(const Handle(Message_ProgressIndicator)& thePI);
158   static const Handle(Message_ProgressIndicator)& GetSIProgress();
159
160   static void SetZIProgress(const Handle(Message_ProgressIndicator)& thePI);
161   static const Handle(Message_ProgressIndicator)& GetZIProgress();
162
163   static void SetTriangulationStatus(const ExecStatus& theStatus);
164   static const ExecStatus& GetTriangulationStatus();
165
166 private:
167   static Handle(Message_ProgressIndicator)& StricklerInterpolationProgress();
168   static Handle(Message_ProgressIndicator)& BathymetryInterpolationProgress();
169   static ExecStatus myTriangulationStatus;
170 };
171
172 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
173 {
174   return theFirst > ( theSecond - Precision::Confusion() ) &&
175          theFirst < ( theSecond + Precision::Confusion() );
176 }
177
178 inline bool ValuesMoreEquals( const double& theFirst, const double& theSecond )
179 {
180   return theFirst >= theSecond || ValuesEquals( theFirst, theSecond );
181 }
182
183 inline  bool ValuesLessEquals( const double& theFirst, const double& theSecond )
184 {
185   return theFirst <= theSecond || ValuesEquals( theFirst, theSecond );
186 }
187
188 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QString& theText );
189 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QColor& theText );
190 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape );
191 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace );
192 HYDRODATA_EXPORT bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 );
193 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY );
194
195 #endif
196
197