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 class Handle_HYDROData_Document;
27 class Handle_HYDROData_Entity;
28 class HYDROData_SequenceOfObjects;
29 class MapOfTreatedObjects;
33 class TCollection_ExtendedString;
37 #include <TopAbs_State.hxx>
43 class TopTools_SequenceOfShape;
45 class HYDRODATA_EXPORT HYDROData_Tool {
49 static void WriteStringsToFile( QFile& theFile,
50 const QStringList& theStrings,
51 const QString& theSep = "\n" );
54 * Enables "MustBeUpdated" flag for objects that are depended on "MustBeUpdated" objects.
55 * \param theDoc document where this operation is performed
57 static void SetMustBeUpdatedObjects( const Handle_HYDROData_Document& theDoc );
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 * \brief Checks the type of object.
74 * \param theObject object to check
75 * \return true if object is geometry object
77 static bool IsGeometryObject( const Handle_HYDROData_Entity& theObject );
80 * \brief Updates the child object name.
81 * \param theOldStr old father object name
82 * \param theNewStr new father object name
83 * \param theObject object to update
85 static void UpdateChildObjectName( const QString& theOldStr,
86 const QString& theNewStr,
87 const Handle_HYDROData_Entity& theObject );
91 * \brief Generate name for new object in python environment.
92 * \param theTreatedObjects objects which was alredy created by dump operation
93 * \param thePrefix name prefix
94 * \return generated name
96 static QString GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
97 const QString& thePrefix );
99 * Computes Point State from TopAbs (simplified & limited method).
102 static TopAbs_State ComputePointState( const gp_XY& thePnt2d,
103 const TopoDS_Face& theFace );
105 static double GetAltitudeForEdge( const TopoDS_Edge& theEdge,
106 const gp_XY& thePoint,
107 double theParameterTolerance,
108 double theSquareDistanceTolerance,
109 double theInvalidAltitude );
110 static double GetAltitudeForWire( const TopoDS_Wire& theWire,
111 const gp_XY& thePoint,
112 double theParameterTolerance,
113 double theSquareDistanceTolerance,
114 double theInvalidAltitude );
117 * \brief Returns the first shape from the group.
118 * \param theGroups the list of groups
119 * \param theGroupId the group id
121 static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
122 const int theGroupId );
124 static TCollection_ExtendedString toExtString( const QString& );
125 static QString toQString( const TCollection_ExtendedString& );
128 inline bool ValuesEquals( const double& theFirst, const double& theSecond )
130 return theFirst > ( theSecond - Precision::Confusion() ) &&
131 theFirst < ( theSecond + Precision::Confusion() );
134 inline bool ValuesMoreEquals( const double& theFirst, const double& theSecond )
136 return theFirst >= theSecond || ValuesEquals( theFirst, theSecond );
139 inline bool ValuesLessEquals( const double& theFirst, const double& theSecond )
141 return theFirst <= theSecond || ValuesEquals( theFirst, theSecond );
144 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QString& theText );
145 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QColor& theText );
146 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape );
147 HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace );