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