b616ec9b7d725593f71abb84d0ea7e01cb8d04c5
[occt.git] / src / AIS / AIS_LocalContext.cxx
1 // File:        AIS_LocalContext.cxx
2 // Created:     Fri Jan 17 13:36:48 1997
3 // Author:      Robert COUBLANC
4 //              <rob@robox.paris1.matra-dtv.fr>
5 //Modified by ROB : Traque des UpdateConversion intempestifs.
6
7 #define BUC60688       //GG 25/05/00 Add SetSensitivity() methods.
8
9 #define BUC60722        //GG_040900 Disable detection on an unviewable object
10
11 #define IMP160701       //SZV Add InitDetected(),MoreDetected(),NextDetected(),
12 //                       DetectedCurrentShape(),DetectedCurrentObject()
13 //                       methods
14
15 #define ALE70590        //GG  Avoid raise especially under W2000-SP2
16 //              when opening many local context due to a
17 //              system error in the selection name computation routine.
18 //              Many thanks to Philippe CARRET for the helpfull he has 
19 //              give to accelerate the resolution of this problem.
20
21 #include <AIS_LocalContext.ixx>
22 #include <SelectMgr_OrFilter.hxx>
23 #include <SelectMgr_CompositionFilter.hxx>
24 #include <AIS_LocalStatus.hxx>
25 #include <AIS_Shape.hxx>
26 #include <TColStd_ListIteratorOfListOfInteger.hxx>
27 #include <AIS_ListIteratorOfListOfInteractive.hxx>
28 #include <AIS_ListOfInteractive.hxx>
29 #include <AIS_DataMapIteratorOfDataMapOfSelStat.hxx>
30 #include <TopAbs_ShapeEnum.hxx>
31 #include <Graphic3d_Structure.hxx>
32 #include <Prs3d_LineAspect.hxx>
33 #include <Prs3d_PlaneAspect.hxx>
34 #include <Prs3d_PointAspect.hxx>
35 #include <Prs3d_Presentation.hxx>
36 #include <Aspect_TypeOfMarker.hxx>
37 #include <StdSelect_ShapeTypeFilter.hxx>
38 #include <AIS_Selection.hxx>
39 #include <V3d_Viewer.hxx>
40 #include <V3d_View.hxx>
41 #include <Visual3d_TransientManager.hxx>
42 #include <Visual3d_View.hxx>
43
44 #ifdef ALE70590
45 #include <stdio.h>
46 #else
47 #include <Standard_SStream.hxx>
48 #endif
49
50 static TCollection_AsciiString AIS_Local_SelName(const Standard_Address address,
51                                                  const Standard_Integer anIndex)
52 {
53 //  TCollection_AsciiString SelName;
54 #ifdef ALE70590
55   char string[100];
56   sprintf(string,"%p_%d", address, anIndex);    // works under any system 
57   TCollection_AsciiString SelName(string);
58 #else
59   Standard_SStream stream;
60   stream<<address;      // something is wrong here using the SStream because
61 //              the following access to rdbuf crash for an unknown reason 
62 //              especially under W2000 with SP2 and sometime under WNT and W98.
63 //              NOTE that stream is not ended by a NULL char and it's probably
64 //              one of the reasons why this crash.
65 //              In any case the resulting ascii string give a wrong and random
66 //              name under WINDOWS !
67   TCollection_AsciiString SelName(stream.rdbuf()->str());
68 //  SelName = TCollection_AsciiString("AIS_Local_");
69   TCollection_AsciiString theind(anIndex);
70   SelName += "_";
71   SelName += theind;
72 #endif
73   return SelName;
74 }
75
76
77 //=======================================================================
78 //function : AIS_LocalContext
79 //purpose  : 
80 //=======================================================================
81
82
83 AIS_LocalContext::AIS_LocalContext(){}
84
85 AIS_LocalContext::AIS_LocalContext(const Handle(AIS_InteractiveContext)& aCtx,
86                                    const Standard_Integer Index,
87                                    const Standard_Boolean LoadDisplayed,
88                                    const Standard_Boolean AcceptStandardModes,
89                                    const Standard_Boolean AcceptEraseOfTemp,
90                                    const Standard_Boolean BothViewers):
91 myCTX(aCtx),
92 myLoadDisplayed(LoadDisplayed),
93 myAcceptStdMode(AcceptStandardModes),
94 myAcceptErase(AcceptEraseOfTemp),
95 mySM(aCtx->SelectionManager()),
96 myMainVS(new StdSelect_ViewerSelector3d(aCtx->MainSelector()->Projector())),
97 myFilters(new SelectMgr_OrFilter()),
98 myAutoHilight(Standard_True),
99 mylastindex(0),
100 mylastgood(0),
101 myCurDetected(0)
102 #ifdef IMP160701
103 ,myAISCurDetected(0)
104 #endif
105 {
106   myMainPM = aCtx->MainPrsMgr();
107   mySelName = AIS_Local_SelName(this, Index);
108   AIS_Selection::CreateSelection(mySelName.ToCString());
109
110   mySM->Add(myMainVS);
111   if(myLoadDisplayed) LoadContextObjects();
112   Process(Standard_False);
113
114 }
115
116
117 //=======================================================================
118 //function : SetContext
119 //purpose  : 
120 //=======================================================================
121
122 void AIS_LocalContext::SetContext(const Handle(AIS_InteractiveContext)& aCtx)
123 {  myCTX = aCtx;}
124
125 //=======================================================================
126 //function : Display
127 //purpose  : 
128 //=======================================================================
129
130 Standard_Boolean AIS_LocalContext::Display(const Handle(AIS_InteractiveObject)& anInteractive,
131                                            const Standard_Integer WhichMode,
132                                            const Standard_Boolean AllowShapeDecomposition,
133                                            const Standard_Integer ActivationMode)
134 {
135   if(myActiveObjects.IsBound(anInteractive)){
136     const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
137     
138     if(STAT->DisplayMode() == -1){
139       if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
140         myMainPM->Display(anInteractive,WhichMode);
141       if(STAT->IsTemporary())
142         STAT->SetDisplayMode(WhichMode);
143     }
144     else if(STAT->DisplayMode()!=WhichMode && STAT->IsTemporary()){
145       myMainPM->Erase(anInteractive,STAT->DisplayMode());
146       STAT->SetDisplayMode(WhichMode);
147       if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
148         myMainPM->Display(anInteractive,WhichMode);
149     }
150     
151     if(ActivationMode!=-1){
152       if(!STAT->IsActivated(ActivationMode)){
153         STAT->ClearSelectionModes();
154         mySM->Load(anInteractive,myMainVS);
155         STAT->AddSelectionMode(ActivationMode);
156         mySM->Activate(anInteractive,ActivationMode,myMainVS);
157       }
158     }
159   }
160   else {
161     Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
162     
163     if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
164       Att->SetDecomposition(Standard_True);
165     else 
166       Att->SetDecomposition(Standard_False);
167     // statut temporaire ou non
168     if(myCTX->DisplayStatus(anInteractive) == AIS_DS_None ||
169        myCTX->DisplayStatus(anInteractive) == AIS_DS_Temporary)
170       Att->SetTemporary(Standard_True);
171     else
172       Att->SetTemporary(Standard_False); 
173
174
175     
176     if(!myCTX->IsDisplayed(anInteractive,WhichMode)){
177       
178       //storing information....
179       Att->SetDisplayMode(WhichMode);
180       if (ActivationMode!=-1)
181         Att->AddSelectionMode(ActivationMode);
182       Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
183       Att->SetHilightMode(HiMod);
184
185       if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
186         myMainPM->Display(anInteractive,WhichMode);
187       
188       if(ActivationMode!=-1){
189         mySM->Load(anInteractive,myMainVS);
190         mySM->Activate(anInteractive,ActivationMode,myMainVS);
191       }
192     }
193     else{
194       Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
195       Att->SetHilightMode(HiMod);
196     }
197     myActiveObjects.Bind(anInteractive,Att);
198   }  
199   Process(anInteractive);
200
201   
202   
203
204   return Standard_True;
205 }
206
207 //=======================================================================
208 //function : Load
209 //purpose  : 
210 //=======================================================================
211
212 Standard_Boolean AIS_LocalContext::
213 Load(const Handle(AIS_InteractiveObject)& anInteractive,
214      const Standard_Boolean AllowShapeDecomposition,
215      const Standard_Integer ActivationMode)
216 {
217   if(myActiveObjects.IsBound(anInteractive)) return Standard_False;
218   Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
219   
220   if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
221     Att->SetDecomposition(Standard_True);
222   else 
223     Att->SetDecomposition(Standard_False);
224   
225   if(!myCTX->IsDisplayed(anInteractive))
226     Att->SetTemporary(Standard_True);
227   else
228     Att->SetTemporary(Standard_False);
229   Att->SetDisplayMode(-1);
230   
231   //storing information....
232   if(ActivationMode!=-1)
233     Att->AddSelectionMode(ActivationMode);
234   Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode():0;
235   Att->SetHilightMode(HiMod);
236   //Action
237   
238   mySM->Load(anInteractive,myMainVS);
239   if(ActivationMode != -1){
240     mySM->Activate(anInteractive,ActivationMode,myMainVS);
241   }
242   myActiveObjects.Bind(anInteractive,Att);
243   Process(anInteractive);
244   return Standard_True;
245 }
246
247 //=======================================================================
248 //function : ClearPrs
249 //purpose  : 
250 //=======================================================================
251
252 Standard_Boolean AIS_LocalContext::
253 ClearPrs(const Handle(AIS_InteractiveObject)& anInteractive,
254          const Standard_Integer aMode)
255 {
256   if(!myActiveObjects.IsBound(anInteractive))
257     return Standard_False;
258
259   Standard_Boolean jobdone(Standard_False);
260   const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
261   
262   //Display step
263   if(STAT->IsSubIntensityOn()) {
264     STAT->SubIntensityOff();
265     if(STAT->HilightMode()==aMode)
266       myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
267   }
268   myMainPM->Clear(anInteractive,aMode); // correction connexions 23/09/97
269   jobdone = Standard_True;
270   if(STAT->DisplayMode()==aMode)
271     STAT->SetDisplayMode(-1);
272   return jobdone;
273 }
274 //=======================================================================
275 //function : Erase
276 //purpose  : 
277 //=======================================================================
278
279 Standard_Boolean AIS_LocalContext::
280 Erase(const Handle(AIS_InteractiveObject)& anInteractive)
281 {
282   if(!myActiveObjects.IsBound(anInteractive))
283     return Standard_False;
284   const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
285   
286   //Display step
287   if(STAT->IsSubIntensityOn()) {
288     STAT->SubIntensityOff();
289     myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
290   }
291
292   Standard_Boolean status(Standard_False);
293
294   if(STAT->DisplayMode()!=-1) {
295     if(IsSelected(anInteractive))
296       AddOrRemoveSelected(anInteractive);
297     if(myMainPM->IsHighlighted(anInteractive,STAT->HilightMode()))
298       myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
299     myMainPM->Erase(anInteractive,STAT->DisplayMode());
300     STAT->SetDisplayMode(-1);
301     status = Standard_True;
302   }
303   if(STAT->IsTemporary()){
304     if(myMainPM->IsDisplayed(anInteractive,STAT->HilightMode()))
305       myMainPM->Erase(anInteractive,STAT->HilightMode());
306   }
307   //selection step
308   
309   TColStd_ListIteratorOfListOfInteger It(STAT->SelectionModes());
310   for(;It.More();It.Next())
311     mySM->Deactivate(anInteractive,It.Value(),myMainVS);
312   //  STAT->ClearSelectionModes();
313   return status;
314 }
315
316
317 //=======================================================================
318 //function : SetShapeDecomposition
319 //purpose  : 
320 //=======================================================================
321
322 void AIS_LocalContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& aStoredObject, 
323                                                 const Standard_Boolean aStatus)
324 {
325   if(!myActiveObjects.IsBound(aStoredObject)) return;
326   
327   if(aStatus == myActiveObjects(aStoredObject)->Decomposed()) 
328     return;
329   
330   myActiveObjects(aStoredObject)->SetDecomposition(aStatus);
331
332   Process(aStoredObject);
333 }
334
335 //=======================================================================
336 //function : Clear
337 //purpose  : 
338 //=======================================================================
339
340 void AIS_LocalContext::Clear(const AIS_ClearMode aType)
341 {
342   switch (aType){
343   case AIS_CM_All:
344     {
345       ClearObjects();
346       myFilters->Clear();
347       while(!myListOfStandardMode.IsEmpty())
348         DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
349       break;
350     }
351   case AIS_CM_Interactive:
352     ClearObjects();
353     break;
354   case AIS_CM_Filters:
355     myFilters->Clear();
356     break;
357   case AIS_CM_StandardModes:
358     {
359       while(!myListOfStandardMode.IsEmpty())
360         DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
361       break;
362     }
363   case AIS_CM_TemporaryShapePrs:
364     ClearDetected();
365   }
366   UpdateSort();
367 }
368 //=======================================================================
369 //function : ActivateMode
370 //purpose  : 
371 //=======================================================================
372
373 void AIS_LocalContext::ActivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
374                                        const Standard_Integer aMode)
375 {
376   if(!myActiveObjects.IsBound(aSelectable)) return;
377 //  if(myActiveObjects(aSelectable)->SelectionMode()!=aMode)
378 //    mySM->Deactivate(aSelectable,aMode,myMainVS);
379   if(aMode != -1){
380     myActiveObjects(aSelectable)->AddSelectionMode(aMode);
381     mySM->Activate(aSelectable,aMode,myMainVS);
382   }
383   UpdateSort();
384 }
385 //=======================================================================
386 //function : ActivateMode
387 //purpose  : 
388 //=======================================================================
389
390 void AIS_LocalContext::DeactivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
391                                          const Standard_Integer aMode)
392 {
393   if(!myActiveObjects.IsBound(aSelectable)) return;
394   
395   if(aMode==-1) return;
396   
397   myActiveObjects(aSelectable)->RemoveSelectionMode(aMode);
398   mySM->Deactivate(aSelectable,aMode,myMainVS);
399   UpdateSort();
400   
401 }
402 //=======================================================================
403 //function : ActivateMode
404 //purpose  : 
405 //=======================================================================
406
407 void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectable)
408 {
409   if(!myActiveObjects.IsBound(aSelectable)) return;
410   
411   mySM->Deactivate(aSelectable,myMainVS);
412   myActiveObjects(aSelectable)->ClearSelectionModes();
413   UpdateSort();
414 }
415
416 //=======================================================================
417 //function : Remove
418 //purpose  : 
419 //=======================================================================
420
421 Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& aSelectable)
422 {
423   if(!myActiveObjects.IsBound(aSelectable)) return Standard_False;
424
425   if(IsSelected(aSelectable))
426     AddOrRemoveSelected(aSelectable,Standard_False);
427     
428   const Handle(AIS_LocalStatus)& Att = myActiveObjects(aSelectable);
429   
430   TColStd_ListIteratorOfListOfInteger It;
431   Standard_Boolean jobdone(Standard_False);
432   // on regarde quel etaient ses attributs temporaires et on
433   // remet tout a 0
434
435   // desactiver les modes stantard
436   if(Att->Decomposed()){
437     for(It.Initialize(myListOfStandardMode);It.More();It.Next()){
438       mySM->Deactivate(aSelectable,It.Value(),myMainVS);
439     }
440   }
441   
442   // si objet ou presentations temporaires...
443   if(Att->IsTemporary())
444     {
445       if(Att->IsSubIntensityOn())
446         myMainPM->Unhighlight(aSelectable,Att->HilightMode());
447       
448       // enlever quand bug sur clear corrige...
449       myMainPM->Erase(aSelectable,Att->DisplayMode());
450       myMainPM->Clear(aSelectable,Att->DisplayMode());
451       if(myMainPM->IsDisplayed(aSelectable,Att->HilightMode()))
452         myMainPM->Erase(aSelectable,Att->HilightMode());
453       //        myMainPM->Clear(aSelectable,Att->HilightMode());
454       jobdone = Standard_True;
455     }
456   // si sous intensite
457   else
458     {
459       if(Att->IsSubIntensityOn())
460         myCTX->SubIntensityOff(aSelectable);
461     }
462   // desactiver les modes propres stockes
463   for(It.Initialize(Att->SelectionModes());It.More();It.Next()){
464     mySM->Deactivate(aSelectable,It.Value(),myMainVS);
465   }
466 // pop : si je laisses cela plantes dans les elements de construction  
467 //       alors a toi de jouer ROB
468 //  RemoveSelected(aSelectable);
469
470   if(IsSelected(aSelectable))
471     AddOrRemoveSelected(aSelectable);
472   myActiveObjects.UnBind(aSelectable);
473
474   //Last detected object keeps for lastindex initialization.
475   Handle(SelectMgr_EntityOwner) aLastPicked = myMainVS->OnePicked();
476
477   UpdateSort();
478
479   //Object removes from SelectMgr
480   if( mySM->Contains(aSelectable) )
481     mySM->Remove(aSelectable);
482
483   //Object removes from Detected sequence
484   AIS_SequenceOfInteractive detectAIS;
485
486   Standard_Integer i = 1;
487   for(i = 1 ; i < myAISDetectedSeq.Length(); i++)
488   {
489     Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
490     if( !anObj.IsNull() && anObj != aSelectable )
491       myAISDetectedSeq.Remove( i );
492   }
493
494   Standard_Integer aHM = aSelectable->HasHilightMode() ? aSelectable->HilightMode() : 0;
495
496   //EntityOwners remove from AIS_Selection
497   Handle(AIS_Selection) aSel = AIS_Selection::Selection(mySelName.ToCString());
498   AIS_NListTransient::Iterator anIter(aSel->Objects()); 
499   AIS_NListTransient removeEntites;
500   for(; anIter.More(); anIter.Next()){
501     const Handle(Standard_Transient)& Tr = anIter.Value();
502     if (!Tr.IsNull()){
503       const Handle(SelectMgr_EntityOwner)& anOwnr = *((const Handle(SelectMgr_EntityOwner)*) &Tr);
504       if(anOwnr->Selectable() == aSelectable){
505         removeEntites.Append(Tr);
506         if(IsSelected(anOwnr))
507           anOwnr->Unhilight(myMainPM, aHM);//Unhilight selected
508       }
509     }
510   }
511   AIS_NListTransient::Iterator anIterRemove(removeEntites); 
512   for(; anIterRemove.More(); anIterRemove.Next())
513     aSel->Select(anIterRemove.Value());//EntityOwner removes from the selection data
514
515   //EntityOwners remove from myMapOfOwner
516   SelectMgr_IndexedMapOfOwner ownersToKeep; 
517   const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
518   for(i = 1; i <= myMapOfOwner.Extent(); i++){
519     const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner(i) ;
520     if(!anOwner.IsNull())
521       if(anOwner->Selectable() != aSelectable)
522         ownersToKeep.Add(anOwner);
523       else
524       {
525         if(anOwner->IsHilighted(myMainPM, aHM))
526         {
527           for(aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
528             Unhilight(anOwner, aViewer->ActiveView());
529         }
530       }
531   }
532   myMapOfOwner.Clear();
533   myMapOfOwner.Assign(ownersToKeep);
534   mylastindex = myMapOfOwner.FindIndex(aLastPicked);
535
536   return Standard_True;
537 }
538
539 //=======================================================================
540 //function : ActivateStandardMode
541 //purpose  : 
542 //=======================================================================
543
544 void AIS_LocalContext::ActivateStandardMode(const TopAbs_ShapeEnum aType)
545 {
546   
547   //on verifie qu'il n'esiste pas deja dans la liste
548   TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
549   for(;It.More();It.Next())
550     if(It.Value()==aType)  return;
551   Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
552   
553
554   // on cree de facon cachee un filtre repondant ok au type 
555   //sauf :
556   // si le type est shape...
557   // si des filtres agissent deja sur le  type <aType>
558   if(aType != TopAbs_SHAPE){
559     if(myStdFilters[IMode].IsNull())
560       myStdFilters[IMode] = new StdSelect_ShapeTypeFilter(aType);
561     if(!HasFilters(aType))
562       myFilters->Add(myStdFilters[IMode]);
563   }
564   
565   // on active le mode pour tous les objets de type Shape 
566   // acceptant la decomposition en mode standard.
567   myListOfStandardMode.Append(IMode);
568   
569   AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
570
571   for(;ItM.More();ItM.Next()){
572 #ifdef BUC60722
573     AIS_DisplayStatus DS = 
574         myCTX->DisplayStatus(Handle(AIS_InteractiveObject)::DownCast(ItM.Key()));
575     if( ItM.Value()->Decomposed() && (DS != AIS_DS_FullErased)  )
576 #else
577     if(ItM.Value()->Decomposed())
578 #endif
579       myCTX->SelectionManager()->Activate(ItM.Key(),
580                                           IMode,
581                                           myMainVS);
582   }
583   
584 }
585
586 //=======================================================================
587 //function : DeActivateStandardMode
588 //purpose  : 
589 //=======================================================================
590
591 void AIS_LocalContext::DeactivateStandardMode(const TopAbs_ShapeEnum aType)
592 {
593   TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
594   Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
595   for(;It.More();It.Next())
596     if(It.Value()==IMode) {
597       AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
598       
599       for(;ItM.More();ItM.Next()){
600         if(ItM.Value()->Decomposed()){
601           myCTX->SelectionManager()->Deactivate(ItM.Key(),
602                                                 IMode,
603                                                 myMainVS);
604           ItM.Value()->RemoveSelectionMode(IMode);
605         }
606       }
607       myListOfStandardMode.Remove(It);
608       if(myFilters->IsIn(myStdFilters[IMode]))
609         myFilters->Remove(myStdFilters[IMode]);
610       UpdateSort();
611       return;
612     }   
613   UpdateSort();
614 }
615
616 //=======================================================================
617 //function : AddFilter
618 //purpose  : 
619 //=======================================================================
620
621 void AIS_LocalContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
622 {
623   // on regarde si le filtre agit sur un type de sous shape 
624   // active pour lequel on aurait deja mis un filtre de type...
625
626   TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
627   
628   for(;It.More();It.Next()){
629     if(aFilter->ActsOn(AIS_Shape::SelectionType(It.Value())))
630       if(myFilters->IsIn(myStdFilters[It.Value()]))
631         myFilters->Remove(myStdFilters[It.Value()]);
632   } 
633   myFilters->Add(aFilter);
634 }
635
636 //=======================================================================
637 //function : RemoveFilter
638 //purpose  : 
639 //=======================================================================
640
641 void AIS_LocalContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
642 {
643   if(myFilters->IsIn(aFilter)) myFilters->Remove(aFilter);
644   
645   // on regarde si le filtre concernait un type standard active.
646   // si oui , on regarde s'il en existe de semblables encore
647   //      parmi les filtres restant..
648   //     s'il n'en reste pas , on remet le filtre standard
649   //     permettant de continuer a selectionner les modes
650   //     actifs...
651   TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
652   TopAbs_ShapeEnum SE;
653   for(;It.More();It.Next()){
654     SE = AIS_Shape::SelectionType(It.Value());
655     if(aFilter->ActsOn(SE))
656       if(!HasFilters(SE))
657         myFilters->Add(myStdFilters[It.Value()]);
658   }
659 }
660
661
662
663 Standard_Boolean AIS_LocalContext::HasSameProjector(const Select3D_Projector& aPrj) const
664 {
665   const Select3D_Projector& CurPrj = myMainVS->Projector();
666   if(CurPrj.Perspective()!=aPrj.Perspective()) return Standard_False;  
667   if(CurPrj.Perspective())
668     if(CurPrj.Focus()!=aPrj.Focus()) return Standard_False;
669   gp_GTrsf CurTrsf(CurPrj.Transformation());
670   gp_GTrsf PrjTrsf(aPrj.Transformation());
671   
672   for(Standard_Integer i=1;i<=3;i++){
673     for(Standard_Integer j=1;j<=3;j++){
674       if(CurTrsf.Value(i,j)!=PrjTrsf.Value(i,j)) 
675         return Standard_False;
676     }
677   }
678   
679   return Standard_True;
680 }
681
682
683 //=======================================================================
684 //function : Terminate
685 //purpose  : 
686 //=======================================================================
687
688 void AIS_LocalContext::Terminate( const Standard_Boolean updateviewer )
689 {
690   ClearDetected();
691   Clear();
692   myMapOfOwner.Clear();
693   
694   mylastindex=0;
695   // nettoyons le selecteur...
696   myMainVS->Clear();
697   myCTX->SelectionManager()->Remove(myMainVS);
698   
699
700   AIS_Selection::SetCurrentSelection(mySelName.ToCString());
701   Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
702   Handle(Standard_Transient) Tr;
703   for(S->Init();S->More();S->Next()){
704     Tr = S->Value();
705     (*((Handle(SelectMgr_EntityOwner)*)&Tr))->State(0);
706   }
707
708       
709   AIS_Selection::Select();
710   AIS_Selection::Remove(mySelName.ToCString());
711
712   // CLE
713   // const Handle(V3d_Viewer)& Vwr = myCTX->CurrentViewer();
714   Handle(V3d_Viewer) Vwr = myCTX->CurrentViewer();
715   // ENDCLE
716   Handle(V3d_View) curV;
717   for(Vwr->InitActiveViews();Vwr->MoreActiveViews();Vwr->NextActiveViews()){
718     curV = Vwr->ActiveView(); 
719     Visual3d_TransientManager::ClearDraw( curV->View(), updateviewer );
720   }
721
722
723 #ifdef DEB
724   Handle(V3d_View) BidV;
725   myMainVS->ClearAreas(BidV);
726   myMainVS->ClearSensitive(BidV);
727   
728 #endif
729 }
730
731
732 //=======================================================================
733 //function : SubIntensity
734 //purpose  : 
735 //=======================================================================
736
737 void AIS_LocalContext::SubIntensityOn(const Handle(AIS_InteractiveObject)& anObject)
738 {
739   if(!myActiveObjects.IsBound(anObject)) return;
740   
741   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
742
743   if(Att->IsTemporary()) 
744     myMainPM->Color(anObject,myCTX->SubIntensityColor(),Att->DisplayMode());
745   
746   Att->SubIntensityOn();
747 }
748 //=======================================================================
749 //function : SubIntensity
750 //purpose  : 
751 //=======================================================================
752
753 void AIS_LocalContext::SubIntensityOff(const Handle(AIS_InteractiveObject)& anObject)
754 {
755   if(!myActiveObjects.IsBound(anObject)) return;
756   
757   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
758
759   if(Att->IsTemporary()) 
760     myMainPM->Unhighlight(anObject);
761   Att->SubIntensityOff();
762 }
763
764
765 //=======================================================================
766 //function : Hilight
767 //purpose  : 
768 //=======================================================================
769
770 void AIS_LocalContext::Hilight(const  Handle(AIS_InteractiveObject)& anObject)
771 {
772   if(!myActiveObjects.IsBound(anObject)){
773     Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0; 
774     Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
775                                                       Standard_False,
776                                                       -1,-1,HiMod);
777     myActiveObjects.Bind(anObject,Att);
778     
779   }
780   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
781   myMainPM->Color(anObject,myCTX->HilightColor(),Att->HilightMode());
782   Att->SubIntensityOn();
783 }
784 //=======================================================================
785 //function : Hilight
786 //purpose  : 
787 //=======================================================================
788
789 void AIS_LocalContext::Hilight(const  Handle(AIS_InteractiveObject)& anObject,
790                                const Quantity_NameOfColor Col)
791 {
792   if(!myActiveObjects.IsBound(anObject)){
793     Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0; 
794     Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
795                                                       Standard_False,
796                                                       -1,-1,HiMod);
797     myActiveObjects.Bind(anObject,Att);
798     
799   }
800   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
801   myMainPM->Color(anObject,Col,Att->HilightMode());
802   Att->SubIntensityOn();
803   Att->SetHilightColor(Col);
804 }
805
806 //=======================================================================
807 //function : Unhilight
808 //purpose  : 
809 //=======================================================================
810
811 void AIS_LocalContext::Unhilight(const Handle(AIS_InteractiveObject)& anObject)
812 {
813   if(!myActiveObjects.IsBound(anObject)) return;
814   
815   // pour voir si d'aventure l'objet est quelque part ailleurs...
816   Standard_Integer Indx;
817   Standard_Boolean IsSomeWhereElse  = 
818     myCTX->IsInLocal(anObject,Indx) && Indx != myCTX->IndexOfCurrentLocal();
819   
820   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
821   myMainPM->Unhighlight(anObject,Att->HilightMode());
822   if(Att->IsTemporary() && Att->DisplayMode()==-1)
823     if(!IsSomeWhereElse)
824       myMainPM->Erase(anObject,Att->HilightMode());
825   
826   Att->SubIntensityOff();
827   Att->SetHilightColor(Quantity_NOC_WHITE);
828 }
829
830
831 //=======================================================================
832 //function : IsIn
833 //purpose  : 
834 //=======================================================================
835
836 Standard_Boolean AIS_LocalContext::
837 IsIn(const Handle(AIS_InteractiveObject)& anObject) const 
838 {
839   return myActiveObjects.IsBound(anObject);
840 }
841
842 //=======================================================================
843 //function : IsHilighted
844 //purpose  : 
845 //=======================================================================
846
847 Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject) const 
848 {
849   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
850   return myActiveObjects(anObject)->IsSubIntensityOn();
851 }
852
853 Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject,
854                                                Standard_Boolean& WithColor,
855                                                Quantity_NameOfColor& HiCol) const 
856 {
857   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
858   if( myActiveObjects(anObject)->IsSubIntensityOn()){
859     HiCol = myActiveObjects(anObject)->HilightColor();
860     if(HiCol==Quantity_NOC_WHITE)
861       WithColor = Standard_True;
862     else
863       WithColor = Standard_False;
864     return Standard_True;
865   }
866   return Standard_False;
867 }
868
869
870 void AIS_LocalContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& anObject,
871                                           const Standard_Integer Prior)
872 {
873   if(!myActiveObjects.IsBound(anObject)) return;
874   const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anObject);
875   if(STAT->DisplayMode()==-1) return;
876   myMainPM->SetDisplayPriority(anObject,STAT->DisplayMode(),Prior);
877   if(STAT->IsSubIntensityOn())
878     myMainPM->SetDisplayPriority(anObject,STAT->HilightMode(),Prior);
879   
880   
881 }
882
883
884 //=======================================================================
885 //function : DisplayedObjects
886 //purpose  : 
887 //=======================================================================
888 Standard_Integer AIS_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const
889 {
890   Standard_Integer NbDisp(0);
891   for(AIS_DataMapIteratorOfDataMapOfSelStat it(myActiveObjects);it.More();it.Next()){
892     const Handle(SelectMgr_SelectableObject)& SO = it.Key();
893     if(!theMap.Contains(SO))
894       if(it.Value()->DisplayMode()!=-1){
895         theMap.Add(SO);
896         NbDisp++;
897       }
898   }
899   return NbDisp;
900 }
901
902
903 //=======================================================================
904 //function : IsDisplayed
905 //purpose  : 
906 //=======================================================================
907
908 Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject) const 
909 {
910   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
911   return (myActiveObjects(anObject)->DisplayMode()!=-1);
912 }
913
914 //=======================================================================
915 //function : IsDisplayed
916 //purpose  : 
917 //=======================================================================
918
919 Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject,
920                                                   const Standard_Integer aMode) const 
921 {
922   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
923   return (myActiveObjects(anObject)->DisplayMode()==aMode);
924 }
925
926 //=======================================================================
927 //function : SelectionModes
928 //purpose  : 
929 //=======================================================================
930
931 const TColStd_ListOfInteger& AIS_LocalContext::
932 SelectionModes(const Handle(AIS_InteractiveObject)& anObject) const 
933 {
934   return myActiveObjects(anObject)->SelectionModes(); 
935 }
936
937 //=======================================================================
938 //function : Status
939 //purpose  : 
940 //=======================================================================
941
942 TCollection_AsciiString AIS_LocalContext::Status() const 
943 {
944   TCollection_AsciiString t;
945   return t;
946 }
947
948 const Handle(AIS_LocalStatus)& AIS_LocalContext::Status(const Handle(AIS_InteractiveObject)& anObject) const 
949 {
950   return myActiveObjects(anObject);
951 }
952
953 //=======================================================================
954 //function : LoadContextObjects
955 //purpose  : 
956 //=======================================================================
957
958 void AIS_LocalContext::LoadContextObjects()
959 {
960   AIS_ListIteratorOfListOfInteractive It;
961   if(myLoadDisplayed) {
962     AIS_ListOfInteractive LL;
963     myCTX->DisplayedObjects(LL,Standard_True);
964     Handle(AIS_LocalStatus) Att;
965     for (It.Initialize(LL);It.More();It.Next()){
966       Att= new AIS_LocalStatus();
967       Att->SetDecomposition((It.Value()->AcceptShapeDecomposition() && myAcceptStdMode));
968       Att->SetTemporary(Standard_False);
969       Att->SetHilightMode(It.Value()->HasHilightMode()? It.Value()->HilightMode(): 0);
970       
971       myActiveObjects.Bind(It.Value(),Att);
972     }
973   }
974 }
975
976 void AIS_LocalContext::UnloadContextObjects()
977 {
978   AIS_ListIteratorOfListOfInteractive It;
979   if(myLoadDisplayed) 
980   {
981     AIS_ListOfInteractive LL;
982     myCTX->DisplayedObjects(LL,Standard_True);
983     
984     for (It.Initialize(LL);It.More();It.Next())
985     {
986       myActiveObjects.UnBind(It.Value());
987     }
988   }
989 }
990 //=======================================================================
991 //function : Process
992 //purpose  : 
993 //=======================================================================
994
995 void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject,
996                                const Standard_Boolean WithProj)
997
998   if(!myActiveObjects.IsBound(anObject)) return;
999   if(myActiveObjects(anObject)->Decomposed())
1000     ActivateStandardModes(anObject,WithProj);
1001   else
1002     {
1003       TColStd_ListIteratorOfListOfInteger It(myActiveObjects(anObject)->SelectionModes());
1004       for(;It.More();It.Next())
1005         myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS,WithProj);
1006     }
1007 }
1008
1009 //=======================================================================
1010 //function : Process
1011 //purpose  : 
1012 //=======================================================================
1013
1014 void AIS_LocalContext::Process(const Standard_Boolean WithProj)
1015
1016
1017   myMainVS->Clear();
1018   
1019   AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
1020   
1021   for(;It.More();It.Next()){
1022     myCTX->SelectionManager()->Load(It.Key(),myMainVS);
1023     if(It.Value()->Decomposed()) 
1024       ActivateStandardModes(It.Key(),WithProj);
1025     else if( myCTX->GetAutoActivateSelection() )
1026     {
1027       It.Value()->AddSelectionMode(0);
1028       myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS,WithProj);
1029     }
1030   }
1031
1032 }
1033
1034 //=======================================================================
1035 //function : ActivateModes
1036 //purpose  : 
1037 //=======================================================================
1038
1039 void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject,
1040                                              const Standard_Boolean WithProj)
1041
1042   if(!myActiveObjects.IsBound(anObject)) return;
1043   
1044   TColStd_ListIteratorOfListOfInteger itl (myListOfStandardMode);
1045
1046   const Handle(AIS_LocalStatus)&  LS = myActiveObjects(anObject);
1047   if(LS->Decomposed()){
1048     for(;itl.More();itl.Next()){
1049       myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS,WithProj);
1050       LS->AddSelectionMode(itl.Value());
1051     }
1052   }
1053 }
1054
1055
1056 //=======================================================================
1057 //function : ClearObjects
1058 //purpose  : 
1059 //=======================================================================
1060
1061 void AIS_LocalContext::ClearObjects()
1062 {
1063   AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
1064   for(;It.More();It.Next())
1065     {
1066       Handle(AIS_InteractiveObject) SO =
1067         Handle(AIS_InteractiveObject)::DownCast(It.Key());
1068       
1069       const Handle(AIS_LocalStatus)& CurAtt = It.Value();
1070       //TColStd_ListIteratorOfListOfInteger ItL;
1071       // si objet temporaire on efface ses presentations geree par myMainPM
1072       AIS_DisplayStatus TheDS = myCTX->DisplayStatus(SO);
1073       
1074       if(TheDS != AIS_DS_Displayed){
1075         if(myMainPM->IsDisplayed(SO,CurAtt->DisplayMode())){
1076           if(CurAtt->IsSubIntensityOn()&&
1077              myMainPM->IsHighlighted(SO,CurAtt->HilightMode()))
1078             myMainPM->Unhighlight(SO,CurAtt->HilightMode());
1079           myMainPM->Erase(SO,CurAtt->DisplayMode());
1080         }
1081         
1082         if(CurAtt->IsTemporary()){
1083           myMainPM->Erase(SO,CurAtt->DisplayMode());}
1084 //        myMainPM->Clear(SO,CurAtt->DisplayMode());}
1085       }
1086       else {
1087         if (CurAtt->IsSubIntensityOn()){
1088           myCTX->SubIntensityOff(Handle(AIS_InteractiveObject)::DownCast(SO));}
1089         Standard_Integer DiMo = SO->HasDisplayMode()?
1090           SO->DisplayMode():myCTX->DisplayMode();
1091         if(CurAtt->DisplayMode()!=-1 &&
1092            CurAtt->DisplayMode()!= DiMo)
1093           myMainPM->Erase(SO,CurAtt->DisplayMode());
1094       }
1095       
1096       TColStd_ListIteratorOfListOfInteger ITL(CurAtt->SelectionModes());
1097       for(;ITL.More();ITL.Next())
1098         mySM->Deactivate(SO,ITL.Value(),myMainVS);
1099       
1100       if(CurAtt->IsTemporary())
1101         mySM->Remove(SO,myMainVS);
1102       
1103     }
1104   ClearSelected( Standard_False );
1105   myActiveObjects.Clear();
1106 //  myMainVS->ClearAreas();myMainVS->ClearSensitive();
1107 }
1108
1109
1110 Standard_Boolean AIS_LocalContext::IsDecompositionOn() const 
1111 {return !myListOfStandardMode.IsEmpty();}
1112
1113
1114
1115
1116 //=======================================================================
1117 //function : HasAlreadyFilters
1118 //purpose  : 
1119 //=======================================================================
1120
1121 Standard_Boolean AIS_LocalContext::
1122 HasFilters(const TopAbs_ShapeEnum aType) const 
1123 {
1124   return myFilters->ActsOn(aType);
1125 }
1126
1127 void AIS_LocalContext::ClearDetected()
1128 {
1129   for(Standard_Integer I=1;I<=myMapOfOwner.Extent();I++){
1130     
1131     if(!myMapOfOwner(I).IsNull()){
1132       if(myMapOfOwner(I)->IsHilighted(myMainPM))
1133         myMapOfOwner(I)->Unhilight(myMainPM);
1134       else if (myMapOfOwner(I)->IsHilighted(myCTX->CollectorPrsMgr()))
1135         myMapOfOwner(I)->Unhilight(myCTX->CollectorPrsMgr());
1136       
1137       else{
1138         const Handle(SelectMgr_SelectableObject)& SO = 
1139           myMapOfOwner.FindKey(I)->Selectable();
1140         if(myActiveObjects.IsBound(SO)){
1141           const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO);
1142           
1143           if(Att->IsTemporary() &&
1144              Att->DisplayMode()==-1 && 
1145              Att->SelectionModes().IsEmpty()){
1146             myMapOfOwner(I)->Clear(myMainPM);
1147             //myMapOfOwner(I)->Clear();//rob-jmi...
1148           }
1149         }
1150       }
1151     }
1152   }
1153
1154 }
1155
1156 void AIS_LocalContext::UpdateConversion()
1157 {
1158   myMainVS->UpdateConversion();
1159 }
1160
1161 void AIS_LocalContext::UpdateSort()
1162 {
1163   myMainVS->UpdateSort();
1164 }
1165
1166
1167
1168 //=======================================================================
1169 //function : IMMEDIATE MODE
1170 //purpose  : 
1171 //=======================================================================
1172
1173 Standard_Boolean  AIS_LocalContext::BeginImmediateDraw()
1174 {
1175   if(myMainPM->IsImmediateModeOn()){
1176     myMainPM->BeginDraw();
1177     return Standard_True;
1178   }
1179   return Standard_False;
1180 }
1181
1182
1183 Standard_Boolean AIS_LocalContext::ImmediateAdd(const Handle(AIS_InteractiveObject)& anIObj,
1184                                                       const Standard_Integer aMode)
1185 {
1186   if(!myMainPM->IsImmediateModeOn())
1187     return Standard_False;
1188   myMainPM->Add(anIObj,aMode);
1189   return Standard_True;
1190 }
1191
1192 Standard_Boolean AIS_LocalContext::ImmediateRemove(const Handle(AIS_InteractiveObject)& anIObj,
1193                                                    const Standard_Integer aMode)
1194 {
1195   if(!myMainPM->IsImmediateModeOn())   return Standard_False;
1196   myMainPM->Remove(anIObj,aMode);
1197   return Standard_True;
1198 }
1199
1200 Standard_Boolean AIS_LocalContext::EndImmediateDraw(const Handle(V3d_View)& aView,
1201                                                           const Standard_Boolean DoubleBuf)
1202 {
1203   if(!myMainPM->IsImmediateModeOn()) return Standard_False;
1204   myMainPM->EndDraw(aView,DoubleBuf);
1205   return Standard_True;
1206 }
1207
1208 Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const
1209 {return myMainPM->IsImmediateModeOn();}
1210
1211 #ifdef BUC60688
1212 void AIS_LocalContext::SetSensitivity(const Standard_Real aPrecision) {
1213
1214   myMainVS->SetSensitivity(aPrecision);
1215 }
1216
1217 void AIS_LocalContext::SetSensitivity(const Standard_Integer aPrecision) {
1218
1219   myMainVS->Set(aPrecision);
1220 }
1221 #endif