2 // File : QAD_NameBrowser.cxx
3 // Created : Mon Nov 26 10:15:24 2001
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE
10 #include "QAD_NameBrowser.h"
12 #include "QAD_Study.h"
13 #include "QAD_Desktop.h"
14 #include "QAD_Application.h"
15 #include "QAD_Selection.h"
16 #include "QAD_InteractiveObject.h"
18 #include "utilities.h"
21 #include <SALOMEconfig.h>
22 #include CORBA_SERVER_HEADER(SALOMEDS)
24 #include <qcombobox.h>
25 #include <qgroupbox.h>
27 #include <qlistview.h>
28 #include <qpushbutton.h>
29 #include <qtoolbutton.h>
33 #include <qwhatsthis.h>
36 Constructs a QAD_NameBrowser which is a child of 'parent', with the
39 QAD_NameBrowser::QAD_NameBrowser( QWidget* parent, const char* name)
40 : QMainWindow( parent, name, WStyle_NormalBorder |
41 WStyle_MinMax | WStyle_SysMenu | WDestructiveClose )
44 setName( "QAD_NameBrowser" );
49 GroupBox1 = new QGroupBox( this, "GroupBox1" );
50 GroupBox1->setGeometry( QRect( 10, 10, 300, 50 ) );
51 GroupBox1->setTitle( tr( "Filters" ) );
53 ComboBox1 = new QComboBox( TRUE, GroupBox1 );
54 ComboBox1->setGeometry( QRect( 10, 20, 120, 21 ) );
55 ComboBox1->insertItem( tr( "Type" ) );
57 connect( ComboBox1, SIGNAL( textChanged(const QString &) ), this, SLOT( updateFilters() ) );
60 PushButton5 = new QPushButton( tr( " = " ), GroupBox1);
61 PushButton5->setGeometry( QRect( 140, 20, 30, 21 ) );
63 ComboBox2 = new QComboBox( TRUE, GroupBox1);
64 ComboBox2->setGeometry( QRect( 180, 20, 111, 21 ) );
65 ComboBox2->insertItem( tr( "All" ) );
66 connect( ComboBox2, SIGNAL( textChanged(const QString &) ), this, SLOT( updateFilters() ) );
68 GroupBox2 = new QGroupBox( this, "GroupBox2" );
69 GroupBox2->setGeometry( QRect( 10, 60, 300, 200 ) );
70 GroupBox2->setTitle( tr( "Objects" ) );
72 PushButton1 = new QPushButton( tr( "All" ), GroupBox2 );
73 PushButton1->setGeometry( QRect( 10, 170, 71, 21 ) );
74 connect( PushButton1, SIGNAL( clicked() ), this, SLOT( selectAllFilteredObjects() ) );
76 ListView1 = new QListView( GroupBox2 );
77 ListView1->setGeometry( QRect( 10, 20, 280, 140 ) );
78 ListView1->addColumn("");
79 ListView1->addColumn("");
80 ListView1->addColumn("");
81 ListView1->setColumnText( 0, tr( "Filtered" ) );
82 ListView1->setColumnWidth(0, 130);
83 ListView1->setRootIsDecorated(TRUE);
84 ListView1->setMultiSelection (TRUE);
85 ListView1->setSelectionMode ( QListView::Extended );
88 SIGNAL( selectionChanged() ),
89 this, SLOT(onFilteredObjects()) );
95 Returns reference to QListView
97 QListView* QAD_NameBrowser::getListView() const
103 Destroys the object and frees any allocated resources
105 QAD_NameBrowser::~QAD_NameBrowser()
107 // no need to delete child widgets, Qt does it all for us
110 void QAD_NameBrowser::selectAllFilteredObjects()
112 ListView1->selectAll( true );
115 void QAD_NameBrowser::updateFilters()
120 void QAD_NameBrowser::initFilters()
122 QAD_Desktop* myDesktop = QAD_Application::getDesktop();
123 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
124 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
129 // QAD_Selection* Sel = QAD_Selection::Selection( myActiveStudy->getSelection() );
130 // const QList<QAD_InteractiveObject>& ListIO = Sel->getInteractiveObjects();
131 // int NbSelected = ListIO.count();
132 // if ( NbSelected == 0 ) {
133 // // setFilter "All"
136 // } else if ( NbSelected == 1 ) {
137 // // setFilter "type of selected object"
138 // QAD_InteractiveObject* IObject = Sel->getFisrtInteractiveObject();
139 // SALOMEDS::SComponent_var SC = SALOMEDS::SComponent::_narrow ( myActiveStudy->FindObjectIOR( IObject->getFatherIOR() ));
140 // if ( !SC->_is_nil() ) {
141 // char* ObjectComp = "";
142 // if ( SC->GetAttribute(SALOMEDS::Name, ObjectComp)) {
143 // Update( aStudy, SC );
148 // // const QList<QAD_InteractiveObject>& ListIO = Sel->getInteractiveObjects();
149 // // QListIterator<QAD_InteractiveObject> it( Sel->getInteractiveObjects() );
150 // // for ( ; it.current(); ++it ) {
151 // // QAD_InteractiveObject* IObject = it.current();
152 // // QString IOR = IObject->getFatherIOR() ));
156 // // heterogeneous selection -> setFilter "All"
159 // // homogeneous selection -> setFilter "type of selected objects"
163 void QAD_NameBrowser::onFilteredObjects()
165 QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
166 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
167 QAD_Selection* Sel = QAD_Selection::Selection( myActiveStudy->getSelection() );
168 QAD_StudyFrame* myActiveSFrame = myActiveStudy->getActiveStudyFrame();
170 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
172 MESSAGE ( "QAD_NAMEBROWSER - NB SELECTED INTERACTIVE OBJECT : " << Sel->getInteractiveObjectCount() )
174 QList<QAD_InteractiveObject> DeltaPos;
176 QList<QAD_InteractiveObject> DeltaNeg;
179 QListViewItemIterator it( ListView1 );
180 for ( ; it.current(); ++it ) {
181 QListViewItem* item = it.current();
182 QString theIOR = item->text(2);
183 QString theEntry = item->text(1);
185 if ( ActiveComp.isEmpty() ) {/* Neutral point = no component loaded */
186 if ( !theEntry.isEmpty() && theIOR.isEmpty() ) { /* A component may be selected */
187 if ( item->isSelected() ) {
188 bool itemAlreadySelected = false;
190 int nbSel = Sel->getInteractiveObjectCount();
191 for ( int i = 0; i < nbSel; i++ ) {
192 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
193 if ( SO->getIOR().compare(item->text(1)) == 0 ) {
194 itemAlreadySelected = true;
198 if (!itemAlreadySelected) {
199 QAD_InteractiveObject* SO = new QAD_InteractiveObject( item->text(1), "" );
200 DeltaPos.append( SO );
203 int nbSel = Sel->getInteractiveObjectCount();
204 for ( int i = 0; i < nbSel; i++ ) {
205 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
206 if ( SO->getIOR().compare(item->text(1)) == 0 ) {
207 DeltaNeg.append( SO );
213 } else { /* An object is selected */
214 if ( item->isSelected() ) {
215 item->setSelected( false );
221 if ( !theIOR.isEmpty() ) {
222 if ( item->isSelected() ) {
223 bool itemAllreadySelected = false;
225 int nbSel = Sel->getInteractiveObjectCount();
226 for ( int i = 0; i < nbSel; i++ ) {
227 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
228 if ( SO->getIOR().compare(theIOR) == 0 ) {
229 itemAllreadySelected = true;
234 if (!itemAllreadySelected) {
235 SALOMEDS::SObject_var obj = aStudy->FindObjectID(theEntry.latin1());
236 SALOMEDS::SComponent_var theComponent = obj->GetFatherComponent();
237 SALOMEDS::GenericAttribute_var anAttr;
238 SALOMEDS::AttributeIOR_var anIOR;
239 Standard_CString ior =" ";
240 Standard_CString iorFather =" ";
241 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
242 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
243 ior = anIOR->Value();
245 theComponent->ComponentIOR(iorFather);
246 QAD_InteractiveObject* SO = new QAD_InteractiveObject( QString(ior),
249 DeltaPos.append( SO );
252 int nbSel = Sel->getInteractiveObjectCount();
253 for ( int i = 0; i < nbSel; i++ ) {
254 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
255 if ( SO->getIOR().compare(theIOR) == 0 ) {
256 DeltaNeg.append( SO );
262 } else if ( !theEntry.isEmpty() && theIOR.isEmpty() ) {
263 if ( item->isSelected() ) {
264 bool itemAllreadySelected = false;
266 int nbSel = Sel->getInteractiveObjectCount();
267 for ( int i = 0; i < nbSel; i++ ) {
268 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
269 if ( SO->getEntry().compare(theEntry) == 0 ) {
270 itemAllreadySelected = true;
274 if (!itemAllreadySelected) {
275 SALOMEDS::SObject_var obj = aStudy->FindObjectID(theEntry.latin1());
276 SALOMEDS::SComponent_var theComponent = obj->GetFatherComponent();
277 SALOMEDS::GenericAttribute_var anAttr;
278 SALOMEDS::AttributeIOR_var anIOR;
279 Standard_CString ior =" ";
280 Standard_CString iorFather =" ";
281 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
282 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
283 ior = anIOR->Value();
285 theComponent->ComponentIOR(iorFather);
286 QAD_InteractiveObject* SO = new QAD_InteractiveObject( QString(ior),
289 DeltaPos.append( SO );
292 int nbSel = Sel->getInteractiveObjectCount();
293 for ( int i = 0; i < nbSel; i++ ) {
294 QAD_InteractiveObject* SO = Sel->getInteractiveObject(i);
295 if ( SO->getEntry().compare(theEntry) == 0 ) {
296 DeltaNeg.append( SO );
303 item->setSelected( false );
309 MESSAGE ( "NAMEBROWSER DeltaNeg.count() == " << DeltaNeg.count() )
310 for ( QAD_InteractiveObject* SO = DeltaNeg.first(); SO; SO = DeltaNeg.next() ) {
311 MESSAGE ( "------" << SO->getIOR() )
312 Sel->RemoveInteractiveObject(SO);
314 MESSAGE ( "NAMEBROWSER DeltaPos.count() == " << DeltaPos.count() )
315 for ( QAD_InteractiveObject* SO = DeltaPos.first(); SO; SO = DeltaPos.next() ) {
316 MESSAGE ( "++++++" << SO->getIOR() )
317 Sel->AddInteractiveObject(SO);
324 void QAD_NameBrowser::Update(SALOMEDS::Study_ptr Study,
325 SALOMEDS::SObject_ptr SO)
327 SALOMEDS::SObject_var RefSO;
328 SALOMEDS::ChildIterator_var it = Study->NewChildIterator(SO);
330 for (; it->More();it->Next()) {
331 SALOMEDS::SObject_var CSO= it->Value();
332 SALOMEDS::GenericAttribute_var anAttr;
333 SALOMEDS::AttributeName_var aName;
334 SALOMEDS::AttributeIOR_var anIOR;
337 if (CSO->FindAttribute(anAttr, "AttributeName")) {
338 aName = SALOMEDS::AttributeName::_narrow(anAttr);
339 if (CSO->FindAttribute(anAttr, "AttributeIOR")) {
340 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
341 Item = AddItem ( aName->Value(), CSO->GetID(), anIOR->Value());
352 void QAD_NameBrowser::Update(SALOMEDS::Study_ptr Study,
353 SALOMEDS::SComponent_ptr SC)
357 if (Study->_is_nil()) {
361 // Standard_CString name;
362 Standard_CString dataType;
363 Standard_CString ior="";
367 SALOMEDS::SComponentIterator_var itcomp;
368 SALOMEDS::GenericAttribute_var anAttr;
369 SALOMEDS::AttributeName_var aName;
370 SALOMEDS::AttributeIOR_var anIOR;
372 if ( !SC->_is_nil() ) {
373 if (SC->FindAttribute(anAttr, "AttributeName")) {
374 aName = SALOMEDS::AttributeName::_narrow(anAttr);
375 Item = AddItem (aName->Value(),SC->GetID(),ior);
377 Item = AddItem (dataType,SC->GetID(),ior);
379 Update ( Study, SALOMEDS::SObject::_narrow(SC) );
382 itcomp = Study->NewComponentIterator();
383 for (; itcomp->More(); itcomp->Next()) {
384 SALOMEDS::SComponent_var SC1 = itcomp->Value();
385 dataType = SC1->ComponentDataType();
387 if (SC1->FindAttribute(anAttr, "AttributeIOR")) {
388 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
389 ior = anIOR->Value();
392 if ( QString(dataType).compare("Interface Applicative") != 0 ) {
393 if (SC1->FindAttribute(anAttr, "AttributeName")) {
394 aName = SALOMEDS::AttributeName::_narrow(anAttr);
395 Item = AddItem (aName->Value(), SC1->GetID(), ior);
397 Item = AddItem (dataType, SC1->GetID(), ior);
400 Update ( Study, SALOMEDS::SObject::_narrow(SC1) );
406 QListViewItem* QAD_NameBrowser::AddItem(const QString& theText,
407 const QString& theEntry,
408 const QString& theIOR)
411 QListViewItem* anItem = new QListViewItem( ListView1 );
412 anItem->setText(0, theText);
413 anItem->setText(1, theEntry);
414 anItem->setText(2, theIOR);
420 Called when NameBrowser is about to close
422 void QAD_NameBrowser::closeEvent(QCloseEvent* e)
424 QAD_Application::getDesktop()->closeNameBrowser();