| 1 | |
| 2 | /*********************************************************************** |
| 3 | |
| 4 | FONCTION : |
| 5 | ---------- |
| 6 | Classe Visual3d_ViewManager.cxx : |
| 7 | |
| 8 | Declaration of variables specific to visualisers |
| 9 | |
| 10 | HISTORIQUE DES MODIFICATIONS : |
| 11 | -------------------------------- |
| 12 | Mars 1992 : NW,JPB,CAL ; Creation. |
| 13 | 19-06-96 : FMN ; Suppression variables inutiles |
| 14 | 04-02-97 : FMN ; Suppression de PSOutput, XWDOutput ... |
| 15 | 06-05-97 : CAL ; Ajout du Clear sur les TOS_COMPUTED. |
| 16 | 19-09-97 : CAL ; Remplacement de Window->Position par Window->Size; |
| 17 | 24-10-97 : CAL ; Retrait de DownCast. |
| 18 | 20-11-97 : CAL ; Disparition de la dependance avec math |
| 19 | 01-12-97 : CAL ; Retrait du test IsActive sur l'Update et le Redraw |
| 20 | 31-12-97 : CAL ; Disparition de MathGra |
| 21 | 16-01-98 : CAL ; Ajout du SetTransform sur une TOS_COMPUTED |
| 22 | 11-03-98 : CAL ; Visual3d_ViewManager::Remove () |
| 23 | 20-05-98 : CAL ; Perfs. Connection entre structures COMPUTED. |
| 24 | 10-06-98 : CAL ; Modification des signatures de xxProjectRaster. |
| 25 | 10-06-98 : CAL ; Modification de la signature de ViewExists. |
| 26 | 01-12-98 : CAL ; S4062. Ajout des layers. |
| 27 | 02-12-98 : CAL ; Remove () ne detruit plus les vues. |
| 28 | |
| 29 | ************************************************************************/ |
| 30 | |
| 31 | /*----------------------------------------------------------------------*/ |
| 32 | /* |
| 33 | * Constants |
| 34 | */ |
| 35 | |
| 36 | #define NO_DOWNCAST |
| 37 | #define NO_DESTROY |
| 38 | |
| 39 | /*----------------------------------------------------------------------*/ |
| 40 | /* |
| 41 | * Includes |
| 42 | */ |
| 43 | |
| 44 | // for the class |
| 45 | #include <Visual3d_ViewManager.ixx> |
| 46 | #include <Visual3d_ViewManager.pxx> |
| 47 | |
| 48 | #include <Standard_ErrorHandler.hxx> |
| 49 | |
| 50 | #include <Aspect.hxx> |
| 51 | |
| 52 | #include <Graphic3d_GraphicDriver.hxx> |
| 53 | #include <Graphic3d_MapOfStructure.hxx> |
| 54 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> |
| 55 | |
| 56 | #include <Visual3d_PickPath.hxx> |
| 57 | #include <Visual3d_SetIteratorOfSetOfView.hxx> |
| 58 | |
| 59 | #ifndef WNT |
| 60 | # include <Xw_Window.hxx> |
| 61 | #else |
| 62 | # include <WNT_Window.hxx> |
| 63 | #endif // WNT |
| 64 | |
| 65 | //-Aliases |
| 66 | |
| 67 | //-Global data definitions |
| 68 | |
| 69 | // -- les vues definies |
| 70 | // MyDefinedView : SetOfView; |
| 71 | |
| 72 | // -- le generateur d'identificateurs de vues |
| 73 | // MyViewGenId : GenId; |
| 74 | |
| 75 | //-Constructors |
| 76 | |
| 77 | Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Aspect_GraphicDevice)& aDevice): |
| 78 | Graphic3d_StructureManager (aDevice), |
| 79 | MyDefinedView (), |
| 80 | MyViewGenId (View_IDMIN+((View_IDMIN+View_IDMAX)/(Visual3d_ViewManager::Limit ()))*(Visual3d_ViewManager::CurrentId ()-1),View_IDMIN+((View_IDMIN+View_IDMAX)/(Visual3d_ViewManager::Limit ()))*Visual3d_ViewManager::CurrentId ()-1), |
| 81 | MyZBufferAuto (Standard_False), |
| 82 | MyTransparency (Standard_False) |
| 83 | { |
| 84 | |
| 85 | Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver (); |
| 86 | |
| 87 | MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd; |
| 88 | |
| 89 | } |
| 90 | |
| 91 | //-Destructors |
| 92 | |
| 93 | void Visual3d_ViewManager::Destroy () { |
| 94 | |
| 95 | #ifdef DESTROY |
| 96 | cout << "Visual3d_ViewManager::Destroy (" << MyId << ")\n" << flush; |
| 97 | #endif |
| 98 | |
| 99 | Remove (); |
| 100 | } |
| 101 | |
| 102 | //-Methods, in order |
| 103 | |
| 104 | void Visual3d_ViewManager::Remove () { |
| 105 | |
| 106 | #ifdef DESTROY |
| 107 | cout << "Visual3d_ViewManager::Remove (" << MyId << ")\n" << flush; |
| 108 | #endif |
| 109 | |
| 110 | // |
| 111 | // Destroy all defined views |
| 112 | // |
| 113 | #ifdef DEB |
| 114 | Standard_Integer Length = MyDefinedView.Extent (); |
| 115 | #else |
| 116 | MyDefinedView.Extent (); |
| 117 | #endif |
| 118 | |
| 119 | #ifdef DESTROY |
| 120 | cout << "The Manager " << MyId << " have " << Length << " defined views\n"; |
| 121 | cout << flush; |
| 122 | #endif |
| 123 | |
| 124 | MyDefinedView.Clear (); |
| 125 | |
| 126 | } |
| 127 | |
| 128 | void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) { |
| 129 | |
| 130 | #ifdef TRACE |
| 131 | cout << "Visual3d_ViewManager::ChangeDisplayPriority (" |
| 132 | << AStructure->Identification () |
| 133 | << ", " << OldPriority << ", " << NewPriority << ")\n"; |
| 134 | cout << flush; |
| 135 | #endif |
| 136 | |
| 137 | // |
| 138 | // Change structure priority in all defined views |
| 139 | // |
| 140 | #ifdef DEB |
| 141 | Standard_Integer Length = MyDefinedView.Extent (); |
| 142 | #else |
| 143 | MyDefinedView.Extent (); |
| 144 | #endif |
| 145 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 146 | |
| 147 | while (MyIterator.More ()) { |
| 148 | (MyIterator.Value ())->ChangeDisplayPriority |
| 149 | (AStructure, OldPriority, NewPriority); |
| 150 | |
| 151 | // MyIterator.Next () is located on the next view |
| 152 | MyIterator.Next (); |
| 153 | } |
| 154 | |
| 155 | } |
| 156 | |
| 157 | void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) { |
| 158 | |
| 159 | //Standard_Integer LengthD = MyDisplayedStructure.Extent() (); |
| 160 | |
| 161 | // Even if physically the structure cannot |
| 162 | // be displayed (pb of visualisation type) |
| 163 | // it has status Displayed. |
| 164 | |
| 165 | if (!MyDisplayedStructure.Contains(AStructure)) |
| 166 | return; |
| 167 | |
| 168 | // |
| 169 | // Recompute structure in all activated views |
| 170 | // |
| 171 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 172 | |
| 173 | while (MyIterator.More ()) { |
| 174 | (MyIterator.Value ())->ReCompute (AStructure); |
| 175 | |
| 176 | // MyIterator.Next () is located on the next view |
| 177 | MyIterator.Next (); |
| 178 | } |
| 179 | |
| 180 | } |
| 181 | |
| 182 | void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure, |
| 183 | const Handle(Graphic3d_DataStructureManager)& AProjector) |
| 184 | { |
| 185 | |
| 186 | if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return; |
| 187 | |
| 188 | #ifdef DOWNCAST |
| 189 | Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector); |
| 190 | #else |
| 191 | Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector; |
| 192 | #endif |
| 193 | Standard_Integer ViewId = theView->Identification (); |
| 194 | |
| 195 | Standard_Integer indexD = 0; |
| 196 | |
| 197 | // Even if physically the structure cannot |
| 198 | // be displayed (pb of visualisation type) |
| 199 | // it has status Displayed. |
| 200 | if (!MyDisplayedStructure.Contains(AStructure)) |
| 201 | return; |
| 202 | |
| 203 | // |
| 204 | // Recompute structure in all activated views |
| 205 | // |
| 206 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 207 | |
| 208 | while (MyIterator.More ()) { |
| 209 | if ((MyIterator.Value ())->Identification () == ViewId) |
| 210 | theView->ReCompute (AStructure); |
| 211 | |
| 212 | // MyIterator.Next () is located on the next view |
| 213 | MyIterator.Next (); |
| 214 | } |
| 215 | |
| 216 | } |
| 217 | |
| 218 | void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) { |
| 219 | |
| 220 | #ifdef DEB |
| 221 | Standard_Integer Length = MyDefinedView.Extent (); |
| 222 | #else |
| 223 | MyDefinedView.Extent (); |
| 224 | #endif |
| 225 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 226 | |
| 227 | while (MyIterator.More ()) { |
| 228 | (MyIterator.Value ())->Clear (AStructure, WithDestruction); |
| 229 | |
| 230 | // MyIterator.Next () is located on the next view |
| 231 | MyIterator.Next (); |
| 232 | } |
| 233 | |
| 234 | } |
| 235 | |
| 236 | void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) { |
| 237 | |
| 238 | #ifdef DEB |
| 239 | Standard_Integer Length = MyDefinedView.Extent (); |
| 240 | #else |
| 241 | MyDefinedView.Extent (); |
| 242 | #endif |
| 243 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 244 | |
| 245 | while (MyIterator.More ()) { |
| 246 | (MyIterator.Value ())->Connect (AMother, ADaughter); |
| 247 | |
| 248 | // MyIterator.Next () is located on the next view |
| 249 | MyIterator.Next (); |
| 250 | } |
| 251 | |
| 252 | } |
| 253 | |
| 254 | void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) { |
| 255 | |
| 256 | #ifdef DEB |
| 257 | Standard_Integer Length = MyDefinedView.Extent (); |
| 258 | #else |
| 259 | MyDefinedView.Extent (); |
| 260 | #endif |
| 261 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 262 | |
| 263 | while (MyIterator.More ()) { |
| 264 | (MyIterator.Value ())->Disconnect (AMother, ADaughter); |
| 265 | |
| 266 | // MyIterator.Next () is located on the next view |
| 267 | MyIterator.Next (); |
| 268 | } |
| 269 | |
| 270 | } |
| 271 | |
| 272 | void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) { |
| 273 | |
| 274 | |
| 275 | // Even if physically the structure cannot |
| 276 | // be displayed (pb of visualisation type) |
| 277 | // it has status Displayed. |
| 278 | |
| 279 | MyDisplayedStructure.Add(AStructure); |
| 280 | |
| 281 | // |
| 282 | // Display structure in all activated views |
| 283 | // |
| 284 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 285 | |
| 286 | while (MyIterator.More ()) { |
| 287 | (MyIterator.Value ())->Display (AStructure); |
| 288 | |
| 289 | // MyIterator.Next () is located on the next view |
| 290 | MyIterator.Next (); |
| 291 | } |
| 292 | |
| 293 | } |
| 294 | |
| 295 | void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) { |
| 296 | |
| 297 | |
| 298 | // Even if physically the structure cannot |
| 299 | // be displayed (pb of visualisation type) |
| 300 | // it has status Displayed. |
| 301 | |
| 302 | MyDisplayedStructure.Remove(AStructure); |
| 303 | |
| 304 | |
| 305 | |
| 306 | // |
| 307 | // Erase structure in all defined views |
| 308 | // |
| 309 | #ifdef DEB |
| 310 | Standard_Integer Length = MyDefinedView.Extent (); |
| 311 | #else |
| 312 | MyDefinedView.Extent (); |
| 313 | #endif |
| 314 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 315 | |
| 316 | while (MyIterator.More ()) { |
| 317 | (MyIterator.Value ())->Erase (AStructure); |
| 318 | |
| 319 | // MyIterator.Next () is located on the next view |
| 320 | MyIterator.Next (); |
| 321 | } |
| 322 | |
| 323 | MyHighlightedStructure.Remove (AStructure); |
| 324 | MyVisibleStructure.Remove (AStructure); |
| 325 | MyPickStructure.Remove (AStructure); |
| 326 | |
| 327 | } |
| 328 | |
| 329 | void Visual3d_ViewManager::Erase () { |
| 330 | |
| 331 | Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure); |
| 332 | |
| 333 | for (; it.More(); it.Next()) { |
| 334 | Handle(Graphic3d_Structure) SG = it.Key(); |
| 335 | SG->Erase(); |
| 336 | } |
| 337 | |
| 338 | } |
| 339 | |
| 340 | void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) { |
| 341 | |
| 342 | MyHighlightedStructure.Add(AStructure); |
| 343 | |
| 344 | // |
| 345 | // Highlight in all activated views |
| 346 | // |
| 347 | #ifdef DEB |
| 348 | Standard_Integer Length = MyDefinedView.Extent (); |
| 349 | #else |
| 350 | MyDefinedView.Extent (); |
| 351 | #endif |
| 352 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 353 | |
| 354 | while (MyIterator.More ()) { |
| 355 | (MyIterator.Value ())->Highlight (AStructure, AMethod); |
| 356 | |
| 357 | // MyIterator.Next () is located on the next view |
| 358 | MyIterator.Next (); |
| 359 | } |
| 360 | |
| 361 | } |
| 362 | |
| 363 | void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) { |
| 364 | |
| 365 | #ifdef DEB |
| 366 | Standard_Integer Length = MyDefinedView.Extent (); |
| 367 | #else |
| 368 | MyDefinedView.Extent (); |
| 369 | #endif |
| 370 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 371 | |
| 372 | while (MyIterator.More ()) { |
| 373 | (MyIterator.Value ())->SetTransform (AStructure, ATrsf); |
| 374 | |
| 375 | // MyIterator.Next () is located on the next view |
| 376 | MyIterator.Next (); |
| 377 | } |
| 378 | |
| 379 | } |
| 380 | |
| 381 | void Visual3d_ViewManager::UnHighlight () { |
| 382 | |
| 383 | Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure); |
| 384 | |
| 385 | for (; it.More(); it.Next()) { |
| 386 | Handle(Graphic3d_Structure) SG = it.Key(); |
| 387 | SG->UnHighlight (); |
| 388 | } |
| 389 | |
| 390 | |
| 391 | } |
| 392 | |
| 393 | void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) { |
| 394 | |
| 395 | MyHighlightedStructure.Remove(AStructure); |
| 396 | |
| 397 | |
| 398 | // |
| 399 | // UnHighlight in all activated views |
| 400 | // |
| 401 | #ifdef DEB |
| 402 | Standard_Integer Length = MyDefinedView.Extent (); |
| 403 | #else |
| 404 | MyDefinedView.Extent (); |
| 405 | #endif |
| 406 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 407 | |
| 408 | while (MyIterator.More ()) { |
| 409 | (MyIterator.Value ())->UnHighlight (AStructure); |
| 410 | |
| 411 | // MyIterator.Next () is located on the next view |
| 412 | MyIterator.Next (); |
| 413 | } |
| 414 | |
| 415 | } |
| 416 | |
| 417 | void Visual3d_ViewManager::Redraw () const { |
| 418 | |
| 419 | Standard_Integer MaxDx, MaxDy; |
| 420 | Standard_Integer Dx, Dy; |
| 421 | MaxDx = MaxDy = IntegerFirst (); |
| 422 | |
| 423 | // |
| 424 | // Redraw all activated views |
| 425 | // |
| 426 | Standard_Integer j = MyDefinedView.Extent (); |
| 427 | if (j == 0) return; |
| 428 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 429 | |
| 430 | if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) { |
| 431 | while (MyIterator.More ()) { |
| 432 | (MyIterator.Value ())->Window ()->Size (Dx, Dy); |
| 433 | if (Dx > MaxDx) MaxDx = Dx; |
| 434 | if (Dy > MaxDy) MaxDy = Dy; |
| 435 | |
| 436 | // MyIterator.Next () is located on the next view |
| 437 | MyIterator.Next (); |
| 438 | } |
| 439 | if (! MyUnderLayer.IsNull ()) |
| 440 | MyUnderLayer->SetViewport (MaxDx, MaxDy); |
| 441 | if (! MyOverLayer.IsNull ()) |
| 442 | MyOverLayer->SetViewport (MaxDx, MaxDy); |
| 443 | } |
| 444 | |
| 445 | if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) |
| 446 | MyIterator.Initialize (MyDefinedView); |
| 447 | while (MyIterator.More ()) { |
| 448 | (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer); |
| 449 | |
| 450 | // MyIterator.Next () is located on the next view |
| 451 | MyIterator.Next (); |
| 452 | } |
| 453 | |
| 454 | } |
| 455 | |
| 456 | void Visual3d_ViewManager::Update () const { |
| 457 | |
| 458 | // |
| 459 | // Update all activated views |
| 460 | // |
| 461 | Standard_Integer j = MyDefinedView.Extent (); |
| 462 | if (j == 0) return; |
| 463 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 464 | |
| 465 | while (MyIterator.More ()) { |
| 466 | (MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer); |
| 467 | |
| 468 | // MyIterator.Next () is located on the next view |
| 469 | MyIterator.Next (); |
| 470 | } |
| 471 | |
| 472 | } |
| 473 | |
| 474 | Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const { |
| 475 | |
| 476 | Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView (); |
| 477 | |
| 478 | #ifdef DEB |
| 479 | Standard_Integer Length = MyDefinedView.Extent (); |
| 480 | #else |
| 481 | MyDefinedView.Extent (); |
| 482 | #endif |
| 483 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 484 | |
| 485 | while (MyIterator.More ()) { |
| 486 | if ((MyIterator.Value ())->IsActive ()) |
| 487 | SG->Add (MyIterator.Value ()); |
| 488 | |
| 489 | // MyIterator.Next () is located on the next view |
| 490 | MyIterator.Next (); |
| 491 | } |
| 492 | |
| 493 | return (SG); |
| 494 | |
| 495 | } |
| 496 | |
| 497 | #ifdef IMPLEMENTED |
| 498 | Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const { |
| 499 | |
| 500 | Standard_Boolean Result = Standard_False; |
| 501 | |
| 502 | // |
| 503 | // Check all activated views |
| 504 | // |
| 505 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 506 | |
| 507 | Standard_Integer i = MyDefinedView.Extent (); |
| 508 | |
| 509 | while ((! Result) && (MyIterator.More ())) { |
| 510 | if ((MyIterator.Value ())->IsActive ()) |
| 511 | Result = |
| 512 | (MyIterator.Value ())->ContainsComputedStructure (); |
| 513 | |
| 514 | // MyIterator.Next () is located on the next view |
| 515 | MyIterator.Next (); |
| 516 | } |
| 517 | |
| 518 | return Result; |
| 519 | } |
| 520 | #endif |
| 521 | |
| 522 | Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const { |
| 523 | |
| 524 | Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView (); |
| 525 | |
| 526 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 527 | |
| 528 | while (MyIterator.More ()) { |
| 529 | SG->Add (MyIterator.Value ()); |
| 530 | |
| 531 | // MyIterator.Next () is located on the next view |
| 532 | MyIterator.Next (); |
| 533 | } |
| 534 | |
| 535 | return (SG); |
| 536 | |
| 537 | } |
| 538 | |
| 539 | void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const { |
| 540 | |
| 541 | // Convert only if the data is correct |
| 542 | Standard_Boolean Exist; |
| 543 | Graphic3d_CView TheCView; |
| 544 | //Graphic3d_Vertex Point; |
| 545 | |
| 546 | TColStd_Array2OfReal Ori_Matrix (0,3,0,3); |
| 547 | TColStd_Array2OfReal Map_Matrix (0,3,0,3); |
| 548 | |
| 549 | Standard_Integer Width, Height; |
| 550 | Standard_Real AX, AY, AZ; |
| 551 | Standard_Real Dx, Dy, Ratio; |
| 552 | |
| 553 | Exist = ViewExists (AWindow, TheCView); |
| 554 | |
| 555 | if (! Exist) { |
| 556 | AU = AV = IntegerLast (); |
| 557 | } |
| 558 | else { |
| 559 | // NKV - 11.02.08 - Use graphic driver functions |
| 560 | Standard_Boolean Result; |
| 561 | |
| 562 | AVertex.Coord (AX, AY, AZ); |
| 563 | |
| 564 | Result = MyGraphicDriver->ProjectRaster (TheCView, |
| 565 | Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ), |
| 566 | AU, AV); |
| 567 | |
| 568 | // the old code |
| 569 | if (!Result) { |
| 570 | |
| 571 | Standard_Real PtX, PtY, PtZ, PtT; |
| 572 | Standard_Real APX, APY, APZ; |
| 573 | Standard_Real APT; |
| 574 | |
| 575 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 576 | #ifdef DEB |
| 577 | Standard_Integer Length = MyDefinedView.Extent (); |
| 578 | #else |
| 579 | MyDefinedView.Extent (); |
| 580 | #endif |
| 581 | |
| 582 | Standard_Integer stop = 0; |
| 583 | |
| 584 | while ((! stop) && (MyIterator.More ())) { |
| 585 | if (TheCView.ViewId == |
| 586 | (MyIterator.Value ())->Identification ()) { |
| 587 | Ori_Matrix = |
| 588 | (MyIterator.Value ())->MatrixOfOrientation (); |
| 589 | Map_Matrix = |
| 590 | (MyIterator.Value ())->MatrixOfMapping (); |
| 591 | stop = 1; |
| 592 | } |
| 593 | |
| 594 | // MyIterator.Next () is located on the next view |
| 595 | MyIterator.Next (); |
| 596 | } |
| 597 | |
| 598 | |
| 599 | // WCS -> View Reference Coordinate Space |
| 600 | PtX = Ori_Matrix (0, 0) * AX |
| 601 | + Ori_Matrix (0, 1) * AY |
| 602 | + Ori_Matrix (0, 2) * AZ |
| 603 | + Ori_Matrix (0, 3); |
| 604 | PtY = Ori_Matrix (1, 0) * AX |
| 605 | + Ori_Matrix (1, 1) * AY |
| 606 | + Ori_Matrix (1, 2) * AZ |
| 607 | + Ori_Matrix (1, 3); |
| 608 | PtZ = Ori_Matrix (2, 0) * AX |
| 609 | + Ori_Matrix (2, 1) * AY |
| 610 | + Ori_Matrix (2, 2) * AZ |
| 611 | + Ori_Matrix (2, 3); |
| 612 | PtT = Ori_Matrix (3, 0) * AX |
| 613 | + Ori_Matrix (3, 1) * AY |
| 614 | + Ori_Matrix (3, 2) * AZ |
| 615 | + Ori_Matrix (3, 3); |
| 616 | |
| 617 | // VRCS -> Normalized Projection Coordinate Space |
| 618 | APX = Map_Matrix (0, 0) * PtX |
| 619 | + Map_Matrix (0, 1) * PtY |
| 620 | + Map_Matrix (0, 2) * PtZ |
| 621 | + Map_Matrix (0, 3) * PtT; |
| 622 | APY = Map_Matrix (1, 0) * PtX |
| 623 | + Map_Matrix (1, 1) * PtY |
| 624 | + Map_Matrix (1, 2) * PtZ |
| 625 | + Map_Matrix (1, 3) * PtT; |
| 626 | APZ = Map_Matrix (2, 0) * PtX |
| 627 | + Map_Matrix (2, 1) * PtY |
| 628 | + Map_Matrix (2, 2) * PtZ |
| 629 | + Map_Matrix (2, 3) * PtT; |
| 630 | APT = Map_Matrix (3, 0) * PtX |
| 631 | + Map_Matrix (3, 1) * PtY |
| 632 | + Map_Matrix (3, 2) * PtZ |
| 633 | + Map_Matrix (3, 3) * PtT; |
| 634 | |
| 635 | if (APT == 0. || stop == 0) { |
| 636 | AU = AV = IntegerLast (); |
| 637 | } |
| 638 | else { |
| 639 | APX /= APT; |
| 640 | APY /= APT; |
| 641 | APZ /= APT; |
| 642 | |
| 643 | // NPCS -> Device Coordinate Space |
| 644 | AWindow->Size (Width, Height); |
| 645 | Dx = Standard_Real (Width); |
| 646 | Dy = Standard_Real (Height); |
| 647 | Ratio = Dx / Dy; |
| 648 | if (Ratio >= 1.) { |
| 649 | AU = Standard_Integer (APX * Dx); |
| 650 | AV = Standard_Integer (Dy - APY * Dy * Ratio); |
| 651 | } |
| 652 | else { |
| 653 | AU = Standard_Integer (APX * Dx / Ratio); |
| 654 | AV = Standard_Integer (Dy - APY * Dy); |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | } |
| 661 | |
| 662 | Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const { |
| 663 | |
| 664 | // Convert only if the data is correct |
| 665 | Graphic3d_CView TheCView; |
| 666 | Graphic3d_Vertex Point; |
| 667 | |
| 668 | if (! ViewExists (AWindow, TheCView)) |
| 669 | Point.SetCoord (RealLast (), RealLast (), RealLast ()); |
| 670 | else { |
| 671 | Standard_Integer Width, Height; |
| 672 | Standard_ShortReal x, y, z; |
| 673 | Standard_Boolean Result; |
| 674 | |
| 675 | AWindow->Size (Width, Height); |
| 676 | |
| 677 | Result = MyGraphicDriver->UnProjectRaster (TheCView, |
| 678 | 0, 0, Width, Height, |
| 679 | AU, AV, x, y, z); |
| 680 | |
| 681 | // unproject is done by UnProjectRaster |
| 682 | if (Result) { |
| 683 | Point.SetCoord |
| 684 | (Standard_Real (x), Standard_Real (y), Standard_Real (z)); |
| 685 | } |
| 686 | // unproject cannot be done by UnProjectRaster |
| 687 | // Code suspended since drivers Phigs and Pex are abandoned. |
| 688 | else { |
| 689 | |
| 690 | Standard_Real NPCX, NPCY, NPCZ; |
| 691 | Standard_Real VRCX, VRCY, VRCZ, VRCT; |
| 692 | Standard_Real WCX, WCY, WCZ, WCT; |
| 693 | |
| 694 | TColStd_Array2OfReal TOri_Matrix (0,3,0,3); |
| 695 | TColStd_Array2OfReal TMap_Matrix (0,3,0,3); |
| 696 | TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3); |
| 697 | TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3); |
| 698 | |
| 699 | Standard_Real Dx, Dy, Ratio; |
| 700 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 701 | Standard_Integer j; |
| 702 | |
| 703 | Standard_Integer stop = 0; |
| 704 | |
| 705 | Standard_Boolean BResult; |
| 706 | |
| 707 | j = MyDefinedView.Extent (); |
| 708 | |
| 709 | while ((! stop) && (MyIterator.More ())) { |
| 710 | if (TheCView.ViewId == |
| 711 | (MyIterator.Value ())->Identification ()) { |
| 712 | TOri_Matrix = |
| 713 | (MyIterator.Value ())->MatrixOfOrientation (); |
| 714 | TMap_Matrix = |
| 715 | (MyIterator.Value ())->MatrixOfMapping (); |
| 716 | stop = 1; |
| 717 | } |
| 718 | |
| 719 | // MyIterator.Next () is located on the next view |
| 720 | MyIterator.Next (); |
| 721 | } |
| 722 | |
| 723 | // View Mapping Transformation and View Clip, inversion |
| 724 | BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv); |
| 725 | |
| 726 | // View Orientation Transformation, inversion |
| 727 | BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv); |
| 728 | |
| 729 | // (AU, AV) : Device Coordinate Space |
| 730 | // DCS -> NPCS Normalized Projection Coordinate Space |
| 731 | Dx = Standard_Real (Width); |
| 732 | Dy = Standard_Real (Height); |
| 733 | Ratio = Dx / Dy; |
| 734 | |
| 735 | if (Ratio >= 1.) { |
| 736 | NPCX = Standard_Real (AU) / Dx; |
| 737 | NPCY = (Dy - Standard_Real (AV)) / Dx; |
| 738 | } |
| 739 | else { |
| 740 | NPCX = Standard_Real (AU) / Dy; |
| 741 | NPCY = (Dy - Standard_Real (AV)) / Dy; |
| 742 | } |
| 743 | NPCZ = 0.0; |
| 744 | |
| 745 | // NPCS -> VRCS View Reference Coordinate Space |
| 746 | // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC); |
| 747 | |
| 748 | VRCX = TMap_Matrix_Inv (0, 0) * NPCX |
| 749 | + TMap_Matrix_Inv (0, 1) * NPCY |
| 750 | + TMap_Matrix_Inv (0, 2) * NPCZ |
| 751 | + TMap_Matrix_Inv (0, 3); |
| 752 | VRCY = TMap_Matrix_Inv (1, 0) * NPCX |
| 753 | + TMap_Matrix_Inv (1, 1) * NPCY |
| 754 | + TMap_Matrix_Inv (1, 2) * NPCZ |
| 755 | + TMap_Matrix_Inv (1, 3); |
| 756 | VRCZ = TMap_Matrix_Inv (2, 0) * NPCX |
| 757 | + TMap_Matrix_Inv (2, 1) * NPCY |
| 758 | + TMap_Matrix_Inv (2, 2) * NPCZ |
| 759 | + TMap_Matrix_Inv (2, 3); |
| 760 | VRCT = TMap_Matrix_Inv (3, 0) * NPCX |
| 761 | + TMap_Matrix_Inv (3, 1) * NPCY |
| 762 | + TMap_Matrix_Inv (3, 2) * NPCZ |
| 763 | + TMap_Matrix_Inv (3, 3); |
| 764 | |
| 765 | // VRCS -> WCS World Coordinate Space |
| 766 | // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC); |
| 767 | |
| 768 | WCX = TOri_Matrix_Inv (0, 0) * VRCX |
| 769 | + TOri_Matrix_Inv (0, 1) * VRCY |
| 770 | + TOri_Matrix_Inv (0, 2) * VRCZ |
| 771 | + TOri_Matrix_Inv (0, 3) * VRCT; |
| 772 | WCY = TOri_Matrix_Inv (1, 0) * VRCX |
| 773 | + TOri_Matrix_Inv (1, 1) * VRCY |
| 774 | + TOri_Matrix_Inv (1, 2) * VRCZ |
| 775 | + TOri_Matrix_Inv (1, 3) * VRCT; |
| 776 | WCZ = TOri_Matrix_Inv (2, 0) * VRCX |
| 777 | + TOri_Matrix_Inv (2, 1) * VRCY |
| 778 | + TOri_Matrix_Inv (2, 2) * VRCZ |
| 779 | + TOri_Matrix_Inv (2, 3) * VRCT; |
| 780 | WCT = TOri_Matrix_Inv (3, 0) * VRCX |
| 781 | + TOri_Matrix_Inv (3, 1) * VRCY |
| 782 | + TOri_Matrix_Inv (3, 2) * VRCZ |
| 783 | + TOri_Matrix_Inv (3, 3) * VRCT; |
| 784 | |
| 785 | if (WCT != 0.) |
| 786 | Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT); |
| 787 | else |
| 788 | Point.SetCoord (RealLast (), RealLast (), RealLast ()); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | return (Point); |
| 793 | |
| 794 | } |
| 795 | |
| 796 | void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const { |
| 797 | |
| 798 | // Conversion only if the data is correct |
| 799 | Graphic3d_CView TheCView; |
| 800 | |
| 801 | if (! ViewExists (AWindow, TheCView)) { |
| 802 | Point.SetCoord (RealLast (), RealLast (), RealLast ()); |
| 803 | Proj.SetCoord (0., 0., 0.); |
| 804 | } |
| 805 | else { |
| 806 | Standard_Integer Width, Height; |
| 807 | Standard_ShortReal x, y, z; |
| 808 | Standard_ShortReal dx, dy, dz; |
| 809 | Standard_Boolean Result; |
| 810 | |
| 811 | AWindow->Size (Width, Height); |
| 812 | |
| 813 | Result = MyGraphicDriver->UnProjectRasterWithRay (TheCView, |
| 814 | 0, 0, Width, Height, |
| 815 | AU, AV, x, y, z, dx, dy, dz); |
| 816 | |
| 817 | // unproject is done by UnProjectRaster |
| 818 | if (Result) { |
| 819 | Point.SetCoord |
| 820 | (Standard_Real (x), Standard_Real (y), Standard_Real (z)); |
| 821 | Proj.SetCoord |
| 822 | (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz)); |
| 823 | Proj.Normalize(); |
| 824 | } |
| 825 | // unproject cannot be done by UnProjectRaster |
| 826 | // Code is suspended since drivers Phigs are Pex abandoned. |
| 827 | else { |
| 828 | |
| 829 | Standard_Real NPCX, NPCY, NPCZ; |
| 830 | Standard_Real VRCX, VRCY, VRCZ, VRCT; |
| 831 | Standard_Real WCX, WCY, WCZ, WCT; |
| 832 | |
| 833 | TColStd_Array2OfReal TOri_Matrix (0,3,0,3); |
| 834 | TColStd_Array2OfReal TMap_Matrix (0,3,0,3); |
| 835 | TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3); |
| 836 | TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3); |
| 837 | |
| 838 | Standard_Real Dx, Dy, Ratio; |
| 839 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 840 | Standard_Integer j; |
| 841 | |
| 842 | Standard_Integer stop = 0; |
| 843 | |
| 844 | Standard_Boolean BResult; |
| 845 | |
| 846 | j = MyDefinedView.Extent (); |
| 847 | |
| 848 | while ((! stop) && (MyIterator.More ())) { |
| 849 | if (TheCView.ViewId == |
| 850 | (MyIterator.Value ())->Identification ()) { |
| 851 | TOri_Matrix = |
| 852 | (MyIterator.Value ())->MatrixOfOrientation (); |
| 853 | TMap_Matrix = |
| 854 | (MyIterator.Value ())->MatrixOfMapping (); |
| 855 | stop = 1; |
| 856 | } |
| 857 | |
| 858 | // MyIterator.Next () is located on the next view |
| 859 | MyIterator.Next (); |
| 860 | } |
| 861 | |
| 862 | // View Mapping Transformation and View Clip, inversion |
| 863 | BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv); |
| 864 | |
| 865 | // View Orientation Transformation, inversion |
| 866 | BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv); |
| 867 | |
| 868 | // (AU, AV) : Device Coordinate Space |
| 869 | // DCS -> NPCS Normalized Projection Coordinate Space |
| 870 | Dx = Standard_Real (Width); |
| 871 | Dy = Standard_Real (Height); |
| 872 | Ratio = Dx / Dy; |
| 873 | |
| 874 | if (Ratio >= 1.) { |
| 875 | NPCX = Standard_Real (AU) / Dx; |
| 876 | NPCY = (Dy - Standard_Real (AV)) / Dx; |
| 877 | } |
| 878 | else { |
| 879 | NPCX = Standard_Real (AU) / Dy; |
| 880 | NPCY = (Dy - Standard_Real (AV)) / Dy; |
| 881 | } |
| 882 | NPCZ = 0.0; |
| 883 | |
| 884 | // NPCS -> VRCS View Reference Coordinate Space |
| 885 | // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC); |
| 886 | |
| 887 | VRCX = TMap_Matrix_Inv (0, 0) * NPCX |
| 888 | + TMap_Matrix_Inv (0, 1) * NPCY |
| 889 | + TMap_Matrix_Inv (0, 2) * NPCZ |
| 890 | + TMap_Matrix_Inv (0, 3); |
| 891 | VRCY = TMap_Matrix_Inv (1, 0) * NPCX |
| 892 | + TMap_Matrix_Inv (1, 1) * NPCY |
| 893 | + TMap_Matrix_Inv (1, 2) * NPCZ |
| 894 | + TMap_Matrix_Inv (1, 3); |
| 895 | VRCZ = TMap_Matrix_Inv (2, 0) * NPCX |
| 896 | + TMap_Matrix_Inv (2, 1) * NPCY |
| 897 | + TMap_Matrix_Inv (2, 2) * NPCZ |
| 898 | + TMap_Matrix_Inv (2, 3); |
| 899 | VRCT = TMap_Matrix_Inv (3, 0) * NPCX |
| 900 | + TMap_Matrix_Inv (3, 1) * NPCY |
| 901 | + TMap_Matrix_Inv (3, 2) * NPCZ |
| 902 | + TMap_Matrix_Inv (3, 3); |
| 903 | |
| 904 | // VRCS -> WCS World Coordinate Space |
| 905 | // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC); |
| 906 | |
| 907 | WCX = TOri_Matrix_Inv (0, 0) * VRCX |
| 908 | + TOri_Matrix_Inv (0, 1) * VRCY |
| 909 | + TOri_Matrix_Inv (0, 2) * VRCZ |
| 910 | + TOri_Matrix_Inv (0, 3) * VRCT; |
| 911 | WCY = TOri_Matrix_Inv (1, 0) * VRCX |
| 912 | + TOri_Matrix_Inv (1, 1) * VRCY |
| 913 | + TOri_Matrix_Inv (1, 2) * VRCZ |
| 914 | + TOri_Matrix_Inv (1, 3) * VRCT; |
| 915 | WCZ = TOri_Matrix_Inv (2, 0) * VRCX |
| 916 | + TOri_Matrix_Inv (2, 1) * VRCY |
| 917 | + TOri_Matrix_Inv (2, 2) * VRCZ |
| 918 | + TOri_Matrix_Inv (2, 3) * VRCT; |
| 919 | WCT = TOri_Matrix_Inv (3, 0) * VRCX |
| 920 | + TOri_Matrix_Inv (3, 1) * VRCY |
| 921 | + TOri_Matrix_Inv (3, 2) * VRCZ |
| 922 | + TOri_Matrix_Inv (3, 3) * VRCT; |
| 923 | |
| 924 | if (WCT != 0.) |
| 925 | Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT); |
| 926 | else |
| 927 | Point.SetCoord (RealLast (), RealLast (), RealLast ()); |
| 928 | |
| 929 | // Define projection ray |
| 930 | NPCZ = 10.0; |
| 931 | |
| 932 | // NPCS -> VRCS View Reference Coordinate Space |
| 933 | // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC); |
| 934 | |
| 935 | VRCX = TMap_Matrix_Inv (0, 0) * NPCX |
| 936 | + TMap_Matrix_Inv (0, 1) * NPCY |
| 937 | + TMap_Matrix_Inv (0, 2) * NPCZ |
| 938 | + TMap_Matrix_Inv (0, 3); |
| 939 | VRCY = TMap_Matrix_Inv (1, 0) * NPCX |
| 940 | + TMap_Matrix_Inv (1, 1) * NPCY |
| 941 | + TMap_Matrix_Inv (1, 2) * NPCZ |
| 942 | + TMap_Matrix_Inv (1, 3); |
| 943 | VRCZ = TMap_Matrix_Inv (2, 0) * NPCX |
| 944 | + TMap_Matrix_Inv (2, 1) * NPCY |
| 945 | + TMap_Matrix_Inv (2, 2) * NPCZ |
| 946 | + TMap_Matrix_Inv (2, 3); |
| 947 | VRCT = TMap_Matrix_Inv (3, 0) * NPCX |
| 948 | + TMap_Matrix_Inv (3, 1) * NPCY |
| 949 | + TMap_Matrix_Inv (3, 2) * NPCZ |
| 950 | + TMap_Matrix_Inv (3, 3); |
| 951 | |
| 952 | // VRCS -> WCS World Coordinate Space |
| 953 | // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC); |
| 954 | |
| 955 | WCX = TOri_Matrix_Inv (0, 0) * VRCX |
| 956 | + TOri_Matrix_Inv (0, 1) * VRCY |
| 957 | + TOri_Matrix_Inv (0, 2) * VRCZ |
| 958 | + TOri_Matrix_Inv (0, 3) * VRCT; |
| 959 | WCY = TOri_Matrix_Inv (1, 0) * VRCX |
| 960 | + TOri_Matrix_Inv (1, 1) * VRCY |
| 961 | + TOri_Matrix_Inv (1, 2) * VRCZ |
| 962 | + TOri_Matrix_Inv (1, 3) * VRCT; |
| 963 | WCZ = TOri_Matrix_Inv (2, 0) * VRCX |
| 964 | + TOri_Matrix_Inv (2, 1) * VRCY |
| 965 | + TOri_Matrix_Inv (2, 2) * VRCZ |
| 966 | + TOri_Matrix_Inv (2, 3) * VRCT; |
| 967 | WCT = TOri_Matrix_Inv (3, 0) * VRCX |
| 968 | + TOri_Matrix_Inv (3, 1) * VRCY |
| 969 | + TOri_Matrix_Inv (3, 2) * VRCZ |
| 970 | + TOri_Matrix_Inv (3, 3) * VRCT; |
| 971 | |
| 972 | if (WCT != 0.) { |
| 973 | Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT); |
| 974 | Proj.Normalize(); |
| 975 | } |
| 976 | else |
| 977 | Proj.SetCoord (0., 0., 0.); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | } |
| 982 | |
| 983 | Visual3d_PickDescriptor Visual3d_ViewManager::Pick (const Visual3d_ContextPick& CTX, const Handle(Aspect_Window)& AWindow, const Standard_Integer AX, const Standard_Integer AY) { |
| 984 | |
| 985 | // The marking is activated only if the data is correct |
| 986 | Standard_Boolean DoPick = Standard_False; |
| 987 | |
| 988 | CALL_DEF_PICK apick; |
| 989 | Standard_Integer Width, Height; |
| 990 | |
| 991 | // Parse the list of views to find a |
| 992 | // view having this specified window |
| 993 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 994 | int TheWindowIdOfView; |
| 995 | |
| 996 | #ifndef WNT |
| 997 | const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow; |
| 998 | int TheSpecifiedWindowId = int (THEWindow->XWindow ()); |
| 999 | #else |
| 1000 | const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow; |
| 1001 | int TheSpecifiedWindowId = int (THEWindow->HWindow ()); |
| 1002 | #endif // WNT |
| 1003 | |
| 1004 | while ((! DoPick) && (MyIterator.More ())) { |
| 1005 | |
| 1006 | if ( ((MyIterator.Value ())->IsDefined ()) && |
| 1007 | ((MyIterator.Value ())->IsActive ()) ) { |
| 1008 | |
| 1009 | const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window (); |
| 1010 | #ifndef WNT |
| 1011 | const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow; |
| 1012 | TheWindowIdOfView = int (theWindow->XWindow ()); |
| 1013 | #else |
| 1014 | const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow; |
| 1015 | TheWindowIdOfView = int (theWindow->HWindow ()); |
| 1016 | #endif // WNT |
| 1017 | // Comparision on window IDs |
| 1018 | if (TheWindowIdOfView == TheSpecifiedWindowId) { |
| 1019 | DoPick = Standard_True; |
| 1020 | |
| 1021 | // Update |
| 1022 | apick.WsId = |
| 1023 | int ((MyIterator.Value ())->Identification ()); |
| 1024 | |
| 1025 | apick.ViewId = |
| 1026 | int ((MyIterator.Value ())->Identification ()); |
| 1027 | #ifndef WNT |
| 1028 | apick.DefWindow.XWindow = TheSpecifiedWindowId; |
| 1029 | #else |
| 1030 | apick.DefWindow.XWindow = (HWND) TheSpecifiedWindowId; |
| 1031 | #endif |
| 1032 | |
| 1033 | apick.x = int (AX); |
| 1034 | apick.y = int (AY); |
| 1035 | |
| 1036 | theWindow->Size (Width, Height); |
| 1037 | apick.DefWindow.dx = float (Width); |
| 1038 | apick.DefWindow.dy = float (Height); |
| 1039 | |
| 1040 | apick.Context.aperture = (float) CTX.Aperture (); |
| 1041 | apick.Context.order = int (CTX.Order ()); |
| 1042 | apick.Context.depth = int (CTX.Depth ()); |
| 1043 | |
| 1044 | } |
| 1045 | } /* if ((MyIterator.Value ())->IsDefined ()) { */ |
| 1046 | |
| 1047 | // MyIterator.Next () is located on the next view |
| 1048 | MyIterator.Next (); |
| 1049 | } |
| 1050 | |
| 1051 | if (DoPick) |
| 1052 | MyGraphicDriver->Pick (apick); |
| 1053 | else |
| 1054 | apick.Pick.depth = 0; |
| 1055 | |
| 1056 | // Picking : return |
| 1057 | Standard_Integer i, j=0; |
| 1058 | Standard_Integer NbPick; |
| 1059 | |
| 1060 | Visual3d_PickDescriptor PDes (CTX); |
| 1061 | Visual3d_PickPath PPat; |
| 1062 | |
| 1063 | PDes.Clear (); |
| 1064 | NbPick = 0; |
| 1065 | // For i=0 it is not a graphic structure it is a view structure |
| 1066 | // For i=1 it is the displayed graphic structure |
| 1067 | // For i=2 to apick.Pick.depth-1 it is the connected graphic structures |
| 1068 | if (apick.Pick.depth != 0) { |
| 1069 | j = apick.Pick.listid[1]; |
| 1070 | if ((Graphic3d_StructureManager::Identification (j))-> |
| 1071 | IsSelectable ()) { |
| 1072 | // Maj element number |
| 1073 | PPat.SetElementNumber (apick.Pick.listelem[1]); |
| 1074 | // Maj pick identifier |
| 1075 | PPat.SetPickIdentifier (apick.Pick.listpickid[1]); |
| 1076 | // Maj structure |
| 1077 | PPat.SetStructIdentifier |
| 1078 | (Graphic3d_StructureManager::Identification (j)); |
| 1079 | // Maj PickPath |
| 1080 | PDes.AddPickPath (PPat); |
| 1081 | NbPick++; |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | // Not very efficient, revise (CAL 22/09/95) |
| 1086 | if (apick.Pick.depth > 2) { |
| 1087 | Handle(Graphic3d_Structure) StructCur = |
| 1088 | Graphic3d_StructureManager::Identification (j); |
| 1089 | Standard_Boolean found; |
| 1090 | Graphic3d_MapOfStructure Set; |
| 1091 | |
| 1092 | for (i=2; i<apick.Pick.depth; i++) { |
| 1093 | found = Standard_False; |
| 1094 | j = apick.Pick.listid[i-1]; |
| 1095 | Set.Clear (); |
| 1096 | StructCur->Descendants (Set); |
| 1097 | Graphic3d_MapIteratorOfMapOfStructure IteratorD (Set); |
| 1098 | |
| 1099 | j = apick.Pick.listid[i]; |
| 1100 | while (IteratorD.More () && !found) { |
| 1101 | StructCur = IteratorD.Key (); |
| 1102 | if (StructCur->Identification () == j ) { |
| 1103 | found = Standard_True; |
| 1104 | // Maj element number |
| 1105 | PPat.SetElementNumber (apick.Pick.listelem[i]); |
| 1106 | // Maj pick identifier |
| 1107 | PPat.SetPickIdentifier (apick.Pick.listpickid[i]); |
| 1108 | // Maj structure |
| 1109 | PPat.SetStructIdentifier (StructCur); |
| 1110 | // Maj PickPath |
| 1111 | PDes.AddPickPath (PPat); |
| 1112 | NbPick++; |
| 1113 | } |
| 1114 | // IteratorD.Next () is located on the next structure |
| 1115 | IteratorD.Next (); |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | apick.Pick.depth = int (NbPick); |
| 1121 | |
| 1122 | MyGraphicDriver->InitPick (); |
| 1123 | |
| 1124 | return (PDes); |
| 1125 | |
| 1126 | } |
| 1127 | |
| 1128 | Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const { |
| 1129 | |
| 1130 | Standard_Boolean Exist = Standard_False; |
| 1131 | |
| 1132 | // Parse the list of views to find |
| 1133 | // a view with the specified window |
| 1134 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 1135 | int TheWindowIdOfView; |
| 1136 | |
| 1137 | #ifndef WNT |
| 1138 | const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow; |
| 1139 | int TheSpecifiedWindowId = int (THEWindow->XWindow ()); |
| 1140 | #else |
| 1141 | const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow; |
| 1142 | int TheSpecifiedWindowId = int (THEWindow->HWindow ()); |
| 1143 | #endif // WNT |
| 1144 | |
| 1145 | while ((! Exist) && (MyIterator.More ())) { |
| 1146 | |
| 1147 | if ( ((MyIterator.Value ())->IsDefined ()) && |
| 1148 | ((MyIterator.Value ())->IsActive ()) ) { |
| 1149 | |
| 1150 | const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window (); |
| 1151 | #ifndef WNT |
| 1152 | const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow; |
| 1153 | TheWindowIdOfView = int (theWindow->XWindow ()); |
| 1154 | #else |
| 1155 | const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow; |
| 1156 | TheWindowIdOfView = int (theWindow->HWindow ()); |
| 1157 | #endif // WNT |
| 1158 | // Comparaison on window IDs |
| 1159 | if (TheWindowIdOfView == TheSpecifiedWindowId) { |
| 1160 | Exist = Standard_True; |
| 1161 | TheCView = *(CALL_DEF_VIEW *)(MyIterator.Value ())->CView (); |
| 1162 | } |
| 1163 | } /* if ((MyIterator.Value ())->IsDefined ()) */ |
| 1164 | |
| 1165 | // MyIterator.Next () is located on the next view |
| 1166 | MyIterator.Next (); |
| 1167 | } |
| 1168 | |
| 1169 | return (Exist); |
| 1170 | |
| 1171 | } |
| 1172 | |
| 1173 | void Visual3d_ViewManager::Activate () { |
| 1174 | |
| 1175 | // |
| 1176 | // Activates all deactivated views |
| 1177 | // |
| 1178 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 1179 | |
| 1180 | #ifdef DEB |
| 1181 | Standard_Integer Length = MyDefinedView.Extent (); |
| 1182 | #else |
| 1183 | MyDefinedView.Extent (); |
| 1184 | #endif |
| 1185 | |
| 1186 | while (MyIterator.More ()) { |
| 1187 | if (! (MyIterator.Value ())->IsActive ()) |
| 1188 | (MyIterator.Value ())->Activate (); |
| 1189 | |
| 1190 | // MyIterator.Next () is located on the next view |
| 1191 | MyIterator.Next (); |
| 1192 | } |
| 1193 | |
| 1194 | } |
| 1195 | |
| 1196 | void Visual3d_ViewManager::Deactivate () { |
| 1197 | |
| 1198 | // |
| 1199 | // Deactivates all activated views |
| 1200 | // |
| 1201 | #ifdef DEB |
| 1202 | Standard_Integer Length = MyDefinedView.Extent (); |
| 1203 | #else |
| 1204 | MyDefinedView.Extent (); |
| 1205 | #endif |
| 1206 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 1207 | |
| 1208 | while (MyIterator.More ()) { |
| 1209 | if ((MyIterator.Value ())->IsActive ()) |
| 1210 | (MyIterator.Value ())->Deactivate (); |
| 1211 | |
| 1212 | // MyIterator.Next () is located on the next view |
| 1213 | MyIterator.Next (); |
| 1214 | } |
| 1215 | |
| 1216 | } |
| 1217 | |
| 1218 | Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const { |
| 1219 | |
| 1220 | // Retourne the planned of definable views for the current |
| 1221 | // Visual3d_ViewManager. |
| 1222 | return |
| 1223 | (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ())); |
| 1224 | |
| 1225 | } |
| 1226 | |
| 1227 | Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const { |
| 1228 | |
| 1229 | return (Graphic3d_StructureManager::Identification (AId)); |
| 1230 | |
| 1231 | } |
| 1232 | |
| 1233 | Standard_Integer Visual3d_ViewManager::Identification () const { |
| 1234 | |
| 1235 | return (Graphic3d_StructureManager::Identification ()); |
| 1236 | |
| 1237 | } |
| 1238 | |
| 1239 | Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) { |
| 1240 | |
| 1241 | MyDefinedView.Add (AView); |
| 1242 | return (MyViewGenId.Next ()); |
| 1243 | |
| 1244 | } |
| 1245 | |
| 1246 | void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId) |
| 1247 | { |
| 1248 | MyViewGenId.Free(aViewId); |
| 1249 | } |
| 1250 | |
| 1251 | void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) { |
| 1252 | |
| 1253 | if (MyTransparency && AFlag) return; |
| 1254 | if (! MyTransparency && ! AFlag) return; |
| 1255 | |
| 1256 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 1257 | while (MyIterator.More ()) { |
| 1258 | (MyIterator.Value ())->SetTransparency (AFlag); |
| 1259 | // MyIterator.Next () is located on the next view |
| 1260 | MyIterator.Next (); |
| 1261 | } |
| 1262 | |
| 1263 | MyTransparency = AFlag; |
| 1264 | |
| 1265 | } |
| 1266 | |
| 1267 | Standard_Boolean Visual3d_ViewManager::Transparency () const { |
| 1268 | |
| 1269 | return (MyTransparency); |
| 1270 | |
| 1271 | } |
| 1272 | |
| 1273 | void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) { |
| 1274 | |
| 1275 | if (MyZBufferAuto && AFlag) return; |
| 1276 | if (! MyZBufferAuto && ! AFlag) return; |
| 1277 | |
| 1278 | // if pass from False to True : |
| 1279 | // no problem, at the next view update, it |
| 1280 | // will properly ask questions to answer (SetVisualisation) |
| 1281 | // if pass from True to False : |
| 1282 | // it is necessary to modify ZBufferActivity at each view so that |
| 1283 | // zbuffer could be active only if required by context. |
| 1284 | // In this case -1 is passed so that the view ask itself the question |
| 1285 | // Note : 0 forces the desactivation, 1 forces the activation |
| 1286 | if (! AFlag) { |
| 1287 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
| 1288 | while (MyIterator.More ()) { |
| 1289 | (MyIterator.Value ())->SetZBufferActivity (-1); |
| 1290 | // MyIterator.Next () is located on the next view |
| 1291 | MyIterator.Next (); |
| 1292 | } |
| 1293 | } |
| 1294 | MyZBufferAuto = AFlag; |
| 1295 | |
| 1296 | } |
| 1297 | |
| 1298 | Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const { |
| 1299 | |
| 1300 | return (MyZBufferAuto); |
| 1301 | |
| 1302 | } |
| 1303 | |
| 1304 | void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) { |
| 1305 | |
| 1306 | #ifdef TRACE_LAYER |
| 1307 | cout << "Visual3d_ViewManager::SetLayer\n" << flush; |
| 1308 | #endif |
| 1309 | |
| 1310 | if (ALayer->Type () == Aspect_TOL_OVERLAY) { |
| 1311 | #ifdef TRACE_LAYER |
| 1312 | if (MyOverLayer.IsNull ()) |
| 1313 | cout << "MyOverLayer is defined" << endl; |
| 1314 | else |
| 1315 | cout << "MyOverLayer is redefined" << endl; |
| 1316 | #endif |
| 1317 | MyOverLayer = ALayer; |
| 1318 | } |
| 1319 | else { |
| 1320 | #ifdef TRACE_LAYER |
| 1321 | if (MyUnderLayer.IsNull ()) |
| 1322 | cout << "MyUnderLayer is defined" << endl; |
| 1323 | else |
| 1324 | cout << "MyUnderLayer is redefined" << endl; |
| 1325 | #endif |
| 1326 | MyUnderLayer = ALayer; |
| 1327 | } |
| 1328 | |
| 1329 | } |
| 1330 | |
| 1331 | const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const { |
| 1332 | |
| 1333 | return (MyUnderLayer); |
| 1334 | |
| 1335 | } |
| 1336 | |
| 1337 | const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const { |
| 1338 | |
| 1339 | return (MyOverLayer); |
| 1340 | |
| 1341 | } |