1 // Copyright (C) 2015-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : GEOMGUI_TextTreeWdg.cxx
20 // Author : Alexander KOVALEV (akl)
22 #include "GEOMGUI_TextTreeWdg.h"
24 #include "GEOMGUI_DimensionProperty.h"
25 #include "GEOMGUI_AnnotationAttrs.h"
26 #include "GEOMGUI_AnnotationMgr.h"
27 #include "GeometryGUI.h"
28 #include "GeometryGUI_Operations.h"
29 #include <GEOM_Constants.h>
30 #include <GEOMUtils.hxx>
33 #include <LightApp_Module.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_Study.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_DataBrowser.h>
47 #include <QTreeWidget>
48 #include <QHeaderView>
50 #include <QVBoxLayout>
51 #include <QHBoxLayout>
54 // ----------------------------------------------------------------------------
55 // Common style interface for managing dimension and annotation properties
56 // ----------------------------------------------------------------------------
59 //! Access interface implementation for shape dimension attribute/property.
60 class DimensionsProperty : public GEOMGUI_TextTreeWdg::VisualProperty
64 DimensionsProperty( SalomeApp_Study* theStudy, const std::string& theEntry ) :
65 myStudy( theStudy ), myEntry( theEntry ) {
66 myAttr.LoadFromAttribute( theStudy, theEntry );
68 virtual int GetNumber() Standard_OVERRIDE {
69 return myAttr.GetNumber();
71 virtual QString GetName( const int theIndex ) Standard_OVERRIDE {
72 return myAttr.GetName( theIndex );
74 virtual bool GetIsVisible( const int theIndex ) Standard_OVERRIDE {
75 return myAttr.IsVisible( theIndex );
77 virtual void SetIsVisible( const int theIndex, const bool theIsVisible ) Standard_OVERRIDE {
78 myAttr.SetVisible( theIndex, theIsVisible );
80 virtual void Save() Standard_OVERRIDE {
81 myAttr.SaveToAttribute( myStudy, myEntry );
83 GEOMGUI_DimensionProperty& Attr() { return myAttr; }
86 GEOMGUI_DimensionProperty myAttr;
87 SalomeApp_Study* myStudy;
91 //! Access interface implementation for shape annotation attribute.
92 class AnnotationsProperty : public GEOMGUI_TextTreeWdg::VisualProperty
96 AnnotationsProperty( SalomeApp_Study* theStudy, const std::string& theEntry ) {
97 myEntry = theEntry.c_str();
99 _PTR(SObject) aSObj = theStudy->studyDS()->FindObjectID( theEntry );
101 myAttr = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
104 virtual int GetNumber() Standard_OVERRIDE {
105 return !myAttr.IsNull() ? myAttr->GetNbAnnotation() : 0;
107 virtual QString GetName( const int theIndex ) Standard_OVERRIDE {
108 return !myAttr.IsNull() ? myAttr->GetText( theIndex ) : QString();
110 virtual bool GetIsVisible( const int theIndex ) Standard_OVERRIDE {
111 GEOMGUI_AnnotationMgr* aMgr = annotationMgr();
115 return aMgr->IsDisplayed( myEntry, theIndex );
117 virtual void SetIsVisible( const int theIndex, const bool theIsVisible ) Standard_OVERRIDE {
118 GEOMGUI_AnnotationMgr* aMgr = annotationMgr();
123 annotationMgr()->Display(myEntry, theIndex);
125 annotationMgr()->Erase(myEntry, theIndex);
127 virtual void Save() Standard_OVERRIDE {
128 /* every change is automatically saved */
130 Handle(GEOMGUI_AnnotationAttrs) Attr() { return myAttr; }
133 GEOMGUI_AnnotationMgr* annotationMgr() const
135 CAM_Application* anApp = dynamic_cast<CAM_Application*>(myStudy->application());
136 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>(anApp->activeModule());
140 return aModule->GetAnnotationMgr();
145 Handle(GEOMGUI_AnnotationAttrs) myAttr;
146 SalomeApp_Study* myStudy;
150 // ----------------------------------------------------------------------------
151 // Text tree widget implementation
152 // ----------------------------------------------------------------------------
154 //=================================================================================
155 // function : Constructor
157 //=================================================================================
158 GEOMGUI_TextTreeWdg::GEOMGUI_TextTreeWdg( SalomeApp_Application* app )
161 myStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
162 myDisplayer = GEOM_Displayer( myStudy );
164 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
165 myVisibleIcon = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) );
166 myInvisibleIcon = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) ) );
168 setWindowTitle( tr( "TEXT_TREE_VIEW_TITLE" ) );
169 setObjectName( "geomTextTreeWdg" );
171 setRootIsDecorated( true );
172 setSelectionMode( QAbstractItemView::ExtendedSelection );
173 setAllColumnsShowFocus( true );
174 setUniformRowHeights( true );
176 QStringList columnNames;
177 columnNames << tr("TEXT_TREE_VIEW_NAME") << "";
178 QTreeWidgetItem * headerItem = new QTreeWidgetItem( columnNames );
179 headerItem->setIcon( 1, myVisibleIcon );
180 setHeaderItem ( headerItem );
181 header()->moveSection( 1, 0 );
182 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
183 header()->setResizeMode( 1, QHeaderView::ResizeToContents );
185 header()->setSectionResizeMode( 1, QHeaderView::ResizeToContents );
187 QStringList rootNames;
188 rootNames << tr("GEOM_DIMENSIONS") << "";
189 myDimensionsItem = new QTreeWidgetItem( this, rootNames );
190 myDimensionsItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
191 addTopLevelItem( myDimensionsItem );
194 rootNames << tr("GEOM_ANNOTATIONS") << "";
195 myAnnotationsItem = new QTreeWidgetItem( this, rootNames );
196 myAnnotationsItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
197 addTopLevelItem( myAnnotationsItem );
199 // get a free dockable window id
201 while( app->dockWindow( myWindowID ))
206 setContextMenuPolicy( Qt::CustomContextMenu );
207 connect( this, SIGNAL( customContextMenuRequested(const QPoint&) ),
208 this, SLOT( showContextMenu(const QPoint&) ) );
210 connect( app->objectBrowser(), SIGNAL( updated() ), this, SLOT( updateTree() ) );
212 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
213 connect( aGeomGUI, SIGNAL( DimensionsUpdated( const QString& ) ),
214 this, SLOT( updateDimensionBranch( const QString& ) ) );
215 connect( aGeomGUI, SIGNAL( SignalAnnotationsUpdated( const QString& ) ),
216 this, SLOT( updateAnnotationBranch( const QString& ) ) );
217 connect( aGeomGUI, SIGNAL( SignalTextTreeRenameObject( const QString& ) ),
218 this, SLOT( updateObjectName( const QString& ) ) );
220 connect( this, SIGNAL( itemClicked( QTreeWidgetItem*, int) ),
221 this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
222 connect( myStudy, SIGNAL( objVisibilityChanged( QString, Qtx::VisibilityState ) ),
223 this, SLOT( onUpdateVisibilityColumn( QString, Qtx::VisibilityState ) ) );
226 //=================================================================================
227 // function : Destructor
229 //=================================================================================
230 GEOMGUI_TextTreeWdg::~GEOMGUI_TextTreeWdg()
232 //std::cout<<"~GEOMGUI_TextTreeWdg"<<std::endl;
235 //=================================================================================
236 // function : createActions
237 // purpose : Create context popup menu actions.
238 //=================================================================================
239 void GEOMGUI_TextTreeWdg::createActions()
241 QAction* a = new QAction( tr( "MEN_DISPLAY" ), this );
242 a->setIcon( myVisibleIcon );
243 myActions.insert( GEOMOp::OpShow, a );
245 QAction* b = new QAction( tr( "MEN_ERASE" ), this );
246 b->setIcon( myInvisibleIcon );
247 myActions.insert( GEOMOp::OpHide, b );
250 //=================================================================================
251 // function : updateTree
252 // purpose : Rebuild branches of objects and remove objects if there are no more annotations
254 //=================================================================================
255 void GEOMGUI_TextTreeWdg::updateTree()
257 myStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
258 _PTR(Study) aDSStudy = myStudy->studyDS();
260 _PTR(SComponent) SC ( aDSStudy->FindComponent( "GEOM" ) );
262 _PTR(ChildIterator) anIter ( aDSStudy->NewChildIterator( SC ) );
263 anIter->InitEx( true );
264 QList<QString> aDimensionObjEntries = getObjects( DimensionShape ).keys();
265 QList<QString> anAnnotationObjEntries = getObjects( AnnotationShape ).keys();
266 while( anIter->More() ) {
267 _PTR(SObject) valSO ( anIter->Value() );
269 if ( !valSO->ReferencedObject( refSO ) ) {
270 // update tree of object's dimensions
271 QString anEntry = valSO->GetID().c_str();
272 updateBranches( anEntry );
273 aDimensionObjEntries.removeAll( anEntry );
274 anAnnotationObjEntries.removeAll( anEntry );
278 foreach ( QString entry, aDimensionObjEntries ) {
279 removeBranch( DimensionShape, entry, true );
281 foreach ( QString entry, anAnnotationObjEntries ) {
282 removeBranch( AnnotationShape, entry, true );
288 //=================================================================================
289 // function : updateBranches
290 // purpose : Rebuild branches for object of the given entry
291 //=================================================================================
292 void GEOMGUI_TextTreeWdg::updateBranches( const QString& theEntry )
294 updateDimensionBranch( theEntry );
295 updateAnnotationBranch( theEntry );
298 //=================================================================================
299 // function : updateDimensionBranch
300 // purpose : Rebuild branch of dimension type for object of the given entry
301 //=================================================================================
302 void GEOMGUI_TextTreeWdg::updateDimensionBranch( const QString& theEntry )
304 fillBranch( DimensionShape, theEntry );
307 //=================================================================================
308 // function : updateAnnotationBranch
309 // purpose : Rebuild branch of annotation type for object of the given entry
310 //=================================================================================
311 void GEOMGUI_TextTreeWdg::updateAnnotationBranch( const QString& theEntry )
313 fillBranch( AnnotationShape, theEntry );
316 //=================================================================================
317 // function : updateObjectName
318 // purpose : Find name of the given object and set the name for corresponded tree item
319 //=================================================================================
320 void GEOMGUI_TextTreeWdg::updateObjectName( const QString& theEntry )
322 QTreeWidgetItem* anObjectItem = 0;
324 QHash<QString, QTreeWidgetItem*> anObjects = getObjects( DimensionShape );
325 if ( anObjects.contains( theEntry ) )
326 anObjectItem = anObjects.value( theEntry );
328 anObjects = getObjects( AnnotationShape );
329 if ( anObjects.contains( theEntry ) )
330 anObjectItem = anObjects.value( theEntry );
335 myStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
337 _PTR(Study) aStudyDS = myStudy->studyDS();
339 _PTR(SObject) anObject( aStudyDS->FindObjectID( theEntry.toStdString() ) );
340 if ( anObject.get() )
341 anObjectItem->setText( 0, anObject->GetName().c_str() );
346 //=================================================================================
347 // function : fillBranch
349 //=================================================================================
350 void GEOMGUI_TextTreeWdg::fillBranch( const BranchType& theBranchType, const QString& theEntry )
352 myStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
354 if ( myStudy && !theEntry.isEmpty() ) {
355 QSharedPointer<VisualProperty> aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
360 _PTR(Study) aStudyDS = myStudy->studyDS();
362 _PTR(SObject) obj( aStudyDS->FindObjectID( theEntry.toStdString() ) );
363 const QString aName = obj->GetName().c_str();
364 const int nbProps = aProp->GetNumber();
366 QTreeWidgetItem* objectItem = itemFromEntry( theBranchType, theEntry );
368 removeBranch( theBranchType, theEntry, nbProps > 0 ? false : true );
370 QStringList itemName;
372 itemName << aName << "";
374 QTreeWidgetItem* aPropRootItem = getPropertyRootItem( theBranchType );
376 objectItem = new QTreeWidgetItem( aPropRootItem, itemName );
377 objectItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
378 objectItem->setData( 1, Qt::UserRole, theEntry );
379 aPropRootItem->addChild( objectItem );
380 getObjects( theBranchType ).insert( theEntry, objectItem );
381 if ( aPropRootItem->childCount() == 1 )
382 aPropRootItem->setExpanded( true );
384 for ( int anIt = 0; anIt < nbProps; ++anIt ) {
385 const QString aPropName = aProp->GetName( anIt );
386 const bool isVisible = aProp->GetIsVisible( anIt );
387 QTreeWidgetItem* anItem = new QTreeWidgetItem;
388 anItem->setText( 0, aPropName );
389 anItem->setIcon( 1, isVisible ? myVisibleIcon : myInvisibleIcon );
390 anItem->setData( 0, Qt::UserRole, anIt );
391 anItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
392 objectItem->addChild( anItem );
399 //=================================================================================
400 // function : getVisualProperty
402 //=================================================================================
403 QSharedPointer<GEOMGUI_TextTreeWdg::VisualProperty>
404 GEOMGUI_TextTreeWdg::getVisualProperty( const BranchType& theBranchType,
405 SalomeApp_Study* theStudy,
406 const std::string& theEntry )
408 switch ( theBranchType )
410 case DimensionShape : return QSharedPointer<VisualProperty>( new DimensionsProperty( theStudy, theEntry ) );
411 case AnnotationShape : return QSharedPointer<VisualProperty>( new AnnotationsProperty( theStudy, theEntry ) );
414 return QSharedPointer<VisualProperty>();
417 //=================================================================================
418 // function : removeBranch
420 //=================================================================================
421 void GEOMGUI_TextTreeWdg::removeBranch( const BranchType& theBranchType, const QString& theEntry,
424 QTreeWidgetItem* objectItem = itemFromEntry( theBranchType, theEntry );
427 qDeleteAll( objectItem->takeChildren() );
429 QTreeWidgetItem* aPropRootItem = getPropertyRootItem( theBranchType );
430 aPropRootItem->removeChild( objectItem );
431 getObjects( theBranchType ).remove( theEntry );
435 //=================================================================================
436 // function : onItemClicked()
437 // purpose : called when tree item was clicked
438 //=================================================================================
439 void GEOMGUI_TextTreeWdg::onItemClicked( QTreeWidgetItem* theItem, int theColumn )
441 if( theColumn != 1 || theItem->icon( 1 ).isNull() || theItem->isDisabled() )
444 std::string anEntry = entryFromItem( theItem->parent() ).toStdString();
445 BranchType aBranchType = branchTypeFromItem( theItem );
447 int aDimIndex = idFromItem( theItem );
449 QSharedPointer<VisualProperty> aProp = getVisualProperty( aBranchType, myStudy, anEntry );
451 CAM_Application* anApp = dynamic_cast<CAM_Application*>(myStudy->application());
452 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>(anApp->activeModule());
453 if ( aProp->GetIsVisible( aDimIndex ) ) {
454 aModule->GetAnnotationMgr()->Erase(anEntry.c_str(), aDimIndex);
455 theItem->setIcon( 1, myInvisibleIcon );
457 aModule->GetAnnotationMgr()->Display(anEntry.c_str(), aDimIndex);
459 theItem->setIcon( 1, myVisibleIcon );
461 redisplay( anEntry.c_str() );
464 //=================================================================================
465 // function : idFromItem
467 //=================================================================================
468 int GEOMGUI_TextTreeWdg::idFromItem( QTreeWidgetItem* theItem )
474 const int anId = theItem->data( 0, Qt::UserRole ).toInt( &isIdOK );
476 return isIdOK ? anId : -1;
479 //=================================================================================
480 // function : entryFromItem
482 //=================================================================================
483 QString GEOMGUI_TextTreeWdg::entryFromItem( QTreeWidgetItem* theShapeItem ) const
488 return theShapeItem->data( 1, Qt::UserRole ).toString();
491 //=================================================================================
492 // function : itemFromEntry
494 //=================================================================================
495 QTreeWidgetItem* GEOMGUI_TextTreeWdg::itemFromEntry( const BranchType& theBranchType, QString theEntry )
497 if ( theEntry.isEmpty() )
500 return getObjects(theBranchType).value( theEntry, 0 );
503 //=================================================================================
504 // function : onUpdateVisibilityColumn
505 // purpose : Update visible state of icons of entry items.
506 //=================================================================================
507 void GEOMGUI_TextTreeWdg::onUpdateVisibilityColumn( QString theEntry, Qtx::VisibilityState theState )
509 // dimension property branch
510 updateVisibilityColumn( DimensionShape, theEntry, theState );
512 // annotation property branch
513 updateVisibilityColumn( AnnotationShape, theEntry, theState );
516 //=================================================================================
517 // function : updateVisibilityColumn
518 // purpose : Update icons of dimension items.
519 //=================================================================================
520 void GEOMGUI_TextTreeWdg::updateVisibilityColumn( const BranchType& theBranchType, QString theEntry,
521 Qtx::VisibilityState theState )
523 QTreeWidgetItem* anItem = itemFromEntry( theBranchType, theEntry );
526 anItem->setDisabled( theState != Qtx::ShownState );
527 QTreeWidgetItem* aChildItem;
529 QSharedPointer<VisualProperty> aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
531 for ( int i=0; i < anItem->childCount(); i++ ) {
532 aChildItem = anItem->child( i );
533 if ( theState == Qtx::ShownState ) {
534 if ( aProp->GetNumber() == 0 )
536 aChildItem->setIcon( 1, aProp->GetIsVisible( idFromItem( aChildItem ) ) ? myVisibleIcon
538 aChildItem->setDisabled( false );
540 aChildItem->setIcon( 1, QIcon() );
541 aChildItem->setDisabled( true );
546 //=================================================================================
547 // function : showContextMenu
549 //=================================================================================
550 void GEOMGUI_TextTreeWdg::showContextMenu( const QPoint& pos )
552 CAM_Application* anApp = dynamic_cast<CAM_Application*>(myStudy->application());
553 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>(anApp->activeModule());
556 if ( !selectedItems().isEmpty() && selectedItems().count() == 1 ) {
557 QTreeWidgetItem* anItem = selectedItems().first();
558 QString anEntry = entryFromItem( anItem->parent() );
559 if ( !anEntry.isEmpty() ) {
560 BranchType aBranchType = branchTypeFromItem( anItem );
561 QSharedPointer<VisualProperty>
562 aProp = getVisualProperty( aBranchType, myStudy, anEntry.toStdString() );
564 if ( aProp->GetNumber() == 0 )
566 // Edit annotation action
567 QAction* anEditAction = aModule->action(GEOMOp::OpEditAnnotation);
569 aMenu.addAction( anEditAction );
570 QAction* aDeleteAction = aModule->action(GEOMOp::OpDeleteAnnotation);
572 aMenu.addAction( aDeleteAction );
574 if ( aProp->GetIsVisible( idFromItem( anItem ) ) )
575 aMenu.addAction( myActions[GEOMOp::OpHide] );
577 aMenu.addAction( myActions[GEOMOp::OpShow] );
581 if (selectedItems().isEmpty() && currentItem()) {
582 QTreeWidgetItem* anItem = currentItem();
583 bool aShowAll = false;
584 if (anItem == getPropertyRootItem(AnnotationShape))
587 QHash<QString, QTreeWidgetItem*> anObjects = getObjects( AnnotationShape );
588 QHash<QString, QTreeWidgetItem*>::const_iterator anIt = anObjects.begin(),
589 aLast = anObjects.end();
590 for (; anIt != aLast && !aShowAll; anIt++) {
591 aShowAll = anIt.value() == anItem;
595 aMenu.addAction( aModule->action(GEOMOp::OpShowAllAnnotations) );
596 aMenu.addAction( aModule->action(GEOMOp::OpHideAllAnnotations) );
599 QAction* selPopupItem = aMenu.exec( viewport()->mapToGlobal(pos) );
601 if ( selPopupItem == myActions[GEOMOp::OpShow] ||
602 selPopupItem == myActions[GEOMOp::OpHide] ) {
603 bool isVisible = selPopupItem == myActions[GEOMOp::OpShow];
604 foreach ( QTreeWidgetItem* anItem, selectedItems() ) {
605 setVisibility( anItem, isVisible );
610 //=================================================================================
611 // function : setVisibility
612 // purpose : set item visible
613 //=================================================================================
614 void GEOMGUI_TextTreeWdg::setVisibility( QTreeWidgetItem* theItem, bool theVisibility )
616 BranchType aBranchType = branchTypeFromItem( theItem );
617 if ( theItem == myDimensionsItem ||
618 theItem == myAnnotationsItem ) {
620 QTreeWidgetItem* anItem;
621 foreach ( QString entry, getObjects( aBranchType ).keys() ) {
622 anItem = itemFromEntry( aBranchType, entry );
623 if ( !anItem->isDisabled() )
624 setAllShapeItemsVisibility( aBranchType, entry, theVisibility );
629 if ( !theItem->isDisabled() && !theItem->parent()->isSelected() ) {
630 QString anEntry = entryFromItem( theItem );
631 if ( !anEntry.isEmpty() ) {
632 // it is a shape item
633 setAllShapeItemsVisibility( aBranchType, anEntry, theVisibility );
635 // it is a dimension item
636 anEntry = entryFromItem( theItem->parent() );
637 setShapeItemVisibility( aBranchType, anEntry, theItem, theVisibility );
643 //=================================================================================
644 // function : setAllShapeItemsVisibility
646 //=================================================================================
647 void GEOMGUI_TextTreeWdg::setAllShapeItemsVisibility( const BranchType& theBranchType,
648 const QString& theEntry,
649 const bool theVisibility )
651 QSharedPointer<VisualProperty>
652 aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
654 QTreeWidgetItem* anItem = itemFromEntry( theBranchType, theEntry );
655 QTreeWidgetItem* aChildItem;
656 for ( int i=0; i < anItem->childCount(); i++ ) {
657 aChildItem = anItem->child( i );
658 setShapeItemVisibility( aProp, aChildItem, theVisibility );
663 redisplay( theEntry );
666 //=================================================================================
667 // function : setShapeItemVisibility
669 //=================================================================================
670 void GEOMGUI_TextTreeWdg::setShapeItemVisibility( const BranchType& theBranchType,
671 const QString& theEntry,
672 QTreeWidgetItem* theWidgetItem,
673 const bool theVisibility )
675 QSharedPointer<VisualProperty>
676 aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
678 if ( setShapeItemVisibility( aProp, theWidgetItem, theVisibility ) ) {
680 redisplay( theEntry );
684 //=================================================================================
685 // function : setShapeItemVisibility
687 //=================================================================================
688 void GEOMGUI_TextTreeWdg::updateVisibility()
690 //QList<QString> aDimensionObjEntries = getObjects( DimensionShape ).keys();
691 BranchType aBranchType = AnnotationShape;
693 QList<QString> anAnnotationObjEntries = getObjects( aBranchType ).keys();
695 QTreeWidgetItem* anEntryItem;
696 foreach ( QString anEntry, getObjects( aBranchType ).keys() )
698 anEntryItem = itemFromEntry( aBranchType, anEntry );
700 QTreeWidgetItem* anItem;
701 for ( int i = 0; i < anEntryItem->childCount(); i++ ) {
702 anItem = anEntryItem->child( i );
703 int aDimIndex = idFromItem( anItem );
704 QSharedPointer<VisualProperty> aProp = getVisualProperty( aBranchType, myStudy,
705 anEntry.toStdString() );
706 bool isItemVisible = aProp->GetIsVisible( aDimIndex );
707 anItem->setIcon( 1, isItemVisible ? myVisibleIcon : myInvisibleIcon );
710 redisplay( anEntry );
714 //=================================================================================
715 // function : getSelected
717 //=================================================================================
718 void GEOMGUI_TextTreeWdg::getSelected( QMap<QString, QList<int> >& theAnnotations )
720 theAnnotations.clear();
722 QItemSelectionModel* aSelectionModel = selectionModel();
723 QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes();
725 for (int i = 0, aNbItems = aSelectedIndices.size(); i < aNbItems; i++) {
726 QTreeWidgetItem* anItem = itemFromIndex( aSelectedIndices[i] );
729 QString anEntry = entryFromItem( anItem->parent() );
730 int aDimIndex = idFromItem( anItem );
734 if ( theAnnotations.contains( anEntry ) )
735 theAnnotations[anEntry].append( aDimIndex );
737 QList<int> anIndices;
738 anIndices.append( aDimIndex );
739 theAnnotations[anEntry] = anIndices;
744 //=================================================================================
745 // function : setSelected
747 //=================================================================================
748 void GEOMGUI_TextTreeWdg::setSelected( const QMap<QString, QList<int> >& theAnnotations )
750 QItemSelectionModel* aSelectionModel = selectionModel();
751 aSelectionModel->clearSelection();
753 QMap<QString, QList<int> >::const_iterator anIt = theAnnotations.begin(),
754 aLast = theAnnotations.end();
755 BranchType aBranchType = AnnotationShape;
756 for ( ; anIt != aLast; anIt++ ) {
757 QString anEntry = anIt.key();
758 QTreeWidgetItem* anEntryItem = itemFromEntry( aBranchType, anEntry );
762 QList<int> anAnnotationIds = anIt.value();
763 QTreeWidgetItem* anItem;
764 for ( int i = 0; i < anEntryItem->childCount(); i++ ) {
765 anItem = anEntryItem->child( i );
766 int aDimIndex = idFromItem( anItem );
767 if ( anAnnotationIds.contains( aDimIndex ) ) {
768 QModelIndex anIndex = indexFromItem( anItem );
769 aSelectionModel->select( anIndex, QItemSelectionModel::Select );
775 //=================================================================================
776 // function : getAllEntries
778 //=================================================================================
779 QList<QString> GEOMGUI_TextTreeWdg::getAllEntries( const BranchType& theBranchType )
781 return getObjects( theBranchType ).keys();
784 //=================================================================================
785 // function : getSingleSelectedObject
787 //=================================================================================
788 QString GEOMGUI_TextTreeWdg::getSingleSelectedObject()
791 QTreeWidgetItem* anItem = currentItem();
793 QHash<QString, QTreeWidgetItem*> anObjects = getObjects( AnnotationShape );
794 QHash<QString, QTreeWidgetItem*>::const_iterator anIt = anObjects.begin(),
795 aLast = anObjects.end();
796 for (; anIt != aLast; anIt++) {
797 if ( anIt.value() == anItem ) {
798 anEntry = anIt.key();
806 //=================================================================================
807 // function : setShapeItemVisibility
809 //=================================================================================
810 bool GEOMGUI_TextTreeWdg::setShapeItemVisibility( QSharedPointer<VisualProperty>& theProps,
811 QTreeWidgetItem* theWidgetItem,
812 const bool theVisibility )
814 int aDimIndex = idFromItem( theWidgetItem );
815 if ( theProps->GetNumber() == 0
816 || theProps->GetIsVisible( aDimIndex ) == theVisibility ) {
819 theProps->SetIsVisible( aDimIndex, theVisibility );
821 theWidgetItem->setIcon( 1, theVisibility ? myVisibleIcon : myInvisibleIcon );
826 //=================================================================================
827 // function : redisplay
829 //=================================================================================
830 void GEOMGUI_TextTreeWdg::redisplay( QString theEntry )
832 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( theEntry.toLatin1().constData(), "GEOM", "TEMP_IO" );
833 myDisplayer.Redisplay( io );
836 //=================================================================================
837 // function : getPropertyRootItem
839 //=================================================================================
840 QTreeWidgetItem* GEOMGUI_TextTreeWdg::getPropertyRootItem( const BranchType& theBranchType )
842 return (theBranchType == DimensionShape) ? myDimensionsItem : myAnnotationsItem;
845 //=================================================================================
846 // function : getObjects
848 //=================================================================================
849 QHash<QString, QTreeWidgetItem*>& GEOMGUI_TextTreeWdg::getObjects( const BranchType& theBranchType )
851 return (theBranchType == DimensionShape) ? myDimensionObjects : myAnnotationObjects;
854 //=================================================================================
855 // function : branchTypeFromItem
857 //=================================================================================
858 GEOMGUI_TextTreeWdg::BranchType GEOMGUI_TextTreeWdg::branchTypeFromItem( QTreeWidgetItem* theItem )
860 BranchType aBranchType = DimensionShape;
862 bool aBranchTypeFound = false;
863 QTreeWidgetItem* anItem = theItem;
864 while( !aBranchTypeFound && anItem ) {
865 if ( anItem == myDimensionsItem ||
866 anItem == myAnnotationsItem) {
867 aBranchTypeFound = true;
868 aBranchType = (anItem == myDimensionsItem) ? DimensionShape : AnnotationShape;
871 anItem = anItem->parent();