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