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