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