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