0024704: Visualization - inherit OpenGl_Structure from Graphic3d_CStructure
[occt.git] / src / Graphic3d / Graphic3d_Structure.cxx
... / ...
CommitLineData
1// Created by: NW,JPB,CAL
2// Copyright (c) 1991-1999 Matra Datavision
3// Copyright (c) 1999-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <Graphic3d_Structure.ixx>
17#include <Graphic3d_Structure.pxx>
18
19#include <Graphic3d_GraphicDriver.hxx>
20#include <Graphic3d_MaterialAspect.hxx>
21
22#include <Graphic3d_MapOfStructure.hxx>
23#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
24
25#include <Quantity_Color.hxx>
26#include <TColStd_Array2OfReal.hxx>
27#include <Graphic3d_TextureMap.hxx>
28
29#include <Aspect_PolygonOffsetMode.hxx>
30
31#include <stdio.h>
32
33//=============================================================================
34//function : Graphic3d_Structure
35//purpose :
36//=============================================================================
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)
45{
46 myCStructure = theManager->GraphicDriver()->Structure (theManager);
47
48 // default aspects
49 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
50 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
51 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
52 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
53 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
54 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
55
56 // update the associated CStructure
57 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
58}
59
60//=============================================================================
61//function : Destroy
62//purpose :
63//=============================================================================
64void Graphic3d_Structure::Destroy()
65{
66 // as myFirstStructureManager can be already destroyed,
67 // avoid attempts to access it
68 myFirstStructureManager = NULL;
69 Remove();
70}
71
72//=============================================================================
73//function : Clear
74//purpose :
75//=============================================================================
76void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
77{
78 if (IsDeleted()) return;
79
80 myCStructure->ContainsFacet = 0;
81
82 // clean groups in graphics driver at first
83 GraphicClear (theWithDestruction);
84
85 // only then remove group references
86 if (theWithDestruction)
87 myGroups.Clear();
88
89 myStructureManager->Clear (this, theWithDestruction);
90
91 Update();
92}
93
94//=============================================================================
95//function : Remove
96//purpose :
97//=============================================================================
98void Graphic3d_Structure::Remove()
99{
100 if (IsDeleted()) return;
101
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;
107 Standard_Integer Length = myGroups.Length();
108 for (Standard_Integer aGrId = 1; aGrId <= Length; ++aGrId)
109 myGroups.ChangeValue (aGrId)->Clear (Standard_False);
110
111 // Standard_Address APtr = (void *) This ().operator->();
112 Standard_Address APtr = (void *) this;
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.
117
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 }
123
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 }
129
130 myCStructure->ContainsFacet = 0;
131
132 // Destruction of me in the graphic library
133 const Standard_Integer aStructId = myCStructure->Id;
134 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
135 myCStructure.Nullify();
136
137 // Liberation of the identification if the destroyed structure
138 // in the first manager that performs creation of the structure.
139 if (myFirstStructureManager != NULL)
140 {
141 myFirstStructureManager->Remove (aStructId);
142 }
143}
144
145//=============================================================================
146//function : Display
147//purpose :
148//=============================================================================
149void Graphic3d_Structure::Display()
150{
151 if (IsDeleted()) return;
152
153 if (!myCStructure->stick)
154 {
155 myCStructure->stick = 1;
156 myStructureManager->Display (this);
157 }
158
159 myCStructure->visible = 1;
160}
161
162//=============================================================================
163//function : Display
164//purpose :
165//=============================================================================
166void Graphic3d_Structure::Display (const Standard_Integer thePriority)
167{
168 if (IsDeleted()) return;
169
170 SetDisplayPriority (thePriority);
171
172 if (!myCStructure->stick)
173 {
174 myCStructure->stick = 1;
175 myStructureManager->Display (this);
176 }
177
178 myCStructure->visible = 1;
179}
180
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 }
192
193 myCStructure->PreviousPriority = myCStructure->Priority;
194 myCStructure->Priority = thePriority;
195
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 }
205 }
206}
207
208//=============================================================================
209//function : ResetDisplayPriority
210//purpose :
211//=============================================================================
212void Graphic3d_Structure::ResetDisplayPriority()
213{
214 if (IsDeleted()
215 || myCStructure->Priority == myCStructure->PreviousPriority)
216 {
217 return;
218 }
219
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 }
226}
227
228//=============================================================================
229//function : DisplayPriority
230//purpose :
231//=============================================================================
232Standard_Integer Graphic3d_Structure::DisplayPriority() const
233{
234 return myCStructure->Priority;
235}
236
237//=============================================================================
238//function : Erase
239//purpose :
240//=============================================================================
241void Graphic3d_Structure::Erase()
242{
243 if (IsDeleted())
244 {
245 return;
246 }
247
248 if (myCStructure->stick)
249 {
250 myCStructure->stick = 0;
251 myStructureManager->Erase (this);
252 }
253}
254
255//=============================================================================
256//function : Highlight
257//purpose :
258//=============================================================================
259void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod theMethod)
260{
261 if (IsDeleted())
262 {
263 return;
264 }
265
266 // Highlight on already Highlighted structure.
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()
277 // Not useful and can be costly.
278 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
279 UnHighlight();
280 myStructureManager->SetUpdateMode (anUpdateMode);
281 }
282 }
283
284 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
285
286 GraphicHighlight (theMethod);
287 myStructureManager->Highlight (this, theMethod);
288
289 Update();
290}
291
292//=============================================================================
293//function : SetHighlightColor
294//purpose :
295//=============================================================================
296void Graphic3d_Structure::SetHighlightColor (const Quantity_Color& theColor)
297{
298 if (IsDeleted())
299 {
300 return;
301 }
302
303 if (!myCStructure->highlight)
304 {
305 myHighlightColor = theColor;
306 return;
307 }
308
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);
325}
326
327//=============================================================================
328//function : SetVisible
329//purpose :
330//=============================================================================
331void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
332{
333 if (IsDeleted()) return;
334
335 myCStructure->visible = theValue ? 1 : 0;
336 myCStructure->UpdateNamedStatus();
337 Update();
338}
339
340//=============================================================================
341//function : SetPick
342//purpose :
343//=============================================================================
344void Graphic3d_Structure::SetPick (const Standard_Boolean theValue)
345{
346 if (IsDeleted ()) return;
347
348 myCStructure->pick = theValue ? 1 : 0;
349 myCStructure->UpdateNamedStatus();
350
351 if (theValue)
352 {
353 myStructureManager->Detectable (this);
354 }
355 else
356 {
357 myStructureManager->Undetectable (this);
358 }
359 Update();
360}
361
362//=============================================================================
363//function : UnHighlight
364//purpose :
365//=============================================================================
366void Graphic3d_Structure::UnHighlight()
367{
368 if (IsDeleted()) return;
369
370 if (myCStructure->highlight)
371 {
372 myCStructure->highlight = 0;
373
374 GraphicUnHighlight();
375 myStructureManager->UnHighlight (this);
376
377 ResetDisplayPriority();
378 Update();
379 }
380}
381
382//=============================================================================
383//function : HighlightColor
384//purpose :
385//=============================================================================
386const Quantity_Color& Graphic3d_Structure::HighlightColor() const
387{
388 return myHighlightColor;
389}
390
391//=============================================================================
392//function : IsDisplayed
393//purpose :
394//=============================================================================
395Standard_Boolean Graphic3d_Structure::IsDisplayed() const
396{
397 return myCStructure->stick ? Standard_True : Standard_False;
398}
399
400//=============================================================================
401//function : IsDeleted
402//purpose :
403//=============================================================================
404Standard_Boolean Graphic3d_Structure::IsDeleted() const
405{
406 return myCStructure.IsNull();
407}
408
409//=============================================================================
410//function : IsHighlighted
411//purpose :
412//=============================================================================
413Standard_Boolean Graphic3d_Structure::IsHighlighted() const
414{
415 return myCStructure->highlight ? Standard_True : Standard_False;
416}
417
418//=============================================================================
419//function : IsSelectable
420//purpose :
421//=============================================================================
422Standard_Boolean Graphic3d_Structure::IsSelectable() const
423{
424 return myCStructure->pick ? Standard_True : Standard_False;
425}
426
427//=============================================================================
428//function : IsVisible
429//purpose :
430//=============================================================================
431Standard_Boolean Graphic3d_Structure::IsVisible() const
432{
433 return myCStructure->visible ? Standard_True : Standard_False;
434}
435
436//=============================================================================
437//function : IsRotated
438//purpose :
439//=============================================================================
440Standard_Boolean Graphic3d_Structure::IsRotated() const
441{
442 // A somewhat light test !
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;
449}
450
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 {
462 if (i == j)
463 aResult = myCStructure->Transformation[i][j] != 1.0;
464 else
465 aResult = myCStructure->Transformation[i][j] != 0.0;
466 }
467 }
468 return aResult;
469}
470
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 }
486
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;
497}
498
499//=============================================================================
500//function : IsEmpty
501//purpose :
502//=============================================================================
503Standard_Boolean Graphic3d_Structure::IsEmpty() const
504{
505 if (IsDeleted())
506 {
507 return Standard_True;
508 }
509
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 }
522
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;
533}
534
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();
548}
549
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 }
561}
562
563//=============================================================================
564//function : Compute
565//purpose :
566//=============================================================================
567void Graphic3d_Structure::Compute()
568{
569 // Implemented by Presentation
570}
571
572//=============================================================================
573//function : Compute
574//purpose :
575//=============================================================================
576Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
577{
578 // Implemented by Presentation
579 return this;
580}
581
582//=============================================================================
583//function : Compute
584//purpose :
585//=============================================================================
586Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
587 const TColStd_Array2OfReal& )
588{
589 // Implemented by Presentation
590 return this;
591}
592
593//=============================================================================
594//function : Compute
595//purpose :
596//=============================================================================
597void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
598 Handle(Graphic3d_Structure)& )
599{
600 // Implemented by Presentation
601}
602
603//=============================================================================
604//function : Compute
605//purpose :
606//=============================================================================
607void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
608 const TColStd_Array2OfReal& ,
609 Handle(Graphic3d_Structure)& )
610{
611 // Implemented by Presentation
612}
613
614//=============================================================================
615//function : ReCompute
616//purpose :
617//=============================================================================
618void Graphic3d_Structure::ReCompute()
619{
620 myStructureManager->ReCompute (this);
621}
622
623//=============================================================================
624//function : ReCompute
625//purpose :
626//=============================================================================
627void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
628{
629 myStructureManager->ReCompute (this, theProjector);
630}
631
632//=============================================================================
633//function : SetInfiniteState
634//purpose :
635//=============================================================================
636void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
637{
638 myCStructure->IsInfinite = theToSet ? 1 : 0;
639}
640
641//=============================================================================
642//function : IsInfinite
643//purpose :
644//=============================================================================
645Standard_Boolean Graphic3d_Structure::IsInfinite() const
646{
647 return IsDeleted()
648 || myCStructure->IsInfinite;
649}
650
651//=============================================================================
652//function : GraphicClear
653//purpose :
654//=============================================================================
655void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
656{
657 // clean and empty each group
658 const Standard_Integer aLength = myGroups.Length();
659 for (Standard_Integer aGrId = 1; aGrId <= aLength; ++aGrId)
660 {
661 myGroups.ChangeValue (aGrId)->Clear();
662 }
663
664 if (theWithDestruction)
665 {
666 while (!myGroups.IsEmpty())
667 {
668 Handle(Graphic3d_Group) aGroup = myGroups.First();
669 aGroup->Remove();
670 }
671
672 myCStructure->Clear();
673 }
674}
675
676//=============================================================================
677//function : GraphicConnect
678//purpose :
679//=============================================================================
680void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
681{
682 myCStructure->Connect (*theDaughter->myCStructure);
683}
684
685//=============================================================================
686//function : GraphicDisconnect
687//purpose :
688//=============================================================================
689void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
690{
691 myCStructure->Disconnect (*theDaughter->myCStructure);
692}
693
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);
710
711 Handle(Graphic3d_AspectLine3d) anAspLine = new Graphic3d_AspectLine3d (aColor, aLType, aWidth);
712 anAspLine->SetShaderProgram (myCStructure->ContextLine.ShaderProgram);
713 return anAspLine;
714}
715
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;
739}
740
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);
757
758 Handle(Graphic3d_AspectMarker3d) anAspMarker = new Graphic3d_AspectMarker3d (aMType, aColor, aScale);
759 anAspMarker->SetShaderProgram (myCStructure->ContextMarker.ShaderProgram);
760 return anAspMarker;
761}
762
763//=============================================================================
764//function : FillArea3dAspect
765//purpose :
766//=============================================================================
767Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
768{
769 // Back Material
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);
779 else
780 aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
781 if (myCStructure->ContextFillArea.Back.IsDiffuse == 1)
782 aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
783 else
784 aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
785 if (myCStructure->ContextFillArea.Back.IsSpecular == 1)
786 aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
787 else
788 aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
789 if (myCStructure->ContextFillArea.Back.IsEmission == 1)
790 aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
791 else
792 aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
793
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);
798
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);
803
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);
808
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);
813
814 aBack.SetEnvReflexion (myCStructure->ContextFillArea.Back.EnvReflexion);
815 aBack.SetMaterialType (myCStructure->ContextFillArea.Back.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
816
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);
876
877 // Edges
878 if (myCStructure->ContextFillArea.Edge == 1)
879 anAspFill->SetEdgeOn();
880 else
881 anAspFill->SetEdgeOff();
882 // Hatch
883 anAspFill->SetHatchStyle (Aspect_HatchStyle (myCStructure->ContextFillArea.Hatch));
884 // Materials
885 // Front and Back face
886 if (myCStructure->ContextFillArea.Distinguish == 1)
887 anAspFill->SetDistinguishOn();
888 else
889 anAspFill->SetDistinguishOff();
890 if (myCStructure->ContextFillArea.BackFace == 1)
891 anAspFill->SuppressBackFace();
892 else
893 anAspFill->AllowBackFace();
894 // Texture
895 anAspFill->SetTextureMap (myCStructure->ContextFillArea.Texture.TextureMap);
896 if (myCStructure->ContextFillArea.Texture.doTextureMap == 1)
897 {
898 anAspFill->SetTextureMapOn();
899 }
900 else
901 {
902 anAspFill->SetTextureMapOff();
903 }
904 anAspFill->SetShaderProgram (myCStructure->ContextFillArea.ShaderProgram);
905 anAspFill->SetPolygonOffsets (myCStructure->ContextFillArea.PolygonOffsetMode,
906 myCStructure->ContextFillArea.PolygonOffsetFactor,
907 myCStructure->ContextFillArea.PolygonOffsetUnits);
908 return anAspFill;
909}
910
911//=============================================================================
912//function : Groups
913//purpose :
914//=============================================================================
915const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
916{
917 return myGroups;
918}
919
920//=============================================================================
921//function : NumberOfGroups
922//purpose :
923//=============================================================================
924Standard_Integer Graphic3d_Structure::NumberOfGroups() const
925{
926 return myGroups.Length();
927}
928
929//=============================================================================
930//function : SetPrimitivesAspect
931//purpose :
932//=============================================================================
933void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
934{
935 if (IsDeleted()) return;
936
937 Standard_Real aWidth;
938 Quantity_Color aColor;
939 Aspect_TypeOfLine aLType;
940 theAspLine->Values (aColor, aLType, aWidth);
941
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;
949
950 myCStructure->UpdateAspects();
951
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;
957
958 Update();
959}
960
961//=============================================================================
962//function : SetPrimitivesAspect
963//purpose :
964//=============================================================================
965void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
966{
967 if (IsDeleted()) return;
968
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]);
991
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();
1000
1001 // Front and Back face
1002 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
1003 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
1004
1005 // Back Material
1006 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
1007 // Light specificity
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());
1014
1015 // Reflection mode
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);
1020
1021 // Material type
1022 //JR/Hp
1023 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0 );
1024
1025 // Specular Color
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());
1029
1030 // Ambient color
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());
1034
1035 // Diffuse color
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());
1039
1040 // Emissive color
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());
1044
1045 myCStructure->ContextFillArea.Back.EnvReflexion =
1046 float ((theAspFill->BackMaterial ()).EnvReflexion());
1047
1048 // Front Material
1049 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
1050 // Light specificity
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());
1057
1058 // Reflection mode
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);
1063
1064 // Materail type
1065 //JR/Hp
1066 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
1067
1068 // Specular Color
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());
1072
1073 // Ambient color
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());
1077
1078 // Diffuse color
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());
1082
1083 // Emissive color
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());
1087
1088 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
1089
1090 myCStructure->ContextFillArea.IsDef = 1; // Definition material ok
1091
1092 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
1093 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
1094 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
1095
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;
1102
1103 myCStructure->UpdateAspects();
1104
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;
1110
1111 Update();
1112}
1113
1114//=============================================================================
1115//function : SetPrimitivesAspect
1116//purpose :
1117//=============================================================================
1118void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
1119{
1120 if (IsDeleted()) return;
1121
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();
1150
1151 // Attributes are "IsSet" during the first update of a context (line, marker...)
1152 myCStructure->ContextLine.IsSet = 1;
1153 myCStructure->ContextFillArea.IsSet = 1;
1154 myCStructure->ContextMarker.IsSet = 1;
1155 myCStructure->ContextText.IsSet = 1;
1156
1157 Update();
1158}
1159
1160//=============================================================================
1161//function : SetPrimitivesAspect
1162//purpose :
1163//=============================================================================
1164void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
1165{
1166 if (IsDeleted()) return;
1167
1168 Standard_Real aScale;
1169 Quantity_Color aColor;
1170 Aspect_TypeOfMarker aMType;
1171 theAspMarker->Values (aColor, aMType, aScale);
1172
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;
1180
1181 myCStructure->UpdateAspects();
1182
1183 // Attributes are "IsSet" during the first update of a context (line, marker...)
1184 myCStructure->ContextLine.IsSet = 1;
1185 myCStructure->ContextFillArea.IsSet = 1;
1186 myCStructure->ContextMarker.IsSet = 1;
1187 myCStructure->ContextText.IsSet = 1;
1188
1189 Update();
1190}
1191
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;
1202 }
1203
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();
1218 }
1219 else {
1220 // To avoid calling method : Update ()
1221 // Not useful and can be costly.
1222 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
1223 Erase();
1224 myVisual = theVisual;
1225 SetComputeVisual (theVisual);
1226 myStructureManager->SetUpdateMode (anUpdateMode);
1227 Display();
1228 }
1229 }
1230}
1231
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");
1247}
1248
1249//=============================================================================
1250//function : Visual
1251//purpose :
1252//=============================================================================
1253Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
1254{
1255 return myVisual;
1256}
1257
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{
1266 // cycle detection
1267 Graphic3d_MapOfStructure aSet;
1268 Graphic3d_Structure::Network (theStructure2, theType, aSet);
1269 return !aSet.Contains (theStructure1);
1270}
1271
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 }
1283}
1284
1285//=============================================================================
1286//function : SetOwner
1287//purpose :
1288//=============================================================================
1289void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
1290{
1291 myOwner = theOwner;
1292}
1293
1294//=============================================================================
1295//function : Owner
1296//purpose :
1297//=============================================================================
1298Standard_Address Graphic3d_Structure::Owner() const
1299{
1300 return myOwner;
1301}
1302
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 }
1314}
1315
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;
1325
1326 // cycle detection
1327 if (theWithCheck
1328 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
1329 {
1330 return;
1331 }
1332
1333 switch (theType)
1334 {
1335 case Graphic3d_TOC_DESCENDANT:
1336 {
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 }
1345
1346 myDescendants.Append (theStructure.operator->());
1347 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
1348
1349 GraphicConnect (theStructure);
1350 myStructureManager->Connect (this, theStructure);
1351
1352 Update();
1353 return;
1354 }
1355 case Graphic3d_TOC_ANCESTOR:
1356 {
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 }
1364 }
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;
1371 }
1372 }
1373}
1374
1375//=============================================================================
1376//function : Disconnect
1377//purpose :
1378//=============================================================================
1379void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
1380{
1381 if (IsDeleted()) return;
1382
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);
1390
1391 GraphicDisconnect (theStructure);
1392 myStructureManager->Disconnect (this, theStructure);
1393
1394 Update();
1395 return;
1396 }
1397 }
1398
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;
1408 }
1409 }
1410}
1411
1412//=============================================================================
1413//function : DisconnectAll
1414//purpose :
1415//=============================================================================
1416void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
1417{
1418 if (IsDeleted()) return;
1419
1420 switch (theType)
1421 {
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 }
1448 }
1449}
1450
1451//=============================================================================
1452//function : Composition
1453//purpose :
1454//=============================================================================
1455Graphic3d_TypeOfComposition Graphic3d_Structure::Composition() const
1456{
1457 return myCStructure->Composition;
1458}
1459
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;
1468
1469 Standard_Real valuetrsf;
1470 Standard_Real valueoldtrsf;
1471 Standard_Real valuenewtrsf;
1472 TColStd_Array2OfReal aNewTrsf (0, 3, 0, 3);
1473 TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3);
1474
1475 // Assign the new transformation in an array [0..3][0..3]
1476 // Avoid problemes if the user has defined matrice [1..4][1..4]
1477 // or [3..6][-1..2] !!
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");
1486 }
1487
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 }
1529 }
1530 }
1531
1532 // Update of CStructure
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 }
1542 }
1543
1544 // If transformation, no validation of hidden already calculated parts
1545 if (IsRotated())
1546 {
1547 ReCompute();
1548 }
1549
1550 GraphicTransform (aNewTrsf);
1551 myStructureManager->SetTransform (this, aNewTrsf);
1552
1553 Update();
1554}
1555
1556//=============================================================================
1557//function : Transform
1558//purpose :
1559//=============================================================================
1560void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const
1561{
1562
1563 Standard_Integer lr = theMatrix.LowerRow ();
1564 Standard_Integer ur = theMatrix.UpperRow ();
1565 Standard_Integer lc = theMatrix.LowerCol ();
1566 Standard_Integer uc = theMatrix.UpperCol ();
1567
1568 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1569 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1570
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 }
1578}
1579
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 }
1596
1597 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
1598 MinMaxCoord (aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
1599
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 }
1613
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;
1630 }
1631
1632 theXMin = RealFirst();
1633 theYMin = RealFirst();
1634 theZMin = RealFirst();
1635 theXMax = RealLast();
1636 theYMax = RealLast();
1637 theZMax = RealLast();
1638 return;
1639 }
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();
1648 for (Standard_Integer aStructIt = 1; aStructIt <= myDescendants.Length(); aStructIt++)
1649 {
1650 Graphic3d_Structure* aStructure = (Graphic3d_Structure*) myDescendants.Value (aStructIt);
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;
1694}
1695
1696//=============================================================================
1697//function : Identification
1698//purpose :
1699//=============================================================================
1700Standard_Integer Graphic3d_Structure::Identification() const
1701{
1702 return myCStructure->Id;
1703}
1704
1705//=============================================================================
1706//function : SetTransformPersistence
1707//purpose :
1708//=============================================================================
1709void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag)
1710{
1711 SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0));
1712}
1713
1714//=============================================================================
1715//function : SetTransformPersistence
1716//purpose :
1717//=============================================================================
1718void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
1719 const gp_Pnt& thePoint)
1720{
1721 if (IsDeleted()) return;
1722
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();
1728
1729 myCStructure->TransformPersistence.IsSet = 1;
1730}
1731
1732//=============================================================================
1733//function : TransformPersistenceMode
1734//purpose :
1735//=============================================================================
1736Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1737{
1738 return myCStructure->TransformPersistence.Flag;
1739}
1740
1741//=============================================================================
1742//function : TransformPersistencePoint
1743//purpose :
1744//=============================================================================
1745gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1746{
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);
1751 return aPnt;
1752}
1753
1754//=============================================================================
1755//function : Add
1756//purpose :
1757//=============================================================================
1758void Graphic3d_Structure::Add (const Handle(Graphic3d_Group)& theGroup)
1759{
1760 // Method called only by the constructor of Graphic3d_Group
1761 // It is easy to check presence of <theGroup> in sequence myGroups.
1762 myGroups.Append (theGroup);
1763}
1764
1765//=============================================================================
1766//function : Remove
1767//purpose :
1768//=============================================================================
1769void Graphic3d_Structure::Remove (const Standard_Address thePtr,
1770 const Graphic3d_TypeOfConnection theType)
1771{
1772 switch (theType)
1773 {
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 }
1800 }
1801}
1802
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)
1813 {
1814 myGroups.Remove (aGrpIter);
1815 return;
1816 }
1817 }
1818}
1819
1820//=============================================================================
1821//function : StructureManager
1822//purpose :
1823//=============================================================================
1824Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1825{
1826 return myStructureManager;
1827}
1828
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 }
1850
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;
1858 for (Standard_Integer aGroupIt = 1; aGroupIt <= myGroups.Length(); aGroupIt++)
1859 {
1860 const Handle(Graphic3d_Group)& aGroup = myGroups.Value (aGroupIt);
1861
1862 if (aGroup->IsEmpty())
1863 {
1864 continue;
1865 }
1866
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 }
1875
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 }
1887
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;
1916 }
1917
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();
1928 for (Standard_Integer aStructIt = 1; aStructIt <= myDescendants.Length(); aStructIt++)
1929 {
1930 Graphic3d_Structure* aStructure = (Graphic3d_Structure*) myDescendants.Value (aStructIt);
1931 if (aStructure->IsEmpty())
1932 {
1933 continue;
1934 }
1935
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 }
1944
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 }
1960
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();
1971 }
1972
1973 theXMin = aXMin;
1974 theYMin = aYMin;
1975 theZMin = aZMin;
1976 theXMax = aXMax;
1977 theYMax = aYMax;
1978 theZMax = aZMax;
1979}
1980
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;
2016 }
2017}
2018
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]);
2031}
2032
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]);
2045}
2046
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
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)
2115 {
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;
2128 }
2129}
2130
2131//=============================================================================
2132//function : PrintNetwork
2133//purpose :
2134//=============================================================================
2135void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
2136 const Graphic3d_TypeOfConnection theType)
2137{
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";
2143 }
2144 std::cout << std::flush;
2145}
2146
2147//=============================================================================
2148//function : Update
2149//purpose :
2150//=============================================================================
2151void Graphic3d_Structure::Update() const
2152{
2153 if (IsDeleted())
2154 {
2155 return;
2156 }
2157
2158 if (myStructureManager->UpdateMode() == Aspect_TOU_ASAP)
2159 {
2160 myStructureManager->Update();
2161 }
2162}
2163
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]);
2233
2234 // Edges
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();
2248 // Light specificity
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());
2255
2256 // Reflection mode
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);
2261
2262 // Material type
2263 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2264
2265 // Specular color
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());
2269
2270 // Ambient color
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());
2274
2275 // Diffuse color
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());
2279
2280 // Emissive color
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());
2284
2285 myCStructure->ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
2286
2287 // Front Material
2288 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
2289 // Light specificity
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());
2296
2297 // Reflection mode
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);
2302
2303 // Material type
2304 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2305
2306 // Specular color
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());
2310
2311 // Ambient color
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());
2315
2316 // Diffuse color
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());
2320
2321 // Emissive color
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());
2325
2326 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
2327
2328 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
2329 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
2330 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
2331
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;
2338}
2339
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)
2350 {
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 }
2384 }
2385}
2386
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();
2401}
2402
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 }
2421}
2422
2423//=============================================================================
2424//function : ComputeVisual
2425//purpose :
2426//=============================================================================
2427Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
2428{
2429 return myComputeVisual;
2430}
2431
2432//=============================================================================
2433//function : SetComputeVisual
2434//purpose :
2435//=============================================================================
2436void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
2437{
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;
2443 }
2444}
2445
2446//=============================================================================
2447//function : Plot
2448//purpose :
2449//=============================================================================
2450void Graphic3d_Structure::Plot (const Handle(Graphic3d_Plotter)& )
2451{
2452 //
2453}
2454
2455//=============================================================================
2456//function : SetHLRValidation
2457//purpose :
2458//=============================================================================
2459void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
2460{
2461 myCStructure->HLRValidation = theFlag ? 1 : 0;
2462}
2463
2464//=============================================================================
2465//function : HLRValidation
2466//purpose :
2467//=============================================================================
2468Standard_Boolean Graphic3d_Structure::HLRValidation() const
2469{
2470 // Hidden parts stored in <me> are valid if :
2471 // 1/ the owner is defined.
2472 // 2/ they are not invalid.
2473 return myOwner != NULL
2474 && myCStructure->HLRValidation != 0;
2475}
2476
2477//=======================================================================
2478//function : CStructure
2479//purpose :
2480//=======================================================================
2481const Handle(Graphic3d_CStructure)& Graphic3d_Structure::CStructure() const
2482{
2483 return myCStructure;
2484}
2485
2486//=======================================================================
2487//function : SetZLayer
2488//purpose :
2489//=======================================================================
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
2496 myStructureManager->ChangeZLayer (this, theLayerId);
2497}
2498
2499//=======================================================================
2500//function : GetZLayer
2501//purpose :
2502//=======================================================================
2503Standard_Integer Graphic3d_Structure::GetZLayer () const
2504{
2505 return myStructureManager->GetZLayer (this);
2506}
2507
2508//=======================================================================
2509//function : SetClipPlanes
2510//purpose :
2511//=======================================================================
2512void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
2513{
2514 myCStructure->SetClipPlanes (thePlanes);
2515}
2516
2517//=======================================================================
2518//function : GetClipPlanes
2519//purpose :
2520//=======================================================================
2521const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
2522{
2523 return myCStructure->ClipPlanes();
2524}