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