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