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