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