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