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