Salome HOME
Python console has been added for HYDRO module (Bug #22).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.cxx
index 798cf88ed181a2ca635233e75e260fc7e699509d..d1fff0327b08f53aa0fa5cc948799ac3712acd6c 100644 (file)
@@ -27,6 +27,7 @@
 #include "HYDROGUI_Tool.h"
 
 #include <HYDROData_Bathymetry.h>
+#include <HYDROData_Calculation.h>
 #include <HYDROData_Document.h>
 #include <HYDROData_Image.h>
 #include <HYDROData_Iterator.h>
@@ -53,6 +54,9 @@
 #include <TDF_Delta.hxx>
 #include <TDF_ListIteratorOfDeltaList.hxx>
 
+#include <QApplication>
+#include <QDir>
+
 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
 : LightApp_DataModel( theModule )
 {
@@ -148,6 +152,33 @@ bool HYDROGUI_DataModel::close()
   return true;
 }
 
+bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
+                                     CAM_Study*     theStudy,
+                                     bool           isMultiFile,
+                                     QStringList&   theListOfFiles )
+{
+  LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
+
+  int aStudyId = theStudy->id();
+
+  LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
+  if ( aDocument.IsNull() || !aStudy )
+    return false;
+
+  QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
+  aFileToExport += QString( QDir::separator() ) + "HYDRO.py";
+
+  bool aRes = aDocument->DumpToPython( aFileToExport );
+
+  if ( aRes )
+  {
+    theListOfFiles.append( aFileToExport );
+  }
+
+  return aRes;
+}
+
 bool HYDROGUI_DataModel::isModified() const
 {
   return getDocument()->IsModified();
@@ -199,9 +230,9 @@ void HYDROGUI_DataModel::update( const int theStudyId )
       {
         for( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
         {
-          Handle(HYDROData_Image) aRefImageObj = anImageObj->Reference( anIndex );
-          if( !aRefImageObj.IsNull() && !aRefImageObj->IsRemoved() )
-            createObject( anImageDataObj, aRefImageObj, anImageDataObj->entry() );
+          Handle(HYDROData_Object) aRefObj = anImageObj->Reference( anIndex );
+          if( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
+            createObject( anImageDataObj, aRefObj, anImageDataObj->entry() );
         }
       }
     }
@@ -218,6 +249,17 @@ void HYDROGUI_DataModel::update( const int theStudyId )
       createObject( aBathymetryRootObj, aBathymetryObj );
   }
 
+  LightApp_DataObject* aCalculRootObj = createObject( aRootObj, "CALCULATION CASES" );
+
+  anIterator = HYDROData_Iterator( aDocument, KIND_CALCULATION );
+  for( ; anIterator.More(); anIterator.Next() )
+  {
+    Handle(HYDROData_Calculation) aCalculObj =
+      Handle(HYDROData_Calculation)::DownCast( anIterator.Current() );
+    if( !aCalculObj.IsNull() )
+      createObject( aCalculRootObj, aCalculObj );
+  }
+
   LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, "POLYLINES" );
 
   anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE );