2 #include "SalomeApp_DataOwner.h"
3 #include "SalomeApp_OCCSelector.h"
5 #include <SALOME_InteractiveObject.hxx>
7 #include <AIS_ListOfInteractive.hxx>
8 #include <AIS_ListIteratorOfListOfInteractive.hxx>
13 SalomeApp_OCCSelector::SalomeApp_OCCSelector( OCCViewer_Viewer* viewer, SUIT_SelectionMgr* mgr )
14 : SUIT_Selector( mgr, viewer ),
18 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
24 SalomeApp_OCCSelector::~SalomeApp_OCCSelector()
31 OCCViewer_Viewer* SalomeApp_OCCSelector::viewer() const
36 /*!On selection changed.*/
37 void SalomeApp_OCCSelector::onSelectionChanged()
42 /*!Gets selection list.*/
43 void SalomeApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
48 AIS_ListOfInteractive aSelList;
49 myViewer->getSelectedObjects( aSelList );
50 for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
51 if ( !anIt.Value().IsNull() )
53 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anIt.Value()->GetOwner());
55 aList.append( SUIT_DataOwnerPtr( new SalomeApp_DataOwner( anObj ) ) );
59 /*!Sets selection list.*/
60 void SalomeApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
65 QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
66 Handle(AIS_InteractiveContext) aContext = myViewer->getAISContext();
67 if ( aContext.IsNull() )
70 AIS_ListOfInteractive aDispList, aSelList;
71 aContext->DisplayedObjects( aDispList );
73 for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
75 QString entryStr = entry( it.Value() );
76 if ( !entryStr.isEmpty() )
77 aDisplayed.insert( entryStr, it.Value() );
80 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
82 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
83 if ( owner && aDisplayed.contains( owner->entry() ) )
84 aSelList.Append( aDisplayed[owner->entry()] );
87 myViewer->unHighlightAll( false );
88 myViewer->setObjectsSelected( aSelList );
91 /*!Gets entry ob object.*/
92 QString SalomeApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
94 if ( anAIS.IsNull() || !anAIS->HasOwner() )
97 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anAIS->GetOwner());
100 if ( !anObj.IsNull() )
101 res = QString( anObj->getEntry() );