Salome HOME
Drawing of zones in OCC view improved.
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.cxx
1
2 #include "HYDROData_Tool.h"
3
4 #include "HYDROData_Image.h"
5 #include "HYDROData_Iterator.h"
6
7 #include <QFile>
8 #include <QStringList>
9 #include <QTextStream>
10
11 void HYDROData_Tool::WriteStringsToFile( QFile&             theFile,
12                                          const QStringList& theStrings,
13                                          const QString&     theSep )
14 {
15   if ( !theFile.isOpen() || theStrings.isEmpty() )
16     return;
17   
18   QString aWriteStr = theStrings.join( theSep );
19   if ( aWriteStr.isEmpty() )
20     return;
21
22   QTextStream anOutStream( &theFile );
23   anOutStream << aWriteStr << theSep << theSep;
24 }
25
26 void HYDROData_Tool::SetMustBeUpdatedImages(
27   Handle_HYDROData_Document theDoc)
28 {
29   bool aChanged = true;
30
31   // iterate until there is no changes because images on all level of dependency must be updated
32   while ( aChanged )
33   {
34     aChanged = false;
35
36     HYDROData_Iterator anIter( theDoc, KIND_IMAGE );
37     for ( ; anIter.More(); anIter.Next() )
38     {
39       Handle(HYDROData_Image) anImage = 
40         Handle(HYDROData_Image)::DownCast( anIter.Current() );
41       if ( anImage.IsNull() || anImage->MustBeUpdated() )
42         continue;
43
44       for ( int i = 0, aNBRefs = anImage->NbReferences(); i < aNBRefs; ++i )
45       {
46         Handle(HYDROData_Image) aRefImage =
47           Handle(HYDROData_Image)::DownCast( anImage->Reference( i ) );
48         if ( !aRefImage.IsNull() && aRefImage->MustBeUpdated() )
49         {
50            // image references to updated => also must be updated
51            anImage->MustBeUpdated(true);
52            aChanged = true;
53         }
54       }
55     }
56   }
57 }