From 0bfbb9326cf44686726a9270cde8e1eb49ae9208 Mon Sep 17 00:00:00 2001 From: rnv Date: Thu, 17 Feb 2011 08:08:30 +0000 Subject: [PATCH] Implementation of the "20830: EDF 1357 GUI : Hide/Show Icon" (at the moment implemeted only in GEOM and SMESH modules). --- src/LightApp/LightApp_Application.cxx | 9 + src/LightApp/LightApp_DataObject.cxx | 14 ++ src/LightApp/LightApp_DataObject.h | 3 +- src/LightApp/LightApp_Displayer.cxx | 102 ++++++-- src/LightApp/LightApp_Displayer.h | 11 + src/LightApp/LightApp_SelectionMgr.cxx | 15 +- src/LightApp/LightApp_ShowHideOp.cxx | 21 +- src/LightApp/LightApp_Study.cxx | 60 +++++ src/LightApp/LightApp_Study.h | 5 +- src/Prs/SALOME_Prs.h | 2 + src/Qtx/Qtx.h | 21 ++ .../SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx | 9 + .../SALOME_PYQT_GUI/SALOME_PYQT_Module.h | 1 + src/SOCC/SOCC_ViewModel.cxx | 21 +- src/SOCC/SOCC_ViewModel.h | 2 + src/SPlot2d/SPlot2d_ViewModel.cxx | 33 ++- src/SPlot2d/SPlot2d_ViewModel.h | 12 +- src/SUIT/Makefile.am | 8 +- src/SUIT/SUIT_DataBrowser.cxx | 5 +- src/SUIT/SUIT_DataObject.cxx | 10 +- src/SUIT/SUIT_DataObject.h | 6 +- src/SUIT/SUIT_TreeModel.cxx | 236 ++++++++++++++++- src/SUIT/SUIT_TreeModel.h | 73 ++++-- src/SUIT/resources/SUIT_images.ts | 36 +++ src/SUIT/resources/icon_visibility_off.png | Bin 0 -> 344 bytes src/SUIT/resources/icon_visibility_on.png | Bin 0 -> 3184 bytes src/SVTK/SVTK_Functor.h | 23 +- src/SVTK/SVTK_View.cxx | 11 + src/SVTK/SVTK_View.h | 8 +- src/SVTK/SVTK_ViewModel.cxx | 15 ++ src/SVTK/SVTK_ViewModel.h | 8 +- src/SalomeApp/Makefile.am | 4 +- src/SalomeApp/SalomeApp_Application.cxx | 137 +++++++++- src/SalomeApp/SalomeApp_Application.h | 16 +- src/SalomeApp/SalomeApp_Module.cxx | 99 +++++++- src/SalomeApp/SalomeApp_Module.h | 12 +- src/SalomeApp/SalomeApp_Study.cxx | 237 ++++++++++-------- 37 files changed, 1083 insertions(+), 202 deletions(-) create mode 100644 src/SUIT/resources/SUIT_images.ts create mode 100644 src/SUIT/resources/icon_visibility_off.png create mode 100644 src/SUIT/resources/icon_visibility_on.png diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index e5978a660..b044b0958 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -149,6 +149,9 @@ #include #endif + +#define VISIBILITY_COLUMN_WIDTH 25 + #include #include #include @@ -168,6 +171,8 @@ #include #include #include +#include +#include #include @@ -1729,6 +1734,10 @@ QWidget* LightApp_Application::createWindow( const int flag ) // Create OBSelector new LightApp_OBSelector( ob, mySelMgr ); + ob->treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed); + ob->treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId); + ob->treeView()->setColumnWidth(SUIT_DataObject::VisibilityId, VISIBILITY_COLUMN_WIDTH); + wid = ob; ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); diff --git a/src/LightApp/LightApp_DataObject.cxx b/src/LightApp/LightApp_DataObject.cxx index cd7e7bdab..8723a26e4 100644 --- a/src/LightApp/LightApp_DataObject.cxx +++ b/src/LightApp/LightApp_DataObject.cxx @@ -124,6 +124,20 @@ int LightApp_DataObject::groupId() const return m ? m->groupId() : CAM_DataObject::groupId(); } +/*! + \brief return custom data for data object +*/ +QVariant LightApp_DataObject::customData(Qtx::CustomDataType type) { + switch(type) { + case Qtx::IdType: + return EntryId; + break; + default: + return QVariant(); + break; + } +} + /*! \brief Check if the object is visible. \return \c true if this object is displayable or \c false otherwise diff --git a/src/LightApp/LightApp_DataObject.h b/src/LightApp/LightApp_DataObject.h index d9e903726..cff5cde01 100644 --- a/src/LightApp/LightApp_DataObject.h +++ b/src/LightApp/LightApp_DataObject.h @@ -39,7 +39,7 @@ class LIGHTAPP_EXPORT LightApp_DataObject : public virtual CAM_DataObject public: //! Column id enum { - EntryId = NameId + 1 //!< entry column + EntryId = VisibilityId + 1 //!< entry column }; public: @@ -57,6 +57,7 @@ public: virtual bool customSorting( const int = NameId ) const; virtual bool compare( const QVariant&, const QVariant&, const int = NameId ) const; virtual int groupId() const; + virtual QVariant customData(Qtx::CustomDataType type); virtual bool isVisible() const; diff --git a/src/LightApp/LightApp_Displayer.cxx b/src/LightApp/LightApp_Displayer.cxx index afa347975..a04cb8017 100644 --- a/src/LightApp/LightApp_Displayer.cxx +++ b/src/LightApp/LightApp_Displayer.cxx @@ -23,6 +23,7 @@ #include "LightApp_Displayer.h" #include "LightApp_Application.h" #include "LightApp_Module.h" +#include "LightApp_Study.h" #include @@ -32,6 +33,7 @@ #include #include +#include #include #ifndef DISABLE_SALOMEOBJECT #include "SALOME_InteractiveObject.hxx" @@ -57,23 +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 ) { - SALOME_Prs* prs = buildPresentation( entry, theViewFrame ); - if ( prs ) + QStringList aList; + aList.append( entry ); + Display( aList, updateViewer, theViewFrame ); +} + +/*! + 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 ) +{ + 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 + setVisibilityState(*it, Qtx::ShownState); } + } } @@ -119,17 +142,40 @@ 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 ) +{ + QStringList aList; + aList.append( entry ); + Erase( aList, forced, updateViewer, theViewFrame ); +} + +/*! + 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 ) { 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 ) vf->Repaint(); delete prs; // delete presentation because displayer is its owner + setVisibilityState(*it,Qtx::HiddenState); } } } @@ -149,6 +195,11 @@ void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, S if ( updateViewer ) vf->Repaint(); } + + LightApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ); + LightApp_Study* study = app ? dynamic_cast( app->activeStudy() ) : 0; + if(study) + study->setVisibilityStateForAll(Qtx::HiddenState); } /*! @@ -266,11 +317,26 @@ LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name, if( m ) { m->connectToStudy( dynamic_cast( app->activeStudy() ) ); - if( m!=app->activeModule() && load ) - { - m->setMenuShown( false ); - m->setToolShown( false ); - } + //rnv: Implementation of the 20830: EDF 1357 GUI : Hide/Show Icon + // Seems it is not necessary hide icons: + // if( m!=app->activeModule() && load ) + // { + // m->setMenuShown( false ); + // m->setToolShown( false ); + // } } return m ? m->displayer() : 0; } + +/*! + Find the active study and set the 'visibility state' property of the object + \param mod_name - name of module + \param load - is module has to be forced loaded +*/ +void LightApp_Displayer::setVisibilityState( const QString& theEntry, Qtx::VisibilityState theState) const { + LightApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ); + LightApp_Study* study = app ? dynamic_cast( app->activeStudy() ) : 0; + + if(study) + study->setVisibilityState( theEntry, theState); +} diff --git a/src/LightApp/LightApp_Displayer.h b/src/LightApp/LightApp_Displayer.h index 272cd7f6e..762f87ccf 100644 --- a/src/LightApp/LightApp_Displayer.h +++ b/src/LightApp/LightApp_Displayer.h @@ -27,6 +27,8 @@ #include +#include + class QString; /*! @@ -41,9 +43,16 @@ public: virtual ~LightApp_Displayer(); void Display( const QString&, const bool = true, SALOME_View* = 0 ); + void Display( const QStringList&, const bool = true, + SALOME_View* = 0 ); + void Redisplay( const QString&, const bool = true ); + + void Erase( const QStringList&, const bool forced = false, + const bool updateViewer = true, SALOME_View* = 0); 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; + bool IsDisplayed( const QString&, SALOME_View* = 0 ) const; void UpdateViewer() const; @@ -52,6 +61,8 @@ public: virtual bool canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const; bool canBeDisplayed( const QString& /*entry*/ ) const; + + void setVisibilityState (const QString& entry, Qtx::VisibilityState) const; protected: virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 ); diff --git a/src/LightApp/LightApp_SelectionMgr.cxx b/src/LightApp/LightApp_SelectionMgr.cxx index a7b9b17d2..87573301c 100644 --- a/src/LightApp/LightApp_SelectionMgr.cxx +++ b/src/LightApp/LightApp_SelectionMgr.cxx @@ -71,6 +71,9 @@ 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 +88,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, @@ -137,6 +136,10 @@ void LightApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const void LightApp_SelectionMgr::selectedObjects( QStringList& theList, const QString& theType, const bool convertReferences ) const { + LightApp_Study* study = dynamic_cast( application()->activeStudy() ); + if ( !study ) + return; + theList.clear(); SUIT_DataOwnerPtrList aList; @@ -149,10 +152,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..d9672e122 100644 --- a/src/LightApp/LightApp_ShowHideOp.cxx +++ b/src/LightApp/LightApp_ShowHideOp.cxx @@ -142,15 +142,18 @@ void LightApp_ShowHideOp::startOperation() else entries.append( entry ); } - - 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 ); - } + + // 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 ); + else if( myActionType==ERASE ) + d->Erase( objEntries, false, false, 0 ); + d->UpdateViewer(); commit(); } diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx index fd344206c..41ee960ba 100644 --- a/src/LightApp/LightApp_Study.cxx +++ b/src/LightApp/LightApp_Study.cxx @@ -31,6 +31,8 @@ #include "SUIT_ResourceMgr.h" #include "SUIT_DataObjectIterator.h" +#include "SUIT_DataBrowser.h" +#include "SUIT_TreeModel.h" #include @@ -629,6 +631,7 @@ void LightApp_Study::removeObjectFromAll( QString theEntry ) { v_it.value().remove(theEntry); } } + /*! Get all objects and it's properties from view manager identified by theViewMgrId. \param theEntry - Entry of the object. @@ -642,3 +645,60 @@ const ObjMap& LightApp_Study::getObjectMap ( int theViewMgrId ) { } return v_it.value(); } + +/*! + Set 'visibility state' property of the object. + \param theEntry - Entry of the object. + \param theState - visibility status +*/ +void LightApp_Study::setVisibilityState(const QString& theEntry, Qtx::VisibilityState theState) { + LightApp_Application* app = (LightApp_Application*)application(); + if(!app) + return; + SUIT_DataBrowser* db = app->objectBrowser(); + if(!db) + return; + + SUIT_AbstractModel* treeModel = dynamic_cast(db->model()); + + if(treeModel) + treeModel->setVisibilityState(theEntry,theState); +} + +/*! + Set 'visibility state' property for all object. + \param theEntry - Entry of the object. +*/ +void LightApp_Study::setVisibilityStateForAll(Qtx::VisibilityState theState) { + + LightApp_Application* app = (LightApp_Application*)application(); + if(!app) + return; + SUIT_DataBrowser* db = app->objectBrowser(); + if(!db) + return; + + SUIT_AbstractModel* treeModel = dynamic_cast(db->model()); + + if(treeModel) + treeModel->setVisibilityStateForAll(theState); +} + +/*! + Get 'visibility state' property of the object. + \param theEntry - Entry of the object. + \return 'visibility state' property of the object. +*/ +Qtx::VisibilityState LightApp_Study::visibilityState(const QString& theEntry) const { + LightApp_Application* app = (LightApp_Application*)application(); + if(app) { + + SUIT_DataBrowser* db = app->objectBrowser(); + if(db) { + SUIT_AbstractModel* treeModel = dynamic_cast(db->model()); + if(treeModel) + return treeModel->visibilityState(theEntry); + } + } + return Qtx::UnpresentableState; +} diff --git a/src/LightApp/LightApp_Study.h b/src/LightApp/LightApp_Study.h index 32a5cddbd..f44870096 100644 --- a/src/LightApp/LightApp_Study.h +++ b/src/LightApp/LightApp_Study.h @@ -30,6 +30,7 @@ #include "string" #include "vector" +#include #include #include @@ -101,7 +102,9 @@ public: virtual const ObjMap& getObjectMap ( int theViewMgrId ); virtual const ViewMgrMap& getViewMgrMap ( int theViewMgrId ) { return myViewMgrMap; }; - + virtual void setVisibilityState(const QString& theEntry, Qtx::VisibilityState theState); + virtual Qtx::VisibilityState visibilityState(const QString& theEntry) const; + virtual void setVisibilityStateForAll(Qtx::VisibilityState theState); protected: virtual void saveModuleData ( QString theModuleName, QStringList theListOfFiles ); 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/Qtx/Qtx.h b/src/Qtx/Qtx.h index 72a2a494f..3189f8ac6 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -113,6 +113,27 @@ public: Auto //!< substitute environment variable by it's value if variable exists, and keep it as is otherwise } SubstMode; + //! object visibility state + typedef enum { + ShownState, //!< Object is shown in viewer + HiddenState, //!< Object is hidden in viewer + UnpresentableState, //!< Unpresentable object + } VisibilityState; + + //! Header view flags + typedef enum { + ShowText = 0x001, //!< Show only text in the header + ShowIcon = 0x010, //!< Show only icon in the header + ShowAll = ShowText | ShowIcon //!< Show icon and text in the header + } HeaderViewFlags; + + //Type of the custom data + typedef enum { + IdType + } CustomDataType; + + + class QTX_EXPORT Localizer { public: 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..cc16915b1 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,15 @@ 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 32487ea43..99247e5bc 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 @@ -58,7 +59,6 @@ //#include "SALOMEDS_StudyManager.hxx" #include - #include // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study. @@ -683,6 +683,25 @@ bool SOCC_Viewer::getTrihedronSize( double& theNewSize, double& theSize ) fabs( theNewSize - theSize) > theNewSize * EPS; } +/*! + \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 ); + } +} /*! Updates current viewer diff --git a/src/SOCC/SOCC_ViewModel.h b/src/SOCC/SOCC_ViewModel.h index 8cd42e85d..5f96cbe56 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 @@ -64,6 +65,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 05a83d2b9..c118be8a5 100644 --- a/src/SPlot2d/SPlot2d_ViewModel.cxx +++ b/src/SPlot2d/SPlot2d_ViewModel.cxx @@ -272,14 +272,20 @@ void SPlot2d_Viewer::Erase( const SALOME_Prs2d* prs, const bool ) SALOME_Prs* SPlot2d_Viewer::CreatePrs( const char* entry ) { Plot2d_ViewFrame* aViewFrame = getActiveViewFrame(); + SPlot2d_Prs *prs = new SPlot2d_Prs(); if(aViewFrame) { - Plot2d_Prs* prs = aViewFrame->CreatePrs(entry); - if( prs ) - return new SPlot2d_Prs( prs ); + 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() && !strcmp( aCurve->getIO()->getEntry(), entry ) ) { + prs->AddObject(aCurve); + break; + } + } } - - return NULL; + return prs; } /*! @@ -310,6 +316,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..05f1f834d 100644 --- a/src/SPlot2d/SPlot2d_ViewModel.h +++ b/src/SPlot2d/SPlot2d_ViewModel.h @@ -27,14 +27,15 @@ #ifndef SPlot2d_ViewModel_H #define SPlot2d_ViewModel_H -#include "SPlot2d.h" - -#include "SALOME_Prs.h" +#include "SPlot2d.h" +#include "SPlot2d_Curve.h" #include "Plot2d_ViewModel.h" -#include "SALOME_InteractiveObject.hxx" #include "Plot2d_ViewFrame.h" #include "Plot2d_ViewWindow.h" -#include "SPlot2d_Curve.h" + +#include +#include +#include class SPLOT2D_EXPORT SPlot2d_Viewer : public Plot2d_Viewer, public SALOME_View { @@ -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/SUIT/Makefile.am b/src/SUIT/Makefile.am index 9b1df08d9..88547c579 100755 --- a/src/SUIT/Makefile.am +++ b/src/SUIT/Makefile.am @@ -122,7 +122,13 @@ nodist_libsuit_la_SOURCES = $(MOC_FILES) nodist_salomeres_DATA = \ SUIT_msg_en.qm \ - SUIT_msg_fr.qm + SUIT_msg_fr.qm \ + SUIT_images.qm + +dist_salomeres_DATA = \ + resources/icon_visibility_on.png \ + resources/icon_visibility_off.png + libsuit_la_CPPFLAGS = $(QT_INCLUDES) -I$(srcdir)/../Qtx -I$(srcdir)/../ObjBrowser diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index e29194155..5742350eb 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -407,7 +407,10 @@ 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 ) ); + m->emitClicked(obj, index); + } } } diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index 8b9f076d2..36c8e5fd5 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -23,6 +23,9 @@ // File : SUIT_DataObject.cxx // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) // + +#include + #include "SUIT_DataObject.h" #include "SUIT_DataObjectKey.h" #include @@ -930,7 +933,12 @@ int SUIT_DataObject::groupId() const { return 0; } - +/*! + \brief return custom data for data object. + */ +QVariant SUIT_DataObject::customData(Qtx::CustomDataType /*type*/) { + return QVariant(); +} /*! \fn void SUIT_DataObject::Signal::created( SUIT_DataObject* object ); \brief Emitted when data object is created. diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index 0b9377ae9..bc6ee7bbc 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -28,6 +28,8 @@ #include "SUIT.h" +#include + #include #include #include @@ -61,7 +63,8 @@ public: //! Column id enum { - NameId //!< name column + NameId, //!< name column + VisibilityId //!< visibility state column }; SUIT_DataObject( SUIT_DataObject* = 0 ); @@ -130,6 +133,7 @@ public: virtual SUIT_DataObjectKey* key() const; virtual int groupId() const; + virtual QVariant customData(Qtx::CustomDataType /*type*/); static Signal* signal(); static bool connect( const char*, QObject*, const char* ); diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index c60b6be27..f4c3a999f 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -20,9 +20,12 @@ // File: SUIT_TreeModel.cxx // Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) // +#include "SUIT_Session.h" #include "SUIT_TreeModel.h" #include "SUIT_TreeSync.h" #include "SUIT_DataObject.h" +#include "SUIT_ResourceMgr.h" + #include #include @@ -501,6 +504,7 @@ void SUIT_TreeModel::registerColumn( const int group_id, const QString& name, co inf.myName = name; inf.myIds.insert( group_id, custom_id ); inf.myAppropriate = Qtx::Shown; + inf.myHeaderFlags = Qtx::ShowAll; int n = myColumns.size(); myColumns.resize( n+1 ); myColumns[n] = inf; @@ -614,6 +618,114 @@ Qtx::Appropriate SUIT_TreeModel::appropriate( const QString& name ) const } +/*! + \brief Set header flags. + + These flags allow show in the header of the column text (name of the column), + icon or both text and icon. + + \param name - column name + \param flags - header flags + +*/ +void SUIT_TreeModel::setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ) { + for( int i=0, n=myColumns.size(); i 0) + needSignal = true; + } + if(needSignal) { + QModelIndexList lst = match(index(0,root()->customData(Qtx::IdType).toInt()), DisplayRole, id, 1, Qt::MatchExactly | Qt::MatchRecursive); + if(!lst.isEmpty()) { + QModelIndex idx = index(lst[0].row(), SUIT_DataObject::VisibilityId ,lst[0].parent()); + emit dataChanged(idx,idx); + } + } +} + +/*! + \brief Set visibility state for all objects. + + \param id - column name + \param state - visible state +*/ +void SUIT_TreeModel::setVisibilityStateForAll(Qtx::VisibilityState state) { + if(state != Qtx::UnpresentableState) { + VisibilityMap::ConstIterator it = myVisibilityMap.begin(); + while(it != myVisibilityMap.end() ) { + if(it.value() != state) + setVisibilityState(it.key(), state); + it++; + } + } else { + QList anIds = myVisibilityMap.keys(); + myVisibilityMap.clear(); + QList::ConstIterator it = anIds.begin(); + while(it != anIds.end()){ + QModelIndexList lst = match(index(0,root()->customData(Qtx::IdType).toInt()), DisplayRole, (*it), 1, Qt::MatchExactly | Qt::MatchRecursive); + if(!lst.isEmpty()) { + QModelIndex idx = index(lst[0].row(), SUIT_DataObject::VisibilityId ,lst[0].parent()); + emit dataChanged(idx,idx); + } + it++; + } + } +} + +/*! + \brief Get visibility state of the object. + + \param id - column name + \return visible state +*/ +Qtx::VisibilityState SUIT_TreeModel::visibilityState(const QString& id) const { + if(myVisibilityMap.contains(id)) + return myVisibilityMap.value(id); + else + return Qtx::UnpresentableState; +} + /*! \brief Get data tree root object. \return data tree root @@ -684,12 +796,24 @@ QVariant SUIT_TreeModel::data( const QModelIndex& index, int role ) const { case DisplayRole: // data object text for the specified column - val = obj->text( id ); + val = obj->text( id ); break; - case DecorationRole: - // data object icon for the specified column - val = obj->icon( id ); + case DecorationRole: { + if(id == SUIT_DataObject::VisibilityId) { + int anId = obj->customData(Qtx::IdType).toInt(); + QString objId = data(createIndex(index.row(),anId,index.internalPointer())).toString(); + if(myVisibilityMap.contains(objId)) { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + val = (myVisibilityMap.value(objId) == Qtx::ShownState) ? + resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" )) : resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" )); + } else { + val = QIcon(); + } + } else { + val = obj->icon( id ); + } break; + } case ToolTipRole: // data object tooltip for the specified column val = obj->toolTip( id ); @@ -848,11 +972,19 @@ QVariant SUIT_TreeModel::headerData( int column, Qt::Orientation orientation, in { case DisplayRole: // column title - d = myColumns[column].myName; + if((myColumns[column].myHeaderFlags & Qtx::ShowText) || + (myColumns[column].myHeaderFlags == Qtx::ShowAll)) + d = myColumns[column].myName; + else + d = QString(); break; case DecorationRole: // column icon - d = myColumns[column].myIcon; + if((myColumns[column].myHeaderFlags & Qtx::ShowIcon) || + (myColumns[column].myHeaderFlags == Qtx::ShowAll)) + d = myColumns[column].myIcon; + else + d = QIcon(); break; case AppropriateRole: // appropriate flag (can column be hidden via context popup menu) @@ -926,8 +1058,10 @@ int SUIT_TreeModel::columnCount( const QModelIndex& /*parent*/ ) const */ int SUIT_TreeModel::rowCount( const QModelIndex& parent ) const { - if ( parent.column() > 0 ) - return 0; + // Commented by rnv in the frame of the + // "20830: EDF 1357 GUI : Hide/Show Icon" imp + // if ( parent.column() > 0 ) + // return 0; TreeItem* parentItem = treeItem( parent ); @@ -1079,6 +1213,19 @@ QAbstractItemDelegate* SUIT_TreeModel::delegate() const return new SUIT_ItemDelegate( const_cast( this ) ); } + +void SUIT_TreeModel::emitClicked( SUIT_DataObject* obj, const QModelIndex& index) { + int obj_group_id = obj->groupId(); + const ColumnInfo& inf = myColumns[index.column()]; + + int id = -1; + if( inf.myIds.contains( 0 ) ) + id = inf.myIds[0]; + if( inf.myIds.contains( obj_group_id ) ) + id = inf.myIds[obj_group_id]; + emit clicked(obj, id); +} + /*! \brief Update tree model. @@ -1209,6 +1356,14 @@ void SUIT_TreeModel::initialize() myRootItem = new TreeItem( 0 ); registerColumn( 0, QObject::tr( "NAME_COLUMN" ), SUIT_DataObject::NameId ); + + QString visCol = QObject::tr( "VISIBILITY_COLUMN" ); + registerColumn( 0, visCol, SUIT_DataObject::VisibilityId ); + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + setColumnIcon( visCol, resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) )); + setHeaderFlags( visCol, Qtx::ShowIcon); + updateTree(); } @@ -1434,6 +1589,7 @@ SUIT_ProxyModel::SUIT_ProxyModel( QObject* parent ) { SUIT_TreeModel* model = new SUIT_TreeModel( this ); connect( model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) ); + connect( model, SIGNAL( clicked(SUIT_DataObject*, int) ), this, SIGNAL(clicked(SUIT_DataObject*, int) ) ); setSourceModel( model ); setDynamicSortFilter( true ); } @@ -1449,6 +1605,7 @@ SUIT_ProxyModel::SUIT_ProxyModel( SUIT_DataObject* root, QObject* parent ) { SUIT_TreeModel* model = new SUIT_TreeModel( root, this ); connect( model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) ); + connect( model, SIGNAL( clicked(SUIT_DataObject*, int) ), this, SIGNAL(clicked(SUIT_DataObject*, int) ) ); setSourceModel( model ); setDynamicSortFilter( true ); } @@ -1463,6 +1620,7 @@ SUIT_ProxyModel::SUIT_ProxyModel( SUIT_AbstractModel* model, QObject* parent ) mySortingEnabled( true ) { connect( *model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) ); + connect( *model, SIGNAL( clicked(SUIT_DataObject*, int) ), this, SIGNAL(clicked(SUIT_DataObject*, int) ) ); setSourceModel( *model ); setDynamicSortFilter( true ); } @@ -1784,10 +1942,70 @@ Qtx::Appropriate SUIT_ProxyModel::appropriate( const QString& name ) const return treeModel() ? treeModel()->appropriate( name ) : Qtx::Shown; } +/*! + \brief Set header flags. + + These flags allow show in the header of the column text (name of the column), + icon or both text and icon. + + \param name - column name + \param flags - header flags + +*/ +void SUIT_ProxyModel::setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ) { + if(treeModel()) + treeModel()->setHeaderFlags(name, flags); +} + +/*! + \brief Get the header flags. + + These flags allow show in the header of the column text (name of the column), + icon or both text and icon. + + \param name - column name + \return header flags +*/ +Qtx::HeaderViewFlags SUIT_ProxyModel::headerFlags( const QString& name ) const { + return treeModel() ? treeModel()->headerFlags( name ) : Qtx::ShowAll; +} +/*! + \brief Set visibility state of the object. + + \param id - column name + \param state - visible state +*/ +void SUIT_ProxyModel::setVisibilityState(const QString& id, Qtx::VisibilityState state) { + if(treeModel()) + treeModel()->setVisibilityState(id,state); +} +/*! + \brief Set visibility state for all objects. + + \param id - column name + \param state - visible state +*/ +void SUIT_ProxyModel::setVisibilityStateForAll(Qtx::VisibilityState state) { + if(treeModel()) + treeModel()->setVisibilityStateForAll(state); +} +/*! + \brief Get visibility state of the object. + + \param id - column name + \return visible state +*/ +Qtx::VisibilityState SUIT_ProxyModel::visibilityState(const QString& id) const { + return treeModel() ? treeModel()->visibilityState(id) : Qtx::UnpresentableState; +} +void SUIT_ProxyModel::emitClicked( SUIT_DataObject* obj, const QModelIndex& index) { + if(treeModel()) + treeModel()->emitClicked(obj,index); +} /*! \class SUIT_ItemDelegate @@ -1839,7 +2057,7 @@ void SUIT_ItemDelegate::paint( QPainter* painter, opt.palette.setBrush( QPalette::Highlight, val.value() ); val = index.data( SUIT_TreeModel::HighlightedTextRole ); if ( val.isValid() && val.value().isValid() ) - opt.palette.setBrush( QPalette::HighlightedText, val.value() ); + opt.palette.setBrush( QPalette::HighlightedText, val.value() ); } QItemDelegate::paint( painter, opt, index ); } diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index a1711fe01..f47033ff2 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -32,6 +32,7 @@ #include #include #include +#include #ifdef WIN32 #pragma warning( disable:4251 ) @@ -49,29 +50,36 @@ public: operator QAbstractItemModel*(); operator const QObject*() const; - virtual SUIT_DataObject* root() const = 0; - virtual void setRoot( SUIT_DataObject* ) = 0; - virtual SUIT_DataObject* object( const QModelIndex& = QModelIndex() ) const = 0; - virtual QModelIndex index( const SUIT_DataObject*, int = 0 ) const = 0; - virtual bool autoDeleteTree() const = 0; - virtual void setAutoDeleteTree( const bool ) = 0; - virtual bool autoUpdate() const = 0; - virtual void setAutoUpdate( const bool ) = 0; - virtual bool updateModified() const = 0; - virtual void setUpdateModified( const bool ) = 0; + virtual SUIT_DataObject* root() const = 0; + virtual void setRoot( SUIT_DataObject* ) = 0; + virtual SUIT_DataObject* object( const QModelIndex& = QModelIndex() ) const = 0; + virtual QModelIndex index( const SUIT_DataObject*, int = 0 ) const = 0; + virtual bool autoDeleteTree() const = 0; + virtual void setAutoDeleteTree( const bool ) = 0; + virtual bool autoUpdate() const = 0; + virtual void setAutoUpdate( const bool ) = 0; + virtual bool updateModified() const = 0; + virtual void setUpdateModified( const bool ) = 0; virtual QAbstractItemDelegate* delegate() const = 0; - virtual bool customSorting( const int ) const = 0; - virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const = 0; - - virtual void updateTree( const QModelIndex& ) = 0; - virtual void updateTree( SUIT_DataObject* = 0 ) = 0; - - 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 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; - virtual Qtx::Appropriate appropriate( const QString& name ) const = 0; + virtual bool customSorting( const int ) const = 0; + virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const = 0; + + virtual void updateTree( const QModelIndex& ) = 0; + virtual void updateTree( SUIT_DataObject* = 0 ) = 0; + + 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 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; + virtual Qtx::Appropriate appropriate( const QString& name ) const = 0; + virtual void setVisibilityState(const QString& id, Qtx::VisibilityState state) = 0; + virtual void setVisibilityStateForAll(Qtx::VisibilityState state) = 0; + virtual Qtx::VisibilityState visibilityState(const QString& id) const = 0; + virtual void setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ) = 0; + virtual Qtx::HeaderViewFlags headerFlags( const QString& name ) const = 0; + virtual void emitClicked( SUIT_DataObject* obj, const QModelIndex& index) = 0; + }; @@ -130,6 +138,13 @@ public: virtual QPixmap columnIcon( const QString& name ) const; virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr ); virtual Qtx::Appropriate appropriate( const QString& name ) const; + virtual void setVisibilityState(const QString& id, Qtx::VisibilityState state); + virtual void setVisibilityStateForAll(Qtx::VisibilityState state); + virtual Qtx::VisibilityState visibilityState(const QString& id) const; + virtual void setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ); + virtual Qtx::HeaderViewFlags headerFlags( const QString& name ) const; + virtual void emitClicked( SUIT_DataObject* obj, const QModelIndex& index); + SUIT_DataObject* object( const QModelIndex& = QModelIndex() ) const; QModelIndex index( const SUIT_DataObject*, int = 0 ) const; @@ -148,6 +163,7 @@ public: QAbstractItemDelegate* delegate() const; + virtual void updateTreeModel(SUIT_DataObject*,TreeItem*); public slots: @@ -156,6 +172,7 @@ public slots: signals: void modelUpdated(); + void clicked( SUIT_DataObject*, int ); private: void initialize(); @@ -181,13 +198,17 @@ private: QString myName; QMap myIds; QPixmap myIcon; + Qtx::HeaderViewFlags myHeaderFlags; Qtx::Appropriate myAppropriate; } ColumnInfo; + + typedef QMap VisibilityMap; SUIT_DataObject* myRoot; TreeItem* myRootItem; ItemMap myItems; + VisibilityMap myVisibilityMap; bool myAutoDeleteTree; bool myAutoUpdate; bool myUpdateModified; @@ -231,6 +252,13 @@ public: virtual QPixmap columnIcon( const QString& name ) const; virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr ); virtual Qtx::Appropriate appropriate( const QString& name ) const; + virtual void setVisibilityState(const QString& id, Qtx::VisibilityState state); + virtual void setVisibilityStateForAll(Qtx::VisibilityState state); + virtual Qtx::VisibilityState visibilityState(const QString& id) const; + virtual void setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ); + virtual Qtx::HeaderViewFlags headerFlags( const QString& name ) const; + virtual void emitClicked( SUIT_DataObject* obj, const QModelIndex& index); + QAbstractItemDelegate* delegate() const; @@ -241,6 +269,7 @@ public slots: signals: void modelUpdated(); + void clicked( SUIT_DataObject*, int ); protected: SUIT_AbstractModel* treeModel() const; diff --git a/src/SUIT/resources/SUIT_images.ts b/src/SUIT/resources/SUIT_images.ts new file mode 100644 index 000000000..250fc0bb8 --- /dev/null +++ b/src/SUIT/resources/SUIT_images.ts @@ -0,0 +1,36 @@ + + + + @default + + ICON_DATAOBJ_VISIBLE + icon_visibility_on.png + + + ICON_DATAOBJ_INVISIBLE + icon_visibility_off.png + + + diff --git a/src/SUIT/resources/icon_visibility_off.png b/src/SUIT/resources/icon_visibility_off.png new file mode 100644 index 0000000000000000000000000000000000000000..31c505d82d1b08a54ac666f380e47837c04a9247 GIT binary patch literal 344 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6I14-?iy0WWg+Z8+Vb&Z8pdd@S zqpu?a!^Xav-+_~Xe1&9>AYTTCDpdxChGqtapZ|gMO9qBg0|tgy2@DKYGZ+}e^C!h0 zbpxtB=jq}YQgLg`g}q)*j54er?(g*wk?M6SZd-7Lc?-+M3t|_!P0V(f{Xe+!s?!SF z7o4|lH+Mu8t$6Abuq9$iMwEAw>6Irl`P!MEEC2jp9wco3z&Rn-BTl&>U-6Uw^&Q z+YbKhU*1G_PHCP|D)HrP#igwaTB7dk=+3H{dZ)8;J6l`al52BL-Z|bcT3xtO)zBo} l>!#KLZ*U+5Lu!Sk^o_Z5E4Meg@_7P6crJiNL9pw)e1;Xm069{HJUZAPk55R%$-RIA z6-eL&AQ0xu!e<4=008gy@A0LT~suv4>S3ILP<0Bm`DLLvaF4FK%)Nj?Pt*r}7;7Xa9z9H|HZjR63e zC`Tj$K)V27Re@400>HumpsYY5E(E}?0f1SyGDiY{y#)Yvj#!WnKwtoXnL;eg03bL5 z07D)V%>y7z1E4U{zu>7~aD})?0RX_umCct+(lZpemCzb@^6=o|A>zVpu|i=NDG+7} zl4`aK{0#b-!z=TL9Wt0BGO&T{GJWpjryhdijfaIQ&2!o}p04JRKYg3k&Tf zVxhe-O!X z{f;To;xw^bEES6JSc$k$B2CA6xl)ltA<32E66t?3@gJ7`36pmX0IY^jz)rRYwaaY4 ze(nJRiw;=Qb^t(r^DT@T3y}a2XEZW-_W%Hszxj_qD**t_m!#tW0KDiJT&R>6OvVTR z07RgHDzHHZ48atvzz&?j9lXF70$~P3Knx_nJP<+#`N z#-MZ2bTkiLfR>_b(HgWKJ%F~Nr_oF3b#wrIijHG|(J>BYjM-sajE6;FiC7vY#};Gd zST$CUHDeuEH+B^pz@B062qXfFfD`NpUW5?BY=V%GM_5c)L#QR}BeW8_2v-S%gfYS= zB9o|3v?Y2H`NVi)In3rTB8+ej^> zQ=~r95NVuDChL%G$=>7$vVg20myx%S50Foi`^m%Pw-h?Xh~i8Mq9jtJloCocWk2Nv zrJpiFnV_ms&8eQ$2&#xWpIS+6pmtC%Q-`S&GF4Q#^mhymh7E(qNMa}%YZ-ePrx>>xFPTiH1=E+A$W$=bG8>s^ zm=Bn5Rah$aDtr}@$`X}2l~$F0mFKEdRdZE8)p@E5RI61Ft6o-prbbn>P~)iy)E2AN zsU20jsWz_8Qg>31P|s0cqrPALg8E|(vWA65poU1JRAaZs8I2(p#xiB`SVGovRs-uS zYnV-9TeA7=Om+qP8+I>yOjAR1s%ETak!GFdam@h^# z)@rS0t$wXH+Irf)+G6c;?H29p+V6F6oj{!|o%K3xI`?%6x;DB|x`n#ibhIR?(H}Q3Gzd138Ei2)WAMz7W9Vy`X}HnwgyEn!VS)>mv$8&{hQn>w4zwy3R}t;BYlZQm5)6pty=DfLrs+A-|>>;~;Q z_F?uV_HFjh9n2gO9o9Q^JA86v({H5aB!kjoO6 zc9$1ZZKsN-Zl8L~mE{`ly3)1N^`o1+o7}D0ZPeY&J;i;i`%NyJ8_8Y6J?}yE@b_5a zam?eLr<8@mESk|3$_SkmS{wQ>%qC18))9_|&j{ZT zes8AvOzF(F2#DZEY>2oYX&IRp`F#{ADl)1r>QS^)ba8a|EY_^#S^HO&t^Rgqwv=MZThqqEWH8 zxJo>d=ABlR_Bh=;eM9Tw|Ih34~oTE|= zX_mAr*D$vzw@+p(E0Yc6dFE}(8oqt`+R{gE3x4zjX+Sb3_cYE^= zgB=w+-tUy`ytONMS8KgRef4hA?t0j zufM;t32jm~jUGrkaOInTZ`zyfns>EuS}G30LFK_G-==(f<51|K&cocp&EJ`SxAh3? zNO>#LI=^+SEu(FqJ)ynt=!~PC9bO$rzPJB=?=j6w@a-(u02P7 zaQ)#(uUl{HW%tYNS3ItC^iAtK(eKlL`f9+{bJzISE?u8_z3;~C8@FyI-5j_jy7l;W z_U#vU3hqqYU3!mrul&B+{ptt$59)uk{;_4iZQ%G|z+lhASr6|H35TBkl>gI*;nGLU zN7W-nBaM%pA0HbH8olyl&XeJ%vZoWz%6?Y=dFykl=imL}`%BMQ{Mhgd`HRoLu6e2R za__6DuR6yg#~-}Tc|Gx_{H@O0eebyMy5GmWADJlpK>kqk(fVV@r_fLLKIeS?{4e)} z^ZO;zpECde00d`2O+f$vv5tKEQIh}w03c&XQcVB=dL;k=fP(-4`Tqa_faw4Lbua(` z>RI+y?e7jKeZ#YO-C0gXvSK~#9!?32H1T5%M`Ki`)aoA??DLPdmPL;{8U5JB8J z6oSptq2SQXRsRA92f+sp6&DwW{sBVVk_=|fkPs4HG(#Xr+oUvvXxdt};iTkj}r(4)PpGp{a%yy$3xuCaXOz)_%`^tZ6=dZx~@~HRAh7m z!!X3_^%99h6u_I+9X=ecGiaI&hJtlZ(=Hy5|78j*0GJ=U;^9s4$bxuO;fyj z=4ErEOrz1DR;!KDP}i%R&*x=t|A5`vTNs-}h8Awu6b}24h5303g~A_Es{g;hj{yL# WTb=;+;gt>m0000 -#include "SALOME_InteractiveObject.hxx" - +#include +#include /*! \file SVTK_Functor.h This file contains numbers of functors that allows user to perform corresponding operations with existing presentations. @@ -107,6 +107,25 @@ namespace SVTK } }; + + //---------------------------------------------------------------- + /*! + This collect visible IO in list + */ + template + struct TCollectIfVisible + { + SALOME_ListIO& myList; + //! To construct the functor + TCollectIfVisible (SALOME_ListIO& theList) : myList(theList) + {} + //! To calculate the functor + void operator()(TActor* theActor) + { + if(theActor->GetVisibility() && theActor->hasIO()) + myList.Append( theActor->getIO() ); + } + }; } diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 1e70b3ab4..b949511a5 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -714,3 +714,14 @@ SVTK_View return QColor(0,0,0); } +/*! + \Collect objects visible in viewer + \param theList - visible objects collection +*/ +void SVTK_View::GetVisible( SALOME_ListIO& theList ) +{ + using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEach(aCopy.GetActors(), + TCollectIfVisible(theList)); +} diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index 1baab2823..ac943026b 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -28,7 +28,9 @@ #endif #include "SVTK.h" -#include "SALOME_InteractiveObject.hxx" + +#include +#include #include @@ -244,6 +246,10 @@ public: Remove(SALOME_Actor* SActor, bool updateViewer = true); + //! Collect objects visible in viewer + void + GetVisible( SALOME_ListIO& theList ); + //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_Renderer::SetPreselectionProp void diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 58d4e47d8..6b5d0cfa6 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -653,6 +653,21 @@ bool SVTK_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& io ) return true; } +/*! + \Collect objects visible in viewer + \param theList - visible objects collection +*/ +void SVTK_Viewer::GetVisible( SALOME_ListIO& theList ) +{ + // here we collect object if it is disaplaed even one view + QVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) + if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) + if(TViewWindow* aViewWnd = dynamic_cast(aViewWindow)) + if(SVTK_View* aView = aViewWnd->getView()) + aView->GetVisible( theList ); +} + /*! Updates current viewer */ diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index 5e038d2c7..4cc7aaa17 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -26,8 +26,9 @@ #include "SVTK.h" #include "SVTK_ViewModelBase.h" -#include "SALOME_Prs.h" -#include "SALOME_InteractiveObject.hxx" +#include +#include +#include #include #include @@ -137,6 +138,9 @@ public: //! See #SALOME_View::EraseAll( const bool = false ) void EraseAll( const bool = false ); + //! See #SALOME_View::getVisible( SALOME_ListIO& ) + virtual void GetVisible( SALOME_ListIO& ); + //! See #SALOME_View::CreatePrs( const char* entry = 0 ) SALOME_Prs* CreatePrs( const char* entry = 0 ); diff --git a/src/SalomeApp/Makefile.am b/src/SalomeApp/Makefile.am index c82f8e5eb..67185c8e8 100755 --- a/src/SalomeApp/Makefile.am +++ b/src/SalomeApp/Makefile.am @@ -116,7 +116,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 +126,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 04628a80b..b1f2201a7 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -45,10 +45,12 @@ #include "SalomeApp_ExitDlg.h" #include +#include #include #include #include #include +#include #include @@ -61,6 +63,9 @@ #include #include #include +#include +#include +#include #include @@ -89,8 +94,10 @@ #include #include -#include #include +#include +#include + #include #include @@ -154,6 +161,9 @@ 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 +349,25 @@ void SalomeApp_Application::createActions() } + +/*!Set desktop:*/ +void SalomeApp_Application::setDesktop( SUIT_Desktop* desk ) +{ + SUIT_Desktop* prev = desktop(); + if ( prev == desk ) + return; + + LightApp_Application::setDesktop( desk ); + + if ( desk != 0 ) { + connect( desk, SIGNAL( message( const QString& ) ), + this, SLOT( onDesktopMessage( const QString& ) ), Qt::UniqueConnection); + + connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); + } +} + /*! \brief Close application. */ @@ -1456,6 +1485,10 @@ void SalomeApp_Application::onDeleteGUIState() void SalomeApp_Application::onStudyCreated( SUIT_Study* study ) { LightApp_Application::onStudyCreated( study ); + + connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), + this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection ); + objectBrowserColumnsVisibility(); } @@ -1477,8 +1510,11 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* study ) { LightApp_Application::onStudyOpened( study ); - objectBrowserColumnsVisibility(); + connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), + this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection ); + objectBrowserColumnsVisibility(); + // temporary commented /*if ( objectBrowser() ) { updateSavePointDataObjects( dynamic_cast( study ) ); @@ -1696,3 +1732,100 @@ 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 ); + + SUIT_ViewModel* vmod = 0; + if ( SUIT_ViewManager* vman = theViewWindow->getViewManager() ) + vmod = vman->getViewModel(); + updateVisibilityState( listObj, vmod ); +} + +/*! + Update visibility state of given objects + */ +void SalomeApp_Application::updateVisibilityState( DataObjectList& theList, + SUIT_ViewModel* theViewModel ) +{ + LightApp_Study* aStudy = dynamic_cast(activeStudy()); + + if(!theViewModel) + return; + + SALOME_View* aView = dynamic_cast( theViewModel ); + + if (theList.isEmpty() || !aView || !aStudy) + return; + + // take visibale objects from current view + QStringList aVisibleList; + SALOME_ListIO aListOfIO; + aView->GetVisible( aListOfIO ); + SALOME_ListIteratorOfListIO anIter(aListOfIO); + for(; anIter.More(); anIter.Next()) { + Handle_SALOME_InteractiveObject& anObj = anIter.Value(); + if (!anObj.IsNull() && anObj->hasEntry()) + aVisibleList.append(anObj->getEntry()); + } + + for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) + { + LightApp_DataObject* obj = dynamic_cast(*itr); + if (!obj ) continue; + + //if object is visible in aView => set Qtx::ShownState status + if ( aVisibleList.contains( obj->entry() ) ) + aStudy->setVisibilityState( obj->entry(), Qtx::ShownState ); + else { + //check that object can be displayed in the aView + //and set Qtx::HiddenState + Qtx::VisibilityState anObjState = Qtx::UnpresentableState; + LightApp_Module* anObjModule = dynamic_cast(obj->module()); + + if(anObjModule) { + LightApp_Displayer* aDisplayer = anObjModule->displayer(); + + if(aDisplayer && !aStudy->isComponent(obj->entry())) { + if(aDisplayer->canBeDisplayed(obj->entry(), theViewModel->getType())) { + anObjState = Qtx::HiddenState; + } + } + } + aStudy->setVisibilityState( obj->entry(), anObjState ); + } + } +} + +/*! + Called then view manager removed +*/ +void SalomeApp_Application::onViewManagerRemoved( SUIT_ViewManager* ) { + ViewManagerList lst; + viewManagers(lst); + if( lst.count() == 1) { // in case if closed last view window + LightApp_Study* aStudy = dynamic_cast(activeStudy()); + if(aStudy) + aStudy->setVisibilityStateForAll(Qtx::UnpresentableState); + } +} + +/*! + Called then study closed +*/ +void SalomeApp_Application::onStudyClosed( SUIT_Study* theStudy){ + LightApp_Application::onStudyClosed(theStudy); + + disconnect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), + this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) ); +} diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index f30f8017c..2278671bc 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 SUIT_ViewModel; 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, + SUIT_ViewModel* theViewModel ); + public slots: virtual void onLoadDoc(); virtual void onNewWithScript(); @@ -120,6 +129,9 @@ protected slots: void onStudySaved( SUIT_Study* ); void onStudyOpened( SUIT_Study* ); void onDesktopMessage( const QString& ); + void onStudyClosed( SUIT_Study* ); + + void onViewManagerRemoved( SUIT_ViewManager* ); protected: virtual void createActions(); @@ -159,6 +171,8 @@ private slots: void onOpenWith(); void onExtAction(); + void onWindowActivated( SUIT_ViewWindow* theViewWindow ); + private: void createExtraActions(); diff --git a/src/SalomeApp/SalomeApp_Module.cxx b/src/SalomeApp/SalomeApp_Module.cxx index 4e35ccca7..4e176537d 100644 --- a/src/SalomeApp/SalomeApp_Module.cxx +++ b/src/SalomeApp/SalomeApp_Module.cxx @@ -39,14 +39,19 @@ #include #include #include + +#include #include +#include +#include #include /*!Constructor.*/ SalomeApp_Module::SalomeApp_Module( const QString& name ) -: LightApp_Module( name ) + : LightApp_Module( name ), + myIsFirstActivate( true ) { } @@ -127,12 +132,51 @@ void SalomeApp_Module::extractContainers( const SALOME_ListIO& source, SALOME_Li * \brief Virtual public * * This method is called just before the study document is saved, so the module has a possibility - * to store visual parameters in AttributeParameter attribue(s) + * to store visual parameters in AttributeParameter attribut */ void SalomeApp_Module::storeVisualParameters(int savePoint) { } + +/*!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 + SalomeApp_Application* app = dynamic_cast(application()); + if (!app) + return false; + + SUIT_DataBrowser* ob = app->objectBrowser(); + if (!ob || !ob->model()) + return false; + + // connect to click on item + connect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ), + this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ), Qt::UniqueConnection ); + + + SUIT_DataObject* rootObj = ob->root(); + if( !rootObj ) + return false; + + DataObjectList listObj = rootObj->children( true ); + + SUIT_ViewModel* vmod = 0; + if ( SUIT_ViewManager* vman = app->activeViewManager() ) + vmod = vman->getViewModel(); + app->updateVisibilityState( listObj, vmod ); + + return state; +} + /*! * \brief Virtual public * @@ -143,3 +187,54 @@ void SalomeApp_Module::restoreVisualParameters(int savePoint) { } +/*! 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 && ob->model()) + disconnect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ), + this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ) ); +} + + +/*! + * \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; + + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if( !study ) + return; + + LightApp_DataObject* lo = dynamic_cast(theObject); + if(!lo) + return; + + // detect action index (from LightApp level) + int id = -1; + + if ( study->visibilityState(lo->entry()) == Qtx::ShownState ) + id = myErase; + else if ( study->visibilityState(lo->entry()) == Qtx::HiddenState ) + id = myDisplay; + + if ( id != -1 ) + startOperation( id ); +} diff --git a/src/SalomeApp/SalomeApp_Module.h b/src/SalomeApp/SalomeApp_Module.h index 9530f9da0..8f12259e3 100644 --- a/src/SalomeApp/SalomeApp_Module.h +++ b/src/SalomeApp/SalomeApp_Module.h @@ -36,10 +36,11 @@ class SalomeApp_Application; class LightApp_Selection; class SALOME_ListIO; class QString; +class SUIT_DataObject; /*! * \brief Base class for all salome modules -*/ + */ class SALOMEAPP_EXPORT SalomeApp_Module : virtual public LightApp_Module { Q_OBJECT @@ -62,10 +63,19 @@ public: virtual void storeVisualParameters(int savePoint); virtual void restoreVisualParameters(int savePoint); virtual LightApp_Selection* createSelection() const; + + public slots: + virtual bool activateModule( SUIT_Study* ); + virtual void studyClosed( SUIT_Study* ); + virtual void onObjectClicked( SUIT_DataObject*, int ); protected: virtual CAM_DataModel* createDataModel(); virtual void extractContainers( const SALOME_ListIO&, SALOME_ListIO& ) const; + + + protected: + bool myIsFirstActivate; }; #endif diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 0b6c411db..353e63d3a 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -28,13 +28,15 @@ #include "SalomeApp_Application.h" #include "SalomeApp_Engine_i.hxx" #include "SalomeApp_VisualState.h" -#include "SUIT_TreeModel.h" -#include "SUIT_DataBrowser.h" // temporary commented //#include #include +#include +#include + +#include #include "utilities.h" @@ -63,129 +65,152 @@ public: virtual void notifyObserverID(const char* theID, CORBA::Long event) { - // MESSAGE("notifyObserverID: theID:" << theID << " event:" << event); - SalomeApp_DataObject* suit_obj; - if ( event == 1 ) // add sobject - { - EntryMapIter it = entry2SuitObject.find( theID ); - if ( it != entry2SuitObject.end() ) - { - MESSAGE("Entry " << theID << " is already added. Problem ??"); - return; - } - - _PTR(SObject) obj = myStudyDS->FindObjectID( theID ); - std::string entry_str = theID; - int last2Pnt_pos = entry_str.rfind( ":" ); - std::string parent_id = entry_str.substr( 0, last2Pnt_pos ); - int tag = atoi( entry_str.substr( last2Pnt_pos+1 ).c_str() ); + switch(event) { + case 1: + { //Add sobject + EntryMapIter it = entry2SuitObject.find( theID ); + if ( it != entry2SuitObject.end() ) + { + MESSAGE("Entry " << theID << " is already added. Problem ??"); + return; + } + _PTR(SObject) obj = myStudyDS->FindObjectID( theID ); + std::string entry_str = theID; + int last2Pnt_pos = entry_str.rfind( ":" ); + std::string parent_id = entry_str.substr( 0, last2Pnt_pos ); + int tag = atoi( entry_str.substr( last2Pnt_pos+1 ).c_str() ); - if ( parent_id.length() == 3 ) // "0:1" - root item? - { - // It's probably a SComponent - _PTR(SComponent) aSComp = obj->GetFatherComponent(); - if ( aSComp && !aSComp->IsNull() && aSComp->GetID() == entry_str ) - suit_obj = new SalomeApp_ModuleObject( aSComp ); + if ( parent_id.length() == 3 ) // "0:1" - root item? + { + // It's probably a SComponent + _PTR(SComponent) aSComp = obj->GetFatherComponent(); + if ( aSComp && !aSComp->IsNull() && aSComp->GetID() == entry_str ) + suit_obj = new SalomeApp_ModuleObject( aSComp ); + else + suit_obj = new SalomeApp_DataObject( obj ); + } else + { suit_obj = new SalomeApp_DataObject( obj ); - } - else - { - suit_obj = new SalomeApp_DataObject( obj ); - } + } - it = entry2SuitObject.find( parent_id ); - if ( it != entry2SuitObject.end() ) - { - SalomeApp_DataObject* father = it->second; - father->insertChildAtTag( suit_obj, tag ); - } - else - { - if ( parent_id.length() == 3 ) // "0:1" - root item? + it = entry2SuitObject.find( parent_id ); + if ( it != entry2SuitObject.end() ) { - // This should be for a module - SUIT_DataObject* father=myStudy->root(); - father->appendChild(suit_obj); + SalomeApp_DataObject* father = it->second; + father->insertChildAtTag( suit_obj, tag ); } else { - MESSAGE("SHOULD NEGER GET HERE!!!"); - - //Try to find the SalomeApp_DataObject object parent - std::string root_id = parent_id.substr( 0, 4 ); - std::string obj_id = parent_id.substr( 4 ); - - std::string anID; - string::size_type debut = 0; - string::size_type fin; - SalomeApp_DataObject* anObj = dynamic_cast( myStudy->root() ); - while ( 1 ) + if ( parent_id.length() == 3 ) // "0:1" - root item? { - fin = obj_id.find_first_of( ':', debut ); - if ( fin == std::string::npos ) - { - //last id - anObj = dynamic_cast( anObj->childObject( atoi( obj_id.substr( debut ).c_str() )-1 ) ); - entry2SuitObject[parent_id] = anObj; - break; - } - anID = root_id + obj_id.substr( 0, fin ); - EntryMapIter it2 = entry2SuitObject.find( anID ); - if ( it2 == entry2SuitObject.end() ) + // This should be for a module + SUIT_DataObject* father=myStudy->root(); + father->appendChild(suit_obj); + } + else + { + MESSAGE("SHOULD NEGER GET HERE!!!"); + + //Try to find the SalomeApp_DataObject object parent + std::string root_id = parent_id.substr( 0, 4 ); + std::string obj_id = parent_id.substr( 4 ); + + std::string anID; + string::size_type debut = 0; + string::size_type fin; + SalomeApp_DataObject* anObj = dynamic_cast( myStudy->root() ); + while ( 1 ) { - //the ID is not known in entry2SuitObject - anObj = dynamic_cast( anObj->childObject( atoi( obj_id.substr( debut, fin-debut ).c_str() )-1 ) ); - entry2SuitObject[anID] = anObj; + fin = obj_id.find_first_of( ':', debut ); + if ( fin == std::string::npos ) + { + //last id + anObj = dynamic_cast( anObj->childObject( atoi( obj_id.substr( debut ).c_str() )-1 ) ); + entry2SuitObject[parent_id] = anObj; + break; + } + anID = root_id + obj_id.substr( 0, fin ); + EntryMapIter it2 = entry2SuitObject.find( anID ); + if ( it2 == entry2SuitObject.end() ) + { + //the ID is not known in entry2SuitObject + anObj = dynamic_cast( anObj->childObject( atoi( obj_id.substr( debut, fin-debut ).c_str() )-1 ) ); + entry2SuitObject[anID] = anObj; + } + else + anObj = it2->second; + debut = fin+1; } - else - anObj = it2->second; - debut = fin+1; + anObj->insertChildAtTag( suit_obj, tag ); } - anObj->insertChildAtTag( suit_obj, tag ); } + entry2SuitObject[theID] = suit_obj; + break; + } + case 2: + { // Remove sobject + EntryMapIter it = entry2SuitObject.find( theID ); + if ( it != entry2SuitObject.end() ) + { + suit_obj = it->second; + // VSR: object is not removed, since SALOMEDS::SObject is not actually removed, only its attributes are cleared; + // thus, the object can be later reused + suit_obj->updateItem(); + //SUIT_DataObject* father=suit_obj->parent(); + //if(father) + // father->removeChild(suit_obj); + //entry2SuitObject.erase(it); + } + else + { + MESSAGE("Want to remove an unknown object" << theID); + } + break; } - entry2SuitObject[theID] = suit_obj; - } - else if ( event == 2 ) // remove sobject - { - EntryMapIter it = entry2SuitObject.find( theID ); - if ( it != entry2SuitObject.end() ) - { - suit_obj = it->second; - // VSR: object is not removed, since SALOMEDS::SObject is not actually removed, only its attributes are cleared; - // thus, the object can be later reused - suit_obj->updateItem(); - //SUIT_DataObject* father=suit_obj->parent(); - //if(father) - // father->removeChild(suit_obj); - //entry2SuitObject.erase(it); - } - else - { - MESSAGE("Want to remove an unknown object" << theID); - } - } - else if ( event == 0 ) //modify sobject - { - EntryMapIter it = entry2SuitObject.find( theID ); - if ( it != entry2SuitObject.end() ) - { - suit_obj = it->second; - suit_obj->updateItem(); + case 0: + { //modify sobject + MESSAGE("Want to modify an object " << theID); + EntryMapIter it = entry2SuitObject.find( theID ); + if ( it != entry2SuitObject.end() ) + { + suit_obj = it->second; + suit_obj->updateItem(); + } + else + { + MESSAGE("Want to modify an unknown object" << theID); + } + break; } - else + case 5: //IOR of the object modified { - MESSAGE("Want to modify an unknown object" << theID); + EntryMapIter it = entry2SuitObject.find( theID ); + if ( it != entry2SuitObject.end() ) + suit_obj = it->second; + + /* Define visibility state */ + if( suit_obj ) { + QString moduleTitle = ((CAM_Application*)myStudy->application())->moduleTitle(suit_obj->componentDataType()); + if(!moduleTitle.isEmpty()) { + LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(moduleTitle,false); + + if(aDisplayer && !myStudy->isComponent(theID)) { + if(aDisplayer->canBeDisplayed(theID)) { + myStudy->setVisibilityState( theID, Qtx::HiddenState ); + MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!"); + } else + MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!"); + } + } + } + break; } - } - else - { - MESSAGE("Unknown event: " << event); - } - } + default:MESSAGE("Unknown event: " << event);break; + } //switch + } //notifyObserverID private: void fillEntryMap() -- 2.39.2