| 1 | // Created on: 1995-02-20 |
| 2 | // Created by: Mister rmi |
| 3 | // Copyright (c) 1995-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 | |
| 18 | #include <Aspect_TypeOfMarker.hxx> |
| 19 | #include <Bnd_Box.hxx> |
| 20 | #include <gp_Pnt.hxx> |
| 21 | #include <Graphic3d_AspectLine3d.hxx> |
| 22 | #include <Graphic3d_AspectMarker3d.hxx> |
| 23 | #include <Prs3d_Drawer.hxx> |
| 24 | #include <Prs3d_LineAspect.hxx> |
| 25 | #include <Prs3d_PlaneAspect.hxx> |
| 26 | #include <Prs3d_PointAspect.hxx> |
| 27 | #include <Prs3d_Presentation.hxx> |
| 28 | #include <PrsMgr_PresentableObjectPointer.hxx> |
| 29 | #include <PrsMgr_PresentationManager3d.hxx> |
| 30 | #include <Select3D_SensitiveEntity.hxx> |
| 31 | #include <SelectBasics_EntityOwner.hxx> |
| 32 | #include <SelectMgr_EntityOwner.hxx> |
| 33 | #include <SelectMgr_IndexedMapOfOwner.hxx> |
| 34 | #include <SelectMgr_SelectableObject.hxx> |
| 35 | #include <SelectMgr_Selection.hxx> |
| 36 | #include <SelectMgr_SelectionManager.hxx> |
| 37 | #include <Standard_NoSuchObject.hxx> |
| 38 | #include <Standard_NotImplemented.hxx> |
| 39 | #include <Standard_Type.hxx> |
| 40 | #include <TopLoc_Location.hxx> |
| 41 | |
| 42 | IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_SelectableObject,PrsMgr_PresentableObject) |
| 43 | |
| 44 | static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq, |
| 45 | const Handle (SelectMgr_Selection)& theSel) |
| 46 | { |
| 47 | Standard_Integer ifound=0; |
| 48 | for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++) |
| 49 | {if(theSel == seq.Value(i)) ifound=i;} |
| 50 | return ifound; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | |
| 55 | //================================================== |
| 56 | // Function: |
| 57 | // Purpose : |
| 58 | //================================================== |
| 59 | |
| 60 | SelectMgr_SelectableObject::SelectMgr_SelectableObject (const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d) |
| 61 | : PrsMgr_PresentableObject (aTypeOfPresentation3d), |
| 62 | myDrawer (new Prs3d_Drawer()), |
| 63 | myHilightDrawer (new Prs3d_Drawer()), |
| 64 | myAssemblyOwner (NULL), |
| 65 | myAutoHilight (Standard_True), |
| 66 | myGlobalSelMode (0) |
| 67 | { |
| 68 | InitDefaultHilightAttributes (myHilightDrawer); |
| 69 | myHilightDrawer->Link (myDrawer); |
| 70 | } |
| 71 | |
| 72 | //================================================== |
| 73 | // Function: Destructor |
| 74 | // Purpose : Clears all selections of the object |
| 75 | //================================================== |
| 76 | SelectMgr_SelectableObject::~SelectMgr_SelectableObject() |
| 77 | { |
| 78 | for (Standard_Integer aSelIdx = 1; aSelIdx <= myselections.Length(); ++aSelIdx) |
| 79 | { |
| 80 | myselections.Value (aSelIdx)->Clear(); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | //================================================== |
| 85 | // Function: HasSelection |
| 86 | // Purpose : |
| 87 | //================================================== |
| 88 | Standard_Boolean SelectMgr_SelectableObject::HasSelection (const Standard_Integer theMode) const |
| 89 | { |
| 90 | for (Standard_Integer aSelIdx = 1; aSelIdx <= myselections.Length(); ++aSelIdx) |
| 91 | { |
| 92 | if (((myselections.Value (aSelIdx))->Mode()) == theMode) |
| 93 | return Standard_True; |
| 94 | } |
| 95 | return Standard_False; |
| 96 | } |
| 97 | |
| 98 | //================================================== |
| 99 | // Function: RecomputePrimitives |
| 100 | // Purpose : IMPORTANT: Do not use this method to update |
| 101 | // selection primitives except implementing custom |
| 102 | // selection manager! This method does not take |
| 103 | // into account necessary BVH updates, but may |
| 104 | // invalidate the pointers it refers to. |
| 105 | // TO UPDATE SELECTION properly from outside classes, |
| 106 | // use method UpdateSelection. |
| 107 | //================================================== |
| 108 | void SelectMgr_SelectableObject::RecomputePrimitives() |
| 109 | { |
| 110 | for (Standard_Integer aSelIdx = 1; aSelIdx <= myselections.Length(); aSelIdx++) |
| 111 | { |
| 112 | RecomputePrimitives (myselections.ChangeValue (aSelIdx)->Mode()); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | //================================================== |
| 117 | // Function: RecomputePrimitives |
| 118 | // Purpose : IMPORTANT: Do not use this method to update |
| 119 | // selection primitives except implementing custom |
| 120 | // selection manager! This method does not take |
| 121 | // into account necessary BVH updates, but may |
| 122 | // invalidate the pointers it refers to. |
| 123 | // TO UPDATE SELECTION properly from outside classes, |
| 124 | // use method UpdateSelection. |
| 125 | //================================================== |
| 126 | void SelectMgr_SelectableObject::RecomputePrimitives (const Standard_Integer theMode) |
| 127 | { |
| 128 | Handle(PrsMgr_PresentableObject) aPrsParent (Parent()); |
| 129 | Handle(SelectMgr_SelectableObject) aSelParent = Handle(SelectMgr_SelectableObject)::DownCast (aPrsParent); |
| 130 | |
| 131 | for (Standard_Integer aSelIdx =1; aSelIdx <= myselections.Length(); aSelIdx++ ) |
| 132 | { |
| 133 | if (myselections.Value (aSelIdx)->Mode() == theMode) |
| 134 | { |
| 135 | myselections (aSelIdx)->Clear(); |
| 136 | ComputeSelection (myselections (aSelIdx), theMode); |
| 137 | myselections (aSelIdx)->UpdateStatus (SelectMgr_TOU_Partial); |
| 138 | myselections (aSelIdx)->UpdateBVHStatus (SelectMgr_TBU_Renew); |
| 139 | if (theMode == 0 && ! aSelParent.IsNull() && ! aSelParent->GetAssemblyOwner().IsNull()) |
| 140 | { |
| 141 | SetAssemblyOwner (aSelParent->GetAssemblyOwner(), theMode); |
| 142 | } |
| 143 | return; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode); |
| 148 | ComputeSelection (aNewSel, theMode); |
| 149 | |
| 150 | if (theMode == 0 && ! aSelParent.IsNull() && ! aSelParent->GetAssemblyOwner().IsNull()) |
| 151 | { |
| 152 | SetAssemblyOwner (aSelParent->GetAssemblyOwner(), theMode); |
| 153 | } |
| 154 | |
| 155 | aNewSel->UpdateStatus (SelectMgr_TOU_Partial); |
| 156 | aNewSel->UpdateBVHStatus (SelectMgr_TBU_Add); |
| 157 | |
| 158 | myselections.Append (aNewSel); |
| 159 | } |
| 160 | |
| 161 | //================================================== |
| 162 | // Function: ClearSelections |
| 163 | // Purpose : |
| 164 | //================================================== |
| 165 | void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update) |
| 166 | { |
| 167 | for (Standard_Integer i =1; i<= myselections.Length(); i++ ) { |
| 168 | myselections.Value(i)->Clear(); |
| 169 | myselections.Value (i)->UpdateBVHStatus (SelectMgr_TBU_Remove); |
| 170 | if(update) |
| 171 | { |
| 172 | myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | |
| 178 | //================================================== |
| 179 | // Function: Selection |
| 180 | // Purpose : |
| 181 | //================================================== |
| 182 | |
| 183 | const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject |
| 184 | ::Selection(const Standard_Integer aMode) const |
| 185 | { |
| 186 | Standard_Boolean Found = Standard_False; |
| 187 | Standard_Integer Rank=0; |
| 188 | for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++) |
| 189 | { |
| 190 | if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True; |
| 191 | Rank=i;}} |
| 192 | return myselections.Value(Rank); |
| 193 | } |
| 194 | |
| 195 | |
| 196 | //================================================== |
| 197 | // Function: AddSelection |
| 198 | // Purpose : |
| 199 | //================================================== |
| 200 | |
| 201 | void SelectMgr_SelectableObject |
| 202 | ::AddSelection(const Handle(SelectMgr_Selection)& aSel, |
| 203 | const Standard_Integer aMode) |
| 204 | { |
| 205 | Standard_Boolean isReplaced = Standard_False; |
| 206 | if(aSel->IsEmpty()) |
| 207 | { |
| 208 | ComputeSelection(aSel, aMode); |
| 209 | aSel->UpdateStatus(SelectMgr_TOU_Partial); |
| 210 | aSel->UpdateBVHStatus (SelectMgr_TBU_Add); |
| 211 | } |
| 212 | if (HasSelection(aMode)) |
| 213 | { |
| 214 | const Handle(SelectMgr_Selection)& temp= Selection(aMode); |
| 215 | Standard_Integer I = Search(myselections,temp); |
| 216 | if(I!=0) |
| 217 | { |
| 218 | myselections.Remove(I); |
| 219 | isReplaced = Standard_True; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | myselections.Append(aSel); |
| 224 | if (isReplaced) |
| 225 | { |
| 226 | myselections.Last()->UpdateBVHStatus (SelectMgr_TBU_Renew); |
| 227 | } |
| 228 | |
| 229 | if (aMode == 0) |
| 230 | { |
| 231 | Handle(PrsMgr_PresentableObject) aPrsParent (Parent()); |
| 232 | Handle(SelectMgr_SelectableObject) aSelParent = Handle(SelectMgr_SelectableObject)::DownCast (aPrsParent); |
| 233 | if (! aSelParent.IsNull() && ! aSelParent->GetAssemblyOwner().IsNull()) |
| 234 | { |
| 235 | SetAssemblyOwner (aSelParent->GetAssemblyOwner(), aMode); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | |
| 241 | |
| 242 | //======================================================================= |
| 243 | //function : ReSetTransformation |
| 244 | //purpose : |
| 245 | //======================================================================= |
| 246 | void SelectMgr_SelectableObject::ResetTransformation() |
| 247 | { |
| 248 | for (Init(); More(); Next()) |
| 249 | { |
| 250 | const Handle(SelectMgr_Selection) & aSel = CurrentSelection(); |
| 251 | for (aSel->Init(); aSel->More(); aSel->Next()) |
| 252 | { |
| 253 | aSel->UpdateStatus(SelectMgr_TOU_Partial); |
| 254 | aSel->UpdateBVHStatus (SelectMgr_TBU_None); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | PrsMgr_PresentableObject::ResetTransformation(); |
| 259 | } |
| 260 | |
| 261 | //======================================================================= |
| 262 | //function : UpdateTransformation |
| 263 | //purpose : |
| 264 | //======================================================================= |
| 265 | void SelectMgr_SelectableObject::UpdateTransformation() |
| 266 | { |
| 267 | for (Init(); More(); Next()) |
| 268 | { |
| 269 | CurrentSelection()->UpdateStatus (SelectMgr_TOU_Partial); |
| 270 | } |
| 271 | |
| 272 | PrsMgr_PresentableObject::UpdateTransformation(); |
| 273 | } |
| 274 | |
| 275 | //======================================================================= |
| 276 | //function : UpdateTransformation |
| 277 | //purpose : |
| 278 | //======================================================================= |
| 279 | void SelectMgr_SelectableObject::UpdateTransformations(const Handle(SelectMgr_Selection)& Sel) |
| 280 | { |
| 281 | TopLoc_Location aSelfLocation (Transformation()); |
| 282 | Handle(Select3D_SensitiveEntity) SE; |
| 283 | if(aSelfLocation.IsIdentity()) return; |
| 284 | for(Sel->Init();Sel->More();Sel->Next()){ |
| 285 | SE = Handle(Select3D_SensitiveEntity)::DownCast (Sel->Sensitive()->BaseSensitive()); |
| 286 | if(!SE.IsNull()){ |
| 287 | const Handle(SelectBasics_EntityOwner)& aEOwner = SE->OwnerId(); |
| 288 | Handle(SelectMgr_EntityOwner) aMgrEO = |
| 289 | Handle(SelectMgr_EntityOwner)::DownCast (aEOwner); |
| 290 | if (!aMgrEO.IsNull()) |
| 291 | aMgrEO->SetLocation (aSelfLocation); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | //======================================================================= |
| 297 | //function : HilightSelected |
| 298 | //purpose : |
| 299 | //======================================================================= |
| 300 | void SelectMgr_SelectableObject::HilightSelected |
| 301 | ( const Handle(PrsMgr_PresentationManager3d)&, |
| 302 | const SelectMgr_SequenceOfOwner&) |
| 303 | { |
| 304 | Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected"); |
| 305 | } |
| 306 | |
| 307 | //======================================================================= |
| 308 | //function : ClearSelected |
| 309 | //purpose : |
| 310 | //======================================================================= |
| 311 | void SelectMgr_SelectableObject::ClearSelected () |
| 312 | { |
| 313 | if( !mySelectionPrs.IsNull() ) |
| 314 | mySelectionPrs->Clear(); |
| 315 | } |
| 316 | |
| 317 | //======================================================================= |
| 318 | //function : HilightOwnerWithColor |
| 319 | //purpose : |
| 320 | //======================================================================= |
| 321 | void SelectMgr_SelectableObject::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)&, |
| 322 | const Handle(Graphic3d_HighlightStyle)&, |
| 323 | const Handle(SelectMgr_EntityOwner)&) |
| 324 | { |
| 325 | Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor"); |
| 326 | } |
| 327 | |
| 328 | //======================================================================= |
| 329 | //function : MaxFaceNodes |
| 330 | //purpose : |
| 331 | //======================================================================= |
| 332 | Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const |
| 333 | { |
| 334 | return myAutoHilight; |
| 335 | } |
| 336 | |
| 337 | //======================================================================= |
| 338 | //function : MaxFaceNodes |
| 339 | //purpose : |
| 340 | //======================================================================= |
| 341 | void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight ) |
| 342 | { |
| 343 | myAutoHilight = newAutoHilight; |
| 344 | } |
| 345 | |
| 346 | //======================================================================= |
| 347 | //function : GetHilightPresentation |
| 348 | //purpose : |
| 349 | //======================================================================= |
| 350 | Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation (const Handle(PrsMgr_PresentationManager3d)& theMgr) |
| 351 | { |
| 352 | if (myHilightPrs.IsNull() && !theMgr.IsNull()) |
| 353 | { |
| 354 | myHilightPrs = new Prs3d_Presentation (theMgr->StructureManager()); |
| 355 | myHilightPrs->SetTransformPersistence (TransformPersistence()); |
| 356 | } |
| 357 | |
| 358 | return myHilightPrs; |
| 359 | } |
| 360 | |
| 361 | |
| 362 | //======================================================================= |
| 363 | //function : GetSelectPresentation |
| 364 | //purpose : |
| 365 | //======================================================================= |
| 366 | Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation (const Handle(PrsMgr_PresentationManager3d)& theMgr) |
| 367 | { |
| 368 | if (mySelectionPrs.IsNull() && !theMgr.IsNull()) |
| 369 | { |
| 370 | mySelectionPrs = new Prs3d_Presentation (theMgr->StructureManager()); |
| 371 | mySelectionPrs->SetTransformPersistence (TransformPersistence()); |
| 372 | } |
| 373 | |
| 374 | return mySelectionPrs; |
| 375 | } |
| 376 | |
| 377 | //======================================================================= |
| 378 | //function : SetZLayer |
| 379 | //purpose : |
| 380 | //======================================================================= |
| 381 | void SelectMgr_SelectableObject::SetZLayer (const Graphic3d_ZLayerId theLayerId) |
| 382 | { |
| 383 | // update own presentations |
| 384 | PrsMgr_PresentableObject::SetZLayer (theLayerId); |
| 385 | |
| 386 | // update selection presentations |
| 387 | if (!mySelectionPrs.IsNull()) |
| 388 | mySelectionPrs->SetZLayer (theLayerId); |
| 389 | |
| 390 | if (!myHilightPrs.IsNull()) |
| 391 | myHilightPrs->SetZLayer (theLayerId); |
| 392 | |
| 393 | // update all entity owner presentations |
| 394 | for (Init (); More () ;Next ()) |
| 395 | { |
| 396 | const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); |
| 397 | for (aSel->Init (); aSel->More (); aSel->Next ()) |
| 398 | { |
| 399 | Handle(Select3D_SensitiveEntity) aEntity = |
| 400 | Handle(Select3D_SensitiveEntity)::DownCast (aSel->Sensitive()->BaseSensitive()); |
| 401 | if (!aEntity.IsNull()) |
| 402 | { |
| 403 | Handle(SelectMgr_EntityOwner) aOwner = |
| 404 | Handle(SelectMgr_EntityOwner)::DownCast (aEntity->OwnerId()); |
| 405 | if (!aOwner.IsNull()) |
| 406 | aOwner->SetZLayer (theLayerId); |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | //======================================================================= |
| 413 | //function : updateSelection |
| 414 | //purpose : Sets update status FULL to selections of the object. Must be |
| 415 | // used as the only method of UpdateSelection from outer classes |
| 416 | // to prevent BVH structures from being outdated. |
| 417 | //======================================================================= |
| 418 | void SelectMgr_SelectableObject::updateSelection (const Standard_Integer theMode) |
| 419 | { |
| 420 | if (theMode == -1) |
| 421 | { |
| 422 | for (Init(); More(); Next()) |
| 423 | { |
| 424 | const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); |
| 425 | aSel->UpdateStatus (SelectMgr_TOU_Full); |
| 426 | } |
| 427 | |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | for (Init(); More(); Next()) |
| 432 | { |
| 433 | if (CurrentSelection()->Mode() == theMode) |
| 434 | { |
| 435 | CurrentSelection()->UpdateStatus (SelectMgr_TOU_Full); |
| 436 | return; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | //======================================================================= |
| 442 | //function : SetAttributes |
| 443 | //purpose : |
| 444 | //======================================================================= |
| 445 | void SelectMgr_SelectableObject::SetAttributes (const Handle(Prs3d_Drawer)& theDrawer) |
| 446 | { |
| 447 | myDrawer = theDrawer; |
| 448 | } |
| 449 | |
| 450 | //======================================================================= |
| 451 | //function : UnsetAttributes |
| 452 | //purpose : |
| 453 | //======================================================================= |
| 454 | void SelectMgr_SelectableObject::UnsetAttributes() |
| 455 | { |
| 456 | Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer(); |
| 457 | if (myDrawer->HasLink()) |
| 458 | { |
| 459 | aDrawer->Link (myDrawer->Link()); |
| 460 | } |
| 461 | myDrawer = aDrawer; |
| 462 | } |
| 463 | |
| 464 | //======================================================================= |
| 465 | //function : SetHilightAttributes |
| 466 | //purpose : |
| 467 | //======================================================================= |
| 468 | void SelectMgr_SelectableObject::SetHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer) |
| 469 | { |
| 470 | myHilightDrawer = theDrawer; |
| 471 | } |
| 472 | |
| 473 | //======================================================================= |
| 474 | //function : UnsetAttributes |
| 475 | //purpose : |
| 476 | //======================================================================= |
| 477 | void SelectMgr_SelectableObject::UnsetHilightAttributes() |
| 478 | { |
| 479 | Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer(); |
| 480 | InitDefaultHilightAttributes (aDrawer); |
| 481 | aDrawer->Link (myDrawer); |
| 482 | myHilightDrawer = aDrawer; |
| 483 | } |
| 484 | |
| 485 | //======================================================================= |
| 486 | //function : InitDefaultHilightAttributes |
| 487 | //purpose : |
| 488 | //======================================================================= |
| 489 | void SelectMgr_SelectableObject::InitDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer) |
| 490 | { |
| 491 | if (!theDrawer->HasOwnPointAspect()) |
| 492 | { |
| 493 | theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0)); |
| 494 | if (theDrawer->HasLink()) |
| 495 | { |
| 496 | *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect(); |
| 497 | } |
| 498 | } |
| 499 | if (!theDrawer->HasOwnLineAspect()) |
| 500 | { |
| 501 | theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); |
| 502 | if (theDrawer->HasLink()) |
| 503 | { |
| 504 | *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect(); |
| 505 | } |
| 506 | } |
| 507 | if (!theDrawer->HasOwnWireAspect()) |
| 508 | { |
| 509 | theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); |
| 510 | if (theDrawer->HasLink()) |
| 511 | { |
| 512 | *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect(); |
| 513 | } |
| 514 | } |
| 515 | if (!theDrawer->HasOwnPlaneAspect()) |
| 516 | { |
| 517 | theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect()); |
| 518 | if (theDrawer->HasLink()) |
| 519 | { |
| 520 | *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect(); |
| 521 | } |
| 522 | } |
| 523 | if (!theDrawer->HasOwnFreeBoundaryAspect()) |
| 524 | { |
| 525 | theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); |
| 526 | if (theDrawer->HasLink()) |
| 527 | { |
| 528 | *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect(); |
| 529 | } |
| 530 | } |
| 531 | if (!theDrawer->HasOwnUnFreeBoundaryAspect()) |
| 532 | { |
| 533 | theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); |
| 534 | if (theDrawer->HasLink()) |
| 535 | { |
| 536 | *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect(); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | theDrawer->WireAspect()->SetWidth(2.); |
| 541 | theDrawer->LineAspect()->SetWidth(2.); |
| 542 | theDrawer->PlaneAspect()->EdgesAspect()->SetWidth(2.); |
| 543 | theDrawer->FreeBoundaryAspect()->SetWidth(2.); |
| 544 | theDrawer->UnFreeBoundaryAspect()->SetWidth(2.); |
| 545 | theDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_POINT); |
| 546 | theDrawer->PointAspect()->SetScale(2.); |
| 547 | |
| 548 | // By default the hilight drawer has absolute type of deflection. |
| 549 | // It is supposed that absolute deflection is taken from Link(). |
| 550 | // It is necessary to use for all sub-shapes identical coefficient |
| 551 | // computed in ::Compute() call for whole shape and stored in base drawer. |
| 552 | theDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); |
| 553 | } |
| 554 | |
| 555 | //======================================================================= |
| 556 | //function : SetAssemblyOwner |
| 557 | //purpose : Sets common entity owner for assembly sensitive object entities |
| 558 | //======================================================================= |
| 559 | void SelectMgr_SelectableObject::SetAssemblyOwner (const Handle(SelectMgr_EntityOwner)& theOwner, |
| 560 | const Standard_Integer theMode) |
| 561 | { |
| 562 | if (theMode == -1) |
| 563 | { |
| 564 | for (Standard_Integer aModeIter = 1; aModeIter <= myselections.Length(); ++aModeIter) |
| 565 | { |
| 566 | Handle(SelectMgr_Selection)& aSel = myselections.ChangeValue (aModeIter); |
| 567 | for (aSel->Init(); aSel->More(); aSel->Next()) |
| 568 | { |
| 569 | aSel->Sensitive()->BaseSensitive()->Set (theOwner); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | if (!HasSelection (theMode)) |
| 577 | return; |
| 578 | |
| 579 | for (Standard_Integer aModeIter = 1; aModeIter <= myselections.Length(); ++aModeIter) |
| 580 | { |
| 581 | if (myselections.Value (aModeIter)->Mode() == theMode) |
| 582 | { |
| 583 | Handle(SelectMgr_Selection)& aSel = myselections.ChangeValue (aModeIter); |
| 584 | for (aSel->Init(); aSel->More(); aSel->Next()) |
| 585 | { |
| 586 | aSel->Sensitive()->BaseSensitive()->Set (theOwner); |
| 587 | } |
| 588 | return; |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | //======================================================================= |
| 594 | //function : GetAssemblyOwner |
| 595 | //purpose : Returns common entity owner if it is an assembly |
| 596 | //======================================================================= |
| 597 | const Handle(SelectMgr_EntityOwner)& SelectMgr_SelectableObject::GetAssemblyOwner() const |
| 598 | { |
| 599 | return myAssemblyOwner; |
| 600 | } |
| 601 | |
| 602 | //======================================================================= |
| 603 | //function : BndBoxOfSelected |
| 604 | //purpose : |
| 605 | //======================================================================= |
| 606 | Bnd_Box SelectMgr_SelectableObject::BndBoxOfSelected (const Handle(SelectMgr_IndexedMapOfOwner)& theOwners) |
| 607 | { |
| 608 | if (theOwners->IsEmpty()) |
| 609 | return Bnd_Box(); |
| 610 | |
| 611 | Bnd_Box aBnd; |
| 612 | for (Init(); More(); Next()) |
| 613 | { |
| 614 | const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); |
| 615 | if (aSel->GetSelectionState() != SelectMgr_SOS_Activated) |
| 616 | continue; |
| 617 | |
| 618 | for (aSel->Init(); aSel->More(); aSel->Next()) |
| 619 | { |
| 620 | const Handle(SelectMgr_EntityOwner) anOwner = |
| 621 | Handle(SelectMgr_EntityOwner)::DownCast (aSel->Sensitive()->BaseSensitive()->OwnerId()); |
| 622 | if (theOwners->Contains (anOwner)) |
| 623 | { |
| 624 | Select3D_BndBox3d aBox = aSel->Sensitive()->BaseSensitive()->BoundingBox(); |
| 625 | aBnd.Update (aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(), |
| 626 | aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z()); |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | return aBnd; |
| 632 | } |
| 633 | |
| 634 | //======================================================================= |
| 635 | //function : GlobalSelOwner |
| 636 | //purpose : Returns entity owner corresponding to selection of the object as a whole |
| 637 | //======================================================================= |
| 638 | Handle(SelectMgr_EntityOwner) SelectMgr_SelectableObject::GlobalSelOwner() const |
| 639 | { |
| 640 | Handle(SelectMgr_EntityOwner) anOwner; |
| 641 | |
| 642 | if (!HasSelection (myGlobalSelMode)) |
| 643 | return anOwner; |
| 644 | |
| 645 | const Handle(SelectMgr_Selection)& aGlobalSel = Selection (myGlobalSelMode); |
| 646 | if (aGlobalSel->IsEmpty()) |
| 647 | return anOwner; |
| 648 | |
| 649 | aGlobalSel->Init(); |
| 650 | anOwner = |
| 651 | Handle(SelectMgr_EntityOwner)::DownCast (aGlobalSel->Sensitive()->BaseSensitive()->OwnerId()); |
| 652 | |
| 653 | return anOwner; |
| 654 | } |