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 : SALOME_Selection.cxx
25 // Author : Nicolas REJNERI
31 \class SALOME_Selection SALOME_Selection.h
32 \brief Selection Mechanism of Interactive Object.
35 #include "SALOME_Selection.h"
36 #include "SALOME_Filter.hxx"
37 #include "SALOME_InteractiveObject.hxx"
38 #include "SALOME_ListIteratorOfListIO.hxx"
39 #include "SALOME_ListIteratorOfListOfFilter.hxx"
41 #include "QAD_Desktop.h"
42 #include "utilities.h"
44 static QList<SALOME_Selection>& SALOME_Sel_GetSelections()
46 static QList<SALOME_Selection> Selections;
50 //=======================================================================
51 // SELECTIONS MANAGEMENT
52 //=======================================================================
57 SALOME_Selection::SALOME_Selection(const QString& aName) :
62 mySelectionMode = 4; /*Actor*/
63 mySelActiveCompOnly = false;
65 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
67 QAD_Application *anActiveApplication = aDesktop->getActiveApp();
68 if (anActiveApplication) QAD_ASSERT(connect(this, SIGNAL(currentSelectionChanged()),anActiveApplication, SLOT(updateActions())));
75 SALOME_Selection::~SALOME_Selection()
80 Create a Selection with name \a aName
81 \return TRUE if the Selection is created. Returns FALSE otherwise.
83 bool SALOME_Selection::CreateSelection(const QString& aName)
85 SALOME_Selection* S = NULL;
86 if ( SALOME_Selection::FindSelection( aName ) )
87 S = SALOME_Selection::Selection( aName );
89 S = new SALOME_Selection(aName);
90 SALOME_Sel_GetSelections().prepend(S);
97 Sets the current Selection with \a aName
99 SALOME_Selection* SALOME_Selection::Selection(const QString& aName)
101 SALOME_Selection* Sel = NULL;
102 if(SALOME_Sel_GetSelections().isEmpty()) return Sel;
104 for( Sel=SALOME_Sel_GetSelections().first(); Sel!=0; Sel=SALOME_Sel_GetSelections().next() ){
105 if( Sel->myName.compare(aName) == 0 )
113 Finds Selection with \a aName
114 \return TRUE if the Selection is found. Returns FALSE otherwise.
116 bool SALOME_Selection::FindSelection(const QString& aName)
118 SALOME_Selection* Sel;
119 for( Sel=SALOME_Sel_GetSelections().first(); Sel!=0; Sel=SALOME_Sel_GetSelections().next() ){
120 if( Sel->myName.compare(aName) == 0 )
128 Removes Selection with \a aName
129 \return TRUE if the Selection is removed. Returns FALSE otherwise.
131 bool SALOME_Selection::RemoveSelection(const QString& aName)
133 SALOME_Selection* Sel;
134 for( Sel=SALOME_Sel_GetSelections().first(); Sel!=0; Sel=SALOME_Sel_GetSelections().next() ){
135 if( Sel->myName.compare(aName) == 0 )
136 return SALOME_Sel_GetSelections().remove(Sel);
143 //=======================================================================
144 // FILTERS MANAGEMENT
145 //=======================================================================
150 void SALOME_Selection::AddFilter(const Handle(SALOME_Filter)& aFilter,
151 bool updateSelection)
153 if ( !FindFilter(aFilter) ) {
154 myFilters.Append( aFilter );
156 SALOME_ListIO removedIObjects;
158 if ( updateSelection ) {
159 SALOME_ListIteratorOfListIO It(myIObjects);
160 for(;It.More();It.Next()){
161 Handle(SALOME_InteractiveObject) Object = It.Value();
162 if( !IsOk(Object) ) {
163 removedIObjects.Append( Object );
164 // RemoveIObject( Object );
168 SALOME_ListIteratorOfListIO It1(removedIObjects);
169 for(;It1.More();It1.Next()){
170 Handle(SALOME_InteractiveObject) Object = It1.Value();
171 RemoveIObject( Object );
180 bool SALOME_Selection::RemoveFilter(const Handle(SALOME_Filter)& aFilter)
182 SALOME_ListIteratorOfListOfFilter It(myFilters);
183 for(;It.More();It.Next()){
184 if (aFilter==It.Value()){
185 myFilters.Remove(It);
192 //! Clears All Filters
193 void SALOME_Selection::ClearFilters()
199 bool SALOME_Selection::FindFilter(const Handle(SALOME_Filter)& aFilter)
201 SALOME_ListIteratorOfListOfFilter It(myFilters);
202 for(;It.More();It.Next())
203 if (aFilter==It.Value())
208 //! Returns the list of stored Filters
209 const SALOME_ListOfFilter& SALOME_Selection::StoredFilters()
216 //=======================================================================
217 // INTERACTIVE OBJECTS MANAGEMENT
218 //=======================================================================
220 void SALOME_Selection::Clear()
225 //! Clears all Interactive Objects
226 void SALOME_Selection::ClearIObjects()
230 QAD_Desktop* myDesktop = (QAD_Desktop*) QAD_Application::getDesktop();
231 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
232 myActiveStudy->unHighlightAll();
234 myMapIOSubIndex.Clear();
236 emit currentSelectionChanged();
239 //! Add an InteractiveObject
240 int SALOME_Selection::AddIObject(const Handle(SALOME_InteractiveObject)& anObject, bool update)
242 QAD_Desktop* myDesktop = (QAD_Desktop*) QAD_Application::getDesktop();
243 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
245 if ( !IsOk(anObject) ) {
246 MESSAGE ( "The Object not authorized by Filters" )
247 myActiveStudy->highlight(anObject,false, update);
252 SALOME_ListIteratorOfListIO It(myIObjects);
253 for(;It.More();It.Next()) {
254 if (anObject->isSame(It.Value())) {
260 // Il n'est pas dedans, on le rajoute....
262 myIObjects.Append( anObject );
263 myActiveStudy->highlight(anObject, true, update);
264 emit currentSelectionChanged();
270 //! Removes an InteractiveObject
271 int SALOME_Selection::RemoveIObject(const Handle(SALOME_InteractiveObject)& anObject, bool update)
273 SALOME_ListIteratorOfListIO It(myIObjects);
274 for(;It.More();It.Next()) {
275 if (anObject->isSame(It.Value())) {
276 QAD_Desktop* myDesktop = (QAD_Desktop*) QAD_Application::getDesktop();
277 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
278 myActiveStudy->highlight(anObject, false, update);
280 if ( myMapIOSubIndex.IsBound( anObject ) ) {
281 myMapIOSubIndex.UnBind( anObject );
284 myIObjects.Remove(It);
286 emit currentSelectionChanged();
293 //! Returns the list of InteractiveObjects
294 const SALOME_ListIO& SALOME_Selection::StoredIObjects()
299 //! Returns the number of InteractiveObjects in the selection.
300 int SALOME_Selection::IObjectCount()
302 return myIObjects.Extent();
305 //! Returns the first InteractiveObject in the selection.
306 Handle(SALOME_InteractiveObject) SALOME_Selection::firstIObject()
308 return myIObjects.First();
311 //! Returns the last InteractiveObject in the selection.
312 Handle(SALOME_InteractiveObject) SALOME_Selection::lastIObject()
314 return myIObjects.Last();
318 Returns TRUE if the InteractiveObject is authorized by Filters. Returns FALSE otherwise.
320 bool SALOME_Selection::IsOk(const Handle(SALOME_InteractiveObject)& anObj)
322 SALOME_ListIteratorOfListOfFilter It(myFilters);
323 for(;It.More();It.Next()){
324 Handle(SALOME_Filter) theFilter = It.Value();
325 if ( !theFilter->IsOk(anObj) )
331 void SALOME_Selection::SetSelectionMode(int mode, bool activeCompOnly)
333 mySelectionMode = mode;
334 mySelActiveCompOnly = activeCompOnly;
337 int SALOME_Selection::SelectionMode()
339 return mySelectionMode;
342 bool SALOME_Selection::IsSelectActiveCompOnly() const
344 return mySelActiveCompOnly;
347 bool SALOME_Selection::HasIndex( const Handle(SALOME_InteractiveObject)& IObject )
349 return myMapIOSubIndex.IsBound(IObject);
352 void SALOME_Selection::GetIndex( const Handle(SALOME_InteractiveObject)& IObject, TColStd_MapOfInteger& theIndex )
354 if ( myMapIOSubIndex.IsBound(IObject) ) {
355 theIndex = myMapIOSubIndex.Find(IObject);
364 bool SALOME_Selection::IsIndexSelected(const Handle(SALOME_InteractiveObject)& IObject, int index)
366 if ( !myMapIOSubIndex.IsBound( IObject ) ) {
369 TColStd_MapOfInteger& MapIndex = myMapIOSubIndex.ChangeFind( IObject );
370 return MapIndex.Contains( index );
376 bool SALOME_Selection::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
381 MESSAGE ( " SALOME_Selection::AddOrRemoveIndex " << index << " - " << modeShift )
382 QAD_Desktop* myDesktop = (QAD_Desktop*) QAD_Application::getDesktop();
383 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
385 if ( !myMapIOSubIndex.IsBound( IObject ) ) {
386 TColStd_MapOfInteger Empty;
387 myMapIOSubIndex.Bind( IObject, Empty );
389 TColStd_MapOfInteger& MapIndex = myMapIOSubIndex.ChangeFind( IObject );
391 if ( MapIndex.Contains( index )) {
393 MapIndex.Remove( index );
394 myActiveStudy->highlight( IObject, true, update );
400 MapIndex.Add( index );
401 myActiveStudy->highlight( IObject, true, update );
402 emit currentSelectionChanged();
406 if ( MapIndex.IsEmpty() ) {
407 myMapIOSubIndex.UnBind( IObject );
408 RemoveIObject( IObject, update );
411 emit currentSelectionChanged();
415 void SALOME_Selection::RemoveIndex( const Handle(SALOME_InteractiveObject)& IObject, int index )
417 if ( myMapIOSubIndex.IsBound( IObject ) ) {
418 TColStd_MapOfInteger& MapIndex = myMapIOSubIndex.ChangeFind( IObject );
419 if ( MapIndex.Contains( index ) )
420 MapIndex.Remove( index );