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 <Geom2d_Curve.hxx>
30 #include <Geom_Curve.hxx>
31 #include <BRepAdaptor_Curve.hxx>
34 class HYDROData_PolylineXY;
35 class HYDROData_Document;
36 class HYDROData_Entity;
37 class HYDROData_SequenceOfObjects;
38 class MapOfTreatedObjects;
42 class TCollection_ExtendedString;
47 #include <TopAbs_State.hxx>
56 class HYDRODATA_EXPORT HYDROData_Tool {
68 static void WriteStringsToFile( QFile& theFile,
69 const QStringList& theStrings,
70 const QString& theSep = "\n" );
73 * \brief Generate name for new object.
74 * \param theDoc document
75 * \param thePrefix name prefix
76 * \param theUsedNames list of already used names
77 * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
78 * \return generated name
80 static QString GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
81 const QString& thePrefix,
82 const QStringList& theUsedNames = QStringList(),
83 const bool theIsTryToUsePurePrefix = false );
86 static bool ExtractGeneratedObjectName(const QString& theName, int& outValue, QString& thePrefName);
89 * \brief Checks the type of object.
90 * \param theObject object to check
91 * \return true if object is geometry object
93 static bool IsGeometryObject( const Handle(HYDROData_Entity)& theObject );
96 * \brief Updates the child object name.
97 * \param theOldStr old father object name
98 * \param theNewStr new father object name
99 * \param theObject object to update
101 static void UpdateChildObjectName( const QString& theOldStr,
102 const QString& theNewStr,
103 const Handle(HYDROData_Entity)& theObject );
107 * \brief Generate name for new object in python environment.
108 * \param theTreatedObjects objects which was alredy created by dump operation
109 * \param thePrefix name prefix
110 * \return generated name
112 static QString GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
113 const QString& thePrefix );
115 * Computes Point State from TopAbs (simplified & limited method).
118 static TopAbs_State ComputePointState( const gp_XY& thePnt2d,
119 const TopoDS_Face& theFace );
121 static double GetAltitudeForEdge( const TopoDS_Edge& theEdge,
122 const gp_XY& thePoint,
123 double theParameterTolerance,
124 double theSquareDistanceTolerance,
125 double theInvalidAltitude );
126 static double GetAltitudeForWire( const TopoDS_Wire& theWire,
127 const gp_XY& thePoint,
128 double theParameterTolerance,
129 double theSquareDistanceTolerance,
130 double theInvalidAltitude );
133 * \brief Returns the first shape from the group.
134 * \param theGroups the list of groups
135 * \param theGroupId the group id
137 static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
138 const int theGroupId );
140 static TCollection_ExtendedString toExtString( const QString& );
141 static QString toQString( const TCollection_ExtendedString& );
143 static Quantity_Color toOccColor( const QColor& );
144 static QColor toQtColor( const Quantity_Color& );
146 static QColor GenerateRandColor();
147 static bool GenerateNonRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
148 static void GenerateRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
150 static bool IsNan( double theValue );
151 static bool IsInf( double theValue );
154 Rebuilds shape container (like compound/compsolid/shell) which contains faces (shared or nonshared with each other)
156 static TopoDS_Shape RebuildCmp(const TopoDS_Shape& in);
158 static TopoDS_Shape PolyXY2Face(const Handle(HYDROData_PolylineXY)& aPolyline);
160 static bool importFromXYZ( QString& theFileName, bool bImportXY, std::vector<gp_XYZ>& thePointsXYZ,
161 std::vector<gp_XY>& thePointsXY);
163 static bool importPolylineFromXYZ(QString aFilename, Handle(HYDROData_Document) theDocument,
164 bool importXY, NCollection_Sequence<Handle(HYDROData_Entity)>& importedEntities);
166 static Handle(Geom2d_Curve) BRepAdaptorTo2DCurve( const BRepAdaptor_Curve& ad );
168 static void SetSIProgress(const Handle(Message_ProgressIndicator)& thePI);
169 static const Handle(Message_ProgressIndicator)& GetSIProgress();
171 static void SetZIProgress(const Handle(Message_ProgressIndicator)& thePI);
172 static const Handle(Message_ProgressIndicator)& GetZIProgress();
174 static void SetTriangulationStatus(const ExecStatus& theStatus);
175 static const ExecStatus& GetTriangulationStatus();
178 static Handle(Message_ProgressIndicator)& StricklerInterpolationProgress();
179 static Handle(Message_ProgressIndicator)& BathymetryInterpolationProgress();
180 static ExecStatus myTriangulationStatus;
188 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
190 return theFirst > ( theSecond - Precision::Confusion() ) &&
191 theFirst < ( theSecond + Precision::Confusion() );
194 inline bool ValuesMoreEquals( const double& theFirst, const double& theSecond )
196 return theFirst >= theSecond || ValuesEquals( theFirst, theSecond );
199 inline bool ValuesLessEquals( const double& theFirst, const double& theSecond )
201 return theFirst <= theSecond || ValuesEquals( theFirst, theSecond );
204 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QString& theText );
205 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QColor& theText );
206 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape );
207 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace );
208 HYDRODATA_EXPORT bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 );
209 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY );