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 #ifndef DISABLE_SALOMEOBJECT
24 #include <SALOME_InteractiveObject.hxx>
26 #include <AIS_ListOfInteractive.hxx>
27 #include <AIS_ListIteratorOfListOfInteractive.hxx>
32 LightApp_OCCSelector::LightApp_OCCSelector( OCCViewer_Viewer* viewer, SUIT_SelectionMgr* mgr )
33 : SUIT_Selector( mgr, viewer ),
37 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
43 LightApp_OCCSelector::~LightApp_OCCSelector()
50 OCCViewer_Viewer* LightApp_OCCSelector::viewer() const
55 /*!On selection changed.*/
56 void LightApp_OCCSelector::onSelectionChanged()
61 /*!Gets selection list.*/
62 void LightApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
67 AIS_ListOfInteractive aSelList;
68 myViewer->getSelectedObjects( aSelList );
69 for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
70 if ( !anIt.Value().IsNull() )
72 #ifndef DISABLE_SALOMEOBJECT
73 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anIt.Value()->GetOwner());
75 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anObj ) ) );
77 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
82 /*!Sets selection list.*/
83 void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
88 QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
89 Handle(AIS_InteractiveContext) aContext = myViewer->getAISContext();
90 if ( aContext.IsNull() )
93 AIS_ListOfInteractive aDispList, aSelList;
94 aContext->DisplayedObjects( aDispList );
96 for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
98 QString entryStr = entry( it.Value() );
99 if ( !entryStr.isEmpty() )
100 aDisplayed.insert( entryStr, it.Value() );
103 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
105 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
106 if ( owner && aDisplayed.contains( owner->entry() ) )
107 aSelList.Append( aDisplayed[owner->entry()] );
110 myViewer->unHighlightAll( false );
111 myViewer->setObjectsSelected( aSelList );
114 /*!Gets entry ob object.*/
115 QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
117 if ( anAIS.IsNull() || !anAIS->HasOwner() )
118 return QString::null;
122 #ifndef DISABLE_SALOMEOBJECT
123 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anAIS->GetOwner());
124 if ( !anObj.IsNull() )
125 res = QString( anObj->getEntry() );