0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- manual
[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>
26#include <AIS_Selection.hxx>
27#include <AIS_Shape.hxx>
28#include <Aspect_TypeOfMarker.hxx>
7fd59977 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>
42cf5bc1 34#include <SelectMgr_CompositionFilter.hxx>
35#include <SelectMgr_EntityOwner.hxx>
36#include <SelectMgr_Filter.hxx>
37#include <SelectMgr_OrFilter.hxx>
38#include <SelectMgr_SelectableObject.hxx>
39#include <SelectMgr_SelectionManager.hxx>
40#include <Standard_Transient.hxx>
41#include <Standard_Type.hxx>
7fd59977 42#include <StdSelect_ShapeTypeFilter.hxx>
f751596e 43#include <StdSelect_ViewerSelector3d.hxx>
42cf5bc1 44#include <TCollection_AsciiString.hxx>
45#include <TColStd_ListIteratorOfListOfInteger.hxx>
46#include <TopAbs_ShapeEnum.hxx>
47#include <TopoDS_Shape.hxx>
7fd59977 48#include <V3d_View.hxx>
42cf5bc1 49#include <V3d_Viewer.hxx>
7fd59977 50
7fd59977 51#include <stdio.h>
7fd59977 52static TCollection_AsciiString AIS_Local_SelName(const Standard_Address address,
53 const Standard_Integer anIndex)
54{
55// TCollection_AsciiString SelName;
7fd59977 56 char string[100];
57 sprintf(string,"%p_%d", address, anIndex); // works under any system
58 TCollection_AsciiString SelName(string);
7fd59977 59 return SelName;
60}
61
62
63//=======================================================================
64//function : AIS_LocalContext
65//purpose :
66//=======================================================================
67
68
69AIS_LocalContext::AIS_LocalContext(){}
70
71AIS_LocalContext::AIS_LocalContext(const Handle(AIS_InteractiveContext)& aCtx,
72 const Standard_Integer Index,
73 const Standard_Boolean LoadDisplayed,
74 const Standard_Boolean AcceptStandardModes,
75 const Standard_Boolean AcceptEraseOfTemp,
35e08fe8 76 const Standard_Boolean /*BothViewers*/):
7fd59977 77myCTX(aCtx),
78myLoadDisplayed(LoadDisplayed),
79myAcceptStdMode(AcceptStandardModes),
80myAcceptErase(AcceptEraseOfTemp),
81mySM(aCtx->SelectionManager()),
f751596e 82myMainVS(aCtx->MainSelector()),
7fd59977 83myFilters(new SelectMgr_OrFilter()),
84myAutoHilight(Standard_True),
b586500b 85myMapOfOwner (new SelectMgr_IndexedMapOfOwner()),
7fd59977 86mylastindex(0),
87mylastgood(0),
d2094e11 88myCurDetected(0),
89myAISCurDetected(0)
90
7fd59977 91{
64e2d3bd 92 // bind self to AIS_InteractiveContext::myLocalContexts. Further, the
93 // constructor executes logic that implies that the context is already
94 // created and mapped.
95 aCtx->myLocalContexts.Bind (Index, this);
96
f751596e 97 myMainVS->ResetSelectionActivationStatus();
7fd59977 98 myMainPM = aCtx->MainPrsMgr();
99 mySelName = AIS_Local_SelName(this, Index);
100 AIS_Selection::CreateSelection(mySelName.ToCString());
101
102 mySM->Add(myMainVS);
103 if(myLoadDisplayed) LoadContextObjects();
f751596e 104 Process();
7fd59977 105
106}
107
108
109//=======================================================================
110//function : SetContext
111//purpose :
112//=======================================================================
113
114void AIS_LocalContext::SetContext(const Handle(AIS_InteractiveContext)& aCtx)
115{ myCTX = aCtx;}
116
117//=======================================================================
118//function : Display
119//purpose :
120//=======================================================================
121
122Standard_Boolean AIS_LocalContext::Display(const Handle(AIS_InteractiveObject)& anInteractive,
123 const Standard_Integer WhichMode,
124 const Standard_Boolean AllowShapeDecomposition,
125 const Standard_Integer ActivationMode)
126{
127 if(myActiveObjects.IsBound(anInteractive)){
128 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
129
130 if(STAT->DisplayMode() == -1){
131 if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
132 myMainPM->Display(anInteractive,WhichMode);
133 if(STAT->IsTemporary())
134 STAT->SetDisplayMode(WhichMode);
135 }
136 else if(STAT->DisplayMode()!=WhichMode && STAT->IsTemporary()){
137 myMainPM->Erase(anInteractive,STAT->DisplayMode());
138 STAT->SetDisplayMode(WhichMode);
139 if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
140 myMainPM->Display(anInteractive,WhichMode);
141 }
142
143 if(ActivationMode!=-1){
144 if(!STAT->IsActivated(ActivationMode)){
145 STAT->ClearSelectionModes();
146 mySM->Load(anInteractive,myMainVS);
147 STAT->AddSelectionMode(ActivationMode);
148 mySM->Activate(anInteractive,ActivationMode,myMainVS);
149 }
150 }
151 }
152 else {
153 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
154
155 if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
156 Att->SetDecomposition(Standard_True);
157 else
158 Att->SetDecomposition(Standard_False);
81bba717 159 // status temporary or not
7fd59977 160 if(myCTX->DisplayStatus(anInteractive) == AIS_DS_None ||
161 myCTX->DisplayStatus(anInteractive) == AIS_DS_Temporary)
162 Att->SetTemporary(Standard_True);
163 else
164 Att->SetTemporary(Standard_False);
165
166
167
168 if(!myCTX->IsDisplayed(anInteractive,WhichMode)){
169
170 //storing information....
171 Att->SetDisplayMode(WhichMode);
172 if (ActivationMode!=-1)
173 Att->AddSelectionMode(ActivationMode);
174 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
175 Att->SetHilightMode(HiMod);
176
177 if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
178 myMainPM->Display(anInteractive,WhichMode);
179
180 if(ActivationMode!=-1){
181 mySM->Load(anInteractive,myMainVS);
182 mySM->Activate(anInteractive,ActivationMode,myMainVS);
183 }
184 }
185 else{
186 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
187 Att->SetHilightMode(HiMod);
188 }
189 myActiveObjects.Bind(anInteractive,Att);
190 }
191 Process(anInteractive);
192
193
194
195
196 return Standard_True;
197}
198
199//=======================================================================
200//function : Load
201//purpose :
202//=======================================================================
203
204Standard_Boolean AIS_LocalContext::
205Load(const Handle(AIS_InteractiveObject)& anInteractive,
206 const Standard_Boolean AllowShapeDecomposition,
207 const Standard_Integer ActivationMode)
208{
f751596e 209 if (myActiveObjects.IsBound (anInteractive))
210 {
211 if (anInteractive->HasSelection (ActivationMode))
212 {
213 const Handle(SelectMgr_Selection)& aSel = anInteractive->Selection (ActivationMode);
214 if (aSel->GetSelectionState() != SelectMgr_SOS_Activated)
215 {
216 if (!myMainVS->Contains (anInteractive))
217 {
218 mySM->Load (anInteractive, myMainVS);
219 }
220 mySM->Activate (anInteractive, ActivationMode, myMainVS);
221 return Standard_True;
222 }
223 }
224 return Standard_False;
225 }
226
7fd59977 227 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
228
229 if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
230 Att->SetDecomposition(Standard_True);
231 else
232 Att->SetDecomposition(Standard_False);
233
234 if(!myCTX->IsDisplayed(anInteractive))
235 Att->SetTemporary(Standard_True);
236 else
237 Att->SetTemporary(Standard_False);
238 Att->SetDisplayMode(-1);
239
240 //storing information....
241 if(ActivationMode!=-1)
242 Att->AddSelectionMode(ActivationMode);
243 Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode():0;
244 Att->SetHilightMode(HiMod);
245 //Action
246
247 mySM->Load(anInteractive,myMainVS);
248 if(ActivationMode != -1){
249 mySM->Activate(anInteractive,ActivationMode,myMainVS);
250 }
251 myActiveObjects.Bind(anInteractive,Att);
252 Process(anInteractive);
253 return Standard_True;
254}
255
256//=======================================================================
257//function : ClearPrs
258//purpose :
259//=======================================================================
260
261Standard_Boolean AIS_LocalContext::
262ClearPrs(const Handle(AIS_InteractiveObject)& anInteractive,
263 const Standard_Integer aMode)
264{
265 if(!myActiveObjects.IsBound(anInteractive))
266 return Standard_False;
267
268 Standard_Boolean jobdone(Standard_False);
269 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
270
271 //Display step
272 if(STAT->IsSubIntensityOn()) {
273 STAT->SubIntensityOff();
274 if(STAT->HilightMode()==aMode)
275 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
276 }
277 myMainPM->Clear(anInteractive,aMode); // correction connexions 23/09/97
278 jobdone = Standard_True;
279 if(STAT->DisplayMode()==aMode)
280 STAT->SetDisplayMode(-1);
281 return jobdone;
282}
283//=======================================================================
284//function : Erase
285//purpose :
286//=======================================================================
287
288Standard_Boolean AIS_LocalContext::
289Erase(const Handle(AIS_InteractiveObject)& anInteractive)
290{
291 if(!myActiveObjects.IsBound(anInteractive))
292 return Standard_False;
293 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
294
295 //Display step
296 if(STAT->IsSubIntensityOn()) {
297 STAT->SubIntensityOff();
298 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
299 }
300
301 Standard_Boolean status(Standard_False);
302
303 if(STAT->DisplayMode()!=-1) {
304 if(IsSelected(anInteractive))
305 AddOrRemoveSelected(anInteractive);
306 if(myMainPM->IsHighlighted(anInteractive,STAT->HilightMode()))
307 myMainPM->Unhighlight(anInteractive,STAT->HilightMode());
eb4320f2 308 myMainPM->SetVisibility (anInteractive, STAT->DisplayMode(), Standard_False);
7fd59977 309 STAT->SetDisplayMode(-1);
310 status = Standard_True;
311 }
312 if(STAT->IsTemporary()){
313 if(myMainPM->IsDisplayed(anInteractive,STAT->HilightMode()))
eb4320f2 314 myMainPM->SetVisibility (anInteractive, STAT->HilightMode(), Standard_False);
7fd59977 315 }
fb4b684a 316
317 // Deactivate selectable entities of interactive object
543a9964 318 const Handle(SelectMgr_SelectableObject)& anObj = anInteractive; // to avoid ambiguity
319 if (mySM->Contains (anObj))
fb4b684a 320 {
c3282ec1 321 while (!STAT->SelectionModes().IsEmpty())
fb4b684a 322 {
c3282ec1 323 mySM->Deactivate (anInteractive, STAT->SelectionModes().Last(), myMainVS);
324 STAT->RemoveSelectionMode (STAT->SelectionModes().Last());
fb4b684a 325 }
326 }
327
bc677575 328 ClearOutdatedSelection (anInteractive, Standard_True);
fb4b684a 329
7fd59977 330 return status;
331}
332
333
334//=======================================================================
335//function : SetShapeDecomposition
336//purpose :
337//=======================================================================
338
339void AIS_LocalContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& aStoredObject,
340 const Standard_Boolean aStatus)
341{
342 if(!myActiveObjects.IsBound(aStoredObject)) return;
343
344 if(aStatus == myActiveObjects(aStoredObject)->Decomposed())
345 return;
346
347 myActiveObjects(aStoredObject)->SetDecomposition(aStatus);
348
349 Process(aStoredObject);
350}
351
352//=======================================================================
353//function : Clear
354//purpose :
355//=======================================================================
356
357void AIS_LocalContext::Clear(const AIS_ClearMode aType)
358{
359 switch (aType){
360 case AIS_CM_All:
361 {
362 ClearObjects();
363 myFilters->Clear();
364 while(!myListOfStandardMode.IsEmpty())
365 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
366 break;
367 }
368 case AIS_CM_Interactive:
369 ClearObjects();
370 break;
371 case AIS_CM_Filters:
372 myFilters->Clear();
373 break;
374 case AIS_CM_StandardModes:
375 {
376 while(!myListOfStandardMode.IsEmpty())
377 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
378 break;
379 }
380 case AIS_CM_TemporaryShapePrs:
381 ClearDetected();
382 }
7fd59977 383}
384//=======================================================================
385//function : ActivateMode
386//purpose :
387//=======================================================================
388
389void AIS_LocalContext::ActivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
390 const Standard_Integer aMode)
391{
392 if(!myActiveObjects.IsBound(aSelectable)) return;
393// if(myActiveObjects(aSelectable)->SelectionMode()!=aMode)
394// mySM->Deactivate(aSelectable,aMode,myMainVS);
395 if(aMode != -1){
396 myActiveObjects(aSelectable)->AddSelectionMode(aMode);
397 mySM->Activate(aSelectable,aMode,myMainVS);
398 }
7fd59977 399}
400//=======================================================================
401//function : ActivateMode
402//purpose :
403//=======================================================================
404
405void AIS_LocalContext::DeactivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
406 const Standard_Integer aMode)
407{
408 if(!myActiveObjects.IsBound(aSelectable)) return;
409
410 if(aMode==-1) return;
411
412 myActiveObjects(aSelectable)->RemoveSelectionMode(aMode);
413 mySM->Deactivate(aSelectable,aMode,myMainVS);
7fd59977 414}
415//=======================================================================
416//function : ActivateMode
417//purpose :
418//=======================================================================
419
420void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectable)
421{
422 if(!myActiveObjects.IsBound(aSelectable)) return;
423
f751596e 424 mySM->Deactivate(aSelectable, -1, myMainVS);
7fd59977 425 myActiveObjects(aSelectable)->ClearSelectionModes();
7fd59977 426}
427
428//=======================================================================
429//function : Remove
430//purpose :
431//=======================================================================
432
433Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& aSelectable)
434{
7fd6425d 435 if(!myActiveObjects.IsBound (aSelectable))
436 {
437 return Standard_False;
438 }
439
440 if (IsSelected (aSelectable))
441 {
442 AddOrRemoveSelected (aSelectable, Standard_False);
443 }
444
445 const Handle(AIS_LocalStatus)& Att = myActiveObjects (aSelectable);
7fd59977 446
7fd59977 447 TColStd_ListIteratorOfListOfInteger It;
7fd59977 448
7fd6425d 449 // Deactivate standard modes
450 if (Att->Decomposed())
451 {
452 for (It.Initialize (myListOfStandardMode); It.More(); It.Next())
453 {
454 mySM->Deactivate (aSelectable, It.Value(), myMainVS);
7fd59977 455 }
456 }
7fd6425d 457
458 // If object or temporary presentations
459 if (Att->IsTemporary())
460 {
461 if (Att->IsSubIntensityOn())
7fd59977 462 {
7fd6425d 463 myMainPM->Unhighlight (aSelectable, Att->HilightMode());
7fd59977 464 }
7fd6425d 465
466 myMainPM->Erase (aSelectable, Att->DisplayMode());
467 myMainPM->Clear (aSelectable, Att->DisplayMode());
468 if (myMainPM->IsDisplayed (aSelectable, Att->HilightMode()))
7fd59977 469 {
7fd6425d 470 myMainPM->Erase (aSelectable, Att->HilightMode());
7fd59977 471 }
7fd59977 472 }
7fd6425d 473 // If subintensity used
474 else if (Att->IsSubIntensityOn())
475 {
476 myCTX->SubIntensityOff (aSelectable);
477 }
7fd59977 478
7fd6425d 479 // Deactivate stored selection modes
480 for (It.Initialize (Att->SelectionModes()); It.More(); It.Next())
481 {
482 mySM->Deactivate (aSelectable, It.Value(), myMainVS);
483 }
7fd59977 484
fb4b684a 485 // Remove the interactive object from selection manager
543a9964 486 const Handle(SelectMgr_SelectableObject)& anObj = aSelectable; // to avoid ambiguity
487 if (mySM->Contains (anObj))
7fd59977 488 {
543a9964 489 mySM->Remove (anObj);
7fd59977 490 }
bc677575 491 ClearOutdatedSelection (aSelectable, Standard_True);
7fd59977 492
7fd6425d 493 // This should be done at the very end because most methods use
494 // myActiveObjects even during clean-up
495 myActiveObjects.UnBind (aSelectable);
7fd59977 496 return Standard_True;
497}
498
499//=======================================================================
500//function : ActivateStandardMode
501//purpose :
502//=======================================================================
503
504void AIS_LocalContext::ActivateStandardMode(const TopAbs_ShapeEnum aType)
505{
506
81bba717 507 //check if it is not in the list
7fd59977 508 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
509 for(;It.More();It.Next())
510 if(It.Value()==aType) return;
511 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
512
513
81bba717 514 // create a hidden filter answering ok to the type except for :
515 // if the type is shape...
516 // if the filters already impact at the type <aType>
7fd59977 517 if(aType != TopAbs_SHAPE){
518 if(myStdFilters[IMode].IsNull())
519 myStdFilters[IMode] = new StdSelect_ShapeTypeFilter(aType);
520 if(!HasFilters(aType))
521 myFilters->Add(myStdFilters[IMode]);
522 }
523
81bba717 524 // the mode is activated for all objects of type Shape
525 // accepting the decomposition in standard mode.
7fd59977 526 myListOfStandardMode.Append(IMode);
527
528 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
529
530 for(;ItM.More();ItM.Next()){
7fd59977 531 if(ItM.Value()->Decomposed())
7fd59977 532 myCTX->SelectionManager()->Activate(ItM.Key(),
533 IMode,
534 myMainVS);
535 }
536
537}
538
539//=======================================================================
540//function : DeActivateStandardMode
541//purpose :
542//=======================================================================
543
544void AIS_LocalContext::DeactivateStandardMode(const TopAbs_ShapeEnum aType)
545{
546 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
547 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
548 for(;It.More();It.Next())
549 if(It.Value()==IMode) {
550 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
551
552 for(;ItM.More();ItM.Next()){
553 if(ItM.Value()->Decomposed()){
554 myCTX->SelectionManager()->Deactivate(ItM.Key(),
555 IMode,
556 myMainVS);
557 ItM.Value()->RemoveSelectionMode(IMode);
558 }
559 }
560 myListOfStandardMode.Remove(It);
561 if(myFilters->IsIn(myStdFilters[IMode]))
562 myFilters->Remove(myStdFilters[IMode]);
7fd59977 563 return;
564 }
7fd59977 565}
566
567//=======================================================================
568//function : AddFilter
569//purpose :
570//=======================================================================
571
572void AIS_LocalContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
573{
81bba717 574 // it is checked if the filter impacts at the type of active sub-shape
575 // for which a filter of type has been already implemented...
7fd59977 576
577 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
578
579 for(;It.More();It.Next()){
580 if(aFilter->ActsOn(AIS_Shape::SelectionType(It.Value())))
581 if(myFilters->IsIn(myStdFilters[It.Value()]))
582 myFilters->Remove(myStdFilters[It.Value()]);
583 }
584 myFilters->Add(aFilter);
585}
586
587//=======================================================================
588//function : RemoveFilter
589//purpose :
590//=======================================================================
591
592void AIS_LocalContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
593{
594 if(myFilters->IsIn(aFilter)) myFilters->Remove(aFilter);
595
81bba717 596 // it is checked if the filter for type standard is active.
597 // if yes, it is checked there are still similarities among the
598 // remaining filters...
599 // otherwise, the standard filter is restored to
600 // continu selecting active modes...
7fd59977 601 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
602 TopAbs_ShapeEnum SE;
603 for(;It.More();It.Next()){
604 SE = AIS_Shape::SelectionType(It.Value());
605 if(aFilter->ActsOn(SE))
606 if(!HasFilters(SE))
607 myFilters->Add(myStdFilters[It.Value()]);
608 }
609}
610
7fd59977 611//=======================================================================
612//function : Terminate
679ecdee 613//purpose :
7fd59977 614//=======================================================================
615
679ecdee 616void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate)
7fd59977 617{
618 ClearDetected();
619 Clear();
b586500b 620 myMapOfOwner->Clear();
7fd59977 621
622 mylastindex=0;
81bba717 623 // clear the selector...
7fd59977 624 myMainVS->Clear();
7fd59977 625
626
627 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
628 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
629 Handle(Standard_Transient) Tr;
630 for(S->Init();S->More();S->Next()){
631 Tr = S->Value();
c5f3a425 632 Handle(SelectMgr_EntityOwner)::DownCast (Tr)->SetSelected (Standard_False);
7fd59977 633 }
634
635
636 AIS_Selection::Select();
637 AIS_Selection::Remove(mySelName.ToCString());
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//=======================================================================
c3282ec1 1117Standard_Boolean AIS_LocalContext::EndImmediateDraw (const Handle(V3d_Viewer)& theViewer)
7fd59977 1118{
679ecdee 1119 if (!myMainPM->IsImmediateModeOn())
1120 {
1121 return Standard_False;
1122 }
1123
c3282ec1 1124 myMainPM->EndImmediateDraw (theViewer);
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
3bf9a45f 1146void AIS_LocalContext::SetPixelTolerance(const Standard_Integer aPrecision) {
3c982548 1147
1148 myMainVS->SetPixelTolerance(aPrecision);
1149}
1150
3bf9a45f 1151Standard_Integer AIS_LocalContext::PixelTolerance() const {
3c982548 1152
1153 return myMainVS->PixelTolerance();
7fd59977 1154}
8a1170ad 1155
1156//=======================================================================
1157//function : SetSelectionSensitivity
1158//purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
1159//=======================================================================
1160void AIS_LocalContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
1161 const Standard_Integer theMode,
1162 const Standard_Integer theNewSensitivity)
1163{
1164 mySM->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
1165}