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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef HYDROData_Tool_HeaderFile
20 #define HYDROData_Tool_HeaderFile
22 #include "HYDROData.h"
23 #include <QStringList>
24 #include <Precision.hxx>
26 #include <TopTools_SequenceOfShape.hxx>
27 #include <NCollection_IndexedDataMap.hxx>
28 #include <Message_ProgressIndicator.hxx>
31 class HYDROData_PolylineXY;
32 class HYDROData_Document;
33 class HYDROData_Entity;
34 class HYDROData_SequenceOfObjects;
35 class MapOfTreatedObjects;
39 class TCollection_ExtendedString;
44 #include <TopAbs_State.hxx>
53 class HYDRODATA_EXPORT HYDROData_Tool {
65 static void WriteStringsToFile( QFile& theFile,
66 const QStringList& theStrings,
67 const QString& theSep = "\n" );
70 * \brief Generate name for new object.
71 * \param theDoc document
72 * \param thePrefix name prefix
73 * \param theUsedNames list of already used names
74 * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
75 * \return generated name
77 static QString GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
78 const QString& thePrefix,
79 const QStringList& theUsedNames = QStringList(),
80 const bool theIsTryToUsePurePrefix = false );
83 static bool ExtractGeneratedObjectName(const QString& theName, int& outValue, QString& thePrefName);
86 * \brief Checks the type of object.
87 * \param theObject object to check
88 * \return true if object is geometry object
90 static bool IsGeometryObject( const Handle(HYDROData_Entity)& theObject );
93 * \brief Updates the child object name.
94 * \param theOldStr old father object name
95 * \param theNewStr new father object name
96 * \param theObject object to update
98 static void UpdateChildObjectName( const QString& theOldStr,
99 const QString& theNewStr,
100 const Handle(HYDROData_Entity)& theObject );
104 * \brief Generate name for new object in python environment.
105 * \param theTreatedObjects objects which was alredy created by dump operation
106 * \param thePrefix name prefix
107 * \return generated name
109 static QString GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
110 const QString& thePrefix );
112 * Computes Point State from TopAbs (simplified & limited method).
115 static TopAbs_State ComputePointState( const gp_XY& thePnt2d,
116 const TopoDS_Face& theFace );
118 static double GetAltitudeForEdge( const TopoDS_Edge& theEdge,
119 const gp_XY& thePoint,
120 double theParameterTolerance,
121 double theSquareDistanceTolerance,
122 double theInvalidAltitude );
123 static double GetAltitudeForWire( const TopoDS_Wire& theWire,
124 const gp_XY& thePoint,
125 double theParameterTolerance,
126 double theSquareDistanceTolerance,
127 double theInvalidAltitude );
130 * \brief Returns the first shape from the group.
131 * \param theGroups the list of groups
132 * \param theGroupId the group id
134 static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
135 const int theGroupId );
137 static TCollection_ExtendedString toExtString( const QString& );
138 static QString toQString( const TCollection_ExtendedString& );
140 static Quantity_Color toOccColor( const QColor& );
141 static QColor toQtColor( const Quantity_Color& );
143 static QColor GenerateRandColor();
144 static bool GenerateNonRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
145 static void GenerateRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
147 static bool IsNan( double theValue );
148 static bool IsInf( double theValue );
151 Rebuilds shape container (like compound/compsolid/shell) which contains faces (shared or nonshared with each other)
153 static TopoDS_Shape RebuildCmp(const TopoDS_Shape& in);
155 static TopoDS_Shape PolyXY2Face(const Handle(HYDROData_PolylineXY)& aPolyline);
157 static void SetSIProgress(const Handle(Message_ProgressIndicator)& thePI);
158 static const Handle(Message_ProgressIndicator)& GetSIProgress();
160 static void SetZIProgress(const Handle(Message_ProgressIndicator)& thePI);
161 static const Handle(Message_ProgressIndicator)& GetZIProgress();
163 static void SetTriangulationStatus(const ExecStatus& theStatus);
164 static const ExecStatus& GetTriangulationStatus();
167 static Handle(Message_ProgressIndicator)& StricklerInterpolationProgress();
168 static Handle(Message_ProgressIndicator)& BathymetryInterpolationProgress();
169 static ExecStatus myTriangulationStatus;
172 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
174 return theFirst > ( theSecond - Precision::Confusion() ) &&
175 theFirst < ( theSecond + Precision::Confusion() );
178 inline bool ValuesMoreEquals( const double& theFirst, const double& theSecond )
180 return theFirst >= theSecond || ValuesEquals( theFirst, theSecond );
183 inline bool ValuesLessEquals( const double& theFirst, const double& theSecond )
185 return theFirst <= theSecond || ValuesEquals( theFirst, theSecond );
188 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QString& theText );
189 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QColor& theText );
190 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape );
191 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace );
192 HYDRODATA_EXPORT bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 );
193 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY );