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