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