From 6cba42fb8db780fafcef130c687dbba87dae0942 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 25 Oct 2005 08:14:22 +0000 Subject: [PATCH] PAL10332 - references are interpreted as original objects in filters, dialogs, etc. --- src/SalomeApp/SalomeApp_Selection.cxx | 34 +++++++++++++++++++++-- src/SalomeApp/SalomeApp_Selection.h | 2 ++ src/SalomeApp/SalomeApp_SelectionMgr.cxx | 35 ++++++++++++++++++++---- src/SalomeApp/SalomeApp_SelectionMgr.h | 2 +- src/SalomeApp/SalomeApp_ShowHideOp.cxx | 18 ++++++------ 5 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/SalomeApp/SalomeApp_Selection.cxx b/src/SalomeApp/SalomeApp_Selection.cxx index 894c73393..3182881af 100644 --- a/src/SalomeApp/SalomeApp_Selection.cxx +++ b/src/SalomeApp/SalomeApp_Selection.cxx @@ -36,6 +36,12 @@ void SalomeApp_Selection::init( const QString& client, SalomeApp_SelectionMgr* m if ( mgr->application() ) myStudy = dynamic_cast( mgr->application()->activeStudy() ); + if( !myStudy ) + return; + + _PTR(Study) studyds = myStudy->studyDS(); + _PTR(SObject) refobj; + SUIT_DataOwnerPtrList sel; mgr->selected( sel, client ); SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end(); @@ -43,8 +49,19 @@ void SalomeApp_Selection::init( const QString& client, SalomeApp_SelectionMgr* m { SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() ); SalomeApp_DataOwner* sowner = dynamic_cast( owner ); - if( sowner ) { - myEntries.append( sowner->entry() ); + if( sowner ) + { + _PTR(SObject) obj = studyds->FindObjectID( sowner->entry() ); + if( obj->ReferencedObject( refobj ) ) + { + myEntries.append( refobj->GetID() ); + myIsReferences.append( true ); + } + else + { + myEntries.append( sowner->entry() ); + myIsReferences.append( false ); + } processOwner( sowner ); } } @@ -82,6 +99,8 @@ QtxValue SalomeApp_Selection::param( const int ind, const QString& p ) const if( !mod_name.isEmpty() ) return mod_name; } + else if( p=="isReference" ) + return QtxValue( isReference( ind ), false ); return QtxValue(); } @@ -128,6 +147,17 @@ QString SalomeApp_Selection::entry( const int index ) const return QString(); } +/*! + Returns true if i-th selected object was reference to object with entry( i ) +*/ +bool SalomeApp_Selection::isReference( const int index ) const +{ + if( index >= 0 && index < count() ) + return myIsReferences[ index ]; + else + return false; +} + /*! Gets type of active view manager. */ diff --git a/src/SalomeApp/SalomeApp_Selection.h b/src/SalomeApp/SalomeApp_Selection.h index ec380f6cf..97f05ee52 100644 --- a/src/SalomeApp/SalomeApp_Selection.h +++ b/src/SalomeApp/SalomeApp_Selection.h @@ -55,6 +55,7 @@ public: protected: QString entry( const int ) const; + bool isReference( const int ) const; /*!Gets study.*/ SalomeApp_Study* study() const { return myStudy; } QString activeViewType() const; @@ -63,6 +64,7 @@ protected: private: QString myPopupClient; QStringList myEntries; // entries of selected objects + QValueList myIsReferences; // whether i-th selected object was a reference SalomeApp_Study* myStudy; }; diff --git a/src/SalomeApp/SalomeApp_SelectionMgr.cxx b/src/SalomeApp/SalomeApp_SelectionMgr.cxx index c186fad5f..fec8f3a0b 100644 --- a/src/SalomeApp/SalomeApp_SelectionMgr.cxx +++ b/src/SalomeApp/SalomeApp_SelectionMgr.cxx @@ -44,7 +44,8 @@ SalomeApp_Application* SalomeApp_SelectionMgr::application() const /*! Get all selected objects from selection manager */ -void SalomeApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType ) const +void SalomeApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType, + const bool convertReferences ) const { theList.Clear(); @@ -52,15 +53,37 @@ void SalomeApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QStr selected( aList, theType ); QMap entryMap; + SalomeApp_Study* st = dynamic_cast( application()->activeStudy() ); + if( !st ) + return; + + _PTR(Study) dstudy = st->studyDS(); + QString entry; + _PTR(SObject) refobj; for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) { const SalomeApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); - if( !owner ) continue; - - if ( !entryMap.contains(owner->entry()) ) - theList.Append( owner->IO() ); - entryMap.insert(owner->entry(), 1); + if( !owner ) + continue; + + _PTR(SObject) obj = dstudy->FindObjectID( owner->entry() ); + if( convertReferences && obj->ReferencedObject( refobj ) ) + { + entry = refobj->GetID(); + if( !entryMap.contains( entry ) ) + theList.Append( new SALOME_InteractiveObject( refobj->GetID().c_str(), + refobj->GetFatherComponent()->ComponentDataType().c_str(), + refobj->Name().c_str() ) ); + } + else + { + entry = owner->entry(); + if( !entryMap.contains( entry ) ) + theList.Append( owner->IO() ); + } + + entryMap.insert( entry , 1); } } diff --git a/src/SalomeApp/SalomeApp_SelectionMgr.h b/src/SalomeApp/SalomeApp_SelectionMgr.h index 79e7e7e0d..54643c2e4 100644 --- a/src/SalomeApp/SalomeApp_SelectionMgr.h +++ b/src/SalomeApp/SalomeApp_SelectionMgr.h @@ -26,7 +26,7 @@ public: SalomeApp_Application* application() const; - void selectedObjects( SALOME_ListIO&, const QString& = QString::null ) const; + void selectedObjects( SALOME_ListIO&, const QString& = QString::null, const bool = true ) const; void setSelectedObjects( const SALOME_ListIO&, const bool = false ); void GetIndexes( const Handle(SALOME_InteractiveObject)& IObject, diff --git a/src/SalomeApp/SalomeApp_ShowHideOp.cxx b/src/SalomeApp/SalomeApp_ShowHideOp.cxx index 9fd3f158b..3eb77dfe7 100644 --- a/src/SalomeApp/SalomeApp_ShowHideOp.cxx +++ b/src/SalomeApp/SalomeApp_ShowHideOp.cxx @@ -2,11 +2,12 @@ #include "SalomeApp_ShowHideOp.h" #include "SalomeApp_Application.h" #include "SalomeApp_SelectionMgr.h" -#include "SalomeApp_DataOwner.h" #include "SalomeApp_Selection.h" #include "SalomeApp_Module.h" #include "SalomeApp_Displayer.h" #include "CAM_Study.h" +#include +#include SalomeApp_ShowHideOp::SalomeApp_ShowHideOp( ActionType type ) : SalomeApp_Operation(), @@ -56,19 +57,18 @@ void SalomeApp_ShowHideOp::startOperation() if( myActionType==DISPLAY_ONLY ) d->EraseAll( false, false, 0 ); - SUIT_DataOwnerPtrList selected; - mgr->selected( selected ); - SUIT_DataOwnerPtrList::const_iterator anIt = selected.begin(), aLast = selected.end(); - for( ; anIt!=aLast; anIt++ ) + SALOME_ListIO selObjs; + mgr->selectedObjects( selObjs ); + SALOME_ListIteratorOfListIO anIt( selObjs ); + for( ; anIt.More(); anIt.Next() ) { - SalomeApp_DataOwner* owner = dynamic_cast( (*anIt).operator->() ); - if( !owner ) + if( anIt.Value().IsNull() ) continue; if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY ) - d->Display( owner->entry(), false, 0 ); + d->Display( anIt.Value()->getEntry(), false, 0 ); else if( myActionType==ERASE ) - d->Erase( owner->entry(), false, false, 0 ); + d->Erase( anIt.Value()->getEntry(), false, false, 0 ); } d->UpdateViewer(); commit(); -- 2.39.2