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