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