2 #include "HYDROData_Tool.h"
4 #include "HYDROData_Image.h"
5 #include "HYDROData_Iterator.h"
11 void HYDROData_Tool::WriteStringsToFile( QFile& theFile,
12 const QStringList& theStrings,
13 const QString& theSep )
15 if ( !theFile.isOpen() || theStrings.isEmpty() )
18 QString aWriteStr = theStrings.join( theSep );
19 if ( aWriteStr.isEmpty() )
22 QTextStream anOutStream( &theFile );
23 anOutStream << aWriteStr << theSep << theSep;
26 void HYDROData_Tool::SetMustBeUpdatedImages(
27 const Handle(HYDROData_Document)& theDoc )
31 // iterate until there is no changes because images on all level of dependency must be updated
36 HYDROData_Iterator anIter( theDoc, KIND_IMAGE );
37 for ( ; anIter.More(); anIter.Next() )
39 Handle(HYDROData_Image) anImage =
40 Handle(HYDROData_Image)::DownCast( anIter.Current() );
41 if ( anImage.IsNull() || anImage->MustBeUpdated() )
44 for ( int i = 0, aNBRefs = anImage->NbReferences(); i < aNBRefs; ++i )
46 Handle(HYDROData_Image) aRefImage =
47 Handle(HYDROData_Image)::DownCast( anImage->Reference( i ) );
48 if ( !aRefImage.IsNull() && aRefImage->MustBeUpdated() )
50 // image references to updated => also must be updated
51 anImage->MustBeUpdated(true);
59 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
60 const QString& thePrefix,
61 const QStringList& theUsedNames )
63 QStringList aNamesList( theUsedNames );
65 // Collect all used names in the document
66 HYDROData_Iterator anIter( theDoc );
67 for( ; anIter.More(); anIter.Next() )
69 Handle(HYDROData_Entity) anObject = anIter.Current();
70 if( anObject.IsNull() )
73 QString anObjName = anObject->GetName();
74 if ( anObjName.isEmpty() )
77 aNamesList.append( anObjName );
85 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
87 // check that there are no other objects with the same name in the document
88 if ( !aNamesList.contains( aName ) )
95 Handle(HYDROData_Entity) HYDROData_Tool::FindObjectByName( const Handle(HYDROData_Document)& theDoc,
96 const QString& theName,
97 const ObjectKind theObjectKind )
99 Handle(HYDROData_Entity) anObject;
100 if ( theName.isEmpty() || theDoc.IsNull() )
103 QStringList aNamesList;
104 aNamesList << theName;
106 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theDoc, aNamesList, theObjectKind );
107 if( aSeqOfObjs.IsEmpty() )
110 anObject = aSeqOfObjs.First();
114 HYDROData_SequenceOfObjects HYDROData_Tool::FindObjectsByNames( const Handle(HYDROData_Document)& theDoc,
115 const QStringList& theNames,
116 const ObjectKind theObjectKind )
118 HYDROData_SequenceOfObjects aResSeq;
119 if( theDoc.IsNull() )
122 QStringList aNamesList = theNames;
124 HYDROData_Iterator anIter( theDoc, theObjectKind );
125 for( ; anIter.More(); anIter.Next() )
127 Handle(HYDROData_Entity) anObject = anIter.Current();
128 if( anObject.IsNull() )
131 QString anObjName = anObject->GetName();
132 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
135 aResSeq.Append( anObject );
137 aNamesList.removeAll( anObjName );
138 if ( aNamesList.isEmpty() )