Salome HOME
Sorting alphabetically.
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.cxx
index 0cd144270fe620e29b9936ee0a4cc679cce5f4f8..58511d16cea71b587a10df916512f4b35cc7e28b 100644 (file)
@@ -1,6 +1,9 @@
 
 #include "HYDROData_Tool.h"
 
+#include "HYDROData_Image.h"
+#include "HYDROData_Iterator.h"
+
 #include <QFile>
 #include <QStringList>
 #include <QTextStream>
@@ -17,5 +20,38 @@ void HYDROData_Tool::WriteStringsToFile( QFile&             theFile,
     return;
 
   QTextStream anOutStream( &theFile );
-  anOutStream << aWriteStr << theSep;
+  anOutStream << aWriteStr << theSep << theSep;
+}
+
+void HYDROData_Tool::SetMustBeUpdatedImages(
+  Handle_HYDROData_Document theDoc)
+{
+  bool aChanged = true;
+
+  // iterate until there is no changes because images on all level of dependency must be updated
+  while ( aChanged )
+  {
+    aChanged = false;
+
+    HYDROData_Iterator anIter( theDoc, KIND_IMAGE );
+    for ( ; anIter.More(); anIter.Next() )
+    {
+      Handle(HYDROData_Image) anImage = 
+        Handle(HYDROData_Image)::DownCast( anIter.Current() );
+      if ( anImage.IsNull() || anImage->MustBeUpdated() )
+        continue;
+
+      for ( int i = 0, aNBRefs = anImage->NbReferences(); i < aNBRefs; ++i )
+      {
+        Handle(HYDROData_Image) aRefImage =
+          Handle(HYDROData_Image)::DownCast( anImage->Reference( i ) );
+        if ( !aRefImage.IsNull() && aRefImage->MustBeUpdated() )
+        {
+           // image references to updated => also must be updated
+           anImage->MustBeUpdated(true);
+           aChanged = true;
+        }
+      }
+    }
+  }
 }