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