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