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