0027607: Visualization - Implement adaptive screen space sampling in path tracing
[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
42cf5bc1 19#include <AIS_DataMapIteratorOfDataMapOfSelStat.hxx>
20#include <AIS_InteractiveContext.hxx>
21#include <AIS_InteractiveObject.hxx>
7fd59977 22#include <AIS_ListIteratorOfListOfInteractive.hxx>
23#include <AIS_ListOfInteractive.hxx>
42cf5bc1 24#include <AIS_LocalContext.hxx>
25#include <AIS_LocalStatus.hxx>
42cf5bc1 26#include <AIS_Shape.hxx>
27#include <Aspect_TypeOfMarker.hxx>
7fd59977 28#include <Graphic3d_Structure.hxx>
29#include <Prs3d_LineAspect.hxx>
30#include <Prs3d_PlaneAspect.hxx>
31#include <Prs3d_PointAspect.hxx>
32#include <Prs3d_Presentation.hxx>
42cf5bc1 33#include <SelectMgr_CompositionFilter.hxx>
34#include <SelectMgr_EntityOwner.hxx>
35#include <SelectMgr_Filter.hxx>
36#include <SelectMgr_OrFilter.hxx>
37#include <SelectMgr_SelectableObject.hxx>
38#include <SelectMgr_SelectionManager.hxx>
39#include <Standard_Transient.hxx>
40#include <Standard_Type.hxx>
7fd59977 41#include <StdSelect_ShapeTypeFilter.hxx>
f751596e 42#include <StdSelect_ViewerSelector3d.hxx>
42cf5bc1 43#include <TCollection_AsciiString.hxx>
44#include <TColStd_ListIteratorOfListOfInteger.hxx>
45#include <TopAbs_ShapeEnum.hxx>
46#include <TopoDS_Shape.hxx>
7fd59977 47#include <V3d_View.hxx>
42cf5bc1 48#include <V3d_Viewer.hxx>
7fd59977 49
7fd59977 50#include <stdio.h>
92efcf78 51IMPLEMENT_STANDARD_RTTIEXT(AIS_LocalContext,MMgt_TShared)
52
7fd59977 53//=======================================================================
54//function : AIS_LocalContext
55//purpose :
56//=======================================================================
57
58
59AIS_LocalContext::AIS_LocalContext(){}
60
61AIS_LocalContext::AIS_LocalContext(const Handle(AIS_InteractiveContext)& aCtx,
62 const Standard_Integer Index,
63 const Standard_Boolean LoadDisplayed,
64 const Standard_Boolean AcceptStandardModes,
65 const Standard_Boolean AcceptEraseOfTemp,
35e08fe8 66 const Standard_Boolean /*BothViewers*/):
7fd59977 67myCTX(aCtx),
68myLoadDisplayed(LoadDisplayed),
69myAcceptStdMode(AcceptStandardModes),
70myAcceptErase(AcceptEraseOfTemp),
71mySM(aCtx->SelectionManager()),
f751596e 72myMainVS(aCtx->MainSelector()),
7fd59977 73myFilters(new SelectMgr_OrFilter()),
74myAutoHilight(Standard_True),
b586500b 75myMapOfOwner (new SelectMgr_IndexedMapOfOwner()),
016e5959 76mySelection(new AIS_Selection()),
7fd59977 77mylastindex(0),
78mylastgood(0),
d2094e11 79myCurDetected(0),
80myAISCurDetected(0)
81
7fd59977 82{
64e2d3bd 83 // bind self to AIS_InteractiveContext::myLocalContexts. Further, the
84 // constructor executes logic that implies that the context is already
85 // created and mapped.
86 aCtx->myLocalContexts.Bind (Index, this);
87
f751596e 88 myMainVS->ResetSelectionActivationStatus();
7fd59977 89 myMainPM = aCtx->MainPrsMgr();
7fd59977 90
91 mySM->Add(myMainVS);
92 if(myLoadDisplayed) LoadContextObjects();
f751596e 93 Process();
7fd59977 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{
f751596e 198 if (myActiveObjects.IsBound (anInteractive))
199 {
200 if (anInteractive->HasSelection (ActivationMode))
201 {
202 const Handle(SelectMgr_Selection)& aSel = anInteractive->Selection (ActivationMode);
203 if (aSel->GetSelectionState() != SelectMgr_SOS_Activated)
204 {
205 if (!myMainVS->Contains (anInteractive))
206 {
207 mySM->Load (anInteractive, myMainVS);
208 }
209 mySM->Activate (anInteractive, ActivationMode, myMainVS);
210 return Standard_True;
211 }
212 }
213 return Standard_False;
214 }
215
7fd59977 216 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
217
218 if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
219 Att->SetDecomposition(Standard_True);
220 else
221 Att->SetDecomposition(Standard_False);
222
223 if(!myCTX->IsDisplayed(anInteractive))
224 Att->SetTemporary(Standard_True);
225 else
226 Att->SetTemporary(Standard_False);
227 Att->SetDisplayMode(-1);
228
229 //storing information....
230 if(ActivationMode!=-1)
231 Att->AddSelectionMode(ActivationMode);
232 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode():0;
233 Att->SetHilightMode(HiMod);
234 //Action
235
236 mySM->Load(anInteractive,myMainVS);
237 if(ActivationMode != -1){
238 mySM->Activate(anInteractive,ActivationMode,myMainVS);
239 }
240 myActiveObjects.Bind(anInteractive,Att);
241 Process(anInteractive);
242 return Standard_True;
243}
244
245//=======================================================================
246//function : ClearPrs
247//purpose :
248//=======================================================================
249
250Standard_Boolean AIS_LocalContext::
251ClearPrs(const Handle(AIS_InteractiveObject)& anInteractive,
252 const Standard_Integer aMode)
253{
254 if(!myActiveObjects.IsBound(anInteractive))
255 return Standard_False;
256
257 Standard_Boolean jobdone(Standard_False);
258 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
259
260 //Display step
261 if(STAT->IsSubIntensityOn()) {
262 STAT->SubIntensityOff();
263 if(STAT->HilightMode()==aMode)
264 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
265 }
266 myMainPM->Clear(anInteractive,aMode); // correction connexions 23/09/97
267 jobdone = Standard_True;
268 if(STAT->DisplayMode()==aMode)
269 STAT->SetDisplayMode(-1);
270 return jobdone;
271}
272//=======================================================================
273//function : Erase
274//purpose :
275//=======================================================================
276
277Standard_Boolean AIS_LocalContext::
278Erase(const Handle(AIS_InteractiveObject)& anInteractive)
279{
280 if(!myActiveObjects.IsBound(anInteractive))
281 return Standard_False;
282 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
283
284 //Display step
285 if(STAT->IsSubIntensityOn()) {
286 STAT->SubIntensityOff();
287 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
288 }
289
290 Standard_Boolean status(Standard_False);
291
292 if(STAT->DisplayMode()!=-1) {
293 if(IsSelected(anInteractive))
294 AddOrRemoveSelected(anInteractive);
295 if(myMainPM->IsHighlighted(anInteractive,STAT->HilightMode()))
296 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
eb4320f2 297 myMainPM->SetVisibility (anInteractive, STAT->DisplayMode(), Standard_False);
7fd59977 298 STAT->SetDisplayMode(-1);
299 status = Standard_True;
300 }
301 if(STAT->IsTemporary()){
302 if(myMainPM->IsDisplayed(anInteractive,STAT->HilightMode()))
eb4320f2 303 myMainPM->SetVisibility (anInteractive, STAT->HilightMode(), Standard_False);
7fd59977 304 }
fb4b684a 305
306 // Deactivate selectable entities of interactive object
543a9964 307 const Handle(SelectMgr_SelectableObject)& anObj = anInteractive; // to avoid ambiguity
308 if (mySM->Contains (anObj))
fb4b684a 309 {
c3282ec1 310 while (!STAT->SelectionModes().IsEmpty())
fb4b684a 311 {
c3282ec1 312 mySM->Deactivate (anInteractive, STAT->SelectionModes().Last(), myMainVS);
313 STAT->RemoveSelectionMode (STAT->SelectionModes().Last());
fb4b684a 314 }
315 }
316
bc677575 317 ClearOutdatedSelection (anInteractive, Standard_True);
fb4b684a 318
7fd59977 319 return status;
320}
321
322
323//=======================================================================
324//function : SetShapeDecomposition
325//purpose :
326//=======================================================================
327
328void AIS_LocalContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& aStoredObject,
329 const Standard_Boolean aStatus)
330{
331 if(!myActiveObjects.IsBound(aStoredObject)) return;
332
333 if(aStatus == myActiveObjects(aStoredObject)->Decomposed())
334 return;
335
336 myActiveObjects(aStoredObject)->SetDecomposition(aStatus);
337
338 Process(aStoredObject);
339}
340
341//=======================================================================
342//function : Clear
343//purpose :
344//=======================================================================
345
346void AIS_LocalContext::Clear(const AIS_ClearMode aType)
347{
348 switch (aType){
349 case AIS_CM_All:
350 {
351 ClearObjects();
352 myFilters->Clear();
353 while(!myListOfStandardMode.IsEmpty())
354 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
355 break;
356 }
357 case AIS_CM_Interactive:
358 ClearObjects();
359 break;
360 case AIS_CM_Filters:
361 myFilters->Clear();
362 break;
363 case AIS_CM_StandardModes:
364 {
365 while(!myListOfStandardMode.IsEmpty())
366 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
367 break;
368 }
369 case AIS_CM_TemporaryShapePrs:
370 ClearDetected();
371 }
7fd59977 372}
373//=======================================================================
374//function : ActivateMode
375//purpose :
376//=======================================================================
377
378void AIS_LocalContext::ActivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
379 const Standard_Integer aMode)
380{
381 if(!myActiveObjects.IsBound(aSelectable)) return;
382// if(myActiveObjects(aSelectable)->SelectionMode()!=aMode)
383// mySM->Deactivate(aSelectable,aMode,myMainVS);
384 if(aMode != -1){
385 myActiveObjects(aSelectable)->AddSelectionMode(aMode);
386 mySM->Activate(aSelectable,aMode,myMainVS);
387 }
7fd59977 388}
389//=======================================================================
390//function : ActivateMode
391//purpose :
392//=======================================================================
393
394void AIS_LocalContext::DeactivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
395 const Standard_Integer aMode)
396{
397 if(!myActiveObjects.IsBound(aSelectable)) return;
398
399 if(aMode==-1) return;
400
401 myActiveObjects(aSelectable)->RemoveSelectionMode(aMode);
402 mySM->Deactivate(aSelectable,aMode,myMainVS);
7fd59977 403}
404//=======================================================================
405//function : ActivateMode
406//purpose :
407//=======================================================================
408
409void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectable)
410{
411 if(!myActiveObjects.IsBound(aSelectable)) return;
412
f751596e 413 mySM->Deactivate(aSelectable, -1, myMainVS);
7fd59977 414 myActiveObjects(aSelectable)->ClearSelectionModes();
7fd59977 415}
416
417//=======================================================================
418//function : Remove
419//purpose :
420//=======================================================================
421
422Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& aSelectable)
423{
7fd6425d 424 if(!myActiveObjects.IsBound (aSelectable))
425 {
426 return Standard_False;
427 }
428
429 if (IsSelected (aSelectable))
430 {
431 AddOrRemoveSelected (aSelectable, Standard_False);
432 }
433
434 const Handle(AIS_LocalStatus)& Att = myActiveObjects (aSelectable);
7fd59977 435
7fd59977 436 TColStd_ListIteratorOfListOfInteger It;
7fd59977 437
7fd6425d 438 // Deactivate standard modes
439 if (Att->Decomposed())
440 {
441 for (It.Initialize (myListOfStandardMode); It.More(); It.Next())
442 {
443 mySM->Deactivate (aSelectable, It.Value(), myMainVS);
7fd59977 444 }
445 }
7fd6425d 446
447 // If object or temporary presentations
448 if (Att->IsTemporary())
449 {
450 if (Att->IsSubIntensityOn())
7fd59977 451 {
7fd6425d 452 myMainPM->Unhighlight (aSelectable, Att->HilightMode());
7fd59977 453 }
7fd6425d 454
455 myMainPM->Erase (aSelectable, Att->DisplayMode());
7fd6425d 456 if (myMainPM->IsDisplayed (aSelectable, Att->HilightMode()))
7fd59977 457 {
7fd6425d 458 myMainPM->Erase (aSelectable, Att->HilightMode());
7fd59977 459 }
7fd59977 460 }
7fd6425d 461 // If subintensity used
462 else if (Att->IsSubIntensityOn())
463 {
464 myCTX->SubIntensityOff (aSelectable);
465 }
7fd59977 466
7fd6425d 467 // Deactivate stored selection modes
468 for (It.Initialize (Att->SelectionModes()); It.More(); It.Next())
469 {
470 mySM->Deactivate (aSelectable, It.Value(), myMainVS);
471 }
7fd59977 472
fb4b684a 473 // Remove the interactive object from selection manager
543a9964 474 const Handle(SelectMgr_SelectableObject)& anObj = aSelectable; // to avoid ambiguity
475 if (mySM->Contains (anObj))
7fd59977 476 {
543a9964 477 mySM->Remove (anObj);
7fd59977 478 }
bc677575 479 ClearOutdatedSelection (aSelectable, Standard_True);
7fd59977 480
7fd6425d 481 // This should be done at the very end because most methods use
482 // myActiveObjects even during clean-up
483 myActiveObjects.UnBind (aSelectable);
7fd59977 484 return Standard_True;
485}
486
487//=======================================================================
488//function : ActivateStandardMode
489//purpose :
490//=======================================================================
491
492void AIS_LocalContext::ActivateStandardMode(const TopAbs_ShapeEnum aType)
493{
494
81bba717 495 //check if it is not in the list
7fd59977 496 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
497 for(;It.More();It.Next())
498 if(It.Value()==aType) return;
499 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
500
501
81bba717 502 // create a hidden filter answering ok to the type except for :
503 // if the type is shape...
504 // if the filters already impact at the type <aType>
7fd59977 505 if(aType != TopAbs_SHAPE){
506 if(myStdFilters[IMode].IsNull())
507 myStdFilters[IMode] = new StdSelect_ShapeTypeFilter(aType);
508 if(!HasFilters(aType))
509 myFilters->Add(myStdFilters[IMode]);
510 }
511
81bba717 512 // the mode is activated for all objects of type Shape
513 // accepting the decomposition in standard mode.
7fd59977 514 myListOfStandardMode.Append(IMode);
515
516 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
517
518 for(;ItM.More();ItM.Next()){
7fd59977 519 if(ItM.Value()->Decomposed())
7fd59977 520 myCTX->SelectionManager()->Activate(ItM.Key(),
521 IMode,
522 myMainVS);
325e442b 523 ItM.Value()->AddSelectionMode (IMode);
7fd59977 524 }
525
526}
527
528//=======================================================================
529//function : DeActivateStandardMode
530//purpose :
531//=======================================================================
532
533void AIS_LocalContext::DeactivateStandardMode(const TopAbs_ShapeEnum aType)
534{
535 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
536 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
537 for(;It.More();It.Next())
538 if(It.Value()==IMode) {
539 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
540
541 for(;ItM.More();ItM.Next()){
542 if(ItM.Value()->Decomposed()){
543 myCTX->SelectionManager()->Deactivate(ItM.Key(),
544 IMode,
545 myMainVS);
546 ItM.Value()->RemoveSelectionMode(IMode);
547 }
548 }
549 myListOfStandardMode.Remove(It);
550 if(myFilters->IsIn(myStdFilters[IMode]))
551 myFilters->Remove(myStdFilters[IMode]);
7fd59977 552 return;
553 }
7fd59977 554}
555
556//=======================================================================
557//function : AddFilter
558//purpose :
559//=======================================================================
560
561void AIS_LocalContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
562{
81bba717 563 // it is checked if the filter impacts at the type of active sub-shape
564 // for which a filter of type has been already implemented...
7fd59977 565
566 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
567
568 for(;It.More();It.Next()){
569 if(aFilter->ActsOn(AIS_Shape::SelectionType(It.Value())))
570 if(myFilters->IsIn(myStdFilters[It.Value()]))
571 myFilters->Remove(myStdFilters[It.Value()]);
572 }
573 myFilters->Add(aFilter);
574}
575
576//=======================================================================
577//function : RemoveFilter
578//purpose :
579//=======================================================================
580
581void AIS_LocalContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
582{
583 if(myFilters->IsIn(aFilter)) myFilters->Remove(aFilter);
584
81bba717 585 // it is checked if the filter for type standard is active.
586 // if yes, it is checked there are still similarities among the
587 // remaining filters...
588 // otherwise, the standard filter is restored to
589 // continu selecting active modes...
7fd59977 590 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
591 TopAbs_ShapeEnum SE;
592 for(;It.More();It.Next()){
593 SE = AIS_Shape::SelectionType(It.Value());
594 if(aFilter->ActsOn(SE))
595 if(!HasFilters(SE))
596 myFilters->Add(myStdFilters[It.Value()]);
597 }
598}
599
7fd59977 600//=======================================================================
601//function : Terminate
679ecdee 602//purpose :
7fd59977 603//=======================================================================
604
679ecdee 605void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate)
7fd59977 606{
607 ClearDetected();
608 Clear();
b586500b 609 myMapOfOwner->Clear();
7fd59977 610
611 mylastindex=0;
81bba717 612 // clear the selector...
7fd59977 613 myMainVS->Clear();
7fd59977 614
02974a19 615 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
616 {
617 aSelIter.Value()->SetSelected (Standard_False);
7fd59977 618 }
02974a19 619 mySelection->Clear();
7fd59977 620
679ecdee 621 Handle(V3d_View) aDummyView;
679ecdee 622 myMainVS->ClearSensitive (aDummyView);
7fd59977 623
679ecdee 624 if (theToUpdate)
625 {
626 myCTX->UpdateCurrentViewer();
627 }
7fd59977 628}
629
630
631//=======================================================================
632//function : SubIntensity
633//purpose :
634//=======================================================================
635
636void AIS_LocalContext::SubIntensityOn(const Handle(AIS_InteractiveObject)& anObject)
637{
638 if(!myActiveObjects.IsBound(anObject)) return;
639
640 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
641
642 if(Att->IsTemporary())
643 myMainPM->Color(anObject,myCTX->SubIntensityColor(),Att->DisplayMode());
644
645 Att->SubIntensityOn();
646}
647//=======================================================================
648//function : SubIntensity
649//purpose :
650//=======================================================================
651
652void AIS_LocalContext::SubIntensityOff(const Handle(AIS_InteractiveObject)& anObject)
653{
654 if(!myActiveObjects.IsBound(anObject)) return;
655
656 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
657
658 if(Att->IsTemporary())
659 myMainPM->Unhighlight(anObject);
660 Att->SubIntensityOff();
661}
662
663
664//=======================================================================
665//function : Hilight
666//purpose :
667//=======================================================================
668
669void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject)
670{
671 if(!myActiveObjects.IsBound(anObject)){
672 Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0;
673 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
674 Standard_False,
675 -1,-1,HiMod);
676 myActiveObjects.Bind(anObject,Att);
677
678 }
679 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
680 myMainPM->Color(anObject,myCTX->HilightColor(),Att->HilightMode());
681 Att->SubIntensityOn();
682}
683//=======================================================================
684//function : Hilight
685//purpose :
686//=======================================================================
687
688void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject,
689 const Quantity_NameOfColor Col)
690{
691 if(!myActiveObjects.IsBound(anObject)){
692 Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0;
693 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
694 Standard_False,
695 -1,-1,HiMod);
696 myActiveObjects.Bind(anObject,Att);
697
698 }
699 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
700 myMainPM->Color(anObject,Col,Att->HilightMode());
701 Att->SubIntensityOn();
702 Att->SetHilightColor(Col);
703}
704
705//=======================================================================
706//function : Unhilight
707//purpose :
708//=======================================================================
709
710void AIS_LocalContext::Unhilight(const Handle(AIS_InteractiveObject)& anObject)
711{
712 if(!myActiveObjects.IsBound(anObject)) return;
713
81bba717 714 // chieck if by hazard the object is somewhere else...
7fd59977 715 Standard_Integer Indx;
716 Standard_Boolean IsSomeWhereElse =
717 myCTX->IsInLocal(anObject,Indx) && Indx != myCTX->IndexOfCurrentLocal();
718
719 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
720 myMainPM->Unhighlight(anObject,Att->HilightMode());
721 if(Att->IsTemporary() && Att->DisplayMode()==-1)
722 if(!IsSomeWhereElse)
eb4320f2 723 myMainPM->SetVisibility (anObject, Att->HilightMode(), Standard_False);
724
7fd59977 725 Att->SubIntensityOff();
726 Att->SetHilightColor(Quantity_NOC_WHITE);
727}
728
729
730//=======================================================================
731//function : IsIn
732//purpose :
733//=======================================================================
734
735Standard_Boolean AIS_LocalContext::
736IsIn(const Handle(AIS_InteractiveObject)& anObject) const
737{
738 return myActiveObjects.IsBound(anObject);
739}
740
741//=======================================================================
742//function : IsHilighted
743//purpose :
744//=======================================================================
745
746Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject) const
747{
748 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
749 return myActiveObjects(anObject)->IsSubIntensityOn();
750}
751
752Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject,
753 Standard_Boolean& WithColor,
754 Quantity_NameOfColor& HiCol) const
755{
756 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
757 if( myActiveObjects(anObject)->IsSubIntensityOn()){
758 HiCol = myActiveObjects(anObject)->HilightColor();
759 if(HiCol==Quantity_NOC_WHITE)
760 WithColor = Standard_True;
761 else
762 WithColor = Standard_False;
763 return Standard_True;
764 }
765 return Standard_False;
766}
767
768
769void AIS_LocalContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& anObject,
770 const Standard_Integer Prior)
771{
772 if(!myActiveObjects.IsBound(anObject)) return;
773 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anObject);
774 if(STAT->DisplayMode()==-1) return;
775 myMainPM->SetDisplayPriority(anObject,STAT->DisplayMode(),Prior);
776 if(STAT->IsSubIntensityOn())
777 myMainPM->SetDisplayPriority(anObject,STAT->HilightMode(),Prior);
778
779
780}
781
7fd59977 782//=======================================================================
783//function : DisplayedObjects
784//purpose :
785//=======================================================================
786Standard_Integer AIS_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const
787{
788 Standard_Integer NbDisp(0);
789 for(AIS_DataMapIteratorOfDataMapOfSelStat it(myActiveObjects);it.More();it.Next()){
790 const Handle(SelectMgr_SelectableObject)& SO = it.Key();
791 if(!theMap.Contains(SO))
792 if(it.Value()->DisplayMode()!=-1){
793 theMap.Add(SO);
794 NbDisp++;
795 }
796 }
797 return NbDisp;
798}
799
800
801//=======================================================================
802//function : IsDisplayed
803//purpose :
804//=======================================================================
805
806Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject) const
807{
808 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
809 return (myActiveObjects(anObject)->DisplayMode()!=-1);
810}
811
812//=======================================================================
813//function : IsDisplayed
814//purpose :
815//=======================================================================
816
817Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject,
818 const Standard_Integer aMode) const
819{
820 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
821 return (myActiveObjects(anObject)->DisplayMode()==aMode);
822}
823
824//=======================================================================
825//function : SelectionModes
826//purpose :
827//=======================================================================
828
829const TColStd_ListOfInteger& AIS_LocalContext::
830SelectionModes(const Handle(AIS_InteractiveObject)& anObject) const
831{
832 return myActiveObjects(anObject)->SelectionModes();
833}
834
835//=======================================================================
836//function : Status
837//purpose :
838//=======================================================================
839
840TCollection_AsciiString AIS_LocalContext::Status() const
841{
842 TCollection_AsciiString t;
843 return t;
844}
845
846const Handle(AIS_LocalStatus)& AIS_LocalContext::Status(const Handle(AIS_InteractiveObject)& anObject) const
847{
848 return myActiveObjects(anObject);
849}
850
851//=======================================================================
852//function : LoadContextObjects
853//purpose :
854//=======================================================================
855
856void AIS_LocalContext::LoadContextObjects()
857{
858 AIS_ListIteratorOfListOfInteractive It;
859 if(myLoadDisplayed) {
860 AIS_ListOfInteractive LL;
861 myCTX->DisplayedObjects(LL,Standard_True);
862 Handle(AIS_LocalStatus) Att;
863 for (It.Initialize(LL);It.More();It.Next()){
f751596e 864 const Handle(AIS_InteractiveObject)& anObj = It.Value();
7fd59977 865 Att= new AIS_LocalStatus();
f751596e 866 Att->SetDecomposition((anObj->AcceptShapeDecomposition() && myAcceptStdMode));
7fd59977 867 Att->SetTemporary(Standard_False);
f751596e 868 Att->SetHilightMode(anObj->HasHilightMode()? anObj->HilightMode(): 0);
869 for (anObj->Init(); anObj->More(); anObj->Next())
870 {
871 const Handle(SelectMgr_Selection)& aSel = anObj->CurrentSelection();
872 aSel->SetSelectionState (SelectMgr_SOS_Deactivated);
873 }
874 myActiveObjects.Bind(anObj,Att);
7fd59977 875 }
876 }
877}
878
879void AIS_LocalContext::UnloadContextObjects()
880{
881 AIS_ListIteratorOfListOfInteractive It;
882 if(myLoadDisplayed)
883 {
884 AIS_ListOfInteractive LL;
885 myCTX->DisplayedObjects(LL,Standard_True);
886
887 for (It.Initialize(LL);It.More();It.Next())
888 {
889 myActiveObjects.UnBind(It.Value());
890 }
891 }
892}
893//=======================================================================
894//function : Process
895//purpose :
896//=======================================================================
897
f751596e 898void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject)
7fd59977 899{
900 if(!myActiveObjects.IsBound(anObject)) return;
901 if(myActiveObjects(anObject)->Decomposed())
f751596e 902 ActivateStandardModes(anObject);
7fd59977 903 else
904 {
905 TColStd_ListIteratorOfListOfInteger It(myActiveObjects(anObject)->SelectionModes());
906 for(;It.More();It.Next())
f751596e 907 myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS);
7fd59977 908 }
909}
910
911//=======================================================================
912//function : Process
913//purpose :
914//=======================================================================
915
f751596e 916void AIS_LocalContext::Process()
7fd59977 917{
918
919 myMainVS->Clear();
920
921 AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
922
923 for(;It.More();It.Next()){
924 myCTX->SelectionManager()->Load(It.Key(),myMainVS);
925 if(It.Value()->Decomposed())
f751596e 926 ActivateStandardModes(It.Key());
7fd59977 927 else if( myCTX->GetAutoActivateSelection() )
928 {
929 It.Value()->AddSelectionMode(0);
f751596e 930 myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS);
7fd59977 931 }
932 }
933
934}
935
936//=======================================================================
937//function : ActivateModes
938//purpose :
939//=======================================================================
940
f751596e 941void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject)
7fd59977 942{
943 if(!myActiveObjects.IsBound(anObject)) return;
944
945 TColStd_ListIteratorOfListOfInteger itl (myListOfStandardMode);
946
947 const Handle(AIS_LocalStatus)& LS = myActiveObjects(anObject);
948 if(LS->Decomposed()){
949 for(;itl.More();itl.Next()){
f751596e 950 myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS);
7fd59977 951 LS->AddSelectionMode(itl.Value());
952 }
953 }
954}
955
956
957//=======================================================================
958//function : ClearObjects
959//purpose :
960//=======================================================================
961
962void AIS_LocalContext::ClearObjects()
963{
964 AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
965 for(;It.More();It.Next())
966 {
967 Handle(AIS_InteractiveObject) SO =
968 Handle(AIS_InteractiveObject)::DownCast(It.Key());
969
970 const Handle(AIS_LocalStatus)& CurAtt = It.Value();
971 //TColStd_ListIteratorOfListOfInteger ItL;
81bba717 972 // if object is temporary the presentations managed by myMainPM are removed
7fd59977 973 AIS_DisplayStatus TheDS = myCTX->DisplayStatus(SO);
974
975 if(TheDS != AIS_DS_Displayed){
976 if(myMainPM->IsDisplayed(SO,CurAtt->DisplayMode())){
977 if(CurAtt->IsSubIntensityOn()&&
978 myMainPM->IsHighlighted(SO,CurAtt->HilightMode()))
979 myMainPM->Unhighlight(SO,CurAtt->HilightMode());
980 myMainPM->Erase(SO,CurAtt->DisplayMode());
981 }
982
983 if(CurAtt->IsTemporary()){
984 myMainPM->Erase(SO,CurAtt->DisplayMode());}
985// myMainPM->Clear(SO,CurAtt->DisplayMode());}
986 }
987 else {
a9dde4a3 988 if (CurAtt->IsSubIntensityOn())
989 {
990 myCTX->SubIntensityOff(SO);
991 }
7fd59977 992 Standard_Integer DiMo = SO->HasDisplayMode()?
993 SO->DisplayMode():myCTX->DisplayMode();
994 if(CurAtt->DisplayMode()!=-1 &&
995 CurAtt->DisplayMode()!= DiMo)
996 myMainPM->Erase(SO,CurAtt->DisplayMode());
997 }
998
f751596e 999 TColStd_ListIteratorOfListOfInteger aSelModeIter (CurAtt->SelectionModes());
1000 for ( ; aSelModeIter.More(); aSelModeIter.Next())
1001 {
1002 Standard_Integer aSelMode = aSelModeIter.Value();
1003 mySM->Deactivate (SO, aSelMode, myMainVS);
1004 }
1005
7fd59977 1006 }
1007 ClearSelected( Standard_False );
b3c433fe 1008
1009 // Clear selection structures for temporary objects, created in local context
1010 for (AIS_DataMapIteratorOfDataMapOfSelStat anIter (myActiveObjects); anIter.More(); anIter.Next())
1011 {
1012 if (anIter.Value()->IsTemporary())
1013 {
1014 mySM->Remove (anIter.Key(), myMainVS);
1015 }
1016 }
1017
7fd59977 1018 myActiveObjects.Clear();
7fd59977 1019}
1020
1021
1022Standard_Boolean AIS_LocalContext::IsDecompositionOn() const
1023{return !myListOfStandardMode.IsEmpty();}
1024
1025
1026
1027
1028//=======================================================================
1029//function : HasAlreadyFilters
1030//purpose :
1031//=======================================================================
1032
1033Standard_Boolean AIS_LocalContext::
1034HasFilters(const TopAbs_ShapeEnum aType) const
1035{
1036 return myFilters->ActsOn(aType);
1037}
1038
1039void AIS_LocalContext::ClearDetected()
1040{
b586500b 1041 for(Standard_Integer I=1;I<=myMapOfOwner->Extent();I++)
eb4320f2 1042 {
b586500b 1043 if(!myMapOfOwner->FindKey (I).IsNull())
eb4320f2 1044 {
b586500b 1045 if(myMapOfOwner->FindKey (I)->IsHilighted(myMainPM))
1046 myMapOfOwner->FindKey (I)->Unhilight(myMainPM);
eb4320f2 1047 else
1048 {
1049 const Handle(SelectMgr_SelectableObject)& SO =
b586500b 1050 myMapOfOwner->FindKey (I)->Selectable();
eb4320f2 1051 if(myActiveObjects.IsBound(SO))
1052 {
1053 const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO);
1054
1055 if(Att->IsTemporary() &&
1056 Att->DisplayMode()==-1 &&
1057 Att->SelectionModes().IsEmpty())
1058 {
b586500b 1059 myMapOfOwner->FindKey (I)->Clear(myMainPM);
eb4320f2 1060 }
1061 }
7fd59977 1062 }
1063 }
1064 }
7fd59977 1065}
1066
7fd59977 1067//=======================================================================
679ecdee 1068//function : BeginImmediateDraw
1069//purpose :
7fd59977 1070//=======================================================================
679ecdee 1071Standard_Boolean AIS_LocalContext::BeginImmediateDraw()
7fd59977 1072{
679ecdee 1073 if (myMainPM->IsImmediateModeOn())
1074 {
1075 myMainPM->BeginImmediateDraw();
7fd59977 1076 return Standard_True;
1077 }
1078 return Standard_False;
1079}
1080
679ecdee 1081//=======================================================================
1082//function : ImmediateAdd
1083//purpose :
1084//=======================================================================
1085Standard_Boolean AIS_LocalContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
1086 const Standard_Integer theMode)
7fd59977 1087{
679ecdee 1088 if (!myMainPM->IsImmediateModeOn())
1089 {
7fd59977 1090 return Standard_False;
679ecdee 1091 }
1092
af324faa 1093 myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode)->Presentation());
7fd59977 1094 return Standard_True;
1095}
1096
679ecdee 1097//=======================================================================
1098//function : EndImmediateDraw
1099//purpose :
1100//=======================================================================
c3282ec1 1101Standard_Boolean AIS_LocalContext::EndImmediateDraw (const Handle(V3d_Viewer)& theViewer)
7fd59977 1102{
679ecdee 1103 if (!myMainPM->IsImmediateModeOn())
1104 {
1105 return Standard_False;
1106 }
1107
c3282ec1 1108 myMainPM->EndImmediateDraw (theViewer);
7fd59977 1109 return Standard_True;
1110}
1111
679ecdee 1112// =======================================================================
1113// function : ClearImmediateDraw
1114// purpose :
1115// =======================================================================
1116void AIS_LocalContext::ClearImmediateDraw()
7fd59977 1117{
679ecdee 1118 myMainPM->ClearImmediateDraw();
7fd59977 1119}
1120
679ecdee 1121//=======================================================================
1122//function : IsImmediateModeOn
1123//purpose :
1124//=======================================================================
7fd59977 1125Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const
679ecdee 1126{
1127 return myMainPM->IsImmediateModeOn();
1128}
7fd59977 1129
3bf9a45f 1130void AIS_LocalContext::SetPixelTolerance(const Standard_Integer aPrecision) {
3c982548 1131
1132 myMainVS->SetPixelTolerance(aPrecision);
1133}
1134
3bf9a45f 1135Standard_Integer AIS_LocalContext::PixelTolerance() const {
3c982548 1136
1137 return myMainVS->PixelTolerance();
7fd59977 1138}
8a1170ad 1139
1140//=======================================================================
1141//function : SetSelectionSensitivity
1142//purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
1143//=======================================================================
1144void AIS_LocalContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
1145 const Standard_Integer theMode,
1146 const Standard_Integer theNewSensitivity)
1147{
1148 mySM->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
1149}