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