0024837: Visualization - revise design and implementation of connected Interactive...
[occt.git] / src / SelectMgr / SelectMgr_SelectionManager.cxx
CommitLineData
b311480e 1// Created on: 1995-02-13
2// Created by: Mister rmi
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <SelectMgr_SelectionManager.ixx>
18#include <SelectMgr_ViewerSelector.hxx>
19#include <SelectMgr_Selection.hxx>
20#include <SelectMgr_SequenceOfSelector.hxx>
21#include <TColStd_MapIteratorOfMapOfTransient.hxx>
22#include <TColStd_MapIteratorOfMapOfTransient.hxx>
23#include <TCollection_AsciiString.hxx>
24#include <TColStd_ListOfInteger.hxx>
25#include <TColStd_ListIteratorOfListOfInteger.hxx>
26#include <SelectMgr_DataMapIteratorOfDataMapOfObjectSelectors.hxx>
27#include <OSD_Environment.hxx>
28
29
30static Standard_Boolean SelectDebugModeOnSM()
31{
32 static Standard_Integer isDebugMode( -1 );
33 if ( isDebugMode < 0 ) {
34 isDebugMode = 1;
35 OSD_Environment selectdb("SELECTIONDEBUG");
36 if ( selectdb.Value().IsEmpty() )
37 isDebugMode = 0;
38 }
39 return ( isDebugMode != 0 );
40}
41
42static Standard_Integer SMSearch(const SelectMgr_SequenceOfSelector& seq,
43 const Handle(SelectMgr_ViewerSelector)& theSel)
44{
45 Standard_Integer ifound=0;
46 for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++)
47 {if(theSel==seq.Value(i)) ifound=i;}
48 return ifound;
49
50}
51
7fd59977 52//==================================================
53// Function: Create
54// Purpose :
55//==================================================
56
57SelectMgr_SelectionManager::SelectMgr_SelectionManager()
58{}
59
60
61//==================================================
62// Function: Add
63// Purpose :
64//==================================================
65void SelectMgr_SelectionManager::
66Add (const Handle(SelectMgr_ViewerSelector)& aViewSel)
67{
68 myselectors.Add(aViewSel);
69}
70
71
72
73//==================================================
74// Function: Remove
75// Purpose :
76//==================================================
77void SelectMgr_SelectionManager::
78Remove (const Handle(SelectMgr_ViewerSelector)& aViewSel)
79{
80 SelectMgr_DataMapIteratorOfDataMapOfObjectSelectors It(mylocal);
81 for(;It.More();It.Next())
82 {
83 SelectMgr_SequenceOfSelector& theviews =mylocal.ChangeFind(It.Key());
84 Standard_Integer rank = SMSearch(theviews,aViewSel);
85 if(rank!=0 && rank<=theviews.Length()) theviews.Remove(rank);
86 }
87 if(myselectors.Contains(aViewSel)) myselectors.Remove(aViewSel);
88}
89
90//==================================================
91// Function: Contains
92// Purpose :
93//==================================================
94Standard_Boolean SelectMgr_SelectionManager::
95Contains (const Handle(SelectMgr_ViewerSelector)& aViewSel) const
96{return myselectors.Contains(aViewSel);}
97
98//==================================================
99// Function: Contains
100// Purpose :
101//==================================================
102Standard_Boolean SelectMgr_SelectionManager::
103Contains (const Handle(SelectMgr_SelectableObject)& aSelObj) const
104{if (myglobal.Contains(aSelObj)) return Standard_True;
105if (mylocal.IsBound(aSelObj)) return Standard_True;
106return Standard_False;
107}
108
109
110
111//==================================================
112// Function: Load
113// Purpose :
114//==================================================
115
116void SelectMgr_SelectionManager::
117Load (const Handle(SelectMgr_SelectableObject)& anObject,
118 const Standard_Integer amode)
119{
120 if(!myglobal.Contains(anObject))
121 myglobal.Add(anObject);
122 if(amode!=-1)
123 LoadMode (anObject,amode);
124}
125
126
127//==================================================
128// Function: Load
129// Purpose :
130//==================================================
131void SelectMgr_SelectionManager::
132Load (const Handle(SelectMgr_SelectableObject)& anObject,
133 const Handle(SelectMgr_ViewerSelector)& aview,
134 const Standard_Integer amode)
135{
136 if(!myselectors.Contains(aview)) myselectors.Add(aview);
137 if(amode!=-1)
138 LoadMode (anObject,amode);
139
140
141 if (mylocal.IsBound(anObject)){
142 SelectMgr_SequenceOfSelector& theviews = mylocal.ChangeFind(anObject);
143 if (SMSearch(theviews,aview)==0) theviews.Append(aview);
144 }
145 else {
146 if(!myglobal.Contains(anObject)){
147 SelectMgr_SequenceOfSelector newviews;
148 newviews.Append(aview);
149 mylocal.Bind(anObject,newviews);
150 }
151 }
152}
153
154
155//==================================================
156// Function: Remove
157// Purpose :
158//==================================================
159
160void SelectMgr_SelectionManager::
161Remove(const Handle(SelectMgr_SelectableObject)& anObject)
162{
163
164 if(myglobal.Contains(anObject)) {
165 TColStd_MapIteratorOfMapOfTransient It(myselectors);
166 for(;It.More();It.Next())
167 {
168 Handle(SelectMgr_ViewerSelector) curview =
169 Handle(SelectMgr_ViewerSelector)::DownCast(It.Key());
170 if(curview->Contains(anObject)){
171 for(anObject->Init();anObject->More();anObject->Next())
172 {
173 curview->Remove(anObject->CurrentSelection());
174 }
175
176 }
177 }
178 myglobal.Remove(anObject);
179 }
180
181 else if(mylocal.IsBound(anObject)) {
182 SelectMgr_SequenceOfSelector& seq = mylocal.ChangeFind (anObject);
183 for (Standard_Integer i=1;i<=seq.Length();i++) {
184 Handle(SelectMgr_ViewerSelector) curview =
185 Handle(SelectMgr_ViewerSelector)::DownCast(seq(i));
186 if(curview->Contains(anObject)){
187 for(anObject->Init();anObject->More();anObject->Next())
188 {
189 curview->Remove(anObject->CurrentSelection());
190 }
191 }
192
193 }
194 mylocal.UnBind(anObject);
195 }
196}
197
198//==================================================
199// Function: Remove
200// Purpose :
201//==================================================
202
203void SelectMgr_SelectionManager::
204Remove(const Handle(SelectMgr_SelectableObject)& anObject,
205 const Handle(SelectMgr_ViewerSelector)& aVS)
206{
207 if(aVS->Contains(anObject)) {
208 for(anObject->Init();anObject->More();anObject->Next()){
209 aVS->Remove(anObject->CurrentSelection());
210 }
211
212
213 if(mylocal.IsBound(anObject)) {
214 SelectMgr_SequenceOfSelector& seq = mylocal.ChangeFind (anObject);
215 Standard_Boolean NotFound (Standard_True);
216 for (Standard_Integer i=1;i<=seq.Length()&&NotFound;i++) {
217 if(seq(i)== aVS){
218 seq.Remove(i);
219 NotFound =Standard_False;
220 }
221 }
222 if(seq.IsEmpty())
223 mylocal.UnBind(anObject);
224 }
225 }
226}
227
228//==================================================
229// Function: Activate
230// Purpose :
231//==================================================
232
233void SelectMgr_SelectionManager::
234Activate(const Handle(SelectMgr_SelectableObject)& anObject,
235 const Standard_Integer aMode,
236 const Standard_Boolean AutomaticProj)
237{
238 if(aMode==-1) return;
239 // Standard_Boolean global = Standard_False;
240 if(!anObject->HasSelection(aMode)) LoadMode(anObject,aMode);
241
242
243 if(myglobal.Contains(anObject)) {
244 TColStd_MapIteratorOfMapOfTransient It(myselectors);
245
246 for(;It.More();It.Next()){
247 Handle(SelectMgr_ViewerSelector) curview =
248 Handle(SelectMgr_ViewerSelector)::DownCast(It.Key());
249 Activate(anObject,aMode,curview,AutomaticProj);
250 }
251 }
252
253 else if(mylocal.IsBound(anObject)) {
254 SelectMgr_SequenceOfSelector& seq = mylocal.ChangeFind (anObject);
255 for (Standard_Integer i=1;i<=seq.Length();i++) {
256 Handle(SelectMgr_ViewerSelector) curview =
257 Handle(SelectMgr_ViewerSelector)::DownCast(seq(i));
258 // ATTENTION : si la selection est a remettre a jour, on le fait la ....
259 const Handle(SelectMgr_Selection)& Sel = anObject->Selection(aMode);
260
261 switch(Sel->UpdateStatus()){
262 case SelectMgr_TOU_Full:
263 anObject->UpdateSelection(aMode); // pas de break expres...
264 case SelectMgr_TOU_Partial:
265 {
0717ddc1 266 if(anObject->HasTransformation())
267 anObject->UpdateTransformation(Sel);
7fd59977 268 Sel->UpdateStatus(SelectMgr_TOU_None);
269 break;
270 }
7fd59977 271 default:
272 break;
7fd59977 273 }
274
275 curview->Activate(Sel,AutomaticProj);
276 }
277 }
278}
279
280
281//==================================================
282// Function: Activate
283// Purpose :
284//==================================================
285
286void SelectMgr_SelectionManager::
287Activate(const Handle(SelectMgr_SelectableObject)& anObject,
288 const Standard_Integer aMode,
289 const Handle(SelectMgr_ViewerSelector)& aViewSel,
290 const Standard_Boolean AutomaticProj)
291{
292 if(aMode==-1) return;
293
294 if(!myselectors.Contains(aViewSel)) return;
295
296 if (!anObject->HasSelection(aMode)) LoadMode(anObject,aMode);
297
7fd59977 298 const Handle(SelectMgr_Selection)& Sel = anObject->Selection(aMode);
299
300 switch(Sel->UpdateStatus()){
301 case SelectMgr_TOU_Full:
302 anObject->UpdateSelection(aMode);
303 case SelectMgr_TOU_Partial:
304 {
0717ddc1 305 if(anObject->HasTransformation())
306 anObject->UpdateTransformation(Sel);
7fd59977 307 break;
308 }
7fd59977 309 default:
310 break;
7fd59977 311 }
312 Sel->UpdateStatus(SelectMgr_TOU_None);
313
314 if (myglobal.Contains(anObject))
315 aViewSel->Activate (anObject->Selection(aMode));
316
317 else {
318 if (mylocal.IsBound(anObject)) {
319 if (SMSearch(mylocal.Find(anObject),aViewSel)==0)
320 (mylocal.ChangeFind (anObject)).Append(aViewSel);
321 aViewSel->Activate (anObject->Selection(aMode),AutomaticProj);
322 }
323 }
324}
325
326//==================================================
327// Function: Deactivate
328// Purpose :
329//==================================================
330
331void SelectMgr_SelectionManager::
332Deactivate(const Handle(SelectMgr_SelectableObject)& anObject)
333{
334 Standard_Boolean global = Standard_False;
335 if(myglobal.Contains(anObject)) global = Standard_True;
336 TColStd_MapIteratorOfMapOfTransient It(myselectors);
337 Handle(SelectMgr_ViewerSelector) curview;
338 for(;It.More();It.Next()){
339 curview = Handle(SelectMgr_ViewerSelector)::DownCast(It.Key());
340 if (global || mylocal.IsBound (anObject)) {
341 for (anObject->Init();anObject->More();anObject->Next())
342 {curview->Deactivate(anObject->CurrentSelection());}
343
344 }
345
346 }
347}
348
349//==================================================
350// Function: Deactivate
351// Purpose :
352//==================================================
353
354void SelectMgr_SelectionManager::
355Deactivate(const Handle(SelectMgr_SelectableObject)& anObject,
356 const Standard_Integer amode)
357
358{
359 Standard_Boolean global = Standard_False;
360 if(myglobal.Contains(anObject)) global = Standard_True;
361 TColStd_MapIteratorOfMapOfTransient It(myselectors);
362 Handle(SelectMgr_ViewerSelector) curview;
363 for(;It.More();It.Next()){
364 curview = Handle(SelectMgr_ViewerSelector)::DownCast(It.Key());
365 if (global || mylocal.IsBound(anObject)) {
366 if(anObject->HasSelection(amode))
367 curview->Deactivate(anObject->Selection(amode));
368
369 }
370 }
371}
372
373//==================================================
374// Function: Deactivate
375// Purpose :
376//==================================================
377
378void SelectMgr_SelectionManager::
379Deactivate(const Handle(SelectMgr_SelectableObject)& anObject,
380 const Standard_Integer aMode,
381 const Handle(SelectMgr_ViewerSelector)& aViewSel)
382{
383 if(myselectors.Contains(aViewSel))
384 {
385 if(myglobal.Contains(anObject)|| mylocal.IsBound(anObject))
386 if(anObject->HasSelection(aMode))
387 aViewSel->Deactivate (anObject->Selection(aMode));
388 }
389
390}
391//==================================================
392// Function: Deactivate
393// Purpose :
394//==================================================
395
396void SelectMgr_SelectionManager::
397Deactivate(const Handle(SelectMgr_SelectableObject)& anObject,
398 const Handle(SelectMgr_ViewerSelector)& aViewSel)
399
400{
401 if(myselectors.Contains(aViewSel))
402 {
403 if(myglobal.Contains(anObject)|| mylocal.IsBound(anObject)) {
404 for (anObject->Init();anObject->More();anObject->Next())
405 {aViewSel->Deactivate(anObject->CurrentSelection());}}
406
407 }
408
409}
410
411
412//==================================================
413// Function: Sleep
414// Purpose :
415//==================================================
416void SelectMgr_SelectionManager::
417Sleep (const Handle(SelectMgr_ViewerSelector)& aViewSel)
418{
419 if (myselectors.Contains(aViewSel))
420 aViewSel->Sleep();
421}
422
423void SelectMgr_SelectionManager::
424Sleep (const Handle(SelectMgr_SelectableObject)& anObject)
425{
426
427 if(myglobal.Contains(anObject)){
428 for( TColStd_MapIteratorOfMapOfTransient It(myselectors);
429 It.More();It.Next())
430 Handle(SelectMgr_ViewerSelector)::DownCast(It.Key())->Sleep(anObject);
431 }
432 else if(mylocal.IsBound(anObject)){
433 const SelectMgr_SequenceOfSelector & VSeq = mylocal(anObject);
434 for (Standard_Integer I=1;I<=VSeq.Length();I++)
435 VSeq(I)->Sleep(anObject);
436 }
437
438
439}
440
441//=======================================================================
442//function : Sleep
443//purpose :
444//=======================================================================
445void SelectMgr_SelectionManager::
446Sleep(const Handle(SelectMgr_SelectableObject)& anObject,
447 const Handle(SelectMgr_ViewerSelector)& aViewSel)
448{
449 if(!myselectors.Contains(aViewSel)) return;
450
451 if(!myglobal.Contains(anObject)){
452 if(!mylocal.IsBound(anObject))
453 return;
454 if(SMSearch(mylocal(anObject),aViewSel)==0)
455 return;
456 }
457 aViewSel->Sleep(anObject);
458}
459
460
461
462//==================================================
463// Function: Awake
464// Purpose :
465//==================================================
466void SelectMgr_SelectionManager::
467Awake (const Handle(SelectMgr_ViewerSelector)& aViewSel,
468 const Standard_Boolean AutomaticProj)
469{
470 if (myselectors.Contains(aViewSel))
471 aViewSel->Awake(AutomaticProj);
472}
473
474
475//=======================================================================
476//function : Awake
477//purpose :
478//=======================================================================
479void SelectMgr_SelectionManager::Awake (const Handle(SelectMgr_SelectableObject)& anObject,
480 const Standard_Boolean AutomaticProj)
481{
482 if(myglobal.Contains(anObject)){
483 for( TColStd_MapIteratorOfMapOfTransient It(myselectors);
484 It.More();It.Next())
485 Handle(SelectMgr_ViewerSelector)::DownCast( It.Key())->Awake(anObject,AutomaticProj);
486 }
487 else if(mylocal.IsBound(anObject)){
488 const SelectMgr_SequenceOfSelector & VSeq = mylocal(anObject);
489 for (Standard_Integer I=1;I<=VSeq.Length();I++)
490 VSeq(I)->Awake(anObject,AutomaticProj);
491 }
492}
493
494//=======================================================================
495//function : Awake
496//purpose :
497//=======================================================================
498void SelectMgr_SelectionManager::Awake (const Handle(SelectMgr_SelectableObject)& anObject,
499 const Handle(SelectMgr_ViewerSelector)& aViewSel,
500 const Standard_Boolean AutomaticProj)
501{
502 if(!myselectors.Contains(aViewSel)) return;
503
504 if(!myglobal.Contains(anObject)){
505 if(!mylocal.IsBound(anObject))
506 return;
507 if(SMSearch(mylocal(anObject),aViewSel)==0)
508 return;
509 }
510 aViewSel->Awake(anObject,AutomaticProj);
511
512}
513
514
515//=======================================================================
516//function : IsActivated
517//purpose :
518//=======================================================================
519Standard_Boolean SelectMgr_SelectionManager::IsActivated(const Handle(SelectMgr_SelectableObject)& anObject) const
520{
521 for(anObject->Init();anObject->More();anObject->Next()){
522 if(IsActivated(anObject,anObject->CurrentSelection()->Mode()))
523 return Standard_True;
524 }
525 return Standard_False;
526}
527//=======================================================================
528//function : IsActivated
529//purpose :
530//=======================================================================
531Standard_Boolean SelectMgr_SelectionManager::IsActivated(const Handle(SelectMgr_SelectableObject)& anObject,
532 const Standard_Integer aMode) const
533{
534 if(!anObject->HasSelection(aMode)) return Standard_False;
535 if (!(myglobal.Contains(anObject) || mylocal.IsBound(anObject)))
536 return Standard_False;
537
538 Handle(Standard_Transient) Tr;
539 const Handle(SelectMgr_Selection)& Sel = anObject->Selection(aMode);
540 for(TColStd_MapIteratorOfMapOfTransient It(myselectors);It.More();It.Next()){
541 Tr = It.Key();
542 Handle(SelectMgr_ViewerSelector) VS = *((Handle(SelectMgr_ViewerSelector)*)&Tr);
543 if(VS->Status(Sel)==SelectMgr_SOS_Activated)
544 return Standard_True;
545 }
546 return Standard_False;
547
548}
549
550//=======================================================================
551//function : IsActivated
552//purpose :
553//=======================================================================
554Standard_Boolean SelectMgr_SelectionManager::IsActivated(const Handle(SelectMgr_SelectableObject)& anObject,
555 const Handle(SelectMgr_ViewerSelector)& VS,
556 const Standard_Integer aMode) const
557{
558 if(!anObject->HasSelection(aMode))
559 return Standard_False;
560 if(!myselectors.Contains(VS))
561 return Standard_False;
562 if (!(myglobal.Contains(anObject) || mylocal.IsBound(anObject)))
563 return Standard_False;
564 const Handle(SelectMgr_Selection)& Sel = anObject->Selection(aMode);
565 return (VS->Status(Sel)==SelectMgr_SOS_Activated);
566}
567
568//==================================================
569// Function: Update
570// Purpose :
571//==================================================
572void SelectMgr_SelectionManager::
573RecomputeSelection (const Handle(SelectMgr_SelectableObject)& anObject,
574 const Standard_Boolean ForceUpdate,
575 const Standard_Integer aMode)
576{
577 if( SelectDebugModeOnSM() ) cout<<"===>SelectMgr_SelectionManager::Update"<<endl;
578
579 if(ForceUpdate){
81bba717 580 if( SelectDebugModeOnSM() ) cout<<"\t Global Recalculation of selections"<<endl;
7fd59977 581 if(aMode==-1){
582 anObject->UpdateSelection();
0717ddc1 583 anObject->UpdateTransformation();
7fd59977 584 }
585 else if(anObject->HasSelection(aMode)){
586 anObject->UpdateSelection(aMode);
0717ddc1 587 anObject->UpdateTransformation();
7fd59977 588 }
589 return;
590 }
81bba717 591 // objet is not known to SMgr.
7fd59977 592 if (!(myglobal.Contains(anObject) || mylocal.IsBound(anObject))){
81bba717 593 if( SelectDebugModeOnSM() ) {cout<<"\t Object not loaded in the SelectionManager"<<endl;
594 cout<<"\t eventual selections are flagged"<<endl;}
7fd59977 595 if( aMode == -1 ){
596 for(anObject->Init();anObject->More();anObject->Next()){
597 if( SelectDebugModeOnSM() ) cout<<"\t\t Mode "<<anObject->CurrentSelection()->Mode()<<" ";
598 anObject->CurrentSelection()->UpdateStatus(SelectMgr_TOU_Full);
599 }
600 if( SelectDebugModeOnSM() )
601 cout << endl;
602 }
603 else if (anObject->HasSelection(aMode))
604 anObject->Selection(aMode)->UpdateStatus(SelectMgr_TOU_Full);
605 }
606
81bba717 607 // recalculate whatever is required
608 // and set flag on top...
7fd59977 609 else{
610 TColStd_MapIteratorOfMapOfTransient It;
611 Handle(Standard_Transient) Tr;
612 Standard_Boolean Found;
81bba717 613 // object selections are parsed
7fd59977 614
615 for(anObject->Init();anObject->More();anObject->Next()){
616 const Handle(SelectMgr_Selection)& Sel = anObject->CurrentSelection();
617 Sel->UpdateStatus(SelectMgr_TOU_Full);
618 Standard_Integer curmode = Sel->Mode();
619 Found = Standard_False;
620
81bba717 621 // parsing of selections ...
7fd59977 622 for(It.Initialize(myselectors);It.More();It.Next()){
623 Tr = It.Key();
624 Handle(SelectMgr_ViewerSelector) VS = *((Handle(SelectMgr_ViewerSelector)*)&Tr);
625 if(VS->Status(Sel)==SelectMgr_SOS_Activated){
626 Found = Standard_True;
627 switch(Sel->UpdateStatus()){
628 case SelectMgr_TOU_Full:
81bba717 629 anObject->UpdateSelection(curmode); // no break on purpose...
7fd59977 630 case SelectMgr_TOU_Partial:
0717ddc1 631 anObject->UpdateTransformation(Sel);
7fd59977 632 break;
7fd59977 633 default:
634 break;
7fd59977 635 }
636 if(Found){
637 VS->Convert(Sel);
638 Sel->UpdateStatus(SelectMgr_TOU_None);
639 }
640 }
641 }
642 }
643 }
644}
645
646//=======================================================================
647//function : Update
81bba717 648//purpose : Selections are recalculated if they are flagged
649// "TO RECALCULATE" and activated in one of selectors.
650// If ForceUpdate = True, and they are "TO RECALCULATE"
651// This is done without caring for the state of activation.
7fd59977 652//=======================================================================
653void SelectMgr_SelectionManager::Update(const Handle(SelectMgr_SelectableObject)& anObject,
654 const Standard_Boolean ForceUpdate)
655{
0717ddc1 656 PrsMgr_ListOfPresentableObjectsIter anIter (anObject->Children());
657 for (; anIter.More(); anIter.Next())
658 {
659 const Handle(SelectMgr_SelectableObject) aSelectable = Handle(SelectMgr_SelectableObject)::DownCast (anIter.Value());
660
661 if (!aSelectable.IsNull())
662 {
663 Update (aSelectable, ForceUpdate);
664 }
665 }
666
7fd59977 667 Standard_Boolean wasrecomputed;
668
669 for(anObject->Init();anObject->More();anObject->Next()){
670 const Handle(SelectMgr_Selection)& Sel = anObject->CurrentSelection();
671 wasrecomputed = Standard_False;
672 if(ForceUpdate){
673 switch(Sel->UpdateStatus()){
674 case SelectMgr_TOU_Full:
81bba717 675 anObject->UpdateSelection(Sel->Mode()); // no break on purpose...
7fd59977 676 case SelectMgr_TOU_Partial:
0717ddc1 677 anObject->UpdateTransformation(Sel);
7fd59977 678 wasrecomputed = Standard_True;
679 break;
7fd59977 680 default:
681 break;
7fd59977 682 }
683 Sel->UpdateStatus(SelectMgr_TOU_None);
684 }
685
81bba717 686 // it is checked which selectors are concerned by the selection
687 // to redo projections if necessary.
7fd59977 688 Handle(Standard_Transient) Tr;
689 for(TColStd_MapIteratorOfMapOfTransient It(myselectors);It.More();It.Next()){
690 Tr = It.Key();
691 Handle(SelectMgr_ViewerSelector) VS = *((Handle(SelectMgr_ViewerSelector)*)&Tr);
692 if(VS->Status(Sel)==SelectMgr_SOS_Activated)
693 switch(Sel->UpdateStatus()){
694 case SelectMgr_TOU_Full:
81bba717 695 anObject->UpdateSelection(Sel->Mode()); // no break on purpose...
7fd59977 696 case SelectMgr_TOU_Partial:
0717ddc1 697 anObject->UpdateTransformation(Sel);
7fd59977 698 wasrecomputed = Standard_True;
699 break;
7fd59977 700 default:
701 break;
7fd59977 702 }
703 if(wasrecomputed)
704 VS->Convert(Sel);
705 Sel->UpdateStatus(SelectMgr_TOU_None);
706 }
707 }
708}
709
710
711//==================================================
712// Function: Update
81bba717 713// Purpose : Attention, it is required to know what is done...
7fd59977 714//==================================================
715void SelectMgr_SelectionManager::
716Update(const Handle(SelectMgr_SelectableObject)& anObject,
717 const Handle(SelectMgr_ViewerSelector)& aViewSel,
718 const Standard_Boolean ForceUpdate)
719{
720 if( SelectDebugModeOnSM() ) cout<<"==>SelectMgr_SelectionManager::Update(obj,VS)"<<endl;
721 if(!myselectors.Contains(aViewSel)) return;
722
723 Standard_Boolean okay = myglobal.Contains(anObject);
724 if(!okay)
725 okay = (mylocal.IsBound(anObject) && (SMSearch(mylocal.Find(anObject),aViewSel)!=0)) ;
726 if(!okay) return;
727
728
729 //
730 Standard_Boolean wasrecomputed;
731 for(anObject->Init();anObject->More();anObject->Next()){
732 const Handle(SelectMgr_Selection)& Sel = anObject->CurrentSelection();
733 wasrecomputed = Standard_False;
734 if(ForceUpdate){
735 switch(Sel->UpdateStatus()){
736 case SelectMgr_TOU_Full:
81bba717 737 anObject->UpdateSelection(Sel->Mode()); // no break on purpose...
7fd59977 738 case SelectMgr_TOU_Partial:
0717ddc1 739 anObject->UpdateTransformation(Sel);
7fd59977 740 wasrecomputed = Standard_True;
741 break;
7fd59977 742 default:
743 break;
7fd59977 744 }
745 Sel->UpdateStatus(SelectMgr_TOU_None);
746 }
747
748 if(aViewSel->Status(Sel) == SelectMgr_SOS_Activated){
749 switch(Sel->UpdateStatus()){
750 case SelectMgr_TOU_Full:
751 anObject->UpdateSelection(Sel->Mode());
752 case SelectMgr_TOU_Partial:
0717ddc1 753 if(anObject->HasTransformation())
754 anObject->UpdateTransformation(Sel);
7fd59977 755 wasrecomputed = Standard_True;
756 break;
7fd59977 757 default:
758 break;
7fd59977 759 }
760 if(wasrecomputed)
761 aViewSel->Convert(Sel);
762 Sel->UpdateStatus(SelectMgr_TOU_None);
763 }
764 }
765}
766
767//==================================================
768// Function: Status
769// Purpose :
770//==================================================
771TCollection_AsciiString SelectMgr_SelectionManager::
772Status() const{
773 TCollection_AsciiString theMgrStatus("\t\t\tStatus of the SelectManager :;\n\t\t\t============================\n");
774
775 TCollection_AsciiString nbview (myselectors.Extent()),nbglobal(myglobal.Extent());
776
777 theMgrStatus += "\t Number of ViewerSelectors: ";
778 theMgrStatus += nbview + "\n\t Number of global objects : " + nbglobal+"\n";
779 theMgrStatus = theMgrStatus+"\t Number of local objects : " + TCollection_AsciiString (mylocal.Extent())+" \n";
780
781 return theMgrStatus;
782}
783
784//==================================================
785// Function: Status
786// Purpose :
787//==================================================
788
789
790TCollection_AsciiString SelectMgr_SelectionManager::
791Status(const Handle(SelectMgr_SelectableObject)& anObject) const
792{
793 TCollection_AsciiString TheStatus("\t\tStatus of object:");
794
795 if(myglobal.Contains(anObject))
796 {TheStatus += "GLOBAL (available for all viewers in the SelectionManager)\n";}
797 else if (mylocal.IsBound(anObject))TheStatus +="LOCAL:\n\t\t";
798 TColStd_MapIteratorOfMapOfTransient It(myselectors);
799 Standard_Integer iv = 0;
800 // Standard_Boolean FirstTime=Standard_True;
801 for(;It.More();It.Next()){
802 const Handle(SelectMgr_ViewerSelector)& curview =
803 Handle(SelectMgr_ViewerSelector)::DownCast(It.Key());
804 iv++;
805 TheStatus = TheStatus + "status in the ViewerSelector :"+TCollection_AsciiString(iv)+"\n\t\t";
806 TheStatus+=curview->Status(anObject);
807 TheStatus+="\n\t\t----------------------\n\t\t";
808 }
809
810 return TheStatus;
811
812}
813
814//==================================================
815// Function: LoadMode
816// Purpose : Private Method
817//==================================================
818
819
820void SelectMgr_SelectionManager
821::LoadMode (const Handle(SelectMgr_SelectableObject)& anObject,
822 const Standard_Integer amode)
823{
824 if(amode==-1) return;
825 if(!anObject->HasSelection(amode))
826 {
827 Handle(SelectMgr_Selection) NewSel = new SelectMgr_Selection(amode);
828 anObject->AddSelection (NewSel,amode);
829 }
830}
831
832
833//=======================================================================
834//function : SetUpdateMode
835//purpose :
836//=======================================================================
837
838void SelectMgr_SelectionManager::
839SetUpdateMode(const Handle(SelectMgr_SelectableObject)& anObject,
840 const SelectMgr_TypeOfUpdate aType)
841{
842 for(anObject->Init();anObject->More();anObject->Next())
843 anObject->CurrentSelection()->UpdateStatus(aType);
844
845}
846
847void SelectMgr_SelectionManager::
848SetUpdateMode(const Handle(SelectMgr_SelectableObject)& anObject,
849 const Standard_Integer aMode,
850 const SelectMgr_TypeOfUpdate aType)
851{
852 if(anObject->HasSelection(aMode))
853 anObject->Selection(aMode)->UpdateStatus(aType);
854}
855