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