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/
19 #include "LightApp_SelectionMgr.h"
21 #include "LightApp_Study.h"
22 #include "LightApp_DataOwner.h"
23 #include "LightApp_DataSubOwner.h"
24 #include "LightApp_Application.h"
26 #include <SUIT_Session.h>
28 #include <SALOME_ListIO.hxx>
29 #include <SALOME_ListIteratorOfListIO.hxx>
31 // Open CASCADE Include
32 #include <TColStd_MapOfInteger.hxx>
33 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
34 #include <TColStd_IndexedMapOfInteger.hxx>
39 LightApp_SelectionMgr::LightApp_SelectionMgr( LightApp_Application* app, const bool fb )
40 : SUIT_SelectionMgr( fb ),
48 LightApp_SelectionMgr::~LightApp_SelectionMgr()
55 LightApp_Application* LightApp_SelectionMgr::application() const
61 Get all selected objects from selection manager
63 void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType,
64 const bool convertReferences ) const
68 SUIT_DataOwnerPtrList aList;
69 selected( aList, theType );
71 QMap<QString,int> entryMap;
74 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
76 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
80 LightApp_Study* study = dynamic_cast<LightApp_Study*>( application()->activeStudy() );
84 entry = owner->entry();
85 if ( convertReferences ) {
86 QString refEntry = study->referencedToEntry( entry );
87 if( !entryMap.contains( entry ) ) {
88 if ( refEntry != entry ) {
89 QString component = study->componentDataType( refEntry );
90 theList.Append( new SALOME_InteractiveObject( refEntry, component, ""/*refobj->Name().c_str()*/ ) );
93 theList.Append( owner->IO() );
97 if( !entryMap.contains( entry ) )
98 theList.Append( owner->IO() );
101 entryMap.insert(owner->entry(), 1);
106 Append selected objects.
108 void LightApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
110 SUIT_DataOwnerPtrList owners;
111 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
113 if ( it.Value()->hasEntry() )
114 owners.append( new LightApp_DataOwner( it.Value() ) );
117 setSelected( owners, append );
121 Emit current selection changed.
123 void LightApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
125 SUIT_SelectionMgr::selectionChanged( theSel );
127 emit currentSelectionChanged();
131 get map of indexes for the given SALOME_InteractiveObject
133 void LightApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
134 TColStd_IndexedMapOfInteger& theIndex)
138 SUIT_DataOwnerPtrList aList;
141 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
143 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
145 if ( subOwner->entry() == QString(IObject->getEntry()) )
146 theIndex.Add( subOwner->index() );
152 get map of indexes for the given entry of SALOME_InteractiveObject
154 void LightApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
158 SUIT_DataOwnerPtrList aList;
161 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
163 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
165 if ( subOwner->entry() == theEntry )
166 theIndex.Add( subOwner->index() );
172 Add or remove interactive objects from selection manager.
174 bool LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
175 const TColStd_MapOfInteger& theIndexes,
178 SUIT_DataOwnerPtrList remainsOwners;
180 SUIT_DataOwnerPtrList aList;
184 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
186 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
189 if ( owner->entry() != QString(IObject->getEntry()) )
191 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( owner );
193 remainsOwners.append( new LightApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
195 remainsOwners.append( new LightApp_DataOwner( owner->entry() ) );
201 remainsOwners = aList;
203 TColStd_MapIteratorOfMapOfInteger It;
204 It.Initialize(theIndexes);
205 for(;It.More();It.Next())
206 remainsOwners.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
209 setSelected( remainsOwners, append );
211 emit currentSelectionChanged();
213 TColStd_IndexedMapOfInteger anIndexes;
214 GetIndexes( IObject, anIndexes );
215 return !anIndexes.IsEmpty();
220 select 'subobjects' with given indexes
222 void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
223 TColStd_IndexedMapOfInteger theIndex, bool append )
225 SUIT_DataOwnerPtrList aList;
227 if ( theIndex.IsEmpty() )
228 aList.append( new LightApp_DataOwner( QString(IObject->getEntry()) ) );
232 for ( i = 1; i <= theIndex.Extent(); i++ )
233 aList.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
236 setSelected( aList, append );
241 select 'subobjects' with given indexes
243 void LightApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
245 SUIT_DataOwnerPtrList aList;
247 MapIOOfMapOfInteger::Iterator it;
248 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
250 if ( it.data().IsEmpty() )
251 aList.append( new LightApp_DataOwner( QString(it.key()->getEntry()) ) );
255 for ( i = 1; i <= it.data().Extent(); i++ )
256 aList.append( new LightApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
260 setSelected( aList, append );
265 get map of selected subowners : object's entry <-> map of indexes
267 void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
271 TColStd_IndexedMapOfInteger anIndexes;
273 SUIT_DataOwnerPtrList aList;
276 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
278 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
281 if ( !theMap.contains( subOwner->entry() ) )
284 GetIndexes( subOwner->entry(), anIndexes );
285 theMap.insert( subOwner->entry(), anIndexes );