| 1 | #define IMP140901 //GG 14/09/01 goback to avoid a regression |
| 2 | // See V2d_Viewer |
| 3 | |
| 4 | // SAV 14/11/01 - modification for detection/highlighting/selection elements of |
| 5 | // SetOf<>. Fully used for SetOfMarkers. |
| 6 | |
| 7 | #define OCC197 // jfa 01/03/2002 // for multiple selection of elements |
| 8 | #define OCC146 // jfa 01/03/2002 // for single selection two times |
| 9 | #define OCC154 // jfa 06/03/2002 // for correct erasing |
| 10 | #define OCC389 // vro 19/06/2002 // for Display(obj,dispMode...) setting a view for the IO |
| 11 | |
| 12 | #include <Standard_Stream.hxx> |
| 13 | |
| 14 | #include <AIS2D_InteractiveContext.ixx> |
| 15 | #include <Aspect_ColorMap.hxx> |
| 16 | #include <Aspect_GenericColorMap.hxx> |
| 17 | #include <Aspect_FontMap.hxx> |
| 18 | #include <Aspect_MarkMap.hxx> |
| 19 | #include <Aspect_TypeMap.hxx> |
| 20 | #include <Aspect_WidthMap.hxx> |
| 21 | #include <Aspect_FontStyle.hxx> |
| 22 | #include <Aspect_LineStyle.hxx> |
| 23 | #include <Aspect_TypeOfMarker.hxx> |
| 24 | #include <Aspect_TypeOfLine.hxx> |
| 25 | #include <Aspect_WidthOfLine.hxx> |
| 26 | #include <Aspect_ColorMapEntry.hxx> |
| 27 | #include <Aspect_TypeMapEntry.hxx> |
| 28 | #include <Aspect_WidthMapEntry.hxx> |
| 29 | #include <Aspect_FontMapEntry.hxx> |
| 30 | #include <Aspect_MarkMapEntry.hxx> |
| 31 | #include <gp_GTrsf2d.hxx> |
| 32 | #include <gp_Trsf2d.hxx> |
| 33 | |
| 34 | #include <Graphic2d_Primitive.hxx> |
| 35 | #include <Graphic2d_SequenceOfPrimitives.hxx> |
| 36 | |
| 37 | #include <Graphic2d_View.hxx> |
| 38 | #include <Graphic2d_DisplayList.hxx> |
| 39 | #include <V2d_View.hxx> |
| 40 | #include <Prs2d_Point.hxx> |
| 41 | #include <Prs2d_Drawer.hxx> |
| 42 | #include <Prs2d_AspectLine.hxx> |
| 43 | |
| 44 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
| 45 | #include <TColStd_MapIteratorOfMapOfTransient.hxx> |
| 46 | #include <TColStd_MapOfTransient.hxx> |
| 47 | #include <TColStd_HSequenceOfInteger.hxx> |
| 48 | #include <AIS2D_DataMapIteratorOfDataMapOfLC.hxx> |
| 49 | #include <AIS2D_DataMapIteratorOfDataMapOfIOStatus.hxx> |
| 50 | #include <AIS2D_ListIteratorOfListOfIO.hxx> |
| 51 | #include <AIS2D_PrimitiveArchit.hxx> |
| 52 | #include <AIS2D_HSequenceOfPrimArchit.hxx> |
| 53 | #include <AIS2D_GlobalStatus.hxx> |
| 54 | #include <AIS2D_LocalStatus.hxx> |
| 55 | #include <AIS2D_LocalContext.hxx> |
| 56 | #include <AIS2D_ProjShape.hxx> |
| 57 | |
| 58 | //SAV |
| 59 | #include <TColStd_MapOfInteger.hxx> |
| 60 | #include <TColStd_MapIteratorOfMapOfInteger.hxx> |
| 61 | |
| 62 | static TColStd_ListIteratorOfListOfInteger ItL; |
| 63 | static Standard_Boolean RectMoveTo = Standard_False; |
| 64 | |
| 65 | AIS2D_InteractiveContext::AIS2D_InteractiveContext(const Handle(V2d_Viewer)& MainViewer): |
| 66 | |
| 67 | myMainVwr( MainViewer ), |
| 68 | myDetectPrecision( 4 ), |
| 69 | myResetDetect( Standard_True ), |
| 70 | myLastPicked(), |
| 71 | myLastinMain(), |
| 72 | myLastinColl(), |
| 73 | mySeqOfDetIO( new AIS2D_HSequenceOfIO() ), |
| 74 | mySeqOfSelIO( new AIS2D_HSequenceOfIO() ), |
| 75 | myCurDetectMode( AIS2D_TOD_NONE ), |
| 76 | myWasLastMain(), |
| 77 | myPickMode( Graphic2d_PM_INCLUDE ), |
| 78 | myHighlightColor( Quantity_NOC_CYAN1 ), |
| 79 | mySelectionColor( Quantity_NOC_GRAY80 ), |
| 80 | mySubIntensity( Quantity_NOC_GRAY40 ), |
| 81 | myDisplayMode( 0 ), |
| 82 | myLocalContexts( ), |
| 83 | myCurLocalIndex( 0 ), |
| 84 | myLastMoveView() , |
| 85 | myCurSelected( 0 ), |
| 86 | myMaxSelected( 0 ) |
| 87 | { |
| 88 | |
| 89 | myMainVwr->View()->SetDefaultOverrideColor( myMainVwr->InitializeColor( mySelectionColor ) ); |
| 90 | } |
| 91 | |
| 92 | AIS2D_InteractiveContext::AIS2D_InteractiveContext(const Handle(V2d_Viewer)& MainViewer,const Handle(V2d_Viewer)& aCollector): |
| 93 | |
| 94 | myMainVwr( MainViewer ), |
| 95 | |
| 96 | myCollectorVwr( aCollector ), |
| 97 | myIsCollClosed( Standard_False ), |
| 98 | myDetectPrecision( 4 ), |
| 99 | myResetDetect( Standard_True ), |
| 100 | myLastPicked(), |
| 101 | myLastinMain(), |
| 102 | myLastinColl(), |
| 103 | mySeqOfDetIO( new AIS2D_HSequenceOfIO() ), |
| 104 | mySeqOfSelIO( new AIS2D_HSequenceOfIO() ), |
| 105 | myCurDetectMode( AIS2D_TOD_NONE ), |
| 106 | myWasLastMain(), |
| 107 | myPickMode( Graphic2d_PM_INCLUDE ), |
| 108 | myHighlightColor( Quantity_NOC_CYAN1 ), |
| 109 | mySelectionColor( Quantity_NOC_GRAY80 ), |
| 110 | mySubIntensity( Quantity_NOC_GRAY40 ), |
| 111 | myDisplayMode( 0 ), |
| 112 | myLocalContexts( ), |
| 113 | myCurLocalIndex( 0 ), |
| 114 | myLastMoveView() |
| 115 | { |
| 116 | myMainVwr->View()->SetDefaultOverrideColor( myMainVwr->InitializeColor( mySelectionColor ) ); |
| 117 | myCollectorVwr->View()->SetDefaultOverrideColor( myMainVwr->InitializeColor( mySelectionColor ) ); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | //************************************************************* |
| 122 | // Management of the Trash Bin Viewer |
| 123 | // ************************************************************* |
| 124 | |
| 125 | void AIS2D_InteractiveContext::OpenCollector() { |
| 126 | myIsCollClosed = Standard_False; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | // ************************************************************* |
| 131 | // Editing general Display Services |
| 132 | // ************************************************************* |
| 133 | |
| 134 | void AIS2D_InteractiveContext::Display( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 135 | const Standard_Boolean UpdateVwr ) { |
| 136 | |
| 137 | if ( anIObj.IsNull() ) return; |
| 138 | |
| 139 | Standard_Integer DispMode, SelMode; |
| 140 | AIS2D_TypeOfDetection HiMod; |
| 141 | Standard_Boolean UpdateCol; |
| 142 | Handle( AIS2D_GlobalStatus ) GStatus; |
| 143 | |
| 144 | GetDefModes( anIObj, DispMode, HiMod, SelMode ); |
| 145 | |
| 146 | if ( !anIObj->HasInteractiveContext() ) |
| 147 | anIObj->SetContext( this ); |
| 148 | |
| 149 | anIObj->SetView( myMainVwr->View() ); |
| 150 | |
| 151 | if ( !HasOpenedContext() ) { |
| 152 | |
| 153 | if ( IsDisplayed( anIObj ) ) return; |
| 154 | UpdateCol = Standard_False; |
| 155 | |
| 156 | if ( !myObjects.IsBound( anIObj ) ) { |
| 157 | |
| 158 | GStatus = new AIS2D_GlobalStatus( AIS2D_DS_Displayed, DispMode, 0); |
| 159 | myObjects.Bind( anIObj, GStatus ); |
| 160 | DrawObject( anIObj, DispMode ) ; |
| 161 | |
| 162 | } else { |
| 163 | |
| 164 | GStatus = myObjects( anIObj ); |
| 165 | switch ( GStatus->GraphicStatus() ) { |
| 166 | |
| 167 | case AIS2D_DS_Erased: { |
| 168 | |
| 169 | if ( GStatus->IsHighlight() ) |
| 170 | UpdateCol = UpdateVwr ; |
| 171 | } |
| 172 | case AIS2D_DS_FullErased: { |
| 173 | |
| 174 | for ( ItL.Initialize( * GStatus -> DisplayedModes()); ItL.More(); ItL.Next()) |
| 175 | if ( GStatus->IsSubIntensityOn() ) { |
| 176 | // Standard_Integer indCol = myMainVwr->InitializeColor(mySubIntensity); |
| 177 | // myMainPM->SetHighlightColor(indCol); |
| 178 | // myMainPM->ColorHighlight( anIObj, indCol, ItL.Value() ); |
| 179 | } |
| 180 | |
| 181 | for ( ItL.Initialize( * GStatus -> SelectionModes() ); ItL.More();ItL.Next() ) |
| 182 | // mySelectorMgr->Activate( anIObj, ItL.Value(), myMainSelector ); |
| 183 | GStatus->SetGraphicStatus( AIS2D_DS_Displayed ); |
| 184 | if ( GStatus->IsHighlight() ) |
| 185 | Highlight( anIObj, HiMod ); |
| 186 | break; |
| 187 | } |
| 188 | default: |
| 189 | break; |
| 190 | } // end switch |
| 191 | } //endif !myObjects.IsBound |
| 192 | |
| 193 | anIObj->Display(); |
| 194 | |
| 195 | if ( UpdateCol && !myCollectorVwr.IsNull() ) myCollectorVwr->UpdateNew(); |
| 196 | |
| 197 | } else { |
| 198 | |
| 199 | myLocalContexts( myCurLocalIndex )->Display( anIObj, DispMode, Standard_True,SelMode ); |
| 200 | |
| 201 | }//endif !HasOpenedContext |
| 202 | |
| 203 | if ( UpdateVwr ) myMainVwr->UpdateNew(); |
| 204 | |
| 205 | } |
| 206 | |
| 207 | void AIS2D_InteractiveContext::Display( |
| 208 | const Handle(AIS2D_InteractiveObject)& anIObj, |
| 209 | const Standard_Integer aDispMode, |
| 210 | const Standard_Integer aSelectMode, |
| 211 | const Standard_Boolean UpdateVwr, |
| 212 | const Standard_Boolean AllowDecomp) { |
| 213 | |
| 214 | if ( anIObj.IsNull() ) return; |
| 215 | if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext(this); |
| 216 | |
| 217 | #ifdef OCC389 |
| 218 | anIObj->SetView(myMainVwr->View()); |
| 219 | #endif |
| 220 | |
| 221 | if ( !HasOpenedContext() ) { |
| 222 | |
| 223 | if ( !anIObj->HasDisplayMode() ) |
| 224 | anIObj->SetDisplayMode(aDispMode); |
| 225 | |
| 226 | if ( !myObjects.IsBound(anIObj) ) { |
| 227 | Handle(AIS2D_GlobalStatus) GStatus= |
| 228 | new AIS2D_GlobalStatus( AIS2D_DS_Displayed, aDispMode, aSelectMode ); |
| 229 | myObjects.Bind( anIObj, GStatus ); |
| 230 | DrawObject( anIObj, aDispMode ); |
| 231 | |
| 232 | if ( aSelectMode != -1 ) { |
| 233 | //if ( !mySelectorMgr->Contains( anIObj ) ) |
| 234 | // mySelectorMgr->Load( anIObj, myMainSelector,aSelectMode ); |
| 235 | //mySelectorMgr->Activate( anIObj, aSelectMode, myMainSelector ); |
| 236 | } |
| 237 | |
| 238 | anIObj->SetSelectionMode(aSelectMode); |
| 239 | |
| 240 | } else { |
| 241 | |
| 242 | Handle(AIS2D_GlobalStatus) GStatus = myObjects( anIObj ); |
| 243 | if ( !GStatus->IsDModeIn( aDispMode ) ) { |
| 244 | DrawObject( anIObj, aDispMode ); |
| 245 | GStatus->AddDisplayMode( aDispMode ); |
| 246 | if ( GStatus->IsSubIntensityOn() ) { |
| 247 | #ifdef DEB |
| 248 | Standard_Integer indCol = myMainVwr->InitializeColor(mySubIntensity); |
| 249 | //myMainPM->SetHighlightColor( indCol ); |
| 250 | //myMainPM->ColorHighlight( anIObj, indCol, aDispMode ); |
| 251 | #endif |
| 252 | } |
| 253 | } |
| 254 | if ( aSelectMode != -1 ) { |
| 255 | GStatus->AddSelectionMode( aSelectMode ); |
| 256 | //mySelectorMgr->Activate( anIObj, aSelectMode, myMainSelector ); |
| 257 | } |
| 258 | |
| 259 | } |
| 260 | anIObj->Display(); |
| 261 | } else |
| 262 | |
| 263 | myLocalContexts(myCurLocalIndex)->Display( anIObj, aDispMode, AllowDecomp, aSelectMode); |
| 264 | |
| 265 | if (UpdateVwr) myMainVwr->Update(); |
| 266 | |
| 267 | } |
| 268 | |
| 269 | void AIS2D_InteractiveContext::Redisplay( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 270 | const Standard_Boolean updateVwr, |
| 271 | const Standard_Boolean /*allModes*/ ) { |
| 272 | |
| 273 | if ( anIObj.IsNull() ) return; |
| 274 | //anIObj->Update(allModes); |
| 275 | |
| 276 | if ( updateVwr ) { |
| 277 | if ( HasOpenedContext() ) |
| 278 | myMainVwr->Update(); |
| 279 | else { |
| 280 | if ( myObjects.IsBound( anIObj ) ) { |
| 281 | switch ( myObjects(anIObj)->GraphicStatus() ) { |
| 282 | case AIS2D_DS_Displayed: |
| 283 | DrawObject( anIObj, 0 ); |
| 284 | myMainVwr->Update(); |
| 285 | break; |
| 286 | case AIS2D_DS_Erased: |
| 287 | if ( !myCollectorVwr.IsNull() ) |
| 288 | myCollectorVwr->Update(); |
| 289 | default: |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | } |
| 297 | |
| 298 | void AIS2D_InteractiveContext::Load( |
| 299 | const Handle(AIS2D_InteractiveObject)& anIObj, |
| 300 | const Standard_Integer SelMode, |
| 301 | const Standard_Boolean AllowDecomp) { |
| 302 | |
| 303 | if ( anIObj.IsNull() ) return; |
| 304 | if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext( this ); |
| 305 | |
| 306 | if ( !HasOpenedContext() ) { |
| 307 | if ( SelMode == -1 && !AllowDecomp ) { |
| 308 | Standard_Integer DispMode; |
| 309 | AIS2D_TypeOfDetection HiMod; |
| 310 | Standard_Integer selMode = SelMode; |
| 311 | |
| 312 | GetDefModes( anIObj, DispMode, HiMod, selMode ); |
| 313 | Handle(AIS2D_GlobalStatus) GStatus= |
| 314 | new AIS2D_GlobalStatus( AIS2D_DS_FullErased, DispMode, selMode ); |
| 315 | myObjects.Bind( anIObj,GStatus ); |
| 316 | return; |
| 317 | } |
| 318 | } |
| 319 | //endif !HasOpenedContext |
| 320 | myLocalContexts(myCurLocalIndex)->Load( anIObj, AllowDecomp, SelMode); |
| 321 | } |
| 322 | |
| 323 | void AIS2D_InteractiveContext::Erase( |
| 324 | const Handle(AIS2D_InteractiveObject)& anIObj, |
| 325 | const Standard_Boolean UpdateVwr, |
| 326 | const Standard_Boolean /*PutInCollector*/) { |
| 327 | |
| 328 | if ( anIObj.IsNull() ) return; |
| 329 | |
| 330 | if ( !HasOpenedContext() ) |
| 331 | #ifdef OCC154 |
| 332 | { |
| 333 | anIObj->Erase(); |
| 334 | if (myObjects.IsBound(anIObj)) |
| 335 | myObjects(anIObj)->SetGraphicStatus(AIS2D_DS_Erased); |
| 336 | } |
| 337 | #else |
| 338 | anIObj->Remove(); |
| 339 | #endif |
| 340 | if ( UpdateVwr ) myMainVwr->UpdateNew(); |
| 341 | |
| 342 | } |
| 343 | |
| 344 | void AIS2D_InteractiveContext::EraseAll (const Standard_Boolean /*PutInCollector*/, |
| 345 | const Standard_Boolean UpdateVwr) |
| 346 | { |
| 347 | if ( !HasOpenedContext() ) |
| 348 | #ifdef OCC154 |
| 349 | { |
| 350 | myMainVwr->View()->Erase(); |
| 351 | AIS2D_DataMapIteratorOfDataMapOfIOStatus anItr (myObjects); |
| 352 | for (; anItr.More(); anItr.Next()) |
| 353 | { |
| 354 | anItr.Value()->SetGraphicStatus(AIS2D_DS_Erased); |
| 355 | } |
| 356 | } |
| 357 | #else |
| 358 | myMainVwr->View()->Remove(); |
| 359 | #endif |
| 360 | if ( UpdateVwr ) myMainVwr->Update(); |
| 361 | } |
| 362 | |
| 363 | void AIS2D_InteractiveContext::DisplayAll (const Standard_Boolean /*OnlyFromCollector*/, |
| 364 | const Standard_Boolean /*updateVwr*/) { |
| 365 | |
| 366 | } |
| 367 | |
| 368 | void AIS2D_InteractiveContext::EraseSelected (const Standard_Boolean PutInCollector, |
| 369 | const Standard_Boolean UpdateVwr) { |
| 370 | if ( !HasOpenedContext() ) { |
| 371 | Standard_Boolean found = Standard_False; |
| 372 | if ( mySeqOfSelIO->IsEmpty() ) return; |
| 373 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) |
| 374 | Erase( mySeqOfSelIO->Value(i), Standard_False, PutInCollector ); |
| 375 | found = Standard_True; |
| 376 | if ( found && UpdateVwr ) { |
| 377 | myMainVwr->Update(); |
| 378 | if ( PutInCollector && !myCollectorVwr.IsNull() ) |
| 379 | myCollectorVwr->Update(); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | } |
| 384 | |
| 385 | void AIS2D_InteractiveContext::DisplaySelected( const Standard_Boolean updateVwr ) { |
| 386 | |
| 387 | if ( !HasOpenedContext() ) { |
| 388 | Standard_Boolean found = Standard_False; |
| 389 | if ( mySeqOfSelIO->IsEmpty() ) return; |
| 390 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) { |
| 391 | Display( mySeqOfSelIO->Value(i), Standard_False ); |
| 392 | found = Standard_True; |
| 393 | } |
| 394 | if ( found && updateVwr ) { |
| 395 | myMainVwr->Update(); |
| 396 | if ( !(myIsCollClosed && myCollectorVwr.IsNull()) ) |
| 397 | myCollectorVwr->Update(); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | } |
| 402 | |
| 403 | Standard_Boolean AIS2D_InteractiveContext::KeepTemporary( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 404 | const Standard_Integer WhichContext ) { |
| 405 | |
| 406 | if ( anIObj.IsNull() ) return Standard_False; |
| 407 | |
| 408 | if ( !HasOpenedContext() ) return Standard_False; |
| 409 | if ( myObjects.IsBound(anIObj) ) return Standard_False; |
| 410 | if ( WhichContext != -1 && !myLocalContexts.IsBound(WhichContext) ) return Standard_False; |
| 411 | |
| 412 | Standard_Integer IsItInLocal = myCurLocalIndex; |
| 413 | Standard_Boolean Found( Standard_False ); |
| 414 | |
| 415 | while ( IsItInLocal > 0 && !Found ) { |
| 416 | if ( !myLocalContexts.IsBound( IsItInLocal ) ) |
| 417 | IsItInLocal--; |
| 418 | else if ( myLocalContexts(IsItInLocal)->IsIn( anIObj ) ) |
| 419 | Found = Standard_True; |
| 420 | else |
| 421 | IsItInLocal--; |
| 422 | } |
| 423 | |
| 424 | if ( !Found ) return Standard_False; |
| 425 | |
| 426 | Handle(AIS2D_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj); |
| 427 | |
| 428 | |
| 429 | if ( LS->IsTemporary() ){ |
| 430 | Standard_Integer DM,SM; |
| 431 | AIS2D_TypeOfDetection HM; |
| 432 | GetDefModes( anIObj, DM, HM, SM ); |
| 433 | |
| 434 | SM = LS->SelectionModes()->IsEmpty() ? SM : LS->SelectionModes()->First(); |
| 435 | if (LS->DisplayMode() != DM ) { |
| 436 | Standard_Integer LSM = LS->SelectionModes()->IsEmpty() ? -1 : LS->SelectionModes()->First(); |
| 437 | myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM); |
| 438 | } |
| 439 | |
| 440 | Handle(AIS2D_GlobalStatus) GS = new AIS2D_GlobalStatus( AIS2D_DS_Displayed, |
| 441 | DM, SM, Standard_False); |
| 442 | myObjects.Bind( anIObj, GS ); |
| 443 | |
| 444 | LS->SetTemporary(Standard_False); |
| 445 | } |
| 446 | return Standard_True; |
| 447 | } |
| 448 | |
| 449 | Standard_Boolean AIS2D_InteractiveContext::IsSelected(const Handle(AIS2D_InteractiveObject)& anIObj) const { |
| 450 | |
| 451 | if ( anIObj.IsNull() ) return Standard_False; |
| 452 | if ( !HasOpenedContext() ) |
| 453 | return ( anIObj->State() == 1 ); |
| 454 | else |
| 455 | return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj); |
| 456 | } |
| 457 | |
| 458 | Standard_Boolean AIS2D_InteractiveContext::IsCurrent(const Handle(AIS2D_InteractiveObject)& anIObj) const { |
| 459 | |
| 460 | if ( anIObj.IsNull() ) return Standard_False; |
| 461 | return ( anIObj->State() ); |
| 462 | } |
| 463 | |
| 464 | Standard_Integer AIS2D_InteractiveContext::OpenLocalContext( const Standard_Boolean UseDispObj, |
| 465 | const Standard_Boolean AllowDecomposit, |
| 466 | const Standard_Boolean AcceptEraseOfObj ) { |
| 467 | if ( !IsCurrent( myLastPicked ) ) |
| 468 | if ( !myLastPicked.IsNull() ) { |
| 469 | #ifdef DEB |
| 470 | AIS2D_TypeOfDetection HiMod = myLastPicked -> HasHighlightMode() ? |
| 471 | myLastPicked->HighlightMode() : myLastPicked->DefaultHighlightMode(); |
| 472 | #endif |
| 473 | myLastPicked->Unhighlight(); |
| 474 | } |
| 475 | |
| 476 | if ( !myLastMoveView.IsNull() ) |
| 477 | if ( myCurLocalIndex > 0 ) |
| 478 | myLocalContexts( myCurLocalIndex )->UnhighLastDetect( myLastMoveView ); |
| 479 | |
| 480 | myLastinMain.Nullify(); |
| 481 | myLastinColl.Nullify(); |
| 482 | myLastPicked.Nullify(); |
| 483 | myWasLastMain = Standard_True; |
| 484 | |
| 485 | // Standard_Integer untilNow = myCurLocalIndex; |
| 486 | |
| 487 | myCurLocalIndex = HighestIndex() + 1; |
| 488 | |
| 489 | Handle(AIS2D_LocalContext) NewLocal= new AIS2D_LocalContext(this, |
| 490 | myCurLocalIndex, |
| 491 | UseDispObj, |
| 492 | AllowDecomposit, |
| 493 | AcceptEraseOfObj ); |
| 494 | |
| 495 | myLocalContexts.Bind( myCurLocalIndex, NewLocal ); |
| 496 | |
| 497 | if ( UseDispObj ) { |
| 498 | if ( AllowDecomposit ) |
| 499 | cout<<"\t\tDecomposition Authorized for Loaded Shapes"<<endl; |
| 500 | else |
| 501 | cout<<"\t\tNo Decomposition Authorized for Loaded Shapes"<<endl; |
| 502 | } else |
| 503 | cout<<"\t\tNo Objects Were Loaded "<<endl; |
| 504 | |
| 505 | return myCurLocalIndex; |
| 506 | |
| 507 | } |
| 508 | |
| 509 | void AIS2D_InteractiveContext::CloseLocalContext( const Standard_Integer ind, |
| 510 | const Standard_Boolean updateVwr ) { |
| 511 | |
| 512 | Standard_Integer GoodIndex = ( ind == -1 ) ? myCurLocalIndex : ind; |
| 513 | if ( !HasOpenedContext() ) return; |
| 514 | if ( !myLocalContexts.IsBound(GoodIndex) ) return; |
| 515 | |
| 516 | if ( myLocalContexts.Extent() == 1 && GoodIndex == myCurLocalIndex ) { |
| 517 | |
| 518 | myLocalContexts(myCurLocalIndex)->Terminate(); |
| 519 | myLocalContexts.UnBind(myCurLocalIndex); |
| 520 | myCurLocalIndex = 0; |
| 521 | |
| 522 | ResetOriginalState(Standard_False); |
| 523 | |
| 524 | } else { |
| 525 | |
| 526 | myLocalContexts(GoodIndex)->Terminate(); |
| 527 | myLocalContexts.UnBind(GoodIndex); |
| 528 | |
| 529 | if ( GoodIndex == myCurLocalIndex ) { |
| 530 | myCurLocalIndex = HighestIndex(); |
| 531 | #ifdef DEB |
| 532 | const Handle(AIS2D_LocalContext)& LocCtx = myLocalContexts(myCurLocalIndex); |
| 533 | #endif |
| 534 | } |
| 535 | |
| 536 | } |
| 537 | |
| 538 | if ( updateVwr ) myMainVwr->Update(); |
| 539 | |
| 540 | } |
| 541 | |
| 542 | Standard_Integer AIS2D_InteractiveContext::IndexOfCurrentLocal() const { |
| 543 | return myCurLocalIndex; |
| 544 | } |
| 545 | |
| 546 | void AIS2D_InteractiveContext::CloseAllContext( const Standard_Boolean /*updateVwr*/ ) { |
| 547 | |
| 548 | |
| 549 | |
| 550 | } |
| 551 | |
| 552 | void AIS2D_InteractiveContext::SetCurrentObject( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 553 | const Standard_Boolean UpdateVwr ) { |
| 554 | |
| 555 | if ( anIObj.IsNull() ) return; |
| 556 | |
| 557 | /*if ( NbCurrents() == 1 && anIObj->State() == 1 ) { |
| 558 | Quantity_NameOfColor HiCol; |
| 559 | Standard_Boolean HasHiCol; |
| 560 | if ( IsHighlighted( anIObj, HasHiCol, HiCol ) ) |
| 561 | if ( HasHiCol && HiCol != mySelectionColor ) |
| 562 | Highlight( anIObj, UpdateVwr ); |
| 563 | return; |
| 564 | } |
| 565 | */ |
| 566 | if ( !HasOpenedContext() ) { |
| 567 | if ( !myObjects.IsBound(anIObj) ) |
| 568 | HighlightWithColor( anIObj, mySelectionColor, Standard_False ); |
| 569 | |
| 570 | anIObj->SetState(1); |
| 571 | Quantity_NameOfColor HiCol; |
| 572 | Standard_Boolean HasHiCol; |
| 573 | if ( IsHighlighted( anIObj, HasHiCol, HiCol ) ) { |
| 574 | if ( HasHiCol && HiCol != mySelectionColor ) |
| 575 | Highlight( anIObj,UpdateVwr ); |
| 576 | } else { |
| 577 | Highlight( anIObj, UpdateVwr ); |
| 578 | } |
| 579 | //if (UpdateVwr) |
| 580 | // UpdateCurrentViewer(); |
| 581 | } |
| 582 | |
| 583 | } |
| 584 | |
| 585 | void AIS2D_InteractiveContext::AddOrRemoveCurObject( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 586 | const Standard_Boolean UpdateVwr ) { |
| 587 | |
| 588 | |
| 589 | if ( !HasOpenedContext() ) { |
| 590 | if ( anIObj.IsNull() ) return; |
| 591 | |
| 592 | switch ( anIObj->HighlightMode() ) { |
| 593 | default: |
| 594 | case AIS2D_TOD_OBJECT: { |
| 595 | if ( IsIOSelected( anIObj ) ) { |
| 596 | Unhighlight( anIObj, Standard_False ); |
| 597 | anIObj->SetState( 0 ); |
| 598 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) |
| 599 | if ( mySeqOfSelIO->Value(i) == anIObj ) { |
| 600 | mySeqOfSelIO->Remove(i); |
| 601 | break; |
| 602 | } |
| 603 | } else { |
| 604 | anIObj->SetState( 1 ); |
| 605 | Highlight( anIObj, Standard_False ); |
| 606 | mySeqOfSelIO->Append(anIObj); |
| 607 | } |
| 608 | } |
| 609 | break; |
| 610 | case AIS2D_TOD_PRIMITIVE: { |
| 611 | Standard_Boolean found = Standard_False; |
| 612 | Handle(AIS2D_HSequenceOfPrimArchit) thePA; |
| 613 | Handle(Graphic2d_Primitive) thePrim = anIObj->Primitive(anIObj->PickedIndex()); |
| 614 | thePA = anIObj->GetSelectedSeqPrim(); |
| 615 | for ( int i = 1; i <= thePA->Length(); ++i ) |
| 616 | if ( thePA->Value(i)->GetPrimitive() == thePrim ) { |
| 617 | //thePrim->Unhighlight(); |
| 618 | Unhighlight( anIObj, Standard_False ); |
| 619 | thePA->Remove(i); |
| 620 | found = Standard_True; |
| 621 | break; |
| 622 | } |
| 623 | if ( !found ) { |
| 624 | Highlight( anIObj, Standard_False ); |
| 625 | thePrim->Highlight(); |
| 626 | anIObj->AddSelectPrim( thePrim, 0 ); |
| 627 | if ( ! IsIOSelected( anIObj ) ) { |
| 628 | mySeqOfSelIO->Append(anIObj); |
| 629 | anIObj->SetState( 1 ); |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | break; |
| 634 | case AIS2D_TOD_ELEMENT:{ |
| 635 | Standard_Boolean found = Standard_False; |
| 636 | Handle(AIS2D_HSequenceOfPrimArchit) thePA; |
| 637 | Handle(Graphic2d_Primitive) thePrim = anIObj->Primitive(anIObj->PickedIndex()); |
| 638 | Standard_Integer ind = thePrim->PickedIndex(); |
| 639 | thePA = anIObj->GetSelectedSeqPrim(); |
| 640 | for ( int i = 1; i <= thePA->Length(); ++i ) |
| 641 | if ( thePA->Value(i)->GetPrimitive() == thePrim && |
| 642 | thePA->Value(i)->GetIndex() == ind ) { |
| 643 | #ifdef OCC197 |
| 644 | // unhighlight the element |
| 645 | // thePrim->Unhighlight(ind); |
| 646 | Handle(TColStd_HSequenceOfInteger) aHiInds = thePrim->HighlightIndices(); |
| 647 | for (int k = 1; k <= aHiInds->Length(); k++) |
| 648 | { |
| 649 | if (aHiInds->Value(k) == ind) |
| 650 | { |
| 651 | aHiInds->Remove(k); |
| 652 | break; |
| 653 | } |
| 654 | } |
| 655 | // unhighlight entire object only if we remove last selected element of it |
| 656 | if (thePA->Length() == 1) |
| 657 | #endif |
| 658 | Unhighlight( anIObj, Standard_False ); |
| 659 | thePA->Remove(i); |
| 660 | found = Standard_True; |
| 661 | break; |
| 662 | } |
| 663 | if ( !found ) { |
| 664 | Highlight( anIObj, Standard_False ); |
| 665 | thePrim->Highlight( ind ); |
| 666 | anIObj->AddSelectPrim( thePrim, ind ); |
| 667 | if ( ! IsIOSelected( anIObj ) ) { |
| 668 | mySeqOfSelIO->Append(anIObj); |
| 669 | anIObj->SetState( 1 ); |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | break; |
| 674 | case AIS2D_TOD_VERTEX: { |
| 675 | Standard_Boolean found = Standard_False; |
| 676 | Handle(AIS2D_HSequenceOfPrimArchit) thePA; |
| 677 | Handle(Graphic2d_Primitive) thePrim = anIObj->Primitive(anIObj->PickedIndex()); |
| 678 | Standard_Integer ind = thePrim->PickedIndex(); |
| 679 | thePA = anIObj->GetSelectedSeqPrim(); |
| 680 | for ( int i = 1; i <= thePA->Length(); ++i ) |
| 681 | if ( thePA->Value(i)->GetPrimitive() == thePrim && |
| 682 | thePA->Value(i)->GetIndex() == ind ) { |
| 683 | #ifdef OCC197 |
| 684 | // unhighlight the vertex |
| 685 | // thePrim->Unhighlight(ind); |
| 686 | Handle(TColStd_HSequenceOfInteger) aHiInds = thePrim->HighlightIndices(); |
| 687 | for (int k = 1; k <= aHiInds->Length(); k++) |
| 688 | { |
| 689 | if (aHiInds->Value(k) == ind) |
| 690 | { |
| 691 | aHiInds->Remove(k); |
| 692 | break; |
| 693 | } |
| 694 | } |
| 695 | // unhighlight entire object only if we remove last selected vertex of it |
| 696 | if (thePA->Length() == 1) |
| 697 | #endif |
| 698 | Unhighlight( anIObj, Standard_False ); |
| 699 | thePA->Remove(i); |
| 700 | found = Standard_True; |
| 701 | break; |
| 702 | } |
| 703 | if ( !found ) { |
| 704 | Highlight( anIObj, Standard_False ); |
| 705 | thePrim->Highlight( ind ); |
| 706 | anIObj->AddSelectPrim( thePrim, ind ); |
| 707 | if ( ! IsIOSelected( anIObj ) ) { |
| 708 | mySeqOfSelIO->Append(anIObj); |
| 709 | anIObj->SetState( 1 ); |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | break; |
| 714 | |
| 715 | } // end switch |
| 716 | |
| 717 | #ifdef OCC197 |
| 718 | if ( UpdateVwr ) myWasLastMain ? myMainVwr->Update() : UpdateCollector(); |
| 719 | #else |
| 720 | if ( UpdateVwr ) UpdateCurrentViewer(); |
| 721 | #endif |
| 722 | } else { |
| 723 | |
| 724 | // cout<<"Nothing Done : Opened Local Context"<<endl; |
| 725 | } |
| 726 | |
| 727 | } |
| 728 | |
| 729 | void AIS2D_InteractiveContext::UpdateCurrent() { |
| 730 | |
| 731 | |
| 732 | } |
| 733 | |
| 734 | void AIS2D_InteractiveContext::SetOkCurrent() { |
| 735 | |
| 736 | } |
| 737 | |
| 738 | /*Handle(AIS2D_InteractiveObject) AIS2D_InteractiveContext::FirstCurrentObject() { |
| 739 | Handle(AIS2D_InteractiveObject) IO ; |
| 740 | InitCurrent(); |
| 741 | if ( MoreCurrent() ) |
| 742 | return Current(); |
| 743 | return IO; |
| 744 | } |
| 745 | */ |
| 746 | void AIS2D_InteractiveContext::HighlightCurrent(const Standard_Boolean UpdateVwr) { |
| 747 | if ( mySeqOfSelIO->IsEmpty() ) return; |
| 748 | Handle(AIS2D_InteractiveObject) IO; |
| 749 | AIS2D_TypeOfDetection theTOD; |
| 750 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) { |
| 751 | IO = mySeqOfSelIO->Value(i); |
| 752 | theTOD = IO->HighlightMode(); |
| 753 | if ( theTOD == AIS2D_TOD_OBJECT ) |
| 754 | Highlight(IO,Standard_False); |
| 755 | else if ( theTOD == AIS2D_TOD_PRIMITIVE || |
| 756 | theTOD == AIS2D_TOD_ELEMENT || |
| 757 | theTOD == AIS2D_TOD_VERTEX ) { |
| 758 | Standard_Integer pLength = IO->PickList()->Length(); |
| 759 | if ( pLength ) { |
| 760 | IO->Highlight(myMainVwr->InitializeColor( mySelectionColor )); |
| 761 | IO->Unhighlight(); |
| 762 | for ( int j = 1; j <= pLength; j++ ) |
| 763 | IO->Primitive(IO->PickList()->Value(j))->Highlight(); |
| 764 | } |
| 765 | } |
| 766 | } // end for |
| 767 | if ( UpdateVwr ) |
| 768 | UpdateCurrentViewer(); |
| 769 | |
| 770 | } |
| 771 | |
| 772 | void AIS2D_InteractiveContext::UnhighlightCurrent(const Standard_Boolean UpdateVwr) { |
| 773 | if ( mySeqOfSelIO->IsEmpty() ) return; |
| 774 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) { |
| 775 | Unhighlight( mySeqOfSelIO->Value(i), Standard_False ); |
| 776 | mySeqOfSelIO->Value(i)->SetState(0); |
| 777 | } |
| 778 | if ( UpdateVwr ) |
| 779 | UpdateCurrentViewer(); |
| 780 | } |
| 781 | |
| 782 | |
| 783 | void AIS2D_InteractiveContext::ClearCurrent(const Standard_Boolean UpdateVwr) { |
| 784 | if ( mySeqOfSelIO->IsEmpty() ) return; |
| 785 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) |
| 786 | Unhighlight( mySeqOfSelIO->Value(i), Standard_False ); |
| 787 | |
| 788 | if ( UpdateVwr ) |
| 789 | UpdateCurrentViewer(); |
| 790 | } |
| 791 | |
| 792 | void AIS2D_InteractiveContext::SetSelectedCurrent() { |
| 793 | |
| 794 | } |
| 795 | |
| 796 | // SAV - just appending object |
| 797 | void AIS2D_InteractiveContext::SetSelected( const Handle(AIS2D_InteractiveObject)& obj, |
| 798 | const Standard_Boolean update ) |
| 799 | { |
| 800 | mySeqOfSelIO->Append( obj ); |
| 801 | for( Standard_Integer i = 1; i <= obj->Length(); i++ ) |
| 802 | obj->AddSelectPrim( obj->Primitive( i ), i ); |
| 803 | } |
| 804 | |
| 805 | void AIS2D_InteractiveContext::UpdateSelected( const Standard_Boolean UpdateVwr ) { |
| 806 | |
| 807 | if ( !HasOpenedContext() ) { |
| 808 | HighlightSelected(); |
| 809 | } |
| 810 | myLocalContexts(myCurLocalIndex)->UpdateSelected( UpdateVwr ); |
| 811 | } |
| 812 | |
| 813 | void AIS2D_InteractiveContext::AddOrRemoveSelected( |
| 814 | const Handle(AIS2D_InteractiveObject)& anIObj, |
| 815 | const Standard_Boolean UpdateVwr ) { |
| 816 | |
| 817 | if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext(this); |
| 818 | if ( ! HasOpenedContext() ) |
| 819 | AddOrRemoveCurObject( anIObj, UpdateVwr ); |
| 820 | else |
| 821 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected( anIObj, UpdateVwr); |
| 822 | |
| 823 | } |
| 824 | |
| 825 | void AIS2D_InteractiveContext::HighlightSelected( const Standard_Boolean UpdateVwr ) { |
| 826 | |
| 827 | if ( !HasOpenedContext() ) { |
| 828 | if ( ! mySeqOfSelIO->IsEmpty() ) |
| 829 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) |
| 830 | Highlight( mySeqOfSelIO->Value(i), Standard_False ); |
| 831 | } else { |
| 832 | myLocalContexts(myCurLocalIndex)->UnhighlightPicked( UpdateVwr ); |
| 833 | } |
| 834 | if( UpdateVwr ) |
| 835 | UpdateCurrentViewer(); |
| 836 | } |
| 837 | |
| 838 | void AIS2D_InteractiveContext::UnhighlightSelected( const Standard_Boolean UpdateVwr ) { |
| 839 | if ( !HasOpenedContext() ) { |
| 840 | if ( ! mySeqOfSelIO->IsEmpty() ) |
| 841 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) |
| 842 | Unhighlight( mySeqOfSelIO->Value(i), Standard_False ); |
| 843 | } else { |
| 844 | myLocalContexts(myCurLocalIndex)->UnhighlightPicked( UpdateVwr ); |
| 845 | } |
| 846 | if( UpdateVwr ) |
| 847 | UpdateCurrentViewer(); |
| 848 | } |
| 849 | |
| 850 | void AIS2D_InteractiveContext::ClearSelected( const Standard_Boolean UpdateVwr ) { |
| 851 | if ( !HasOpenedContext() ) |
| 852 | ClearCurrent( UpdateVwr ); |
| 853 | else |
| 854 | myLocalContexts(myCurLocalIndex)->ClearSelected( UpdateVwr ); |
| 855 | } |
| 856 | |
| 857 | AIS2D_DisplayStatus AIS2D_InteractiveContext::DisplayStatus( const Handle(AIS2D_InteractiveObject)& anIObj ) const { |
| 858 | |
| 859 | if ( anIObj.IsNull() ) return AIS2D_DS_None; |
| 860 | |
| 861 | if ( myObjects.IsBound(anIObj)) |
| 862 | return myObjects(anIObj)->GraphicStatus(); |
| 863 | |
| 864 | AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts); |
| 865 | for ( ; ItM.More(); ItM.Next() ) |
| 866 | if ( ItM.Value()->IsIn(anIObj) ) |
| 867 | return AIS2D_DS_Temporary; |
| 868 | |
| 869 | return AIS2D_DS_None; |
| 870 | |
| 871 | } |
| 872 | |
| 873 | AIS2D_PToListOfInt AIS2D_InteractiveContext::DisplayedModes( const Handle(AIS2D_InteractiveObject)& anIObj ) const { |
| 874 | return myObjects(anIObj)->DisplayedModes(); |
| 875 | } |
| 876 | |
| 877 | Standard_Boolean AIS2D_InteractiveContext::IsDisplayed( const Handle(AIS2D_InteractiveObject)& anIObj ) const { |
| 878 | |
| 879 | if ( anIObj.IsNull() ) return Standard_False; |
| 880 | |
| 881 | if ( myObjects.IsBound(anIObj) ) |
| 882 | if ( myObjects(anIObj)->GraphicStatus() == AIS2D_DS_Displayed ) |
| 883 | return Standard_True; |
| 884 | |
| 885 | AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts); |
| 886 | for ( ; ItM.More(); ItM.Next() ) |
| 887 | if ( ItM.Value()->IsDisplayed(anIObj) ) return Standard_True; |
| 888 | |
| 889 | return Standard_False; |
| 890 | |
| 891 | } |
| 892 | |
| 893 | Standard_Boolean AIS2D_InteractiveContext::IsDisplayed( const Handle(AIS2D_InteractiveObject)& /*anIObj*/, |
| 894 | const Standard_Integer /*aMode*/ ) const { |
| 895 | |
| 896 | return Standard_False; |
| 897 | |
| 898 | } |
| 899 | |
| 900 | Standard_Boolean AIS2D_InteractiveContext::IsHighlighted( const Handle(AIS2D_InteractiveObject)& anIObj ) const { |
| 901 | |
| 902 | if ( anIObj.IsNull() ) return Standard_False; |
| 903 | |
| 904 | if (!HasOpenedContext()){ |
| 905 | #ifdef OCC146 |
| 906 | if (!anIObj->IsHighlighted()) return Standard_False; |
| 907 | #endif |
| 908 | if(!myObjects.IsBound(anIObj)) |
| 909 | return Standard_False; |
| 910 | return myObjects(anIObj)->IsHighlight(); |
| 911 | } |
| 912 | AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts); |
| 913 | for (;ItM.More();ItM.Next() ) { |
| 914 | if (ItM.Value()->IsHighlight(anIObj) ) |
| 915 | return Standard_True; |
| 916 | } |
| 917 | return Standard_False; |
| 918 | |
| 919 | |
| 920 | } |
| 921 | |
| 922 | Standard_Boolean AIS2D_InteractiveContext::IsHighlighted( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 923 | Standard_Boolean& /*WithColor*/, |
| 924 | Quantity_NameOfColor& /*theHiCol*/ ) const { |
| 925 | if ( anIObj.IsNull() ) return Standard_False; |
| 926 | |
| 927 | if ( !HasOpenedContext() ) { |
| 928 | #ifdef OCC146 |
| 929 | if (!anIObj->IsHighlighted()) return Standard_False; |
| 930 | #endif |
| 931 | if ( !myObjects.IsBound(anIObj) ) |
| 932 | return Standard_False; |
| 933 | return myObjects(anIObj)->IsHighlight(); |
| 934 | } |
| 935 | AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts); |
| 936 | for ( ; ItM.More(); ItM.Next() ) |
| 937 | if ( ItM.Value()->IsHighlight(anIObj) ) |
| 938 | return Standard_True; |
| 939 | |
| 940 | return Standard_False; |
| 941 | |
| 942 | } |
| 943 | |
| 944 | void AIS2D_InteractiveContext::SubIntensityOn( |
| 945 | const Handle(AIS2D_InteractiveObject)& anIObj, |
| 946 | const Standard_Boolean UpdateVwr) { |
| 947 | |
| 948 | Standard_Integer indCol; |
| 949 | if ( !HasOpenedContext() ) { |
| 950 | if ( !myObjects.IsBound(anIObj) ) return; |
| 951 | const Handle(AIS2D_GlobalStatus) GStatus = myObjects(anIObj); |
| 952 | if ( GStatus->IsSubIntensityOn() ) return; |
| 953 | GStatus->SubIntensityOn(); |
| 954 | Standard_Boolean UpdMain(Standard_False),UpdColl(Standard_False); |
| 955 | |
| 956 | for (TColStd_ListIteratorOfListOfInteger It( * GStatus->DisplayedModes() ); It.More(); It.Next() ) { |
| 957 | if ( GStatus->GraphicStatus()==AIS2D_DS_Displayed) { |
| 958 | SetHighlightColor( mySubIntensity ); |
| 959 | HighlightWithColor( anIObj, mySubIntensity ); |
| 960 | UpdMain = Standard_True; |
| 961 | } else if ( GStatus->GraphicStatus()==AIS2D_DS_Erased ) { |
| 962 | indCol = myCollectorVwr->InitializeColor( mySubIntensity ); |
| 963 | myCollectorVwr->View()->SetDefaultOverrideColor( indCol ); |
| 964 | HighlightWithColor(anIObj, mySubIntensity ); |
| 965 | UpdColl=Standard_True; |
| 966 | } |
| 967 | } |
| 968 | if ( UpdateVwr ) { |
| 969 | if ( UpdMain) myMainVwr->Update(); |
| 970 | if ( UpdColl ) myCollectorVwr->Update(); |
| 971 | } |
| 972 | } else { |
| 973 | if ( myObjects.IsBound(anIObj) ) { |
| 974 | const Handle(AIS2D_GlobalStatus)& GStatus = myObjects(anIObj); |
| 975 | GStatus->SubIntensityOn(); |
| 976 | for ( ItL.Initialize( * GStatus->DisplayedModes() ); ItL.More(); ItL.Next() ) { |
| 977 | SetHighlightColor( mySubIntensity ); |
| 978 | HighlightWithColor(anIObj, mySubIntensity ); |
| 979 | } |
| 980 | } else |
| 981 | myLocalContexts(myCurLocalIndex)->SubIntensityOn(anIObj); |
| 982 | |
| 983 | if (UpdateVwr) myMainVwr->Update(); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | void AIS2D_InteractiveContext::SubIntensityOff( |
| 988 | const Handle(AIS2D_InteractiveObject)& anIObj, |
| 989 | const Standard_Boolean UpdateVwr) { |
| 990 | |
| 991 | if ( !HasOpenedContext() ) { |
| 992 | if ( !myObjects.IsBound(anIObj) ) return; |
| 993 | const Handle(AIS2D_GlobalStatus)& GStatus = myObjects(anIObj); |
| 994 | if ( !GStatus->IsSubIntensityOn() ) return; |
| 995 | GStatus->SubIntensityOff(); |
| 996 | Standard_Boolean UpdMain(Standard_False),UpdColl(Standard_False); |
| 997 | |
| 998 | for ( TColStd_ListIteratorOfListOfInteger It( * GStatus->DisplayedModes() ); It.More() ;It.Next() ) { |
| 999 | if ( GStatus->GraphicStatus() != AIS2D_DS_Erased ) { |
| 1000 | Unhighlight( anIObj ); |
| 1001 | UpdMain = Standard_True; |
| 1002 | } else { |
| 1003 | Unhighlight( anIObj ); |
| 1004 | UpdColl=Standard_True; |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | Standard_Integer DM,SM; |
| 1009 | AIS2D_TypeOfDetection HM; |
| 1010 | GetDefModes(anIObj,DM,HM,SM); |
| 1011 | if ( IsIOSelected(anIObj) ) |
| 1012 | Highlight(anIObj,HM); |
| 1013 | |
| 1014 | if ( UpdateVwr ) { |
| 1015 | if ( UpdMain ) myMainVwr->Update(); |
| 1016 | if ( UpdColl ) myCollectorVwr->Update(); |
| 1017 | } |
| 1018 | } else { |
| 1019 | if ( myObjects.IsBound(anIObj) ) { |
| 1020 | const Handle(AIS2D_GlobalStatus)& GStatus = myObjects(anIObj); |
| 1021 | GStatus->SubIntensityOff(); |
| 1022 | for (ItL.Initialize(* GStatus->DisplayedModes());ItL.More();ItL.Next()) |
| 1023 | Unhighlight(anIObj); |
| 1024 | if (GStatus->IsHighlight()) |
| 1025 | Highlight(anIObj); |
| 1026 | } else |
| 1027 | myLocalContexts(myCurLocalIndex)->SubIntensityOff(anIObj); |
| 1028 | if ( IsSelected(anIObj) ) |
| 1029 | Highlight(anIObj); |
| 1030 | |
| 1031 | if ( UpdateVwr) myMainVwr->Update(); |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | Standard_Boolean AIS2D_InteractiveContext::IsInCollector( const Handle(AIS2D_InteractiveObject)& anIObj ) const { |
| 1036 | |
| 1037 | if ( anIObj.IsNull() ) |
| 1038 | return Standard_False; |
| 1039 | |
| 1040 | if ( myObjects.IsBound(anIObj) ) |
| 1041 | return ( myObjects( anIObj)->GraphicStatus() == AIS2D_DS_Erased ); |
| 1042 | return Standard_False; |
| 1043 | } |
| 1044 | |
| 1045 | void AIS2D_InteractiveContext::Status( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 1046 | TCollection_ExtendedString& aStatus ) const { |
| 1047 | |
| 1048 | aStatus = ""; |
| 1049 | |
| 1050 | if ( anIObj.IsNull() ) return ; |
| 1051 | if ( myObjects.IsBound(anIObj) ) { |
| 1052 | aStatus += "\t ____________________________________________"; |
| 1053 | aStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:"; |
| 1054 | const Handle(AIS2D_GlobalStatus)& theGStat = myObjects(anIObj); |
| 1055 | switch ( theGStat->GraphicStatus() ) { |
| 1056 | case AIS2D_DS_Displayed: { |
| 1057 | aStatus +="\t| -->Displayed\n"; |
| 1058 | break; |
| 1059 | } |
| 1060 | case AIS2D_DS_Erased: { |
| 1061 | aStatus +="\t| -->Erased\n"; |
| 1062 | break; |
| 1063 | } |
| 1064 | case AIS2D_DS_FullErased: { |
| 1065 | aStatus +="\t| -->Full Erased\n"; |
| 1066 | break; |
| 1067 | |
| 1068 | } |
| 1069 | case AIS2D_DS_Temporary: |
| 1070 | case AIS2D_DS_None: |
| 1071 | break; |
| 1072 | |
| 1073 | } |
| 1074 | aStatus += "\t| Active Display Modes in the MainViewer :\n"; |
| 1075 | for ( ItL.Initialize(*(theGStat->DisplayedModes())); |
| 1076 | ItL.More(); ItL.Next() ) { |
| 1077 | aStatus += "\t|\t Mode "; |
| 1078 | aStatus += TCollection_AsciiString(ItL.Value()); |
| 1079 | aStatus+="\n"; |
| 1080 | } |
| 1081 | if ( IsCurrent(anIObj) ) |
| 1082 | aStatus +="\t| Current\n"; |
| 1083 | //if ( IsSelected(anIObj) ) |
| 1084 | // aStatus +="\t| Selected\n"; |
| 1085 | |
| 1086 | aStatus += "\t| Active Selection Modes in the MainViewer :\n"; |
| 1087 | for ( ItL.Initialize(*(theGStat->SelectionModes() )); |
| 1088 | ItL.More(); ItL.Next() ) { |
| 1089 | aStatus += "\t\t Mode "; |
| 1090 | aStatus += TCollection_AsciiString(ItL.Value()); |
| 1091 | aStatus+="\n"; |
| 1092 | } |
| 1093 | aStatus += "\t ____________________________________________"; |
| 1094 | |
| 1095 | } |
| 1096 | |
| 1097 | } |
| 1098 | |
| 1099 | void AIS2D_InteractiveContext::UpdateCurrentViewer() { |
| 1100 | |
| 1101 | if ( !myMainVwr.IsNull() ) myMainVwr->UpdateNew(); |
| 1102 | |
| 1103 | } |
| 1104 | |
| 1105 | void AIS2D_InteractiveContext::UpdateCollector() { |
| 1106 | if ( !myCollectorVwr.IsNull() ) myCollectorVwr->UpdateNew(); |
| 1107 | } |
| 1108 | |
| 1109 | void AIS2D_InteractiveContext::DisplayedObjects (AIS2D_ListOfIO& aListOfIO, |
| 1110 | const Standard_Boolean OnlyFromNeutral) const |
| 1111 | { |
| 1112 | AIS2D_DataMapIteratorOfDataMapOfIOStatus It( myObjects ); |
| 1113 | |
| 1114 | if ( !HasOpenedContext() || OnlyFromNeutral ) { |
| 1115 | for ( ; It.More(); It.Next() ) |
| 1116 | if ( It.Value()->GraphicStatus() == AIS2D_DS_Displayed ) |
| 1117 | aListOfIO.Append( It.Key() ); |
| 1118 | } else { |
| 1119 | TColStd_MapOfTransient theMap; |
| 1120 | |
| 1121 | for ( ; It.More(); It.Next() ) { |
| 1122 | if ( It.Value()->GraphicStatus() == AIS2D_DS_Displayed ) |
| 1123 | theMap.Add(It.Key()); |
| 1124 | } |
| 1125 | |
| 1126 | Standard_Integer NbDisp; |
| 1127 | for ( AIS2D_DataMapIteratorOfDataMapOfLC it1(myLocalContexts); |
| 1128 | it1.More(); it1.Next() ) { |
| 1129 | const Handle(AIS2D_LocalContext)& LC = it1.Value(); |
| 1130 | NbDisp = LC->DisplayedObjects(theMap); |
| 1131 | } |
| 1132 | |
| 1133 | Handle(AIS2D_InteractiveObject) curIO; |
| 1134 | Handle(Standard_Transient) Tr; |
| 1135 | for ( TColStd_MapIteratorOfMapOfTransient it2(theMap); it2.More(); it2.Next() ) { |
| 1136 | Tr = it2.Key(); |
| 1137 | curIO = *((Handle(AIS2D_InteractiveObject)*) &Tr); |
| 1138 | aListOfIO.Append(curIO); |
| 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | void AIS2D_InteractiveContext::GetDefModes( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 1144 | Standard_Integer& DispMode, |
| 1145 | AIS2D_TypeOfDetection& HiMode, |
| 1146 | Standard_Integer& SelMode) const { |
| 1147 | |
| 1148 | if ( anIObj.IsNull() ) return ; |
| 1149 | |
| 1150 | DispMode = anIObj->HasDisplayMode() ? anIObj->DisplayMode() : anIObj->DefaultDisplayMode(); |
| 1151 | HiMode = anIObj->HasHighlightMode() ? anIObj->HighlightMode() : anIObj->DefaultHighlightMode(); |
| 1152 | SelMode = anIObj->HasSelectionMode() ? anIObj->SelectionMode() : anIObj->DefaultSelectionMode(); |
| 1153 | |
| 1154 | } |
| 1155 | |
| 1156 | void AIS2D_InteractiveContext::EraseGlobal( |
| 1157 | const Handle(AIS2D_InteractiveObject)& anIObj, |
| 1158 | const Standard_Boolean /*UpdateVwr*/, |
| 1159 | const Standard_Boolean /*PutInCollector*/) { |
| 1160 | |
| 1161 | if ( anIObj.IsNull() ) return ; |
| 1162 | if ( !myObjects.IsBound( anIObj ) ) return; |
| 1163 | |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | void AIS2D_InteractiveContext::SetHighlightColor( const Quantity_NameOfColor aCol ) { |
| 1168 | |
| 1169 | if ( myHighlightColor != aCol ) { |
| 1170 | myHighlightColor = aCol; |
| 1171 | Standard_Integer anIndex = myMainVwr->InitializeColor(aCol); |
| 1172 | myMainVwr->View()->SetDefaultOverrideColor( anIndex ); |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | void AIS2D_InteractiveContext::SetSelectionColor( const Quantity_NameOfColor aCol ) { |
| 1177 | |
| 1178 | if ( mySelectionColor != aCol ) { |
| 1179 | mySelectionColor = aCol; |
| 1180 | Standard_Integer anIndex = myMainVwr->InitializeColor(aCol); |
| 1181 | myMainVwr->View()->SetDefaultOverrideColor(anIndex); |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | void AIS2D_InteractiveContext::SetSubIntensityColor( const Quantity_NameOfColor aCol ) { |
| 1186 | mySubIntensity = aCol; |
| 1187 | } |
| 1188 | |
| 1189 | Standard_Integer AIS2D_InteractiveContext::HighestIndex() const { |
| 1190 | |
| 1191 | AIS2D_DataMapIteratorOfDataMapOfLC It( myLocalContexts ); |
| 1192 | Standard_Integer HiInd = 0; |
| 1193 | for ( ; It.More(); It.Next() ) |
| 1194 | HiInd = ( It.Key() > HiInd ) ? It.Key() : HiInd; |
| 1195 | return HiInd; |
| 1196 | |
| 1197 | } |
| 1198 | |
| 1199 | Standard_Integer AIS2D_InteractiveContext::InitializeColor( const Quantity_Color& aColor ) { |
| 1200 | |
| 1201 | #ifdef IMP140901 |
| 1202 | Handle(Aspect_ColorMap) colormap = myMainVwr->ColorMap(); |
| 1203 | #else |
| 1204 | Handle(Aspect_GenericColorMap) colormap = myMainVwr->ColorMap(); |
| 1205 | #endif |
| 1206 | Standard_Integer size = colormap->Size(); |
| 1207 | Standard_Integer indColor = colormap->AddEntry(aColor); |
| 1208 | if( size != colormap->Size() ) { |
| 1209 | myMainVwr->SetColorMap( colormap ); |
| 1210 | } |
| 1211 | return indColor; |
| 1212 | |
| 1213 | } |
| 1214 | |
| 1215 | Standard_Integer AIS2D_InteractiveContext::InitializeStyle( const Aspect_TypeOfLine aType ) { |
| 1216 | |
| 1217 | Handle(Aspect_TypeMap) typemap = myMainVwr->TypeMap(); |
| 1218 | Standard_Integer size = typemap->Size(); |
| 1219 | Standard_Integer indType = typemap->AddEntry(aType); |
| 1220 | if( size != typemap->Size() ) { |
| 1221 | myMainVwr->SetTypeMap( typemap ); |
| 1222 | } |
| 1223 | |
| 1224 | return indType; |
| 1225 | |
| 1226 | } |
| 1227 | |
| 1228 | Standard_Integer AIS2D_InteractiveContext::InitializeWidth( const Aspect_WidthOfLine aWidth ) { |
| 1229 | |
| 1230 | Handle(Aspect_WidthMap) widthmap = myMainVwr->WidthMap(); |
| 1231 | Standard_Integer size = widthmap->Size(); |
| 1232 | Standard_Integer indWidth = widthmap->AddEntry(aWidth); |
| 1233 | if( size != widthmap->Size() ) { |
| 1234 | myMainVwr->SetWidthMap( widthmap ); |
| 1235 | } |
| 1236 | |
| 1237 | return indWidth; |
| 1238 | |
| 1239 | } |
| 1240 | |
| 1241 | Standard_Integer AIS2D_InteractiveContext::InitializeMarker( const Aspect_TypeOfMarker aMark ) { |
| 1242 | |
| 1243 | Handle(Aspect_MarkMap) markmap = myMainVwr->MarkMap(); |
| 1244 | Standard_Integer size = markmap->Size(); |
| 1245 | Standard_Integer indMark = markmap->AddEntry(aMark); |
| 1246 | if( size != markmap->Size() ) { |
| 1247 | myMainVwr->SetMarkMap( markmap ); |
| 1248 | } |
| 1249 | |
| 1250 | return indMark; |
| 1251 | |
| 1252 | } |
| 1253 | |
| 1254 | Standard_Integer AIS2D_InteractiveContext::InitializeFont( const Aspect_FontStyle& aFont ) { |
| 1255 | |
| 1256 | Handle(Aspect_FontMap) fontmap = myMainVwr->FontMap(); |
| 1257 | Standard_Integer size = fontmap->Size(); |
| 1258 | Standard_Integer indFont = fontmap->AddEntry(aFont); |
| 1259 | if( size != fontmap->Size() ) { |
| 1260 | myMainVwr->SetFontMap( fontmap ); |
| 1261 | } |
| 1262 | return indFont; |
| 1263 | |
| 1264 | } |
| 1265 | |
| 1266 | void AIS2D_InteractiveContext::DrawObject( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 1267 | const Standard_Integer aDispMode ) { |
| 1268 | |
| 1269 | if ( anIObj->IsKind(STANDARD_TYPE(AIS2D_ProjShape) ) ) { |
| 1270 | |
| 1271 | Handle(AIS2D_ProjShape) thePS = Handle(AIS2D_ProjShape)::DownCast(anIObj); |
| 1272 | Handle(Graphic2d_Line) theLines = thePS->GetPrimitives(); |
| 1273 | Handle(Prs2d_AspectLine) theAspLine; |
| 1274 | |
| 1275 | if ( !anIObj->HasAspect(theLines) ) { |
| 1276 | Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE); |
| 1277 | theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot); |
| 1278 | anIObj->SetAspect( theAspLine, theLines ); |
| 1279 | |
| 1280 | } else { |
| 1281 | theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLines) ); |
| 1282 | } |
| 1283 | |
| 1284 | Quantity_Color aColor; |
| 1285 | Aspect_TypeOfLine aType; |
| 1286 | Aspect_WidthOfLine aWidth; |
| 1287 | |
| 1288 | theAspLine->ValuesOfLine( aColor, aType, aWidth ); |
| 1289 | |
| 1290 | Standard_Integer colorInd = theAspLine->ColorIndex(); |
| 1291 | Standard_Integer typeInd = theAspLine->TypeIndex(); |
| 1292 | Standard_Integer widthInd = theAspLine->WidthIndex(); |
| 1293 | |
| 1294 | if ( !colorInd ) { |
| 1295 | colorInd = InitializeColor( aColor ); |
| 1296 | theLines->SetColorIndex( colorInd ); |
| 1297 | } |
| 1298 | |
| 1299 | if ( !typeInd ) { |
| 1300 | typeInd = InitializeStyle( aType ); |
| 1301 | theLines->SetTypeIndex( typeInd ); |
| 1302 | } |
| 1303 | |
| 1304 | if ( !widthInd ) { |
| 1305 | widthInd = InitializeWidth( aWidth ); |
| 1306 | theLines->SetWidthIndex( widthInd ); |
| 1307 | } |
| 1308 | |
| 1309 | if ( thePS->IsHLMode() ) { |
| 1310 | Handle(Graphic2d_Line) theHLines = thePS->GetHLPrimitives(); |
| 1311 | theHLines->SetColorIndex( colorInd ); |
| 1312 | theHLines->SetWidthIndex( widthInd ); |
| 1313 | Standard_Integer theDashInd = InitializeStyle( Aspect_TOL_DASH ); |
| 1314 | theHLines->SetTypeIndex( theDashInd ); |
| 1315 | } |
| 1316 | |
| 1317 | } else { |
| 1318 | |
| 1319 | Handle(Graphic2d_Primitive) thePrim; |
| 1320 | |
| 1321 | for ( Standard_Integer i = 1; i <= anIObj->Length(); i++ ) { |
| 1322 | thePrim = anIObj->Primitive( i ); |
| 1323 | thePrim->SetDisplayMode(aDispMode); |
| 1324 | if ( thePrim->IsKind(STANDARD_TYPE(Graphic2d_Line) ) ) { |
| 1325 | |
| 1326 | Handle(Graphic2d_Line) theLine = Handle(Graphic2d_Line)::DownCast(thePrim); |
| 1327 | Handle(Prs2d_AspectLine) theAspLine; |
| 1328 | |
| 1329 | if ( !anIObj->HasAspect(theLine) ) { |
| 1330 | Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE); |
| 1331 | theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot); |
| 1332 | anIObj->SetAspect( theAspLine, theLine ); |
| 1333 | |
| 1334 | } else { |
| 1335 | theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLine) ); |
| 1336 | } |
| 1337 | |
| 1338 | Quantity_Color aColor; |
| 1339 | Aspect_TypeOfLine aType; |
| 1340 | Aspect_WidthOfLine aWidth; |
| 1341 | |
| 1342 | Quantity_Color aIntColor; |
| 1343 | Graphic2d_TypeOfPolygonFilling aTypeFill; |
| 1344 | Standard_Integer aTile; |
| 1345 | Standard_Boolean aDrawEdge; |
| 1346 | |
| 1347 | theAspLine->ValuesOfLine( aColor, aType, aWidth ); |
| 1348 | theAspLine->ValuesOfPoly( aIntColor, aTypeFill, aTile, aDrawEdge ); |
| 1349 | |
| 1350 | Standard_Integer colorInd = theAspLine->ColorIndex(); |
| 1351 | Standard_Integer typeInd = theAspLine->TypeIndex(); |
| 1352 | Standard_Integer widthInd = theAspLine->WidthIndex(); |
| 1353 | Standard_Integer colorIntInd = theAspLine->InterColorIndex(); |
| 1354 | |
| 1355 | if ( !colorInd ) { |
| 1356 | colorInd = InitializeColor( aColor ); |
| 1357 | theLine->SetColorIndex( colorInd ); |
| 1358 | } |
| 1359 | |
| 1360 | if ( !typeInd ) { |
| 1361 | typeInd = InitializeStyle( aType ); |
| 1362 | theLine->SetTypeIndex( typeInd ); |
| 1363 | } |
| 1364 | |
| 1365 | if ( !widthInd ) { |
| 1366 | widthInd = InitializeWidth( aWidth ); |
| 1367 | theLine->SetWidthIndex( widthInd ); |
| 1368 | } |
| 1369 | |
| 1370 | if ( !colorIntInd ) { |
| 1371 | colorIntInd = InitializeColor( aIntColor ); |
| 1372 | theLine->SetInteriorColorIndex( colorIntInd ); |
| 1373 | } |
| 1374 | |
| 1375 | theLine->SetTypeOfPolygonFilling( aTypeFill ); |
| 1376 | theLine->SetInteriorPattern( aTile ); |
| 1377 | theLine->SetDrawEdge( aDrawEdge ); |
| 1378 | |
| 1379 | if ( theLine->IsKind(STANDARD_TYPE(Prs2d_Point) ) ) { |
| 1380 | |
| 1381 | Handle(Prs2d_Point) thePnt = Handle(Prs2d_Point)::DownCast(theLine); |
| 1382 | thePnt->SetIndex( InitializeMarker( thePnt->Marker() ) ); |
| 1383 | } |
| 1384 | |
| 1385 | } // end if the kind of primitive is Graphic2d_Line |
| 1386 | |
| 1387 | } // end for exploration of the interactive object |
| 1388 | |
| 1389 | } // end if IO is AIS2D_ProjShape |
| 1390 | |
| 1391 | } |
| 1392 | |
| 1393 | void AIS2D_InteractiveContext::ResetOriginalState(const Standard_Boolean /*updateviewer*/) { |
| 1394 | /* |
| 1395 | Standard_Boolean upd_main(Standard_False),upd_col(Standard_False); |
| 1396 | TColStd_ListIteratorOfListOfInteger itl; |
| 1397 | |
| 1398 | for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){ |
| 1399 | const Handle(AIS_InteractiveObject)& iobj = it.Key(); |
| 1400 | const Handle(AIS_GlobalStatus)& STAT = it.Value(); |
| 1401 | switch(STAT->GraphicStatus()){ |
| 1402 | case AIS_DS_Displayed:{ |
| 1403 | upd_main = Standard_True; |
| 1404 | |
| 1405 | // partie display... |
| 1406 | for(itl.Initialize(STAT->DisplayedModes());itl.More();itl.Next()) |
| 1407 | myMainPM->Display(iobj,itl.Value()); |
| 1408 | if(STAT->IsHilighted()){ |
| 1409 | if(STAT->HilightColor()!=Quantity_NOC_WHITE) |
| 1410 | HilightWithColor(iobj,STAT->HilightColor(),Standard_False); |
| 1411 | else |
| 1412 | Hilight(iobj,Standard_False); |
| 1413 | } |
| 1414 | //partie selection |
| 1415 | for(itl.Initialize(STAT->SelectionModes());itl.More();itl.Next()){ |
| 1416 | if(itl.Value()!=-1) |
| 1417 | mgrSelector->Activate(iobj,itl.Value(),myMainSel); |
| 1418 | } |
| 1419 | break; |
| 1420 | } |
| 1421 | case AIS_DS_Erased:{ |
| 1422 | upd_col = Standard_True; |
| 1423 | EraseGlobal(iobj,Standard_False,Standard_True); |
| 1424 | break; |
| 1425 | } |
| 1426 | case AIS_DS_FullErased:{ |
| 1427 | EraseGlobal(iobj,Standard_False,Standard_False); |
| 1428 | break; |
| 1429 | } |
| 1430 | #ifndef DEB |
| 1431 | default: |
| 1432 | break; |
| 1433 | #endif |
| 1434 | } |
| 1435 | } |
| 1436 | if(updateviewer){ |
| 1437 | if(upd_main) |
| 1438 | myMainVwr->Update(); |
| 1439 | if(upd_col) |
| 1440 | myCollectorVwr->Update(); |
| 1441 | }*/ |
| 1442 | } |
| 1443 | |
| 1444 | Standard_Boolean AIS2D_InteractiveContext::AvailableToDetect( const Handle(AIS2D_InteractiveObject)& anIO ) const { |
| 1445 | #ifndef OCC146 |
| 1446 | if ( anIO->HighlightMode() == AIS2D_TOD_OBJECT) |
| 1447 | return ( ! anIO->State() ); |
| 1448 | #endif |
| 1449 | return Standard_True; |
| 1450 | } |
| 1451 | |
| 1452 | void AIS2D_InteractiveContext::DoDetectObject( const Handle(AIS2D_InteractiveObject)& theIO, |
| 1453 | const Handle(Graphic2d_TransientManager)& theDrawer ) { |
| 1454 | theIO->ClearSeqDetPrim(); |
| 1455 | #ifdef OCC146 |
| 1456 | if (!theIO->State()) |
| 1457 | #endif |
| 1458 | theIO->Unhighlight(); |
| 1459 | myCurDetectMode = theIO->HighlightMode(); |
| 1460 | switch ( myCurDetectMode ) { |
| 1461 | default : |
| 1462 | case AIS2D_TOD_OBJECT : |
| 1463 | if ( !IsIOSelected( theIO ) ) { |
| 1464 | theDrawer->Draw( theIO ); |
| 1465 | #ifdef OCC146 |
| 1466 | } |
| 1467 | { |
| 1468 | #endif |
| 1469 | if ( !IsIOPicked( theIO ) ) |
| 1470 | mySeqOfDetIO->Append( theIO ); |
| 1471 | } |
| 1472 | break; |
| 1473 | case AIS2D_TOD_PRIMITIVE: { |
| 1474 | Standard_Integer pLength = theIO->PickList()->Length(); |
| 1475 | Handle(Graphic2d_Primitive) thePrim; |
| 1476 | |
| 1477 | if ( pLength ) { |
| 1478 | for ( int i = 1; i <= pLength; i++ ) { |
| 1479 | thePrim = theIO->Primitive(theIO->PickList()->Value(i)); |
| 1480 | if ( ! thePrim->IsHighlighted() && |
| 1481 | ! IsPrimSelected ( theIO, thePrim ) ) { |
| 1482 | theDrawer->Draw( thePrim ); |
| 1483 | #ifdef OCC146 |
| 1484 | } |
| 1485 | { |
| 1486 | #endif |
| 1487 | if ( ! IsPrimPicked( theIO, thePrim ) ) { |
| 1488 | theIO->AddDetectPrim( thePrim, 0 ); |
| 1489 | if ( !IsIOPicked( theIO ) ) |
| 1490 | mySeqOfDetIO->Append( theIO ); |
| 1491 | } |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | } else { |
| 1496 | thePrim = theIO->Primitive( theIO->PickedIndex() ); |
| 1497 | if ( ! thePrim->IsHighlighted() ) { |
| 1498 | theDrawer->Draw( thePrim ); |
| 1499 | #ifdef OCC146 |
| 1500 | } |
| 1501 | { |
| 1502 | #endif |
| 1503 | if ( ! IsPrimPicked( theIO, thePrim ) ) { |
| 1504 | theIO->AddDetectPrim( thePrim, 0 ); |
| 1505 | if ( !IsIOPicked( theIO ) ) |
| 1506 | mySeqOfDetIO->Append( theIO ); |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | break; |
| 1512 | case AIS2D_TOD_ELEMENT: { |
| 1513 | Standard_Integer theInd, pLength = theIO->PickList()->Length(); |
| 1514 | Handle(Graphic2d_Primitive) thePrim; |
| 1515 | if ( pLength ) { |
| 1516 | for ( int i = 1; i <= pLength; i++ ) { |
| 1517 | thePrim = theIO->Primitive(theIO->PickList()->Value(i)); |
| 1518 | theInd = thePrim->PickedIndex(); |
| 1519 | if ( ! thePrim->IsHighlighted() ) { |
| 1520 | |
| 1521 | // SAV - begin |
| 1522 | const TColStd_MapOfInteger& indices = thePrim->PickedIndices(); |
| 1523 | |
| 1524 | if ( indices.Extent() ) { |
| 1525 | theDrawer->DrawPickedElements( thePrim ); |
| 1526 | |
| 1527 | TColStd_MapIteratorOfMapOfInteger it( indices ); |
| 1528 | theIO->AddDetectPrim( thePrim, it.Key() ); |
| 1529 | |
| 1530 | if ( !IsIOPicked( theIO ) ) |
| 1531 | mySeqOfDetIO->Append( theIO ); |
| 1532 | } |
| 1533 | else { |
| 1534 | |
| 1535 | for ( int j = 1; j <= thePrim->NumOfElemIndices(); ++j ) { |
| 1536 | theDrawer->DrawElement( thePrim, j ); |
| 1537 | if ( ! IsElemPicked( theIO, thePrim, j ) ) { |
| 1538 | theIO->AddDetectPrim( thePrim, j ); |
| 1539 | if ( !IsIOPicked( theIO ) ) |
| 1540 | mySeqOfDetIO->Append( theIO ); |
| 1541 | } |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | /* |
| 1546 | for ( int j = 1; j <= thePrim->NumOfElemIndices(); ++j ) { |
| 1547 | theDrawer->DrawElement( thePrim, j ); |
| 1548 | if ( ! IsElemPicked( theIO, thePrim, j ) ) { |
| 1549 | theIO->AddDetectPrim( thePrim, j ); |
| 1550 | if ( !IsIOPicked( theIO ) ) |
| 1551 | mySeqOfDetIO->Append( theIO ); |
| 1552 | } |
| 1553 | } |
| 1554 | */ |
| 1555 | } |
| 1556 | /*if ( ! IsElemSelected( theIO, thePrim, theInd ) ) { |
| 1557 | theDrawer->DrawElement( thePrim, theInd ); |
| 1558 | if ( ! IsElemPicked( theIO, thePrim, theInd ) ) { |
| 1559 | theIO->AddDetectPrim( thePrim, theInd ); |
| 1560 | if ( ! IsIOPicked( theIO ) ) |
| 1561 | mySeqOfDetIO->Append( theIO ); |
| 1562 | } |
| 1563 | |
| 1564 | } |
| 1565 | */ |
| 1566 | } |
| 1567 | } else { |
| 1568 | thePrim = theIO->Primitive(theIO->PickedIndex()); |
| 1569 | theInd = thePrim->PickedIndex(); |
| 1570 | #ifdef BUG |
| 1571 | if ( theInd > 0 ) |
| 1572 | #else |
| 1573 | if ( theInd != 0 ) |
| 1574 | #endif |
| 1575 | #ifdef OCC146 |
| 1576 | { |
| 1577 | #endif |
| 1578 | if ( ! IsElemSelected( theIO, thePrim, theInd ) ) { |
| 1579 | theDrawer->DrawElement( thePrim, theInd ); |
| 1580 | #ifdef OCC146 |
| 1581 | } |
| 1582 | { |
| 1583 | #endif |
| 1584 | if ( ! IsElemPicked( theIO, thePrim, theInd ) ) { |
| 1585 | theIO->AddDetectPrim( thePrim, theInd ); |
| 1586 | if ( ! IsIOPicked( theIO ) ) |
| 1587 | mySeqOfDetIO->Append( theIO ); |
| 1588 | } |
| 1589 | } |
| 1590 | #ifdef OCC146 |
| 1591 | } |
| 1592 | #endif |
| 1593 | } |
| 1594 | } |
| 1595 | break; |
| 1596 | case AIS2D_TOD_VERTEX: { |
| 1597 | Standard_Integer theInd, pLength = theIO->PickList()->Length(); |
| 1598 | Handle(Graphic2d_Primitive) thePrim; |
| 1599 | if ( pLength ) { |
| 1600 | for ( int i = 1; i <= pLength; i++ ) { |
| 1601 | thePrim = theIO->Primitive(theIO->PickList()->Value(i)); |
| 1602 | theInd = thePrim->PickedIndex(); |
| 1603 | if ( ! thePrim->IsHighlighted() ) |
| 1604 | for ( int j = 1; j <= thePrim->NumOfVertIndices(); ++j ) { |
| 1605 | theDrawer->DrawVertex( thePrim, j ); |
| 1606 | if ( ! IsElemPicked( theIO, thePrim, -j ) ) { |
| 1607 | theIO->AddDetectPrim( thePrim, -j ); |
| 1608 | if ( !IsIOPicked( theIO ) ) |
| 1609 | mySeqOfDetIO->Append( theIO ); |
| 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | /*if ( ! IsElemSelected( theIO, thePrim, theInd ) ) { |
| 1614 | theDrawer->DrawVertex( thePrim, -theInd ); |
| 1615 | if ( ! IsElemPicked( theIO, thePrim, theInd ) ) { |
| 1616 | theIO->AddDetectPrim( thePrim, -theInd ); |
| 1617 | if ( ! IsIOPicked( theIO ) ) |
| 1618 | mySeqOfDetIO->Append( theIO ); |
| 1619 | } |
| 1620 | }*/ |
| 1621 | |
| 1622 | } else { |
| 1623 | thePrim = theIO->Primitive(theIO->PickedIndex()); |
| 1624 | theInd = thePrim->PickedIndex(); |
| 1625 | if ( theInd < 0 ) |
| 1626 | #ifdef OCC146 |
| 1627 | { |
| 1628 | #endif |
| 1629 | if ( ! IsElemSelected( theIO, thePrim, theInd ) ) { |
| 1630 | theDrawer->DrawVertex( thePrim, -theInd ); |
| 1631 | #ifdef OCC146 |
| 1632 | } |
| 1633 | { |
| 1634 | #endif |
| 1635 | if ( ! IsElemPicked( theIO, thePrim, theInd ) ) { |
| 1636 | theIO->AddDetectPrim( thePrim, theInd ); |
| 1637 | if ( !IsIOPicked( theIO ) ) |
| 1638 | mySeqOfDetIO->Append( theIO ); |
| 1639 | } |
| 1640 | } |
| 1641 | #ifdef OCC146 |
| 1642 | } |
| 1643 | #endif |
| 1644 | |
| 1645 | } |
| 1646 | } |
| 1647 | break; |
| 1648 | } |
| 1649 | |
| 1650 | } |
| 1651 | |
| 1652 | Standard_Boolean AIS2D_InteractiveContext::IsIOPicked( const Handle(AIS2D_InteractiveObject)& anIO ) const { |
| 1653 | |
| 1654 | for ( int i = 1; i <= mySeqOfDetIO->Length(); i++ ) |
| 1655 | if ( anIO == mySeqOfDetIO->Value(i) ) |
| 1656 | return Standard_True; |
| 1657 | return Standard_False; |
| 1658 | |
| 1659 | } |
| 1660 | |
| 1661 | Standard_Boolean AIS2D_InteractiveContext::IsIOSelected( const Handle(AIS2D_InteractiveObject)& anIO ) const { |
| 1662 | |
| 1663 | for ( int i = 1; i <= mySeqOfSelIO->Length(); i++ ) |
| 1664 | if ( anIO == mySeqOfSelIO->Value(i) ) |
| 1665 | return Standard_True; |
| 1666 | return Standard_False; |
| 1667 | |
| 1668 | } |
| 1669 | |
| 1670 | Standard_Boolean AIS2D_InteractiveContext::IsPrimSelected( const Handle(AIS2D_InteractiveObject)& anIO, |
| 1671 | const Handle(Graphic2d_Primitive)& aPrim ) const { |
| 1672 | |
| 1673 | Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetSelectedSeqPrim(); |
| 1674 | |
| 1675 | for ( int i = 1; i <= theSPA->Length(); i++ ) |
| 1676 | if ( aPrim == theSPA->Value(i)->GetPrimitive() ) |
| 1677 | return Standard_True; |
| 1678 | return Standard_False; |
| 1679 | |
| 1680 | } |
| 1681 | |
| 1682 | Standard_Boolean AIS2D_InteractiveContext::IsPrimPicked( const Handle(AIS2D_InteractiveObject)& anIO, |
| 1683 | const Handle(Graphic2d_Primitive)& aPrim ) const { |
| 1684 | Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetDetectSeqPrim(); |
| 1685 | |
| 1686 | for ( int i = 1; i <= theSPA->Length(); i++ ) |
| 1687 | if ( aPrim == theSPA->Value(i)->GetPrimitive() ) |
| 1688 | return Standard_True; |
| 1689 | return Standard_False; |
| 1690 | } |
| 1691 | |
| 1692 | Standard_Boolean AIS2D_InteractiveContext::IsElemPicked( const Handle(AIS2D_InteractiveObject)& anIO, |
| 1693 | const Handle(Graphic2d_Primitive)& aPrim, |
| 1694 | const Standard_Integer ind ) const { |
| 1695 | Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetDetectSeqPrim(); |
| 1696 | for ( int i = 1; i <= theSPA->Length(); i++ ) |
| 1697 | if ( aPrim == theSPA->Value(i)->GetPrimitive() && |
| 1698 | ind == theSPA->Value(i)->GetIndex() ) |
| 1699 | return Standard_True; |
| 1700 | return Standard_False; |
| 1701 | } |
| 1702 | |
| 1703 | Standard_Boolean AIS2D_InteractiveContext::IsElemSelected( const Handle(AIS2D_InteractiveObject)& anIO, |
| 1704 | const Handle(Graphic2d_Primitive)& aPrim, |
| 1705 | const Standard_Integer ind ) const { |
| 1706 | Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetSelectedSeqPrim(); |
| 1707 | for ( int i = 1; i <= theSPA->Length(); i++ ) |
| 1708 | if ( aPrim == theSPA->Value(i)->GetPrimitive() && |
| 1709 | ind == theSPA->Value(i)->GetIndex() ) |
| 1710 | return Standard_True; |
| 1711 | return Standard_False; |
| 1712 | } |
| 1713 | |
| 1714 | void AIS2D_InteractiveContext::Highlight( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 1715 | const Standard_Boolean updateVwr ) { |
| 1716 | if ( anIObj.IsNull() ) return; |
| 1717 | |
| 1718 | if ( !anIObj->HasInteractiveContext() ) |
| 1719 | anIObj->SetContext( this ); |
| 1720 | if ( !HasOpenedContext() ) { |
| 1721 | if ( !myObjects.IsBound(anIObj) ) return; |
| 1722 | Handle(AIS2D_GlobalStatus) aGS = myObjects(anIObj); |
| 1723 | |
| 1724 | aGS->SetHighlightStatus( Standard_True ); |
| 1725 | |
| 1726 | switch ( aGS->GraphicStatus() ) { |
| 1727 | |
| 1728 | case AIS2D_DS_Displayed: { |
| 1729 | |
| 1730 | Standard_Integer DispMode,SelMode; |
| 1731 | AIS2D_TypeOfDetection HiMode; |
| 1732 | GetDefModes( anIObj, DispMode, HiMode, SelMode ); |
| 1733 | Standard_Integer pInd; |
| 1734 | anIObj->Highlight(myMainVwr->InitializeColor( mySelectionColor )); |
| 1735 | switch( HiMode ) { |
| 1736 | default: |
| 1737 | case AIS2D_TOD_OBJECT: |
| 1738 | break; |
| 1739 | case AIS2D_TOD_PRIMITIVE: |
| 1740 | pInd = anIObj->PickedIndex(); |
| 1741 | anIObj->Unhighlight(); |
| 1742 | break; |
| 1743 | case AIS2D_TOD_ELEMENT: |
| 1744 | pInd = anIObj->PickedIndex(); |
| 1745 | anIObj->Unhighlight(); |
| 1746 | break; |
| 1747 | case AIS2D_TOD_VERTEX: |
| 1748 | pInd = anIObj->PickedIndex(); |
| 1749 | anIObj->Unhighlight(); |
| 1750 | break; |
| 1751 | } //end switch |
| 1752 | |
| 1753 | if ( updateVwr) myMainVwr->Update(); |
| 1754 | |
| 1755 | break; |
| 1756 | } |
| 1757 | case AIS2D_DS_Erased: { |
| 1758 | #ifdef DEB |
| 1759 | Standard_Integer HiMode = anIObj->HasHighlightMode() ? |
| 1760 | anIObj->HighlightMode() : anIObj->DefaultHighlightMode(); |
| 1761 | #endif |
| 1762 | anIObj->Highlight(myCollectorVwr->InitializeColor( mySelectionColor )); |
| 1763 | if ( updateVwr ) myCollectorVwr->Update(); |
| 1764 | break; |
| 1765 | } |
| 1766 | case AIS2D_DS_FullErased: |
| 1767 | case AIS2D_DS_Temporary: |
| 1768 | case AIS2D_DS_None: |
| 1769 | break; |
| 1770 | } //end switch |
| 1771 | } // end if opened context isn't exists |
| 1772 | //else |
| 1773 | // myLocalContexts(myCurLocalIndex)->Highlight(anIObj); |
| 1774 | |
| 1775 | } |
| 1776 | |
| 1777 | void AIS2D_InteractiveContext::HighlightWithColor( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 1778 | const Quantity_NameOfColor aCol, |
| 1779 | const Standard_Boolean updateVwr ) { |
| 1780 | |
| 1781 | if ( anIObj.IsNull() ) return; |
| 1782 | |
| 1783 | if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext(this); |
| 1784 | |
| 1785 | if ( !HasOpenedContext() ) { |
| 1786 | if ( !myObjects.IsBound(anIObj) ) return; |
| 1787 | |
| 1788 | const Handle(AIS2D_GlobalStatus)& aGS = myObjects(anIObj); |
| 1789 | //const TColStd_ListOfInteger& LL = * aGS->DisplayedModes(); |
| 1790 | |
| 1791 | aGS->SetHighlightStatus (Standard_True); |
| 1792 | |
| 1793 | switch ( aGS->GraphicStatus() ) { |
| 1794 | case AIS2D_DS_Displayed:{ |
| 1795 | Standard_Integer DispMode, SelMode; |
| 1796 | AIS2D_TypeOfDetection HiMode; |
| 1797 | GetDefModes( anIObj, DispMode, HiMode, SelMode ); |
| 1798 | Standard_Integer indCol = myMainVwr->InitializeColor( aCol ); |
| 1799 | anIObj->Highlight(indCol); |
| 1800 | //SetSelectionColor(aCol); |
| 1801 | aGS->SetHighlightColor(aCol); |
| 1802 | // if ( updateVwr ) myMainVwr->Update(); |
| 1803 | break; |
| 1804 | } |
| 1805 | case AIS2D_DS_Erased: { |
| 1806 | #ifdef DEB |
| 1807 | Standard_Integer HiMode = anIObj->HasHighlightMode()? anIObj->HighlightMode():0; |
| 1808 | Standard_Integer indCol = myCollectorVwr->InitializeColor( aCol ); |
| 1809 | #endif |
| 1810 | if ( updateVwr) myCollectorVwr->Update(); |
| 1811 | break; |
| 1812 | } |
| 1813 | case AIS2D_DS_FullErased: |
| 1814 | case AIS2D_DS_Temporary: |
| 1815 | case AIS2D_DS_None: |
| 1816 | break; |
| 1817 | } |
| 1818 | } // else |
| 1819 | // myLocalContexts(myCurLocalIndex)->Highlight(anIObj,aCol); |
| 1820 | if ( updateVwr) myMainVwr->Update(); |
| 1821 | |
| 1822 | } |
| 1823 | |
| 1824 | void AIS2D_InteractiveContext::Unhighlight( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 1825 | const Standard_Boolean updateVwr ) { |
| 1826 | if ( anIObj.IsNull() ) return; |
| 1827 | anIObj->Unhighlight(); |
| 1828 | switch ( anIObj->HighlightMode() ) { |
| 1829 | default: |
| 1830 | case AIS2D_TOD_OBJECT: |
| 1831 | break; |
| 1832 | case AIS2D_TOD_PRIMITIVE: |
| 1833 | if ( !anIObj->Primitive(anIObj->PickedIndex()).IsNull() ) |
| 1834 | anIObj->Primitive(anIObj->PickedIndex())->Unhighlight(); |
| 1835 | break; |
| 1836 | case AIS2D_TOD_ELEMENT: |
| 1837 | if ( !anIObj->Primitive(anIObj->PickedIndex()).IsNull() ) |
| 1838 | anIObj->Primitive(anIObj->PickedIndex())->Unhighlight(); |
| 1839 | break; |
| 1840 | case AIS2D_TOD_VERTEX: |
| 1841 | if ( !anIObj->Primitive(anIObj->PickedIndex()).IsNull() ) |
| 1842 | anIObj->Primitive(anIObj->PickedIndex())->Unhighlight(); |
| 1843 | break; |
| 1844 | } |
| 1845 | if ( updateVwr) myMainVwr->UpdateNew(); |
| 1846 | } |
| 1847 | |
| 1848 | void AIS2D_InteractiveContext::Place( |
| 1849 | const Standard_Integer XPix, |
| 1850 | const Standard_Integer YPix, |
| 1851 | const Handle(V2d_View)& aView, |
| 1852 | const Handle(AIS2D_InteractiveObject)& anIO, |
| 1853 | const Standard_Boolean isTemporary ) { |
| 1854 | |
| 1855 | Standard_Real XPS, YPS; |
| 1856 | aView->Convert( XPix, YPix, XPS, YPS ); |
| 1857 | gp_GTrsf2d theGTrsf; |
| 1858 | gp_Trsf2d theTrsf; |
| 1859 | theTrsf.SetTranslationPart( gp_Vec2d(gp_Pnt2d(0.,0.), gp_Pnt2d(XPS, YPS) ) ); |
| 1860 | theGTrsf.SetTrsf2d( theTrsf ); |
| 1861 | anIO->SetTransform( theGTrsf ); |
| 1862 | Handle(V2d_Viewer) theViewer = aView->Viewer(); |
| 1863 | if ( isTemporary ) { |
| 1864 | |
| 1865 | Handle(Graphic2d_TransientManager) theDrawer = |
| 1866 | Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() ); |
| 1867 | Standard_Integer ind = theViewer->InitializeColor(myHighlightColor); |
| 1868 | theDrawer->SetOverride( Standard_True ); |
| 1869 | theDrawer->SetOverrideColor( ind ); |
| 1870 | Display( anIO, Standard_False ); |
| 1871 | anIO->Highlight( ind ); |
| 1872 | theDrawer->BeginDraw( aView->Driver() ); |
| 1873 | theDrawer->Draw( anIO ); |
| 1874 | theDrawer->EndDraw(); |
| 1875 | theDrawer->SetOverride( Standard_False ); |
| 1876 | return; |
| 1877 | } |
| 1878 | if ( !IsDisplayed( anIO ) ) |
| 1879 | Display( anIO ); |
| 1880 | else |
| 1881 | theViewer->Update(); |
| 1882 | |
| 1883 | } |
| 1884 | |
| 1885 | void AIS2D_InteractiveContext::Drag( |
| 1886 | const Standard_Integer XPix, |
| 1887 | const Standard_Integer YPix, |
| 1888 | const Handle(V2d_View)& aView, |
| 1889 | const Standard_Boolean isTemporary ) { |
| 1890 | |
| 1891 | if ( ! mySeqOfSelIO->IsEmpty() ) { |
| 1892 | Handle(AIS2D_InteractiveObject) theIO; |
| 1893 | for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) { |
| 1894 | theIO = mySeqOfSelIO->Value(j); |
| 1895 | if ( !isTemporary ) { |
| 1896 | Unhighlight( theIO, Standard_False ); |
| 1897 | theIO->SetState(0); |
| 1898 | mySeqOfSelIO->Remove(j); |
| 1899 | } |
| 1900 | Place( XPix, YPix, aView, theIO, isTemporary ); |
| 1901 | } |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | AIS2D_StatusOfDetection AIS2D_InteractiveContext::MoveTo( |
| 1906 | const Standard_Integer XPix, |
| 1907 | const Standard_Integer YPix, |
| 1908 | const Handle(V2d_View)& aView ) { |
| 1909 | |
| 1910 | RectMoveTo = Standard_False; |
| 1911 | if ( HasOpenedContext() && aView->Viewer() != myCollectorVwr ) { |
| 1912 | myWasLastMain = Standard_True; |
| 1913 | return myLocalContexts(myCurLocalIndex)->MoveTo( XPix, YPix, aView ); |
| 1914 | } |
| 1915 | Standard_Boolean is_main = Standard_True, UpdVwr = Standard_False; |
| 1916 | Handle(V2d_Viewer) theViewer = aView->Viewer(); |
| 1917 | |
| 1918 | if ( theViewer == myMainVwr ) { |
| 1919 | myLastPicked = myLastinMain; |
| 1920 | myWasLastMain = Standard_True; |
| 1921 | } else if ( theViewer == myCollectorVwr ) { |
| 1922 | myLastPicked = myLastinColl; |
| 1923 | is_main = Standard_False; |
| 1924 | myWasLastMain = Standard_False; |
| 1925 | } else |
| 1926 | return AIS2D_SOD_Error; |
| 1927 | |
| 1928 | AIS2D_StatusOfDetection theStat( AIS2D_SOD_Nothing ); |
| 1929 | |
| 1930 | Handle(Graphic2d_TransientManager) theDrawer = |
| 1931 | Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() ); |
| 1932 | |
| 1933 | Handle(Graphic2d_DisplayList) thePickList = aView->Pick( XPix, YPix, myDetectPrecision); |
| 1934 | |
| 1935 | if ( ! thePickList->IsEmpty() ) { |
| 1936 | |
| 1937 | if ( thePickList->Length() == 1 ) { |
| 1938 | Handle(Graphic2d_GraphicObject) theGO = thePickList->Value(1); |
| 1939 | if ( ! theGO->IsKind(STANDARD_TYPE(AIS2D_InteractiveObject) ) ) |
| 1940 | return AIS2D_SOD_Nothing; |
| 1941 | Handle(AIS2D_InteractiveObject) theIO = Handle(AIS2D_InteractiveObject)::DownCast(theGO); |
| 1942 | if ( IsIOPicked( theIO ) ) |
| 1943 | switch ( theIO->HighlightMode() ) { |
| 1944 | default: |
| 1945 | case AIS2D_TOD_OBJECT: |
| 1946 | return AIS2D_SOD_OnlyOneDetected; |
| 1947 | break; |
| 1948 | case AIS2D_TOD_PRIMITIVE: |
| 1949 | if ( IsPrimPicked(theIO, theIO->Primitive(theIO->PickedIndex())) ) |
| 1950 | return AIS2D_SOD_OnlyOneDetected; |
| 1951 | break; |
| 1952 | case AIS2D_TOD_ELEMENT: { |
| 1953 | Standard_Integer ind = theIO->PickedIndex(); |
| 1954 | if ( IsElemPicked( theIO, theIO->Primitive(ind), theIO->Primitive(ind)->PickedIndex() ) ) |
| 1955 | return AIS2D_SOD_OnlyOneDetected; |
| 1956 | else if ( ind < 0 ) |
| 1957 | myResetDetect= Standard_True; |
| 1958 | |
| 1959 | } |
| 1960 | break; |
| 1961 | case AIS2D_TOD_VERTEX: { |
| 1962 | Standard_Integer ind = theIO->PickedIndex(); |
| 1963 | if ( IsElemPicked( theIO, theIO->Primitive(ind), theIO->Primitive(ind)->PickedIndex() ) ) |
| 1964 | return AIS2D_SOD_OnlyOneDetected; |
| 1965 | //else if ( ind > 0 ) |
| 1966 | // myResetDetect= Standard_True; |
| 1967 | |
| 1968 | } |
| 1969 | break; |
| 1970 | |
| 1971 | } |
| 1972 | #ifdef OCC146 |
| 1973 | myResetDetect = Standard_True; |
| 1974 | #endif |
| 1975 | } |
| 1976 | if ( myResetDetect ) { |
| 1977 | mySeqOfDetIO->Clear(); |
| 1978 | Standard_Integer ind = myMainVwr->InitializeColor(myHighlightColor); |
| 1979 | |
| 1980 | for ( int i = 1 ; i <= thePickList->Length(); i++ ) { |
| 1981 | Handle(Graphic2d_GraphicObject) theGOi = thePickList->Value(i); |
| 1982 | if ( theGOi->IsKind(STANDARD_TYPE(AIS2D_InteractiveObject) ) ) { |
| 1983 | |
| 1984 | myLastPicked = Handle(AIS2D_InteractiveObject)::DownCast( theGOi ); |
| 1985 | ( is_main ) ? myLastinMain = myLastPicked : myLastinColl = myLastPicked; |
| 1986 | if ( myLastPicked->HasHighlightMode() ) |
| 1987 | |
| 1988 | if ( AvailableToDetect(myLastPicked) ) { |
| 1989 | if ( myLastPicked->HighlightMode() == AIS2D_TOD_OBJECT ) |
| 1990 | #ifdef OCC146 |
| 1991 | if (!myLastPicked->State()) |
| 1992 | #endif |
| 1993 | myLastPicked->Highlight( ind ); |
| 1994 | theDrawer->SetOverride(Standard_True); |
| 1995 | theDrawer->SetOverrideColor(ind); |
| 1996 | theDrawer->BeginDraw( aView->Driver() ); |
| 1997 | DoDetectObject( myLastPicked, theDrawer ); |
| 1998 | theDrawer->EndDraw(); |
| 1999 | theDrawer->SetOverride(Standard_False); |
| 2000 | |
| 2001 | } else theStat = AIS2D_SOD_Selected; |
| 2002 | } |
| 2003 | } // end for |
| 2004 | |
| 2005 | myResetDetect= Standard_False; |
| 2006 | |
| 2007 | } // end if myResetDetect is true |
| 2008 | |
| 2009 | } else { |
| 2010 | |
| 2011 | theStat = AIS2D_SOD_Nothing; |
| 2012 | theDrawer->RestoreArea( aView->Driver() ); |
| 2013 | myResetDetect= Standard_True; |
| 2014 | |
| 2015 | if ( ! mySeqOfDetIO->IsEmpty() ) { |
| 2016 | Handle(AIS2D_InteractiveObject) theIO; |
| 2017 | for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) { |
| 2018 | theIO = mySeqOfDetIO->Value(i); |
| 2019 | if ( theIO->HighlightMode() == AIS2D_TOD_ELEMENT || |
| 2020 | theIO->HighlightMode() == AIS2D_TOD_VERTEX ) { |
| 2021 | theIO->ClearSeqDetPrim(); |
| 2022 | } else { |
| 2023 | if ( ! theIO->State() ) |
| 2024 | theIO->Unhighlight(); |
| 2025 | } |
| 2026 | theIO->ClearSeqDetPrim(); |
| 2027 | } |
| 2028 | UpdVwr = Standard_True; |
| 2029 | } |
| 2030 | ( is_main ) ? myLastinMain.Nullify() : myLastinColl.Nullify(); |
| 2031 | mySeqOfDetIO->Clear(); |
| 2032 | |
| 2033 | } // end if PickList isn't empty |
| 2034 | |
| 2035 | //if ( !myLastPicked.IsNull() ) myLastPicked->Unhighlight(); |
| 2036 | |
| 2037 | if ( UpdVwr ) |
| 2038 | is_main ? myMainVwr->Update() : myCollectorVwr->Update(); |
| 2039 | myLastPicked.Nullify(); |
| 2040 | myLastMoveView = aView; |
| 2041 | |
| 2042 | return theStat; |
| 2043 | |
| 2044 | } |
| 2045 | |
| 2046 | |
| 2047 | //SAV |
| 2048 | AIS2D_StatusOfDetection AIS2D_InteractiveContext |
| 2049 | ::MoveCircleTo( const Standard_Integer XPix, |
| 2050 | const Standard_Integer YPix, |
| 2051 | const Standard_Integer Radius, |
| 2052 | const Handle(V2d_View)& aView ) |
| 2053 | { |
| 2054 | mySeqOfDetIO->Clear(); |
| 2055 | |
| 2056 | Handle(Graphic2d_DisplayList) thePickList = |
| 2057 | aView->PickByCircle( XPix, YPix, Radius ); |
| 2058 | |
| 2059 | return Detect( thePickList, aView ); |
| 2060 | } |
| 2061 | |
| 2062 | |
| 2063 | AIS2D_StatusOfDetection AIS2D_InteractiveContext::MoveTo( |
| 2064 | const Standard_Integer Xmin, |
| 2065 | const Standard_Integer Ymin, |
| 2066 | const Standard_Integer Xmax, |
| 2067 | const Standard_Integer Ymax, |
| 2068 | const Handle(V2d_View)& aView ) { |
| 2069 | |
| 2070 | |
| 2071 | /*if ( HasOpenedContext() && aView->Viewer() != myCollectorVwr ) { |
| 2072 | myWasLastMain = Standard_True; |
| 2073 | return myLocalContexts(myCurLocalIndex)->MoveTo( Xmin, Ymin, Xmax, Ymax, aView ); |
| 2074 | } |
| 2075 | */ |
| 2076 | mySeqOfDetIO->Clear(); |
| 2077 | |
| 2078 | Handle(Graphic2d_DisplayList) thePickList = aView->Pick( Xmin, Ymin, Xmax, Ymax, myPickMode ); |
| 2079 | |
| 2080 | return Detect( thePickList, aView ); |
| 2081 | } |
| 2082 | |
| 2083 | //SAV |
| 2084 | AIS2D_StatusOfDetection AIS2D_InteractiveContext |
| 2085 | ::Detect( const Handle(Graphic2d_DisplayList)& dList, |
| 2086 | const Handle(V2d_View)& aView ) |
| 2087 | { |
| 2088 | AIS2D_StatusOfDetection theStat( AIS2D_SOD_Nothing ); |
| 2089 | |
| 2090 | RectMoveTo = Standard_True; |
| 2091 | Handle(V2d_Viewer) theViewer = aView->Viewer(); |
| 2092 | Standard_Boolean is_main = ( theViewer == myCollectorVwr ) ? |
| 2093 | Standard_False : Standard_True; |
| 2094 | if ( is_main ) myWasLastMain = Standard_True; |
| 2095 | |
| 2096 | Handle(Graphic2d_TransientManager) theDrawer = |
| 2097 | Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() ); |
| 2098 | |
| 2099 | |
| 2100 | if ( ! dList->IsEmpty() ) { |
| 2101 | Standard_Integer ind = ( is_main ) ? |
| 2102 | myMainVwr->InitializeColor(myHighlightColor) : |
| 2103 | myCollectorVwr->InitializeColor(myHighlightColor); |
| 2104 | Handle(AIS2D_InteractiveObject) theIO; |
| 2105 | theDrawer->SetOverride( Standard_True ); |
| 2106 | theDrawer->SetOverrideColor( ind ); |
| 2107 | theDrawer->BeginDraw( aView->Driver() ); |
| 2108 | |
| 2109 | for ( int i = 1 ; i <= dList->Length(); i++ ) { |
| 2110 | Handle(Graphic2d_GraphicObject) theGOi = dList->Value(i); |
| 2111 | if ( theGOi->IsKind(STANDARD_TYPE(AIS2D_InteractiveObject))) { |
| 2112 | theIO = Handle(AIS2D_InteractiveObject)::DownCast( theGOi ); |
| 2113 | if ( theIO->HasHighlightMode() ) |
| 2114 | if ( AvailableToDetect( theIO ) ) { |
| 2115 | if ( theIO->HighlightMode() == AIS2D_TOD_OBJECT ) |
| 2116 | theIO->Highlight( ind ); |
| 2117 | |
| 2118 | DoDetectObject( theIO, theDrawer ); |
| 2119 | |
| 2120 | } else theStat = AIS2D_SOD_Selected; |
| 2121 | } |
| 2122 | } // end for |
| 2123 | theDrawer->EndDraw(); |
| 2124 | theDrawer->SetOverride( Standard_False ); |
| 2125 | } else { |
| 2126 | |
| 2127 | theStat = AIS2D_SOD_Nothing; |
| 2128 | theDrawer->RestoreArea( aView->Driver() ); |
| 2129 | if ( !mySeqOfDetIO->IsEmpty() ) |
| 2130 | for ( int i = 1; i<= mySeqOfDetIO->Length(); ++i ) { |
| 2131 | mySeqOfDetIO->Value(i)->Unhighlight(); |
| 2132 | mySeqOfDetIO->Value(i)->ClearSeqDetPrim(); |
| 2133 | } |
| 2134 | mySeqOfDetIO->Clear(); |
| 2135 | is_main ? myMainVwr->Update() : myCollectorVwr->Update(); |
| 2136 | } // end if PickList isn't empty |
| 2137 | |
| 2138 | |
| 2139 | return theStat; |
| 2140 | } |
| 2141 | |
| 2142 | AIS2D_StatusOfPick AIS2D_InteractiveContext::Select( const Standard_Boolean UpdateVwr ) { |
| 2143 | |
| 2144 | if ( HasOpenedContext() ) |
| 2145 | if ( myWasLastMain ) |
| 2146 | return myLocalContexts(myCurLocalIndex)->Select(UpdateVwr); |
| 2147 | else { |
| 2148 | myLocalContexts( myCurLocalIndex )->SetSelected( myLastPicked, UpdateVwr ); |
| 2149 | return AIS2D_SOP_OneSelected; |
| 2150 | } |
| 2151 | #ifdef DEB |
| 2152 | AIS2D_StatusOfPick PS( AIS2D_SOP_NothingSelected ); |
| 2153 | #endif |
| 2154 | |
| 2155 | if ( ! mySeqOfDetIO->IsEmpty() ) { |
| 2156 | Handle(AIS2D_InteractiveObject) theIO; |
| 2157 | Handle(AIS2D_HSequenceOfPrimArchit) thePA; |
| 2158 | |
| 2159 | switch ( myCurDetectMode ) { |
| 2160 | default : |
| 2161 | case AIS2D_TOD_OBJECT : { |
| 2162 | for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) { |
| 2163 | theIO = mySeqOfDetIO->Value(i); |
| 2164 | if ( ! RectMoveTo ) { |
| 2165 | thePA = theIO->GetSelectedSeqPrim(); |
| 2166 | if ( ! thePA->IsEmpty() ) { |
| 2167 | for ( int j = 1; j <= thePA->Length(); ++j ) |
| 2168 | thePA->Value(j)->GetPrimitive()->Unhighlight(); |
| 2169 | theIO->ClearSeqSelPrim(); |
| 2170 | } |
| 2171 | |
| 2172 | if ( ! mySeqOfSelIO->IsEmpty() ) |
| 2173 | for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) { |
| 2174 | Unhighlight( mySeqOfSelIO->Value(i), Standard_False ); |
| 2175 | mySeqOfSelIO->Value(i)->SetState(0); |
| 2176 | mySeqOfSelIO->Remove(i); |
| 2177 | } |
| 2178 | } |
| 2179 | if ( ! theIO->State() ) { |
| 2180 | SetCurrentObject( theIO, Standard_False ); |
| 2181 | mySeqOfSelIO->Append(theIO); |
| 2182 | } |
| 2183 | } |
| 2184 | theIO->ClearSeqDetPrim(); |
| 2185 | } |
| 2186 | break; |
| 2187 | |
| 2188 | case AIS2D_TOD_PRIMITIVE: |
| 2189 | { |
| 2190 | for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) |
| 2191 | { |
| 2192 | Standard_Integer j; |
| 2193 | |
| 2194 | theIO = mySeqOfDetIO->Value(i); |
| 2195 | theIO->Highlight(myMainVwr->InitializeColor(mySelectionColor)); |
| 2196 | theIO->Unhighlight(); |
| 2197 | theIO->SetState(1); |
| 2198 | |
| 2199 | // unselect selected |
| 2200 | if ( !RectMoveTo ) |
| 2201 | { |
| 2202 | |
| 2203 | thePA = theIO->GetSelectedSeqPrim(); |
| 2204 | for ( j = 1; j <= thePA->Length(); ++j ) |
| 2205 | { |
| 2206 | thePA->Value(j)->GetPrimitive()->Unhighlight(); |
| 2207 | } |
| 2208 | theIO->ClearSeqSelPrim(); |
| 2209 | |
| 2210 | for ( j = 1; j <= mySeqOfSelIO->Length(); ++j ) |
| 2211 | { |
| 2212 | // by EAV: 12.09.01 |
| 2213 | // Unhighlight( mySeqOfSelIO->Value(j), Standard_False ); |
| 2214 | mySeqOfSelIO->Value(j)->SetState( 0 ); |
| 2215 | mySeqOfSelIO->Remove(j); |
| 2216 | } |
| 2217 | } |
| 2218 | |
| 2219 | // select detected |
| 2220 | thePA = theIO->GetDetectSeqPrim(); |
| 2221 | for ( j = 1; j <= thePA->Length(); ++j ) |
| 2222 | { |
| 2223 | Handle(Graphic2d_Primitive) thePrim = thePA->Value(j)->GetPrimitive(); |
| 2224 | if ( !thePrim ->IsHighlighted() ) { |
| 2225 | thePrim->Highlight(); |
| 2226 | theIO->AddSelectPrim( thePrim, 0 ); |
| 2227 | } |
| 2228 | } |
| 2229 | if ( ! IsIOSelected( theIO ) ) |
| 2230 | mySeqOfSelIO->Append( mySeqOfDetIO->Value(i) ); |
| 2231 | |
| 2232 | } // end for |
| 2233 | #ifndef OCC146 |
| 2234 | theIO->ClearSeqDetPrim(); |
| 2235 | #endif |
| 2236 | } |
| 2237 | break; |
| 2238 | case AIS2D_TOD_ELEMENT: { |
| 2239 | Standard_Integer theInd; |
| 2240 | for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) { |
| 2241 | theIO = mySeqOfDetIO->Value(i); |
| 2242 | theIO->Highlight(myMainVwr->InitializeColor(mySelectionColor)); |
| 2243 | theIO->Unhighlight(); |
| 2244 | theIO->SetState(1); |
| 2245 | if ( !RectMoveTo ) { |
| 2246 | thePA = theIO->GetSelectedSeqPrim(); |
| 2247 | if ( ! thePA->IsEmpty() ) { |
| 2248 | for ( int j = 1; j <= thePA->Length(); ++j ) |
| 2249 | thePA->Value(j)->GetPrimitive()->Unhighlight(); |
| 2250 | theIO->ClearSeqSelPrim(); |
| 2251 | } |
| 2252 | if ( ! mySeqOfSelIO->IsEmpty() ) |
| 2253 | for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) { |
| 2254 | Unhighlight( mySeqOfSelIO->Value(i), Standard_False ); |
| 2255 | mySeqOfSelIO->Value(i)->SetState(0); |
| 2256 | mySeqOfSelIO->Remove(i); |
| 2257 | } |
| 2258 | } |
| 2259 | thePA = theIO->GetDetectSeqPrim(); |
| 2260 | if ( ! thePA->IsEmpty() ) { |
| 2261 | Handle(Graphic2d_Primitive) thePrim; |
| 2262 | for ( int j = 1; j <= thePA->Length(); ++j ) { |
| 2263 | thePrim = thePA->Value(j)->GetPrimitive(); |
| 2264 | theInd = thePA->Value(j)->GetIndex(); |
| 2265 | |
| 2266 | //SAV - marking that highlighted elements became selected |
| 2267 | // fixing regression of element single selection |
| 2268 | if ( !thePrim->SetElementsSelected() ) |
| 2269 | thePrim->Highlight( theInd ); |
| 2270 | else |
| 2271 | thePrim->Unhighlight(); |
| 2272 | theIO->AddSelectPrim( thePrim, theInd ); |
| 2273 | } |
| 2274 | } |
| 2275 | if ( ! IsIOSelected( theIO ) ) mySeqOfSelIO->Append(mySeqOfDetIO->Value(i)); |
| 2276 | } // end for |
| 2277 | #ifndef OCC146 |
| 2278 | theIO->ClearSeqDetPrim(); |
| 2279 | #endif |
| 2280 | } |
| 2281 | break; |
| 2282 | case AIS2D_TOD_VERTEX: { |
| 2283 | Standard_Integer theInd; |
| 2284 | for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) { |
| 2285 | theIO = mySeqOfDetIO->Value(i); |
| 2286 | theIO->Highlight(myMainVwr->InitializeColor(mySelectionColor)); |
| 2287 | theIO->Unhighlight(); |
| 2288 | theIO->SetState(1); |
| 2289 | if ( !RectMoveTo ) { |
| 2290 | thePA = theIO->GetSelectedSeqPrim(); |
| 2291 | if ( ! thePA->IsEmpty() ) { |
| 2292 | for ( int j = 1; j <= thePA->Length(); ++j ) |
| 2293 | thePA->Value(j)->GetPrimitive()->Unhighlight(); |
| 2294 | theIO->ClearSeqSelPrim(); |
| 2295 | } |
| 2296 | if ( ! mySeqOfSelIO->IsEmpty() ) |
| 2297 | for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) { |
| 2298 | Unhighlight( mySeqOfSelIO->Value(i), Standard_False ); |
| 2299 | mySeqOfSelIO->Value(i)->SetState(0); |
| 2300 | mySeqOfSelIO->Remove(i); |
| 2301 | } |
| 2302 | } |
| 2303 | thePA = theIO->GetDetectSeqPrim(); |
| 2304 | if ( ! thePA->IsEmpty() ) { |
| 2305 | Handle(Graphic2d_Primitive) thePrim; |
| 2306 | for ( int j = 1; j <= thePA->Length(); ++j ) { |
| 2307 | thePrim = thePA->Value(j)->GetPrimitive(); |
| 2308 | theInd = thePA->Value(j)->GetIndex(); |
| 2309 | thePrim->Highlight( theInd ); |
| 2310 | theIO->AddSelectPrim( thePrim, theInd ); |
| 2311 | } |
| 2312 | } |
| 2313 | if ( ! IsIOSelected( theIO ) ) mySeqOfSelIO->Append(mySeqOfDetIO->Value(i)); |
| 2314 | } // end for |
| 2315 | #ifndef OCC146 |
| 2316 | theIO->ClearSeqDetPrim(); |
| 2317 | #endif |
| 2318 | } |
| 2319 | break; |
| 2320 | } // end switch |
| 2321 | #ifndef OCC146 |
| 2322 | mySeqOfDetIO->Clear(); |
| 2323 | #endif |
| 2324 | } else { |
| 2325 | |
| 2326 | // if sequence of detected objects is empty |
| 2327 | if ( ! mySeqOfSelIO->IsEmpty() ) { |
| 2328 | switch ( myCurDetectMode ) { |
| 2329 | default : |
| 2330 | case AIS2D_TOD_OBJECT : { |
| 2331 | Handle(AIS2D_InteractiveObject) theIO; |
| 2332 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) { |
| 2333 | theIO = mySeqOfSelIO->Value(i); |
| 2334 | theIO->Unhighlight(); |
| 2335 | theIO->SetState(0); |
| 2336 | if ( myObjects.IsBound(theIO) ) |
| 2337 | if ( myObjects(theIO)->IsSubIntensityOn() ) |
| 2338 | HighlightWithColor( theIO, mySubIntensity, Standard_False ); |
| 2339 | } |
| 2340 | } |
| 2341 | break; |
| 2342 | case AIS2D_TOD_PRIMITIVE: { |
| 2343 | Handle(AIS2D_InteractiveObject) theIO; |
| 2344 | Handle(AIS2D_HSequenceOfPrimArchit) thePA; |
| 2345 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) { |
| 2346 | theIO = mySeqOfSelIO->Value(i); |
| 2347 | thePA = theIO->GetSelectedSeqPrim(); |
| 2348 | theIO->Unhighlight(); |
| 2349 | if ( ! thePA->IsEmpty() ) { |
| 2350 | for ( int j = 1; j <= thePA->Length(); ++j ) |
| 2351 | thePA->Value(j)->GetPrimitive()->Unhighlight(); |
| 2352 | theIO->ClearSeqSelPrim(); |
| 2353 | } |
| 2354 | theIO->SetState(0); |
| 2355 | if ( myObjects.IsBound(theIO) ) |
| 2356 | if ( myObjects(theIO)->IsSubIntensityOn() ) |
| 2357 | HighlightWithColor( theIO, mySubIntensity, Standard_False ); |
| 2358 | } |
| 2359 | |
| 2360 | } |
| 2361 | break; |
| 2362 | case AIS2D_TOD_ELEMENT: { |
| 2363 | Handle(AIS2D_InteractiveObject) theIO; |
| 2364 | Handle(AIS2D_HSequenceOfPrimArchit) thePA; |
| 2365 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) { |
| 2366 | theIO = mySeqOfSelIO->Value(i); |
| 2367 | thePA = theIO->GetSelectedSeqPrim(); |
| 2368 | theIO->Unhighlight(); |
| 2369 | if ( ! thePA->IsEmpty() ) { |
| 2370 | for ( int j = 1; j <= thePA->Length(); ++j ) { |
| 2371 | thePA->Value(j)->GetPrimitive()->Unhighlight(); |
| 2372 | // SAV - unselecting sub primitives |
| 2373 | thePA->Value(j)->GetPrimitive()->ClearSelectedElements(); |
| 2374 | } |
| 2375 | theIO->ClearSeqSelPrim(); |
| 2376 | } |
| 2377 | theIO->SetState(0); |
| 2378 | if ( myObjects.IsBound(theIO) ) |
| 2379 | if ( myObjects(theIO)->IsSubIntensityOn() ) |
| 2380 | HighlightWithColor( theIO, mySubIntensity, Standard_False ); |
| 2381 | } |
| 2382 | } |
| 2383 | break; |
| 2384 | case AIS2D_TOD_VERTEX: { |
| 2385 | Handle(AIS2D_InteractiveObject) theIO; |
| 2386 | Handle(AIS2D_HSequenceOfPrimArchit) thePA; |
| 2387 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) { |
| 2388 | theIO = mySeqOfSelIO->Value(i); |
| 2389 | thePA = theIO->GetSelectedSeqPrim(); |
| 2390 | theIO->Unhighlight(); |
| 2391 | if ( ! thePA->IsEmpty() ) { |
| 2392 | for ( int j = 1; j <= thePA->Length(); ++j ) |
| 2393 | thePA->Value(j)->GetPrimitive()->Unhighlight(); |
| 2394 | theIO->ClearSeqSelPrim(); |
| 2395 | } |
| 2396 | theIO->SetState(0); |
| 2397 | if ( myObjects.IsBound(theIO) ) |
| 2398 | if ( myObjects(theIO)->IsSubIntensityOn() ) |
| 2399 | HighlightWithColor( theIO, mySubIntensity, Standard_False ); |
| 2400 | } |
| 2401 | } |
| 2402 | break; |
| 2403 | } // end switch |
| 2404 | mySeqOfSelIO->Clear(); |
| 2405 | } // end if sequence of detected objects isn't empty |
| 2406 | |
| 2407 | |
| 2408 | } |
| 2409 | if ( UpdateVwr ) myWasLastMain ? myMainVwr->Update() : UpdateCollector(); |
| 2410 | |
| 2411 | Standard_Integer NS = mySeqOfSelIO->Length(); |
| 2412 | if ( !NS ) return AIS2D_SOP_NothingSelected; |
| 2413 | if ( NS == 1 ) return AIS2D_SOP_OneSelected; |
| 2414 | |
| 2415 | return AIS2D_SOP_SeveralSelected; |
| 2416 | |
| 2417 | } |
| 2418 | |
| 2419 | AIS2D_StatusOfPick AIS2D_InteractiveContext::ShiftSelect( const Standard_Boolean UpdateVwr ) |
| 2420 | { |
| 2421 | if ( HasOpenedContext() ) { |
| 2422 | if ( myWasLastMain ) |
| 2423 | return myLocalContexts( myCurLocalIndex )->ShiftSelect( UpdateVwr ); |
| 2424 | else { |
| 2425 | myLocalContexts( myCurLocalIndex )->AddOrRemoveSelected( myLastPicked, UpdateVwr ); |
| 2426 | Standard_Integer NS = mySeqOfSelIO->Length(); |
| 2427 | if ( !NS ) return AIS2D_SOP_NothingSelected; |
| 2428 | if ( NS == 1 ) return AIS2D_SOP_OneSelected; |
| 2429 | return AIS2D_SOP_SeveralSelected; |
| 2430 | } |
| 2431 | } //end if opened local context exists |
| 2432 | |
| 2433 | if ( myWasLastMain && !myLastinMain.IsNull() ) |
| 2434 | AddOrRemoveCurObject( myLastinMain,UpdateVwr ); |
| 2435 | else if ( !myWasLastMain && !myLastinColl.IsNull() ) |
| 2436 | AddOrRemoveCurObject( myLastinColl, UpdateVwr ); |
| 2437 | |
| 2438 | Standard_Integer NS = mySeqOfSelIO->Length(); |
| 2439 | if ( NS == 0 ) return AIS2D_SOP_NothingSelected; |
| 2440 | if ( NS == 1 ) return AIS2D_SOP_OneSelected; |
| 2441 | return AIS2D_SOP_SeveralSelected; |
| 2442 | |
| 2443 | } |
| 2444 | |
| 2445 | AIS2D_StatusOfPick AIS2D_InteractiveContext::ShiftSelect( |
| 2446 | const Standard_Integer /*XPMin*/, |
| 2447 | const Standard_Integer /*YPMin*/, |
| 2448 | const Standard_Integer /*XPMax*/, |
| 2449 | const Standard_Integer /*YPMax*/, |
| 2450 | const Handle(V2d_View)& /*aView*/, |
| 2451 | const Standard_Boolean /*UpdateVwr*/ ) |
| 2452 | { |
| 2453 | /* |
| 2454 | if ( HasOpenedContext() ) |
| 2455 | return myLocalContexts( myCurLocalIndex )->ShiftSelect( XPMin, YPMin, XPMax, YPMax, aView, UpdateVwr ); |
| 2456 | |
| 2457 | UnhighlightCurrent(Standard_False); |
| 2458 | // static Handle(StdSelect_ViewerSelector2d) aSelector; |
| 2459 | |
| 2460 | if ( aView->Viewer() == myMainVwr) { |
| 2461 | // aSelector= myMainSelector; |
| 2462 | myWasLastMain = Standard_True;} |
| 2463 | |
| 2464 | else if (aView->Viewer() == myCollectorVwr){ |
| 2465 | // aSelector= myCollectorSel; |
| 2466 | myWasLastMain = Standard_False;} |
| 2467 | else |
| 2468 | return AIS2D_SOP_NothingSelected; |
| 2469 | aSelector->SetSensitivity( aView->Convert(mySensitivity) ); |
| 2470 | aSelector->Pick( XPMin, YPMin, XPMax, YPMax, aView ); |
| 2471 | AIS2D_Selection::SetCurrentSelection( myCurrentName.ToCString() ); |
| 2472 | for ( aSelector->Init(); aSelector->More(); aSelector->Next() ) { |
| 2473 | const Handle(SelectMgr_SelectableObject)& SObj = aSelector->Picked()->Selectable(); |
| 2474 | if ( !SObj.IsNull() ) { |
| 2475 | AIS2D_SelectStatus SelStat = AIS2D_Selection::Select(SObj); |
| 2476 | Standard_Integer mod = (SelStat == AIS2D_SS_Added) ? 1 : 0; |
| 2477 | ( * ( (Handle(AIS2D_InteractiveObject)* ) & SObj ) )->SetState(mod); |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | HighlightCurrent( UpdateVwr ); |
| 2482 | |
| 2483 | Standard_Integer NS = NbCurrents(); |
| 2484 | if ( NS == 0 ) return AIS2D_SOP_NothingSelected; |
| 2485 | if ( NS == 1 ) return AIS2D_SOP_OneSelected; |
| 2486 | return AIS2D_SOP_SeveralSelected; |
| 2487 | */ |
| 2488 | return AIS2D_SOP_NothingSelected; |
| 2489 | } |
| 2490 | |
| 2491 | Standard_Integer AIS2D_InteractiveContext::NbSelected() const |
| 2492 | { |
| 2493 | if ( mySeqOfSelIO->IsEmpty() ) |
| 2494 | return 0; |
| 2495 | |
| 2496 | Standard_Integer nsel = 0; |
| 2497 | switch ( myCurDetectMode ) |
| 2498 | { |
| 2499 | case AIS2D_TOD_ELEMENT: |
| 2500 | case AIS2D_TOD_VERTEX: |
| 2501 | case AIS2D_TOD_PRIMITIVE: |
| 2502 | { |
| 2503 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) |
| 2504 | { |
| 2505 | Handle( AIS2D_InteractiveObject ) io = mySeqOfSelIO->Value( i ); |
| 2506 | if ( !io.IsNull() ) |
| 2507 | nsel += io->GetSelectedSeqPrim()->Length(); |
| 2508 | } |
| 2509 | break; |
| 2510 | } |
| 2511 | default : |
| 2512 | nsel = mySeqOfSelIO->Length(); break; |
| 2513 | } |
| 2514 | return nsel; |
| 2515 | } |
| 2516 | |
| 2517 | void AIS2D_InteractiveContext::InitSelected() |
| 2518 | { |
| 2519 | myCurSelected = 1; |
| 2520 | myMaxSelected = NbSelected(); |
| 2521 | } |
| 2522 | |
| 2523 | Standard_Boolean AIS2D_InteractiveContext::MoreSelected() const |
| 2524 | { |
| 2525 | return myCurSelected <= myMaxSelected; |
| 2526 | } |
| 2527 | |
| 2528 | void AIS2D_InteractiveContext::NextSelected() |
| 2529 | { |
| 2530 | myCurSelected++; |
| 2531 | } |
| 2532 | |
| 2533 | Handle( MMgt_TShared ) AIS2D_InteractiveContext::SelectedObject() const |
| 2534 | { |
| 2535 | switch ( myCurDetectMode ) |
| 2536 | { |
| 2537 | case AIS2D_TOD_ELEMENT: |
| 2538 | case AIS2D_TOD_VERTEX: |
| 2539 | case AIS2D_TOD_PRIMITIVE: |
| 2540 | { |
| 2541 | Standard_Integer current = 0; |
| 2542 | for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) |
| 2543 | { |
| 2544 | Handle( AIS2D_InteractiveObject ) io = mySeqOfSelIO->Value( i ); |
| 2545 | if ( !io.IsNull() ) |
| 2546 | { |
| 2547 | Standard_Integer l = io->GetSelectedSeqPrim()->Length(); |
| 2548 | if ( myCurSelected <= current + l ) |
| 2549 | { |
| 2550 | return io->GetSelectedSeqPrim()->Value( myCurSelected - current )->GetPrimitive(); |
| 2551 | } |
| 2552 | current += l; |
| 2553 | } |
| 2554 | } |
| 2555 | break; |
| 2556 | } |
| 2557 | default: break; |
| 2558 | } |
| 2559 | return mySeqOfSelIO->Value( myCurSelected ); |
| 2560 | } |
| 2561 | |
| 2562 | // ******************************************************************************* |
| 2563 | // Immediate Mode Management |
| 2564 | // ******************************************************************************* |
| 2565 | |
| 2566 | void AIS2D_InteractiveContext::BeginImmediateDraw( const Handle(V2d_View)& aView ) { |
| 2567 | |
| 2568 | Handle(V2d_Viewer) theViewer = aView->Viewer(); |
| 2569 | Handle(Graphic2d_TransientManager) theDrawer = |
| 2570 | Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() ); |
| 2571 | theDrawer->BeginDraw( aView->Driver() ); |
| 2572 | |
| 2573 | } |
| 2574 | |
| 2575 | void AIS2D_InteractiveContext::ImmediateDraw( const Handle(AIS2D_InteractiveObject)& anIObj, |
| 2576 | const Handle(V2d_View)& aView ) { |
| 2577 | |
| 2578 | Handle(V2d_Viewer) theViewer = aView->Viewer(); |
| 2579 | Handle(Graphic2d_TransientManager) theDrawer = |
| 2580 | Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() ); |
| 2581 | theDrawer->Draw( anIObj ); |
| 2582 | |
| 2583 | } |
| 2584 | |
| 2585 | void AIS2D_InteractiveContext::EndImmediateDraw( const Handle(V2d_View)& aView ) { |
| 2586 | Handle(V2d_Viewer) theViewer = aView->Viewer(); |
| 2587 | Handle(Graphic2d_TransientManager) theDrawer = |
| 2588 | Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() ); |
| 2589 | theDrawer->EndDraw(); |
| 2590 | } |
| 2591 | |
| 2592 | Standard_Boolean AIS2D_InteractiveContext::IsImmediateModeOn(const Handle(V2d_View)& /*aView*/) const { |
| 2593 | return Standard_False; |
| 2594 | } |
| 2595 | |
| 2596 | //SAV |
| 2597 | void AIS2D_InteractiveContext::SetDetectionMode( const AIS2D_TypeOfDetection mode ) |
| 2598 | { |
| 2599 | myCurDetectMode = mode; |
| 2600 | } |