Salome HOME
Using LightApp library
[samples/light.git] / src / LIGHTGUI / LIGHTGUI_DataModel.cxx
index 675fcbe80b77d13f65237e49030c483a465c9389..8090dcafeedfc1c5970045c04ce4ed5b6bacd521 100644 (file)
 #include "LIGHTGUI_DataModel.h"
 #include "LIGHTGUI_DataObject.h"
 
-#include <SalomeApp_Study.h>
+#include <LightApp_Study.h>
 #include <SUIT_Tools.h>
 #include <SUIT_DataObjectIterator.h>
+#include <CAM_Module.h>
+#include <CAM_Application.h>
 
 #include <qstring.h>
 #include <qfile.h>
 
+#include <vector.h>
+#include <string.h>
+
 //=================================================================================
 // function : LIGHTGUI_DataModel()
 // purpose  : constructor
 //=================================================================================
 LIGHTGUI_DataModel::LIGHTGUI_DataModel ( CAM_Module* theModule )
-     : SalomeApp_DataModel( theModule ),
+     : LightApp_DataModel( theModule ),
        myFileName( "" ),
        myStudyURL( "" )
 {
@@ -58,14 +63,14 @@ LIGHTGUI_DataModel::~LIGHTGUI_DataModel()
 //=================================================================================
 bool LIGHTGUI_DataModel::open ( const QString& theURL, CAM_Study* study )
 {
-  SalomeApp_Study* aDoc = dynamic_cast<SalomeApp_Study*>( study );
+  LightApp_Study* aDoc = dynamic_cast<LightApp_Study*>( study );
   if ( !aDoc )
     return false;
 
-  SalomeApp_DataModel::open( theURL, study );
+  LightApp_DataModel::open( theURL, aDoc );
 
-  // Get list of files, created for this module by SalomeApp_Engine_i::Load().
-  std::vector<std::string> aListOfFiles = GetListOfFiles();
+  // Get list of files, created for this module by LightApp_Engine_i::Load().
+  std::vector<std::string> aListOfFiles = aDoc->GetListOfFiles();
 
   // The first list item contains path to a temporary
   // directory, where the persistent files was placed
@@ -73,18 +78,18 @@ bool LIGHTGUI_DataModel::open ( const QString& theURL, CAM_Study* study )
     QString aTmpDir ( aListOfFiles[0] );
 
     // This module operates with a single persistent file
-    if ( aListOfFiles.size() == 2 ) {
-      myStudyURL = theURL;
-      QString aFileName ( aListOfFiles[1] );
-      QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName;
+  if ( aListOfFiles.size() == 2 ) {
+    myStudyURL = theURL;
+    QString aFileName ( aListOfFiles[1] );
+    QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName;
 
-      loadFile( aFullPath, study );
-    }
+    loadFile( aFullPath, aDoc );
+  }
 
     // Remove the files and temporary directory, created
-    // for this module by SalomeApp_Engine_i::Load()
+    // for this module by LightApp_Engine_i::Load()
     bool isMultiFile = false; // TODO: decide, how to access this parameter
-    RemoveTemporaryFiles( isMultiFile );
+    aDoc->RemoveTemporaryFiles( isMultiFile );
   }
 
   return true;
@@ -99,7 +104,11 @@ bool LIGHTGUI_DataModel::save()
   // 1. Save data to temporary files
   bool isMultiFile = false; // TODO: decide, how to access this parameter
 
-  QString aTmpDir ( SalomeApp_DataModel::GetTmpDir( myStudyURL.latin1(), isMultiFile ) );
+  LightApp_DataModel::save();
+
+  LightApp_Study* study = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
+
+  QString aTmpDir = study->GetTmpDir( myStudyURL.latin1(), isMultiFile );
   QString aFileName = SUIT_Tools::file( myStudyURL, false ) + "_LIGHTGUI.txt";
   QString aFullPath = aTmpDir + aFileName;
   dumpFile( aFullPath );
@@ -108,7 +117,7 @@ bool LIGHTGUI_DataModel::save()
   std::vector<std::string> aListOfFiles ( 2 );
   aListOfFiles[0] = aTmpDir.latin1();
   aListOfFiles[1] = aFileName.latin1();
-  SetListOfFiles( aListOfFiles );
+  study->SetListOfFiles( aListOfFiles );
 
   return true;
 }
@@ -129,6 +138,7 @@ bool LIGHTGUI_DataModel::saveAs ( const QString& theURL, CAM_Study* )
 //=================================================================================
 bool LIGHTGUI_DataModel::close()
 {
+  LightApp_DataModel::close();
   return true;
 }
 
@@ -164,10 +174,10 @@ bool LIGHTGUI_DataModel::isSaved() const
 // function : update()
 // purpose  : updates data model
 //=================================================================================
-void LIGHTGUI_DataModel::update ( SalomeApp_DataObject*, SalomeApp_Study* )
+void LIGHTGUI_DataModel::update ( LightApp_DataObject*, LightApp_Study* )
 {
   // Nothing to do here: we always keep the data tree in the up-to-date state
-  // The only goal of this method is to hide default behavior from SalomApp_DataModel
+  // The only goal of this method is to hide default behavior from LightApp_DataModel
   return;
 }
 
@@ -394,9 +404,10 @@ void LIGHTGUI_DataModel::buildTree ( SUIT_DataObject* studyRoot, const QStringLi
 {
   if ( !studyRoot )
     return;
-  
+
   LIGHTGUI_ModuleObject* modelRoot = new LIGHTGUI_ModuleObject( this, studyRoot );
-  CAM_DataObject* aParaObject, aLineObject;
+  LIGHTGUI_DataObject* aParaObject;
+  LIGHTGUI_DataObject* aLineObject;
 
   aParaObject = new LIGHTGUI_DataObject ( "", modelRoot );
 
@@ -405,7 +416,7 @@ void LIGHTGUI_DataModel::buildTree ( SUIT_DataObject* studyRoot, const QStringLi
   for ( ; it1 != it2; ++it1 ) {
     if ( (*it1).stripWhiteSpace().isEmpty() ) {
       aParaObject = new LIGHTGUI_DataObject ( *it1, modelRoot );
-    } 
+    }
     else {
       aLineObject = new LIGHTGUI_DataObject ( *it1, aParaObject );
     }