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