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