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