]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
PAL10332 - references are interpreted as original objects in filters, dialogs, etc.
authorasl <asl@opencascade.com>
Tue, 25 Oct 2005 08:14:22 +0000 (08:14 +0000)
committerasl <asl@opencascade.com>
Tue, 25 Oct 2005 08:14:22 +0000 (08:14 +0000)
src/SalomeApp/SalomeApp_Selection.cxx
src/SalomeApp/SalomeApp_Selection.h
src/SalomeApp/SalomeApp_SelectionMgr.cxx
src/SalomeApp/SalomeApp_SelectionMgr.h
src/SalomeApp/SalomeApp_ShowHideOp.cxx

index 894c73393092f60166934b7f2105250f320c2039..3182881af2aac7eee5c4b23a4939de4315fa714f 100644 (file)
@@ -36,6 +36,12 @@ void SalomeApp_Selection::init( const QString& client, SalomeApp_SelectionMgr* m
     if ( mgr->application() )
       myStudy = dynamic_cast<SalomeApp_Study*>( 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<SalomeApp_DataOwner*>( 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.
 */
index ec380f6cfe5144540ee0586b27a72f2030da4ffe..97f05ee521e42aeba70f4440148df535de981ffd 100644 (file)
@@ -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<bool>               myIsReferences; // whether i-th selected object was a reference
   SalomeApp_Study*               myStudy;                                               
 };
 
index c186fad5f6970b682838cca6da229d65f4ff37ae..fec8f3a0b9cdae9e5487c4a25bb5c17a412440f4 100644 (file)
@@ -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<QString,int> entryMap;
+  SalomeApp_Study* st = dynamic_cast<SalomeApp_Study*>( 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<const SalomeApp_DataOwner*>( (*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);
   }
 }
 
index 79e7e7e0d7f54c7b91227117bbae122ed68b8fc1..54643c2e44bc88ad5ca68616be579769555eb42a 100644 (file)
@@ -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, 
index 9fd3f158bed754521402a323135c9e42a4914078..3eb77dfe7fc1874896953286936f418501bd2354 100644 (file)
@@ -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 <SALOME_ListIO.hxx>
+#include <SALOME_ListIteratorOfListIO.hxx>
 
 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<SalomeApp_DataOwner*>( (*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();