| 1 | // Created on: 1996-12-18 |
| 2 | // Created by: Robert COUBLANC |
| 3 | // Copyright (c) 1996-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 : 22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets |
| 18 | |
| 19 | #define BUC60577 //GG_101099 Enable to compute correctly |
| 20 | // transparency with more than one object in the view. |
| 21 | |
| 22 | #define GER61351 //GG_171199 Enable to set an object RGB color |
| 23 | // instead a restricted object NameOfColor. |
| 24 | // Add SetCurrentFacingModel() method |
| 25 | |
| 26 | #define IMP020200 //GG Add SetTransformation() method |
| 27 | |
| 28 | #define IMP140200 //GG Add HasPresentation() and Presentation() methods |
| 29 | // Add SetAspect() method. |
| 30 | |
| 31 | #define BUC60632 //GG 15/03/00 Add protection on SetDisplayMode() |
| 32 | // method, compute only authorized presentation. |
| 33 | |
| 34 | #define IMP220501 //GG CADPAK_V2 Update selection properly |
| 35 | |
| 36 | #define OCC708 //SAV unsetting transformation correctly |
| 37 | |
| 38 | #include <AIS_InteractiveObject.ixx> |
| 39 | |
| 40 | #include <Aspect_PolygonOffsetMode.hxx> |
| 41 | #include <Prs3d_ShadingAspect.hxx> |
| 42 | #include <Prs3d_LineAspect.hxx> |
| 43 | #include <Prs3d_PointAspect.hxx> |
| 44 | #include <Prs3d_TextAspect.hxx> |
| 45 | #include <Prs3d_Presentation.hxx> |
| 46 | #include <Prs3d_Root.hxx> |
| 47 | #include <PrsMgr_ModedPresentation.hxx> |
| 48 | #include <PrsMgr_PresentationManager3d.hxx> |
| 49 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
| 50 | #include <AIS_GraphicTool.hxx> |
| 51 | #include <Graphic3d_AspectFillArea3d.hxx> |
| 52 | #include <Graphic3d_AspectLine3d.hxx> |
| 53 | #include <Graphic3d_AspectMarker3d.hxx> |
| 54 | #include <Graphic3d_AspectText3d.hxx> |
| 55 | #include <Graphic3d_Group.hxx> |
| 56 | #include <Graphic3d_Structure.hxx> |
| 57 | |
| 58 | |
| 59 | //======================================================================= |
| 60 | //function : AIS_InteractiveObject |
| 61 | //purpose : |
| 62 | //======================================================================= |
| 63 | |
| 64 | AIS_InteractiveObject:: |
| 65 | AIS_InteractiveObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d): |
| 66 | SelectMgr_SelectableObject(aTypeOfPresentation3d), |
| 67 | myDrawer(new AIS_Drawer()), |
| 68 | myTransparency(0.), |
| 69 | myOwnColor(Quantity_NOC_WHITE), |
| 70 | myOwnMaterial(Graphic3d_NOM_DEFAULT), |
| 71 | myHilightMode(-1), |
| 72 | myOwnWidth(0.0), |
| 73 | myInfiniteState(Standard_False), |
| 74 | hasOwnColor(Standard_False), |
| 75 | hasOwnMaterial(Standard_False), |
| 76 | myCurrentFacingModel(Aspect_TOFM_BOTH_SIDE), |
| 77 | myRecomputeEveryPrs(Standard_True), |
| 78 | myCTXPtr(NULL), |
| 79 | mySelPriority(-1), |
| 80 | myDisplayMode (-1), |
| 81 | mySelectionMode(0), |
| 82 | mystate(0), |
| 83 | myHasTransformation(Standard_False) |
| 84 | { |
| 85 | Handle (AIS_InteractiveContext) Bid; |
| 86 | myCTXPtr = Bid.operator->(); |
| 87 | #ifdef GER61351 |
| 88 | SetCurrentFacingModel(); |
| 89 | #endif |
| 90 | } |
| 91 | |
| 92 | //======================================================================= |
| 93 | //function : Redisplay |
| 94 | //purpose : |
| 95 | //======================================================================= |
| 96 | |
| 97 | void AIS_InteractiveObject::Redisplay(const Standard_Boolean AllModes) |
| 98 | { |
| 99 | Update(AllModes); |
| 100 | UpdateSelection(); |
| 101 | } |
| 102 | |
| 103 | //======================================================================= |
| 104 | //function : Type |
| 105 | //purpose : |
| 106 | //======================================================================= |
| 107 | |
| 108 | AIS_KindOfInteractive AIS_InteractiveObject::Type() const |
| 109 | {return AIS_KOI_None;} |
| 110 | |
| 111 | //======================================================================= |
| 112 | //function : Signature |
| 113 | //purpose : |
| 114 | //======================================================================= |
| 115 | |
| 116 | Standard_Integer AIS_InteractiveObject::Signature() const |
| 117 | {return -1;} |
| 118 | |
| 119 | //======================================================================= |
| 120 | //function : RecomputeEveryPrs |
| 121 | //purpose : |
| 122 | //======================================================================= |
| 123 | |
| 124 | Standard_Boolean AIS_InteractiveObject::RecomputeEveryPrs() const |
| 125 | {return myRecomputeEveryPrs;} |
| 126 | |
| 127 | //======================================================================= |
| 128 | //function : |
| 129 | //purpose : |
| 130 | //======================================================================= |
| 131 | Standard_Boolean AIS_InteractiveObject::HasInteractiveContext() const |
| 132 | { |
| 133 | Handle (AIS_InteractiveContext) aNull; |
| 134 | return (myCTXPtr != aNull.operator->()); |
| 135 | } |
| 136 | |
| 137 | //======================================================================= |
| 138 | //function : |
| 139 | //purpose : |
| 140 | //======================================================================= |
| 141 | Handle(AIS_InteractiveContext) AIS_InteractiveObject::GetContext() const |
| 142 | { |
| 143 | return myCTXPtr; |
| 144 | } |
| 145 | |
| 146 | //======================================================================= |
| 147 | //function : |
| 148 | //purpose : |
| 149 | //======================================================================= |
| 150 | void AIS_InteractiveObject::SetContext(const Handle(AIS_InteractiveContext)& aCtx) |
| 151 | { |
| 152 | myCTXPtr = aCtx.operator->(); |
| 153 | if( aCtx.IsNull()) |
| 154 | return; |
| 155 | if (myDrawer.IsNull()) { |
| 156 | myDrawer = new AIS_Drawer; |
| 157 | #ifdef DEB |
| 158 | cout << "AIS_InteractiveObject::SetContext DRAWER NUL!" << endl; |
| 159 | #endif |
| 160 | } |
| 161 | myDrawer->Link(aCtx->DefaultDrawer()); |
| 162 | } |
| 163 | |
| 164 | //======================================================================= |
| 165 | //function : |
| 166 | //purpose : |
| 167 | //======================================================================= |
| 168 | Standard_Boolean AIS_InteractiveObject::HasOwner() const |
| 169 | { |
| 170 | return (!myOwner.IsNull()); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | |
| 175 | //======================================================================= |
| 176 | //function : |
| 177 | //purpose : |
| 178 | //======================================================================= |
| 179 | void AIS_InteractiveObject::ClearOwner() |
| 180 | { |
| 181 | myOwner.Nullify(); |
| 182 | } |
| 183 | |
| 184 | //======================================================================= |
| 185 | //function : |
| 186 | //purpose : |
| 187 | //======================================================================= |
| 188 | Standard_Boolean AIS_InteractiveObject::HasUsers() const |
| 189 | { |
| 190 | return (!myUsers.IsEmpty()); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | //======================================================================= |
| 195 | //function : |
| 196 | //purpose : |
| 197 | //======================================================================= |
| 198 | void AIS_InteractiveObject::AddUser(const Handle(Standard_Transient)& aUser) |
| 199 | { |
| 200 | myUsers.Append(aUser); |
| 201 | } |
| 202 | |
| 203 | //======================================================================= |
| 204 | //function : |
| 205 | //purpose : |
| 206 | //======================================================================= |
| 207 | void AIS_InteractiveObject::ClearUsers() |
| 208 | { |
| 209 | myUsers.Clear(); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | //======================================================================= |
| 214 | //function : |
| 215 | //purpose : |
| 216 | //======================================================================= |
| 217 | void AIS_InteractiveObject::SetDisplayMode(const Standard_Integer aMode) |
| 218 | { |
| 219 | #ifdef BUC60632 |
| 220 | if( AcceptDisplayMode(aMode) ) |
| 221 | #endif |
| 222 | myDisplayMode = aMode; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | //======================================================================= |
| 227 | //function : |
| 228 | //purpose : |
| 229 | //======================================================================= |
| 230 | void AIS_InteractiveObject::SetSelectionMode(const Standard_Integer aMode) |
| 231 | { |
| 232 | mySelectionMode = aMode; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | |
| 237 | //======================================================================= |
| 238 | //function : |
| 239 | //purpose : |
| 240 | //======================================================================= |
| 241 | #ifdef GER61351 |
| 242 | void AIS_InteractiveObject::SetCurrentFacingModel(const Aspect_TypeOfFacingModel aModel) { |
| 243 | myCurrentFacingModel = aModel; |
| 244 | } |
| 245 | |
| 246 | //======================================================================= |
| 247 | //function : CurrentFacingModel |
| 248 | //purpose : |
| 249 | //======================================================================= |
| 250 | |
| 251 | Aspect_TypeOfFacingModel AIS_InteractiveObject::CurrentFacingModel() const { |
| 252 | return myCurrentFacingModel; |
| 253 | } |
| 254 | #endif |
| 255 | |
| 256 | //======================================================================= |
| 257 | //function : SetColor |
| 258 | //purpose : |
| 259 | //======================================================================= |
| 260 | |
| 261 | void AIS_InteractiveObject::SetColor(const Quantity_NameOfColor aColor) |
| 262 | #ifdef GER61351 |
| 263 | { |
| 264 | SetColor(Quantity_Color(aColor)); |
| 265 | } |
| 266 | |
| 267 | //======================================================================= |
| 268 | //function : SetColor |
| 269 | //purpose : |
| 270 | //======================================================================= |
| 271 | |
| 272 | void AIS_InteractiveObject::SetColor(const Quantity_Color &aColor) |
| 273 | #endif |
| 274 | { |
| 275 | myOwnColor = aColor; |
| 276 | hasOwnColor = Standard_True; |
| 277 | } |
| 278 | |
| 279 | //======================================================================= |
| 280 | //function : UnsetColor |
| 281 | //purpose : |
| 282 | //======================================================================= |
| 283 | void AIS_InteractiveObject::UnsetColor() |
| 284 | { |
| 285 | hasOwnColor = Standard_False; |
| 286 | } |
| 287 | |
| 288 | //======================================================================= |
| 289 | //function : |
| 290 | //purpose : |
| 291 | //======================================================================= |
| 292 | void AIS_InteractiveObject::SetWidth(const Standard_Real aValue) |
| 293 | { |
| 294 | myOwnWidth = aValue; |
| 295 | } |
| 296 | |
| 297 | //======================================================================= |
| 298 | //function : |
| 299 | //purpose : |
| 300 | //======================================================================= |
| 301 | void AIS_InteractiveObject::UnsetWidth() |
| 302 | { |
| 303 | myOwnWidth = 0.; |
| 304 | } |
| 305 | |
| 306 | |
| 307 | //======================================================================= |
| 308 | //function : |
| 309 | //purpose : |
| 310 | //======================================================================= |
| 311 | //POP pour K4L |
| 312 | void AIS_InteractiveObject::SetMaterial(const Graphic3d_NameOfMaterial aName) |
| 313 | //void AIS_InteractiveObject::SetMaterial(const Graphic3d_NameOfPhysicalMaterial aName) |
| 314 | { |
| 315 | if( HasColor() || IsTransparent() || HasMaterial() ) |
| 316 | { |
| 317 | myDrawer->ShadingAspect()->SetMaterial(aName); |
| 318 | } |
| 319 | else |
| 320 | { |
| 321 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
| 322 | |
| 323 | myDrawer->ShadingAspect()->SetMaterial(aName); |
| 324 | #ifndef BUC60577 //??? |
| 325 | myDrawer->ShadingAspect()->SetColor(AIS_GraphicTool::GetInteriorColor(myDrawer->Link())); |
| 326 | #endif |
| 327 | } |
| 328 | myOwnMaterial = aName; |
| 329 | hasOwnMaterial = Standard_True; |
| 330 | } |
| 331 | //======================================================================= |
| 332 | //function : SetMaterial |
| 333 | //purpose : |
| 334 | //======================================================================= |
| 335 | |
| 336 | void AIS_InteractiveObject::SetMaterial(const Graphic3d_MaterialAspect& aMat) |
| 337 | { |
| 338 | #ifdef BUC60577 |
| 339 | if( HasColor() || IsTransparent() || HasMaterial() ) |
| 340 | #else |
| 341 | if(hasOwnColor ||(myTransparency==0.0) || hasOwnMaterial ) |
| 342 | #endif |
| 343 | { |
| 344 | myDrawer->ShadingAspect()->SetMaterial(aMat); |
| 345 | } |
| 346 | else |
| 347 | { |
| 348 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
| 349 | myDrawer->ShadingAspect()->SetMaterial(aMat); |
| 350 | } |
| 351 | hasOwnMaterial = Standard_True; |
| 352 | |
| 353 | } |
| 354 | //======================================================================= |
| 355 | //function : |
| 356 | //purpose : |
| 357 | //======================================================================= |
| 358 | void AIS_InteractiveObject::UnsetMaterial() |
| 359 | { |
| 360 | #ifdef BUC60577 |
| 361 | if( !HasMaterial() ) return; |
| 362 | if( HasColor() || IsTransparent()) { |
| 363 | myDrawer->ShadingAspect()->SetMaterial( |
| 364 | AIS_GraphicTool::GetMaterial(myDrawer->Link())); |
| 365 | if( HasColor() ) SetColor(myOwnColor); |
| 366 | if( IsTransparent() ) SetTransparency(myTransparency); |
| 367 | } |
| 368 | #else |
| 369 | if(!hasOwnMaterial) return; |
| 370 | if(hasOwnColor ||(myTransparency==0.0)) |
| 371 | { |
| 372 | myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link())); |
| 373 | } |
| 374 | #endif |
| 375 | else{ |
| 376 | Handle(Prs3d_ShadingAspect) SA; |
| 377 | myDrawer->SetShadingAspect(SA); |
| 378 | } |
| 379 | hasOwnMaterial = Standard_False; |
| 380 | } |
| 381 | |
| 382 | //======================================================================= |
| 383 | //function : SetTransparency |
| 384 | //purpose : |
| 385 | //======================================================================= |
| 386 | void AIS_InteractiveObject::SetTransparency(const Standard_Real aValue) |
| 387 | { |
| 388 | |
| 389 | #ifdef BUC60577 // Back & Front material can be different ! |
| 390 | |
| 391 | if(!HasColor() && !IsTransparent() && !HasMaterial() ) { |
| 392 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
| 393 | if(!myDrawer->Link().IsNull()) |
| 394 | myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link())); |
| 395 | } |
| 396 | Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
| 397 | Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial(); |
| 398 | FMat.SetTransparency(aValue); BMat.SetTransparency(aValue); |
| 399 | myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat); |
| 400 | myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat); |
| 401 | #else |
| 402 | if(aValue<0.0 || aValue>1.0) return; |
| 403 | |
| 404 | if(aValue<=0.05) |
| 405 | { |
| 406 | UnsetTransparency(); |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | |
| 411 | if(hasOwnColor || hasOwnMaterial || myTransparency> 0.0) |
| 412 | { |
| 413 | Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
| 414 | Mat.SetTransparency(aValue); |
| 415 | myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat); |
| 416 | myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat); |
| 417 | } |
| 418 | else |
| 419 | { |
| 420 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
| 421 | if(!myDrawer->Link().IsNull()) |
| 422 | myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link())); |
| 423 | Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
| 424 | Mat.SetTransparency(aValue); |
| 425 | myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat); |
| 426 | myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat); |
| 427 | } |
| 428 | #endif |
| 429 | myTransparency = aValue; |
| 430 | } |
| 431 | |
| 432 | //======================================================================= |
| 433 | //function : UnsetTransparency |
| 434 | //purpose : |
| 435 | //======================================================================= |
| 436 | void AIS_InteractiveObject::UnsetTransparency() |
| 437 | { |
| 438 | #ifdef BUC60577 // Back & Front material can be different ! |
| 439 | if(HasColor() || HasMaterial() ) |
| 440 | { |
| 441 | Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
| 442 | Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial(); |
| 443 | FMat.SetTransparency(0.); BMat.SetTransparency(0.); |
| 444 | myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat); |
| 445 | myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat); |
| 446 | } |
| 447 | #else |
| 448 | if(hasOwnColor || hasOwnMaterial ) |
| 449 | { |
| 450 | Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
| 451 | Mat.SetTransparency(0.0); |
| 452 | // myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat); |
| 453 | // myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat); |
| 454 | myDrawer->ShadingAspect()->SetMaterial(Mat); |
| 455 | } |
| 456 | #endif |
| 457 | else{ |
| 458 | Handle (Prs3d_ShadingAspect) SA; |
| 459 | myDrawer->SetShadingAspect(SA); |
| 460 | } |
| 461 | myTransparency =0.0; |
| 462 | } |
| 463 | //======================================================================= |
| 464 | //function : Transparency |
| 465 | //purpose : |
| 466 | //======================================================================= |
| 467 | Standard_Real AIS_InteractiveObject::Transparency() const |
| 468 | { |
| 469 | return (myTransparency<=0.05 ? 0 : myTransparency); |
| 470 | // Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
| 471 | // return Mat.Transparency(); |
| 472 | } |
| 473 | |
| 474 | //======================================================================= |
| 475 | //function : SetAttributes |
| 476 | //purpose : |
| 477 | //======================================================================= |
| 478 | |
| 479 | void AIS_InteractiveObject::SetAttributes(const Handle(AIS_Drawer)& aDrawer) |
| 480 | {myDrawer = aDrawer;} |
| 481 | |
| 482 | |
| 483 | //======================================================================= |
| 484 | //function : UnsetAttributes |
| 485 | //purpose : |
| 486 | //======================================================================= |
| 487 | void AIS_InteractiveObject::UnsetAttributes() |
| 488 | { |
| 489 | Handle(AIS_Drawer) dr = new AIS_Drawer(); |
| 490 | if(myDrawer->HasLink()) |
| 491 | dr->Link(myDrawer->Link()); |
| 492 | myDrawer = dr; |
| 493 | hasOwnColor = Standard_False; |
| 494 | hasOwnMaterial = Standard_False; |
| 495 | myOwnWidth = 0.0; |
| 496 | myTransparency = 0.0; |
| 497 | } |
| 498 | |
| 499 | //======================================================================= |
| 500 | //function : |
| 501 | //purpose : |
| 502 | //======================================================================= |
| 503 | void AIS_InteractiveObject::MustRecomputePrs(const Standard_Integer ) const |
| 504 | {} |
| 505 | |
| 506 | //======================================================================= |
| 507 | //function : |
| 508 | //purpose : |
| 509 | //======================================================================= |
| 510 | const TColStd_ListOfInteger& AIS_InteractiveObject::ListOfRecomputeModes() const |
| 511 | {return myToRecomputeModes;} |
| 512 | |
| 513 | //======================================================================= |
| 514 | //function : |
| 515 | //purpose : |
| 516 | //======================================================================= |
| 517 | void AIS_InteractiveObject::SetRecomputeOk() |
| 518 | {myToRecomputeModes.Clear();} |
| 519 | |
| 520 | |
| 521 | //======================================================================= |
| 522 | //function : AcceptDisplayMode |
| 523 | //purpose : |
| 524 | //======================================================================= |
| 525 | |
| 526 | Standard_Boolean AIS_InteractiveObject::AcceptDisplayMode(const Standard_Integer ) const |
| 527 | {return Standard_True;} |
| 528 | |
| 529 | //======================================================================= |
| 530 | //function : DefaultDisplayMode |
| 531 | //purpose : |
| 532 | //======================================================================= |
| 533 | |
| 534 | Standard_Integer AIS_InteractiveObject::DefaultDisplayMode() const |
| 535 | {return 0;} |
| 536 | |
| 537 | |
| 538 | //======================================================================= |
| 539 | //function : SetInfiniteState |
| 540 | //purpose : |
| 541 | //======================================================================= |
| 542 | void AIS_InteractiveObject::SetInfiniteState(const Standard_Boolean aFlag) |
| 543 | { |
| 544 | myInfiniteState = aFlag; |
| 545 | Handle(Prs3d_Presentation) P; |
| 546 | |
| 547 | for(Standard_Integer i =1; i<=myPresentations.Length();i++){ |
| 548 | P = Handle(Prs3d_Presentation)::DownCast(myPresentations(i).Presentation()); |
| 549 | if(!P.IsNull()) |
| 550 | P->SetInfiniteState(myInfiniteState);} |
| 551 | } |
| 552 | |
| 553 | #ifdef IMP020200 |
| 554 | //======================================================================= |
| 555 | //function : SetTransformation |
| 556 | //purpose : |
| 557 | //======================================================================= |
| 558 | void AIS_InteractiveObject::SetTransformation(const Handle(Geom_Transformation)& aTrsf, const Standard_Boolean postConcatenate, const Standard_Boolean updateSelection) { |
| 559 | |
| 560 | if(!GetContext().IsNull()){ |
| 561 | const PrsMgr_Presentations& prs = Presentations(); |
| 562 | Handle(Prs3d_Presentation) P; |
| 563 | Standard_Integer mode; |
| 564 | myHasTransformation = Standard_True; |
| 565 | for( Standard_Integer i=1 ; i<=prs.Length() ; i++ ) { |
| 566 | mode = prs(i).Mode(); |
| 567 | P = GetContext()->MainPrsMgr()->CastPresentation(this,mode)->Presentation(); |
| 568 | if( postConcatenate ) P->Multiply(aTrsf); |
| 569 | else P->Transform(aTrsf); |
| 570 | if( updateSelection ) { |
| 571 | #ifdef IMP220501 |
| 572 | myCTXPtr->ClearSelected(Standard_True); |
| 573 | myCTXPtr->RecomputeSelectionOnly(this); |
| 574 | #else |
| 575 | if( HasSelection(mode) ) { |
| 576 | UpdateSelection(mode); |
| 577 | } |
| 578 | #endif |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | //======================================================================= |
| 585 | //function : SetTransformation |
| 586 | //purpose : |
| 587 | //======================================================================= |
| 588 | void AIS_InteractiveObject::UnsetTransformation() { |
| 589 | #ifdef OCC708 |
| 590 | static Handle(Geom_Transformation) trsf = new Geom_Transformation( gp_Trsf() ); |
| 591 | #else |
| 592 | Handle(Geom_Transformation) trsf; |
| 593 | #endif |
| 594 | |
| 595 | SetTransformation(trsf); // Set identity transformation |
| 596 | myHasTransformation = Standard_False; |
| 597 | } |
| 598 | |
| 599 | //======================================================================= |
| 600 | //function : Transformation |
| 601 | //purpose : |
| 602 | //======================================================================= |
| 603 | Handle(Geom_Transformation) AIS_InteractiveObject::Transformation() { |
| 604 | Handle(Geom_Transformation) trsf; |
| 605 | |
| 606 | if(!GetContext().IsNull() ) { |
| 607 | const PrsMgr_Presentations& prs = Presentations(); |
| 608 | if( prs.Length() > 0 ) { |
| 609 | Handle(Prs3d_Presentation) P = |
| 610 | GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation(); |
| 611 | trsf = P->Transformation(); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | return trsf; |
| 616 | } |
| 617 | |
| 618 | //======================================================================= |
| 619 | //function : HasTransformation |
| 620 | //purpose : |
| 621 | //======================================================================= |
| 622 | Standard_Boolean AIS_InteractiveObject::HasTransformation() const { |
| 623 | |
| 624 | return myHasTransformation; |
| 625 | } |
| 626 | #endif |
| 627 | |
| 628 | #ifdef IMP140200 |
| 629 | //======================================================================= |
| 630 | //function : HasPresentation |
| 631 | //purpose : |
| 632 | //======================================================================= |
| 633 | Standard_Boolean AIS_InteractiveObject::HasPresentation() const { |
| 634 | |
| 635 | if( !GetContext().IsNull() && |
| 636 | GetContext()->MainPrsMgr()->HasPresentation(this,myDisplayMode) ) { |
| 637 | return Standard_True; |
| 638 | } |
| 639 | |
| 640 | return Standard_False; |
| 641 | } |
| 642 | |
| 643 | //======================================================================= |
| 644 | //function : Presentation |
| 645 | //purpose : |
| 646 | //======================================================================= |
| 647 | Handle(Prs3d_Presentation) AIS_InteractiveObject::Presentation() const { |
| 648 | Handle(Prs3d_Presentation) prs; |
| 649 | |
| 650 | if( HasPresentation() ) { |
| 651 | prs = GetContext()->MainPrsMgr()-> |
| 652 | CastPresentation(this,myDisplayMode)->Presentation(); |
| 653 | } |
| 654 | |
| 655 | return prs; |
| 656 | } |
| 657 | |
| 658 | //======================================================================= |
| 659 | //function : SetAspect |
| 660 | //purpose : |
| 661 | //======================================================================= |
| 662 | void AIS_InteractiveObject::SetAspect(const Handle(Prs3d_BasicAspect)& anAspect, |
| 663 | const Standard_Boolean globalChange) { |
| 664 | |
| 665 | if( HasPresentation() ) { |
| 666 | Handle(Prs3d_Presentation) prs = Presentation(); |
| 667 | { Handle(Prs3d_ShadingAspect) aspect = |
| 668 | Handle(Prs3d_ShadingAspect)::DownCast(anAspect); |
| 669 | if( !aspect.IsNull() ) { |
| 670 | if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect()); |
| 671 | Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect()); |
| 672 | return; |
| 673 | } |
| 674 | } |
| 675 | { Handle(Prs3d_LineAspect) aspect = |
| 676 | Handle(Prs3d_LineAspect)::DownCast(anAspect); |
| 677 | if( !aspect.IsNull() ) { |
| 678 | if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect()); |
| 679 | Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect()); |
| 680 | return; |
| 681 | } |
| 682 | } |
| 683 | { Handle(Prs3d_PointAspect) aspect = |
| 684 | Handle(Prs3d_PointAspect)::DownCast(anAspect); |
| 685 | if( !aspect.IsNull() ) { |
| 686 | if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect()); |
| 687 | Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect()); |
| 688 | return; |
| 689 | } |
| 690 | } |
| 691 | { Handle(Prs3d_TextAspect) aspect = |
| 692 | Handle(Prs3d_TextAspect)::DownCast(anAspect); |
| 693 | if( !aspect.IsNull() ) { |
| 694 | if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect()); |
| 695 | Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect()); |
| 696 | return; |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | #endif |
| 702 | |
| 703 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 704 | |
| 705 | //======================================================================= |
| 706 | //function : SetPolygonOffsets |
| 707 | //purpose : |
| 708 | //======================================================================= |
| 709 | void AIS_InteractiveObject::SetPolygonOffsets(const Standard_Integer aMode, |
| 710 | const Standard_ShortReal aFactor, |
| 711 | const Standard_ShortReal aUnits) |
| 712 | { |
| 713 | if ( !HasPolygonOffsets() ) |
| 714 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
| 715 | |
| 716 | myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets( aMode, aFactor, aUnits ); |
| 717 | |
| 718 | // Modify existing presentations |
| 719 | Handle(Graphic3d_Structure) aStruct; |
| 720 | for( Standard_Integer i = 1, n = myPresentations.Length(); i <= n; i++ ) { |
| 721 | Handle(PrsMgr_Presentation3d) aPrs3d = |
| 722 | Handle(PrsMgr_Presentation3d)::DownCast( myPresentations(i).Presentation() ); |
| 723 | if ( !aPrs3d.IsNull() ) { |
| 724 | aStruct = Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() ); |
| 725 | if( !aStruct.IsNull() ) { |
| 726 | aStruct->SetPrimitivesAspect( myDrawer->ShadingAspect()->Aspect() ); |
| 727 | // Workaround for issue 23115: Need to update also groups, because their |
| 728 | // face aspect ALWAYS overrides the structure's. |
| 729 | const Graphic3d_SequenceOfGroup& aGroups = aStruct->Groups(); |
| 730 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next()) |
| 731 | { |
| 732 | Handle(Graphic3d_Group)& aGrp = aGroupIter.ChangeValue(); |
| 733 | if (aGrp.IsNull() |
| 734 | || !aGrp->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) |
| 735 | { |
| 736 | continue; |
| 737 | } |
| 738 | |
| 739 | Handle(Graphic3d_AspectFillArea3d) aFaceAsp = new Graphic3d_AspectFillArea3d(); |
| 740 | Handle(Graphic3d_AspectLine3d) aLineAsp = new Graphic3d_AspectLine3d(); |
| 741 | Handle(Graphic3d_AspectMarker3d) aPntAsp = new Graphic3d_AspectMarker3d(); |
| 742 | Handle(Graphic3d_AspectText3d) aTextAsp = new Graphic3d_AspectText3d(); |
| 743 | // TODO: Add methods for retrieving individual aspects from Graphic3d_Group |
| 744 | aGrp->GroupPrimitivesAspect(aLineAsp, aTextAsp, aPntAsp, aFaceAsp); |
| 745 | aFaceAsp->SetPolygonOffsets(aMode, aFactor, aUnits); |
| 746 | aGrp->SetGroupPrimitivesAspect(aFaceAsp); |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | |
| 754 | //======================================================================= |
| 755 | //function : HasPolygonOffsets |
| 756 | //purpose : |
| 757 | //======================================================================= |
| 758 | Standard_Boolean AIS_InteractiveObject::HasPolygonOffsets() const |
| 759 | { |
| 760 | return !( myDrawer->ShadingAspect().IsNull() || |
| 761 | ( !myDrawer->Link().IsNull() && |
| 762 | myDrawer->ShadingAspect() == myDrawer->Link()->ShadingAspect() ) ); |
| 763 | } |
| 764 | |
| 765 | //======================================================================= |
| 766 | //function : PolygonOffsets |
| 767 | //purpose : |
| 768 | //======================================================================= |
| 769 | void AIS_InteractiveObject::PolygonOffsets(Standard_Integer& aMode, |
| 770 | Standard_ShortReal& aFactor, |
| 771 | Standard_ShortReal& aUnits) const |
| 772 | { |
| 773 | if( HasPolygonOffsets() ) |
| 774 | myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode, aFactor, aUnits ); |
| 775 | } |
| 776 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |