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>
30 class HYDROData_PolylineXY;
31 class HYDROData_Document;
32 class HYDROData_Entity;
33 class HYDROData_SequenceOfObjects;
34 class MapOfTreatedObjects;
38 class TCollection_ExtendedString;
42 #include <TopAbs_State.hxx>
51 class HYDRODATA_EXPORT HYDROData_Tool {
55 static void WriteStringsToFile( QFile& theFile,
56 const QStringList& theStrings,
57 const QString& theSep = "\n" );
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
67 static QString GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
68 const QString& thePrefix,
69 const QStringList& theUsedNames = QStringList(),
70 const bool theIsTryToUsePurePrefix = false );
73 static bool ExtractGeneratedObjectName(const QString& theName, int& outValue, QString& thePrefName);
76 * \brief Checks the type of object.
77 * \param theObject object to check
78 * \return true if object is geometry object
80 static bool IsGeometryObject( const Handle(HYDROData_Entity)& theObject );
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
88 static void UpdateChildObjectName( const QString& theOldStr,
89 const QString& theNewStr,
90 const Handle(HYDROData_Entity)& theObject );
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
99 static QString GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
100 const QString& thePrefix );
102 * Computes Point State from TopAbs (simplified & limited method).
105 static TopAbs_State ComputePointState( const gp_XY& thePnt2d,
106 const TopoDS_Face& theFace );
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 );
120 * \brief Returns the first shape from the group.
121 * \param theGroups the list of groups
122 * \param theGroupId the group id
124 static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
125 const int theGroupId );
127 static TCollection_ExtendedString toExtString( const QString& );
128 static QString toQString( const TCollection_ExtendedString& );
130 static Quantity_Color toOccColor( const QColor& );
131 static QColor toQtColor( const Quantity_Color& );
133 static QColor GenerateRandColor();
134 static bool GenerateNonRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
135 static void GenerateRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
137 static bool IsNan( double theValue );
138 static bool IsInf( double theValue );
141 Rebuilds shape container (like compound/compsolid/shell) which contains faces (shared or nonshared with each other)
143 static TopoDS_Shape RebuildCmp(const TopoDS_Shape& in);
145 static TopoDS_Shape PolyXY2Face(const Handle(HYDROData_PolylineXY)& aPolyline);
149 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
151 return theFirst > ( theSecond - Precision::Confusion() ) &&
152 theFirst < ( theSecond + Precision::Confusion() );
155 inline bool ValuesMoreEquals( const double& theFirst, const double& theSecond )
157 return theFirst >= theSecond || ValuesEquals( theFirst, theSecond );
160 inline bool ValuesLessEquals( const double& theFirst, const double& theSecond )
162 return theFirst <= theSecond || ValuesEquals( theFirst, theSecond );
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 );