1 // Copyright (C) 2007-2008 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
22 #include "LightApp_SelectionMgr.h"
24 #include "LightApp_Study.h"
25 #include "LightApp_DataOwner.h"
26 #include "LightApp_DataSubOwner.h"
27 #include "LightApp_Application.h"
29 #include <SUIT_Session.h>
31 #ifndef DISABLE_SALOMEOBJECT
32 #include <SALOME_ListIO.hxx>
33 #include <SALOME_ListIteratorOfListIO.hxx>
35 // Open CASCADE Include
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TCollection_AsciiString.hxx>
45 LightApp_SelectionMgr::LightApp_SelectionMgr( LightApp_Application* app, const bool fb )
46 : SUIT_SelectionMgr( fb ),
54 LightApp_SelectionMgr::~LightApp_SelectionMgr()
61 LightApp_Application* LightApp_SelectionMgr::application() const
66 #ifndef DISABLE_SALOMEOBJECT
68 Get all selected objects from selection manager
70 void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType,
71 const bool convertReferences ) const
75 SUIT_DataOwnerPtrList aList;
76 selected( aList, theType );
78 QMap<QString,int> entryMap;
80 QString entry, checkEntry;
81 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
83 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
87 LightApp_Study* study = dynamic_cast<LightApp_Study*>( application()->activeStudy() );
91 entry = owner->entry();
92 // Entry to check object uniqueness.
93 // It is selected owner entry in the case, when we do not convert references,
94 // and entry of a real object, when we convert references.
96 if ( convertReferences ) {
97 QString refEntry = study->referencedToEntry( entry );
98 checkEntry = refEntry;
99 if ( !entryMap.contains( checkEntry ) ) {
100 if ( refEntry != entry ) {
101 QString component = study->componentDataType( refEntry );
102 theList.Append( new SALOME_InteractiveObject( refEntry.toLatin1().constData(), component.toLatin1().constData(), ""/*refobj->Name().c_str()*/ ) );
104 else if( !owner->IO().IsNull() )
105 theList.Append( owner->IO() );
109 if( !entryMap.contains( entry ) && !owner->IO().IsNull() )
110 theList.Append( owner->IO() );
113 entryMap.insert(checkEntry, 1);
118 Append selected objects.
120 void LightApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
122 SUIT_DataOwnerPtrList owners;
123 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
125 if ( it.Value()->hasEntry() )
126 owners.append( new LightApp_DataOwner( it.Value() ) );
129 setSelected( owners, append );
134 Get all selected objects from selection manager
136 void LightApp_SelectionMgr::selectedObjects( QStringList& theList, const QString& theType,
137 const bool convertReferences ) const
141 SUIT_DataOwnerPtrList aList;
142 selected( aList, theType );
145 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
147 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
151 LightApp_Study* study = dynamic_cast<LightApp_Study*>( application()->activeStudy() );
155 entry = owner->entry();
156 if( !theList.contains( entry ) )
157 theList.append( entry );
164 Emit current selection changed.
166 void LightApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
168 SUIT_SelectionMgr::selectionChanged( theSel );
170 emit currentSelectionChanged();
173 #ifndef DISABLE_SALOMEOBJECT
176 get map of indexes for the given SALOME_InteractiveObject
178 void LightApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
179 TColStd_IndexedMapOfInteger& theIndex)
183 SUIT_DataOwnerPtrList aList;
186 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
188 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
190 if ( subOwner->entry() == QString(IObject->getEntry()) )
191 theIndex.Add( subOwner->index() );
197 get map of indexes for the given entry of SALOME_InteractiveObject
199 void LightApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
203 SUIT_DataOwnerPtrList aList;
206 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
208 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
210 if ( subOwner->entry() == theEntry )
211 theIndex.Add( subOwner->index() );
217 Add or remove interactive objects from selection manager.
219 //bool LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
220 void LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
221 const TColStd_MapOfInteger& theIndexes,
224 SUIT_DataOwnerPtrList remainsOwners;
226 SUIT_DataOwnerPtrList aList;
229 QString ioEntry (IObject->getEntry());
232 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
234 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
237 if ( owner->entry() != ioEntry )
239 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( owner );
241 remainsOwners.append( new LightApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
243 remainsOwners.append( new LightApp_DataOwner( owner->entry() ) );
249 remainsOwners = aList;
251 TColStd_MapIteratorOfMapOfInteger It;
252 It.Initialize(theIndexes);
253 for(;It.More();It.Next())
254 remainsOwners.append( new LightApp_DataSubOwner( ioEntry, It.Key() ) );
257 setSelected( remainsOwners, append );
259 emit currentSelectionChanged();
261 // Bug 17269: To avoid calling of selected(aList)
262 //TColStd_IndexedMapOfInteger anIndexes;
263 //GetIndexes( IObject, anIndexes );
264 //return !anIndexes.IsEmpty();
268 select 'subobjects' with given indexes
270 void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
271 TColStd_IndexedMapOfInteger theIndex, bool append )
273 SUIT_DataOwnerPtrList aList;
275 if ( theIndex.IsEmpty() )
276 aList.append( new LightApp_DataOwner( QString(IObject->getEntry()) ) );
280 for ( i = 1; i <= theIndex.Extent(); i++ )
281 aList.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
284 setSelected( aList, append );
289 select 'subobjects' with given indexes
291 void LightApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
293 SUIT_DataOwnerPtrList aList;
295 MapIOOfMapOfInteger::Iterator it(theMapIO);
296 for ( ; it.More(); it.Next() )
298 if ( it.Value().IsEmpty() )
299 aList.append( new LightApp_DataOwner( QString(it.Key()->getEntry()) ) );
303 for ( i = 1; i <= it.Value().Extent(); i++ )
304 aList.append( new LightApp_DataSubOwner( QString(it.Key()->getEntry()), it.Value()( i ) ) );
308 setSelected( aList, append );
313 get map of selected subowners : object's entry <-> map of indexes
315 void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
319 TColStd_IndexedMapOfInteger anIndexes;
321 SUIT_DataOwnerPtrList aList;
324 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
326 const LightApp_DataSubOwner* subOwner =
327 dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
331 if ( !theMap.IsBound( TCollection_AsciiString(subOwner->entry().toLatin1().data()) ) )
333 if ( !theMap.IsBound( subOwner->entry().toLatin1().data() ) )
337 //Bug 17269: GetIndexes( subOwner->entry(), anIndexes );
338 //Bug 17269: To avoid multiple calling of selected(aList)
339 for ( SUIT_DataOwnerPtrList::const_iterator itr2 = itr; itr2 != aList.end(); ++itr2 )
341 const LightApp_DataSubOwner* subOwner2 =
342 dynamic_cast<const LightApp_DataSubOwner*>( (*itr2).operator->() );
344 if ( subOwner2->entry() == subOwner->entry() )
345 anIndexes.Add( subOwner2->index() );
348 theMap.Bind( subOwner->entry().toLatin1().data(), anIndexes );