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