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>
29 #include <Message_ProgressRange.hxx>
30 #include <Geom2d_Curve.hxx>
31 #include <Geom_Curve.hxx>
32 #include <BRepAdaptor_Curve.hxx>
35 class HYDROData_PolylineXY;
36 class HYDROData_Document;
37 class HYDROData_Entity;
38 class HYDROData_SequenceOfObjects;
39 class MapOfTreatedObjects;
43 class TCollection_ExtendedString;
48 #include <TopAbs_State.hxx>
57 class HYDRODATA_EXPORT HYDROData_Tool {
69 static void WriteStringsToFile( QFile& theFile,
70 const QStringList& theStrings,
71 const QString& theSep = "\n" );
74 * \brief Generate name for new object.
75 * \param theDoc document
76 * \param thePrefix name prefix
77 * \param theUsedNames list of already used names
78 * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
79 * \return generated name
81 static QString GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
82 const QString& thePrefix,
83 const QStringList& theUsedNames = QStringList(),
84 const bool theIsTryToUsePurePrefix = false );
87 static bool ExtractGeneratedObjectName(const QString& theName, int& outValue, QString& thePrefName);
90 * \brief Checks the type of object.
91 * \param theObject object to check
92 * \return true if object is geometry object
94 static bool IsGeometryObject( const Handle(HYDROData_Entity)& theObject );
97 * \brief Updates the child object name.
98 * \param theOldStr old father object name
99 * \param theNewStr new father object name
100 * \param theObject object to update
102 static void UpdateChildObjectName( const QString& theOldStr,
103 const QString& theNewStr,
104 const Handle(HYDROData_Entity)& theObject );
108 * \brief Generate name for new object in python environment.
109 * \param theTreatedObjects objects which was alredy created by dump operation
110 * \param thePrefix name prefix
111 * \return generated name
113 static QString GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
114 const QString& thePrefix );
116 * Computes Point State from TopAbs (simplified & limited method).
119 static TopAbs_State ComputePointState( const gp_XY& thePnt2d,
120 const TopoDS_Face& theFace );
122 static double GetAltitudeForEdge( const TopoDS_Edge& theEdge,
123 const gp_XY& thePoint,
124 double theParameterTolerance,
125 double theSquareDistanceTolerance,
126 double theInvalidAltitude );
127 static double GetAltitudeForWire( const TopoDS_Wire& theWire,
128 const gp_XY& thePoint,
129 double theParameterTolerance,
130 double theSquareDistanceTolerance,
131 double theInvalidAltitude );
134 * \brief Returns the first shape from the group.
135 * \param theGroups the list of groups
136 * \param theGroupId the group id
138 static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
139 const int theGroupId );
141 static TCollection_ExtendedString toExtString( const QString& );
142 static QString toQString( const TCollection_ExtendedString& );
144 static Quantity_Color toOccColor( const QColor& );
145 static QColor toQtColor( const Quantity_Color& );
147 static QColor GenerateRandColor();
148 static bool GenerateNonRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
149 static void GenerateRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
151 static bool IsNan( double theValue );
152 static bool IsInf( double theValue );
155 Rebuilds shape container (like compound/compsolid/shell) which contains faces (shared or nonshared with each other)
157 static TopoDS_Shape RebuildCmp(const TopoDS_Shape& in);
159 static TopoDS_Shape PolyXY2Face(const Handle(HYDROData_PolylineXY)& aPolyline);
161 static bool importFromXYZ( QString& theFileName, bool bImportXY, std::vector<gp_XYZ>& thePointsXYZ,
162 std::vector<gp_XY>& thePointsXY);
164 static bool importPolylineFromXYZ(QString aFilename, Handle(HYDROData_Document) theDocument,
165 bool importXY, NCollection_Sequence<Handle(HYDROData_Entity)>& importedEntities);
167 static Handle(Geom2d_Curve) BRepAdaptorTo2DCurve( const BRepAdaptor_Curve& ad );
169 static void SetSIProgress(const Handle(Message_ProgressIndicator)& thePI);
170 static const Message_ProgressRange& GetSIProgress();
172 static void SetZIProgress(const Handle(Message_ProgressIndicator)& thePI);
173 static const Message_ProgressRange& GetZIProgress();
175 static void SetTriangulationStatus(const ExecStatus& theStatus);
176 static const ExecStatus& GetTriangulationStatus();
179 static Message_ProgressRange& StricklerInterpolationProgress();
180 static Message_ProgressRange& BathymetryInterpolationProgress();
181 static ExecStatus myTriangulationStatus;
189 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
191 return theFirst > ( theSecond - Precision::Confusion() ) &&
192 theFirst < ( theSecond + Precision::Confusion() );
195 inline bool ValuesMoreEquals( const double& theFirst, const double& theSecond )
197 return theFirst >= theSecond || ValuesEquals( theFirst, theSecond );
200 inline bool ValuesLessEquals( const double& theFirst, const double& theSecond )
202 return theFirst <= theSecond || ValuesEquals( theFirst, theSecond );
205 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QString& theText );
206 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QColor& theText );
207 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape );
208 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace );
209 HYDRODATA_EXPORT bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 );
210 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY );