1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "LightApp_DataOwner.h"
23 #include "LightApp_OCCSelector.h"
25 #ifndef DISABLE_SALOMEOBJECT
26 #include <SALOME_InteractiveObject.hxx>
28 #include <AIS_ListOfInteractive.hxx>
29 #include <AIS_ListIteratorOfListOfInteractive.hxx>
34 #ifndef DISABLE_OCCVIEWER
35 LightApp_OCCSelector::LightApp_OCCSelector( OCCViewer_Viewer* viewer, SUIT_SelectionMgr* mgr )
36 : SUIT_Selector( mgr, viewer ),
40 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
41 connect( myViewer, SIGNAL( deselection() ), this, SLOT( onDeselection() ) );
45 LightApp_OCCSelector::LightApp_OCCSelector( SUIT_SelectionMgr* mgr )
46 : SUIT_Selector( mgr )
53 LightApp_OCCSelector::~LightApp_OCCSelector()
60 #ifndef DISABLE_OCCVIEWER
61 OCCViewer_Viewer* LightApp_OCCSelector::viewer() const
68 /*!On selection changed.*/
69 void LightApp_OCCSelector::onSelectionChanged()
74 /*!On selection cleared.*/
75 void LightApp_OCCSelector::onDeselection()
77 mySelectedExternals.clear();
80 /*!Gets selection list.*/
81 void LightApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
83 #ifndef DISABLE_OCCVIEWER
87 AIS_ListOfInteractive aSelList;
88 myViewer->getSelectedObjects( aSelList );
89 for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
90 if ( !anIt.Value().IsNull() )
92 #ifndef DISABLE_SALOMEOBJECT
93 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anIt.Value()->GetOwner());
95 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anObj ) ) );
97 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
100 // add externally selected objects
101 SUIT_DataOwnerPtrList::const_iterator anExtIter;
102 for(anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++) {
103 aList.append(*anExtIter);
108 /*!Sets selection list.*/
109 void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
111 #ifndef DISABLE_OCCVIEWER
115 QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
116 Handle(AIS_InteractiveContext) aContext = myViewer->getAISContext();
117 if ( aContext.IsNull() )
120 AIS_ListOfInteractive aDispList, aSelList;
121 aContext->DisplayedObjects( aDispList );
123 for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
125 QString entryStr = entry( it.Value() );
126 if ( !entryStr.isEmpty() )
127 aDisplayed.insert( entryStr, it.Value() );
130 mySelectedExternals.clear();
132 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
134 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
135 if ( owner && aDisplayed.contains( owner->entry() ) )
136 aSelList.Append( aDisplayed[owner->entry()] );
138 mySelectedExternals.append(*itr);
141 myViewer->unHighlightAll( false );
142 myViewer->setObjectsSelected( aSelList );
146 #ifndef DISABLE_OCCVIEWER
147 /*!Gets entry ob object.*/
148 QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
150 if ( anAIS.IsNull() || !anAIS->HasOwner() )
155 #ifndef DISABLE_SALOMEOBJECT
156 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anAIS->GetOwner());
157 if ( !anObj.IsNull() )
158 res = QString( anObj->getEntry() );