1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : QAD_ObjectBrowser.cxx
25 // Author : Nicolas REJNERI
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"
47 #include <qlistview.h>
49 #include <qpopupmenu.h>
50 #include <qtabwidget.h>
51 #include <qpushbutton.h>
56 #include <qdragobject.h>
57 #include <qstringlist.h>
62 //VRV: porting on Qt 3.0.5
63 #if QT_VERSION >= 0x030005
66 //VRV: porting on Qt 3.0.5
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
80 static int MYDEBUG = 0;
82 static int MYDEBUG = 0;
87 Small button which updates Object Browser's contents
89 Btn::Btn ( QWidget * parent, const char * name ) : QToolButton( parent, name )
91 connect( this, SIGNAL(clicked()), this, SLOT(onClicked()) );
95 QAD_ObjectBrowser* OB = QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
100 Gets selected top-level items (i.e. not including sub-items) [ static ]
102 static void getSelectedParents( QListViewItem* listViewItem, QList<QListViewItem>& itemList )
104 QListViewItem* item = listViewItem->firstChild();
106 if ( item->isSelected() ) {
107 itemList.append( item );
110 getSelectedParents( item, itemList );
112 item = item->nextSibling();
116 Gets selected top-level items (i.e. not including sub-items) [ static ]
118 static void getSelectedParents( QListView* listView, QList<QListViewItem>& itemList, bool ignoreRoot = false )
121 QListViewItem* item = listView->firstChild();
123 if ( item->isSelected() && !ignoreRoot ) {
124 itemList.append( item );
127 getSelectedParents( item, itemList );
129 item = item->nextSibling();
133 Gets top-most parent item [ static ]
135 static QListViewItem* getTopParent( QListViewItem* item )
139 QListViewItem* p = item->parent();
142 while ( p->parent() ) {
148 Returns true if the item is top-level (root)
150 static bool isRootItem( QListViewItem* item )
152 return ( item->listView() && !item->parent() );
157 QAD_ObjectBrowser::QAD_ObjectBrowser( SALOMEDS::Study_var study, QWidget* parent, const char* name, WFlags fl )
158 : QTabWidget( parent, name, fl )
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
171 QAD_ObjectBrowser::~QAD_ObjectBrowser()
173 if (!myStudy->_is_nil())
174 CORBA::release(myStudy);
178 Configures Object Browser and UseCase Browser.
179 Columns, Selection Mode and Palette.
181 void QAD_ObjectBrowser::setupListView()
183 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
185 this->setTabPosition( QTabWidget::Bottom );
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" );
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 ) );
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 );
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 ); /* ... */
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* ) ) );
223 connect( myListView, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
224 this, SLOT( showPopupMenu( QListViewItem* ) ) );
226 //VRV: porting on Qt 3.0.5
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* ) ) );
235 /* create and setup UseCase Browser ================================ */
236 myVBox = new QWidget( this );
237 QVBoxLayout* vBoxLayout = new QVBoxLayout( myVBox );
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 ) );
244 /* First column = object name */
245 myUseCaseView->addColumn( tr( "OBJECT_BROWSER_OBJECT" ) );
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 );
260 myUseCaseView->setCornerWidget( new Btn( this ) );
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" ) );
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();
301 vBoxLayout->addLayout( btnLayout );
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() ) );
309 /* Connect section */
310 #if QT_VERSION < 0x030005
311 connect( myUseCaseView, SIGNAL( rightButtonClicked( QListViewItem*, const QPoint&, int ) ),
312 this, SLOT( showPopupMenu( QListViewItem* ) ) );
314 connect( myUseCaseView, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
315 this, SLOT( showPopupMenu( QListViewItem* ) ) );
318 connect( myUseCaseView, SIGNAL( selectionChanged() ),
319 this, SLOT( onSelectedItem() ) );
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" ) );
325 if ( showUseCase != "true")
326 this->removePage(myVBox);
328 setShowInfoColumns( AddColumn == "true" );
329 setShowValueColumn( ValueColumn == "true" );
330 setEnableChronoSort( ShowCHRONO_SORT == "true" );
332 if ( noAutoSizeColumns == "true" )
334 for (int i = 0; i < myListView->header()->count(); i++ )
335 myListView->setColumnWidthMode(i, QListView::Manual);
338 resize( QSize( 100, 400 ) );
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.
346 static bool dragged = false;
347 static QStringList draggedlist;
348 bool QAD_ObjectBrowser::eventFilter( QObject* o, QEvent* e )
350 QAD_Desktop* Desktop = (QAD_Desktop*) QAD_Application::getDesktop();
351 QAD_Study* myActiveStudy = Desktop->getActiveStudy();
353 if ( myStudy->_is_nil() )
354 return QTabWidget::eventFilter( o, e );
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 );
371 for ( ; it.current(); ++it ) {
372 QAD_ObjectBrowserItem* selItem = ( QAD_ObjectBrowserItem* )( it.current() );
373 if ( selItem->isSelected() ) {
374 if ( isRootItem( selItem ) ) {
379 entryList.append( selItem->getEntry() );
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() );
394 else if ( e->type() == QEvent::MouseMove ) {
395 // vsr 03/03/05 - start dragging only if mouse starts moving
397 if ( !draggedlist.isEmpty() ) {
398 QTextDrag *d = new QTextDrag( draggedlist.join("*"), myUseCaseView->viewport() );
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;
412 QAD_ObjectBrowserItem* item = ( QAD_ObjectBrowserItem* )( myUseCaseView->itemAt( me->pos() ) );
413 myUseCaseView->clearSelection();
414 myUseCaseView->setSelected( item, true );
415 myUseCaseView->setCurrentItem( item );
418 else if ( e->type() == QEvent::DragMove ) {
419 QDragMoveEvent* dme = ( QDragMoveEvent* )e;
420 if ( dme->source() == myUseCaseView->viewport() ) {
428 else if ( e->type() == QEvent::Drop ) {
429 QDropEvent* de = ( QDropEvent* )e;
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 );
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 );
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 );
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 );
466 myActiveStudy->updateUseCaseBrowser();
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 );
487 return QTabWidget::eventFilter( o, e );
492 Returns true if item is collapsed has collapsed children
494 static bool hasCollapsed( QListViewItem* item )
499 bool res = ( item->childCount() && !item->isOpen() );
500 for ( QListViewItem* child = item->firstChild(); !res && child; child = child->nextSibling() )
501 res = hasCollapsed( child );
507 Expands item and all its children
509 static void expand(QListViewItem* item)
514 item->setOpen( true );
516 for ( QListViewItem* child = item->firstChild(); child; child = child->nextSibling() )
523 void QAD_ObjectBrowser::onCreatePopup()
525 QAD_Desktop* Desktop = (QAD_Desktop*) QAD_Application::getDesktop();
526 QAD_Study* myActiveStudy = Desktop->getActiveStudy();
527 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
529 bool canExpand = false;
530 /* VSR : Creation of common POPUP menu for Object Browser/Use Case Browser */
531 if ( Sel->IObjectCount() > 0 ) {
536 Desktop->definePopup( theContext, theParent, theObject );
538 Desktop->createPopup( myPopup, theContext, "ObjectBrowser", theObject);
539 if ( !Desktop->getActiveComponent().isEmpty() ) {
540 Desktop->customPopup( myPopup, theContext, "ObjectBrowser", theObject );
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" ),
549 SLOT( onEditAttribute() ) );
552 for ( QListViewItemIterator it( currentPage() == myListView ? myListView : myUseCaseView ); it.current() && !canExpand; ++it )
553 canExpand = canExpand || ( it.current()->isSelected() && hasCollapsed( it.current() ) );
556 if ( myPopup->count() > 0 )
557 myPopup->insertSeparator();
558 myPopup->insertItem( tr( "EXPAND_ALL_CMD" ),
560 SLOT( onExpandAll() ) );
565 // No selected item => it's not necessary to create popup
566 //NRI- : Desktop->createPopup( myPopup, "", "ObjectBrowser", "");
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 );
574 if ( myPopup && !myStudy->_is_nil() ) {
575 SALOMEDS::UseCaseBuilder_var UCBuilder = myStudy->GetUseCaseBuilder();
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() ) ) );
586 myPopup->insertItem( tr( "EXPAND_ALL_CMD" ),
588 SLOT( onExpandAll() ) );
591 QPopupMenu *UseCasePopup = new QPopupMenu( myPopup );
593 UseCasePopup->insertItem( tr( "UC_NEW_ID" ), this, SLOT( onUseCasePopupMenu( int ) ), 0, UC_NEW_EMPTY_ID );
595 UseCasePopup->insertItem( tr( "UC_SET_CURRENT_ID" ), this, SLOT( onUseCasePopupMenu( int ) ), 0, UC_SET_CURRENT_ID );
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 );
601 if ( UseCasePopup->count() > 0 ) {
602 if ( myPopup->count() > 0 )
603 myPopup->insertSeparator();
604 myPopup->insertItem( tr( "UC_POPUP" ), UseCasePopup );
614 Called on "Expand all" popup menu command
616 void QAD_ObjectBrowser::onExpandAll()
618 for ( QListViewItemIterator it( currentPage() == myListView ? myListView : myUseCaseView ); it.current(); ++it )
619 if ( it.current()->isSelected() )
620 expand( it.current() );
624 Returns Object Browser list view
626 QListView* QAD_ObjectBrowser::getListView() const
632 Returns UseCase Browser list view
634 QListView* QAD_ObjectBrowser::getUseCaseView() const
636 return myUseCaseView;
640 Adds anItem ( probably a SComponent )
642 QAD_ObjectBrowserItem* QAD_ObjectBrowser::AddItem(QListView* theView,
643 const QString& theName,
644 const QString& theEntry,
645 const QString& theIOR,
647 const QString& theValue,
648 QAD_ObjectBrowserItem* theAfter)
651 QAD_ObjectBrowserItem* last = (QAD_ObjectBrowserItem*)(theView->firstChild());
655 for ( ; last->nextSibling(); last = (QAD_ObjectBrowserItem*)(last->nextSibling()) );
657 QAD_ObjectBrowserItem* anItem = new QAD_ObjectBrowserItem( theView, last );
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( "" );
671 Adds anItem ( probably a StudyObject )
673 QAD_ObjectBrowserItem* QAD_ObjectBrowser::AddItem(QAD_ObjectBrowserItem* theParentItem,
674 const QString& theName,
675 const QString& theEntry,
676 const QString& theIOR,
678 const QString& theRef,
679 const QString& theValue,
680 QAD_ObjectBrowserItem* theAfter)
683 QAD_ObjectBrowserItem* last = (QAD_ObjectBrowserItem*)(theParentItem->firstChild());
687 for ( ; last->nextSibling(); last = (QAD_ObjectBrowserItem*)(last->nextSibling()) );
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 );
702 Updates Object Browsers' item [ protected ]
704 void QAD_ObjectBrowser::Update( SALOMEDS::SObject_ptr SO,
705 QAD_ObjectBrowserItem* theParentItem )
707 if ( myStudy->_is_nil() || SO->_is_nil() || !theParentItem ) {
710 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(SO);
712 for (; it->More();it->Next()) {
713 SALOMEDS::SObject_var CSO = it->Value();
714 SALOMEDS::SObject_var RefSO;
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;
731 QAD_ObjectBrowserItem* Item = 0;
734 if ( CSO->ReferencedObject(RefSO) && !RefSO->_is_nil() ) {
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();
745 valueString = getValueFromObject( RefSO );
746 aString = aName->Value();
747 Item = AddItem(theParentItem,
748 QString(" * ") + aString.in(),
754 myListViewMap[ RefSOEntry ].append( Item );
757 if(MYDEBUG) MESSAGE("QAD_ObjectBrowser::Update : noname item: "<<CSO->GetID());
761 valueString = getValueFromObject( CSO );
763 if (CSO->FindAttribute(anAttr, "AttributeIOR")) {
764 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
765 aString = anIOR->Value();
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 );
776 if(MYDEBUG) MESSAGE("QAD_ObjectBrowser::Update : noname item: "<<CSO->GetID());
778 // adding other attributes
781 if ( CSO->FindAttribute(anAttr, "AttributeSelectable") ) {
782 aSelectable = SALOMEDS::AttributeSelectable::_narrow(anAttr);
783 Item->setSelectable(aSelectable->IsSelectable());
786 if ( CSO->FindAttribute(anAttr, "AttributeExpandable") ) {
787 anExpandable = SALOMEDS::AttributeExpandable::_narrow(anAttr);
788 Item->setExpandable(anExpandable->IsExpandable());
791 if ( CSO->FindAttribute(anAttr, "AttributeOpened") ) {
792 anOpened = SALOMEDS::AttributeOpened::_narrow(anAttr);
793 Item->setOpen(anOpened->IsOpened());
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);
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);
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);
819 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
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 );
835 // if ( theParentItem->isOpen() )
836 // Item->setOpen(TRUE);
844 Updates Object Browser tree and UseCase Browser tree
846 void QAD_ObjectBrowser::Update()
848 int xc = myListView->contentsX();
849 int yc = myListView->contentsY();
850 myListView->viewport()->setUpdatesEnabled( false );
853 myListViewMap.clear();
855 if ( myStudy->_is_nil() ) {
859 QString ShowIAPP = QAD_CONFIG->getSetting("ObjectBrowser:IAPP");
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();
869 aString = SC->GetID();
870 QString SCEntry = aString.in();
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;
885 if (SC->FindAttribute(anAttr, "AttributeIOR")) {
886 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
887 aString = anIOR->Value();
891 bool caseIAPP = false;
893 // create data-tree item, corresponding to component (and set name if component has it)
894 if ( dataType.compare("Interface Applicative") == 0 ) {
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 );
904 Item = AddItem (myListView, dataType, SCEntry, ior, 1, "");
905 myListViewMap[ SCEntry ].append( Item );
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 );
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, "");
926 // add other attributes
929 if ( SC->FindAttribute(anAttr, "AttributeSelectable") ) {
930 aSelectable = SALOMEDS::AttributeSelectable::_narrow(anAttr);
931 Item->setSelectable(aSelectable->IsSelectable());
934 if ( SC->FindAttribute(anAttr, "AttributeExpandable") ) {
935 anExpandable = SALOMEDS::AttributeExpandable::_narrow(anAttr);
936 Item->setExpandable(anExpandable->IsExpandable());
939 if ( SC->FindAttribute(anAttr, "AttributeOpened") ) {
940 anOpened = SALOMEDS::AttributeOpened::_narrow(anAttr);
941 Item->setOpen(anOpened->IsOpened());
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);
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);
959 if ( SC->FindAttribute(anAttr, "AttributePixMap") ) {
960 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
961 if ( aPixmap->HasPixMap() ) {
963 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
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 );
976 if ( strcmp(dataType, TypeComponent) == 0 )
979 if ( caseIAPP && ShowIAPP.compare("true") == 0 )
986 myListView->setContentsPos(xc,yc);
988 myListView->viewport()->setUpdatesEnabled( true );
989 myListView->viewport()->repaint( false );
990 /* Updating UseCase Browser ============================================= */
991 if ( this->count() > 1 )
992 UpdateUseCaseBrowser();
996 Removes item with all childs from the map - used to optimize UseCase browser update
998 void removeFromMap( ItemMap& theMap, QAD_ObjectBrowserItem* item )
1001 QAD_ObjectBrowserItem* subItem = ( QAD_ObjectBrowserItem* )( item->firstChild() );
1003 removeFromMap( theMap, subItem );
1004 subItem = ( QAD_ObjectBrowserItem* )( subItem->nextSibling() );
1006 if ( theMap.contains( item->getEntry() ) ) {
1007 theMap[ item->getEntry() ].removeRef( item );
1008 if ( theMap[ item->getEntry() ].isEmpty() ) {
1009 theMap.remove( item->getEntry() );
1016 Updates only UseCase Browser
1018 void QAD_ObjectBrowser::UpdateUseCaseBrowser() {
1019 // myUseCaseView->clear(); myUseCaseMap.clear();
1020 if ( myStudy->_is_nil() || this->count()<2 ) {
1023 myUseCaseView->blockSignals( true );
1024 // myUseCaseView->setUpdatesEnabled( false );
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
1035 root = AddItem( myUseCaseView, UCName, "0:2", "", 1, "" );
1036 myUseCaseMap[ "0:2" ].append( root );
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;
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 );
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 );
1071 myUseCaseView->blockSignals( false );
1072 // myUseCaseView->setUpdatesEnabled( true );
1073 // myUseCaseView->update();
1074 // UCItem->setOpen( true );
1078 Updates UseCase Browser's item
1080 void QAD_ObjectBrowser::UpdateUCItem( SALOMEDS::SObject_var UCObject, QAD_ObjectBrowserItem* UCItem )
1082 if ( myStudy->_is_nil() || !UCItem )
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 )
1092 // --- VSR: 01/02/05 --- finish
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;
1106 CORBA::String_var aString = UCObject->GetID();
1107 QString UCEntry = aString.in();
1109 SALOMEDS::UseCaseBuilder_var UCBuilder = myStudy->GetUseCaseBuilder();
1110 SALOMEDS::SObject_var SOCurrent = UCBuilder->GetCurrentObject();
1111 bool isUseCase = UCBuilder->IsUseCase( UCObject );
1113 QAD_ObjectBrowserItem* UCSubItem = 0;
1114 if ( myUseCaseMap.contains( UCEntry ) && myUseCaseMap[ UCEntry ].count() > 0 )
1115 UCSubItem = myUseCaseMap[ UCEntry ].first();
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();
1127 valueString = getValueFromObject( RefSO );
1128 aString = aName->Value();
1130 UCSubItem = AddItem( UCItem,
1131 QString( " * " ) + aString.in(),
1137 myUseCaseMap[ RefSOEntry ].append( UCSubItem );
1140 UCSubItem->setName( QString( " * " ) + aString.in() );
1141 UCSubItem->setEntry( RefSOEntry );
1142 UCSubItem->setIOR( ior );
1143 UCSubItem->setReference( UCEntry );
1144 UCSubItem->setValue( valueString );
1146 UCSubItem->setCurrent( !SOCurrent->_is_nil() && QString( SOCurrent->GetID() ) == QString( UCEntry ) );
1151 valueString = getValueFromObject( UCObject );
1153 if ( UCObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
1154 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
1155 aString = anIOR->Value();
1158 // getting Name and adding new Item
1159 if ( UCObject->FindAttribute( anAttr, "AttributeName" ) ) {
1160 aName = SALOMEDS::AttributeName::_narrow( anAttr );
1161 aString = aName->Value();
1163 UCSubItem = AddItem( UCItem, aString.in(), UCEntry, ior, isUseCase ? 1 : 0, "", valueString );
1164 myUseCaseMap[ UCEntry ].append( UCSubItem );
1167 UCSubItem->setName( aString.in() );
1168 UCSubItem->setEntry( UCEntry );
1169 UCSubItem->setIOR( ior );
1170 UCSubItem->setReference( "" );
1171 UCSubItem->setValue( valueString );
1174 // adding other attributes
1176 UCSubItem->setCurrent( !SOCurrent->_is_nil() && QString( SOCurrent->GetID() ) == QString( UCEntry ) );
1178 // if ( UCObject->FindAttribute( anAttr, "AttributeSelectable" ) ) {
1179 // aSelectable = SALOMEDS::AttributeSelectable::_narrow( anAttr );
1180 // UCSubItem->setSelectable( aSelectable->IsSelectable() );
1183 // if ( UCObject->FindAttribute( anAttr, "AttributeExpandable" ) ) {
1184 // anExpandable = SALOMEDS::AttributeExpandable::_narrow( anAttr );
1185 // UCSubItem->setExpandable( anExpandable->IsExpandable() );
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 );
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 );
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();
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 );
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;
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 );
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 );
1259 Unhighlights all items
1261 void QAD_ObjectBrowser::unHighlightAll()
1263 myListView->clearSelection();
1264 myUseCaseView->clearSelection();
1268 Highlights items which refer to object
1270 void QAD_ObjectBrowser::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight )
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();
1282 Gets items from Object Browser which refer to object
1284 bool QAD_ObjectBrowser::getItems( const Handle(SALOME_InteractiveObject)& IObject,
1285 QList<QAD_ObjectBrowserItem>& List)
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) );
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) );
1298 return (List.count() > 0);
1302 Gets items from Object Browser which refer to object
1304 bool QAD_ObjectBrowser::getItems( SALOMEDS::SObject_ptr SO,
1305 QList<QAD_ObjectBrowserItem>& List)
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) );
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) );
1318 return (List.count() > 0);
1322 Gets first item from Object Browser which refers to object (not reference)
1324 QAD_ObjectBrowserItem* QAD_ObjectBrowser::getItem( const Handle(SALOME_InteractiveObject)& IObject )
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() )
1338 Finds item from Object Browser corresponding to Object, returns 0 if fails
1340 QAD_ObjectBrowserItem* QAD_ObjectBrowser::getItem( SALOMEDS::SObject_ptr SO )
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() )
1355 Gets first item from UseCase Browser which refers to object (not reference)
1357 QAD_ObjectBrowserItem* QAD_ObjectBrowser::getUCItem( const Handle(SALOME_InteractiveObject)& IObject )
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() )
1371 Finds item from UseCase Browser corresponding to Object, returns 0 if fails
1373 QAD_ObjectBrowserItem* QAD_ObjectBrowser::getUCItem( SALOMEDS::SObject_ptr SO )
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() )
1386 Finds item corresponding to interactive object, returns 0 if fails
1388 void QAD_ObjectBrowser::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
1390 QAD_ObjectBrowserItem* item = getItem( IObject );
1392 item->setName( newName );
1395 item = getUCItem( IObject );
1397 item->setName( newName );
1403 Creates and show specific Popup to this according to current selection (Object Browser)
1405 void QAD_ObjectBrowser::showPopupMenu(QListViewItem* theItem)
1407 QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1408 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1409 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1411 if (theItem != NULL && ( Sel->IObjectCount()>0 || ActiveComp.isEmpty() ) ) {
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() );
1427 QAD_Tools::checkPopup( myPopup );
1428 if ( myPopup->count()>0 ) {
1429 myPopup->exec( QCursor::pos() );
1437 Creates and show specific Popup to this according to current selection (UseCase Browser)
1439 void QAD_ObjectBrowser::showUseCasePopupMenu(QListViewItem* theItem)
1443 QAD_Tools::checkPopup( myPopup );
1444 if ( myPopup->count() > 0 ) {
1445 myPopup->exec( QCursor::pos() );
1452 Called when current selection was changed (Object Browser)
1454 void QAD_ObjectBrowser::onSelectedItem()
1457 if ( sender()->inherits("QListView") )
1458 whoIs = (QListView*)sender();
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();
1466 SALOME_ListIO DeltaPos;
1468 SALOME_ListIO DeltaNeg;
1471 typedef QMap<QString, SALOME_InteractiveObject*> SelMap;
1473 SelMap currMap, allMap;
1474 for( SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); It.More(); It.Next() )
1475 currMap.insert( It.Value()->getEntry(), It.Value().operator->() );
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();
1484 if ( !theEntry.isEmpty() ) {
1485 if ( item->isSelected() ) {
1486 allMap.insert( theEntry, 0 );
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(),
1498 newIO->setReference( theRef.latin1() );
1501 newIO = new SALOME_InteractiveObject( theEntry.latin1(),
1504 newIO->setReference( theRef.latin1() );
1506 if (!newIO.IsNull()) {
1507 DeltaPos.Append( newIO );
1510 } else if ( currMap.contains( theEntry ) )
1511 DeltaNeg.Append( currMap[theEntry] );
1515 SALOME_ListIteratorOfListIO ItNeg( DeltaNeg );
1516 for(;ItNeg.More();ItNeg.Next()) {
1517 Sel->RemoveIObject( ItNeg.Value() );
1520 SALOME_ListIteratorOfListIO ItPos( DeltaPos );
1521 for(;ItPos.More();ItPos.Next()) {
1522 Sel->AddIObject( ItPos.Value() );
1525 for ( SelMap::iterator it = currMap.begin(); it != currMap.end(); ++it )
1526 if ( !allMap.contains( it.key() ) )
1527 Sel->RemoveIObject( it.data() );
1530 myApp->updateActions();
1534 Called when selection is changed (UseCase Browser)
1536 void QAD_ObjectBrowser::onUseCaseSelectedItem()
1541 Called when item is expanded
1543 void QAD_ObjectBrowser::onExpanded (QListViewItem* item)
1545 QAD_ObjectBrowserItem* aItem = (QAD_ObjectBrowserItem*)item;
1546 if (!myStudy->_is_nil() && aItem)
1548 SALOMEDS::SObject_var Object = myStudy->FindObjectID(aItem->getEntry());
1549 if (!Object->_is_nil())
1551 SALOMEDS::StudyBuilder_var StudyBuilder = myStudy->NewBuilder();
1552 SALOMEDS::AttributeOpened_var anAttr = SALOMEDS::AttributeOpened::_narrow(
1553 StudyBuilder->FindOrCreateAttribute(Object, "AttributeOpened") );
1554 anAttr->SetOpened(true);
1560 Called when item is collapsed
1562 void QAD_ObjectBrowser::onCollapsed(QListViewItem* item)
1564 QAD_ObjectBrowserItem* aItem = (QAD_ObjectBrowserItem*)item;
1565 if (!myStudy->_is_nil() && aItem)
1567 SALOMEDS::SObject_var Object = myStudy->FindObjectID(aItem->getEntry());
1568 if (!Object->_is_nil())
1570 SALOMEDS::StudyBuilder_var StudyBuilder = myStudy->NewBuilder();
1571 SALOMEDS::AttributeOpened_var anAttr = SALOMEDS::AttributeOpened::_narrow(
1572 StudyBuilder->FindOrCreateAttribute(Object, "AttributeOpened") );
1573 anAttr->SetOpened(false);
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]
1583 QString QAD_ObjectBrowser::getValueFromObject( SALOMEDS::SObject_ptr SO )
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
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;
1600 if ( SO->FindAttribute( anAttr, "AttributeInteger" ) ) {
1601 anInt = SALOMEDS::AttributeInteger::_narrow( anAttr );
1602 QString val = QString::number( anInt->Value() );
1606 if ( SO->FindAttribute( anAttr, "AttributeReal" ) ) {
1607 aReal = SALOMEDS::AttributeReal::_narrow( anAttr );
1608 QString val = QString::number( aReal->Value() );
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() )
1618 int nbRows = aTableInt->GetNbRows() ;
1619 int nbCols = aTableInt->GetNbColumns();
1620 QString val = tlt + QString( "[" ) + QString::number( nbRows ) + QString( "," ) + QString::number( nbCols ) + QString( "]" );
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() )
1630 int nbRows = aTableReal->GetNbRows() ;
1631 int nbCols = aTableReal->GetNbColumns();
1632 QString val = tlt + QString( "[" ) + QString::number( nbRows ) + QString( "," ) + QString::number( nbCols ) + QString( "]" );
1636 if ( SO->FindAttribute(anAttr, "AttributeComment") ) {
1637 aComment = SALOMEDS::AttributeComment::_narrow( anAttr );
1638 aString = aComment->Value();
1639 QString val = QString( aString.in() );
1642 return QString::null;
1646 Shows/hides IAPP sub-tree in ObjectBrowser
1647 Current implementation just udpates browser
1649 void QAD_ObjectBrowser::setShowIAPP( bool show )
1655 Shows/hides info columns: Entry, IOR, Reference
1657 void QAD_ObjectBrowser::setShowInfoColumns( bool show )
1659 bool shown = myListView->header()->isResizeEnabled( 2 );
1661 if ( show != shown ) {
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 );
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 );
1691 Shows/hides Value column
1693 void QAD_ObjectBrowser::setShowValueColumn( bool show )
1695 bool shown = myListView->header()->isResizeEnabled( 1 );
1697 if ( show != shown ) {
1699 myListView->header()->setResizeEnabled( true, 1 );
1700 myListView->setColumnWidthMode( 1, QListView::Maximum );
1701 if ( myListView->columnWidth( 1 ) <= 0 )
1702 myListView->header()->resizeSection( 1, 50 );
1705 myListView->setColumnWidthMode( 1, QListView::Manual );
1706 myListView->header()->resizeSection( 1, 0 );
1707 myListView->header()->setResizeEnabled( false, 1 );
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
1719 void QAD_ObjectBrowser::setEnableChronoSort( bool 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 ) ;
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 );
1733 // myListView->sort( ) ;
1737 Slot, called to edit value
1739 void QAD_ObjectBrowser::onEditAttribute()
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() )
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;
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" ),
1766 QAD_Application::getDesktop() );
1768 anInt->SetValue( val );
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" ),
1779 QAD_Application::getDesktop() );
1781 aReal->SetValue( val );
1784 // if Table of integer
1786 if ( SO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
1787 SALOMEGUI_TableDlg* dlg = new SALOMEGUI_TableDlg( QAD_Application::getDesktop(),
1790 SALOMEGUI_TableDlg::ttInt );
1791 bOk = ( dlg->exec() == QDialog::Accepted );
1795 if ( SO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
1796 SALOMEGUI_TableDlg* dlg = new SALOMEGUI_TableDlg( QAD_Application::getDesktop(),
1799 SALOMEGUI_TableDlg::ttReal );
1800 bOk = ( dlg->exec() == QDialog::Accepted );
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" ),
1810 QAD_Application::getDesktop() );
1812 aComment->SetValue( val );
1823 Returns true if object has editable attrubute :
1824 integer, real, table or comment
1826 bool QAD_ObjectBrowser::hasEditableAttribute( const Handle(SALOME_InteractiveObject)& object )
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() )
1833 QString val = getValueFromObject( obj );
1834 return ( !val.isNull() );
1840 Returns true if object has table attrubute ( integer and/or real )
1842 bool QAD_ObjectBrowser::hasTable( const Handle(SALOME_InteractiveObject)& object )
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() )
1850 if ( obj->FindAttribute( anAttr, "AttributeTableOfInteger" ) )
1852 if ( obj->FindAttribute( anAttr, "AttributeTableOfReal" ) )
1859 Slot, called when one of the UseCase Browser menu command is called
1861 void QAD_ObjectBrowser::onUseCasePopupMenu( int action )
1863 if ( myStudy->_is_nil() )
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() )
1872 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
1873 QObject::tr("WRN_WARNING"),
1874 QObject::tr("WRN_STUDY_LOCKED"),
1875 QObject::tr("BUT_OK") );
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;
1884 QList<QListViewItem> ucSelected;
1885 ucSelected.setAutoDelete( false );
1886 getSelectedParents( myUseCaseView, ucSelected );
1888 if ( action == UC_NEW_EMPTY_ID ) {
1889 if ( ucSelected.count() == 1 ) {
1890 if ( isRootItem( ucSelected.at(0) ) )
1891 UCBuilder->SetRootCurrent();
1893 UCBuilder->SetCurrentObject( myStudy->FindObjectID( (( QAD_ObjectBrowserItem* )( ucSelected.at(0) ))->getEntry() ) );
1894 UCBuilder->AddUseCase( tr( "NEW_OBJECT" ) );
1895 myActiveStudy->updateUseCaseBrowser();
1899 if ( action == UC_SET_CURRENT_ID ) {
1900 if ( ucSelected.count() > 0 ) {
1901 if ( isRootItem( ucSelected.at(0) ) )
1902 UCBuilder->SetRootCurrent();
1904 UCBuilder->SetCurrentObject( myStudy->FindObjectID( (( QAD_ObjectBrowserItem* )( ucSelected.at(0) ))->getEntry() ) );
1906 myActiveStudy->updateUseCaseBrowser( );
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( );
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 );
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
1940 myActiveStudy->updateUseCaseBrowser( true );
1944 if ( action == UC_REMOVE_ID ) {
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 ) ) {
1951 SALOMEDS::SObject_var SO = myStudy->FindObjectID( item->getEntry() );
1952 if ( !SO->_is_nil() ) {
1953 UCBuilder->Remove( SO );
1959 Sel->ClearIObjects();
1960 myActiveStudy->updateUseCaseBrowser( true );
1963 if ( action == UC_CLEAR_ID ) {
1964 if ( myUseCaseView->childCount() > 0 && myUseCaseView->firstChild()->childCount() > 0) {
1965 QAD_ObjectBrowserItem* child = ( QAD_ObjectBrowserItem* )myUseCaseView->firstChild()->firstChild();
1967 UCBuilder->Remove( myStudy->FindObjectID( child->getEntry().latin1() ) );
1968 child = ( QAD_ObjectBrowserItem* )( child->nextSibling() );
1970 Sel->ClearIObjects();
1971 myActiveStudy->updateUseCaseBrowser();
1976 Use Case browser buttons slot
1978 void QAD_ObjectBrowser::onUseCaseBtn()
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() )
1986 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
1987 QObject::tr("WRN_WARNING"),
1988 QObject::tr("WRN_STUDY_LOCKED"),
1989 QObject::tr("BUT_OK") );
1993 if ( sender() == myNewBtn ) {
1994 SALOMEDS::UseCaseBuilder_var UCBuilder = myStudy->GetUseCaseBuilder();
1995 UCBuilder->AddUseCase( tr( "NEW_OBJECT" ) );
1996 myActiveStudy->updateUseCaseBrowser();
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 );
2009 Show/remove UseCase Browser
2012 void QAD_ObjectBrowser::showUseCaseBrowser ( bool show )
2014 bool shown = (this->count() > 1);
2020 this->addTab( myVBox, tr( "TLT_USECASE_BROWSER" ) );
2021 UpdateUseCaseBrowser();
2025 this->removePage(myVBox);
2030 Switch between auto resizing of columns and manual mode
2032 void QAD_ObjectBrowser::autoSizeColumns( bool autosize )
2036 for (int i = 0; i < myListView->header()->count(); i++ )
2037 if (myListView->header()->isResizeEnabled(i))
2038 myListView->setColumnWidthMode(i, QListView::Maximum);
2043 for (int i = 0; i < myListView->header()->count(); i++ )
2044 myListView->setColumnWidthMode(i, QListView::Manual);