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