1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
20 #include "LightApp_DataOwner.h"
21 #include "LightApp_OCCSelector.h"
23 #include <SALOME_InteractiveObject.hxx>
25 #include <AIS_ListOfInteractive.hxx>
26 #include <AIS_ListIteratorOfListOfInteractive.hxx>
31 LightApp_OCCSelector::LightApp_OCCSelector( OCCViewer_Viewer* viewer, SUIT_SelectionMgr* mgr )
32 : SUIT_Selector( mgr, viewer ),
36 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
42 LightApp_OCCSelector::~LightApp_OCCSelector()
49 OCCViewer_Viewer* LightApp_OCCSelector::viewer() const
54 /*!On selection changed.*/
55 void LightApp_OCCSelector::onSelectionChanged()
60 /*!Gets selection list.*/
61 void LightApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
66 AIS_ListOfInteractive aSelList;
67 myViewer->getSelectedObjects( aSelList );
68 for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
69 if ( !anIt.Value().IsNull() )
71 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anIt.Value()->GetOwner());
73 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anObj ) ) );
77 /*!Sets selection list.*/
78 void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
83 QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
84 Handle(AIS_InteractiveContext) aContext = myViewer->getAISContext();
85 if ( aContext.IsNull() )
88 AIS_ListOfInteractive aDispList, aSelList;
89 aContext->DisplayedObjects( aDispList );
91 for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
93 QString entryStr = entry( it.Value() );
94 if ( !entryStr.isEmpty() )
95 aDisplayed.insert( entryStr, it.Value() );
98 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
100 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
101 if ( owner && aDisplayed.contains( owner->entry() ) )
102 aSelList.Append( aDisplayed[owner->entry()] );
105 myViewer->unHighlightAll( false );
106 myViewer->setObjectsSelected( aSelList );
109 /*!Gets entry ob object.*/
110 QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
112 if ( anAIS.IsNull() || !anAIS->HasOwner() )
113 return QString::null;
115 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anAIS->GetOwner());
118 if ( !anObj.IsNull() )
119 res = QString( anObj->getEntry() );