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