| 1 | // Created by: NW,JPB,CAL |
| 2 | // Copyright (c) 1991-1999 Matra Datavision |
| 3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 4 | // |
| 5 | // This file is part of Open CASCADE Technology software library. |
| 6 | // |
| 7 | // This library is free software; you can redistribute it and/or modify it under |
| 8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
| 9 | // by the Free Software Foundation, with special exception defined in the file |
| 10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 11 | // distribution for complete text of the license and disclaimer of any warranty. |
| 12 | // |
| 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 14 | // commercial license or contractual agreement. |
| 15 | |
| 16 | // Modified 1/08/97 ; PCT : ajout texture mapping |
| 17 | // 20/08/97 ; PCT : ajout transparence pour texture |
| 18 | // 11/97 ; CAL : gestion du GraphicClear |
| 19 | // 11/97 ; CAL : ajout pointer StructPtr |
| 20 | // 11/97 ; CAL : amelioration de l'effacement SetManager |
| 21 | // CAL : 15 janvier 1998 |
| 22 | // Ajout de la methode IsTransformed dans une Structure. |
| 23 | // (Permet la transmission de cette Trsf vers |
| 24 | // la structure COMPUTED si necessaire) |
| 25 | // Ajout de la methode IsRotated dans une Structure. |
| 26 | // (Permet de connaitre le type de transformation |
| 27 | // pour declencher le calcul des parties cachees |
| 28 | // de maniere plus sioux) |
| 29 | // Ajout de 3 nouvelles methodes Compute virtual dans Structure. |
| 30 | // (Permet des Compute un peu plus specialises) |
| 31 | // Ajout des 2 methodes sur Owner dans Structure. |
| 32 | // (evite de calculer 2 fois les parties cachees |
| 33 | // pour 2 representations differentes affichees |
| 34 | // d'un meme Presentable Object (Owner)) |
| 35 | // Ajout des 2 methodes sur HLRValidation dans Structure. |
| 36 | // (permet de valider ou d'invalider le calcul des |
| 37 | // parties cachees sur certaines representations) |
| 38 | // Ajout de la transmission de la transformation d'une structure |
| 39 | // vers sa COMPUTED. |
| 40 | // 24/2/98 ; CAL : Modification de la gestion des champs |
| 41 | // CAL : 26 mars 1998 |
| 42 | // Patch, erreur dans la gestion du nombre de Group avec |
| 43 | // facettes dans Graphic3d_Structure avec une operation |
| 44 | // de Clear. (PRO12795) |
| 45 | // FGU : 30 Avril 1998 |
| 46 | // Ajout emission |
| 47 | // CAL : 20 mai 1998 |
| 48 | // Perfs. Connection entre structures COMPUTED. |
| 49 | // 30/11/98 ; FMN : S4069. Textes always visible. |
| 50 | // 22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets |
| 51 | |
| 52 | #define BUC60918 //GG 31/05/01 A transparente structure priority must have the |
| 53 | // MAX_PRIORITY value so, the highlighted structure must have |
| 54 | // MAX_PRIORITY-1 value. |
| 55 | // Add ResetDisplayPriority() method. |
| 56 | |
| 57 | #define OCC1174 // SAV 08/01/03 Added back face interior color controling |
| 58 | |
| 59 | |
| 60 | |
| 61 | //-Version |
| 62 | |
| 63 | //-Design Declaration of variables specific to graphic structures |
| 64 | |
| 65 | //-Warning A structure is defined in a manager |
| 66 | // This is a sequence of groups of primitives |
| 67 | |
| 68 | //-References |
| 69 | |
| 70 | //-Language C++ 2.0 |
| 71 | |
| 72 | //-Declarations |
| 73 | |
| 74 | // for the class |
| 75 | |
| 76 | #define XDOWNCAST |
| 77 | #define XDESTROY |
| 78 | #define XDEBUG |
| 79 | #define XTRACE |
| 80 | #define XTRACE_ISTRSF |
| 81 | |
| 82 | #include <stdio.h> |
| 83 | |
| 84 | #include <Graphic3d_Structure.ixx> |
| 85 | #include <Graphic3d_Structure.pxx> |
| 86 | |
| 87 | #include <Graphic3d_GraphicDriver.hxx> |
| 88 | #include <Graphic3d_MaterialAspect.hxx> |
| 89 | |
| 90 | #include <Graphic3d_MapOfStructure.hxx> |
| 91 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> |
| 92 | |
| 93 | #include <Quantity_Color.hxx> |
| 94 | #include <TColStd_Array2OfReal.hxx> |
| 95 | #include <Graphic3d_TextureMap.hxx> |
| 96 | |
| 97 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 98 | #include <Aspect_PolygonOffsetMode.hxx> |
| 99 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 100 | |
| 101 | //-Aliases |
| 102 | |
| 103 | //-Global data definitions |
| 104 | |
| 105 | //-Constructors |
| 106 | |
| 107 | Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& AManager): |
| 108 | MyAncestors (), |
| 109 | MyDescendants (), |
| 110 | MyGroups (), |
| 111 | MyHighlightColor (Quantity_NOC_WHITE) |
| 112 | { |
| 113 | |
| 114 | Standard_Integer i, j; |
| 115 | |
| 116 | MyOwner = NULL; |
| 117 | |
| 118 | Handle(Graphic3d_AspectLine3d) aAspectLine3d = |
| 119 | new Graphic3d_AspectLine3d (); |
| 120 | Handle(Graphic3d_AspectText3d) aAspectText3d = |
| 121 | new Graphic3d_AspectText3d (); |
| 122 | Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = |
| 123 | new Graphic3d_AspectMarker3d (); |
| 124 | Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = |
| 125 | new Graphic3d_AspectFillArea3d (); |
| 126 | |
| 127 | // Return default values |
| 128 | AManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, |
| 129 | aAspectMarker3d, aAspectFillArea3d); |
| 130 | |
| 131 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 132 | // It is necessary to set default polygon offsets for a new presentation |
| 133 | aAspectFillArea3d->SetPolygonOffsets( Aspect_POM_Fill, 1., 0. ); |
| 134 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 135 | |
| 136 | // Update the associated CStructure |
| 137 | UpdateStructure (aAspectLine3d, aAspectText3d, |
| 138 | aAspectMarker3d, aAspectFillArea3d); |
| 139 | |
| 140 | MyFirstPtrStructureManager = MyPtrStructureManager = |
| 141 | (void *) AManager.operator->(); |
| 142 | MyCStructure.Id = int (AManager->NewIdentification ()); |
| 143 | |
| 144 | MyCStructure.IsOpen = 0; |
| 145 | MyCStructure.IsDeleted = 0; |
| 146 | |
| 147 | MyCStructure.Composition = 0; /* Graphic3d_TOC_REPLACE */ |
| 148 | |
| 149 | for (i=0; i<=3; i++) |
| 150 | for (j=0; j<=3; j++) |
| 151 | if (i == j) |
| 152 | MyCStructure.Transformation[i][j] = float (1.0); |
| 153 | else |
| 154 | MyCStructure.Transformation[i][j] = float (0.0); |
| 155 | |
| 156 | MyCStructure.Priority = int (Structure_MAX_PRIORITY / 2); |
| 157 | MyCStructure.PreviousPriority = MyCStructure.Priority; |
| 158 | MyCStructure.stick = 0, |
| 159 | MyCStructure.highlight = 0, |
| 160 | MyCStructure.visible = 1, |
| 161 | MyCStructure.pick = 1; |
| 162 | MyCStructure.ContainsFacet = 0, |
| 163 | MyCStructure.IsInfinite = 0, |
| 164 | MyCStructure.HLRValidation = 0; |
| 165 | |
| 166 | MyCStructure.ContextLine.IsDef = 1, |
| 167 | MyCStructure.ContextFillArea.IsDef = 1, |
| 168 | MyCStructure.ContextMarker.IsDef = 1, |
| 169 | MyCStructure.ContextText.IsDef = 1; |
| 170 | |
| 171 | MyCStructure.ContextLine.IsSet = 0, |
| 172 | MyCStructure.ContextFillArea.IsSet = 0, |
| 173 | MyCStructure.ContextMarker.IsSet = 0, |
| 174 | MyCStructure.ContextText.IsSet = 0; |
| 175 | |
| 176 | MyVisual = Graphic3d_TOS_ALL; |
| 177 | MyComputeVisual = Graphic3d_TOS_ALL; |
| 178 | |
| 179 | /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */ |
| 180 | /*MyCStructure.TransformPersistence.IsDef = 1;*/ |
| 181 | MyCStructure.TransformPersistence.IsSet = 0; |
| 182 | MyCStructure.TransformPersistence.Flag = Graphic3d_TMF_None; |
| 183 | MyCStructure.TransformPersistence.Point.x = 0.0; |
| 184 | MyCStructure.TransformPersistence.Point.y = 0.0; |
| 185 | MyCStructure.TransformPersistence.Point.z = 0.0; |
| 186 | /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */ |
| 187 | |
| 188 | MyGraphicDriver = AManager->GraphicDriver(); |
| 189 | MyGraphicDriver->Structure (MyCStructure); |
| 190 | |
| 191 | #ifdef TRACE |
| 192 | cout << "Graphic3d_Structure::Create (" << MyCStructure.Id << ")\n"; |
| 193 | #endif |
| 194 | |
| 195 | } |
| 196 | |
| 197 | //-Destructors |
| 198 | |
| 199 | void Graphic3d_Structure::Destroy () { |
| 200 | |
| 201 | #ifdef DESTROY |
| 202 | cout << "Graphic3d_Structure::Destroy (" << MyCStructure.Id << ")\n"; |
| 203 | #endif |
| 204 | |
| 205 | // as MyFirstPtrStructureManager can be already destroyed, |
| 206 | // avoid attempts to access it |
| 207 | MyFirstPtrStructureManager = 0; |
| 208 | Remove (); |
| 209 | |
| 210 | } |
| 211 | |
| 212 | //-Methods, in order |
| 213 | |
| 214 | void Graphic3d_Structure::Clear (const Standard_Boolean WithDestruction) |
| 215 | { |
| 216 | if (IsDeleted()) return; |
| 217 | |
| 218 | MyCStructure.ContainsFacet = 0; |
| 219 | |
| 220 | // clean groups in graphics driver at first |
| 221 | GraphicClear (WithDestruction); |
| 222 | |
| 223 | // only then remove group references |
| 224 | if (WithDestruction) |
| 225 | MyGroups.Clear(); |
| 226 | |
| 227 | MyStructureManager->Clear (this, WithDestruction); |
| 228 | |
| 229 | Update(); |
| 230 | } |
| 231 | |
| 232 | void Graphic3d_Structure::Remove () { |
| 233 | |
| 234 | if (IsDeleted ()) return; |
| 235 | |
| 236 | #ifdef DESTROY |
| 237 | if (MyDescendants.Length () != 0) { |
| 238 | cout << "The structure " << MyCStructure.Id << " have " |
| 239 | << MyDescendants.Length () << " descendants.\n" << flush; |
| 240 | } |
| 241 | if (MyAncestors.Length () != 0) { |
| 242 | cout << "The structure " << MyCStructure.Id << " have " |
| 243 | << MyAncestors.Length () << " ancestors.\n" << flush; |
| 244 | } |
| 245 | #endif |
| 246 | |
| 247 | Standard_Integer i, Length; |
| 248 | |
| 249 | // clean groups in graphics driver at first; this is also should be done |
| 250 | // to avoid unwanted group cleaning in group's destructor |
| 251 | // Pass Standard_False to Clear(..) method to avoid updating in |
| 252 | // structure manager, it isn't necessary, besides of it structure manager |
| 253 | // could be already destroyed and invalid pointers used in structure; |
| 254 | Length = MyGroups.Length(); |
| 255 | for (Standard_Integer aGrId = 1; aGrId <= Length; ++aGrId) |
| 256 | MyGroups.ChangeValue (aGrId)->Clear (Standard_False); |
| 257 | |
| 258 | // Standard_Address APtr = (void *) This ().operator->(); |
| 259 | Standard_Address APtr = (void *) this; |
| 260 | // It is necessary to remove the eventual pointer on the structure |
| 261 | // that can be destroyed, in the list of descendants |
| 262 | // of ancesters of this structure and in the list of ancesters |
| 263 | // of descendants of the same structure. |
| 264 | |
| 265 | Length = MyDescendants.Length (); |
| 266 | for (i=1; i<=Length; i++) |
| 267 | ((Graphic3d_Structure *) |
| 268 | (MyDescendants.Value (i)))->Remove (APtr, Graphic3d_TOC_ANCESTOR); |
| 269 | |
| 270 | Length = MyAncestors.Length (); |
| 271 | for (i=1; i<=Length; i++) |
| 272 | ((Graphic3d_Structure *) |
| 273 | (MyAncestors.Value (i)))->Remove (APtr, Graphic3d_TOC_DESCENDANT); |
| 274 | |
| 275 | MyCStructure.ContainsFacet = 0; |
| 276 | MyCStructure.IsDeleted = 1; |
| 277 | |
| 278 | // Destruction of me in the graphic library |
| 279 | MyGraphicDriver->RemoveStructure (MyCStructure); |
| 280 | |
| 281 | // Liberation of the identification if the destroyed structure |
| 282 | // in the first manager that performs creation of the structure. |
| 283 | if ( MyFirstPtrStructureManager ) |
| 284 | MyFirstStructureManager->Remove (Standard_Integer (MyCStructure.Id)); |
| 285 | |
| 286 | } |
| 287 | |
| 288 | void Graphic3d_Structure::Display () { |
| 289 | |
| 290 | if (IsDeleted ()) return; |
| 291 | |
| 292 | if (! MyCStructure.stick) { |
| 293 | MyCStructure.stick = 1; |
| 294 | MyStructureManager->Display (this); |
| 295 | } |
| 296 | |
| 297 | MyCStructure.visible = 1; |
| 298 | } |
| 299 | |
| 300 | void Graphic3d_Structure::Display (const Standard_Integer Priority) { |
| 301 | |
| 302 | if (IsDeleted ()) return; |
| 303 | |
| 304 | SetDisplayPriority (Priority); |
| 305 | |
| 306 | if (! MyCStructure.stick) { |
| 307 | MyCStructure.stick = 1; |
| 308 | MyStructureManager->Display (this); |
| 309 | } |
| 310 | |
| 311 | MyCStructure.visible = 1; |
| 312 | } |
| 313 | |
| 314 | void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer Priority) { |
| 315 | |
| 316 | if (IsDeleted ()) return; |
| 317 | |
| 318 | #ifdef BUC60918 |
| 319 | if( Priority == MyCStructure.Priority ) return; |
| 320 | #endif |
| 321 | |
| 322 | MyCStructure.PreviousPriority = MyCStructure.Priority; |
| 323 | MyCStructure.Priority = int (Priority); |
| 324 | |
| 325 | if (MyCStructure.Priority != MyCStructure.PreviousPriority) { |
| 326 | if ( (MyCStructure.Priority > Structure_MAX_PRIORITY) || |
| 327 | (MyCStructure.Priority < Structure_MIN_PRIORITY) ) |
| 328 | Graphic3d_PriorityDefinitionError::Raise |
| 329 | ("Bad value for StructurePriority"); |
| 330 | |
| 331 | if (MyCStructure.stick) |
| 332 | MyStructureManager->ChangeDisplayPriority (this, |
| 333 | Standard_Integer (MyCStructure.PreviousPriority), |
| 334 | Standard_Integer (MyCStructure.Priority)); |
| 335 | } |
| 336 | |
| 337 | } |
| 338 | |
| 339 | #ifdef BUC60918 |
| 340 | void Graphic3d_Structure::ResetDisplayPriority () { |
| 341 | |
| 342 | if (IsDeleted ()) return; |
| 343 | |
| 344 | if (MyCStructure.Priority != MyCStructure.PreviousPriority) { |
| 345 | Standard_Integer priority = MyCStructure.Priority; |
| 346 | MyCStructure.Priority = MyCStructure.PreviousPriority; |
| 347 | |
| 348 | if (MyCStructure.stick) |
| 349 | MyStructureManager->ChangeDisplayPriority (this, |
| 350 | priority, |
| 351 | Standard_Integer (MyCStructure.Priority)); |
| 352 | } |
| 353 | |
| 354 | } |
| 355 | #endif |
| 356 | |
| 357 | Standard_Integer Graphic3d_Structure::DisplayPriority () const { |
| 358 | |
| 359 | return Standard_Integer (MyCStructure.Priority); |
| 360 | |
| 361 | } |
| 362 | |
| 363 | void Graphic3d_Structure::Erase () { |
| 364 | |
| 365 | if (IsDeleted ()) return; |
| 366 | |
| 367 | if (MyCStructure.stick) { |
| 368 | MyCStructure.stick = 0; |
| 369 | MyStructureManager->Erase (this); |
| 370 | } |
| 371 | |
| 372 | } |
| 373 | |
| 374 | void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod AMethod) { |
| 375 | |
| 376 | if (IsDeleted ()) return; |
| 377 | |
| 378 | // Highlight on already Highlighted structure. |
| 379 | if (MyCStructure.highlight) { |
| 380 | |
| 381 | Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode (); |
| 382 | if (UpdateMode == Aspect_TOU_WAIT) |
| 383 | UnHighlight (); |
| 384 | else { |
| 385 | // To avoid call of method : Update () |
| 386 | // Not useful and can be costly. |
| 387 | MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT); |
| 388 | UnHighlight (); |
| 389 | MyStructureManager->SetUpdateMode (UpdateMode); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | #ifdef BUC60918 |
| 394 | SetDisplayPriority (Standard_Integer (Structure_MAX_PRIORITY)-1); |
| 395 | #else |
| 396 | SetDisplayPriority (Standard_Integer (Structure_MAX_PRIORITY)); |
| 397 | #endif |
| 398 | |
| 399 | GraphicHighlight (AMethod); |
| 400 | MyStructureManager->Highlight (this, AMethod); |
| 401 | |
| 402 | Update (); |
| 403 | |
| 404 | } |
| 405 | |
| 406 | void Graphic3d_Structure::SetHighlightColor (const Quantity_Color& AColor) { |
| 407 | |
| 408 | if (IsDeleted ()) return; |
| 409 | |
| 410 | if (! MyCStructure.highlight) |
| 411 | MyHighlightColor = AColor; |
| 412 | else { |
| 413 | // Change highlight color on already Highlighted structure. |
| 414 | |
| 415 | Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode (); |
| 416 | if (UpdateMode == Aspect_TOU_WAIT) |
| 417 | UnHighlight (); |
| 418 | else { |
| 419 | // To avoid call of method : Update () |
| 420 | // Not useful and can be costly. |
| 421 | MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT); |
| 422 | UnHighlight (); |
| 423 | MyStructureManager->SetUpdateMode (UpdateMode); |
| 424 | } |
| 425 | MyHighlightColor = AColor; |
| 426 | Highlight (MyHighlightMethod); |
| 427 | } |
| 428 | |
| 429 | } |
| 430 | |
| 431 | void Graphic3d_Structure::SetVisible (const Standard_Boolean AValue) { |
| 432 | |
| 433 | if (IsDeleted ()) return; |
| 434 | |
| 435 | MyCStructure.visible = AValue ? 1:0; |
| 436 | |
| 437 | MyGraphicDriver->NameSetStructure (MyCStructure); |
| 438 | |
| 439 | Update (); |
| 440 | |
| 441 | } |
| 442 | |
| 443 | void Graphic3d_Structure::SetPick (const Standard_Boolean AValue) { |
| 444 | |
| 445 | if (IsDeleted ()) return; |
| 446 | |
| 447 | MyCStructure.pick = AValue ? 1:0; |
| 448 | |
| 449 | MyGraphicDriver->NameSetStructure (MyCStructure); |
| 450 | |
| 451 | if (AValue) |
| 452 | MyStructureManager->Detectable (this); |
| 453 | else |
| 454 | MyStructureManager->Undetectable (this); |
| 455 | |
| 456 | Update (); |
| 457 | |
| 458 | } |
| 459 | |
| 460 | void Graphic3d_Structure::UnHighlight () { |
| 461 | |
| 462 | if (IsDeleted ()) return; |
| 463 | |
| 464 | if (MyCStructure.highlight) { |
| 465 | MyCStructure.highlight = 0; |
| 466 | |
| 467 | GraphicUnHighlight (); |
| 468 | MyStructureManager->UnHighlight (this); |
| 469 | #ifdef BUC60918 |
| 470 | ResetDisplayPriority(); |
| 471 | #else |
| 472 | SetDisplayPriority |
| 473 | (Standard_Integer (MyCStructure.PreviousPriority)); |
| 474 | #endif |
| 475 | Update (); |
| 476 | } |
| 477 | |
| 478 | } |
| 479 | |
| 480 | Quantity_Color Graphic3d_Structure::HighlightColor () const { |
| 481 | |
| 482 | return (MyHighlightColor); |
| 483 | |
| 484 | } |
| 485 | |
| 486 | Standard_Boolean Graphic3d_Structure::IsDisplayed () const { |
| 487 | |
| 488 | if (MyCStructure.stick) |
| 489 | return (Standard_True); |
| 490 | else |
| 491 | return (Standard_False); |
| 492 | |
| 493 | } |
| 494 | |
| 495 | Standard_Boolean Graphic3d_Structure::IsDeleted () const { |
| 496 | |
| 497 | if (MyCStructure.IsDeleted) |
| 498 | return (Standard_True); |
| 499 | else |
| 500 | return (Standard_False); |
| 501 | |
| 502 | } |
| 503 | |
| 504 | Standard_Boolean Graphic3d_Structure::IsHighlighted () const { |
| 505 | |
| 506 | if (MyCStructure.highlight) |
| 507 | return (Standard_True); |
| 508 | else |
| 509 | return (Standard_False); |
| 510 | |
| 511 | } |
| 512 | |
| 513 | Standard_Boolean Graphic3d_Structure::IsSelectable () const { |
| 514 | |
| 515 | if (MyCStructure.pick) |
| 516 | return (Standard_True); |
| 517 | else |
| 518 | return (Standard_False); |
| 519 | |
| 520 | } |
| 521 | |
| 522 | Standard_Boolean Graphic3d_Structure::IsVisible () const { |
| 523 | |
| 524 | if (MyCStructure.visible) |
| 525 | return (Standard_True); |
| 526 | else |
| 527 | return (Standard_False); |
| 528 | |
| 529 | } |
| 530 | |
| 531 | Standard_Boolean Graphic3d_Structure::IsRotated () const { |
| 532 | |
| 533 | // A somewhat light test ! |
| 534 | return ( MyCStructure.Transformation[0][1] != 0. |
| 535 | || MyCStructure.Transformation[0][2] != 0. |
| 536 | || MyCStructure.Transformation[1][0] != 0. |
| 537 | || MyCStructure.Transformation[1][2] != 0. |
| 538 | || MyCStructure.Transformation[2][0] != 0. |
| 539 | || MyCStructure.Transformation[2][1] != 0. ); |
| 540 | |
| 541 | } |
| 542 | |
| 543 | Standard_Boolean Graphic3d_Structure::IsTransformed () const { |
| 544 | |
| 545 | Standard_Boolean Result = Standard_False; |
| 546 | Standard_Integer i, j; |
| 547 | |
| 548 | for (i=0; i<=3 && ! Result; i++) |
| 549 | for (j=0; j<=3 && ! Result; j++) |
| 550 | if (i == j) |
| 551 | Result = MyCStructure.Transformation[i][j] != 1.; |
| 552 | else |
| 553 | Result = MyCStructure.Transformation[i][j] != 0.; |
| 554 | |
| 555 | #ifdef TRACE_ISTRSF |
| 556 | cout << "Structure " << Identification (); |
| 557 | if (Result) |
| 558 | cout << " is transformed\n" << flush; |
| 559 | else |
| 560 | cout << " is not transformed\n" << flush; |
| 561 | #endif |
| 562 | |
| 563 | return Result; |
| 564 | |
| 565 | } |
| 566 | |
| 567 | Standard_Boolean Graphic3d_Structure::ContainsFacet () const { |
| 568 | |
| 569 | if (IsDeleted ()) return (Standard_False); |
| 570 | |
| 571 | // A structure contains at least one facet : |
| 572 | // if one of these groups contains at least one facet. |
| 573 | |
| 574 | Standard_Boolean Result1 = Standard_False; |
| 575 | Standard_Boolean Result2 = Standard_False; |
| 576 | Standard_Integer i, Length; |
| 577 | |
| 578 | Result1 = (MyCStructure.ContainsFacet > 0); |
| 579 | |
| 580 | // If one of groups contains at least one facet, the structure contains it too. |
| 581 | if (Result1) return (Result1); |
| 582 | |
| 583 | Length = MyDescendants.Length (); |
| 584 | |
| 585 | // Stop at the first descendant containing at least one facet. |
| 586 | for (i=1; i<=Length && ! Result2; i++) |
| 587 | Result2 = ((Graphic3d_Structure *) |
| 588 | (MyDescendants.Value (i)))->ContainsFacet (); |
| 589 | |
| 590 | return (Result2); |
| 591 | |
| 592 | } |
| 593 | |
| 594 | Standard_Boolean Graphic3d_Structure::IsEmpty () const { |
| 595 | |
| 596 | if (IsDeleted ()) return (Standard_True); |
| 597 | |
| 598 | // A structure is empty : |
| 599 | // if all these groups are empty or if all |
| 600 | // groups are empty and all their descendants |
| 601 | // are empty or if all its descendants are empty. |
| 602 | |
| 603 | Standard_Boolean Result1 = Standard_True; |
| 604 | Standard_Integer i, Length = MyGroups.Length (); |
| 605 | |
| 606 | // Stop at the first non-empty group |
| 607 | for (i=1; i<=Length && Result1; i++) |
| 608 | Result1 = (MyGroups.Value (i))->IsEmpty (); |
| 609 | |
| 610 | // If a group is non-empty the structure is also non-empty. |
| 611 | if (! Result1) return (Standard_False); |
| 612 | |
| 613 | Standard_Boolean Result2 = Standard_True; |
| 614 | |
| 615 | Length = MyDescendants.Length (); |
| 616 | |
| 617 | // Stop at the first non-empty descendant |
| 618 | for (i=1; i<=Length && Result2; i++) |
| 619 | Result2 = ((Graphic3d_Structure *) |
| 620 | (MyDescendants.Value (i)))->IsEmpty (); |
| 621 | |
| 622 | return (Result2); |
| 623 | |
| 624 | } |
| 625 | |
| 626 | void Graphic3d_Structure::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const { |
| 627 | |
| 628 | CTXL = Line3dAspect (); |
| 629 | CTXT = Text3dAspect (); |
| 630 | CTXM = Marker3dAspect (); |
| 631 | CTXF = FillArea3dAspect (); |
| 632 | |
| 633 | } |
| 634 | |
| 635 | void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer ADelta) { |
| 636 | |
| 637 | MyCStructure.ContainsFacet = MyCStructure.ContainsFacet + ADelta; |
| 638 | if (MyCStructure.ContainsFacet < 0) MyCStructure.ContainsFacet = 0; |
| 639 | |
| 640 | #ifdef DEBUG |
| 641 | cout << "MyCStructure.ContainsFacet " << MyCStructure.ContainsFacet; |
| 642 | cout << endl << flush; |
| 643 | #endif |
| 644 | |
| 645 | } |
| 646 | |
| 647 | void Graphic3d_Structure::Compute() |
| 648 | { |
| 649 | // Implemented by Presentation |
| 650 | } |
| 651 | |
| 652 | Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ) { |
| 653 | |
| 654 | // Implemented by Presentation |
| 655 | return this; |
| 656 | } |
| 657 | |
| 658 | Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , const TColStd_Array2OfReal& ) { |
| 659 | |
| 660 | // Implemented by Presentation |
| 661 | return this; |
| 662 | } |
| 663 | |
| 664 | void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , Handle(Graphic3d_Structure)& ) { |
| 665 | |
| 666 | // Implemented by Presentation |
| 667 | } |
| 668 | |
| 669 | void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , const TColStd_Array2OfReal& , Handle(Graphic3d_Structure)& ) { |
| 670 | |
| 671 | // Implemented by Presentation |
| 672 | } |
| 673 | |
| 674 | void Graphic3d_Structure::ReCompute () { |
| 675 | |
| 676 | MyStructureManager->ReCompute (this); |
| 677 | |
| 678 | } |
| 679 | |
| 680 | void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& aProjector) { |
| 681 | |
| 682 | MyStructureManager->ReCompute (this, aProjector); |
| 683 | |
| 684 | } |
| 685 | |
| 686 | void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean AValue) { |
| 687 | |
| 688 | MyCStructure.IsInfinite = AValue ? 1:0; |
| 689 | |
| 690 | } |
| 691 | |
| 692 | Standard_Boolean Graphic3d_Structure::IsInfinite () const { |
| 693 | |
| 694 | if (IsDeleted ()) return (Standard_True); |
| 695 | |
| 696 | if (MyCStructure.IsInfinite) |
| 697 | return (Standard_True); |
| 698 | else |
| 699 | return (Standard_False); |
| 700 | |
| 701 | } |
| 702 | |
| 703 | void Graphic3d_Structure::GraphicClear (const Standard_Boolean WithDestruction) |
| 704 | { |
| 705 | // clean and empty each group |
| 706 | Standard_Integer Length = MyGroups.Length(); |
| 707 | for (Standard_Integer aGrId = 1; aGrId <= Length; ++aGrId) |
| 708 | { |
| 709 | MyGroups.ChangeValue (aGrId)->Clear(); |
| 710 | } |
| 711 | |
| 712 | if (WithDestruction) |
| 713 | { |
| 714 | while (!MyGroups.IsEmpty()) |
| 715 | { |
| 716 | Handle(Graphic3d_Group) aGroup = MyGroups.First(); |
| 717 | aGroup->Remove(); |
| 718 | } |
| 719 | |
| 720 | MyGraphicDriver->ClearStructure (MyCStructure); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter) |
| 725 | { |
| 726 | MyGraphicDriver->Connect (MyCStructure, theDaughter->MyCStructure); |
| 727 | } |
| 728 | |
| 729 | void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter) |
| 730 | { |
| 731 | MyGraphicDriver->Disconnect (MyCStructure, theDaughter->MyCStructure); |
| 732 | } |
| 733 | |
| 734 | Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect () const { |
| 735 | |
| 736 | Standard_Real R, G, B; |
| 737 | Standard_Real AWidth; |
| 738 | Quantity_Color AColor; |
| 739 | Aspect_TypeOfLine ALType; |
| 740 | |
| 741 | // ContextLine |
| 742 | R = Standard_Real (MyCStructure.ContextLine.Color.r); |
| 743 | G = Standard_Real (MyCStructure.ContextLine.Color.g); |
| 744 | B = Standard_Real (MyCStructure.ContextLine.Color.b); |
| 745 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 746 | ALType = Aspect_TypeOfLine (MyCStructure.ContextLine.LineType); |
| 747 | AWidth = Standard_Real (MyCStructure.ContextLine.Width); |
| 748 | |
| 749 | Handle(Graphic3d_AspectLine3d) CTXL = new Graphic3d_AspectLine3d (AColor, ALType, AWidth); |
| 750 | CTXL->SetShaderProgram (MyCStructure.ContextLine.ShaderProgram); |
| 751 | |
| 752 | return CTXL; |
| 753 | |
| 754 | } |
| 755 | |
| 756 | Handle(Graphic3d_AspectText3d) Graphic3d_Structure::Text3dAspect () const { |
| 757 | |
| 758 | Standard_Real R, G, B; |
| 759 | Standard_CString AFont; |
| 760 | Standard_Real ASpace; |
| 761 | Standard_Real AnExpansion; |
| 762 | Quantity_Color AColor; |
| 763 | Aspect_TypeOfStyleText AStyle; |
| 764 | Aspect_TypeOfDisplayText ADisplayType; |
| 765 | |
| 766 | // ContextText |
| 767 | R = Standard_Real (MyCStructure.ContextText.Color.r); |
| 768 | G = Standard_Real (MyCStructure.ContextText.Color.g); |
| 769 | B = Standard_Real (MyCStructure.ContextText.Color.b); |
| 770 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 771 | AFont = Standard_CString (MyCStructure.ContextText.Font); |
| 772 | AnExpansion = Standard_Real (MyCStructure.ContextText.Expan); |
| 773 | ASpace = Standard_Real (MyCStructure.ContextText.Space); |
| 774 | AStyle = Aspect_TypeOfStyleText (MyCStructure.ContextText.Style); |
| 775 | ADisplayType = Aspect_TypeOfDisplayText (MyCStructure.ContextText.DisplayType); |
| 776 | |
| 777 | Handle(Graphic3d_AspectText3d) CTXT = new Graphic3d_AspectText3d (AColor, AFont, AnExpansion, ASpace,AStyle,ADisplayType); |
| 778 | CTXT->SetShaderProgram (MyCStructure.ContextText.ShaderProgram); |
| 779 | |
| 780 | return CTXT; |
| 781 | |
| 782 | } |
| 783 | |
| 784 | Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect () const { |
| 785 | |
| 786 | Standard_Real R, G, B; |
| 787 | Standard_Real AScale; |
| 788 | Quantity_Color AColor; |
| 789 | Aspect_TypeOfMarker AMType; |
| 790 | |
| 791 | // ContextMarker |
| 792 | R = Standard_Real (MyCStructure.ContextMarker.Color.r); |
| 793 | G = Standard_Real (MyCStructure.ContextMarker.Color.g); |
| 794 | B = Standard_Real (MyCStructure.ContextMarker.Color.b); |
| 795 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 796 | AMType = MyCStructure.ContextMarker.MarkerType; |
| 797 | AScale = Standard_Real (MyCStructure.ContextMarker.Scale); |
| 798 | |
| 799 | Handle(Graphic3d_AspectMarker3d) CTXM = new Graphic3d_AspectMarker3d (AMType, AColor, AScale); |
| 800 | CTXM->SetShaderProgram (MyCStructure.ContextMarker.ShaderProgram); |
| 801 | |
| 802 | return CTXM; |
| 803 | |
| 804 | } |
| 805 | |
| 806 | Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect () const { |
| 807 | |
| 808 | Standard_Real R, G, B; |
| 809 | Standard_Real AWidth; |
| 810 | Quantity_Color AColor; |
| 811 | Quantity_Color AnIntColor; |
| 812 | Quantity_Color AnEdgeColor; |
| 813 | Aspect_TypeOfLine ALType; |
| 814 | Aspect_InteriorStyle AStyle; |
| 815 | Standard_Boolean EdgeOn = Standard_False; |
| 816 | Graphic3d_MaterialAspect Front; |
| 817 | Graphic3d_MaterialAspect Back; |
| 818 | |
| 819 | // ContextFillArea |
| 820 | AStyle = Aspect_InteriorStyle (MyCStructure.ContextFillArea.Style); |
| 821 | R = Standard_Real (MyCStructure.ContextFillArea.IntColor.r); |
| 822 | G = Standard_Real (MyCStructure.ContextFillArea.IntColor.g); |
| 823 | B = Standard_Real (MyCStructure.ContextFillArea.IntColor.b); |
| 824 | AnIntColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 825 | // Edges |
| 826 | if (MyCStructure.ContextFillArea.Edge == 1) EdgeOn = Standard_True; |
| 827 | R = Standard_Real (MyCStructure.ContextFillArea.EdgeColor.r); |
| 828 | G = Standard_Real (MyCStructure.ContextFillArea.EdgeColor.g); |
| 829 | B = Standard_Real (MyCStructure.ContextFillArea.EdgeColor.b); |
| 830 | AnEdgeColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 831 | ALType = Aspect_TypeOfLine (MyCStructure.ContextFillArea.LineType); |
| 832 | AWidth = Standard_Real (MyCStructure.ContextFillArea.Width); |
| 833 | // Back Material |
| 834 | Back.SetShininess ( |
| 835 | Standard_Real (MyCStructure.ContextFillArea.Back.Shininess)); |
| 836 | Back.SetAmbient ( |
| 837 | Standard_Real (MyCStructure.ContextFillArea.Back.Ambient)); |
| 838 | Back.SetDiffuse ( |
| 839 | Standard_Real (MyCStructure.ContextFillArea.Back.Diffuse)); |
| 840 | Back.SetSpecular ( |
| 841 | Standard_Real (MyCStructure.ContextFillArea.Back.Specular)); |
| 842 | Back.SetTransparency ( |
| 843 | Standard_Real (MyCStructure.ContextFillArea.Back.Transparency)); |
| 844 | Back.SetEmissive ( |
| 845 | Standard_Real (MyCStructure.ContextFillArea.Back.Emission)); |
| 846 | if (MyCStructure.ContextFillArea.Back.IsAmbient == 1) |
| 847 | Back.SetReflectionModeOn (Graphic3d_TOR_AMBIENT); |
| 848 | else |
| 849 | Back.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); |
| 850 | if (MyCStructure.ContextFillArea.Back.IsDiffuse == 1) |
| 851 | Back.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE); |
| 852 | else |
| 853 | Back.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); |
| 854 | if (MyCStructure.ContextFillArea.Back.IsSpecular == 1) |
| 855 | Back.SetReflectionModeOn (Graphic3d_TOR_SPECULAR); |
| 856 | else |
| 857 | Back.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); |
| 858 | if (MyCStructure.ContextFillArea.Back.IsEmission == 1) |
| 859 | Back.SetReflectionModeOn (Graphic3d_TOR_EMISSION); |
| 860 | else |
| 861 | Back.SetReflectionModeOff (Graphic3d_TOR_EMISSION); |
| 862 | |
| 863 | R = Standard_Real (MyCStructure.ContextFillArea.Back.ColorSpec.r); |
| 864 | G = Standard_Real (MyCStructure.ContextFillArea.Back.ColorSpec.g); |
| 865 | B = Standard_Real (MyCStructure.ContextFillArea.Back.ColorSpec.b); |
| 866 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 867 | Back.SetSpecularColor (AColor); |
| 868 | |
| 869 | R = Standard_Real (MyCStructure.ContextFillArea.Back.ColorAmb.r); |
| 870 | G = Standard_Real (MyCStructure.ContextFillArea.Back.ColorAmb.g); |
| 871 | B = Standard_Real (MyCStructure.ContextFillArea.Back.ColorAmb.b); |
| 872 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 873 | Back.SetAmbientColor (AColor); |
| 874 | |
| 875 | R = Standard_Real (MyCStructure.ContextFillArea.Back.ColorDif.r); |
| 876 | G = Standard_Real (MyCStructure.ContextFillArea.Back.ColorDif.g); |
| 877 | B = Standard_Real (MyCStructure.ContextFillArea.Back.ColorDif.b); |
| 878 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 879 | Back.SetDiffuseColor (AColor); |
| 880 | |
| 881 | R = Standard_Real (MyCStructure.ContextFillArea.Back.ColorEms.r); |
| 882 | G = Standard_Real (MyCStructure.ContextFillArea.Back.ColorEms.g); |
| 883 | B = Standard_Real (MyCStructure.ContextFillArea.Back.ColorEms.b); |
| 884 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 885 | Back.SetEmissiveColor (AColor); |
| 886 | |
| 887 | Back.SetEnvReflexion (MyCStructure.ContextFillArea.Back.EnvReflexion); |
| 888 | |
| 889 | Graphic3d_TypeOfMaterial mType = |
| 890 | MyCStructure.ContextFillArea.Back.IsPhysic ? |
| 891 | Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT; |
| 892 | Back.SetMaterialType(mType); |
| 893 | |
| 894 | // Front Material |
| 895 | Front.SetShininess ( |
| 896 | Standard_Real (MyCStructure.ContextFillArea.Front.Shininess)); |
| 897 | Front.SetAmbient ( |
| 898 | Standard_Real (MyCStructure.ContextFillArea.Front.Ambient)); |
| 899 | Front.SetDiffuse ( |
| 900 | Standard_Real (MyCStructure.ContextFillArea.Front.Diffuse)); |
| 901 | Front.SetSpecular ( |
| 902 | Standard_Real (MyCStructure.ContextFillArea.Front.Specular)); |
| 903 | Front.SetTransparency ( |
| 904 | Standard_Real (MyCStructure.ContextFillArea.Front.Transparency)); |
| 905 | Front.SetEmissive ( |
| 906 | Standard_Real (MyCStructure.ContextFillArea.Front.Emission)); |
| 907 | if (MyCStructure.ContextFillArea.Front.IsAmbient == 1) |
| 908 | Front.SetReflectionModeOn (Graphic3d_TOR_AMBIENT); |
| 909 | else |
| 910 | Front.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); |
| 911 | if (MyCStructure.ContextFillArea.Front.IsDiffuse == 1) |
| 912 | Front.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE); |
| 913 | else |
| 914 | Front.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); |
| 915 | if (MyCStructure.ContextFillArea.Front.IsSpecular == 1) |
| 916 | Front.SetReflectionModeOn (Graphic3d_TOR_SPECULAR); |
| 917 | else |
| 918 | Front.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); |
| 919 | if (MyCStructure.ContextFillArea.Front.Emission == 1) |
| 920 | Front.SetReflectionModeOn (Graphic3d_TOR_EMISSION); |
| 921 | else |
| 922 | Front.SetReflectionModeOff (Graphic3d_TOR_EMISSION); |
| 923 | |
| 924 | R = Standard_Real (MyCStructure.ContextFillArea.Front.ColorSpec.r); |
| 925 | G = Standard_Real (MyCStructure.ContextFillArea.Front.ColorSpec.g); |
| 926 | B = Standard_Real (MyCStructure.ContextFillArea.Front.ColorSpec.b); |
| 927 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 928 | Front.SetSpecularColor (AColor); |
| 929 | |
| 930 | R = Standard_Real (MyCStructure.ContextFillArea.Front.ColorAmb.r); |
| 931 | G = Standard_Real (MyCStructure.ContextFillArea.Front.ColorAmb.g); |
| 932 | B = Standard_Real (MyCStructure.ContextFillArea.Front.ColorAmb.b); |
| 933 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 934 | Front.SetAmbientColor (AColor); |
| 935 | |
| 936 | R = Standard_Real (MyCStructure.ContextFillArea.Front.ColorDif.r); |
| 937 | G = Standard_Real (MyCStructure.ContextFillArea.Front.ColorDif.g); |
| 938 | B = Standard_Real (MyCStructure.ContextFillArea.Front.ColorDif.b); |
| 939 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 940 | Front.SetDiffuseColor (AColor); |
| 941 | |
| 942 | R = Standard_Real (MyCStructure.ContextFillArea.Front.ColorEms.r); |
| 943 | G = Standard_Real (MyCStructure.ContextFillArea.Front.ColorEms.g); |
| 944 | B = Standard_Real (MyCStructure.ContextFillArea.Front.ColorEms.b); |
| 945 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); |
| 946 | Front.SetEmissiveColor (AColor); |
| 947 | |
| 948 | Front.SetEnvReflexion (MyCStructure.ContextFillArea.Front.EnvReflexion); |
| 949 | |
| 950 | mType = MyCStructure.ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT; |
| 951 | Front.SetMaterialType(mType); |
| 952 | |
| 953 | Handle(Graphic3d_AspectFillArea3d) CTXF = |
| 954 | new Graphic3d_AspectFillArea3d (AStyle, AnIntColor, AnEdgeColor, ALType, AWidth, Front, Back); |
| 955 | |
| 956 | // Edges |
| 957 | if (EdgeOn) |
| 958 | CTXF->SetEdgeOn (); |
| 959 | else |
| 960 | CTXF->SetEdgeOff (); |
| 961 | // Hatch |
| 962 | CTXF->SetHatchStyle(Aspect_HatchStyle (MyCStructure.ContextFillArea.Hatch)); |
| 963 | // Materials |
| 964 | // Front and Back face |
| 965 | if (MyCStructure.ContextFillArea.Distinguish == 1) |
| 966 | CTXF->SetDistinguishOn (); |
| 967 | else |
| 968 | CTXF->SetDistinguishOff (); |
| 969 | if (MyCStructure.ContextFillArea.BackFace == 1) |
| 970 | CTXF->SuppressBackFace (); |
| 971 | else |
| 972 | CTXF->AllowBackFace (); |
| 973 | // Texture |
| 974 | CTXF->SetTextureMap (MyCStructure.ContextFillArea.Texture.TextureMap); |
| 975 | if (MyCStructure.ContextFillArea.Texture.doTextureMap == 1) |
| 976 | { |
| 977 | CTXF->SetTextureMapOn(); |
| 978 | } |
| 979 | else |
| 980 | { |
| 981 | CTXF->SetTextureMapOff(); |
| 982 | } |
| 983 | CTXF->SetShaderProgram (MyCStructure.ContextFillArea.ShaderProgram); |
| 984 | |
| 985 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 986 | CTXF->SetPolygonOffsets(MyCStructure.ContextFillArea.PolygonOffsetMode, |
| 987 | MyCStructure.ContextFillArea.PolygonOffsetFactor, |
| 988 | MyCStructure.ContextFillArea.PolygonOffsetUnits); |
| 989 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 990 | |
| 991 | return CTXF; |
| 992 | |
| 993 | } |
| 994 | |
| 995 | const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const { |
| 996 | return MyGroups; |
| 997 | } |
| 998 | |
| 999 | Standard_Integer Graphic3d_Structure::NumberOfGroups () const { |
| 1000 | return (MyGroups.Length ()); |
| 1001 | } |
| 1002 | |
| 1003 | void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) { |
| 1004 | |
| 1005 | if (IsDeleted ()) return; |
| 1006 | |
| 1007 | Standard_Real R, G, B; |
| 1008 | Standard_Real AWidth; |
| 1009 | Quantity_Color AColor; |
| 1010 | Aspect_TypeOfLine ALType; |
| 1011 | |
| 1012 | CTX->Values (AColor, ALType, AWidth); |
| 1013 | AColor.Values (R, G, B, Quantity_TOC_RGB); |
| 1014 | |
| 1015 | MyCStructure.ContextLine.Color.r = float (R); |
| 1016 | MyCStructure.ContextLine.Color.g = float (G); |
| 1017 | MyCStructure.ContextLine.Color.b = float (B); |
| 1018 | MyCStructure.ContextLine.LineType = int (ALType); |
| 1019 | MyCStructure.ContextLine.Width = float (AWidth); |
| 1020 | MyCStructure.ContextLine.ShaderProgram = CTX->ShaderProgram(); |
| 1021 | MyCStructure.ContextLine.IsDef = 1; |
| 1022 | |
| 1023 | MyGraphicDriver->ContextStructure (MyCStructure); |
| 1024 | |
| 1025 | // CAL 14/04/95 |
| 1026 | // Attributes are "IsSet" during the first update |
| 1027 | // of context (line, marker...) |
| 1028 | MyCStructure.ContextLine.IsSet = 1; |
| 1029 | MyCStructure.ContextFillArea.IsSet = 1; |
| 1030 | MyCStructure.ContextMarker.IsSet = 1; |
| 1031 | MyCStructure.ContextText.IsSet = 1; |
| 1032 | |
| 1033 | Update (); |
| 1034 | |
| 1035 | } |
| 1036 | |
| 1037 | void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) { |
| 1038 | |
| 1039 | if (IsDeleted ()) return; |
| 1040 | |
| 1041 | Standard_Real R, G, B; |
| 1042 | Standard_Real AWidth; |
| 1043 | Quantity_Color AnIntColor; |
| 1044 | Quantity_Color BackIntColor; |
| 1045 | Quantity_Color AnEdgeColor; |
| 1046 | Aspect_TypeOfLine ALType; |
| 1047 | Aspect_InteriorStyle AStyle; |
| 1048 | |
| 1049 | CTX->Values (AStyle, AnIntColor, BackIntColor, AnEdgeColor, ALType, AWidth); |
| 1050 | AnIntColor.Values (R, G, B, Quantity_TOC_RGB); |
| 1051 | |
| 1052 | MyCStructure.ContextFillArea.Style = int (AStyle); |
| 1053 | MyCStructure.ContextFillArea.IntColor.r = float (R); |
| 1054 | MyCStructure.ContextFillArea.IntColor.g = float (G); |
| 1055 | MyCStructure.ContextFillArea.IntColor.b = float (B); |
| 1056 | |
| 1057 | #ifdef OCC1174 |
| 1058 | if ( CTX->Distinguish() ) |
| 1059 | BackIntColor.Values( R, G, B, Quantity_TOC_RGB ); |
| 1060 | #endif |
| 1061 | MyCStructure.ContextFillArea.BackIntColor.r = float( R ); |
| 1062 | MyCStructure.ContextFillArea.BackIntColor.g = float( G ); |
| 1063 | MyCStructure.ContextFillArea.BackIntColor.b = float( B ); |
| 1064 | |
| 1065 | |
| 1066 | // Edges |
| 1067 | MyCStructure.ContextFillArea.Edge = CTX->Edge () ? 1:0; |
| 1068 | AnEdgeColor.Values (R, G, B, Quantity_TOC_RGB); |
| 1069 | MyCStructure.ContextFillArea.EdgeColor.r = float (R); |
| 1070 | MyCStructure.ContextFillArea.EdgeColor.g = float (G); |
| 1071 | MyCStructure.ContextFillArea.EdgeColor.b = float (B); |
| 1072 | MyCStructure.ContextFillArea.LineType = int (ALType); |
| 1073 | MyCStructure.ContextFillArea.Width = float (AWidth); |
| 1074 | MyCStructure.ContextFillArea.Hatch = int (CTX->HatchStyle ()); |
| 1075 | |
| 1076 | /*** Front and Back face ***/ |
| 1077 | MyCStructure.ContextFillArea.Distinguish = CTX->Distinguish () ? 1:0; |
| 1078 | MyCStructure.ContextFillArea.BackFace = CTX->BackFace () ? 1:0; |
| 1079 | |
| 1080 | /*** Back Material ***/ |
| 1081 | // Light specificity |
| 1082 | MyCStructure.ContextFillArea.Back.Shininess = |
| 1083 | float ((CTX->BackMaterial ()).Shininess ()); |
| 1084 | MyCStructure.ContextFillArea.Back.Ambient = |
| 1085 | float ((CTX->BackMaterial ()).Ambient ()); |
| 1086 | MyCStructure.ContextFillArea.Back.Diffuse = |
| 1087 | float ((CTX->BackMaterial ()).Diffuse ()); |
| 1088 | MyCStructure.ContextFillArea.Back.Specular = |
| 1089 | float ((CTX->BackMaterial ()).Specular ()); |
| 1090 | MyCStructure.ContextFillArea.Back.Transparency = |
| 1091 | float ((CTX->BackMaterial ()).Transparency ()); |
| 1092 | MyCStructure.ContextFillArea.Back.Emission = |
| 1093 | float ((CTX->BackMaterial ()).Emissive ()); |
| 1094 | |
| 1095 | // Reflection mode |
| 1096 | MyCStructure.ContextFillArea.Back.IsAmbient = |
| 1097 | ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); |
| 1098 | MyCStructure.ContextFillArea.Back.IsDiffuse = |
| 1099 | ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); |
| 1100 | MyCStructure.ContextFillArea.Back.IsSpecular = |
| 1101 | ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); |
| 1102 | MyCStructure.ContextFillArea.Back.IsEmission = |
| 1103 | ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); |
| 1104 | |
| 1105 | // Material type |
| 1106 | //JR/Hp |
| 1107 | const Graphic3d_MaterialAspect ama = CTX->BackMaterial () ; |
| 1108 | Standard_Boolean amt = ama.MaterialType(Graphic3d_MATERIAL_PHYSIC) ; |
| 1109 | MyCStructure.ContextFillArea.Back.IsPhysic = ( amt ? 1 : 0 ); |
| 1110 | |
| 1111 | // Specular Color |
| 1112 | MyCStructure.ContextFillArea.Back.ColorSpec.r = |
| 1113 | float (((CTX->BackMaterial ()).SpecularColor ()).Red ()); |
| 1114 | MyCStructure.ContextFillArea.Back.ColorSpec.g = |
| 1115 | float (((CTX->BackMaterial ()).SpecularColor ()).Green ()); |
| 1116 | MyCStructure.ContextFillArea.Back.ColorSpec.b = |
| 1117 | float (((CTX->BackMaterial ()).SpecularColor ()).Blue ()); |
| 1118 | |
| 1119 | // Ambient color |
| 1120 | MyCStructure.ContextFillArea.Back.ColorAmb.r = |
| 1121 | float (((CTX->BackMaterial ()).AmbientColor ()).Red ()); |
| 1122 | MyCStructure.ContextFillArea.Back.ColorAmb.g = |
| 1123 | float (((CTX->BackMaterial ()).AmbientColor ()).Green ()); |
| 1124 | MyCStructure.ContextFillArea.Back.ColorAmb.b = |
| 1125 | float (((CTX->BackMaterial ()).AmbientColor ()).Blue ()); |
| 1126 | |
| 1127 | // Diffuse color |
| 1128 | MyCStructure.ContextFillArea.Back.ColorDif.r = |
| 1129 | float (((CTX->BackMaterial ()).DiffuseColor ()).Red ()); |
| 1130 | MyCStructure.ContextFillArea.Back.ColorDif.g = |
| 1131 | float (((CTX->BackMaterial ()).DiffuseColor ()).Green ()); |
| 1132 | MyCStructure.ContextFillArea.Back.ColorDif.b = |
| 1133 | float (((CTX->BackMaterial ()).DiffuseColor ()).Blue ()); |
| 1134 | |
| 1135 | // Emissive color |
| 1136 | MyCStructure.ContextFillArea.Back.ColorEms.r = |
| 1137 | float (((CTX->BackMaterial ()).EmissiveColor ()).Red ()); |
| 1138 | MyCStructure.ContextFillArea.Back.ColorEms.g = |
| 1139 | float (((CTX->BackMaterial ()).EmissiveColor ()).Green ()); |
| 1140 | MyCStructure.ContextFillArea.Back.ColorEms.b = |
| 1141 | float (((CTX->BackMaterial ()).EmissiveColor ()).Blue ()); |
| 1142 | |
| 1143 | MyCStructure.ContextFillArea.Back.EnvReflexion = |
| 1144 | float ((CTX->BackMaterial ()).EnvReflexion()); |
| 1145 | |
| 1146 | /*** Front Material ***/ |
| 1147 | // Light specificity |
| 1148 | MyCStructure.ContextFillArea.Front.Shininess = |
| 1149 | float ((CTX->FrontMaterial ()).Shininess ()); |
| 1150 | MyCStructure.ContextFillArea.Front.Ambient = |
| 1151 | float ((CTX->FrontMaterial ()).Ambient ()); |
| 1152 | MyCStructure.ContextFillArea.Front.Diffuse = |
| 1153 | float ((CTX->FrontMaterial ()).Diffuse ()); |
| 1154 | MyCStructure.ContextFillArea.Front.Specular = |
| 1155 | float ((CTX->FrontMaterial ()).Specular ()); |
| 1156 | MyCStructure.ContextFillArea.Front.Transparency = |
| 1157 | float ((CTX->FrontMaterial ()).Transparency ()); |
| 1158 | MyCStructure.ContextFillArea.Front.Emission = |
| 1159 | float ((CTX->FrontMaterial ()).Emissive ()); |
| 1160 | |
| 1161 | // Reflection mode |
| 1162 | MyCStructure.ContextFillArea.Front.IsAmbient = |
| 1163 | ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); |
| 1164 | MyCStructure.ContextFillArea.Front.IsDiffuse = |
| 1165 | ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); |
| 1166 | MyCStructure.ContextFillArea.Front.IsSpecular = |
| 1167 | ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); |
| 1168 | MyCStructure.ContextFillArea.Front.IsEmission = |
| 1169 | ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); |
| 1170 | |
| 1171 | // Materail type |
| 1172 | //JR/Hp |
| 1173 | const Graphic3d_MaterialAspect amas = CTX->FrontMaterial () ; |
| 1174 | Standard_Boolean amty = amas.MaterialType(Graphic3d_MATERIAL_PHYSIC) ; |
| 1175 | MyCStructure.ContextFillArea.Front.IsPhysic = ( amty ? 1 : 0 ); |
| 1176 | |
| 1177 | // Specular Color |
| 1178 | MyCStructure.ContextFillArea.Front.ColorSpec.r = |
| 1179 | float (((CTX->FrontMaterial ()).SpecularColor ()).Red ()); |
| 1180 | MyCStructure.ContextFillArea.Front.ColorSpec.g = |
| 1181 | float (((CTX->FrontMaterial ()).SpecularColor ()).Green ()); |
| 1182 | MyCStructure.ContextFillArea.Front.ColorSpec.b = |
| 1183 | float (((CTX->FrontMaterial ()).SpecularColor ()).Blue ()); |
| 1184 | |
| 1185 | // Ambient color |
| 1186 | MyCStructure.ContextFillArea.Front.ColorAmb.r = |
| 1187 | float (((CTX->FrontMaterial ()).AmbientColor ()).Red ()); |
| 1188 | MyCStructure.ContextFillArea.Front.ColorAmb.g = |
| 1189 | float (((CTX->FrontMaterial ()).AmbientColor ()).Green ()); |
| 1190 | MyCStructure.ContextFillArea.Front.ColorAmb.b = |
| 1191 | float (((CTX->FrontMaterial ()).AmbientColor ()).Blue ()); |
| 1192 | |
| 1193 | // Diffuse color |
| 1194 | MyCStructure.ContextFillArea.Front.ColorDif.r = |
| 1195 | float (((CTX->FrontMaterial ()).DiffuseColor ()).Red ()); |
| 1196 | MyCStructure.ContextFillArea.Front.ColorDif.g = |
| 1197 | float (((CTX->FrontMaterial ()).DiffuseColor ()).Green ()); |
| 1198 | MyCStructure.ContextFillArea.Front.ColorDif.b = |
| 1199 | float (((CTX->FrontMaterial ()).DiffuseColor ()).Blue ()); |
| 1200 | |
| 1201 | // Emissive color |
| 1202 | MyCStructure.ContextFillArea.Front.ColorEms.r = |
| 1203 | float (((CTX->FrontMaterial ()).EmissiveColor ()).Red ()); |
| 1204 | MyCStructure.ContextFillArea.Front.ColorEms.g = |
| 1205 | float (((CTX->FrontMaterial ()).EmissiveColor ()).Green ()); |
| 1206 | MyCStructure.ContextFillArea.Front.ColorEms.b = |
| 1207 | float (((CTX->FrontMaterial ()).EmissiveColor ()).Blue ()); |
| 1208 | |
| 1209 | MyCStructure.ContextFillArea.Front.EnvReflexion = |
| 1210 | float ((CTX->FrontMaterial ()).EnvReflexion()); |
| 1211 | |
| 1212 | MyCStructure.ContextFillArea.IsDef = 1; // Definition material ok |
| 1213 | |
| 1214 | MyCStructure.ContextFillArea.Texture.TextureMap = CTX->TextureMap(); |
| 1215 | MyCStructure.ContextFillArea.Texture.doTextureMap = CTX->TextureMapState() ? 1 : 0; |
| 1216 | MyCStructure.ContextFillArea.ShaderProgram = CTX->ShaderProgram(); |
| 1217 | |
| 1218 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 1219 | Standard_Integer aPolyMode; |
| 1220 | Standard_ShortReal aPolyFactor, aPolyUnits; |
| 1221 | CTX->PolygonOffsets(aPolyMode, aPolyFactor, aPolyUnits); |
| 1222 | MyCStructure.ContextFillArea.PolygonOffsetMode = aPolyMode; |
| 1223 | MyCStructure.ContextFillArea.PolygonOffsetFactor = (Standard_ShortReal)aPolyFactor; |
| 1224 | MyCStructure.ContextFillArea.PolygonOffsetUnits = (Standard_ShortReal)aPolyUnits; |
| 1225 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 1226 | |
| 1227 | MyGraphicDriver->ContextStructure (MyCStructure); |
| 1228 | |
| 1229 | // CAL 14/04/95 |
| 1230 | // Attributes are "IsSet" during the first update |
| 1231 | // of context (line, marker...) |
| 1232 | MyCStructure.ContextLine.IsSet = 1; |
| 1233 | MyCStructure.ContextFillArea.IsSet = 1; |
| 1234 | MyCStructure.ContextMarker.IsSet = 1; |
| 1235 | MyCStructure.ContextText.IsSet = 1; |
| 1236 | |
| 1237 | Update (); |
| 1238 | |
| 1239 | } |
| 1240 | |
| 1241 | void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) { |
| 1242 | |
| 1243 | if (IsDeleted ()) return; |
| 1244 | |
| 1245 | Standard_Real R, G, B; |
| 1246 | Standard_Real Rs, Gs, Bs; |
| 1247 | Standard_CString AFont; |
| 1248 | Standard_Real ASpace; |
| 1249 | Standard_Real AnExpansion; |
| 1250 | Quantity_Color AColor; |
| 1251 | Aspect_TypeOfStyleText AStyle; |
| 1252 | Aspect_TypeOfDisplayText ADisplayType; |
| 1253 | Quantity_Color AColorSubTitle; |
| 1254 | Standard_Boolean ATextZoomable; |
| 1255 | Standard_Real ATextAngle; |
| 1256 | Font_FontAspect ATextFontAspect; |
| 1257 | |
| 1258 | CTX->Values (AColor, AFont, AnExpansion, ASpace, AStyle, ADisplayType,AColorSubTitle,ATextZoomable,ATextAngle,ATextFontAspect); |
| 1259 | AColor.Values (R, G, B, Quantity_TOC_RGB); |
| 1260 | AColorSubTitle.Values (Rs, Gs, Bs, Quantity_TOC_RGB); |
| 1261 | |
| 1262 | MyCStructure.ContextText.Color.r = float (R); |
| 1263 | MyCStructure.ContextText.Color.g = float (G); |
| 1264 | MyCStructure.ContextText.Color.b = float (B); |
| 1265 | MyCStructure.ContextText.Font = (char*) (AFont); |
| 1266 | MyCStructure.ContextText.Expan = float (AnExpansion); |
| 1267 | MyCStructure.ContextText.Space = float (ASpace); |
| 1268 | MyCStructure.ContextText.Style = int (AStyle); |
| 1269 | MyCStructure.ContextText.DisplayType = int (ADisplayType); |
| 1270 | MyCStructure.ContextText.ColorSubTitle.r = float (Rs); |
| 1271 | MyCStructure.ContextText.ColorSubTitle.g = float (Gs); |
| 1272 | MyCStructure.ContextText.ColorSubTitle.b = float (Bs); |
| 1273 | MyCStructure.ContextText.TextZoomable = ATextZoomable; |
| 1274 | MyCStructure.ContextText.TextAngle = float (ATextAngle); |
| 1275 | MyCStructure.ContextText.TextFontAspect = int (ATextFontAspect); |
| 1276 | MyCStructure.ContextText.ShaderProgram = CTX->ShaderProgram(); |
| 1277 | |
| 1278 | MyCStructure.ContextText.IsDef = 1; |
| 1279 | |
| 1280 | MyGraphicDriver->ContextStructure (MyCStructure); |
| 1281 | |
| 1282 | // CAL 14/04/95 |
| 1283 | // Attributes are "IsSet" during the first update of a context (line, marker...) |
| 1284 | MyCStructure.ContextLine.IsSet = 1; |
| 1285 | MyCStructure.ContextFillArea.IsSet = 1; |
| 1286 | MyCStructure.ContextMarker.IsSet = 1; |
| 1287 | MyCStructure.ContextText.IsSet = 1; |
| 1288 | |
| 1289 | Update (); |
| 1290 | |
| 1291 | } |
| 1292 | |
| 1293 | void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) { |
| 1294 | |
| 1295 | if (IsDeleted ()) return; |
| 1296 | |
| 1297 | Standard_Real R, G, B; |
| 1298 | Standard_Real AScale; |
| 1299 | Quantity_Color AColor; |
| 1300 | Aspect_TypeOfMarker AMType; |
| 1301 | |
| 1302 | CTX->Values (AColor, AMType, AScale); |
| 1303 | AColor.Values (R, G, B, Quantity_TOC_RGB); |
| 1304 | |
| 1305 | MyCStructure.ContextMarker.Color.r = float (R); |
| 1306 | MyCStructure.ContextMarker.Color.g = float (G); |
| 1307 | MyCStructure.ContextMarker.Color.b = float (B); |
| 1308 | MyCStructure.ContextMarker.MarkerType = AMType; |
| 1309 | MyCStructure.ContextMarker.Scale = float (AScale); |
| 1310 | MyCStructure.ContextMarker.ShaderProgram = CTX->ShaderProgram(); |
| 1311 | MyCStructure.ContextMarker.IsDef = 1; |
| 1312 | |
| 1313 | MyGraphicDriver->ContextStructure (MyCStructure); |
| 1314 | |
| 1315 | // Attributes are "IsSet" during the first update of a context (line, marker...) |
| 1316 | MyCStructure.ContextLine.IsSet = 1; |
| 1317 | MyCStructure.ContextFillArea.IsSet = 1; |
| 1318 | MyCStructure.ContextMarker.IsSet = 1; |
| 1319 | MyCStructure.ContextText.IsSet = 1; |
| 1320 | |
| 1321 | Update (); |
| 1322 | |
| 1323 | } |
| 1324 | |
| 1325 | void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure AVisual) { |
| 1326 | |
| 1327 | if (IsDeleted ()) return; |
| 1328 | if (MyVisual == AVisual) return; |
| 1329 | |
| 1330 | if (! MyCStructure.stick) { |
| 1331 | MyVisual = AVisual; |
| 1332 | SetComputeVisual (AVisual); |
| 1333 | } |
| 1334 | else { |
| 1335 | |
| 1336 | Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode (); |
| 1337 | if (UpdateMode == Aspect_TOU_WAIT) { |
| 1338 | Erase (); |
| 1339 | MyVisual = AVisual; |
| 1340 | SetComputeVisual (AVisual); |
| 1341 | Display (); |
| 1342 | } |
| 1343 | else { |
| 1344 | // To avoid calling method : Update () |
| 1345 | // Not useful and can be costly. |
| 1346 | MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT); |
| 1347 | Erase (); |
| 1348 | MyVisual = AVisual; |
| 1349 | SetComputeVisual (AVisual); |
| 1350 | MyStructureManager->SetUpdateMode (UpdateMode); |
| 1351 | Display (); |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | } |
| 1356 | |
| 1357 | void Graphic3d_Structure::SetZoomLimit (const Standard_Real LimitInf, const Standard_Real LimitSup) { |
| 1358 | |
| 1359 | if (LimitInf <= 0.0) |
| 1360 | Graphic3d_StructureDefinitionError::Raise |
| 1361 | ("Bad value for ZoomLimit inf"); |
| 1362 | |
| 1363 | if (LimitSup <= 0.0) |
| 1364 | Graphic3d_StructureDefinitionError::Raise |
| 1365 | ("Bad value for ZoomLimit sup"); |
| 1366 | |
| 1367 | if (LimitSup < LimitInf) |
| 1368 | Graphic3d_StructureDefinitionError::Raise |
| 1369 | ("ZoomLimit sup < ZoomLimit inf"); |
| 1370 | |
| 1371 | } |
| 1372 | |
| 1373 | Graphic3d_TypeOfStructure Graphic3d_Structure::Visual () const { |
| 1374 | |
| 1375 | return (MyVisual); |
| 1376 | |
| 1377 | } |
| 1378 | |
| 1379 | Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& AStructure1, const Handle(Graphic3d_Structure)& AStructure2, const Graphic3d_TypeOfConnection AType) { |
| 1380 | |
| 1381 | Graphic3d_MapOfStructure ASet; |
| 1382 | |
| 1383 | // cycle detection |
| 1384 | Graphic3d_Structure::Network (AStructure2, AType, ASet); |
| 1385 | |
| 1386 | return (! ASet.Contains (AStructure1)); |
| 1387 | |
| 1388 | } |
| 1389 | |
| 1390 | void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure &SG) const { |
| 1391 | |
| 1392 | Standard_Integer i, Length = MyAncestors.Length (); |
| 1393 | |
| 1394 | for (i=1; i<=Length; i++) |
| 1395 | SG.Add ((Graphic3d_Structure *) (MyAncestors.Value (i))); |
| 1396 | |
| 1397 | |
| 1398 | } |
| 1399 | |
| 1400 | void Graphic3d_Structure::SetOwner (const Standard_Address Owner) { |
| 1401 | |
| 1402 | MyOwner = Owner; |
| 1403 | |
| 1404 | } |
| 1405 | |
| 1406 | Standard_Address Graphic3d_Structure::Owner () const { |
| 1407 | |
| 1408 | return MyOwner; |
| 1409 | |
| 1410 | } |
| 1411 | |
| 1412 | void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& SG) const { |
| 1413 | |
| 1414 | Standard_Integer i, Length = MyDescendants.Length (); |
| 1415 | |
| 1416 | for (i=1; i<=Length; i++) |
| 1417 | SG.Add ((Graphic3d_Structure *) (MyDescendants.Value (i))); |
| 1418 | |
| 1419 | } |
| 1420 | |
| 1421 | void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, const Standard_Boolean WithCheck) { |
| 1422 | |
| 1423 | if (IsDeleted ()) return; |
| 1424 | |
| 1425 | if (WithCheck) |
| 1426 | // cycle detection |
| 1427 | if (! Graphic3d_Structure::AcceptConnection |
| 1428 | (this, AStructure, AType)) |
| 1429 | return; |
| 1430 | |
| 1431 | // connection |
| 1432 | Standard_Integer i; |
| 1433 | switch (AType) |
| 1434 | { |
| 1435 | |
| 1436 | case Graphic3d_TOC_DESCENDANT : |
| 1437 | { |
| 1438 | Standard_Integer indexD = 0; |
| 1439 | Standard_Integer LengthD = MyDescendants.Length (); |
| 1440 | for (i=1; i<=LengthD && indexD==0; i++) |
| 1441 | if ((void *) (MyDescendants.Value (i)) == |
| 1442 | (void *) (AStructure.operator->())) indexD = i; |
| 1443 | |
| 1444 | if (indexD == 0) { |
| 1445 | MyDescendants.Append ((void *) AStructure.operator->()); |
| 1446 | AStructure->Connect (this, Graphic3d_TOC_ANCESTOR); |
| 1447 | |
| 1448 | GraphicConnect (AStructure); |
| 1449 | MyStructureManager->Connect (this, AStructure); |
| 1450 | |
| 1451 | Update (); |
| 1452 | } |
| 1453 | } |
| 1454 | break; |
| 1455 | |
| 1456 | case Graphic3d_TOC_ANCESTOR : |
| 1457 | { |
| 1458 | Standard_Integer indexA = 0; |
| 1459 | Standard_Integer LengthA = MyAncestors.Length (); |
| 1460 | for (i=1; i<=LengthA && indexA==0; i++) |
| 1461 | if ((void *) (MyAncestors.Value (i)) == |
| 1462 | (void *) (AStructure.operator->())) indexA = i; |
| 1463 | |
| 1464 | if (indexA == 0) { |
| 1465 | MyAncestors.Append ((void *) AStructure.operator->()); |
| 1466 | AStructure->Connect (this, Graphic3d_TOC_DESCENDANT); |
| 1467 | |
| 1468 | // MyGraphicDriver->Connect is called in case |
| 1469 | // if connection between parent and child |
| 1470 | } |
| 1471 | } |
| 1472 | break; |
| 1473 | } |
| 1474 | |
| 1475 | } |
| 1476 | |
| 1477 | void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& AStructure) { |
| 1478 | |
| 1479 | if (IsDeleted ()) return; |
| 1480 | |
| 1481 | Standard_Integer i; |
| 1482 | |
| 1483 | Standard_Integer indexD = 0; |
| 1484 | Standard_Integer LengthD = MyDescendants.Length (); |
| 1485 | for (i=1; i<=LengthD && indexD==0; i++) |
| 1486 | if ((void *) (MyDescendants.Value (i)) == |
| 1487 | (void *) (AStructure.operator->())) indexD = i; |
| 1488 | |
| 1489 | // Search in the Descendants |
| 1490 | if (indexD != 0) { |
| 1491 | MyDescendants.Remove (indexD); |
| 1492 | AStructure->Disconnect (this); |
| 1493 | |
| 1494 | GraphicDisconnect (AStructure); |
| 1495 | MyStructureManager->Disconnect (this, AStructure); |
| 1496 | |
| 1497 | Update (); |
| 1498 | } |
| 1499 | else { |
| 1500 | Standard_Integer indexA = 0; |
| 1501 | Standard_Integer LengthA = MyAncestors.Length (); |
| 1502 | for (i=1; i<=LengthA && indexA==0; i++) |
| 1503 | if ((void *) (MyAncestors.Value (i)) == |
| 1504 | (void *) (AStructure.operator->())) indexA = i; |
| 1505 | |
| 1506 | // Search in the Ancestors |
| 1507 | if (indexA != 0) { |
| 1508 | MyAncestors.Remove (indexA); |
| 1509 | AStructure->Disconnect (this); |
| 1510 | |
| 1511 | // No call of MyGraphicDriver->Disconnect |
| 1512 | // in case of an ancestor |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | } |
| 1517 | |
| 1518 | void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection AType) { |
| 1519 | |
| 1520 | if (IsDeleted ()) return; |
| 1521 | |
| 1522 | Standard_Integer i, Length; |
| 1523 | |
| 1524 | // disconnection |
| 1525 | switch (AType) |
| 1526 | { |
| 1527 | case Graphic3d_TOC_DESCENDANT : |
| 1528 | Length = MyDescendants.Length (); |
| 1529 | for (i=1; i<=Length; i++) |
| 1530 | // Value (1) instead of Value (i) as MyDescendants |
| 1531 | // is modified by : |
| 1532 | // Graphic3d_Structure::Disconnect (AStructure) |
| 1533 | // that takes AStructure from MyDescendants |
| 1534 | ((Graphic3d_Structure *) |
| 1535 | (MyDescendants.Value (1)))->Disconnect (this); |
| 1536 | break; |
| 1537 | case Graphic3d_TOC_ANCESTOR : |
| 1538 | Length = MyAncestors.Length (); |
| 1539 | for (i=1; i<=Length; i++) |
| 1540 | // Value (1) instead of Value (i) as MyAncestors |
| 1541 | // is modified by : |
| 1542 | // Graphic3d_Structure::Disconnect (AStructure) |
| 1543 | // that takes AStructure from MyAncestors |
| 1544 | ((Graphic3d_Structure *) |
| 1545 | (MyAncestors.Value (1)))->Disconnect (this); |
| 1546 | break; |
| 1547 | } |
| 1548 | |
| 1549 | } |
| 1550 | |
| 1551 | Graphic3d_TypeOfComposition Graphic3d_Structure::Composition () const { |
| 1552 | |
| 1553 | if (MyCStructure.Composition) |
| 1554 | return (Graphic3d_TOC_POSTCONCATENATE); |
| 1555 | else |
| 1556 | return (Graphic3d_TOC_REPLACE); |
| 1557 | |
| 1558 | } |
| 1559 | |
| 1560 | void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& AMatrix, const Graphic3d_TypeOfComposition AType) { |
| 1561 | |
| 1562 | if (IsDeleted ()) return; |
| 1563 | |
| 1564 | Standard_Integer lr, ur, lc, uc; |
| 1565 | Standard_Real valuetrsf; |
| 1566 | Standard_Real valueoldtrsf; |
| 1567 | Standard_Real valuenewtrsf; |
| 1568 | Standard_Integer i, j, k; |
| 1569 | TColStd_Array2OfReal TheTrsf (0, 3, 0, 3); |
| 1570 | TColStd_Array2OfReal NewTrsf (0, 3, 0, 3); |
| 1571 | TColStd_Array2OfReal AMatrix44 (0, 3, 0, 3); |
| 1572 | |
| 1573 | // Assign the new transformation in an array [0..3][0..3] |
| 1574 | // Avoid problemes if the user has defined matrice [1..4][1..4] |
| 1575 | // or [3..6][-1..2] !! |
| 1576 | lr = AMatrix.LowerRow (); |
| 1577 | ur = AMatrix.UpperRow (); |
| 1578 | lc = AMatrix.LowerCol (); |
| 1579 | uc = AMatrix.UpperCol (); |
| 1580 | |
| 1581 | if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) |
| 1582 | Graphic3d_TransformError::Raise |
| 1583 | ("Transform : not a 4x4 matrix"); |
| 1584 | |
| 1585 | if (AType == Graphic3d_TOC_REPLACE) { |
| 1586 | MyCStructure.Composition = 0; |
| 1587 | // Update of CStructure |
| 1588 | for (i=0; i<=3; i++) |
| 1589 | for (j=0; j<=3; j++) { |
| 1590 | MyCStructure.Transformation[i][j] = |
| 1591 | float (AMatrix (lr + i, lc + j)); |
| 1592 | NewTrsf (i, j) = AMatrix (lr + i, lc + j); |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | if (AType == Graphic3d_TOC_POSTCONCATENATE) { |
| 1597 | MyCStructure.Composition = 1; |
| 1598 | // To simplify management of indices |
| 1599 | for (i=0; i<=3; i++) |
| 1600 | for (j=0; j<=3; j++) |
| 1601 | AMatrix44 (i, j) = AMatrix (lr + i, lc + j); |
| 1602 | // Calculation of the product of matrices |
| 1603 | for (i=0; i<=3; i++) |
| 1604 | for (j=0; j<=3; j++) { |
| 1605 | NewTrsf (i, j) = 0.0; |
| 1606 | for (k=0; k<=3; k++) { |
| 1607 | valueoldtrsf = MyCStructure.Transformation[i][k]; |
| 1608 | valuetrsf = AMatrix44 (k, j); |
| 1609 | valuenewtrsf = NewTrsf (i, j) + |
| 1610 | valueoldtrsf * valuetrsf; |
| 1611 | NewTrsf (i, j) = valuenewtrsf; |
| 1612 | } |
| 1613 | } |
| 1614 | // Update of CStructure |
| 1615 | for (i=0; i<=3; i++) |
| 1616 | for (j=0; j<=3; j++) |
| 1617 | MyCStructure.Transformation[i][j] = float (NewTrsf (i, j)); |
| 1618 | } |
| 1619 | |
| 1620 | // If transformation, no validation of hidden already calculated parts. |
| 1621 | if (IsRotated ()) |
| 1622 | ReCompute (); |
| 1623 | |
| 1624 | GraphicTransform (NewTrsf); |
| 1625 | MyStructureManager->SetTransform (this, NewTrsf); |
| 1626 | |
| 1627 | Update (); |
| 1628 | |
| 1629 | } |
| 1630 | |
| 1631 | void Graphic3d_Structure::Transform (TColStd_Array2OfReal& AMatrix) const { |
| 1632 | |
| 1633 | Standard_Integer lr = AMatrix.LowerRow (); |
| 1634 | Standard_Integer ur = AMatrix.UpperRow (); |
| 1635 | Standard_Integer lc = AMatrix.LowerCol (); |
| 1636 | Standard_Integer uc = AMatrix.UpperCol (); |
| 1637 | |
| 1638 | if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) |
| 1639 | Graphic3d_TransformError::Raise |
| 1640 | ("Transform : not a 4x4 matrix"); |
| 1641 | |
| 1642 | for (Standard_Integer i=0; i<=3; i++) |
| 1643 | for (Standard_Integer j=0; j<=3; j++) |
| 1644 | AMatrix (lr + i, lc + j) = MyCStructure.Transformation[i][j]; |
| 1645 | |
| 1646 | } |
| 1647 | |
| 1648 | void Graphic3d_Structure::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const { |
| 1649 | |
| 1650 | Standard_Real RL = RealLast (); |
| 1651 | Standard_Real RF = RealFirst (); |
| 1652 | |
| 1653 | Standard_Real XTMin, YTMin, ZTMin, XTMax, YTMax, ZTMax, U, V, W; |
| 1654 | |
| 1655 | MinMaxCoord (XTMin, YTMin, ZTMin, XTMax, YTMax, ZTMax); |
| 1656 | if ((XTMin == RF) && (YTMin == RF) && |
| 1657 | (ZTMin == RF) && (XTMax == RL) && |
| 1658 | (YTMax == RL) && (ZTMax == RL)) { |
| 1659 | // Case impossible as it would mean that |
| 1660 | // the structure is empty |
| 1661 | XMin = RF; |
| 1662 | YMin = RF; |
| 1663 | ZMin = RF; |
| 1664 | |
| 1665 | XMax = RL; |
| 1666 | YMax = RL; |
| 1667 | ZMax = RL; |
| 1668 | } |
| 1669 | else { |
| 1670 | Standard_Integer i, j; |
| 1671 | TColStd_Array2OfReal TheTrsf (0, 3, 0, 3); |
| 1672 | |
| 1673 | for (i=0; i<=3; i++) |
| 1674 | for (j=0; j<=3; j++) |
| 1675 | TheTrsf (i, j) = MyCStructure.Transformation[i][j]; |
| 1676 | |
| 1677 | Graphic3d_Structure::Transforms |
| 1678 | (TheTrsf, XTMin, YTMin, ZTMin, XMin, YMin, ZMin); |
| 1679 | Graphic3d_Structure::Transforms |
| 1680 | (TheTrsf, XTMax, YTMax, ZTMax, XMax, YMax, ZMax); |
| 1681 | Graphic3d_Structure::Transforms |
| 1682 | (TheTrsf, XTMin, YTMin, ZTMax, U, V, W); |
| 1683 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; |
| 1684 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; |
| 1685 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; |
| 1686 | Graphic3d_Structure::Transforms |
| 1687 | (TheTrsf, XTMax, YTMin, ZTMax, U, V, W); |
| 1688 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; |
| 1689 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; |
| 1690 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; |
| 1691 | Graphic3d_Structure::Transforms |
| 1692 | (TheTrsf, XTMax, YTMin, ZTMin, U, V, W); |
| 1693 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; |
| 1694 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; |
| 1695 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; |
| 1696 | Graphic3d_Structure::Transforms |
| 1697 | (TheTrsf, XTMax, YTMax, ZTMin, U, V, W); |
| 1698 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; |
| 1699 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; |
| 1700 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; |
| 1701 | Graphic3d_Structure::Transforms |
| 1702 | (TheTrsf, XTMin, YTMax, ZTMax, U, V, W); |
| 1703 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; |
| 1704 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; |
| 1705 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; |
| 1706 | Graphic3d_Structure::Transforms |
| 1707 | (TheTrsf, XTMin, YTMax, ZTMin, U, V, W); |
| 1708 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; |
| 1709 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; |
| 1710 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | Standard_Integer Graphic3d_Structure::Identification () const { |
| 1715 | |
| 1716 | Standard_Integer Result = MyCStructure.Id; |
| 1717 | |
| 1718 | return Result; |
| 1719 | |
| 1720 | } |
| 1721 | |
| 1722 | void Graphic3d_Structure::SetTransformPersistence( const Graphic3d_TransModeFlags& AFlag ) |
| 1723 | { |
| 1724 | SetTransformPersistence( AFlag, gp_Pnt( 0, 0, 0 ) ); |
| 1725 | } |
| 1726 | |
| 1727 | void Graphic3d_Structure::SetTransformPersistence( const Graphic3d_TransModeFlags& AFlag, |
| 1728 | const gp_Pnt& APoint ) |
| 1729 | { |
| 1730 | if (IsDeleted ()) return; |
| 1731 | |
| 1732 | MyCStructure.TransformPersistence.Flag = AFlag; |
| 1733 | MyCStructure.TransformPersistence.Point.x = float (APoint.X()); |
| 1734 | MyCStructure.TransformPersistence.Point.y = float (APoint.Y()); |
| 1735 | MyCStructure.TransformPersistence.Point.z = float (APoint.Z()); |
| 1736 | //MyStructureManager->Update (); |
| 1737 | //Update(); |
| 1738 | MyGraphicDriver->ContextStructure( MyCStructure ); |
| 1739 | |
| 1740 | MyCStructure.TransformPersistence.IsSet = 1; |
| 1741 | } |
| 1742 | |
| 1743 | Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const |
| 1744 | { |
| 1745 | return MyCStructure.TransformPersistence.Flag; |
| 1746 | } |
| 1747 | |
| 1748 | gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const |
| 1749 | { |
| 1750 | gp_Pnt aPnt( 0., 0., 0. ); |
| 1751 | aPnt.SetX( MyCStructure.TransformPersistence.Point.x ); |
| 1752 | aPnt.SetY( MyCStructure.TransformPersistence.Point.y ); |
| 1753 | aPnt.SetZ( MyCStructure.TransformPersistence.Point.z ); |
| 1754 | |
| 1755 | return aPnt; |
| 1756 | } |
| 1757 | |
| 1758 | void Graphic3d_Structure::Add (const Handle(Graphic3d_Group)& AGroup) { |
| 1759 | |
| 1760 | // Method called only by the constructor of Graphic3d_Group |
| 1761 | // It is easy to check presence of <AGroup> |
| 1762 | // in sequence MyGroups. |
| 1763 | MyGroups.Append (AGroup); |
| 1764 | |
| 1765 | } |
| 1766 | |
| 1767 | void Graphic3d_Structure::Remove (const Standard_Address APtr, const Graphic3d_TypeOfConnection AType) { |
| 1768 | |
| 1769 | Standard_Integer i, index, length; |
| 1770 | |
| 1771 | switch (AType) |
| 1772 | { |
| 1773 | case Graphic3d_TOC_DESCENDANT : |
| 1774 | index = 0; |
| 1775 | length = MyDescendants.Length (); |
| 1776 | for (i=1; i<=length && index==0; i++) |
| 1777 | if ((void *) (MyDescendants.Value (i)) == APtr) |
| 1778 | index = i; |
| 1779 | if (index != 0) |
| 1780 | MyDescendants.Remove (index); |
| 1781 | #ifdef TRACE |
| 1782 | else |
| 1783 | cout << "Error, Graphic3d_Structure::Remove\n"; |
| 1784 | #endif |
| 1785 | break; |
| 1786 | |
| 1787 | case Graphic3d_TOC_ANCESTOR : |
| 1788 | index = 0; |
| 1789 | length = MyAncestors.Length (); |
| 1790 | for (i=1; i<=length && index==0; i++) |
| 1791 | if ((void *) (MyAncestors.Value (i)) == APtr) |
| 1792 | index = i; |
| 1793 | if (index != 0) |
| 1794 | MyAncestors.Remove (index); |
| 1795 | #ifdef TRACE |
| 1796 | else |
| 1797 | cout << "Error, Graphic3d_Structure::Remove\n"; |
| 1798 | #endif |
| 1799 | break; |
| 1800 | } |
| 1801 | |
| 1802 | } |
| 1803 | |
| 1804 | void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& AGroup) { |
| 1805 | |
| 1806 | const Standard_Integer Length = MyGroups.Length (); |
| 1807 | // Search in Groups |
| 1808 | for (Standard_Integer i=1; i<=Length; i++) |
| 1809 | if (MyGroups.Value (i) == AGroup) |
| 1810 | { |
| 1811 | MyGroups.Remove (i); |
| 1812 | return; |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager () const { |
| 1817 | |
| 1818 | #ifdef DOWNCAST |
| 1819 | return |
| 1820 | (Handle(Graphic3d_StructureManager)::DownCast(Handle(Standard_Transient) |
| 1821 | ((Standard_Transient*) MyPtrStructureManager))); |
| 1822 | #else |
| 1823 | return MyStructureManager; |
| 1824 | #endif |
| 1825 | |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | void Graphic3d_Structure::MinMaxCoord (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const { |
| 1830 | |
| 1831 | Standard_Real RL = RealLast (); |
| 1832 | Standard_Real RF = RealFirst (); |
| 1833 | |
| 1834 | Standard_Real Xm, Ym, Zm, XM, YM, ZM; |
| 1835 | |
| 1836 | //Bounding borders of infinite line has been calculated as own point |
| 1837 | //in center of this line |
| 1838 | if (IsEmpty () || IsInfinite ()) { |
| 1839 | if( IsInfinite ()){ |
| 1840 | for (int i=1; i<=MyGroups.Length (); i++) |
| 1841 | if (! (MyGroups.Value (i))->IsEmpty () ) { |
| 1842 | (MyGroups.Value (i))->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM); |
| 1843 | Graphic3d_Vertex vertex1(Xm, Ym, Zm); |
| 1844 | Graphic3d_Vertex vertex2(XM, YM, ZM); |
| 1845 | const Standard_Real distance = vertex1.Distance( vertex2 ); |
| 1846 | if( distance >= 500000.0){ |
| 1847 | XMin = XMax = 0.5*(Xm+ XM); |
| 1848 | YMin = YMax = 0.5*(Ym+ YM); |
| 1849 | ZMin = ZMax = 0.5*(Zm+ ZM); |
| 1850 | return; |
| 1851 | } |
| 1852 | } |
| 1853 | } |
| 1854 | XMin = RF; |
| 1855 | YMin = RF; |
| 1856 | ZMin = RF; |
| 1857 | |
| 1858 | XMax = RL; |
| 1859 | YMax = RL; |
| 1860 | ZMax = RL; |
| 1861 | } |
| 1862 | else { |
| 1863 | XMin = RL; |
| 1864 | YMin = RL; |
| 1865 | ZMin = RL; |
| 1866 | |
| 1867 | XMax = RF; |
| 1868 | YMax = RF; |
| 1869 | ZMax = RF; |
| 1870 | Standard_Integer i, Length; |
| 1871 | |
| 1872 | Length = MyGroups.Length (); |
| 1873 | for (i=1; i<=Length; i++) |
| 1874 | if (! (MyGroups.Value (i))->IsEmpty () ) { |
| 1875 | (MyGroups.Value (i))->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM); |
| 1876 | if (Xm < XMin) XMin = Xm; |
| 1877 | if (Ym < YMin) YMin = Ym; |
| 1878 | if (Zm < ZMin) ZMin = Zm; |
| 1879 | if (XM > XMax) XMax = XM; |
| 1880 | if (YM > YMax) YMax = YM; |
| 1881 | if (ZM > ZMax) ZMax = ZM; |
| 1882 | } |
| 1883 | |
| 1884 | Length = MyDescendants.Length (); |
| 1885 | for (i=1; i<=Length; i++) |
| 1886 | if (! ((Graphic3d_Structure *) |
| 1887 | (MyDescendants.Value (i)))->IsEmpty () ) { |
| 1888 | ((Graphic3d_Structure *) |
| 1889 | (MyDescendants.Value (i)))->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM); |
| 1890 | |
| 1891 | if (Xm < XMin) XMin = Xm; |
| 1892 | if (Ym < YMin) YMin = Ym; |
| 1893 | if (Zm < ZMin) ZMin = Zm; |
| 1894 | if (XM > XMax) XMax = XM; |
| 1895 | if (YM > YMax) YMax = YM; |
| 1896 | if (ZM > ZMax) ZMax = ZM; |
| 1897 | } |
| 1898 | |
| 1899 | if ((XMin == RL) && (YMin == RL) && |
| 1900 | (ZMin == RL) && (XMax == RF) && |
| 1901 | (YMax == RF) && (ZMax == RF)) { |
| 1902 | // Case impossible as it would mean |
| 1903 | // that the structure is empty |
| 1904 | XMin = RF; |
| 1905 | YMin = RF; |
| 1906 | ZMin = RF; |
| 1907 | |
| 1908 | XMax = RL; |
| 1909 | YMax = RL; |
| 1910 | ZMax = RL; |
| 1911 | } |
| 1912 | |
| 1913 | } |
| 1914 | |
| 1915 | } |
| 1916 | |
| 1917 | void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real& NewX, Standard_Real& NewY, Standard_Real& NewZ) { |
| 1918 | |
| 1919 | Standard_Real A, B, C, D; |
| 1920 | |
| 1921 | Standard_Real RL = RealLast (); |
| 1922 | Standard_Real RF = RealFirst (); |
| 1923 | |
| 1924 | if ((X == RF) || (Y == RF) || (Z == RF) || |
| 1925 | (X == RL) || (Y == RL) || (Z == RL)) { |
| 1926 | NewX = X; |
| 1927 | NewY = Y; |
| 1928 | NewZ = Z; |
| 1929 | } |
| 1930 | else { |
| 1931 | A = ATrsf (0, 0); |
| 1932 | B = ATrsf (0, 1); |
| 1933 | C = ATrsf (0, 2); |
| 1934 | D = ATrsf (0, 3); |
| 1935 | NewX = A * X + B * Y + C * Z + D; |
| 1936 | A = ATrsf (1, 0); |
| 1937 | B = ATrsf (1, 1); |
| 1938 | C = ATrsf (1, 2); |
| 1939 | D = ATrsf (1, 3); |
| 1940 | NewY = A * X + B * Y + C * Z + D; |
| 1941 | A = ATrsf (2, 0); |
| 1942 | B = ATrsf (2, 1); |
| 1943 | C = ATrsf (2, 2); |
| 1944 | D = ATrsf (2, 3); |
| 1945 | NewZ = A * X + B * Y + C * Z + D; |
| 1946 | } |
| 1947 | |
| 1948 | } |
| 1949 | |
| 1950 | Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vector& Coord) { |
| 1951 | |
| 1952 | Standard_Real NewX, NewY, NewZ; |
| 1953 | Graphic3d_Vector Result; |
| 1954 | |
| 1955 | Graphic3d_Structure::Transforms |
| 1956 | (ATrsf, Coord.X (), Coord.Y (), Coord.Z (), NewX, NewY, NewZ); |
| 1957 | Result.SetCoord (NewX, NewY, NewZ); |
| 1958 | |
| 1959 | return (Result); |
| 1960 | |
| 1961 | } |
| 1962 | |
| 1963 | Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vertex& Coord) { |
| 1964 | |
| 1965 | Standard_Real NewX, NewY, NewZ; |
| 1966 | Graphic3d_Vertex Result; |
| 1967 | |
| 1968 | Graphic3d_Structure::Transforms |
| 1969 | (ATrsf, Coord.X (), Coord.Y (), Coord.Z (), NewX, NewY, NewZ); |
| 1970 | Result.SetCoord (NewX, NewY, NewZ); |
| 1971 | |
| 1972 | return (Result); |
| 1973 | |
| 1974 | } |
| 1975 | |
| 1976 | void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, Graphic3d_MapOfStructure& ASet) { |
| 1977 | |
| 1978 | |
| 1979 | Graphic3d_MapOfStructure h1; |
| 1980 | Graphic3d_MapOfStructure h2; |
| 1981 | AStructure->Descendants (h1); |
| 1982 | AStructure->Ancestors (h2); |
| 1983 | |
| 1984 | Graphic3d_MapIteratorOfMapOfStructure IteratorD (h1); |
| 1985 | Graphic3d_MapIteratorOfMapOfStructure IteratorA (h2); |
| 1986 | |
| 1987 | ASet.Add (AStructure); |
| 1988 | |
| 1989 | // exploration |
| 1990 | switch (AType) |
| 1991 | { |
| 1992 | |
| 1993 | case Graphic3d_TOC_DESCENDANT : |
| 1994 | while (IteratorD.More ()) { |
| 1995 | Graphic3d_Structure::Network |
| 1996 | (IteratorD.Key (), AType, ASet); |
| 1997 | // IteratorD.Next () is located on the next structure |
| 1998 | IteratorD.Next (); |
| 1999 | } |
| 2000 | break; |
| 2001 | |
| 2002 | case Graphic3d_TOC_ANCESTOR : |
| 2003 | while (IteratorA.More ()) { |
| 2004 | Graphic3d_Structure::Network |
| 2005 | (IteratorA.Key (), AType, ASet); |
| 2006 | // IteratorA.Next () is located on the next structure |
| 2007 | IteratorA.Next (); |
| 2008 | } |
| 2009 | break; |
| 2010 | } |
| 2011 | |
| 2012 | } |
| 2013 | |
| 2014 | void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType) |
| 2015 | { |
| 2016 | |
| 2017 | Graphic3d_MapOfStructure ASet; |
| 2018 | |
| 2019 | Graphic3d_MapIteratorOfMapOfStructure IteratorASet (ASet); |
| 2020 | |
| 2021 | Graphic3d_Structure::Network (AStructure, AType, ASet); |
| 2022 | |
| 2023 | while (IteratorASet.More ()) { |
| 2024 | cout << "\tIdent " |
| 2025 | << (IteratorASet.Key ())->Identification () << "\n"; |
| 2026 | IteratorASet.Next (); |
| 2027 | } |
| 2028 | cout << flush; |
| 2029 | |
| 2030 | } |
| 2031 | |
| 2032 | void Graphic3d_Structure::Update () const |
| 2033 | { |
| 2034 | |
| 2035 | if (IsDeleted ()) return; |
| 2036 | |
| 2037 | if (MyStructureManager->UpdateMode () == Aspect_TOU_ASAP) |
| 2038 | MyStructureManager->Update (); |
| 2039 | |
| 2040 | } |
| 2041 | |
| 2042 | void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& CTXL, const Handle(Graphic3d_AspectText3d)& CTXT, const Handle(Graphic3d_AspectMarker3d)& CTXM, const Handle(Graphic3d_AspectFillArea3d)& CTXF) |
| 2043 | { |
| 2044 | |
| 2045 | Standard_Real R, G, B; |
| 2046 | Standard_Real Rs, Gs, Bs; |
| 2047 | Standard_CString AFont; |
| 2048 | Standard_Real ASpace; |
| 2049 | Standard_Real AnExpansion; |
| 2050 | Standard_Real AWidth; |
| 2051 | Standard_Real AScale; |
| 2052 | Quantity_Color AColor; |
| 2053 | Quantity_Color AnIntColor; |
| 2054 | Quantity_Color BackIntColor; |
| 2055 | Quantity_Color AnEdgeColor; |
| 2056 | Aspect_TypeOfLine ALType; |
| 2057 | Aspect_TypeOfMarker AMType; |
| 2058 | Aspect_InteriorStyle AStyle; |
| 2059 | Aspect_TypeOfStyleText AStyleT; |
| 2060 | Aspect_TypeOfDisplayText ADisplayType; |
| 2061 | Quantity_Color AColorSubTitle; |
| 2062 | Standard_Boolean ATextZoomable; |
| 2063 | Standard_Real ATextAngle; |
| 2064 | Font_FontAspect ATextFontAspect; |
| 2065 | |
| 2066 | |
| 2067 | CTXL->Values (AColor, ALType, AWidth); |
| 2068 | AColor.Values (R, G, B, Quantity_TOC_RGB); |
| 2069 | |
| 2070 | MyCStructure.ContextLine.Color.r = float (R); |
| 2071 | MyCStructure.ContextLine.Color.g = float (G); |
| 2072 | MyCStructure.ContextLine.Color.b = float (B); |
| 2073 | MyCStructure.ContextLine.LineType = int (ALType); |
| 2074 | MyCStructure.ContextLine.Width = float (AWidth); |
| 2075 | MyCStructure.ContextLine.ShaderProgram = CTXL->ShaderProgram(); |
| 2076 | |
| 2077 | CTXM->Values (AColor, AMType, AScale); |
| 2078 | AColor.Values (R, G, B, Quantity_TOC_RGB); |
| 2079 | |
| 2080 | MyCStructure.ContextMarker.Color.r = float (R); |
| 2081 | MyCStructure.ContextMarker.Color.g = float (G); |
| 2082 | MyCStructure.ContextMarker.Color.b = float (B); |
| 2083 | MyCStructure.ContextMarker.MarkerType = AMType; |
| 2084 | MyCStructure.ContextMarker.Scale = float (AScale); |
| 2085 | MyCStructure.ContextMarker.ShaderProgram = CTXM->ShaderProgram(); |
| 2086 | |
| 2087 | CTXT->Values (AColor, AFont, AnExpansion, ASpace,AStyleT,ADisplayType,AColorSubTitle,ATextZoomable,ATextAngle,ATextFontAspect); |
| 2088 | AColor.Values (R, G, B, Quantity_TOC_RGB); |
| 2089 | AColorSubTitle.Values (Rs, Gs, Bs, Quantity_TOC_RGB); |
| 2090 | |
| 2091 | MyCStructure.ContextText.Color.r = float (R); |
| 2092 | MyCStructure.ContextText.Color.g = float (G); |
| 2093 | MyCStructure.ContextText.Color.b = float (B); |
| 2094 | MyCStructure.ContextText.Font = (char*) (AFont); |
| 2095 | MyCStructure.ContextText.Expan = float (AnExpansion); |
| 2096 | MyCStructure.ContextText.Style = int (AStyleT); |
| 2097 | MyCStructure.ContextText.DisplayType = int (ADisplayType); |
| 2098 | MyCStructure.ContextText.Space = float (ASpace); |
| 2099 | MyCStructure.ContextText.ColorSubTitle.r = float (Rs); |
| 2100 | MyCStructure.ContextText.ColorSubTitle.g = float (Gs); |
| 2101 | MyCStructure.ContextText.ColorSubTitle.b = float (Bs); |
| 2102 | MyCStructure.ContextText.TextZoomable = ATextZoomable; |
| 2103 | MyCStructure.ContextText.TextAngle = float (ATextAngle); |
| 2104 | MyCStructure.ContextText.TextFontAspect = int (ATextFontAspect); |
| 2105 | MyCStructure.ContextText.ShaderProgram = CTXT->ShaderProgram(); |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | CTXF->Values (AStyle, AnIntColor, BackIntColor, AnEdgeColor, ALType, AWidth); |
| 2110 | AnIntColor.Values (R, G, B, Quantity_TOC_RGB); |
| 2111 | |
| 2112 | MyCStructure.ContextFillArea.Style = int (AStyle); |
| 2113 | MyCStructure.ContextFillArea.IntColor.r = float (R); |
| 2114 | MyCStructure.ContextFillArea.IntColor.g = float (G); |
| 2115 | MyCStructure.ContextFillArea.IntColor.b = float (B); |
| 2116 | #ifdef OCC1174 |
| 2117 | if ( CTXF->Distinguish() ) |
| 2118 | BackIntColor.Values( R, G, B, Quantity_TOC_RGB ); |
| 2119 | #endif |
| 2120 | MyCStructure.ContextFillArea.BackIntColor.r = float( R ); |
| 2121 | MyCStructure.ContextFillArea.BackIntColor.g = float( G ); |
| 2122 | MyCStructure.ContextFillArea.BackIntColor.b = float( B ); |
| 2123 | |
| 2124 | // Edges |
| 2125 | MyCStructure.ContextFillArea.Edge = CTXF->Edge () ? 1:0; |
| 2126 | AnEdgeColor.Values (R, G, B, Quantity_TOC_RGB); |
| 2127 | MyCStructure.ContextFillArea.EdgeColor.r = float (R); |
| 2128 | MyCStructure.ContextFillArea.EdgeColor.g = float (G); |
| 2129 | MyCStructure.ContextFillArea.EdgeColor.b = float (B); |
| 2130 | MyCStructure.ContextFillArea.LineType = int (ALType); |
| 2131 | MyCStructure.ContextFillArea.Width = float (AWidth); |
| 2132 | MyCStructure.ContextFillArea.Hatch = int (CTXF->HatchStyle ()); |
| 2133 | |
| 2134 | /*** Front and Back face ***/ |
| 2135 | MyCStructure.ContextFillArea.Distinguish = CTXF->Distinguish () ? 1:0; |
| 2136 | MyCStructure.ContextFillArea.BackFace = CTXF->BackFace () ? 1:0; |
| 2137 | /*** Back Material ***/ |
| 2138 | // Light specificity |
| 2139 | MyCStructure.ContextFillArea.Back.Shininess = |
| 2140 | float ((CTXF->BackMaterial ()).Shininess ()); |
| 2141 | MyCStructure.ContextFillArea.Back.Ambient = |
| 2142 | float ((CTXF->BackMaterial ()).Ambient ()); |
| 2143 | MyCStructure.ContextFillArea.Back.Diffuse = |
| 2144 | float ((CTXF->BackMaterial ()).Diffuse ()); |
| 2145 | MyCStructure.ContextFillArea.Back.Specular = |
| 2146 | float ((CTXF->BackMaterial ()).Specular ()); |
| 2147 | MyCStructure.ContextFillArea.Back.Transparency = |
| 2148 | float ((CTXF->BackMaterial ()).Transparency ()); |
| 2149 | MyCStructure.ContextFillArea.Back.Emission = |
| 2150 | float ((CTXF->BackMaterial ()).Emissive ()); |
| 2151 | |
| 2152 | // Reflection mode |
| 2153 | MyCStructure.ContextFillArea.Back.IsAmbient = |
| 2154 | ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); |
| 2155 | MyCStructure.ContextFillArea.Back.IsDiffuse = |
| 2156 | ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); |
| 2157 | MyCStructure.ContextFillArea.Back.IsSpecular = |
| 2158 | ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); |
| 2159 | MyCStructure.ContextFillArea.Back.IsEmission = |
| 2160 | ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); |
| 2161 | |
| 2162 | // Material type |
| 2163 | //JR/Hp |
| 2164 | const Graphic3d_MaterialAspect ama = CTXF->BackMaterial () ; |
| 2165 | Standard_Boolean amt = ama.MaterialType(Graphic3d_MATERIAL_PHYSIC) ; |
| 2166 | MyCStructure.ContextFillArea.Back.IsPhysic = ( amt ? 1 : 0 ); |
| 2167 | |
| 2168 | // Specular color |
| 2169 | MyCStructure.ContextFillArea.Back.ColorSpec.r = |
| 2170 | float (((CTXF->BackMaterial ()).SpecularColor ()).Red ()); |
| 2171 | MyCStructure.ContextFillArea.Back.ColorSpec.g = |
| 2172 | float (((CTXF->BackMaterial ()).SpecularColor ()).Green ()); |
| 2173 | MyCStructure.ContextFillArea.Back.ColorSpec.b = |
| 2174 | float (((CTXF->BackMaterial ()).SpecularColor ()).Blue ()); |
| 2175 | |
| 2176 | // Ambient color |
| 2177 | MyCStructure.ContextFillArea.Back.ColorAmb.r = |
| 2178 | float (((CTXF->BackMaterial ()).AmbientColor ()).Red ()); |
| 2179 | MyCStructure.ContextFillArea.Back.ColorAmb.g = |
| 2180 | float (((CTXF->BackMaterial ()).AmbientColor ()).Green ()); |
| 2181 | MyCStructure.ContextFillArea.Back.ColorAmb.b = |
| 2182 | float (((CTXF->BackMaterial ()).AmbientColor ()).Blue ()); |
| 2183 | |
| 2184 | // Diffuse color |
| 2185 | MyCStructure.ContextFillArea.Back.ColorDif.r = |
| 2186 | float (((CTXF->BackMaterial ()).DiffuseColor ()).Red ()); |
| 2187 | MyCStructure.ContextFillArea.Back.ColorDif.g = |
| 2188 | float (((CTXF->BackMaterial ()).DiffuseColor ()).Green ()); |
| 2189 | MyCStructure.ContextFillArea.Back.ColorDif.b = |
| 2190 | float (((CTXF->BackMaterial ()).DiffuseColor ()).Blue ()); |
| 2191 | |
| 2192 | // Emissive color |
| 2193 | MyCStructure.ContextFillArea.Back.ColorEms.r = |
| 2194 | float (((CTXF->BackMaterial ()).EmissiveColor ()).Red ()); |
| 2195 | MyCStructure.ContextFillArea.Back.ColorEms.g = |
| 2196 | float (((CTXF->BackMaterial ()).EmissiveColor ()).Green ()); |
| 2197 | MyCStructure.ContextFillArea.Back.ColorEms.b = |
| 2198 | float (((CTXF->BackMaterial ()).EmissiveColor ()).Blue ()); |
| 2199 | |
| 2200 | MyCStructure.ContextFillArea.Back.EnvReflexion = |
| 2201 | float ((CTXF->BackMaterial ()).EnvReflexion()); |
| 2202 | |
| 2203 | /*** Front Material ***/ |
| 2204 | // Light specificity |
| 2205 | MyCStructure.ContextFillArea.Front.Shininess = |
| 2206 | float ((CTXF->FrontMaterial ()).Shininess ()); |
| 2207 | MyCStructure.ContextFillArea.Front.Ambient = |
| 2208 | float ((CTXF->FrontMaterial ()).Ambient ()); |
| 2209 | MyCStructure.ContextFillArea.Front.Diffuse = |
| 2210 | float ((CTXF->FrontMaterial ()).Diffuse ()); |
| 2211 | MyCStructure.ContextFillArea.Front.Specular = |
| 2212 | float ((CTXF->FrontMaterial ()).Specular ()); |
| 2213 | MyCStructure.ContextFillArea.Front.Transparency = |
| 2214 | float ((CTXF->FrontMaterial ()).Transparency ()); |
| 2215 | MyCStructure.ContextFillArea.Front.Emission = |
| 2216 | float ((CTXF->FrontMaterial ()).Emissive ()); |
| 2217 | |
| 2218 | // Reflection mode |
| 2219 | MyCStructure.ContextFillArea.Front.IsAmbient = |
| 2220 | ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); |
| 2221 | MyCStructure.ContextFillArea.Front.IsDiffuse = |
| 2222 | ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); |
| 2223 | MyCStructure.ContextFillArea.Front.IsSpecular = |
| 2224 | ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); |
| 2225 | MyCStructure.ContextFillArea.Front.IsEmission = |
| 2226 | ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); |
| 2227 | |
| 2228 | // Material type |
| 2229 | //JR/Hp |
| 2230 | const Graphic3d_MaterialAspect amas = CTXF->FrontMaterial () ; |
| 2231 | Standard_Boolean amty = amas.MaterialType(Graphic3d_MATERIAL_PHYSIC) ; |
| 2232 | MyCStructure.ContextFillArea.Front.IsPhysic = ( amty ? 1 : 0 ); |
| 2233 | |
| 2234 | // Specular color |
| 2235 | MyCStructure.ContextFillArea.Front.ColorSpec.r = |
| 2236 | float (((CTXF->FrontMaterial ()).SpecularColor ()).Red ()); |
| 2237 | MyCStructure.ContextFillArea.Front.ColorSpec.g = |
| 2238 | float (((CTXF->FrontMaterial ()).SpecularColor ()).Green ()); |
| 2239 | MyCStructure.ContextFillArea.Front.ColorSpec.b = |
| 2240 | float (((CTXF->FrontMaterial ()).SpecularColor ()).Blue ()); |
| 2241 | |
| 2242 | // Ambient color |
| 2243 | MyCStructure.ContextFillArea.Front.ColorAmb.r = |
| 2244 | float (((CTXF->FrontMaterial ()).AmbientColor ()).Red ()); |
| 2245 | MyCStructure.ContextFillArea.Front.ColorAmb.g = |
| 2246 | float (((CTXF->FrontMaterial ()).AmbientColor ()).Green ()); |
| 2247 | MyCStructure.ContextFillArea.Front.ColorAmb.b = |
| 2248 | float (((CTXF->FrontMaterial ()).AmbientColor ()).Blue ()); |
| 2249 | |
| 2250 | // Diffuse color |
| 2251 | MyCStructure.ContextFillArea.Front.ColorDif.r = |
| 2252 | float (((CTXF->FrontMaterial ()).DiffuseColor ()).Red ()); |
| 2253 | MyCStructure.ContextFillArea.Front.ColorDif.g = |
| 2254 | float (((CTXF->FrontMaterial ()).DiffuseColor ()).Green ()); |
| 2255 | MyCStructure.ContextFillArea.Front.ColorDif.b = |
| 2256 | float (((CTXF->FrontMaterial ()).DiffuseColor ()).Blue ()); |
| 2257 | |
| 2258 | // Emissive color |
| 2259 | MyCStructure.ContextFillArea.Front.ColorEms.r = |
| 2260 | float (((CTXF->FrontMaterial ()).EmissiveColor ()).Red ()); |
| 2261 | MyCStructure.ContextFillArea.Front.ColorEms.g = |
| 2262 | float (((CTXF->FrontMaterial ()).EmissiveColor ()).Green ()); |
| 2263 | MyCStructure.ContextFillArea.Front.ColorEms.b = |
| 2264 | float (((CTXF->FrontMaterial ()).EmissiveColor ()).Blue ()); |
| 2265 | |
| 2266 | MyCStructure.ContextFillArea.Front.EnvReflexion = |
| 2267 | float ((CTXF->FrontMaterial ()).EnvReflexion()); |
| 2268 | |
| 2269 | MyCStructure.ContextFillArea.Texture.TextureMap = CTXF->TextureMap(); |
| 2270 | MyCStructure.ContextFillArea.Texture.doTextureMap = CTXF->TextureMapState() ? 1 : 0; |
| 2271 | MyCStructure.ContextFillArea.ShaderProgram = CTXF->ShaderProgram(); |
| 2272 | |
| 2273 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 2274 | Standard_Integer aPolyMode; |
| 2275 | Standard_ShortReal aPolyFactor, aPolyUnits; |
| 2276 | CTXF->PolygonOffsets(aPolyMode, aPolyFactor, aPolyUnits); |
| 2277 | MyCStructure.ContextFillArea.PolygonOffsetMode = aPolyMode; |
| 2278 | MyCStructure.ContextFillArea.PolygonOffsetFactor = (Standard_ShortReal)aPolyFactor; |
| 2279 | MyCStructure.ContextFillArea.PolygonOffsetUnits = (Standard_ShortReal)aPolyUnits; |
| 2280 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
| 2281 | } |
| 2282 | |
| 2283 | void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod AMethod) { |
| 2284 | |
| 2285 | Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax; |
| 2286 | Standard_Real R, G, B; |
| 2287 | |
| 2288 | MyCStructure.highlight = 1; |
| 2289 | MyHighlightMethod = AMethod; |
| 2290 | |
| 2291 | switch (AMethod) |
| 2292 | { |
| 2293 | case Aspect_TOHM_COLOR : |
| 2294 | MyHighlightColor.Values (R, G, B, Quantity_TOC_RGB); |
| 2295 | MyGraphicDriver->HighlightColor |
| 2296 | (MyCStructure, float (R), float (G), |
| 2297 | float (B) , Standard_True); |
| 2298 | MyGraphicDriver->NameSetStructure (MyCStructure); |
| 2299 | break; |
| 2300 | case Aspect_TOHM_BLINK : |
| 2301 | MyGraphicDriver->Blink (MyCStructure, Standard_True); |
| 2302 | MyGraphicDriver->NameSetStructure (MyCStructure); |
| 2303 | break; |
| 2304 | case Aspect_TOHM_BOUNDBOX : |
| 2305 | if (IsEmpty () || IsInfinite ()) { |
| 2306 | // Empty or infinite structure |
| 2307 | XMin = YMin = ZMin = 0.; |
| 2308 | XMax = YMax = ZMax = 0.; |
| 2309 | } |
| 2310 | else { |
| 2311 | MinMaxCoord |
| 2312 | (XMin, YMin, ZMin, XMax, YMax, ZMax); |
| 2313 | } |
| 2314 | MyCStructure.BoundBox.Pmin.x = float (XMin); |
| 2315 | MyCStructure.BoundBox.Pmin.y = float (YMin); |
| 2316 | MyCStructure.BoundBox.Pmin.z = float (ZMin); |
| 2317 | MyCStructure.BoundBox.Pmax.x = float (XMax); |
| 2318 | MyCStructure.BoundBox.Pmax.y = float (YMax); |
| 2319 | MyCStructure.BoundBox.Pmax.z = float (ZMax); |
| 2320 | MyHighlightColor.Values (R, G, B, Quantity_TOC_RGB); |
| 2321 | MyCStructure.BoundBox.Color.r = float (R); |
| 2322 | MyCStructure.BoundBox.Color.g = float (G); |
| 2323 | MyCStructure.BoundBox.Color.b = float (B); |
| 2324 | MyGraphicDriver->BoundaryBox (MyCStructure, Standard_True); |
| 2325 | break; |
| 2326 | } |
| 2327 | |
| 2328 | } |
| 2329 | |
| 2330 | void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& AMatrix) { |
| 2331 | |
| 2332 | Standard_Integer i, j; |
| 2333 | |
| 2334 | for (i=0; i<=3; i++) |
| 2335 | for (j=0; j<=3; j++) |
| 2336 | MyCStructure.Transformation[i][j] = float (AMatrix (i, j)); |
| 2337 | |
| 2338 | MyGraphicDriver->TransformStructure (MyCStructure); |
| 2339 | |
| 2340 | } |
| 2341 | |
| 2342 | void Graphic3d_Structure::GraphicUnHighlight () { |
| 2343 | |
| 2344 | MyCStructure.highlight = 0; |
| 2345 | |
| 2346 | switch (MyHighlightMethod) |
| 2347 | { |
| 2348 | case Aspect_TOHM_COLOR : |
| 2349 | MyGraphicDriver->HighlightColor |
| 2350 | (MyCStructure, 0.0, 0.0, 0.0 , Standard_False); |
| 2351 | MyGraphicDriver->NameSetStructure (MyCStructure); |
| 2352 | break; |
| 2353 | case Aspect_TOHM_BLINK : |
| 2354 | MyGraphicDriver->Blink (MyCStructure, Standard_False); |
| 2355 | MyGraphicDriver->NameSetStructure (MyCStructure); |
| 2356 | break; |
| 2357 | case Aspect_TOHM_BOUNDBOX : |
| 2358 | MyGraphicDriver->BoundaryBox |
| 2359 | (MyCStructure, Standard_False); |
| 2360 | MyGraphicDriver->NameSetStructure (MyCStructure); |
| 2361 | break; |
| 2362 | } |
| 2363 | |
| 2364 | } |
| 2365 | |
| 2366 | Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual () const { |
| 2367 | |
| 2368 | return (MyComputeVisual); |
| 2369 | |
| 2370 | } |
| 2371 | |
| 2372 | void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure AVisual) { |
| 2373 | |
| 2374 | // The ComputeVisual is saved only if the structure is |
| 2375 | // declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING. |
| 2376 | // This declaration permits to calculate |
| 2377 | // proper representation of the structure calculated by Compute |
| 2378 | // instead of passage to TOS_COMPUTED. |
| 2379 | if (AVisual != Graphic3d_TOS_COMPUTED) |
| 2380 | MyComputeVisual = AVisual; |
| 2381 | |
| 2382 | } |
| 2383 | |
| 2384 | void Graphic3d_Structure::Plot (const Handle(Graphic3d_Plotter)& ) { |
| 2385 | |
| 2386 | } |
| 2387 | |
| 2388 | void Graphic3d_Structure::SetManager (const Handle(Graphic3d_StructureManager)& AManager, |
| 2389 | const Standard_Boolean |
| 2390 | #ifdef IMPLEMENTED |
| 2391 | WithPropagation |
| 2392 | #endif |
| 2393 | ) |
| 2394 | |
| 2395 | { |
| 2396 | // All connected structures should follow ? |
| 2397 | #ifdef IMPLEMENTED |
| 2398 | if (WithPropagation) { |
| 2399 | Standard_Integer i, Length; |
| 2400 | Length = MyDescendants.Length (); |
| 2401 | for (i=1; i<=Length; i++) |
| 2402 | ((Graphic3d_Structure *) |
| 2403 | (MyDescendants.Value (i)))->SetStructureManager (AManager); |
| 2404 | |
| 2405 | Length = MyAncestors.Length (); |
| 2406 | for (i=1; i<=Length; i++) |
| 2407 | ((Graphic3d_Structure *) |
| 2408 | (MyAncestors.Value (i)))->SetStructureManager (AManager); |
| 2409 | } |
| 2410 | #endif |
| 2411 | |
| 2412 | // change of identification ? |
| 2413 | // MyStructureManager->Remove (Standard_Integer (MyCStructure.Id)); |
| 2414 | // AManager->NewIdentification (); |
| 2415 | // MyCStructure.Id = int (AManager->NewIdentification ()); |
| 2416 | |
| 2417 | Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode (); |
| 2418 | Aspect_TypeOfUpdate NewUpdateMode = AManager->UpdateMode (); |
| 2419 | MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT); |
| 2420 | AManager->SetUpdateMode (Aspect_TOU_WAIT); |
| 2421 | |
| 2422 | if (MyCStructure.stick) { |
| 2423 | MyStructureManager->Erase (this); |
| 2424 | AManager->Display (this); |
| 2425 | } |
| 2426 | |
| 2427 | if (MyCStructure.highlight) { |
| 2428 | } |
| 2429 | |
| 2430 | if (MyCStructure.pick) { |
| 2431 | MyStructureManager->Undetectable (this); |
| 2432 | AManager->Detectable (this); |
| 2433 | } |
| 2434 | |
| 2435 | MyStructureManager->SetUpdateMode (UpdateMode); |
| 2436 | AManager->SetUpdateMode (NewUpdateMode); |
| 2437 | |
| 2438 | // New manager |
| 2439 | MyPtrStructureManager = (void *) AManager.operator->(); |
| 2440 | |
| 2441 | } |
| 2442 | |
| 2443 | void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean AFlag) { |
| 2444 | |
| 2445 | MyCStructure.HLRValidation = AFlag ? 1:0; |
| 2446 | |
| 2447 | } |
| 2448 | |
| 2449 | Standard_Boolean Graphic3d_Structure::HLRValidation () const { |
| 2450 | |
| 2451 | // Hidden parts stored in <me> are valid if : |
| 2452 | // 1/ the owner is defined. |
| 2453 | // 2/ they are not invalid. |
| 2454 | |
| 2455 | Standard_Boolean Result = MyOwner != NULL && MyCStructure.HLRValidation != 0; |
| 2456 | |
| 2457 | return Result; |
| 2458 | |
| 2459 | } |
| 2460 | |
| 2461 | //======================================================================= |
| 2462 | //function : CStructure |
| 2463 | //purpose : |
| 2464 | //======================================================================= |
| 2465 | Graphic3d_CStructure* Graphic3d_Structure::CStructure() |
| 2466 | { |
| 2467 | return &MyCStructure; |
| 2468 | } |
| 2469 | |
| 2470 | //======================================================================= |
| 2471 | //function : SetZLayer |
| 2472 | //purpose : |
| 2473 | //======================================================================= |
| 2474 | void Graphic3d_Structure::SetZLayer (const Standard_Integer theLayerId) |
| 2475 | { |
| 2476 | // if the structure is not displayed, unable to change its display layer |
| 2477 | if (IsDeleted ()) |
| 2478 | return; |
| 2479 | |
| 2480 | MyStructureManager->ChangeZLayer (this, theLayerId); |
| 2481 | } |
| 2482 | |
| 2483 | //======================================================================= |
| 2484 | //function : GetZLayer |
| 2485 | //purpose : |
| 2486 | //======================================================================= |
| 2487 | Standard_Integer Graphic3d_Structure::GetZLayer () const |
| 2488 | { |
| 2489 | return MyStructureManager->GetZLayer (this); |
| 2490 | } |
| 2491 | |
| 2492 | //======================================================================= |
| 2493 | //function : SetClipPlanes |
| 2494 | //purpose : |
| 2495 | //======================================================================= |
| 2496 | void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes) |
| 2497 | { |
| 2498 | MyCStructure.ClipPlanes = thePlanes; |
| 2499 | MyGraphicDriver->SetClipPlanes (MyCStructure); |
| 2500 | } |
| 2501 | |
| 2502 | //======================================================================= |
| 2503 | //function : GetClipPlanes |
| 2504 | //purpose : |
| 2505 | //======================================================================= |
| 2506 | const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const |
| 2507 | { |
| 2508 | return MyCStructure.ClipPlanes; |
| 2509 | } |