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 Handle(HYDROData_Image) aTrsfRefImage = anImage->GetTrsfReferenceImage();
45 if ( !aTrsfRefImage.IsNull() && aTrsfRefImage->MustBeUpdated() )
47 anImage->MustBeUpdated( true );
52 for ( int i = 0, aNBRefs = anImage->NbReferences(); i < aNBRefs; ++i )
54 Handle(HYDROData_Image) aRefImage =
55 Handle(HYDROData_Image)::DownCast( anImage->Reference( i ) );
56 if ( !aRefImage.IsNull() && aRefImage->MustBeUpdated() )
58 // image references to updated => also must be updated
59 anImage->MustBeUpdated(true);
67 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
68 const QString& thePrefix,
69 const QStringList& theUsedNames )
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 );
93 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
95 // check that there are no other objects with the same name in the document
96 if ( !aNamesList.contains( aName ) )
103 Handle(HYDROData_Entity) HYDROData_Tool::FindObjectByName( const Handle(HYDROData_Document)& theDoc,
104 const QString& theName,
105 const ObjectKind theObjectKind )
107 Handle(HYDROData_Entity) anObject;
108 if ( theName.isEmpty() || theDoc.IsNull() )
111 QStringList aNamesList;
112 aNamesList << theName;
114 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theDoc, aNamesList, theObjectKind );
115 if( aSeqOfObjs.IsEmpty() )
118 anObject = aSeqOfObjs.First();
122 HYDROData_SequenceOfObjects HYDROData_Tool::FindObjectsByNames( const Handle(HYDROData_Document)& theDoc,
123 const QStringList& theNames,
124 const ObjectKind theObjectKind )
126 HYDROData_SequenceOfObjects aResSeq;
127 if( theDoc.IsNull() )
130 QStringList aNamesList = theNames;
132 HYDROData_Iterator anIter( theDoc, theObjectKind );
133 for( ; anIter.More(); anIter.Next() )
135 Handle(HYDROData_Entity) anObject = anIter.Current();
136 if( anObject.IsNull() )
139 QString anObjName = anObject->GetName();
140 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
143 aResSeq.Append( anObject );
145 aNamesList.removeAll( anObjName );
146 if ( aNamesList.isEmpty() )