6d580f1dd0d419a33a9a407f571f57539e005e81
[occt.git] / src / Graphic3d / Graphic3d_Structure.cxx
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.
42 //      30/11/98 ; FMN : S4069. Textes always visible.
43 //      22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets
44
45 #define G003    //EUG 26/01/00 Degeneration management
46
47 #define BUC60918        //GG 31/05/01 A transparente structure priority must have the
48 //                      MAX_PRIORITY value so, the highlighted structure must have
49 //                      MAX_PRIORITY-1 value.
50 //                      Add ResetDisplayPriority() method.
51
52 #define OCC1174 // SAV 08/01/03 Added back face interior color controling
53
54
55 //
56 //-Copyright    MatraDatavision 1991,1992,1993,1994,1995
57
58 //-Version
59
60 //-Design       Declaration of variables specific to graphic structures
61
62 //-Warning      A structure is defined in a manager
63 //              This is a sequence of groups of primitives
64
65 //-References
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
95 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
96 #include <Aspect_PolygonOffsetMode.hxx>
97 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
98
99 //-Aliases
100
101 //-Global data definitions
102
103 //-Constructors
104
105 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& AManager):
106 MyGroupGenId (Group_IDMIN, Group_IDMAX),
107 MyAncestors (),
108 MyDescendants (),
109 MyGroups (),
110 MyHighlightColor (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
126   // Return default values
127   AManager->PrimitivesAspect (aAspectLine3d, aAspectText3d,
128     aAspectMarker3d, aAspectFillArea3d);
129
130   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
131   // It is necessary to set default polygon offsets for a new presentation
132   aAspectFillArea3d->SetPolygonOffsets( Aspect_POM_Fill, 1., 0. );
133   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
134
135   // Update the associated CStructure
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
204 void 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,
211   // avoid attempts to access it
212   MyFirstPtrStructureManager = 0;
213   Remove ();
214
215 }
216
217 //-Methods, in order
218
219 void Graphic3d_Structure::Clear (const Standard_Boolean WithDestruction)
220 {
221   if (IsDeleted()) return;
222
223   MyCStructure.ContainsFacet = 0;
224
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();
232   }
233   GraphicClear (WithDestruction);
234
235   // only then remove group references
236   if (WithDestruction)
237   {
238     MyGroupGenId.Free();
239     MyGroups.Clear();
240   }
241
242   MyStructureManager->Clear (this, WithDestruction);
243
244   Update();
245 }
246
247 void 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;
263
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;
269   Length = MyGroups.Length();
270   for (Standard_Integer aGrId = 1; aGrId <= Length; ++aGrId)
271     MyGroups.ChangeValue (aGrId)->Clear (Standard_False);
272
273   //        Standard_Address APtr = (void *) This ().operator->();
274   Standard_Address APtr = (void *) this;
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.
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
293   // Destruction of me in the graphic library
294   MyGraphicDriver->RemoveStructure (MyCStructure);
295
296   // Liberation of the identification if the destroyed structure
297   // in the first manager that performs creation of the structure.
298   if ( MyFirstPtrStructureManager )
299     MyFirstStructureManager->Remove (Standard_Integer (MyCStructure.Id));
300
301 }
302
303 void 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
314 void 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
327 void 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
353 void 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
370 Standard_Integer Graphic3d_Structure::DisplayPriority () const {
371
372   return Standard_Integer (MyCStructure.Priority);
373
374 }
375
376 void 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
387 void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod AMethod) {
388
389   if (IsDeleted ()) return;
390
391   // Highlight on already Highlighted structure.
392   if (MyCStructure.highlight) {
393
394     Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode ();
395     if (UpdateMode == Aspect_TOU_WAIT)
396       UnHighlight ();
397     else {
398       // To avoid call of method : Update ()
399       // Not useful and can be costly.
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
419 void Graphic3d_Structure::SetHighlightColor (const Quantity_Color& AColor) {
420
421   if (IsDeleted ()) return;
422
423   if (! MyCStructure.highlight)
424     MyHighlightColor = AColor;
425   else {
426     // Change highlight color on already Highlighted structure.
427
428     Aspect_TypeOfUpdate UpdateMode  = MyStructureManager->UpdateMode ();
429     if (UpdateMode == Aspect_TOU_WAIT)
430       UnHighlight ();
431     else {
432       // To avoid call of method : Update ()
433       // Not useful and can be costly.
434       MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
435       UnHighlight ();
436       MyStructureManager->SetUpdateMode (UpdateMode);
437     }
438     MyHighlightColor = AColor;
439     Highlight (MyHighlightMethod);
440   }
441
442 }
443
444 void 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
461 void 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
478 void 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
498 Quantity_Color Graphic3d_Structure::HighlightColor () const {
499
500   return (MyHighlightColor);
501
502 }
503
504 Standard_Boolean Graphic3d_Structure::IsDisplayed () const {
505
506   if (MyCStructure.stick)
507     return (Standard_True);
508   else
509     return (Standard_False);
510
511 }
512
513 Standard_Boolean Graphic3d_Structure::IsDeleted () const {
514
515   if (MyCStructure.IsDeleted)
516     return (Standard_True);
517   else
518     return (Standard_False);
519
520 }
521
522 Standard_Boolean Graphic3d_Structure::IsHighlighted () const {
523
524   if (MyCStructure.highlight)
525     return (Standard_True);
526   else
527     return (Standard_False);
528
529 }
530
531 Standard_Boolean Graphic3d_Structure::IsSelectable () const {
532
533   if (MyCStructure.pick)
534     return (Standard_True);
535   else
536     return (Standard_False);
537
538 }
539
540 Standard_Boolean Graphic3d_Structure::IsVisible () const {
541
542   if (MyCStructure.visible)
543     return (Standard_True);
544   else
545     return (Standard_False);
546
547 }
548
549 Standard_Boolean Graphic3d_Structure::IsRotated () const {
550
551   // A somewhat light test !
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
561 Standard_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
574   cout << "Structure " << Identification ();
575   if (Result)
576     cout << " is transformed\n" << flush;
577   else
578     cout << " is not transformed\n" << flush;
579 #endif
580
581   return Result;
582
583 }
584
585 Standard_Boolean Graphic3d_Structure::ContainsFacet () const {
586
587   if (IsDeleted ()) return (Standard_False);
588
589   // A structure contains at least one facet :
590   // if one of these groups contains at least one facet.
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
598   // If one of groups contains at least one facet, the structure contains it too.
599   if (Result1) return (Result1);
600
601   Length  = MyDescendants.Length ();
602
603   // Stop at the first descendant  containing at least one facet.
604   for (i=1; i<=Length && ! Result2; i++)
605     Result2 = ((Graphic3d_Structure *)
606     (MyDescendants.Value (i)))->ContainsFacet ();
607
608   return (Result2);
609
610 }
611
612 Standard_Boolean Graphic3d_Structure::IsEmpty () const {
613
614   if (IsDeleted ()) return (Standard_True);
615
616   // A structure is empty :
617   // if all these groups are empty or if all
618   // groups are empty and all their descendants
619   // are empty or if all its descendants are empty.
620
621   Standard_Boolean Result1   = Standard_True;
622   Standard_Integer i, Length = MyGroups.Length ();
623
624   // Stop at the first non-empty group
625   for (i=1; i<=Length && Result1; i++)
626     Result1 = (MyGroups.Value (i))->IsEmpty ();
627
628   // If a group is non-empty the structure is also non-empty.
629   if (! Result1) return (Standard_False);
630
631   Standard_Boolean Result2 = Standard_True;
632
633   Length  = MyDescendants.Length ();
634
635   // Stop at the first non-empty descendant
636   for (i=1; i<=Length && Result2; i++)
637     Result2 = ((Graphic3d_Structure *)
638     (MyDescendants.Value (i)))->IsEmpty ();
639
640   return (Result2);
641
642 }
643
644 void 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
653 void 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
665 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ) {
666
667   // Implemented by Presentation
668   return this;
669 }
670
671 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , const TColStd_Array2OfReal& ) {
672
673   // Implemented by Presentation
674   return this;
675 }
676
677 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , Handle(Graphic3d_Structure)& ) {
678
679   // Implemented by Presentation
680 }
681
682 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , const TColStd_Array2OfReal& , Handle(Graphic3d_Structure)& ) {
683
684   // Implemented by Presentation
685 }
686
687 void Graphic3d_Structure::ReCompute () {
688
689   MyStructureManager->ReCompute (this);
690
691 }
692
693 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& aProjector) {
694
695   MyStructureManager->ReCompute (this, aProjector);
696
697 }
698
699 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean AValue) {
700
701   MyCStructure.IsInfinite = AValue ? 1:0;
702
703 }
704
705 Standard_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
716 void 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
743 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& ADaughter) {
744
745   MyGraphicDriver->Connect
746     (MyCStructure, *((CALL_DEF_STRUCTURE *)ADaughter->CStructure()));
747
748 }
749
750 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& ADaughter) {
751
752   MyGraphicDriver->Disconnect
753     (MyCStructure, *((CALL_DEF_STRUCTURE *)ADaughter->CStructure()));
754
755 }
756
757 Handle(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
779 Handle(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
807 Handle(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
829 Handle(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
912   Graphic3d_TypeOfMaterial mType =
913     MyCStructure.ContextFillArea.Back.IsPhysic ?
914 Graphic3d_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(
1006     MyCStructure.ContextFillArea.DegenerationMode);
1007   Quantity_Ratio dRatio =
1008     MyCStructure.ContextFillArea.SkipRatio;
1009   CTXF->SetDegenerateModel(dMode,dRatio);
1010 #endif  // G003
1011
1012   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
1013   CTXF->SetPolygonOffsets(MyCStructure.ContextFillArea.PolygonOffsetMode,
1014     MyCStructure.ContextFillArea.PolygonOffsetFactor,
1015     MyCStructure.ContextFillArea.PolygonOffsetUnits);
1016   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
1017
1018   return CTXF;
1019
1020 }
1021
1022 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const {
1023   return MyGroups;
1024 }
1025
1026 Standard_Integer Graphic3d_Structure::NumberOfGroups () const {
1027   return (MyGroups.Length ());
1028 }
1029
1030 void 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
1052   // Attributes are "IsSet" during the first update
1053   // of context (line, marker...)
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
1063 void 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;
1103   MyCStructure.ContextFillArea.DegenerationMode =
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
1143   // Specular Color
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
1175   MyCStructure.ContextFillArea.Back.EnvReflexion =
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
1241   MyCStructure.ContextFillArea.Front.EnvReflexion =
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
1254   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
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;
1261   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
1262
1263   MyGraphicDriver->ContextStructure (MyCStructure);
1264 #ifdef G003
1265   MyGraphicDriver -> DegenerateStructure (MyCStructure);
1266 #endif
1267
1268   // CAL 14/04/95
1269   // Attributes are "IsSet" during the first update
1270   // of context (line, marker...)
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
1280 void 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);
1312   MyCStructure.ContextText.TextZoomable     = ATextZoomable;
1313   MyCStructure.ContextText.TextAngle        = ATextAngle;
1314   MyCStructure.ContextText.TextFontAspect   = (int)ATextFontAspect;
1315
1316   MyCStructure.ContextText.IsDef          = 1;
1317
1318   MyGraphicDriver->ContextStructure (MyCStructure);
1319
1320   // CAL 14/04/95
1321   // Attributes are "IsSet" during the first update of a context (line, marker...)
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
1331 void 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
1352   // Attributes are "IsSet" during the first update of a context (line, marker...)
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
1362 void 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 {
1381       // To avoid calling method : Update ()
1382       // Not useful and can be costly.
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
1394 void 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
1410 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual () const {
1411
1412   return (MyVisual);
1413
1414 }
1415
1416 Standard_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
1427 void 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
1437 void Graphic3d_Structure::SetOwner (const Standard_Address Owner) {
1438
1439   MyOwner = Owner;
1440
1441 }
1442
1443 Standard_Address Graphic3d_Structure::Owner () const {
1444
1445   return MyOwner;
1446
1447 }
1448
1449 void 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
1458 void 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;
1470   switch (AType)
1471   {
1472
1473   case Graphic3d_TOC_DESCENDANT :
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
1493   case Graphic3d_TOC_ANCESTOR :
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
1505         // MyGraphicDriver->Connect is called in case
1506         // if connection between parent and child
1507       }
1508     }
1509     break;
1510   }
1511
1512 }
1513
1514 void 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
1526   // Search in the Descendants
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
1543     // Search in the Ancestors
1544     if (indexA != 0) {
1545       MyAncestors.Remove (indexA);
1546       AStructure->Disconnect (this);
1547
1548       // No call of MyGraphicDriver->Disconnect
1549       // in case of an ancestor
1550     }
1551   }
1552
1553 }
1554
1555 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection AType) {
1556
1557   if (IsDeleted ()) return;
1558
1559   Standard_Integer i, Length;
1560
1561   // disconnection
1562   switch (AType)
1563   {
1564   case Graphic3d_TOC_DESCENDANT :
1565     Length      = MyDescendants.Length ();
1566     for (i=1; i<=Length; i++)
1567       // Value (1) instead of Value (i) as MyDescendants
1568       // is modified by :
1569       // Graphic3d_Structure::Disconnect (AStructure)
1570       // that takes AStructure from MyDescendants
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++)
1577       // Value (1) instead of Value (i) as MyAncestors
1578       // is modified by :
1579       // Graphic3d_Structure::Disconnect (AStructure)
1580       // that takes AStructure from MyAncestors
1581       ((Graphic3d_Structure *)
1582       (MyAncestors.Value (1)))->Disconnect (this);
1583     break;
1584   }
1585
1586 }
1587
1588 Graphic3d_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
1597 void 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]
1611   // Avoid problemes if the user has defined matrice [1..4][1..4]
1612   //                                              or [3..6][-1..2] !!
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;
1624     // Update of CStructure
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;
1635     // To simplify management of indices
1636     for (i=0; i<=3; i++)
1637       for (j=0; j<=3; j++)
1638         AMatrix44 (i, j) = AMatrix (lr + i, lc + j);
1639     // Calculation of the product of matrices
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       }
1651       // Update of CStructure
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
1657   // If transformation, no validation of hidden already calculated parts.
1658   if (IsRotated ())
1659     ReCompute ();
1660
1661   GraphicTransform (NewTrsf);
1662   MyStructureManager->SetTransform (this, NewTrsf);
1663
1664   Update ();
1665
1666 }
1667
1668 void 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
1685 void 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)) {
1696       // Case impossible as it would mean that
1697       // the structure is empty
1698       XMin = RF;
1699       YMin = RF;
1700       ZMin = RF;
1701
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
1751 void Graphic3d_Structure::GroupLabels (Standard_Integer& LB, Standard_Integer& LE) {
1752
1753   LB      = MyGroupGenId.Next ();
1754   LE      = MyGroupGenId.Next ();
1755
1756 }
1757
1758 Standard_Integer Graphic3d_Structure::Identification () const {
1759
1760   Standard_Integer Result = MyCStructure.Id;
1761
1762   return Result;
1763
1764 }
1765
1766 void Graphic3d_Structure::SetTransformPersistence( const Graphic3d_TransModeFlags& AFlag )
1767 {
1768   SetTransformPersistence( AFlag, gp_Pnt( 0, 0, 0 ) );
1769 }
1770
1771 void Graphic3d_Structure::SetTransformPersistence( const Graphic3d_TransModeFlags& AFlag,
1772                                                   const gp_Pnt& APoint )
1773 {
1774   if (IsDeleted ()) return;
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
1787 Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1788 {
1789   return MyCStructure.TransformPersistence.Flag;
1790 }
1791
1792 gp_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
1802 void Graphic3d_Structure::Add (const Handle(Graphic3d_Group)& AGroup) {
1803
1804   // Method called only by the constructor of Graphic3d_Group
1805   // It is easy to check presence of <AGroup>
1806   // in sequence MyGroups.
1807   MyGroups.Append (AGroup);
1808
1809 }
1810
1811 void Graphic3d_Structure::Remove (const Standard_Address APtr, const Graphic3d_TypeOfConnection AType) {
1812
1813   Standard_Integer i, index, length;
1814
1815   switch (AType)
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
1848 void 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
1855   // Search in Groups
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
1866 Handle(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
1878 Graphic3d_TypeOfPrimitive Graphic3d_Structure::Type (const Standard_Integer ElementNumber) const {
1879
1880   if (IsDeleted ()) return (Graphic3d_TOP_UNDEFINED);
1881
1882   Graphic3d_TypeOfPrimitive Result;
1883
1884   Result  = MyGraphicDriver->ElementType
1885     (MyCStructure, ElementNumber);
1886
1887   return (Result);
1888
1889 }
1890
1891 Standard_Boolean Graphic3d_Structure::Exploration (const Standard_Integer ElementNumber, Graphic3d_VertexNC& AVertex, Graphic3d_Vector& AVector) const {
1892
1893   Standard_Boolean Result = Standard_False;
1894
1895   if (IsDeleted ()) return (Result);
1896
1897   Result  = MyGraphicDriver->ElementExploration
1898     (MyCStructure, ElementNumber, AVertex, AVector);
1899
1900   return (Result);
1901
1902 }
1903
1904 void Graphic3d_Structure::Exploration () const {
1905
1906   if (IsDeleted ()) return;
1907
1908   MyGraphicDriver->DumpStructure (MyCStructure);
1909
1910 }
1911
1912 void Graphic3d_Structure::MinMaxCoord (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
1913
1914   Standard_Real RL = RealLast ();
1915   Standard_Real RF = RealFirst ();
1916
1917   Standard_Real Xm, Ym, Zm, XM, YM, ZM;
1918
1919   //Bounding borders of infinite line has been calculated as own point
1920   //in center of this line
1921   if (IsEmpty () || IsInfinite ()) {
1922     if( IsInfinite ()){
1923       for (int i=1; i<=MyGroups.Length (); i++)
1924         if (! (MyGroups.Value (i))->IsEmpty () ) {
1925           (MyGroups.Value (i))->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
1926           Graphic3d_Vertex vertex1(Xm, Ym, Zm);
1927           Graphic3d_Vertex vertex2(XM, YM, ZM);
1928           Standard_Real distance = vertex1.Distance( vertex1,vertex2 );
1929           if( distance >= 500000.0){
1930             XMin = XMax = (Xm+ XM)/2.0;
1931             YMin = YMax = (Ym+ YM)/2.0;
1932             ZMin = ZMax = (Zm+ ZM)/2.0;
1933             return;
1934           }
1935         }
1936     }
1937     XMin = RF;
1938     YMin = RF;
1939     ZMin = RF;
1940
1941     XMax = RL;
1942     YMax = RL;
1943     ZMax = RL;
1944   }
1945   else {
1946     XMin = RL;
1947     YMin = RL;
1948     ZMin = RL;
1949
1950     XMax = RF;
1951     YMax = RF;
1952     ZMax = RF;
1953     Standard_Integer i, Length;
1954
1955     Length  = MyGroups.Length ();
1956     for (i=1; i<=Length; i++)
1957       if (! (MyGroups.Value (i))->IsEmpty () ) {
1958         (MyGroups.Value (i))->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
1959         if (Xm < XMin) XMin = Xm;
1960         if (Ym < YMin) YMin = Ym;
1961         if (Zm < ZMin) ZMin = Zm;
1962         if (XM > XMax) XMax = XM;
1963         if (YM > YMax) YMax = YM;
1964         if (ZM > ZMax) ZMax = ZM;
1965       }
1966
1967       Length  = MyDescendants.Length ();
1968       for (i=1; i<=Length; i++)
1969         if (! ((Graphic3d_Structure *)
1970           (MyDescendants.Value (i)))->IsEmpty () ) {
1971             ((Graphic3d_Structure *)
1972               (MyDescendants.Value (i)))->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
1973
1974             if (Xm < XMin) XMin = Xm;
1975             if (Ym < YMin) YMin = Ym;
1976             if (Zm < ZMin) ZMin = Zm;
1977             if (XM > XMax) XMax = XM;
1978             if (YM > YMax) YMax = YM;
1979             if (ZM > ZMax) ZMax = ZM;
1980           }
1981
1982           if ((XMin == RL) && (YMin == RL) &&
1983               (ZMin == RL) && (XMax == RF) &&
1984               (YMax == RF) && (ZMax == RF)) {
1985               // Case impossible as it would mean
1986               // that the structure is empty
1987               XMin    = RF;
1988               YMin    = RF;
1989               ZMin    = RF;
1990
1991               XMax    = RL;
1992               YMax    = RL;
1993               ZMax    = RL;
1994             }
1995
1996   }
1997
1998 }
1999
2000 void 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) {
2001
2002   Standard_Real A, B, C, D;
2003
2004   Standard_Real RL        = RealLast ();
2005   Standard_Real RF        = RealFirst ();
2006
2007   if ((X == RF) || (Y == RF) || (Z == RF) ||
2008     (X == RL) || (Y == RL) || (Z == RL)) {
2009       NewX    = X;
2010       NewY    = Y;
2011       NewZ    = Z;
2012     }
2013   else {
2014     A       = ATrsf (0, 0);
2015     B       = ATrsf (0, 1);
2016     C       = ATrsf (0, 2);
2017     D       = ATrsf (0, 3);
2018     NewX    = A * X + B * Y + C * Z + D;
2019     A       = ATrsf (1, 0);
2020     B       = ATrsf (1, 1);
2021     C       = ATrsf (1, 2);
2022     D       = ATrsf (1, 3);
2023     NewY    = A * X + B * Y + C * Z + D;
2024     A       = ATrsf (2, 0);
2025     B       = ATrsf (2, 1);
2026     C       = ATrsf (2, 2);
2027     D       = ATrsf (2, 3);
2028     NewZ    = A * X + B * Y + C * Z + D;
2029   }
2030
2031 }
2032
2033 Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vector& Coord) {
2034
2035   Standard_Real NewX, NewY, NewZ;
2036   Graphic3d_Vector Result;
2037
2038   Graphic3d_Structure::Transforms
2039     (ATrsf, Coord.X (), Coord.Y (), Coord.Z (), NewX, NewY, NewZ);
2040   Result.SetCoord (NewX, NewY, NewZ);
2041
2042   return (Result);
2043
2044 }
2045
2046 Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vertex& Coord) {
2047
2048   Standard_Real NewX, NewY, NewZ;
2049   Graphic3d_Vertex Result;
2050
2051   Graphic3d_Structure::Transforms
2052     (ATrsf, Coord.X (), Coord.Y (), Coord.Z (), NewX, NewY, NewZ);
2053   Result.SetCoord (NewX, NewY, NewZ);
2054
2055   return (Result);
2056
2057 }
2058
2059 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, Graphic3d_MapOfStructure& ASet) {
2060
2061
2062   Graphic3d_MapOfStructure h1;
2063   Graphic3d_MapOfStructure h2;
2064   AStructure->Descendants (h1);
2065   AStructure->Ancestors (h2);
2066
2067   Graphic3d_MapIteratorOfMapOfStructure IteratorD (h1);
2068   Graphic3d_MapIteratorOfMapOfStructure IteratorA (h2);
2069
2070   ASet.Add (AStructure);
2071
2072   // exploration
2073   switch (AType)
2074   {
2075
2076   case Graphic3d_TOC_DESCENDANT :
2077     while (IteratorD.More ()) {
2078       Graphic3d_Structure::Network
2079         (IteratorD.Key (), AType, ASet);
2080       // IteratorD.Next () is located on the next structure
2081       IteratorD.Next ();
2082     }
2083     break;
2084
2085   case Graphic3d_TOC_ANCESTOR :
2086     while (IteratorA.More ()) {
2087       Graphic3d_Structure::Network
2088         (IteratorA.Key (), AType, ASet);
2089       // IteratorA.Next () is located on the next structure
2090       IteratorA.Next ();
2091     }
2092     break;
2093   }
2094
2095 }
2096
2097 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType)
2098 {
2099
2100   Graphic3d_MapOfStructure ASet;
2101
2102   Graphic3d_MapIteratorOfMapOfStructure IteratorASet (ASet);
2103
2104   Graphic3d_Structure::Network (AStructure, AType, ASet);
2105
2106   while (IteratorASet.More ()) {
2107     cout << "\tIdent "
2108       << (IteratorASet.Key ())->Identification () << "\n";
2109     IteratorASet.Next ();
2110   }
2111   cout << flush;
2112
2113 }
2114
2115 void Graphic3d_Structure::Update () const
2116 {
2117
2118   if (IsDeleted ()) return;
2119
2120   if (MyStructureManager->UpdateMode () == Aspect_TOU_ASAP)
2121     MyStructureManager->Update ();
2122
2123 }
2124
2125 void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& CTXL, const Handle(Graphic3d_AspectText3d)& CTXT, const Handle(Graphic3d_AspectMarker3d)& CTXM, const Handle(Graphic3d_AspectFillArea3d)& CTXF)
2126 {
2127
2128   Standard_Real             R, G, B;
2129   Standard_Real             Rs, Gs, Bs;
2130   Standard_CString          AFont;
2131   Standard_Real             ASpace;
2132   Standard_Real             AnExpansion;
2133   Standard_Real             AWidth;
2134   Standard_Real             AScale;
2135   Quantity_Color            AColor;
2136   Quantity_Color            AnIntColor;
2137   Quantity_Color            BackIntColor;
2138   Quantity_Color            AnEdgeColor;
2139   Aspect_TypeOfLine         ALType;
2140   Aspect_TypeOfMarker       AMType;
2141   Aspect_InteriorStyle      AStyle;
2142   Aspect_TypeOfStyleText    AStyleT;
2143   Aspect_TypeOfDisplayText  ADisplayType;
2144   Quantity_Color            AColorSubTitle;
2145   Standard_Boolean          ATextZoomable;
2146   Standard_Real             ATextAngle;
2147   OSD_FontAspect            ATextFontAspect;
2148
2149
2150   CTXL->Values (AColor, ALType, AWidth);
2151   AColor.Values (R, G, B, Quantity_TOC_RGB);
2152
2153   MyCStructure.ContextLine.Color.r        = float (R);
2154   MyCStructure.ContextLine.Color.g        = float (G);
2155   MyCStructure.ContextLine.Color.b        = float (B);
2156   MyCStructure.ContextLine.LineType       = int (ALType);
2157   MyCStructure.ContextLine.Width          = float (AWidth);
2158
2159   CTXM->Values (AColor, AMType, AScale);
2160   AColor.Values (R, G, B, Quantity_TOC_RGB);
2161
2162   MyCStructure.ContextMarker.Color.r      = float (R);
2163   MyCStructure.ContextMarker.Color.g      = float (G);
2164   MyCStructure.ContextMarker.Color.b      = float (B);
2165   MyCStructure.ContextMarker.MarkerType   = int (AMType);
2166   MyCStructure.ContextMarker.Scale        = float (AScale);
2167
2168   CTXT->Values (AColor, AFont, AnExpansion, ASpace,AStyleT,ADisplayType,AColorSubTitle,ATextZoomable,ATextAngle,ATextFontAspect);
2169   AColor.Values (R, G, B, Quantity_TOC_RGB);
2170   AColorSubTitle.Values (Rs, Gs, Bs, Quantity_TOC_RGB);
2171
2172   MyCStructure.ContextText.Color.r          = float (R);
2173   MyCStructure.ContextText.Color.g          = float (G);
2174   MyCStructure.ContextText.Color.b          = float (B);
2175   MyCStructure.ContextText.Font             = (char*) (AFont);
2176   MyCStructure.ContextText.Expan            = float (AnExpansion);
2177   MyCStructure.ContextText.Style            = int (AStyleT);
2178   MyCStructure.ContextText.DisplayType      = int (ADisplayType);
2179   MyCStructure.ContextText.Space            = float (ASpace);
2180   MyCStructure.ContextText.ColorSubTitle.r  = float (Rs);
2181   MyCStructure.ContextText.ColorSubTitle.g  = float (Gs);
2182   MyCStructure.ContextText.ColorSubTitle.b  = float (Bs);
2183   MyCStructure.ContextText.TextZoomable     = ATextZoomable;
2184   MyCStructure.ContextText.TextAngle        = ATextAngle;
2185   MyCStructure.ContextText.TextFontAspect   = (int)ATextFontAspect;
2186
2187
2188
2189   CTXF->Values (AStyle, AnIntColor, BackIntColor, AnEdgeColor, ALType, AWidth);
2190   AnIntColor.Values (R, G, B, Quantity_TOC_RGB);
2191
2192   MyCStructure.ContextFillArea.Style      = int (AStyle);
2193   MyCStructure.ContextFillArea.IntColor.r = float (R);
2194   MyCStructure.ContextFillArea.IntColor.g = float (G);
2195   MyCStructure.ContextFillArea.IntColor.b = float (B);
2196 #ifdef OCC1174
2197   if ( CTXF->Distinguish() )
2198     BackIntColor.Values( R, G, B, Quantity_TOC_RGB );
2199 #endif
2200   MyCStructure.ContextFillArea.BackIntColor.r     = float( R );
2201   MyCStructure.ContextFillArea.BackIntColor.g     = float( G );
2202   MyCStructure.ContextFillArea.BackIntColor.b     = float( B );
2203
2204   // Edges
2205   MyCStructure.ContextFillArea.Edge       = CTXF->Edge () ? 1:0;
2206   AnEdgeColor.Values (R, G, B, Quantity_TOC_RGB);
2207   MyCStructure.ContextFillArea.EdgeColor.r        = float (R);
2208   MyCStructure.ContextFillArea.EdgeColor.g        = float (G);
2209   MyCStructure.ContextFillArea.EdgeColor.b        = float (B);
2210   MyCStructure.ContextFillArea.LineType           = int (ALType);
2211   MyCStructure.ContextFillArea.Width              = float (AWidth);
2212   MyCStructure.ContextFillArea.Hatch              = int (CTXF->HatchStyle ());
2213 #ifdef G003
2214   Quantity_Ratio ratio;
2215   MyCStructure.ContextFillArea.DegenerationMode =
2216     int (CTXF->DegenerateModel(ratio));
2217   MyCStructure.ContextFillArea.SkipRatio = float (ratio);
2218 #endif  // G003
2219
2220
2221   /*** Front and Back face ***/
2222   MyCStructure.ContextFillArea.Distinguish = CTXF->Distinguish () ? 1:0;
2223   MyCStructure.ContextFillArea.BackFace    = CTXF->BackFace () ? 1:0;
2224   /*** Back Material ***/
2225   // Light specificity
2226   MyCStructure.ContextFillArea.Back.Shininess     =
2227     float ((CTXF->BackMaterial ()).Shininess ());
2228   MyCStructure.ContextFillArea.Back.Ambient       =
2229     float ((CTXF->BackMaterial ()).Ambient ());
2230   MyCStructure.ContextFillArea.Back.Diffuse       =
2231     float ((CTXF->BackMaterial ()).Diffuse ());
2232   MyCStructure.ContextFillArea.Back.Specular      =
2233     float ((CTXF->BackMaterial ()).Specular ());
2234   MyCStructure.ContextFillArea.Back.Transparency  =
2235     float ((CTXF->BackMaterial ()).Transparency ());
2236   MyCStructure.ContextFillArea.Back.Emission      =
2237     float ((CTXF->BackMaterial ()).Emissive ());
2238
2239   // Reflection mode
2240   MyCStructure.ContextFillArea.Back.IsAmbient     =
2241     ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 );
2242   MyCStructure.ContextFillArea.Back.IsDiffuse     =
2243     ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 );
2244   MyCStructure.ContextFillArea.Back.IsSpecular    =
2245     ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 );
2246   MyCStructure.ContextFillArea.Back.IsEmission    =
2247     ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 );
2248
2249   // Material type
2250   //JR/Hp
2251   const Graphic3d_MaterialAspect ama = CTXF->BackMaterial () ;
2252   Standard_Boolean amt = ama.MaterialType(Graphic3d_MATERIAL_PHYSIC) ;
2253   MyCStructure.ContextFillArea.Back.IsPhysic = ( amt ? 1 : 0 );
2254
2255   // Specular color
2256   MyCStructure.ContextFillArea.Back.ColorSpec.r   =
2257     float (((CTXF->BackMaterial ()).SpecularColor ()).Red ());
2258   MyCStructure.ContextFillArea.Back.ColorSpec.g   =
2259     float (((CTXF->BackMaterial ()).SpecularColor ()).Green ());
2260   MyCStructure.ContextFillArea.Back.ColorSpec.b   =
2261     float (((CTXF->BackMaterial ()).SpecularColor ()).Blue ());
2262
2263   // Ambient color
2264   MyCStructure.ContextFillArea.Back.ColorAmb.r    =
2265     float (((CTXF->BackMaterial ()).AmbientColor ()).Red ());
2266   MyCStructure.ContextFillArea.Back.ColorAmb.g    =
2267     float (((CTXF->BackMaterial ()).AmbientColor ()).Green ());
2268   MyCStructure.ContextFillArea.Back.ColorAmb.b    =
2269     float (((CTXF->BackMaterial ()).AmbientColor ()).Blue ());
2270
2271   // Diffuse color
2272   MyCStructure.ContextFillArea.Back.ColorDif.r    =
2273     float (((CTXF->BackMaterial ()).DiffuseColor ()).Red ());
2274   MyCStructure.ContextFillArea.Back.ColorDif.g    =
2275     float (((CTXF->BackMaterial ()).DiffuseColor ()).Green ());
2276   MyCStructure.ContextFillArea.Back.ColorDif.b    =
2277     float (((CTXF->BackMaterial ()).DiffuseColor ()).Blue ());
2278
2279   // Emissive color
2280   MyCStructure.ContextFillArea.Back.ColorEms.r    =
2281     float (((CTXF->BackMaterial ()).EmissiveColor ()).Red ());
2282   MyCStructure.ContextFillArea.Back.ColorEms.g    =
2283     float (((CTXF->BackMaterial ()).EmissiveColor ()).Green ());
2284   MyCStructure.ContextFillArea.Back.ColorEms.b    =
2285     float (((CTXF->BackMaterial ()).EmissiveColor ()).Blue ());
2286
2287   MyCStructure.ContextFillArea.Back.EnvReflexion =
2288     float ((CTXF->BackMaterial ()).EnvReflexion());
2289
2290   /*** Front Material ***/
2291   // Light specificity
2292   MyCStructure.ContextFillArea.Front.Shininess    =
2293     float ((CTXF->FrontMaterial ()).Shininess ());
2294   MyCStructure.ContextFillArea.Front.Ambient      =
2295     float ((CTXF->FrontMaterial ()).Ambient ());
2296   MyCStructure.ContextFillArea.Front.Diffuse      =
2297     float ((CTXF->FrontMaterial ()).Diffuse ());
2298   MyCStructure.ContextFillArea.Front.Specular     =
2299     float ((CTXF->FrontMaterial ()).Specular ());
2300   MyCStructure.ContextFillArea.Front.Transparency =
2301     float ((CTXF->FrontMaterial ()).Transparency ());
2302   MyCStructure.ContextFillArea.Front.Emission     =
2303     float ((CTXF->FrontMaterial ()).Emissive ());
2304
2305   // Reflection mode
2306   MyCStructure.ContextFillArea.Front.IsAmbient    =
2307     ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 );
2308   MyCStructure.ContextFillArea.Front.IsDiffuse    =
2309     ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 );
2310   MyCStructure.ContextFillArea.Front.IsSpecular   =
2311     ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 );
2312   MyCStructure.ContextFillArea.Front.IsEmission   =
2313     ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 );
2314
2315   // Material type
2316   //JR/Hp
2317   const Graphic3d_MaterialAspect amas = CTXF->FrontMaterial () ;
2318   Standard_Boolean amty = amas.MaterialType(Graphic3d_MATERIAL_PHYSIC) ;
2319   MyCStructure.ContextFillArea.Front.IsPhysic = ( amty ? 1 : 0 );
2320
2321   // Specular color
2322   MyCStructure.ContextFillArea.Front.ColorSpec.r  =
2323     float (((CTXF->FrontMaterial ()).SpecularColor ()).Red ());
2324   MyCStructure.ContextFillArea.Front.ColorSpec.g  =
2325     float (((CTXF->FrontMaterial ()).SpecularColor ()).Green ());
2326   MyCStructure.ContextFillArea.Front.ColorSpec.b  =
2327     float (((CTXF->FrontMaterial ()).SpecularColor ()).Blue ());
2328
2329   // Ambient color
2330   MyCStructure.ContextFillArea.Front.ColorAmb.r   =
2331     float (((CTXF->FrontMaterial ()).AmbientColor ()).Red ());
2332   MyCStructure.ContextFillArea.Front.ColorAmb.g   =
2333     float (((CTXF->FrontMaterial ()).AmbientColor ()).Green ());
2334   MyCStructure.ContextFillArea.Front.ColorAmb.b   =
2335     float (((CTXF->FrontMaterial ()).AmbientColor ()).Blue ());
2336
2337   // Diffuse color
2338   MyCStructure.ContextFillArea.Front.ColorDif.r   =
2339     float (((CTXF->FrontMaterial ()).DiffuseColor ()).Red ());
2340   MyCStructure.ContextFillArea.Front.ColorDif.g   =
2341     float (((CTXF->FrontMaterial ()).DiffuseColor ()).Green ());
2342   MyCStructure.ContextFillArea.Front.ColorDif.b   =
2343     float (((CTXF->FrontMaterial ()).DiffuseColor ()).Blue ());
2344
2345   // Emissive color
2346   MyCStructure.ContextFillArea.Front.ColorEms.r   =
2347     float (((CTXF->FrontMaterial ()).EmissiveColor ()).Red ());
2348   MyCStructure.ContextFillArea.Front.ColorEms.g   =
2349     float (((CTXF->FrontMaterial ()).EmissiveColor ()).Green ());
2350   MyCStructure.ContextFillArea.Front.ColorEms.b   =
2351     float (((CTXF->FrontMaterial ()).EmissiveColor ()).Blue ());
2352
2353   MyCStructure.ContextFillArea.Front.EnvReflexion =
2354     float ((CTXF->FrontMaterial ()).EnvReflexion());
2355
2356   Handle(Graphic3d_TextureMap) TempTextureMap = CTXF->TextureMap();
2357   if (! TempTextureMap.IsNull() )
2358     MyCStructure.ContextFillArea.Texture.TexId = TempTextureMap->TextureId();
2359   else
2360     MyCStructure.ContextFillArea.Texture.TexId = -1;
2361
2362   MyCStructure.ContextFillArea.Texture.doTextureMap = CTXF->TextureMapState() ? 1:0;
2363
2364   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
2365   Standard_Integer aPolyMode;
2366   Standard_Real    aPolyFactor, aPolyUnits;
2367   CTXF->PolygonOffsets(aPolyMode, aPolyFactor, aPolyUnits);
2368   MyCStructure.ContextFillArea.PolygonOffsetMode   = aPolyMode;
2369   MyCStructure.ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2370   MyCStructure.ContextFillArea.PolygonOffsetUnits  = aPolyUnits;
2371   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
2372 }
2373
2374 void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod AMethod) {
2375
2376   Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax;
2377   Standard_Real R, G, B;
2378
2379   MyCStructure.highlight  = 1;
2380   MyHighlightMethod       = AMethod;
2381
2382   switch (AMethod)
2383   {
2384   case Aspect_TOHM_COLOR :
2385     MyHighlightColor.Values (R, G, B, Quantity_TOC_RGB);
2386     MyGraphicDriver->HighlightColor
2387       (MyCStructure, float (R), float (G),
2388       float (B) , Standard_True);
2389     MyGraphicDriver->NameSetStructure (MyCStructure);
2390     break;
2391   case Aspect_TOHM_BLINK :
2392     MyGraphicDriver->Blink (MyCStructure, Standard_True);
2393     MyGraphicDriver->NameSetStructure (MyCStructure);
2394     break;
2395   case Aspect_TOHM_BOUNDBOX :
2396     if (IsEmpty () || IsInfinite ()) {
2397       // Empty or infinite structure
2398       XMin = YMin = ZMin = 0.;
2399       XMax = YMax = ZMax = 0.;
2400     }
2401     else {
2402       MinMaxCoord
2403         (XMin, YMin, ZMin, XMax, YMax, ZMax);
2404     }
2405     MyCStructure.BoundBox.Pmin.x    = float (XMin);
2406     MyCStructure.BoundBox.Pmin.y    = float (YMin);
2407     MyCStructure.BoundBox.Pmin.z    = float (ZMin);
2408     MyCStructure.BoundBox.Pmax.x    = float (XMax);
2409     MyCStructure.BoundBox.Pmax.y    = float (YMax);
2410     MyCStructure.BoundBox.Pmax.z    = float (ZMax);
2411     MyHighlightColor.Values (R, G, B, Quantity_TOC_RGB);
2412     MyCStructure.BoundBox.Color.r   = float (R);
2413     MyCStructure.BoundBox.Color.g   = float (G);
2414     MyCStructure.BoundBox.Color.b   = float (B);
2415     MyGraphicDriver->BoundaryBox (MyCStructure, Standard_True);
2416     break;
2417   }
2418
2419 }
2420
2421 void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& AMatrix) {
2422
2423   Standard_Integer i, j;
2424
2425   for (i=0; i<=3; i++)
2426     for (j=0; j<=3; j++)
2427       MyCStructure.Transformation[i][j] = float (AMatrix (i, j));
2428
2429   MyGraphicDriver->TransformStructure (MyCStructure);
2430
2431 }
2432
2433 void Graphic3d_Structure::GraphicUnHighlight () {
2434
2435   MyCStructure.highlight  = 0;
2436
2437   switch (MyHighlightMethod)
2438   {
2439   case Aspect_TOHM_COLOR :
2440     MyGraphicDriver->HighlightColor
2441       (MyCStructure, 0.0, 0.0, 0.0 , Standard_False);
2442     MyGraphicDriver->NameSetStructure (MyCStructure);
2443     break;
2444   case Aspect_TOHM_BLINK :
2445     MyGraphicDriver->Blink (MyCStructure, Standard_False);
2446     MyGraphicDriver->NameSetStructure (MyCStructure);
2447     break;
2448   case Aspect_TOHM_BOUNDBOX :
2449     MyGraphicDriver->BoundaryBox
2450       (MyCStructure, Standard_False);
2451     MyGraphicDriver->NameSetStructure (MyCStructure);
2452     break;
2453   }
2454
2455 }
2456
2457 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual () const {
2458
2459   return (MyComputeVisual);
2460
2461 }
2462
2463 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure AVisual) {
2464
2465   // The ComputeVisual is saved only if the structure is
2466   // declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2467   // This declaration permits to calculate
2468   // proper representation of the structure calculated by Compute
2469   // instead of passage to TOS_COMPUTED.
2470   if (AVisual != Graphic3d_TOS_COMPUTED)
2471     MyComputeVisual = AVisual;
2472
2473 }
2474
2475 void Graphic3d_Structure::Plot (const Handle(Graphic3d_Plotter)& ) {
2476
2477 }
2478
2479 void Graphic3d_Structure::SetManager (const Handle(Graphic3d_StructureManager)& AManager, const Standard_Boolean WithPropagation) {
2480
2481   // All connected structures should follow ?
2482 #ifdef IMPLEMENTED
2483   if (WithPropagation) {
2484     Standard_Integer i, Length;
2485     Length  = MyDescendants.Length ();
2486     for (i=1; i<=Length; i++)
2487       ((Graphic3d_Structure *)
2488       (MyDescendants.Value (i)))->SetStructureManager (AManager);
2489
2490     Length  = MyAncestors.Length ();
2491     for (i=1; i<=Length; i++)
2492       ((Graphic3d_Structure *)
2493       (MyAncestors.Value (i)))->SetStructureManager (AManager);
2494   }
2495 #endif
2496
2497   // change of identification ?
2498   // MyStructureManager->Remove (Standard_Integer (MyCStructure.Id));
2499   // AManager->NewIdentification ();
2500   // MyCStructure.Id      = int (AManager->NewIdentification ());
2501
2502   Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode ();
2503   Aspect_TypeOfUpdate NewUpdateMode = AManager->UpdateMode ();
2504   MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
2505   AManager->SetUpdateMode (Aspect_TOU_WAIT);
2506
2507   if (MyCStructure.stick) {
2508     MyStructureManager->Erase (this);
2509     AManager->Display (this);
2510   }
2511
2512   if (MyCStructure.highlight) {
2513   }
2514
2515   if (MyCStructure.visible) {
2516     MyStructureManager->Invisible (this);
2517     AManager->Visible (this);
2518   }
2519
2520   if (MyCStructure.pick) {
2521     MyStructureManager->Undetectable (this);
2522     AManager->Detectable (this);
2523   }
2524
2525   MyStructureManager->SetUpdateMode (UpdateMode);
2526   AManager->SetUpdateMode (NewUpdateMode);
2527
2528   // New manager
2529   MyPtrStructureManager   = (void *) AManager.operator->();
2530
2531 }
2532
2533 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean AFlag) {
2534
2535   MyCStructure.HLRValidation      = AFlag ? 1:0;
2536
2537 }
2538
2539 Standard_Boolean Graphic3d_Structure::HLRValidation () const {
2540
2541   // Hidden parts stored in <me> are valid if :
2542   // 1/ the owner is defined.
2543   // 2/ they are not invalid.
2544
2545   Standard_Boolean Result = MyOwner != NULL && MyCStructure.HLRValidation != 0;
2546
2547   return Result;
2548
2549 }
2550
2551 Standard_Address Graphic3d_Structure::CStructure () const {
2552
2553   return Standard_Address (&MyCStructure);
2554
2555 }