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