From: ptv Date: Wed, 17 Nov 2010 08:32:44 +0000 (+0000) Subject: 0020830: EDF 1357 GUI : Hide/Show Icon X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2f6e611b93cb1346558e0467e229a28e52a7d3f3;p=modules%2Fgui.git 0020830: EDF 1357 GUI : Hide/Show Icon --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 8ad007ba5..24dea7174 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -132,6 +132,11 @@ #include #endif +#ifndef DISABLE_SALOMEOBJECT + #include + #include +#endif + //#ifndef DISABLE_SUPERVGRAPHVIEWER // #include // #include @@ -3425,3 +3430,13 @@ void LightApp_Application::onPaste() if( m ) m->paste(); } + +#ifndef DISABLE_SALOMEOBJECT +/*! + Update visibility state of given objects + */ +void LightApp_Application::updateVisibilityState( DataObjectList& /*theList*/, + SALOME_View* /*theView*/ ) +{ +} +#endif diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 4561c4d77..1142b739c 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -50,6 +50,11 @@ class SUIT_Study; class SUIT_Accel; class CAM_Module; +#ifndef DISABLE_SALOMEOBJECT +class SALOME_View; +#include +#endif + class QString; class QWidget; class QStringList; @@ -157,6 +162,12 @@ public: //! Removes ViewManagers only of known type virtual void clearKnownViewManagers(); +#ifndef DISABLE_SALOMEOBJECT + //! update visibility state of objects + virtual void updateVisibilityState( DataObjectList& theList, + SALOME_View* theView ); +#endif + signals: void studyOpened(); void studySaved(); diff --git a/src/LightApp/LightApp_DataObject.cxx b/src/LightApp/LightApp_DataObject.cxx index 804bbc214..789c42189 100644 --- a/src/LightApp/LightApp_DataObject.cxx +++ b/src/LightApp/LightApp_DataObject.cxx @@ -29,6 +29,7 @@ #include #include +#include #include @@ -269,6 +270,24 @@ bool LightApp_DataObject::compare( const QVariant& left, const QVariant& right, return CAM_DataObject::compare( left, right, id ); } +/*! + \brief Constructor. + \param theRoot - main parent object + \param theMap - map of entry-object relation +*/ +void LightApp_DataObject::FillEntryObjMap( SUIT_DataObject* theRoot, + LightApp_EntryObjMap& theMap ) +{ + if (!theRoot) + return; + SUIT_DataObjectIterator it( theRoot, SUIT_DataObjectIterator::DepthLeft ); + for ( ; it.current(); ++it ) { + LightApp_DataObject* obj = dynamic_cast( it.current() ); + if ( obj ) + theMap.insert( obj->entry(), obj ); + } +} + /*! \class LightApp_ModuleObject \brief Used for optimized access to the data model from the data objects. diff --git a/src/LightApp/LightApp_DataObject.h b/src/LightApp/LightApp_DataObject.h index 3b8bb9cc1..c6f5cf7fd 100644 --- a/src/LightApp/LightApp_DataObject.h +++ b/src/LightApp/LightApp_DataObject.h @@ -28,9 +28,14 @@ #include "LightApp.h" #include +#include class CAM_DataModel; class LightApp_Study; +class LightApp_DataObject; + +//! entry - data object relationship map +typedef QMap LightApp_EntryObjMap; class LIGHTAPP_EXPORT LightApp_DataObject : public virtual CAM_DataObject { @@ -58,6 +63,10 @@ public: virtual bool compare( const QVariant&, const QVariant&, const int = NameId ) const; virtual int groupId() const; + static void FillEntryObjMap( SUIT_DataObject* theRoot, + LightApp_EntryObjMap& theMap ); + + protected: QString myCompDataType; SUIT_DataObject* myCompObject; diff --git a/src/LightApp/LightApp_Displayer.cxx b/src/LightApp/LightApp_Displayer.cxx index afa347975..e2c430af0 100644 --- a/src/LightApp/LightApp_Displayer.cxx +++ b/src/LightApp/LightApp_Displayer.cxx @@ -33,8 +33,10 @@ #include #include +#include #ifndef DISABLE_SALOMEOBJECT - #include "SALOME_InteractiveObject.hxx" +#include +#include #endif /*! @@ -57,24 +59,44 @@ LightApp_Displayer::~LightApp_Displayer() \param updateViewer - is it necessary to update viewer \param theViewFrame - view */ -void LightApp_Displayer::Display( const QString& entry, const bool updateViewer, SALOME_View* theViewFrame ) +void LightApp_Displayer::Display( const QString& entry, const bool updateViewer, + SALOME_View* theViewFrame, const bool updateVisState ) { - SALOME_Prs* prs = buildPresentation( entry, theViewFrame ); - if ( prs ) + QStringList aList; + aList.append( entry ); + Display( aList, updateViewer, theViewFrame, updateVisState ); +} + +/*! + Displays object in view + \param list - object entries + \param updateViewer - is it necessary to update viewer + \param theViewFrame - view +*/ +void LightApp_Displayer::Display( const QStringList& list, const bool updateViewer, + SALOME_View* theViewFrame, const bool updateVisState ) +{ + SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); + QStringList::const_iterator it = list.constBegin(); + for ( ; it != list.constEnd(); ++it) { - SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); - if ( vf ) + SALOME_Prs* prs = buildPresentation( *it, vf ); + if ( prs ) { - vf->BeforeDisplay( this ); - vf->Display( prs ); - vf->AfterDisplay( this ); - - if ( updateViewer ) - vf->Repaint(); + if ( vf ) + { + vf->BeforeDisplay( this ); + vf->Display( prs ); + vf->AfterDisplay( this ); + if ( updateViewer ) + vf->Repaint(); + } delete prs; // delete presentation because displayer is its owner } } + if ( updateVisState ) + updateVisibilityState( list, vf ); } /*! @@ -104,8 +126,8 @@ void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewe SALOME_View* view = dynamic_cast(vmodel); if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) ) { - Erase( entry, true, false, view ); - Display( entry, updateViewer, view ); + Erase( entry, true, false, view, false ); + Display( entry, updateViewer, view, false ); } } } @@ -119,12 +141,34 @@ void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewe \param theViewFrame - view */ void LightApp_Displayer::Erase( const QString& entry, const bool forced, - const bool updateViewer, SALOME_View* theViewFrame ) + const bool updateViewer, + SALOME_View* theViewFrame, const bool updateVisState ) +{ + QStringList aList; + aList.append( entry ); + Erase( aList, forced, updateViewer, theViewFrame, updateVisState ); +} + +/*! + Erases object in view + \param list - object entries + \param forced - deletes object from viewer (otherwise it will be erased, but cached) + \param updateViewer - is it necessary to update viewer + \param theViewFrame - view +*/ +void LightApp_Displayer::Erase( const QStringList& list, const bool forced, + const bool updateViewer, + SALOME_View* theViewFrame, const bool updateVisState ) { SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); - if ( vf ) { - SALOME_Prs* prs = vf->CreatePrs( entry.toLatin1() ); + if ( !vf ) + return; + + QStringList::const_iterator it = list.constBegin(); + for ( ; it != list.constEnd(); ++it) + { + SALOME_Prs* prs = vf->CreatePrs( (*it).toLatin1().data() ); if ( prs ) { vf->Erase( prs, forced ); if ( updateViewer ) @@ -132,6 +176,8 @@ void LightApp_Displayer::Erase( const QString& entry, const bool forced, delete prs; // delete presentation because displayer is its owner } } + if ( updateVisState ) + updateVisibilityState( list, vf ); } /*! @@ -140,7 +186,8 @@ void LightApp_Displayer::Erase( const QString& entry, const bool forced, \param updateViewer - is it necessary to update viewer \param theViewFrame - view */ -void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const +void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, + SALOME_View* theViewFrame, const bool updateVisState ) const { SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); @@ -149,6 +196,69 @@ void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, S if ( updateViewer ) vf->Repaint(); } + if ( updateVisState ) + updateVisibilityState( vf ); +} + +/*! + updte visibility state of all objects + \param theViewFrame - view +*/ +void LightApp_Displayer::updateVisibilityState( SALOME_View* theViewFrame ) const +{ + // this code wrapped by pre-processor directive, becase it works with SALOME_View + // and has no effect in case of SALOMEOBJECT disabled +#ifndef DISABLE_SALOMEOBJECT + SUIT_Session* session = SUIT_Session::session(); + LightApp_Application* app = dynamic_cast(session->activeApplication()); + if (!app) + return; + SUIT_Study* study = app->activeStudy(); + if (!study) + return; + + DataObjectList anObjList; + SUIT_DataObjectIterator it( study->root(), SUIT_DataObjectIterator::DepthLeft ); + for ( ; it.current(); ++it ) + anObjList.append( it.current() ); + app->updateVisibilityState( anObjList, theViewFrame ); +#endif +} + +/*! + updte visibility state of given objects + \param theList - objects to update state + \param theViewFrame - view +*/ +void LightApp_Displayer::updateVisibilityState( const QStringList& theList, + SALOME_View* theViewFrame ) const +{ + // this code wrapped by pre-processor directive, becase it works with SALOME_View + // and has no effect in case of SALOMEOBJECT disabled +#ifndef DISABLE_SALOMEOBJECT + SUIT_Session* session = SUIT_Session::session(); + LightApp_Application* app = dynamic_cast(session->activeApplication()); + if (!app) + return; + SUIT_Study* study = app->activeStudy(); + if (!study) + return; + + LightApp_EntryObjMap anEntryObjMap; + LightApp_DataObject::FillEntryObjMap( study->root(), anEntryObjMap ); + if (anEntryObjMap.isEmpty()) + return; + + // take data objects by entries + DataObjectList anObjList; + QStringList::const_iterator it = theList.constBegin(); + for ( ; it != theList.constEnd(); ++it) { + if (anEntryObjMap.contains( *it ) ) + anObjList.append( anEntryObjMap[ *it ] ); + } + + app->updateVisibilityState( anObjList, theViewFrame ); +#endif } /*! diff --git a/src/LightApp/LightApp_Displayer.h b/src/LightApp/LightApp_Displayer.h index 272cd7f6e..1685b2f06 100644 --- a/src/LightApp/LightApp_Displayer.h +++ b/src/LightApp/LightApp_Displayer.h @@ -28,6 +28,7 @@ #include class QString; +class QStringList; /*! \class LightApp_Displayer @@ -40,10 +41,17 @@ public: LightApp_Displayer(); virtual ~LightApp_Displayer(); - void Display( const QString&, const bool = true, SALOME_View* = 0 ); - void Redisplay( const QString&, const bool = true ); - void Erase( const QString&, const bool forced = false, const bool updateViewer = true, SALOME_View* = 0 ); - void EraseAll( const bool forced = false, const bool updateViewer = true, SALOME_View* = 0 ) const; + void Display( const QString&, const bool = true, + SALOME_View* = 0, const bool updateVisState = true ); + void Display( const QStringList&, const bool = true, + SALOME_View* = 0, const bool updateVisState= true ); + void Redisplay( const QString&, const bool = true ); + void Erase( const QString&, const bool forced = false, + const bool updateViewer = true, SALOME_View* = 0, const bool updateVisState = true ); + void Erase( const QStringList&, const bool forced = false, + const bool updateViewer = true, SALOME_View* = 0, const bool updateVisState = true ); + void EraseAll( const bool forced = false, const bool updateViewer = true, + SALOME_View* = 0, const bool updateVisState = true ) const; bool IsDisplayed( const QString&, SALOME_View* = 0 ) const; void UpdateViewer() const; @@ -55,6 +63,10 @@ public: protected: virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 ); + + void updateVisibilityState( SALOME_View* theViewFrame ) const; + void updateVisibilityState( const QStringList& theList, + SALOME_View* theViewFrame ) const; }; #endif diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index c456acd82..11f02ba0e 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -121,6 +121,24 @@ void LightApp_Module::initialize( CAM_Application* app ) SUIT_ResourceMgr* resMgr = app ? app->resourceMgr() : 0; if ( resMgr ) resMgr->raiseTranslators( name() ); + + // create show-hide actions + QPixmap p; + SUIT_Desktop* d = app->desktop(); + QAction + *disp = createAction( -1, tr( "TOP_SHOW" ), p, tr( "MEN_SHOW" ), tr( "STB_SHOW" ), + 0, d, false, this, SLOT( onShowHide() ), QString("General:Show object(s)") ), + *erase = createAction( -1, tr( "TOP_HIDE" ), p, tr( "MEN_HIDE" ), tr( "STB_HIDE" ), + 0, d, false, this, SLOT( onShowHide() ) , QString("General:Hide object(s)") ), + *dispOnly = createAction( -1, tr( "TOP_DISPLAY_ONLY" ), p, tr( "MEN_DISPLAY_ONLY" ), tr( "STB_DISPLAY_ONLY" ), + 0, d, false, this, SLOT( onShowHide() ) ), + *eraseAll = createAction( -1, tr( "TOP_ERASE_ALL" ), p, tr( "MEN_ERASE_ALL" ), tr( "STB_ERASE_ALL" ), + 0, d, false, this, SLOT( onShowHide() ) ); + // store actions indeces in protected fields + myDisplay = actionId( disp ); + myErase = actionId( erase ); + myDisplayOnly = actionId( dispOnly ); + myEraseAll = actionId( eraseAll ); } /*!NOT IMPLEMENTED*/ @@ -398,22 +416,12 @@ QtxPopupMgr* LightApp_Module::popupMgr() { myPopupMgr = new QtxPopupMgr( 0, this ); - QPixmap p; - SUIT_Desktop* d = application()->desktop(); - + // take already created actions QAction - *disp = createAction( -1, tr( "TOP_SHOW" ), p, tr( "MEN_SHOW" ), tr( "STB_SHOW" ), - 0, d, false, this, SLOT( onShowHide() ), QString("General:Show object(s)") ), - *erase = createAction( -1, tr( "TOP_HIDE" ), p, tr( "MEN_HIDE" ), tr( "STB_HIDE" ), - 0, d, false, this, SLOT( onShowHide() ) , QString("General:Hide object(s)") ), - *dispOnly = createAction( -1, tr( "TOP_DISPLAY_ONLY" ), p, tr( "MEN_DISPLAY_ONLY" ), tr( "STB_DISPLAY_ONLY" ), - 0, d, false, this, SLOT( onShowHide() ) ), - *eraseAll = createAction( -1, tr( "TOP_ERASE_ALL" ), p, tr( "MEN_ERASE_ALL" ), tr( "STB_ERASE_ALL" ), - 0, d, false, this, SLOT( onShowHide() ) ); - myDisplay = actionId( disp ); - myErase = actionId( erase ); - myDisplayOnly = actionId( dispOnly ); - myEraseAll = actionId( eraseAll ); + *disp = action( myDisplay ), + *erase = action( myErase ), + *dispOnly = action( myDisplayOnly ), + *eraseAll = action( myEraseAll ); myPopupMgr->insert( disp, -1, 0 ); myPopupMgr->insert( erase, -1, 0 ); diff --git a/src/LightApp/LightApp_OBSelector.cxx b/src/LightApp/LightApp_OBSelector.cxx index 0e48995e2..7624af276 100644 --- a/src/LightApp/LightApp_OBSelector.cxx +++ b/src/LightApp/LightApp_OBSelector.cxx @@ -154,7 +154,7 @@ void LightApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList ) return; if( myEntries.count() == 0 || myModifiedTime < myBrowser->getModifiedTime() ) - fillEntries( myEntries ); + fillEntries(); DataObjectList objList; for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); @@ -172,19 +172,13 @@ void LightApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList ) \brief Fill map of the data objects currently shown in the Object Browser. \param entries map to be filled */ -void LightApp_OBSelector::fillEntries( QMap& entries ) +void LightApp_OBSelector::fillEntries() { - entries.clear(); + myEntries.clear(); if ( !myBrowser ) return; - - for ( SUIT_DataObjectIterator it( myBrowser->root(), - SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) { - LightApp_DataObject* obj = dynamic_cast( it.current() ); - if ( obj ) - entries.insert( obj->entry(), obj ); - } + LightApp_DataObject::FillEntryObjMap( myBrowser->root(), myEntries ); setModified(); } diff --git a/src/LightApp/LightApp_OBSelector.h b/src/LightApp/LightApp_OBSelector.h index 4a7bb6239..3d9a813dc 100644 --- a/src/LightApp/LightApp_OBSelector.h +++ b/src/LightApp/LightApp_OBSelector.h @@ -27,6 +27,7 @@ #define LIGHTAPP_OBSELECTOR_H #include "LightApp.h" +#include "LightApp_DataObject.h" #include #include @@ -34,7 +35,6 @@ #include class SUIT_DataBrowser; -class LightApp_DataObject; class LIGHTAPP_EXPORT LightApp_OBSelector : public QObject, public SUIT_Selector { @@ -50,7 +50,7 @@ public: unsigned long getModifiedTime() const; void setModified(); - + private slots: void onSelectionChanged(); @@ -59,13 +59,13 @@ protected: virtual void setSelection( const SUIT_DataOwnerPtrList& ); private: - void fillEntries( QMap& ); + void fillEntries(); private: - SUIT_DataBrowser* myBrowser; - SUIT_DataOwnerPtrList mySelectedList; - QMap myEntries; - unsigned long myModifiedTime; + SUIT_DataBrowser* myBrowser; + SUIT_DataOwnerPtrList mySelectedList; + LightApp_EntryObjMap myEntries; + unsigned long myModifiedTime; }; #endif diff --git a/src/LightApp/LightApp_SelectionMgr.cxx b/src/LightApp/LightApp_SelectionMgr.cxx index a7b9b17d2..9424ee377 100644 --- a/src/LightApp/LightApp_SelectionMgr.cxx +++ b/src/LightApp/LightApp_SelectionMgr.cxx @@ -71,6 +71,10 @@ LightApp_Application* LightApp_SelectionMgr::application() const void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType, const bool convertReferences ) const { + LightApp_Study* study = dynamic_cast( application()->activeStudy() ); + if ( !study ) + return; + theList.Clear(); SUIT_DataOwnerPtrList aList; @@ -85,10 +89,6 @@ void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QStri if( !owner ) continue; - LightApp_Study* study = dynamic_cast( application()->activeStudy() ); - if ( !study ) - return; - entry = owner->entry(); // Entry to check object uniqueness. // It is selected owner entry in the case, when we do not convert references, @@ -138,7 +138,7 @@ void LightApp_SelectionMgr::selectedObjects( QStringList& theList, const QString const bool convertReferences ) const { theList.clear(); - + SUIT_DataOwnerPtrList aList; selected( aList, theType ); @@ -149,10 +149,6 @@ void LightApp_SelectionMgr::selectedObjects( QStringList& theList, const QString if( !owner ) continue; - LightApp_Study* study = dynamic_cast( application()->activeStudy() ); - if ( !study ) - return; - entry = owner->entry(); if( !theList.contains( entry ) ) theList.append( entry ); diff --git a/src/LightApp/LightApp_ShowHideOp.cxx b/src/LightApp/LightApp_ShowHideOp.cxx index d2d3608d9..063af3111 100644 --- a/src/LightApp/LightApp_ShowHideOp.cxx +++ b/src/LightApp/LightApp_ShowHideOp.cxx @@ -142,15 +142,17 @@ void LightApp_ShowHideOp::startOperation() else entries.append( entry ); } + // be sure to use real obejct entries + QStringList objEntries; + QStringList::const_iterator it = entries.begin(), last = entries.end(); + for ( ; it!=last; ++it ) + objEntries.append( study->referencedToEntry( *it ) ); + + if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY ) + d->Display( objEntries, false, 0, true ); + else if( myActionType==ERASE ) + d->Erase( objEntries, false, false, 0, true ); - for( QStringList::const_iterator it = entries.begin(), last = entries.end(); it!=last; it++ ) - { - QString e = study->referencedToEntry( *it ); - if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY ) - d->Display( e, false, 0 ); - else if( myActionType==ERASE ) - d->Erase( e, false, false, 0 ); - } d->UpdateViewer(); commit(); } diff --git a/src/Prs/SALOME_Prs.h b/src/Prs/SALOME_Prs.h index 3ce235a4c..22eb63d24 100755 --- a/src/Prs/SALOME_Prs.h +++ b/src/Prs/SALOME_Prs.h @@ -35,6 +35,7 @@ class SALOME_View; class SALOME_Displayer; +class SALOME_ListIO; class Handle_SALOME_InteractiveObject; /*! @@ -199,6 +200,7 @@ public: //! \retval Return false. virtual bool isVisible( const Handle_SALOME_InteractiveObject& ){ return false; } virtual void Repaint() {} //!< Null body here. + virtual void GetVisible( SALOME_ListIO& theList ) {} }; /*! diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx index c89d9cc0b..a90548451 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx @@ -142,6 +142,14 @@ QString SALOME_PYQT_Module::engineIOR() const return myIOR; } +/*! + * Redefined to invokec correct version + */ +bool SALOME_PYQT_Module::activateModule( SUIT_Study* study ) +{ + return SalomeApp_Module::activateModule( study ); +} + /*! * Tries to get engine IOR from the Python module using engineIOR() function. * That function can load module engine using appropriate container if required. diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h index f4a35eaeb..8660ecc4d 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h @@ -48,6 +48,7 @@ public: virtual QString engineIOR() const; public slots: + virtual bool activateModule( SUIT_Study* ); void preferenceChanged( const QString&, const QString&, const QString& ); diff --git a/src/SOCC/SOCC_ViewModel.cxx b/src/SOCC/SOCC_ViewModel.cxx index 260bed36e..d38101e35 100755 --- a/src/SOCC/SOCC_ViewModel.cxx +++ b/src/SOCC/SOCC_ViewModel.cxx @@ -45,6 +45,7 @@ #include #include #include +#include // Temporarily commented to avoid awful dependecy on SALOMEDS // TODO: better mechanism of storing display/erse status in a study @@ -198,6 +199,26 @@ bool SOCC_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& obj ) return false; } +/*! + \Collect objects visible in viewer + \param theList - visible objects collection +*/ +void SOCC_Viewer::GetVisible( SALOME_ListIO& theList ) +{ + AIS_ListOfInteractive List; + getAISContext()->DisplayedObjects(List); + + AIS_ListIteratorOfListOfInteractive ite(List); + for ( ; ite.More(); ite.Next() ) + { + Handle(SALOME_InteractiveObject) anObj = + Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() ); + + if ( !anObj.IsNull() && anObj->hasEntry() ) + theList.Append( anObj ); + } +} + /*! Sets color of object \param obj - object to be updated diff --git a/src/SOCC/SOCC_ViewModel.h b/src/SOCC/SOCC_ViewModel.h index 7a5b10ef4..04b10bbf4 100755 --- a/src/SOCC/SOCC_ViewModel.h +++ b/src/SOCC/SOCC_ViewModel.h @@ -31,6 +31,7 @@ #include "SALOME_Prs.h" #include "OCCViewer_ViewModel.h" +class SALOME_ListIO; class Handle(SALOME_InteractiveObject); class SOCC_EXPORT SOCC_Viewer: public OCCViewer_Viewer, public SALOME_View @@ -63,6 +64,7 @@ public: virtual void LocalSelection( const SALOME_OCCPrs*, const int ); virtual void GlobalSelection( const bool = false ) const; virtual bool isVisible( const Handle(SALOME_InteractiveObject)& ); + virtual void GetVisible( SALOME_ListIO& ); virtual void Repaint(); // a utility function, used by SALOME_View_s methods diff --git a/src/SPlot2d/SPlot2d_ViewModel.cxx b/src/SPlot2d/SPlot2d_ViewModel.cxx index 581027ee3..832213e56 100644 --- a/src/SPlot2d/SPlot2d_ViewModel.cxx +++ b/src/SPlot2d/SPlot2d_ViewModel.cxx @@ -309,6 +309,23 @@ bool SPlot2d_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& IObject return aViewFrame->isVisible( curve ); } +/*! + \Collect objects visible in viewer + \param theList - visible objects collection +*/ +void SPlot2d_Viewer::GetVisible( SALOME_ListIO& theList ) +{ + Plot2d_ViewFrame* aViewFrame = getActiveViewFrame(); + if(aViewFrame == NULL) return; + CurveDict aCurves = aViewFrame->getCurves(); + CurveDict::Iterator it = aCurves.begin(); + for( ; it != aCurves.end(); ++it ) { + SPlot2d_Curve* aCurve = dynamic_cast(it.value()); + if ( aCurve && aCurve->hasIO() && aViewFrame->isVisible( aCurve ) ) + theList.Append( aCurve->getIO() ); + } +} + /*! Return interactive obeject if is presented in the viewer */ diff --git a/src/SPlot2d/SPlot2d_ViewModel.h b/src/SPlot2d/SPlot2d_ViewModel.h index 87e187474..992ec9714 100644 --- a/src/SPlot2d/SPlot2d_ViewModel.h +++ b/src/SPlot2d/SPlot2d_ViewModel.h @@ -29,9 +29,10 @@ #include "SPlot2d.h" -#include "SALOME_Prs.h" +#include #include "Plot2d_ViewModel.h" -#include "SALOME_InteractiveObject.hxx" +#include +#include #include "Plot2d_ViewFrame.h" #include "Plot2d_ViewWindow.h" #include "SPlot2d_Curve.h" @@ -73,6 +74,7 @@ public: virtual void BeforeDisplay( SALOME_Displayer* d ); virtual void AfterDisplay ( SALOME_Displayer* d ); virtual bool isVisible( const Handle(SALOME_InteractiveObject)& IObject ); + virtual void GetVisible( SALOME_ListIO& theList ); /* operations */ diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 9006a49ff..16fd18711 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -932,10 +932,16 @@ QString STD_Application::getDirectory( const QString& initial, const QString& ca void STD_Application::setDesktop( SUIT_Desktop* desk ) { SUIT_Desktop* prev = desktop(); + if ( prev == desk ) + return; + + if ( prev != 0 ) + disconnect( prev, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ), + this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) ); SUIT_Application::setDesktop( desk ); - if ( prev != desk && desk ) + if ( desk ) connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ), this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) ); } diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index d4ec696a8..d08fcfeaf 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -372,7 +372,11 @@ void SUIT_DataBrowser::onClicked( const QModelIndex& index ) if ( m ) { SUIT_DataObject* obj = m->object( index ); - if ( obj ) emit( clicked( obj ) ); + if ( obj ) + { + emit( clicked( obj ) ); + emit( clicked( obj, index.column() ) ); + } } } diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h index 1c8e8d958..cc153cad7 100644 --- a/src/SUIT/SUIT_DataBrowser.h +++ b/src/SUIT/SUIT_DataBrowser.h @@ -73,6 +73,7 @@ private: signals: void requestUpdate(); void clicked( SUIT_DataObject* ); + void clicked( SUIT_DataObject*, int ); void doubleClicked( SUIT_DataObject* ); private slots: diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index 96f91e7d7..f6fe06037 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -49,7 +49,8 @@ SUIT_DataObject::SUIT_DataObject( SUIT_DataObject* p ) : myParent( 0 ), myOpen( false ), myCheck( false ), - myAutoDel( true ) + myAutoDel( true ), + myVisState( Unpresentable ) { setParent( p ); signal()->emitCreated( this ); @@ -645,6 +646,28 @@ void SUIT_DataObject::setOpen( const bool on ) myOpen = on; } +/*! + \brief Returns the visibility state of the object. + \sa setVisibilityState() +*/ +SUIT_DataObject::VisibilityState SUIT_DataObject::visibilityState() const +{ + return myVisState; +} + +/*! + \brief Set the visibility state of the object. + \param on new "opened" state of the object + \sa isOpen() +*/ +void SUIT_DataObject::setVisibilityState( const VisibilityState theState ) +{ + if (myVisState == theState) + return; + myVisState = theState; + signal()->emitUpdated( this ); +} + /*! \brief Check if the specified column supports custom sorting. @@ -863,6 +886,16 @@ void SUIT_DataObject::Signal::emitRemoved( SUIT_DataObject* object, SUIT_DataObj emit( removed( object, parent ) ); } +/*! + \brief Emit signal about data object modification + \param object data object being updated +*/ +void SUIT_DataObject::Signal::emitUpdated( SUIT_DataObject* object ) +{ + if ( object ) + emit updated( object ); +} + /*! \brief Schedule data object for the late deleting. \param object data object to be deleted later diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index 796620248..4c82dffae 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -61,9 +61,18 @@ public: //! Column id enum { + VisibilityId, //!< visibility state column NameId //!< name column }; + //! object visibility state + typedef enum + { + Shown, + Hidden, + Unpresentable, + } VisibilityState; + SUIT_DataObject( SUIT_DataObject* = 0 ); virtual ~SUIT_DataObject(); @@ -119,6 +128,9 @@ public: virtual bool isOpen() const; virtual void setOpen( const bool ); + virtual VisibilityState visibilityState() const; + virtual void setVisibilityState( const VisibilityState ); + virtual void update(); virtual bool customSorting( const int = NameId ) const; virtual bool compare( const QVariant&, const QVariant&, const int = NameId ) const; @@ -140,6 +152,7 @@ private: bool myCheck; bool myAutoDel; DataObjectList myChildren; + VisibilityState myVisState; static Signal* mySignal; @@ -160,6 +173,7 @@ private: void emitDestroyed( SUIT_DataObject* ); void emitInserted( SUIT_DataObject*, SUIT_DataObject* ); void emitRemoved( SUIT_DataObject*, SUIT_DataObject* ); + void emitUpdated( SUIT_DataObject* ); void deleteLater( SUIT_DataObject* ); @@ -168,6 +182,7 @@ signals: void destroyed( SUIT_DataObject* ); void inserted( SUIT_DataObject*, SUIT_DataObject* ); void removed( SUIT_DataObject*, SUIT_DataObject* ); + void updated( SUIT_DataObject* ); friend class SUIT_DataObject; diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 71211f3ca..46c55ced2 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -469,6 +469,8 @@ SUIT_TreeModel::~SUIT_TreeModel() this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), + this, SLOT( onUpdated( SUIT_DataObject* ) ) ); delete myRoot; } @@ -529,6 +531,27 @@ void SUIT_TreeModel::unregisterColumn( const int group_id, const QString& name ) } } +/*! + \brief Return column name by group and custom indeces + \param group_id - unique data object group identificator + \param custom_id - custom column id that should be passed into method SUIT_DataObject::data() + \return column name or empty string if column not found + */ +QString SUIT_TreeModel::columnName( const int group_id, const int custom_id ) +{ + QString name = QString::null; + for( int i = 0, n = myColumns.size(); ivisibilityState(); + break; default: break; } // ... switch ( role ) ... @@ -789,6 +818,14 @@ bool SUIT_TreeModel::setData( const QModelIndex& index, return true; } break; + case VisibilityRole: + // visibility state + if ( (int)obj->visibilityState() != value.toInt() ) { + obj->setVisibilityState( (SUIT_DataObject::VisibilityState)value.toInt() ); + emit( dataChanged( index, index ) ); + return true; + } + break; default: break; } @@ -1007,6 +1044,8 @@ void SUIT_TreeModel::setAutoUpdate( const bool on ) this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), + this, SLOT( onUpdated( SUIT_DataObject* ) ) ); myAutoUpdate = on; if ( myAutoUpdate ) { @@ -1014,6 +1053,8 @@ void SUIT_TreeModel::setAutoUpdate( const bool on ) this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::connect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::connect( SIGNAL( updated( SUIT_DataObject* ) ), + this, SLOT( onUpdated( SUIT_DataObject* ) ) ); updateTree(); } @@ -1106,11 +1147,15 @@ void SUIT_TreeModel::initialize() this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), + this, SLOT( onUpdated( SUIT_DataObject* ) ) ); if ( autoUpdate() ) { SUIT_DataObject::connect( SIGNAL( inserted( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::connect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::connect( SIGNAL( updated( SUIT_DataObject* ) ), + this, SLOT( onUpdated( SUIT_DataObject* ) ) ); } myItems.clear(); // ????? is it really necessary @@ -1118,7 +1163,10 @@ void SUIT_TreeModel::initialize() if ( !myRootItem ) myRootItem = new TreeItem( 0 ); + QString VisCol = QObject::tr( "VISIBILITY_COLUMN" ); + registerColumn( 0, VisCol, SUIT_DataObject::VisibilityId ); registerColumn( 0, QObject::tr( "NAME_COLUMN" ), SUIT_DataObject::NameId ); + setAppropriate( VisCol, Qtx::Hidden ); updateTree(); } @@ -1278,6 +1326,20 @@ void SUIT_TreeModel::onRemoved( SUIT_DataObject* /*object*/, SUIT_DataObject* pa updateTree( parent ); } +/*! + \brief Called when the data object is modified (their data updated) + \param object data object being modified +*/ +void SUIT_TreeModel::onUpdated( SUIT_DataObject* object ) +{ + if ( !object ) + return; + // update all columns corresponding to the given data object + QModelIndex firstIdx = index( object, 0 ); + QModelIndex lastIdx = index( object, columnCount() - 1 ); + emit dataChanged( firstIdx, lastIdx ); +} + /*! \class SUIT_ProxyModel \brief Proxy model which can be used above the SUIT_TreeMovel class @@ -1555,6 +1617,17 @@ void SUIT_ProxyModel::unregisterColumn( const int group_id, const QString& name treeModel()->unregisterColumn( group_id, name ); } +/*! + \brief Return column name by group and custom indeces + \param group_id - unique data object group identificator + \param custom_id - custom column id that should be passed into method SUIT_DataObject::data() + \return column name or empty string if column not found + */ +QString SUIT_ProxyModel::columnName( const int group_id, const int custom_id ) +{ + return treeModel() ? treeModel()->columnName( group_id, custom_id ) : QString::null; +} + /*! \brief Change column icon. diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index adc728c2d..c17eb3879 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -66,6 +66,7 @@ public: virtual void registerColumn( const int group_id, const QString& name, const int custom_id ) = 0; virtual void unregisterColumn( const int group_id, const QString& name ) = 0; + virtual QString columnName( const int group_id, const int custom_id ) = 0; virtual void setColumnIcon( const QString& name, const QPixmap& icon ) = 0; virtual QPixmap columnIcon( const QString& name ) const = 0; virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr ) = 0; @@ -102,6 +103,7 @@ public: TextColorRole, //!< (editor) text color (Qt::UserRole + 1) HighlightRole, //!< highlight color (Qt::UserRole + 2) HighlightedTextRole, //!< highlighted text color (Qt::UserRole + 3) + VisibilityRole, //!< visibility state role (Qt::UserRole + 4) AppropriateRole = Qtx::AppropriateRole //!< appropriate flag (Qt::UserRole + 100) } Role; @@ -124,6 +126,7 @@ public: virtual int rowCount( const QModelIndex& = QModelIndex() ) const; virtual void registerColumn( const int group_id, const QString& name, const int custom_id ); virtual void unregisterColumn( const int group_id, const QString& name ); + virtual QString columnName( const int group_id, const int custom_id ); virtual void setColumnIcon( const QString& name, const QPixmap& icon ); virtual QPixmap columnIcon( const QString& name ) const; virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr ); @@ -165,6 +168,7 @@ private: private slots: void onInserted( SUIT_DataObject*, SUIT_DataObject* ); void onRemoved( SUIT_DataObject*, SUIT_DataObject* ); + void onUpdated( SUIT_DataObject* ); private: typedef QMap ItemMap; @@ -215,6 +219,7 @@ public: virtual bool lessThan( const QModelIndex&, const QModelIndex& ) const; virtual void registerColumn( const int group_id, const QString& name, const int custom_id ); virtual void unregisterColumn( const int group_id, const QString& name ); + virtual QString columnName( const int group_id, const int custom_id ); virtual void setColumnIcon( const QString& name, const QPixmap& icon ); virtual QPixmap columnIcon( const QString& name ) const; virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr ); diff --git a/src/SalomeApp/Makefile.am b/src/SalomeApp/Makefile.am index c82f8e5eb..c2f1df2c3 100755 --- a/src/SalomeApp/Makefile.am +++ b/src/SalomeApp/Makefile.am @@ -101,6 +101,8 @@ salomepython_PYTHON = salome_pluginsmanager.py dist_salomescript_DATA = addvars2notebook.py dist_salomeres_DATA = \ + resources/icon_visibility_on.png \ + resources/icon_visibility_off.png\ resources/SalomeApp.ini \ resources/SalomeApp.xml @@ -116,7 +118,7 @@ libSalomeApp_la_CPPFLAGS = $(PYTHON_INCLUDES) $(QT_INCLUDES) $(QWT_INCLUDES) \ -I$(srcdir)/../STD -I$(srcdir)/../VTKViewer -I$(srcdir)/../ObjBrowser \ -I$(srcdir)/../PyConsole -I$(srcdir)/../TOOLSGUI \ -I$(srcdir)/../PyInterp -I$(srcdir)/../Session -I$(top_builddir)/idl \ - -I$(srcdir)/../Event -I$(srcdir)/../CASCatch \ + -I$(srcdir)/../Event -I$(srcdir)/../CASCatch -I$(srcdir)/../Prs \ @CORBA_CXXFLAGS@ @CORBA_INCLUDES@ @LIBXML_INCLUDES@ libSalomeApp_la_LDFLAGS = $(PYTHON_LIBS) $(QT_MT_LIBS) libSalomeApp_la_LIBADD = $(KERNEL_LDFLAGS) -lOpUtil -lSALOMELocalTrace -lSalomeDSClient \ @@ -126,4 +128,4 @@ libSalomeApp_la_LIBADD = $(KERNEL_LDFLAGS) -lOpUtil -lSALOMELocalTrace -lSalome ../SVTK/libSVTK.la ../SOCC/libSOCC.la ../PyInterp/libPyInterp.la \ ../PyConsole/libPyConsole.la ../LogWindow/libLogWindow.la \ ../LightApp/libLightApp.la ../TOOLSGUI/libToolsGUI.la ../Session/libSalomeSession.la \ - ../Event/libEvent.la ../CASCatch/libCASCatch.la $(CAS_KERNEL) + ../Event/libEvent.la ../CASCatch/libCASCatch.la ../Prs/libSalomePrs.la $(CAS_KERNEL) diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 3adecffd4..3bebeb56e 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -41,6 +41,7 @@ #include "SalomeApp_StudyPropertiesDlg.h" #include "SalomeApp_LoadStudiesDlg.h" #include "SalomeApp_NoteBookDlg.h" +#include "SalomeApp_Module.h" #include "SalomeApp_ExitDlg.h" @@ -61,6 +62,9 @@ #include #include #include +#include +#include +#include #include @@ -89,8 +93,9 @@ #include #include -#include #include +#include +#include #include #include @@ -154,6 +159,8 @@ SalomeApp_Application::SalomeApp_Application() { connect( desktop(), SIGNAL( message( const QString& ) ), this, SLOT( onDesktopMessage( const QString& ) ) ); + connect( desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) ); setNoteBook(0); } @@ -339,6 +346,32 @@ void SalomeApp_Application::createActions() } +/*!Set desktop:*/ +void SalomeApp_Application::setDesktop( SUIT_Desktop* desk ) +{ + SUIT_Desktop* prev = desktop(); + if ( prev == desk ) + return; + + if ( prev != 0 ) + { + disconnect( prev, SIGNAL( message( const QString& ) ), + this, SLOT( onDesktopMessage( const QString& ) ) ); + disconnect( prev, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) ); + } + + LightApp_Application::setDesktop( desk ); + + if ( desk != 0 ) + { + connect( desk, SIGNAL( message( const QString& ) ), + this, SLOT( onDesktopMessage( const QString& ) ) ); + connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) ); + } +} + /*! \brief Close application. */ @@ -861,15 +894,20 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) EntryCol = QObject::tr( "ENTRY_COLUMN" ); SUIT_AbstractModel* treeModel = dynamic_cast( ob->model() ); - treeModel->registerColumn( 0, EntryCol, SalomeApp_DataObject::EntryId ); - treeModel->registerColumn( 0, ValueCol, SalomeApp_DataObject::ValueId ); - treeModel->registerColumn( 0, IORCol, SalomeApp_DataObject::IORId ); - treeModel->registerColumn( 0, RefCol, SalomeApp_DataObject::RefEntryId ); - treeModel->setAppropriate( EntryCol, Qtx::Toggled ); - treeModel->setAppropriate( ValueCol, Qtx::Toggled ); - treeModel->setAppropriate( IORCol, Qtx::Toggled ); - treeModel->setAppropriate( RefCol, Qtx::Toggled ); - + if (treeModel) + { + treeModel->registerColumn( 0, EntryCol, SalomeApp_DataObject::EntryId ); + treeModel->registerColumn( 0, ValueCol, SalomeApp_DataObject::ValueId ); + treeModel->registerColumn( 0, IORCol, SalomeApp_DataObject::IORId ); + treeModel->registerColumn( 0, RefCol, SalomeApp_DataObject::RefEntryId ); + treeModel->setAppropriate( EntryCol, Qtx::Toggled ); + treeModel->setAppropriate( ValueCol, Qtx::Toggled ); + treeModel->setAppropriate( IORCol, Qtx::Toggled ); + treeModel->setAppropriate( RefCol, Qtx::Toggled ); + // show visibility column + treeModel->setAppropriate( treeModel->columnName( 0, SalomeApp_DataObject::VisibilityId ), Qtx::Toggled ); + } + bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); bool autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true ); bool resizeOnExpandItem = resMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", true ); @@ -1266,6 +1304,13 @@ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) { // update "non-existing" (not loaded yet) data models SalomeApp_Study* study = dynamic_cast(activeStudy()); + SUIT_DataBrowser* ob = objectBrowser(); + if ( !ob ) + { + getWindow( WT_ObjectBrowser ); + ob = objectBrowser(); + } + if ( study ) { _PTR(Study) stdDS = study->studyDS(); @@ -1277,13 +1322,14 @@ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) if ( aComponent->ComponentDataType() == "Interface Applicative" ) continue; // skip the magic "Interface Applicative" component - - if ( !objectBrowser() ) - getWindow( WT_ObjectBrowser ); - const bool isAutoUpdate = objectBrowser()->autoUpdate(); - objectBrowser()->setAutoUpdate( false ); - SalomeApp_DataModel::synchronize( aComponent, study ); - objectBrowser()->setAutoUpdate( isAutoUpdate ); + + if (ob) + { + const bool isAutoUpdate = ob->autoUpdate(); + ob->setAutoUpdate( false ); + SalomeApp_DataModel::synchronize( aComponent, study ); + ob->setAutoUpdate( isAutoUpdate ); + } } } } @@ -1543,11 +1589,12 @@ bool SalomeApp_Application::useStudy( const QString& theName ) /*! Show/hide object browser colums according to preferences */ void SalomeApp_Application::objectBrowserColumnsVisibility() { - if ( objectBrowser() ) + SUIT_DataBrowser* ob = objectBrowser(); + if ( ob ) for ( int i = SalomeApp_DataObject::EntryId; i <= SalomeApp_DataObject::RefEntryId; i++ ) { bool shown = resourceMgr()->booleanValue( "ObjectBrowser", QString( "visibility_column_id_%1" ).arg( i ), true ); - objectBrowser()->treeView()->setColumnHidden( i, !shown ); + ob->treeView()->setColumnHidden( i, !shown ); } } @@ -1652,3 +1699,56 @@ void SalomeApp_Application::onExtAction() if (!QMetaObject::invokeMethod(aModule, qPrintable(aDataList[1]), Q_ARG(QString, aEntry))) printf("Error: Can't Invoke method %s\n", qPrintable(aDataList[1])); } + + +/*! + * Called when window activated + */ +void SalomeApp_Application::onWindowActivated( SUIT_ViewWindow* theViewWindow ) +{ + SUIT_DataBrowser* anOB = objectBrowser(); + if( !anOB ) + return; + SUIT_DataObject* rootObj = anOB->root(); + if( !rootObj ) + return; + + DataObjectList listObj = rootObj->children( true ); + + SALOME_View* sView = 0; + if ( SUIT_ViewManager* vman = theViewWindow->getViewManager() ) + if ( SUIT_ViewModel* vmod = vman->getViewModel() ) + sView = dynamic_cast( vmod ); + updateVisibilityState( listObj, sView ); +} + +/*! + Update visibility state of given objects + */ +void SalomeApp_Application::updateVisibilityState( DataObjectList& theList, + SALOME_View* theView ) +{ + if (theList.isEmpty() || !theView ) + return; + // take visibale objects from current view + QMap aVisEntityMap; + SALOME_ListIO aListOfIO; + theView->GetVisible( aListOfIO ); + SALOME_ListIteratorOfListIO anIter(aListOfIO); + for(; anIter.More(); anIter.Next()) + { + Handle_SALOME_InteractiveObject& anObj = anIter.Value(); + if (!anObj.IsNull() && anObj->hasEntry()) + aVisEntityMap[ anObj->getEntry() ] = 1; + } + + for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) + { + LightApp_DataObject* obj = dynamic_cast(*itr); + if (!obj) continue; + if (aVisEntityMap.contains( obj->entry() ) ) + obj->setVisibilityState( SUIT_DataObject::Shown ); + else if (obj->visibilityState() == SUIT_DataObject::Shown) + obj->setVisibilityState( SUIT_DataObject::Hidden ); + } +} diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index f4e82a0a9..0fcf17f5e 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -34,6 +34,8 @@ #include "SalomeApp.h" #include +#include + #include //#include @@ -45,8 +47,9 @@ class LightApp_Preferences; class SalomeApp_Study; class SalomeApp_NoteBookDlg; -class SUIT_DataObject; +class SUIT_Desktop; +class SALOME_View; class SALOME_LifeCycleCORBA; @@ -87,6 +90,8 @@ public: virtual bool checkDataObject(LightApp_DataObject* theObj); + virtual void setDesktop( SUIT_Desktop* ); + static CORBA::ORB_var orb(); static SALOMEDSClient_StudyManager* studyMgr(); static SALOME_NamingService* namingService(); @@ -104,6 +109,10 @@ public: virtual void setNoteBook(SalomeApp_NoteBookDlg* theNoteBook); virtual SalomeApp_NoteBookDlg* getNoteBook() const; + //! update visibility state of objects + void updateVisibilityState( DataObjectList& theList, + SALOME_View* theView ); + public slots: virtual void onLoadDoc(); virtual bool onLoadDoc( const QString& ); @@ -158,6 +167,8 @@ private slots: void onOpenWith(); void onExtAction(); + void onWindowActivated( SUIT_ViewWindow* theViewWindow ); + private: void createExtraActions(); diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index 28ac15f0e..4aa3bcee4 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -38,6 +38,7 @@ #include #include +#include /*! \class SalomeApp_DataObject @@ -153,6 +154,11 @@ QString SalomeApp_DataObject::text( const int id ) const return txt; } +/*! + \brief Map to store data object icons +*/ +typedef QMap MapKeyPixmap; + /*! \brief Get data object icon for the specified column. \param id column id @@ -160,29 +166,56 @@ QString SalomeApp_DataObject::text( const int id ) const */ QPixmap SalomeApp_DataObject::icon( const int id ) const { - // we display icon only for the first (NameId ) column + // we display icon only for the NameId and VisibilityId columns + QString pixmapName = QString::null; + QString componentType = QString::null; if ( id == NameId ) { + componentType = componentDataType(); _PTR(GenericAttribute) anAttr; if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){ _PTR(AttributePixMap) aPixAttr ( anAttr ); if ( aPixAttr->HasPixMap() ) { - QString componentType = componentDataType(); - QString pixmapID = aPixAttr->GetPixMap().c_str(); + QString pixmapID = aPixAttr->GetPixMap().c_str(); // select a plugin within a component QStringList plugin_pixmap = pixmapID.split( "::", QString::KeepEmptyParts ); if ( plugin_pixmap.size() == 2 ) { componentType = plugin_pixmap.front(); pixmapID = plugin_pixmap.back(); } - QString pixmapName = QObject::tr( pixmapID.toLatin1().constData() ); - LightApp_RootObject* aRoot = dynamic_cast( root() ); - if ( aRoot && aRoot->study() ) { - SUIT_ResourceMgr* mgr = aRoot->study()->application()->resourceMgr(); - return mgr->loadPixmap( componentType, pixmapName, false ); - } + pixmapName = QObject::tr( pixmapID.toLatin1().constData() ); } } } + else if ( id == VisibilityId ) { + componentType = "SalomeApp"; + if (visibilityState() == Shown) + pixmapName = QObject::tr( "ICON_DATAOBJ_VISIBLE" ); + else if (visibilityState() == Hidden) + pixmapName = QObject::tr( "ICON_DATAOBJ_INVISIBLE" ); + else + return QPixmap(); + } + if (pixmapName.isEmpty()) + return LightApp_DataObject::icon( id ); + + // here we assume that user doesnot reaplce icons during application work + static QMap CompKeyMap; + if (!CompKeyMap.contains ( componentType )) + CompKeyMap.insert( componentType, MapKeyPixmap() ); + MapKeyPixmap& keyPixMap = CompKeyMap[ componentType ]; + if (!keyPixMap.contains( pixmapName )) + { + // load from resources + SUIT_ResourceMgr* mgr = 0; + LightApp_RootObject* aRoot = dynamic_cast( root() ); + if ( aRoot && aRoot->study() ) + mgr = aRoot->study()->application()->resourceMgr(); + if (mgr) + keyPixMap.insert( pixmapName, mgr->loadPixmap( componentType, pixmapName, false ) ); + } + if (keyPixMap.contains( pixmapName )) + return keyPixMap[ pixmapName ]; + return LightApp_DataObject::icon( id ); } diff --git a/src/SalomeApp/SalomeApp_Module.cxx b/src/SalomeApp/SalomeApp_Module.cxx index 4e35ccca7..96603fba3 100644 --- a/src/SalomeApp/SalomeApp_Module.cxx +++ b/src/SalomeApp/SalomeApp_Module.cxx @@ -28,8 +28,10 @@ #include "SalomeApp_DataModel.h" #include "SalomeApp_Application.h" #include "SalomeApp_Study.h" +#include "SalomeApp_DataObject.h" #include "LightApp_Selection.h" +#include "LightApp_DataObject.h" #include "CAM_DataModel.h" @@ -41,13 +43,18 @@ #include #include +#include +#include #include /*!Constructor.*/ SalomeApp_Module::SalomeApp_Module( const QString& name ) -: LightApp_Module( name ) + : LightApp_Module( name ), + myIsFirstActivate( true ) { + SUIT_DataObject::connect( SIGNAL( inserted( SUIT_DataObject*, SUIT_DataObject* ) ), + this, SLOT( onObjectInserted( SUIT_DataObject* ) ) ); } /*!Destructor.*/ @@ -143,3 +150,130 @@ void SalomeApp_Module::restoreVisualParameters(int savePoint) { } +/*!Returns module data object module*/ +static SalomeApp_Module* objectModule( CAM_Application* theApp, + SalomeApp_DataObject* theObj ) +{ + SalomeApp_Module* mod = 0; + if ( !theApp || !theObj ) + return mod; + + mod = dynamic_cast + (theApp->module(theApp->moduleTitle( theObj->componentDataType() ))); + + return mod; +} + +/*! Redefined to reset internal flags valid for study instance */ +void SalomeApp_Module::studyClosed( SUIT_Study* theStudy ) +{ + LightApp_Module::studyClosed( theStudy ); + myIsFirstActivate = true; + + LightApp_Application* app = dynamic_cast(application()); + if (!app) + return; + SUIT_DataBrowser* ob = app->objectBrowser(); + if (ob) + disconnect( ob, SIGNAL( clicked( SUIT_DataObject*, int ) ), + this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ) ); +} + +/*!Activate module.*/ +bool SalomeApp_Module::activateModule( SUIT_Study* theStudy ) +{ + bool state = LightApp_Module::activateModule( theStudy ); + if (!myIsFirstActivate) + return state; + + myIsFirstActivate = false; + + // update visibility state of objects + LightApp_Application* app = dynamic_cast(application()); + if (!app) + return state; + + SUIT_DataBrowser* ob = app->objectBrowser(); + if (!ob) + return state; + + // connect to click on item + connect( ob, SIGNAL( clicked( SUIT_DataObject*, int ) ), + this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ) ); + + SUIT_DataObject* rootObj = ob->root(); + if( !rootObj ) + return state; + DataObjectList listObj = rootObj->children( true ); + for ( DataObjectList::iterator itr = listObj.begin(); itr != listObj.end(); ++itr ) + { + SalomeApp_DataObject* obj = dynamic_cast(*itr); + if ( !obj || dynamic_cast(obj) || obj->isReference() ) + continue; + + SalomeApp_Module* mod = objectModule( app, obj ); + if (mod && mod == this) + mod->initVisibilityState( obj ); + } + return state; +} + +/*! + * \brief Virtual public slot + * + * This method is called after the object inserted into data view + * This is default implementation + */ +void SalomeApp_Module::onObjectInserted( SUIT_DataObject* theObject ) +{ + SalomeApp_DataObject* anObj = dynamic_cast( theObject ); + if (!anObj) + return; + + // no visibility state for module root and reference objects + if ( dynamic_cast(anObj) || anObj->isReference()) + { + anObj->setVisibilityState( SUIT_DataObject::Unpresentable ); + return; + } + + // update visibility state in native object module + SalomeApp_Module* mod = objectModule( application(), anObj ); + if ( mod ) + mod->initVisibilityState( anObj ); +} + +/*! + * \brief Virtual protected method + * + * This method is intended to update their visibility state + * This is default implementation + */ +void SalomeApp_Module::initVisibilityState( SUIT_DataObject* theObject ) +{ + if ( theObject ) + theObject->setVisibilityState( SUIT_DataObject::Unpresentable ); +} + +/*! + * \brief Virtual public slot + * + * This method is called after the object inserted into data view to update their visibility state + * This is default implementation + */ +void SalomeApp_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn ) +{ + if (!isActiveModule()) + return; + // change visibility of object + if (!theObject || theColumn != SUIT_DataObject::VisibilityId ) + return; + // detect action index (from LightApp level) + int id = -1; + if ( theObject->visibilityState() == SUIT_DataObject::Shown ) + id = myErase; + else if ( theObject->visibilityState() == SUIT_DataObject::Hidden ) + id = myDisplay; + if ( id != -1 ) + startOperation( id ); +} diff --git a/src/SalomeApp/SalomeApp_Module.h b/src/SalomeApp/SalomeApp_Module.h index 9530f9da0..a062cb60d 100644 --- a/src/SalomeApp/SalomeApp_Module.h +++ b/src/SalomeApp/SalomeApp_Module.h @@ -36,6 +36,7 @@ class SalomeApp_Application; class LightApp_Selection; class SALOME_ListIO; class QString; +class SUIT_DataObject; /*! * \brief Base class for all salome modules @@ -63,9 +64,19 @@ public: virtual void restoreVisualParameters(int savePoint); virtual LightApp_Selection* createSelection() const; +public slots: + virtual bool activateModule( SUIT_Study* ); + virtual void studyClosed( SUIT_Study* ); + virtual void onObjectInserted( SUIT_DataObject* ); + virtual void onObjectClicked( SUIT_DataObject*, int ); + protected: virtual CAM_DataModel* createDataModel(); virtual void extractContainers( const SALOME_ListIO&, SALOME_ListIO& ) const; + virtual void initVisibilityState( SUIT_DataObject* ); + + protected: + bool myIsFirstActivate; }; #endif diff --git a/src/SalomeApp/resources/SalomeApp_images.ts b/src/SalomeApp/resources/SalomeApp_images.ts index 0d814c5d4..250fc0bb8 100644 --- a/src/SalomeApp/resources/SalomeApp_images.ts +++ b/src/SalomeApp/resources/SalomeApp_images.ts @@ -22,4 +22,15 @@ See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com --> + + @default + + ICON_DATAOBJ_VISIBLE + icon_visibility_on.png + + + ICON_DATAOBJ_INVISIBLE + icon_visibility_off.png + + diff --git a/src/SalomeApp/resources/icon_visibility_off.png b/src/SalomeApp/resources/icon_visibility_off.png new file mode 100644 index 000000000..31c505d82 Binary files /dev/null and b/src/SalomeApp/resources/icon_visibility_off.png differ diff --git a/src/SalomeApp/resources/icon_visibility_on.png b/src/SalomeApp/resources/icon_visibility_on.png new file mode 100644 index 000000000..61ebe4703 Binary files /dev/null and b/src/SalomeApp/resources/icon_visibility_on.png differ