Back to index

salome-gui  6.5.0
SALOME_PYQT_DataModelLight.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
00021 //  Date   : 22/06/2007
00022 //
00023 #include "PyInterp_Interp.h" // // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
00024 
00025 #include "SALOME_PYQT_DataModelLight.h" 
00026 #include "SALOME_PYQT_DataObjectLight.h"
00027 #include "SALOME_PYQT_ModuleLight.h"
00028 #include <utilities.h>
00029 
00030 #include <LightApp_Study.h>
00031 #include <CAM_Module.h>
00032 #include <CAM_Application.h>
00033 #include <CAM_Study.h>
00034 
00035 
00036 //=================================================================================
00037 // function : SALOME_PYQT_DataModelLight()
00038 // purpose  : constructor
00039 //=================================================================================
00040 SALOME_PYQT_DataModelLight::SALOME_PYQT_DataModelLight(CAM_Module * theModule)
00041   : LightApp_DataModel( theModule ),
00042     myFileName( "" ),
00043     myStudyURL( "" ),
00044     myModified( false )
00045 {
00046   
00047 }
00048 
00049 //=================================================================================
00050 // function : ~SALOME_PYQT_DataModelLight()
00051 // purpose  : destructor
00052 //=================================================================================
00053 SALOME_PYQT_DataModelLight::~SALOME_PYQT_DataModelLight()
00054 {
00055 }
00056 
00057 //=================================================================================
00058 // function : open()
00059 // purpose  : Open data model operation
00060 //=================================================================================
00061 bool SALOME_PYQT_DataModelLight::open( const QString& theURL, CAM_Study* study, QStringList theListOfFiles)
00062 {
00063   MESSAGE("SALOME_PYQT_DataModelLight::open()");
00064   LightApp_Study* aDoc = dynamic_cast<LightApp_Study*>( study );
00065   SALOME_PYQT_ModuleLight* aModule = dynamic_cast<SALOME_PYQT_ModuleLight*>(module());
00066   if ( !aDoc || !aModule)
00067     return false;
00068   
00069   LightApp_DataModel::open( theURL, aDoc, theListOfFiles );
00070 
00071   setModified( false );
00072   
00073   return aModule->open(theListOfFiles);
00074   
00075 }
00076 
00077 //=================================================================================
00078 // function : save()
00079 // purpose  : Save data model operation
00080 //=================================================================================
00081 bool SALOME_PYQT_DataModelLight::save( QStringList& theListOfFiles)
00082 {
00083   MESSAGE("SALOME_PYQT_DataModelLight::save()");
00084   bool isMultiFile = false; // temporary solution
00085   
00086   LightApp_DataModel::save(theListOfFiles);
00087   LightApp_Study* study = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
00088   SALOME_PYQT_ModuleLight* aModule = dynamic_cast<SALOME_PYQT_ModuleLight*>(module());
00089 
00090   if(!aModule || !study)
00091     return false;
00092   
00093 
00094   std::string aTmpDir = study->GetTmpDir(myStudyURL.toLatin1().constData(), isMultiFile );
00095 
00096   theListOfFiles.append(QString(aTmpDir.c_str()));
00097   int listSize = theListOfFiles.size();
00098   aModule->save(theListOfFiles);
00099 
00100   setModified( false );
00101 
00102   //Return true if in the List of files was added item(s)
00103   //else return false 
00104   return theListOfFiles.size() > listSize;
00105 }
00106 
00107 //=================================================================================
00108 // function : saveAs()
00109 // purpose  : SaveAs data model operation
00110 //=================================================================================
00111 bool SALOME_PYQT_DataModelLight::saveAs ( const QString& theURL, CAM_Study* theStudy, QStringList& theListOfFiles)
00112 {
00113   myStudyURL = theURL;
00114   return save(theListOfFiles);
00115 }
00116 
00117 
00118 
00119 bool SALOME_PYQT_DataModelLight::create( CAM_Study* study )
00120 {
00121   return true;
00122 }
00123 
00124 //=================================================================================
00125 // function : dumpPython()
00126 // purpose  : Re-defined from LigthApp_DataModel in order to participate 
00127 //            in dump study process
00128 //=================================================================================
00129 bool SALOME_PYQT_DataModelLight::dumpPython( const QString& theURL, 
00130                                         CAM_Study* theStudy,
00131                                         bool isMultiFile,
00132                                         QStringList& theListOfFiles )
00133 {
00134   MESSAGE("SALOME_PYQT_DataModelLight::dumpPython()");
00135   
00136   LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
00137 
00138   LightApp_Study* study = dynamic_cast<LightApp_Study*>( theStudy );
00139   SALOME_PYQT_ModuleLight* aModule = dynamic_cast<SALOME_PYQT_ModuleLight*>(module());
00140 
00141   if(!aModule || !study)
00142     return false;
00143   
00144   std::string aTmpDir = study->GetTmpDir( theURL.toLatin1().constData(), isMultiFile );
00145 
00146   theListOfFiles.append( QString( aTmpDir.c_str() ) );
00147   int oldSize = theListOfFiles.size();
00148 
00149   aModule->dumpPython( theListOfFiles );
00150 
00151   //Return true if some items have been added, else return false 
00152   return theListOfFiles.size() > oldSize;
00153 }
00154 
00155 //=================================================================================
00156 // function : isModified()
00157 // purpose  : returns this model's modification status that can be controlled 
00158 //            with help of setModified() calls by the underlying Python module
00159 //=================================================================================
00160 bool SALOME_PYQT_DataModelLight::isModified() const
00161 {
00162   return myModified;
00163 }
00164 
00165 //=================================================================================
00166 // function : setModified()
00167 // purpose  : sets the model's modification status, should be used by 
00168 //            the underlying Python module when its data changes.
00169 //=================================================================================
00170 void SALOME_PYQT_DataModelLight::setModified( bool flag )
00171 {
00172   myModified = flag;
00173 }
00174 
00175 //=================================================================================
00176 // function : close()
00177 // purpose  : Close data model operation
00178 //=================================================================================
00179 bool SALOME_PYQT_DataModelLight::close()
00180 {
00181   LightApp_DataModel::close();
00182   return true;
00183 }
00184 
00185 
00186 void SALOME_PYQT_DataModelLight::update ( LightApp_DataObject* theObj, LightApp_Study* theStudy )
00187 {
00188   // Nothing to do here: we always keep the data tree in the up-to-date state
00189   // The only goal of this method is to hide default behavior from LightApp_DataModel
00190   return;
00191 }
00192 
00193 CAM_DataObject* SALOME_PYQT_DataModelLight::getRoot()
00194 {
00195   LightApp_Study* study = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
00196   CAM_ModuleObject *aModelRoot = dynamic_cast<CAM_ModuleObject*>(root());
00197   if(study && aModelRoot == NULL) {
00198     aModelRoot = createModuleObject( study->root() );
00199     aModelRoot->setDataModel( this );
00200     setRoot(aModelRoot);
00201   }
00202   return aModelRoot;
00203 }