0025180: Visualization - Homogeneous transformation API in TKV3d
[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
2831708b 16#include <Graphic3d_Structure.hxx>
7fd59977 17
42cf5bc1 18#include <Bnd_Box.hxx>
19#include <gp_Pnt.hxx>
42cf5bc1 20#include <Graphic3d_DataStructureManager.hxx>
7fd59977 21#include <Graphic3d_GraphicDriver.hxx>
42cf5bc1 22#include <Graphic3d_Group.hxx>
7fd59977 23#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
42cf5bc1 24#include <Graphic3d_MapOfStructure.hxx>
42cf5bc1 25#include <Graphic3d_PriorityDefinitionError.hxx>
42cf5bc1 26#include <Graphic3d_StructureDefinitionError.hxx>
27#include <Graphic3d_StructureManager.hxx>
42cf5bc1 28#include <Graphic3d_TransformError.hxx>
29#include <Graphic3d_Vector.hxx>
7fd59977 30#include <Quantity_Color.hxx>
42cf5bc1 31#include <Standard_Type.hxx>
7fd59977 32
2831708b 33#include "Graphic3d_Structure.pxx"
34
63bcc448 35#include <stdio.h>
2831708b 36
92efcf78 37IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Structure,MMgt_TShared)
38
63bcc448 39//=============================================================================
40//function : Graphic3d_Structure
41//purpose :
42//=============================================================================
43Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
44: myStructureManager (theManager.operator->()),
45 myFirstStructureManager (theManager.operator->()),
46 myComputeVisual (Graphic3d_TOS_ALL),
47 myHighlightColor (Quantity_NOC_WHITE),
48 myHighlightMethod (Aspect_TOHM_COLOR),
49 myOwner (NULL),
50 myVisual (Graphic3d_TOS_ALL)
7fd59977 51{
c357e426 52 myCStructure = theManager->GraphicDriver()->CreateStructure (theManager);
7fd59977 53}
54
63bcc448 55//=============================================================================
679ecdee 56//function : Graphic3d_Structure
57//purpose :
58//=============================================================================
59Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
60 const Handle(Graphic3d_Structure)& thePrs)
61: myStructureManager (theManager.operator->()),
62 myFirstStructureManager (theManager.operator->()),
63 myComputeVisual (thePrs->myComputeVisual),
64 myHighlightColor (thePrs->myHighlightColor),
65 myHighlightMethod (thePrs->myHighlightMethod),
66 myOwner (thePrs->myOwner),
67 myVisual (thePrs->myVisual)
68{
69 myCStructure = thePrs->myCStructure->ShadowLink (theManager);
679ecdee 70}
71
72//=============================================================================
e6f550da 73//function : ~Graphic3d_Structure
63bcc448 74//purpose :
75//=============================================================================
e6f550da 76Graphic3d_Structure::~Graphic3d_Structure()
63bcc448 77{
78 // as myFirstStructureManager can be already destroyed,
bbf32d01 79 // avoid attempts to access it
63bcc448 80 myFirstStructureManager = NULL;
81 Remove();
7fd59977 82}
83
63bcc448 84//=============================================================================
85//function : Clear
86//purpose :
87//=============================================================================
88void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
98178592
A
89{
90 if (IsDeleted()) return;
7fd59977 91
98178592 92 // clean groups in graphics driver at first
63bcc448 93 GraphicClear (theWithDestruction);
7fd59977 94
b64d84be 95 myCStructure->ContainsFacet = 0;
63bcc448 96 myStructureManager->Clear (this, theWithDestruction);
7fd59977 97
50d06d8f 98 Update (true);
7fd59977 99}
100
b7cd4ba7 101//=======================================================================
102//function : CalculateBoundBox
103//purpose : Calculates AABB of a structure.
104//=======================================================================
105void Graphic3d_Structure::CalculateBoundBox()
106{
107 Graphic3d_BndBox4d aBox;
108 addTransformed (aBox, Standard_True);
825aa485 109 if (aBox.IsValid())
b7cd4ba7 110 {
111 Graphic3d_Vec4 aMinPt (RealToShortReal (aBox.CornerMin().x()),
112 RealToShortReal (aBox.CornerMin().y()),
113 RealToShortReal (aBox.CornerMin().z()),
114 1.0f);
115 Graphic3d_Vec4 aMaxPt (RealToShortReal (aBox.CornerMax().x()),
116 RealToShortReal (aBox.CornerMax().y()),
117 RealToShortReal (aBox.CornerMax().z()),
118 1.0f);
119 myCStructure->ChangeBoundingBox() = Graphic3d_BndBox4f (aMinPt, aMaxPt);
120 }
121 else
122 {
123 myCStructure->ChangeBoundingBox().Clear();
124 }
125}
126
63bcc448 127//=============================================================================
128//function : Remove
129//purpose :
130//=============================================================================
131void Graphic3d_Structure::Remove()
132{
133 if (IsDeleted()) return;
98178592 134
6c8126b5
A
135 // clean groups in graphics driver at first; this is also should be done
136 // to avoid unwanted group cleaning in group's destructor
137 // Pass Standard_False to Clear(..) method to avoid updating in
138 // structure manager, it isn't necessary, besides of it structure manager
139 // could be already destroyed and invalid pointers used in structure;
b64d84be 140 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
141 {
142 aGroupIter.ChangeValue()->Clear (Standard_False);
143 }
98178592 144
7fd59977 145 Standard_Address APtr = (void *) this;
81bba717 146 // It is necessary to remove the eventual pointer on the structure
147 // that can be destroyed, in the list of descendants
b64d84be 148 // of ancestors of this structure and in the list of ancestors
81bba717 149 // of descendants of the same structure.
7fd59977 150
602d1ead 151 for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx)
63bcc448 152 {
602d1ead 153 ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
63bcc448 154 }
7fd59977 155
602d1ead 156 for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx)
63bcc448 157 {
602d1ead 158 ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
63bcc448 159 }
7fd59977 160
81bba717 161 // Destruction of me in the graphic library
63bcc448 162 const Standard_Integer aStructId = myCStructure->Id;
016e5959 163 myCStructure->GraphicDriver()->RemoveIdentification(aStructId);
63bcc448 164 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
165 myCStructure.Nullify();
7fd59977 166}
167
63bcc448 168//=============================================================================
169//function : Display
170//purpose :
171//=============================================================================
172void Graphic3d_Structure::Display()
173{
174 if (IsDeleted()) return;
7fd59977 175
63bcc448 176 if (!myCStructure->stick)
177 {
178 myCStructure->stick = 1;
179 myStructureManager->Display (this);
7fd59977 180 }
181
a1954302 182 if (myCStructure->visible != 1)
183 {
184 myCStructure->visible = 1;
185 myCStructure->OnVisibilityChanged();
186 }
7fd59977 187}
188
63bcc448 189//=============================================================================
b7cd4ba7 190//function : SetIsForHighlight
191//purpose :
192//=============================================================================
193void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
194{
195 myCStructure->IsForHighlight = isForHighlight;
196}
197
198//=============================================================================
63bcc448 199//function : SetDisplayPriority
200//purpose :
201//=============================================================================
202void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
203{
204 if (IsDeleted()
205 || thePriority == myCStructure->Priority)
206 {
207 return;
208 }
7fd59977 209
63bcc448 210 myCStructure->PreviousPriority = myCStructure->Priority;
211 myCStructure->Priority = thePriority;
7fd59977 212
63bcc448 213 if (myCStructure->Priority != myCStructure->PreviousPriority)
214 {
215 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
216 || (myCStructure->Priority < Structure_MIN_PRIORITY),
217 "Bad value for StructurePriority");
218 if (myCStructure->stick)
219 {
220 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
221 }
7fd59977 222 }
7fd59977 223}
224
63bcc448 225//=============================================================================
226//function : ResetDisplayPriority
227//purpose :
228//=============================================================================
229void Graphic3d_Structure::ResetDisplayPriority()
230{
231 if (IsDeleted()
232 || myCStructure->Priority == myCStructure->PreviousPriority)
233 {
234 return;
7fd59977 235 }
236
63bcc448 237 const Standard_Integer aPriority = myCStructure->Priority;
238 myCStructure->Priority = myCStructure->PreviousPriority;
239 if (myCStructure->stick)
240 {
241 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
242 }
7fd59977 243}
7fd59977 244
63bcc448 245//=============================================================================
246//function : DisplayPriority
247//purpose :
248//=============================================================================
249Standard_Integer Graphic3d_Structure::DisplayPriority() const
250{
251 return myCStructure->Priority;
7fd59977 252}
253
63bcc448 254//=============================================================================
255//function : Erase
256//purpose :
257//=============================================================================
258void Graphic3d_Structure::Erase()
259{
260 if (IsDeleted())
261 {
262 return;
7fd59977 263 }
264
63bcc448 265 if (myCStructure->stick)
266 {
267 myCStructure->stick = 0;
268 myStructureManager->Erase (this);
269 }
7fd59977 270}
271
63bcc448 272//=============================================================================
273//function : Highlight
274//purpose :
275//=============================================================================
a1954302 276void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod theMethod,
277 const Quantity_Color& theColor,
278 const Standard_Boolean theToUpdateMgr)
63bcc448 279{
280 if (IsDeleted())
281 {
282 return;
283 }
7fd59977 284
a1954302 285 myHighlightColor = theColor;
286
81bba717 287 // Highlight on already Highlighted structure.
63bcc448 288 if (myCStructure->highlight)
289 {
290 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
291 if (anUpdateMode == Aspect_TOU_WAIT)
292 {
293 UnHighlight();
294 }
295 else
296 {
297 // To avoid call of method : Update()
81bba717 298 // Not useful and can be costly.
63bcc448 299 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
300 UnHighlight();
301 myStructureManager->SetUpdateMode (anUpdateMode);
7fd59977 302 }
303 }
304
63bcc448 305 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
7fd59977 306
63bcc448 307 GraphicHighlight (theMethod);
7fd59977 308
a1954302 309 if (!theToUpdateMgr)
63bcc448 310 {
311 return;
312 }
7fd59977 313
a1954302 314 if (myCStructure->stick)
63bcc448 315 {
a1954302 316 myStructureManager->Highlight (this, theMethod);
7fd59977 317 }
318
a1954302 319 Update();
7fd59977 320}
321
63bcc448 322//=============================================================================
323//function : SetVisible
324//purpose :
325//=============================================================================
326void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
327{
328 if (IsDeleted()) return;
7fd59977 329
a1954302 330 const unsigned isVisible = theValue ? 1 : 0;
331 if (myCStructure->visible == isVisible)
63bcc448 332 {
a1954302 333 return;
63bcc448 334 }
a1954302 335
336 myCStructure->visible = isVisible;
337 myCStructure->OnVisibilityChanged();
50d06d8f 338 Update (true);
7fd59977 339}
340
63bcc448 341//=============================================================================
342//function : UnHighlight
343//purpose :
344//=============================================================================
345void Graphic3d_Structure::UnHighlight()
346{
347 if (IsDeleted()) return;
7fd59977 348
63bcc448 349 if (myCStructure->highlight)
350 {
351 myCStructure->highlight = 0;
7fd59977 352
63bcc448 353 GraphicUnHighlight();
354 myStructureManager->UnHighlight (this);
7fd59977 355
7fd59977 356 ResetDisplayPriority();
63bcc448 357 Update();
7fd59977 358 }
7fd59977 359}
360
63bcc448 361//=============================================================================
362//function : HighlightColor
363//purpose :
364//=============================================================================
365const Quantity_Color& Graphic3d_Structure::HighlightColor() const
366{
367 return myHighlightColor;
7fd59977 368}
369
63bcc448 370//=============================================================================
371//function : IsDisplayed
372//purpose :
373//=============================================================================
374Standard_Boolean Graphic3d_Structure::IsDisplayed() const
375{
376 return myCStructure->stick ? Standard_True : Standard_False;
7fd59977 377}
378
63bcc448 379//=============================================================================
380//function : IsDeleted
381//purpose :
382//=============================================================================
383Standard_Boolean Graphic3d_Structure::IsDeleted() const
384{
385 return myCStructure.IsNull();
7fd59977 386}
387
63bcc448 388//=============================================================================
389//function : IsHighlighted
390//purpose :
391//=============================================================================
392Standard_Boolean Graphic3d_Structure::IsHighlighted() const
393{
394 return myCStructure->highlight ? Standard_True : Standard_False;
7fd59977 395}
396
63bcc448 397//=============================================================================
63bcc448 398//function : IsVisible
399//purpose :
400//=============================================================================
401Standard_Boolean Graphic3d_Structure::IsVisible() const
402{
403 return myCStructure->visible ? Standard_True : Standard_False;
7fd59977 404}
405
63bcc448 406//=============================================================================
63bcc448 407//function : IsTransformed
408//purpose :
409//=============================================================================
410Standard_Boolean Graphic3d_Structure::IsTransformed() const
411{
1f7f5a90 412 return !myCStructure->Transformation().IsNull()
413 && myCStructure->Transformation()->Form() != gp_Identity;
7fd59977 414}
415
63bcc448 416//=============================================================================
417//function : ContainsFacet
418//purpose :
419//=============================================================================
420Standard_Boolean Graphic3d_Structure::ContainsFacet() const
421{
422 if (IsDeleted())
423 {
424 return Standard_False;
425 }
426 else if (myCStructure->ContainsFacet > 0)
427 {
428 // if one of groups contains at least one facet, the structure contains it too
429 return Standard_True;
430 }
7fd59977 431
63bcc448 432 // stop at the first descendant containing at least one facet
602d1ead 433 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
63bcc448 434 {
602d1ead 435 if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet())
63bcc448 436 {
437 return Standard_True;
438 }
439 }
440 return Standard_False;
7fd59977 441}
442
63bcc448 443//=============================================================================
444//function : IsEmpty
445//purpose :
446//=============================================================================
447Standard_Boolean Graphic3d_Structure::IsEmpty() const
448{
449 if (IsDeleted())
450 {
451 return Standard_True;
452 }
7fd59977 453
63bcc448 454 // structure is empty:
455 // - if all these groups are empty
456 // - or if all groups are empty and all their descendants are empty
457 // - or if all its descendants are empty
b64d84be 458 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
63bcc448 459 {
b64d84be 460 if (!aGroupIter.Value()->IsEmpty())
63bcc448 461 {
462 return Standard_False;
463 }
464 }
7fd59977 465
63bcc448 466 // stop at the first non-empty descendant
602d1ead 467 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
63bcc448 468 {
602d1ead 469 if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty())
63bcc448 470 {
471 return Standard_False;
472 }
473 }
474 return Standard_True;
7fd59977 475}
476
63bcc448 477//=============================================================================
63bcc448 478//function : GroupsWithFacet
479//purpose :
480//=============================================================================
481void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
482{
483 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
484 if (myCStructure->ContainsFacet < 0)
485 {
486 myCStructure->ContainsFacet = 0;
487 }
7fd59977 488}
489
63bcc448 490//=============================================================================
491//function : Compute
492//purpose :
493//=============================================================================
eb4320f2 494void Graphic3d_Structure::Compute()
495{
496 // Implemented by Presentation
497}
498
63bcc448 499//=============================================================================
500//function : Compute
501//purpose :
502//=============================================================================
503Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
504{
7fd59977 505 // Implemented by Presentation
506 return this;
507}
508
63bcc448 509//=============================================================================
510//function : Compute
511//purpose :
512//=============================================================================
513Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
1f7f5a90 514 const Handle(Geom_Transformation)& )
63bcc448 515{
7fd59977 516 // Implemented by Presentation
517 return this;
518}
519
63bcc448 520//=============================================================================
521//function : Compute
522//purpose :
523//=============================================================================
524void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
525 Handle(Graphic3d_Structure)& )
526{
7fd59977 527 // Implemented by Presentation
528}
529
63bcc448 530//=============================================================================
531//function : Compute
532//purpose :
533//=============================================================================
534void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
1f7f5a90 535 const Handle(Geom_Transformation)& ,
63bcc448 536 Handle(Graphic3d_Structure)& )
537{
7fd59977 538 // Implemented by Presentation
539}
540
63bcc448 541//=============================================================================
542//function : ReCompute
543//purpose :
544//=============================================================================
545void Graphic3d_Structure::ReCompute()
546{
547 myStructureManager->ReCompute (this);
7fd59977 548}
549
63bcc448 550//=============================================================================
551//function : ReCompute
552//purpose :
553//=============================================================================
554void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
555{
556 myStructureManager->ReCompute (this, theProjector);
7fd59977 557}
558
197ac94e 559//=============================================================================
560//function : SetInfiniteState
561//purpose :
562//=============================================================================
563void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
564{
63bcc448 565 myCStructure->IsInfinite = theToSet ? 1 : 0;
7fd59977 566}
567
63bcc448 568//=============================================================================
569//function : IsInfinite
570//purpose :
571//=============================================================================
572Standard_Boolean Graphic3d_Structure::IsInfinite() const
573{
574 return IsDeleted()
575 || myCStructure->IsInfinite;
7fd59977 576}
577
63bcc448 578//=============================================================================
579//function : GraphicClear
580//purpose :
581//=============================================================================
582void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
5e27df78 583{
b64d84be 584 if (myCStructure.IsNull())
5e27df78 585 {
b64d84be 586 return;
5e27df78 587 }
7fd59977 588
b64d84be 589 // clean and empty each group
590 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
5e27df78 591 {
b64d84be 592 aGroupIter.ChangeValue()->Clear();
593 }
594 if (!theWithDestruction)
595 {
596 return;
597 }
7fd59977 598
b64d84be 599 while (!myCStructure->Groups().IsEmpty())
600 {
601 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
602 aGroup->Remove();
7fd59977 603 }
b64d84be 604 myCStructure->Clear();
7fd59977 605}
606
63bcc448 607//=============================================================================
608//function : GraphicConnect
609//purpose :
610//=============================================================================
bf75be98 611void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
612{
63bcc448 613 myCStructure->Connect (*theDaughter->myCStructure);
7fd59977 614}
615
63bcc448 616//=============================================================================
617//function : GraphicDisconnect
618//purpose :
619//=============================================================================
bf75be98 620void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
621{
63bcc448 622 myCStructure->Disconnect (*theDaughter->myCStructure);
7fd59977 623}
624
63bcc448 625//=============================================================================
63bcc448 626//function : Groups
627//purpose :
628//=============================================================================
629const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
630{
b64d84be 631 return myCStructure->Groups();
7fd59977 632}
633
63bcc448 634//=============================================================================
635//function : NumberOfGroups
636//purpose :
637//=============================================================================
638Standard_Integer Graphic3d_Structure::NumberOfGroups() const
639{
b64d84be 640 return myCStructure->Groups().Length();
7fd59977 641}
642
63bcc448 643//=============================================================================
63bcc448 644//function : SetVisual
645//purpose :
646//=============================================================================
647void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
648{
649 if (IsDeleted()
650 || myVisual == theVisual)
651 {
652 return;
7fd59977 653 }
7fd59977 654
63bcc448 655 if (!myCStructure->stick)
656 {
657 myVisual = theVisual;
658 SetComputeVisual (theVisual);
659 }
660 else
661 {
662 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
663 if (anUpdateMode == Aspect_TOU_WAIT)
664 {
665 Erase();
666 myVisual = theVisual;
667 SetComputeVisual (theVisual);
668 Display();
7fd59977 669 }
670 else {
81bba717 671 // To avoid calling method : Update ()
672 // Not useful and can be costly.
63bcc448 673 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
674 Erase();
675 myVisual = theVisual;
676 SetComputeVisual (theVisual);
677 myStructureManager->SetUpdateMode (anUpdateMode);
678 Display();
7fd59977 679 }
680 }
7fd59977 681}
682
63bcc448 683//=============================================================================
684//function : SetZoomLimit
685//purpose :
686//=============================================================================
687void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
688 const Standard_Real theLimitSup)
689{
690 (void )theLimitInf;
691 (void )theLimitSup;
692 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
693 "Bad value for ZoomLimit inf");
694 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
695 "Bad value for ZoomLimit sup");
696 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
697 "ZoomLimit sup < ZoomLimit inf");
7fd59977 698}
699
63bcc448 700//=============================================================================
701//function : Visual
702//purpose :
703//=============================================================================
704Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
705{
706 return myVisual;
7fd59977 707}
708
63bcc448 709//=============================================================================
710//function : AcceptConnection
711//purpose :
712//=============================================================================
713Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
714 const Handle(Graphic3d_Structure)& theStructure2,
715 const Graphic3d_TypeOfConnection theType)
716{
7fd59977 717 // cycle detection
63bcc448 718 Graphic3d_MapOfStructure aSet;
719 Graphic3d_Structure::Network (theStructure2, theType, aSet);
720 return !aSet.Contains (theStructure1);
7fd59977 721}
722
63bcc448 723//=============================================================================
724//function : Ancestors
725//purpose :
726//=============================================================================
727void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
728{
602d1ead 729 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next())
63bcc448 730 {
602d1ead 731 theSet.Add ((Graphic3d_Structure* )anIter.Value());
63bcc448 732 }
7fd59977 733}
734
63bcc448 735//=============================================================================
736//function : SetOwner
737//purpose :
738//=============================================================================
739void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
740{
741 myOwner = theOwner;
7fd59977 742}
743
63bcc448 744//=============================================================================
745//function : Owner
746//purpose :
747//=============================================================================
748Standard_Address Graphic3d_Structure::Owner() const
749{
750 return myOwner;
7fd59977 751}
752
63bcc448 753//=============================================================================
754//function : Descendants
755//purpose :
756//=============================================================================
757void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
758{
602d1ead 759 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
63bcc448 760 {
602d1ead 761 theSet.Add ((Graphic3d_Structure* )anIter.Value());
63bcc448 762 }
7fd59977 763}
764
63bcc448 765//=============================================================================
602d1ead 766//function : AppendAncestor
d4aaad5b 767//purpose :
768//=============================================================================
602d1ead 769Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor)
d4aaad5b 770{
602d1ead 771 const Standard_Integer aSize = myAncestors.Size();
d4aaad5b 772
602d1ead 773 return myAncestors.Add (theAncestor) > aSize; // new object
d4aaad5b 774}
775
776//=============================================================================
602d1ead 777//function : AppendDescendant
d4aaad5b 778//purpose :
779//=============================================================================
602d1ead 780Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant)
d4aaad5b 781{
602d1ead 782 const Standard_Integer aSize = myDescendants.Size();
d4aaad5b 783
602d1ead 784 return myDescendants.Add (theDescendant) > aSize; // new object
d4aaad5b 785}
786
787//=============================================================================
602d1ead 788//function : RemoveAncestor
d4aaad5b 789//purpose :
790//=============================================================================
602d1ead 791Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor)
d4aaad5b 792{
602d1ead 793 const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor);
794
795 if (anIndex != 0)
d4aaad5b 796 {
602d1ead 797 myAncestors.Swap (anIndex, myAncestors.Size());
798 myAncestors.RemoveLast();
d4aaad5b 799 }
800
602d1ead 801 return anIndex != 0; // object was found
d4aaad5b 802}
803
804//=============================================================================
602d1ead 805//function : RemoveDescendant
d4aaad5b 806//purpose :
807//=============================================================================
602d1ead 808Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant)
d4aaad5b 809{
602d1ead 810 const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant);
d4aaad5b 811
602d1ead 812 if (anIndex != 0)
d4aaad5b 813 {
602d1ead 814 myDescendants.Swap (anIndex, myDescendants.Size());
815 myDescendants.RemoveLast();
d4aaad5b 816 }
817
602d1ead 818 return anIndex != 0; // object was found
d4aaad5b 819}
820
821//=============================================================================
63bcc448 822//function : Connect
823//purpose :
824//=============================================================================
825void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
826 const Graphic3d_TypeOfConnection theType,
827 const Standard_Boolean theWithCheck)
828{
d4aaad5b 829 if (IsDeleted())
830 {
831 return;
832 }
7fd59977 833
63bcc448 834 // cycle detection
835 if (theWithCheck
836 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
7fd59977 837 {
63bcc448 838 return;
839 }
7fd59977 840
d4aaad5b 841 const Standard_Address aStructure = theStructure.operator->();
842
843 if (theType == Graphic3d_TOC_DESCENDANT)
63bcc448 844 {
d4aaad5b 845 if (!AppendDescendant (aStructure))
7fd59977 846 {
d4aaad5b 847 return;
848 }
7fd59977 849
d4aaad5b 850 CalculateBoundBox();
851 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
7fd59977 852
d4aaad5b 853 GraphicConnect (theStructure);
854 myStructureManager->Connect (this, theStructure);
7fd59977 855
50d06d8f 856 Update (true);
d4aaad5b 857 }
858 else // Graphic3d_TOC_ANCESTOR
859 {
860 if (!AppendAncestor (aStructure))
861 {
63bcc448 862 return;
7fd59977 863 }
63bcc448 864
d4aaad5b 865 CalculateBoundBox();
866 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
63bcc448 867
d4aaad5b 868 // myStructureManager->Connect is called in case if connection between parent and child
7fd59977 869 }
7fd59977 870}
871
63bcc448 872//=============================================================================
873//function : Disconnect
874//purpose :
875//=============================================================================
876void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
877{
d4aaad5b 878 if (IsDeleted())
63bcc448 879 {
d4aaad5b 880 return;
881 }
7fd59977 882
d4aaad5b 883 const Standard_Address aStructure = theStructure.operator->();
7fd59977 884
d4aaad5b 885 if (RemoveDescendant (aStructure))
886 {
887 theStructure->Disconnect (this);
b7cd4ba7 888
d4aaad5b 889 GraphicDisconnect (theStructure);
890 myStructureManager->Disconnect (this, theStructure);
7fd59977 891
d4aaad5b 892 CalculateBoundBox();
50d06d8f 893 Update (true);
d4aaad5b 894 }
895 else if (RemoveAncestor (aStructure))
63bcc448 896 {
d4aaad5b 897 theStructure->Disconnect (this);
898 CalculateBoundBox();
899
900 // no call of myStructureManager->Disconnect in case of an ancestor
7fd59977 901 }
7fd59977 902}
903
63bcc448 904//=============================================================================
905//function : DisconnectAll
906//purpose :
907//=============================================================================
908void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
909{
910 if (IsDeleted()) return;
7fd59977 911
63bcc448 912 switch (theType)
7fd59977 913 {
63bcc448 914 case Graphic3d_TOC_DESCENDANT:
915 {
602d1ead 916 for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx)
63bcc448 917 {
918 // Value (1) instead of Value (i) as myDescendants
919 // is modified by :
920 // Graphic3d_Structure::Disconnect (AStructure)
921 // that takes AStructure from myDescendants
602d1ead 922 ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this);
63bcc448 923 }
924 break;
925 }
926 case Graphic3d_TOC_ANCESTOR:
927 {
602d1ead 928 for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx)
63bcc448 929 {
930 // Value (1) instead of Value (i) as myAncestors
931 // is modified by :
932 // Graphic3d_Structure::Disconnect (AStructure)
933 // that takes AStructure from myAncestors
602d1ead 934 ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this);
63bcc448 935 }
936 break;
937 }
7fd59977 938 }
7fd59977 939}
940
63bcc448 941//=============================================================================
63bcc448 942//function : SetTransform
943//purpose :
944//=============================================================================
1f7f5a90 945void Graphic3d_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf)
63bcc448 946{
947 if (IsDeleted()) return;
7fd59977 948
1f7f5a90 949 const Standard_Boolean wasTransformed = IsTransformed();
950
951 if (!theTrsf.IsNull()
952 && theTrsf->Trsf().Form() == gp_Identity)
63bcc448 953 {
1f7f5a90 954 myCStructure->SetTransformation (Handle(Geom_Transformation)());
7fd59977 955 }
1f7f5a90 956 else
63bcc448 957 {
1f7f5a90 958 myCStructure->SetTransformation (theTrsf);
7fd59977 959 }
960
63bcc448 961 // If transformation, no validation of hidden already calculated parts
6bd94e0d 962 if (IsTransformed() || (!IsTransformed() && wasTransformed))
63bcc448 963 {
964 ReCompute();
965 }
7fd59977 966
1f7f5a90 967 myStructureManager->SetTransform (this, theTrsf);
7fd59977 968
50d06d8f 969 Update (true);
7fd59977 970}
971
63bcc448 972//=============================================================================
197ac94e 973//function : MinMaxValues
974//purpose :
975//=============================================================================
ed063270 976Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
197ac94e 977{
b7cd4ba7 978 Graphic3d_BndBox4d aBox;
ed063270 979 Bnd_Box aResult;
b7cd4ba7 980 addTransformed (aBox, theToIgnoreInfiniteFlag);
ed063270 981 if (aBox.IsValid())
197ac94e 982 {
ed063270 983 aResult.Add (gp_Pnt (aBox.CornerMin().x(),
984 aBox.CornerMin().y(),
985 aBox.CornerMin().z()));
986 aResult.Add (gp_Pnt (aBox.CornerMax().x(),
987 aBox.CornerMax().y(),
988 aBox.CornerMax().z()));
989
990 Standard_Real aLimMin = ShortRealFirst() + 1.0;
991 Standard_Real aLimMax = ShortRealLast() - 1.0;
992 gp_Pnt aMin = aResult.CornerMin();
993 gp_Pnt aMax = aResult.CornerMax();
994 if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin &&
995 aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
996 {
997 //For structure which infinite in all three dimensions the Whole bounding box will be returned
998 aResult.SetWhole();
999 }
197ac94e 1000 }
ed063270 1001 return aResult;
7fd59977 1002}
1003
63bcc448 1004//=============================================================================
1005//function : Identification
1006//purpose :
1007//=============================================================================
1008Standard_Integer Graphic3d_Structure::Identification() const
1009{
1010 return myCStructure->Id;
7fd59977 1011}
1012
63bcc448 1013//=============================================================================
1014//function : SetTransformPersistence
1015//purpose :
1016//=============================================================================
778cd667 1017void Graphic3d_Structure::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
7fd59977 1018{
778cd667 1019 if (IsDeleted())
1020 {
1021 return;
1022 }
7fd59977 1023
778cd667 1024 myCStructure->SetTransformPersistence (theTrsfPers);
7fd59977 1025}
1026
63bcc448 1027//=============================================================================
63bcc448 1028//function : Remove
1029//purpose :
1030//=============================================================================
1031void Graphic3d_Structure::Remove (const Standard_Address thePtr,
1032 const Graphic3d_TypeOfConnection theType)
1033{
d4aaad5b 1034 if (theType == Graphic3d_TOC_DESCENDANT)
7fd59977 1035 {
d4aaad5b 1036 RemoveDescendant (thePtr);
1037 }
1038 else
1039 {
1040 RemoveAncestor (thePtr);
7fd59977 1041 }
7fd59977 1042}
1043
63bcc448 1044//=============================================================================
b64d84be 1045//function : NewGroup
1046//purpose :
1047//=============================================================================
1048Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1049{
1050 return myCStructure->NewGroup (this);
1051}
1052
1053//=============================================================================
63bcc448 1054//function : Remove
1055//purpose :
1056//=============================================================================
1057void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1058{
b64d84be 1059 if (theGroup.IsNull()
1060 || theGroup->myStructure != this)
63bcc448 1061 {
b64d84be 1062 return;
63bcc448 1063 }
b64d84be 1064
1065 myCStructure->RemoveGroup (theGroup);
1066 theGroup->myStructure = NULL;
7fd59977 1067}
1068
63bcc448 1069//=============================================================================
1070//function : StructureManager
1071//purpose :
1072//=============================================================================
1073Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1074{
1075 return myStructureManager;
7fd59977 1076}
1077
197ac94e 1078//=============================================================================
b7cd4ba7 1079//function : minMaxCoord
197ac94e 1080//purpose :
1081//=============================================================================
8d3aa19e 1082Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
197ac94e 1083{
b7cd4ba7 1084 Graphic3d_BndBox4f aBnd;
b64d84be 1085 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
197ac94e 1086 {
8d3aa19e 1087 aBnd.Combine (aGroupIter.Value()->BoundingBox());
197ac94e 1088 }
b7cd4ba7 1089 return aBnd;
197ac94e 1090}
1091
1092//=============================================================================
b7cd4ba7 1093//function : addTransformed
197ac94e 1094//purpose :
1095//=============================================================================
0717ddc1 1096void Graphic3d_Structure::getBox (Graphic3d_BndBox4d& theBox,
1097 const Standard_Boolean theToIgnoreInfiniteFlag) const
197ac94e 1098{
8d3aa19e 1099 Graphic3d_BndBox4f aBoxF = minMaxCoord();
b7cd4ba7 1100 if (aBoxF.IsValid())
197ac94e 1101 {
0717ddc1 1102 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
1103 (Standard_Real )aBoxF.CornerMin().y(),
1104 (Standard_Real )aBoxF.CornerMin().z(),
1105 (Standard_Real )aBoxF.CornerMin().w()),
1106 Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMax().x(),
1107 (Standard_Real )aBoxF.CornerMax().y(),
1108 (Standard_Real )aBoxF.CornerMax().z(),
1109 (Standard_Real )aBoxF.CornerMax().w()));
b7cd4ba7 1110 if (IsInfinite()
1111 && !theToIgnoreInfiniteFlag)
197ac94e 1112 {
0717ddc1 1113 const Graphic3d_Vec4d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
b7cd4ba7 1114 if (aDiagVec.xyz().SquareModulus() >= 500000.0 * 500000.0)
1115 {
1116 // bounding borders of infinite line has been calculated as own point in center of this line
0717ddc1 1117 theBox = Graphic3d_BndBox4d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
b7cd4ba7 1118 }
1119 else
1120 {
1121 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d (RealFirst(), RealFirst(), RealFirst(), 1.0),
1122 Graphic3d_Vec4d (RealLast(), RealLast(), RealLast(), 1.0));
1123 return;
1124 }
197ac94e 1125 }
197ac94e 1126 }
0717ddc1 1127}
1128
1129//=============================================================================
1130//function : addTransformed
1131//purpose :
1132//=============================================================================
1133void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox,
1134 const Standard_Boolean theToIgnoreInfiniteFlag) const
1135{
1136 Graphic3d_BndBox4d aCombinedBox, aBox;
1137 getBox (aCombinedBox, theToIgnoreInfiniteFlag);
7fd59977 1138
602d1ead 1139 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
197ac94e 1140 {
602d1ead 1141 const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value();
0717ddc1 1142 aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1143 aCombinedBox.Combine (aBox);
197ac94e 1144 }
7fd59977 1145
0717ddc1 1146 aBox = aCombinedBox;
b7cd4ba7 1147 if (aBox.IsValid())
197ac94e 1148 {
1f7f5a90 1149 if (!myCStructure->Transformation().IsNull())
1150 {
1151 TransformBoundaries (myCStructure->Transformation()->Trsf(),
1152 aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1153 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1154 }
0717ddc1 1155
1156 // if box is still valid after transformation
1157 if (aBox.IsValid())
1158 {
1159 theBox.Combine (aBox);
1160 }
1161 else // it was infinite, return untransformed
1162 {
1163 theBox.Combine (aCombinedBox);
1164 }
7fd59977 1165 }
7fd59977 1166}
1167
63bcc448 1168//=============================================================================
1169//function : Transforms
1170//purpose :
1171//=============================================================================
1f7f5a90 1172void Graphic3d_Structure::Transforms (const gp_Trsf& theTrsf,
63bcc448 1173 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
1174 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
1175{
1176 const Standard_Real aRL = RealLast();
1177 const Standard_Real aRF = RealFirst();
1f7f5a90 1178 theNewX = theX;
1179 theNewY = theY;
1180 theNewZ = theZ;
63bcc448 1181 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1182 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1183 {
1f7f5a90 1184 return;
7fd59977 1185 }
7fd59977 1186
1f7f5a90 1187 theTrsf.Transforms (theNewX, theNewY, theNewZ);
7fd59977 1188}
1189
197ac94e 1190//=============================================================================
1191//function : Transforms
1192//purpose :
1193//=============================================================================
1f7f5a90 1194void Graphic3d_Structure::TransformBoundaries (const gp_Trsf& theTrsf,
197ac94e 1195 Standard_Real& theXMin,
1196 Standard_Real& theYMin,
1197 Standard_Real& theZMin,
1198 Standard_Real& theXMax,
1199 Standard_Real& theYMax,
1200 Standard_Real& theZMax)
1201{
1202 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1203
1204 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1205 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1206
1207 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1208 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1209 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1210 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1211
1212 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
1213 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1214 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1215 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1216
1217 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
1218 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1219 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1220 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1221
1222 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
1223 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1224 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1225 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1226
1227 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
1228 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1229 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1230 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1231
1232 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
1233 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1234 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1235 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1236
1237 theXMin = aXMin;
1238 theYMin = aYMin;
1239 theZMin = aZMin;
1240 theXMax = aXMax;
1241 theYMax = aYMax;
1242 theZMax = aZMax;
1243}
1244
63bcc448 1245//=============================================================================
1246//function : Network
1247//purpose :
1248//=============================================================================
1249void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
1250 const Graphic3d_TypeOfConnection theType,
1251 Graphic3d_MapOfStructure& theSet)
1252{
1253 Graphic3d_MapOfStructure aSetD, aSetA;
1254 theStructure->Descendants (aSetD);
1255 theStructure->Ancestors (aSetA);
1256 theSet.Add (theStructure);
1257 switch (theType)
7fd59977 1258 {
63bcc448 1259 case Graphic3d_TOC_DESCENDANT:
1260 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
1261 {
1262 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
1263 }
1264 break;
1265 case Graphic3d_TOC_ANCESTOR:
1266 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
1267 {
1268 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
1269 }
1270 break;
7fd59977 1271 }
7fd59977 1272}
1273
63bcc448 1274//=============================================================================
1275//function : PrintNetwork
1276//purpose :
1277//=============================================================================
1278void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
1279 const Graphic3d_TypeOfConnection theType)
7fd59977 1280{
63bcc448 1281 Graphic3d_MapOfStructure aSet;
1282 Graphic3d_Structure::Network (theStructure, theType, aSet);
1283 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
1284 {
1285 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
7fd59977 1286 }
63bcc448 1287 std::cout << std::flush;
7fd59977 1288}
1289
63bcc448 1290//=============================================================================
1291//function : Update
1292//purpose :
1293//=============================================================================
50d06d8f 1294void Graphic3d_Structure::Update (const bool theUpdateLayer) const
7fd59977 1295{
63bcc448 1296 if (IsDeleted())
1297 {
1298 return;
1299 }
7fd59977 1300
50d06d8f 1301 myStructureManager->Update (myStructureManager->UpdateMode(),
1302 theUpdateLayer ? myCStructure->ZLayer() : Graphic3d_ZLayerId_UNKNOWN);
63bcc448 1303}
7fd59977 1304
63bcc448 1305//=============================================================================
63bcc448 1306//function : GraphicHighlight
1307//purpose :
1308//=============================================================================
1309void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod theMethod)
1310{
63bcc448 1311 myCStructure->highlight = 1;
1312 myHighlightMethod = theMethod;
1313 switch (theMethod)
7fd59977 1314 {
63bcc448 1315 case Aspect_TOHM_COLOR:
1316 {
b6472664 1317 myCStructure->HighlightWithColor (myHighlightColor, Standard_True);
63bcc448 1318 break;
1319 }
1320 case Aspect_TOHM_BOUNDBOX:
1321 {
b6472664 1322 myCStructure->HighlightColor = myHighlightColor;
b64d84be 1323 myCStructure->HighlightWithBndBox (this, Standard_True);
63bcc448 1324 break;
1325 }
7fd59977 1326 }
7fd59977 1327}
1328
63bcc448 1329//=============================================================================
1330//function : GraphicTransform
1331//purpose :
1332//=============================================================================
1f7f5a90 1333void Graphic3d_Structure::GraphicTransform (const Handle(Geom_Transformation)& theTrsf)
63bcc448 1334{
1f7f5a90 1335 myCStructure->SetTransformation (theTrsf);
7fd59977 1336}
1337
63bcc448 1338//=============================================================================
1339//function : GraphicUnHighlight
1340//purpose :
1341//=============================================================================
1342void Graphic3d_Structure::GraphicUnHighlight()
1343{
1344 myCStructure->highlight = 0;
1345 switch (myHighlightMethod)
1346 {
1347 case Aspect_TOHM_COLOR:
1348 myCStructure->HighlightWithColor (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f), Standard_False);
63bcc448 1349 break;
1350 case Aspect_TOHM_BOUNDBOX:
b64d84be 1351 myCStructure->HighlightWithBndBox (this, Standard_False);
63bcc448 1352 break;
1353 }
7fd59977 1354}
1355
63bcc448 1356//=============================================================================
1357//function : ComputeVisual
1358//purpose :
1359//=============================================================================
1360Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
1361{
1362 return myComputeVisual;
7fd59977 1363}
1364
63bcc448 1365//=============================================================================
1366//function : SetComputeVisual
1367//purpose :
1368//=============================================================================
1369void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
35e08fe8 1370{
63bcc448 1371 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
1372 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
1373 if (theVisual != Graphic3d_TOS_COMPUTED)
1374 {
1375 myComputeVisual = theVisual;
7fd59977 1376 }
7fd59977 1377}
1378
63bcc448 1379//=============================================================================
63bcc448 1380//function : SetHLRValidation
1381//purpose :
1382//=============================================================================
1383void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
1384{
1385 myCStructure->HLRValidation = theFlag ? 1 : 0;
1386}
7fd59977 1387
63bcc448 1388//=============================================================================
1389//function : HLRValidation
1390//purpose :
1391//=============================================================================
1392Standard_Boolean Graphic3d_Structure::HLRValidation() const
1393{
81bba717 1394 // Hidden parts stored in <me> are valid if :
1395 // 1/ the owner is defined.
1396 // 2/ they are not invalid.
63bcc448 1397 return myOwner != NULL
1398 && myCStructure->HLRValidation != 0;
7fd59977 1399}
1400
bf75be98 1401//=======================================================================
59f45b7c 1402//function : SetZLayer
1403//purpose :
1404//=======================================================================
a1954302 1405void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId)
59f45b7c 1406{
1407 // if the structure is not displayed, unable to change its display layer
1408 if (IsDeleted ())
1409 return;
1410
63bcc448 1411 myStructureManager->ChangeZLayer (this, theLayerId);
a1954302 1412 myCStructure->SetZLayer (theLayerId);
59f45b7c 1413}
1414
1415//=======================================================================
1416//function : GetZLayer
1417//purpose :
1418//=======================================================================
a1954302 1419Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const
59f45b7c 1420{
a1954302 1421 return myCStructure->ZLayer();
59f45b7c 1422}
4269bd1b 1423
1424//=======================================================================
1425//function : SetClipPlanes
1426//purpose :
1427//=======================================================================
3202bf1e 1428void Graphic3d_Structure::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
4269bd1b 1429{
63bcc448 1430 myCStructure->SetClipPlanes (thePlanes);
4269bd1b 1431}
1432
1433//=======================================================================
1434//function : GetClipPlanes
1435//purpose :
1436//=======================================================================
3202bf1e 1437const Handle(Graphic3d_SequenceOfHClipPlane)& Graphic3d_Structure::ClipPlanes() const
4269bd1b 1438{
63bcc448 1439 return myCStructure->ClipPlanes();
4269bd1b 1440}
b7cd4ba7 1441
1442//=======================================================================
1443//function : SetMutable
1444//purpose :
1445//=======================================================================
1446void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
1447{
1448 myCStructure->IsMutable = theIsMutable;
1449}
1450
1451//=======================================================================
1452//function : IsMutable
1453//purpose :
1454//=======================================================================
1455Standard_Boolean Graphic3d_Structure::IsMutable() const
1456{
1457 return myCStructure->IsMutable;
1458}