1 // Copyright (C) 2007-2024 CEA, EDF, 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, or (at your option) any later version.
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 if ( !myViewer->isSelectionEnabled() )
91 AIS_ListOfInteractive aSelList;
92 myViewer->getSelectedObjects( aSelList );
93 for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
94 if ( !anIt.Value().IsNull() )
96 #ifndef DISABLE_SALOMEOBJECT
97 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anIt.Value()->GetOwner());
99 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anObj ) ) );
101 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
104 // add externally selected objects
105 SUIT_DataOwnerPtrList::const_iterator anExtIter;
106 for(anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++) {
107 aList.append(*anExtIter);
112 /*!Sets selection list.*/
113 void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
115 #ifndef DISABLE_OCCVIEWER
119 QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
120 Handle(AIS_InteractiveContext) aContext = myViewer->getAISContext();
121 if ( aContext.IsNull() )
124 AIS_ListOfInteractive aDispList, aSelList;
125 aContext->DisplayedObjects( aDispList );
127 for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
129 QString entryStr = entry( it.Value() );
130 if ( !entryStr.isEmpty() )
131 aDisplayed.insert( entryStr, it.Value() );
134 mySelectedExternals.clear();
136 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
138 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
139 if ( owner && aDisplayed.contains( owner->entry() ) )
140 aSelList.Append( aDisplayed[owner->entry()] );
142 mySelectedExternals.append(*itr);
145 myViewer->unHighlightAll( false );
146 myViewer->setObjectsSelected( aSelList );
150 #ifndef DISABLE_OCCVIEWER
151 /*!Gets entry ob object.*/
152 QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
154 if ( anAIS.IsNull() || !anAIS->HasOwner() )
159 #ifndef DISABLE_SALOMEOBJECT
160 Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anAIS->GetOwner());
161 if ( !anObj.IsNull() )
162 res = QString( anObj->getEntry() );