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