1 // Copyright (C) 2007-2012 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
23 // File : LightApp_OBSelector.cxx
26 #include "LightApp_OBSelector.h"
28 #include "LightApp_DataOwner.h"
29 #include "LightApp_DataObject.h"
30 #include "LightApp_Application.h"
31 #include <SUIT_DataBrowser.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_DataObjectIterator.h>
38 \class LightApp_OBSelector
39 \brief Object browser selection handler class.
44 \param ob object browser
45 \param mgr selection manager
47 LightApp_OBSelector::LightApp_OBSelector( SUIT_DataBrowser* ob, SUIT_SelectionMgr* mgr )
48 : SUIT_Selector( mgr, ob ),
52 connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
60 LightApp_OBSelector::~LightApp_OBSelector()
65 \brief Get object browser.
66 \return a pointer to the object browser
68 SUIT_DataBrowser* LightApp_OBSelector::browser() const
74 \brief Get selector type.
77 QString LightApp_OBSelector::type() const
79 return "ObjectBrowser";
83 \brief Get the time of the last selection changing.
84 \return latest selection changing time
86 unsigned long LightApp_OBSelector::getModifiedTime() const
88 return myModifiedTime;
92 \brief Update the time of the latest selection changing.
94 void LightApp_OBSelector::setModified()
96 myModifiedTime = clock();
100 \brief Called when the Object browser selection is changed.
102 void LightApp_OBSelector::onSelectionChanged()
104 QTime t1 = QTime::currentTime();
105 mySelectedList.clear();
107 QTime t2 = QTime::currentTime();
108 qDebug( QString( "selection time = %1 msecs" ).arg( t1.msecsTo( t2 ) ).toLatin1().constData() );
112 \brief Get list of currently selected objects.
113 \param theList list to be filled with the selected objects owners
115 void LightApp_OBSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
117 if ( mySelectedList.count() == 0 ) {
118 SUIT_Session* session = SUIT_Session::session();
119 SUIT_Application* sapp = session ? session->activeApplication() : 0;
120 LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
121 if( !app || !myBrowser )
124 DataObjectList objlist;
125 myBrowser->getSelected( objlist );
126 LightApp_OBSelector* that = (LightApp_OBSelector*)this;
127 QListIterator<SUIT_DataObject*> it( objlist );
128 while ( it.hasNext() ) {
129 LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( it.next() );
130 if ( obj && app->checkDataObject( obj) ) {
131 #ifndef DISABLE_SALOMEOBJECT
132 Handle(SALOME_InteractiveObject) aSObj = new SALOME_InteractiveObject
133 ( obj->entry().toLatin1().constData(),
134 obj->componentDataType().toLatin1().constData(),
135 obj->name().toLatin1().constData() );
136 LightApp_DataOwner* owner = new LightApp_DataOwner( aSObj );
138 LightApp_DataOwner* owner = new LightApp_DataOwner( obj->entry() );
140 that->mySelectedList.append( SUIT_DataOwnerPtr( owner ) );
144 theList = mySelectedList;
148 \brief Set selection.
149 \param theList list of the object owners to be set selected
151 void LightApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
156 if( myEntries.count() == 0 || myModifiedTime < myBrowser->getModifiedTime() )
157 fillEntries( myEntries );
159 DataObjectList objList;
160 for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin();
161 it != theList.end(); ++it ) {
162 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
163 if ( owner && myEntries.contains( owner->entry() ) )
164 objList.append( myEntries[owner->entry()] );
167 myBrowser->setSelected( objList );
168 mySelectedList.clear();
172 \brief Fill map of the data objects currently shown in the Object Browser.
173 \param entries map to be filled
175 void LightApp_OBSelector::fillEntries( QMap<QString, LightApp_DataObject*>& entries )
182 for ( SUIT_DataObjectIterator it( myBrowser->root(),
183 SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
184 LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( it.current() );
186 entries.insert( obj->entry(), obj );