#include "LightApp_Preferences.h"
#include "LightApp_WidgetContainer.h"
#include "LightApp_SelectionMgr.h"
+#include "LightApp_NameDlg.h"
#include "STD_LoadStudiesDlg.h"
SUIT_Desktop* desk = desktop();
+ //! Save GUI state
+ createAction( SaveGUIStateId, tr( "TOT_DESK_FILE_SAVE_GUI_STATE" ), QIconSet(),
+ tr( "MEN_DESK_FILE_SAVE_GUI_STATE" ), tr( "PRP_DESK_FILE_SAVE_GUI_STATE" ),
+ 0, desk, false, this, SLOT( onSaveGUIState() ) );
+
//! Dump study
createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
+ createMenu( SaveGUIStateId, fileMenu, 10, -1 );
createMenu( DumpStudyId, fileMenu, 10, -1 );
createMenu( separator(), fileMenu, -1, 15, -1 );
createMenu( LoadScriptId, fileMenu, 10, -1 );
if ( a )
a->setEnabled( activeStudy() );
+ // Properties menu
a = action( PropertiesId );
if( a )
a->setEnabled( activeStudy() );
+ // Save GUI state menu
+ a = action( SaveGUIStateId );
+ if( a )
+ a->setEnabled( activeStudy() );
+
// update state of Copy/Paste menu items
onSelectionChanged();
}
}
}
+/*!Private SLOT. On save GUI state.*/
+void SalomeApp_Application::onSaveGUIState()
+{
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if ( !appStudy ) return;
+
+ SalomeApp_VisualState( this ).storeState();
+ updateObjectBrowser( false );
+}
+
/*!Gets file filter.
*\retval QString "(*.hdf)"
*/
LightApp_SelectionMgr* mgr = selectionMgr();
mgr->selectedObjects( aList, QString::null, false );
+ // add GUI state commands: restore, rename
+ if ( aList.Extent() == 1 && aList.First()->hasEntry() &&
+ QString( aList.First()->getEntry() ).startsWith( tr( "SAVE_POINT_DEF_NAME" ) ) ) {
+ thePopup->insertSeparator();
+ thePopup->insertItem( tr( "MEN_RESTORE_VS" ), this, SLOT( onRestoreGUIState() ) );
+ thePopup->insertItem( tr( "MEN_RENAME_VS" ), this, SLOT( onRenameGUIState() ) );
+ thePopup->insertItem( tr( "MEN_DELETE_VS" ), this, SLOT( onDeleteGUIState() ) );
+ }
+
// "Delete reference" item should appear only for invalid references
// isInvalidRefs will be true, if at least one of selected objects is invalid reference
if (aList.Extent() != 1)
return;
Handle(SALOME_InteractiveObject) aIObj = aList.First();
+ // check if item is a "GUI state" item (also a first level object)
+ QString entry( aIObj->getEntry() );
+ if ( entry.startsWith( tr( "SAVE_POINT_DEF_NAME" ) ) )
+ return;
QString aModuleName(aIObj->getComponentDataType());
QString aModuleTitle = moduleTitle(aModuleName);
CAM_Module* currentModule = activeModule();
thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
}
+/*! updateSavePointDataObjects: syncronize data objects that correspond to save points (gui states)*/
+void updateSavePointDataObjects( OB_Browser* ob, SalomeApp_Study* study )
+{
+ if ( !study || !ob )
+ return;
+
+ // find GUI states root object
+ SUIT_DataObject* guiRootObj = 0;
+ DataObjectList ch;
+ study->root()->children( ch );
+ DataObjectList::const_iterator it = ch.begin(), last = ch.end();
+ for ( ; it != last ; ++it ) {
+ if ( dynamic_cast<SalomeApp_SavePointRootObject*>( *it ) )
+ guiRootObj = *it;
+ }
+ std::vector<int> savePoints = study->getSavePoints();
+ // case 1: no more save points but they existed in study's tree
+ if ( savePoints.empty() && guiRootObj ) {
+ delete guiRootObj;
+ return;
+ }
+ // case 2: no more save points but root does not exist either
+ if ( savePoints.empty() && !guiRootObj )
+ return;
+ // case 3: save points but no root for them - create it
+ if ( !savePoints.empty() && !guiRootObj )
+ guiRootObj = new SalomeApp_SavePointRootObject( study->root() );
+ // case 4: everything already exists.. nothing to do..
+
+ // store data objects in a map id-to-DataObject
+ QMap<int,SalomeApp_SavePointObject*> mapDO;
+ ch.clear();
+ guiRootObj->children( ch );
+ for( it = ch.begin(), last = ch.end(); it != last ; ++it ) {
+ SalomeApp_SavePointObject* dobj = dynamic_cast<SalomeApp_SavePointObject*>( *it );
+ if ( dobj )
+ mapDO[dobj->getId()] = dobj;
+ }
+
+ // iterate new save points. if DataObject with such ID not found in map - create DataObject
+ // if in the map - remove it from map.
+ for ( int i = 0; i < savePoints.size(); i++ )
+ if ( !mapDO.contains( savePoints[i] ) )
+ new SalomeApp_SavePointObject( guiRootObj, savePoints[i], study );
+ else {
+ ob->updateTree( mapDO[ savePoints[i] ] );
+ mapDO.remove( savePoints[i] );
+ }
+ // delete DataObjects that are still in the map -- their IDs were not found in data model
+ for ( QMap<int,SalomeApp_SavePointObject*>::Iterator it = mapDO.begin(); it != mapDO.end(); ++it )
+ delete it.data();
+}
+
/*!Update obect browser:
1.if 'updateModels' true, update existing data models;
2. update "non-existing" (not loaded yet) data models;
- 3. update object browser if it existing */
+ 3. update object browser if it exists */
void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
{
// update "non-existing" (not loaded yet) data models
_PTR(SComponent) aComponent ( it->Value() );
if ( aComponent->ComponentDataType() == "Interface Applicative" )
- continue; // skip the magic "Interface Applicative" component
+ continue;
OB_Browser* ob = static_cast<OB_Browser*>( getWindow( WT_ObjectBrowser ));
const bool isAutoUpdate = ob->isAutoUpdate();
//SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
}
}
+ // create data objects that correspond to GUI state save points
+ ::updateSavePointDataObjects( objectBrowser(), study );
}
-
// update existing data models (already loaded SComponents)
LightApp_Application::updateObjectBrowser( updateModels );
-/* if ( objectBrowser() )
- {
- objectBrowser()->updateGeometry();
- objectBrowser()->updateTree();
- }*/
+ // -- debug --
+ // if ( study && study->root() )
+ // study->root()->dump();
}
/*!Display Catalog Genenerator dialog */
{
return createViewManager(type);
}
+
+
+/*!Global utility funciton, returns selected GUI Save point object's ID */
+int getSelectedSavePoint( const LightApp_SelectionMgr* selMgr )
+{
+ SALOME_ListIO aList;
+ selMgr->selectedObjects( aList );
+ Handle(SALOME_InteractiveObject) aIObj = aList.First();
+ QString entry( aIObj->getEntry() );
+ QString startStr = QObject::tr( "SAVE_POINT_DEF_NAME" );
+ if ( !entry.startsWith( startStr ) ) // it's a "GUI state" object
+ return -1;
+ bool ok; // conversion to integer is ok?
+ int savePoint = entry.right( entry.length() - startStr.length() ).toInt( &ok );
+ return ok ? savePoint : -1;
+}
+
+/*!Called on Restore GUI State popup command*/
+void SalomeApp_Application::onRestoreGUIState()
+{
+ int savePoint = ::getSelectedSavePoint( selectionMgr() );
+ if ( savePoint == -1 )
+ return;
+ SalomeApp_VisualState( this ).restoreState( savePoint );
+}
+
+/*!Called on Rename GUI State popup command*/
+void SalomeApp_Application::onRenameGUIState()
+{
+ int savePoint = ::getSelectedSavePoint( selectionMgr() );
+ if ( savePoint == -1 )
+ return;
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if ( !study )
+ return;
+
+ QString newName = LightApp_NameDlg::getName( desktop(), study->getNameOfSavePoint( savePoint ) );
+ if ( !newName.isNull() && !newName.isEmpty() ) {
+ study->setNameOfSavePoint( savePoint, newName );
+ updateSavePointDataObjects( objectBrowser(), study );
+ }
+}
+
+
+/*!Called on Delete GUI State popup command*/
+void SalomeApp_Application::onDeleteGUIState()
+{
+ int savePoint = ::getSelectedSavePoint( selectionMgr() );
+ if ( savePoint == -1 )
+ return;
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if ( !study )
+ return;
+
+ study->removeSavePoint( savePoint );
+ updateSavePointDataObjects( objectBrowser(), study );
+}
+
+/*!Called on Save study operation*/
+void SalomeApp_Application::onStudySaved( SUIT_Study* study )
+{
+ updateObjectBrowser( false );
+ LightApp_Application::onStudySaved( study );
+}
+
public:
enum { DumpStudyId = LightApp_Application::UserID, LoadScriptId, PropertiesId,
- CatalogGenId, RegDisplayId, UserID };
+ CatalogGenId, RegDisplayId, SaveGUIStateId, UserID };
public:
SalomeApp_Application();
virtual void onCopy();
virtual void onPaste();
+protected slots:
+ void onStudySaved( SUIT_Study* );
+
protected:
virtual void createActions();
virtual SUIT_Study* createNewStudy();
void onProperties();
void onDumpStudy();
void onLoadScript();
+ void onSaveGUIState();
+ void onDeleteGUIState();
void onCatalogGen();
void onRegDisplay();
void onOpenWith();
+ void onRestoreGUIState();
+ void onRenameGUIState();
};
#ifdef WIN32
SalomeApp_DataModelSync sync( study->studyDS(), study->root() );
- // QString srcName = sobj ? sobj->GetName().c_str() : "";
- // QString trgName = ( suitObj && !suitObj->name().isNull() ) ? suitObj->name() : "";
- // printf( "--- SalomeApp_DataModel::syncronize() calls synchronize()_1: src = %s, trg = %s ---\n", srcName.latin1(), trgName.latin1() );
-
- SUIT_DataObject* o = ::synchronize<kerPtr,suitPtr,SalomeApp_DataModelSync>( sobj, suitObj, sync );
-// showTree( o );
- return o;
-}
-
-//================================================================
-// Function : synchronize
-/*! Purpose : synchronizes kernel tree and suit data tree starting from 'sobj' and 'obj' correspondly */
-//================================================================
-SUIT_DataObject* SalomeApp_DataModel::synchronize( const _PTR( SObject )& sobj, SUIT_DataObject* obj,
- SalomeApp_Study* study )
-{
- if( !study )
- return 0;
- SalomeApp_DataModelSync sync( study->studyDS(), study->root() );
-
- // QString srcName = sobj ? sobj->GetName().c_str() : "";
- // QString trgName = ( obj && !obj->name().isNull() ) ? obj->name() : "";
- // printf( "--- SalomeApp_DataModel::syncronize() calls synchronize()_2: src = s, trg = %s ---\n", srcName.latin1(), trgName.latin1() );
-
- return ::synchronize<kerPtr,suitPtr,SalomeApp_DataModelSync>( sobj, obj, sync );
+ return ::synchronize<kerPtr,suitPtr,SalomeApp_DataModelSync>( sobj, suitObj, sync );
}
//================================================================
public:
static SUIT_DataObject* synchronize( const _PTR( SComponent )&, SalomeApp_Study* );
- static SUIT_DataObject* synchronize( const _PTR( SObject )&, SUIT_DataObject*, SalomeApp_Study* );
- SalomeApp_DataModel ( CAM_Module* theModule );
- virtual ~SalomeApp_DataModel();
+ SalomeApp_DataModel ( CAM_Module* theModule );
+ virtual ~SalomeApp_DataModel();
virtual bool open( const QString&, CAM_Study*, QStringList );
virtual bool create( CAM_Study* );
#include "SalomeApp_Study.h"
#include "LightApp_RootObject.h"
+#include <CAM_DataObject.h>
+
#include <SUIT_Application.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_DataObjectKey.h>
return SalomeApp_DataObject::name();
}
+/*
+ Class: SalomeApp_SavePointObject
+ Level: Public
+*/
+
+/*!Constructor.Initialize by \a parent.*/
+SalomeApp_SavePointObject::SalomeApp_SavePointObject( SUIT_DataObject* _parent, const int id, SalomeApp_Study* study )
+ : LightApp_DataObject( _parent ), CAM_DataObject( _parent ), // IMPORTANT TO CALL ALL VIRTUAL CONSTRUCTORS!
+ myId( id ),
+ myStudy( study )
+{
+}
+
+/*!Destructor. Do nothing.*/
+SalomeApp_SavePointObject::~SalomeApp_SavePointObject()
+{
+}
+
+/*!Returns save points ID */
+int SalomeApp_SavePointObject::getId() const
+{
+ return myId;
+}
+
+/*!Returns "invalid" entry, which does not correspond to any object in data structure
+ but indicates that it is a save point object */
+QString SalomeApp_SavePointObject::entry() const
+{
+ return QObject::tr( "SAVE_POINT_DEF_NAME" ) + QString::number( myId );
+}
+
+/*!Returns displayed name of object */
+QString SalomeApp_SavePointObject::name() const
+{
+ return myStudy->getNameOfSavePoint( myId );
+}
+
+QPixmap SalomeApp_SavePointObject::icon() const
+{
+ return QPixmap();
+}
+
+QString SalomeApp_SavePointObject::toolTip() const
+{
+ return QObject::tr( "SAVE_POINT_OBJECT_TOOLTIP" ).arg( name() );
+}
+
SalomeApp_ModuleObject( CAM_DataModel*, const _PTR(SObject)&, SUIT_DataObject* = 0 );
virtual ~SalomeApp_ModuleObject();
- virtual QString name() const;
+ virtual QString name() const;
+};
+
+/*!
+ * SalomeApp_SavePointObject - class that represents persistent visual_state object
+ * these objects are stored in data model, but NOT in SObjects structure, so we
+ * must handle them separately using this special class for them
+ */
+
+class SALOMEAPP_EXPORT SalomeApp_SavePointObject : public virtual LightApp_DataObject
+{
+public:
+ SalomeApp_SavePointObject( SUIT_DataObject* parent, const int, SalomeApp_Study* study );
+ virtual ~SalomeApp_SavePointObject();
+
+ virtual QString entry() const;
+
+ virtual QString name() const;
+ virtual QPixmap icon() const;
+ virtual QString toolTip() const;
+
+ int getId() const;
+
+private:
+ int myId;
+ SalomeApp_Study* myStudy;
+};
+
+/*!
+ * SalomeApp_SavePointRootObject - class that represents parent object for visual_state objects
+ */
+
+class SALOMEAPP_EXPORT SalomeApp_SavePointRootObject : public SUIT_DataObject
+{
+public:
+ SalomeApp_SavePointRootObject( SUIT_DataObject* parent ) : SUIT_DataObject( parent ) {}
+
+ virtual QString name() const { return QObject::tr( "SAVE_POINT_ROOT_NAME" ); }
+ virtual QString toolTip() const{ return QObject::tr( "SAVE_POINT_ROOT_TOOLTIP" ); }
};
#endif
emit opened( this );
study->IsSaved(true);
- std::vector<int> savePoints = getSavePoints();
- if ( savePoints.size() > 0 ) //############### VISUAL PARAMETERS
- SalomeApp_VisualState( (SalomeApp_Application*)application() ).restoreState( savePoints[savePoints.size()-1] );
-
+ bool restore = application()->resourceMgr()->booleanValue( "Study", "store_visual_state", true );
+ if ( restore ) {
+ std::vector<int> savePoints = getSavePoints();
+ if ( savePoints.size() > 0 )
+ SalomeApp_VisualState( (SalomeApp_Application*)application() ).restoreState( savePoints[savePoints.size()-1] );
+ }
return res;
}
bool res = CAM_Study::openDocument( theStudyName );
emit opened( this );
+ bool restore = application()->resourceMgr()->booleanValue( "Study", "store_visual_state", true );
+ if ( restore ) {
+ std::vector<int> savePoints = getSavePoints();
+ if ( savePoints.size() > 0 )
+ SalomeApp_VisualState( (SalomeApp_Application*)application() ).restoreState( savePoints[savePoints.size()-1] );
+ }
+
//SRN: BugID IPAL9021: End
return res;
//=======================================================================
bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
{
- //############### VISUAL PARAMETERS
- SalomeApp_VisualState( (SalomeApp_Application*)application() ).storeState();
+ bool store = application()->resourceMgr()->booleanValue( "Study", "store_visual_state", true );
+ if ( store )
+ SalomeApp_VisualState( (SalomeApp_Application*)application() ).storeState();
ModelList list; dataModels( list );
//=======================================================================
bool SalomeApp_Study::saveDocument()
{
- //############### VISUAL PARAMETERS
- SalomeApp_VisualState( (SalomeApp_Application*)application() ).storeState();
+ bool store = application()->resourceMgr()->booleanValue( "Study", "store_visual_state", true );
+ if ( store )
+ SalomeApp_VisualState( (SalomeApp_Application*)application() ).storeState();
ModelList list; dataModels( list );
//================================================================
int SalomeApp_VisualState::storeState()
{
- bool store = myApp->resourceMgr()->booleanValue( "Study", "store_visual_state", true );
- if ( !store )
- return -1;
-
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
if ( !study )
return -1;
sModule->storeVisualParameters( savePoint );
}
}
+
+ // set default name of new savePoint
+ study->setNameOfSavePoint( savePoint, QObject::tr( "SAVE_POINT_DEF_NAME" ) + QString::number( savePoint ) );
return savePoint;
}
//================================================================
void SalomeApp_VisualState::restoreState(int savePoint)
{
- bool store = myApp->resourceMgr()->booleanValue( "Study", "store_visual_state", true );
- if ( !store )
- return;
-
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
if ( !study )
return;
msgid "SalomeApp_Application::PRP_DESK_FILE_DUMP_STUDY"
msgstr "Dumps study to the python script"
+msgid "SalomeApp_Application::TOT_DESK_FILE_SAVE_GUI_STATE"
+msgstr "Save GUI state"
+
+msgid "SalomeApp_Application::MEN_DESK_FILE_SAVE_GUI_STATE"
+msgstr "Save GUI state..."
+
+msgid "SalomeApp_Application::PRP_DESK_FILE_SAVE_GUI_STATE"
+msgstr "Saves current state of viewers, displayed objects, etc."
+
msgid "SalomeApp_Application::TOT_DESK_FILE_LOAD_SCRIPT"
msgstr "Load python script"
msgstr "Delete Invalid Reference"
msgid "SalomeApp_Application::PREF_STORE_VISUAL_STATE"
-msgstr "Store visual parameters"
+msgstr "Store/restore last GUI state"
//=======================================================================================
msgstr "Publish in study"
msgid "SAVE_GUI_STATE"
-msgstr "Store current GUI state"
+msgstr "Save GUI state"
//=======================================================================================
msgid "SalomeApp_Application::WRN_DUMP_STUDY_FAILED"
msgstr "Dump study failed"
+msgid "SAVE_POINT_OBJECT_TOOLTIP"
+msgstr "Saved GUI state: %1"
+
+msgid "SAVE_POINT_DEF_NAME"
+msgstr "GUI state: "
+
+msgid "SAVE_POINT_ROOT_TOOLTIP"
+msgstr "Persistent GUI states"
+
+msgid "SAVE_POINT_ROOT_NAME"
+msgstr "GUI states"
+
+//=======================================================================================
+
+msgid "SalomeApp_Application::MEN_RESTORE_VS"
+msgstr "Restore"
+
+msgid "SalomeApp_Application::MEN_RENAME_VS"
+msgstr "Rename"
+
+msgid "SalomeApp_Application::MEN_DELETE_VS"
+msgstr "Delete"