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