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