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