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/ or email : webmaster.salome@opencascade.com
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() ) );
38 connect( myViewer, SIGNAL( deselection() ), this, SLOT( onDeselection() ) );
45 LightApp_OCCSelector::~LightApp_OCCSelector()
52 OCCViewer_Viewer* LightApp_OCCSelector::viewer() const
58 /*!On selection changed.*/
59 void LightApp_OCCSelector::onSelectionChanged()
64 /*!On selection cleared.*/
65 void LightApp_OCCSelector::onDeselection()
67 mySelectedExternals.clear();
70 /*!Gets selection list.*/
71 void LightApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
76 AIS_ListOfInteractive aSelList;
77 myViewer->getSelectedObjects( aSelList );
78 for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
79 if ( !anIt.Value().IsNull() )
81 #ifndef DISABLE_SALOMEOBJECT
82 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anIt.Value()->GetOwner());
84 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anObj ) ) );
86 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
89 // add externally selected objects
90 SUIT_DataOwnerPtrList::const_iterator anExtIter;
91 for(anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++) {
92 aList.append(*anExtIter);
96 /*!Sets selection list.*/
97 void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
102 QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
103 Handle(AIS_InteractiveContext) aContext = myViewer->getAISContext();
104 if ( aContext.IsNull() )
107 AIS_ListOfInteractive aDispList, aSelList;
108 aContext->DisplayedObjects( aDispList );
110 for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
112 QString entryStr = entry( it.Value() );
113 if ( !entryStr.isEmpty() )
114 aDisplayed.insert( entryStr, it.Value() );
117 mySelectedExternals.clear();
119 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
121 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
122 if ( owner && aDisplayed.contains( owner->entry() ) )
123 aSelList.Append( aDisplayed[owner->entry()] );
125 mySelectedExternals.append(*itr);
128 myViewer->unHighlightAll( false );
129 myViewer->setObjectsSelected( aSelList );
132 /*!Gets entry ob object.*/
133 QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
135 if ( anAIS.IsNull() || !anAIS->HasOwner() )
136 return QString::null;
140 #ifndef DISABLE_SALOMEOBJECT
141 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anAIS->GetOwner());
142 if ( !anObj.IsNull() )
143 res = QString( anObj->getEntry() );