Salome HOME
5d74fd8e21a1fec6be8e91ae452b444d217ee854
[modules/gui.git] / src / SALOME_PYQT / SALOME_PYQT_GUILight / SALOME_PYQT_DataModelLight.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
21 //  Date   : 22/06/2007
22 //
23 #include "PyInterp_Interp.h" // // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
24
25 #include "SALOME_PYQT_DataModelLight.h" 
26 #include "SALOME_PYQT_DataObjectLight.h"
27 #include "SALOME_PYQT_ModuleLight.h"
28 #include <utilities.h>
29
30 #include <LightApp_Study.h>
31 #include <CAM_Module.h>
32 #include <CAM_Application.h>
33 #include <CAM_Study.h>
34
35
36 //=================================================================================
37 // function : SALOME_PYQT_DataModelLight()
38 // purpose  : constructor
39 //=================================================================================
40 SALOME_PYQT_DataModelLight::SALOME_PYQT_DataModelLight(CAM_Module * theModule)
41   : LightApp_DataModel( theModule ),
42     myFileName( "" ),
43     myStudyURL( "" ),
44     myModified( false )
45 {
46   
47 }
48
49 //=================================================================================
50 // function : ~SALOME_PYQT_DataModelLight()
51 // purpose  : destructor
52 //=================================================================================
53 SALOME_PYQT_DataModelLight::~SALOME_PYQT_DataModelLight()
54 {
55 }
56
57 //=================================================================================
58 // function : open()
59 // purpose  : Open data model operation
60 //=================================================================================
61 bool SALOME_PYQT_DataModelLight::open( const QString& theURL, CAM_Study* study, QStringList theListOfFiles)
62 {
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)
67     return false;
68   
69   LightApp_DataModel::open( theURL, aDoc, theListOfFiles );
70
71   setModified( false );
72   
73   return aModule->load(theListOfFiles, theURL);
74   
75 }
76
77 //=================================================================================
78 // function : save()
79 // purpose  : Save data model operation
80 //=================================================================================
81 bool SALOME_PYQT_DataModelLight::save( QStringList& theListOfFiles)
82 {
83   MESSAGE("SALOME_PYQT_DataModelLight::save()");
84   bool isMultiFile = false; // temporary solution
85   
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());
89
90   if(!aModule || !study)
91     return false;
92   
93
94   std::string aTmpDir = study->GetTmpDir(myStudyURL.toUtf8().constData(), isMultiFile );
95
96   theListOfFiles.append(QString(aTmpDir.c_str()));
97   int listSize = theListOfFiles.size();
98   aModule->save(theListOfFiles, myStudyURL);
99
100   setModified( false );
101
102   //Return true if in the List of files was added item(s)
103   //else return false 
104   return theListOfFiles.size() > listSize;
105 }
106
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)
112 {
113   myStudyURL = theURL;
114   return save(theListOfFiles);
115 }
116
117
118
119 bool SALOME_PYQT_DataModelLight::create( CAM_Study* /*study*/ )
120 {
121   return true;
122 }
123
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, 
130                                              CAM_Study* theStudy,
131                                              bool isMultiFile,
132                                              QStringList& theListOfFiles )
133 {
134   MESSAGE("SALOME_PYQT_DataModelLight::dumpPython()");
135   
136   LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
137
138   LightApp_Study* study = dynamic_cast<LightApp_Study*>( theStudy );
139   SALOME_PYQT_ModuleLight* aModule = dynamic_cast<SALOME_PYQT_ModuleLight*>(module());
140
141   if(!aModule || !study)
142     return false;
143   
144   std::string aTmpDir = study->GetTmpDir( theURL.toUtf8().constData(), isMultiFile );
145
146   theListOfFiles.append( QString( aTmpDir.c_str() ) );
147   int oldSize = theListOfFiles.size();
148
149   aModule->dumpPython( theListOfFiles );
150
151   //Return true if some items have been added, else return false 
152   return theListOfFiles.size() > oldSize;
153 }
154
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
161 {
162   return myModified;
163 }
164
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 )
171 {
172   myModified = flag;
173 }
174
175 //=================================================================================
176 // function : close()
177 // purpose  : Close data model operation
178 //=================================================================================
179 bool SALOME_PYQT_DataModelLight::close()
180 {
181   LightApp_DataModel::close();
182   return true;
183 }
184
185
186 void SALOME_PYQT_DataModelLight::update ( LightApp_DataObject* /*theObj*/, LightApp_Study* /*theStudy*/ )
187 {
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
190   return;
191 }
192
193 CAM_DataObject* SALOME_PYQT_DataModelLight::getRoot()
194 {
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 );
200     setRoot(aModelRoot);
201   }
202   return aModelRoot;
203 }