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_OBSelector.h"
21 #include "LightApp_DataOwner.h"
22 #include "LightApp_DataObject.h"
24 #include <OB_Browser.h>
26 #include <SUIT_DataObjectIterator.h>
27 #include <qdatetime.h>
32 LightApp_OBSelector::LightApp_OBSelector( OB_Browser* ob, SUIT_SelectionMgr* mgr )
33 : SUIT_Selector( mgr, ob ),
37 connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
46 LightApp_OBSelector::~LightApp_OBSelector()
53 OB_Browser* LightApp_OBSelector::browser() const
61 void LightApp_OBSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
63 if (mySelectedList.count() == 0 ) {
66 DataObjectList objlist;
67 myBrowser->getSelected( objlist );
68 LightApp_OBSelector* that = (LightApp_OBSelector*)this;
69 for ( DataObjectListIterator it( objlist ); it.current(); ++it )
71 LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( it.current() );
74 #ifndef DISABLE_SALOMEOBJECT
75 Handle(SALOME_InteractiveObject) aSObj = new SALOME_InteractiveObject
76 ( obj->entry(), obj->componentDataType(), obj->name() );
77 LightApp_DataOwner* owner = new LightApp_DataOwner( aSObj );
79 LightApp_DataOwner* owner = new LightApp_DataOwner( obj->entry() );
81 that->mySelectedList.append( SUIT_DataOwnerPtr( owner ) );
85 theList = mySelectedList;
89 void LightApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
94 if( myEntries.count() == 0 ||
95 myModifiedTime < myBrowser->getModifiedTime() )
96 fillEntries( myEntries );
98 DataObjectList objList;
99 for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it )
101 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
102 if ( owner && myEntries.contains( owner->entry() ) )
103 objList.append( myEntries[owner->entry()] );
106 myBrowser->setSelected( objList );
107 mySelectedList.clear();
110 /*!On selection changed.*/
111 void LightApp_OBSelector::onSelectionChanged()
113 QTime t1 = QTime::currentTime();
114 mySelectedList.clear();
116 QTime t2 = QTime::currentTime();
117 qDebug( QString( "selection time = %1 msecs" ).arg( t1.msecsTo( t2 ) ) );
121 void LightApp_OBSelector::fillEntries( QMap<QString, LightApp_DataObject*>& entires )
128 for ( SUIT_DataObjectIterator it( myBrowser->getRootObject(),
129 SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it )
131 LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( it.current() );
133 entires.insert( obj->entry(), obj );
139 /*!Update modified time.*/
140 void LightApp_OBSelector::setModified()
142 myModifiedTime = clock();