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 <TopoDS_Shape.hxx>
11 #include <TopTools_SequenceOfShape.hxx>
13 #include <TopExp_Explorer.hxx>
16 #include <QStringList>
17 #include <QTextStream>
19 void HYDROData_Tool::WriteStringsToFile( QFile& theFile,
20 const QStringList& theStrings,
21 const QString& theSep )
23 if ( !theFile.isOpen() || theStrings.isEmpty() )
26 QString aWriteStr = theStrings.join( theSep );
27 if ( aWriteStr.isEmpty() )
30 QTextStream anOutStream( &theFile );
31 anOutStream << aWriteStr << theSep << theSep;
34 void HYDROData_Tool::SetMustBeUpdatedObjects(
35 const Handle(HYDROData_Document)& theDoc )
37 bool anIsChanged = true;
39 // iterate until there is no changes because objects on all level of dependency must be updated
44 HYDROData_Iterator anIter( theDoc );
45 for ( ; anIter.More(); anIter.Next() )
47 Handle(HYDROData_Entity) anObject = anIter.Current();
48 if ( anObject.IsNull() || anObject->IsMustBeUpdated() )
51 HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
52 for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
54 Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
55 if ( aRefObject.IsNull() || !aRefObject->IsMustBeUpdated() )
58 anObject->SetToUpdate( true );
66 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
67 const QString& thePrefix,
68 const QStringList& theUsedNames,
69 const bool theIsTryToUsePurePrefix )
71 QStringList aNamesList( theUsedNames );
73 // Collect all used names in the document
74 HYDROData_Iterator anIter( theDoc );
75 for( ; anIter.More(); anIter.Next() )
77 Handle(HYDROData_Entity) anObject = anIter.Current();
78 if( anObject.IsNull() )
81 QString anObjName = anObject->GetName();
82 if ( anObjName.isEmpty() )
85 aNamesList.append( anObjName );
90 if ( theIsTryToUsePurePrefix && !aNamesList.contains( thePrefix ) ) {
96 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
98 // check that there are no other objects with the same name in the document
99 if ( !aNamesList.contains( aName ) )
107 Handle(HYDROData_Entity) HYDROData_Tool::FindObjectByName( const Handle(HYDROData_Document)& theDoc,
108 const QString& theName,
109 const ObjectKind theObjectKind )
111 Handle(HYDROData_Entity) anObject;
112 if ( theName.isEmpty() || theDoc.IsNull() )
115 QStringList aNamesList;
116 aNamesList << theName;
118 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theDoc, aNamesList, theObjectKind );
119 if( aSeqOfObjs.IsEmpty() )
122 anObject = aSeqOfObjs.First();
126 HYDROData_SequenceOfObjects HYDROData_Tool::FindObjectsByNames( const Handle(HYDROData_Document)& theDoc,
127 const QStringList& theNames,
128 const ObjectKind theObjectKind )
130 HYDROData_SequenceOfObjects aResSeq;
131 if( theDoc.IsNull() )
134 QStringList aNamesList = theNames;
136 HYDROData_Iterator anIter( theDoc, theObjectKind );
137 for( ; anIter.More(); anIter.Next() )
139 Handle(HYDROData_Entity) anObject = anIter.Current();
140 if( anObject.IsNull() )
143 QString anObjName = anObject->GetName();
144 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
147 aResSeq.Append( anObject );
149 aNamesList.removeAll( anObjName );
150 if ( aNamesList.isEmpty() )
157 bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject )
159 if ( theObject.IsNull() )
162 return theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) ||
163 theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) );
166 void HYDROData_Tool::UpdateChildObjectName( const QString& theOldStr,
167 const QString& theNewStr,
168 const Handle(HYDROData_Entity)& theObject )
170 if ( theObject.IsNull() )
173 QString anObjName = theObject->GetName();
174 if ( theOldStr.isEmpty() )
176 while ( anObjName.startsWith( '_' ) )
177 anObjName.remove( 0, 1 );
179 anObjName.prepend( theNewStr + "_" );
181 else if ( anObjName.startsWith( theOldStr ) )
183 anObjName.replace( 0, theOldStr.length(), theNewStr );
188 theObject->SetName( anObjName );