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