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/ or email : webmaster.salome@opencascade.com
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;
76 QString entry, checkEntry;
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 // Entry to check object uniqueness.
89 // It is selected owner entry in the case, when we do not convert references,
90 // and entry of a real object, when we convert references.
92 if ( convertReferences ) {
93 QString refEntry = study->referencedToEntry( entry );
94 checkEntry = refEntry;
95 if ( !entryMap.contains( checkEntry ) ) {
96 if ( refEntry != entry ) {
97 QString component = study->componentDataType( refEntry );
98 theList.Append( new SALOME_InteractiveObject( refEntry, component, ""/*refobj->Name().c_str()*/ ) );
100 else if( !owner->IO().IsNull() )
101 theList.Append( owner->IO() );
105 if( !entryMap.contains( entry ) && !owner->IO().IsNull() )
106 theList.Append( owner->IO() );
109 entryMap.insert(checkEntry, 1);
114 Append selected objects.
116 void LightApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
118 SUIT_DataOwnerPtrList owners;
119 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
121 if ( it.Value()->hasEntry() )
122 owners.append( new LightApp_DataOwner( it.Value() ) );
125 setSelected( owners, append );
130 Get all selected objects from selection manager
132 void LightApp_SelectionMgr::selectedObjects( QStringList& theList, const QString& theType,
133 const bool convertReferences ) const
137 SUIT_DataOwnerPtrList aList;
138 selected( aList, theType );
141 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
143 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
147 LightApp_Study* study = dynamic_cast<LightApp_Study*>( application()->activeStudy() );
151 entry = owner->entry();
152 if( !theList.contains( entry ) )
153 theList.append( entry );
160 Emit current selection changed.
162 void LightApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
164 SUIT_SelectionMgr::selectionChanged( theSel );
166 emit currentSelectionChanged();
169 #ifndef DISABLE_SALOMEOBJECT
172 get map of indexes for the given SALOME_InteractiveObject
174 void LightApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
175 TColStd_IndexedMapOfInteger& theIndex)
179 SUIT_DataOwnerPtrList aList;
182 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
184 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
186 if ( subOwner->entry() == QString(IObject->getEntry()) )
187 theIndex.Add( subOwner->index() );
193 get map of indexes for the given entry of SALOME_InteractiveObject
195 void LightApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
199 SUIT_DataOwnerPtrList aList;
202 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
204 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
206 if ( subOwner->entry() == theEntry )
207 theIndex.Add( subOwner->index() );
213 Add or remove interactive objects from selection manager.
215 //bool LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
216 void LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
217 const TColStd_MapOfInteger& theIndexes,
220 SUIT_DataOwnerPtrList remainsOwners;
222 SUIT_DataOwnerPtrList aList;
225 QString ioEntry (IObject->getEntry());
228 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
230 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
233 if ( owner->entry() != ioEntry )
235 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( owner );
237 remainsOwners.append( new LightApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
239 remainsOwners.append( new LightApp_DataOwner( owner->entry() ) );
245 remainsOwners = aList;
247 TColStd_MapIteratorOfMapOfInteger It;
248 It.Initialize(theIndexes);
249 for(;It.More();It.Next())
250 remainsOwners.append( new LightApp_DataSubOwner( ioEntry, It.Key() ) );
253 setSelected( remainsOwners, append );
255 emit currentSelectionChanged();
257 // Bug 17269: To avoid calling of selected(aList)
258 //TColStd_IndexedMapOfInteger anIndexes;
259 //GetIndexes( IObject, anIndexes );
260 //return !anIndexes.IsEmpty();
264 select 'subobjects' with given indexes
266 void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
267 TColStd_IndexedMapOfInteger theIndex, bool append )
269 SUIT_DataOwnerPtrList aList;
271 if ( theIndex.IsEmpty() )
272 aList.append( new LightApp_DataOwner( QString(IObject->getEntry()) ) );
276 for ( i = 1; i <= theIndex.Extent(); i++ )
277 aList.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
280 setSelected( aList, append );
285 select 'subobjects' with given indexes
287 void LightApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
289 SUIT_DataOwnerPtrList aList;
291 MapIOOfMapOfInteger::Iterator it;
292 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
294 if ( it.data().IsEmpty() )
295 aList.append( new LightApp_DataOwner( QString(it.key()->getEntry()) ) );
299 for ( i = 1; i <= it.data().Extent(); i++ )
300 aList.append( new LightApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
304 setSelected( aList, append );
309 get map of selected subowners : object's entry <-> map of indexes
311 void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
315 TColStd_IndexedMapOfInteger anIndexes;
317 SUIT_DataOwnerPtrList aList;
320 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
322 const LightApp_DataSubOwner* subOwner =
323 dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
326 if ( !theMap.contains( subOwner->entry() ) )
329 //Bug 17269: GetIndexes( subOwner->entry(), anIndexes );
330 //Bug 17269: To avoid multiple calling of selected(aList)
331 for ( SUIT_DataOwnerPtrList::const_iterator itr2 = itr; itr2 != aList.end(); ++itr2 )
333 const LightApp_DataSubOwner* subOwner2 =
334 dynamic_cast<const LightApp_DataSubOwner*>( (*itr2).operator->() );
336 if ( subOwner2->entry() == subOwner->entry() )
337 anIndexes.Add( subOwner2->index() );
340 theMap.insert( subOwner->entry(), anIndexes );