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"
9 #include <TopTools_SequenceOfShape.hxx>
10 #include <TopExp_Explorer.hxx>
13 #include <QStringList>
14 #include <QTextStream>
21 #include <Geom_Plane.hxx>
22 #include <BRep_Tool.hxx>
23 #include <BRepBuilderAPI_FindPlane.hxx>
25 #include <TopoDS_Vertex.hxx>
26 #include <TopoDS_Wire.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <TopoDS_Iterator.hxx>
29 #include <TopTools_MapOfShape.hxx>
30 #include <TColgp_SequenceOfVec.hxx>
31 #include <TopTools_ShapeMapHasher.hxx>
33 #include <BRepAdaptor_Surface.hxx>
34 #include <BRepTopAdaptor_FClass2d.hxx>
35 #include <BRep_Tool.hxx>
36 #include <TopAbs_State.hxx>
37 static int aMaxNameId = std::numeric_limits<int>::max();
39 void HYDROData_Tool::WriteStringsToFile( QFile& theFile,
40 const QStringList& theStrings,
41 const QString& theSep )
43 if ( !theFile.isOpen() || theStrings.isEmpty() )
46 QString aWriteStr = theStrings.join( theSep );
47 if ( aWriteStr.isEmpty() )
50 QTextStream anOutStream( &theFile );
51 anOutStream << aWriteStr << theSep << theSep;
54 void HYDROData_Tool::SetMustBeUpdatedObjects(
55 const Handle(HYDROData_Document)& theDoc )
57 bool anIsChanged = true;
59 // iterate until there is no changes because objects on all level of dependency must be updated
64 HYDROData_Iterator anIter( theDoc );
65 for ( ; anIter.More(); anIter.Next() )
67 Handle(HYDROData_Entity) anObject = anIter.Current();
68 if ( anObject.IsNull() || anObject->IsMustBeUpdated() )
71 HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
72 for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
74 Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
75 if ( aRefObject.IsNull() || !aRefObject->IsMustBeUpdated() )
78 anObject->SetToUpdate( true );
86 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
87 const QString& thePrefix,
88 const QStringList& theUsedNames,
89 const bool theIsTryToUsePurePrefix )
91 QStringList aNamesList( theUsedNames );
93 // Collect all used names in the document
94 HYDROData_Iterator anIter( theDoc );
95 for( ; anIter.More(); anIter.Next() )
97 Handle(HYDROData_Entity) anObject = anIter.Current();
98 if( anObject.IsNull() )
101 QString anObjName = anObject->GetName();
102 if ( anObjName.isEmpty() )
105 aNamesList.append( anObjName );
110 if ( theIsTryToUsePurePrefix && !aNamesList.contains( thePrefix ) ) {
114 while( anId < aMaxNameId )
116 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
118 // check that there are no other objects with the same name in the document
119 if ( !aNamesList.contains( aName ) )
127 bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject )
129 if ( theObject.IsNull() )
132 return theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) ||
133 theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) );
136 void HYDROData_Tool::UpdateChildObjectName( const QString& theOldStr,
137 const QString& theNewStr,
138 const Handle(HYDROData_Entity)& theObject )
140 if ( theObject.IsNull() )
143 QString anObjName = theObject->GetName();
144 if ( theOldStr.isEmpty() )
146 while ( anObjName.startsWith( '_' ) )
147 anObjName.remove( 0, 1 );
149 anObjName.prepend( theNewStr + "_" );
151 else if ( anObjName.startsWith( theOldStr ) )
153 anObjName.replace( 0, theOldStr.length(), theNewStr );
158 theObject->SetName( anObjName );
161 QString HYDROData_Tool::GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
162 const QString& thePrefix )
164 QString aName = thePrefix;
165 if ( !theTreatedObjects.contains( aName ) )
169 while( anId < aMaxNameId )
171 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
173 // check that there are no other objects with the same name
174 if ( !theTreatedObjects.contains( aName ) )
180 //======================================================================================================
181 TopAbs_State HYDROData_Tool::ComputePointState( const gp_XY& theXY, const TopoDS_Face& theFace )
183 TopAbs_State aState(TopAbs_UNKNOWN);
184 if(theFace.IsNull()) return aState;
185 Standard_Real aTol = BRep_Tool::Tolerance(theFace);
186 BRepAdaptor_Surface Ads ( theFace, Standard_False );
187 Standard_Real toluv = Min ( Ads.UResolution(aTol), Ads.VResolution(aTol) );
188 const gp_Pln& aPlane = Ads.Surface().Plane();
189 gp_Pnt aPnt(theXY.X(), theXY.Y(), 0.);
190 Standard_Real aU1, aV1;
191 ElSLib::Parameters(aPlane,aPnt, aU1, aV1);
192 BRepTopAdaptor_FClass2d aClassifier( theFace, toluv );
193 aState = aClassifier.Perform( gp_Pnt2d(aU1, aV1), Standard_False );