1 #include "LightApp_Study.h"
3 #include "CAM_DataModel.h"
4 #include "LightApp_Application.h"
5 #include "LightApp_DataModel.h"
6 #include "LightApp_DataObject.h"
7 #include "LightApp_RootObject.h"
8 #include "LightApp_Driver.h"
10 #include "SUIT_ResourceMgr.h"
11 #include "SUIT_DataObjectIterator.h"
13 #include <OB_Browser.h>
15 #include <TCollection_AsciiString.hxx>
17 #include <OSD_Path.hxx>
18 #include <OSD_File.hxx>
19 #include <OSD_Directory.hxx>
20 #include <OSD_Process.hxx>
21 #include <OSD_Directory.hxx>
22 #include <OSD_Protection.hxx>
23 #include <OSD_SingleProtection.hxx>
24 #include <OSD_FileIterator.hxx>
31 LightApp_Study::LightApp_Study( SUIT_Application* app )
34 myDriver = new LightApp_Driver();
40 LightApp_Study::~LightApp_Study()
47 void LightApp_Study::createDocument()
50 setRoot( new LightApp_RootObject( this ) );
52 CAM_Study::createDocument();
57 //=======================================================================
58 // name : openDocument
59 /*! Purpose : Open document*/
60 //=======================================================================
61 bool LightApp_Study::openDocument( const QString& theFileName )
63 myDriver->ClearDriverContents();
64 // create files for models from theFileName
65 if( !openStudyData(theFileName))
68 setRoot( new LightApp_RootObject( this ) ); // create myRoot
70 // update loaded data models: call open() and update() on them.
73 for ( ModelListIterator it( dm_s ); it.current(); ++it )
74 openDataModel( studyName(), it.current() );
75 // this will build a SUIT_DataObject-s tree under myRoot member field
76 // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step
77 // but tree that corresponds to not-loaded data models will be updated any way.
78 ((LightApp_Application*)application())->updateObjectBrowser( false );
80 bool res = CAM_Study::openDocument( theFileName );
86 //=======================================================================
87 // name : loadDocument
88 /*! Purpose : Load document */
89 //=======================================================================
90 bool LightApp_Study::loadDocument( const QString& theStudyName )
92 myDriver->ClearDriverContents();
93 if( !openStudyData(theStudyName))
96 setRoot( new LightApp_RootObject( this ) ); // create myRoot
98 //SRN: BugID IPAL9021, put there the same code as in a method openDocument
100 // update loaded data models: call open() and update() on them.
104 for ( ModelListIterator it( dm_s ); it.current(); ++it )
105 openDataModel( studyName(), it.current() );
107 // this will build a SUIT_DataObject-s tree under myRoot member field
108 // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step
109 // but tree that corresponds to not-loaded data models will be updated any way.
110 ((LightApp_Application*)application())->updateObjectBrowser( false );
112 bool res = CAM_Study::openDocument( theStudyName );
114 //SRN: BugID IPAL9021: End
118 //=======================================================================
119 // name : saveDocumentAs
120 /*! Purpose : Save document */
121 //=======================================================================
122 bool LightApp_Study::saveDocumentAs( const QString& theFileName )
124 ModelList list; dataModels( list );
126 LightApp_DataModel* aModel = (LightApp_DataModel*)list.first();
128 myDriver->ClearDriverContents();
129 QStringList listOfFiles;
130 for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) {
132 aModel->saveAs( theFileName, this, listOfFiles );
133 if ( !listOfFiles.isEmpty() )
134 saveModuleData(aModel->module()->name(), listOfFiles);
137 bool res = saveStudyData(theFileName);
138 res = res && CAM_Study::saveDocumentAs( theFileName );
139 //SRN: BugID IPAL9377, removed usage of uninitialized variable <res>
146 //=======================================================================
147 // name : saveDocument
148 /*! Purpose : Save document */
149 //=======================================================================
150 bool LightApp_Study::saveDocument()
152 ModelList list; dataModels( list );
154 LightApp_DataModel* aModel = (LightApp_DataModel*)list.first();
156 myDriver->ClearDriverContents();
157 QStringList listOfFiles;
158 for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) {
160 aModel->save( listOfFiles );
161 saveModuleData(aModel->module()->name(), listOfFiles);
164 bool res = saveStudyData(studyName());
165 res = res && CAM_Study::saveDocument();
172 //================================================================
173 // Function : closeDocument
174 /*! Purpose : Close document */
175 //================================================================
176 void LightApp_Study::closeDocument(bool permanently)
178 // Inform everybody that this study is going to close when it's most safe to,
179 // i.e. in the very beginning
182 CAM_Study::closeDocument(permanently);
185 //================================================================
186 // Function : referencedToEntry
187 /*! Purpose : Return current entry*/
188 //================================================================
189 QString LightApp_Study::referencedToEntry( const QString& entry ) const
194 //================================================================
195 // Function : children
196 /*! Purpose : Return entries of children of object*/
197 //================================================================
198 void LightApp_Study::children( const QString&, QStringList& ) const
202 //================================================================
203 // Function : isComponent
204 /*! Purpose : Return true if entry corresponds to component*/
205 //================================================================
206 bool LightApp_Study::isComponent( const QString& entry ) const
211 //================================================================
212 // Function : componentDataType
213 /*! Purpose : Return component data type from entry*/
214 //================================================================
215 QString LightApp_Study::componentDataType( const QString& entry ) const
217 LightApp_DataObject* aCurObj;
218 for ( SUIT_DataObjectIterator it( root(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
219 aCurObj = dynamic_cast<LightApp_DataObject*>( it.current() );
220 if ( aCurObj && aCurObj->entry() == entry ) {
221 return aCurObj->componentDataType();
227 //================================================================
228 // Function : isModified
230 //================================================================
231 bool LightApp_Study::isModified() const
233 bool isAnyChanged = CAM_Study::isModified();
234 ModelList list; dataModels( list );
236 LightApp_DataModel* aModel = 0;
237 for ( QPtrListIterator<CAM_DataModel> it( list ); it.current() && !isAnyChanged; ++it ){
238 aModel = dynamic_cast<LightApp_DataModel*>( it.current() );
240 isAnyChanged = aModel->isModified();
245 //================================================================
246 // Function : isSaved
247 /*! Purpose : Check: data model is saved?*/
248 //================================================================
249 bool LightApp_Study::isSaved() const
251 bool isAllSaved = CAM_Study::isSaved();
252 ModelList list; dataModels( list );
254 LightApp_DataModel* aModel = 0;
255 for ( QPtrListIterator<CAM_DataModel> it( list ); it.current() && isAllSaved; ++it ){
256 aModel = dynamic_cast<LightApp_DataModel*>( it.current() );
258 isAllSaved = aModel->isSaved();
263 //=======================================================================
264 // name : saveModuleData
265 /*! Purpose : Create SComponent for module, necessary for SalomeApp study */
266 //=======================================================================
267 void LightApp_Study::addComponent(const CAM_DataModel* dm)
271 //=======================================================================
272 // name : saveModuleData
273 /*! Purpose : save list file for module 'theModuleName' */
274 //=======================================================================
275 void LightApp_Study::saveModuleData(QString theModuleName, QStringList theListOfFiles)
277 int aNb = theListOfFiles.count();
281 std::vector<std::string> aListOfFiles ( aNb );
283 for ( QStringList::Iterator it = theListOfFiles.begin(); it != theListOfFiles.end(); ++it ) {
284 if ( (*it).isEmpty() )
286 aListOfFiles[anIndex] = (*it).latin1();
289 myDriver->SetListOfFiles(theModuleName, aListOfFiles);
292 //=======================================================================
293 // name : openModuleData
294 /*! Purpose : gets list of file for module 'theModuleNam' */
295 //=======================================================================
296 void LightApp_Study::openModuleData(QString theModuleName, QStringList& theListOfFiles)
298 std::vector<std::string> aListOfFiles = myDriver->GetListOfFiles(theModuleName);
299 int i, aLength = aListOfFiles.size() - 1;
303 //Get a temporary directory for saved a file
304 theListOfFiles.append(aListOfFiles[0].c_str());
305 for(i = 0; i < aLength; i++)
306 theListOfFiles.append(aListOfFiles[i+1].c_str());
309 //=======================================================================
310 // name : saveStudyData
311 /*! Purpose : save data from study */
312 //=======================================================================
313 bool LightApp_Study::saveStudyData( const QString& theFileName )
315 ModelList list; dataModels( list );
316 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
319 bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
321 bool aRes = myDriver->SaveDatasInFile(theFileName.latin1(), isMultiFile);
323 std::vector<std::string> aList(0);
324 for ( ModelListIterator it( list ); it.current(); ++it )
325 myDriver->SetListOfFiles(it.current()->module()->name(), aList);
330 //=======================================================================
331 // name : openStudyData
332 /*! Purpose : open data for study */
333 //=======================================================================
334 bool LightApp_Study::openStudyData( const QString& theFileName )
336 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
339 bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
341 bool aRes = myDriver->ReadDatasFromFile(theFileName.latin1(), isMultiFile);
345 //================================================================
346 // Function : openDataModel
347 /*! Purpose : Open data model */
348 //================================================================
349 bool LightApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm )
354 QStringList listOfFiles;
355 openModuleData(dm->module()->name(), listOfFiles);
356 if (dm && dm->open(studyName, this, listOfFiles)) {
357 // Remove the files and temporary directory, created
358 // for this module by LightApp_Driver::OpenStudyData()
359 bool isMultiFile = false; // TODO: decide, how to access this parameter
360 RemoveTemporaryFiles( dm->module()->name(), isMultiFile );
362 // Something has been read -> create data model tree
363 LightApp_DataModel* aDM = dynamic_cast<LightApp_DataModel*>( dm );
365 aDM->update(NULL, this);
371 //================================================================
372 // Function : GetTmpDir
373 /*! Purpose : to be used by modules*/
374 //================================================================
375 std::string LightApp_Study::GetTmpDir (const char* theURL,
376 const bool isMultiFile)
378 return myDriver->GetTmpDir(theURL, isMultiFile);
381 //================================================================
382 // Function : GetListOfFiles
383 /*! Purpose : to be used by modules*/
384 //================================================================
385 std::vector<std::string> LightApp_Study::GetListOfFiles(const char* theModuleName) const
387 std::vector<std::string> aListOfFiles;
388 aListOfFiles = myDriver->GetListOfFiles(theModuleName);
392 //================================================================
393 // Function : SetListOfFiles
394 /*! Purpose : to be used by modules*/
395 //================================================================
396 void LightApp_Study::SetListOfFiles (const char* theModuleName, const std::vector<std::string> theListOfFiles)
398 myDriver->SetListOfFiles(theModuleName, theListOfFiles);
401 //================================================================
402 // Function : RemoveTemporaryFiles
403 /*! Purpose : to be used by modules*/
404 //================================================================
405 void LightApp_Study::RemoveTemporaryFiles (const char* theModuleName, const bool isMultiFile) const
409 bool isDirDeleted = true;
410 myDriver->RemoveTemporaryFiles(theModuleName, isDirDeleted);
413 //================================================================
414 // Function : RemoveTemporaryFiles
415 /*! Purpose : to be used by modules*/
416 //================================================================
417 void LightApp_Study::components( QStringList& comp ) const
419 DataObjectList children = root()->children();
420 DataObjectList::const_iterator anIt = children.begin(), aLast = children.end();
421 for( ; anIt!=aLast; anIt++ )
423 LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( *anIt );
424 if( obj && obj->entry()!="Interface Applicative" )
425 comp.append( obj->entry() );