Salome HOME
HYDRO Feature 1: Import images (T 1.3)
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.cxx
index a2fda47afe05083a4568d9cdab44b80cc8d9456c..1c8368ffaf5d37f99c03aeb4cd531f6065a0d6b2 100644 (file)
 
 #include "HYDROGUI_DataModel.h"
 
-#include "HYDROGUI_Module.h"
 #include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_Tool.h"
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Image.h>
 #include <HYDROData_Iterator.h>
+#include <HYDROData_Polyline.h>
+#include <HYDROData_VisualState.h>
+#include <HYDROData_Bathymetry.h>
 
 #include <CAM_Application.h>
 #include <CAM_DataObject.h>
@@ -46,6 +50,9 @@
 
 #include <HYDROData_Document.h>
 
+#include <TDF_Delta.hxx>
+#include <TDF_ListIteratorOfDeltaList.hxx>
+
 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
 : LightApp_DataModel( theModule )
 {
@@ -63,7 +70,7 @@ bool HYDROGUI_DataModel::open( const QString& theURL,
   LightApp_DataModel::open( theURL, theStudy, theFileList );
   const int aStudyId = theStudy->id();
 
-  bool res = false;
+  Data_DocError res = DocError_UnknownProblem;
   if( theFileList.count() == 2 )
   {
     QString aTmpDir = theFileList[0];
@@ -78,9 +85,9 @@ bool HYDROGUI_DataModel::open( const QString& theURL,
     }
     catch(...)
     {
-      res = false;
+      res = DocError_UnknownProblem;
     }
-    if (!res)
+    if( res != DocError_OK )
     {
       module()->application()->putInfo( tr( "LOAD_ERROR" ) );
       return false;
@@ -89,7 +96,7 @@ bool HYDROGUI_DataModel::open( const QString& theURL,
 
   // if the document open was successful, the data model update happens
   // in the set mode of the module
-  if( !res )
+  if( res == DocError_OK )
     update( aStudyId );
 
   return true;
@@ -100,8 +107,6 @@ bool HYDROGUI_DataModel::save( QStringList& theFileList )
   if( !module()->application()->activeStudy() )
     return false;
   
-  const int aStudyId = module()->application()->activeStudy()->id();
-
   LightApp_DataModel::save( theFileList );
 
   QString aTmpDir;
@@ -114,11 +119,11 @@ bool HYDROGUI_DataModel::save( QStringList& theFileList )
   // save data to temporary files
   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
   aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
-  aFileName = SUIT_Tools::file (myStudyURL, false ) + "_HYDRO.cbf";
+  aFileName = SUIT_Tools::filemyStudyURL, false ) + "_HYDRO.cbf";
 
   QString aFullPath = aTmpDir + aFileName;
-  bool res = HYDROData_Document::Document( aStudyId )->Save( (char*)aFullPath.toLatin1().constData() );
-  if( !res )
+  Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() );
+  if( res != DocError_OK )
   {
     module()->application()->putInfo( tr( "SAVE_ERROR" ) );
     return false;
@@ -145,8 +150,7 @@ bool HYDROGUI_DataModel::close()
 
 bool HYDROGUI_DataModel::isModified() const
 {
-  int aStudyId = module()->application()->activeStudy()->id();
-  return HYDROData_Document::Document( aStudyId )->IsModified();
+  return getDocument()->IsModified();
 }
 
 bool HYDROGUI_DataModel::isSaved() const
@@ -164,9 +168,6 @@ void HYDROGUI_DataModel::update( const int theStudyId )
   if( !aStudyRoot )
     return;
 
-  if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
-    anObjectBrowser->setAutoOpenLevel( 3 );
-
   // create root object if not exist
   CAM_DataObject* aRootObj = root();
   if( !aRootObj )
@@ -195,6 +196,45 @@ void HYDROGUI_DataModel::update( const int theStudyId )
     if( !anImageObj.IsNull() )
       createObject( anImageRootObj, anImageObj );
   }
+
+  LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, "BATHYMETRIES" );
+
+  anIterator = HYDROData_Iterator( aDocument, KIND_BATHYMETRY );
+  for( ; anIterator.More(); anIterator.Next() )
+  {
+    Handle(HYDROData_Bathymetry) aBathymetryObj =
+      Handle(HYDROData_Bathymetry)::DownCast( anIterator.Current() );
+    if( !aBathymetryObj.IsNull() )
+      createObject( aBathymetryRootObj, aBathymetryObj );
+  }
+
+  LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, "POLYLINES" );
+
+  anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE );
+  for( ; anIterator.More(); anIterator.Next() )
+  {
+    Handle(HYDROData_Polyline) aPolylineObj =
+      Handle(HYDROData_Polyline)::DownCast( anIterator.Current() );
+    if( !aPolylineObj.IsNull() )
+      createObject( aPolylineRootObj, aPolylineObj );
+  }
+
+  LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, "VISUAL_STATES" );
+
+  anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE );
+  for( ; anIterator.More(); anIterator.Next() )
+  {
+    Handle(HYDROData_VisualState) aVisualStateObj =
+      Handle(HYDROData_VisualState)::DownCast( anIterator.Current() );
+    if( !aVisualStateObj.IsNull() )
+      createObject( aVisualStateRootObj, aVisualStateObj );
+  }
+
+  if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
+  {
+    anObjectBrowser->setAutoOpenLevel( 3 );
+    anObjectBrowser->openLevels();
+  }
 }
 
 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Object)& theModelObject )
@@ -239,8 +279,7 @@ void HYDROGUI_DataModel::updateModel()
 Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
                                                             const ObjectKind theObjectKind )
 {
-  const int aStudyId = module()->application()->activeStudy()->id();
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
+  Handle(HYDROData_Document) aDocument = getDocument();
   if( !aDocument.IsNull() )
   {
     HYDROData_Iterator anIterator( aDocument, theObjectKind );
@@ -258,6 +297,74 @@ Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEn
   return NULL;
 }
 
+bool HYDROGUI_DataModel::canUndo() const
+{
+  return getDocument()->CanUndo();
+}
+
+bool HYDROGUI_DataModel::canRedo() const
+{
+  return getDocument()->CanRedo();
+}
+
+QStringList HYDROGUI_DataModel::undoNames() const
+{
+  QStringList aNames;
+  for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
+    aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
+  return aNames;
+}
+
+QStringList HYDROGUI_DataModel::redoNames() const
+{
+  QStringList aNames;
+  for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
+    aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
+  return aNames;
+}
+
+void HYDROGUI_DataModel::clearUndos()
+{
+  getDocument()->ClearUndos();
+}
+
+void HYDROGUI_DataModel::clearRedos()
+{
+  getDocument()->ClearRedos();
+}
+
+bool HYDROGUI_DataModel::undo()
+{
+  try 
+  {
+    getDocument()->Undo();
+  }
+  catch ( Standard_Failure )
+  {
+    return false;
+  }
+  return true;
+}
+
+bool HYDROGUI_DataModel::redo()
+{
+  try 
+  {
+    getDocument()->Redo();
+  }
+  catch ( Standard_Failure )
+  {
+    return false;
+  }
+  return true;
+}
+
+Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
+{
+  int aStudyId = module()->application()->activeStudy()->id();
+  return HYDROData_Document::Document( aStudyId );
+}
+
 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
                                                        Handle(HYDROData_Object) theModelObject )
 {