0022149: Strings with Japanese characters can not be displayed in 3D viewer
[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.
bbf32d01
K
42// 30/11/98 ; FMN : S4069. Textes always visible.
43// 22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets
7fd59977 44
45#define G003 //EUG 26/01/00 Degeneration management
46
bbf32d01 47#define BUC60918 //GG 31/05/01 A transparente structure priority must have the
7fd59977 48// MAX_PRIORITY value so, the highlighted structure must have
bbf32d01 49// MAX_PRIORITY-1 value.
7fd59977 50// Add ResetDisplayPriority() method.
51
52#define OCC1174 // SAV 08/01/03 Added back face interior color controling
53
54
bbf32d01 55//
7fd59977 56//-Copyright MatraDatavision 1991,1992,1993,1994,1995
57
bbf32d01 58//-Version
7fd59977 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
bbf32d01 65//-References
7fd59977 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
bbf32d01 95// OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
7fd59977 96#include <Aspect_PolygonOffsetMode.hxx>
bbf32d01 97// OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
7fd59977 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
bbf32d01 130 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
7fd59977 131 // It is necessary to set default polygon offsets for a new presentation
132 aAspectFillArea3d->SetPolygonOffsets( Aspect_POM_Fill, 1., 0. );
bbf32d01 133 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
7fd59977 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,
bbf32d01 211 // avoid attempts to access it
7fd59977 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
bbf32d01 276 // Liberation of the identification if the destroyed structure
81bba717 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 :
bbf32d01 597 // if all these groups are empty or if all
81bba717 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
bbf32d01 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
bbf32d01
K
892 Graphic3d_TypeOfMaterial mType =
893 MyCStructure.ContextFillArea.Back.IsPhysic ?
7fd59977 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(
bbf32d01 986 MyCStructure.ContextFillArea.DegenerationMode);
7fd59977 987 Quantity_Ratio dRatio =
988 MyCStructure.ContextFillArea.SkipRatio;
989 CTXF->SetDegenerateModel(dMode,dRatio);
990#endif // G003
991
bbf32d01
K
992 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
993 CTXF->SetPolygonOffsets(MyCStructure.ContextFillArea.PolygonOffsetMode,
7fd59977 994 MyCStructure.ContextFillArea.PolygonOffsetFactor,
995 MyCStructure.ContextFillArea.PolygonOffsetUnits);
bbf32d01 996 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
7fd59977 997
998 return CTXF;
999
1000}
1001
bbf32d01
K
1002const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const {
1003 return MyGroups;
7fd59977 1004}
1005
1006Standard_Integer Graphic3d_Structure::NumberOfGroups () const {
7fd59977 1007 return (MyGroups.Length ());
7fd59977 1008}
1009
1010void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
1011
1012 if (IsDeleted ()) return;
1013
1014 Standard_Real R, G, B;
1015 Standard_Real AWidth;
1016 Quantity_Color AColor;
1017 Aspect_TypeOfLine ALType;
1018
1019 CTX->Values (AColor, ALType, AWidth);
1020 AColor.Values (R, G, B, Quantity_TOC_RGB);
1021
1022 MyCStructure.ContextLine.Color.r = float (R);
1023 MyCStructure.ContextLine.Color.g = float (G);
1024 MyCStructure.ContextLine.Color.b = float (B);
1025 MyCStructure.ContextLine.LineType = int (ALType);
1026 MyCStructure.ContextLine.Width = float (AWidth);
1027 MyCStructure.ContextLine.IsDef = 1;
1028
1029 MyGraphicDriver->ContextStructure (MyCStructure);
1030
1031 // CAL 14/04/95
bbf32d01
K
1032 // Attributes are "IsSet" during the first update
1033 // of context (line, marker...)
7fd59977 1034 MyCStructure.ContextLine.IsSet = 1;
1035 MyCStructure.ContextFillArea.IsSet = 1;
1036 MyCStructure.ContextMarker.IsSet = 1;
1037 MyCStructure.ContextText.IsSet = 1;
1038
1039 Update ();
1040
1041}
1042
1043void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
1044
1045 if (IsDeleted ()) return;
1046
1047 Standard_Real R, G, B;
1048 Standard_Real AWidth;
1049 Quantity_Color AnIntColor;
1050 Quantity_Color BackIntColor;
1051 Quantity_Color AnEdgeColor;
1052 Aspect_TypeOfLine ALType;
1053 Aspect_InteriorStyle AStyle;
1054
1055 CTX->Values (AStyle, AnIntColor, BackIntColor, AnEdgeColor, ALType, AWidth);
1056 AnIntColor.Values (R, G, B, Quantity_TOC_RGB);
1057
1058 MyCStructure.ContextFillArea.Style = int (AStyle);
1059 MyCStructure.ContextFillArea.IntColor.r = float (R);
1060 MyCStructure.ContextFillArea.IntColor.g = float (G);
1061 MyCStructure.ContextFillArea.IntColor.b = float (B);
1062
1063#ifdef OCC1174
1064 if ( CTX->Distinguish() )
1065 BackIntColor.Values( R, G, B, Quantity_TOC_RGB );
1066#endif
1067 MyCStructure.ContextFillArea.BackIntColor.r = float( R );
1068 MyCStructure.ContextFillArea.BackIntColor.g = float( G );
1069 MyCStructure.ContextFillArea.BackIntColor.b = float( B );
1070
1071
1072 // Edges
1073 MyCStructure.ContextFillArea.Edge = CTX->Edge () ? 1:0;
1074 AnEdgeColor.Values (R, G, B, Quantity_TOC_RGB);
1075 MyCStructure.ContextFillArea.EdgeColor.r = float (R);
1076 MyCStructure.ContextFillArea.EdgeColor.g = float (G);
1077 MyCStructure.ContextFillArea.EdgeColor.b = float (B);
1078 MyCStructure.ContextFillArea.LineType = int (ALType);
1079 MyCStructure.ContextFillArea.Width = float (AWidth);
1080 MyCStructure.ContextFillArea.Hatch = int (CTX->HatchStyle ());
1081#ifdef G003
1082 Quantity_Ratio ratio;
bbf32d01 1083 MyCStructure.ContextFillArea.DegenerationMode =
7fd59977 1084 int (CTX->DegenerateModel(ratio));
1085 MyCStructure.ContextFillArea.SkipRatio = float (ratio);
1086#endif // G003
1087
1088 /*** Front and Back face ***/
1089 MyCStructure.ContextFillArea.Distinguish = CTX->Distinguish () ? 1:0;
1090 MyCStructure.ContextFillArea.BackFace = CTX->BackFace () ? 1:0;
1091
1092 /*** Back Material ***/
1093 // Light specificity
1094 MyCStructure.ContextFillArea.Back.Shininess =
1095 float ((CTX->BackMaterial ()).Shininess ());
1096 MyCStructure.ContextFillArea.Back.Ambient =
1097 float ((CTX->BackMaterial ()).Ambient ());
1098 MyCStructure.ContextFillArea.Back.Diffuse =
1099 float ((CTX->BackMaterial ()).Diffuse ());
1100 MyCStructure.ContextFillArea.Back.Specular =
1101 float ((CTX->BackMaterial ()).Specular ());
1102 MyCStructure.ContextFillArea.Back.Transparency =
1103 float ((CTX->BackMaterial ()).Transparency ());
1104 MyCStructure.ContextFillArea.Back.Emission =
1105 float ((CTX->BackMaterial ()).Emissive ());
1106
1107 // Reflection mode
1108 MyCStructure.ContextFillArea.Back.IsAmbient =
1109 ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 );
1110 MyCStructure.ContextFillArea.Back.IsDiffuse =
1111 ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 );
1112 MyCStructure.ContextFillArea.Back.IsSpecular =
1113 ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 );
1114 MyCStructure.ContextFillArea.Back.IsEmission =
1115 ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 );
1116
1117 // Material type
1118 //JR/Hp
1119 const Graphic3d_MaterialAspect ama = CTX->BackMaterial () ;
1120 Standard_Boolean amt = ama.MaterialType(Graphic3d_MATERIAL_PHYSIC) ;
1121 MyCStructure.ContextFillArea.Back.IsPhysic = ( amt ? 1 : 0 );
1122
bbf32d01 1123 // Specular Color
7fd59977 1124 MyCStructure.ContextFillArea.Back.ColorSpec.r =
1125 float (((CTX->BackMaterial ()).SpecularColor ()).Red ());
1126 MyCStructure.ContextFillArea.Back.ColorSpec.g =
1127 float (((CTX->BackMaterial ()).SpecularColor ()).Green ());
1128 MyCStructure.ContextFillArea.Back.ColorSpec.b =
1129 float (((CTX->BackMaterial ()).SpecularColor ()).Blue ());
1130
1131 // Ambient color
1132 MyCStructure.ContextFillArea.Back.ColorAmb.r =
1133 float (((CTX->BackMaterial ()).AmbientColor ()).Red ());
1134 MyCStructure.ContextFillArea.Back.ColorAmb.g =
1135 float (((CTX->BackMaterial ()).AmbientColor ()).Green ());
1136 MyCStructure.ContextFillArea.Back.ColorAmb.b =
1137 float (((CTX->BackMaterial ()).AmbientColor ()).Blue ());
1138
1139 // Diffuse color
1140 MyCStructure.ContextFillArea.Back.ColorDif.r =
1141 float (((CTX->BackMaterial ()).DiffuseColor ()).Red ());
1142 MyCStructure.ContextFillArea.Back.ColorDif.g =
1143 float (((CTX->BackMaterial ()).DiffuseColor ()).Green ());
1144 MyCStructure.ContextFillArea.Back.ColorDif.b =
1145 float (((CTX->BackMaterial ()).DiffuseColor ()).Blue ());
1146
1147 // Emissive color
1148 MyCStructure.ContextFillArea.Back.ColorEms.r =
1149 float (((CTX->BackMaterial ()).EmissiveColor ()).Red ());
1150 MyCStructure.ContextFillArea.Back.ColorEms.g =
1151 float (((CTX->BackMaterial ()).EmissiveColor ()).Green ());
1152 MyCStructure.ContextFillArea.Back.ColorEms.b =
1153 float (((CTX->BackMaterial ()).EmissiveColor ()).Blue ());
1154
bbf32d01 1155 MyCStructure.ContextFillArea.Back.EnvReflexion =
7fd59977 1156 float ((CTX->BackMaterial ()).EnvReflexion());
1157
1158 /*** Front Material ***/
1159 // Light specificity
1160 MyCStructure.ContextFillArea.Front.Shininess =
1161 float ((CTX->FrontMaterial ()).Shininess ());
1162 MyCStructure.ContextFillArea.Front.Ambient =
1163 float ((CTX->FrontMaterial ()).Ambient ());
1164 MyCStructure.ContextFillArea.Front.Diffuse =
1165 float ((CTX->FrontMaterial ()).Diffuse ());
1166 MyCStructure.ContextFillArea.Front.Specular =
1167 float ((CTX->FrontMaterial ()).Specular ());
1168 MyCStructure.ContextFillArea.Front.Transparency =
1169 float ((CTX->FrontMaterial ()).Transparency ());
1170 MyCStructure.ContextFillArea.Front.Emission =
1171 float ((CTX->FrontMaterial ()).Emissive ());
1172
1173 // Reflection mode
1174 MyCStructure.ContextFillArea.Front.IsAmbient =
1175 ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 );
1176 MyCStructure.ContextFillArea.Front.IsDiffuse =
1177 ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 );
1178 MyCStructure.ContextFillArea.Front.IsSpecular =
1179 ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 );
1180 MyCStructure.ContextFillArea.Front.IsEmission =
1181 ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 );
1182
1183 // Materail type
1184 //JR/Hp
1185 const Graphic3d_MaterialAspect amas = CTX->FrontMaterial () ;
1186 Standard_Boolean amty = amas.MaterialType(Graphic3d_MATERIAL_PHYSIC) ;
1187 MyCStructure.ContextFillArea.Front.IsPhysic = ( amty ? 1 : 0 );
1188
1189 // Specular Color
1190 MyCStructure.ContextFillArea.Front.ColorSpec.r =
1191 float (((CTX->FrontMaterial ()).SpecularColor ()).Red ());
1192 MyCStructure.ContextFillArea.Front.ColorSpec.g =
1193 float (((CTX->FrontMaterial ()).SpecularColor ()).Green ());
1194 MyCStructure.ContextFillArea.Front.ColorSpec.b =
1195 float (((CTX->FrontMaterial ()).SpecularColor ()).Blue ());
1196
1197 // Ambient color
1198 MyCStructure.ContextFillArea.Front.ColorAmb.r =
1199 float (((CTX->FrontMaterial ()).AmbientColor ()).Red ());
1200 MyCStructure.ContextFillArea.Front.ColorAmb.g =
1201 float (((CTX->FrontMaterial ()).AmbientColor ()).Green ());
1202 MyCStructure.ContextFillArea.Front.ColorAmb.b =
1203 float (((CTX->FrontMaterial ()).AmbientColor ()).Blue ());
1204
1205 // Diffuse color
1206 MyCStructure.ContextFillArea.Front.ColorDif.r =
1207 float (((CTX->FrontMaterial ()).DiffuseColor ()).Red ());
1208 MyCStructure.ContextFillArea.Front.ColorDif.g =
1209 float (((CTX->FrontMaterial ()).DiffuseColor ()).Green ());
1210 MyCStructure.ContextFillArea.Front.ColorDif.b =
1211 float (((CTX->FrontMaterial ()).DiffuseColor ()).Blue ());
1212
1213 // Emissive color
1214 MyCStructure.ContextFillArea.Front.ColorEms.r =
1215 float (((CTX->FrontMaterial ()).EmissiveColor ()).Red ());
1216 MyCStructure.ContextFillArea.Front.ColorEms.g =
1217 float (((CTX->FrontMaterial ()).EmissiveColor ()).Green ());
1218 MyCStructure.ContextFillArea.Front.ColorEms.b =
1219 float (((CTX->FrontMaterial ()).EmissiveColor ()).Blue ());
1220
bbf32d01 1221 MyCStructure.ContextFillArea.Front.EnvReflexion =
7fd59977 1222 float ((CTX->FrontMaterial ()).EnvReflexion());
1223
1224 MyCStructure.ContextFillArea.IsDef = 1; // Definition material ok
1225
1226 Handle(Graphic3d_TextureMap) TempTextureMap = CTX->TextureMap();
1227 if (! TempTextureMap.IsNull() )
1228 MyCStructure.ContextFillArea.Texture.TexId = TempTextureMap->TextureId();
1229 else
1230 MyCStructure.ContextFillArea.Texture.TexId = -1;
1231
1232 MyCStructure.ContextFillArea.Texture.doTextureMap = CTX->TextureMapState() ? 1:0;
1233
bbf32d01 1234 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
7fd59977 1235 Standard_Integer aPolyMode;
1236 Standard_Real aPolyFactor, aPolyUnits;
1237 CTX->PolygonOffsets(aPolyMode, aPolyFactor, aPolyUnits);
1238 MyCStructure.ContextFillArea.PolygonOffsetMode = aPolyMode;
1239 MyCStructure.ContextFillArea.PolygonOffsetFactor = aPolyFactor;
1240 MyCStructure.ContextFillArea.PolygonOffsetUnits = aPolyUnits;
bbf32d01 1241 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
7fd59977 1242
1243 MyGraphicDriver->ContextStructure (MyCStructure);
1244#ifdef G003
1245 MyGraphicDriver -> DegenerateStructure (MyCStructure);
1246#endif
1247
1248 // CAL 14/04/95
81bba717 1249 // Attributes are "IsSet" during the first update
1250 // of context (line, marker...)
7fd59977 1251 MyCStructure.ContextLine.IsSet = 1;
1252 MyCStructure.ContextFillArea.IsSet = 1;
1253 MyCStructure.ContextMarker.IsSet = 1;
1254 MyCStructure.ContextText.IsSet = 1;
1255
1256 Update ();
1257
1258}
1259
1260void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
1261
1262 if (IsDeleted ()) return;
1263
1264 Standard_Real R, G, B;
1265 Standard_Real Rs, Gs, Bs;
1266 Standard_CString AFont;
1267 Standard_Real ASpace;
1268 Standard_Real AnExpansion;
1269 Quantity_Color AColor;
1270 Aspect_TypeOfStyleText AStyle;
1271 Aspect_TypeOfDisplayText ADisplayType;
1272 Quantity_Color AColorSubTitle;
1273 Standard_Boolean ATextZoomable;
1274 Standard_Real ATextAngle;
1275 OSD_FontAspect ATextFontAspect;
1276
1277 CTX->Values (AColor, AFont, AnExpansion, ASpace, AStyle, ADisplayType,AColorSubTitle,ATextZoomable,ATextAngle,ATextFontAspect);
1278 AColor.Values (R, G, B, Quantity_TOC_RGB);
1279 AColorSubTitle.Values (Rs, Gs, Bs, Quantity_TOC_RGB);
1280
1281 MyCStructure.ContextText.Color.r = float (R);
1282 MyCStructure.ContextText.Color.g = float (G);
1283 MyCStructure.ContextText.Color.b = float (B);
1284 MyCStructure.ContextText.Font = (char*) (AFont);
1285 MyCStructure.ContextText.Expan = float (AnExpansion);
1286 MyCStructure.ContextText.Space = float (ASpace);
1287 MyCStructure.ContextText.Style = int (AStyle);
1288 MyCStructure.ContextText.DisplayType = int (ADisplayType);
1289 MyCStructure.ContextText.ColorSubTitle.r = float (Rs);
1290 MyCStructure.ContextText.ColorSubTitle.g = float (Gs);
1291 MyCStructure.ContextText.ColorSubTitle.b = float (Bs);
bbf32d01
K
1292 MyCStructure.ContextText.TextZoomable = ATextZoomable;
1293 MyCStructure.ContextText.TextAngle = ATextAngle;
1294 MyCStructure.ContextText.TextFontAspect = (int)ATextFontAspect;
7fd59977 1295
1296 MyCStructure.ContextText.IsDef = 1;
1297
1298 MyGraphicDriver->ContextStructure (MyCStructure);
1299
1300 // CAL 14/04/95
81bba717 1301 // Attributes are "IsSet" during the first update of a context (line, marker...)
7fd59977 1302 MyCStructure.ContextLine.IsSet = 1;
1303 MyCStructure.ContextFillArea.IsSet = 1;
1304 MyCStructure.ContextMarker.IsSet = 1;
1305 MyCStructure.ContextText.IsSet = 1;
1306
1307 Update ();
1308
1309}
1310
1311void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
1312
1313 if (IsDeleted ()) return;
1314
1315 Standard_Real R, G, B;
1316 Standard_Real AScale;
1317 Quantity_Color AColor;
1318 Aspect_TypeOfMarker AMType;
1319
1320 CTX->Values (AColor, AMType, AScale);
1321 AColor.Values (R, G, B, Quantity_TOC_RGB);
1322
1323 MyCStructure.ContextMarker.Color.r = float (R);
1324 MyCStructure.ContextMarker.Color.g = float (G);
1325 MyCStructure.ContextMarker.Color.b = float (B);
1326 MyCStructure.ContextMarker.MarkerType = int (AMType);
1327 MyCStructure.ContextMarker.Scale = float (AScale);
1328 MyCStructure.ContextMarker.IsDef = 1;
1329
1330 MyGraphicDriver->ContextStructure (MyCStructure);
1331
81bba717 1332 // Attributes are "IsSet" during the first update of a context (line, marker...)
7fd59977 1333 MyCStructure.ContextLine.IsSet = 1;
1334 MyCStructure.ContextFillArea.IsSet = 1;
1335 MyCStructure.ContextMarker.IsSet = 1;
1336 MyCStructure.ContextText.IsSet = 1;
1337
1338 Update ();
1339
1340}
1341
1342void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure AVisual) {
1343
1344 if (IsDeleted ()) return;
1345 if (MyVisual == AVisual) return;
1346
1347 if (! MyCStructure.stick) {
1348 MyVisual = AVisual;
1349 SetComputeVisual (AVisual);
1350 }
1351 else {
1352
1353 Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode ();
1354 if (UpdateMode == Aspect_TOU_WAIT) {
1355 Erase ();
1356 MyVisual = AVisual;
1357 SetComputeVisual (AVisual);
1358 Display ();
1359 }
1360 else {
81bba717 1361 // To avoid calling method : Update ()
1362 // Not useful and can be costly.
7fd59977 1363 MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
1364 Erase ();
1365 MyVisual = AVisual;
1366 SetComputeVisual (AVisual);
1367 MyStructureManager->SetUpdateMode (UpdateMode);
1368 Display ();
1369 }
1370 }
1371
1372}
1373
1374void Graphic3d_Structure::SetZoomLimit (const Standard_Real LimitInf, const Standard_Real LimitSup) {
1375
1376 if (LimitInf <= 0.0)
1377 Graphic3d_StructureDefinitionError::Raise
1378 ("Bad value for ZoomLimit inf");
1379
1380 if (LimitSup <= 0.0)
1381 Graphic3d_StructureDefinitionError::Raise
1382 ("Bad value for ZoomLimit sup");
1383
1384 if (LimitSup < LimitInf)
1385 Graphic3d_StructureDefinitionError::Raise
1386 ("ZoomLimit sup < ZoomLimit inf");
1387
1388}
1389
1390Graphic3d_TypeOfStructure Graphic3d_Structure::Visual () const {
1391
1392 return (MyVisual);
1393
1394}
1395
1396Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& AStructure1, const Handle(Graphic3d_Structure)& AStructure2, const Graphic3d_TypeOfConnection AType) {
1397
1398 Graphic3d_MapOfStructure ASet;
1399
1400 // cycle detection
1401 Graphic3d_Structure::Network (AStructure2, AType, ASet);
1402
1403 return (! ASet.Contains (AStructure1));
1404
1405}
1406
1407void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure &SG) const {
1408
1409 Standard_Integer i, Length = MyAncestors.Length ();
1410
1411 for (i=1; i<=Length; i++)
1412 SG.Add ((Graphic3d_Structure *) (MyAncestors.Value (i)));
1413
1414
1415}
1416
1417void Graphic3d_Structure::SetOwner (const Standard_Address Owner) {
1418
1419 MyOwner = Owner;
1420
1421}
1422
1423Standard_Address Graphic3d_Structure::Owner () const {
1424
1425 return MyOwner;
1426
1427}
1428
1429void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& SG) const {
1430
1431 Standard_Integer i, Length = MyDescendants.Length ();
1432
1433 for (i=1; i<=Length; i++)
1434 SG.Add ((Graphic3d_Structure *) (MyDescendants.Value (i)));
1435
1436}
1437
1438void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, const Standard_Boolean WithCheck) {
1439
1440 if (IsDeleted ()) return;
1441
1442 if (WithCheck)
1443 // cycle detection
1444 if (! Graphic3d_Structure::AcceptConnection
1445 (this, AStructure, AType))
1446 return;
1447
1448 // connection
1449 Standard_Integer i;
bbf32d01 1450 switch (AType)
7fd59977 1451 {
1452
bbf32d01 1453 case Graphic3d_TOC_DESCENDANT :
7fd59977 1454 {
1455 Standard_Integer indexD = 0;
1456 Standard_Integer LengthD = MyDescendants.Length ();
1457 for (i=1; i<=LengthD && indexD==0; i++)
1458 if ((void *) (MyDescendants.Value (i)) ==
1459 (void *) (AStructure.operator->())) indexD = i;
1460
1461 if (indexD == 0) {
1462 MyDescendants.Append ((void *) AStructure.operator->());
1463 AStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
1464
1465 GraphicConnect (AStructure);
1466 MyStructureManager->Connect (this, AStructure);
1467
1468 Update ();
1469 }
1470 }
1471 break;
1472
bbf32d01 1473 case Graphic3d_TOC_ANCESTOR :
7fd59977 1474 {
1475 Standard_Integer indexA = 0;
1476 Standard_Integer LengthA = MyAncestors.Length ();
1477 for (i=1; i<=LengthA && indexA==0; i++)
1478 if ((void *) (MyAncestors.Value (i)) ==
1479 (void *) (AStructure.operator->())) indexA = i;
1480
1481 if (indexA == 0) {
1482 MyAncestors.Append ((void *) AStructure.operator->());
1483 AStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
1484
81bba717 1485 // MyGraphicDriver->Connect is called in case
1486 // if connection between parent and child
7fd59977 1487 }
1488 }
1489 break;
1490 }
1491
1492}
1493
1494void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& AStructure) {
1495
1496 if (IsDeleted ()) return;
1497
1498 Standard_Integer i;
1499
1500 Standard_Integer indexD = 0;
1501 Standard_Integer LengthD = MyDescendants.Length ();
1502 for (i=1; i<=LengthD && indexD==0; i++)
1503 if ((void *) (MyDescendants.Value (i)) ==
1504 (void *) (AStructure.operator->())) indexD = i;
1505
81bba717 1506 // Search in the Descendants
7fd59977 1507 if (indexD != 0) {
1508 MyDescendants.Remove (indexD);
1509 AStructure->Disconnect (this);
1510
1511 GraphicDisconnect (AStructure);
1512 MyStructureManager->Disconnect (this, AStructure);
1513
1514 Update ();
1515 }
1516 else {
1517 Standard_Integer indexA = 0;
1518 Standard_Integer LengthA = MyAncestors.Length ();
1519 for (i=1; i<=LengthA && indexA==0; i++)
1520 if ((void *) (MyAncestors.Value (i)) ==
1521 (void *) (AStructure.operator->())) indexA = i;
1522
81bba717 1523 // Search in the Ancestors
7fd59977 1524 if (indexA != 0) {
1525 MyAncestors.Remove (indexA);
1526 AStructure->Disconnect (this);
1527
81bba717 1528 // No call of MyGraphicDriver->Disconnect
1529 // in case of an ancestor
7fd59977 1530 }
1531 }
1532
1533}
1534
1535void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection AType) {
1536
1537 if (IsDeleted ()) return;
1538
1539 Standard_Integer i, Length;
1540
1541 // disconnection
bbf32d01 1542 switch (AType)
7fd59977 1543 {
1544 case Graphic3d_TOC_DESCENDANT :
1545 Length = MyDescendants.Length ();
1546 for (i=1; i<=Length; i++)
81bba717 1547 // Value (1) instead of Value (i) as MyDescendants
1548 // is modified by :
7fd59977 1549 // Graphic3d_Structure::Disconnect (AStructure)
81bba717 1550 // that takes AStructure from MyDescendants
7fd59977 1551 ((Graphic3d_Structure *)
1552 (MyDescendants.Value (1)))->Disconnect (this);
1553 break;
1554 case Graphic3d_TOC_ANCESTOR :
1555 Length = MyAncestors.Length ();
1556 for (i=1; i<=Length; i++)
bbf32d01 1557 // Value (1) instead of Value (i) as MyAncestors
81bba717 1558 // is modified by :
7fd59977 1559 // Graphic3d_Structure::Disconnect (AStructure)
81bba717 1560 // that takes AStructure from MyAncestors
7fd59977 1561 ((Graphic3d_Structure *)
1562 (MyAncestors.Value (1)))->Disconnect (this);
1563 break;
1564 }
1565
1566}
1567
1568Graphic3d_TypeOfComposition Graphic3d_Structure::Composition () const {
1569
1570 if (MyCStructure.Composition)
1571 return (Graphic3d_TOC_POSTCONCATENATE);
1572 else
1573 return (Graphic3d_TOC_REPLACE);
1574
1575}
1576
1577void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& AMatrix, const Graphic3d_TypeOfComposition AType) {
1578
1579 if (IsDeleted ()) return;
1580
1581 Standard_Integer lr, ur, lc, uc;
1582 Standard_Real valuetrsf;
1583 Standard_Real valueoldtrsf;
1584 Standard_Real valuenewtrsf;
1585 Standard_Integer i, j, k;
1586 TColStd_Array2OfReal TheTrsf (0, 3, 0, 3);
1587 TColStd_Array2OfReal NewTrsf (0, 3, 0, 3);
1588 TColStd_Array2OfReal AMatrix44 (0, 3, 0, 3);
1589
1590 // Assign the new transformation in an array [0..3][0..3]
81bba717 1591 // Avoid problemes if the user has defined matrice [1..4][1..4]
bbf32d01 1592 // or [3..6][-1..2] !!
7fd59977 1593 lr = AMatrix.LowerRow ();
1594 ur = AMatrix.UpperRow ();
1595 lc = AMatrix.LowerCol ();
1596 uc = AMatrix.UpperCol ();
1597
1598 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
1599 Graphic3d_TransformError::Raise
1600 ("Transform : not a 4x4 matrix");
1601
1602 if (AType == Graphic3d_TOC_REPLACE) {
1603 MyCStructure.Composition = 0;
81bba717 1604 // Update of CStructure
7fd59977 1605 for (i=0; i<=3; i++)
1606 for (j=0; j<=3; j++) {
1607 MyCStructure.Transformation[i][j] =
1608 float (AMatrix (lr + i, lc + j));
1609 NewTrsf (i, j) = AMatrix (lr + i, lc + j);
1610 }
1611 }
1612
1613 if (AType == Graphic3d_TOC_POSTCONCATENATE) {
1614 MyCStructure.Composition = 1;
81bba717 1615 // To simplify management of indices
7fd59977 1616 for (i=0; i<=3; i++)
1617 for (j=0; j<=3; j++)
1618 AMatrix44 (i, j) = AMatrix (lr + i, lc + j);
81bba717 1619 // Calculation of the product of matrices
7fd59977 1620 for (i=0; i<=3; i++)
1621 for (j=0; j<=3; j++) {
1622 NewTrsf (i, j) = 0.0;
1623 for (k=0; k<=3; k++) {
1624 valueoldtrsf = MyCStructure.Transformation[i][k];
1625 valuetrsf = AMatrix44 (k, j);
1626 valuenewtrsf = NewTrsf (i, j) +
1627 valueoldtrsf * valuetrsf;
1628 NewTrsf (i, j) = valuenewtrsf;
1629 }
1630 }
81bba717 1631 // Update of CStructure
7fd59977 1632 for (i=0; i<=3; i++)
1633 for (j=0; j<=3; j++)
1634 MyCStructure.Transformation[i][j] = float (NewTrsf (i, j));
1635 }
1636
81bba717 1637 // If transformation, no validation of hidden already calculated parts.
7fd59977 1638 if (IsRotated ())
1639 ReCompute ();
1640
1641 GraphicTransform (NewTrsf);
1642 MyStructureManager->SetTransform (this, NewTrsf);
1643
1644 Update ();
1645
1646}
1647
1648void Graphic3d_Structure::Transform (TColStd_Array2OfReal& AMatrix) const {
1649
1650 Standard_Integer lr = AMatrix.LowerRow ();
1651 Standard_Integer ur = AMatrix.UpperRow ();
1652 Standard_Integer lc = AMatrix.LowerCol ();
1653 Standard_Integer uc = AMatrix.UpperCol ();
1654
1655 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
1656 Graphic3d_TransformError::Raise
1657 ("Transform : not a 4x4 matrix");
1658
1659 for (Standard_Integer i=0; i<=3; i++)
1660 for (Standard_Integer j=0; j<=3; j++)
1661 AMatrix (lr + i, lc + j) = MyCStructure.Transformation[i][j];
1662
1663}
1664
1665void Graphic3d_Structure::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
1666
1667 Standard_Real RL = RealLast ();
1668 Standard_Real RF = RealFirst ();
1669
1670 Standard_Real XTMin, YTMin, ZTMin, XTMax, YTMax, ZTMax, U, V, W;
1671
1672 MinMaxCoord (XTMin, YTMin, ZTMin, XTMax, YTMax, ZTMax);
1673 if ((XTMin == RF) && (YTMin == RF) &&
1674 (ZTMin == RF) && (XTMax == RL) &&
1675 (YTMax == RL) && (ZTMax == RL)) {
bbf32d01 1676 // Case impossible as it would mean that
81bba717 1677 // the structure is empty
bbf32d01
K
1678 XMin = RF;
1679 YMin = RF;
7fd59977 1680 ZMin = RF;
bbf32d01 1681
7fd59977 1682 XMax = RL;
1683 YMax = RL;
1684 ZMax = RL;
1685 }
1686 else {
1687 Standard_Integer i, j;
1688 TColStd_Array2OfReal TheTrsf (0, 3, 0, 3);
1689
1690 for (i=0; i<=3; i++)
1691 for (j=0; j<=3; j++)
1692 TheTrsf (i, j) = MyCStructure.Transformation[i][j];
1693
1694 Graphic3d_Structure::Transforms
1695 (TheTrsf, XTMin, YTMin, ZTMin, XMin, YMin, ZMin);
1696 Graphic3d_Structure::Transforms
1697 (TheTrsf, XTMax, YTMax, ZTMax, XMax, YMax, ZMax);
1698 Graphic3d_Structure::Transforms
1699 (TheTrsf, XTMin, YTMin, ZTMax, U, V, W);
1700 XMin = Min(U,XMin) ; XMax = Max(U,XMax) ;
1701 YMin = Min(V,YMin) ; YMax = Max(V,YMax) ;
1702 ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ;
1703 Graphic3d_Structure::Transforms
1704 (TheTrsf, XTMax, YTMin, ZTMax, U, V, W);
1705 XMin = Min(U,XMin) ; XMax = Max(U,XMax) ;
1706 YMin = Min(V,YMin) ; YMax = Max(V,YMax) ;
1707 ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ;
1708 Graphic3d_Structure::Transforms
1709 (TheTrsf, XTMax, YTMin, ZTMin, U, V, W);
1710 XMin = Min(U,XMin) ; XMax = Max(U,XMax) ;
1711 YMin = Min(V,YMin) ; YMax = Max(V,YMax) ;
1712 ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ;
1713 Graphic3d_Structure::Transforms
1714 (TheTrsf, XTMax, YTMax, ZTMin, U, V, W);
1715 XMin = Min(U,XMin) ; XMax = Max(U,XMax) ;
1716 YMin = Min(V,YMin) ; YMax = Max(V,YMax) ;
1717 ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ;
1718 Graphic3d_Structure::Transforms
1719 (TheTrsf, XTMin, YTMax, ZTMax, U, V, W);
1720 XMin = Min(U,XMin) ; XMax = Max(U,XMax) ;
1721 YMin = Min(V,YMin) ; YMax = Max(V,YMax) ;
1722 ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ;
1723 Graphic3d_Structure::Transforms
1724 (TheTrsf, XTMin, YTMax, ZTMin, U, V, W);
1725 XMin = Min(U,XMin) ; XMax = Max(U,XMax) ;
1726 YMin = Min(V,YMin) ; YMax = Max(V,YMax) ;
1727 ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ;
1728 }
1729}
1730
1731void Graphic3d_Structure::GroupLabels (Standard_Integer& LB, Standard_Integer& LE) {
1732
1733 LB = MyGroupGenId.Next ();
1734 LE = MyGroupGenId.Next ();
1735
1736}
1737
1738Standard_Integer Graphic3d_Structure::Identification () const {
1739
1740 Standard_Integer Result = MyCStructure.Id;
1741
1742 return Result;
1743
1744}
1745
1746void Graphic3d_Structure::SetTransformPersistence( const Graphic3d_TransModeFlags& AFlag )
1747{
1748 SetTransformPersistence( AFlag, gp_Pnt( 0, 0, 0 ) );
1749}
1750
1751void Graphic3d_Structure::SetTransformPersistence( const Graphic3d_TransModeFlags& AFlag,
1752 const gp_Pnt& APoint )
1753{
bbf32d01 1754 if (IsDeleted ()) return;
7fd59977 1755
1756 MyCStructure.TransformPersistence.Flag = AFlag;
1757 MyCStructure.TransformPersistence.Point.x = APoint.X();
1758 MyCStructure.TransformPersistence.Point.y = APoint.Y();
1759 MyCStructure.TransformPersistence.Point.z = APoint.Z();
1760 //MyStructureManager->Update ();
1761 //Update();
1762 MyGraphicDriver->ContextStructure( MyCStructure );
1763
1764 MyCStructure.TransformPersistence.IsSet = 1;
1765}
1766
1767Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1768{
1769 return MyCStructure.TransformPersistence.Flag;
1770}
1771
1772gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1773{
1774 gp_Pnt aPnt( 0., 0., 0. );
1775 aPnt.SetX( MyCStructure.TransformPersistence.Point.x );
1776 aPnt.SetY( MyCStructure.TransformPersistence.Point.y );
1777 aPnt.SetZ( MyCStructure.TransformPersistence.Point.z );
1778
1779 return aPnt;
1780}
1781
1782void Graphic3d_Structure::Add (const Handle(Graphic3d_Group)& AGroup) {
1783
81bba717 1784 // Method called only by the constructor of Graphic3d_Group
1785 // It is easy to check presence of <AGroup>
1786 // in sequence MyGroups.
7fd59977 1787 MyGroups.Append (AGroup);
1788
1789}
1790
1791void Graphic3d_Structure::Remove (const Standard_Address APtr, const Graphic3d_TypeOfConnection AType) {
1792
1793 Standard_Integer i, index, length;
1794
bbf32d01 1795 switch (AType)
7fd59977 1796 {
1797 case Graphic3d_TOC_DESCENDANT :
1798 index = 0;
1799 length = MyDescendants.Length ();
1800 for (i=1; i<=length && index==0; i++)
1801 if ((void *) (MyDescendants.Value (i)) == APtr)
1802 index = i;
1803 if (index != 0)
1804 MyDescendants.Remove (index);
1805#ifdef TRACE
1806 else
1807 cout << "Error, Graphic3d_Structure::Remove\n";
1808#endif
1809 break;
1810
1811 case Graphic3d_TOC_ANCESTOR :
1812 index = 0;
1813 length = MyAncestors.Length ();
1814 for (i=1; i<=length && index==0; i++)
1815 if ((void *) (MyAncestors.Value (i)) == APtr)
1816 index = i;
1817 if (index != 0)
1818 MyAncestors.Remove (index);
1819#ifdef TRACE
1820 else
1821 cout << "Error, Graphic3d_Structure::Remove\n";
1822#endif
1823 break;
1824 }
1825
1826}
1827
1828void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& AGroup) {
1829
1830 Standard_Integer index = 0;
1831 Standard_Integer Length = MyGroups.Length ();
1832 for (Standard_Integer i=1; i<=Length && index==0; i++)
1833 if (MyGroups.Value (i) == AGroup) index = i;
1834
81bba717 1835 // Search in Groups
7fd59977 1836 if (index != 0) {
1837 Standard_Integer GroupLabelBegin, GroupLabelEnd;
1838 AGroup->Labels (GroupLabelBegin, GroupLabelEnd);
1839 MyGroupGenId.Free (GroupLabelBegin);
1840 MyGroupGenId.Free (GroupLabelEnd);
1841 MyGroups.Remove (index);
1842 }
1843
1844}
1845
1846Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager () const {
1847
1848#ifdef DOWNCAST
1849 return
1850 (Handle(Graphic3d_StructureManager)::DownCast(Handle(Standard_Transient)
1851 ((Standard_Transient*) MyPtrStructureManager)));
1852#else
1853 return MyStructureManager;
1854#endif
1855
1856}
1857
1858Graphic3d_TypeOfPrimitive Graphic3d_Structure::Type (const Standard_Integer ElementNumber) const {
1859
1860 if (IsDeleted ()) return (Graphic3d_TOP_UNDEFINED);
1861
1862 Graphic3d_TypeOfPrimitive Result;
1863
1864 Result = MyGraphicDriver->ElementType
1865 (MyCStructure, ElementNumber);
1866
1867 return (Result);
1868
1869}
1870
1871Standard_Boolean Graphic3d_Structure::Exploration (const Standard_Integer ElementNumber, Graphic3d_VertexNC& AVertex, Graphic3d_Vector& AVector) const {
1872
1873 Standard_Boolean Result = Standard_False;
1874
1875 if (IsDeleted ()) return (Result);
1876
1877 Result = MyGraphicDriver->ElementExploration
1878 (MyCStructure, ElementNumber, AVertex, AVector);
1879
1880 return (Result);
1881
1882}
1883
1884void Graphic3d_Structure::Exploration () const {
1885
1886 if (IsDeleted ()) return;
1887
1888 MyGraphicDriver->DumpStructure (MyCStructure);
1889
1890}
1891
1892void Graphic3d_Structure::MinMaxCoord (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
1893
1894 Standard_Real RL = RealLast ();
1895 Standard_Real RF = RealFirst ();
1896
1897 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
1898
1899 //Bounding borders of infinite line has been calculated as own point
1900 //in center of this line
1901 if (IsEmpty () || IsInfinite ()) {
1902 if( IsInfinite ()){
1903 for (int i=1; i<=MyGroups.Length (); i++)
1904 if (! (MyGroups.Value (i))->IsEmpty () ) {
1905 (MyGroups.Value (i))->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
1906 Graphic3d_Vertex vertex1(Xm, Ym, Zm);
1907 Graphic3d_Vertex vertex2(XM, YM, ZM);
1908 Standard_Real distance = vertex1.Distance( vertex1,vertex2 );
1909 if( distance >= 500000.0){
1910 XMin = XMax = (Xm+ XM)/2.0;
1911 YMin = YMax = (Ym+ YM)/2.0;
1912 ZMin = ZMax = (Zm+ ZM)/2.0;
1913 return;
bbf32d01 1914 }
7fd59977 1915 }
1916 }
1917 XMin = RF;
1918 YMin = RF;
1919 ZMin = RF;
1920
1921 XMax = RL;
1922 YMax = RL;
1923 ZMax = RL;
1924 }
1925 else {
1926 XMin = RL;
1927 YMin = RL;
1928 ZMin = RL;
1929
1930 XMax = RF;
1931 YMax = RF;
1932 ZMax = RF;
1933 Standard_Integer i, Length;
1934
1935 Length = MyGroups.Length ();
1936 for (i=1; i<=Length; i++)
1937 if (! (MyGroups.Value (i))->IsEmpty () ) {
1938 (MyGroups.Value (i))->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
1939 if (Xm < XMin) XMin = Xm;
1940 if (Ym < YMin) YMin = Ym;
1941 if (Zm < ZMin) ZMin = Zm;
1942 if (XM > XMax) XMax = XM;
1943 if (YM > YMax) YMax = YM;
1944 if (ZM > ZMax) ZMax = ZM;
1945 }
1946
1947 Length = MyDescendants.Length ();
1948 for (i=1; i<=Length; i++)
1949 if (! ((Graphic3d_Structure *)
1950 (MyDescendants.Value (i)))->IsEmpty () ) {
1951 ((Graphic3d_Structure *)
1952 (MyDescendants.Value (i)))->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
1953
1954 if (Xm < XMin) XMin = Xm;
1955 if (Ym < YMin) YMin = Ym;
1956 if (Zm < ZMin) ZMin = Zm;
1957 if (XM > XMax) XMax = XM;
1958 if (YM > YMax) YMax = YM;
1959 if (ZM > ZMax) ZMax = ZM;
1960 }
1961
1962 if ((XMin == RL) && (YMin == RL) &&
1963 (ZMin == RL) && (XMax == RF) &&
1964 (YMax == RF) && (ZMax == RF)) {
bbf32d01 1965 // Case impossible as it would mean
81bba717 1966 // that the structure is empty
7fd59977 1967 XMin = RF;
1968 YMin = RF;
1969 ZMin = RF;
1970
1971 XMax = RL;
1972 YMax = RL;
1973 ZMax = RL;
1974 }
1975
1976 }
1977
1978}
1979
1980void 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) {
1981
1982 Standard_Real A, B, C, D;
1983
1984 Standard_Real RL = RealLast ();
1985 Standard_Real RF = RealFirst ();
1986
1987 if ((X == RF) || (Y == RF) || (Z == RF) ||
1988 (X == RL) || (Y == RL) || (Z == RL)) {
1989 NewX = X;
1990 NewY = Y;
1991 NewZ = Z;
1992 }
1993 else {
1994 A = ATrsf (0, 0);
1995 B = ATrsf (0, 1);
1996 C = ATrsf (0, 2);
1997 D = ATrsf (0, 3);
1998 NewX = A * X + B * Y + C * Z + D;
1999 A = ATrsf (1, 0);
2000 B = ATrsf (1, 1);
2001 C = ATrsf (1, 2);
2002 D = ATrsf (1, 3);
2003 NewY = A * X + B * Y + C * Z + D;
2004 A = ATrsf (2, 0);
2005 B = ATrsf (2, 1);
2006 C = ATrsf (2, 2);
2007 D = ATrsf (2, 3);
2008 NewZ = A * X + B * Y + C * Z + D;
2009 }
2010
2011}
2012
2013Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vector& Coord) {
2014
2015 Standard_Real NewX, NewY, NewZ;
2016 Graphic3d_Vector Result;
2017
2018 Graphic3d_Structure::Transforms
2019 (ATrsf, Coord.X (), Coord.Y (), Coord.Z (), NewX, NewY, NewZ);
2020 Result.SetCoord (NewX, NewY, NewZ);
2021
2022 return (Result);
2023
2024}
2025
2026Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vertex& Coord) {
2027
2028 Standard_Real NewX, NewY, NewZ;
2029 Graphic3d_Vertex 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
2039void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, Graphic3d_MapOfStructure& ASet) {
2040
2041
2042 Graphic3d_MapOfStructure h1;
2043 Graphic3d_MapOfStructure h2;
2044 AStructure->Descendants (h1);
2045 AStructure->Ancestors (h2);
2046
2047 Graphic3d_MapIteratorOfMapOfStructure IteratorD (h1);
2048 Graphic3d_MapIteratorOfMapOfStructure IteratorA (h2);
2049
2050 ASet.Add (AStructure);
2051
2052 // exploration
bbf32d01 2053 switch (AType)
7fd59977 2054 {
2055
2056 case Graphic3d_TOC_DESCENDANT :
2057 while (IteratorD.More ()) {
2058 Graphic3d_Structure::Network
2059 (IteratorD.Key (), AType, ASet);
81bba717 2060 // IteratorD.Next () is located on the next structure
7fd59977 2061 IteratorD.Next ();
2062 }
2063 break;
2064
2065 case Graphic3d_TOC_ANCESTOR :
2066 while (IteratorA.More ()) {
2067 Graphic3d_Structure::Network
2068 (IteratorA.Key (), AType, ASet);
bbf32d01
K
2069 // IteratorA.Next () is located on the next structure
2070 IteratorA.Next ();
7fd59977 2071 }
2072 break;
2073 }
2074
2075}
2076
bbf32d01 2077void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType)
7fd59977 2078{
2079
2080 Graphic3d_MapOfStructure ASet;
2081
2082 Graphic3d_MapIteratorOfMapOfStructure IteratorASet (ASet);
2083
2084 Graphic3d_Structure::Network (AStructure, AType, ASet);
2085
2086 while (IteratorASet.More ()) {
2087 cout << "\tIdent "
2088 << (IteratorASet.Key ())->Identification () << "\n";
2089 IteratorASet.Next ();
2090 }
2091 cout << flush;
2092
2093}
2094
bbf32d01 2095void Graphic3d_Structure::Update () const
7fd59977 2096{
2097
2098 if (IsDeleted ()) return;
2099
2100 if (MyStructureManager->UpdateMode () == Aspect_TOU_ASAP)
2101 MyStructureManager->Update ();
2102
2103}
2104
bbf32d01 2105void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& CTXL, const Handle(Graphic3d_AspectText3d)& CTXT, const Handle(Graphic3d_AspectMarker3d)& CTXM, const Handle(Graphic3d_AspectFillArea3d)& CTXF)
7fd59977 2106{
2107
2108 Standard_Real R, G, B;
2109 Standard_Real Rs, Gs, Bs;
2110 Standard_CString AFont;
2111 Standard_Real ASpace;
2112 Standard_Real AnExpansion;
2113 Standard_Real AWidth;
2114 Standard_Real AScale;
2115 Quantity_Color AColor;
2116 Quantity_Color AnIntColor;
2117 Quantity_Color BackIntColor;
2118 Quantity_Color AnEdgeColor;
2119 Aspect_TypeOfLine ALType;
2120 Aspect_TypeOfMarker AMType;
2121 Aspect_InteriorStyle AStyle;
2122 Aspect_TypeOfStyleText AStyleT;
2123 Aspect_TypeOfDisplayText ADisplayType;
bbf32d01 2124 Quantity_Color AColorSubTitle;
7fd59977 2125 Standard_Boolean ATextZoomable;
2126 Standard_Real ATextAngle;
2127 OSD_FontAspect ATextFontAspect;
2128
2129
2130 CTXL->Values (AColor, ALType, AWidth);
2131 AColor.Values (R, G, B, Quantity_TOC_RGB);
2132
2133 MyCStructure.ContextLine.Color.r = float (R);
2134 MyCStructure.ContextLine.Color.g = float (G);
2135 MyCStructure.ContextLine.Color.b = float (B);
2136 MyCStructure.ContextLine.LineType = int (ALType);
2137 MyCStructure.ContextLine.Width = float (AWidth);
2138
2139 CTXM->Values (AColor, AMType, AScale);
2140 AColor.Values (R, G, B, Quantity_TOC_RGB);
2141
2142 MyCStructure.ContextMarker.Color.r = float (R);
2143 MyCStructure.ContextMarker.Color.g = float (G);
2144 MyCStructure.ContextMarker.Color.b = float (B);
2145 MyCStructure.ContextMarker.MarkerType = int (AMType);
2146 MyCStructure.ContextMarker.Scale = float (AScale);
2147
2148 CTXT->Values (AColor, AFont, AnExpansion, ASpace,AStyleT,ADisplayType,AColorSubTitle,ATextZoomable,ATextAngle,ATextFontAspect);
2149 AColor.Values (R, G, B, Quantity_TOC_RGB);
2150 AColorSubTitle.Values (Rs, Gs, Bs, Quantity_TOC_RGB);
2151
2152 MyCStructure.ContextText.Color.r = float (R);
2153 MyCStructure.ContextText.Color.g = float (G);
2154 MyCStructure.ContextText.Color.b = float (B);
2155 MyCStructure.ContextText.Font = (char*) (AFont);
2156 MyCStructure.ContextText.Expan = float (AnExpansion);
2157 MyCStructure.ContextText.Style = int (AStyleT);
2158 MyCStructure.ContextText.DisplayType = int (ADisplayType);
2159 MyCStructure.ContextText.Space = float (ASpace);
2160 MyCStructure.ContextText.ColorSubTitle.r = float (Rs);
2161 MyCStructure.ContextText.ColorSubTitle.g = float (Gs);
2162 MyCStructure.ContextText.ColorSubTitle.b = float (Bs);
2163 MyCStructure.ContextText.TextZoomable = ATextZoomable;
2164 MyCStructure.ContextText.TextAngle = ATextAngle;
bbf32d01 2165 MyCStructure.ContextText.TextFontAspect = (int)ATextFontAspect;
7fd59977 2166
2167
2168
2169 CTXF->Values (AStyle, AnIntColor, BackIntColor, AnEdgeColor, ALType, AWidth);
2170 AnIntColor.Values (R, G, B, Quantity_TOC_RGB);
2171
2172 MyCStructure.ContextFillArea.Style = int (AStyle);
2173 MyCStructure.ContextFillArea.IntColor.r = float (R);
2174 MyCStructure.ContextFillArea.IntColor.g = float (G);
2175 MyCStructure.ContextFillArea.IntColor.b = float (B);
2176#ifdef OCC1174
2177 if ( CTXF->Distinguish() )
2178 BackIntColor.Values( R, G, B, Quantity_TOC_RGB );
2179#endif
2180 MyCStructure.ContextFillArea.BackIntColor.r = float( R );
2181 MyCStructure.ContextFillArea.BackIntColor.g = float( G );
2182 MyCStructure.ContextFillArea.BackIntColor.b = float( B );
2183
2184 // Edges
2185 MyCStructure.ContextFillArea.Edge = CTXF->Edge () ? 1:0;
2186 AnEdgeColor.Values (R, G, B, Quantity_TOC_RGB);
2187 MyCStructure.ContextFillArea.EdgeColor.r = float (R);
2188 MyCStructure.ContextFillArea.EdgeColor.g = float (G);
2189 MyCStructure.ContextFillArea.EdgeColor.b = float (B);
2190 MyCStructure.ContextFillArea.LineType = int (ALType);
2191 MyCStructure.ContextFillArea.Width = float (AWidth);
2192 MyCStructure.ContextFillArea.Hatch = int (CTXF->HatchStyle ());
2193#ifdef G003
2194 Quantity_Ratio ratio;
bbf32d01 2195 MyCStructure.ContextFillArea.DegenerationMode =
7fd59977 2196 int (CTXF->DegenerateModel(ratio));
2197 MyCStructure.ContextFillArea.SkipRatio = float (ratio);
2198#endif // G003
2199
2200
2201 /*** Front and Back face ***/
2202 MyCStructure.ContextFillArea.Distinguish = CTXF->Distinguish () ? 1:0;
2203 MyCStructure.ContextFillArea.BackFace = CTXF->BackFace () ? 1:0;
2204 /*** Back Material ***/
2205 // Light specificity
2206 MyCStructure.ContextFillArea.Back.Shininess =
2207 float ((CTXF->BackMaterial ()).Shininess ());
2208 MyCStructure.ContextFillArea.Back.Ambient =
2209 float ((CTXF->BackMaterial ()).Ambient ());
2210 MyCStructure.ContextFillArea.Back.Diffuse =
2211 float ((CTXF->BackMaterial ()).Diffuse ());
2212 MyCStructure.ContextFillArea.Back.Specular =
2213 float ((CTXF->BackMaterial ()).Specular ());
2214 MyCStructure.ContextFillArea.Back.Transparency =
2215 float ((CTXF->BackMaterial ()).Transparency ());
2216 MyCStructure.ContextFillArea.Back.Emission =
2217 float ((CTXF->BackMaterial ()).Emissive ());
2218
2219 // Reflection mode
2220 MyCStructure.ContextFillArea.Back.IsAmbient =
2221 ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 );
2222 MyCStructure.ContextFillArea.Back.IsDiffuse =
2223 ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 );
2224 MyCStructure.ContextFillArea.Back.IsSpecular =
2225 ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 );
2226 MyCStructure.ContextFillArea.Back.IsEmission =
2227 ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 );
2228
2229 // Material type
2230 //JR/Hp
2231 const Graphic3d_MaterialAspect ama = CTXF->BackMaterial () ;
2232 Standard_Boolean amt = ama.MaterialType(Graphic3d_MATERIAL_PHYSIC) ;
2233 MyCStructure.ContextFillArea.Back.IsPhysic = ( amt ? 1 : 0 );
2234
2235 // Specular color
2236 MyCStructure.ContextFillArea.Back.ColorSpec.r =
2237 float (((CTXF->BackMaterial ()).SpecularColor ()).Red ());
2238 MyCStructure.ContextFillArea.Back.ColorSpec.g =
2239 float (((CTXF->BackMaterial ()).SpecularColor ()).Green ());
2240 MyCStructure.ContextFillArea.Back.ColorSpec.b =
2241 float (((CTXF->BackMaterial ()).SpecularColor ()).Blue ());
2242
2243 // Ambient color
2244 MyCStructure.ContextFillArea.Back.ColorAmb.r =
2245 float (((CTXF->BackMaterial ()).AmbientColor ()).Red ());
2246 MyCStructure.ContextFillArea.Back.ColorAmb.g =
2247 float (((CTXF->BackMaterial ()).AmbientColor ()).Green ());
2248 MyCStructure.ContextFillArea.Back.ColorAmb.b =
2249 float (((CTXF->BackMaterial ()).AmbientColor ()).Blue ());
2250
2251 // Diffuse color
2252 MyCStructure.ContextFillArea.Back.ColorDif.r =
2253 float (((CTXF->BackMaterial ()).DiffuseColor ()).Red ());
2254 MyCStructure.ContextFillArea.Back.ColorDif.g =
2255 float (((CTXF->BackMaterial ()).DiffuseColor ()).Green ());
2256 MyCStructure.ContextFillArea.Back.ColorDif.b =
2257 float (((CTXF->BackMaterial ()).DiffuseColor ()).Blue ());
2258
2259 // Emissive color
2260 MyCStructure.ContextFillArea.Back.ColorEms.r =
2261 float (((CTXF->BackMaterial ()).EmissiveColor ()).Red ());
2262 MyCStructure.ContextFillArea.Back.ColorEms.g =
2263 float (((CTXF->BackMaterial ()).EmissiveColor ()).Green ());
2264 MyCStructure.ContextFillArea.Back.ColorEms.b =
2265 float (((CTXF->BackMaterial ()).EmissiveColor ()).Blue ());
2266
bbf32d01 2267 MyCStructure.ContextFillArea.Back.EnvReflexion =
7fd59977 2268 float ((CTXF->BackMaterial ()).EnvReflexion());
2269
2270 /*** Front Material ***/
2271 // Light specificity
2272 MyCStructure.ContextFillArea.Front.Shininess =
2273 float ((CTXF->FrontMaterial ()).Shininess ());
2274 MyCStructure.ContextFillArea.Front.Ambient =
2275 float ((CTXF->FrontMaterial ()).Ambient ());
2276 MyCStructure.ContextFillArea.Front.Diffuse =
2277 float ((CTXF->FrontMaterial ()).Diffuse ());
2278 MyCStructure.ContextFillArea.Front.Specular =
2279 float ((CTXF->FrontMaterial ()).Specular ());
2280 MyCStructure.ContextFillArea.Front.Transparency =
2281 float ((CTXF->FrontMaterial ()).Transparency ());
2282 MyCStructure.ContextFillArea.Front.Emission =
2283 float ((CTXF->FrontMaterial ()).Emissive ());
2284
2285 // Reflection mode
2286 MyCStructure.ContextFillArea.Front.IsAmbient =
2287 ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 );
2288 MyCStructure.ContextFillArea.Front.IsDiffuse =
2289 ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 );
2290 MyCStructure.ContextFillArea.Front.IsSpecular =
2291 ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 );
2292 MyCStructure.ContextFillArea.Front.IsEmission =
2293 ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 );
2294
2295 // Material type
2296 //JR/Hp
2297 const Graphic3d_MaterialAspect amas = CTXF->FrontMaterial () ;
2298 Standard_Boolean amty = amas.MaterialType(Graphic3d_MATERIAL_PHYSIC) ;
2299 MyCStructure.ContextFillArea.Front.IsPhysic = ( amty ? 1 : 0 );
2300
2301 // Specular color
2302 MyCStructure.ContextFillArea.Front.ColorSpec.r =
2303 float (((CTXF->FrontMaterial ()).SpecularColor ()).Red ());
2304 MyCStructure.ContextFillArea.Front.ColorSpec.g =
2305 float (((CTXF->FrontMaterial ()).SpecularColor ()).Green ());
2306 MyCStructure.ContextFillArea.Front.ColorSpec.b =
2307 float (((CTXF->FrontMaterial ()).SpecularColor ()).Blue ());
2308
2309 // Ambient color
2310 MyCStructure.ContextFillArea.Front.ColorAmb.r =
2311 float (((CTXF->FrontMaterial ()).AmbientColor ()).Red ());
2312 MyCStructure.ContextFillArea.Front.ColorAmb.g =
2313 float (((CTXF->FrontMaterial ()).AmbientColor ()).Green ());
2314 MyCStructure.ContextFillArea.Front.ColorAmb.b =
2315 float (((CTXF->FrontMaterial ()).AmbientColor ()).Blue ());
2316
2317 // Diffuse color
2318 MyCStructure.ContextFillArea.Front.ColorDif.r =
2319 float (((CTXF->FrontMaterial ()).DiffuseColor ()).Red ());
2320 MyCStructure.ContextFillArea.Front.ColorDif.g =
2321 float (((CTXF->FrontMaterial ()).DiffuseColor ()).Green ());
2322 MyCStructure.ContextFillArea.Front.ColorDif.b =
2323 float (((CTXF->FrontMaterial ()).DiffuseColor ()).Blue ());
2324
2325 // Emissive color
2326 MyCStructure.ContextFillArea.Front.ColorEms.r =
2327 float (((CTXF->FrontMaterial ()).EmissiveColor ()).Red ());
2328 MyCStructure.ContextFillArea.Front.ColorEms.g =
2329 float (((CTXF->FrontMaterial ()).EmissiveColor ()).Green ());
2330 MyCStructure.ContextFillArea.Front.ColorEms.b =
2331 float (((CTXF->FrontMaterial ()).EmissiveColor ()).Blue ());
2332
bbf32d01 2333 MyCStructure.ContextFillArea.Front.EnvReflexion =
7fd59977 2334 float ((CTXF->FrontMaterial ()).EnvReflexion());
2335
2336 Handle(Graphic3d_TextureMap) TempTextureMap = CTXF->TextureMap();
2337 if (! TempTextureMap.IsNull() )
2338 MyCStructure.ContextFillArea.Texture.TexId = TempTextureMap->TextureId();
2339 else
2340 MyCStructure.ContextFillArea.Texture.TexId = -1;
2341
2342 MyCStructure.ContextFillArea.Texture.doTextureMap = CTXF->TextureMapState() ? 1:0;
2343
bbf32d01 2344 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
7fd59977 2345 Standard_Integer aPolyMode;
2346 Standard_Real aPolyFactor, aPolyUnits;
2347 CTXF->PolygonOffsets(aPolyMode, aPolyFactor, aPolyUnits);
2348 MyCStructure.ContextFillArea.PolygonOffsetMode = aPolyMode;
2349 MyCStructure.ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2350 MyCStructure.ContextFillArea.PolygonOffsetUnits = aPolyUnits;
bbf32d01 2351 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
7fd59977 2352}
2353
2354void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod AMethod) {
2355
2356 Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax;
2357 Standard_Real R, G, B;
2358
2359 MyCStructure.highlight = 1;
2360 MyHighlightMethod = AMethod;
2361
bbf32d01 2362 switch (AMethod)
7fd59977 2363 {
2364 case Aspect_TOHM_COLOR :
2365 MyHighlightColor.Values (R, G, B, Quantity_TOC_RGB);
2366 MyGraphicDriver->HighlightColor
2367 (MyCStructure, float (R), float (G),
2368 float (B) , Standard_True);
2369 MyGraphicDriver->NameSetStructure (MyCStructure);
2370 break;
2371 case Aspect_TOHM_BLINK :
2372 MyGraphicDriver->Blink (MyCStructure, Standard_True);
2373 MyGraphicDriver->NameSetStructure (MyCStructure);
2374 break;
2375 case Aspect_TOHM_BOUNDBOX :
2376 if (IsEmpty () || IsInfinite ()) {
81bba717 2377 // Empty or infinite structure
7fd59977 2378 XMin = YMin = ZMin = 0.;
2379 XMax = YMax = ZMax = 0.;
2380 }
2381 else {
2382 MinMaxCoord
2383 (XMin, YMin, ZMin, XMax, YMax, ZMax);
2384 }
2385 MyCStructure.BoundBox.Pmin.x = float (XMin);
2386 MyCStructure.BoundBox.Pmin.y = float (YMin);
2387 MyCStructure.BoundBox.Pmin.z = float (ZMin);
2388 MyCStructure.BoundBox.Pmax.x = float (XMax);
2389 MyCStructure.BoundBox.Pmax.y = float (YMax);
2390 MyCStructure.BoundBox.Pmax.z = float (ZMax);
2391 MyHighlightColor.Values (R, G, B, Quantity_TOC_RGB);
2392 MyCStructure.BoundBox.Color.r = float (R);
2393 MyCStructure.BoundBox.Color.g = float (G);
2394 MyCStructure.BoundBox.Color.b = float (B);
2395 MyGraphicDriver->BoundaryBox (MyCStructure, Standard_True);
2396 break;
2397 }
2398
2399}
2400
2401void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& AMatrix) {
2402
2403 Standard_Integer i, j;
2404
2405 for (i=0; i<=3; i++)
2406 for (j=0; j<=3; j++)
2407 MyCStructure.Transformation[i][j] = float (AMatrix (i, j));
2408
2409 MyGraphicDriver->TransformStructure (MyCStructure);
2410
2411}
2412
2413void Graphic3d_Structure::GraphicUnHighlight () {
2414
2415 MyCStructure.highlight = 0;
2416
bbf32d01 2417 switch (MyHighlightMethod)
7fd59977 2418 {
2419 case Aspect_TOHM_COLOR :
2420 MyGraphicDriver->HighlightColor
2421 (MyCStructure, 0.0, 0.0, 0.0 , Standard_False);
2422 MyGraphicDriver->NameSetStructure (MyCStructure);
2423 break;
2424 case Aspect_TOHM_BLINK :
2425 MyGraphicDriver->Blink (MyCStructure, Standard_False);
2426 MyGraphicDriver->NameSetStructure (MyCStructure);
2427 break;
2428 case Aspect_TOHM_BOUNDBOX :
2429 MyGraphicDriver->BoundaryBox
2430 (MyCStructure, Standard_False);
2431 MyGraphicDriver->NameSetStructure (MyCStructure);
2432 break;
2433 }
2434
2435}
2436
2437Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual () const {
2438
2439 return (MyComputeVisual);
2440
2441}
2442
2443void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure AVisual) {
2444
81bba717 2445 // The ComputeVisual is saved only if the structure is
2446 // declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2447 // This declaration permits to calculate
2448 // proper representation of the structure calculated by Compute
2449 // instead of passage to TOS_COMPUTED.
7fd59977 2450 if (AVisual != Graphic3d_TOS_COMPUTED)
2451 MyComputeVisual = AVisual;
2452
2453}
2454
2455void Graphic3d_Structure::Plot (const Handle(Graphic3d_Plotter)& ) {
2456
2457}
2458
2459void Graphic3d_Structure::SetManager (const Handle(Graphic3d_StructureManager)& AManager, const Standard_Boolean WithPropagation) {
2460
81bba717 2461 // All connected structures should follow ?
7fd59977 2462#ifdef IMPLEMENTED
2463 if (WithPropagation) {
2464 Standard_Integer i, Length;
2465 Length = MyDescendants.Length ();
2466 for (i=1; i<=Length; i++)
2467 ((Graphic3d_Structure *)
2468 (MyDescendants.Value (i)))->SetStructureManager (AManager);
2469
2470 Length = MyAncestors.Length ();
2471 for (i=1; i<=Length; i++)
2472 ((Graphic3d_Structure *)
2473 (MyAncestors.Value (i)))->SetStructureManager (AManager);
2474 }
2475#endif
2476
81bba717 2477 // change of identification ?
7fd59977 2478 // MyStructureManager->Remove (Standard_Integer (MyCStructure.Id));
2479 // AManager->NewIdentification ();
2480 // MyCStructure.Id = int (AManager->NewIdentification ());
2481
2482 Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode ();
2483 Aspect_TypeOfUpdate NewUpdateMode = AManager->UpdateMode ();
2484 MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
2485 AManager->SetUpdateMode (Aspect_TOU_WAIT);
2486
2487 if (MyCStructure.stick) {
2488 MyStructureManager->Erase (this);
2489 AManager->Display (this);
2490 }
2491
2492 if (MyCStructure.highlight) {
2493 }
2494
2495 if (MyCStructure.visible) {
2496 MyStructureManager->Invisible (this);
2497 AManager->Visible (this);
2498 }
2499
2500 if (MyCStructure.pick) {
2501 MyStructureManager->Undetectable (this);
2502 AManager->Detectable (this);
2503 }
2504
2505 MyStructureManager->SetUpdateMode (UpdateMode);
2506 AManager->SetUpdateMode (NewUpdateMode);
2507
81bba717 2508 // New manager
7fd59977 2509 MyPtrStructureManager = (void *) AManager.operator->();
2510
2511}
2512
2513void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean AFlag) {
2514
2515 MyCStructure.HLRValidation = AFlag ? 1:0;
2516
2517}
2518
2519Standard_Boolean Graphic3d_Structure::HLRValidation () const {
2520
81bba717 2521 // Hidden parts stored in <me> are valid if :
2522 // 1/ the owner is defined.
2523 // 2/ they are not invalid.
7fd59977 2524
2525 Standard_Boolean Result = MyOwner != NULL && MyCStructure.HLRValidation != 0;
2526
2527 return Result;
2528
2529}
2530
2531Standard_Address Graphic3d_Structure::CStructure () const {
2532
2533 return Standard_Address (&MyCStructure);
2534
2535}