1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : QAD_NameBrowser.cxx
25 // Author : Nicolas REJNERI
30 #include "QAD_NameBrowser.h"
32 #include "QAD_Study.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_Application.h"
35 #include "QAD_Selection.h"
36 #include "QAD_InteractiveObject.h"
38 #include "utilities.h"
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(SALOMEDS)
44 #include <qcombobox.h>
45 #include <qgroupbox.h>
47 #include <qlistview.h>
48 #include <qpushbutton.h>
49 #include <qtoolbutton.h>
53 #include <qwhatsthis.h>
56 Constructs a QAD_NameBrowser which is a child of 'parent', with the
59 QAD_NameBrowser::QAD_NameBrowser( QWidget* parent, const char* name)
60 : QMainWindow( parent, name, WStyle_NormalBorder |
61 WStyle_MinMax | WStyle_SysMenu | WDestructiveClose )
64 setName( "QAD_NameBrowser" );
69 GroupBox1 = new QGroupBox( this, "GroupBox1" );
70 GroupBox1->setGeometry( QRect( 10, 10, 300, 50 ) );
71 GroupBox1->setTitle( tr( "Filters" ) );
73 ComboBox1 = new QComboBox( TRUE, GroupBox1 );
74 ComboBox1->setGeometry( QRect( 10, 20, 120, 21 ) );
75 ComboBox1->insertItem( tr( "Type" ) );
77 connect( ComboBox1, SIGNAL( textChanged(const QString &) ), this, SLOT( updateFilters() ) );
80 PushButton5 = new QPushButton( tr( " = " ), GroupBox1);
81 PushButton5->setGeometry( QRect( 140, 20, 30, 21 ) );
83 ComboBox2 = new QComboBox( TRUE, GroupBox1);
84 ComboBox2->setGeometry( QRect( 180, 20, 111, 21 ) );
85 ComboBox2->insertItem( tr( "All" ) );
86 connect( ComboBox2, SIGNAL( textChanged(const QString &) ), this, SLOT( updateFilters() ) );
88 GroupBox2 = new QGroupBox( this, "GroupBox2" );
89 GroupBox2->setGeometry( QRect( 10, 60, 300, 200 ) );
90 GroupBox2->setTitle( tr( "Objects" ) );
92 PushButton1 = new QPushButton( tr( "All" ), GroupBox2 );
93 PushButton1->setGeometry( QRect( 10, 170, 71, 21 ) );
94 connect( PushButton1, SIGNAL( clicked() ), this, SLOT( selectAllFilteredObjects() ) );
96 ListView1 = new QListView( GroupBox2 );
97 ListView1->setGeometry( QRect( 10, 20, 280, 140 ) );
98 ListView1->addColumn("");
99 ListView1->addColumn("");
100 ListView1->addColumn("");
101 ListView1->setColumnText( 0, tr( "Filtered" ) );
102 ListView1->setColumnWidth(0, 130);
103 ListView1->setRootIsDecorated(TRUE);
104 ListView1->setMultiSelection (TRUE);
105 ListView1->setSelectionMode ( QListView::Extended );
108 SIGNAL( selectionChanged() ),
109 this, SLOT(onFilteredObjects()) );
115 Returns reference to QListView
117 QListView* QAD_NameBrowser::getListView() const
123 Destroys the object and frees any allocated resources
125 QAD_NameBrowser::~QAD_NameBrowser()
127 // no need to delete child widgets, Qt does it all for us
130 void QAD_NameBrowser::selectAllFilteredObjects()
132 ListView1->selectAll( true );
135 void QAD_NameBrowser::updateFilters()
140 void QAD_NameBrowser::initFilters()
142 QAD_Desktop* myDesktop = QAD_Application::getDesktop();
143 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
144 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
149 // QAD_Selection* Sel = QAD_Selection::Selection( myActiveStudy->getSelection() );
150 // const QList<QAD_InteractiveObject>& ListIO = Sel->getInteractiveObjects();
151 // int NbSelected = ListIO.count();
152 // if ( NbSelected == 0 ) {
153 // // setFilter "All"
156 // } else if ( NbSelected == 1 ) {
157 // // setFilter "type of selected object"
158 // QAD_InteractiveObject* IObject = Sel->getFisrtInteractiveObject();
159 // SALOMEDS::SComponent_var SC = SALOMEDS::SComponent::_narrow ( myActiveStudy->FindObjectIOR( IObject->getFatherIOR() ));
160 // if ( !SC->_is_nil() ) {
161 // char* ObjectComp = "";
162 // if ( SC->GetAttribute(SALOMEDS::Name, ObjectComp)) {
163 // Update( aStudy, SC );
168 // // const QList<QAD_InteractiveObject>& ListIO = Sel->getInteractiveObjects();
169 // // QListIterator<QAD_InteractiveObject> it( Sel->getInteractiveObjects() );
170 // // for ( ; it.current(); ++it ) {
171 // // QAD_InteractiveObject* IObject = it.current();
172 // // QString IOR = IObject->getFatherIOR() ));
176 // // heterogeneous selection -> setFilter "All"
179 // // homogeneous selection -> setFilter "type of selected objects"
183 void QAD_NameBrowser::onFilteredObjects()
185 QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
186 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
187 QAD_Selection* Sel = QAD_Selection::Selection( myActiveStudy->getSelection() );
188 QAD_StudyFrame* myActiveSFrame = myActiveStudy->getActiveStudyFrame();
190 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
192 MESSAGE ( "QAD_NAMEBROWSER - NB SELECTED INTERACTIVE OBJECT : " << Sel->getInteractiveObjectCount() )
194 QList<QAD_InteractiveObject> DeltaPos;
196 QList<QAD_InteractiveObject> DeltaNeg;
199 QListViewItemIterator it( ListView1 );
200 for ( ; it.current(); ++it ) {
201 QListViewItem* item = it.current();
202 QString theIOR = item->text(2);
203 QString theEntry = item->text(1);
205 if ( ActiveComp.isEmpty() ) {/* Neutral point = no component loaded */
206 if ( !theEntry.isEmpty() && theIOR.isEmpty() ) { /* A component may be selected */
207 if ( item->isSelected() ) {
208 bool itemAlreadySelected = false;
210 int nbSel = Sel->getInteractiveObjectCount();
211 for ( int i = 0; i < nbSel; i++ ) {
212 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
213 if ( SO->getIOR().compare(item->text(1)) == 0 ) {
214 itemAlreadySelected = true;
218 if (!itemAlreadySelected) {
219 QAD_InteractiveObject* SO = new QAD_InteractiveObject( item->text(1), "" );
220 DeltaPos.append( SO );
223 int nbSel = Sel->getInteractiveObjectCount();
224 for ( int i = 0; i < nbSel; i++ ) {
225 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
226 if ( SO->getIOR().compare(item->text(1)) == 0 ) {
227 DeltaNeg.append( SO );
233 } else { /* An object is selected */
234 if ( item->isSelected() ) {
235 item->setSelected( false );
241 if ( !theIOR.isEmpty() ) {
242 if ( item->isSelected() ) {
243 bool itemAllreadySelected = false;
245 int nbSel = Sel->getInteractiveObjectCount();
246 for ( int i = 0; i < nbSel; i++ ) {
247 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
248 if ( SO->getIOR().compare(theIOR) == 0 ) {
249 itemAllreadySelected = true;
254 if (!itemAllreadySelected) {
255 SALOMEDS::SObject_var obj = aStudy->FindObjectID(theEntry.latin1());
256 SALOMEDS::SComponent_var theComponent = obj->GetFatherComponent();
257 SALOMEDS::GenericAttribute_var anAttr;
258 SALOMEDS::AttributeIOR_var anIOR;
259 Standard_CString ior =" ";
260 Standard_CString iorFather =" ";
261 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
262 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
263 ior = anIOR->Value();
265 theComponent->ComponentIOR(iorFather);
266 QAD_InteractiveObject* SO = new QAD_InteractiveObject( QString(ior),
269 DeltaPos.append( SO );
272 int nbSel = Sel->getInteractiveObjectCount();
273 for ( int i = 0; i < nbSel; i++ ) {
274 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
275 if ( SO->getIOR().compare(theIOR) == 0 ) {
276 DeltaNeg.append( SO );
282 } else if ( !theEntry.isEmpty() && theIOR.isEmpty() ) {
283 if ( item->isSelected() ) {
284 bool itemAllreadySelected = false;
286 int nbSel = Sel->getInteractiveObjectCount();
287 for ( int i = 0; i < nbSel; i++ ) {
288 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
289 if ( SO->getEntry().compare(theEntry) == 0 ) {
290 itemAllreadySelected = true;
294 if (!itemAllreadySelected) {
295 SALOMEDS::SObject_var obj = aStudy->FindObjectID(theEntry.latin1());
296 SALOMEDS::SComponent_var theComponent = obj->GetFatherComponent();
297 SALOMEDS::GenericAttribute_var anAttr;
298 SALOMEDS::AttributeIOR_var anIOR;
299 Standard_CString ior =" ";
300 Standard_CString iorFather =" ";
301 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
302 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
303 ior = anIOR->Value();
305 theComponent->ComponentIOR(iorFather);
306 QAD_InteractiveObject* SO = new QAD_InteractiveObject( QString(ior),
309 DeltaPos.append( SO );
312 int nbSel = Sel->getInteractiveObjectCount();
313 for ( int i = 0; i < nbSel; i++ ) {
314 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
315 if ( SO->getEntry().compare(theEntry) == 0 ) {
316 DeltaNeg.append( SO );
323 item->setSelected( false );
329 MESSAGE ( "NAMEBROWSER DeltaNeg.count() == " << DeltaNeg.count() )
330 for ( QAD_InteractiveObject* SO = DeltaNeg.first(); SO; SO = DeltaNeg.next() ) {
331 MESSAGE ( "------" << SO->getIOR() )
332 Sel->RemoveInteractiveObject(SO);
334 MESSAGE ( "NAMEBROWSER DeltaPos.count() == " << DeltaPos.count() )
335 for ( QAD_InteractiveObject* SO = DeltaPos.first(); SO; SO = DeltaPos.next() ) {
336 MESSAGE ( "++++++" << SO->getIOR() )
337 Sel->AddInteractiveObject(SO);
344 void QAD_NameBrowser::Update(SALOMEDS::Study_ptr Study,
345 SALOMEDS::SObject_ptr SO)
347 SALOMEDS::SObject_var RefSO;
348 SALOMEDS::ChildIterator_var it = Study->NewChildIterator(SO);
350 for (; it->More();it->Next()) {
351 SALOMEDS::SObject_var CSO= it->Value();
352 SALOMEDS::GenericAttribute_var anAttr;
353 SALOMEDS::AttributeName_var aName;
354 SALOMEDS::AttributeIOR_var anIOR;
357 if (CSO->FindAttribute(anAttr, "AttributeName")) {
358 aName = SALOMEDS::AttributeName::_narrow(anAttr);
359 if (CSO->FindAttribute(anAttr, "AttributeIOR")) {
360 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
361 Item = AddItem ( aName->Value(), CSO->GetID(), anIOR->Value());
372 void QAD_NameBrowser::Update(SALOMEDS::Study_ptr Study,
373 SALOMEDS::SComponent_ptr SC)
377 if (Study->_is_nil()) {
381 // Standard_CString name;
382 Standard_CString dataType;
383 Standard_CString ior="";
387 SALOMEDS::SComponentIterator_var itcomp;
388 SALOMEDS::GenericAttribute_var anAttr;
389 SALOMEDS::AttributeName_var aName;
390 SALOMEDS::AttributeIOR_var anIOR;
392 if ( !SC->_is_nil() ) {
393 if (SC->FindAttribute(anAttr, "AttributeName")) {
394 aName = SALOMEDS::AttributeName::_narrow(anAttr);
395 Item = AddItem (aName->Value(),SC->GetID(),ior);
397 Item = AddItem (dataType,SC->GetID(),ior);
399 Update ( Study, SALOMEDS::SObject::_narrow(SC) );
402 itcomp = Study->NewComponentIterator();
403 for (; itcomp->More(); itcomp->Next()) {
404 SALOMEDS::SComponent_var SC1 = itcomp->Value();
405 dataType = SC1->ComponentDataType();
407 if (SC1->FindAttribute(anAttr, "AttributeIOR")) {
408 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
409 ior = anIOR->Value();
412 if ( QString(dataType).compare("Interface Applicative") != 0 ) {
413 if (SC1->FindAttribute(anAttr, "AttributeName")) {
414 aName = SALOMEDS::AttributeName::_narrow(anAttr);
415 Item = AddItem (aName->Value(), SC1->GetID(), ior);
417 Item = AddItem (dataType, SC1->GetID(), ior);
420 Update ( Study, SALOMEDS::SObject::_narrow(SC1) );
426 QListViewItem* QAD_NameBrowser::AddItem(const QString& theText,
427 const QString& theEntry,
428 const QString& theIOR)
431 QListViewItem* anItem = new QListViewItem( ListView1 );
432 anItem->setText(0, theText);
433 anItem->setText(1, theEntry);
434 anItem->setText(2, theIOR);
440 Called when NameBrowser is about to close
442 void QAD_NameBrowser::closeEvent(QCloseEvent* e)
444 QAD_Application::getDesktop()->closeNameBrowser();