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