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>
13 void HYDROData_Tool::WriteStringsToFile( QFile& theFile,
14 const QStringList& theStrings,
15 const QString& theSep )
17 if ( !theFile.isOpen() || theStrings.isEmpty() )
20 QString aWriteStr = theStrings.join( theSep );
21 if ( aWriteStr.isEmpty() )
24 QTextStream anOutStream( &theFile );
25 anOutStream << aWriteStr << theSep << theSep;
28 void HYDROData_Tool::SetMustBeUpdatedObjects(
29 const Handle(HYDROData_Document)& theDoc )
31 bool anIsChanged = true;
33 // iterate until there is no changes because objects on all level of dependency must be updated
38 HYDROData_Iterator anIter( theDoc );
39 for ( ; anIter.More(); anIter.Next() )
41 Handle(HYDROData_Entity) anObject = anIter.Current();
42 if ( anObject.IsNull() || anObject->IsMustBeUpdated() )
45 HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
46 for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
48 Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
49 if ( aRefObject.IsNull() || !aRefObject->IsMustBeUpdated() )
52 anObject->SetToUpdate( true );
60 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
61 const QString& thePrefix,
62 const QStringList& theUsedNames,
63 const bool theIsTryToUsePurePrefix )
65 QStringList aNamesList( theUsedNames );
67 // Collect all used names in the document
68 HYDROData_Iterator anIter( theDoc );
69 for( ; anIter.More(); anIter.Next() )
71 Handle(HYDROData_Entity) anObject = anIter.Current();
72 if( anObject.IsNull() )
75 QString anObjName = anObject->GetName();
76 if ( anObjName.isEmpty() )
79 aNamesList.append( anObjName );
84 if ( theIsTryToUsePurePrefix && !aNamesList.contains( thePrefix ) ) {
90 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
92 // check that there are no other objects with the same name in the document
93 if ( !aNamesList.contains( aName ) )
101 Handle(HYDROData_Entity) HYDROData_Tool::FindObjectByName( const Handle(HYDROData_Document)& theDoc,
102 const QString& theName,
103 const ObjectKind theObjectKind )
105 Handle(HYDROData_Entity) anObject;
106 if ( theName.isEmpty() || theDoc.IsNull() )
109 QStringList aNamesList;
110 aNamesList << theName;
112 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theDoc, aNamesList, theObjectKind );
113 if( aSeqOfObjs.IsEmpty() )
116 anObject = aSeqOfObjs.First();
120 HYDROData_SequenceOfObjects HYDROData_Tool::FindObjectsByNames( const Handle(HYDROData_Document)& theDoc,
121 const QStringList& theNames,
122 const ObjectKind theObjectKind )
124 HYDROData_SequenceOfObjects aResSeq;
125 if( theDoc.IsNull() )
128 QStringList aNamesList = theNames;
130 HYDROData_Iterator anIter( theDoc, theObjectKind );
131 for( ; anIter.More(); anIter.Next() )
133 Handle(HYDROData_Entity) anObject = anIter.Current();
134 if( anObject.IsNull() )
137 QString anObjName = anObject->GetName();
138 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
141 aResSeq.Append( anObject );
143 aNamesList.removeAll( anObjName );
144 if ( aNamesList.isEmpty() )
151 bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject )
153 if ( theObject.IsNull() )
156 return theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) ||
157 theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) );