2 #include "HYDROData_Tool.h"
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_Image.h"
6 #include "HYDROData_Iterator.h"
7 #include "HYDROData_NaturalObject.h"
10 #include <QStringList>
11 #include <QTextStream>
17 #include <TopAbs_State.hxx>
18 #include <BRepAdaptor_Surface.hxx>
19 #include <BRepTopAdaptor_FClass2d.hxx>
20 #include <BRep_Tool.hxx>
22 static int aMaxNameId = std::numeric_limits<int>::max();
24 void HYDROData_Tool::WriteStringsToFile( QFile& theFile,
25 const QStringList& theStrings,
26 const QString& theSep )
28 if ( !theFile.isOpen() || theStrings.isEmpty() )
31 QString aWriteStr = theStrings.join( theSep );
32 if ( aWriteStr.isEmpty() )
35 QTextStream anOutStream( &theFile );
36 anOutStream << aWriteStr << theSep << theSep;
39 void HYDROData_Tool::SetMustBeUpdatedObjects(
40 const Handle(HYDROData_Document)& theDoc )
42 bool anIsChanged = true;
44 // iterate until there is no changes because objects on all level of dependency must be updated
49 HYDROData_Iterator anIter( theDoc );
50 for ( ; anIter.More(); anIter.Next() )
52 Handle(HYDROData_Entity) anObject = anIter.Current();
53 if ( anObject.IsNull() || anObject->IsMustBeUpdated() )
56 HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
57 for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
59 Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
60 if ( aRefObject.IsNull() || !aRefObject->IsMustBeUpdated() )
63 anObject->SetToUpdate( true );
71 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
72 const QString& thePrefix,
73 const QStringList& theUsedNames,
74 const bool theIsTryToUsePurePrefix )
76 QStringList aNamesList( theUsedNames );
78 // Collect all used names in the document
79 HYDROData_Iterator anIter( theDoc );
80 for( ; anIter.More(); anIter.Next() )
82 Handle(HYDROData_Entity) anObject = anIter.Current();
83 if( anObject.IsNull() )
86 QString anObjName = anObject->GetName();
87 if ( anObjName.isEmpty() )
90 aNamesList.append( anObjName );
95 if ( theIsTryToUsePurePrefix && !aNamesList.contains( thePrefix ) ) {
99 while( anId < aMaxNameId )
101 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
103 // check that there are no other objects with the same name in the document
104 if ( !aNamesList.contains( aName ) )
112 bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject )
114 if ( theObject.IsNull() )
117 return theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) ||
118 theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) );
121 void HYDROData_Tool::UpdateChildObjectName( const QString& theOldStr,
122 const QString& theNewStr,
123 const Handle(HYDROData_Entity)& theObject )
125 if ( theObject.IsNull() )
128 QString anObjName = theObject->GetName();
129 if ( theOldStr.isEmpty() )
131 while ( anObjName.startsWith( '_' ) )
132 anObjName.remove( 0, 1 );
134 anObjName.prepend( theNewStr + "_" );
136 else if ( anObjName.startsWith( theOldStr ) )
138 anObjName.replace( 0, theOldStr.length(), theNewStr );
143 theObject->SetName( anObjName );
146 QString HYDROData_Tool::GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
147 const QString& thePrefix )
149 QString aName = thePrefix;
150 if ( !theTreatedObjects.contains( aName ) )
154 while( anId < aMaxNameId )
156 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
158 // check that there are no other objects with the same name
159 if ( !theTreatedObjects.contains( aName ) )
165 //======================================================================================================
166 TopAbs_State HYDROData_Tool::ComputePointState( const gp_XY& theXY, const TopoDS_Face& theFace )
168 TopAbs_State aState(TopAbs_UNKNOWN);
169 if(theFace.IsNull()) return aState;
170 Standard_Real aTol = BRep_Tool::Tolerance(theFace);
171 BRepAdaptor_Surface Ads ( theFace, Standard_False );
172 Standard_Real toluv = Min ( Ads.UResolution(aTol), Ads.VResolution(aTol) );
173 const gp_Pln& aPlane = Ads.Surface().Plane();
174 gp_Pnt aPnt(theXY.X(), theXY.Y(), 0.);
175 Standard_Real aU1, aV1;
176 ElSLib::Parameters(aPlane,aPnt, aU1, aV1);
177 BRepTopAdaptor_FClass2d aClassifier( theFace, toluv );
178 aState = aClassifier.Perform( gp_Pnt2d(aU1, aV1), Standard_False );