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