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 )
73 QStringList aNamesList( theUsedNames );
75 // Collect all used names in the document
76 HYDROData_Iterator anIter( theDoc );
77 for( ; anIter.More(); anIter.Next() )
79 Handle(HYDROData_Entity) anObject = anIter.Current();
80 if( anObject.IsNull() )
83 QString anObjName = anObject->GetName();
84 if ( anObjName.isEmpty() )
87 aNamesList.append( anObjName );
95 aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
97 // check that there are no other objects with the same name in the document
98 if ( !aNamesList.contains( aName ) )
105 Handle(HYDROData_Entity) HYDROData_Tool::FindObjectByName( const Handle(HYDROData_Document)& theDoc,
106 const QString& theName,
107 const ObjectKind theObjectKind )
109 Handle(HYDROData_Entity) anObject;
110 if ( theName.isEmpty() || theDoc.IsNull() )
113 QStringList aNamesList;
114 aNamesList << theName;
116 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theDoc, aNamesList, theObjectKind );
117 if( aSeqOfObjs.IsEmpty() )
120 anObject = aSeqOfObjs.First();
124 HYDROData_SequenceOfObjects HYDROData_Tool::FindObjectsByNames( const Handle(HYDROData_Document)& theDoc,
125 const QStringList& theNames,
126 const ObjectKind theObjectKind )
128 HYDROData_SequenceOfObjects aResSeq;
129 if( theDoc.IsNull() )
132 QStringList aNamesList = theNames;
134 HYDROData_Iterator anIter( theDoc, theObjectKind );
135 for( ; anIter.More(); anIter.Next() )
137 Handle(HYDROData_Entity) anObject = anIter.Current();
138 if( anObject.IsNull() )
141 QString anObjName = anObject->GetName();
142 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
145 aResSeq.Append( anObject );
147 aNamesList.removeAll( anObjName );
148 if ( aNamesList.isEmpty() )
155 bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject )
157 if ( theObject.IsNull() )
160 return theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) ||
161 theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) );