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 #ifndef DISABLE_SALOMEOBJECT
29 #include <SALOME_ListIO.hxx>
30 #include <SALOME_ListIteratorOfListIO.hxx>
32 // Open CASCADE Include
33 #include <TColStd_MapOfInteger.hxx>
34 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
35 #include <TColStd_IndexedMapOfInteger.hxx>
41 LightApp_SelectionMgr::LightApp_SelectionMgr( LightApp_Application* app, const bool fb )
42 : SUIT_SelectionMgr( fb ),
50 LightApp_SelectionMgr::~LightApp_SelectionMgr()
57 LightApp_Application* LightApp_SelectionMgr::application() const
62 #ifndef DISABLE_SALOMEOBJECT
64 Get all selected objects from selection manager
66 void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType,
67 const bool convertReferences ) const
71 SUIT_DataOwnerPtrList aList;
72 selected( aList, theType );
74 QMap<QString,int> entryMap;
77 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
79 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
83 LightApp_Study* study = dynamic_cast<LightApp_Study*>( application()->activeStudy() );
87 entry = owner->entry();
88 if ( convertReferences ) {
89 QString refEntry = study->referencedToEntry( entry );
90 if( !entryMap.contains( entry ) ) {
91 if ( refEntry != entry ) {
92 QString component = study->componentDataType( refEntry );
93 theList.Append( new SALOME_InteractiveObject( refEntry, component, ""/*refobj->Name().c_str()*/ ) );
96 theList.Append( owner->IO() );
100 if( !entryMap.contains( entry ) )
101 theList.Append( owner->IO() );
104 entryMap.insert(owner->entry(), 1);
109 Append selected objects.
111 void LightApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
113 SUIT_DataOwnerPtrList owners;
114 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
116 if ( it.Value()->hasEntry() )
117 owners.append( new LightApp_DataOwner( it.Value() ) );
120 setSelected( owners, append );
125 Get all selected objects from selection manager
127 void LightApp_SelectionMgr::selectedObjects( QStringList& theList, const QString& theType,
128 const bool convertReferences ) const
132 SUIT_DataOwnerPtrList aList;
133 selected( aList, theType );
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->() );
142 LightApp_Study* study = dynamic_cast<LightApp_Study*>( application()->activeStudy() );
146 entry = owner->entry();
147 if( !theList.contains( entry ) )
148 theList.append( entry );
155 Emit current selection changed.
157 void LightApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
159 SUIT_SelectionMgr::selectionChanged( theSel );
161 emit currentSelectionChanged();
164 #ifndef DISABLE_SALOMEOBJECT
167 get map of indexes for the given SALOME_InteractiveObject
169 void LightApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
170 TColStd_IndexedMapOfInteger& theIndex)
174 SUIT_DataOwnerPtrList aList;
177 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
179 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
181 if ( subOwner->entry() == QString(IObject->getEntry()) )
182 theIndex.Add( subOwner->index() );
188 get map of indexes for the given entry of SALOME_InteractiveObject
190 void LightApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
194 SUIT_DataOwnerPtrList aList;
197 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
199 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
201 if ( subOwner->entry() == theEntry )
202 theIndex.Add( subOwner->index() );
208 Add or remove interactive objects from selection manager.
210 bool LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
211 const TColStd_MapOfInteger& theIndexes,
214 SUIT_DataOwnerPtrList remainsOwners;
216 SUIT_DataOwnerPtrList aList;
220 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
222 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
225 if ( owner->entry() != QString(IObject->getEntry()) )
227 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( owner );
229 remainsOwners.append( new LightApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
231 remainsOwners.append( new LightApp_DataOwner( owner->entry() ) );
237 remainsOwners = aList;
239 TColStd_MapIteratorOfMapOfInteger It;
240 It.Initialize(theIndexes);
241 for(;It.More();It.Next())
242 remainsOwners.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
245 setSelected( remainsOwners, append );
247 emit currentSelectionChanged();
249 TColStd_IndexedMapOfInteger anIndexes;
250 GetIndexes( IObject, anIndexes );
251 return !anIndexes.IsEmpty();
256 select 'subobjects' with given indexes
258 void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
259 TColStd_IndexedMapOfInteger theIndex, bool append )
261 SUIT_DataOwnerPtrList aList;
263 if ( theIndex.IsEmpty() )
264 aList.append( new LightApp_DataOwner( QString(IObject->getEntry()) ) );
268 for ( i = 1; i <= theIndex.Extent(); i++ )
269 aList.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
272 setSelected( aList, append );
277 select 'subobjects' with given indexes
279 void LightApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
281 SUIT_DataOwnerPtrList aList;
283 MapIOOfMapOfInteger::Iterator it;
284 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
286 if ( it.data().IsEmpty() )
287 aList.append( new LightApp_DataOwner( QString(it.key()->getEntry()) ) );
291 for ( i = 1; i <= it.data().Extent(); i++ )
292 aList.append( new LightApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
296 setSelected( aList, append );
301 get map of selected subowners : object's entry <-> map of indexes
303 void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
307 TColStd_IndexedMapOfInteger anIndexes;
309 SUIT_DataOwnerPtrList aList;
312 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
314 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
317 if ( !theMap.contains( subOwner->entry() ) )
320 GetIndexes( subOwner->entry(), anIndexes );
321 theMap.insert( subOwner->entry(), anIndexes );