OCC22138 Remove *.gxx files from Mesh algorithm Update of WOK UDLIST
[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 Handle(Select3D_Projector)& thePrj) const
664 {
665   const Handle(Select3D_Projector)& aCurPrj = myMainVS->Projector();
666   if (aCurPrj->Perspective() != thePrj->Perspective())
667     return Standard_False;  
668   if (aCurPrj->Perspective() && aCurPrj->Focus() != thePrj->Focus())
669     return Standard_False;
670   const gp_GTrsf& aCurTrsf = aCurPrj->Transformation();
671   const gp_GTrsf& aPrjTrsf = thePrj->Transformation();
672
673   for (Standard_Integer i = 1; i <= 3; ++i)
674   {
675     for (Standard_Integer j = 1; j <= 3 ; ++j)
676     {
677       if (aCurTrsf.Value (i, j) != aPrjTrsf.Value (i, j))
678         return Standard_False;
679     }
680   }
681
682   return Standard_True;
683 }
684
685
686 //=======================================================================
687 //function : Terminate
688 //purpose  : 
689 //=======================================================================
690
691 void AIS_LocalContext::Terminate( const Standard_Boolean updateviewer )
692 {
693   ClearDetected();
694   Clear();
695   myMapOfOwner.Clear();
696   
697   mylastindex=0;
698   // nettoyons le selecteur...
699   myMainVS->Clear();
700   myCTX->SelectionManager()->Remove(myMainVS);
701   
702
703   AIS_Selection::SetCurrentSelection(mySelName.ToCString());
704   Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
705   Handle(Standard_Transient) Tr;
706   for(S->Init();S->More();S->Next()){
707     Tr = S->Value();
708     (*((Handle(SelectMgr_EntityOwner)*)&Tr))->State(0);
709   }
710
711       
712   AIS_Selection::Select();
713   AIS_Selection::Remove(mySelName.ToCString());
714
715   // CLE
716   // const Handle(V3d_Viewer)& Vwr = myCTX->CurrentViewer();
717   Handle(V3d_Viewer) Vwr = myCTX->CurrentViewer();
718   // ENDCLE
719   Handle(V3d_View) curV;
720   for(Vwr->InitActiveViews();Vwr->MoreActiveViews();Vwr->NextActiveViews()){
721     curV = Vwr->ActiveView(); 
722     Visual3d_TransientManager::ClearDraw( curV->View(), updateviewer );
723   }
724
725
726 #ifdef DEB
727   Handle(V3d_View) BidV;
728   myMainVS->ClearAreas(BidV);
729   myMainVS->ClearSensitive(BidV);
730   
731 #endif
732 }
733
734
735 //=======================================================================
736 //function : SubIntensity
737 //purpose  : 
738 //=======================================================================
739
740 void AIS_LocalContext::SubIntensityOn(const Handle(AIS_InteractiveObject)& anObject)
741 {
742   if(!myActiveObjects.IsBound(anObject)) return;
743   
744   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
745
746   if(Att->IsTemporary()) 
747     myMainPM->Color(anObject,myCTX->SubIntensityColor(),Att->DisplayMode());
748   
749   Att->SubIntensityOn();
750 }
751 //=======================================================================
752 //function : SubIntensity
753 //purpose  : 
754 //=======================================================================
755
756 void AIS_LocalContext::SubIntensityOff(const Handle(AIS_InteractiveObject)& anObject)
757 {
758   if(!myActiveObjects.IsBound(anObject)) return;
759   
760   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
761
762   if(Att->IsTemporary()) 
763     myMainPM->Unhighlight(anObject);
764   Att->SubIntensityOff();
765 }
766
767
768 //=======================================================================
769 //function : Hilight
770 //purpose  : 
771 //=======================================================================
772
773 void AIS_LocalContext::Hilight(const  Handle(AIS_InteractiveObject)& anObject)
774 {
775   if(!myActiveObjects.IsBound(anObject)){
776     Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0; 
777     Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
778                                                       Standard_False,
779                                                       -1,-1,HiMod);
780     myActiveObjects.Bind(anObject,Att);
781     
782   }
783   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
784   myMainPM->Color(anObject,myCTX->HilightColor(),Att->HilightMode());
785   Att->SubIntensityOn();
786 }
787 //=======================================================================
788 //function : Hilight
789 //purpose  : 
790 //=======================================================================
791
792 void AIS_LocalContext::Hilight(const  Handle(AIS_InteractiveObject)& anObject,
793                                const Quantity_NameOfColor Col)
794 {
795   if(!myActiveObjects.IsBound(anObject)){
796     Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0; 
797     Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
798                                                       Standard_False,
799                                                       -1,-1,HiMod);
800     myActiveObjects.Bind(anObject,Att);
801     
802   }
803   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
804   myMainPM->Color(anObject,Col,Att->HilightMode());
805   Att->SubIntensityOn();
806   Att->SetHilightColor(Col);
807 }
808
809 //=======================================================================
810 //function : Unhilight
811 //purpose  : 
812 //=======================================================================
813
814 void AIS_LocalContext::Unhilight(const Handle(AIS_InteractiveObject)& anObject)
815 {
816   if(!myActiveObjects.IsBound(anObject)) return;
817   
818   // pour voir si d'aventure l'objet est quelque part ailleurs...
819   Standard_Integer Indx;
820   Standard_Boolean IsSomeWhereElse  = 
821     myCTX->IsInLocal(anObject,Indx) && Indx != myCTX->IndexOfCurrentLocal();
822   
823   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
824   myMainPM->Unhighlight(anObject,Att->HilightMode());
825   if(Att->IsTemporary() && Att->DisplayMode()==-1)
826     if(!IsSomeWhereElse)
827       myMainPM->Erase(anObject,Att->HilightMode());
828   
829   Att->SubIntensityOff();
830   Att->SetHilightColor(Quantity_NOC_WHITE);
831 }
832
833
834 //=======================================================================
835 //function : IsIn
836 //purpose  : 
837 //=======================================================================
838
839 Standard_Boolean AIS_LocalContext::
840 IsIn(const Handle(AIS_InteractiveObject)& anObject) const 
841 {
842   return myActiveObjects.IsBound(anObject);
843 }
844
845 //=======================================================================
846 //function : IsHilighted
847 //purpose  : 
848 //=======================================================================
849
850 Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject) const 
851 {
852   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
853   return myActiveObjects(anObject)->IsSubIntensityOn();
854 }
855
856 Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject,
857                                                Standard_Boolean& WithColor,
858                                                Quantity_NameOfColor& HiCol) const 
859 {
860   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
861   if( myActiveObjects(anObject)->IsSubIntensityOn()){
862     HiCol = myActiveObjects(anObject)->HilightColor();
863     if(HiCol==Quantity_NOC_WHITE)
864       WithColor = Standard_True;
865     else
866       WithColor = Standard_False;
867     return Standard_True;
868   }
869   return Standard_False;
870 }
871
872
873 void AIS_LocalContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& anObject,
874                                           const Standard_Integer Prior)
875 {
876   if(!myActiveObjects.IsBound(anObject)) return;
877   const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anObject);
878   if(STAT->DisplayMode()==-1) return;
879   myMainPM->SetDisplayPriority(anObject,STAT->DisplayMode(),Prior);
880   if(STAT->IsSubIntensityOn())
881     myMainPM->SetDisplayPriority(anObject,STAT->HilightMode(),Prior);
882   
883   
884 }
885
886
887 //=======================================================================
888 //function : DisplayedObjects
889 //purpose  : 
890 //=======================================================================
891 Standard_Integer AIS_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const
892 {
893   Standard_Integer NbDisp(0);
894   for(AIS_DataMapIteratorOfDataMapOfSelStat it(myActiveObjects);it.More();it.Next()){
895     const Handle(SelectMgr_SelectableObject)& SO = it.Key();
896     if(!theMap.Contains(SO))
897       if(it.Value()->DisplayMode()!=-1){
898         theMap.Add(SO);
899         NbDisp++;
900       }
901   }
902   return NbDisp;
903 }
904
905
906 //=======================================================================
907 //function : IsDisplayed
908 //purpose  : 
909 //=======================================================================
910
911 Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject) const 
912 {
913   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
914   return (myActiveObjects(anObject)->DisplayMode()!=-1);
915 }
916
917 //=======================================================================
918 //function : IsDisplayed
919 //purpose  : 
920 //=======================================================================
921
922 Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject,
923                                                   const Standard_Integer aMode) const 
924 {
925   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
926   return (myActiveObjects(anObject)->DisplayMode()==aMode);
927 }
928
929 //=======================================================================
930 //function : SelectionModes
931 //purpose  : 
932 //=======================================================================
933
934 const TColStd_ListOfInteger& AIS_LocalContext::
935 SelectionModes(const Handle(AIS_InteractiveObject)& anObject) const 
936 {
937   return myActiveObjects(anObject)->SelectionModes(); 
938 }
939
940 //=======================================================================
941 //function : Status
942 //purpose  : 
943 //=======================================================================
944
945 TCollection_AsciiString AIS_LocalContext::Status() const 
946 {
947   TCollection_AsciiString t;
948   return t;
949 }
950
951 const Handle(AIS_LocalStatus)& AIS_LocalContext::Status(const Handle(AIS_InteractiveObject)& anObject) const 
952 {
953   return myActiveObjects(anObject);
954 }
955
956 //=======================================================================
957 //function : LoadContextObjects
958 //purpose  : 
959 //=======================================================================
960
961 void AIS_LocalContext::LoadContextObjects()
962 {
963   AIS_ListIteratorOfListOfInteractive It;
964   if(myLoadDisplayed) {
965     AIS_ListOfInteractive LL;
966     myCTX->DisplayedObjects(LL,Standard_True);
967     Handle(AIS_LocalStatus) Att;
968     for (It.Initialize(LL);It.More();It.Next()){
969       Att= new AIS_LocalStatus();
970       Att->SetDecomposition((It.Value()->AcceptShapeDecomposition() && myAcceptStdMode));
971       Att->SetTemporary(Standard_False);
972       Att->SetHilightMode(It.Value()->HasHilightMode()? It.Value()->HilightMode(): 0);
973       
974       myActiveObjects.Bind(It.Value(),Att);
975     }
976   }
977 }
978
979 void AIS_LocalContext::UnloadContextObjects()
980 {
981   AIS_ListIteratorOfListOfInteractive It;
982   if(myLoadDisplayed) 
983   {
984     AIS_ListOfInteractive LL;
985     myCTX->DisplayedObjects(LL,Standard_True);
986     
987     for (It.Initialize(LL);It.More();It.Next())
988     {
989       myActiveObjects.UnBind(It.Value());
990     }
991   }
992 }
993 //=======================================================================
994 //function : Process
995 //purpose  : 
996 //=======================================================================
997
998 void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject,
999                                const Standard_Boolean WithProj)
1000
1001   if(!myActiveObjects.IsBound(anObject)) return;
1002   if(myActiveObjects(anObject)->Decomposed())
1003     ActivateStandardModes(anObject,WithProj);
1004   else
1005     {
1006       TColStd_ListIteratorOfListOfInteger It(myActiveObjects(anObject)->SelectionModes());
1007       for(;It.More();It.Next())
1008         myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS,WithProj);
1009     }
1010 }
1011
1012 //=======================================================================
1013 //function : Process
1014 //purpose  : 
1015 //=======================================================================
1016
1017 void AIS_LocalContext::Process(const Standard_Boolean WithProj)
1018
1019
1020   myMainVS->Clear();
1021   
1022   AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
1023   
1024   for(;It.More();It.Next()){
1025     myCTX->SelectionManager()->Load(It.Key(),myMainVS);
1026     if(It.Value()->Decomposed()) 
1027       ActivateStandardModes(It.Key(),WithProj);
1028     else if( myCTX->GetAutoActivateSelection() )
1029     {
1030       It.Value()->AddSelectionMode(0);
1031       myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS,WithProj);
1032     }
1033   }
1034
1035 }
1036
1037 //=======================================================================
1038 //function : ActivateModes
1039 //purpose  : 
1040 //=======================================================================
1041
1042 void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject,
1043                                              const Standard_Boolean WithProj)
1044
1045   if(!myActiveObjects.IsBound(anObject)) return;
1046   
1047   TColStd_ListIteratorOfListOfInteger itl (myListOfStandardMode);
1048
1049   const Handle(AIS_LocalStatus)&  LS = myActiveObjects(anObject);
1050   if(LS->Decomposed()){
1051     for(;itl.More();itl.Next()){
1052       myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS,WithProj);
1053       LS->AddSelectionMode(itl.Value());
1054     }
1055   }
1056 }
1057
1058
1059 //=======================================================================
1060 //function : ClearObjects
1061 //purpose  : 
1062 //=======================================================================
1063
1064 void AIS_LocalContext::ClearObjects()
1065 {
1066   AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
1067   for(;It.More();It.Next())
1068     {
1069       Handle(AIS_InteractiveObject) SO =
1070         Handle(AIS_InteractiveObject)::DownCast(It.Key());
1071       
1072       const Handle(AIS_LocalStatus)& CurAtt = It.Value();
1073       //TColStd_ListIteratorOfListOfInteger ItL;
1074       // si objet temporaire on efface ses presentations geree par myMainPM
1075       AIS_DisplayStatus TheDS = myCTX->DisplayStatus(SO);
1076       
1077       if(TheDS != AIS_DS_Displayed){
1078         if(myMainPM->IsDisplayed(SO,CurAtt->DisplayMode())){
1079           if(CurAtt->IsSubIntensityOn()&&
1080              myMainPM->IsHighlighted(SO,CurAtt->HilightMode()))
1081             myMainPM->Unhighlight(SO,CurAtt->HilightMode());
1082           myMainPM->Erase(SO,CurAtt->DisplayMode());
1083         }
1084         
1085         if(CurAtt->IsTemporary()){
1086           myMainPM->Erase(SO,CurAtt->DisplayMode());}
1087 //        myMainPM->Clear(SO,CurAtt->DisplayMode());}
1088       }
1089       else {
1090         if (CurAtt->IsSubIntensityOn()){
1091           myCTX->SubIntensityOff(Handle(AIS_InteractiveObject)::DownCast(SO));}
1092         Standard_Integer DiMo = SO->HasDisplayMode()?
1093           SO->DisplayMode():myCTX->DisplayMode();
1094         if(CurAtt->DisplayMode()!=-1 &&
1095            CurAtt->DisplayMode()!= DiMo)
1096           myMainPM->Erase(SO,CurAtt->DisplayMode());
1097       }
1098       
1099       TColStd_ListIteratorOfListOfInteger ITL(CurAtt->SelectionModes());
1100       for(;ITL.More();ITL.Next())
1101         mySM->Deactivate(SO,ITL.Value(),myMainVS);
1102       
1103       if(CurAtt->IsTemporary())
1104         mySM->Remove(SO,myMainVS);
1105       
1106     }
1107   ClearSelected( Standard_False );
1108   myActiveObjects.Clear();
1109 //  myMainVS->ClearAreas();myMainVS->ClearSensitive();
1110 }
1111
1112
1113 Standard_Boolean AIS_LocalContext::IsDecompositionOn() const 
1114 {return !myListOfStandardMode.IsEmpty();}
1115
1116
1117
1118
1119 //=======================================================================
1120 //function : HasAlreadyFilters
1121 //purpose  : 
1122 //=======================================================================
1123
1124 Standard_Boolean AIS_LocalContext::
1125 HasFilters(const TopAbs_ShapeEnum aType) const 
1126 {
1127   return myFilters->ActsOn(aType);
1128 }
1129
1130 void AIS_LocalContext::ClearDetected()
1131 {
1132   for(Standard_Integer I=1;I<=myMapOfOwner.Extent();I++){
1133     
1134     if(!myMapOfOwner(I).IsNull()){
1135       if(myMapOfOwner(I)->IsHilighted(myMainPM))
1136         myMapOfOwner(I)->Unhilight(myMainPM);
1137       else if (myMapOfOwner(I)->IsHilighted(myCTX->CollectorPrsMgr()))
1138         myMapOfOwner(I)->Unhilight(myCTX->CollectorPrsMgr());
1139       
1140       else{
1141         const Handle(SelectMgr_SelectableObject)& SO = 
1142           myMapOfOwner.FindKey(I)->Selectable();
1143         if(myActiveObjects.IsBound(SO)){
1144           const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO);
1145           
1146           if(Att->IsTemporary() &&
1147              Att->DisplayMode()==-1 && 
1148              Att->SelectionModes().IsEmpty()){
1149             myMapOfOwner(I)->Clear(myMainPM);
1150             //myMapOfOwner(I)->Clear();//rob-jmi...
1151           }
1152         }
1153       }
1154     }
1155   }
1156
1157 }
1158
1159 void AIS_LocalContext::UpdateConversion()
1160 {
1161   myMainVS->UpdateConversion();
1162 }
1163
1164 void AIS_LocalContext::UpdateSort()
1165 {
1166   myMainVS->UpdateSort();
1167 }
1168
1169
1170
1171 //=======================================================================
1172 //function : IMMEDIATE MODE
1173 //purpose  : 
1174 //=======================================================================
1175
1176 Standard_Boolean  AIS_LocalContext::BeginImmediateDraw()
1177 {
1178   if(myMainPM->IsImmediateModeOn()){
1179     myMainPM->BeginDraw();
1180     return Standard_True;
1181   }
1182   return Standard_False;
1183 }
1184
1185
1186 Standard_Boolean AIS_LocalContext::ImmediateAdd(const Handle(AIS_InteractiveObject)& anIObj,
1187                                                       const Standard_Integer aMode)
1188 {
1189   if(!myMainPM->IsImmediateModeOn())
1190     return Standard_False;
1191   myMainPM->Add(anIObj,aMode);
1192   return Standard_True;
1193 }
1194
1195 Standard_Boolean AIS_LocalContext::ImmediateRemove(const Handle(AIS_InteractiveObject)& anIObj,
1196                                                    const Standard_Integer aMode)
1197 {
1198   if(!myMainPM->IsImmediateModeOn())   return Standard_False;
1199   myMainPM->Remove(anIObj,aMode);
1200   return Standard_True;
1201 }
1202
1203 Standard_Boolean AIS_LocalContext::EndImmediateDraw(const Handle(V3d_View)& aView,
1204                                                           const Standard_Boolean DoubleBuf)
1205 {
1206   if(!myMainPM->IsImmediateModeOn()) return Standard_False;
1207   myMainPM->EndDraw(aView,DoubleBuf);
1208   return Standard_True;
1209 }
1210
1211 Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const
1212 {return myMainPM->IsImmediateModeOn();}
1213
1214 #ifdef BUC60688
1215 void AIS_LocalContext::SetSensitivity(const Standard_Real aPrecision) {
1216
1217   myMainVS->SetSensitivity(aPrecision);
1218 }
1219
1220 void AIS_LocalContext::SetSensitivity(const Standard_Integer aPrecision) {
1221
1222   myMainVS->Set(aPrecision);
1223 }
1224 #endif