0026082: When view is resized horizontally the visualization is not scaled
[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 }
28ee613b 1706 theIObj->UpdateSelection();
2195ab96 1707 theIObj->SetRecomputeOk();
1708 }
1709
1710 if (theToUpdateViewer)
1711 {
1712 UpdateCurrentViewer();
1713 }
7fd59977 1714}
1715
2195ab96 1716//=======================================================================
1717//function : redisplayPrsModes
1718//purpose :
1719//=======================================================================
1720void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1721 const Standard_Boolean theToUpdateViewer)
7fd59977 1722{
2195ab96 1723 if (theIObj->RecomputeEveryPrs())
1724 {
36132a2e 1725 theIObj->Update (Standard_True);
1726 theIObj->UpdateSelection();
2195ab96 1727 }
7fd59977 1728 else
2195ab96 1729 {
1730 TColStd_ListOfInteger aModes;
1731 theIObj->ToBeUpdated (aModes);
1732 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
7fd59977 1733 {
2195ab96 1734 theIObj->Update (aModeIter.Value(), Standard_False);
7fd59977 1735 }
2195ab96 1736 theIObj->SetRecomputeOk();
1737 }
7fd59977 1738
2195ab96 1739 if (theToUpdateViewer)
1740 {
1741 UpdateCurrentViewer();
1742 }
7fd59977 1743}
1744
1745//=======================================================================
2195ab96 1746//function : SetColor
1747//purpose :
7fd59977 1748//=======================================================================
2195ab96 1749void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1750 const Quantity_NameOfColor theColor,
1751 const Standard_Boolean theToUpdateViewer)
1752{
1753 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1754}
7fd59977 1755
2195ab96 1756//=======================================================================
1757//function : SetColor
1758//purpose :
1759//=======================================================================
1760void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1761 const Quantity_Color& theColor,
1762 const Standard_Boolean theToUpdateViewer)
7fd59977 1763{
2195ab96 1764 if (theIObj.IsNull())
1765 {
1766 return;
1767 }
7fd59977 1768
2195ab96 1769 if (!theIObj->HasInteractiveContext())
1770 {
1771 theIObj->SetContext (this);
1772 }
1773 theIObj->SetColor (theColor);
1774 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1775}
7fd59977 1776
2195ab96 1777//=======================================================================
1778//function : SetDeviationCoefficient
1779//purpose :
1780//=======================================================================
1781void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1782 const Standard_Real theCoefficient,
1783 const Standard_Boolean theToUpdateViewer)
1784{
1785 if (theIObj.IsNull())
1786 {
1787 return;
1788 }
7fd59977 1789
2195ab96 1790 if (!theIObj->HasInteractiveContext())
1791 {
1792 theIObj->SetContext (this);
1793 }
7fd59977 1794
2195ab96 1795 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1796 if (theIObj->Type() != AIS_KOI_Object
1797 && theIObj->Type() != AIS_KOI_Shape)
1798 {
1799 return;
1800 }
1801 else if (theIObj->Signature() != 0)
1802 {
1803 return;
1804 }
1805
1806 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1807 aShape->SetOwnDeviationCoefficient (theCoefficient);
1808 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1809}
1810
1811//=======================================================================
1812//function : SetHLRDeviationCoefficient
2195ab96 1813//purpose :
7fd59977 1814//=======================================================================
2195ab96 1815void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1816 const Standard_Real theCoefficient,
1817 const Standard_Boolean theToUpdateViewer)
7fd59977 1818{
2195ab96 1819 if (theIObj.IsNull())
1820 {
1821 return;
1822 }
1823
1824 if (!theIObj->HasInteractiveContext())
1825 {
1826 theIObj->SetContext (this);
1827 }
7fd59977 1828
81bba717 1829 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1830 if (theIObj->Type() != AIS_KOI_Object
1831 && theIObj->Type() != AIS_KOI_Shape)
1832 {
1833 return;
1834 }
1835 else if (theIObj->Signature() != 0)
1836 {
1837 return;
1838 }
7fd59977 1839
2195ab96 1840 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1841 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1842 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1843}
1844
7fd59977 1845//=======================================================================
1846//function : SetDeviationAngle
2195ab96 1847//purpose :
7fd59977 1848//=======================================================================
2195ab96 1849void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1850 const Standard_Real theAngle,
1851 const Standard_Boolean theToUpdateViewer)
7fd59977 1852{
2195ab96 1853 if (theIObj.IsNull())
1854 {
1855 return;
1856 }
1857
1858 if (!theIObj->HasInteractiveContext())
1859 {
1860 theIObj->SetContext (this);
1861 }
7fd59977 1862
e33e7e78 1863 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1864 if (theIObj->Type() != AIS_KOI_Shape)
1865 {
1866 return;
1867 }
1868 else if (theIObj->Signature() != 0)
1869 {
1870 return;
1871 }
7fd59977 1872
2195ab96 1873 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1874 aShape->SetOwnDeviationAngle (theAngle);
1875 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1876}
2195ab96 1877
7fd59977 1878//=======================================================================
2195ab96 1879//function : SetAngleAndDeviation
1880//purpose :
7fd59977 1881//=======================================================================
2195ab96 1882void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1883 const Standard_Real theAngle,
1884 const Standard_Boolean theToUpdateViewer)
7fd59977 1885{
2195ab96 1886 if (theIObj.IsNull())
1887 {
1888 return;
1889 }
1890
1891 if (!theIObj->HasInteractiveContext())
1892 {
1893 theIObj->SetContext (this);
1894 }
7fd59977 1895
e33e7e78 1896 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1897 if (theIObj->Type() != AIS_KOI_Shape)
1898 {
1899 return;
1900 }
1901 if (theIObj->Signature() != 0)
1902 {
1903 return;
1904 }
7fd59977 1905
2195ab96 1906 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1907 aShape->SetAngleAndDeviation (theAngle);
7fd59977 1908
2195ab96 1909 if (theIObj->RecomputeEveryPrs())
1910 {
36132a2e 1911 theIObj->Update (Standard_True);
1912 theIObj->UpdateSelection();
2195ab96 1913 }
7fd59977 1914 else
2195ab96 1915 {
1916 Update (theIObj, theToUpdateViewer);
1917 }
7fd59977 1918}
1919
1920//=======================================================================
2195ab96 1921//function : SetHLRAngleAndDeviation
1922//purpose :
7fd59977 1923//=======================================================================
2195ab96 1924void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1925 const Standard_Real theAngle,
1926 const Standard_Boolean theToUpdateViewer)
7fd59977 1927{
2195ab96 1928 if (theIObj.IsNull())
1929 {
1930 return;
1931 }
7fd59977 1932
2195ab96 1933 if (!theIObj->HasInteractiveContext())
1934 {
1935 theIObj->SetContext (this);
1936 }
7fd59977 1937
e33e7e78 1938 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1939 if (theIObj->Type() != AIS_KOI_Shape)
1940 {
1941 return;
1942 }
1943 if (theIObj->Signature() != 0)
1944 {
1945 return;
1946 }
1947 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1948 aShape->SetHLRAngleAndDeviation (theAngle);
1949 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1950}
1951
1952//=======================================================================
1953//function : SetHLRDeviationAngle
2195ab96 1954//purpose :
7fd59977 1955//=======================================================================
2195ab96 1956void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1957 const Standard_Real theAngle,
1958 const Standard_Boolean theToUpdateViewer)
7fd59977 1959{
2195ab96 1960 if (theIObj.IsNull())
1961 {
1962 return;
1963 }
7fd59977 1964
2195ab96 1965 if (!theIObj->HasInteractiveContext())
1966 {
1967 theIObj->SetContext (this);
1968 }
7fd59977 1969
2195ab96 1970 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1971 if (theIObj->Type() != AIS_KOI_Shape)
1972 {
1973 return;
1974 }
1975 if (theIObj->Signature() != 0)
1976 {
1977 return;
1978 }
1979 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1980 aShape->SetOwnHLRDeviationAngle (theAngle);
1981 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1982}
1983
1984//=======================================================================
1985//function : UnsetColor
2195ab96 1986//purpose :
7fd59977 1987//=======================================================================
2195ab96 1988void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1989 const Standard_Boolean theToUpdateViewer)
7fd59977 1990{
2195ab96 1991 if (theIObj.IsNull())
1992 {
1993 return;
1994 }
1995
1996 theIObj->UnsetColor();
1997 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 1998}
1999
2000//=======================================================================
2001//function : HasColor
2195ab96 2002//purpose :
7fd59977 2003//=======================================================================
2195ab96 2004Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 2005{
2195ab96 2006 return theIObj->HasColor();
7fd59977 2007}
2008
2009//=======================================================================
2010//function : Color
2195ab96 2011//purpose :
7fd59977 2012//=======================================================================
2195ab96 2013Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 2014{
2195ab96 2015 return theIObj->Color();
7fd59977 2016}
2017
2195ab96 2018//=======================================================================
2019//function : Color
2020//purpose :
2021//=======================================================================
2022void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2023 Quantity_Color& theColor) const
7fd59977 2024{
2195ab96 2025 theIObj->Color (theColor);
7fd59977 2026}
7fd59977 2027
2028//=======================================================================
2029//function : Width
2195ab96 2030//purpose :
7fd59977 2031//=======================================================================
2195ab96 2032Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 2033{
2195ab96 2034 return theIObj->Width();
7fd59977 2035}
2036
2037//=======================================================================
2038//function : SetWidth
2195ab96 2039//purpose :
7fd59977 2040//=======================================================================
2195ab96 2041void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2042 const Standard_Real theWidth,
2043 const Standard_Boolean theToUpdateViewer)
7fd59977 2044{
2195ab96 2045 if (theIObj.IsNull())
2046 {
2047 return;
2048 }
2049
2050 if (!theIObj->HasInteractiveContext())
2051 {
2052 theIObj->SetContext (this);
2053 }
2054
2055 theIObj->SetWidth (theWidth);
2056 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2057}
2058
2059//=======================================================================
2060//function : UnsetWidth
2195ab96 2061//purpose :
7fd59977 2062//=======================================================================
2195ab96 2063void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2064 const Standard_Boolean theToUpdateViewer)
7fd59977 2065{
2195ab96 2066 if (theIObj.IsNull())
2067 {
2068 return;
2069 }
2070
2071 theIObj->UnsetWidth();
2072 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2073}
2074
2075//=======================================================================
2076//function : SetMaterial
2195ab96 2077//purpose :
7fd59977 2078//=======================================================================
2195ab96 2079void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2080 const Graphic3d_NameOfMaterial theName,
2081 const Standard_Boolean theToUpdateViewer)
7fd59977 2082{
2195ab96 2083 if (theIObj.IsNull())
2084 {
2085 return;
2086 }
2087
2088 if (!theIObj->HasInteractiveContext())
2089 {
2090 theIObj->SetContext (this);
2091 }
7fd59977 2092
2195ab96 2093 theIObj->SetMaterial (theName);
2094 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2095}
2096
2097//=======================================================================
2098//function : UnsetMaterial
2195ab96 2099//purpose :
7fd59977 2100//=======================================================================
2195ab96 2101void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2102 const Standard_Boolean theToUpdateViewer)
7fd59977 2103{
2195ab96 2104 if (theIObj.IsNull())
2105 {
2106 return;
2107 }
2108 theIObj->UnsetMaterial();
2109 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2110}
2111
2112//=======================================================================
2113//function : SetTransparency
2195ab96 2114//purpose :
7fd59977 2115//=======================================================================
2195ab96 2116void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2117 const Standard_Real theValue,
2118 const Standard_Boolean theToUpdateViewer)
7fd59977 2119{
2195ab96 2120 if (theIObj.IsNull())
2121 {
2122 return;
2123 }
2124
2125 if (!theIObj->HasInteractiveContext())
2126 {
2127 theIObj->SetContext (this);
2128 }
7fd59977 2129
2195ab96 2130 if (!theIObj->IsTransparent()
2131 && theValue <= 0.05)
a6964ce6 2132 {
2133 return;
2134 }
2135
2195ab96 2136 if (theValue <= 0.05)
2137 {
2138 UnsetTransparency (theIObj, theToUpdateViewer);
7fd59977 2139 return;
2140 }
a6964ce6 2141
2195ab96 2142 theIObj->SetTransparency (theValue);
2143 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2144}
2145
2146//=======================================================================
2147//function : UnsetTransparency
2195ab96 2148//purpose :
7fd59977 2149//=======================================================================
2195ab96 2150void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2151 const Standard_Boolean theToUpdateViewer)
7fd59977 2152{
2195ab96 2153 if (theIObj.IsNull())
2154 {
2155 return;
2156 }
7fd59977 2157
2195ab96 2158 theIObj->UnsetTransparency();
2159 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2160}
2161
2195ab96 2162//=======================================================================
2163//function : SetSelectedAspect
2164//purpose :
2165//=======================================================================
2166void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2167 const Standard_Boolean theIsGlobalChange,
2168 const Standard_Boolean theToUpdateViewer)
2169{
2170 if (HasOpenedContext())
2171 {
2172 return;
2173 }
2174
2175 Standard_Boolean isFound = Standard_False;
2176 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
2177 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
2178 {
2179 isFound = Standard_True;
2180 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
2181 anObj->SetAspect (theAspect, theIsGlobalChange);
2182 }
2183
2184 if (isFound
2185 && theToUpdateViewer)
2186 {
2187 myMainVwr->Update();
7fd59977 2188 }
2189}
7fd59977 2190
2191//=======================================================================
2192//function : SetLocalAttributes
2195ab96 2193//purpose :
7fd59977 2194//=======================================================================
2195ab96 2195void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
6262338c 2196 const Handle(Prs3d_Drawer)& theDrawer,
2195ab96 2197 const Standard_Boolean theToUpdateViewer)
7fd59977 2198{
2195ab96 2199 if (theIObj.IsNull())
2200 {
2201 return;
2202 }
2203
2204 if (!theIObj->HasInteractiveContext())
2205 {
2206 theIObj->SetContext (this);
2207 }
2208
2209 theIObj->SetAttributes (theDrawer);
2210 Update (theIObj, theToUpdateViewer);
7fd59977 2211}
2212
2213//=======================================================================
2214//function : UnsetLocalAttributes
2195ab96 2215//purpose :
7fd59977 2216//=======================================================================
2195ab96 2217void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2218 const Standard_Boolean theToUpdateViewer)
7fd59977 2219{
2195ab96 2220 if (theIObj.IsNull())
2221 {
2222 return;
2223 }
7fd59977 2224
2195ab96 2225 if (!theIObj->HasInteractiveContext())
2226 {
2227 theIObj->SetContext (this);
2228 }
2229 theIObj->UnsetAttributes();
2230 Update (theIObj, theToUpdateViewer);
2231}
7fd59977 2232
2233//=======================================================================
2234//function : Status
2195ab96 2235//purpose :
7fd59977 2236//=======================================================================
2195ab96 2237void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2238 TCollection_ExtendedString& theStatus) const
7fd59977 2239{
2195ab96 2240 theStatus = "";
2241 if (theIObj.IsNull()
2242 || !myObjects.IsBound (theIObj))
2243 {
2244 return;
2245 }
7fd59977 2246
2195ab96 2247 theStatus += "\t ____________________________________________";
2248 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2249 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2250 switch (aStatus->GraphicStatus())
2251 {
7fd59977 2252 case AIS_DS_Displayed:
2195ab96 2253 {
2254 theStatus += "\t| -->Displayed\n";
7fd59977 2255 break;
2256 }
2195ab96 2257 case AIS_DS_Erased:
2258 {
2259 theStatus += "\t| -->Erased\n";
2260 break;
7fd59977 2261 }
2195ab96 2262 default:
2263 break;
2264 }
2265
2266 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2267 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2268 {
2269 theStatus += "\t|\t Mode ";
2270 theStatus += TCollection_AsciiString (aDispModeIter.Value());
2271 theStatus += "\n";
2272 }
2273 if (IsCurrent (theIObj)) theStatus +="\t| Current\n";
2274 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
7fd59977 2275
2195ab96 2276 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2277 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2278 {
2279 theStatus += "\t\t Mode ";
2280 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2281 theStatus += "\n";
2282 }
2283 theStatus += "\t ____________________________________________";
2284}
7fd59977 2285
2286//=======================================================================
2287//function : GetDefModes
2195ab96 2288//purpose :
7fd59977 2289//=======================================================================
2195ab96 2290void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2291 Standard_Integer& theDispMode,
2292 Standard_Integer& theHiMode,
2293 Standard_Integer& theSelMode) const
7fd59977 2294{
2195ab96 2295 if (theIObj.IsNull())
2296 {
2297 return;
2298 }
7fd59977 2299
2195ab96 2300 theDispMode = theIObj->HasDisplayMode()
2301 ? theIObj->DisplayMode()
2302 : (theIObj->AcceptDisplayMode (myDisplayMode)
2303 ? myDisplayMode
2304 : 0);
2305 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2306 theSelMode = theIObj->HasSelectionMode() ? theIObj->SelectionMode() : -1;
2307}
7fd59977 2308
2309//=======================================================================
2310//function : EraseGlobal
2195ab96 2311//purpose :
7fd59977 2312//=======================================================================
2195ab96 2313void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2314 const Standard_Boolean theToUpdateviewer)
7fd59977 2315{
2195ab96 2316 if (theIObj.IsNull()
2317 || !myObjects.IsBound (theIObj))
2318 {
2319 return;
2320 }
7fd59977 2321
2195ab96 2322 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2323
a1954302 2324 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2325 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2326 || aStatus->GraphicStatus() == AIS_DS_Erased)
2195ab96 2327 {
a1954302 2328 return;
2329 }
2195ab96 2330
a1954302 2331 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2332 {
2333 if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2195ab96 2334 {
a1954302 2335 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2195ab96 2336 }
2337
a1954302 2338 myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2339 }
2195ab96 2340
a1954302 2341 if (IsCurrent (theIObj)
2342 && !aStatus->IsDModeIn (aDispMode))
2343 {
2344 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2345 }
2346
2347 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2348 {
2349 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
7fd59977 2350 }
2195ab96 2351 aStatus->SetGraphicStatus (AIS_DS_Erased);
a1954302 2352
2353 if (theToUpdateviewer)
2354 {
2355 myMainVwr->Update();
2356 }
7fd59977 2357}
2358
2359//=======================================================================
2360//function : ClearGlobal
2195ab96 2361//purpose :
7fd59977 2362//=======================================================================
2195ab96 2363void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2364 const Standard_Boolean theToUpdateviewer)
7fd59977 2365{
2195ab96 2366 if (theIObj.IsNull()
2367 || !myObjects.IsBound (theIObj))
2368 {
f751596e 2369 // for cases when reference shape of connected interactives was not displayed
2370 // but its selection primitives were calculated
2371 mgrSelector->Remove (theIObj);
2195ab96 2372 return;
2373 }
2374
2375 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2376 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2377 {
2378 if (aStatus->IsHilighted())
2379 {
2380 if (IsCurrent (theIObj))
2381 {
2382 AddOrRemoveCurrentObject (theIObj, theToUpdateviewer);
2383 }
2384 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2385 {
2386 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2387 }
2388 }
2389 myMainPM->Erase (theIObj, aDispModeIter.Value());
2390 myMainPM->Clear (theIObj, aDispModeIter.Value());
2391 if (theIObj->HasHilightMode())
2392 {
2393 Standard_Integer im = theIObj->HilightMode();
2394 myMainPM->Unhighlight (theIObj, im);
2395 myMainPM->Erase (theIObj, im);
2396 }
2397 }
7fd59977 2398
2195ab96 2399 // Object removes from Detected sequence
2400 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
7fd59977 2401 {
2402 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2195ab96 2403 if (!anObj.IsNull()
2404 && anObj != theIObj)
2405 {
2406 myAISDetectedSeq.Remove (aDetIter);
2407 }
7fd59977 2408 }
2409
2195ab96 2410 if (myLastinMain == theIObj)
2411 {
44d9ae89 2412 myLastinMain.Nullify();
2195ab96 2413 }
2414 if (myLastPicked == theIObj)
2415 {
7fd59977 2416 myLastPicked.Nullify();
2195ab96 2417 }
2418
2419 // remove IO from the selection manager to avoid memory leaks
2420 mgrSelector->Remove (theIObj);
7fd59977 2421
2195ab96 2422 myObjects.UnBind (theIObj);
a272ed94 2423 myMainVwr->Viewer()->UnregisterObject (theIObj);
2424 for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2425 {
2426 myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj);
2427 }
7fd59977 2428
2195ab96 2429 if (theToUpdateviewer
2430 && aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 2431 {
2432 myMainVwr->Update();
2433 }
7fd59977 2434}
2435
2436//=======================================================================
2437//function : ClearGlobalPrs
2195ab96 2438//purpose :
7fd59977 2439//=======================================================================
2195ab96 2440void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2441 const Standard_Integer theMode,
2442 const Standard_Boolean theToUpdateViewer)
7fd59977 2443{
2195ab96 2444 if (theIObj.IsNull()
2445 || !myObjects.IsBound (theIObj))
2446 {
2447 return;
2448 }
2449
2450 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2451 if (aStatus->IsDModeIn (theMode))
2452 {
2453 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2454 if (aDispMode == theMode
2455 && myMainPM->IsHighlighted (theIObj, theMode))
2456 {
2457 myMainPM->Unhighlight (theIObj, theMode);
2458 }
2459
2460 myMainPM->Erase (theIObj, theMode);
2461 myMainPM->Clear (theIObj, theMode);
7fd59977 2462 }
eb4320f2 2463
2195ab96 2464 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2465 && theToUpdateViewer)
2466 {
7fd59977 2467 myMainVwr->Update();
2195ab96 2468 }
7fd59977 2469}
2470
2471//=======================================================================
2472//function : DrawHiddenLine
2195ab96 2473//purpose :
7fd59977 2474//=======================================================================
2195ab96 2475Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2476{
7fd59977 2477 return myDefaultDrawer->DrawHiddenLine();
2478}
2479
2480//=======================================================================
2481//function : EnableDrawHiddenLine
2195ab96 2482//purpose :
7fd59977 2483//=======================================================================
2195ab96 2484void AIS_InteractiveContext::EnableDrawHiddenLine() const
2485{
7fd59977 2486 myDefaultDrawer->EnableDrawHiddenLine();
2487}
2488
2489//=======================================================================
2490//function : DisableDrawHiddenLine
2195ab96 2491//purpose :
7fd59977 2492//=======================================================================
2195ab96 2493void AIS_InteractiveContext::DisableDrawHiddenLine() const
2494{
7fd59977 2495 myDefaultDrawer->DisableDrawHiddenLine();
2496}
2497
2498//=======================================================================
2499//function : HiddenLineAspect
2195ab96 2500//purpose :
7fd59977 2501//=======================================================================
2195ab96 2502Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2503{
7fd59977 2504 return myDefaultDrawer->HiddenLineAspect();
2505}
2506
2507//=======================================================================
2508//function : SetHiddenLineAspect
2195ab96 2509//purpose :
7fd59977 2510//=======================================================================
2195ab96 2511void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2512{
2513 myDefaultDrawer->SetHiddenLineAspect (theAspect);
7fd59977 2514}
2515
2516//=======================================================================
2517//function : SetIsoNumber
2195ab96 2518//purpose :
7fd59977 2519//=======================================================================
2195ab96 2520void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2521 const AIS_TypeOfIso theType)
7fd59977 2522{
2195ab96 2523 switch (theType)
2524 {
2525 case AIS_TOI_IsoU:
2526 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2527 break;
2528 case AIS_TOI_IsoV:
2529 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2530 break;
2531 case AIS_TOI_Both:
2532 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2533 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2534 break;
7fd59977 2535 }
2536}
2195ab96 2537
7fd59977 2538//=======================================================================
2539//function : IsoNumber
2195ab96 2540//purpose :
7fd59977 2541//=======================================================================
2195ab96 2542Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
7fd59977 2543{
2195ab96 2544 switch (theType)
2545 {
2546 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2547 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2548 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2549 ? myDefaultDrawer->UIsoAspect()->Number()
2550 : -1;
7fd59977 2551 }
2552 return 0;
2553}
2554
2555//=======================================================================
2556//function : IsoOnPlane
2195ab96 2557//purpose :
7fd59977 2558//=======================================================================
2195ab96 2559void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
7fd59977 2560{
2195ab96 2561 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
7fd59977 2562}
2563
2564//=======================================================================
2565//function : IsoOnPlane
2195ab96 2566//purpose :
7fd59977 2567//=======================================================================
2195ab96 2568Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
7fd59977 2569{
2570 return myDefaultDrawer->IsoOnPlane();
2571}
2572
2573//=======================================================================
2574//function : SetSelectionMode
2195ab96 2575//purpose :
7fd59977 2576//=======================================================================
2195ab96 2577void AIS_InteractiveContext::SetSelectionMode (const Handle(AIS_InteractiveObject)& ,
2578 const Standard_Integer )
7fd59977 2579{
2195ab96 2580 //
7fd59977 2581}
2582
2583//=======================================================================
2584//function : UnsetSelectionMode
2195ab96 2585//purpose :
7fd59977 2586//=======================================================================
2195ab96 2587void AIS_InteractiveContext::UnsetSelectionMode (const Handle(AIS_InteractiveObject)& )
7fd59977 2588{
2195ab96 2589 //
7fd59977 2590}
2591
3c982548 2592//=======================================================================
3c982548 2593//function : SetPixelTolerance
28ee613b 2594//purpose : Disables the mechanism of adaptive tolerance calculation in
2595// SelectMgr_ViewerSelector and sets the given tolerance for ALL
2596// sensitive entities activated. For more information, see
2597// SelectMgr_ViewerSelector.hxx
3c982548 2598//=======================================================================
f751596e 2599void AIS_InteractiveContext::SetPixelTolerance (const Standard_Real thePrecision)
2195ab96 2600{
2601 if (HasOpenedContext())
2602 {
2603 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2604 }
2605 else
2606 {
2607 myMainSel->SetPixelTolerance (thePrecision);
7fd59977 2608 }
2609}
3c982548 2610
2611//=======================================================================
2612//function : PixelTolerance
2195ab96 2613//purpose :
3c982548 2614//=======================================================================
f751596e 2615Standard_Real AIS_InteractiveContext::PixelTolerance() const
2195ab96 2616{
2617 return HasOpenedContext()
2618 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2619 : myMainSel->PixelTolerance();
3c982548 2620}
7fd59977 2621
2622//=======================================================================
2623//function : IsInLocal
2195ab96 2624//purpose :
7fd59977 2625//=======================================================================
2195ab96 2626Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2627 Standard_Integer& theIndex) const
7fd59977 2628{
2195ab96 2629 if (theIObj.IsNull())
2630 {
2631 return Standard_False;
2632 }
2633
81bba717 2634 // if it exists at neutral point 0 index is returned
2195ab96 2635 if (myObjects.IsBound (theIObj))
2636 {
2637 theIndex = 0;
7fd59977 2638 return Standard_False;
2639 }
2195ab96 2640
2641 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2642 {
2643 if (myLocalContexts.IsBound (aCtxIter))
2644 {
2645 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2646 {
2647 theIndex = aCtxIter;
7fd59977 2648 return Standard_True;
7fd59977 2649 }
2650 }
2651 }
2195ab96 2652 theIndex = -1;
7fd59977 2653 return Standard_False;
2195ab96 2654}
2655
7fd59977 2656//=======================================================================
2657//function : InitAttributes
2195ab96 2658//purpose :
7fd59977 2659//=======================================================================
7fd59977 2660void AIS_InteractiveContext::InitAttributes()
2661{
2195ab96 2662 mgrSelector->Add (myMainSel);
7fd59977 2663 myCurrentName = AIS_Context_NewCurName();
2664 mySelectionName = AIS_Context_NewSelName();
2665
2195ab96 2666 AIS_Selection::CreateSelection (mySelectionName.ToCString());
2667 AIS_Selection::CreateSelection (myCurrentName.ToCString());
7fd59977 2668
2195ab96 2669 myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2670 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2671 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
7fd59977 2672
2673// myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2195ab96 2674 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2675 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2676 aLineAspect->SetWidth (1.0);
2677 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
7fd59977 2678
28ee613b 2679 // tolerance to 2 pixels...
2680 SetPixelTolerance (2.0);
7fd59977 2681
2682 // Customizing the drawer for trihedrons and planes...
2195ab96 2683 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2684 const Standard_Real aLength = 100.0;
2685 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2686 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2687 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2688 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2689 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
7fd59977 2690
2195ab96 2691 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2692 const Standard_Real aPlaneLength = 200.0;
2693 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2694 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
7fd59977 2695}
2696
7fd59977 2697//=======================================================================
2698//function : TrihedronSize
2195ab96 2699//purpose :
7fd59977 2700//=======================================================================
2701Standard_Real AIS_InteractiveContext::TrihedronSize() const
2702{
2703 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2704}
2195ab96 2705
7fd59977 2706//=======================================================================
2707//function : SetTrihedronSize
2195ab96 2708//purpose :
7fd59977 2709//=======================================================================
2195ab96 2710void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2711 const Standard_Boolean /*updateviewer*/)
7fd59977 2712{
2195ab96 2713 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2714 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2715 Redisplay (AIS_KOI_Datum, 4, Standard_True);
7fd59977 2716}
2717
7fd59977 2718//=======================================================================
2719//function : SetPlaneSize
2195ab96 2720//purpose :
7fd59977 2721//=======================================================================
2195ab96 2722void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2723 const Standard_Real theValY,
7fd59977 2724 const Standard_Boolean /*updateviewer*/)
2725{
2195ab96 2726 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2727 Redisplay (AIS_KOI_Datum, 7);
7fd59977 2728}
2729
2730//=======================================================================
2731//function : SetPlaneSize
2195ab96 2732//purpose :
7fd59977 2733//=======================================================================
2195ab96 2734void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2735 const Standard_Boolean theToUpdateViewer)
7fd59977 2736{
2195ab96 2737 SetPlaneSize (theVal, theVal, theToUpdateViewer);
7fd59977 2738}
2739
2740//=======================================================================
2741//function : PlaneSize
2195ab96 2742//purpose :
7fd59977 2743//=======================================================================
2195ab96 2744Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2745 Standard_Real& theY) const
7fd59977 2746{
2195ab96 2747 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2748 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2749 return (Abs (theX - theY) <= Precision::Confusion());
7fd59977 2750}
2751
7fd59977 2752//=======================================================================
2195ab96 2753//function : SetAutoActivateSelection
2754//purpose :
7fd59977 2755//=======================================================================
2195ab96 2756void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
7fd59977 2757{
2195ab96 2758 myIsAutoActivateSelMode = theIsAuto;
7fd59977 2759}
2760
2761//=======================================================================
2195ab96 2762//function : GetAutoActivateSelection
2763//purpose :
7fd59977 2764//=======================================================================
2765Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2766{
2767 return myIsAutoActivateSelMode;
2768}
59f45b7c 2769
2770//=======================================================================
2771//function : SetZLayer
2195ab96 2772//purpose :
59f45b7c 2773//=======================================================================
59f45b7c 2774void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2775 const Standard_Integer theLayerId)
2776{
2195ab96 2777 if (theIObj.IsNull())
59f45b7c 2778 return;
2779
a1954302 2780 theIObj->SetZLayer (theLayerId);
59f45b7c 2781}
2782
2783//=======================================================================
2784//function : GetZLayer
2195ab96 2785//purpose :
59f45b7c 2786//=======================================================================
59f45b7c 2787Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2788{
a1954302 2789 return !theIObj.IsNull()
2790 ? theIObj->ZLayer()
2791 : Graphic3d_ZLayerId_UNKNOWN;
59f45b7c 2792}
f751596e 2793
2794//=======================================================================
2795//function : RebuildSelectionStructs
2796//purpose : Rebuilds 1st level of BVH selection forcibly
2797//=======================================================================
2798void AIS_InteractiveContext::RebuildSelectionStructs()
2799{
2800 myMainSel->RebuildObjectsTree (Standard_True);
2801}
2802
2803//=======================================================================
2804//function : Disconnect
2805//purpose : Disconnects selectable object from an assembly and updates selection structures
2806//=======================================================================
2807void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2808 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2809{
2810 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2811 {
2812 const Handle(AIS_MultipleConnectedInteractive)& theObj =
2813 Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly);
2814 theObj->Disconnect (theObjToDisconnect);
2815 mgrSelector->Remove (theObjToDisconnect);
2816 }
2817 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect == NULL)
2818 {
2819 const Handle(AIS_ConnectedInteractive)& theObj =
2820 Handle(AIS_ConnectedInteractive)::DownCast (theAssembly);
2821 theObj->Disconnect();
2822 mgrSelector->Remove (theObj);
2823 }
2824 else
2825 return;
2826}