0025991: Cyclic dependency in OCCT detected by WOK compiler
[occt.git] / src / AIS / AIS_LocalContext.cxx
CommitLineData
b311480e 1// Created on: 1997-01-17
2// Created by: Robert COUBLANC
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17//Modified by ROB : Traque des UpdateConversion intempestifs.
18
7fd59977 19#include <AIS_LocalContext.ixx>
20#include <SelectMgr_OrFilter.hxx>
21#include <SelectMgr_CompositionFilter.hxx>
22#include <AIS_LocalStatus.hxx>
23#include <AIS_Shape.hxx>
24#include <TColStd_ListIteratorOfListOfInteger.hxx>
25#include <AIS_ListIteratorOfListOfInteractive.hxx>
26#include <AIS_ListOfInteractive.hxx>
27#include <AIS_DataMapIteratorOfDataMapOfSelStat.hxx>
28#include <TopAbs_ShapeEnum.hxx>
29#include <Graphic3d_Structure.hxx>
30#include <Prs3d_LineAspect.hxx>
31#include <Prs3d_PlaneAspect.hxx>
32#include <Prs3d_PointAspect.hxx>
33#include <Prs3d_Presentation.hxx>
34#include <Aspect_TypeOfMarker.hxx>
35#include <StdSelect_ShapeTypeFilter.hxx>
36#include <AIS_Selection.hxx>
37#include <V3d_Viewer.hxx>
38#include <V3d_View.hxx>
7fd59977 39#include <Visual3d_View.hxx>
40
7fd59977 41#include <stdio.h>
7fd59977 42
43static TCollection_AsciiString AIS_Local_SelName(const Standard_Address address,
44 const Standard_Integer anIndex)
45{
46// TCollection_AsciiString SelName;
7fd59977 47 char string[100];
48 sprintf(string,"%p_%d", address, anIndex); // works under any system
49 TCollection_AsciiString SelName(string);
7fd59977 50 return SelName;
51}
52
53
54//=======================================================================
55//function : AIS_LocalContext
56//purpose :
57//=======================================================================
58
59
60AIS_LocalContext::AIS_LocalContext(){}
61
62AIS_LocalContext::AIS_LocalContext(const Handle(AIS_InteractiveContext)& aCtx,
63 const Standard_Integer Index,
64 const Standard_Boolean LoadDisplayed,
65 const Standard_Boolean AcceptStandardModes,
66 const Standard_Boolean AcceptEraseOfTemp,
35e08fe8 67 const Standard_Boolean /*BothViewers*/):
7fd59977 68myCTX(aCtx),
69myLoadDisplayed(LoadDisplayed),
70myAcceptStdMode(AcceptStandardModes),
71myAcceptErase(AcceptEraseOfTemp),
72mySM(aCtx->SelectionManager()),
73myMainVS(new StdSelect_ViewerSelector3d(aCtx->MainSelector()->Projector())),
74myFilters(new SelectMgr_OrFilter()),
75myAutoHilight(Standard_True),
76mylastindex(0),
77mylastgood(0),
d2094e11 78myCurDetected(0),
79myAISCurDetected(0)
80
7fd59977 81{
64e2d3bd 82 // bind self to AIS_InteractiveContext::myLocalContexts. Further, the
83 // constructor executes logic that implies that the context is already
84 // created and mapped.
85 aCtx->myLocalContexts.Bind (Index, this);
86
7fd59977 87 myMainPM = aCtx->MainPrsMgr();
88 mySelName = AIS_Local_SelName(this, Index);
89 AIS_Selection::CreateSelection(mySelName.ToCString());
90
91 mySM->Add(myMainVS);
92 if(myLoadDisplayed) LoadContextObjects();
93 Process(Standard_False);
94
95}
96
97
98//=======================================================================
99//function : SetContext
100//purpose :
101//=======================================================================
102
103void AIS_LocalContext::SetContext(const Handle(AIS_InteractiveContext)& aCtx)
104{ myCTX = aCtx;}
105
106//=======================================================================
107//function : Display
108//purpose :
109//=======================================================================
110
111Standard_Boolean AIS_LocalContext::Display(const Handle(AIS_InteractiveObject)& anInteractive,
112 const Standard_Integer WhichMode,
113 const Standard_Boolean AllowShapeDecomposition,
114 const Standard_Integer ActivationMode)
115{
116 if(myActiveObjects.IsBound(anInteractive)){
117 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
118
119 if(STAT->DisplayMode() == -1){
120 if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
121 myMainPM->Display(anInteractive,WhichMode);
122 if(STAT->IsTemporary())
123 STAT->SetDisplayMode(WhichMode);
124 }
125 else if(STAT->DisplayMode()!=WhichMode && STAT->IsTemporary()){
126 myMainPM->Erase(anInteractive,STAT->DisplayMode());
127 STAT->SetDisplayMode(WhichMode);
128 if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
129 myMainPM->Display(anInteractive,WhichMode);
130 }
131
132 if(ActivationMode!=-1){
133 if(!STAT->IsActivated(ActivationMode)){
134 STAT->ClearSelectionModes();
135 mySM->Load(anInteractive,myMainVS);
136 STAT->AddSelectionMode(ActivationMode);
137 mySM->Activate(anInteractive,ActivationMode,myMainVS);
138 }
139 }
140 }
141 else {
142 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
143
144 if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
145 Att->SetDecomposition(Standard_True);
146 else
147 Att->SetDecomposition(Standard_False);
81bba717 148 // status temporary or not
7fd59977 149 if(myCTX->DisplayStatus(anInteractive) == AIS_DS_None ||
150 myCTX->DisplayStatus(anInteractive) == AIS_DS_Temporary)
151 Att->SetTemporary(Standard_True);
152 else
153 Att->SetTemporary(Standard_False);
154
155
156
157 if(!myCTX->IsDisplayed(anInteractive,WhichMode)){
158
159 //storing information....
160 Att->SetDisplayMode(WhichMode);
161 if (ActivationMode!=-1)
162 Att->AddSelectionMode(ActivationMode);
163 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
164 Att->SetHilightMode(HiMod);
165
166 if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
167 myMainPM->Display(anInteractive,WhichMode);
168
169 if(ActivationMode!=-1){
170 mySM->Load(anInteractive,myMainVS);
171 mySM->Activate(anInteractive,ActivationMode,myMainVS);
172 }
173 }
174 else{
175 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
176 Att->SetHilightMode(HiMod);
177 }
178 myActiveObjects.Bind(anInteractive,Att);
179 }
180 Process(anInteractive);
181
182
183
184
185 return Standard_True;
186}
187
188//=======================================================================
189//function : Load
190//purpose :
191//=======================================================================
192
193Standard_Boolean AIS_LocalContext::
194Load(const Handle(AIS_InteractiveObject)& anInteractive,
195 const Standard_Boolean AllowShapeDecomposition,
196 const Standard_Integer ActivationMode)
197{
198 if(myActiveObjects.IsBound(anInteractive)) return Standard_False;
199 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
200
201 if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
202 Att->SetDecomposition(Standard_True);
203 else
204 Att->SetDecomposition(Standard_False);
205
206 if(!myCTX->IsDisplayed(anInteractive))
207 Att->SetTemporary(Standard_True);
208 else
209 Att->SetTemporary(Standard_False);
210 Att->SetDisplayMode(-1);
211
212 //storing information....
213 if(ActivationMode!=-1)
214 Att->AddSelectionMode(ActivationMode);
215 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode():0;
216 Att->SetHilightMode(HiMod);
217 //Action
218
219 mySM->Load(anInteractive,myMainVS);
220 if(ActivationMode != -1){
221 mySM->Activate(anInteractive,ActivationMode,myMainVS);
222 }
223 myActiveObjects.Bind(anInteractive,Att);
224 Process(anInteractive);
225 return Standard_True;
226}
227
228//=======================================================================
229//function : ClearPrs
230//purpose :
231//=======================================================================
232
233Standard_Boolean AIS_LocalContext::
234ClearPrs(const Handle(AIS_InteractiveObject)& anInteractive,
235 const Standard_Integer aMode)
236{
237 if(!myActiveObjects.IsBound(anInteractive))
238 return Standard_False;
239
240 Standard_Boolean jobdone(Standard_False);
241 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
242
243 //Display step
244 if(STAT->IsSubIntensityOn()) {
245 STAT->SubIntensityOff();
246 if(STAT->HilightMode()==aMode)
247 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
248 }
249 myMainPM->Clear(anInteractive,aMode); // correction connexions 23/09/97
250 jobdone = Standard_True;
251 if(STAT->DisplayMode()==aMode)
252 STAT->SetDisplayMode(-1);
253 return jobdone;
254}
255//=======================================================================
256//function : Erase
257//purpose :
258//=======================================================================
259
260Standard_Boolean AIS_LocalContext::
261Erase(const Handle(AIS_InteractiveObject)& anInteractive)
262{
263 if(!myActiveObjects.IsBound(anInteractive))
264 return Standard_False;
265 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
266
267 //Display step
268 if(STAT->IsSubIntensityOn()) {
269 STAT->SubIntensityOff();
270 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
271 }
272
273 Standard_Boolean status(Standard_False);
274
275 if(STAT->DisplayMode()!=-1) {
276 if(IsSelected(anInteractive))
277 AddOrRemoveSelected(anInteractive);
278 if(myMainPM->IsHighlighted(anInteractive,STAT->HilightMode()))
279 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
eb4320f2 280 myMainPM->SetVisibility (anInteractive, STAT->DisplayMode(), Standard_False);
7fd59977 281 STAT->SetDisplayMode(-1);
282 status = Standard_True;
283 }
284 if(STAT->IsTemporary()){
285 if(myMainPM->IsDisplayed(anInteractive,STAT->HilightMode()))
eb4320f2 286 myMainPM->SetVisibility (anInteractive, STAT->HilightMode(), Standard_False);
7fd59977 287 }
fb4b684a 288
289 // Deactivate selectable entities of interactive object
290 if (mySM->Contains (anInteractive))
291 {
292 TColStd_ListIteratorOfListOfInteger aModeIter (STAT->SelectionModes());
293 for (; aModeIter.More(); aModeIter.Next())
294 {
295 mySM->Deactivate (anInteractive, aModeIter.Value(), myMainVS);
296 }
297 }
298
299 UpdateSort();
300
bc677575 301 ClearOutdatedSelection (anInteractive, Standard_True);
fb4b684a 302
7fd59977 303 return status;
304}
305
306
307//=======================================================================
308//function : SetShapeDecomposition
309//purpose :
310//=======================================================================
311
312void AIS_LocalContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& aStoredObject,
313 const Standard_Boolean aStatus)
314{
315 if(!myActiveObjects.IsBound(aStoredObject)) return;
316
317 if(aStatus == myActiveObjects(aStoredObject)->Decomposed())
318 return;
319
320 myActiveObjects(aStoredObject)->SetDecomposition(aStatus);
321
322 Process(aStoredObject);
323}
324
325//=======================================================================
326//function : Clear
327//purpose :
328//=======================================================================
329
330void AIS_LocalContext::Clear(const AIS_ClearMode aType)
331{
332 switch (aType){
333 case AIS_CM_All:
334 {
335 ClearObjects();
336 myFilters->Clear();
337 while(!myListOfStandardMode.IsEmpty())
338 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
339 break;
340 }
341 case AIS_CM_Interactive:
342 ClearObjects();
343 break;
344 case AIS_CM_Filters:
345 myFilters->Clear();
346 break;
347 case AIS_CM_StandardModes:
348 {
349 while(!myListOfStandardMode.IsEmpty())
350 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
351 break;
352 }
353 case AIS_CM_TemporaryShapePrs:
354 ClearDetected();
355 }
356 UpdateSort();
357}
358//=======================================================================
359//function : ActivateMode
360//purpose :
361//=======================================================================
362
363void AIS_LocalContext::ActivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
364 const Standard_Integer aMode)
365{
366 if(!myActiveObjects.IsBound(aSelectable)) return;
367// if(myActiveObjects(aSelectable)->SelectionMode()!=aMode)
368// mySM->Deactivate(aSelectable,aMode,myMainVS);
369 if(aMode != -1){
370 myActiveObjects(aSelectable)->AddSelectionMode(aMode);
371 mySM->Activate(aSelectable,aMode,myMainVS);
372 }
373 UpdateSort();
374}
375//=======================================================================
376//function : ActivateMode
377//purpose :
378//=======================================================================
379
380void AIS_LocalContext::DeactivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
381 const Standard_Integer aMode)
382{
383 if(!myActiveObjects.IsBound(aSelectable)) return;
384
385 if(aMode==-1) return;
386
387 myActiveObjects(aSelectable)->RemoveSelectionMode(aMode);
388 mySM->Deactivate(aSelectable,aMode,myMainVS);
389 UpdateSort();
390
391}
392//=======================================================================
393//function : ActivateMode
394//purpose :
395//=======================================================================
396
397void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectable)
398{
399 if(!myActiveObjects.IsBound(aSelectable)) return;
400
401 mySM->Deactivate(aSelectable,myMainVS);
402 myActiveObjects(aSelectable)->ClearSelectionModes();
403 UpdateSort();
404}
405
406//=======================================================================
407//function : Remove
408//purpose :
409//=======================================================================
410
411Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& aSelectable)
412{
7fd6425d 413 if(!myActiveObjects.IsBound (aSelectable))
414 {
415 return Standard_False;
416 }
417
418 if (IsSelected (aSelectable))
419 {
420 AddOrRemoveSelected (aSelectable, Standard_False);
421 }
422
423 const Handle(AIS_LocalStatus)& Att = myActiveObjects (aSelectable);
7fd59977 424
7fd59977 425 TColStd_ListIteratorOfListOfInteger It;
7fd59977 426
7fd6425d 427 // Deactivate standard modes
428 if (Att->Decomposed())
429 {
430 for (It.Initialize (myListOfStandardMode); It.More(); It.Next())
431 {
432 mySM->Deactivate (aSelectable, It.Value(), myMainVS);
7fd59977 433 }
434 }
7fd6425d 435
436 // If object or temporary presentations
437 if (Att->IsTemporary())
438 {
439 if (Att->IsSubIntensityOn())
7fd59977 440 {
7fd6425d 441 myMainPM->Unhighlight (aSelectable, Att->HilightMode());
7fd59977 442 }
7fd6425d 443
444 myMainPM->Erase (aSelectable, Att->DisplayMode());
445 myMainPM->Clear (aSelectable, Att->DisplayMode());
446 if (myMainPM->IsDisplayed (aSelectable, Att->HilightMode()))
7fd59977 447 {
7fd6425d 448 myMainPM->Erase (aSelectable, Att->HilightMode());
7fd59977 449 }
7fd59977 450 }
7fd6425d 451 // If subintensity used
452 else if (Att->IsSubIntensityOn())
453 {
454 myCTX->SubIntensityOff (aSelectable);
455 }
7fd59977 456
7fd6425d 457 // Deactivate stored selection modes
458 for (It.Initialize (Att->SelectionModes()); It.More(); It.Next())
459 {
460 mySM->Deactivate (aSelectable, It.Value(), myMainVS);
461 }
7fd59977 462
fb4b684a 463 // Remove the interactive object from selection manager
464 if (mySM->Contains (aSelectable))
7fd59977 465 {
fb4b684a 466 mySM->Remove (aSelectable);
7fd59977 467 }
fb4b684a 468 UpdateSort();
bc677575 469 ClearOutdatedSelection (aSelectable, Standard_True);
7fd59977 470
7fd6425d 471 // This should be done at the very end because most methods use
472 // myActiveObjects even during clean-up
473 myActiveObjects.UnBind (aSelectable);
7fd59977 474 return Standard_True;
475}
476
477//=======================================================================
478//function : ActivateStandardMode
479//purpose :
480//=======================================================================
481
482void AIS_LocalContext::ActivateStandardMode(const TopAbs_ShapeEnum aType)
483{
484
81bba717 485 //check if it is not in the list
7fd59977 486 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
487 for(;It.More();It.Next())
488 if(It.Value()==aType) return;
489 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
490
491
81bba717 492 // create a hidden filter answering ok to the type except for :
493 // if the type is shape...
494 // if the filters already impact at the type <aType>
7fd59977 495 if(aType != TopAbs_SHAPE){
496 if(myStdFilters[IMode].IsNull())
497 myStdFilters[IMode] = new StdSelect_ShapeTypeFilter(aType);
498 if(!HasFilters(aType))
499 myFilters->Add(myStdFilters[IMode]);
500 }
501
81bba717 502 // the mode is activated for all objects of type Shape
503 // accepting the decomposition in standard mode.
7fd59977 504 myListOfStandardMode.Append(IMode);
505
506 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
507
508 for(;ItM.More();ItM.Next()){
7fd59977 509 if(ItM.Value()->Decomposed())
7fd59977 510 myCTX->SelectionManager()->Activate(ItM.Key(),
511 IMode,
512 myMainVS);
513 }
514
515}
516
517//=======================================================================
518//function : DeActivateStandardMode
519//purpose :
520//=======================================================================
521
522void AIS_LocalContext::DeactivateStandardMode(const TopAbs_ShapeEnum aType)
523{
524 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
525 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
526 for(;It.More();It.Next())
527 if(It.Value()==IMode) {
528 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
529
530 for(;ItM.More();ItM.Next()){
531 if(ItM.Value()->Decomposed()){
532 myCTX->SelectionManager()->Deactivate(ItM.Key(),
533 IMode,
534 myMainVS);
535 ItM.Value()->RemoveSelectionMode(IMode);
536 }
537 }
538 myListOfStandardMode.Remove(It);
539 if(myFilters->IsIn(myStdFilters[IMode]))
540 myFilters->Remove(myStdFilters[IMode]);
541 UpdateSort();
542 return;
543 }
544 UpdateSort();
545}
546
547//=======================================================================
548//function : AddFilter
549//purpose :
550//=======================================================================
551
552void AIS_LocalContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
553{
81bba717 554 // it is checked if the filter impacts at the type of active sub-shape
555 // for which a filter of type has been already implemented...
7fd59977 556
557 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
558
559 for(;It.More();It.Next()){
560 if(aFilter->ActsOn(AIS_Shape::SelectionType(It.Value())))
561 if(myFilters->IsIn(myStdFilters[It.Value()]))
562 myFilters->Remove(myStdFilters[It.Value()]);
563 }
564 myFilters->Add(aFilter);
565}
566
567//=======================================================================
568//function : RemoveFilter
569//purpose :
570//=======================================================================
571
572void AIS_LocalContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
573{
574 if(myFilters->IsIn(aFilter)) myFilters->Remove(aFilter);
575
81bba717 576 // it is checked if the filter for type standard is active.
577 // if yes, it is checked there are still similarities among the
578 // remaining filters...
579 // otherwise, the standard filter is restored to
580 // continu selecting active modes...
7fd59977 581 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
582 TopAbs_ShapeEnum SE;
583 for(;It.More();It.Next()){
584 SE = AIS_Shape::SelectionType(It.Value());
585 if(aFilter->ActsOn(SE))
586 if(!HasFilters(SE))
587 myFilters->Add(myStdFilters[It.Value()]);
588 }
589}
590
591
592
ab943560 593Standard_Boolean AIS_LocalContext::HasSameProjector(const Handle(Select3D_Projector)& thePrj) const
7fd59977 594{
ab943560 595 const Handle(Select3D_Projector)& aCurPrj = myMainVS->Projector();
596 if (aCurPrj->Perspective() != thePrj->Perspective())
597 return Standard_False;
598 if (aCurPrj->Perspective() && aCurPrj->Focus() != thePrj->Focus())
599 return Standard_False;
600 const gp_GTrsf& aCurTrsf = aCurPrj->Transformation();
601 const gp_GTrsf& aPrjTrsf = thePrj->Transformation();
602
603 for (Standard_Integer i = 1; i <= 3; ++i)
604 {
605 for (Standard_Integer j = 1; j <= 3 ; ++j)
606 {
607 if (aCurTrsf.Value (i, j) != aPrjTrsf.Value (i, j))
608 return Standard_False;
7fd59977 609 }
610 }
ab943560 611
7fd59977 612 return Standard_True;
613}
614
615
616//=======================================================================
617//function : Terminate
679ecdee 618//purpose :
7fd59977 619//=======================================================================
620
679ecdee 621void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate)
7fd59977 622{
623 ClearDetected();
624 Clear();
625 myMapOfOwner.Clear();
626
627 mylastindex=0;
81bba717 628 // clear the selector...
7fd59977 629 myMainVS->Clear();
630 myCTX->SelectionManager()->Remove(myMainVS);
631
632
633 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
634 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
635 Handle(Standard_Transient) Tr;
636 for(S->Init();S->More();S->Next()){
637 Tr = S->Value();
c398b00e 638 (*((Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False);
7fd59977 639 }
640
641
642 AIS_Selection::Select();
643 AIS_Selection::Remove(mySelName.ToCString());
644
679ecdee 645 Handle(V3d_Viewer) aViewer = myCTX->CurrentViewer();
646 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
647 {
648 Handle(V3d_View) aView = aViewer->ActiveView();
649 aView->View()->ClearImmediate();
7fd59977 650 }
651
679ecdee 652 Handle(V3d_View) aDummyView;
653 myMainVS->ClearAreas (aDummyView);
654 myMainVS->ClearSensitive (aDummyView);
7fd59977 655
679ecdee 656 if (theToUpdate)
657 {
658 myCTX->UpdateCurrentViewer();
659 }
7fd59977 660}
661
662
663//=======================================================================
664//function : SubIntensity
665//purpose :
666//=======================================================================
667
668void AIS_LocalContext::SubIntensityOn(const Handle(AIS_InteractiveObject)& anObject)
669{
670 if(!myActiveObjects.IsBound(anObject)) return;
671
672 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
673
674 if(Att->IsTemporary())
675 myMainPM->Color(anObject,myCTX->SubIntensityColor(),Att->DisplayMode());
676
677 Att->SubIntensityOn();
678}
679//=======================================================================
680//function : SubIntensity
681//purpose :
682//=======================================================================
683
684void AIS_LocalContext::SubIntensityOff(const Handle(AIS_InteractiveObject)& anObject)
685{
686 if(!myActiveObjects.IsBound(anObject)) return;
687
688 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
689
690 if(Att->IsTemporary())
691 myMainPM->Unhighlight(anObject);
692 Att->SubIntensityOff();
693}
694
695
696//=======================================================================
697//function : Hilight
698//purpose :
699//=======================================================================
700
701void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject)
702{
703 if(!myActiveObjects.IsBound(anObject)){
704 Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0;
705 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
706 Standard_False,
707 -1,-1,HiMod);
708 myActiveObjects.Bind(anObject,Att);
709
710 }
711 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
712 myMainPM->Color(anObject,myCTX->HilightColor(),Att->HilightMode());
713 Att->SubIntensityOn();
714}
715//=======================================================================
716//function : Hilight
717//purpose :
718//=======================================================================
719
720void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject,
721 const Quantity_NameOfColor Col)
722{
723 if(!myActiveObjects.IsBound(anObject)){
724 Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0;
725 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
726 Standard_False,
727 -1,-1,HiMod);
728 myActiveObjects.Bind(anObject,Att);
729
730 }
731 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
732 myMainPM->Color(anObject,Col,Att->HilightMode());
733 Att->SubIntensityOn();
734 Att->SetHilightColor(Col);
735}
736
737//=======================================================================
738//function : Unhilight
739//purpose :
740//=======================================================================
741
742void AIS_LocalContext::Unhilight(const Handle(AIS_InteractiveObject)& anObject)
743{
744 if(!myActiveObjects.IsBound(anObject)) return;
745
81bba717 746 // chieck if by hazard the object is somewhere else...
7fd59977 747 Standard_Integer Indx;
748 Standard_Boolean IsSomeWhereElse =
749 myCTX->IsInLocal(anObject,Indx) && Indx != myCTX->IndexOfCurrentLocal();
750
751 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
752 myMainPM->Unhighlight(anObject,Att->HilightMode());
753 if(Att->IsTemporary() && Att->DisplayMode()==-1)
754 if(!IsSomeWhereElse)
eb4320f2 755 myMainPM->SetVisibility (anObject, Att->HilightMode(), Standard_False);
756
7fd59977 757 Att->SubIntensityOff();
758 Att->SetHilightColor(Quantity_NOC_WHITE);
759}
760
761
762//=======================================================================
763//function : IsIn
764//purpose :
765//=======================================================================
766
767Standard_Boolean AIS_LocalContext::
768IsIn(const Handle(AIS_InteractiveObject)& anObject) const
769{
770 return myActiveObjects.IsBound(anObject);
771}
772
773//=======================================================================
774//function : IsHilighted
775//purpose :
776//=======================================================================
777
778Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject) const
779{
780 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
781 return myActiveObjects(anObject)->IsSubIntensityOn();
782}
783
784Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject,
785 Standard_Boolean& WithColor,
786 Quantity_NameOfColor& HiCol) const
787{
788 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
789 if( myActiveObjects(anObject)->IsSubIntensityOn()){
790 HiCol = myActiveObjects(anObject)->HilightColor();
791 if(HiCol==Quantity_NOC_WHITE)
792 WithColor = Standard_True;
793 else
794 WithColor = Standard_False;
795 return Standard_True;
796 }
797 return Standard_False;
798}
799
800
801void AIS_LocalContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& anObject,
802 const Standard_Integer Prior)
803{
804 if(!myActiveObjects.IsBound(anObject)) return;
805 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anObject);
806 if(STAT->DisplayMode()==-1) return;
807 myMainPM->SetDisplayPriority(anObject,STAT->DisplayMode(),Prior);
808 if(STAT->IsSubIntensityOn())
809 myMainPM->SetDisplayPriority(anObject,STAT->HilightMode(),Prior);
810
811
812}
813
7fd59977 814//=======================================================================
815//function : DisplayedObjects
816//purpose :
817//=======================================================================
818Standard_Integer AIS_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const
819{
820 Standard_Integer NbDisp(0);
821 for(AIS_DataMapIteratorOfDataMapOfSelStat it(myActiveObjects);it.More();it.Next()){
822 const Handle(SelectMgr_SelectableObject)& SO = it.Key();
823 if(!theMap.Contains(SO))
824 if(it.Value()->DisplayMode()!=-1){
825 theMap.Add(SO);
826 NbDisp++;
827 }
828 }
829 return NbDisp;
830}
831
832
833//=======================================================================
834//function : IsDisplayed
835//purpose :
836//=======================================================================
837
838Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject) const
839{
840 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
841 return (myActiveObjects(anObject)->DisplayMode()!=-1);
842}
843
844//=======================================================================
845//function : IsDisplayed
846//purpose :
847//=======================================================================
848
849Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject,
850 const Standard_Integer aMode) const
851{
852 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
853 return (myActiveObjects(anObject)->DisplayMode()==aMode);
854}
855
856//=======================================================================
857//function : SelectionModes
858//purpose :
859//=======================================================================
860
861const TColStd_ListOfInteger& AIS_LocalContext::
862SelectionModes(const Handle(AIS_InteractiveObject)& anObject) const
863{
864 return myActiveObjects(anObject)->SelectionModes();
865}
866
867//=======================================================================
868//function : Status
869//purpose :
870//=======================================================================
871
872TCollection_AsciiString AIS_LocalContext::Status() const
873{
874 TCollection_AsciiString t;
875 return t;
876}
877
878const Handle(AIS_LocalStatus)& AIS_LocalContext::Status(const Handle(AIS_InteractiveObject)& anObject) const
879{
880 return myActiveObjects(anObject);
881}
882
883//=======================================================================
884//function : LoadContextObjects
885//purpose :
886//=======================================================================
887
888void AIS_LocalContext::LoadContextObjects()
889{
890 AIS_ListIteratorOfListOfInteractive It;
891 if(myLoadDisplayed) {
892 AIS_ListOfInteractive LL;
893 myCTX->DisplayedObjects(LL,Standard_True);
894 Handle(AIS_LocalStatus) Att;
895 for (It.Initialize(LL);It.More();It.Next()){
896 Att= new AIS_LocalStatus();
897 Att->SetDecomposition((It.Value()->AcceptShapeDecomposition() && myAcceptStdMode));
898 Att->SetTemporary(Standard_False);
899 Att->SetHilightMode(It.Value()->HasHilightMode()? It.Value()->HilightMode(): 0);
900
901 myActiveObjects.Bind(It.Value(),Att);
902 }
903 }
904}
905
906void AIS_LocalContext::UnloadContextObjects()
907{
908 AIS_ListIteratorOfListOfInteractive It;
909 if(myLoadDisplayed)
910 {
911 AIS_ListOfInteractive LL;
912 myCTX->DisplayedObjects(LL,Standard_True);
913
914 for (It.Initialize(LL);It.More();It.Next())
915 {
916 myActiveObjects.UnBind(It.Value());
917 }
918 }
919}
920//=======================================================================
921//function : Process
922//purpose :
923//=======================================================================
924
925void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject,
926 const Standard_Boolean WithProj)
927{
928 if(!myActiveObjects.IsBound(anObject)) return;
929 if(myActiveObjects(anObject)->Decomposed())
930 ActivateStandardModes(anObject,WithProj);
931 else
932 {
933 TColStd_ListIteratorOfListOfInteger It(myActiveObjects(anObject)->SelectionModes());
934 for(;It.More();It.Next())
935 myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS,WithProj);
936 }
937}
938
939//=======================================================================
940//function : Process
941//purpose :
942//=======================================================================
943
944void AIS_LocalContext::Process(const Standard_Boolean WithProj)
945{
946
947 myMainVS->Clear();
948
949 AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
950
951 for(;It.More();It.Next()){
952 myCTX->SelectionManager()->Load(It.Key(),myMainVS);
953 if(It.Value()->Decomposed())
954 ActivateStandardModes(It.Key(),WithProj);
955 else if( myCTX->GetAutoActivateSelection() )
956 {
957 It.Value()->AddSelectionMode(0);
958 myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS,WithProj);
959 }
960 }
961
962}
963
964//=======================================================================
965//function : ActivateModes
966//purpose :
967//=======================================================================
968
969void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject,
970 const Standard_Boolean WithProj)
971{
972 if(!myActiveObjects.IsBound(anObject)) return;
973
974 TColStd_ListIteratorOfListOfInteger itl (myListOfStandardMode);
975
976 const Handle(AIS_LocalStatus)& LS = myActiveObjects(anObject);
977 if(LS->Decomposed()){
978 for(;itl.More();itl.Next()){
979 myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS,WithProj);
980 LS->AddSelectionMode(itl.Value());
981 }
982 }
983}
984
985
986//=======================================================================
987//function : ClearObjects
988//purpose :
989//=======================================================================
990
991void AIS_LocalContext::ClearObjects()
992{
993 AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
994 for(;It.More();It.Next())
995 {
996 Handle(AIS_InteractiveObject) SO =
997 Handle(AIS_InteractiveObject)::DownCast(It.Key());
998
999 const Handle(AIS_LocalStatus)& CurAtt = It.Value();
1000 //TColStd_ListIteratorOfListOfInteger ItL;
81bba717 1001 // if object is temporary the presentations managed by myMainPM are removed
7fd59977 1002 AIS_DisplayStatus TheDS = myCTX->DisplayStatus(SO);
1003
1004 if(TheDS != AIS_DS_Displayed){
1005 if(myMainPM->IsDisplayed(SO,CurAtt->DisplayMode())){
1006 if(CurAtt->IsSubIntensityOn()&&
1007 myMainPM->IsHighlighted(SO,CurAtt->HilightMode()))
1008 myMainPM->Unhighlight(SO,CurAtt->HilightMode());
1009 myMainPM->Erase(SO,CurAtt->DisplayMode());
1010 }
1011
1012 if(CurAtt->IsTemporary()){
1013 myMainPM->Erase(SO,CurAtt->DisplayMode());}
1014// myMainPM->Clear(SO,CurAtt->DisplayMode());}
1015 }
1016 else {
1017 if (CurAtt->IsSubIntensityOn()){
1018 myCTX->SubIntensityOff(Handle(AIS_InteractiveObject)::DownCast(SO));}
1019 Standard_Integer DiMo = SO->HasDisplayMode()?
1020 SO->DisplayMode():myCTX->DisplayMode();
1021 if(CurAtt->DisplayMode()!=-1 &&
1022 CurAtt->DisplayMode()!= DiMo)
1023 myMainPM->Erase(SO,CurAtt->DisplayMode());
1024 }
1025
1026 TColStd_ListIteratorOfListOfInteger ITL(CurAtt->SelectionModes());
1027 for(;ITL.More();ITL.Next())
1028 mySM->Deactivate(SO,ITL.Value(),myMainVS);
1029
1030 if(CurAtt->IsTemporary())
1031 mySM->Remove(SO,myMainVS);
1032
1033 }
1034 ClearSelected( Standard_False );
1035 myActiveObjects.Clear();
1036// myMainVS->ClearAreas();myMainVS->ClearSensitive();
1037}
1038
1039
1040Standard_Boolean AIS_LocalContext::IsDecompositionOn() const
1041{return !myListOfStandardMode.IsEmpty();}
1042
1043
1044
1045
1046//=======================================================================
1047//function : HasAlreadyFilters
1048//purpose :
1049//=======================================================================
1050
1051Standard_Boolean AIS_LocalContext::
1052HasFilters(const TopAbs_ShapeEnum aType) const
1053{
1054 return myFilters->ActsOn(aType);
1055}
1056
1057void AIS_LocalContext::ClearDetected()
1058{
eb4320f2 1059 for(Standard_Integer I=1;I<=myMapOfOwner.Extent();I++)
1060 {
1061 if(!myMapOfOwner(I).IsNull())
1062 {
7fd59977 1063 if(myMapOfOwner(I)->IsHilighted(myMainPM))
eb4320f2 1064 myMapOfOwner(I)->Unhilight(myMainPM);
1065 else
1066 {
1067 const Handle(SelectMgr_SelectableObject)& SO =
1068 myMapOfOwner.FindKey(I)->Selectable();
1069 if(myActiveObjects.IsBound(SO))
1070 {
1071 const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO);
1072
1073 if(Att->IsTemporary() &&
1074 Att->DisplayMode()==-1 &&
1075 Att->SelectionModes().IsEmpty())
1076 {
1077 myMapOfOwner(I)->Clear(myMainPM);
1078 }
1079 }
7fd59977 1080 }
1081 }
1082 }
7fd59977 1083}
1084
1085void AIS_LocalContext::UpdateConversion()
1086{
1087 myMainVS->UpdateConversion();
1088}
1089
1090void AIS_LocalContext::UpdateSort()
1091{
1092 myMainVS->UpdateSort();
1093}
1094
7fd59977 1095//=======================================================================
679ecdee 1096//function : BeginImmediateDraw
1097//purpose :
7fd59977 1098//=======================================================================
679ecdee 1099Standard_Boolean AIS_LocalContext::BeginImmediateDraw()
7fd59977 1100{
679ecdee 1101 if (myMainPM->IsImmediateModeOn())
1102 {
1103 myMainPM->BeginImmediateDraw();
7fd59977 1104 return Standard_True;
1105 }
1106 return Standard_False;
1107}
1108
679ecdee 1109//=======================================================================
1110//function : ImmediateAdd
1111//purpose :
1112//=======================================================================
1113Standard_Boolean AIS_LocalContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
1114 const Standard_Integer theMode)
7fd59977 1115{
679ecdee 1116 if (!myMainPM->IsImmediateModeOn())
1117 {
7fd59977 1118 return Standard_False;
679ecdee 1119 }
1120
af324faa 1121 myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode)->Presentation());
7fd59977 1122 return Standard_True;
1123}
1124
679ecdee 1125//=======================================================================
1126//function : EndImmediateDraw
1127//purpose :
1128//=======================================================================
1129Standard_Boolean AIS_LocalContext::EndImmediateDraw (const Handle(V3d_View)& theView)
7fd59977 1130{
679ecdee 1131 if (!myMainPM->IsImmediateModeOn())
1132 {
1133 return Standard_False;
1134 }
1135
1136 myMainPM->EndImmediateDraw (theView);
7fd59977 1137 return Standard_True;
1138}
1139
679ecdee 1140// =======================================================================
1141// function : ClearImmediateDraw
1142// purpose :
1143// =======================================================================
1144void AIS_LocalContext::ClearImmediateDraw()
7fd59977 1145{
679ecdee 1146 myMainPM->ClearImmediateDraw();
7fd59977 1147}
1148
679ecdee 1149//=======================================================================
1150//function : IsImmediateModeOn
1151//purpose :
1152//=======================================================================
7fd59977 1153Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const
679ecdee 1154{
1155 return myMainPM->IsImmediateModeOn();
1156}
7fd59977 1157
3c982548 1158void AIS_LocalContext::SetSensitivityMode(const StdSelect_SensitivityMode aMode) {
1159
1160 myMainVS->SetSensitivityMode(aMode);
1161}
1162
1163StdSelect_SensitivityMode AIS_LocalContext::SensitivityMode() const {
1164
1165 return myMainVS->SensitivityMode();
1166}
1167
7fd59977 1168void AIS_LocalContext::SetSensitivity(const Standard_Real aPrecision) {
1169
1170 myMainVS->SetSensitivity(aPrecision);
1171}
1172
3c982548 1173Standard_Real AIS_LocalContext::Sensitivity() const {
7fd59977 1174
3c982548 1175 return myMainVS->Sensitivity();
1176}
1177
1178void AIS_LocalContext::SetPixelTolerance(const Standard_Integer aPrecision) {
1179
1180 myMainVS->SetPixelTolerance(aPrecision);
1181}
1182
1183Standard_Integer AIS_LocalContext::PixelTolerance() const {
1184
1185 return myMainVS->PixelTolerance();
7fd59977 1186}