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
20 // File : GEOMGUI_TextTreeSelector.cxx
23 #include "GEOMGUI_TextTreeSelector.h"
24 #include "GEOMGUI_TextTreeWdg.h"
25 #include "GEOMGUI_AnnotationMgr.h"
27 #include "LightApp_DataOwner.h"
28 #include "LightApp_DataObject.h"
29 #include "LightApp_Application.h"
30 #include <SUIT_Session.h>
31 #include <SUIT_DataObjectIterator.h>
34 \class GEOMGUI_TextTreeSelector
35 \brief Text tree selection handler class. It provides selection synchronization between
36 application and text tree widget. This selector listens item selection changed signal of
37 text tree widget to emit common selection changed signal of SUIT selector to start selection
38 synchronization. In get/setSelection selector processes annotation items. These items have
39 specific entry generated in annotation manager, having the "object entry:annotation_id" structure.
44 \param widget text tree widget
45 \param theManager selection manager
47 GEOMGUI_TextTreeSelector::GEOMGUI_TextTreeSelector( GEOMGUI_TextTreeWdg* theWidget,
48 GEOMGUI_AnnotationMgr* theAnnotationMgr,
49 SUIT_SelectionMgr* theManager )
50 : SUIT_Selector( theManager, theWidget ),
51 myTextTree( theWidget ), myAnnotationMgr( theAnnotationMgr )
54 connect( myTextTree, SIGNAL( itemSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
61 GEOMGUI_TextTreeSelector::~GEOMGUI_TextTreeSelector()
66 \brief Get object browser.
67 \return a pointer to the text tree widget
69 GEOMGUI_TextTreeWdg* GEOMGUI_TextTreeSelector::textTree() const
75 \brief Get selector unique type.
78 QString GEOMGUI_TextTreeSelector::type() const
84 \brief Called when the Object browser selection is changed. It emits signal to synchronize
85 selection in application.
87 void GEOMGUI_TextTreeSelector::onSelectionChanged()
89 mySelectedList.clear();
94 \brief Get list of currently selected annotation objects.
95 \param theList list to be filled with the selected objects owners
96 The list contains owners for interactive objects of annotations
98 void GEOMGUI_TextTreeSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
100 if ( mySelectedList.count() == 0 ) {
102 GEOMGUI_TextTreeSelector* aThisSelector = (GEOMGUI_TextTreeSelector*)this;
103 QMap<QString, QList<int> > aSelectedAnnotations;
104 myTextTree->getSelected(aSelectedAnnotations);
106 QMap<QString, QList<int> >::const_iterator anIt = aSelectedAnnotations.begin(),
107 aLast = aSelectedAnnotations.end();
108 for ( ; anIt != aLast; anIt++ ) {
109 QString anEntry = anIt.key();
110 QList<int> anIndices = anIt.value();
111 QList<int>::const_iterator anIdIt = anIndices.begin(), anIdLast = anIndices.end();
112 for ( ; anIdIt != anIdLast; anIdIt++ ) {
113 int anIndex = *anIdIt;
114 Handle(SALOME_InteractiveObject) anIO = myAnnotationMgr->FindInteractiveObject( anEntry, anIndex );
118 LightApp_DataOwner* owner = new LightApp_DataOwner( anIO );
119 aThisSelector->mySelectedList.append( SUIT_DataOwnerPtr( owner ) );
123 theList = mySelectedList;
127 \brief Set selection.
128 \param theList list of the object owners to be set selected
130 void GEOMGUI_TextTreeSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
135 QMap<QString, QList<int> > aSelectedAnnotations;
136 DataObjectList objList;
137 for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin();
138 it != theList.end(); ++it ) {
139 const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
142 Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
146 QString anIOEntry = anIO->getEntry();
147 QStringList anAnnotationInfo = anIOEntry.split(GEOMGUI_AnnotationMgr::GetEntrySeparator());
148 if (anAnnotationInfo.size() != 2 )
151 QString anEntry = anAnnotationInfo[0];
152 int anAnnotationId = anAnnotationInfo[1].toInt();
153 if ( anAnnotationId < 0)
156 QList<int> anIndices;
157 if ( aSelectedAnnotations.contains( anEntry ) )
158 anIndices = aSelectedAnnotations[anEntry];
160 if ( !anIndices.contains( anAnnotationId ) )
161 anIndices.append( anAnnotationId );
163 aSelectedAnnotations[anEntry] = anIndices;
165 myTextTree->setSelected(aSelectedAnnotations);
166 mySelectedList.clear();