1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
23 #include "PyInterp_Interp.h" // // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
25 #include "SALOME_PYQT_DataModelLight.h"
26 #include "SALOME_PYQT_DataObjectLight.h"
27 #include "SALOME_PYQT_ModuleLight.h"
28 #include <utilities.h>
30 #include <LightApp_Study.h>
31 #include <CAM_Module.h>
32 #include <CAM_Application.h>
33 #include <CAM_Study.h>
36 //=================================================================================
37 // function : SALOME_PYQT_DataModelLight()
38 // purpose : constructor
39 //=================================================================================
40 SALOME_PYQT_DataModelLight::SALOME_PYQT_DataModelLight(CAM_Module * theModule)
41 : LightApp_DataModel( theModule ),
49 //=================================================================================
50 // function : ~SALOME_PYQT_DataModelLight()
51 // purpose : destructor
52 //=================================================================================
53 SALOME_PYQT_DataModelLight::~SALOME_PYQT_DataModelLight()
57 //=================================================================================
59 // purpose : Open data model operation
60 //=================================================================================
61 bool SALOME_PYQT_DataModelLight::open( const QString& theURL, CAM_Study* study, QStringList theListOfFiles)
63 MESSAGE("SALOME_PYQT_DataModelLight::open()");
64 LightApp_Study* aDoc = dynamic_cast<LightApp_Study*>( study );
65 SALOME_PYQT_ModuleLight* aModule = dynamic_cast<SALOME_PYQT_ModuleLight*>(module());
66 if ( !aDoc || !aModule)
69 LightApp_DataModel::open( theURL, aDoc, theListOfFiles );
73 return aModule->load(theListOfFiles);
77 //=================================================================================
79 // purpose : Save data model operation
80 //=================================================================================
81 bool SALOME_PYQT_DataModelLight::save( QStringList& theListOfFiles)
83 MESSAGE("SALOME_PYQT_DataModelLight::save()");
84 bool isMultiFile = false; // temporary solution
86 LightApp_DataModel::save(theListOfFiles);
87 LightApp_Study* study = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
88 SALOME_PYQT_ModuleLight* aModule = dynamic_cast<SALOME_PYQT_ModuleLight*>(module());
90 if(!aModule || !study)
94 std::string aTmpDir = study->GetTmpDir(myStudyURL.toLatin1().constData(), isMultiFile );
96 theListOfFiles.append(QString(aTmpDir.c_str()));
97 int listSize = theListOfFiles.size();
98 aModule->save(theListOfFiles);
100 setModified( false );
102 //Return true if in the List of files was added item(s)
104 return theListOfFiles.size() > listSize;
107 //=================================================================================
108 // function : saveAs()
109 // purpose : SaveAs data model operation
110 //=================================================================================
111 bool SALOME_PYQT_DataModelLight::saveAs ( const QString& theURL, CAM_Study* theStudy, QStringList& theListOfFiles)
114 return save(theListOfFiles);
119 bool SALOME_PYQT_DataModelLight::create( CAM_Study* study )
124 //=================================================================================
125 // function : dumpPython()
126 // purpose : Re-defined from LigthApp_DataModel in order to participate
127 // in dump study process
128 //=================================================================================
129 bool SALOME_PYQT_DataModelLight::dumpPython( const QString& theURL,
132 QStringList& theListOfFiles )
134 MESSAGE("SALOME_PYQT_DataModelLight::dumpPython()");
136 LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
138 LightApp_Study* study = dynamic_cast<LightApp_Study*>( theStudy );
139 SALOME_PYQT_ModuleLight* aModule = dynamic_cast<SALOME_PYQT_ModuleLight*>(module());
141 if(!aModule || !study)
144 std::string aTmpDir = study->GetTmpDir( theURL.toLatin1().constData(), isMultiFile );
146 theListOfFiles.append( QString( aTmpDir.c_str() ) );
147 int oldSize = theListOfFiles.size();
149 aModule->dumpPython( theListOfFiles );
151 //Return true if some items have been added, else return false
152 return theListOfFiles.size() > oldSize;
155 //=================================================================================
156 // function : isModified()
157 // purpose : returns this model's modification status that can be controlled
158 // with help of setModified() calls by the underlying Python module
159 //=================================================================================
160 bool SALOME_PYQT_DataModelLight::isModified() const
165 //=================================================================================
166 // function : setModified()
167 // purpose : sets the model's modification status, should be used by
168 // the underlying Python module when its data changes.
169 //=================================================================================
170 void SALOME_PYQT_DataModelLight::setModified( bool flag )
175 //=================================================================================
176 // function : close()
177 // purpose : Close data model operation
178 //=================================================================================
179 bool SALOME_PYQT_DataModelLight::close()
181 LightApp_DataModel::close();
186 void SALOME_PYQT_DataModelLight::update ( LightApp_DataObject* theObj, LightApp_Study* theStudy )
188 // Nothing to do here: we always keep the data tree in the up-to-date state
189 // The only goal of this method is to hide default behavior from LightApp_DataModel
193 CAM_DataObject* SALOME_PYQT_DataModelLight::getRoot()
195 LightApp_Study* study = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
196 CAM_ModuleObject *aModelRoot = dynamic_cast<CAM_ModuleObject*>(root());
197 if(study && aModelRoot == NULL) {
198 aModelRoot = createModuleObject( study->root() );
199 aModelRoot->setDataModel( this );