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