0025371: Visualization - raise exception in AIS_ConnectedInteractive::Connect() on...
[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
336 // Remove object from current selection of local context
337 ClearSelected (anInteractive, Standard_False);
338
7fd59977 339 return status;
340}
341
342
343//=======================================================================
344//function : SetShapeDecomposition
345//purpose :
346//=======================================================================
347
348void AIS_LocalContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& aStoredObject,
349 const Standard_Boolean aStatus)
350{
351 if(!myActiveObjects.IsBound(aStoredObject)) return;
352
353 if(aStatus == myActiveObjects(aStoredObject)->Decomposed())
354 return;
355
356 myActiveObjects(aStoredObject)->SetDecomposition(aStatus);
357
358 Process(aStoredObject);
359}
360
361//=======================================================================
362//function : Clear
363//purpose :
364//=======================================================================
365
366void AIS_LocalContext::Clear(const AIS_ClearMode aType)
367{
368 switch (aType){
369 case AIS_CM_All:
370 {
371 ClearObjects();
372 myFilters->Clear();
373 while(!myListOfStandardMode.IsEmpty())
374 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
375 break;
376 }
377 case AIS_CM_Interactive:
378 ClearObjects();
379 break;
380 case AIS_CM_Filters:
381 myFilters->Clear();
382 break;
383 case AIS_CM_StandardModes:
384 {
385 while(!myListOfStandardMode.IsEmpty())
386 DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
387 break;
388 }
389 case AIS_CM_TemporaryShapePrs:
390 ClearDetected();
391 }
392 UpdateSort();
393}
394//=======================================================================
395//function : ActivateMode
396//purpose :
397//=======================================================================
398
399void AIS_LocalContext::ActivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
400 const Standard_Integer aMode)
401{
402 if(!myActiveObjects.IsBound(aSelectable)) return;
403// if(myActiveObjects(aSelectable)->SelectionMode()!=aMode)
404// mySM->Deactivate(aSelectable,aMode,myMainVS);
405 if(aMode != -1){
406 myActiveObjects(aSelectable)->AddSelectionMode(aMode);
407 mySM->Activate(aSelectable,aMode,myMainVS);
408 }
409 UpdateSort();
410}
411//=======================================================================
412//function : ActivateMode
413//purpose :
414//=======================================================================
415
416void AIS_LocalContext::DeactivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
417 const Standard_Integer aMode)
418{
419 if(!myActiveObjects.IsBound(aSelectable)) return;
420
421 if(aMode==-1) return;
422
423 myActiveObjects(aSelectable)->RemoveSelectionMode(aMode);
424 mySM->Deactivate(aSelectable,aMode,myMainVS);
425 UpdateSort();
426
427}
428//=======================================================================
429//function : ActivateMode
430//purpose :
431//=======================================================================
432
433void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectable)
434{
435 if(!myActiveObjects.IsBound(aSelectable)) return;
436
437 mySM->Deactivate(aSelectable,myMainVS);
438 myActiveObjects(aSelectable)->ClearSelectionModes();
439 UpdateSort();
440}
441
442//=======================================================================
443//function : Remove
444//purpose :
445//=======================================================================
446
447Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& aSelectable)
448{
449 if(!myActiveObjects.IsBound(aSelectable)) return Standard_False;
450
451 if(IsSelected(aSelectable))
452 AddOrRemoveSelected(aSelectable,Standard_False);
453
454 const Handle(AIS_LocalStatus)& Att = myActiveObjects(aSelectable);
455
456 TColStd_ListIteratorOfListOfInteger It;
81bba717 457 // it is checked which were the temporary attributes
458 // and they are set to 0
7fd59977 459
81bba717 460 // desactivate standard modes
7fd59977 461 if(Att->Decomposed()){
462 for(It.Initialize(myListOfStandardMode);It.More();It.Next()){
463 mySM->Deactivate(aSelectable,It.Value(),myMainVS);
464 }
465 }
466
81bba717 467 // if object or temporary presentations...
7fd59977 468 if(Att->IsTemporary())
469 {
470 if(Att->IsSubIntensityOn())
471 myMainPM->Unhighlight(aSelectable,Att->HilightMode());
472
81bba717 473 // remove if bug on clear correct...
7fd59977 474 myMainPM->Erase(aSelectable,Att->DisplayMode());
475 myMainPM->Clear(aSelectable,Att->DisplayMode());
476 if(myMainPM->IsDisplayed(aSelectable,Att->HilightMode()))
477 myMainPM->Erase(aSelectable,Att->HilightMode());
478 // myMainPM->Clear(aSelectable,Att->HilightMode());
7fd59977 479 }
81bba717 480 // if below intensity
7fd59977 481 else
482 {
483 if(Att->IsSubIntensityOn())
484 myCTX->SubIntensityOff(aSelectable);
485 }
81bba717 486 // desactivate stored proper modes
7fd59977 487 for(It.Initialize(Att->SelectionModes());It.More();It.Next()){
488 mySM->Deactivate(aSelectable,It.Value(),myMainVS);
489 }
ab943560 490// pop : si je laisses cela plantes dans les elements de construction
491// alors a toi de jouer ROB
7fd59977 492// RemoveSelected(aSelectable);
493
494 if(IsSelected(aSelectable))
495 AddOrRemoveSelected(aSelectable);
496 myActiveObjects.UnBind(aSelectable);
497
fb4b684a 498 // Remove the interactive object from selection manager
499 if (mySM->Contains (aSelectable))
7fd59977 500 {
fb4b684a 501 mySM->Remove (aSelectable);
7fd59977 502 }
503
fb4b684a 504 UpdateSort();
505
506 // Remove object from current selection of local context
507 ClearSelected (aSelectable, Standard_False);
7fd59977 508
509 return Standard_True;
510}
511
512//=======================================================================
513//function : ActivateStandardMode
514//purpose :
515//=======================================================================
516
517void AIS_LocalContext::ActivateStandardMode(const TopAbs_ShapeEnum aType)
518{
519
81bba717 520 //check if it is not in the list
7fd59977 521 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
522 for(;It.More();It.Next())
523 if(It.Value()==aType) return;
524 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
525
526
81bba717 527 // create a hidden filter answering ok to the type except for :
528 // if the type is shape...
529 // if the filters already impact at the type <aType>
7fd59977 530 if(aType != TopAbs_SHAPE){
531 if(myStdFilters[IMode].IsNull())
532 myStdFilters[IMode] = new StdSelect_ShapeTypeFilter(aType);
533 if(!HasFilters(aType))
534 myFilters->Add(myStdFilters[IMode]);
535 }
536
81bba717 537 // the mode is activated for all objects of type Shape
538 // accepting the decomposition in standard mode.
7fd59977 539 myListOfStandardMode.Append(IMode);
540
541 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
542
543 for(;ItM.More();ItM.Next()){
7fd59977 544 if(ItM.Value()->Decomposed())
7fd59977 545 myCTX->SelectionManager()->Activate(ItM.Key(),
546 IMode,
547 myMainVS);
548 }
549
550}
551
552//=======================================================================
553//function : DeActivateStandardMode
554//purpose :
555//=======================================================================
556
557void AIS_LocalContext::DeactivateStandardMode(const TopAbs_ShapeEnum aType)
558{
559 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
560 Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
561 for(;It.More();It.Next())
562 if(It.Value()==IMode) {
563 AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
564
565 for(;ItM.More();ItM.Next()){
566 if(ItM.Value()->Decomposed()){
567 myCTX->SelectionManager()->Deactivate(ItM.Key(),
568 IMode,
569 myMainVS);
570 ItM.Value()->RemoveSelectionMode(IMode);
571 }
572 }
573 myListOfStandardMode.Remove(It);
574 if(myFilters->IsIn(myStdFilters[IMode]))
575 myFilters->Remove(myStdFilters[IMode]);
576 UpdateSort();
577 return;
578 }
579 UpdateSort();
580}
581
582//=======================================================================
583//function : AddFilter
584//purpose :
585//=======================================================================
586
587void AIS_LocalContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
588{
81bba717 589 // it is checked if the filter impacts at the type of active sub-shape
590 // for which a filter of type has been already implemented...
7fd59977 591
592 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
593
594 for(;It.More();It.Next()){
595 if(aFilter->ActsOn(AIS_Shape::SelectionType(It.Value())))
596 if(myFilters->IsIn(myStdFilters[It.Value()]))
597 myFilters->Remove(myStdFilters[It.Value()]);
598 }
599 myFilters->Add(aFilter);
600}
601
602//=======================================================================
603//function : RemoveFilter
604//purpose :
605//=======================================================================
606
607void AIS_LocalContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
608{
609 if(myFilters->IsIn(aFilter)) myFilters->Remove(aFilter);
610
81bba717 611 // it is checked if the filter for type standard is active.
612 // if yes, it is checked there are still similarities among the
613 // remaining filters...
614 // otherwise, the standard filter is restored to
615 // continu selecting active modes...
7fd59977 616 TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
617 TopAbs_ShapeEnum SE;
618 for(;It.More();It.Next()){
619 SE = AIS_Shape::SelectionType(It.Value());
620 if(aFilter->ActsOn(SE))
621 if(!HasFilters(SE))
622 myFilters->Add(myStdFilters[It.Value()]);
623 }
624}
625
626
627
ab943560 628Standard_Boolean AIS_LocalContext::HasSameProjector(const Handle(Select3D_Projector)& thePrj) const
7fd59977 629{
ab943560 630 const Handle(Select3D_Projector)& aCurPrj = myMainVS->Projector();
631 if (aCurPrj->Perspective() != thePrj->Perspective())
632 return Standard_False;
633 if (aCurPrj->Perspective() && aCurPrj->Focus() != thePrj->Focus())
634 return Standard_False;
635 const gp_GTrsf& aCurTrsf = aCurPrj->Transformation();
636 const gp_GTrsf& aPrjTrsf = thePrj->Transformation();
637
638 for (Standard_Integer i = 1; i <= 3; ++i)
639 {
640 for (Standard_Integer j = 1; j <= 3 ; ++j)
641 {
642 if (aCurTrsf.Value (i, j) != aPrjTrsf.Value (i, j))
643 return Standard_False;
7fd59977 644 }
645 }
ab943560 646
7fd59977 647 return Standard_True;
648}
649
650
651//=======================================================================
652//function : Terminate
679ecdee 653//purpose :
7fd59977 654//=======================================================================
655
679ecdee 656void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate)
7fd59977 657{
658 ClearDetected();
659 Clear();
660 myMapOfOwner.Clear();
661
662 mylastindex=0;
81bba717 663 // clear the selector...
7fd59977 664 myMainVS->Clear();
665 myCTX->SelectionManager()->Remove(myMainVS);
666
667
668 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
669 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
670 Handle(Standard_Transient) Tr;
671 for(S->Init();S->More();S->Next()){
672 Tr = S->Value();
c398b00e 673 (*((Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False);
7fd59977 674 }
675
676
677 AIS_Selection::Select();
678 AIS_Selection::Remove(mySelName.ToCString());
679
679ecdee 680 Handle(V3d_Viewer) aViewer = myCTX->CurrentViewer();
681 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
682 {
683 Handle(V3d_View) aView = aViewer->ActiveView();
684 aView->View()->ClearImmediate();
7fd59977 685 }
686
679ecdee 687 Handle(V3d_View) aDummyView;
688 myMainVS->ClearAreas (aDummyView);
689 myMainVS->ClearSensitive (aDummyView);
7fd59977 690
679ecdee 691 if (theToUpdate)
692 {
693 myCTX->UpdateCurrentViewer();
694 }
7fd59977 695}
696
697
698//=======================================================================
699//function : SubIntensity
700//purpose :
701//=======================================================================
702
703void AIS_LocalContext::SubIntensityOn(const Handle(AIS_InteractiveObject)& anObject)
704{
705 if(!myActiveObjects.IsBound(anObject)) return;
706
707 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
708
709 if(Att->IsTemporary())
710 myMainPM->Color(anObject,myCTX->SubIntensityColor(),Att->DisplayMode());
711
712 Att->SubIntensityOn();
713}
714//=======================================================================
715//function : SubIntensity
716//purpose :
717//=======================================================================
718
719void AIS_LocalContext::SubIntensityOff(const Handle(AIS_InteractiveObject)& anObject)
720{
721 if(!myActiveObjects.IsBound(anObject)) return;
722
723 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
724
725 if(Att->IsTemporary())
726 myMainPM->Unhighlight(anObject);
727 Att->SubIntensityOff();
728}
729
730
731//=======================================================================
732//function : Hilight
733//purpose :
734//=======================================================================
735
736void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject)
737{
738 if(!myActiveObjects.IsBound(anObject)){
739 Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0;
740 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
741 Standard_False,
742 -1,-1,HiMod);
743 myActiveObjects.Bind(anObject,Att);
744
745 }
746 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
747 myMainPM->Color(anObject,myCTX->HilightColor(),Att->HilightMode());
748 Att->SubIntensityOn();
749}
750//=======================================================================
751//function : Hilight
752//purpose :
753//=======================================================================
754
755void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject,
756 const Quantity_NameOfColor Col)
757{
758 if(!myActiveObjects.IsBound(anObject)){
759 Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0;
760 Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
761 Standard_False,
762 -1,-1,HiMod);
763 myActiveObjects.Bind(anObject,Att);
764
765 }
766 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
767 myMainPM->Color(anObject,Col,Att->HilightMode());
768 Att->SubIntensityOn();
769 Att->SetHilightColor(Col);
770}
771
772//=======================================================================
773//function : Unhilight
774//purpose :
775//=======================================================================
776
777void AIS_LocalContext::Unhilight(const Handle(AIS_InteractiveObject)& anObject)
778{
779 if(!myActiveObjects.IsBound(anObject)) return;
780
81bba717 781 // chieck if by hazard the object is somewhere else...
7fd59977 782 Standard_Integer Indx;
783 Standard_Boolean IsSomeWhereElse =
784 myCTX->IsInLocal(anObject,Indx) && Indx != myCTX->IndexOfCurrentLocal();
785
786 const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
787 myMainPM->Unhighlight(anObject,Att->HilightMode());
788 if(Att->IsTemporary() && Att->DisplayMode()==-1)
789 if(!IsSomeWhereElse)
eb4320f2 790 myMainPM->SetVisibility (anObject, Att->HilightMode(), Standard_False);
791
7fd59977 792 Att->SubIntensityOff();
793 Att->SetHilightColor(Quantity_NOC_WHITE);
794}
795
796
797//=======================================================================
798//function : IsIn
799//purpose :
800//=======================================================================
801
802Standard_Boolean AIS_LocalContext::
803IsIn(const Handle(AIS_InteractiveObject)& anObject) const
804{
805 return myActiveObjects.IsBound(anObject);
806}
807
808//=======================================================================
809//function : IsHilighted
810//purpose :
811//=======================================================================
812
813Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject) const
814{
815 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
816 return myActiveObjects(anObject)->IsSubIntensityOn();
817}
818
819Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject,
820 Standard_Boolean& WithColor,
821 Quantity_NameOfColor& HiCol) const
822{
823 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
824 if( myActiveObjects(anObject)->IsSubIntensityOn()){
825 HiCol = myActiveObjects(anObject)->HilightColor();
826 if(HiCol==Quantity_NOC_WHITE)
827 WithColor = Standard_True;
828 else
829 WithColor = Standard_False;
830 return Standard_True;
831 }
832 return Standard_False;
833}
834
835
836void AIS_LocalContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& anObject,
837 const Standard_Integer Prior)
838{
839 if(!myActiveObjects.IsBound(anObject)) return;
840 const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anObject);
841 if(STAT->DisplayMode()==-1) return;
842 myMainPM->SetDisplayPriority(anObject,STAT->DisplayMode(),Prior);
843 if(STAT->IsSubIntensityOn())
844 myMainPM->SetDisplayPriority(anObject,STAT->HilightMode(),Prior);
845
846
847}
848
7fd59977 849//=======================================================================
850//function : DisplayedObjects
851//purpose :
852//=======================================================================
853Standard_Integer AIS_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const
854{
855 Standard_Integer NbDisp(0);
856 for(AIS_DataMapIteratorOfDataMapOfSelStat it(myActiveObjects);it.More();it.Next()){
857 const Handle(SelectMgr_SelectableObject)& SO = it.Key();
858 if(!theMap.Contains(SO))
859 if(it.Value()->DisplayMode()!=-1){
860 theMap.Add(SO);
861 NbDisp++;
862 }
863 }
864 return NbDisp;
865}
866
867
868//=======================================================================
869//function : IsDisplayed
870//purpose :
871//=======================================================================
872
873Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject) const
874{
875 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
876 return (myActiveObjects(anObject)->DisplayMode()!=-1);
877}
878
879//=======================================================================
880//function : IsDisplayed
881//purpose :
882//=======================================================================
883
884Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject,
885 const Standard_Integer aMode) const
886{
887 if(!myActiveObjects.IsBound(anObject)) return Standard_False;
888 return (myActiveObjects(anObject)->DisplayMode()==aMode);
889}
890
891//=======================================================================
892//function : SelectionModes
893//purpose :
894//=======================================================================
895
896const TColStd_ListOfInteger& AIS_LocalContext::
897SelectionModes(const Handle(AIS_InteractiveObject)& anObject) const
898{
899 return myActiveObjects(anObject)->SelectionModes();
900}
901
902//=======================================================================
903//function : Status
904//purpose :
905//=======================================================================
906
907TCollection_AsciiString AIS_LocalContext::Status() const
908{
909 TCollection_AsciiString t;
910 return t;
911}
912
913const Handle(AIS_LocalStatus)& AIS_LocalContext::Status(const Handle(AIS_InteractiveObject)& anObject) const
914{
915 return myActiveObjects(anObject);
916}
917
918//=======================================================================
919//function : LoadContextObjects
920//purpose :
921//=======================================================================
922
923void AIS_LocalContext::LoadContextObjects()
924{
925 AIS_ListIteratorOfListOfInteractive It;
926 if(myLoadDisplayed) {
927 AIS_ListOfInteractive LL;
928 myCTX->DisplayedObjects(LL,Standard_True);
929 Handle(AIS_LocalStatus) Att;
930 for (It.Initialize(LL);It.More();It.Next()){
931 Att= new AIS_LocalStatus();
932 Att->SetDecomposition((It.Value()->AcceptShapeDecomposition() && myAcceptStdMode));
933 Att->SetTemporary(Standard_False);
934 Att->SetHilightMode(It.Value()->HasHilightMode()? It.Value()->HilightMode(): 0);
935
936 myActiveObjects.Bind(It.Value(),Att);
937 }
938 }
939}
940
941void AIS_LocalContext::UnloadContextObjects()
942{
943 AIS_ListIteratorOfListOfInteractive It;
944 if(myLoadDisplayed)
945 {
946 AIS_ListOfInteractive LL;
947 myCTX->DisplayedObjects(LL,Standard_True);
948
949 for (It.Initialize(LL);It.More();It.Next())
950 {
951 myActiveObjects.UnBind(It.Value());
952 }
953 }
954}
955//=======================================================================
956//function : Process
957//purpose :
958//=======================================================================
959
960void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject,
961 const Standard_Boolean WithProj)
962{
963 if(!myActiveObjects.IsBound(anObject)) return;
964 if(myActiveObjects(anObject)->Decomposed())
965 ActivateStandardModes(anObject,WithProj);
966 else
967 {
968 TColStd_ListIteratorOfListOfInteger It(myActiveObjects(anObject)->SelectionModes());
969 for(;It.More();It.Next())
970 myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS,WithProj);
971 }
972}
973
974//=======================================================================
975//function : Process
976//purpose :
977//=======================================================================
978
979void AIS_LocalContext::Process(const Standard_Boolean WithProj)
980{
981
982 myMainVS->Clear();
983
984 AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
985
986 for(;It.More();It.Next()){
987 myCTX->SelectionManager()->Load(It.Key(),myMainVS);
988 if(It.Value()->Decomposed())
989 ActivateStandardModes(It.Key(),WithProj);
990 else if( myCTX->GetAutoActivateSelection() )
991 {
992 It.Value()->AddSelectionMode(0);
993 myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS,WithProj);
994 }
995 }
996
997}
998
999//=======================================================================
1000//function : ActivateModes
1001//purpose :
1002//=======================================================================
1003
1004void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject,
1005 const Standard_Boolean WithProj)
1006{
1007 if(!myActiveObjects.IsBound(anObject)) return;
1008
1009 TColStd_ListIteratorOfListOfInteger itl (myListOfStandardMode);
1010
1011 const Handle(AIS_LocalStatus)& LS = myActiveObjects(anObject);
1012 if(LS->Decomposed()){
1013 for(;itl.More();itl.Next()){
1014 myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS,WithProj);
1015 LS->AddSelectionMode(itl.Value());
1016 }
1017 }
1018}
1019
1020
1021//=======================================================================
1022//function : ClearObjects
1023//purpose :
1024//=======================================================================
1025
1026void AIS_LocalContext::ClearObjects()
1027{
1028 AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
1029 for(;It.More();It.Next())
1030 {
1031 Handle(AIS_InteractiveObject) SO =
1032 Handle(AIS_InteractiveObject)::DownCast(It.Key());
1033
1034 const Handle(AIS_LocalStatus)& CurAtt = It.Value();
1035 //TColStd_ListIteratorOfListOfInteger ItL;
81bba717 1036 // if object is temporary the presentations managed by myMainPM are removed
7fd59977 1037 AIS_DisplayStatus TheDS = myCTX->DisplayStatus(SO);
1038
1039 if(TheDS != AIS_DS_Displayed){
1040 if(myMainPM->IsDisplayed(SO,CurAtt->DisplayMode())){
1041 if(CurAtt->IsSubIntensityOn()&&
1042 myMainPM->IsHighlighted(SO,CurAtt->HilightMode()))
1043 myMainPM->Unhighlight(SO,CurAtt->HilightMode());
1044 myMainPM->Erase(SO,CurAtt->DisplayMode());
1045 }
1046
1047 if(CurAtt->IsTemporary()){
1048 myMainPM->Erase(SO,CurAtt->DisplayMode());}
1049// myMainPM->Clear(SO,CurAtt->DisplayMode());}
1050 }
1051 else {
1052 if (CurAtt->IsSubIntensityOn()){
1053 myCTX->SubIntensityOff(Handle(AIS_InteractiveObject)::DownCast(SO));}
1054 Standard_Integer DiMo = SO->HasDisplayMode()?
1055 SO->DisplayMode():myCTX->DisplayMode();
1056 if(CurAtt->DisplayMode()!=-1 &&
1057 CurAtt->DisplayMode()!= DiMo)
1058 myMainPM->Erase(SO,CurAtt->DisplayMode());
1059 }
1060
1061 TColStd_ListIteratorOfListOfInteger ITL(CurAtt->SelectionModes());
1062 for(;ITL.More();ITL.Next())
1063 mySM->Deactivate(SO,ITL.Value(),myMainVS);
1064
1065 if(CurAtt->IsTemporary())
1066 mySM->Remove(SO,myMainVS);
1067
1068 }
1069 ClearSelected( Standard_False );
1070 myActiveObjects.Clear();
1071// myMainVS->ClearAreas();myMainVS->ClearSensitive();
1072}
1073
1074
1075Standard_Boolean AIS_LocalContext::IsDecompositionOn() const
1076{return !myListOfStandardMode.IsEmpty();}
1077
1078
1079
1080
1081//=======================================================================
1082//function : HasAlreadyFilters
1083//purpose :
1084//=======================================================================
1085
1086Standard_Boolean AIS_LocalContext::
1087HasFilters(const TopAbs_ShapeEnum aType) const
1088{
1089 return myFilters->ActsOn(aType);
1090}
1091
1092void AIS_LocalContext::ClearDetected()
1093{
eb4320f2 1094 for(Standard_Integer I=1;I<=myMapOfOwner.Extent();I++)
1095 {
1096 if(!myMapOfOwner(I).IsNull())
1097 {
7fd59977 1098 if(myMapOfOwner(I)->IsHilighted(myMainPM))
eb4320f2 1099 myMapOfOwner(I)->Unhilight(myMainPM);
1100 else
1101 {
1102 const Handle(SelectMgr_SelectableObject)& SO =
1103 myMapOfOwner.FindKey(I)->Selectable();
1104 if(myActiveObjects.IsBound(SO))
1105 {
1106 const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO);
1107
1108 if(Att->IsTemporary() &&
1109 Att->DisplayMode()==-1 &&
1110 Att->SelectionModes().IsEmpty())
1111 {
1112 myMapOfOwner(I)->Clear(myMainPM);
1113 }
1114 }
7fd59977 1115 }
1116 }
1117 }
7fd59977 1118}
1119
1120void AIS_LocalContext::UpdateConversion()
1121{
1122 myMainVS->UpdateConversion();
1123}
1124
1125void AIS_LocalContext::UpdateSort()
1126{
1127 myMainVS->UpdateSort();
1128}
1129
7fd59977 1130//=======================================================================
679ecdee 1131//function : BeginImmediateDraw
1132//purpose :
7fd59977 1133//=======================================================================
679ecdee 1134Standard_Boolean AIS_LocalContext::BeginImmediateDraw()
7fd59977 1135{
679ecdee 1136 if (myMainPM->IsImmediateModeOn())
1137 {
1138 myMainPM->BeginImmediateDraw();
7fd59977 1139 return Standard_True;
1140 }
1141 return Standard_False;
1142}
1143
679ecdee 1144//=======================================================================
1145//function : ImmediateAdd
1146//purpose :
1147//=======================================================================
1148Standard_Boolean AIS_LocalContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
1149 const Standard_Integer theMode)
7fd59977 1150{
679ecdee 1151 if (!myMainPM->IsImmediateModeOn())
1152 {
7fd59977 1153 return Standard_False;
679ecdee 1154 }
1155
af324faa 1156 myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode)->Presentation());
7fd59977 1157 return Standard_True;
1158}
1159
679ecdee 1160//=======================================================================
1161//function : EndImmediateDraw
1162//purpose :
1163//=======================================================================
1164Standard_Boolean AIS_LocalContext::EndImmediateDraw (const Handle(V3d_View)& theView)
7fd59977 1165{
679ecdee 1166 if (!myMainPM->IsImmediateModeOn())
1167 {
1168 return Standard_False;
1169 }
1170
1171 myMainPM->EndImmediateDraw (theView);
7fd59977 1172 return Standard_True;
1173}
1174
679ecdee 1175// =======================================================================
1176// function : ClearImmediateDraw
1177// purpose :
1178// =======================================================================
1179void AIS_LocalContext::ClearImmediateDraw()
7fd59977 1180{
679ecdee 1181 myMainPM->ClearImmediateDraw();
7fd59977 1182}
1183
679ecdee 1184//=======================================================================
1185//function : IsImmediateModeOn
1186//purpose :
1187//=======================================================================
7fd59977 1188Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const
679ecdee 1189{
1190 return myMainPM->IsImmediateModeOn();
1191}
7fd59977 1192
3c982548 1193void AIS_LocalContext::SetSensitivityMode(const StdSelect_SensitivityMode aMode) {
1194
1195 myMainVS->SetSensitivityMode(aMode);
1196}
1197
1198StdSelect_SensitivityMode AIS_LocalContext::SensitivityMode() const {
1199
1200 return myMainVS->SensitivityMode();
1201}
1202
7fd59977 1203void AIS_LocalContext::SetSensitivity(const Standard_Real aPrecision) {
1204
1205 myMainVS->SetSensitivity(aPrecision);
1206}
1207
3c982548 1208Standard_Real AIS_LocalContext::Sensitivity() const {
7fd59977 1209
3c982548 1210 return myMainVS->Sensitivity();
1211}
1212
1213void AIS_LocalContext::SetPixelTolerance(const Standard_Integer aPrecision) {
1214
1215 myMainVS->SetPixelTolerance(aPrecision);
1216}
1217
1218Standard_Integer AIS_LocalContext::PixelTolerance() const {
1219
1220 return myMainVS->PixelTolerance();
7fd59977 1221}
59f45b7c 1222
1223//=======================================================================
1224//function : SetZLayer
1225//purpose :
1226//=======================================================================
1227
1228void AIS_LocalContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
1229 const Standard_Integer theLayerId)
1230{
1231 if (!myActiveObjects.IsBound (theIObj))
1232 return;
1233
1234 const Handle(AIS_LocalStatus)& aStatus = myActiveObjects (theIObj);
1235 if (aStatus->DisplayMode () == -1)
1236 return;
1237
1238 theIObj->SetZLayer (myMainPM, theLayerId);
1239}
1240
1241//=======================================================================
1242//function : GetZLayer
1243//purpose :
1244//=======================================================================
1245
1246Standard_Integer AIS_LocalContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
1247{
1248 if (!myActiveObjects.IsBound (theIObj))
1249 return -1;
1250
1251 return theIObj->GetZLayer (myMainPM);
1252}