From: nds Date: Wed, 28 Sep 2005 08:23:41 +0000 (+0000) Subject: Modify algoritm save and open file LightApp_Study X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7976b16ff1d09400ac4e480ab89da4ae54c655c9;p=modules%2Fgui.git Modify algoritm save and open file LightApp_Study --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 153abd3e9..19d970dd8 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -105,6 +106,7 @@ LightApp_Preferences* LightApp_Application::_prefs_ = 0; Description : Application containing LightApp module */ +/*!Constructor.*/ LightApp_Application::LightApp_Application() : CAM_Application( false ), myPrefs( 0 ) @@ -114,7 +116,7 @@ myPrefs( 0 ) setDesktop( desk ); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false ); + QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ); desktop()->setIcon( aLogo ); desktop()->setDockableMenuBar( true ); @@ -606,6 +608,11 @@ void LightApp_Application::onSelectionChanged() { } +/*!Return window. + *\param flag - key for window + *\param studyId - study id + * Flag used how identificator of window in windows list. + */ QWidget* LightApp_Application::window( const int flag, const int studyId ) const { QWidget* wid = 0; @@ -770,17 +777,20 @@ PythonConsole* LightApp_Application::pythonConsole() /*!Update obect browser*/ void LightApp_Application::updateObjectBrowser( const bool updateModels ) { - // update existing data models (already loaded SComponents) + // update existing data models if ( updateModels ) { - for ( ModuleListIterator it = modules(); it.current(); ++it ) - { - CAM_DataModel* camDM = it.current()->dataModel(); - if ( camDM && camDM->inherits( "LightApp_DataModel" ) ) - ((LightApp_DataModel*)camDM)->update(); + LightApp_Study* study = dynamic_cast(activeStudy()); + if ( study ) { + CAM_Study::ModelList dm_list; + study->dataModels( dm_list ); + for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) { + CAM_DataModel* camDM = it.current(); + if ( camDM && camDM->inherits( "LightApp_DataModel" ) ) + ((LightApp_DataModel*)camDM)->update(); + } } } - if ( objectBrowser() ) { objectBrowser()->updateGeometry(); @@ -870,6 +880,10 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType return viewMgr; } +//======================================================================= +// name : onCloseView +/*! Purpose : SLOT. Remove view manager from application*/ +//======================================================================= void LightApp_Application::onCloseView( SUIT_ViewManager* theVM ) { removeViewManager( theVM ); @@ -937,14 +951,14 @@ void LightApp_Application::onDesktopActivated() } /*!Gets file filter. - *\retval QString "(*.hdf)" + *\retval QString "(*.bin)" */ QString LightApp_Application::getFileFilter() const { - return "(*.hdf)"; + return "(*.bin)"; } -/*!*/ +/*! Gets file name*/ QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters, const QString& caption, QWidget* parent ) { @@ -954,7 +968,7 @@ QString LightApp_Application::getFileName( bool open, const QString& initial, co return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true ); } -/*!*/ +/*! Gets directory*/ QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent ) { if ( !parent ) @@ -962,7 +976,7 @@ QString LightApp_Application::getDirectory( const QString& initial, const QStrin return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true ); } -/*!*/ +/*! Get open file names*/ QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters, const QString& caption, QWidget* parent ) { @@ -1175,6 +1189,7 @@ void LightApp_Application::moduleAdded( CAM_Module* mod ) } } +/*!Create preferences.*/ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) { if ( !pref ) @@ -1315,6 +1330,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) } +/*!Changed preferences */ void LightApp_Application::preferencesChanged( const QString& sec, const QString& param ) { SUIT_ResourceMgr* resMgr = resourceMgr(); @@ -1558,6 +1574,7 @@ void LightApp_Application::moduleIconNames( QMap& iconMap ) co } } +/*!Insert items in popup, which necessary for current application*/ void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title ) { CAM_Application::contextMenuPopup( type, thePopup, title ); diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index d93b51cc4..1062ddbd3 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -34,7 +34,7 @@ class QPixmap; #endif /*! - Description : Application containing LightApp module + Description : Application containing only LightApp module */ class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application diff --git a/src/LightApp/LightApp_DataModel.cxx b/src/LightApp/LightApp_DataModel.cxx index bde156ce7..6ccba618b 100644 --- a/src/LightApp/LightApp_DataModel.cxx +++ b/src/LightApp/LightApp_DataModel.cxx @@ -35,9 +35,9 @@ LightApp_DataModel::~LightApp_DataModel() //================================================================ // Function : open -/*! Purpose : Open data model*/ +/*! Purpose : Emit opened()*/ //================================================================ -bool LightApp_DataModel::open( const QString&, CAM_Study* study ) +bool LightApp_DataModel::open( const QString&, CAM_Study* study, QStringList ) { emit opened(); //TODO: is it really needed? to be removed maybe... return true; @@ -47,7 +47,7 @@ bool LightApp_DataModel::open( const QString&, CAM_Study* study ) // Function : save /*! Purpose : Emit saved()*/ //================================================================ -bool LightApp_DataModel::save() +bool LightApp_DataModel::save( QStringList& ) { emit saved(); return true; @@ -55,9 +55,9 @@ bool LightApp_DataModel::save() //================================================================ // Function : saveAs -/*! Purpose : Emit saved() */ +/*! Purpose : Emit saved()*/ //================================================================ -bool LightApp_DataModel::saveAs( const QString&, CAM_Study* ) +bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList& ) { emit saved(); return true; @@ -75,7 +75,7 @@ bool LightApp_DataModel::close() //================================================================ // Function : update -/*! Purpose : Update application.*/ +/*! Purpose : Update application (empty virtual function).*/ //================================================================ void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) { diff --git a/src/LightApp/LightApp_DataModel.h b/src/LightApp/LightApp_DataModel.h index f39350dc6..7b1f92d6c 100644 --- a/src/LightApp/LightApp_DataModel.h +++ b/src/LightApp/LightApp_DataModel.h @@ -17,8 +17,9 @@ class LightApp_Module; class LightApp_Study; class LightApp_DataObject; -// Class : LightApp_DataModel -/// Description : Base class of data model +/*! + Description : Base class of data model +*/ class LIGHTAPP_EXPORT LightApp_DataModel : public CAM_DataModel { Q_OBJECT @@ -27,9 +28,9 @@ public: LightApp_DataModel ( CAM_Module* theModule ); virtual ~LightApp_DataModel(); - virtual bool open( const QString&, CAM_Study* ); - virtual bool save(); - virtual bool saveAs( const QString&, CAM_Study* ); + virtual bool open( const QString&, CAM_Study*, QStringList ); + virtual bool save( QStringList& ); + virtual bool saveAs( const QString&, CAM_Study*, QStringList& ); virtual bool close(); virtual void update( LightApp_DataObject* = 0, LightApp_Study* = 0 ); diff --git a/src/LightApp/LightApp_DataObject.cxx b/src/LightApp/LightApp_DataObject.cxx index 00580c891..648685e25 100644 --- a/src/LightApp/LightApp_DataObject.cxx +++ b/src/LightApp/LightApp_DataObject.cxx @@ -87,7 +87,7 @@ SUIT_DataObjectKey* LightApp_DataObject::key() const */ SUIT_DataObject* LightApp_DataObject::componentObject() const { - SUIT_DataObject* compObj = 0; // for root object (invisible SALOME_ROOT_OBJECT) + SUIT_DataObject* compObj = 0; // for root object if ( parent() && parent() == root() ) compObj = (SUIT_DataObject*)this; // for component-level objects @@ -106,3 +106,48 @@ QString LightApp_DataObject::componentDataType() const return ""; } +/* + Class: LightApp_ModuleObject + Level: Public +*/ + +/*!Constructor.Initialize by \a parent.*/ +LightApp_ModuleObject::LightApp_ModuleObject( SUIT_DataObject* parent ) +: CAM_RootObject( parent ), + CAM_DataObject( parent ) +{ +} + +/*!Constructor.Initialize by \a module and parent.*/ +LightApp_ModuleObject::LightApp_ModuleObject( CAM_DataModel* dm, SUIT_DataObject* parent ) +: CAM_RootObject( dm, parent ), + CAM_DataObject( parent ) +{ +} + +/*!Destructor. Do nothing.*/ +LightApp_ModuleObject::~LightApp_ModuleObject() +{ +} + +/*!Returns module name */ +QString LightApp_ModuleObject::name() const +{ + return CAM_RootObject::name(); +} + +/*!Insert new child object to the children list at specified position + *\add component in Study for this module object if it necessary*/ +void LightApp_ModuleObject::insertChild( SUIT_DataObject* theObj, int thePosition ) +{ + CAM_RootObject::insertChild(theObj, thePosition); + + CAM_DataModel* aModel = dataModel(); + + LightApp_RootObject* aRoot = dynamic_cast(parent()); + + if (aRoot) + aRoot->study()->addComponent(aModel); + + +} diff --git a/src/LightApp/LightApp_DataObject.h b/src/LightApp/LightApp_DataObject.h index 30594a5cf..7cbdef947 100644 --- a/src/LightApp/LightApp_DataObject.h +++ b/src/LightApp/LightApp_DataObject.h @@ -4,10 +4,13 @@ #include "LightApp.h" #include "CAM_DataObject.h" +#include "CAM_DataModel.h" #include "CAM_RootObject.h" class LightApp_Study; +/*!Description : Data Object has empty entry so it's children must redefine metod entry() and return some unique string*/ + class LIGHTAPP_EXPORT LightApp_DataObject : public virtual CAM_DataObject { class Key; @@ -23,9 +26,26 @@ public: virtual QString entry() const; SUIT_DataObject* componentObject() const; - /*! GEOM, SMESH, VISU, etc.*/ QString componentDataType() const; }; +/*! + * LightApp_ModuleObject - class for optimized access to DataModel from + * CAM_RootObject.h. + * In modules which will be redefine LightApp_DataObject, LightApp_ModuleObject must be children from rederined DataObject for having necessary properties and children from LightApp_ModuleObject. + */ + +class LIGHTAPP_EXPORT LightApp_ModuleObject : public CAM_RootObject +{ +public: + LightApp_ModuleObject( SUIT_DataObject* = 0 ); + LightApp_ModuleObject ( CAM_DataModel*, SUIT_DataObject* = 0 ); + + virtual ~LightApp_ModuleObject(); + + virtual QString name() const; + virtual void insertChild( SUIT_DataObject*, int thePosition ); +}; + #endif diff --git a/src/LightApp/LightApp_Dialog.cxx b/src/LightApp/LightApp_Dialog.cxx index 5599c4983..b225983fa 100644 --- a/src/LightApp/LightApp_Dialog.cxx +++ b/src/LightApp/LightApp_Dialog.cxx @@ -10,7 +10,7 @@ /* Class : LightApp_Dialog - Description : Base class for all SALOME dialogs + Description : Base class for all dialogs */ //======================================================================= diff --git a/src/LightApp/LightApp_Dialog.h b/src/LightApp/LightApp_Dialog.h index 5e36c4394..1fb0302e1 100644 --- a/src/LightApp/LightApp_Dialog.h +++ b/src/LightApp/LightApp_Dialog.h @@ -18,7 +18,7 @@ class SUIT_ResourceMgr; /* Class : LightApp_Dialog - Description : Base class for all SALOME dialogs + Description : Base class for all LightApp dialogs */ class LightApp_Dialog : public QtxDialog { diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 649ccfefe..70045fcaf 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -80,7 +80,9 @@ void LightApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, delete sel; } -/*!Update object browser.*/ +/*!Update object browser. + * For updating model or whole object browser use update() method can be used. +*/ void LightApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root ) { if( updateDataModel ) @@ -141,7 +143,7 @@ LightApp_Application* LightApp_Module::getApp() const /*! * \brief Update something in accordance with update flags - * \param theFlags - update flags + * \param theFlags - update flags * * Update viewer or/and object browser etc. in accordance with update flags ( see * LightApp_UpdateFlags enumeration ). Derived modules can redefine this method for their @@ -276,7 +278,7 @@ void LightApp_Module::setPreferenceProperty( const int id, const QString& prop, /*! * \brief Starts operation with given identifier - * \param id - identifier of operation to be started + * \param id - identifier of operation to be started * * Module stores operations in map. This method starts operation by id. * If operation isn't in map, then it will be created by createOperation method @@ -311,6 +313,7 @@ void LightApp_Module::startOperation( const int id ) * Creates operation with given id. You should not call this method, it will be called * automatically from startOperation. You may redefine this method in concrete module to * create operations. + */ LightApp_Operation* LightApp_Module::createOperation( const int /*id*/ ) const { @@ -319,7 +322,7 @@ LightApp_Operation* LightApp_Module::createOperation( const int /*id*/ ) const /*! * \brief Virtual protected slot called when operation stopped - * \param theOp - stopped operation + * \param theOp - stopped operation * * Virtual protected slot called when operation stopped. Redefine this slot if you want to * perform actions after stopping operation diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h index 1367d4500..a01c550e7 100644 --- a/src/LightApp/LightApp_Module.h +++ b/src/LightApp/LightApp_Module.h @@ -27,7 +27,7 @@ class QVariant; /* Class : LightApp_Module - Description : Base class for all salome modules + Description : Base class for all light modules */ class LIGHTAPP_EXPORT LightApp_Module : public CAM_Module @@ -49,13 +49,9 @@ public: LightApp_Application* getApp() const; virtual void update( const int ); - // Update viewer or/and object browser etc. in accordance with update flags - // ( see LightApp_UpdateFlags enumeration ). Derived modules can redefine this method - // for their own purposes virtual void updateObjBrowser( bool = true, SUIT_DataObject* = 0 ); - // Update object bropwser ( for updating model or whole object browser use update() method - // can be used ) + virtual void selectionChanged(); virtual void preferencesChanged( const QString&, const QString& ); @@ -88,16 +84,9 @@ protected: const QString& param = QString::null ); QVariant preferenceProperty( const int, const QString& ) const; void setPreferenceProperty( const int, const QString&, const QVariant& ); - /*! Module stores operations in map. This method starts operation by id. - * If operation isn't in map, then it will be created by createOperation method - * and will be inserted to map - */ - void startOperation( const int ); - /*! Create operation by its id. You must not call this method, it will be called automatically - * by startOperation. Please redefine this method in current module - */ - virtual LightApp_Operation* createOperation( const int ) const; + void startOperation( const int ); + virtual LightApp_Operation* createOperation( const int ) const; virtual void updateControls(); diff --git a/src/LightApp/LightApp_Operation.cxx b/src/LightApp/LightApp_Operation.cxx index 0d5a24d5a..197eb93ee 100755 --- a/src/LightApp/LightApp_Operation.cxx +++ b/src/LightApp/LightApp_Operation.cxx @@ -1,4 +1,4 @@ -// SALOME LightApp +// LIGHT LightApp // // Copyright (C) 2005 CEA/DEN, EDF R&D // @@ -6,7 +6,7 @@ // // File : LightApp_Operation.h // Author : Sergey LITONIN -// Module : SALOME +// Module : LIGHT #include #include diff --git a/src/LightApp/LightApp_Operation.h b/src/LightApp/LightApp_Operation.h index 0ab698ffa..d2ab49477 100755 --- a/src/LightApp/LightApp_Operation.h +++ b/src/LightApp/LightApp_Operation.h @@ -1,4 +1,4 @@ -// SALOME LightApp +// LIGHT LightApp // // Copyright (C) 2005 CEA/DEN, EDF R&D // @@ -6,7 +6,7 @@ // // File : LightApp_Operation.h // Author : Sergey LITONIN -// Module : SALOME +// Module : LIGHT #ifndef LightApp_Operation_H @@ -27,9 +27,9 @@ class SUIT_Desktop; */ /*! - * \brief Base class for all salome operations + * \brief Base class for all operations * - * Base class for all salome operations (see SUIT_Operation for more description) + * Base class for all operations (see SUIT_Operation for more description) */ class LightApp_Operation : public SUIT_Operation { diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx index e6b3258cc..278b70edd 100644 --- a/src/LightApp/LightApp_Study.cxx +++ b/src/LightApp/LightApp_Study.cxx @@ -4,9 +4,23 @@ #include "LightApp_Application.h" #include "LightApp_DataModel.h" #include "LightApp_RootObject.h" +#include "LightApp_Driver.h" + +#include "SUIT_ResourceMgr.h" #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + #include /*! @@ -15,6 +29,7 @@ LightApp_Study::LightApp_Study( SUIT_Application* app ) : CAM_Study( app ) { + myDriver = new LightApp_Driver(); } /*! @@ -43,6 +58,11 @@ void LightApp_Study::createDocument() //======================================================================= bool LightApp_Study::openDocument( const QString& theFileName ) { + myDriver->ClearDriverContents(); + // create files for models from theFileName + if( !openStudyData(theFileName)) + return false; + setRoot( new LightApp_RootObject( this ) ); // create myRoot // update loaded data models: call open() and update() on them. @@ -50,7 +70,6 @@ bool LightApp_Study::openDocument( const QString& theFileName ) dataModels( dm_s ); for ( ModelListIterator it( dm_s ); it.current(); ++it ) openDataModel( studyName(), it.current() ); - // this will build a SUIT_DataObject-s tree under myRoot member field // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step // but tree that corresponds to not-loaded data models will be updated any way. @@ -59,27 +78,6 @@ bool LightApp_Study::openDocument( const QString& theFileName ) bool res = CAM_Study::openDocument( theFileName ); emit opened( this ); - - return res; -} - -//======================================================================= -// name : saveDocumentAs -/*! Purpose : Save document */ -//======================================================================= -bool LightApp_Study::saveDocumentAs( const QString& theFileName ) -{ - ModelList list; dataModels( list ); - - LightApp_DataModel* aModel = (LightApp_DataModel*)list.first(); - for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) - aModel->saveAs( theFileName, this ); - - bool res = CAM_Study::saveDocumentAs( theFileName );//SRN: BugID IPAL9377, removed usage of uninitialized variable - - if ( res ) - emit saved( this ); - return res; } @@ -89,6 +87,10 @@ bool LightApp_Study::saveDocumentAs( const QString& theFileName ) //======================================================================= bool LightApp_Study::loadDocument( const QString& theStudyName ) { + myDriver->ClearDriverContents(); + if( !openStudyData(theStudyName)) + return false; + setRoot( new LightApp_RootObject( this ) ); // create myRoot //SRN: BugID IPAL9021, put there the same code as in a method openDocument @@ -96,6 +98,7 @@ bool LightApp_Study::loadDocument( const QString& theStudyName ) // update loaded data models: call open() and update() on them. ModelList dm_s; dataModels( dm_s ); + for ( ModelListIterator it( dm_s ); it.current(); ++it ) openDataModel( studyName(), it.current() ); @@ -110,21 +113,58 @@ bool LightApp_Study::loadDocument( const QString& theStudyName ) return res; } +//======================================================================= +// name : saveDocumentAs +/*! Purpose : Save document */ +//======================================================================= +bool LightApp_Study::saveDocumentAs( const QString& theFileName ) +{ + ModelList list; dataModels( list ); + + LightApp_DataModel* aModel = (LightApp_DataModel*)list.first(); + + myDriver->ClearDriverContents(); + QStringList listOfFiles; + for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) { + listOfFiles.clear(); + aModel->saveAs( theFileName, this, listOfFiles ); + if ( !listOfFiles.isEmpty() ) + saveModuleData(aModel->module()->name(), listOfFiles); + } + + bool res = saveStudyData(theFileName); + res = res && CAM_Study::saveDocumentAs( theFileName ); + //SRN: BugID IPAL9377, removed usage of uninitialized variable + if ( res ) + emit saved( this ); + + return res; +} + //======================================================================= // name : saveDocument /*! Purpose : Save document */ //======================================================================= -void LightApp_Study::saveDocument() +bool LightApp_Study::saveDocument() { ModelList list; dataModels( list ); LightApp_DataModel* aModel = (LightApp_DataModel*)list.first(); - for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) - aModel->save(); - CAM_Study::saveDocument(); + myDriver->ClearDriverContents(); + QStringList listOfFiles; + for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) { + listOfFiles.clear(); + aModel->save( listOfFiles ); + saveModuleData(aModel->module()->name(), listOfFiles); + } + + bool res = saveStudyData(studyName()); + res = res && CAM_Study::saveDocument(); + if (res) + emit saved( this ); - emit saved( this ); + return res; } //================================================================ @@ -146,7 +186,7 @@ void LightApp_Study::closeDocument(bool permanently) //================================================================ bool LightApp_Study::isModified() const { - bool isAnyChanged = false; + bool isAnyChanged = CAM_Study::isModified(); ModelList list; dataModels( list ); LightApp_DataModel* aModel = 0; @@ -164,7 +204,7 @@ bool LightApp_Study::isModified() const //================================================================ bool LightApp_Study::isSaved() const { - bool isAllSaved = false; + bool isAllSaved = CAM_Study::isSaved(); ModelList list; dataModels( list ); LightApp_DataModel* aModel = 0; @@ -176,41 +216,152 @@ bool LightApp_Study::isSaved() const return isAllSaved; } +//======================================================================= +// name : saveModuleData +/*! Purpose : Create SComponent for module, necessary for SalomeApp study */ +//======================================================================= +void LightApp_Study::addComponent(const CAM_DataModel* dm) +{ +} + +//======================================================================= +// name : saveModuleData +/*! Purpose : save list file for module 'theModuleName' */ +//======================================================================= +void LightApp_Study::saveModuleData(QString theModuleName, QStringList theListOfFiles) +{ + int aNb = theListOfFiles.count(); + if ( aNb == 0 ) + return; + + std::vector aListOfFiles ( aNb ); + int anIndex = 0; + for ( QStringList::Iterator it = theListOfFiles.begin(); it != theListOfFiles.end(); ++it ) { + if ( (*it).isEmpty() ) + continue; + aListOfFiles[anIndex] = (*it).latin1(); + anIndex++; + } + myDriver->SetListOfFiles(theModuleName, aListOfFiles); +} + +//======================================================================= +// name : openModuleData +/*! Purpose : gets list of file for module 'theModuleNam' */ +//======================================================================= +void LightApp_Study::openModuleData(QString theModuleName, QStringList& theListOfFiles) +{ + std::vector aListOfFiles = myDriver->GetListOfFiles(theModuleName); + int i, aLength = aListOfFiles.size() - 1; + if (aLength < 0) + return; + + //Get a temporary directory for saved a file + theListOfFiles.append(aListOfFiles[0].c_str()); + for(i = 0; i < aLength; i++) + theListOfFiles.append(aListOfFiles[i+1].c_str()); +} + +//======================================================================= +// name : saveStudyData +/*! Purpose : save data from study */ +//======================================================================= +bool LightApp_Study::saveStudyData( const QString& theFileName ) +{ + ModelList list; dataModels( list ); + SUIT_ResourceMgr* resMgr = application()->resourceMgr(); + if( !resMgr ) + return false; + bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ); + + bool aRes = myDriver->SaveDatasInFile(theFileName.latin1(), isMultiFile); + // clear map + std::vector aList(0); + for ( ModelListIterator it( list ); it.current(); ++it ) + myDriver->SetListOfFiles(it.current()->module()->name(), aList); + + return aRes; +} + +//======================================================================= +// name : openStudyData +/*! Purpose : open data for study */ +//======================================================================= +bool LightApp_Study::openStudyData( const QString& theFileName ) +{ + SUIT_ResourceMgr* resMgr = application()->resourceMgr(); + if( !resMgr ) + return false; + bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ); + + bool aRes = myDriver->ReadDatasFromFile(theFileName.latin1(), isMultiFile); + return aRes; +} + //================================================================ -// Function : GetListOfFiles +// Function : openDataModel +/*! Purpose : Open data model */ +//================================================================ +bool LightApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm ) +{ + if (!dm) + return false; + + QStringList listOfFiles; + openModuleData(dm->module()->name(), listOfFiles); + if (dm && dm->open(studyName, this, listOfFiles)) { + // Remove the files and temporary directory, created + // for this module by LightApp_Driver::OpenStudyData() + bool isMultiFile = false; // TODO: decide, how to access this parameter + RemoveTemporaryFiles( dm->module()->name(), isMultiFile ); + + // Something has been read -> create data model tree + LightApp_DataModel* aDM = dynamic_cast( dm ); + if ( aDM ) + aDM->update(NULL, this); + return true; + } + return false; +} + +//================================================================ +// Function : GetTmpDir /*! Purpose : to be used by modules*/ //================================================================ -std::vector LightApp_Study::GetListOfFiles() const +std::string LightApp_Study::GetTmpDir (const char* theURL, + const bool isMultiFile) { - std::vector aListOfFiles; - return aListOfFiles; + return myDriver->GetTmpDir(theURL, isMultiFile); } //================================================================ -// Function : SetListOfFiles +// Function : GetListOfFiles /*! Purpose : to be used by modules*/ //================================================================ -void LightApp_Study::SetListOfFiles (const std::vector theListOfFiles) +std::vector LightApp_Study::GetListOfFiles(const char* theModuleName) const { + std::vector aListOfFiles; + aListOfFiles = myDriver->GetListOfFiles(theModuleName); + return aListOfFiles; } //================================================================ -// Function : GetTmpDir +// Function : SetListOfFiles /*! Purpose : to be used by modules*/ //================================================================ -std::string LightApp_Study::GetTmpDir (const char* theURL, - const bool isMultiFile) +void LightApp_Study::SetListOfFiles (const char* theModuleName, const std::vector theListOfFiles) { - std::string aTmpDir = ""; - return aTmpDir; + myDriver->SetListOfFiles(theModuleName, theListOfFiles); } //================================================================ // Function : RemoveTemporaryFiles -/*! Purpose : to be used by CORBAless modules*/ +/*! Purpose : to be used by modules*/ //================================================================ -void LightApp_Study::RemoveTemporaryFiles (const bool isMultiFile) const +void LightApp_Study::RemoveTemporaryFiles (const char* theModuleName, const bool isMultiFile) const { if (isMultiFile) return; + bool isDirDeleted = true; + myDriver->RemoveTemporaryFiles(theModuleName, isDirDeleted); } diff --git a/src/LightApp/LightApp_Study.h b/src/LightApp/LightApp_Study.h index f60a763cc..403b1c2b2 100644 --- a/src/LightApp/LightApp_Study.h +++ b/src/LightApp/LightApp_Study.h @@ -2,8 +2,10 @@ #define LIGHTAPP_STUDY_H #include "LightApp.h" +#include "LightApp_Driver.h" #include "CAM_Study.h" +#include "CAM_DataModel.h" #include "SUIT_Study.h" #include "string.h" @@ -26,33 +28,44 @@ public: virtual void createDocument(); virtual bool openDocument( const QString& ); + virtual bool loadDocument( const QString& ); - virtual void saveDocument(); + virtual bool saveDocument(); virtual bool saveDocumentAs( const QString& ); - virtual bool loadDocument( const QString& ); virtual void closeDocument(bool permanently = true); virtual bool isSaved() const; virtual bool isModified() const; - /** @name methods to be used by modules*/ - //@{ - virtual std::vector GetListOfFiles () const; - virtual void SetListOfFiles (const std::vector theListOfFiles); + virtual void addComponent ( const CAM_DataModel* dm); + + virtual std::string GetTmpDir ( const char* theURL, const bool isMultiFile ); + +protected: + virtual void saveModuleData ( QString theModuleName, QStringList theListOfFiles ); + virtual void openModuleData ( QString theModuleName, QStringList& theListOfFiles ); + virtual bool saveStudyData ( const QString& theFileName ); + virtual bool openStudyData ( const QString& theFileName ); - virtual std::string GetTmpDir (const char* theURL, - const bool isMultiFile); + virtual std::vector GetListOfFiles ( const char* theModuleName ) const; + virtual void SetListOfFiles ( const char* theModuleName, + const std::vector theListOfFiles ); - virtual void RemoveTemporaryFiles (const bool isMultiFile) const; - //@} - // END: methods to be used by modules + virtual void RemoveTemporaryFiles ( const char* theModuleName, const bool isMultiFile ) const; + +protected: + virtual bool openDataModel ( const QString&, CAM_DataModel* ); signals: - void saved( SUIT_Study* ); - void opened( SUIT_Study* ); - void closed( SUIT_Study* ); + void saved ( SUIT_Study* ); + void opened ( SUIT_Study* ); + void closed ( SUIT_Study* ); void created( SUIT_Study* ); + + +private: + LightApp_Driver* myDriver; }; #endif diff --git a/src/LightApp/LightApp_SwitchOp.cxx b/src/LightApp/LightApp_SwitchOp.cxx index 305d186a1..4232ced87 100755 --- a/src/LightApp/LightApp_SwitchOp.cxx +++ b/src/LightApp/LightApp_SwitchOp.cxx @@ -1,5 +1,5 @@ /** -* SALOME LightApp +* LIGHT LightApp * * Copyright (C) 2005 CEA/DEN, EDF R&D * @@ -7,7 +7,7 @@ * * File : LightApp_SwitchOp.h * Author : Sergey LITONIN -* Module : SALOME +* Module : LIGHT */ #include "LightApp_SwitchOp.h" diff --git a/src/LightApp/LightApp_SwitchOp.h b/src/LightApp/LightApp_SwitchOp.h index d635f81b5..ac1850e30 100755 --- a/src/LightApp/LightApp_SwitchOp.h +++ b/src/LightApp/LightApp_SwitchOp.h @@ -1,5 +1,5 @@ /** -* SALOME SalomeApp +* LIGHT LightApp * * Copyright (C) 2005 CEA/DEN, EDF R&D * @@ -7,7 +7,7 @@ * * File : LightApp_SwitchOp.h * Author : Sergey LITONIN -* Module : SALOME +* Module : LIGHT */ diff --git a/src/LightApp/LightApp_UpdateFlags.h b/src/LightApp/LightApp_UpdateFlags.h index f7a0f9d06..2fc7fa780 100755 --- a/src/LightApp/LightApp_UpdateFlags.h +++ b/src/LightApp/LightApp_UpdateFlags.h @@ -1,4 +1,4 @@ -// SALOME LightApp +// LIGHT LightApp // // Copyright (C) 2005 CEA/DEN, EDF R&D // @@ -6,7 +6,7 @@ // // File : LightApp_UpdateFlags.h // Author : Sergey LITONIN -// Module : SALOME +// Module : LIGHT #ifndef LightApp_UpdateFlags_H diff --git a/src/LightApp/LightApp_VTKSelector.cxx b/src/LightApp/LightApp_VTKSelector.cxx index 4b0a8b1cf..93708458b 100644 --- a/src/LightApp/LightApp_VTKSelector.cxx +++ b/src/LightApp/LightApp_VTKSelector.cxx @@ -78,7 +78,7 @@ LightApp_VTKSelector } /*! - Gets type of salome vtk viewer. + Gets type of vtk viewer. */ QString LightApp_VTKSelector diff --git a/src/LightApp/LightApp_VTKSelector.h b/src/LightApp/LightApp_VTKSelector.h index 82c29f643..da3edd170 100644 --- a/src/LightApp/LightApp_VTKSelector.h +++ b/src/LightApp/LightApp_VTKSelector.h @@ -50,7 +50,7 @@ class LightApp_SVTKDataOwner : public LightApp_DataOwner /*! - Provide salome vtk selection of data owners. + Provide vtk selection of data owners. */ class LIGHTAPP_EXPORT LightApp_VTKSelector : public SUIT_Selector { diff --git a/src/LightApp/Makefile.in b/src/LightApp/Makefile.in index db57aa765..d6e6cd096 100755 --- a/src/LightApp/Makefile.in +++ b/src/LightApp/Makefile.in @@ -20,6 +20,7 @@ EXPORT_HEADERS= LightApp.h \ LightApp_DataOwner.h \ LightApp_DataSubOwner.h \ LightApp_Dialog.h \ + LightApp_Driver.h \ LightApp_GLSelector.h \ LightApp_Module.h \ LightApp_ModuleDlg.h \ @@ -53,6 +54,7 @@ LIB_SRC= LightApp_AboutDlg.cxx \ LightApp_DataOwner.cxx \ LightApp_DataSubOwner.cxx \ LightApp_Dialog.cxx \ + LightApp_Driver.cxx \ LightApp_GLSelector.cxx \ LightApp_Module.cxx \ LightApp_ModuleDlg.cxx \ @@ -74,6 +76,7 @@ LIB_MOC = LightApp_AboutDlg.h \ LightApp_Application.h \ LightApp_DataModel.h \ LightApp_Dialog.h \ + LightApp_Driver.h \ LightApp_GLSelector.h \ LightApp_OBSelector.h \ LightApp_OCCSelector.h \