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