2 // File : SALOME_Selection.cxx
3 // Created : Wed Feb 20 17:24:59 2002
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE 2002
11 \class SALOME_Selection SALOME_Selection.h
12 \brief Selection Mechanism of Interactive Object.
15 #include "SALOME_Selection.h"
16 #include "SALOME_Filter.hxx"
17 #include "SALOME_InteractiveObject.hxx"
18 #include "SALOME_ListIteratorOfListIO.hxx"
19 #include "SALOME_ListIteratorOfListOfFilter.hxx"
21 #include "QAD_Desktop.h"
22 #include "utilities.h"
24 static QList<SALOME_Selection>& SALOME_Sel_GetSelections()
26 static QList<SALOME_Selection> Selections;
30 //=======================================================================
31 // SELECTIONS MANAGEMENT
32 //=======================================================================
37 SALOME_Selection::SALOME_Selection(const QString& aName) :
42 mySelectionMode = 4; /*Actor*/
43 mySelActiveCompOnly = false;
45 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
47 QAD_Application *anActiveApplication = aDesktop->getActiveApp();
48 if (anActiveApplication) QAD_ASSERT(connect(this, SIGNAL(currentSelectionChanged()),anActiveApplication, SLOT(updateActions())));
55 SALOME_Selection::~SALOME_Selection()
60 Create a Selection with name \a aName
61 \return TRUE if the Selection is created. Returns FALSE otherwise.
63 bool SALOME_Selection::CreateSelection(const QString& aName)
65 SALOME_Selection* S = NULL;
66 if ( SALOME_Selection::FindSelection( aName ) )
67 S = SALOME_Selection::Selection( aName );
69 S = new SALOME_Selection(aName);
70 SALOME_Sel_GetSelections().prepend(S);
77 Sets the current Selection with \a aName
79 SALOME_Selection* SALOME_Selection::Selection(const QString& aName)
81 SALOME_Selection* Sel = NULL;
82 if(SALOME_Sel_GetSelections().isEmpty()) return Sel;
84 for( Sel=SALOME_Sel_GetSelections().first(); Sel!=0; Sel=SALOME_Sel_GetSelections().next() ){
85 if( Sel->myName.compare(aName) == 0 )
93 Finds Selection with \a aName
94 \return TRUE if the Selection is found. Returns FALSE otherwise.
96 bool SALOME_Selection::FindSelection(const QString& aName)
98 SALOME_Selection* Sel;
99 for( Sel=SALOME_Sel_GetSelections().first(); Sel!=0; Sel=SALOME_Sel_GetSelections().next() ){
100 if( Sel->myName.compare(aName) == 0 )
108 Removes Selection with \a aName
109 \return TRUE if the Selection is removed. Returns FALSE otherwise.
111 bool SALOME_Selection::RemoveSelection(const QString& aName)
113 SALOME_Selection* Sel;
114 for( Sel=SALOME_Sel_GetSelections().first(); Sel!=0; Sel=SALOME_Sel_GetSelections().next() ){
115 if( Sel->myName.compare(aName) == 0 )
116 return SALOME_Sel_GetSelections().remove(Sel);
123 //=======================================================================
124 // FILTERS MANAGEMENT
125 //=======================================================================
130 void SALOME_Selection::AddFilter(const Handle(SALOME_Filter)& aFilter,
131 bool updateSelection)
133 if ( !FindFilter(aFilter) ) {
134 myFilters.Append( aFilter );
136 SALOME_ListIO removedIObjects;
138 if ( updateSelection ) {
139 SALOME_ListIteratorOfListIO It(myIObjects);
140 for(;It.More();It.Next()){
141 Handle(SALOME_InteractiveObject) Object = It.Value();
142 if( !IsOk(Object) ) {
143 removedIObjects.Append( Object );
144 // RemoveIObject( Object );
148 SALOME_ListIteratorOfListIO It1(removedIObjects);
149 for(;It1.More();It1.Next()){
150 Handle(SALOME_InteractiveObject) Object = It1.Value();
151 RemoveIObject( Object );
160 bool SALOME_Selection::RemoveFilter(const Handle(SALOME_Filter)& aFilter)
162 SALOME_ListIteratorOfListOfFilter It(myFilters);
163 for(;It.More();It.Next()){
164 if (aFilter==It.Value()){
165 myFilters.Remove(It);
172 //! Clears All Filters
173 void SALOME_Selection::ClearFilters()
179 bool SALOME_Selection::FindFilter(const Handle(SALOME_Filter)& aFilter)
181 SALOME_ListIteratorOfListOfFilter It(myFilters);
182 for(;It.More();It.Next())
183 if (aFilter==It.Value())
188 //! Returns the list of stored Filters
189 const SALOME_ListOfFilter& SALOME_Selection::StoredFilters()
196 //=======================================================================
197 // INTERACTIVE OBJECTS MANAGEMENT
198 //=======================================================================
200 void SALOME_Selection::Clear()
205 //! Clears all Interactive Objects
206 void SALOME_Selection::ClearIObjects()
210 QAD_Desktop* myDesktop = (QAD_Desktop*) QAD_Application::getDesktop();
211 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
212 myActiveStudy->unHighlightAll();
214 myMapIOSubIndex.Clear();
216 emit currentSelectionChanged();
219 //! Add an InteractiveObject
220 int SALOME_Selection::AddIObject(const Handle(SALOME_InteractiveObject)& anObject, bool update)
222 QAD_Desktop* myDesktop = (QAD_Desktop*) QAD_Application::getDesktop();
223 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
225 if ( !IsOk(anObject) ) {
226 MESSAGE ( "The Object not authorized by Filters" )
227 myActiveStudy->highlight(anObject,false, update);
232 SALOME_ListIteratorOfListIO It(myIObjects);
233 for(;It.More();It.Next()) {
234 if (anObject->isSame(It.Value())) {
240 // Il n'est pas dedans, on le rajoute....
242 myIObjects.Append( anObject );
243 myActiveStudy->highlight(anObject, true, update);
244 emit currentSelectionChanged();
250 //! Removes an InteractiveObject
251 int SALOME_Selection::RemoveIObject(const Handle(SALOME_InteractiveObject)& anObject, bool update)
253 SALOME_ListIteratorOfListIO It(myIObjects);
254 for(;It.More();It.Next()) {
255 if (anObject->isSame(It.Value())) {
256 QAD_Desktop* myDesktop = (QAD_Desktop*) QAD_Application::getDesktop();
257 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
258 myActiveStudy->highlight(anObject, false, update);
260 if ( myMapIOSubIndex.IsBound( anObject ) ) {
261 myMapIOSubIndex.UnBind( anObject );
264 myIObjects.Remove(It);
266 emit currentSelectionChanged();
273 //! Returns the list of InteractiveObjects
274 const SALOME_ListIO& SALOME_Selection::StoredIObjects()
279 //! Returns the number of InteractiveObjects in the selection.
280 int SALOME_Selection::IObjectCount()
282 return myIObjects.Extent();
285 //! Returns the first InteractiveObject in the selection.
286 Handle(SALOME_InteractiveObject) SALOME_Selection::firstIObject()
288 return myIObjects.First();
291 //! Returns the last InteractiveObject in the selection.
292 Handle(SALOME_InteractiveObject) SALOME_Selection::lastIObject()
294 return myIObjects.Last();
298 Returns TRUE if the InteractiveObject is authorized by Filters. Returns FALSE otherwise.
300 bool SALOME_Selection::IsOk(const Handle(SALOME_InteractiveObject)& anObj)
302 SALOME_ListIteratorOfListOfFilter It(myFilters);
303 for(;It.More();It.Next()){
304 Handle(SALOME_Filter) theFilter = It.Value();
305 if ( !theFilter->IsOk(anObj) )
311 void SALOME_Selection::SetSelectionMode(int mode, bool activeCompOnly)
313 mySelectionMode = mode;
314 mySelActiveCompOnly = activeCompOnly;
317 int SALOME_Selection::SelectionMode()
319 return mySelectionMode;
322 bool SALOME_Selection::IsSelectActiveCompOnly() const
324 return mySelActiveCompOnly;
327 bool SALOME_Selection::HasIndex( const Handle(SALOME_InteractiveObject)& IObject )
329 return myMapIOSubIndex.IsBound(IObject);
332 void SALOME_Selection::GetIndex( const Handle(SALOME_InteractiveObject)& IObject, TColStd_MapOfInteger& theIndex )
334 if ( myMapIOSubIndex.IsBound(IObject) ) {
335 theIndex = myMapIOSubIndex.Find(IObject);
344 bool SALOME_Selection::IsIndexSelected(const Handle(SALOME_InteractiveObject)& IObject, int index)
346 if ( !myMapIOSubIndex.IsBound( IObject ) ) {
349 TColStd_MapOfInteger& MapIndex = myMapIOSubIndex.ChangeFind( IObject );
350 return MapIndex.Contains( index );
356 bool SALOME_Selection::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
361 MESSAGE ( " SALOME_Selection::AddOrRemoveIndex " << index << " - " << modeShift )
362 QAD_Desktop* myDesktop = (QAD_Desktop*) QAD_Application::getDesktop();
363 QAD_Study* myActiveStudy = myDesktop->getActiveStudy();
365 if ( !myMapIOSubIndex.IsBound( IObject ) ) {
366 TColStd_MapOfInteger Empty;
367 myMapIOSubIndex.Bind( IObject, Empty );
369 TColStd_MapOfInteger& MapIndex = myMapIOSubIndex.ChangeFind( IObject );
371 if ( MapIndex.Contains( index )) {
373 MapIndex.Remove( index );
374 myActiveStudy->highlight( IObject, true, update );
380 MapIndex.Add( index );
381 myActiveStudy->highlight( IObject, true, update );
382 emit currentSelectionChanged();
386 if ( MapIndex.IsEmpty() ) {
387 myMapIOSubIndex.UnBind( IObject );
388 RemoveIObject( IObject, update );
391 emit currentSelectionChanged();
395 void SALOME_Selection::RemoveIndex( const Handle(SALOME_InteractiveObject)& IObject, int index )
397 if ( myMapIOSubIndex.IsBound( IObject ) ) {
398 TColStd_MapOfInteger& MapIndex = myMapIOSubIndex.ChangeFind( IObject );
399 if ( MapIndex.Contains( index ) )
400 MapIndex.Remove( index );