]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEGUI/QAD_ObjectBrowser.cxx
Salome HOME
Porting to Mandrake 10.1 and new products:
[modules/kernel.git] / src / SALOMEGUI / QAD_ObjectBrowser.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : QAD_ObjectBrowser.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #include "QAD_ObjectBrowserItem.h"
30 #include "QAD_ObjectBrowser.h"
31 #include "QAD_Application.h"
32 #include "QAD_MessageBox.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_Config.h"
35 #include "QAD_Settings.h"
36 #include "QAD_Tools.h"
37 #include "QAD_RightFrame.h"
38 #include "QAD_LeftFrame.h"
39 #include "SALOME_Selection.h"
40 #include "SALOME_InteractiveObject.hxx"
41 #include "SALOME_ListIteratorOfListIO.hxx"
42 #include "SALOMEGUI_SetValueDlg.h"
43 #include "SALOMEGUI_TableDlg.h"
44 #include "SALOMEGUI_NameDlg.h"
45  
46 // QT Includes
47 #include <qlistview.h>
48 #include <qheader.h>
49 #include <qpopupmenu.h>
50 #include <qtabwidget.h>
51 #include <qpushbutton.h>
52 #include <qlayout.h>
53 #include <qvbox.h>
54 #include <qhbox.h>
55 #include <qtooltip.h>
56 #include <qdragobject.h>
57 #include <qstringlist.h>
58 #include <qmap.h>
59
60 using namespace std;
61
62 //VRV: porting on Qt 3.0.5
63 #if QT_VERSION >= 0x030005
64 #include <qcursor.h> 
65 #endif
66 //VRV: porting on Qt 3.0.5
67
68 #define UC_NEW_EMPTY_ID    1000000
69 #define UC_NEW_COMP_ID     1000002
70 #define UC_NEW_FULL_ID     1000004
71 #define UC_NEW_COPY_ID     1000006
72 #define UC_APPEND_ID       1000008
73 #define UC_REMOVE_ID       1000010
74 #define UC_RENAME_ID       1000012
75 #define UC_CLEAR_ID        1000014
76 #define UC_SET_CURRENT_ID  1000016
77
78
79 #ifdef _DEBUG_
80 static int MYDEBUG = 0;
81 #else
82 static int MYDEBUG = 0;
83 #endif
84
85
86 /*!
87   Small button which updates Object Browser's contents
88 */
89 Btn::Btn ( QWidget * parent, const char * name ) : QToolButton( parent, name ) 
90 {
91   connect( this, SIGNAL(clicked()), this, SLOT(onClicked()) );
92 }
93 void Btn::onClicked()
94 {
95   QAD_ObjectBrowser* OB = QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
96   OB->Update();
97 }
98
99 /*!
100   Gets selected top-level items (i.e. not including sub-items) [ static ]
101 */
102 static void getSelectedParents( QListViewItem* listViewItem, QList<QListViewItem>& itemList )
103 {
104   QListViewItem* item = listViewItem->firstChild();
105   while ( item ) {
106     if ( item->isSelected() ) {
107       itemList.append( item );
108     }
109     else {
110       getSelectedParents( item, itemList );
111     }
112     item = item->nextSibling();
113   }
114 }
115 /*!
116   Gets selected top-level items (i.e. not including sub-items) [ static ]
117 */
118 static void getSelectedParents( QListView* listView, QList<QListViewItem>& itemList, bool ignoreRoot = false )
119 {
120   itemList.clear();
121   QListViewItem* item = listView->firstChild();
122   while ( item ) {
123     if ( item->isSelected() && !ignoreRoot ) {
124       itemList.append( item );
125     }
126     else {
127       getSelectedParents( item, itemList );
128     }
129     item = item->nextSibling();
130   }
131 }
132 /*!
133   Gets top-most parent item [ static ]
134 */
135 static QListViewItem* getTopParent( QListViewItem* item )
136 {
137   if ( !item )
138     return 0;
139   QListViewItem* p = item->parent();
140   if ( !p )
141     return item;
142   while ( p->parent() ) {
143     p = p->parent();
144   }
145   return p;
146 }
147 /*!
148   Returns true if the item is top-level (root)
149 */
150 static bool isRootItem( QListViewItem* item )
151 {
152   return ( item->listView() && !item->parent() );
153 }
154 /*!
155   Constructor
156 */
157 QAD_ObjectBrowser::QAD_ObjectBrowser( SALOMEDS::Study_var study, QWidget* parent, const char* name, WFlags fl )
158      : QTabWidget( parent, name, fl )
159 {
160   myStudy = SALOMEDS::Study::_duplicate( study );
161   myListViewMap.clear();
162   myUseCaseMap.clear();
163   myListView=0;    // must be done before setupListView(): setCornerWidget() provoque call to eventFilter
164   myUseCaseView=0; // and test myUseCaseView->viewport() before initialisation
165   setupListView();
166 }
167
168 /*!
169   Destructor
170 */
171 QAD_ObjectBrowser::~QAD_ObjectBrowser() 
172 {
173   if (!myStudy->_is_nil())
174     CORBA::release(myStudy);
175 }
176
177 /*!
178   Configures Object Browser and UseCase Browser. 
179   Columns, Selection Mode and Palette.
180 */
181 void QAD_ObjectBrowser::setupListView()
182 {
183   QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
184
185   this->setTabPosition( QTabWidget::Bottom );
186   
187   /* Reading setting : Columns for Value, OCAF Doc entry, object IOR, OCAF Doc ref entry and Chrono sorting */
188   QString AddColumn       = QAD_CONFIG->getSetting( "ObjectBrowser:AddColumn"   );
189   QString ValueColumn     = QAD_CONFIG->getSetting( "ObjectBrowser:ValueColumn" );
190   QString ShowCHRONO_SORT = QAD_CONFIG->getSetting( "ObjectBrowser:ChronologicalSort" );
191   QString showUseCase = QAD_CONFIG->getSetting("ObjectBrowser:ShowUseCaseBrowser");
192   QString noAutoSizeColumns = QAD_CONFIG->getSetting( "ObjectBrowser:NoAutoSizeColumns" );
193  
194   /* create and setup Object Browser ================================= */
195   myListView = new QListView( this, "Object Browser");
196   myListView->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
197   myListView->setMinimumSize( 1, 1 );
198   myListView->setPalette( QAD_Application::getPalette( true ) );
199
200   /* First two columns = object name and value - always visible */
201   myListView->addColumn( tr( "OBJECT_BROWSER_OBJECT" ) );   /* Adding Object column             */
202   myListView->addColumn( tr( "OBJECT_BROWSER_VALUE" ) );    /* Adding Value column              */
203   myListView->addColumn( tr( "OBJECT_BROWSER_ENTRY" ) );    /* Adding Doc entry column          */
204   myListView->addColumn( tr( "OBJECT_BROWSER_IOR" ) );      /* Adding Object IOR column         */
205   myListView->addColumn( tr( "OBJECT_BROWSER_REFENTRY" ) ); /* Adding OCAF Doc ref entry column */
206   myListView->header()->setMovingEnabled( false );
207  
208   /* Properties */
209   myListView->header()->setClickEnabled( TRUE );          /* Enable clicking on the header                    */
210   myListView->setShowSortIndicator( TRUE ) ;              /* Add user arrows to indicate the sort order : LPN */
211   myListView->setRootIsDecorated( TRUE );                 /* Enable expand/collapse control for the root item */
212   myListView->setSelectionMode ( QListView::Extended );   /* Enable multiple selection                        */
213   myListView->setVScrollBarMode( QScrollView::AlwaysOn ); /* Set scrollbars always visible                    */
214   myListView->setHScrollBarMode( QScrollView::AlwaysOn ); /* ...                                              */
215
216   myListView->setCornerWidget( new Btn( this ) );
217   /* Connect section */
218   //VRV: porting on Qt 3.0.5
219 #if QT_VERSION < 0x030005
220   connect( myListView, SIGNAL( rightButtonClicked( QListViewItem*, const QPoint&, int ) ),
221            this,       SLOT(   showPopupMenu( QListViewItem* ) ) );
222 #else
223   connect( myListView, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
224            this,       SLOT(   showPopupMenu( QListViewItem* ) ) );
225 #endif  
226   //VRV: porting on Qt 3.0.5
227
228   connect( myListView, SIGNAL( selectionChanged() ),
229            this,       SLOT( onSelectedItem() ) );
230   connect( myListView, SIGNAL( expanded( QListViewItem* ) ),
231            this,       SLOT( onExpanded( QListViewItem* ) ) );
232   connect( myListView, SIGNAL( collapsed( QListViewItem* ) ),
233            this,       SLOT( onCollapsed( QListViewItem* ) ) );
234     
235   /* create and setup UseCase Browser ================================ */
236   myVBox = new QWidget( this );
237   QVBoxLayout* vBoxLayout = new QVBoxLayout( myVBox );
238   
239   myUseCaseView = new QListView( myVBox, "UseCase Browser");
240   myUseCaseView->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
241   myUseCaseView->setMinimumSize( 1, 1 );
242   myUseCaseView->setPalette( QAD_Application::getPalette( true ) );
243
244   /* First column = object name */
245   myUseCaseView->addColumn( tr( "OBJECT_BROWSER_OBJECT" ) );
246   /* Properties */
247   myUseCaseView->header()->setClickEnabled( TRUE );          /* Enable clicking on the header                    */
248   myUseCaseView->setShowSortIndicator( TRUE ) ;              /* Add user arrows to indicate the sort order : LPN */
249   myUseCaseView->setRootIsDecorated( TRUE );                 /* Enable expand/collapse control for the root item */
250   myUseCaseView->setSelectionMode ( QListView::Extended );   /* Enable multiple selection                        */
251   myUseCaseView->setVScrollBarMode( QScrollView::AlwaysOn ); /* Set scrollbars always visible                    */
252   myUseCaseView->setHScrollBarMode( QScrollView::AlwaysOn ); /* ...                                              */
253   myUseCaseView->header()->setMovingEnabled( false );
254   myUseCaseView->viewport()->setAcceptDrops( true );
255   myUseCaseView->installEventFilter( this );
256   myUseCaseView->viewport()->installEventFilter( this );
257   myUseCaseView->setSorting( -1 ) ;
258   vBoxLayout->addWidget( myUseCaseView ); 
259
260   myUseCaseView->setCornerWidget( new Btn( this ) );
261
262   myNewBtn = new QToolButton( myVBox );
263   myNewBtn->setIconSet( resMgr->loadPixmap( "QAD", tr("ICON_UC_NEW") ) );
264   myNewBtn->setAutoRaise( true );
265   QToolTip::add( myNewBtn, tr( "UC_NEW_ID" ), QAD_Application::getDesktop()->toolTipGroup(), tr( "UC_NEW_TIP" ) );
266   myAddBtn = new QToolButton( myVBox );
267   myAddBtn->setIconSet( resMgr->loadPixmap( "QAD", tr("ICON_UC_ADD") ) );
268   myAddBtn->setAutoRaise( true );
269   QToolTip::add( myAddBtn, tr( "UC_APPEND_ID" ), QAD_Application::getDesktop()->toolTipGroup(), tr( "UC_APPEND_TIP" ) );
270   myDelBtn = new QToolButton( myVBox );
271   myDelBtn->setIconSet( resMgr->loadPixmap( "QAD", tr("ICON_UC_REMOVE") ) );
272   myDelBtn->setAutoRaise( true );
273   QToolTip::add( myDelBtn, tr( "UC_REMOVE_ID" ), QAD_Application::getDesktop()->toolTipGroup(), tr( "UC_REMOVE_TIP" ) );
274   myClearBtn = new QToolButton( myVBox );
275   myClearBtn->setIconSet( resMgr->loadPixmap( "QAD", tr("ICON_UC_CLEAR") ) );
276   myClearBtn->setAutoRaise( true );
277   QToolTip::add( myClearBtn, tr( "UC_CLEAR_ID" ), QAD_Application::getDesktop()->toolTipGroup(), tr( "UC_CLEAR_TIP" ) );
278   myCurrentBtn = new QToolButton( myVBox );
279   myCurrentBtn->setIconSet( resMgr->loadPixmap( "QAD", tr("ICON_UC_SET_CURRENT") ) );
280   myCurrentBtn->setAutoRaise( true );
281   QToolTip::add( myCurrentBtn, tr( "UC_SET_CURRENT_ID" ), QAD_Application::getDesktop()->toolTipGroup(), tr( "UC_SET_CURRENT_TIP" ) );
282
283   QHBoxLayout* btnLayout = new QHBoxLayout;
284   btnLayout->setMargin( 3 ); btnLayout->setSpacing( 3 );
285   btnLayout->addWidget( myNewBtn );
286   btnLayout->addStretch();
287   btnLayout->addSpacing( 5 );
288   btnLayout->addStretch();
289   btnLayout->addWidget( myAddBtn );
290   btnLayout->addWidget( myDelBtn );
291   btnLayout->addStretch();
292   btnLayout->addSpacing( 5 );
293   btnLayout->addStretch();
294   btnLayout->addWidget( myClearBtn );
295   btnLayout->addStretch();
296   btnLayout->addSpacing( 5 );
297   btnLayout->addStretch();
298   btnLayout->addWidget( myCurrentBtn );
299   btnLayout->addStretch();
300
301   vBoxLayout->addLayout( btnLayout ); 
302
303   connect( myNewBtn,     SIGNAL( clicked() ), this, SLOT( onUseCaseBtn() ) );
304   connect( myAddBtn,     SIGNAL( clicked() ), this, SLOT( onUseCaseBtn() ) );
305   connect( myDelBtn,     SIGNAL( clicked() ), this, SLOT( onUseCaseBtn() ) );
306   connect( myClearBtn,   SIGNAL( clicked() ), this, SLOT( onUseCaseBtn() ) );
307   connect( myCurrentBtn, SIGNAL( clicked() ), this, SLOT( onUseCaseBtn() ) );
308
309   /* Connect section */
310 #if QT_VERSION < 0x030005
311   connect( myUseCaseView, SIGNAL( rightButtonClicked( QListViewItem*, const QPoint&, int ) ),
312            this,       SLOT(   showPopupMenu( QListViewItem* ) ) );
313 #else
314   connect( myUseCaseView, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
315            this,       SLOT(   showPopupMenu( QListViewItem* ) ) );
316 #endif  
317   
318   connect( myUseCaseView, SIGNAL( selectionChanged() ),
319            this,       SLOT( onSelectedItem() ) );
320
321   /* add Object Browser and UseCase Browser as pages ================= */
322   this->addTab( myListView,    tr( "TLT_OBJECT_BROWSER" ) );
323   this->addTab( myVBox, tr( "TLT_USECASE_BROWSER" ) );
324   
325   if ( showUseCase != "true")
326     this->removePage(myVBox);
327  
328   setShowInfoColumns( AddColumn == "true" );
329   setShowValueColumn( ValueColumn == "true" );
330   setEnableChronoSort( ShowCHRONO_SORT == "true" );
331   
332   if ( noAutoSizeColumns == "true" ) 
333     {
334       for (int i = 0; i < myListView->header()->count(); i++ )
335         myListView->setColumnWidthMode(i, QListView::Manual);
336     }
337
338   resize( QSize( 100, 400 ) );
339 }
340
341 /*!
342   Event filter
343   We can use the following static variables for drag-n-drop operations because it is impossible
344   to perform several dragging operation at one time.
345 */
346 static bool dragged = false;
347 static QStringList draggedlist;
348 bool QAD_ObjectBrowser::eventFilter( QObject* o, QEvent* e )
349 {
350   QAD_Desktop* Desktop     = (QAD_Desktop*) QAD_Application::getDesktop();
351   QAD_Study* myActiveStudy = Desktop->getActiveStudy();
352  
353   if ( myStudy->_is_nil() )
354     return QTabWidget::eventFilter( o, e );
355
356   SALOMEDS::UseCaseBuilder_var UCBuilder = myStudy->GetUseCaseBuilder();
357   if (! myUseCaseView) return QTabWidget::eventFilter( o, e );
358   if (o == myUseCaseView->viewport()) {
359     if ( e->type() == QEvent::MouseButtonPress ) {
360       // Test if clicked on selection and start drag if necessary
361       QMouseEvent* me = ( QMouseEvent* )e;
362       QAD_ObjectBrowserItem* item = ( QAD_ObjectBrowserItem* )( myUseCaseView->itemAt( me->pos() ) );
363       if ( item && item->isSelected() && me->button() == LeftButton && !(me->state() & (ControlButton | ShiftButton)) ) {
364         if ( me->pos().x() > myUseCaseView->header()->sectionPos( myUseCaseView->header()->mapToIndex( 0 ) ) +
365                              myUseCaseView->treeStepSize() * ( item->depth() + ( myUseCaseView->rootIsDecorated() ? 1 : 0 ) ) + 
366                              myUseCaseView->itemMargin() ||
367              me->pos().x() < myUseCaseView->header()->sectionPos( myUseCaseView->header()->mapToIndex( 0 ) ) ) { 
368           QStringList entryList;
369           QListViewItemIterator it( myUseCaseView );
370           bool done = true;
371           for ( ; it.current(); ++it ) {
372             QAD_ObjectBrowserItem* selItem = ( QAD_ObjectBrowserItem* )( it.current() );
373             if ( selItem->isSelected() ) {
374               if ( isRootItem( selItem ) ) {
375                 done = false;
376                 break;
377               }
378               else {
379                 entryList.append( selItem->getEntry() );
380               }
381             }
382           }
383           if ( done && !entryList.isEmpty() ) {
384             draggedlist = entryList;
385             // vsr 03/03/05 - start dragging only if mouse starts moving after pressing left button (see below)
386             //QTextDrag *d = new QTextDrag( entryList.join("*"), myUseCaseView->viewport() );
387             //d->dragMove();
388             dragged = true;
389             return true;
390           }
391         }
392       }
393     }
394     else if ( e->type() == QEvent::MouseMove ) {
395       // vsr 03/03/05 - start dragging only if mouse starts moving
396       if ( dragged ) {
397         if ( !draggedlist.isEmpty() ) {
398           QTextDrag *d = new QTextDrag( draggedlist.join("*"), myUseCaseView->viewport() );
399           d->dragMove();
400         }
401         dragged = false;
402         draggedlist.clear();
403       }
404     }
405     else if ( e->type() == QEvent::MouseButtonRelease ) {
406       // vsr 03/03/05 - if dragging was not performed (mouse was not moved after mouse press)
407       // simulate the ordinary mouse click that means just selection of the one item
408       QMouseEvent* me = ( QMouseEvent* )e;
409       if ( dragged ) {
410         draggedlist.clear();
411         dragged = false;
412         QAD_ObjectBrowserItem* item = ( QAD_ObjectBrowserItem* )( myUseCaseView->itemAt( me->pos() ) );
413         myUseCaseView->clearSelection();
414         myUseCaseView->setSelected( item, true );
415         myUseCaseView->setCurrentItem( item );
416       }
417     }
418     else if ( e->type() == QEvent::DragMove ) {
419       QDragMoveEvent* dme = ( QDragMoveEvent* )e;
420       if ( dme->source() == myUseCaseView->viewport() ) {
421         dme->accept();
422       }
423       else {
424         dme->ignore();
425       }
426       return true;
427     }
428     else if ( e->type() == QEvent::Drop ) {
429       QDropEvent* de = ( QDropEvent* )e;
430       QString text;
431       QAD_ObjectBrowserItem* dropItem = ( QAD_ObjectBrowserItem* )( myUseCaseView->itemAt( de->pos() ) );
432       if ( de->source() == myUseCaseView->viewport() ) {
433         if ( QTextDrag::decode( de, text ) && dropItem && !dropItem->isSelected() ) {
434           QAD_ObjectBrowserItem* useCaseItem = ( QAD_ObjectBrowserItem* )getTopParent( dropItem );
435           if ( useCaseItem ) {
436             if ( !UCBuilder->_is_nil() ) {
437               UCBuilder->SetRootCurrent();
438               if ( useCaseItem != dropItem ) {
439                 SALOMEDS::SObject_var dropObject = myStudy->FindObjectID( dropItem->getEntry() );
440                 if ( !dropObject->_is_nil() )
441                   UCBuilder->SetCurrentObject( dropObject );
442               }
443               QStringList entryList = QStringList::split( "*", text, false );
444               // if Move action then first remove all selected items
445               if ( de->action() == QDropEvent::Move ) {
446                 QList<QListViewItem> ucSelected; 
447                 ucSelected.setAutoDelete( false );
448                 getSelectedParents( myUseCaseView, ucSelected );
449                 for ( int j = 0; j < entryList.count(); j++ ) {
450                   QAD_ObjectBrowserItem* delItem = ( QAD_ObjectBrowserItem* )( ucSelected.at( j ) );
451                   QAD_ObjectBrowserItem* ucDelItem = ( QAD_ObjectBrowserItem* )getTopParent( delItem );
452                   SALOMEDS::SObject_var delSO = myStudy->FindObjectID( delItem->getEntry() );
453                   if ( !delSO->_is_nil() && ucDelItem ) {
454                     UCBuilder->Remove( delSO );
455                   }
456                 }
457               }
458               // then try to append items to destination
459               for ( int i = 0; i < entryList.count(); i++ ) {
460                 SALOMEDS::SObject_var SO = myStudy->FindObjectID( entryList[i] );
461                 if ( !SO->_is_nil() ) {
462                   UCBuilder->Remove( SO );
463                   UCBuilder->Append( SO );
464                 }
465               }
466               myActiveStudy->updateUseCaseBrowser();
467             }
468           }
469         }
470         de->acceptAction();
471       }
472       else {
473         de->ignore();
474       }
475       return true;
476     }
477   }
478   else if ( o == myUseCaseView ) {
479     if ( e->type() == QEvent::KeyPress ) {
480       QKeyEvent* ke = ( QKeyEvent* )e;
481       if ( ke->key() == Key_Delete ) {
482         onUseCasePopupMenu( UC_REMOVE_ID );
483         return true;
484       }
485     }
486   }
487   return QTabWidget::eventFilter( o, e );
488 }
489
490
491 /*!
492   Returns true if item is collapsed has collapsed children
493 */
494 static bool hasCollapsed( QListViewItem* item )
495 {
496   if ( !item )
497     return false;
498
499   bool res = ( item->childCount() && !item->isOpen() );
500   for ( QListViewItem* child = item->firstChild(); !res && child; child = child->nextSibling() )
501     res = hasCollapsed( child );
502
503   return res;
504 }
505
506 /*!
507   Expands item and all its children
508 */
509 static void expand(QListViewItem* item)
510 {
511   if ( !item )
512     return;
513
514   item->setOpen( true );
515
516   for ( QListViewItem* child = item->firstChild(); child; child = child->nextSibling() )
517     expand( child );
518 }
519
520 /*!
521   Builds popup menu
522 */
523 void QAD_ObjectBrowser::onCreatePopup()
524 {
525   QAD_Desktop*     Desktop = (QAD_Desktop*) QAD_Application::getDesktop();
526   QAD_Study*   myActiveStudy = Desktop->getActiveStudy();
527   SALOME_Selection*      Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
528
529   bool canExpand = false;
530   /* VSR : Creation of common POPUP menu for Object Browser/Use Case Browser */
531   if ( Sel->IObjectCount() > 0 ) {
532     QString theContext;
533     QString theParent;
534     QString theObject;
535     
536     Desktop->definePopup( theContext, theParent, theObject );
537     if ( myPopup ) {
538       Desktop->createPopup( myPopup, theContext, "ObjectBrowser", theObject);
539       if ( !Desktop->getActiveComponent().isEmpty() ) {
540         Desktop->customPopup( myPopup, theContext, "ObjectBrowser", theObject );
541       }
542       // VSR:22/01/03 - Command for edit attributes value
543       bool EditValues  = QAD_CONFIG->getSetting( "ObjectBrowser:EditValues" ) == "true";
544       if ( EditValues && Sel->IObjectCount() == 1 && hasEditableAttribute(Sel->firstIObject()) ) {
545         if ( myPopup->count() > 0 )
546           myPopup->insertSeparator();
547         myPopup->insertItem( tr( "EDIT_VALUE_CMD" ),
548                              this,
549                              SLOT( onEditAttribute() ) );
550       }
551
552       for ( QListViewItemIterator it( currentPage() == myListView ? myListView : myUseCaseView ); it.current() && !canExpand; ++it )
553         canExpand = canExpand || ( it.current()->isSelected() && hasCollapsed( it.current() ) );
554
555       if ( canExpand ) {
556         if ( myPopup->count() > 0 )
557           myPopup->insertSeparator();
558         myPopup->insertItem( tr( "EXPAND_ALL_CMD" ),
559                              this,
560                              SLOT( onExpandAll() ) );
561       }
562     }
563   } else {
564     // NRI 02/12/2002
565     // No selected item => it's not necessary to create popup
566     //NRI- :  Desktop->createPopup( myPopup, "", "ObjectBrowser", "");
567   }
568   if ( currentPage() != myListView ) {
569     /* VSR : Creation of POPUP menu for UseCase Browser */
570     QList<QListViewItem> ucSelected; 
571     ucSelected.setAutoDelete( false );
572     getSelectedParents( myUseCaseView, ucSelected );
573     
574     if ( myPopup && !myStudy->_is_nil() ) {
575       SALOMEDS::UseCaseBuilder_var UCBuilder = myStudy->GetUseCaseBuilder();
576 //      myPopup->clear();
577       bool isOne = ucSelected.count() == 1;
578       bool isRoot = isOne && isRootItem( ucSelected.at( 0 ) );
579       bool manyChildren = myUseCaseView->childCount() > 0 && myUseCaseView->firstChild()->childCount() > 0;
580       bool isUseCase = isOne && 
581         ( isRoot || UCBuilder->IsUseCase( myStudy->FindObjectID( (( QAD_ObjectBrowserItem* )( ucSelected.at(0) ))->getEntry() ) ) ); 
582
583       if ( isRoot ) {
584         myPopup->clear();
585         if ( canExpand ) {
586           myPopup->insertItem( tr( "EXPAND_ALL_CMD" ),
587                                this,
588                                SLOT( onExpandAll() ) );
589         }
590       }
591       QPopupMenu *UseCasePopup = new QPopupMenu( myPopup );
592       if ( isOne )
593         UseCasePopup->insertItem( tr( "UC_NEW_ID" ), this, SLOT( onUseCasePopupMenu( int ) ), 0, UC_NEW_EMPTY_ID );
594       if ( isOne )
595         UseCasePopup->insertItem( tr( "UC_SET_CURRENT_ID" ), this, SLOT( onUseCasePopupMenu( int ) ), 0, UC_SET_CURRENT_ID );
596       if ( isUseCase )
597         UseCasePopup->insertItem( tr( "UC_RENAME_ID" ),    this, SLOT( onUseCasePopupMenu( int ) ), 0, UC_RENAME_ID );
598       if ( isRoot && manyChildren )
599         UseCasePopup->insertItem( tr( "UC_CLEAR_ID" ),   this, SLOT( onUseCasePopupMenu( int ) ), 0, UC_CLEAR_ID );
600
601       if ( UseCasePopup->count() > 0 ) {
602         if ( myPopup->count() > 0 )
603           myPopup->insertSeparator();
604         myPopup->insertItem( tr( "UC_POPUP" ), UseCasePopup );
605       }
606       else {
607         delete UseCasePopup;
608       }
609     }
610   }
611 }
612
613 /*!
614   Called on "Expand all" popup menu command
615 */
616 void QAD_ObjectBrowser::onExpandAll()
617 {
618   for ( QListViewItemIterator it( currentPage() == myListView ? myListView : myUseCaseView ); it.current(); ++it )
619     if ( it.current()->isSelected() )
620       expand( it.current() );  
621 }
622
623 /*!
624   Returns Object Browser list view
625 */
626 QListView* QAD_ObjectBrowser::getListView() const
627 {
628   return myListView;
629 }
630
631 /*!
632   Returns UseCase Browser list view
633 */
634 QListView* QAD_ObjectBrowser::getUseCaseView() const
635 {
636   return myUseCaseView;
637 }
638
639 /*!
640   Adds anItem ( probably a SComponent )
641 */
642 QAD_ObjectBrowserItem* QAD_ObjectBrowser::AddItem(QListView*             theView,
643                                                   const QString&         theName,
644                                                   const QString&         theEntry,
645                                                   const QString&         theIOR, 
646                                                   int                    theType, 
647                                                   const QString&         theValue,
648                                                   QAD_ObjectBrowserItem* theAfter)
649
650 {
651   QAD_ObjectBrowserItem* last = (QAD_ObjectBrowserItem*)(theView->firstChild());
652   if ( theAfter )
653     last = theAfter;
654   else if ( last ) {
655     for ( ; last->nextSibling(); last = (QAD_ObjectBrowserItem*)(last->nextSibling()) );
656   }
657   QAD_ObjectBrowserItem* anItem = new QAD_ObjectBrowserItem( theView, last );
658   
659   anItem->setType( theType );
660   anItem->setOpen( FALSE );
661   anItem->setName( theName );
662   anItem->setValue( theValue );
663   anItem->setEntry( theEntry );
664   anItem->setIOR( theIOR );
665   anItem->setReference( "" );
666
667   return anItem;
668 }
669
670 /*!
671   Adds anItem ( probably a StudyObject )
672 */
673 QAD_ObjectBrowserItem* QAD_ObjectBrowser::AddItem(QAD_ObjectBrowserItem* theParentItem,
674                                                   const QString&         theName,
675                                                   const QString&         theEntry,
676                                                   const QString&         theIOR,
677                                                   int                    theType,
678                                                   const QString&         theRef,
679                                                   const QString&         theValue,
680                                                   QAD_ObjectBrowserItem* theAfter)
681
682 {
683   QAD_ObjectBrowserItem* last = (QAD_ObjectBrowserItem*)(theParentItem->firstChild());
684   if ( theAfter )
685     last = theAfter;
686   else if ( last ) {
687     for ( ; last->nextSibling(); last = (QAD_ObjectBrowserItem*)(last->nextSibling()) );
688   }
689   QAD_ObjectBrowserItem* anItem = new QAD_ObjectBrowserItem(theParentItem, last);
690   anItem->setType( theType );
691   anItem->setOpen( FALSE );
692   anItem->setName( theName );
693   anItem->setValue( theValue );
694   anItem->setEntry( theEntry );
695   anItem->setIOR( theIOR );
696   anItem->setReference( theRef );
697
698   return anItem;
699 }
700
701 /*!
702   Updates Object Browsers' item [ protected ]
703 */
704 void QAD_ObjectBrowser::Update( SALOMEDS::SObject_ptr SO,
705                                 QAD_ObjectBrowserItem* theParentItem )
706 {
707   if ( myStudy->_is_nil() || SO->_is_nil() || !theParentItem ) {
708     return;
709   }
710   SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(SO);
711
712   for (; it->More();it->Next()) {
713     SALOMEDS::SObject_var             CSO = it->Value();
714     SALOMEDS::SObject_var             RefSO;
715     QString                           ior = "";
716     CORBA::String_var                 aString(CSO->GetID());
717     QString                           CSOEntry(aString.in());
718     SALOMEDS::GenericAttribute_var    anAttr;
719     SALOMEDS::AttributeName_var       aName;
720     SALOMEDS::AttributeComment_var    aCmnt;
721     SALOMEDS::AttributeIOR_var        anIOR;
722     SALOMEDS::AttributeReal_var       aReal;
723     SALOMEDS::AttributeInteger_var    anInt;
724     SALOMEDS::AttributeSelectable_var aSelectable;
725     SALOMEDS::AttributeExpandable_var anExpandable;
726     SALOMEDS::AttributeOpened_var     anOpened;
727     SALOMEDS::AttributePixMap_var     aPixmap;
728     SALOMEDS::AttributeTextColor_var  aTextColor;
729     SALOMEDS::AttributeTextHighlightColor_var  aTextHighlightColor;
730
731     QAD_ObjectBrowserItem*            Item = 0;
732     QString                           valueString;
733    
734     if ( CSO->ReferencedObject(RefSO) && !RefSO->_is_nil() ) {
735       
736       aString = RefSO->GetID();
737       QString RefSOEntry(aString.in());
738       if (CSO->FindAttribute(anAttr, "AttributeName") || RefSO->FindAttribute(anAttr, "AttributeName")) {
739         aName = SALOMEDS::AttributeName::_narrow(anAttr);
740         if (RefSO->FindAttribute(anAttr, "AttributeIOR")) {
741           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
742           aString = anIOR->Value();
743           ior = aString.in();
744         }
745         valueString = getValueFromObject( RefSO );
746         aString = aName->Value();
747         Item = AddItem(theParentItem, 
748                        QString(" * ") + aString.in(), 
749                        RefSOEntry, 
750                        ior, 
751                        2, 
752                        CSOEntry, 
753                        valueString);
754         myListViewMap[ RefSOEntry ].append( Item );
755       }
756       else {
757         if(MYDEBUG) MESSAGE("QAD_ObjectBrowser::Update : noname item: "<<CSO->GetID());
758       }
759     } else {
760       // getting Value
761       valueString = getValueFromObject( CSO );
762       // getting IOR
763       if (CSO->FindAttribute(anAttr, "AttributeIOR"))  {
764         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
765         aString = anIOR->Value();
766         ior = aString.in();
767       }
768       // getting Name and adding new Item
769       if (CSO->FindAttribute(anAttr, "AttributeName") ) {
770         aName = SALOMEDS::AttributeName::_narrow(anAttr);
771         aString = aName->Value();
772         Item = AddItem(theParentItem, aString.in(), CSOEntry, ior, 0, "", valueString);
773         myListViewMap[ CSOEntry ].append( Item );
774       } 
775       else {
776         if(MYDEBUG) MESSAGE("QAD_ObjectBrowser::Update : noname item: "<<CSO->GetID());
777       }
778       // adding other attributes 
779       if (Item) {
780         // Selectable
781         if ( CSO->FindAttribute(anAttr, "AttributeSelectable") ) {
782           aSelectable = SALOMEDS::AttributeSelectable::_narrow(anAttr);
783           Item->setSelectable(aSelectable->IsSelectable());
784         }
785         // Expandable
786         if ( CSO->FindAttribute(anAttr, "AttributeExpandable") ) {
787           anExpandable = SALOMEDS::AttributeExpandable::_narrow(anAttr);
788           Item->setExpandable(anExpandable->IsExpandable());
789         }
790         // Opened
791         if ( CSO->FindAttribute(anAttr, "AttributeOpened") ) {
792           anOpened = SALOMEDS::AttributeOpened::_narrow(anAttr);
793           Item->setOpen(anOpened->IsOpened());
794         }
795         // TextColor
796         if ( CSO->FindAttribute(anAttr, "AttributeTextColor") ) {
797           aTextColor = SALOMEDS::AttributeTextColor::_narrow(anAttr);
798           QColor aColor((int)(aTextColor->TextColor().R), (int)(aTextColor->TextColor().G), (int)(aTextColor->TextColor().B)) ;
799           Item->setTextColor(aColor);
800         }
801         // TextHighlightColor
802         if ( CSO->FindAttribute(anAttr, "AttributeTextHighlightColor") ) {
803           aTextHighlightColor = SALOMEDS::AttributeTextHighlightColor::_narrow(anAttr);
804           QColor aColor((int)(aTextHighlightColor->TextHighlightColor().R), 
805                         (int)(aTextHighlightColor->TextHighlightColor().G), 
806                         (int)(aTextHighlightColor->TextHighlightColor().B)) ;
807           Item->setTextHighlightColor(aColor);
808         }
809         // Pixmap
810         if ( CSO->FindAttribute(anAttr, "AttributePixMap") ) {
811           aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
812           if ( aPixmap->HasPixMap() ) {
813             SALOMEDS::SComponent_var father = CSO->GetFatherComponent();
814             if (father->FindAttribute(anAttr, "AttributeName") ) {
815               SALOMEDS::AttributeName_var aFatherName;
816               aFatherName = SALOMEDS::AttributeName::_narrow(anAttr);
817
818               QString msg;
819               QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
820               if ( resMgr ) {
821                 //if(resMgr->loadResources( QString(aFatherName->Value()) + "GUI", msg )) {
822                 if( resMgr->loadResources( QAD_Application::getDesktop()->getComponentName( QString( aFatherName->Value() ) ), msg ) ) {
823                   QPixmap icon ( resMgr->loadPixmap( QAD_Application::getDesktop()->getComponentName( QString( aFatherName->Value() ) ),
824                                                     tr( aPixmap->GetPixMap() )  /*tr( "ICON_OBJBROWSER_" + theComponent )*/ ) );
825                   //QPixmap icon ( resMgr->loadPixmap( QString(aFatherName->Value()) + "GUI",
826                   //tr(aPixmap->GetPixMap()) /*tr( "ICON_OBJBROWSER_" + theComponent )*/ ));
827                   Item->setPixmap( 0, icon );
828                 }
829               }
830             }
831           }
832         }
833       } 
834     }
835 //  if ( theParentItem->isOpen() )
836 //    Item->setOpen(TRUE);
837
838     if ( Item )
839       Update(CSO, Item);
840   }
841 }
842
843 /*!
844   Updates Object Browser tree and UseCase Browser tree
845 */
846 void QAD_ObjectBrowser::Update()
847 {
848   int xc = myListView->contentsX();
849   int yc = myListView->contentsY();
850   myListView->viewport()->setUpdatesEnabled( false );
851  
852   myListView->clear();
853   myListViewMap.clear();
854
855   if ( myStudy->_is_nil() ) {
856     return;
857   }
858
859   QString ShowIAPP = QAD_CONFIG->getSetting("ObjectBrowser:IAPP");
860
861   /* Updating Object Browser ============================================== */
862   SALOMEDS::SComponentIterator_var itcomp = myStudy->NewComponentIterator();
863   for (; itcomp->More(); itcomp->Next()) {
864     QAD_ObjectBrowserItem*   Item     = 0;
865     SALOMEDS::SComponent_var SC       = itcomp->Value();
866     CORBA::String_var        aString  = SC->ComponentDataType();
867     QString                  dataType = aString.in();
868     QString                  ior      = "";
869     aString = SC->GetID();
870     QString                  SCEntry  = aString.in();
871
872     SALOMEDS::GenericAttribute_var    anAttr;
873     SALOMEDS::AttributeName_var       aName;
874     SALOMEDS::AttributeComment_var    aCmnt;
875     SALOMEDS::AttributeIOR_var        anIOR;
876     SALOMEDS::AttributeReal_var       aReal;
877     SALOMEDS::AttributeInteger_var    anInt;
878     SALOMEDS::AttributeSelectable_var aSelectable;
879     SALOMEDS::AttributeExpandable_var anExpandable;
880     SALOMEDS::AttributeOpened_var     anOpened;
881     SALOMEDS::AttributePixMap_var     aPixmap;
882     SALOMEDS::AttributeTextColor_var  aTextColor;
883     SALOMEDS::AttributeTextHighlightColor_var  aTextHighlightColor;
884
885     if (SC->FindAttribute(anAttr, "AttributeIOR")) {
886       anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
887       aString = anIOR->Value();
888       ior = aString.in();
889     }
890
891     bool caseIAPP = false;
892
893     // create data-tree item, corresponding to component (and set name if component has it)
894     if ( dataType.compare("Interface Applicative") == 0 ) {
895       caseIAPP = true;
896       if ( ShowIAPP.compare("true") == 0 ) {
897         if (SC->FindAttribute(anAttr, "AttributeName")) {
898           aName = SALOMEDS::AttributeName::_narrow(anAttr);
899           aString = aName->Value();
900           Item = AddItem (myListView, aString.in(), SCEntry.latin1(), ior, 1, "");
901           myListViewMap[ SCEntry ].append( Item );
902         } 
903         else {
904           Item = AddItem (myListView, dataType, SCEntry, ior, 1, "");
905           myListViewMap[ SCEntry ].append( Item );
906         }
907
908       }
909     } 
910     else {
911       caseIAPP = false;
912       if (SC->FindAttribute(anAttr, "AttributeName")) {
913         aName = SALOMEDS::AttributeName::_narrow(anAttr);
914         aString = aName->Value();
915         Item = AddItem (myListView, aString.in(), SCEntry, ior, 1, "");
916         myListViewMap[ SCEntry ].append( Item );
917       } 
918       else {
919         /*In according to CAF - any label (even if it is empty) exist during to whole session.
920           So, if label haven't an "AttributeName" it is means that the label is empty.
921           Therefore follow action couses bug - 
922         Item = AddItem (myListView, dataType,       SC->GetID(), ior, 1, "");
923         */
924       }
925     }
926     // add other attributes 
927     if (Item) {
928       // Selectable
929       if ( SC->FindAttribute(anAttr, "AttributeSelectable") ) {
930         aSelectable = SALOMEDS::AttributeSelectable::_narrow(anAttr);
931         Item->setSelectable(aSelectable->IsSelectable());
932       }
933       // Expandable
934       if ( SC->FindAttribute(anAttr, "AttributeExpandable") ) {
935         anExpandable = SALOMEDS::AttributeExpandable::_narrow(anAttr);
936         Item->setExpandable(anExpandable->IsExpandable());
937       }
938       // Opened
939       if ( SC->FindAttribute(anAttr, "AttributeOpened") ) {
940         anOpened = SALOMEDS::AttributeOpened::_narrow(anAttr);
941         Item->setOpen(anOpened->IsOpened());
942       }
943       // TextColor
944       if ( SC->FindAttribute(anAttr, "AttributeTextColor") ) {
945         aTextColor = SALOMEDS::AttributeTextColor::_narrow(anAttr);
946         QColor aColor((int)(aTextColor->TextColor().R), (int)(aTextColor->TextColor().G), (int)(aTextColor->TextColor().B)) ;
947         Item->setTextColor(aColor);
948       }
949       // TextHighlightColor
950       if ( SC->FindAttribute(anAttr, "AttributeTextHighlightColor") ) {
951         aTextHighlightColor = SALOMEDS::AttributeTextHighlightColor::_narrow(anAttr);
952         QColor aColor((int)(aTextHighlightColor->TextHighlightColor().R), 
953                       (int)(aTextHighlightColor->TextHighlightColor().G), 
954                       (int)(aTextHighlightColor->TextHighlightColor().B)) ;
955         Item->setTextHighlightColor(aColor);
956       }
957       
958       // Pixmap
959       if ( SC->FindAttribute(anAttr, "AttributePixMap") ) {
960         aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
961         if ( aPixmap->HasPixMap() ) {
962           QString msg;
963           QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
964           if ( resMgr ) {
965             if(MYDEBUG) MESSAGE ( " Component " << aName->Value() );
966             if(MYDEBUG) MESSAGE ( " Icon " << aPixmap->GetPixMap() );
967             if(resMgr->loadResources( QAD_Application::getDesktop()->getComponentName(QString(aName->Value())), msg )) {
968               QPixmap icon ( resMgr->loadPixmap( QAD_Application::getDesktop()->getComponentName(QString(aName->Value())),
969                                                  tr(aPixmap->GetPixMap()) /*tr( "ICON_OBJBROWSER_" + theComponent )*/ ));
970               Item->setPixmap( 0, icon );
971             }
972           }
973         }
974       }
975       /*
976          if ( strcmp(dataType, TypeComponent) == 0 )
977          Item->setOpen(TRUE);
978       */
979       if ( caseIAPP && ShowIAPP.compare("true") == 0 )
980         Update (SC, Item);
981       
982       if ( !caseIAPP )
983         Update (SC, Item);
984     }
985   }
986   myListView->setContentsPos(xc,yc);
987
988   myListView->viewport()->setUpdatesEnabled( true );
989   myListView->viewport()->repaint( false );
990   /* Updating UseCase Browser ============================================= */
991   if ( this->count() > 1 ) 
992     UpdateUseCaseBrowser(); 
993
994
995 /*!
996   Removes item with all childs from the map - used to optimize UseCase browser update
997 */
998 void removeFromMap( ItemMap& theMap, QAD_ObjectBrowserItem* item )
999 {
1000   if ( item ) {
1001     QAD_ObjectBrowserItem* subItem = ( QAD_ObjectBrowserItem* )( item->firstChild() );
1002     while ( subItem ) {
1003       removeFromMap( theMap, subItem );
1004       subItem = ( QAD_ObjectBrowserItem* )( subItem->nextSibling() );
1005     }
1006     if ( theMap.contains( item->getEntry() ) ) {
1007       theMap[ item->getEntry() ].removeRef( item );
1008       if ( theMap[ item->getEntry() ].isEmpty() ) {
1009         theMap.remove( item->getEntry() );
1010       }
1011     }
1012   }
1013 }
1014
1015 /*!
1016   Updates only UseCase Browser
1017 */
1018 void QAD_ObjectBrowser::UpdateUseCaseBrowser() {
1019 //  myUseCaseView->clear(); myUseCaseMap.clear();
1020   if ( myStudy->_is_nil() || this->count()<2 ) {
1021     return;
1022   }
1023   myUseCaseView->blockSignals( true );
1024 //  myUseCaseView->setUpdatesEnabled( false );
1025
1026   QAD_ObjectBrowserItem* root = ( QAD_ObjectBrowserItem* )myUseCaseView->firstChild();
1027   SALOMEDS::UseCaseBuilder_var  UCBuilder = myStudy->GetUseCaseBuilder();
1028   SALOMEDS::SObject_var SOCurrent = UCBuilder->GetCurrentObject();
1029   CORBA::String_var aString = UCBuilder->GetName();
1030   QString UCName = aString.in();
1031   if ( UCName.isEmpty() )
1032     UCName = QString( tr( "Root" ) );
1033   // creating root item if is not yet created
1034   if ( !root ) {
1035     root = AddItem( myUseCaseView, UCName, "0:2", "", 1, "" );
1036     myUseCaseMap[ "0:2" ].append( root );
1037   }
1038   else
1039     root->setName( UCName );
1040   // setting it current if necessary
1041   root->setCurrent( SOCurrent->_is_nil() || !strcmp( SOCurrent->GetID(), "0:2" ) );
1042   // updating list view...
1043   QMap<QString,SALOMEDS::SObject_var> ucList;
1044   SALOMEDS::UseCaseIterator_var UCIter = UCBuilder->GetUseCaseIterator( SALOMEDS::SObject::_nil() );
1045   if ( !UCIter->_is_nil() ) {
1046     for ( ; UCIter->More(); UCIter->Next() ) {
1047       SALOMEDS::SObject_var UCObject = UCIter->Value();
1048       aString = UCObject->GetID();
1049       QString UCEntry = aString.in();
1050       ucList[ UCEntry ] = UCObject;
1051     }
1052   }
1053   // ... 1) delete removed items
1054   QAD_ObjectBrowserItem* childItem = ( QAD_ObjectBrowserItem* )root->firstChild();
1055   while ( childItem ) {
1056     QAD_ObjectBrowserItem* prevItem = childItem;
1057     childItem = ( QAD_ObjectBrowserItem* )childItem->nextSibling();
1058     if ( !ucList.contains( prevItem->getEntry() ) ) {
1059 //      myUseCaseMap[ prevItem->getEntry() ].removeRef( prevItem );
1060 //      if ( myUseCaseMap[ prevItem->getEntry() ].isEmpty() )
1061 //      myUseCaseMap.remove( prevItem->getEntry() );
1062       removeFromMap( myUseCaseMap, prevItem );
1063       delete prevItem;
1064     }
1065   }
1066   // ... 2) create/update existing
1067   QMap<QString,SALOMEDS::SObject_var>::Iterator it;
1068   for ( it = ucList.begin(); it != ucList.end(); ++it ) {
1069     UpdateUCItem( it.data(), root );
1070   }
1071   myUseCaseView->blockSignals( false );
1072 //  myUseCaseView->setUpdatesEnabled( true );
1073 //  myUseCaseView->update();
1074 //  UCItem->setOpen( true );
1075 }
1076
1077 /*!
1078   Updates UseCase Browser's item
1079 */
1080 void QAD_ObjectBrowser::UpdateUCItem( SALOMEDS::SObject_var UCObject, QAD_ObjectBrowserItem* UCItem )
1081 {
1082   if ( myStudy->_is_nil() || !UCItem ) 
1083     return;
1084
1085   // --- VSR: 01/02/05 --- start
1086   // skip all 'Interface Applicative' objects
1087   SALOMEDS::SComponent_var SCO = UCObject->GetFatherComponent();
1088   CORBA::String_var aCorbaString = SCO->ComponentDataType();
1089   QString dataType = aCorbaString.in();
1090   if ( dataType.compare("Interface Applicative") == 0 )
1091     return;
1092   // --- VSR: 01/02/05 --- finish
1093
1094   /* Creating SObjects item */
1095   SALOMEDS::SObject_var                      RefSO;
1096   SALOMEDS::GenericAttribute_var             anAttr;
1097   SALOMEDS::AttributeName_var                aName;
1098   SALOMEDS::AttributeIOR_var                 anIOR;
1099   SALOMEDS::AttributeSelectable_var          aSelectable;
1100   SALOMEDS::AttributeExpandable_var          anExpandable;
1101   SALOMEDS::AttributePixMap_var              aPixmap;
1102   SALOMEDS::AttributeTextColor_var           aTextColor;
1103   SALOMEDS::AttributeTextHighlightColor_var  aTextHighlightColor;
1104   QString                                    valueString;
1105   QString                                    ior = "";
1106   CORBA::String_var                          aString = UCObject->GetID();
1107   QString                                    UCEntry = aString.in();
1108
1109   SALOMEDS::UseCaseBuilder_var               UCBuilder = myStudy->GetUseCaseBuilder();
1110   SALOMEDS::SObject_var                      SOCurrent = UCBuilder->GetCurrentObject();
1111   bool                                       isUseCase = UCBuilder->IsUseCase( UCObject );
1112
1113   QAD_ObjectBrowserItem* UCSubItem = 0;
1114   if ( myUseCaseMap.contains( UCEntry ) && myUseCaseMap[ UCEntry ].count() > 0 )
1115     UCSubItem = myUseCaseMap[ UCEntry ].first();
1116
1117   if ( UCObject->ReferencedObject( RefSO ) && !RefSO->_is_nil() ) {
1118     aString = RefSO->GetID();
1119     QString RefSOEntry = aString.in();
1120     if ( UCObject->FindAttribute( anAttr, "AttributeName" ) || RefSO->FindAttribute( anAttr, "AttributeName" ) ) {
1121       aName = SALOMEDS::AttributeName::_narrow( anAttr );
1122       if ( RefSO->FindAttribute( anAttr, "AttributeIOR" ) ) {
1123         anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
1124         aString = anIOR->Value();
1125         ior = aString.in();
1126       }
1127       valueString = getValueFromObject( RefSO );
1128       aString = aName->Value();
1129       if ( !UCSubItem ) {
1130         UCSubItem = AddItem( UCItem, 
1131                              QString( " * " ) + aString.in(), 
1132                              RefSOEntry, 
1133                              ior, 
1134                              2, 
1135                              UCEntry, 
1136                              valueString );
1137         myUseCaseMap[ RefSOEntry ].append( UCSubItem );
1138       }
1139       else {
1140         UCSubItem->setName( QString( " * " ) + aString.in() );
1141         UCSubItem->setEntry( RefSOEntry );
1142         UCSubItem->setIOR( ior );
1143         UCSubItem->setReference( UCEntry );
1144         UCSubItem->setValue( valueString );
1145       }
1146       UCSubItem->setCurrent( !SOCurrent->_is_nil() && QString( SOCurrent->GetID() ) == QString( UCEntry ) );
1147     }
1148   } 
1149   else {
1150     // getting Value
1151     valueString = getValueFromObject( UCObject );
1152     // getting IOR
1153     if ( UCObject->FindAttribute( anAttr, "AttributeIOR" ) )  {
1154       anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
1155       aString = anIOR->Value();
1156       ior = aString.in();
1157     }
1158     // getting Name and adding new Item
1159     if ( UCObject->FindAttribute( anAttr, "AttributeName" ) ) {
1160       aName = SALOMEDS::AttributeName::_narrow( anAttr );
1161       aString = aName->Value();
1162       if ( !UCSubItem ) {
1163         UCSubItem = AddItem( UCItem, aString.in(), UCEntry, ior, isUseCase ? 1 : 0, "", valueString );
1164         myUseCaseMap[ UCEntry ].append( UCSubItem );
1165       }
1166       else {
1167         UCSubItem->setName( aString.in() );
1168         UCSubItem->setEntry( UCEntry );
1169         UCSubItem->setIOR( ior );
1170         UCSubItem->setReference( "" );
1171         UCSubItem->setValue( valueString );
1172       }
1173     } 
1174     // adding other attributes 
1175     if ( UCSubItem ) {
1176       UCSubItem->setCurrent( !SOCurrent->_is_nil() && QString( SOCurrent->GetID() ) == QString( UCEntry ) );
1177 //  Selectable
1178 //      if ( UCObject->FindAttribute( anAttr, "AttributeSelectable" ) ) {
1179 //      aSelectable = SALOMEDS::AttributeSelectable::_narrow( anAttr );
1180 //      UCSubItem->setSelectable( aSelectable->IsSelectable() );
1181 //      }
1182 // Expandable
1183 //      if ( UCObject->FindAttribute( anAttr, "AttributeExpandable" ) ) {
1184 //      anExpandable = SALOMEDS::AttributeExpandable::_narrow( anAttr );
1185 //      UCSubItem->setExpandable( anExpandable->IsExpandable() );
1186 //      }
1187 // TextColor
1188       if ( UCObject->FindAttribute(anAttr, "AttributeTextColor" ) ) {
1189         aTextColor = SALOMEDS::AttributeTextColor::_narrow( anAttr );
1190         QColor aColor( (int)(aTextColor->TextColor().R), 
1191                        (int)(aTextColor->TextColor().G), 
1192                        (int)(aTextColor->TextColor().B) );
1193         UCSubItem->setTextColor( aColor );
1194       }
1195       // TextHighlightColor
1196       if ( UCObject->FindAttribute( anAttr, "AttributeTextHighlightColor" ) ) {
1197         aTextHighlightColor = SALOMEDS::AttributeTextHighlightColor::_narrow( anAttr );
1198         QColor aColor( (int)(aTextHighlightColor->TextHighlightColor().R), 
1199                        (int)(aTextHighlightColor->TextHighlightColor().G), 
1200                        (int)(aTextHighlightColor->TextHighlightColor().B) );
1201         UCSubItem->setTextHighlightColor( aColor );
1202       }
1203       // Pixmap
1204       if ( UCObject->FindAttribute( anAttr, "AttributePixMap" ) ) {
1205         aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1206         if ( aPixmap->HasPixMap() ) {
1207           SALOMEDS::SComponent_var father = UCObject->GetFatherComponent();
1208           if ( father->FindAttribute( anAttr, "AttributeName" ) ) {
1209             SALOMEDS::AttributeName_var aFatherName;
1210             aFatherName = SALOMEDS::AttributeName::_narrow( anAttr );
1211             QAD_ResourceMgr* resMgr = QAD_Desktop::getResourceManager();
1212             if ( resMgr ) {
1213               QString msg;
1214               if( resMgr->loadResources( QAD_Application::getDesktop()->getComponentName(QString( aFatherName->Value() )), msg ) ) {
1215                 QPixmap icon ( resMgr->loadPixmap( QAD_Application::getDesktop()->getComponentName(QString( aFatherName->Value() )),
1216                                                    tr( aPixmap->GetPixMap() ) /*tr( "ICON_OBJBROWSER_" + theComponent )*/ ) );
1217                 UCSubItem->setPixmap( 0, icon );
1218               }
1219             }
1220           }
1221         }
1222       }
1223     } 
1224   }
1225   if ( UCSubItem ) {
1226     // updating children ...
1227     QMap<QString,SALOMEDS::SObject_var> ucList;
1228     SALOMEDS::UseCaseIterator_var UCIter = UCBuilder->GetUseCaseIterator( UCObject );
1229     if ( !UCIter->_is_nil() ) {
1230       for ( ; UCIter->More(); UCIter->Next() ) {
1231         SALOMEDS::SObject_var UCSubObject = UCIter->Value();
1232         aString = UCSubObject->GetID();
1233         QString UCSubEntry = aString.in();
1234         ucList[ UCSubEntry ] = UCSubObject;
1235       }
1236     }
1237     // ... 1) delete removed items
1238     QAD_ObjectBrowserItem* childItem = ( QAD_ObjectBrowserItem* )UCSubItem->firstChild();
1239     while ( childItem ) {
1240       QAD_ObjectBrowserItem* prevItem = childItem;
1241       childItem = ( QAD_ObjectBrowserItem* )childItem->nextSibling();
1242       if ( !ucList.contains( prevItem->getEntry() ) ) {
1243         //      myUseCaseMap[ prevItem->getEntry() ].removeRef( prevItem );
1244         //      if ( myUseCaseMap[ prevItem->getEntry() ].isEmpty() )
1245         //      myUseCaseMap.remove( prevItem->getEntry() );
1246         removeFromMap( myUseCaseMap, prevItem );
1247         delete prevItem;
1248       }
1249     }
1250     // ... 2) create/update existing
1251     QMap<QString,SALOMEDS::SObject_var>::Iterator it;
1252     for ( it = ucList.begin(); it != ucList.end(); ++it ) {
1253       UpdateUCItem( it.data(), UCSubItem );
1254     }
1255   }
1256 }
1257
1258 /*!
1259   Unhighlights all items
1260 */
1261 void QAD_ObjectBrowser::unHighlightAll()
1262 {
1263   myListView->clearSelection();
1264   myUseCaseView->clearSelection();  
1265 }
1266
1267 /*!
1268   Highlights items which refer to object
1269 */
1270 void QAD_ObjectBrowser::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight )
1271 {
1272   QList<QAD_ObjectBrowserItem> List;
1273   if (getItems(IObject, List)) {
1274     for (int i = 0; i < List.count(); i++) {
1275       List.at(i)->setSelected( highlight );
1276       List.at(i)->repaint();
1277     } 
1278   }
1279 }
1280
1281 /*!
1282   Gets items from Object Browser which refer to object 
1283 */
1284 bool QAD_ObjectBrowser::getItems( const Handle(SALOME_InteractiveObject)& IObject, 
1285                                   QList<QAD_ObjectBrowserItem>& List)
1286 {
1287   List.clear();
1288   if ( myListViewMap.contains( IObject->getEntry() ) ) {
1289     ItemList ilist = myListViewMap[ IObject->getEntry() ];
1290     for ( int i = 0; i < ilist.count(); i++ )
1291       List.append( ilist.at(i) );
1292   }
1293   if ( myUseCaseMap.contains( IObject->getEntry() ) ) {
1294     ItemList ilist = myUseCaseMap[ IObject->getEntry() ];
1295     for ( int i = 0; i < ilist.count(); i++ )
1296       List.append( ilist.at(i) );
1297   }
1298   return (List.count() > 0);
1299 }
1300
1301 /*!
1302   Gets items from Object Browser which refer to object 
1303 */
1304 bool QAD_ObjectBrowser::getItems( SALOMEDS::SObject_ptr SO, 
1305                                   QList<QAD_ObjectBrowserItem>& List)
1306 {
1307   List.clear();
1308   if ( myListViewMap.contains( SO->GetID() ) ) {
1309     ItemList ilist = myListViewMap[ SO->GetID() ];
1310     for ( int i = 0; i < ilist.count(); i++ )
1311       List.append( ilist.at(i) );
1312   }
1313   if ( myUseCaseMap.contains( SO->GetID() ) ) {
1314     ItemList ilist = myUseCaseMap[ SO->GetID() ];
1315     for ( int i = 0; i < ilist.count(); i++ )
1316       List.append( ilist.at(i) );
1317   }
1318   return (List.count() > 0);
1319 }
1320
1321 /*!
1322   Gets first item from Object Browser which refers to object (not reference) 
1323 */
1324 QAD_ObjectBrowserItem* QAD_ObjectBrowser::getItem( const Handle(SALOME_InteractiveObject)& IObject )
1325 {
1326   if ( myListViewMap.contains( IObject->getEntry() ) ) {
1327     ItemList ilist = myListViewMap[ IObject->getEntry() ];
1328     for ( int i = 0; i < ilist.count(); i++ ) {
1329       QString aRef   = ilist.at(i)->getReference();
1330       if ( ilist.at(i)->getReference().isEmpty() )
1331         return ilist.at(i);
1332     }
1333   }
1334   return 0;
1335 }
1336
1337 /*!
1338   Finds item from Object Browser corresponding to Object, returns 0 if fails
1339 */
1340 QAD_ObjectBrowserItem* QAD_ObjectBrowser::getItem( SALOMEDS::SObject_ptr SO )
1341 {
1342   if ( myListViewMap.contains( SO->GetID() ) ) {
1343     ItemList ilist = myListViewMap[ SO->GetID() ];
1344     for ( int i = 0; i < ilist.count(); i++ ) {
1345       QString aRef   = ilist.at(i)->getReference();
1346       if ( ilist.at(i)->getReference().isEmpty() )
1347         return ilist.at(i);
1348     }
1349   }
1350   return 0;
1351 }
1352
1353
1354 /*!
1355   Gets first item from UseCase Browser which refers to object (not reference) 
1356 */
1357 QAD_ObjectBrowserItem* QAD_ObjectBrowser::getUCItem( const Handle(SALOME_InteractiveObject)& IObject )
1358 {
1359   if ( myUseCaseMap.contains( IObject->getEntry() ) ) {
1360     ItemList ilist = myUseCaseMap[ IObject->getEntry() ];
1361     for ( int i = 0; i < ilist.count(); i++ ) {
1362       QString aRef   = ilist.at(i)->getReference();
1363       if ( ilist.at(i)->getReference().isEmpty() )
1364         return ilist.at(i);
1365     }
1366   }
1367   return 0;
1368 }
1369
1370 /*!
1371   Finds item from UseCase Browser corresponding to Object, returns 0 if fails
1372 */
1373 QAD_ObjectBrowserItem* QAD_ObjectBrowser::getUCItem( SALOMEDS::SObject_ptr SO )
1374 {
1375   if ( myUseCaseMap.contains( SO->GetID() ) ) {
1376     ItemList ilist = myUseCaseMap[ SO->GetID() ];
1377     for ( int i = 0; i < ilist.count(); i++ ) {
1378       QString aRef   = ilist.at(i)->getReference();
1379       if ( ilist.at(i)->getReference().isEmpty() )
1380         return ilist.at(i);
1381     }
1382   }
1383   return 0;
1384 }
1385 /*!
1386   Finds item corresponding to interactive object, returns 0 if fails
1387 */
1388 void QAD_ObjectBrowser::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
1389 {
1390   QAD_ObjectBrowserItem* item = getItem( IObject );
1391   if ( item ) {
1392     item->setName( newName );
1393     item->repaint();
1394   }
1395   item = getUCItem( IObject );
1396   if ( item ) {
1397     item->setName( newName );
1398     item->repaint();
1399   }
1400 }
1401
1402 /*!
1403   Creates and show specific Popup to this according to current selection (Object Browser)
1404 */
1405 void QAD_ObjectBrowser::showPopupMenu(QListViewItem* theItem)
1406 {
1407   QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1408   SALOME_Selection*    Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1409   QString       ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1410
1411   if (theItem != NULL && ( Sel->IObjectCount()>0 || ActiveComp.isEmpty() ) ) {
1412
1413     // PAL5618: if IO is presented by several items, assure that the selected IO
1414     // is presented exactly by theItem: difference is in reference
1415     QAD_ObjectBrowserItem *item = (QAD_ObjectBrowserItem *) theItem;
1416     QString theEntry = item->getEntry();
1417     const SALOME_ListIO& SelIO = Sel->StoredIObjects();
1418     for ( SALOME_ListIteratorOfListIO SelIt( SelIO ); SelIt.More(); SelIt.Next() ) {
1419       const Handle(SALOME_InteractiveObject)& IO = SelIt.Value();
1420       if ( strcmp ( IO->getEntry(), theEntry ) == 0 )
1421         IO->setReference( item->getReference() );
1422     }
1423     
1424     createPopup();
1425
1426     if ( myPopup ) {
1427       QAD_Tools::checkPopup( myPopup );
1428       if ( myPopup->count()>0 ) {
1429         myPopup->exec( QCursor::pos() );
1430       }
1431       destroyPopup();
1432     }
1433   }
1434 }
1435
1436 /*!
1437   Creates and show specific Popup to this according to current selection (UseCase Browser)
1438 */
1439 void QAD_ObjectBrowser::showUseCasePopupMenu(QListViewItem* theItem)
1440 {
1441   createPopup();
1442   if ( myPopup ) {
1443     QAD_Tools::checkPopup( myPopup );
1444     if ( myPopup->count() > 0 ) {
1445       myPopup->exec( QCursor::pos() );
1446     }
1447     destroyPopup();
1448   }
1449 }
1450
1451 /*!
1452   Called when current selection was changed (Object Browser)
1453 */
1454 void QAD_ObjectBrowser::onSelectedItem()
1455 {
1456   QListView* whoIs;
1457   if ( sender()->inherits("QListView") )
1458     whoIs = (QListView*)sender();
1459   else
1460     whoIs = myListView;
1461   QAD_Study*   myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1462   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1463   SALOME_Selection*      Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1464   QAD_Application* myApp     = QAD_Application::getDesktop()->getActiveApp();
1465
1466   SALOME_ListIO DeltaPos;
1467   DeltaPos.Clear();
1468   SALOME_ListIO DeltaNeg;
1469   DeltaNeg.Clear();
1470
1471   typedef QMap<QString, SALOME_InteractiveObject*> SelMap;
1472
1473   SelMap currMap, allMap;
1474   for( SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); It.More(); It.Next() )
1475     currMap.insert( It.Value()->getEntry(), It.Value().operator->() );
1476
1477   QListViewItemIterator it( whoIs );
1478   for ( ; it.current(); ++it ) {
1479     QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)it.current();
1480     QString theEntry = item->getEntry();
1481     QString theName  = item->getName();
1482     QString theRef   = item->getReference();
1483
1484     if ( !theEntry.isEmpty() ) {
1485       if ( item->isSelected() ) {
1486         allMap.insert( theEntry, 0 );
1487
1488         if ( !currMap.contains( theEntry ) ) {
1489           Handle(SALOME_InteractiveObject) newIO;
1490           SALOMEDS::SObject_var obj = aStudy->FindObjectID( theEntry.latin1() );
1491           if ( !obj->_is_nil() ) {
1492             SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
1493             if ( !comp->_is_nil() ) {
1494               CORBA::String_var datatype(comp->ComponentDataType());
1495               newIO = new SALOME_InteractiveObject( theEntry.latin1(),
1496                                                     datatype.in(),
1497                                                     theName.latin1() );
1498               newIO->setReference( theRef.latin1() );
1499             }
1500           } else {
1501             newIO = new SALOME_InteractiveObject( theEntry.latin1(),
1502                                                   "",
1503                                                   theName.latin1() );
1504             newIO->setReference( theRef.latin1() );
1505           }
1506           if (!newIO.IsNull()) {
1507             DeltaPos.Append( newIO );
1508           } 
1509         }
1510       } else if ( currMap.contains( theEntry ) )
1511         DeltaNeg.Append( currMap[theEntry] );
1512     }
1513   }
1514
1515   SALOME_ListIteratorOfListIO ItNeg( DeltaNeg );
1516   for(;ItNeg.More();ItNeg.Next()) {
1517     Sel->RemoveIObject( ItNeg.Value() );
1518   }
1519   
1520   SALOME_ListIteratorOfListIO ItPos( DeltaPos );
1521   for(;ItPos.More();ItPos.Next()) {
1522     Sel->AddIObject( ItPos.Value() );
1523   }
1524
1525   for ( SelMap::iterator it = currMap.begin(); it != currMap.end(); ++it ) 
1526     if ( !allMap.contains( it.key() ) )
1527       Sel->RemoveIObject( it.data() );
1528
1529   if ( myApp )
1530     myApp->updateActions();
1531 }
1532
1533 /*!
1534   Called when selection is changed (UseCase Browser)
1535 */
1536 void QAD_ObjectBrowser::onUseCaseSelectedItem()
1537 {
1538 }
1539
1540 /*!
1541   Called when item is expanded
1542 */
1543 void QAD_ObjectBrowser::onExpanded (QListViewItem* item)
1544 {
1545   QAD_ObjectBrowserItem* aItem = (QAD_ObjectBrowserItem*)item;
1546   if (!myStudy->_is_nil() && aItem)
1547   {
1548     SALOMEDS::SObject_var Object = myStudy->FindObjectID(aItem->getEntry());
1549     if (!Object->_is_nil())
1550     {
1551       SALOMEDS::StudyBuilder_var StudyBuilder = myStudy->NewBuilder();
1552       SALOMEDS::AttributeOpened_var  anAttr = SALOMEDS::AttributeOpened::_narrow(
1553                    StudyBuilder->FindOrCreateAttribute(Object, "AttributeOpened") );
1554       anAttr->SetOpened(true);
1555     }
1556   }
1557 }
1558
1559 /*!
1560   Called when item is collapsed
1561 */
1562 void QAD_ObjectBrowser::onCollapsed(QListViewItem* item)
1563 {
1564   QAD_ObjectBrowserItem* aItem = (QAD_ObjectBrowserItem*)item;
1565   if (!myStudy->_is_nil() && aItem)
1566   {
1567     SALOMEDS::SObject_var Object = myStudy->FindObjectID(aItem->getEntry());
1568     if (!Object->_is_nil())
1569     {
1570       SALOMEDS::StudyBuilder_var StudyBuilder = myStudy->NewBuilder();
1571       SALOMEDS::AttributeOpened_var  anAttr = SALOMEDS::AttributeOpened::_narrow(
1572                    StudyBuilder->FindOrCreateAttribute(Object, "AttributeOpened") );
1573       anAttr->SetOpened(false);
1574     }
1575   }
1576 }
1577
1578 /*!
1579   Find and returns value for the object
1580   Warning: object can have several values attributes, search is done in the following order:
1581   [integer], [real], [table of integer], [table of real], [comment]
1582 */
1583 QString QAD_ObjectBrowser::getValueFromObject( SALOMEDS::SObject_ptr SO )
1584 {
1585   if ( SO->_is_nil() )
1586     return QString::null;
1587   SALOMEDS::SComponent_var isComponent = SALOMEDS::SComponent::_narrow( SO );
1588   if ( !isComponent->_is_nil() )
1589     return QString::null; // no values to show for components
1590
1591   SALOMEDS::GenericAttribute_var        anAttr;
1592   SALOMEDS::AttributeInteger_var        anInt;
1593   SALOMEDS::AttributeReal_var           aReal;
1594   SALOMEDS::AttributeTableOfInteger_var aTableInt;
1595   SALOMEDS::AttributeTableOfReal_var    aTableReal;
1596   SALOMEDS::AttributeComment_var        aComment;
1597   CORBA::String_var aString;
1598
1599   // Integer
1600   if ( SO->FindAttribute( anAttr, "AttributeInteger" ) ) {
1601     anInt = SALOMEDS::AttributeInteger::_narrow( anAttr );
1602     QString val = QString::number( anInt->Value() );
1603     return val;
1604   }
1605   // Real
1606   if ( SO->FindAttribute( anAttr, "AttributeReal" ) ) {
1607     aReal = SALOMEDS::AttributeReal::_narrow( anAttr );
1608     QString val = QString::number( aReal->Value() );
1609     return val;
1610   } 
1611   // Table of integer
1612   if ( SO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
1613     aTableInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
1614     aString = aTableInt->GetTitle();
1615     QString tlt( aString.in() );
1616     if ( !tlt.isEmpty() )
1617       tlt += " ";
1618     int nbRows  = aTableInt->GetNbRows() ; 
1619     int nbCols  = aTableInt->GetNbColumns();
1620     QString val = tlt + QString( "[" ) + QString::number( nbRows ) + QString( "," ) + QString::number( nbCols ) + QString( "]" );
1621     return val;
1622   }
1623   // Table of real
1624   if ( SO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
1625     aTableReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
1626     aString = aTableReal->GetTitle();
1627     QString tlt( aString.in() );
1628     if ( !tlt.isEmpty() )
1629       tlt += " ";
1630     int nbRows  = aTableReal->GetNbRows() ; 
1631     int nbCols  = aTableReal->GetNbColumns();
1632     QString val = tlt + QString( "[" ) + QString::number( nbRows ) + QString( "," ) + QString::number( nbCols ) + QString( "]" );
1633     return val;
1634   }
1635   // Comment
1636   if ( SO->FindAttribute(anAttr, "AttributeComment") ) {
1637     aComment = SALOMEDS::AttributeComment::_narrow( anAttr );
1638     aString = aComment->Value();
1639     QString val = QString( aString.in() );
1640     return val;
1641   }
1642   return QString::null;
1643 }
1644
1645 /*!
1646   Shows/hides IAPP sub-tree in ObjectBrowser
1647   Current implementation just udpates browser
1648 */
1649 void QAD_ObjectBrowser::setShowIAPP( bool show )
1650 {
1651   Update();
1652 }
1653
1654 /*!
1655   Shows/hides info columns: Entry, IOR, Reference
1656 */
1657 void QAD_ObjectBrowser::setShowInfoColumns( bool show )
1658 {
1659   bool shown = myListView->header()->isResizeEnabled( 2 );
1660   
1661   if ( show != shown ) {
1662     if ( show ) {
1663       myListView->header()->setResizeEnabled( true, 2 );
1664       myListView->header()->setResizeEnabled( true, 3 );
1665       myListView->header()->setResizeEnabled( true, 4 );
1666       myListView->setColumnWidthMode( 2, QListView::Maximum );
1667       myListView->setColumnWidthMode( 3, QListView::Maximum );
1668       myListView->setColumnWidthMode( 4, QListView::Maximum );
1669       if ( myListView->columnWidth( 2 ) <= 0 )
1670         myListView->header()->resizeSection( 2, 50 );
1671       if ( myListView->columnWidth( 3 ) <= 0 )
1672         myListView->header()->resizeSection( 3, 50 );
1673       if ( myListView->columnWidth( 4 ) <= 0 )
1674         myListView->header()->resizeSection( 4, 50 );
1675     }
1676     else {
1677       myListView->setColumnWidthMode( 2, QListView::Manual );
1678       myListView->setColumnWidthMode( 3, QListView::Manual );
1679       myListView->setColumnWidthMode( 4, QListView::Manual );
1680       myListView->header()->resizeSection( 2, 0 );
1681       myListView->header()->resizeSection( 3, 0 );
1682       myListView->header()->resizeSection( 4, 0 );
1683       myListView->header()->setResizeEnabled( false, 2 );
1684       myListView->header()->setResizeEnabled( false, 3 );
1685       myListView->header()->setResizeEnabled( false, 4 );
1686     }
1687   }
1688 }
1689
1690 /*!
1691   Shows/hides Value column
1692 */
1693 void QAD_ObjectBrowser::setShowValueColumn( bool show )
1694 {
1695   bool shown = myListView->header()->isResizeEnabled( 1 );
1696   
1697   if ( show != shown ) {
1698     if ( show ) {
1699       myListView->header()->setResizeEnabled( true, 1 );
1700       myListView->setColumnWidthMode( 1, QListView::Maximum );
1701       if ( myListView->columnWidth( 1 ) <= 0 )
1702         myListView->header()->resizeSection( 1, 50 );
1703     }
1704     else {
1705       myListView->setColumnWidthMode( 1, QListView::Manual );
1706       myListView->header()->resizeSection( 1, 0 );
1707       myListView->header()->setResizeEnabled( false, 1 );
1708     }
1709   }
1710 }
1711
1712 /*!
1713   Sets CHRONO sorting enabled/disabled
1714   Note: when CHRONO sorting is enabled items are sorted by Entry value and column headers 
1715         become unclickable to prohibit another sort type;
1716         when CHRONO sorting is disabled column headers become clickable - this allows
1717         to sort data by any column
1718 */
1719 void QAD_ObjectBrowser::setEnableChronoSort( bool enable )
1720 {
1721   if ( enable ) {
1722     // if CHRONO sorting is enabled set clickable header disabled ...
1723     myListView->header()->setClickEnabled( false );
1724     // ... and then sort by column 2 - OCAF doc entry
1725     myListView->setSorting( 2, TRUE ) ;
1726   }
1727   else {
1728     // if CHRONO sorting is enabled set clickable header enabled ...
1729     myListView->header()->setClickEnabled( true );
1730     // and clear sorting by column 2
1731     myListView->setSorting( 10, TRUE );
1732   }
1733 //  myListView->sort( ) ;  
1734 }
1735
1736 /*!
1737   Slot, called to edit value
1738 */
1739 void QAD_ObjectBrowser::onEditAttribute()
1740 {
1741   QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1742   SALOME_Selection*    Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1743   QString       ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1744   if ( myStudy->_is_nil() )
1745     return;
1746
1747   if ( Sel->IObjectCount() == 1 ) {
1748     SALOMEDS::SObject_var SO = myStudy->FindObjectID( Sel->firstIObject()->getEntry() );
1749     SALOMEDS::SComponent_var isComponent = SALOMEDS::SComponent::_narrow( SO );
1750     if ( !SO->_is_nil() && isComponent->_is_nil() ) { // no values to show for components
1751       SALOMEDS::GenericAttribute_var        anAttr;
1752       SALOMEDS::AttributeInteger_var        anInt;
1753       SALOMEDS::AttributeReal_var           aReal;
1754       SALOMEDS::AttributeTableOfInteger_var aTableInt;
1755       SALOMEDS::AttributeTableOfReal_var    aTableReal;
1756       SALOMEDS::AttributeComment_var        aComment;
1757       bool bOk = false;
1758         
1759       // if Integer
1760       if ( SO->FindAttribute( anAttr, "AttributeInteger" ) ) {
1761         anInt = SALOMEDS::AttributeInteger::_narrow( anAttr );
1762         int val = SALOMEGUI_SetValueDlg::getInteger( tr( "SET_VALUE_INT_TLT" ),
1763                                                      tr( "SET_VALUE_INT_LBL" ),
1764                                                      anInt->Value(),
1765                                                      &bOk,
1766                                                      QAD_Application::getDesktop() );
1767         if ( bOk ) {
1768           anInt->SetValue( val );
1769         }
1770       }
1771       // if Real
1772       else 
1773       if ( SO->FindAttribute( anAttr, "AttributeReal" ) ) {
1774         aReal = SALOMEDS::AttributeReal::_narrow( anAttr );
1775         double val = SALOMEGUI_SetValueDlg::getDouble( tr( "SET_VALUE_REAL_TLT" ),
1776                                                        tr( "SET_VALUE_REAL_LBL" ),
1777                                                        aReal->Value(),
1778                                                        &bOk,
1779                                                        QAD_Application::getDesktop() );
1780         if ( bOk ) {
1781           aReal->SetValue( val );
1782         }
1783       }
1784       // if Table of integer
1785       else
1786       if ( SO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
1787         SALOMEGUI_TableDlg* dlg = new SALOMEGUI_TableDlg( QAD_Application::getDesktop(),
1788                                                           SO, 
1789                                                           true, 
1790                                                           SALOMEGUI_TableDlg::ttInt );
1791         bOk = ( dlg->exec() == QDialog::Accepted );
1792       }
1793       // if Table of real
1794       else
1795       if ( SO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
1796         SALOMEGUI_TableDlg* dlg = new SALOMEGUI_TableDlg( QAD_Application::getDesktop(),
1797                                                           SO, 
1798                                                           true, 
1799                                                           SALOMEGUI_TableDlg::ttReal );
1800         bOk = ( dlg->exec() == QDialog::Accepted );
1801       }
1802       // if Comment
1803       else
1804       if ( SO->FindAttribute(anAttr, "AttributeComment") ) {
1805         aComment = SALOMEDS::AttributeComment::_narrow( anAttr );
1806         QString val = SALOMEGUI_SetValueDlg::getString( tr( "SET_VALUE_COMMENT_TLT" ),
1807                                                         tr( "SET_VALUE_COMMENT_LBL" ),
1808                                                         aComment->Value(),
1809                                                         &bOk,
1810                                                         QAD_Application::getDesktop() );
1811         if ( bOk ) {
1812           aComment->SetValue( val );
1813         }
1814       }
1815       if ( bOk ) {
1816         Update();
1817       }
1818     }
1819   }
1820 }
1821
1822 /*!
1823   Returns true if object has editable attrubute : 
1824   integer, real, table or comment
1825 */
1826 bool QAD_ObjectBrowser::hasEditableAttribute( const Handle(SALOME_InteractiveObject)& object )
1827 {
1828   if ( !myStudy->_is_nil() ) {
1829     SALOMEDS::SObject_var obj  = myStudy->FindObjectID( object->getEntry() );
1830     SALOMEDS::SComponent_var comp = myStudy->FindComponentID( object->getEntry() );
1831     if ( !comp->_is_nil() || obj->_is_nil() )
1832       return false;
1833     QString val = getValueFromObject( obj );
1834     return ( !val.isNull() );
1835   }
1836   return false;
1837 }
1838
1839 /*!
1840   Returns true if object has table attrubute ( integer and/or real )
1841 */
1842 bool QAD_ObjectBrowser::hasTable( const Handle(SALOME_InteractiveObject)& object )
1843 {
1844   SALOMEDS::GenericAttribute_var anAttr;
1845   if ( !myStudy->_is_nil() ) {
1846     SALOMEDS::SObject_var obj  = myStudy->FindObjectID( object->getEntry() );
1847     SALOMEDS::SComponent_var comp = myStudy->FindComponentID( object->getEntry() );
1848     if ( !comp->_is_nil() || obj->_is_nil() )
1849       return false;
1850     if ( obj->FindAttribute( anAttr, "AttributeTableOfInteger" ) )
1851       return true;
1852     if ( obj->FindAttribute( anAttr, "AttributeTableOfReal" ) )
1853       return true;
1854   }
1855   return false;
1856 }
1857
1858 /*!
1859   Slot, called when one of the UseCase Browser menu command is called
1860 */
1861 void QAD_ObjectBrowser::onUseCasePopupMenu( int action )
1862 {
1863   if ( myStudy->_is_nil() )
1864     return;
1865   
1866   // Check if the study is locked
1867   QAD_Desktop* Desktop     = (QAD_Desktop*) QAD_Application::getDesktop();
1868   QAD_Study* myActiveStudy = Desktop->getActiveStudy();
1869   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1870   if ( aStudy->GetProperties()->IsLocked() )
1871     {
1872       QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
1873                               QObject::tr("WRN_WARNING"), 
1874                               QObject::tr("WRN_STUDY_LOCKED"),
1875                               QObject::tr("BUT_OK") );
1876       return;
1877     }
1878
1879   SALOME_Selection* Sel    = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1880   SALOMEDS::UseCaseBuilder_var UCBuilder = myStudy->GetUseCaseBuilder();
1881   SALOMEDS::SObject_var Current = UCBuilder->GetCurrentObject();
1882   CORBA::String_var aString;
1883
1884   QList<QListViewItem> ucSelected; 
1885   ucSelected.setAutoDelete( false );
1886   getSelectedParents( myUseCaseView, ucSelected );
1887
1888   if ( action == UC_NEW_EMPTY_ID ) {
1889     if ( ucSelected.count() == 1 ) {
1890       if ( isRootItem( ucSelected.at(0) ) )
1891         UCBuilder->SetRootCurrent();
1892       else
1893         UCBuilder->SetCurrentObject( myStudy->FindObjectID( (( QAD_ObjectBrowserItem* )( ucSelected.at(0) ))->getEntry() ) );
1894       UCBuilder->AddUseCase( tr( "NEW_OBJECT" ) ); 
1895       myActiveStudy->updateUseCaseBrowser();
1896     }
1897   }
1898   else
1899   if ( action == UC_SET_CURRENT_ID ) {
1900     if ( ucSelected.count() > 0 ) {
1901       if ( isRootItem( ucSelected.at(0) ) )
1902         UCBuilder->SetRootCurrent();
1903       else
1904         UCBuilder->SetCurrentObject( myStudy->FindObjectID( (( QAD_ObjectBrowserItem* )( ucSelected.at(0) ))->getEntry() ) );
1905     }
1906     myActiveStudy->updateUseCaseBrowser( );
1907   }
1908   else
1909   if ( action == UC_RENAME_ID ) {
1910     if ( ucSelected.count() == 1 ) {
1911       QAD_ObjectBrowserItem* useCaseItem = ( QAD_ObjectBrowserItem* )( ucSelected.at( 0 ) );
1912       aString = UCBuilder->GetName();
1913       if ( isRootItem( useCaseItem ) ) {
1914         QString name = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), aString.in() );
1915         if ( !name.isEmpty() ) {
1916           UCBuilder->SetName( name.latin1() );
1917           myActiveStudy->updateUseCaseBrowser( );
1918         }
1919       }
1920       else/* if ( UCBuilder->IsUseCase( myStudy->FindObjectID( (( QAD_ObjectBrowserItem* )( ucSelected.at(0) ))->getEntry() ) ) )*/ {
1921         QString name = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), aString.in() );
1922         if ( !name.isEmpty() ) {
1923           myActiveStudy->renameIObject( Sel->firstIObject(), name );
1924         }
1925       }
1926     }
1927   }
1928   else 
1929   if ( action == UC_APPEND_ID ) {
1930     if ( Sel->IObjectCount() > 0 ) {
1931       SALOME_ListIO SelIO; SelIO = Sel->StoredIObjects();
1932       SALOME_ListIteratorOfListIO SelIt( SelIO );
1933       for( ; SelIt.More(); SelIt.Next() ) {
1934         SALOMEDS::SObject_var selSO = myStudy->FindObjectID( SelIt.Value()->getEntry() );
1935         if ( !selSO->_is_nil() && strcmp( SelIt.Value()->getEntry(), ( "0:2" ) ) != 0 ) {
1936           UCBuilder->Remove( selSO );  // first remove object for sure ...
1937           UCBuilder->Append( selSO );  // ... and now re-append it
1938         }
1939       }
1940       myActiveStudy->updateUseCaseBrowser( true );
1941     }
1942   }
1943   else 
1944   if ( action == UC_REMOVE_ID ) {
1945     ucSelected.clear();
1946     getSelectedParents( myUseCaseView, ucSelected, true );
1947     for ( int i = 0; i < ucSelected.count(); i++ ) {
1948       QAD_ObjectBrowserItem* item = ( QAD_ObjectBrowserItem* )ucSelected.at( i );
1949       if ( !isRootItem( item ) ) {
1950         // SObject selected
1951         SALOMEDS::SObject_var SO = myStudy->FindObjectID( item->getEntry() );
1952         if ( !SO->_is_nil() ) {
1953           UCBuilder->Remove( SO );
1954         }
1955       }
1956       else {
1957       }
1958     }
1959     Sel->ClearIObjects();
1960     myActiveStudy->updateUseCaseBrowser( true );
1961   }
1962   else 
1963   if ( action == UC_CLEAR_ID ) {
1964     if ( myUseCaseView->childCount() > 0 && myUseCaseView->firstChild()->childCount() > 0) {
1965       QAD_ObjectBrowserItem* child = ( QAD_ObjectBrowserItem* )myUseCaseView->firstChild()->firstChild();
1966       while ( child ) {
1967         UCBuilder->Remove( myStudy->FindObjectID( child->getEntry().latin1() ) );
1968         child = ( QAD_ObjectBrowserItem* )( child->nextSibling() );
1969       }
1970       Sel->ClearIObjects();
1971       myActiveStudy->updateUseCaseBrowser();
1972     }
1973   }
1974 }
1975 /*!
1976   Use Case browser buttons slot
1977 */
1978 void QAD_ObjectBrowser::onUseCaseBtn()
1979 {
1980   // Check if the study is locked
1981   QAD_Desktop* Desktop     = (QAD_Desktop*) QAD_Application::getDesktop();
1982   QAD_Study* myActiveStudy = Desktop->getActiveStudy();
1983   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1984   if ( aStudy->GetProperties()->IsLocked() )
1985     {
1986       QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
1987                               QObject::tr("WRN_WARNING"), 
1988                               QObject::tr("WRN_STUDY_LOCKED"),
1989                               QObject::tr("BUT_OK") );
1990       return;
1991     }
1992   
1993   if ( sender() == myNewBtn ) {
1994     SALOMEDS::UseCaseBuilder_var UCBuilder = myStudy->GetUseCaseBuilder();
1995     UCBuilder->AddUseCase( tr( "NEW_OBJECT" ) ); 
1996     myActiveStudy->updateUseCaseBrowser();
1997   }
1998   if ( sender() == myAddBtn )
1999     onUseCasePopupMenu( UC_APPEND_ID );
2000   if ( sender() == myDelBtn )
2001     onUseCasePopupMenu( UC_REMOVE_ID );
2002   if ( sender() == myClearBtn )
2003     onUseCasePopupMenu( UC_CLEAR_ID );
2004   if ( sender() == myCurrentBtn )
2005     onUseCasePopupMenu( UC_SET_CURRENT_ID );
2006 }
2007
2008 /* 
2009    Show/remove UseCase Browser 
2010 */
2011
2012 void QAD_ObjectBrowser::showUseCaseBrowser ( bool show )
2013 {
2014   bool shown = (this->count() > 1);
2015   
2016   if (show != shown)
2017     {
2018       if (show)
2019         {
2020           this->addTab( myVBox, tr( "TLT_USECASE_BROWSER" ) );
2021           UpdateUseCaseBrowser();
2022           unHighlightAll();
2023         }
2024       else
2025         this->removePage(myVBox);
2026     }
2027 }
2028
2029 /*!
2030   Switch between auto resizing of columns and manual mode
2031 */
2032 void QAD_ObjectBrowser::autoSizeColumns( bool autosize )
2033 {
2034   if (autosize)
2035     {
2036       for (int i = 0; i < myListView->header()->count(); i++ )
2037         if (myListView->header()->isResizeEnabled(i))
2038           myListView->setColumnWidthMode(i, QListView::Maximum);
2039       
2040     }
2041   else
2042     {
2043       for (int i = 0; i < myListView->header()->count(); i++ )
2044         myListView->setColumnWidthMode(i, QListView::Manual); 
2045     }
2046 }