| 1 | // Created on: 1996-10-30 |
| 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 by rob Thu Apr 02 1998 |
| 18 | // - use of optimisation in SelectMgr_ViewerSelector |
| 19 | // -> Best management in detected entities... |
| 20 | |
| 21 | #define BUC60569 //GG_051199 Enable to select the local context |
| 22 | // in any case and especially in multi selection mode. |
| 23 | // Note that right now when an hilighted owner is selected |
| 24 | // this owner is unhilighted,this permits to see the selection! |
| 25 | // Principle : an owner can have 3 state : |
| 26 | // 1 : The owner is selected and no more highlightable |
| 27 | // 0 : The owner is NOT selected |
| 28 | // -1: The owner is selected but stay highlightable (NEW) |
| 29 | |
| 30 | // IMP230600 //GG Add protection on selection methodes |
| 31 | // when nothing is selected |
| 32 | |
| 33 | #define BUC60726 //GG_040900 When nothing is detected, |
| 34 | // Clear the last temporary stuff in any case |
| 35 | |
| 36 | #define BUC60765 //GG_121000 Avoid to raise when the same selection |
| 37 | // is attached to several local context. |
| 38 | |
| 39 | #define BUC60771 //GG_261000 Avoid to crash after closing a view |
| 40 | // containing a selected entity and creating a new one. |
| 41 | |
| 42 | #define BUC60774 //GG_261000 Returns right select status on |
| 43 | // bounding-box selection type. |
| 44 | |
| 45 | #define BUC60818 //GG_300101 Enable detection even if |
| 46 | // SetAutomaticHilight(FALSE) has been used. |
| 47 | |
| 48 | #define IMP300101 //GG Enable to use polygon highlighting |
| 49 | |
| 50 | #define BUC60876 //GG_050401 Clear selection always even |
| 51 | // if the current highlight mode is not 0. |
| 52 | |
| 53 | #define BUC60953 //SAV_060701 For Select optimization. Selection by rectangle case. |
| 54 | // for single selection no optimization done. |
| 55 | |
| 56 | #define IMP120701 //SZV made a shape valid for selection |
| 57 | // when required. |
| 58 | |
| 59 | #define IMP160701 //SZV Add InitDetected(),MoreDetected(),NextDetected(), |
| 60 | // DetectedCurrentShape(),DetectedCurrentObject() |
| 61 | // methods |
| 62 | |
| 63 | #define OCC138 //VTN Avoding infinit loop in AddOrRemoveSelected method. |
| 64 | |
| 65 | #define OCC189 //SAV: 18/03/02 AIS_Selection::Objects() returns ListOfTransient |
| 66 | // instead of array. |
| 67 | |
| 68 | #define USE_MAP //san : 18/04/03 USE_MAP - additional datamap is used to speed up access |
| 69 | //to certain owners in AIS_Selection::myresult list |
| 70 | |
| 71 | #define OCC9026 //AEL Performance optimization of the FindSelectedOwnerFromShape() method. |
| 72 | |
| 73 | #include <AIS_LocalContext.jxx> |
| 74 | #include <StdSelect_BRepOwner.hxx> |
| 75 | #include <TColStd_MapOfTransient.hxx> |
| 76 | #include <TColStd_MapIteratorOfMapOfTransient.hxx> |
| 77 | #include <Prs3d_Presentation.hxx> |
| 78 | #include <Prs3d_Drawer.hxx> |
| 79 | #include <Prs3d_ShadingAspect.hxx> |
| 80 | #include <AIS_LocalStatus.hxx> |
| 81 | #include <StdPrs_WFShape.hxx> |
| 82 | #include <Graphic3d_ArrayOfTriangles.hxx> |
| 83 | #include <Graphic3d_Group.hxx> |
| 84 | #include <Select3D_SensitiveTriangulation.hxx> |
| 85 | #include <SelectBasics_SensitiveEntity.hxx> |
| 86 | #include <TCollection_AsciiString.hxx> |
| 87 | #include <NCollection_Map.hxx> |
| 88 | |
| 89 | #ifdef OCC9026 |
| 90 | #include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx> |
| 91 | #endif |
| 92 | #include <SelectMgr_Selection.hxx> |
| 93 | #include <SelectMgr_SequenceOfOwner.hxx> |
| 94 | #include <OSD_Environment.hxx> |
| 95 | |
| 96 | #include <Geom_Transformation.hxx> |
| 97 | #include <AIS_Selection.hxx> |
| 98 | #include <Aspect_Grid.hxx> |
| 99 | #ifdef IMP120701 |
| 100 | #include <AIS_Shape.hxx> |
| 101 | #endif |
| 102 | |
| 103 | |
| 104 | static Standard_Integer GetHiMod(const Handle(AIS_InteractiveObject)& IO) |
| 105 | { |
| 106 | return IO->HasHilightMode() ? IO->HilightMode():0; |
| 107 | } |
| 108 | |
| 109 | //================================================== |
| 110 | // Function: MoveTo |
| 111 | // Purpose : |
| 112 | //================================================== |
| 113 | AIS_StatusOfDetection AIS_LocalContext::MoveTo (const Standard_Integer theXpix, |
| 114 | const Standard_Integer theYpix, |
| 115 | const Handle(V3d_View)& theView, |
| 116 | const Standard_Boolean theToRedrawImmediate) |
| 117 | { |
| 118 | // check that ViewerSelector gives |
| 119 | if (theView->Viewer() != myCTX->CurrentViewer()) |
| 120 | { |
| 121 | return AIS_SOD_Error; |
| 122 | } |
| 123 | |
| 124 | myAISCurDetected = 0; |
| 125 | myAISDetectedSeq.Clear(); |
| 126 | |
| 127 | myCurDetected = 0; |
| 128 | myDetectedSeq.Clear(); |
| 129 | myMainVS->Pick (theXpix, theYpix, theView); |
| 130 | |
| 131 | const Standard_Integer aDetectedNb = myMainVS->NbPicked(); |
| 132 | for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter) |
| 133 | { |
| 134 | Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (aDetIter); |
| 135 | if (anOwner.IsNull() |
| 136 | || !myFilters->IsOk (anOwner)) |
| 137 | { |
| 138 | continue; |
| 139 | } |
| 140 | |
| 141 | myDetectedSeq.Append (aDetIter); // normally they are already arranged in correct order... |
| 142 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); |
| 143 | if (!anObj.IsNull()) |
| 144 | { |
| 145 | myAISDetectedSeq.Append (anObj); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // result of courses.. |
| 150 | if (aDetectedNb == 0 || myDetectedSeq.IsEmpty()) |
| 151 | { |
| 152 | if (mylastindex != 0 && mylastindex <= myMapOfOwner.Extent()) |
| 153 | { |
| 154 | Unhilight (myMapOfOwner (mylastindex), theView); |
| 155 | if (theToRedrawImmediate) |
| 156 | { |
| 157 | theView->RedrawImmediate(); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | mylastindex = 0; |
| 162 | return aDetectedNb == 0 |
| 163 | ? AIS_SOD_Nothing |
| 164 | : AIS_SOD_AllBad; |
| 165 | } |
| 166 | |
| 167 | // all owners detected by the selector are passed to the |
| 168 | // filters and correct ones are preserved... |
| 169 | myCurDetected = 1; |
| 170 | Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected)); |
| 171 | manageDetected (anOwner, theView, theToRedrawImmediate); |
| 172 | if (myDetectedSeq.Length() == 1) |
| 173 | { |
| 174 | return aDetectedNb == 1 |
| 175 | ? AIS_SOD_OnlyOneDetected |
| 176 | : AIS_SOD_OnlyOneGood; |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | return AIS_SOD_SeveralGood; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | //======================================================================= |
| 185 | //function : Select |
| 186 | //purpose : |
| 187 | //======================================================================= |
| 188 | AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Boolean toUpdateViewer) |
| 189 | { |
| 190 | if (myAutoHilight) |
| 191 | { |
| 192 | UnhilightPicked (Standard_False); |
| 193 | } |
| 194 | |
| 195 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
| 196 | |
| 197 | Standard_Integer aDetIndex = DetectedIndex(); |
| 198 | if (aDetIndex <= 0) |
| 199 | { |
| 200 | ClearSelected (toUpdateViewer); |
| 201 | return (AIS_Selection::Extent() == 0) ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
| 202 | } |
| 203 | |
| 204 | const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex); |
| 205 | |
| 206 | ClearSelected (Standard_False); |
| 207 | |
| 208 | if (!anOwner->IsSelected()) // anOwner is not selected |
| 209 | { |
| 210 | anOwner->SetSelected (Standard_True); |
| 211 | AIS_Selection::Select (anOwner); |
| 212 | } |
| 213 | |
| 214 | if (myAutoHilight) |
| 215 | { |
| 216 | const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer(); |
| 217 | for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
| 218 | { |
| 219 | Unhilight (anOwner, aViewer->ActiveView()); |
| 220 | } |
| 221 | |
| 222 | // advanced selection highlighting mechanism |
| 223 | if (!anOwner->IsAutoHilight() && anOwner->HasSelectable()) |
| 224 | { |
| 225 | Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable()); |
| 226 | UpdateSelected (anIO, Standard_False); |
| 227 | } |
| 228 | |
| 229 | if (toUpdateViewer) |
| 230 | { |
| 231 | myCTX->CurrentViewer()->Update(); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | return (AIS_Selection::Extent() == 1) ? AIS_SOP_OneSelected : AIS_SOP_SeveralSelected; |
| 236 | } |
| 237 | |
| 238 | //======================================================================= |
| 239 | //function : Select |
| 240 | //purpose : |
| 241 | //======================================================================= |
| 242 | AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Integer theXPMin, |
| 243 | const Standard_Integer theYPMin, |
| 244 | const Standard_Integer theXPMax, |
| 245 | const Standard_Integer theYPMax, |
| 246 | const Handle(V3d_View)& theView, |
| 247 | const Standard_Boolean toUpdateViewer) |
| 248 | { |
| 249 | if (theView->Viewer() == myCTX->CurrentViewer()) |
| 250 | { |
| 251 | myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); |
| 252 | if (myAutoHilight) |
| 253 | { |
| 254 | UnhilightPicked (Standard_False); |
| 255 | } |
| 256 | |
| 257 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
| 258 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
| 259 | |
| 260 | myMainVS->Init(); |
| 261 | if (!myMainVS->More()) |
| 262 | { |
| 263 | ClearSelected (toUpdateViewer); |
| 264 | mylastindex = 0; |
| 265 | return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
| 266 | } |
| 267 | |
| 268 | ClearSelected (Standard_False); |
| 269 | |
| 270 | for (myMainVS->Init(); myMainVS->More(); myMainVS->Next()) |
| 271 | { |
| 272 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked(); |
| 273 | if (myFilters->IsOk (anOwner)) |
| 274 | { |
| 275 | // it can be helpful to classify this owner immediately... |
| 276 | if (!anOwner->IsSelected()) |
| 277 | { |
| 278 | anOwner->SetSelected (Standard_True); |
| 279 | AIS_Selection::Select (anOwner); |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if (myAutoHilight) |
| 285 | { |
| 286 | HilightPicked (toUpdateViewer); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
| 291 | |
| 292 | return (aSelNum == 1) ? AIS_SOP_OneSelected |
| 293 | : (aSelNum > 1) ? AIS_SOP_SeveralSelected |
| 294 | : AIS_SOP_Error; |
| 295 | } |
| 296 | |
| 297 | //================================================== |
| 298 | // Function: Select |
| 299 | // Purpose : Selection by polyline |
| 300 | //================================================== |
| 301 | AIS_StatusOfPick AIS_LocalContext::Select (const TColgp_Array1OfPnt2d& thePolyline, |
| 302 | const Handle(V3d_View)& theView, |
| 303 | const Standard_Boolean toUpdateViewer) |
| 304 | { |
| 305 | if (theView->Viewer() == myCTX->CurrentViewer()) |
| 306 | { |
| 307 | myMainVS->Pick (thePolyline, theView); |
| 308 | |
| 309 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
| 310 | |
| 311 | Standard_Integer aLastSelNum = AIS_Selection::Extent(); |
| 312 | myMainVS->Init(); |
| 313 | if (!myMainVS->More()) |
| 314 | { |
| 315 | // Nothing is selected clear selection. |
| 316 | ClearSelected (toUpdateViewer); |
| 317 | mylastindex = 0; |
| 318 | |
| 319 | // Return state to know if something was unselected |
| 320 | return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
| 321 | } |
| 322 | |
| 323 | if (myAutoHilight) |
| 324 | { |
| 325 | UnhilightPicked (Standard_False); |
| 326 | } |
| 327 | |
| 328 | // Clear previous selection without update to process this selection |
| 329 | ClearSelected (Standard_False); |
| 330 | |
| 331 | for (myMainVS->Init(); myMainVS->More(); myMainVS->Next()) |
| 332 | { |
| 333 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked(); |
| 334 | if (myFilters->IsOk (anOwner)) |
| 335 | { |
| 336 | // it can be helpful to classify this owner immediately... |
| 337 | if (!anOwner->IsSelected()) |
| 338 | { |
| 339 | AIS_Selection::AddSelect (anOwner); |
| 340 | anOwner->SetSelected (Standard_True); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | if (myAutoHilight) |
| 346 | { |
| 347 | HilightPicked (toUpdateViewer); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
| 352 | return (aSelNum == 1) ? AIS_SOP_OneSelected |
| 353 | : (aSelNum > 1) ? AIS_SOP_SeveralSelected |
| 354 | : AIS_SOP_Error; |
| 355 | } |
| 356 | |
| 357 | //======================================================================= |
| 358 | //function : ShiftSelect |
| 359 | //purpose : |
| 360 | //======================================================================= |
| 361 | AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Boolean toUpdateViewer) |
| 362 | { |
| 363 | Standard_Integer aDetIndex = DetectedIndex(); |
| 364 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
| 365 | |
| 366 | if(aDetIndex > 0) |
| 367 | { |
| 368 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
| 369 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
| 370 | const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex); |
| 371 | Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True; |
| 372 | AIS_Selection::Select (anOwner); |
| 373 | anOwner->SetSelected (toSelect); |
| 374 | |
| 375 | if(myAutoHilight) |
| 376 | { |
| 377 | const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer(); |
| 378 | for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
| 379 | { |
| 380 | Unhilight (anOwner, aViewer->ActiveView()); |
| 381 | } |
| 382 | |
| 383 | // advanced selection highlighting mechanism |
| 384 | if (!anOwner->IsAutoHilight() && anOwner->HasSelectable()) |
| 385 | { |
| 386 | Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); |
| 387 | UpdateSelected (anIO, Standard_False); |
| 388 | } |
| 389 | |
| 390 | if (toUpdateViewer) |
| 391 | { |
| 392 | myCTX->CurrentViewer()->Update(); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | #ifdef BUC60774 |
| 397 | Standard_Integer NS = AIS_Selection::Extent(); |
| 398 | if( NS == 1 ) return AIS_SOP_OneSelected; |
| 399 | else if( NS > 1 ) return AIS_SOP_SeveralSelected; |
| 400 | return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
| 401 | #endif |
| 402 | } |
| 403 | return AIS_SOP_Error; |
| 404 | } |
| 405 | |
| 406 | //======================================================================= |
| 407 | //function : ShiftSelect |
| 408 | //purpose : |
| 409 | //======================================================================= |
| 410 | AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Integer theXPMin, |
| 411 | const Standard_Integer theYPMin, |
| 412 | const Standard_Integer theXPMax, |
| 413 | const Standard_Integer theYPMax, |
| 414 | const Handle(V3d_View)& theView, |
| 415 | const Standard_Boolean toUpdateViewer) |
| 416 | { |
| 417 | myMainPM->ClearImmediateDraw(); |
| 418 | |
| 419 | if (theView->Viewer() == myCTX->CurrentViewer()) |
| 420 | { |
| 421 | myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); |
| 422 | |
| 423 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
| 424 | Standard_Integer aLastSelNum = AIS_Selection::Extent(); |
| 425 | |
| 426 | myMainVS->Init(); |
| 427 | if (!myMainVS->More()) |
| 428 | { |
| 429 | // Nothing is selected clear selection, but don't clear the selection |
| 430 | // as it is shift selection and previous selection matters. |
| 431 | // Return state to know if something was unselected |
| 432 | return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
| 433 | } |
| 434 | |
| 435 | if (myAutoHilight) |
| 436 | { |
| 437 | UnhilightPicked (Standard_False); |
| 438 | } |
| 439 | |
| 440 | for (myMainVS->Init(); myMainVS->More(); myMainVS->Next()) |
| 441 | { |
| 442 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked(); |
| 443 | if(myFilters->IsOk (anOwner)) |
| 444 | { |
| 445 | Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True; |
| 446 | AIS_Selection::Select (anOwner); |
| 447 | anOwner->SetSelected (toSelect); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | if (myAutoHilight) |
| 452 | { |
| 453 | HilightPicked (toUpdateViewer); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
| 458 | |
| 459 | return (aSelNum == 1) ? AIS_SOP_OneSelected |
| 460 | : (aSelNum > 1) ? AIS_SOP_SeveralSelected |
| 461 | : AIS_SOP_Error; |
| 462 | } |
| 463 | |
| 464 | //================================================== |
| 465 | // Function: Select |
| 466 | // Purpose : Selection by polyline |
| 467 | //================================================== |
| 468 | AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline, |
| 469 | const Handle(V3d_View)& theView, |
| 470 | const Standard_Boolean toUpdateViewer) |
| 471 | { |
| 472 | if (theView->Viewer() == myCTX->CurrentViewer()) |
| 473 | { |
| 474 | myMainVS->Pick (thePolyline, theView); |
| 475 | |
| 476 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
| 477 | |
| 478 | Standard_Integer aLastSelNum = AIS_Selection::Extent(); |
| 479 | myMainVS->Init(); |
| 480 | if(!myMainVS->More()) |
| 481 | { |
| 482 | // Nothing is selected clear selection, but don't clear the selection |
| 483 | // as it is shift selection and previous selection matters. |
| 484 | // Return state to know if something was unselected |
| 485 | return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
| 486 | } |
| 487 | |
| 488 | if (myAutoHilight) |
| 489 | { |
| 490 | UnhilightPicked (Standard_False); |
| 491 | } |
| 492 | |
| 493 | for (myMainVS->Init(); myMainVS->More(); myMainVS->Next()) |
| 494 | { |
| 495 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked(); |
| 496 | if (myFilters->IsOk (anOwner)) |
| 497 | { |
| 498 | Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True; |
| 499 | AIS_Selection::Select (anOwner); |
| 500 | anOwner->SetSelected (toSelect); |
| 501 | } |
| 502 | } |
| 503 | if (myAutoHilight) |
| 504 | { |
| 505 | HilightPicked (toUpdateViewer); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
| 510 | |
| 511 | return (aSelNum == 1) ? AIS_SOP_OneSelected |
| 512 | : (aSelNum > 1) ? AIS_SOP_SeveralSelected |
| 513 | : AIS_SOP_Error; |
| 514 | } |
| 515 | |
| 516 | //================================================== |
| 517 | // Function: Hilight |
| 518 | // Purpose : |
| 519 | //================================================== |
| 520 | void AIS_LocalContext::Hilight (const Handle(SelectMgr_EntityOwner)& theOwner, |
| 521 | const Handle(V3d_View)& theView) |
| 522 | { |
| 523 | if (theView.IsNull()) |
| 524 | { |
| 525 | return; |
| 526 | } |
| 527 | |
| 528 | const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable())); |
| 529 | myMainPM->BeginImmediateDraw(); |
| 530 | theOwner->HilightWithColor (myMainPM, myCTX->HilightColor(), aHilightMode); |
| 531 | myMainPM->EndImmediateDraw (theView); |
| 532 | } |
| 533 | |
| 534 | //================================================== |
| 535 | // Function: Unhilight |
| 536 | // Purpose : |
| 537 | //================================================== |
| 538 | void AIS_LocalContext::Unhilight (const Handle(SelectMgr_EntityOwner)& theOwner, |
| 539 | const Handle(V3d_View)& theView) |
| 540 | { |
| 541 | if (theView.IsNull()) |
| 542 | { |
| 543 | return; |
| 544 | } |
| 545 | |
| 546 | myMainPM->ClearImmediateDraw(); |
| 547 | const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable())); |
| 548 | if (IsSelected (theOwner)) |
| 549 | { |
| 550 | if (theOwner->IsAutoHilight()) |
| 551 | { |
| 552 | theOwner->HilightWithColor (myMainPM, myCTX->SelectionColor(), aHilightMode); |
| 553 | } |
| 554 | } |
| 555 | else |
| 556 | { |
| 557 | theOwner->Unhilight (myMainPM, aHilightMode); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | //======================================================================= |
| 562 | //function : HilightPicked |
| 563 | //purpose : |
| 564 | //======================================================================= |
| 565 | void AIS_LocalContext::HilightPicked(const Standard_Boolean updateviewer) |
| 566 | { |
| 567 | Standard_Boolean updMain(Standard_False); |
| 568 | |
| 569 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
| 570 | #ifdef BUC60765 |
| 571 | if( Sel.IsNull() ) return; |
| 572 | #endif |
| 573 | |
| 574 | typedef NCollection_DataMap <Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > SelectMgr_DataMapOfObjectOwners; |
| 575 | SelectMgr_DataMapOfObjectOwners aMap; |
| 576 | |
| 577 | Handle (PrsMgr_PresentationManager3d) PM = myMainPM; |
| 578 | |
| 579 | // to avoid problems when there is a loop searching for selected objects... |
| 580 | #if !defined OCC189 && !defined USE_MAP |
| 581 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
| 582 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++) |
| 583 | { |
| 584 | const Handle(Standard_Transient)& Tr = Obj(i); |
| 585 | #else |
| 586 | const AIS_NListTransient& Obj = Sel->Objects(); |
| 587 | AIS_NListTransient::Iterator anIter( Obj ); |
| 588 | for(; anIter.More(); anIter.Next()) |
| 589 | { |
| 590 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
| 591 | #endif |
| 592 | if(!Tr.IsNull()){ |
| 593 | const Handle(SelectMgr_EntityOwner)& Ownr = |
| 594 | *((const Handle(SelectMgr_EntityOwner)*) &Tr); |
| 595 | Handle(AIS_InteractiveObject) IO; |
| 596 | if(Ownr->HasSelectable()){ |
| 597 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr); |
| 598 | if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ |
| 599 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
| 600 | IO = *((Handle(AIS_InteractiveObject)*)&SO); |
| 601 | updMain = Standard_True; |
| 602 | } |
| 603 | else |
| 604 | updMain = Standard_True; |
| 605 | } |
| 606 | else |
| 607 | updMain = Standard_True; |
| 608 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
| 609 | Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO)); |
| 610 | if ( Ownr->IsAutoHilight() ) |
| 611 | Ownr->HilightWithColor(PM,myCTX->SelectionColor(),HM); |
| 612 | else if ( aMap.IsBound (SO) ) |
| 613 | aMap(SO)->Append ( Ownr ); |
| 614 | else { |
| 615 | NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq = new SelectMgr_SequenceOfOwner; |
| 616 | aSeq->Append ( Ownr ); |
| 617 | aMap.Bind ( SO, aSeq ); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | for ( SelectMgr_DataMapOfObjectOwners::Iterator aMapIter(aMap); |
| 623 | aMapIter.More(); aMapIter.Next() ) |
| 624 | { |
| 625 | aMapIter.Key()->HilightSelected (myMainPM, *aMapIter.Value()); |
| 626 | } |
| 627 | |
| 628 | if (updateviewer) |
| 629 | { |
| 630 | myCTX->CurrentViewer()->Update(); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | //================================================== |
| 635 | // Function: |
| 636 | // Purpose : |
| 637 | //================================================== |
| 638 | void AIS_LocalContext::UnhilightPicked (const Standard_Boolean updateviewer) |
| 639 | { |
| 640 | myMainPM->ClearImmediateDraw(); |
| 641 | |
| 642 | Standard_Boolean updMain(Standard_False); |
| 643 | |
| 644 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
| 645 | #ifdef BUC60765 |
| 646 | if( Sel.IsNull() ) return; |
| 647 | #endif |
| 648 | Handle (PrsMgr_PresentationManager3d) PM = myMainPM; |
| 649 | NCollection_Map<Handle(SelectMgr_SelectableObject)> anObjMap; |
| 650 | |
| 651 | #if !defined OCC189 && !defined USE_MAP |
| 652 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
| 653 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){ |
| 654 | const Handle(Standard_Transient)& Tr = Obj(i); |
| 655 | #else |
| 656 | const AIS_NListTransient& Obj = Sel->Objects(); |
| 657 | AIS_NListTransient::Iterator anIter( Obj ); |
| 658 | for(; anIter.More(); anIter.Next()){ |
| 659 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
| 660 | #endif |
| 661 | if(!Tr.IsNull()){ |
| 662 | const Handle(SelectMgr_EntityOwner)& Ownr = |
| 663 | *((const Handle(SelectMgr_EntityOwner)*) &Tr); |
| 664 | Standard_Integer HM(0); |
| 665 | if(Ownr->HasSelectable()){ |
| 666 | #ifdef BUC60876 |
| 667 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
| 668 | Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO); |
| 669 | anObjMap.Add (IO); |
| 670 | |
| 671 | HM = GetHiMod(IO); |
| 672 | #endif |
| 673 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr); |
| 674 | if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ |
| 675 | #ifndef BUC60876 |
| 676 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
| 677 | Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO); |
| 678 | HM = GetHiMod(IO); |
| 679 | #endif |
| 680 | updMain = Standard_True; |
| 681 | } |
| 682 | else |
| 683 | updMain = Standard_True; |
| 684 | } |
| 685 | Ownr->Unhilight(PM,HM); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | for (NCollection_Map<Handle(SelectMgr_SelectableObject)>::Iterator anIter1 ( anObjMap ); |
| 690 | anIter1.More(); anIter1.Next() ) |
| 691 | { |
| 692 | if ( !anIter1.Key()->IsAutoHilight() ) |
| 693 | anIter1.Key()->ClearSelected(); |
| 694 | } |
| 695 | |
| 696 | if(updateviewer){ |
| 697 | #ifdef BUC60774 |
| 698 | myCTX->CurrentViewer()->Update(); |
| 699 | #else |
| 700 | if(updMain) myCTX->CurrentViewer()->Update(); |
| 701 | #endif |
| 702 | } |
| 703 | |
| 704 | } |
| 705 | |
| 706 | //======================================================================= |
| 707 | //function : IsSelected |
| 708 | //purpose : |
| 709 | //======================================================================= |
| 710 | Standard_Boolean AIS_LocalContext::IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const |
| 711 | { |
| 712 | return (!FindSelectedOwnerFromIO(anIObj).IsNull()); |
| 713 | } |
| 714 | |
| 715 | //======================================================================= |
| 716 | //function : IsSelected |
| 717 | //purpose : |
| 718 | //======================================================================= |
| 719 | |
| 720 | Standard_Boolean AIS_LocalContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const |
| 721 | { |
| 722 | return !theOwner.IsNull() && theOwner->IsSelected(); |
| 723 | } |
| 724 | |
| 725 | //================================================== |
| 726 | // Function: |
| 727 | // Purpose : |
| 728 | //================================================== |
| 729 | void AIS_LocalContext:: |
| 730 | InitSelected() |
| 731 | { |
| 732 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
| 733 | AIS_Selection::CurrentSelection()->Init(); |
| 734 | } |
| 735 | |
| 736 | //================================================== |
| 737 | // Function: |
| 738 | // Purpose : |
| 739 | //================================================== |
| 740 | Standard_Boolean AIS_LocalContext:: |
| 741 | MoreSelected() const |
| 742 | { |
| 743 | return AIS_Selection::CurrentSelection()->More(); |
| 744 | } |
| 745 | |
| 746 | //================================================== |
| 747 | // Function: |
| 748 | // Purpose : |
| 749 | //================================================== |
| 750 | void AIS_LocalContext:: |
| 751 | NextSelected() |
| 752 | { |
| 753 | AIS_Selection::CurrentSelection()->Next(); |
| 754 | } |
| 755 | |
| 756 | //================================================== |
| 757 | // Function: |
| 758 | // Purpose : |
| 759 | //================================================== |
| 760 | Standard_Boolean AIS_LocalContext:: |
| 761 | HasShape() const |
| 762 | { |
| 763 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
| 764 | if( Tr.IsNull() ) return Standard_False; |
| 765 | Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
| 766 | Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO); |
| 767 | if(BRO.IsNull()) return Standard_False; |
| 768 | Standard_Boolean hasshape = BRO->HasShape(); |
| 769 | Standard_Boolean comes = BRO->ComesFromDecomposition(); |
| 770 | return (hasshape&&comes); |
| 771 | } |
| 772 | |
| 773 | //================================================== |
| 774 | // Function: |
| 775 | // Purpose : |
| 776 | //================================================== |
| 777 | const TopoDS_Shape& AIS_LocalContext:: |
| 778 | SelectedShape() const |
| 779 | { |
| 780 | static TopoDS_Shape aSh; |
| 781 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
| 782 | Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
| 783 | Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO); |
| 784 | if( BRO.IsNull() ) |
| 785 | { |
| 786 | return aSh; |
| 787 | } |
| 788 | return BRO->Shape(); |
| 789 | } |
| 790 | |
| 791 | //================================================== |
| 792 | // Function: |
| 793 | // Purpose : |
| 794 | //================================================== |
| 795 | Handle(AIS_InteractiveObject) AIS_LocalContext:: |
| 796 | SelectedInteractive() const |
| 797 | { |
| 798 | Handle(AIS_InteractiveObject) IO; |
| 799 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
| 800 | if( !Tr.IsNull() ) { |
| 801 | Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
| 802 | Handle(SelectMgr_SelectableObject) SO; |
| 803 | if(EO->HasSelectable()){ |
| 804 | SO = EO->Selectable(); |
| 805 | IO = *((Handle(AIS_InteractiveObject)*)&SO); |
| 806 | } |
| 807 | } |
| 808 | return IO; |
| 809 | } |
| 810 | //================================================== |
| 811 | // Function: |
| 812 | // Purpose : |
| 813 | //================================================== |
| 814 | Handle(SelectMgr_EntityOwner) AIS_LocalContext:: |
| 815 | SelectedOwner() const |
| 816 | { |
| 817 | Handle(SelectMgr_EntityOwner) EO; |
| 818 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
| 819 | if( !Tr.IsNull() ) |
| 820 | EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
| 821 | return EO; |
| 822 | } |
| 823 | |
| 824 | //================================================== |
| 825 | // Function: |
| 826 | // Purpose : |
| 827 | //================================================== |
| 828 | Standard_Boolean AIS_LocalContext:: |
| 829 | HasApplicative() const |
| 830 | { |
| 831 | Handle(AIS_InteractiveObject) IO = SelectedInteractive(); |
| 832 | if( IO.IsNull() ) return Standard_False; |
| 833 | return IO->HasOwner(); |
| 834 | } |
| 835 | |
| 836 | //================================================== |
| 837 | // Function: |
| 838 | // Purpose : |
| 839 | //================================================== |
| 840 | const Handle(Standard_Transient)& AIS_LocalContext:: |
| 841 | SelectedApplicative() const |
| 842 | { |
| 843 | return SelectedInteractive()->GetOwner(); |
| 844 | } |
| 845 | |
| 846 | |
| 847 | |
| 848 | //======================================================================= |
| 849 | //function : UpdateSelection |
| 850 | //purpose : should disappear... |
| 851 | //======================================================================= |
| 852 | void AIS_LocalContext::UpdateSelected(const Standard_Boolean updateviewer) |
| 853 | { |
| 854 | UnhilightPicked(Standard_False); |
| 855 | HilightPicked(updateviewer); |
| 856 | } |
| 857 | |
| 858 | //================================================================ |
| 859 | // Function : UpdateSelected |
| 860 | // Purpose : Part of advanced selection mechanism. |
| 861 | // Highlightes or clears selection presentation for the given IO |
| 862 | //================================================================ |
| 863 | void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj, |
| 864 | const Standard_Boolean updateviewer) |
| 865 | { |
| 866 | if (anobj.IsNull() || anobj->IsAutoHilight()) |
| 867 | return; |
| 868 | |
| 869 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
| 870 | Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection(); |
| 871 | |
| 872 | SelectMgr_SequenceOfOwner aSeq; |
| 873 | for ( Sel->Init(); Sel->More(); Sel->Next() ){ |
| 874 | Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(Sel->Value()); |
| 875 | |
| 876 | if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj ) |
| 877 | aSeq.Append( aOwner ); |
| 878 | } |
| 879 | |
| 880 | if ( aSeq.Length() ) |
| 881 | anobj->HilightSelected( myMainPM, aSeq ); |
| 882 | else |
| 883 | anobj->ClearSelected(); |
| 884 | |
| 885 | if(updateviewer){ |
| 886 | myCTX->CurrentViewer()->Update(); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | //================================================== |
| 891 | // Function: ClearSelected |
| 892 | // Purpose : |
| 893 | //================================================== |
| 894 | void AIS_LocalContext::ClearSelected (const Standard_Boolean updateviewer) |
| 895 | { |
| 896 | UnhilightPicked(updateviewer); |
| 897 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
| 898 | |
| 899 | Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection(); |
| 900 | #if !defined OCC189 && !defined USE_MAP |
| 901 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
| 902 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){ |
| 903 | const Handle(Standard_Transient)& Tr = Obj(i); |
| 904 | #else |
| 905 | const AIS_NListTransient& Obj = Sel->Objects(); |
| 906 | AIS_NListTransient::Iterator anIter( Obj ); |
| 907 | for(; anIter.More(); anIter.Next()){ |
| 908 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
| 909 | #endif |
| 910 | if(!Tr.IsNull()) |
| 911 | { |
| 912 | (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False); |
| 913 | } |
| 914 | } |
| 915 | AIS_Selection::Select(); |
| 916 | mylastindex = 0; |
| 917 | } |
| 918 | |
| 919 | |
| 920 | //======================================================================= |
| 921 | //function : SetSelected |
| 922 | //purpose : |
| 923 | //======================================================================= |
| 924 | void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj, |
| 925 | const Standard_Boolean updateviewer) |
| 926 | { |
| 927 | if(!IsValidForSelection(anIObj)) return; |
| 928 | UnhilightPicked(Standard_False); |
| 929 | |
| 930 | //1st case, owner already <anIObj> as owner |
| 931 | // and not separated is found... |
| 932 | |
| 933 | Handle(AIS_Selection) sel = AIS_Selection::Selection(mySelName.ToCString()); |
| 934 | //Standard_Boolean found(Standard_False); |
| 935 | Handle(Standard_Transient) Tr; |
| 936 | Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj); |
| 937 | if(EO.IsNull()){ |
| 938 | //check if in selection number 0 there is an owner that can be triturated... |
| 939 | if(anIObj->HasSelection(0)){ |
| 940 | const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0); |
| 941 | SIOBJ->Init(); |
| 942 | if(SIOBJ->More()){ |
| 943 | Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId(); |
| 944 | EO = *((Handle(SelectMgr_EntityOwner)*)&BO); |
| 945 | } |
| 946 | } |
| 947 | if(EO.IsNull()) |
| 948 | EO = new SelectMgr_EntityOwner(anIObj); |
| 949 | } |
| 950 | |
| 951 | ClearSelected(Standard_False); |
| 952 | |
| 953 | AIS_Selection::Select(EO); |
| 954 | EO->SetSelected (Standard_True); |
| 955 | |
| 956 | HilightPicked(updateviewer); |
| 957 | } |
| 958 | |
| 959 | //======================================================================= |
| 960 | //function : AddOrRemoveSelected |
| 961 | //purpose : |
| 962 | //======================================================================= |
| 963 | |
| 964 | void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj, |
| 965 | const Standard_Boolean updateviewer) |
| 966 | { |
| 967 | if(!IsValidForSelection(anIObj)) return; |
| 968 | UnhilightPicked(Standard_False); |
| 969 | // first check if it is selected... |
| 970 | Handle(SelectMgr_EntityOwner) EO; |
| 971 | |
| 972 | EO = FindSelectedOwnerFromIO(anIObj); |
| 973 | |
| 974 | if (EO.IsNull()) |
| 975 | { |
| 976 | if(anIObj->HasSelection(0)) |
| 977 | { |
| 978 | const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0); |
| 979 | SIOBJ->Init(); |
| 980 | if(SIOBJ->More()) |
| 981 | { |
| 982 | Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId(); |
| 983 | EO = *((Handle(SelectMgr_EntityOwner)*)&BO); |
| 984 | } |
| 985 | } |
| 986 | if(EO.IsNull()) |
| 987 | { |
| 988 | EO = new SelectMgr_EntityOwner(anIObj); |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | // cout<<"AIS_LocalContext::AddOrRemoveSelected : Selection = "<<mySelName<<endl; |
| 993 | const Handle(AIS_Selection)& S = AIS_Selection::Selection(mySelName.ToCString()); |
| 994 | |
| 995 | if (!S.IsNull()) |
| 996 | { |
| 997 | AIS_SelectStatus aStatus = S->Select(EO); |
| 998 | EO->SetSelected (aStatus == AIS_SS_Added); |
| 999 | } |
| 1000 | |
| 1001 | HilightPicked(updateviewer); |
| 1002 | } |
| 1003 | |
| 1004 | //======================================================================= |
| 1005 | //function : AddOrRemoveSelected |
| 1006 | //purpose : To check... |
| 1007 | //======================================================================= |
| 1008 | void AIS_LocalContext::AddOrRemoveSelected(const TopoDS_Shape& Sh, |
| 1009 | const Standard_Boolean updateviewer) |
| 1010 | { |
| 1011 | UnhilightPicked (Standard_False); |
| 1012 | Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromShape(Sh); |
| 1013 | if (!EO.IsNull()) |
| 1014 | { |
| 1015 | AIS_Selection::Selection(mySelName.ToCString())->Select(EO); |
| 1016 | EO->SetSelected (Standard_True); |
| 1017 | } |
| 1018 | HilightPicked (updateviewer); |
| 1019 | } |
| 1020 | |
| 1021 | void AIS_LocalContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner, |
| 1022 | const Standard_Boolean toUpdateViewer) |
| 1023 | { |
| 1024 | if(myAutoHilight) |
| 1025 | { |
| 1026 | UnhilightPicked (Standard_False); |
| 1027 | } |
| 1028 | |
| 1029 | Standard_Boolean toSelect = theOwner->IsSelected() ? Standard_False : Standard_True; |
| 1030 | |
| 1031 | AIS_Selection::Selection (mySelName.ToCString())->Select (theOwner); |
| 1032 | theOwner->SetSelected (toSelect); |
| 1033 | |
| 1034 | if(myAutoHilight) |
| 1035 | { |
| 1036 | HilightPicked (toUpdateViewer); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | //================================================== |
| 1041 | // Function: manageDetected |
| 1042 | // Purpose : |
| 1043 | //================================================== |
| 1044 | void AIS_LocalContext::manageDetected (const Handle(SelectMgr_EntityOwner)& thePickOwner, |
| 1045 | const Handle(V3d_View)& theView, |
| 1046 | const Standard_Boolean theToRedrawImmediate) |
| 1047 | { |
| 1048 | if (thePickOwner.IsNull()) |
| 1049 | { |
| 1050 | if (theToRedrawImmediate) |
| 1051 | { |
| 1052 | theView->RedrawImmediate(); |
| 1053 | } |
| 1054 | return; |
| 1055 | } |
| 1056 | |
| 1057 | if (!myFilters->IsOk (thePickOwner)) |
| 1058 | { |
| 1059 | if (mylastindex != 0) |
| 1060 | { |
| 1061 | mylastgood = mylastindex; |
| 1062 | } |
| 1063 | if (theToRedrawImmediate) |
| 1064 | { |
| 1065 | theView->RedrawImmediate(); |
| 1066 | } |
| 1067 | return; |
| 1068 | } |
| 1069 | |
| 1070 | //======================================================================================================= |
| 1071 | // 2 cases : a- object is in the map of picks: |
| 1072 | // 1. this is the same index as the last detected: -> Do nothing |
| 1073 | // 2. otherwise : |
| 1074 | // - if lastindex = 0 (no object was detected at the last step) |
| 1075 | // the object presentation is highlighted and lastindex = index(objet) |
| 1076 | // - othrwise : |
| 1077 | // the presentation of the object corresponding to lastindex is "unhighlighted" |
| 1078 | // it is removed if the object is not visualized but only active |
| 1079 | // then the presentation of the detected object is highlighted and lastindex = index(objet) |
| 1080 | // b- the object is not in the map of picked objects |
| 1081 | // - if lastindex != 0 (object detected at the last step) it is unhighlighted ... |
| 1082 | // if the object was decomposed, presentation is created for the detected shape and the couple |
| 1083 | // (Proprietaire,Prs)is added in the map. |
| 1084 | // otherwise the couple(proprietaire, NullPrs) is placed in the map and the interactive object |
| 1085 | // itself is highlighted. |
| 1086 | // |
| 1087 | //======================================================================================================= |
| 1088 | |
| 1089 | const Standard_Integer aNewIndex = myMapOfOwner.Contains (thePickOwner) |
| 1090 | ? myMapOfOwner.FindIndex (thePickOwner) |
| 1091 | : myMapOfOwner.Add (thePickOwner); |
| 1092 | |
| 1093 | // For the advanced mesh selection mode the owner indices comparison |
| 1094 | // is not effective because in that case only one owner manage the |
| 1095 | // selection in current selection mode. It is necessary to check the current detected |
| 1096 | // entity and hilight it only if the detected entity is not the same as |
| 1097 | // previous detected (IsForcedHilight call) |
| 1098 | if (aNewIndex != mylastindex |
| 1099 | || thePickOwner->IsForcedHilight()) |
| 1100 | { |
| 1101 | if (mylastindex != 0 |
| 1102 | && mylastindex <= myMapOfOwner.Extent()) |
| 1103 | { |
| 1104 | const Handle(SelectMgr_EntityOwner)& aLastOwner = myMapOfOwner (mylastindex); |
| 1105 | Unhilight (aLastOwner, theView); |
| 1106 | } |
| 1107 | |
| 1108 | if (myAutoHilight) |
| 1109 | { |
| 1110 | if (!thePickOwner->IsSelected() || myCTX->ToHilightSelected()) |
| 1111 | { |
| 1112 | Hilight (thePickOwner, theView); |
| 1113 | } |
| 1114 | if (theToRedrawImmediate) |
| 1115 | { |
| 1116 | theView->RedrawImmediate(); |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | mylastindex = aNewIndex; |
| 1121 | } |
| 1122 | |
| 1123 | if (mylastindex) |
| 1124 | { |
| 1125 | mylastgood = mylastindex; |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | //======================================================================= |
| 1130 | //function : HasDetectedShape |
| 1131 | //purpose : |
| 1132 | //======================================================================= |
| 1133 | |
| 1134 | Standard_Boolean AIS_LocalContext::HasDetectedShape() const |
| 1135 | { |
| 1136 | if(mylastindex==0) return Standard_False; |
| 1137 | return IsShape(mylastindex); |
| 1138 | } |
| 1139 | |
| 1140 | //======================================================================= |
| 1141 | //function : DetectedShape |
| 1142 | //purpose : |
| 1143 | //======================================================================= |
| 1144 | |
| 1145 | const TopoDS_Shape& |
| 1146 | AIS_LocalContext::DetectedShape() const |
| 1147 | { |
| 1148 | static TopoDS_Shape bidsh; |
| 1149 | if(mylastindex != 0) |
| 1150 | { |
| 1151 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex)); |
| 1152 | if(BROwnr.IsNull()) return bidsh; |
| 1153 | return BROwnr->Shape(); |
| 1154 | } |
| 1155 | return bidsh; |
| 1156 | } |
| 1157 | |
| 1158 | //======================================================================= |
| 1159 | //function : DetectedInteractive |
| 1160 | //purpose : |
| 1161 | //======================================================================= |
| 1162 | |
| 1163 | Handle(AIS_InteractiveObject) |
| 1164 | AIS_LocalContext::DetectedInteractive() const |
| 1165 | { |
| 1166 | Handle(AIS_InteractiveObject) Iobj; |
| 1167 | if(IsValidIndex(mylastindex)){ |
| 1168 | Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable(); |
| 1169 | Iobj = *((Handle(AIS_InteractiveObject)*) &SO); |
| 1170 | } |
| 1171 | return Iobj; |
| 1172 | } |
| 1173 | //======================================================================= |
| 1174 | //function : DetectedInteractive |
| 1175 | //purpose : |
| 1176 | //======================================================================= |
| 1177 | Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const |
| 1178 | { |
| 1179 | Handle(SelectMgr_EntityOwner) bid; |
| 1180 | if(!IsValidIndex(mylastindex)) return bid; |
| 1181 | return myMapOfOwner.FindKey(mylastindex); |
| 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | //======================================================================= |
| 1186 | //function : ComesFromDecomposition |
| 1187 | //purpose : |
| 1188 | //======================================================================= |
| 1189 | |
| 1190 | Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const |
| 1191 | { |
| 1192 | const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex); |
| 1193 | Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable(); |
| 1194 | if (myActiveObjects.IsBound (aSel)) { // debug of jmi |
| 1195 | const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel); |
| 1196 | return Stat->Decomposed(); |
| 1197 | } |
| 1198 | return Standard_False; |
| 1199 | } |
| 1200 | |
| 1201 | |
| 1202 | //======================================================================= |
| 1203 | //function : DisplayAreas |
| 1204 | //purpose : |
| 1205 | //======================================================================= |
| 1206 | |
| 1207 | void AIS_LocalContext::DisplayAreas(const Handle(V3d_View)& aviou) |
| 1208 | { |
| 1209 | myMainVS->DisplayAreas(aviou); |
| 1210 | } |
| 1211 | |
| 1212 | //======================================================================= |
| 1213 | //function : ClearAreas |
| 1214 | //purpose : |
| 1215 | //======================================================================= |
| 1216 | |
| 1217 | void AIS_LocalContext::ClearAreas(const Handle(V3d_View)& aviou) |
| 1218 | { |
| 1219 | myMainVS->ClearAreas(aviou); |
| 1220 | } |
| 1221 | |
| 1222 | //======================================================================= |
| 1223 | //function : DisplaySensitive |
| 1224 | //purpose : |
| 1225 | //======================================================================= |
| 1226 | |
| 1227 | void AIS_LocalContext::DisplaySensitive(const Handle(V3d_View)& aviou) |
| 1228 | { |
| 1229 | myMainVS->DisplaySensitive(aviou); |
| 1230 | } |
| 1231 | |
| 1232 | //======================================================================= |
| 1233 | //function : ClearSensitive |
| 1234 | //purpose : |
| 1235 | //======================================================================= |
| 1236 | |
| 1237 | void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou) |
| 1238 | { |
| 1239 | myMainVS->ClearSensitive(aviou); |
| 1240 | } |
| 1241 | |
| 1242 | |
| 1243 | //======================================================================= |
| 1244 | //function : IsShape |
| 1245 | //purpose : |
| 1246 | //======================================================================= |
| 1247 | Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const |
| 1248 | { |
| 1249 | |
| 1250 | if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull()) |
| 1251 | return Standard_False; |
| 1252 | return |
| 1253 | ComesFromDecomposition(Index); |
| 1254 | } |
| 1255 | |
| 1256 | Standard_Boolean AIS_LocalContext::IsValidForSelection(const Handle(AIS_InteractiveObject)& anIObj) const |
| 1257 | { |
| 1258 | |
| 1259 | #ifdef IMP120701 |
| 1260 | // Shape was not transfered from AIS_Shape to EntityOwner |
| 1261 | Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(anIObj); |
| 1262 | if( !shape.IsNull() ) |
| 1263 | return myFilters->IsOk(new StdSelect_BRepOwner(shape->Shape(),shape)); |
| 1264 | #endif |
| 1265 | return myFilters->IsOk(new SelectMgr_EntityOwner(anIObj)); |
| 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | //======================================================================= |
| 1270 | //function : HilightNextDetected |
| 1271 | //purpose : |
| 1272 | //======================================================================= |
| 1273 | Standard_Integer AIS_LocalContext::HilightNextDetected (const Handle(V3d_View)& theView, |
| 1274 | const Standard_Boolean theToRedrawImmediate) |
| 1275 | { |
| 1276 | // go to the next owner |
| 1277 | if (myDetectedSeq.IsEmpty()) |
| 1278 | { |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
| 1282 | const Standard_Integer aLen = myDetectedSeq.Length(); |
| 1283 | if (++myCurDetected > aLen) |
| 1284 | { |
| 1285 | myCurDetected = 1; |
| 1286 | } |
| 1287 | Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myCurDetected); |
| 1288 | if (anOwner.IsNull()) |
| 1289 | { |
| 1290 | return 0; |
| 1291 | } |
| 1292 | manageDetected (anOwner, theView, theToRedrawImmediate); |
| 1293 | return myCurDetected; |
| 1294 | } |
| 1295 | |
| 1296 | //======================================================================= |
| 1297 | //function : HilightPreviousDetected |
| 1298 | //purpose : |
| 1299 | //======================================================================= |
| 1300 | Standard_Integer AIS_LocalContext::HilightPreviousDetected (const Handle(V3d_View)& theView, |
| 1301 | const Standard_Boolean theToRedrawImmediate) |
| 1302 | { |
| 1303 | if (myDetectedSeq.IsEmpty()) |
| 1304 | { |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | if (--myCurDetected < 1) |
| 1309 | { |
| 1310 | myCurDetected = 1; |
| 1311 | } |
| 1312 | Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myCurDetected); |
| 1313 | if (anOwner.IsNull()) |
| 1314 | { |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
| 1318 | manageDetected (anOwner, theView, theToRedrawImmediate); |
| 1319 | return myCurDetected; |
| 1320 | } |
| 1321 | |
| 1322 | //======================================================================= |
| 1323 | //function : UnhilightLastDetected |
| 1324 | //purpose : |
| 1325 | //======================================================================= |
| 1326 | Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)& theView) |
| 1327 | { |
| 1328 | if (!IsValidIndex (mylastindex)) |
| 1329 | { |
| 1330 | return Standard_False; |
| 1331 | } |
| 1332 | |
| 1333 | myMainPM->BeginImmediateDraw(); |
| 1334 | const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (mylastindex); |
| 1335 | const Standard_Integer aHilightMode = anOwner->HasSelectable() |
| 1336 | ? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable())) |
| 1337 | : 0; |
| 1338 | |
| 1339 | myMapOfOwner (mylastindex)->Unhilight (myMainPM, aHilightMode); |
| 1340 | myMainPM->EndImmediateDraw (theView); |
| 1341 | mylastindex = 0; |
| 1342 | return Standard_True; |
| 1343 | } |
| 1344 | |
| 1345 | //======================================================================= |
| 1346 | //function : FindSelectedOwnerFromIO |
| 1347 | //purpose : it is checked if one of the selected owners really presents IObj |
| 1348 | //======================================================================= |
| 1349 | Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO |
| 1350 | (const Handle(AIS_InteractiveObject)& anIObj) const |
| 1351 | { |
| 1352 | Handle(SelectMgr_EntityOwner) EO,bid; |
| 1353 | if (anIObj.IsNull()) return EO; |
| 1354 | |
| 1355 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
| 1356 | if(Sel.IsNull()) { |
| 1357 | #ifdef DEB |
| 1358 | cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection " |
| 1359 | <<mySelName<<" Nulle "<<endl; |
| 1360 | #endif |
| 1361 | return EO; |
| 1362 | } |
| 1363 | Standard_Boolean found(Standard_False); |
| 1364 | #if !defined OCC189 && !defined USE_MAP |
| 1365 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
| 1366 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){ |
| 1367 | const Handle(Standard_Transient)& Tr = Obj(i); |
| 1368 | #else |
| 1369 | const AIS_NListTransient& Obj = Sel->Objects(); |
| 1370 | AIS_NListTransient::Iterator anIter( Obj ); |
| 1371 | for(; anIter.More(); anIter.Next()){ |
| 1372 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
| 1373 | #endif |
| 1374 | if(!Tr.IsNull()){ |
| 1375 | EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
| 1376 | if(EO->HasSelectable()){ |
| 1377 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO); |
| 1378 | if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ |
| 1379 | if (anIObj == EO->Selectable()){ |
| 1380 | found =Standard_True; |
| 1381 | break; |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | } |
| 1386 | } |
| 1387 | if(found) return EO; |
| 1388 | return bid; |
| 1389 | } |
| 1390 | |
| 1391 | //======================================================================= |
| 1392 | //function : FindSelectedOwnerFromShape |
| 1393 | //purpose : it is checked if one of the selected owners really presents IObj |
| 1394 | //======================================================================= |
| 1395 | Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const TopoDS_Shape& sh) const |
| 1396 | { |
| 1397 | #ifdef OCC9026 |
| 1398 | Handle(SelectMgr_EntityOwner) EO, bid; |
| 1399 | #else |
| 1400 | Handle(SelectMgr_EntityOwner) EO; |
| 1401 | #endif |
| 1402 | if (sh.IsNull()) return EO; |
| 1403 | |
| 1404 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
| 1405 | if(Sel.IsNull()) { |
| 1406 | #ifdef DEB |
| 1407 | cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "<<mySelName<<" Nulle "<<endl; |
| 1408 | #endif |
| 1409 | return EO; |
| 1410 | } |
| 1411 | |
| 1412 | Standard_Boolean found(Standard_False); |
| 1413 | |
| 1414 | #ifdef OCC9026 |
| 1415 | if (!found) { |
| 1416 | SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive aSensitiveIt (myMainVS->Primitives()); |
| 1417 | for (; aSensitiveIt.More(); aSensitiveIt.Next()) { |
| 1418 | EO = Handle(SelectMgr_EntityOwner)::DownCast (aSensitiveIt.Value()->OwnerId()); |
| 1419 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO); |
| 1420 | if (!BROwnr.IsNull() && BROwnr->HasShape() && BROwnr->Shape() == sh) { |
| 1421 | found = Standard_True; |
| 1422 | break; |
| 1423 | } |
| 1424 | } |
| 1425 | } |
| 1426 | #else |
| 1427 | #if !defined OCC189 && !defined USE_MAP |
| 1428 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
| 1429 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){ |
| 1430 | const Handle(Standard_Transient)& Tr = Obj(i); |
| 1431 | #else |
| 1432 | const AIS_NListTransient& Obj = Sel->Objects(); |
| 1433 | AIS_NListTransient::Iterator anIter( Obj ); |
| 1434 | for(; anIter.More(); anIter.Next()){ |
| 1435 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
| 1436 | #endif |
| 1437 | if(!Tr.IsNull()){ |
| 1438 | |
| 1439 | EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
| 1440 | if(EO->HasShape()) |
| 1441 | if ( EO->Shape() == sh) |
| 1442 | found =Standard_True; |
| 1443 | break; |
| 1444 | } |
| 1445 | } |
| 1446 | #endif |
| 1447 | |
| 1448 | if(found) return EO; |
| 1449 | return bid; |
| 1450 | } |
| 1451 | |
| 1452 | #ifdef IMP160701 |
| 1453 | //======================================================================= |
| 1454 | //function : AIS_LocalContext::InitDetected |
| 1455 | //purpose : |
| 1456 | //======================================================================= |
| 1457 | void AIS_LocalContext::InitDetected() |
| 1458 | { |
| 1459 | myAISCurDetected = myAISDetectedSeq.Length()? 1 : 0; |
| 1460 | } |
| 1461 | |
| 1462 | //======================================================================= |
| 1463 | //function : AIS_LocalContext::MoreDetected |
| 1464 | //purpose : |
| 1465 | //======================================================================= |
| 1466 | Standard_Boolean AIS_LocalContext::MoreDetected() const |
| 1467 | { |
| 1468 | return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()); |
| 1469 | } |
| 1470 | |
| 1471 | //======================================================================= |
| 1472 | //function : AIS_LocalContext::NextDetected |
| 1473 | //purpose : |
| 1474 | //======================================================================= |
| 1475 | void AIS_LocalContext::NextDetected() |
| 1476 | { |
| 1477 | myAISCurDetected++; |
| 1478 | } |
| 1479 | |
| 1480 | //======================================================================= |
| 1481 | //function : DetectedCurrentShape |
| 1482 | //purpose : |
| 1483 | //======================================================================= |
| 1484 | const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const |
| 1485 | { |
| 1486 | static TopoDS_Shape aDummyShape; |
| 1487 | |
| 1488 | Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject()); |
| 1489 | |
| 1490 | if (aCurrentShape.IsNull()) |
| 1491 | { |
| 1492 | return aDummyShape; |
| 1493 | } |
| 1494 | |
| 1495 | return aCurrentShape->Shape(); |
| 1496 | } |
| 1497 | //======================================================================= |
| 1498 | //function : DetectedCurrentObject |
| 1499 | //purpose : |
| 1500 | //======================================================================= |
| 1501 | Handle(AIS_InteractiveObject) AIS_LocalContext::DetectedCurrentObject() const |
| 1502 | { |
| 1503 | return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL; |
| 1504 | } |
| 1505 | #endif |