| 1 | // Created on: 1997-01-17 |
| 2 | // Created by: Robert COUBLANC |
| 3 | // Copyright (c) 1997-1999 Matra Datavision |
| 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 8 | // This library is free software; you can redistribute it and/or modify it under |
| 9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
| 10 | // by the Free Software Foundation, with special exception defined in the file |
| 11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 12 | // distribution for complete text of the license and disclaimer of any warranty. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | //Modified by ROB : Traque des UpdateConversion intempestifs. |
| 18 | |
| 19 | #define BUC60688 //GG 25/05/00 Add SetSensitivity() methods. |
| 20 | |
| 21 | #define BUC60722 //GG_040900 Disable detection on an unviewable object |
| 22 | |
| 23 | #define IMP160701 //SZV Add InitDetected(),MoreDetected(),NextDetected(), |
| 24 | // DetectedCurrentShape(),DetectedCurrentObject() |
| 25 | // methods |
| 26 | |
| 27 | #define ALE70590 //GG Avoid raise especially under W2000-SP2 |
| 28 | // when opening many local context due to a |
| 29 | // system error in the selection name computation routine. |
| 30 | // Many thanks to Philippe CARRET for the helpfull he has |
| 31 | // give to accelerate the resolution of this problem. |
| 32 | |
| 33 | #include <AIS_LocalContext.ixx> |
| 34 | #include <SelectMgr_OrFilter.hxx> |
| 35 | #include <SelectMgr_CompositionFilter.hxx> |
| 36 | #include <AIS_LocalStatus.hxx> |
| 37 | #include <AIS_Shape.hxx> |
| 38 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
| 39 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
| 40 | #include <AIS_ListOfInteractive.hxx> |
| 41 | #include <AIS_DataMapIteratorOfDataMapOfSelStat.hxx> |
| 42 | #include <TopAbs_ShapeEnum.hxx> |
| 43 | #include <Graphic3d_Structure.hxx> |
| 44 | #include <Prs3d_LineAspect.hxx> |
| 45 | #include <Prs3d_PlaneAspect.hxx> |
| 46 | #include <Prs3d_PointAspect.hxx> |
| 47 | #include <Prs3d_Presentation.hxx> |
| 48 | #include <Aspect_TypeOfMarker.hxx> |
| 49 | #include <StdSelect_ShapeTypeFilter.hxx> |
| 50 | #include <AIS_Selection.hxx> |
| 51 | #include <V3d_Viewer.hxx> |
| 52 | #include <V3d_View.hxx> |
| 53 | #include <Visual3d_View.hxx> |
| 54 | |
| 55 | #ifdef ALE70590 |
| 56 | #include <stdio.h> |
| 57 | #else |
| 58 | #include <Standard_SStream.hxx> |
| 59 | #endif |
| 60 | |
| 61 | static TCollection_AsciiString AIS_Local_SelName(const Standard_Address address, |
| 62 | const Standard_Integer anIndex) |
| 63 | { |
| 64 | // TCollection_AsciiString SelName; |
| 65 | #ifdef ALE70590 |
| 66 | char string[100]; |
| 67 | sprintf(string,"%p_%d", address, anIndex); // works under any system |
| 68 | TCollection_AsciiString SelName(string); |
| 69 | #else |
| 70 | Standard_SStream stream; |
| 71 | stream<<address; // something is wrong here using the SStream because |
| 72 | // the following access to rdbuf crash for an unknown reason |
| 73 | // especially under W2000 with SP2 and sometime under WNT and W98. |
| 74 | // NOTE that stream is not ended by a NULL char and it's probably |
| 75 | // one of the reasons why this crash. |
| 76 | // In any case the resulting ascii string give a wrong and random |
| 77 | // name under WINDOWS ! |
| 78 | TCollection_AsciiString SelName(stream.rdbuf()->str()); |
| 79 | // SelName = TCollection_AsciiString("AIS_Local_"); |
| 80 | TCollection_AsciiString theind(anIndex); |
| 81 | SelName += "_"; |
| 82 | SelName += theind; |
| 83 | #endif |
| 84 | return SelName; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | //======================================================================= |
| 89 | //function : AIS_LocalContext |
| 90 | //purpose : |
| 91 | //======================================================================= |
| 92 | |
| 93 | |
| 94 | AIS_LocalContext::AIS_LocalContext(){} |
| 95 | |
| 96 | AIS_LocalContext::AIS_LocalContext(const Handle(AIS_InteractiveContext)& aCtx, |
| 97 | const Standard_Integer Index, |
| 98 | const Standard_Boolean LoadDisplayed, |
| 99 | const Standard_Boolean AcceptStandardModes, |
| 100 | const Standard_Boolean AcceptEraseOfTemp, |
| 101 | const Standard_Boolean /*BothViewers*/): |
| 102 | myCTX(aCtx), |
| 103 | myLoadDisplayed(LoadDisplayed), |
| 104 | myAcceptStdMode(AcceptStandardModes), |
| 105 | myAcceptErase(AcceptEraseOfTemp), |
| 106 | mySM(aCtx->SelectionManager()), |
| 107 | myMainVS(new StdSelect_ViewerSelector3d(aCtx->MainSelector()->Projector())), |
| 108 | myFilters(new SelectMgr_OrFilter()), |
| 109 | myAutoHilight(Standard_True), |
| 110 | mylastindex(0), |
| 111 | mylastgood(0), |
| 112 | myCurDetected(0) |
| 113 | #ifdef IMP160701 |
| 114 | ,myAISCurDetected(0) |
| 115 | #endif |
| 116 | { |
| 117 | // bind self to AIS_InteractiveContext::myLocalContexts. Further, the |
| 118 | // constructor executes logic that implies that the context is already |
| 119 | // created and mapped. |
| 120 | aCtx->myLocalContexts.Bind (Index, this); |
| 121 | |
| 122 | myMainPM = aCtx->MainPrsMgr(); |
| 123 | mySelName = AIS_Local_SelName(this, Index); |
| 124 | AIS_Selection::CreateSelection(mySelName.ToCString()); |
| 125 | |
| 126 | mySM->Add(myMainVS); |
| 127 | if(myLoadDisplayed) LoadContextObjects(); |
| 128 | Process(Standard_False); |
| 129 | |
| 130 | } |
| 131 | |
| 132 | |
| 133 | //======================================================================= |
| 134 | //function : SetContext |
| 135 | //purpose : |
| 136 | //======================================================================= |
| 137 | |
| 138 | void AIS_LocalContext::SetContext(const Handle(AIS_InteractiveContext)& aCtx) |
| 139 | { myCTX = aCtx;} |
| 140 | |
| 141 | //======================================================================= |
| 142 | //function : Display |
| 143 | //purpose : |
| 144 | //======================================================================= |
| 145 | |
| 146 | Standard_Boolean AIS_LocalContext::Display(const Handle(AIS_InteractiveObject)& anInteractive, |
| 147 | const Standard_Integer WhichMode, |
| 148 | const Standard_Boolean AllowShapeDecomposition, |
| 149 | const Standard_Integer ActivationMode) |
| 150 | { |
| 151 | if(myActiveObjects.IsBound(anInteractive)){ |
| 152 | const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive); |
| 153 | |
| 154 | if(STAT->DisplayMode() == -1){ |
| 155 | if(!myMainPM->IsDisplayed(anInteractive,WhichMode)) |
| 156 | myMainPM->Display(anInteractive,WhichMode); |
| 157 | if(STAT->IsTemporary()) |
| 158 | STAT->SetDisplayMode(WhichMode); |
| 159 | } |
| 160 | else if(STAT->DisplayMode()!=WhichMode && STAT->IsTemporary()){ |
| 161 | myMainPM->Erase(anInteractive,STAT->DisplayMode()); |
| 162 | STAT->SetDisplayMode(WhichMode); |
| 163 | if(!myMainPM->IsDisplayed(anInteractive,WhichMode)) |
| 164 | myMainPM->Display(anInteractive,WhichMode); |
| 165 | } |
| 166 | |
| 167 | if(ActivationMode!=-1){ |
| 168 | if(!STAT->IsActivated(ActivationMode)){ |
| 169 | STAT->ClearSelectionModes(); |
| 170 | mySM->Load(anInteractive,myMainVS); |
| 171 | STAT->AddSelectionMode(ActivationMode); |
| 172 | mySM->Activate(anInteractive,ActivationMode,myMainVS); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | else { |
| 177 | Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(); |
| 178 | |
| 179 | if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition) |
| 180 | Att->SetDecomposition(Standard_True); |
| 181 | else |
| 182 | Att->SetDecomposition(Standard_False); |
| 183 | // status temporary or not |
| 184 | if(myCTX->DisplayStatus(anInteractive) == AIS_DS_None || |
| 185 | myCTX->DisplayStatus(anInteractive) == AIS_DS_Temporary) |
| 186 | Att->SetTemporary(Standard_True); |
| 187 | else |
| 188 | Att->SetTemporary(Standard_False); |
| 189 | |
| 190 | |
| 191 | |
| 192 | if(!myCTX->IsDisplayed(anInteractive,WhichMode)){ |
| 193 | |
| 194 | //storing information.... |
| 195 | Att->SetDisplayMode(WhichMode); |
| 196 | if (ActivationMode!=-1) |
| 197 | Att->AddSelectionMode(ActivationMode); |
| 198 | Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode; |
| 199 | Att->SetHilightMode(HiMod); |
| 200 | |
| 201 | if(!myMainPM->IsDisplayed(anInteractive,WhichMode)) |
| 202 | myMainPM->Display(anInteractive,WhichMode); |
| 203 | |
| 204 | if(ActivationMode!=-1){ |
| 205 | mySM->Load(anInteractive,myMainVS); |
| 206 | mySM->Activate(anInteractive,ActivationMode,myMainVS); |
| 207 | } |
| 208 | } |
| 209 | else{ |
| 210 | Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode; |
| 211 | Att->SetHilightMode(HiMod); |
| 212 | } |
| 213 | myActiveObjects.Bind(anInteractive,Att); |
| 214 | } |
| 215 | Process(anInteractive); |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | return Standard_True; |
| 221 | } |
| 222 | |
| 223 | //======================================================================= |
| 224 | //function : Load |
| 225 | //purpose : |
| 226 | //======================================================================= |
| 227 | |
| 228 | Standard_Boolean AIS_LocalContext:: |
| 229 | Load(const Handle(AIS_InteractiveObject)& anInteractive, |
| 230 | const Standard_Boolean AllowShapeDecomposition, |
| 231 | const Standard_Integer ActivationMode) |
| 232 | { |
| 233 | if(myActiveObjects.IsBound(anInteractive)) return Standard_False; |
| 234 | Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(); |
| 235 | |
| 236 | if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition) |
| 237 | Att->SetDecomposition(Standard_True); |
| 238 | else |
| 239 | Att->SetDecomposition(Standard_False); |
| 240 | |
| 241 | if(!myCTX->IsDisplayed(anInteractive)) |
| 242 | Att->SetTemporary(Standard_True); |
| 243 | else |
| 244 | Att->SetTemporary(Standard_False); |
| 245 | Att->SetDisplayMode(-1); |
| 246 | |
| 247 | //storing information.... |
| 248 | if(ActivationMode!=-1) |
| 249 | Att->AddSelectionMode(ActivationMode); |
| 250 | Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode():0; |
| 251 | Att->SetHilightMode(HiMod); |
| 252 | //Action |
| 253 | |
| 254 | mySM->Load(anInteractive,myMainVS); |
| 255 | if(ActivationMode != -1){ |
| 256 | mySM->Activate(anInteractive,ActivationMode,myMainVS); |
| 257 | } |
| 258 | myActiveObjects.Bind(anInteractive,Att); |
| 259 | Process(anInteractive); |
| 260 | return Standard_True; |
| 261 | } |
| 262 | |
| 263 | //======================================================================= |
| 264 | //function : ClearPrs |
| 265 | //purpose : |
| 266 | //======================================================================= |
| 267 | |
| 268 | Standard_Boolean AIS_LocalContext:: |
| 269 | ClearPrs(const Handle(AIS_InteractiveObject)& anInteractive, |
| 270 | const Standard_Integer aMode) |
| 271 | { |
| 272 | if(!myActiveObjects.IsBound(anInteractive)) |
| 273 | return Standard_False; |
| 274 | |
| 275 | Standard_Boolean jobdone(Standard_False); |
| 276 | const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive); |
| 277 | |
| 278 | //Display step |
| 279 | if(STAT->IsSubIntensityOn()) { |
| 280 | STAT->SubIntensityOff(); |
| 281 | if(STAT->HilightMode()==aMode) |
| 282 | myMainPM->Unhighlight(anInteractive,STAT->HilightMode()); |
| 283 | } |
| 284 | myMainPM->Clear(anInteractive,aMode); // correction connexions 23/09/97 |
| 285 | jobdone = Standard_True; |
| 286 | if(STAT->DisplayMode()==aMode) |
| 287 | STAT->SetDisplayMode(-1); |
| 288 | return jobdone; |
| 289 | } |
| 290 | //======================================================================= |
| 291 | //function : Erase |
| 292 | //purpose : |
| 293 | //======================================================================= |
| 294 | |
| 295 | Standard_Boolean AIS_LocalContext:: |
| 296 | Erase(const Handle(AIS_InteractiveObject)& anInteractive) |
| 297 | { |
| 298 | if(!myActiveObjects.IsBound(anInteractive)) |
| 299 | return Standard_False; |
| 300 | const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive); |
| 301 | |
| 302 | //Display step |
| 303 | if(STAT->IsSubIntensityOn()) { |
| 304 | STAT->SubIntensityOff(); |
| 305 | myMainPM->Unhighlight(anInteractive,STAT->HilightMode()); |
| 306 | } |
| 307 | |
| 308 | Standard_Boolean status(Standard_False); |
| 309 | |
| 310 | if(STAT->DisplayMode()!=-1) { |
| 311 | if(IsSelected(anInteractive)) |
| 312 | AddOrRemoveSelected(anInteractive); |
| 313 | if(myMainPM->IsHighlighted(anInteractive,STAT->HilightMode())) |
| 314 | myMainPM->Unhighlight(anInteractive,STAT->HilightMode()); |
| 315 | myMainPM->SetVisibility (anInteractive, STAT->DisplayMode(), Standard_False); |
| 316 | STAT->SetDisplayMode(-1); |
| 317 | status = Standard_True; |
| 318 | } |
| 319 | if(STAT->IsTemporary()){ |
| 320 | if(myMainPM->IsDisplayed(anInteractive,STAT->HilightMode())) |
| 321 | myMainPM->SetVisibility (anInteractive, STAT->HilightMode(), Standard_False); |
| 322 | } |
| 323 | //selection step |
| 324 | |
| 325 | TColStd_ListIteratorOfListOfInteger It(STAT->SelectionModes()); |
| 326 | for(;It.More();It.Next()) |
| 327 | mySM->Deactivate(anInteractive,It.Value(),myMainVS); |
| 328 | // STAT->ClearSelectionModes(); |
| 329 | return status; |
| 330 | } |
| 331 | |
| 332 | |
| 333 | //======================================================================= |
| 334 | //function : SetShapeDecomposition |
| 335 | //purpose : |
| 336 | //======================================================================= |
| 337 | |
| 338 | void AIS_LocalContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& aStoredObject, |
| 339 | const Standard_Boolean aStatus) |
| 340 | { |
| 341 | if(!myActiveObjects.IsBound(aStoredObject)) return; |
| 342 | |
| 343 | if(aStatus == myActiveObjects(aStoredObject)->Decomposed()) |
| 344 | return; |
| 345 | |
| 346 | myActiveObjects(aStoredObject)->SetDecomposition(aStatus); |
| 347 | |
| 348 | Process(aStoredObject); |
| 349 | } |
| 350 | |
| 351 | //======================================================================= |
| 352 | //function : Clear |
| 353 | //purpose : |
| 354 | //======================================================================= |
| 355 | |
| 356 | void AIS_LocalContext::Clear(const AIS_ClearMode aType) |
| 357 | { |
| 358 | switch (aType){ |
| 359 | case AIS_CM_All: |
| 360 | { |
| 361 | ClearObjects(); |
| 362 | myFilters->Clear(); |
| 363 | while(!myListOfStandardMode.IsEmpty()) |
| 364 | DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last())); |
| 365 | break; |
| 366 | } |
| 367 | case AIS_CM_Interactive: |
| 368 | ClearObjects(); |
| 369 | break; |
| 370 | case AIS_CM_Filters: |
| 371 | myFilters->Clear(); |
| 372 | break; |
| 373 | case AIS_CM_StandardModes: |
| 374 | { |
| 375 | while(!myListOfStandardMode.IsEmpty()) |
| 376 | DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last())); |
| 377 | break; |
| 378 | } |
| 379 | case AIS_CM_TemporaryShapePrs: |
| 380 | ClearDetected(); |
| 381 | } |
| 382 | UpdateSort(); |
| 383 | } |
| 384 | //======================================================================= |
| 385 | //function : ActivateMode |
| 386 | //purpose : |
| 387 | //======================================================================= |
| 388 | |
| 389 | void AIS_LocalContext::ActivateMode(const Handle(AIS_InteractiveObject)& aSelectable, |
| 390 | const Standard_Integer aMode) |
| 391 | { |
| 392 | if(!myActiveObjects.IsBound(aSelectable)) return; |
| 393 | // if(myActiveObjects(aSelectable)->SelectionMode()!=aMode) |
| 394 | // mySM->Deactivate(aSelectable,aMode,myMainVS); |
| 395 | if(aMode != -1){ |
| 396 | myActiveObjects(aSelectable)->AddSelectionMode(aMode); |
| 397 | mySM->Activate(aSelectable,aMode,myMainVS); |
| 398 | } |
| 399 | UpdateSort(); |
| 400 | } |
| 401 | //======================================================================= |
| 402 | //function : ActivateMode |
| 403 | //purpose : |
| 404 | //======================================================================= |
| 405 | |
| 406 | void AIS_LocalContext::DeactivateMode(const Handle(AIS_InteractiveObject)& aSelectable, |
| 407 | const Standard_Integer aMode) |
| 408 | { |
| 409 | if(!myActiveObjects.IsBound(aSelectable)) return; |
| 410 | |
| 411 | if(aMode==-1) return; |
| 412 | |
| 413 | myActiveObjects(aSelectable)->RemoveSelectionMode(aMode); |
| 414 | mySM->Deactivate(aSelectable,aMode,myMainVS); |
| 415 | UpdateSort(); |
| 416 | |
| 417 | } |
| 418 | //======================================================================= |
| 419 | //function : ActivateMode |
| 420 | //purpose : |
| 421 | //======================================================================= |
| 422 | |
| 423 | void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectable) |
| 424 | { |
| 425 | if(!myActiveObjects.IsBound(aSelectable)) return; |
| 426 | |
| 427 | mySM->Deactivate(aSelectable,myMainVS); |
| 428 | myActiveObjects(aSelectable)->ClearSelectionModes(); |
| 429 | UpdateSort(); |
| 430 | } |
| 431 | |
| 432 | //======================================================================= |
| 433 | //function : Remove |
| 434 | //purpose : |
| 435 | //======================================================================= |
| 436 | |
| 437 | Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& aSelectable) |
| 438 | { |
| 439 | if(!myActiveObjects.IsBound(aSelectable)) return Standard_False; |
| 440 | |
| 441 | if(IsSelected(aSelectable)) |
| 442 | AddOrRemoveSelected(aSelectable,Standard_False); |
| 443 | |
| 444 | const Handle(AIS_LocalStatus)& Att = myActiveObjects(aSelectable); |
| 445 | |
| 446 | TColStd_ListIteratorOfListOfInteger It; |
| 447 | // it is checked which were the temporary attributes |
| 448 | // and they are set to 0 |
| 449 | |
| 450 | // desactivate standard modes |
| 451 | if(Att->Decomposed()){ |
| 452 | for(It.Initialize(myListOfStandardMode);It.More();It.Next()){ |
| 453 | mySM->Deactivate(aSelectable,It.Value(),myMainVS); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | // if object or temporary presentations... |
| 458 | if(Att->IsTemporary()) |
| 459 | { |
| 460 | if(Att->IsSubIntensityOn()) |
| 461 | myMainPM->Unhighlight(aSelectable,Att->HilightMode()); |
| 462 | |
| 463 | // remove if bug on clear correct... |
| 464 | myMainPM->Erase(aSelectable,Att->DisplayMode()); |
| 465 | myMainPM->Clear(aSelectable,Att->DisplayMode()); |
| 466 | if(myMainPM->IsDisplayed(aSelectable,Att->HilightMode())) |
| 467 | myMainPM->Erase(aSelectable,Att->HilightMode()); |
| 468 | // myMainPM->Clear(aSelectable,Att->HilightMode()); |
| 469 | } |
| 470 | // if below intensity |
| 471 | else |
| 472 | { |
| 473 | if(Att->IsSubIntensityOn()) |
| 474 | myCTX->SubIntensityOff(aSelectable); |
| 475 | } |
| 476 | // desactivate stored proper modes |
| 477 | for(It.Initialize(Att->SelectionModes());It.More();It.Next()){ |
| 478 | mySM->Deactivate(aSelectable,It.Value(),myMainVS); |
| 479 | } |
| 480 | // pop : si je laisses cela plantes dans les elements de construction |
| 481 | // alors a toi de jouer ROB |
| 482 | // RemoveSelected(aSelectable); |
| 483 | |
| 484 | if(IsSelected(aSelectable)) |
| 485 | AddOrRemoveSelected(aSelectable); |
| 486 | myActiveObjects.UnBind(aSelectable); |
| 487 | |
| 488 | //Last detected object keeps for lastindex initialization. |
| 489 | Handle(SelectMgr_EntityOwner) aLastPicked = myMainVS->OnePicked(); |
| 490 | |
| 491 | UpdateSort(); |
| 492 | |
| 493 | //Object removes from SelectMgr |
| 494 | if( mySM->Contains(aSelectable) ) |
| 495 | mySM->Remove(aSelectable); |
| 496 | |
| 497 | //Object removes from Detected sequence |
| 498 | AIS_SequenceOfInteractive detectAIS; |
| 499 | |
| 500 | Standard_Integer i = 1; |
| 501 | for(i = 1 ; i < myAISDetectedSeq.Length(); i++) |
| 502 | { |
| 503 | Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject(); |
| 504 | if( !anObj.IsNull() && anObj != aSelectable ) |
| 505 | myAISDetectedSeq.Remove( i ); |
| 506 | } |
| 507 | |
| 508 | Standard_Integer aHM = aSelectable->HasHilightMode() ? aSelectable->HilightMode() : 0; |
| 509 | |
| 510 | //EntityOwners remove from AIS_Selection |
| 511 | Handle(AIS_Selection) aSel = AIS_Selection::Selection(mySelName.ToCString()); |
| 512 | AIS_NListTransient::Iterator anIter(aSel->Objects()); |
| 513 | AIS_NListTransient removeEntites; |
| 514 | for(; anIter.More(); anIter.Next()){ |
| 515 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
| 516 | if (!Tr.IsNull()){ |
| 517 | const Handle(SelectMgr_EntityOwner)& anOwnr = *((const Handle(SelectMgr_EntityOwner)*) &Tr); |
| 518 | if(anOwnr->Selectable() == aSelectable){ |
| 519 | removeEntites.Append(Tr); |
| 520 | if(IsSelected(anOwnr)) |
| 521 | anOwnr->Unhilight(myMainPM, aHM);//Unhilight selected |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | AIS_NListTransient::Iterator anIterRemove(removeEntites); |
| 526 | for(; anIterRemove.More(); anIterRemove.Next()) |
| 527 | aSel->Select(anIterRemove.Value());//EntityOwner removes from the selection data |
| 528 | |
| 529 | //EntityOwners remove from myMapOfOwner |
| 530 | SelectMgr_IndexedMapOfOwner ownersToKeep; |
| 531 | const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer(); |
| 532 | for(i = 1; i <= myMapOfOwner.Extent(); i++){ |
| 533 | const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner(i) ; |
| 534 | if(!anOwner.IsNull()) { |
| 535 | if(anOwner->Selectable() != aSelectable) |
| 536 | ownersToKeep.Add(anOwner); |
| 537 | else |
| 538 | { |
| 539 | if(anOwner->IsHilighted(myMainPM, aHM)) |
| 540 | { |
| 541 | for(aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
| 542 | Unhilight(anOwner, aViewer->ActiveView()); |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | myMapOfOwner.Clear(); |
| 548 | myMapOfOwner.Assign(ownersToKeep); |
| 549 | mylastindex = myMapOfOwner.FindIndex(aLastPicked); |
| 550 | |
| 551 | return Standard_True; |
| 552 | } |
| 553 | |
| 554 | //======================================================================= |
| 555 | //function : ActivateStandardMode |
| 556 | //purpose : |
| 557 | //======================================================================= |
| 558 | |
| 559 | void AIS_LocalContext::ActivateStandardMode(const TopAbs_ShapeEnum aType) |
| 560 | { |
| 561 | |
| 562 | //check if it is not in the list |
| 563 | TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode); |
| 564 | for(;It.More();It.Next()) |
| 565 | if(It.Value()==aType) return; |
| 566 | Standard_Integer IMode = AIS_Shape::SelectionMode(aType); |
| 567 | |
| 568 | |
| 569 | // create a hidden filter answering ok to the type except for : |
| 570 | // if the type is shape... |
| 571 | // if the filters already impact at the type <aType> |
| 572 | if(aType != TopAbs_SHAPE){ |
| 573 | if(myStdFilters[IMode].IsNull()) |
| 574 | myStdFilters[IMode] = new StdSelect_ShapeTypeFilter(aType); |
| 575 | if(!HasFilters(aType)) |
| 576 | myFilters->Add(myStdFilters[IMode]); |
| 577 | } |
| 578 | |
| 579 | // the mode is activated for all objects of type Shape |
| 580 | // accepting the decomposition in standard mode. |
| 581 | myListOfStandardMode.Append(IMode); |
| 582 | |
| 583 | AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects); |
| 584 | |
| 585 | for(;ItM.More();ItM.Next()){ |
| 586 | if(ItM.Value()->Decomposed()) |
| 587 | myCTX->SelectionManager()->Activate(ItM.Key(), |
| 588 | IMode, |
| 589 | myMainVS); |
| 590 | } |
| 591 | |
| 592 | } |
| 593 | |
| 594 | //======================================================================= |
| 595 | //function : DeActivateStandardMode |
| 596 | //purpose : |
| 597 | //======================================================================= |
| 598 | |
| 599 | void AIS_LocalContext::DeactivateStandardMode(const TopAbs_ShapeEnum aType) |
| 600 | { |
| 601 | TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode); |
| 602 | Standard_Integer IMode = AIS_Shape::SelectionMode(aType); |
| 603 | for(;It.More();It.Next()) |
| 604 | if(It.Value()==IMode) { |
| 605 | AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects); |
| 606 | |
| 607 | for(;ItM.More();ItM.Next()){ |
| 608 | if(ItM.Value()->Decomposed()){ |
| 609 | myCTX->SelectionManager()->Deactivate(ItM.Key(), |
| 610 | IMode, |
| 611 | myMainVS); |
| 612 | ItM.Value()->RemoveSelectionMode(IMode); |
| 613 | } |
| 614 | } |
| 615 | myListOfStandardMode.Remove(It); |
| 616 | if(myFilters->IsIn(myStdFilters[IMode])) |
| 617 | myFilters->Remove(myStdFilters[IMode]); |
| 618 | UpdateSort(); |
| 619 | return; |
| 620 | } |
| 621 | UpdateSort(); |
| 622 | } |
| 623 | |
| 624 | //======================================================================= |
| 625 | //function : AddFilter |
| 626 | //purpose : |
| 627 | //======================================================================= |
| 628 | |
| 629 | void AIS_LocalContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter) |
| 630 | { |
| 631 | // it is checked if the filter impacts at the type of active sub-shape |
| 632 | // for which a filter of type has been already implemented... |
| 633 | |
| 634 | TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode); |
| 635 | |
| 636 | for(;It.More();It.Next()){ |
| 637 | if(aFilter->ActsOn(AIS_Shape::SelectionType(It.Value()))) |
| 638 | if(myFilters->IsIn(myStdFilters[It.Value()])) |
| 639 | myFilters->Remove(myStdFilters[It.Value()]); |
| 640 | } |
| 641 | myFilters->Add(aFilter); |
| 642 | } |
| 643 | |
| 644 | //======================================================================= |
| 645 | //function : RemoveFilter |
| 646 | //purpose : |
| 647 | //======================================================================= |
| 648 | |
| 649 | void AIS_LocalContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter) |
| 650 | { |
| 651 | if(myFilters->IsIn(aFilter)) myFilters->Remove(aFilter); |
| 652 | |
| 653 | // it is checked if the filter for type standard is active. |
| 654 | // if yes, it is checked there are still similarities among the |
| 655 | // remaining filters... |
| 656 | // otherwise, the standard filter is restored to |
| 657 | // continu selecting active modes... |
| 658 | TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode); |
| 659 | TopAbs_ShapeEnum SE; |
| 660 | for(;It.More();It.Next()){ |
| 661 | SE = AIS_Shape::SelectionType(It.Value()); |
| 662 | if(aFilter->ActsOn(SE)) |
| 663 | if(!HasFilters(SE)) |
| 664 | myFilters->Add(myStdFilters[It.Value()]); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | |
| 669 | |
| 670 | Standard_Boolean AIS_LocalContext::HasSameProjector(const Handle(Select3D_Projector)& thePrj) const |
| 671 | { |
| 672 | const Handle(Select3D_Projector)& aCurPrj = myMainVS->Projector(); |
| 673 | if (aCurPrj->Perspective() != thePrj->Perspective()) |
| 674 | return Standard_False; |
| 675 | if (aCurPrj->Perspective() && aCurPrj->Focus() != thePrj->Focus()) |
| 676 | return Standard_False; |
| 677 | const gp_GTrsf& aCurTrsf = aCurPrj->Transformation(); |
| 678 | const gp_GTrsf& aPrjTrsf = thePrj->Transformation(); |
| 679 | |
| 680 | for (Standard_Integer i = 1; i <= 3; ++i) |
| 681 | { |
| 682 | for (Standard_Integer j = 1; j <= 3 ; ++j) |
| 683 | { |
| 684 | if (aCurTrsf.Value (i, j) != aPrjTrsf.Value (i, j)) |
| 685 | return Standard_False; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | return Standard_True; |
| 690 | } |
| 691 | |
| 692 | |
| 693 | //======================================================================= |
| 694 | //function : Terminate |
| 695 | //purpose : |
| 696 | //======================================================================= |
| 697 | |
| 698 | void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate) |
| 699 | { |
| 700 | ClearDetected(); |
| 701 | Clear(); |
| 702 | myMapOfOwner.Clear(); |
| 703 | |
| 704 | mylastindex=0; |
| 705 | // clear the selector... |
| 706 | myMainVS->Clear(); |
| 707 | myCTX->SelectionManager()->Remove(myMainVS); |
| 708 | |
| 709 | |
| 710 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
| 711 | Handle(AIS_Selection) S = AIS_Selection::CurrentSelection(); |
| 712 | Handle(Standard_Transient) Tr; |
| 713 | for(S->Init();S->More();S->Next()){ |
| 714 | Tr = S->Value(); |
| 715 | (*((Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False); |
| 716 | } |
| 717 | |
| 718 | |
| 719 | AIS_Selection::Select(); |
| 720 | AIS_Selection::Remove(mySelName.ToCString()); |
| 721 | |
| 722 | Handle(V3d_Viewer) aViewer = myCTX->CurrentViewer(); |
| 723 | for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
| 724 | { |
| 725 | Handle(V3d_View) aView = aViewer->ActiveView(); |
| 726 | aView->View()->ClearImmediate(); |
| 727 | } |
| 728 | |
| 729 | Handle(V3d_View) aDummyView; |
| 730 | myMainVS->ClearAreas (aDummyView); |
| 731 | myMainVS->ClearSensitive (aDummyView); |
| 732 | |
| 733 | if (theToUpdate) |
| 734 | { |
| 735 | myCTX->UpdateCurrentViewer(); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | |
| 740 | //======================================================================= |
| 741 | //function : SubIntensity |
| 742 | //purpose : |
| 743 | //======================================================================= |
| 744 | |
| 745 | void AIS_LocalContext::SubIntensityOn(const Handle(AIS_InteractiveObject)& anObject) |
| 746 | { |
| 747 | if(!myActiveObjects.IsBound(anObject)) return; |
| 748 | |
| 749 | const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject); |
| 750 | |
| 751 | if(Att->IsTemporary()) |
| 752 | myMainPM->Color(anObject,myCTX->SubIntensityColor(),Att->DisplayMode()); |
| 753 | |
| 754 | Att->SubIntensityOn(); |
| 755 | } |
| 756 | //======================================================================= |
| 757 | //function : SubIntensity |
| 758 | //purpose : |
| 759 | //======================================================================= |
| 760 | |
| 761 | void AIS_LocalContext::SubIntensityOff(const Handle(AIS_InteractiveObject)& anObject) |
| 762 | { |
| 763 | if(!myActiveObjects.IsBound(anObject)) return; |
| 764 | |
| 765 | const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject); |
| 766 | |
| 767 | if(Att->IsTemporary()) |
| 768 | myMainPM->Unhighlight(anObject); |
| 769 | Att->SubIntensityOff(); |
| 770 | } |
| 771 | |
| 772 | |
| 773 | //======================================================================= |
| 774 | //function : Hilight |
| 775 | //purpose : |
| 776 | //======================================================================= |
| 777 | |
| 778 | void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject) |
| 779 | { |
| 780 | if(!myActiveObjects.IsBound(anObject)){ |
| 781 | Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0; |
| 782 | Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True, |
| 783 | Standard_False, |
| 784 | -1,-1,HiMod); |
| 785 | myActiveObjects.Bind(anObject,Att); |
| 786 | |
| 787 | } |
| 788 | const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject); |
| 789 | myMainPM->Color(anObject,myCTX->HilightColor(),Att->HilightMode()); |
| 790 | Att->SubIntensityOn(); |
| 791 | } |
| 792 | //======================================================================= |
| 793 | //function : Hilight |
| 794 | //purpose : |
| 795 | //======================================================================= |
| 796 | |
| 797 | void AIS_LocalContext::Hilight(const Handle(AIS_InteractiveObject)& anObject, |
| 798 | const Quantity_NameOfColor Col) |
| 799 | { |
| 800 | if(!myActiveObjects.IsBound(anObject)){ |
| 801 | Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0; |
| 802 | Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True, |
| 803 | Standard_False, |
| 804 | -1,-1,HiMod); |
| 805 | myActiveObjects.Bind(anObject,Att); |
| 806 | |
| 807 | } |
| 808 | const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject); |
| 809 | myMainPM->Color(anObject,Col,Att->HilightMode()); |
| 810 | Att->SubIntensityOn(); |
| 811 | Att->SetHilightColor(Col); |
| 812 | } |
| 813 | |
| 814 | //======================================================================= |
| 815 | //function : Unhilight |
| 816 | //purpose : |
| 817 | //======================================================================= |
| 818 | |
| 819 | void AIS_LocalContext::Unhilight(const Handle(AIS_InteractiveObject)& anObject) |
| 820 | { |
| 821 | if(!myActiveObjects.IsBound(anObject)) return; |
| 822 | |
| 823 | // chieck if by hazard the object is somewhere else... |
| 824 | Standard_Integer Indx; |
| 825 | Standard_Boolean IsSomeWhereElse = |
| 826 | myCTX->IsInLocal(anObject,Indx) && Indx != myCTX->IndexOfCurrentLocal(); |
| 827 | |
| 828 | const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject); |
| 829 | myMainPM->Unhighlight(anObject,Att->HilightMode()); |
| 830 | if(Att->IsTemporary() && Att->DisplayMode()==-1) |
| 831 | if(!IsSomeWhereElse) |
| 832 | myMainPM->SetVisibility (anObject, Att->HilightMode(), Standard_False); |
| 833 | |
| 834 | Att->SubIntensityOff(); |
| 835 | Att->SetHilightColor(Quantity_NOC_WHITE); |
| 836 | } |
| 837 | |
| 838 | |
| 839 | //======================================================================= |
| 840 | //function : IsIn |
| 841 | //purpose : |
| 842 | //======================================================================= |
| 843 | |
| 844 | Standard_Boolean AIS_LocalContext:: |
| 845 | IsIn(const Handle(AIS_InteractiveObject)& anObject) const |
| 846 | { |
| 847 | return myActiveObjects.IsBound(anObject); |
| 848 | } |
| 849 | |
| 850 | //======================================================================= |
| 851 | //function : IsHilighted |
| 852 | //purpose : |
| 853 | //======================================================================= |
| 854 | |
| 855 | Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject) const |
| 856 | { |
| 857 | if(!myActiveObjects.IsBound(anObject)) return Standard_False; |
| 858 | return myActiveObjects(anObject)->IsSubIntensityOn(); |
| 859 | } |
| 860 | |
| 861 | Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject, |
| 862 | Standard_Boolean& WithColor, |
| 863 | Quantity_NameOfColor& HiCol) const |
| 864 | { |
| 865 | if(!myActiveObjects.IsBound(anObject)) return Standard_False; |
| 866 | if( myActiveObjects(anObject)->IsSubIntensityOn()){ |
| 867 | HiCol = myActiveObjects(anObject)->HilightColor(); |
| 868 | if(HiCol==Quantity_NOC_WHITE) |
| 869 | WithColor = Standard_True; |
| 870 | else |
| 871 | WithColor = Standard_False; |
| 872 | return Standard_True; |
| 873 | } |
| 874 | return Standard_False; |
| 875 | } |
| 876 | |
| 877 | |
| 878 | void AIS_LocalContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& anObject, |
| 879 | const Standard_Integer Prior) |
| 880 | { |
| 881 | if(!myActiveObjects.IsBound(anObject)) return; |
| 882 | const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anObject); |
| 883 | if(STAT->DisplayMode()==-1) return; |
| 884 | myMainPM->SetDisplayPriority(anObject,STAT->DisplayMode(),Prior); |
| 885 | if(STAT->IsSubIntensityOn()) |
| 886 | myMainPM->SetDisplayPriority(anObject,STAT->HilightMode(),Prior); |
| 887 | |
| 888 | |
| 889 | } |
| 890 | |
| 891 | //======================================================================= |
| 892 | //function : DisplayedObjects |
| 893 | //purpose : |
| 894 | //======================================================================= |
| 895 | Standard_Integer AIS_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const |
| 896 | { |
| 897 | Standard_Integer NbDisp(0); |
| 898 | for(AIS_DataMapIteratorOfDataMapOfSelStat it(myActiveObjects);it.More();it.Next()){ |
| 899 | const Handle(SelectMgr_SelectableObject)& SO = it.Key(); |
| 900 | if(!theMap.Contains(SO)) |
| 901 | if(it.Value()->DisplayMode()!=-1){ |
| 902 | theMap.Add(SO); |
| 903 | NbDisp++; |
| 904 | } |
| 905 | } |
| 906 | return NbDisp; |
| 907 | } |
| 908 | |
| 909 | |
| 910 | //======================================================================= |
| 911 | //function : IsDisplayed |
| 912 | //purpose : |
| 913 | //======================================================================= |
| 914 | |
| 915 | Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject) const |
| 916 | { |
| 917 | if(!myActiveObjects.IsBound(anObject)) return Standard_False; |
| 918 | return (myActiveObjects(anObject)->DisplayMode()!=-1); |
| 919 | } |
| 920 | |
| 921 | //======================================================================= |
| 922 | //function : IsDisplayed |
| 923 | //purpose : |
| 924 | //======================================================================= |
| 925 | |
| 926 | Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject, |
| 927 | const Standard_Integer aMode) const |
| 928 | { |
| 929 | if(!myActiveObjects.IsBound(anObject)) return Standard_False; |
| 930 | return (myActiveObjects(anObject)->DisplayMode()==aMode); |
| 931 | } |
| 932 | |
| 933 | //======================================================================= |
| 934 | //function : SelectionModes |
| 935 | //purpose : |
| 936 | //======================================================================= |
| 937 | |
| 938 | const TColStd_ListOfInteger& AIS_LocalContext:: |
| 939 | SelectionModes(const Handle(AIS_InteractiveObject)& anObject) const |
| 940 | { |
| 941 | return myActiveObjects(anObject)->SelectionModes(); |
| 942 | } |
| 943 | |
| 944 | //======================================================================= |
| 945 | //function : Status |
| 946 | //purpose : |
| 947 | //======================================================================= |
| 948 | |
| 949 | TCollection_AsciiString AIS_LocalContext::Status() const |
| 950 | { |
| 951 | TCollection_AsciiString t; |
| 952 | return t; |
| 953 | } |
| 954 | |
| 955 | const Handle(AIS_LocalStatus)& AIS_LocalContext::Status(const Handle(AIS_InteractiveObject)& anObject) const |
| 956 | { |
| 957 | return myActiveObjects(anObject); |
| 958 | } |
| 959 | |
| 960 | //======================================================================= |
| 961 | //function : LoadContextObjects |
| 962 | //purpose : |
| 963 | //======================================================================= |
| 964 | |
| 965 | void AIS_LocalContext::LoadContextObjects() |
| 966 | { |
| 967 | AIS_ListIteratorOfListOfInteractive It; |
| 968 | if(myLoadDisplayed) { |
| 969 | AIS_ListOfInteractive LL; |
| 970 | myCTX->DisplayedObjects(LL,Standard_True); |
| 971 | Handle(AIS_LocalStatus) Att; |
| 972 | for (It.Initialize(LL);It.More();It.Next()){ |
| 973 | Att= new AIS_LocalStatus(); |
| 974 | Att->SetDecomposition((It.Value()->AcceptShapeDecomposition() && myAcceptStdMode)); |
| 975 | Att->SetTemporary(Standard_False); |
| 976 | Att->SetHilightMode(It.Value()->HasHilightMode()? It.Value()->HilightMode(): 0); |
| 977 | |
| 978 | myActiveObjects.Bind(It.Value(),Att); |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | void AIS_LocalContext::UnloadContextObjects() |
| 984 | { |
| 985 | AIS_ListIteratorOfListOfInteractive It; |
| 986 | if(myLoadDisplayed) |
| 987 | { |
| 988 | AIS_ListOfInteractive LL; |
| 989 | myCTX->DisplayedObjects(LL,Standard_True); |
| 990 | |
| 991 | for (It.Initialize(LL);It.More();It.Next()) |
| 992 | { |
| 993 | myActiveObjects.UnBind(It.Value()); |
| 994 | } |
| 995 | } |
| 996 | } |
| 997 | //======================================================================= |
| 998 | //function : Process |
| 999 | //purpose : |
| 1000 | //======================================================================= |
| 1001 | |
| 1002 | void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject, |
| 1003 | const Standard_Boolean WithProj) |
| 1004 | { |
| 1005 | if(!myActiveObjects.IsBound(anObject)) return; |
| 1006 | if(myActiveObjects(anObject)->Decomposed()) |
| 1007 | ActivateStandardModes(anObject,WithProj); |
| 1008 | else |
| 1009 | { |
| 1010 | TColStd_ListIteratorOfListOfInteger It(myActiveObjects(anObject)->SelectionModes()); |
| 1011 | for(;It.More();It.Next()) |
| 1012 | myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS,WithProj); |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | //======================================================================= |
| 1017 | //function : Process |
| 1018 | //purpose : |
| 1019 | //======================================================================= |
| 1020 | |
| 1021 | void AIS_LocalContext::Process(const Standard_Boolean WithProj) |
| 1022 | { |
| 1023 | |
| 1024 | myMainVS->Clear(); |
| 1025 | |
| 1026 | AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects); |
| 1027 | |
| 1028 | for(;It.More();It.Next()){ |
| 1029 | myCTX->SelectionManager()->Load(It.Key(),myMainVS); |
| 1030 | if(It.Value()->Decomposed()) |
| 1031 | ActivateStandardModes(It.Key(),WithProj); |
| 1032 | else if( myCTX->GetAutoActivateSelection() ) |
| 1033 | { |
| 1034 | It.Value()->AddSelectionMode(0); |
| 1035 | myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS,WithProj); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | } |
| 1040 | |
| 1041 | //======================================================================= |
| 1042 | //function : ActivateModes |
| 1043 | //purpose : |
| 1044 | //======================================================================= |
| 1045 | |
| 1046 | void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject, |
| 1047 | const Standard_Boolean WithProj) |
| 1048 | { |
| 1049 | if(!myActiveObjects.IsBound(anObject)) return; |
| 1050 | |
| 1051 | TColStd_ListIteratorOfListOfInteger itl (myListOfStandardMode); |
| 1052 | |
| 1053 | const Handle(AIS_LocalStatus)& LS = myActiveObjects(anObject); |
| 1054 | if(LS->Decomposed()){ |
| 1055 | for(;itl.More();itl.Next()){ |
| 1056 | myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS,WithProj); |
| 1057 | LS->AddSelectionMode(itl.Value()); |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | //======================================================================= |
| 1064 | //function : ClearObjects |
| 1065 | //purpose : |
| 1066 | //======================================================================= |
| 1067 | |
| 1068 | void AIS_LocalContext::ClearObjects() |
| 1069 | { |
| 1070 | AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects); |
| 1071 | for(;It.More();It.Next()) |
| 1072 | { |
| 1073 | Handle(AIS_InteractiveObject) SO = |
| 1074 | Handle(AIS_InteractiveObject)::DownCast(It.Key()); |
| 1075 | |
| 1076 | const Handle(AIS_LocalStatus)& CurAtt = It.Value(); |
| 1077 | //TColStd_ListIteratorOfListOfInteger ItL; |
| 1078 | // if object is temporary the presentations managed by myMainPM are removed |
| 1079 | AIS_DisplayStatus TheDS = myCTX->DisplayStatus(SO); |
| 1080 | |
| 1081 | if(TheDS != AIS_DS_Displayed){ |
| 1082 | if(myMainPM->IsDisplayed(SO,CurAtt->DisplayMode())){ |
| 1083 | if(CurAtt->IsSubIntensityOn()&& |
| 1084 | myMainPM->IsHighlighted(SO,CurAtt->HilightMode())) |
| 1085 | myMainPM->Unhighlight(SO,CurAtt->HilightMode()); |
| 1086 | myMainPM->Erase(SO,CurAtt->DisplayMode()); |
| 1087 | } |
| 1088 | |
| 1089 | if(CurAtt->IsTemporary()){ |
| 1090 | myMainPM->Erase(SO,CurAtt->DisplayMode());} |
| 1091 | // myMainPM->Clear(SO,CurAtt->DisplayMode());} |
| 1092 | } |
| 1093 | else { |
| 1094 | if (CurAtt->IsSubIntensityOn()){ |
| 1095 | myCTX->SubIntensityOff(Handle(AIS_InteractiveObject)::DownCast(SO));} |
| 1096 | Standard_Integer DiMo = SO->HasDisplayMode()? |
| 1097 | SO->DisplayMode():myCTX->DisplayMode(); |
| 1098 | if(CurAtt->DisplayMode()!=-1 && |
| 1099 | CurAtt->DisplayMode()!= DiMo) |
| 1100 | myMainPM->Erase(SO,CurAtt->DisplayMode()); |
| 1101 | } |
| 1102 | |
| 1103 | TColStd_ListIteratorOfListOfInteger ITL(CurAtt->SelectionModes()); |
| 1104 | for(;ITL.More();ITL.Next()) |
| 1105 | mySM->Deactivate(SO,ITL.Value(),myMainVS); |
| 1106 | |
| 1107 | if(CurAtt->IsTemporary()) |
| 1108 | mySM->Remove(SO,myMainVS); |
| 1109 | |
| 1110 | } |
| 1111 | ClearSelected( Standard_False ); |
| 1112 | myActiveObjects.Clear(); |
| 1113 | // myMainVS->ClearAreas();myMainVS->ClearSensitive(); |
| 1114 | } |
| 1115 | |
| 1116 | |
| 1117 | Standard_Boolean AIS_LocalContext::IsDecompositionOn() const |
| 1118 | {return !myListOfStandardMode.IsEmpty();} |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | //======================================================================= |
| 1124 | //function : HasAlreadyFilters |
| 1125 | //purpose : |
| 1126 | //======================================================================= |
| 1127 | |
| 1128 | Standard_Boolean AIS_LocalContext:: |
| 1129 | HasFilters(const TopAbs_ShapeEnum aType) const |
| 1130 | { |
| 1131 | return myFilters->ActsOn(aType); |
| 1132 | } |
| 1133 | |
| 1134 | void AIS_LocalContext::ClearDetected() |
| 1135 | { |
| 1136 | for(Standard_Integer I=1;I<=myMapOfOwner.Extent();I++) |
| 1137 | { |
| 1138 | if(!myMapOfOwner(I).IsNull()) |
| 1139 | { |
| 1140 | if(myMapOfOwner(I)->IsHilighted(myMainPM)) |
| 1141 | myMapOfOwner(I)->Unhilight(myMainPM); |
| 1142 | else |
| 1143 | { |
| 1144 | const Handle(SelectMgr_SelectableObject)& SO = |
| 1145 | myMapOfOwner.FindKey(I)->Selectable(); |
| 1146 | if(myActiveObjects.IsBound(SO)) |
| 1147 | { |
| 1148 | const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO); |
| 1149 | |
| 1150 | if(Att->IsTemporary() && |
| 1151 | Att->DisplayMode()==-1 && |
| 1152 | Att->SelectionModes().IsEmpty()) |
| 1153 | { |
| 1154 | myMapOfOwner(I)->Clear(myMainPM); |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | void AIS_LocalContext::UpdateConversion() |
| 1163 | { |
| 1164 | myMainVS->UpdateConversion(); |
| 1165 | } |
| 1166 | |
| 1167 | void AIS_LocalContext::UpdateSort() |
| 1168 | { |
| 1169 | myMainVS->UpdateSort(); |
| 1170 | } |
| 1171 | |
| 1172 | //======================================================================= |
| 1173 | //function : BeginImmediateDraw |
| 1174 | //purpose : |
| 1175 | //======================================================================= |
| 1176 | Standard_Boolean AIS_LocalContext::BeginImmediateDraw() |
| 1177 | { |
| 1178 | if (myMainPM->IsImmediateModeOn()) |
| 1179 | { |
| 1180 | myMainPM->BeginImmediateDraw(); |
| 1181 | return Standard_True; |
| 1182 | } |
| 1183 | return Standard_False; |
| 1184 | } |
| 1185 | |
| 1186 | //======================================================================= |
| 1187 | //function : ImmediateAdd |
| 1188 | //purpose : |
| 1189 | //======================================================================= |
| 1190 | Standard_Boolean AIS_LocalContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj, |
| 1191 | const Standard_Integer theMode) |
| 1192 | { |
| 1193 | if (!myMainPM->IsImmediateModeOn()) |
| 1194 | { |
| 1195 | return Standard_False; |
| 1196 | } |
| 1197 | |
| 1198 | myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode)->Presentation()); |
| 1199 | return Standard_True; |
| 1200 | } |
| 1201 | |
| 1202 | //======================================================================= |
| 1203 | //function : EndImmediateDraw |
| 1204 | //purpose : |
| 1205 | //======================================================================= |
| 1206 | Standard_Boolean AIS_LocalContext::EndImmediateDraw (const Handle(V3d_View)& theView) |
| 1207 | { |
| 1208 | if (!myMainPM->IsImmediateModeOn()) |
| 1209 | { |
| 1210 | return Standard_False; |
| 1211 | } |
| 1212 | |
| 1213 | myMainPM->EndImmediateDraw (theView); |
| 1214 | return Standard_True; |
| 1215 | } |
| 1216 | |
| 1217 | // ======================================================================= |
| 1218 | // function : ClearImmediateDraw |
| 1219 | // purpose : |
| 1220 | // ======================================================================= |
| 1221 | void AIS_LocalContext::ClearImmediateDraw() |
| 1222 | { |
| 1223 | myMainPM->ClearImmediateDraw(); |
| 1224 | } |
| 1225 | |
| 1226 | //======================================================================= |
| 1227 | //function : IsImmediateModeOn |
| 1228 | //purpose : |
| 1229 | //======================================================================= |
| 1230 | Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const |
| 1231 | { |
| 1232 | return myMainPM->IsImmediateModeOn(); |
| 1233 | } |
| 1234 | |
| 1235 | void AIS_LocalContext::SetSensitivityMode(const StdSelect_SensitivityMode aMode) { |
| 1236 | |
| 1237 | myMainVS->SetSensitivityMode(aMode); |
| 1238 | } |
| 1239 | |
| 1240 | StdSelect_SensitivityMode AIS_LocalContext::SensitivityMode() const { |
| 1241 | |
| 1242 | return myMainVS->SensitivityMode(); |
| 1243 | } |
| 1244 | |
| 1245 | void AIS_LocalContext::SetSensitivity(const Standard_Real aPrecision) { |
| 1246 | |
| 1247 | myMainVS->SetSensitivity(aPrecision); |
| 1248 | } |
| 1249 | |
| 1250 | Standard_Real AIS_LocalContext::Sensitivity() const { |
| 1251 | |
| 1252 | return myMainVS->Sensitivity(); |
| 1253 | } |
| 1254 | |
| 1255 | void AIS_LocalContext::SetPixelTolerance(const Standard_Integer aPrecision) { |
| 1256 | |
| 1257 | myMainVS->SetPixelTolerance(aPrecision); |
| 1258 | } |
| 1259 | |
| 1260 | Standard_Integer AIS_LocalContext::PixelTolerance() const { |
| 1261 | |
| 1262 | return myMainVS->PixelTolerance(); |
| 1263 | } |
| 1264 | |
| 1265 | //======================================================================= |
| 1266 | //function : SetZLayer |
| 1267 | //purpose : |
| 1268 | //======================================================================= |
| 1269 | |
| 1270 | void AIS_LocalContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj, |
| 1271 | const Standard_Integer theLayerId) |
| 1272 | { |
| 1273 | if (!myActiveObjects.IsBound (theIObj)) |
| 1274 | return; |
| 1275 | |
| 1276 | const Handle(AIS_LocalStatus)& aStatus = myActiveObjects (theIObj); |
| 1277 | if (aStatus->DisplayMode () == -1) |
| 1278 | return; |
| 1279 | |
| 1280 | theIObj->SetZLayer (myMainPM, theLayerId); |
| 1281 | } |
| 1282 | |
| 1283 | //======================================================================= |
| 1284 | //function : GetZLayer |
| 1285 | //purpose : |
| 1286 | //======================================================================= |
| 1287 | |
| 1288 | Standard_Integer AIS_LocalContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const |
| 1289 | { |
| 1290 | if (!myActiveObjects.IsBound (theIObj)) |
| 1291 | return -1; |
| 1292 | |
| 1293 | return theIObj->GetZLayer (myMainPM); |
| 1294 | } |