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