1 // Copyright (C) 2007-2012 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
23 #include "LightApp_DataOwner.h"
24 #include "LightApp_OCCSelector.h"
26 #ifndef DISABLE_SALOMEOBJECT
27 #include <SALOME_InteractiveObject.hxx>
29 #include <AIS_ListOfInteractive.hxx>
30 #include <AIS_ListIteratorOfListOfInteractive.hxx>
35 #ifndef DISABLE_OCCVIEWER
36 LightApp_OCCSelector::LightApp_OCCSelector( OCCViewer_Viewer* viewer, SUIT_SelectionMgr* mgr )
37 : SUIT_Selector( mgr, viewer ),
41 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
42 connect( myViewer, SIGNAL( deselection() ), this, SLOT( onDeselection() ) );
46 LightApp_OCCSelector::LightApp_OCCSelector( SUIT_SelectionMgr* mgr )
47 : SUIT_Selector( mgr )
54 LightApp_OCCSelector::~LightApp_OCCSelector()
61 #ifndef DISABLE_OCCVIEWER
62 OCCViewer_Viewer* LightApp_OCCSelector::viewer() const
69 /*!On selection changed.*/
70 void LightApp_OCCSelector::onSelectionChanged()
75 /*!On selection cleared.*/
76 void LightApp_OCCSelector::onDeselection()
78 mySelectedExternals.clear();
81 /*!Gets selection list.*/
82 void LightApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
84 #ifndef DISABLE_OCCVIEWER
88 AIS_ListOfInteractive aSelList;
89 myViewer->getSelectedObjects( aSelList );
90 for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
91 if ( !anIt.Value().IsNull() )
93 #ifndef DISABLE_SALOMEOBJECT
94 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anIt.Value()->GetOwner());
96 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anObj ) ) );
98 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
101 // add externally selected objects
102 SUIT_DataOwnerPtrList::const_iterator anExtIter;
103 for(anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++) {
104 aList.append(*anExtIter);
109 /*!Sets selection list.*/
110 void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
112 #ifndef DISABLE_OCCVIEWER
116 QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
117 Handle(AIS_InteractiveContext) aContext = myViewer->getAISContext();
118 if ( aContext.IsNull() )
121 AIS_ListOfInteractive aDispList, aSelList;
122 aContext->DisplayedObjects( aDispList );
124 for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
126 QString entryStr = entry( it.Value() );
127 if ( !entryStr.isEmpty() )
128 aDisplayed.insert( entryStr, it.Value() );
131 mySelectedExternals.clear();
133 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
135 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
136 if ( owner && aDisplayed.contains( owner->entry() ) )
137 aSelList.Append( aDisplayed[owner->entry()] );
139 mySelectedExternals.append(*itr);
142 myViewer->unHighlightAll( false );
143 myViewer->setObjectsSelected( aSelList );
147 #ifndef DISABLE_OCCVIEWER
148 /*!Gets entry ob object.*/
149 QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
151 if ( anAIS.IsNull() || !anAIS->HasOwner() )
156 #ifndef DISABLE_SALOMEOBJECT
157 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anAIS->GetOwner());
158 if ( !anObj.IsNull() )
159 res = QString( anObj->getEntry() );