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