0025722: Wrong implementation of SetFuzzyValue method
[occt.git] / src / AIS / AIS_InteractiveContext.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 XAB & Serguei Dec 97 (angle &deviation coeffts)
7fd59977 18
7fd59977 19#include <AIS_InteractiveContext.ixx>
20
21//#include <AIS_DataMapIteratorOfDataMapOfInteractiveInteger.hxx>
22#include <TColStd_ListIteratorOfListOfInteger.hxx>
23#include <TColStd_MapIteratorOfMapOfTransient.hxx>
24#include <AIS_LocalContext.hxx>
25#include <AIS_LocalStatus.hxx>
26#include <Precision.hxx>
27#include <AIS_Selection.hxx>
28#include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
0717ddc1 29#include <AIS_ConnectedInteractive.hxx>
30#include <AIS_MultipleConnectedInteractive.hxx>
7fd59977 31#include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
32#include <AIS_GlobalStatus.hxx>
33#include <AIS_MapIteratorOfMapOfInteractive.hxx>
34#include <PrsMgr_ModedPresentation.hxx>
35#include <Visual3d_ViewManager.hxx>
36#include <Prs3d_ShadingAspect.hxx>
37#include <AIS_Shape.hxx>
38#include <Graphic3d_AspectFillArea3d.hxx>
39#include <HLRBRep.hxx>
40#include <Prs3d_IsoAspect.hxx>
41#include <Prs3d_DatumAspect.hxx>
42#include <Prs3d_PlaneAspect.hxx>
43#include <PrsMgr_PresentableObject.hxx>
e33e7e78 44#include <Standard_Atomic.hxx>
7fd59977 45#include <UnitsAPI.hxx>
46
47#include <AIS_Trihedron.hxx>
48#include <Geom_Axis2Placement.hxx>
49#include <OSD_Environment.hxx>
50
51#include <AIS_ListIteratorOfListOfInteractive.hxx>
52
e33e7e78 53namespace
7fd59977 54{
e33e7e78
RK
55 static volatile Standard_Integer THE_AIS_INDEX_SEL = 0;
56 static volatile Standard_Integer THE_AIS_INDEX_CUR = 0;
7fd59977 57
e33e7e78
RK
58 static TCollection_AsciiString AIS_Context_NewSelName()
59 {
60 return TCollection_AsciiString ("AIS_SelContext_")
61 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_SEL));
62 }
7fd59977 63
e33e7e78
RK
64 static TCollection_AsciiString AIS_Context_NewCurName()
65 {
66 return TCollection_AsciiString ("AIS_CurContext_")
67 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_CUR));
68 }
2195ab96 69}
7fd59977 70
71//=======================================================================
72//function : AIS_InteractiveContext
73//purpose :
74//=======================================================================
75
76AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
77mgrSelector(new SelectMgr_SelectionManager()),
78myMainPM(new PrsMgr_PresentationManager3d(MainViewer->Viewer())),
79myMainVwr(MainViewer),
80myMainSel(new StdSelect_ViewerSelector3d()),
cbff1e55 81myWasLastMain(Standard_False),
82myCurrentTouched(Standard_False),
83mySelectedTouched(Standard_False),
84myToHilightSelected(Standard_True),
7fd59977 85myFilters(new SelectMgr_OrFilter()),
86myDefaultDrawer(new Prs3d_Drawer()),
87myDefaultColor(Quantity_NOC_GOLDENROD),
88myHilightColor(Quantity_NOC_CYAN1),
89mySelectionColor(Quantity_NOC_GRAY80),
90myPreselectionColor(Quantity_NOC_GREEN),
91mySubIntensity(Quantity_NOC_GRAY40),
92myDisplayMode(0),
93myCurLocalIndex(0),
cbff1e55 94myAISCurDetected(0),
7fd59977 95myZDetectionFlag(0),
7fd59977 96myIsAutoActivateSelMode( Standard_True )
97{
98 InitAttributes();
99}
100
7fd59977 101void AIS_InteractiveContext::Delete() const
102{
2195ab96 103 // clear the static current selection
30bf45dc 104 AIS_Selection::ClearCurrentSelection();
2195ab96 105
7fd59977 106 // to avoid an exception
2195ab96 107 if (AIS_Selection::Find (mySelectionName.ToCString()))
108 {
109 AIS_Selection::Remove (mySelectionName.ToCString());
110 }
7fd59977 111
112 // to avoid an exception
2195ab96 113 if (AIS_Selection::Find (myCurrentName.ToCString()))
114 {
115 AIS_Selection::Remove (myCurrentName.ToCString());
116 }
7fd59977 117
118 // let's remove one reference explicitly. this operation's supposed to
119 // be performed when mgrSelector will be destroyed but anyway...
2195ab96 120 mgrSelector->Remove (myMainSel);
121
da0e82aa 122 Handle(AIS_InteractiveContext) aNullContext;
2195ab96 123 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
da0e82aa 124 {
2195ab96 125 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
126 anObj->SetContext (aNullContext);
da0e82aa 127 }
7fd59977 128 MMgt_TShared::Delete();
129}
130
131//=======================================================================
132//function : AIS_SelectionName
133//purpose :
134//=======================================================================
135const TCollection_AsciiString& AIS_InteractiveContext::SelectionName() const
136{
137 if(!HasOpenedContext())
138 return mySelectionName;
139 return myLocalContexts(myCurLocalIndex)->SelectionName();
140
141}
142
143
144
145//=======================================================================
146//function : UpdateCurrentViewer
147//purpose :
148//=======================================================================
149
150void AIS_InteractiveContext::UpdateCurrentViewer()
151{
152 if (!myMainVwr.IsNull())
153 myMainVwr->Update();
154}
155
7fd59977 156
157//=======================================================================
158//function : DomainOfMainViewer
159//purpose :
160//=======================================================================
161
162Standard_CString AIS_InteractiveContext::DomainOfMainViewer() const
163{
164 return myMainVwr->Domain();
165
166}
167
168//=======================================================================
169//function : DisplayedObjects
2195ab96 170//purpose :
7fd59977 171//=======================================================================
2195ab96 172void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
173 const Standard_Boolean theOnlyFromNeutral) const
7fd59977 174{
2195ab96 175 if (!HasOpenedContext()
176 || theOnlyFromNeutral)
177 {
178 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
179 {
180 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
181 {
182 theListOfIO.Append (anObjIter.Key());
183 }
7fd59977 184 }
2195ab96 185 return;
7fd59977 186 }
7fd59977 187
2195ab96 188 // neutral point
189 TColStd_MapOfTransient aDispMap;
190 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
191 {
192 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
193 {
194 aDispMap.Add (anObjIter.Key());
7fd59977 195 }
2195ab96 196 }
197
198 // parse all local contexts...
199 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
200 {
201 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
202 aLocCtx->DisplayedObjects (aDispMap);
203 }
204
205 Handle(AIS_InteractiveObject) anObj;
206 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
207 {
208 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
209 anObj = *((Handle(AIS_InteractiveObject)* )&aTransient);
210 theListOfIO.Append (anObj);
211 }
7fd59977 212}
2195ab96 213
7fd59977 214//=======================================================================
215//function : DisplayedObjects
2195ab96 216//purpose :
7fd59977 217//=======================================================================
2195ab96 218void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
219 const Standard_Integer theSign,
220 AIS_ListOfInteractive& theListOfIO,
221 const Standard_Boolean /*OnlyFromNeutral*/) const
7fd59977 222{
2195ab96 223 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
7fd59977 224}
225
226//=======================================================================
7fd59977 227//function : ErasedObjects
2195ab96 228//purpose :
7fd59977 229//=======================================================================
2195ab96 230void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
7fd59977 231{
2195ab96 232 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
7fd59977 233}
234
235//=======================================================================
236//function : ErasedObjects
2195ab96 237//purpose :
7fd59977 238//=======================================================================
2195ab96 239void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
240 const Standard_Integer theSign,
241 AIS_ListOfInteractive& theListOfIO) const
7fd59977 242{
2195ab96 243 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
7fd59977 244}
245
246//=======================================================================
247//function : ObjectsByDisplayStatus
2195ab96 248//purpose :
7fd59977 249//=======================================================================
2195ab96 250void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
251 AIS_ListOfInteractive& theListOfIO) const
7fd59977 252{
2195ab96 253 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
254 {
255 if (anObjIter.Value()->GraphicStatus() == theStatus)
256 {
257 theListOfIO.Append (anObjIter.Key());
258 }
7fd59977 259 }
260}
261
262//=======================================================================
263//function : ObjectsByDisplayStatus
2195ab96 264//purpose :
7fd59977 265//=======================================================================
2195ab96 266void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
267 const Standard_Integer theSign,
268 const AIS_DisplayStatus theStatus,
269 AIS_ListOfInteractive& theListOfIO) const
270{
271 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
272 {
273 if (anObjIter.Value()->GraphicStatus() != theStatus
274 || anObjIter.Key()->Type() != theKind)
275 {
276 continue;
277 }
7fd59977 278
2195ab96 279 if (theSign == -1
280 || anObjIter.Key()->Signature() == theSign)
281 {
282 theListOfIO.Append (anObjIter.Key());
7fd59977 283 }
284 }
285}
286
287//=======================================================================
288//function : ObjectsInside
2195ab96 289//purpose :
7fd59977 290//=======================================================================
2195ab96 291void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
292 const AIS_KindOfInteractive theKind,
293 const Standard_Integer theSign) const
7fd59977 294{
2195ab96 295 if (theKind == AIS_KOI_None
296 && theSign == -1)
297 {
298 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
299 {
300 theListOfIO.Append (anObjIter.Key());
7fd59977 301 }
2195ab96 302 return;
7fd59977 303 }
2195ab96 304
305 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
306 {
307 if (anObjIter.Key()->Type() != theKind)
308 {
309 continue;
310 }
311
312 if (theSign == -1
313 || anObjIter.Key()->Signature() == theSign)
314 {
315 theListOfIO.Append (anObjIter.Key());
7fd59977 316 }
317 }
318}
319
320//=======================================================================
321//function : Display
2195ab96 322//purpose :
7fd59977 323//=======================================================================
2195ab96 324void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
325 const Standard_Boolean theToUpdateViewer)
326{
327 if (theIObj.IsNull())
328 {
329 return;
330 }
331
332 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
333 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
334
335 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
336 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
337}
7fd59977 338
2195ab96 339//=======================================================================
340//function : Display
341//purpose :
342//=======================================================================
343void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
344 const Standard_Integer theDispMode,
345 const Standard_Integer theSelectionMode,
346 const Standard_Boolean theToUpdateViewer,
347 const Standard_Boolean theToAllowDecomposition)
7fd59977 348{
2195ab96 349 if (theIObj.IsNull())
350 {
351 return;
352 }
7fd59977 353
2195ab96 354 if (!theIObj->HasInteractiveContext())
355 {
356 theIObj->SetContext (this);
357 }
7fd59977 358
2195ab96 359 if (HasOpenedContext())
360 {
361 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
362 if (theToUpdateViewer)
363 {
364 myMainVwr->Update();
365 }
366 return;
367 }
7fd59977 368
2195ab96 369 if (!myObjects.IsBound (theIObj))
370 {
371 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
372 myObjects.Bind (theIObj, aStatus);
373 myMainPM->Display(theIObj, theDispMode);
374 if (theSelectionMode != -1)
375 {
376 if (!mgrSelector->Contains (theIObj))
377 {
378 mgrSelector->Load (theIObj);
7fd59977 379 }
2195ab96 380 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
381 }
7fd59977 382 }
7fd59977 383 else
384 {
2195ab96 385 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
386 if (aStatus->GraphicStatus() != AIS_DS_Displayed
387 && aStatus->GraphicStatus() != AIS_DS_Erased)
388 {
389 return;
390 }
a6964ce6 391
2195ab96 392 // Erase presentations for all display modes different from aDispMode.
393 // Then make sure aDispMode is displayed and maybe highlighted.
394 // Finally, activate selection mode <SelMode> if not yet activated.
395 TColStd_ListOfInteger aModesToRemove;
396 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
397 {
398 const Standard_Integer anOldMode = aDispModeIter.Value();
399 if (anOldMode != theDispMode)
400 {
401 aModesToRemove.Append (anOldMode);
402 if(myMainPM->IsHighlighted (theIObj, anOldMode))
403 {
404 myMainPM->Unhighlight (theIObj, anOldMode);
405 }
406 myMainPM->Erase (theIObj, anOldMode);
407 }
408 }
7fd59977 409
2195ab96 410 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
411 {
412 aStatus->RemoveDisplayMode (aRemModeIter.Value());
413 }
7fd59977 414
2195ab96 415 if (!aStatus->IsDModeIn (theDispMode))
416 {
417 aStatus->AddDisplayMode (theDispMode);
418 }
7fd59977 419
2195ab96 420 myMainPM->Display (theIObj, theDispMode);
421 if (aStatus->GraphicStatus() == AIS_DS_Erased)
422 {
423 aStatus->SetGraphicStatus (AIS_DS_Displayed);
7fd59977 424 }
2195ab96 425 if (aStatus->IsHilighted())
426 {
427 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
428 myMainPM->Highlight (theIObj, aHiMod);
429 }
430 if (theSelectionMode != -1)
431 {
432 if (!mgrSelector->Contains (theIObj))
433 {
434 mgrSelector->Load (theIObj);
7fd59977 435 }
2195ab96 436 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
437 {
438 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
7fd59977 439 }
7fd59977 440 }
441 }
7fd59977 442
2195ab96 443 if (theToUpdateViewer)
444 {
445 myMainVwr->Update();
446 }
447}
7fd59977 448
449//=======================================================================
450//function : Load
2195ab96 451//purpose :
7fd59977 452//=======================================================================
2195ab96 453void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
454 const Standard_Integer theSelMode,
455 const Standard_Boolean theToAllowDecomposition)
7fd59977 456{
2195ab96 457 if (theIObj.IsNull())
458 {
459 return;
460 }
7fd59977 461
2195ab96 462 if (!theIObj->HasInteractiveContext())
463 {
464 theIObj->SetContext (this);
465 }
466
467 if (HasOpenedContext())
468 {
469 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
470 return;
7fd59977 471 }
7fd59977 472
2195ab96 473 if (theSelMode == -1
89cc29b0 474 && !theToAllowDecomposition)
2195ab96 475 {
89cc29b0 476 if (!myObjects.IsBound (theIObj))
477 {
478 Standard_Integer aDispMode, aHiMod, aSelModeDef;
479 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
480 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
481 myObjects.Bind (theIObj, aStatus);
482 }
483
484 // Register theIObj in the selection manager to prepare further activation of selection
485 if (!mgrSelector->Contains (theIObj))
486 {
487 mgrSelector->Load (theIObj);
488 }
2195ab96 489 }
490}
7fd59977 491
492//=======================================================================
493//function : Erase
2195ab96 494//purpose :
7fd59977 495//=======================================================================
2195ab96 496void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
497 const Standard_Boolean theToUpdateViewer)
7fd59977 498{
2195ab96 499 if (theIObj.IsNull())
500 {
501 return;
502 }
7fd59977 503
2195ab96 504 if (!theIObj->IsAutoHilight())
505 {
506 theIObj->ClearSelected();
7fd59977 507 }
2195ab96 508
509 Standard_Boolean wasInCtx = Standard_False;
510 if (HasOpenedContext())
511 {
512 // First it is checked if it is possible to remove in the current local context
513 // then one tries to remove in other local contexts, if they allow it...
514 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
515 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
7fd59977 516 {
2195ab96 517 if (aCtxIter.Value()->AcceptErase())
518 {
519 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
7fd59977 520 }
7fd59977 521 }
2195ab96 522 }
523
524 if (!wasInCtx)
525 {
526 EraseGlobal (theIObj, Standard_False);
527 }
528
529 if (theToUpdateViewer)
530 {
531 myMainVwr->Update();
532 }
7fd59977 533}
7fd59977 534
535//=======================================================================
536//function : EraseAll
2195ab96 537//purpose :
7fd59977 538//=======================================================================
2195ab96 539void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
7fd59977 540{
2195ab96 541 if (HasOpenedContext())
eb4320f2 542 {
2195ab96 543 return;
544 }
545
546 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
547 {
548 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 549 {
2195ab96 550 Erase (anObjIter.Key(), Standard_False);
7fd59977 551 }
552 }
2195ab96 553
554 if (theToUpdateViewer)
555 {
556 myMainVwr->Update();
557 }
7fd59977 558}
559
560//=======================================================================
561//function : DisplayAll
2195ab96 562//purpose :
7fd59977 563//=======================================================================
2195ab96 564void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
7fd59977 565{
2195ab96 566 if (HasOpenedContext())
567 {
568 return;
569 }
eb4320f2 570
2195ab96 571 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
572 {
573 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
574 if (aStatus == AIS_DS_Erased)
eb4320f2 575 {
2195ab96 576 Display (anObjIter.Key(), Standard_False);
7fd59977 577 }
578 }
2195ab96 579
580 if (theToUpdateViewer)
581 {
582 myMainVwr->Update();
583 }
7fd59977 584}
585
586//=======================================================================
587//function : DisplaySelected
2195ab96 588//purpose :
7fd59977 589//=======================================================================
2195ab96 590void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
7fd59977 591{
2195ab96 592 if (HasOpenedContext())
eb4320f2 593 {
2195ab96 594 return;
7fd59977 595 }
7fd59977 596
2195ab96 597 Standard_Boolean isFound = Standard_False;
598 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
599 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
600 {
601 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
602 Display (anObj, Standard_False);
603 isFound = Standard_True;
604 }
7fd59977 605
2195ab96 606 if (isFound && theToUpdateViewer)
607 {
608 myMainVwr->Update();
609 }
610}
7fd59977 611
2195ab96 612//=======================================================================
613//function : EraseSelected
614//purpose :
615//=======================================================================
616void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 617{
2195ab96 618 if (HasOpenedContext())
eb4320f2 619 {
2195ab96 620 return;
621 }
622
623 Standard_Boolean isFound = Standard_False;
624 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection(myCurrentName.ToCString());
625 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
626 {
627 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
628 Erase (anObj, Standard_False);
629 isFound = Standard_True;
630 }
631
632 if (isFound && theToUpdateViewer)
633 {
634 myMainVwr->Update();
7fd59977 635 }
636}
2195ab96 637
7fd59977 638//=======================================================================
639//function :
640//purpose :
641//=======================================================================
642
643Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
644 const Standard_Integer WhichContext)
645{
646 if(anIObj.IsNull()) return Standard_False;
647
648 if(!HasOpenedContext()) return Standard_False;
649 if(myObjects.IsBound(anIObj)) return Standard_False;
650 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
651
81bba717 652 // Protection : if one tries to preserve a temporary object
653 // which is not in the local active context... rob 11-06-97
7fd59977 654
655 Standard_Integer IsItInLocal = myCurLocalIndex;
656 Standard_Boolean Found(Standard_False);
657
658 while(IsItInLocal>0 && !Found){
659 if(!myLocalContexts.IsBound(IsItInLocal))
660 IsItInLocal--;
661 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
662 Found = Standard_True;
663 else
664 IsItInLocal--;
665 }
666
667 if(!Found) return Standard_False;
668
669
670// const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
671// myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
672 // CLE
673 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
674 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
675 // ENDCLE
676
677
678 if(LS->IsTemporary()){
679 Standard_Integer DM,HM,SM;
680 GetDefModes(anIObj,DM,HM,SM);
681
682 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
683 if(LS->DisplayMode()!= DM ){
684 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
685 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
686 }
687
688 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
689 DM,
690 SM,
691 Standard_False);
692// GS->SubIntensityOn();
693 myObjects.Bind(anIObj,GS);
694 mgrSelector->Load(anIObj);
695 mgrSelector->Activate(anIObj,SM,myMainSel);
696
697 LS->SetTemporary(Standard_False);
698 }
699 return Standard_True;
700}
701
7fd59977 702//=======================================================================
2195ab96 703//function : DisplayStatus
704//purpose :
7fd59977 705//=======================================================================
2195ab96 706AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 707{
2195ab96 708 if (theIObj.IsNull())
709 {
710 return AIS_DS_None;
711 }
712 else if (myObjects.IsBound (theIObj))
713 {
714 return myObjects (theIObj)->GraphicStatus();
715 }
7fd59977 716
2195ab96 717 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
718 {
719 if (aCtxIter.Value()->IsIn (theIObj))
720 {
7fd59977 721 return AIS_DS_Temporary;
2195ab96 722 }
7fd59977 723 }
7fd59977 724 return AIS_DS_None;
7fd59977 725}
726
7fd59977 727//=======================================================================
728//function : DisplayedModes
2195ab96 729//purpose :
7fd59977 730//=======================================================================
2195ab96 731const TColStd_ListOfInteger& AIS_InteractiveContext::DisplayedModes (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 732{
2195ab96 733 return myObjects (theIObj)->DisplayedModes();
7fd59977 734}
735
7fd59977 736//=======================================================================
737//function : Remove
2195ab96 738//purpose :
7fd59977 739//=======================================================================
2195ab96 740void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
741 const Standard_Boolean theToUpdateViewer)
7fd59977 742{
2195ab96 743 if (theIObj.IsNull())
744 {
745 return;
7fd59977 746 }
2195ab96 747
748 if (HasOpenedContext())
749 {
750 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
751 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
7fd59977 752 {
2195ab96 753 if (aCtxIter.Value()->AcceptErase())
754 {
755 aCtxIter.Value()->Remove (theIObj);
7fd59977 756 }
7fd59977 757 }
2195ab96 758 }
759
760 ClearGlobal (theIObj, theToUpdateViewer);
7fd59977 761}
762
763//=======================================================================
764//function : RemoveAll
2195ab96 765//purpose :
7fd59977 766//=======================================================================
2195ab96 767void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
7fd59977 768{
769 AIS_ListOfInteractive aList;
2195ab96 770 ObjectsInside (aList);
771 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
772 {
773 Remove (aListIterator.Value(), Standard_False);
7fd59977 774 }
7fd59977 775
2195ab96 776 if (theToUpdateViewer)
777 {
778 myMainVwr->Update();
7fd59977 779 }
7fd59977 780}
781
7fd59977 782//=======================================================================
783//function : ClearPrs
2195ab96 784//purpose :
7fd59977 785//=======================================================================
2195ab96 786void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
787 const Standard_Integer theMode,
788 const Standard_Boolean theToUpdateViewer)
7fd59977 789{
2195ab96 790 if (theIObj.IsNull())
791 {
792 return;
793 }
7fd59977 794
2195ab96 795 if (!HasOpenedContext())
796 {
797 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
798 return;
7fd59977 799 }
2195ab96 800
801 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
802 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
803 {
804 if (aCtxIter.Value()->AcceptErase())
7fd59977 805 {
2195ab96 806 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
7fd59977 807 }
2195ab96 808 }
809 if (!wasInCtx)
810 {
811 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
812 }
813 else if (theToUpdateViewer)
814 {
815 myMainVwr->Update();
816 }
7fd59977 817}
818
819//=======================================================================
820//function : Hilight
2195ab96 821//purpose :
7fd59977 822//=======================================================================
2195ab96 823void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
824 const Standard_Boolean theToUpdateViewer)
7fd59977 825{
2195ab96 826 if (theIObj.IsNull())
827 {
828 return;
829 }
7fd59977 830
2195ab96 831 if (!theIObj->HasInteractiveContext())
832 {
833 theIObj->SetContext (this);
834 }
7fd59977 835 if (!HasOpenedContext())
eb4320f2 836 {
2195ab96 837 if (!myObjects.IsBound (theIObj))
838 {
839 return;
840 }
eb4320f2 841
2195ab96 842 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
843 aStatus->SetHilightStatus (Standard_True);
844 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 845 {
2195ab96 846 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
847 myMainPM->Highlight (theIObj, aHilightMode);
7fd59977 848 }
eb4320f2 849 }
7fd59977 850 else
eb4320f2 851 {
2195ab96 852 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
eb4320f2 853 }
854
2195ab96 855 if (theToUpdateViewer)
856 {
857 myMainVwr->Update();
858 }
7fd59977 859}
860//=======================================================================
861//function : Hilight
862//purpose :
863//=======================================================================
864
865void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
866 const Quantity_NameOfColor aCol,
867 const Standard_Boolean updateviewer)
868{
869 if(anIObj.IsNull()) return;
870
871 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
872
873 if (!HasOpenedContext())
eb4320f2 874 {
875 if(!myObjects.IsBound(anIObj)) return;
7fd59977 876
eb4320f2 877 const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
878 STATUS->SetHilightStatus (Standard_True);
879
880 if (STATUS->GraphicStatus() == AIS_DS_Displayed)
881 {
882 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
883 myMainPM->Color (anIObj, aCol, aHilightMode);
884 STATUS->SetHilightColor (aCol);
7fd59977 885 }
eb4320f2 886 }
7fd59977 887 else
eb4320f2 888 {
7fd59977 889 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
eb4320f2 890 }
7fd59977 891 if(updateviewer) myMainVwr->Update();
892}
893
894//=======================================================================
895//function : Unhilight
896//purpose :
897//=======================================================================
898
899void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
900{
901 if(anIObj.IsNull()) return;
902
903 if (!HasOpenedContext())
eb4320f2 904 {
905 if(!myObjects.IsBound(anIObj)) return;
7fd59977 906
eb4320f2 907 const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
908 STATUS->SetHilightStatus (Standard_False);
909 STATUS->SetHilightColor(Quantity_NOC_WHITE);
910
911 if (STATUS->GraphicStatus() == AIS_DS_Displayed)
912 {
913 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
914 myMainPM->Unhighlight (anIObj, aHilightMode);
7fd59977 915 }
eb4320f2 916 }
7fd59977 917 else
eb4320f2 918 {
7fd59977 919 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
eb4320f2 920 }
7fd59977 921 if(updateviewer) myMainVwr->Update();
922}
923
924//=======================================================================
925//function : IsHilighted
926//purpose :
927//=======================================================================
928
929Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
930{
931 if(anIObj.IsNull()) return Standard_False;
932
933 if (!HasOpenedContext()){
934 if(!myObjects.IsBound(anIObj))
935 return Standard_False;
936 return myObjects(anIObj)->IsHilighted();
937 }
938 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
939 for(;ItM.More();ItM.Next()){
940 if(ItM.Value()->IsHilighted(anIObj))
941 return Standard_True;
942 }
943 return Standard_False;
944}
945
946Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
947 Standard_Boolean& WithColor,
948 Quantity_NameOfColor& TheHiCol) const
949{
950 if(!HasOpenedContext()){
951 if(myObjects.IsBound(anIObj)){
952 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
953 if(STAT->IsHilighted()){
954 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
955 WithColor=Standard_True;
956 TheHiCol = STAT->HilightColor();
957 }
958 else
959 WithColor = Standard_False;
960 return Standard_True;
961 }
962 }
963 return Standard_False;
964 }
965 Standard_Integer MaxIndex = HighestIndex();
966 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
967 if(myLocalContexts.IsBound(i)){
968 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
969 return Standard_True;
970 }
971
972 }
973 return Standard_False;
974}
975
976
977
978//=======================================================================
979//function : IsDisplayed
980//purpose :
981//=======================================================================
982
983Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
984{
985 if(anIObj.IsNull()) return Standard_False;
986
987
988 if(myObjects.IsBound(anIObj))
989 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
990 return Standard_True;
991
992 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
993 for(;ItM.More();ItM.Next()){
994 if(ItM.Value()->IsDisplayed(anIObj))
995 return Standard_True;
996 }
997 return Standard_False;
998
999}
7fd59977 1000
1001//=======================================================================
1002//function : IsDisplayed
2195ab96 1003//purpose :
7fd59977 1004//=======================================================================
2195ab96 1005Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1006 const Standard_Integer theMode) const
7fd59977 1007{
2195ab96 1008 if (theIObj.IsNull())
1009 {
1010 return Standard_False;
1011 }
1012
1013 if (myObjects.IsBound (theIObj))
1014 {
1015 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1016 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1017 && aStatus->IsDModeIn (theMode))
1018 {
7fd59977 1019 return Standard_True;
2195ab96 1020 }
7fd59977 1021 }
2195ab96 1022
1023 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1024 {
1025 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1026 {
7fd59977 1027 return Standard_True;
2195ab96 1028 }
7fd59977 1029 }
1030 return Standard_False;
1031}
1032
7fd59977 1033//=======================================================================
1034//function : DisplayPriority
2195ab96 1035//purpose :
7fd59977 1036//=======================================================================
2195ab96 1037Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1038{
2195ab96 1039 if (theIObj.IsNull())
1040 {
1041 return -1;
1042 }
1043 else if (!myObjects.IsBound (theIObj))
1044 {
1045 return 0;
1046 }
eb4320f2 1047
2195ab96 1048 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1049 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1050 || aStatus->GraphicStatus() == AIS_DS_Erased)
eb4320f2 1051 {
2195ab96 1052 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1053 ? theIObj->DisplayMode()
1054 : (theIObj->AcceptDisplayMode (myDisplayMode)
1055 ? myDisplayMode
1056 : 0);
1057 return myMainPM->DisplayPriority (theIObj, aDispMode);
7fd59977 1058 }
1059 return 0;
1060}
2195ab96 1061
7fd59977 1062//=======================================================================
1063//function : SetDisplayPriority
2195ab96 1064//purpose :
7fd59977 1065//=======================================================================
2195ab96 1066void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1067 const Standard_Integer thePriority)
7fd59977 1068{
2195ab96 1069 if (theIObj.IsNull())
1070 {
7fd59977 1071 return;
2195ab96 1072 }
1073
1074 if (!theIObj->HasInteractiveContext())
eb4320f2 1075 {
2195ab96 1076 theIObj->SetContext (this);
1077 }
eb4320f2 1078
2195ab96 1079 if (myObjects.IsBound (theIObj))
1080 {
1081 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1082 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1083 || aStatus->GraphicStatus() == AIS_DS_Erased)
eb4320f2 1084 {
2195ab96 1085 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1086 ? theIObj->DisplayMode()
1087 : (theIObj->AcceptDisplayMode (myDisplayMode)
1088 ? myDisplayMode
1089 : 0);
1090 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
7fd59977 1091 }
1092 }
1093 else if (HasOpenedContext())
eb4320f2 1094 {
2195ab96 1095 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
eb4320f2 1096 }
7fd59977 1097}
1098
1099//=======================================================================
1100//function : Redisplay
2195ab96 1101//purpose :
7fd59977 1102//=======================================================================
2195ab96 1103void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1104 const Standard_Boolean theToUpdateViewer,
1105 const Standard_Boolean theAllModes)
7fd59977 1106{
2195ab96 1107 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1108 RecomputeSelectionOnly (theIObj);
7fd59977 1109}
1110
1111//=======================================================================
1112//function : Redisplay
2195ab96 1113//purpose :
7fd59977 1114//=======================================================================
2195ab96 1115void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1116 const Standard_Integer /*theSign*/,
1117 const Standard_Boolean theToUpdateViewer)
1118{
1119 Standard_Boolean isRedisplayed = Standard_False;
1120 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1121 {
1122 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1123 if (anObj->Type() != theKOI)
1124 {
1125 continue;
7fd59977 1126 }
2195ab96 1127
1128 Redisplay (anObj, Standard_False);
1129 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1130 || isRedisplayed;
7fd59977 1131 }
2195ab96 1132
1133 if (theToUpdateViewer
1134 && isRedisplayed)
eb4320f2 1135 {
1136 myMainVwr->Update();
7fd59977 1137 }
1138}
1139
7fd59977 1140//=======================================================================
1141//function : RecomputePrsOnly
2195ab96 1142//purpose :
7fd59977 1143//=======================================================================
2195ab96 1144void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1145 const Standard_Boolean theToUpdateViewer,
1146 const Standard_Boolean theAllModes)
7fd59977 1147{
2195ab96 1148 if (theIObj.IsNull())
1149 {
1150 return;
1151 }
eb4320f2 1152
2195ab96 1153 theIObj->Update (theAllModes);
1154 if (!theToUpdateViewer)
eb4320f2 1155 {
1156 return;
1157 }
1158
2195ab96 1159 if (HasOpenedContext()
1160 || (myObjects.IsBound (theIObj)
1161 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
eb4320f2 1162 {
1163 myMainVwr->Update();
7fd59977 1164 }
1165}
1166//=======================================================================
1167//function : RecomputeSelectionOnly
1168//purpose :
1169//=======================================================================
bc677575 1170void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
7fd59977 1171{
bc677575 1172 if (theIO.IsNull())
1173 {
1174 return;
1175 }
7fd59977 1176
bc677575 1177 mgrSelector->RecomputeSelection (theIO);
0d969553 1178
bc677575 1179 if (HasOpenedContext())
1180 {
1181 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
eb4320f2 1182 {
bc677575 1183 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
eb4320f2 1184 }
bc677575 1185 return;
1186 }
1187
1188 if (!myObjects.IsBound (theIO) ||
1189 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1190 {
1191 return;
1192 }
1193
1194 TColStd_ListOfInteger aModes;
1195 ActivatedModes (theIO, aModes);
1196 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1197 for (; aModesIter.More(); aModesIter.Next())
1198 {
1199 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
7fd59977 1200 }
1201}
1202
1203//=======================================================================
1204//function : Update
2195ab96 1205//purpose :
7fd59977 1206//=======================================================================
f3889691 1207void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
2195ab96 1208 const Standard_Boolean theUpdateViewer)
7fd59977 1209{
f3889691 1210 if (theIObj.IsNull())
1211 {
1212 return;
1213 }
7fd59977 1214
2195ab96 1215 TColStd_ListOfInteger aPrsModes;
1216 theIObj->ToBeUpdated (aPrsModes);
1217 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
f3889691 1218 {
1219 theIObj->Update (aPrsModesIt.Value(), Standard_False);
7fd59977 1220 }
f3889691 1221
1222 mgrSelector->Update(theIObj);
1223
bc677575 1224 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1225 {
1226 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1227 }
1228
f3889691 1229 if (theUpdateViewer)
1230 {
1231 if (!myObjects.IsBound (theIObj))
1232 {
1233 return;
1234 }
1235
1236 switch (myObjects (theIObj)->GraphicStatus())
1237 {
1238 case AIS_DS_Displayed:
1239 case AIS_DS_Temporary:
1240 myMainVwr->Update();
1241 break;
1242 default:
1243 break;
7fd59977 1244 }
1245 }
1246}
1247
7fd59977 1248//=======================================================================
1249//function : SetLocation
2195ab96 1250//purpose :
7fd59977 1251//=======================================================================
2195ab96 1252void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1253 const TopLoc_Location& theLoc)
7fd59977 1254{
2195ab96 1255 if (theIObj.IsNull())
1256 {
1257 return;
1258 }
7fd59977 1259
2195ab96 1260 if (theIObj->HasTransformation()
1261 && theLoc.IsIdentity())
1262 {
1263 theIObj->ResetTransformation();
1264 mgrSelector->Update (theIObj, Standard_False);
1265 return;
1266 }
1267 else if (theLoc.IsIdentity())
1268 {
7fd59977 1269 return;
1270 }
7fd59977 1271
0d969553 1272 // first reset the previous location to properly clean everything...
2195ab96 1273 if (theIObj->HasTransformation())
1274 {
1275 theIObj->ResetTransformation();
1276 }
7fd59977 1277
2195ab96 1278 theIObj->SetLocalTransformation (theLoc.Transformation());
7fd59977 1279
2195ab96 1280 if (!HasOpenedContext())
1281 {
1282 mgrSelector->Update (theIObj, Standard_False);
1283 }
7fd59977 1284 else
2195ab96 1285 {
1286 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1287 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1288 }
7fd59977 1289}
2195ab96 1290
7fd59977 1291//=======================================================================
1292//function : ResetLocation
2195ab96 1293//purpose :
7fd59977 1294//=======================================================================
2195ab96 1295void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
7fd59977 1296{
2195ab96 1297 if (theIObj.IsNull())
1298 {
1299 return;
1300 }
7fd59977 1301
2195ab96 1302 theIObj->ResetTransformation();
1303 mgrSelector->Update (theIObj, Standard_False);
7fd59977 1304}
1305
1306//=======================================================================
1307//function : HasLocation
2195ab96 1308//purpose :
7fd59977 1309//=======================================================================
2195ab96 1310Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1311{
2195ab96 1312 return !theIObj.IsNull()
1313 && theIObj->HasTransformation();
7fd59977 1314}
1315
2195ab96 1316//=======================================================================
1317//function : Location
1318//purpose :
1319//=======================================================================
1320TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1321{
2195ab96 1322 return theIObj->Transformation();
7fd59977 1323}
1324
1325//=======================================================================
1326//function : SetDeviationCoefficient
2195ab96 1327//purpose :
7fd59977 1328//=======================================================================
2195ab96 1329void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
7fd59977 1330{
2195ab96 1331 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
7fd59977 1332}
2195ab96 1333
7fd59977 1334//=======================================================================
1335//function : SetDeviationAngle
2195ab96 1336//purpose :
7fd59977 1337//=======================================================================
2195ab96 1338void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
7fd59977 1339{
2195ab96 1340 myDefaultDrawer->SetDeviationCoefficient (theAngle);
7fd59977 1341}
1342
1343//=======================================================================
1344//function : DeviationAngle
1345//purpose : Gets deviationAngle
1346//=======================================================================
7fd59977 1347Standard_Real AIS_InteractiveContext::DeviationAngle() const
1348{
2195ab96 1349 return myDefaultDrawer->DeviationAngle();
7fd59977 1350}
1351
1352//=======================================================================
1353//function : DeviationCoefficient
2195ab96 1354//purpose :
7fd59977 1355//=======================================================================
2195ab96 1356Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
7fd59977 1357{
1358 return myDefaultDrawer->DeviationCoefficient();
1359}
2195ab96 1360
7fd59977 1361//=======================================================================
1362//function : SetHLRDeviationCoefficient
2195ab96 1363//purpose :
7fd59977 1364//=======================================================================
2195ab96 1365void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
7fd59977 1366{
2195ab96 1367 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
7fd59977 1368}
1369
1370//=======================================================================
1371//function : HLRDeviationCoefficient
2195ab96 1372//purpose :
7fd59977 1373//=======================================================================
2195ab96 1374Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
7fd59977 1375{
1376 return myDefaultDrawer->HLRDeviationCoefficient();
1377}
1378
1379//=======================================================================
1380//function : SetHLRAngle
2195ab96 1381//purpose :
7fd59977 1382//=======================================================================
2195ab96 1383void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
7fd59977 1384{
2195ab96 1385 myDefaultDrawer->SetHLRAngle (theAngle);
7fd59977 1386}
1387
1388//=======================================================================
1389//function : SetHLRAngleAndDeviation
1390//purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1391// and set them in myHLRAngle and in myHLRDeviationCoefficient
1392// of myDefaultDrawer
1393//=======================================================================
2195ab96 1394void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
7fd59977 1395{
2195ab96 1396 Standard_Real anOutAngl, anOutDefl;
1397 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
7fd59977 1398
2195ab96 1399 myDefaultDrawer->SetHLRAngle (anOutAngl);
1400 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
7fd59977 1401}
1402
1403//=======================================================================
1404//function : HLRAngle
2195ab96 1405//purpose :
7fd59977 1406//=======================================================================
7fd59977 1407Standard_Real AIS_InteractiveContext::HLRAngle() const
1408{
1409 return myDefaultDrawer->HLRAngle();
1410}
1411
1412//=======================================================================
1413//function : SetDisplayMode
2195ab96 1414//purpose :
7fd59977 1415//=======================================================================
2195ab96 1416void AIS_InteractiveContext::SetDisplayMode (const AIS_DisplayMode theMode,
1417 const Standard_Boolean theToUpdateViewer)
7fd59977 1418{
2195ab96 1419 if (theMode == myDisplayMode)
1420 {
1421 return;
1422 }
7fd59977 1423
2195ab96 1424 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1425 {
1426 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1427 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1428 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1429 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
7fd59977 1430
2195ab96 1431 if (!toProcess
1432 || anObj->HasDisplayMode()
1433 || !anObj->AcceptDisplayMode (theMode))
1434 {
1435 continue;
1436 }
1437
1438 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1439 if (aStatus->IsDModeIn (myDisplayMode))
1440 {
1441 aStatus->RemoveDisplayMode (myDisplayMode);
1442 }
1443
1444 aStatus->AddDisplayMode (theMode);
1445 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1446 {
1447 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1448 myMainPM->Display (anObj, theMode);
1449 if (aStatus->IsSubIntensityOn())
7fd59977 1450 {
2195ab96 1451 myMainPM->Color (anObj, mySubIntensity, theMode);
7fd59977 1452 }
2195ab96 1453 }
1454 }
1455
1456 myDisplayMode = theMode;
1457 if (theToUpdateViewer)
1458 {
1459 myMainVwr->Update();
1460 }
7fd59977 1461}
1462
1463//=======================================================================
1464//function : SetDisplayMode
2195ab96 1465//purpose :
7fd59977 1466//=======================================================================
2195ab96 1467void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1468 const Standard_Integer theMode,
1469 const Standard_Boolean theToUpdateViewer)
7fd59977 1470{
2195ab96 1471 if (!theIObj->HasInteractiveContext())
1472 {
1473 theIObj->SetContext(this);
1474 }
7fd59977 1475
2195ab96 1476 if (!myObjects.IsBound (theIObj))
1477 {
1478 theIObj->SetDisplayMode (theMode);
1479 return;
1480 }
1481 else if (!theIObj->AcceptDisplayMode (theMode))
1482 {
1483 return;
1484 }
eb4320f2 1485
2195ab96 1486 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1487 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1488 {
1489 theIObj->SetDisplayMode (theMode);
1490 return;
1491 }
a6964ce6 1492
2195ab96 1493 // erase presentations for all display modes different from <aMode>
1494 TColStd_ListOfInteger aModesToRemove;
1495 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
1496 {
1497 const Standard_Integer anOldMode = aDispModeIter.Value();
1498 if (anOldMode != theMode)
1499 {
1500 aModesToRemove.Append (anOldMode);
1501 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1502 {
1503 myMainPM->Unhighlight (theIObj, anOldMode);
7fd59977 1504 }
2195ab96 1505 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
7fd59977 1506 }
1507 }
2195ab96 1508
1509 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
1510 {
1511 aStatus->RemoveDisplayMode (aRemModeIter.Value());
1512 }
1513
1514 if (!aStatus->IsDModeIn (theMode))
1515 {
1516 aStatus->AddDisplayMode (theMode);
1517 }
1518
1519 myMainPM->Display (theIObj, theMode);
1520 Standard_Integer aDispMode, aHiMode, aSelMode;
1521 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1522 if (aStatus->IsHilighted())
1523 {
1524 myMainPM->Highlight (theIObj, aHiMode);
1525 }
1526 if (aStatus->IsSubIntensityOn())
1527 {
1528 myMainPM->Color (theIObj, mySubIntensity, theMode);
1529 }
1530
1531 if (theToUpdateViewer)
1532 {
1533 myMainVwr->Update();
1534 }
1535 theIObj->SetDisplayMode (theMode);
7fd59977 1536}
1537
1538//=======================================================================
1539//function : UnsetDisplayMode
2195ab96 1540//purpose :
7fd59977 1541//=======================================================================
2195ab96 1542void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1543 const Standard_Boolean theToUpdateViewer)
7fd59977 1544{
2195ab96 1545 if (theIObj.IsNull()
1546 || !theIObj->HasDisplayMode())
1547 {
1548 return;
1549 }
1550
1551 if (!myObjects.IsBound (theIObj))
1552 {
1553 theIObj->UnsetDisplayMode();
1554 return;
1555 }
1556
1557 const Standard_Integer anOldMode = theIObj->DisplayMode();
1558 if (myDisplayMode == anOldMode)
1559 {
1560 return;
1561 }
1562
1563 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1564 aStatus->RemoveDisplayMode (anOldMode);
1565 if (!aStatus->IsDModeIn(myDisplayMode))
1566 {
1567 aStatus->AddDisplayMode (myDisplayMode);
1568 }
1569
1570 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1571 {
1572 if (myMainPM->IsHighlighted (theIObj, anOldMode))
7fd59977 1573 {
2195ab96 1574 myMainPM->Unhighlight (theIObj, anOldMode);
1575 }
1576 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1577 myMainPM->Display (theIObj, myDisplayMode);
1578
1579 Standard_Integer aDispMode, aHiMode, aSelMode;
1580 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1581 if (aStatus->IsHilighted())
1582 {
1583 myMainPM->Highlight (theIObj, aHiMode);
1584 }
1585 if (aStatus->IsSubIntensityOn())
1586 {
1587 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
7fd59977 1588 }
2195ab96 1589
1590 if (theToUpdateViewer)
1591 {
1592 myMainVwr->Update();
1593 }
1594 }
1595
1596 theIObj->UnsetDisplayMode();
7fd59977 1597}
1598
1599//=======================================================================
1600//function : SetCurrentFacingModel
2195ab96 1601//purpose :
7fd59977 1602//=======================================================================
2195ab96 1603void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1604 const Aspect_TypeOfFacingModel theModel)
b8ddfc2f 1605{
2195ab96 1606 if (!theIObj.IsNull())
1607 {
1608 theIObj->SetCurrentFacingModel (theModel);
1609 }
7fd59977 1610}
7fd59977 1611
1612//=======================================================================
2195ab96 1613//function : redisplayPrsRecModes
1614//purpose :
7fd59977 1615//=======================================================================
2195ab96 1616void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1617 const Standard_Boolean theToUpdateViewer)
7fd59977 1618{
2195ab96 1619 if (theIObj->RecomputeEveryPrs())
1620 {
1621 theIObj->Redisplay();
1622 }
1623 else
1624 {
1625 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1626 {
1627 theIObj->Update (aModes.Value(), Standard_False);
1628 }
1629 theIObj->SetRecomputeOk();
1630 }
1631
1632 if (theToUpdateViewer)
1633 {
1634 UpdateCurrentViewer();
1635 }
7fd59977 1636}
1637
2195ab96 1638//=======================================================================
1639//function : redisplayPrsModes
1640//purpose :
1641//=======================================================================
1642void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1643 const Standard_Boolean theToUpdateViewer)
7fd59977 1644{
2195ab96 1645 if (theIObj->RecomputeEveryPrs())
1646 {
1647 theIObj->Redisplay();
1648 }
7fd59977 1649 else
2195ab96 1650 {
1651 TColStd_ListOfInteger aModes;
1652 theIObj->ToBeUpdated (aModes);
1653 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
7fd59977 1654 {
2195ab96 1655 theIObj->Update (aModeIter.Value(), Standard_False);
7fd59977 1656 }
2195ab96 1657 theIObj->SetRecomputeOk();
1658 }
7fd59977 1659
2195ab96 1660 if (theToUpdateViewer)
1661 {
1662 UpdateCurrentViewer();
1663 }
7fd59977 1664}
1665
1666//=======================================================================
2195ab96 1667//function : SetColor
1668//purpose :
7fd59977 1669//=======================================================================
2195ab96 1670void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1671 const Quantity_NameOfColor theColor,
1672 const Standard_Boolean theToUpdateViewer)
1673{
1674 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1675}
7fd59977 1676
2195ab96 1677//=======================================================================
1678//function : SetColor
1679//purpose :
1680//=======================================================================
1681void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1682 const Quantity_Color& theColor,
1683 const Standard_Boolean theToUpdateViewer)
7fd59977 1684{
2195ab96 1685 if (theIObj.IsNull())
1686 {
1687 return;
1688 }
7fd59977 1689
2195ab96 1690 if (!theIObj->HasInteractiveContext())
1691 {
1692 theIObj->SetContext (this);
1693 }
1694 theIObj->SetColor (theColor);
1695 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1696}
7fd59977 1697
2195ab96 1698//=======================================================================
1699//function : SetDeviationCoefficient
1700//purpose :
1701//=======================================================================
1702void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1703 const Standard_Real theCoefficient,
1704 const Standard_Boolean theToUpdateViewer)
1705{
1706 if (theIObj.IsNull())
1707 {
1708 return;
1709 }
7fd59977 1710
2195ab96 1711 if (!theIObj->HasInteractiveContext())
1712 {
1713 theIObj->SetContext (this);
1714 }
7fd59977 1715
2195ab96 1716 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1717 if (theIObj->Type() != AIS_KOI_Object
1718 && theIObj->Type() != AIS_KOI_Shape)
1719 {
1720 return;
1721 }
1722 else if (theIObj->Signature() != 0)
1723 {
1724 return;
1725 }
1726
1727 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1728 aShape->SetOwnDeviationCoefficient (theCoefficient);
1729 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1730}
1731
1732//=======================================================================
1733//function : SetHLRDeviationCoefficient
2195ab96 1734//purpose :
7fd59977 1735//=======================================================================
2195ab96 1736void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1737 const Standard_Real theCoefficient,
1738 const Standard_Boolean theToUpdateViewer)
7fd59977 1739{
2195ab96 1740 if (theIObj.IsNull())
1741 {
1742 return;
1743 }
1744
1745 if (!theIObj->HasInteractiveContext())
1746 {
1747 theIObj->SetContext (this);
1748 }
7fd59977 1749
81bba717 1750 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1751 if (theIObj->Type() != AIS_KOI_Object
1752 && theIObj->Type() != AIS_KOI_Shape)
1753 {
1754 return;
1755 }
1756 else if (theIObj->Signature() != 0)
1757 {
1758 return;
1759 }
7fd59977 1760
2195ab96 1761 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1762 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1763 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1764}
1765
7fd59977 1766//=======================================================================
1767//function : SetDeviationAngle
2195ab96 1768//purpose :
7fd59977 1769//=======================================================================
2195ab96 1770void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1771 const Standard_Real theAngle,
1772 const Standard_Boolean theToUpdateViewer)
7fd59977 1773{
2195ab96 1774 if (theIObj.IsNull())
1775 {
1776 return;
1777 }
1778
1779 if (!theIObj->HasInteractiveContext())
1780 {
1781 theIObj->SetContext (this);
1782 }
7fd59977 1783
e33e7e78 1784 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1785 if (theIObj->Type() != AIS_KOI_Shape)
1786 {
1787 return;
1788 }
1789 else if (theIObj->Signature() != 0)
1790 {
1791 return;
1792 }
7fd59977 1793
2195ab96 1794 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1795 aShape->SetOwnDeviationAngle (theAngle);
1796 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1797}
2195ab96 1798
7fd59977 1799//=======================================================================
2195ab96 1800//function : SetAngleAndDeviation
1801//purpose :
7fd59977 1802//=======================================================================
2195ab96 1803void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1804 const Standard_Real theAngle,
1805 const Standard_Boolean theToUpdateViewer)
7fd59977 1806{
2195ab96 1807 if (theIObj.IsNull())
1808 {
1809 return;
1810 }
1811
1812 if (!theIObj->HasInteractiveContext())
1813 {
1814 theIObj->SetContext (this);
1815 }
7fd59977 1816
e33e7e78 1817 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1818 if (theIObj->Type() != AIS_KOI_Shape)
1819 {
1820 return;
1821 }
1822 if (theIObj->Signature() != 0)
1823 {
1824 return;
1825 }
7fd59977 1826
2195ab96 1827 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1828 aShape->SetAngleAndDeviation (theAngle);
7fd59977 1829
2195ab96 1830 if (theIObj->RecomputeEveryPrs())
1831 {
1832 theIObj->Redisplay();
1833 }
7fd59977 1834 else
2195ab96 1835 {
1836 Update (theIObj, theToUpdateViewer);
1837 }
7fd59977 1838}
1839
1840//=======================================================================
2195ab96 1841//function : SetHLRAngleAndDeviation
1842//purpose :
7fd59977 1843//=======================================================================
2195ab96 1844void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1845 const Standard_Real theAngle,
1846 const Standard_Boolean theToUpdateViewer)
7fd59977 1847{
2195ab96 1848 if (theIObj.IsNull())
1849 {
1850 return;
1851 }
7fd59977 1852
2195ab96 1853 if (!theIObj->HasInteractiveContext())
1854 {
1855 theIObj->SetContext (this);
1856 }
7fd59977 1857
e33e7e78 1858 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1859 if (theIObj->Type() != AIS_KOI_Shape)
1860 {
1861 return;
1862 }
1863 if (theIObj->Signature() != 0)
1864 {
1865 return;
1866 }
1867 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1868 aShape->SetHLRAngleAndDeviation (theAngle);
1869 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1870}
1871
1872//=======================================================================
1873//function : SetHLRDeviationAngle
2195ab96 1874//purpose :
7fd59977 1875//=======================================================================
2195ab96 1876void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1877 const Standard_Real theAngle,
1878 const Standard_Boolean theToUpdateViewer)
7fd59977 1879{
2195ab96 1880 if (theIObj.IsNull())
1881 {
1882 return;
1883 }
7fd59977 1884
2195ab96 1885 if (!theIObj->HasInteractiveContext())
1886 {
1887 theIObj->SetContext (this);
1888 }
7fd59977 1889
2195ab96 1890 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1891 if (theIObj->Type() != AIS_KOI_Shape)
1892 {
1893 return;
1894 }
1895 if (theIObj->Signature() != 0)
1896 {
1897 return;
1898 }
1899 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1900 aShape->SetOwnHLRDeviationAngle (theAngle);
1901 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1902}
1903
1904//=======================================================================
1905//function : UnsetColor
2195ab96 1906//purpose :
7fd59977 1907//=======================================================================
2195ab96 1908void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1909 const Standard_Boolean theToUpdateViewer)
7fd59977 1910{
2195ab96 1911 if (theIObj.IsNull())
1912 {
1913 return;
1914 }
1915
1916 theIObj->UnsetColor();
1917 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 1918}
1919
1920//=======================================================================
1921//function : HasColor
2195ab96 1922//purpose :
7fd59977 1923//=======================================================================
2195ab96 1924Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1925{
2195ab96 1926 return theIObj->HasColor();
7fd59977 1927}
1928
1929//=======================================================================
1930//function : Color
2195ab96 1931//purpose :
7fd59977 1932//=======================================================================
2195ab96 1933Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1934{
2195ab96 1935 return theIObj->Color();
7fd59977 1936}
1937
2195ab96 1938//=======================================================================
1939//function : Color
1940//purpose :
1941//=======================================================================
1942void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1943 Quantity_Color& theColor) const
7fd59977 1944{
2195ab96 1945 theIObj->Color (theColor);
7fd59977 1946}
7fd59977 1947
1948//=======================================================================
1949//function : Width
2195ab96 1950//purpose :
7fd59977 1951//=======================================================================
2195ab96 1952Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1953{
2195ab96 1954 return theIObj->Width();
7fd59977 1955}
1956
1957//=======================================================================
1958//function : SetWidth
2195ab96 1959//purpose :
7fd59977 1960//=======================================================================
2195ab96 1961void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1962 const Standard_Real theWidth,
1963 const Standard_Boolean theToUpdateViewer)
7fd59977 1964{
2195ab96 1965 if (theIObj.IsNull())
1966 {
1967 return;
1968 }
1969
1970 if (!theIObj->HasInteractiveContext())
1971 {
1972 theIObj->SetContext (this);
1973 }
1974
1975 theIObj->SetWidth (theWidth);
1976 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 1977}
1978
1979//=======================================================================
1980//function : UnsetWidth
2195ab96 1981//purpose :
7fd59977 1982//=======================================================================
2195ab96 1983void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1984 const Standard_Boolean theToUpdateViewer)
7fd59977 1985{
2195ab96 1986 if (theIObj.IsNull())
1987 {
1988 return;
1989 }
1990
1991 theIObj->UnsetWidth();
1992 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 1993}
1994
1995//=======================================================================
1996//function : SetMaterial
2195ab96 1997//purpose :
7fd59977 1998//=======================================================================
2195ab96 1999void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2000 const Graphic3d_NameOfMaterial theName,
2001 const Standard_Boolean theToUpdateViewer)
7fd59977 2002{
2195ab96 2003 if (theIObj.IsNull())
2004 {
2005 return;
2006 }
2007
2008 if (!theIObj->HasInteractiveContext())
2009 {
2010 theIObj->SetContext (this);
2011 }
7fd59977 2012
2195ab96 2013 theIObj->SetMaterial (theName);
2014 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2015}
2016
2017//=======================================================================
2018//function : UnsetMaterial
2195ab96 2019//purpose :
7fd59977 2020//=======================================================================
2195ab96 2021void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2022 const Standard_Boolean theToUpdateViewer)
7fd59977 2023{
2195ab96 2024 if (theIObj.IsNull())
2025 {
2026 return;
2027 }
2028 theIObj->UnsetMaterial();
2029 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2030}
2031
2032//=======================================================================
2033//function : SetTransparency
2195ab96 2034//purpose :
7fd59977 2035//=======================================================================
2195ab96 2036void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2037 const Standard_Real theValue,
2038 const Standard_Boolean theToUpdateViewer)
7fd59977 2039{
2195ab96 2040 if (theIObj.IsNull())
2041 {
2042 return;
2043 }
2044
2045 if (!theIObj->HasInteractiveContext())
2046 {
2047 theIObj->SetContext (this);
2048 }
7fd59977 2049
2195ab96 2050 if (!theIObj->IsTransparent()
2051 && theValue <= 0.05)
a6964ce6 2052 {
2053 return;
2054 }
2055
2195ab96 2056 if (theValue <= 0.05)
2057 {
2058 UnsetTransparency (theIObj, theToUpdateViewer);
7fd59977 2059 return;
2060 }
a6964ce6 2061
2195ab96 2062 theIObj->SetTransparency (theValue);
2063 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2064}
2065
2066//=======================================================================
2067//function : UnsetTransparency
2195ab96 2068//purpose :
7fd59977 2069//=======================================================================
2195ab96 2070void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2071 const Standard_Boolean theToUpdateViewer)
7fd59977 2072{
2195ab96 2073 if (theIObj.IsNull())
2074 {
2075 return;
2076 }
7fd59977 2077
2195ab96 2078 theIObj->UnsetTransparency();
2079 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2080}
2081
2195ab96 2082//=======================================================================
2083//function : SetSelectedAspect
2084//purpose :
2085//=======================================================================
2086void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2087 const Standard_Boolean theIsGlobalChange,
2088 const Standard_Boolean theToUpdateViewer)
2089{
2090 if (HasOpenedContext())
2091 {
2092 return;
2093 }
2094
2095 Standard_Boolean isFound = Standard_False;
2096 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
2097 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
2098 {
2099 isFound = Standard_True;
2100 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
2101 anObj->SetAspect (theAspect, theIsGlobalChange);
2102 }
2103
2104 if (isFound
2105 && theToUpdateViewer)
2106 {
2107 myMainVwr->Update();
7fd59977 2108 }
2109}
7fd59977 2110
2111//=======================================================================
2112//function : SetLocalAttributes
2195ab96 2113//purpose :
7fd59977 2114//=======================================================================
2195ab96 2115void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2116 const Handle(AIS_Drawer)& theDrawer,
2117 const Standard_Boolean theToUpdateViewer)
7fd59977 2118{
2195ab96 2119 if (theIObj.IsNull())
2120 {
2121 return;
2122 }
2123
2124 if (!theIObj->HasInteractiveContext())
2125 {
2126 theIObj->SetContext (this);
2127 }
2128
2129 theIObj->SetAttributes (theDrawer);
2130 Update (theIObj, theToUpdateViewer);
7fd59977 2131}
2132
2133//=======================================================================
2134//function : UnsetLocalAttributes
2195ab96 2135//purpose :
7fd59977 2136//=======================================================================
2195ab96 2137void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2138 const Standard_Boolean theToUpdateViewer)
7fd59977 2139{
2195ab96 2140 if (theIObj.IsNull())
2141 {
2142 return;
2143 }
7fd59977 2144
2195ab96 2145 if (!theIObj->HasInteractiveContext())
2146 {
2147 theIObj->SetContext (this);
2148 }
2149 theIObj->UnsetAttributes();
2150 Update (theIObj, theToUpdateViewer);
2151}
7fd59977 2152
2153//=======================================================================
2154//function : Status
2195ab96 2155//purpose :
7fd59977 2156//=======================================================================
2195ab96 2157void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2158 TCollection_ExtendedString& theStatus) const
7fd59977 2159{
2195ab96 2160 theStatus = "";
2161 if (theIObj.IsNull()
2162 || !myObjects.IsBound (theIObj))
2163 {
2164 return;
2165 }
7fd59977 2166
2195ab96 2167 theStatus += "\t ____________________________________________";
2168 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2169 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2170 switch (aStatus->GraphicStatus())
2171 {
7fd59977 2172 case AIS_DS_Displayed:
2195ab96 2173 {
2174 theStatus += "\t| -->Displayed\n";
7fd59977 2175 break;
2176 }
2195ab96 2177 case AIS_DS_Erased:
2178 {
2179 theStatus += "\t| -->Erased\n";
2180 break;
7fd59977 2181 }
2195ab96 2182 default:
2183 break;
2184 }
2185
2186 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2187 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2188 {
2189 theStatus += "\t|\t Mode ";
2190 theStatus += TCollection_AsciiString (aDispModeIter.Value());
2191 theStatus += "\n";
2192 }
2193 if (IsCurrent (theIObj)) theStatus +="\t| Current\n";
2194 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
7fd59977 2195
2195ab96 2196 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2197 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2198 {
2199 theStatus += "\t\t Mode ";
2200 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2201 theStatus += "\n";
2202 }
2203 theStatus += "\t ____________________________________________";
2204}
7fd59977 2205
2206//=======================================================================
2207//function : GetDefModes
2195ab96 2208//purpose :
7fd59977 2209//=======================================================================
2195ab96 2210void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2211 Standard_Integer& theDispMode,
2212 Standard_Integer& theHiMode,
2213 Standard_Integer& theSelMode) const
7fd59977 2214{
2195ab96 2215 if (theIObj.IsNull())
2216 {
2217 return;
2218 }
7fd59977 2219
2195ab96 2220 theDispMode = theIObj->HasDisplayMode()
2221 ? theIObj->DisplayMode()
2222 : (theIObj->AcceptDisplayMode (myDisplayMode)
2223 ? myDisplayMode
2224 : 0);
2225 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2226 theSelMode = theIObj->HasSelectionMode() ? theIObj->SelectionMode() : -1;
2227}
7fd59977 2228
2229//=======================================================================
2230//function : EraseGlobal
2195ab96 2231//purpose :
7fd59977 2232//=======================================================================
2195ab96 2233void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2234 const Standard_Boolean theToUpdateviewer)
7fd59977 2235{
2195ab96 2236 if (theIObj.IsNull()
2237 || !myObjects.IsBound (theIObj))
2238 {
2239 return;
2240 }
7fd59977 2241
2195ab96 2242 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2243
2244 Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2245 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
2246 {
2247 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2248 {
2249 if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2250 {
2251 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2252 }
2253 myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2254 }
2255
2256 if (IsCurrent (theIObj)
2257 && !aStatus->IsDModeIn (aDispMode))
2258 {
2259 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2260 }
2261
2262 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2263 {
2264 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2265 }
2266
2267 if (theToUpdateviewer)
2268 {
2269 myMainVwr->Update();
7fd59977 2270 }
7fd59977 2271 }
2195ab96 2272 aStatus->SetGraphicStatus (AIS_DS_Erased);
7fd59977 2273}
2274
2275//=======================================================================
2276//function : ClearGlobal
2195ab96 2277//purpose :
7fd59977 2278//=======================================================================
2195ab96 2279void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2280 const Standard_Boolean theToUpdateviewer)
7fd59977 2281{
2195ab96 2282 if (theIObj.IsNull()
2283 || !myObjects.IsBound (theIObj))
2284 {
2285 return;
2286 }
2287
2288 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2289 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2290 {
2291 if (aStatus->IsHilighted())
2292 {
2293 if (IsCurrent (theIObj))
2294 {
2295 AddOrRemoveCurrentObject (theIObj, theToUpdateviewer);
2296 }
2297 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2298 {
2299 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2300 }
2301 }
2302 myMainPM->Erase (theIObj, aDispModeIter.Value());
2303 myMainPM->Clear (theIObj, aDispModeIter.Value());
2304 if (theIObj->HasHilightMode())
2305 {
2306 Standard_Integer im = theIObj->HilightMode();
2307 myMainPM->Unhighlight (theIObj, im);
2308 myMainPM->Erase (theIObj, im);
2309 }
2310 }
7fd59977 2311
2195ab96 2312 // Object removes from Detected sequence
2313 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
7fd59977 2314 {
2315 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2195ab96 2316 if (!anObj.IsNull()
2317 && anObj != theIObj)
2318 {
2319 myAISDetectedSeq.Remove (aDetIter);
2320 }
7fd59977 2321 }
2322
2195ab96 2323 if (myLastinMain == theIObj)
2324 {
44d9ae89 2325 myLastinMain.Nullify();
2195ab96 2326 }
2327 if (myLastPicked == theIObj)
2328 {
7fd59977 2329 myLastPicked.Nullify();
2195ab96 2330 }
2331
2332 // remove IO from the selection manager to avoid memory leaks
2333 mgrSelector->Remove (theIObj);
7fd59977 2334
2195ab96 2335 myObjects.UnBind (theIObj);
7fd59977 2336
2195ab96 2337 if (theToUpdateviewer
2338 && aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 2339 {
2340 myMainVwr->Update();
2341 }
7fd59977 2342}
2343
2344//=======================================================================
2345//function : ClearGlobalPrs
2195ab96 2346//purpose :
7fd59977 2347//=======================================================================
2195ab96 2348void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2349 const Standard_Integer theMode,
2350 const Standard_Boolean theToUpdateViewer)
7fd59977 2351{
2195ab96 2352 if (theIObj.IsNull()
2353 || !myObjects.IsBound (theIObj))
2354 {
2355 return;
2356 }
2357
2358 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2359 if (aStatus->IsDModeIn (theMode))
2360 {
2361 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2362 if (aDispMode == theMode
2363 && myMainPM->IsHighlighted (theIObj, theMode))
2364 {
2365 myMainPM->Unhighlight (theIObj, theMode);
2366 }
2367
2368 myMainPM->Erase (theIObj, theMode);
2369 myMainPM->Clear (theIObj, theMode);
7fd59977 2370 }
eb4320f2 2371
2195ab96 2372 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2373 && theToUpdateViewer)
2374 {
7fd59977 2375 myMainVwr->Update();
2195ab96 2376 }
7fd59977 2377}
2378
2379//=======================================================================
2380//function : DrawHiddenLine
2195ab96 2381//purpose :
7fd59977 2382//=======================================================================
2195ab96 2383Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2384{
7fd59977 2385 return myDefaultDrawer->DrawHiddenLine();
2386}
2387
2388//=======================================================================
2389//function : EnableDrawHiddenLine
2195ab96 2390//purpose :
7fd59977 2391//=======================================================================
2195ab96 2392void AIS_InteractiveContext::EnableDrawHiddenLine() const
2393{
7fd59977 2394 myDefaultDrawer->EnableDrawHiddenLine();
2395}
2396
2397//=======================================================================
2398//function : DisableDrawHiddenLine
2195ab96 2399//purpose :
7fd59977 2400//=======================================================================
2195ab96 2401void AIS_InteractiveContext::DisableDrawHiddenLine() const
2402{
7fd59977 2403 myDefaultDrawer->DisableDrawHiddenLine();
2404}
2405
2406//=======================================================================
2407//function : HiddenLineAspect
2195ab96 2408//purpose :
7fd59977 2409//=======================================================================
2195ab96 2410Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2411{
7fd59977 2412 return myDefaultDrawer->HiddenLineAspect();
2413}
2414
2415//=======================================================================
2416//function : SetHiddenLineAspect
2195ab96 2417//purpose :
7fd59977 2418//=======================================================================
2195ab96 2419void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2420{
2421 myDefaultDrawer->SetHiddenLineAspect (theAspect);
7fd59977 2422}
2423
2424//=======================================================================
2425//function : SetIsoNumber
2195ab96 2426//purpose :
7fd59977 2427//=======================================================================
2195ab96 2428void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2429 const AIS_TypeOfIso theType)
7fd59977 2430{
2195ab96 2431 switch (theType)
2432 {
2433 case AIS_TOI_IsoU:
2434 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2435 break;
2436 case AIS_TOI_IsoV:
2437 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2438 break;
2439 case AIS_TOI_Both:
2440 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2441 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2442 break;
7fd59977 2443 }
2444}
2195ab96 2445
7fd59977 2446//=======================================================================
2447//function : IsoNumber
2195ab96 2448//purpose :
7fd59977 2449//=======================================================================
2195ab96 2450Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
7fd59977 2451{
2195ab96 2452 switch (theType)
2453 {
2454 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2455 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2456 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2457 ? myDefaultDrawer->UIsoAspect()->Number()
2458 : -1;
7fd59977 2459 }
2460 return 0;
2461}
2462
2463//=======================================================================
2464//function : IsoOnPlane
2195ab96 2465//purpose :
7fd59977 2466//=======================================================================
2195ab96 2467void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
7fd59977 2468{
2195ab96 2469 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
7fd59977 2470}
2471
2472//=======================================================================
2473//function : IsoOnPlane
2195ab96 2474//purpose :
7fd59977 2475//=======================================================================
2195ab96 2476Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
7fd59977 2477{
2478 return myDefaultDrawer->IsoOnPlane();
2479}
2480
2481//=======================================================================
2482//function : SetSelectionMode
2195ab96 2483//purpose :
7fd59977 2484//=======================================================================
2195ab96 2485void AIS_InteractiveContext::SetSelectionMode (const Handle(AIS_InteractiveObject)& ,
2486 const Standard_Integer )
7fd59977 2487{
2195ab96 2488 //
7fd59977 2489}
2490
2491//=======================================================================
2492//function : UnsetSelectionMode
2195ab96 2493//purpose :
7fd59977 2494//=======================================================================
2195ab96 2495void AIS_InteractiveContext::UnsetSelectionMode (const Handle(AIS_InteractiveObject)& )
7fd59977 2496{
2195ab96 2497 //
7fd59977 2498}
2499
3c982548 2500//=======================================================================
2501//function : SetSensitivityMode
2195ab96 2502//purpose :
3c982548 2503//=======================================================================
2195ab96 2504void AIS_InteractiveContext::SetSensitivityMode (const StdSelect_SensitivityMode theMode)
2505{
2506 if (HasOpenedContext())
2507 {
2508 myLocalContexts (myCurLocalIndex)->SetSensitivityMode (theMode);
2509 }
2510 else
2511 {
2512 myMainSel->SetSensitivityMode (theMode);
3c982548 2513 }
2514}
2515
2516//=======================================================================
2517//function : SensitivityMode
2195ab96 2518//purpose :
3c982548 2519//=======================================================================
2195ab96 2520StdSelect_SensitivityMode AIS_InteractiveContext::SensitivityMode() const
2521{
2522 return HasOpenedContext()
2523 ? myLocalContexts (myCurLocalIndex)->SensitivityMode()
2524 : myMainSel->SensitivityMode();
3c982548 2525}
2526
7fd59977 2527//=======================================================================
2528//function : SetSensitivity
2195ab96 2529//purpose :
7fd59977 2530//=======================================================================
2195ab96 2531void AIS_InteractiveContext::SetSensitivity (const Standard_Real thePrecision)
2532{
2533 if (HasOpenedContext())
2534 {
2535 myLocalContexts(myCurLocalIndex)->SetSensitivity (thePrecision);
2536 }
2537 else
2538 {
2539 myMainSel->SetSensitivity (thePrecision);
7fd59977 2540 }
2541}
2542
2543//=======================================================================
3c982548 2544//function : Sensitivity
2195ab96 2545//purpose :
7fd59977 2546//=======================================================================
2195ab96 2547Standard_Real AIS_InteractiveContext::Sensitivity() const
2548{
2549 return HasOpenedContext()
2550 ? myLocalContexts(myCurLocalIndex)->Sensitivity()
2551 : myMainSel->Sensitivity();
3c982548 2552}
2553
2554//=======================================================================
2555//function : SetPixelTolerance
2195ab96 2556//purpose :
3c982548 2557//=======================================================================
2195ab96 2558void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2559{
2560 if (HasOpenedContext())
2561 {
2562 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2563 }
2564 else
2565 {
2566 myMainSel->SetPixelTolerance (thePrecision);
7fd59977 2567 }
2568}
3c982548 2569
2570//=======================================================================
2571//function : PixelTolerance
2195ab96 2572//purpose :
3c982548 2573//=======================================================================
2195ab96 2574Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2575{
2576 return HasOpenedContext()
2577 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2578 : myMainSel->PixelTolerance();
3c982548 2579}
7fd59977 2580
2581//=======================================================================
2582//function : IsInLocal
2195ab96 2583//purpose :
7fd59977 2584//=======================================================================
2195ab96 2585Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2586 Standard_Integer& theIndex) const
7fd59977 2587{
2195ab96 2588 if (theIObj.IsNull())
2589 {
2590 return Standard_False;
2591 }
2592
81bba717 2593 // if it exists at neutral point 0 index is returned
2195ab96 2594 if (myObjects.IsBound (theIObj))
2595 {
2596 theIndex = 0;
7fd59977 2597 return Standard_False;
2598 }
2195ab96 2599
2600 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2601 {
2602 if (myLocalContexts.IsBound (aCtxIter))
2603 {
2604 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2605 {
2606 theIndex = aCtxIter;
7fd59977 2607 return Standard_True;
7fd59977 2608 }
2609 }
2610 }
2195ab96 2611 theIndex = -1;
7fd59977 2612 return Standard_False;
2195ab96 2613}
2614
7fd59977 2615//=======================================================================
2616//function : InitAttributes
2195ab96 2617//purpose :
7fd59977 2618//=======================================================================
7fd59977 2619void AIS_InteractiveContext::InitAttributes()
2620{
2195ab96 2621 mgrSelector->Add (myMainSel);
7fd59977 2622 myCurrentName = AIS_Context_NewCurName();
2623 mySelectionName = AIS_Context_NewSelName();
2624
2195ab96 2625 AIS_Selection::CreateSelection (mySelectionName.ToCString());
2626 AIS_Selection::CreateSelection (myCurrentName.ToCString());
7fd59977 2627
2195ab96 2628 myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2629 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2630 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
7fd59977 2631
2632// myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2195ab96 2633 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2634 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2635 aLineAspect->SetWidth (1.0);
2636 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
7fd59977 2637
81bba717 2638 // tolerance to 4 pixels...
3c982548 2639 SetPixelTolerance();
7fd59977 2640
2641 // Customizing the drawer for trihedrons and planes...
2195ab96 2642 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2643 const Standard_Real aLength = 100.0;
2644 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2645 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2646 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2647 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2648 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
7fd59977 2649
2195ab96 2650 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2651 const Standard_Real aPlaneLength = 200.0;
2652 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2653 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
7fd59977 2654}
2655
7fd59977 2656//=======================================================================
2657//function : TrihedronSize
2195ab96 2658//purpose :
7fd59977 2659//=======================================================================
2660Standard_Real AIS_InteractiveContext::TrihedronSize() const
2661{
2662 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2663}
2195ab96 2664
7fd59977 2665//=======================================================================
2666//function : SetTrihedronSize
2195ab96 2667//purpose :
7fd59977 2668//=======================================================================
2195ab96 2669void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2670 const Standard_Boolean /*updateviewer*/)
7fd59977 2671{
2195ab96 2672 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2673 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2674 Redisplay (AIS_KOI_Datum, 4, Standard_True);
7fd59977 2675}
2676
7fd59977 2677//=======================================================================
2678//function : SetPlaneSize
2195ab96 2679//purpose :
7fd59977 2680//=======================================================================
2195ab96 2681void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2682 const Standard_Real theValY,
7fd59977 2683 const Standard_Boolean /*updateviewer*/)
2684{
2195ab96 2685 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2686 Redisplay (AIS_KOI_Datum, 7);
7fd59977 2687}
2688
2689//=======================================================================
2690//function : SetPlaneSize
2195ab96 2691//purpose :
7fd59977 2692//=======================================================================
2195ab96 2693void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2694 const Standard_Boolean theToUpdateViewer)
7fd59977 2695{
2195ab96 2696 SetPlaneSize (theVal, theVal, theToUpdateViewer);
7fd59977 2697}
2698
2699//=======================================================================
2700//function : PlaneSize
2195ab96 2701//purpose :
7fd59977 2702//=======================================================================
2195ab96 2703Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2704 Standard_Real& theY) const
7fd59977 2705{
2195ab96 2706 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2707 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2708 return (Abs (theX - theY) <= Precision::Confusion());
7fd59977 2709}
2710
7fd59977 2711//=======================================================================
2195ab96 2712//function : SetAutoActivateSelection
2713//purpose :
7fd59977 2714//=======================================================================
2195ab96 2715void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
7fd59977 2716{
2195ab96 2717 myIsAutoActivateSelMode = theIsAuto;
7fd59977 2718}
2719
2720//=======================================================================
2195ab96 2721//function : GetAutoActivateSelection
2722//purpose :
7fd59977 2723//=======================================================================
2724Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2725{
2726 return myIsAutoActivateSelMode;
2727}
59f45b7c 2728
2729//=======================================================================
2730//function : SetZLayer
2195ab96 2731//purpose :
59f45b7c 2732//=======================================================================
59f45b7c 2733void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2734 const Standard_Integer theLayerId)
2735{
2195ab96 2736 if (theIObj.IsNull())
59f45b7c 2737 return;
2738
2739 if (myObjects.IsBound (theIObj))
2740 {
eb4320f2 2741 if (myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed || myObjects (theIObj)->GraphicStatus() == AIS_DS_Erased)
59f45b7c 2742 {
eb4320f2 2743 theIObj->SetZLayer (myMainPM, theLayerId);
59f45b7c 2744 }
2745 }
2195ab96 2746 else if (HasOpenedContext())
59f45b7c 2747 {
2748 myLocalContexts (myCurLocalIndex)->SetZLayer (theIObj, theLayerId);
2749 }
2750}
2751
2752//=======================================================================
2753//function : GetZLayer
2195ab96 2754//purpose :
59f45b7c 2755//=======================================================================
59f45b7c 2756Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2757{
2195ab96 2758 if (theIObj.IsNull())
59f45b7c 2759 return -1;
2760
2761 if (myObjects.IsBound (theIObj))
71c4f9c6 2762 {
59f45b7c 2763 return theIObj->GetZLayer (myMainPM);
71c4f9c6 2764 }
2195ab96 2765 else if (HasOpenedContext())
71c4f9c6 2766 {
2767 return myLocalContexts (myCurLocalIndex)->GetZLayer (theIObj);
2768 }
59f45b7c 2769
71c4f9c6 2770 return -1;
59f45b7c 2771}