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