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::SetMustBeUpdatedImages(
29 const Handle(HYDROData_Document)& theDoc )
31 bool anIsChanged = true;
33 // iterate until there is no changes because images on all level of dependency must be updated
38 HYDROData_Iterator anIter( theDoc, KIND_IMAGE );
39 for ( ; anIter.More(); anIter.Next() )
41 Handle(HYDROData_Image) anImage =
42 Handle(HYDROData_Image)::DownCast( anIter.Current() );
43 if ( anImage.IsNull() || anImage->IsMustBeUpdated() )
46 Handle(HYDROData_Image) aTrsfRefImage = anImage->GetTrsfReferenceImage();
47 if ( !aTrsfRefImage.IsNull() && aTrsfRefImage->IsMustBeUpdated() )
49 anImage->SetToUpdate( true );
54 for ( int i = 0, aNBRefs = anImage->NbReferences(); i < aNBRefs; ++i )
56 Handle(HYDROData_Image) aRefImage =
57 Handle(HYDROData_Image)::DownCast( anImage->Reference( i ) );
58 if ( !aRefImage.IsNull() && aRefImage->IsMustBeUpdated() )
60 // image references to updated => also must be updated
61 anImage->SetToUpdate( true );
69 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
70 const QString& thePrefix,
71 const QStringList& theUsedNames,
72 const bool theIsTryToUsePurePrefix )
74 QStringList aNamesList( theUsedNames );
76 // Collect all used names in the document
77 HYDROData_Iterator anIter( theDoc );
78 for( ; anIter.More(); anIter.Next() )
80 Handle(HYDROData_Entity) anObject = anIter.Current();
81 if( anObject.IsNull() )
84 QString anObjName = anObject->GetName();
85 if ( anObjName.isEmpty() )
88 aNamesList.append( anObjName );
93 if ( theIsTryToUsePurePrefix && !aNamesList.contains( thePrefix ) ) {
99 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
101 // check that there are no other objects with the same name in the document
102 if ( !aNamesList.contains( aName ) )
110 Handle(HYDROData_Entity) HYDROData_Tool::FindObjectByName( const Handle(HYDROData_Document)& theDoc,
111 const QString& theName,
112 const ObjectKind theObjectKind )
114 Handle(HYDROData_Entity) anObject;
115 if ( theName.isEmpty() || theDoc.IsNull() )
118 QStringList aNamesList;
119 aNamesList << theName;
121 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theDoc, aNamesList, theObjectKind );
122 if( aSeqOfObjs.IsEmpty() )
125 anObject = aSeqOfObjs.First();
129 HYDROData_SequenceOfObjects HYDROData_Tool::FindObjectsByNames( const Handle(HYDROData_Document)& theDoc,
130 const QStringList& theNames,
131 const ObjectKind theObjectKind )
133 HYDROData_SequenceOfObjects aResSeq;
134 if( theDoc.IsNull() )
137 QStringList aNamesList = theNames;
139 HYDROData_Iterator anIter( theDoc, theObjectKind );
140 for( ; anIter.More(); anIter.Next() )
142 Handle(HYDROData_Entity) anObject = anIter.Current();
143 if( anObject.IsNull() )
146 QString anObjName = anObject->GetName();
147 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
150 aResSeq.Append( anObject );
152 aNamesList.removeAll( anObjName );
153 if ( aNamesList.isEmpty() )
160 bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject )
162 if ( theObject.IsNull() )
165 return theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) ||
166 theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) );