0022649: Export to EMF not available
[occt.git] / src / Visual3d / Visual3d_View.cxx
1 /***********************************************************************
2
3      FONCTION :
4      ----------
5         Classe Visual3d_View.cxx :
6
7
8         Declaration of variables specific to views.
9
10         A view is defined by :
11                 -  ViewManager
12                 -  ContextView
13                 -  ViewMapping
14                 -  ViewOrientation
15
16      HISTORIQUE DES MODIFICATIONS   :
17      --------------------------------
18       Mars 1992 : NW,JPB,CAL ; Creation.
19       04-02-97  : FMN ; Suppression de PSOutput, XWDOutput ...
20       22-04-97  : CAL ; Ajout du Plot.
21       03-06-97  : FMN ; Correction calcul SetRatio
22       06-05-97  : CAL ; Ajout du Clear sur les TOS_COMPUTED.
23       28-07-97  : PCT ; Ajout lumiere frontale headlight.
24       19-09-97  : CAL ; Remplacement de Window->Position par Window->Size;
25       17-10-97  : CAL ; Le Projects nouveau est arrive. (NewProjects)
26       24-10-97  : CAL ; Retrait de DownCast.
27       24-10-97  : CAL ; Retrait des DataStructure (Vieille maquette inutilisee).
28       17-11-97  : FMN ; Ajout DoResize dans Resized()
29       20-11-97  : CAL ; Disparition de la dependance avec math
30       ??-11-97  : CAL ; Retrait de la dependance avec math. Calcul developpe.
31       ??-11-97  : CAL ; Ajout de NumberOfDisplayedStructures
32       07-08-97  : PCT ; ajout support texture mapping
33       05-01-98  : CAL ; Ajout de AnimationMode
34       15-01-98  : FMN ; FRA60019 calcul Ratio pour MyViewMappingReset
35       15-01-98  : CAL ; Ajout de la transformation d'une TOS_COMPUTED
36       26-01-98  : CAL ; Ajout de la methode HaveTheSameOwner
37       06-02-98  : FMN ; CTS19079: TOP TEN: Probleme de highlight dans EDesigner.
38       05-03-98  : CAL ; GraphicTransform que si Trsf non invalidante
39       27-03-98  : CAL ; Ajout de TheStructure = devant Compute (...) !!!!
40       16-04-98  : CAL ; Remise a ID de la Trsf sur la COMPUTED
41       20-05-98  : CAL ; Perfs. Connection entre structures COMPUTED.
42       24-06-98  : CAL ; PRO14526 SetTransparency sur une vue non active.
43       17-07-98  : CAL ; PRO14872 test sur aTrsf dans ::SetTransform.
44       16-09-98  : BGN ; Points d'entree du Triedre (S3819, Phase 1)
45       22-09-98  : BGN ; S3989 (anciennement S3819)
46                         TypeOfTriedron* from Aspect (pas Visual3d)
47       06-10-98  : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
48       16-10-98  : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
49       02-11-98  : CAL ; Retrait de OSD::SetSignal.
50       18-11-98  : FMN ; Correction sur la gestion de la perspective
51       02-12-98  : CAL ; S4062. Ajout des layers.
52       13-09-99  : GG  ; GER61454 Adds LightLimit() and PlaneLimit() methods
53       10-11-99  : GG  ; PRO19603 Add Redraw( area ) method
54       14-01-00  : GG  ; IMP140100 Add ViewManager( ) method
55       22-10-01  : SAV ; Added EnableDepthTest() method.
56       30-04-02  : JMB ; MyDisplayStructure : use a Map instead of a Set (very bad performance
57                         in data access when a lot of objects are used)
58                         Will improve performance of selection mechanisms
59
60 ************************************************************************/
61
62 #define BUC60572        //GG_03-08-99    Add protection on Zclipping & Zcueing planes
63 //              positions.
64
65 #define BUC60570        //GG 14-09-99 Don't activates lighting
66 //                      when the view shading model is NONE.
67
68 #define GER61454        //GG 14-09-99 Activates model clipping planes
69
70 #define IMP140100       //GG14-01-00 Add ViewManager( ) method
71
72 #define G003            //EUG 30-09-00 Degeneration management
73 //                                     Backfacing management
74
75 #define RIC120302       //GG Add a NEW SetWindow method which enable
76 //                      to connect a graphic widget and context to OGL.
77
78 #define  BUC61044    /* 25/10/01 SAV ; added functionality to control gl depth testing
79                         from higher API */
80 #define  BUC61045    /* 25/10/01 SAV ; added functionality to control gl lighting
81                         from higher API */
82
83 #define OCC1188         //SAV Added methods to set background image
84
85 /*----------------------------------------------------------------------*/
86 /*
87  * Constantes
88  */
89
90 #define NO_DEBUG
91 #define NO_DESTROY
92 #define NO_TRACE
93 #define NO_TRACE_ACCEPT
94 #define NO_TRACE_CLEAR
95 #define NO_TRACE_CONNECT
96 #define NO_TRACE_HIGH
97 #define NO_TRACE_COMP
98 #define NO_TRACE_TRSF
99 #define NO_TRACE_DISPLAY
100 #define NO_TRACE_ISCOMP
101 #define NO_TRACE_LENGTH
102 #define NO_TRACE_LAYER
103
104 /*----------------------------------------------------------------------*/
105 /*
106  * Includes
107  */
108
109 #ifdef WNT
110 #include <windows.h>
111 #endif
112
113 // for the class
114 #include <Visual3d_View.ixx>
115 #include <Visual3d_View.pxx>
116 #include <Visual3d_DepthCueingDefinitionError.hxx>
117 #include <Visual3d_ZClippingDefinitionError.hxx>
118
119 #ifdef OLD_METHOD
120 #include <math_Vector.hxx>
121 #endif /* OLD_METHOD */
122
123 #include <OSD.hxx>
124
125 #include <Graphic3d_Structure.hxx>
126 #include <Graphic3d_MapOfStructure.hxx>
127 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
128 #include <Graphic3d_DataStructureManager.hxx>
129
130 #include <Graphic3d_GraphicDriver.hxx>
131 #include <Graphic3d_GraphicDevice.hxx>
132
133 #include <Graphic3d_Vector.hxx>
134 #include <Graphic3d_Vertex.hxx>
135
136 #include <Visual3d_Light.hxx>
137 #include <Visual3d_SetOfLight.hxx>
138 #include <Visual3d_HSetOfLight.hxx>
139 #include <Visual3d_SetIteratorOfSetOfLight.hxx>
140
141 #include <Visual3d_ClipPlane.hxx>
142 #include <Visual3d_SetOfClipPlane.hxx>
143 #include <Visual3d_HSetOfClipPlane.hxx>
144 #include <Visual3d_SetIteratorOfSetOfClipPlane.hxx>
145
146 #include <Visual3d_SetIteratorOfSetOfView.hxx>
147
148 #include <Graphic3d_TextureEnv.hxx>
149
150 #include <TColStd_HArray2OfReal.hxx>
151
152 #ifndef WNT
153 # include <Xw_Window.hxx>
154 #else
155 # include <WNT_Window.hxx>
156 #endif  // WNT
157
158 #include <float.h>
159
160 //-Aliases
161
162 //-Global data definitions
163
164 //-Constructors
165
166 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager):
167 MyContext (),
168 MyViewMapping (),
169 MyViewMappingReset (),
170 MyViewOrientation (),
171 MyViewOrientationReset (),
172 MyTransformation (0, 3, 0, 3),
173 MyMatrixOfMapping (0, 3, 0, 3),
174 MyMatrixOfOrientation (0, 3, 0, 3),
175 MyTOCOMPUTESequence (),
176 MyCOMPUTEDSequence (),
177 MyDisplayedStructure ()
178 {
179 Standard_Integer i, j;
180
181 #ifdef IMP140100
182         MyPtrViewManager        = AManager.operator->();
183 #else
184         MyPtrViewManager        = (void *) AManager.operator->();
185 #endif
186
187         memset (&MyCView, 0, sizeof(MyCView));
188         MyCView.ViewId          = int (AManager->Identification (this));
189         MyCView.Active          = 0;
190         MyCView.IsDeleted       = 0;
191
192         MyCView.WsId    = -1;
193         MyCView.DefWindow.IsDefined     = 0;
194
195         MyCView.Context.NbActiveLight   = 0;
196         MyCView.Context.NbActivePlane   = 0;
197 #ifdef GER61454
198         MyCView.Context.ActivePlane = NULL;
199 #endif
200
201         for (i=0; i<=3; i++)
202                 for (j=0; j<=3; j++)
203                         if (i == j)     MyTransformation (i, j) = 1.0;
204                         else            MyTransformation (i, j) = 0.0;
205
206 Standard_Real X, Y, Z;
207
208         (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
209         MyCView.Orientation.ViewReferencePoint.x        = float (X);
210         MyCView.Orientation.ViewReferencePoint.y        = float (Y);
211         MyCView.Orientation.ViewReferencePoint.z        = float (Z);
212         (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
213         MyCView.Orientation.ViewReferencePlane.x        = float (X);
214         MyCView.Orientation.ViewReferencePlane.y        = float (Y);
215         MyCView.Orientation.ViewReferencePlane.z        = float (Z);
216         (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
217         MyCView.Orientation.ViewReferenceUp.x           = float (X);
218         MyCView.Orientation.ViewReferenceUp.y           = float (Y);
219         MyCView.Orientation.ViewReferenceUp.z           = float (Z);
220
221 Standard_Real Sx, Sy, Sz;
222
223         MyViewOrientation.AxialScale(Sx, Sy, Sz);
224         MyCView.Orientation.ViewScaleX                  = float (Sx);
225         MyCView.Orientation.ViewScaleY                  = float (Sy);
226         MyCView.Orientation.ViewScaleZ                  = float (Sz);
227
228         // NKV : 23/07/07 - Define custom MODELVIEW matrix
229         MyCView.Orientation.IsCustomMatrix = 0;
230         memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
231         MyCView.Orientation.ModelViewMatrix[0][0] =
232         MyCView.Orientation.ModelViewMatrix[1][1] =
233         MyCView.Orientation.ModelViewMatrix[2][2] =
234         MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
235         //
236
237 Standard_Real um, vm, uM, vM;
238
239         MyCView.Mapping.Projection      = int (MyViewMapping.Projection ());
240         (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
241         MyCView.Mapping.ProjectionReferencePoint.x      = float (X);
242         MyCView.Mapping.ProjectionReferencePoint.y      = float (Y);
243         MyCView.Mapping.ProjectionReferencePoint.z      = float (Z);
244         MyCView.Mapping.ViewPlaneDistance       =
245                         float (MyViewMapping.ViewPlaneDistance ());
246         MyCView.Mapping.BackPlaneDistance       =
247                         float (MyViewMapping.BackPlaneDistance ());
248         MyCView.Mapping.FrontPlaneDistance      =
249                         float (MyViewMapping.FrontPlaneDistance ());
250         MyViewMapping.WindowLimit (um, vm, uM, vM);
251         MyCView.Mapping.WindowLimit.um  = float (um);
252         MyCView.Mapping.WindowLimit.vm  = float (vm);
253         MyCView.Mapping.WindowLimit.uM  = float (uM);
254         MyCView.Mapping.WindowLimit.vM  = float (vM);
255
256         // NKV : 23/07/07 - Define custom MODELVIEW matrix
257         MyCView.Mapping.IsCustomMatrix = 0;
258         memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
259         MyCView.Mapping.ProjectionMatrix[0][0] =
260         MyCView.Mapping.ProjectionMatrix[1][1] =
261         MyCView.Mapping.ProjectionMatrix[2][2] =
262         MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
263         //
264
265         MyCView.Context.ZBufferActivity = -1;
266
267         MyMatOfMapIsModified    = Standard_True;
268         MyMatOfOriIsModified    = Standard_True;
269         MyMatOfMapIsEvaluated   = Standard_False;
270         MyMatOfOriIsEvaluated   = Standard_False;
271
272         DegenerateModeIsActive  = Standard_False;
273         AnimationModeIsActive   = Standard_False;
274 #ifdef G003
275         MyCView.IsDegenerates     = 0;
276         MyCView.IsDegeneratesPrev = 0;
277         ComputedModeIsActive      = Standard_False;
278         MyCView.Backfacing        = 0;
279 #endif  // G003
280
281         MyCView.DefBitmap.bitmap = 0;
282         MyCView.ptrUnderLayer = 0;
283         MyCView.ptrOverLayer = 0;
284         MyCView.GContext = 0;
285         MyCView.GDisplayCB = 0;
286         MyCView.GClientData = 0;
287
288 Handle(Aspect_GraphicDriver) agd =
289         (MyViewManager->GraphicDevice ())->GraphicDriver ();
290
291         MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
292
293 }
294
295 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager, const Visual3d_ViewOrientation& VO, const Visual3d_ViewMapping& VM, const Visual3d_ContextView& CTX):
296 MyTransformation (0, 3, 0, 3),
297 MyMatrixOfMapping (0, 3, 0, 3),
298 MyMatrixOfOrientation (0, 3, 0, 3),
299 MyTOCOMPUTESequence (),
300 MyCOMPUTEDSequence (),
301 MyDisplayedStructure ()
302 {
303 Standard_Integer i, j;
304
305 #ifdef IMP140100
306         MyPtrViewManager        = AManager.operator->();
307 #else
308         MyPtrViewManager        = (void *) AManager.operator->();
309 #endif
310
311         MyViewOrientation       = VO;
312         MyViewMapping           = VM;
313         MyContext               = CTX;
314         MyViewOrientationReset  = VO;
315         MyViewMappingReset      = VM;
316
317         memset (&MyCView, 0, sizeof(MyCView));
318         MyCView.ViewId          = int (AManager->Identification (this));
319         MyCView.Active          = 0;
320         MyCView.IsDeleted       = 0;
321
322         MyCView.WsId    = -1;
323         MyCView.DefWindow.IsDefined     = 0;
324
325         MyCView.Context.NbActiveLight   = 0;
326         MyCView.Context.NbActivePlane   = 0;
327 #ifdef GER61454
328         MyCView.Context.ActivePlane = NULL;
329 #endif
330
331         for (i=0; i<=3; i++)
332                 for (j=0; j<=3; j++)
333                         if (i == j)     MyTransformation (i, j) = 1.0;
334                         else            MyTransformation (i, j) = 0.0;
335
336 Standard_Real X, Y, Z;
337
338         (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
339         MyCView.Orientation.ViewReferencePoint.x        = float (X);
340         MyCView.Orientation.ViewReferencePoint.y        = float (Y);
341         MyCView.Orientation.ViewReferencePoint.z        = float (Z);
342         (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
343         MyCView.Orientation.ViewReferencePlane.x        = float (X);
344         MyCView.Orientation.ViewReferencePlane.y        = float (Y);
345         MyCView.Orientation.ViewReferencePlane.z        = float (Z);
346         (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
347         MyCView.Orientation.ViewReferenceUp.x           = float (X);
348         MyCView.Orientation.ViewReferenceUp.y           = float (Y);
349         MyCView.Orientation.ViewReferenceUp.z           = float (Z);
350
351 Standard_Real Sx, Sy, Sz;
352
353         MyViewOrientation.AxialScale(Sx, Sy, Sz);
354         MyCView.Orientation.ViewScaleX                  = float (Sx);
355         MyCView.Orientation.ViewScaleY                  = float (Sy);
356         MyCView.Orientation.ViewScaleZ                  = float (Sz);
357
358         // NKV : 23/07/07 - Define custom MODELVIEW matrix
359         if (MyViewOrientation.IsCustomMatrix()) {
360           MyCView.Orientation.IsCustomMatrix = 1;
361           for ( i = 0; i < 4; i++)
362             for ( j = 0; j < 4; j++)
363               MyCView.Orientation.ModelViewMatrix[i][j] = MyViewOrientation.MyModelViewMatrix->Value(i,j);
364         }
365         else {
366           MyCView.Orientation.IsCustomMatrix = 0;
367           memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
368           MyCView.Orientation.ModelViewMatrix[0][0] =
369           MyCView.Orientation.ModelViewMatrix[1][1] =
370           MyCView.Orientation.ModelViewMatrix[2][2] =
371           MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
372         }
373         //
374
375 Standard_Real um, vm, uM, vM;
376
377         MyCView.Mapping.Projection      = int (MyViewMapping.Projection ());
378         (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
379         MyCView.Mapping.ProjectionReferencePoint.x      = float (X);
380         MyCView.Mapping.ProjectionReferencePoint.y      = float (Y);
381         MyCView.Mapping.ProjectionReferencePoint.z      = float (Z);
382         MyCView.Mapping.ViewPlaneDistance       =
383                         float (MyViewMapping.ViewPlaneDistance ());
384         MyCView.Mapping.BackPlaneDistance       =
385                         float (MyViewMapping.BackPlaneDistance ());
386         MyCView.Mapping.FrontPlaneDistance      =
387                         float (MyViewMapping.FrontPlaneDistance ());
388         MyViewMapping.WindowLimit (um, vm, uM, vM);
389         MyCView.Mapping.WindowLimit.um  = float (um);
390         MyCView.Mapping.WindowLimit.vm  = float (vm);
391         MyCView.Mapping.WindowLimit.uM  = float (uM);
392         MyCView.Mapping.WindowLimit.vM  = float (vM);
393
394         // NKV : 23/07/07 - Define custom MODELVIEW matrix
395         if (MyViewMapping.IsCustomMatrix()) {
396           MyCView.Mapping.IsCustomMatrix = 1;
397           for ( i = 0; i < 4; i++)
398             for ( j = 0; j < 4; j++)
399               MyCView.Mapping.ProjectionMatrix[i][j] = MyViewMapping.MyProjectionMatrix->Value(i,j);
400         }
401         else {
402           MyCView.Mapping.IsCustomMatrix = 0;
403           memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
404           MyCView.Mapping.ProjectionMatrix[0][0] =
405           MyCView.Mapping.ProjectionMatrix[1][1] =
406           MyCView.Mapping.ProjectionMatrix[2][2] =
407           MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
408         }
409         //
410
411         MyCView.Context.ZBufferActivity = -1;
412
413         MyMatOfMapIsModified    = Standard_True;
414         MyMatOfOriIsModified    = Standard_True;
415         MyMatOfMapIsEvaluated   = Standard_False;
416         MyMatOfOriIsEvaluated   = Standard_False;
417 #ifdef G003
418         AnimationModeIsActive     = Standard_False;
419         MyCView.IsDegenerates     = 0;
420         MyCView.IsDegeneratesPrev = 0;
421         ComputedModeIsActive      = Standard_False;
422 #endif  // G003
423
424         MyCView.DefBitmap.bitmap = 0;
425         MyCView.ptrUnderLayer = 0;
426         MyCView.ptrOverLayer = 0;
427         MyCView.GContext = 0;
428         MyCView.GDisplayCB = 0;
429         MyCView.GClientData = 0;
430
431 Handle(Aspect_GraphicDriver) agd =
432         (MyViewManager->GraphicDevice ())->GraphicDriver ();
433
434         MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
435
436 }
437
438 //-Destructors
439
440 //-Methods, in order
441 // RIC120302
442 void Visual3d_View::SetWindow (const Handle(Aspect_Window)&      AWindow,
443                                const Aspect_RenderingContext     AContext,
444                                const Aspect_GraphicCallbackProc& ADisplayCB,
445                                const Standard_Address            AClientData)
446 {
447   if (IsDeleted ()) return;
448
449   if (IsDefined ())
450     Visual3d_ViewDefinitionError::Raise ("Window already defined");
451
452   MyCView.GContext        = AContext;
453   MyCView.GDisplayCB      = ADisplayCB;
454   MyCView.GClientData     = AClientData;
455   SetWindow(AWindow);
456 }
457 // RIC120302
458
459 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow) {
460
461         if (IsDeleted ()) return;
462
463         if (IsDefined ())
464                 Visual3d_ViewDefinitionError::Raise ("Window already defined");
465
466         MyWindow        = AWindow;
467         MyCView.WsId                    = MyCView.ViewId;
468         MyCView.DefWindow.IsDefined     = 1;
469 #ifndef WNT
470 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AWindow;
471         MyCView.DefWindow.XWindow       = theWindow->XWindow ();
472 #ifdef RIC120302
473         MyCView.DefWindow.XParentWindow = theWindow->XParentWindow ();
474 #endif
475 #else
476 WNT_WindowData* wd;
477 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AWindow;
478         MyCView.DefWindow.XWindow       = ( HWND )(theWindow->HWindow());
479 #ifdef RIC120302
480         MyCView.DefWindow.XParentWindow = ( HWND )(theWindow->HParentWindow());
481 #endif
482         wd = ( WNT_WindowData* )GetWindowLongPtr (( HWND )(theWindow->HWindow()), GWLP_USERDATA);
483         wd -> WNT_WDriver_Ptr = ( void* )this;
484         wd -> WNT_VMgr        = ( void* )MyPtrViewManager;
485 #endif  /* WNT */
486
487         Standard_Integer Width, Height;
488         AWindow->Size (Width, Height);
489
490         MyCView.DefWindow.dx    = float( Width );
491         MyCView.DefWindow.dy    = float( Height );
492
493         Standard_Real R, G, B;
494         MyBackground    = MyWindow->Background ();
495         (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
496         MyCView.DefWindow.Background.r  = float (R);
497         MyCView.DefWindow.Background.g  = float (G);
498         MyCView.DefWindow.Background.b  = float (B);
499
500         UpdateView ();
501         if (! MyGraphicDriver->View (MyCView))
502                 Visual3d_ViewDefinitionError::Raise ("Association failed");
503
504         MyGradientBackground = MyWindow->GradientBackground();
505         SetGradientBackground(MyGradientBackground,1);
506
507         Standard_Boolean AWait = Standard_False;        // => immediate update
508         MyGraphicDriver->SetVisualisation (MyCView);
509         MyGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn ());
510         MyGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn ());
511         MyGraphicDriver->ClipLimit (MyCView, AWait);
512         MyGraphicDriver->Environment(MyCView);
513
514         // Update planses of model clipping
515         UpdatePlanes ();
516
517         // Update light sources 
518         UpdateLights ();
519
520         /*
521          * Association view-window does not cause the display
522          * of structures that can be displayed in the new view.
523          * In fact, association view-window is done, but the
524          * display is produced only if the view is activated (Activate).
525          */
526
527         SetRatio ();
528
529 }
530
531 Handle(Aspect_Window) Visual3d_View::Window () const {
532
533         if (! IsDefined ())
534                 Visual3d_ViewDefinitionError::Raise ("Window not defined");
535
536         return (MyWindow);
537
538 }
539
540 Standard_Boolean Visual3d_View::IsDefined () const {
541
542         if (MyCView.DefWindow.IsDefined)
543                 return (Standard_True);
544         else
545                 return (Standard_False);
546
547 }
548
549 Standard_Boolean Visual3d_View::IsDeleted () const {
550
551         if (MyCView.IsDeleted)
552                 return (Standard_True);
553         else
554                 return (Standard_False);
555
556 }
557
558 void Visual3d_View::Destroy () {
559
560 #ifdef DESTROY
561         cout << "Visual3d_View::Destroy (" << Identification () << ")\n";
562 #endif
563
564         // Since MyPtrViewManager can be already distroyed,
565         // avoid attempts to access it in SetBackground()
566         MyPtrViewManager = 0;
567         Remove ();
568
569 }
570
571 void Visual3d_View::Remove () {
572
573 #ifdef DESTROY
574         cout << "Visual3d_View::Remove (" << Identification () << ")" << endl;
575 #endif
576
577         if (IsDeleted ()) return;
578         if (! IsDefined ()) return;
579
580         MyTOCOMPUTESequence.Clear ();
581         MyCOMPUTEDSequence.Clear ();
582         MyDisplayedStructure.Clear ();
583
584         Quantity_Color BlackColor (0.0, 0.0, 0.0, Quantity_TOC_RGB);
585         Aspect_Background BlackBackground (BlackColor);
586         SetBackground (BlackBackground);
587
588         Aspect_GradientBackground BlackGradBackground;
589         SetGradientBackground (BlackGradBackground,0);
590
591         if (MyPtrViewManager)
592           MyPtrViewManager->UnIdentification( MyCView.ViewId );
593
594         MyGraphicDriver->RemoveView (MyCView);
595
596         MyCView.WsId            = -1;
597         MyCView.IsDeleted       = 1;
598         MyCView.DefWindow.IsDefined     = 0;
599
600         MyMatOfMapIsModified    = Standard_True;
601         MyMatOfOriIsModified    = Standard_True;
602         MyMatOfMapIsEvaluated   = Standard_False;
603         MyMatOfOriIsEvaluated   = Standard_False;
604
605         MyWindow.Nullify ();
606
607 }
608
609 void Visual3d_View::Resized () {
610
611         if (IsDeleted ()) return;
612
613         if (! IsDefined ())
614                 Visual3d_ViewDefinitionError::Raise ("Window not defined");
615         MyWindow->DoResize() ;
616         SetRatio ();
617
618 }
619
620 void Visual3d_View::SetRatio () {
621
622         if (IsDeleted ()) return;
623
624 Aspect_TypeOfUpdate UpdateMode = MyViewManager->UpdateMode ();
625         MyViewManager->SetUpdateMode (Aspect_TOU_WAIT);
626
627 Standard_Real Umin, Vmin, Umax, Vmax;
628 Standard_Integer Dxw, Dyw;
629 Standard_Real Dxv, Dyv;
630 Standard_Real Xc, Yc;
631 Standard_Real Rap;
632
633         Rap     = 0. ;
634         MyWindow->Size (Dxw, Dyw);
635         MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
636         Xc      = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
637         Dxv     = Umax - Umin ; Dyv     = Vmax - Vmin ;
638         if( Dxw > 0 && Dyw > 0 ) Rap = (Standard_Real)Dyw/(Standard_Real)Dxw ;
639         if( Rap > 0.0 ) {
640
641             if( Dxv <= Dyv )
642             {
643                 if (Rap <= 1.0)
644                 {
645                     Dyv = Dxv;
646                     Dxv = Dxv/Rap;
647                 }
648                 else
649                 {
650                     Dxv = Dxv;
651                     Dyv = Dxv*Rap;
652                 }
653             }
654             else
655             {
656                 if (Rap <= 1.0)
657                 {
658                     Dxv = Dyv/Rap;
659                     Dyv = Dyv;
660                 }
661                 else
662                 {
663                     Dxv = Dyv;
664                     Dyv = Dyv*Rap;
665                 }
666             }
667
668             Umin        = Xc - Dxv/2. ; Vmin    = Yc - Dyv/2. ;
669             Umax        = Xc + Dxv/2. ; Vmax    = Yc + Dyv/2. ;
670
671             MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
672
673             // Update before SetViewMapping.
674
675             MyCView.DefWindow.dx        = float( Dxw );
676             MyCView.DefWindow.dy        = float( Dyw );
677
678             SetViewMapping (MyViewMapping);
679 //          SetViewMappingDefault ();
680             // FMN+ Update Ratio for MyViewMappingReset
681
682             MyViewMappingReset.WindowLimit(Umin,Vmin,Umax,Vmax) ;
683             Xc  = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
684             Dxv = Umax - Umin ; Dyv     = Vmax - Vmin ;
685
686             if( Dxv <= Dyv )
687             {
688                 if (Rap <= 1.0)
689                 {
690                     Dyv = Dxv;
691                     Dxv = Dxv/Rap;
692                 }
693                 else
694                 {
695                     Dxv = Dxv;
696                     Dyv = Dxv*Rap;
697                 }
698             }
699             else
700             {
701                 if (Rap <= 1.0)
702                 {
703                     Dxv = Dyv/Rap;
704                     Dyv = Dyv;
705                 }
706                 else
707                 {
708                     Dxv = Dyv;
709                     Dyv = Dyv*Rap;
710                 }
711             }
712
713             Umin        = Xc - Dxv/2. ; Vmin    = Yc - Dyv/2. ;
714             Umax        = Xc + Dxv/2. ; Vmax    = Yc + Dyv/2. ;
715
716             MyViewMappingReset.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
717
718             // FMN- Update Ratio for MyViewMappingReset
719
720             MyGraphicDriver->RatioWindow (MyCView);
721         }
722
723         // Force recalculation of 2 matrices.
724         //
725         // The current view can help to reconstruct a copied view
726         // that is itself. Owing to SetWindow and SetRatio the
727         // recalculation of matrices of this new view is imposed.
728         MyMatOfMapIsEvaluated   = Standard_False;
729         MyMatOfOriIsEvaluated   = Standard_False;
730
731         MyViewManager->SetUpdateMode (UpdateMode);
732         if (UpdateMode == Aspect_TOU_ASAP) Update ();
733
734 }
735
736 void Visual3d_View::UpdateLights () {
737
738 Standard_Integer i, j;
739 CALL_DEF_LIGHT *lights=NULL;
740
741 #ifdef BUC60570
742   if( MyContext.Model() == Visual3d_TOM_NONE ) {
743 // Activates only a white ambient light
744     MyCView.Context.NbActiveLight = 1;
745     lights      = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
746     MyCView.Context.ActiveLight = lights;
747
748     lights[0].WsId              = MyCView.ViewId;
749     lights[0].ViewId    = MyCView.ViewId;
750     lights[0].LightType = int (Visual3d_TOLS_AMBIENT);
751     lights[0].Active    = 1;
752     lights[0].LightId   = 0;
753     lights[0].Headlight = 0;
754     lights[0].Color.r   = lights[0].Color.g = lights[0].Color.b = 1.;
755   } else {
756 #endif
757         i       = MyContext.NumberOfActivatedLights ();
758         j       = MyGraphicDriver->InquireLightLimit ();
759         MyCView.Context.NbActiveLight   = (i > j ? j : i);
760
761         if (MyCView.Context.NbActiveLight > 0) {
762
763                 // Dynamic Allocation
764                 lights  = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
765
766                 MyCView.Context.ActiveLight     = lights;
767
768 Standard_Real X, Y, Z;
769
770 Standard_Real LightConcentration;
771 Standard_Real LightAttenuation1;
772 Standard_Real LightAttenuation2;
773 Standard_Real LightAngle;
774 Quantity_Color LightColor;
775 Graphic3d_Vertex LightPosition;
776 Graphic3d_Vector LightDirection;
777 Visual3d_TypeOfLightSource LightType=Visual3d_TOLS_AMBIENT;
778
779                 // Parcing of light sources
780                 for (j=0; j<MyCView.Context.NbActiveLight; j++) {
781                         LightType       = (MyContext.ActivatedLight (j+1))->LightType ();
782
783                         lights[j].WsId          = MyCView.ViewId;
784                         lights[j].ViewId        = MyCView.ViewId;
785
786                         lights[j].LightType     = int (LightType);
787                         lights[j].Active        = 1;
788                         lights[j].LightId       =
789                                 int ((MyContext.ActivatedLight (j+1))->Identification ());
790                         lights[j].Headlight = (MyContext.ActivatedLight (j+1))->Headlight ()? 1:0;
791
792                         switch (LightType) {
793
794                         case Visual3d_TOLS_AMBIENT :
795                                 (MyContext.ActivatedLight (j+1))->Values (
796                                                         LightColor
797                                                                 );
798                         break;
799
800                         case Visual3d_TOLS_POSITIONAL :
801                                 (MyContext.ActivatedLight (j+1))->Values (
802                                                         LightColor,
803                                                         LightPosition,
804                                                         LightAttenuation1,
805                                                         LightAttenuation2
806                                                                 );
807                         break;
808
809                         case Visual3d_TOLS_DIRECTIONAL :
810                                 (MyContext.ActivatedLight (j+1))->Values (
811                                                         LightColor,
812                                                         LightDirection
813                                                                 );
814                         break;
815
816                         case Visual3d_TOLS_SPOT :
817                                 (MyContext.ActivatedLight (j+1))->Values (
818                                                         LightColor,
819                                                         LightPosition,
820                                                         LightDirection,
821                                                         LightConcentration,
822                                                         LightAttenuation1,
823                                                         LightAttenuation2,
824                                                         LightAngle
825                                                                 );
826                         break;
827
828                         }
829
830                         lights[j].Color.r       = float (LightColor.Red ());
831                         lights[j].Color.g       = float (LightColor.Green ());
832                         lights[j].Color.b       = float (LightColor.Blue ());
833
834                         if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
835                              (LightType == Visual3d_TOLS_SPOT) ) {
836                                 LightPosition.Coord (X, Y, Z);
837                                 lights[j].Position.x    = float (X);
838                                 lights[j].Position.y    = float (Y);
839                                 lights[j].Position.z    = float (Z);
840                         }
841
842                         if ( (LightType == Visual3d_TOLS_DIRECTIONAL) ||
843                              (LightType == Visual3d_TOLS_SPOT) ) {
844                                 LightDirection.Coord (X, Y, Z);
845                                 lights[j].Direction.x   = float (X);
846                                 lights[j].Direction.y   = float (Y);
847                                 lights[j].Direction.z   = float (Z);
848                         }
849
850                         if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
851                              (LightType == Visual3d_TOLS_SPOT) ) {
852                                 lights[j].Attenuation[0] =
853                                         float (LightAttenuation1);
854                                 lights[j].Attenuation[1] =
855                                         float (LightAttenuation2);
856                         }
857
858                         if (LightType == Visual3d_TOLS_SPOT) {
859                                 lights[j].Concentration =
860                                         float (LightConcentration);
861                                 lights[j].Angle         =
862                                         float (LightAngle);
863                         }
864                 }
865
866         }
867 #ifdef BUC60570
868   }
869 #endif
870         // management of light sources
871         if (! IsDeleted ())
872                 if (IsDefined ())
873                         MyGraphicDriver->SetLight (MyCView);
874
875         // Dynamic allocation
876         if (MyCView.Context.NbActiveLight > 0) delete [] lights;
877
878 }
879
880 void Visual3d_View::UpdatePlanes () {
881
882 Standard_Integer i, j;
883 CALL_DEF_PLANE *planes=NULL;
884
885         i       = MyContext.NumberOfActivatedClipPlanes ();
886         j       = MyGraphicDriver->InquirePlaneLimit ();
887         MyCView.Context.NbActivePlane   = (i > j ? j : i);
888
889         if (MyCView.Context.NbActivePlane > 0) {
890
891                 // Dynamic Allocation 
892 #ifdef GER61454 //Keep the plane address for the next Update !
893                 if( !MyCView.Context.ActivePlane )
894                    MyCView.Context.ActivePlane = new CALL_DEF_PLANE [j];
895                 planes = MyCView.Context.ActivePlane;
896 #else
897                 planes  = new CALL_DEF_PLANE [MyCView.Context.NbActivePlane];
898
899                 MyCView.Context.ActivePlane     = planes;
900 #endif
901 Standard_Real A, B, C, D;
902
903                 // Parcing of clipping planes
904                 for (j=0; j<MyCView.Context.NbActivePlane; j++) {
905
906                         planes[j].WsId          = MyCView.ViewId;
907                         planes[j].ViewId        = MyCView.ViewId;
908
909                         planes[j].Active        = 1;
910                         planes[j].PlaneId       =
911                                 int ((MyContext.ActivatedClipPlane (j+1))->Identification ());
912
913                         (MyContext.ActivatedClipPlane (j+1))->Plane (A, B, C, D);
914                         planes[j].CoefA         = float (A);
915                         planes[j].CoefB         = float (B);
916                         planes[j].CoefC         = float (C);
917                         planes[j].CoefD         = float (D);
918                 }
919
920         }
921
922         // Management of planes of clipping model
923         if (! IsDeleted ())
924                 if (IsDefined ())
925                         MyGraphicDriver->SetPlane (MyCView);
926
927         // Dynamic allocation
928 #ifdef GER61454
929         if ( MyCView.Context.ActivePlane && (MyCView.Context.NbActivePlane == 0)
930  ) {
931           delete [] MyCView.Context.ActivePlane;
932           MyCView.Context.ActivePlane = NULL;
933         }
934 #else
935         if (MyCView.Context.NbActivePlane > 0) delete [] planes;
936 #endif
937
938 }
939
940 void Visual3d_View::SetBackground (const Aspect_Background& ABack) {
941
942         if (IsDeleted ()) return;
943
944         if (! IsDefined ())
945                 Visual3d_ViewDefinitionError::Raise ("Window not defined");
946
947         // At this level, only GL can update the background.
948         // It is not necessary to call MyWindow->SetBackground (ABack); as
949         // this method starts update of window background by X
950         // (if the windowing is X)
951
952         Standard_Real R, G, B;
953         MyBackground    = ABack;
954         (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
955         MyCView.DefWindow.Background.r  = float (R);
956         MyCView.DefWindow.Background.g  = float (G);
957         MyCView.DefWindow.Background.b  = float (B);
958
959         MyGraphicDriver->Background (MyCView);
960
961         if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
962           Update ();
963
964 }
965
966 void Visual3d_View::SetGradientBackground(const Aspect_GradientBackground& ABack, const Standard_Boolean update)
967 {
968
969   if (IsDeleted ()) return;
970
971   if (! IsDefined ())
972     Visual3d_ViewDefinitionError::Raise ("Window not defined");
973
974   MyGradientBackground = ABack;
975   Quantity_Color aCol1,aCol2;
976   MyGradientBackground.Colors(aCol1,aCol2);
977   MyGraphicDriver->GradientBackground(MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
978
979   if ( update )
980      Update ();
981   else if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
982     Update();
983 }
984
985 void Visual3d_View::SetBackgroundImage( const Standard_CString FileName,
986                                         const Aspect_FillMethod FillStyle,
987                                         const Standard_Boolean update )
988 {
989 #ifdef OCC1188
990   if ( IsDeleted() )
991     return;
992   if ( !IsDefined() )
993     Visual3d_ViewDefinitionError::Raise ("Window not defined");
994
995   MyGraphicDriver->BackgroundImage( FileName, MyCView, FillStyle );
996
997   if ( update )
998     Update();
999   else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1000     Update();
1001 #endif
1002 }
1003
1004 void Visual3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
1005                                      const Standard_Boolean update )
1006 {
1007 #ifdef OCC1188
1008   if ( IsDeleted() )
1009     return;
1010   if ( !IsDefined() )
1011     Visual3d_ViewDefinitionError::Raise ("Window not defined");
1012
1013   MyGraphicDriver->SetBgImageStyle( MyCView, FillStyle );
1014
1015   if ( update )
1016     Update();
1017   else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1018     Update();
1019 #endif
1020 }
1021
1022 Aspect_Background Visual3d_View::Background () const {
1023
1024         return (MyBackground);
1025
1026 }
1027
1028 void Visual3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
1029                                         const Standard_Boolean update )
1030 {
1031   if ( IsDeleted() )
1032     return;
1033   if ( !IsDefined() )
1034     Visual3d_ViewDefinitionError::Raise ("Window not defined");
1035
1036   MyGraphicDriver->SetBgGradientStyle( MyCView, FillStyle );
1037
1038   if ( update )
1039     Update();
1040   else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1041     Update();
1042
1043 }
1044
1045 Aspect_GradientBackground Visual3d_View::GradientBackground () const {
1046
1047         return MyGradientBackground;
1048
1049 }
1050
1051 void Visual3d_View::SetTransform (const TColStd_Array2OfReal& AMatrix) {
1052
1053         if (IsDeleted ()) return;
1054
1055 Standard_Integer lr, ur, lc, uc;
1056 Standard_Integer i, j;
1057
1058         // Assign the new transformation in an array [0..3][0..3]
1059         // Avoid problems if the has defined a matrice [1..4][1..4]
1060         //                                                 ou [3..6][-1..2] !!
1061         lr      = AMatrix.LowerRow ();
1062         ur      = AMatrix.UpperRow ();
1063         lc      = AMatrix.LowerCol ();
1064         uc      = AMatrix.UpperCol ();
1065
1066         if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
1067                 Visual3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1068
1069         for (i=0; i<=3; i++)
1070         for (j=0; j<=3; j++)
1071                 MyTransformation (i, j) = AMatrix (lr + i, lc + j);
1072
1073 Graphic3d_Vector VPN;
1074 Graphic3d_Vertex VRP;
1075 Graphic3d_Vector VUP;
1076 Standard_Real Sx, Sy, Sz;
1077
1078 Visual3d_ViewOrientation NewViewOrientation;
1079
1080         VPN     = MyViewOrientation.ViewReferencePlane ();
1081         VRP     = MyViewOrientation.ViewReferencePoint ();
1082         VUP     = MyViewOrientation.ViewReferenceUp ();
1083         MyViewOrientation.AxialScale(Sx, Sy, Sz);
1084
1085         NewViewOrientation.SetViewReferencePlane
1086                 (Graphic3d_Structure::Transforms (Transform (), VPN));
1087
1088         NewViewOrientation.SetViewReferencePoint
1089                 (Graphic3d_Structure::Transforms (Transform (), VRP));
1090
1091         NewViewOrientation.SetViewReferenceUp
1092                 (Graphic3d_Structure::Transforms (Transform (), VUP));
1093         NewViewOrientation.SetAxialScale(Sx, Sy, Sz);
1094
1095         SetViewOrientation (NewViewOrientation);
1096
1097         MyMatOfOriIsModified    = Standard_True;
1098         MyMatOfOriIsEvaluated   = Standard_False;
1099
1100 }
1101
1102 const TColStd_Array2OfReal& Visual3d_View::Transform () const {
1103
1104         return (MyTransformation);
1105
1106 }
1107
1108 void Visual3d_View::SetViewOrientation (const Visual3d_ViewOrientation& VO) {
1109
1110         if (IsDeleted ()) return;
1111
1112         MyViewOrientation       = VO;
1113
1114 Standard_Real X, Y, Z;
1115
1116         // Tests on modification of parameters.
1117 Standard_Boolean VUPIsModified  = Standard_False;
1118 Standard_Boolean VRPIsModified  = Standard_False;
1119 Standard_Boolean VRUIsModified  = Standard_False;
1120 Standard_Boolean ScaleIsModified  = Standard_False;
1121 Standard_Boolean CustomIsModified = Standard_False;
1122
1123         (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1124         VUPIsModified =
1125             MyCView.Orientation.ViewReferencePoint.x != float (X)
1126          || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1127          || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1128         MyCView.Orientation.ViewReferencePoint.x        = float (X);
1129         MyCView.Orientation.ViewReferencePoint.y        = float (Y);
1130         MyCView.Orientation.ViewReferencePoint.z        = float (Z);
1131
1132         (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1133         VRPIsModified =
1134             MyCView.Orientation.ViewReferencePlane.x != float (X)
1135          || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1136          || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1137         MyCView.Orientation.ViewReferencePlane.x        = float (X);
1138         MyCView.Orientation.ViewReferencePlane.y        = float (Y);
1139         MyCView.Orientation.ViewReferencePlane.z        = float (Z);
1140
1141         (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1142         VRUIsModified =
1143             MyCView.Orientation.ViewReferenceUp.x != float (X)
1144          || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1145          || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1146         MyCView.Orientation.ViewReferenceUp.x           = float (X);
1147         MyCView.Orientation.ViewReferenceUp.y           = float (Y);
1148         MyCView.Orientation.ViewReferenceUp.z           = float (Z);
1149
1150 Standard_Real Sx, Sy, Sz;
1151
1152         MyViewOrientation.AxialScale(Sx, Sy, Sz);
1153         ScaleIsModified =
1154             MyCView.Orientation.ViewScaleX != float (X)
1155          || MyCView.Orientation.ViewScaleY != float (Y)
1156          || MyCView.Orientation.ViewScaleZ != float (Z);
1157         MyCView.Orientation.ViewScaleX                  = float (Sx);
1158         MyCView.Orientation.ViewScaleY                  = float (Sy);
1159         MyCView.Orientation.ViewScaleZ                  = float (Sz);
1160
1161         CustomIsModified =
1162           MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
1163         MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
1164         if ( MyViewOrientation.IsCustomMatrix() ) {
1165           Standard_Integer i, j;
1166           for (i = 0; i < 4; i++)
1167             for (j = 0; j < 4; j++) {
1168               if (!CustomIsModified) CustomIsModified =
1169                 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
1170               MyCView.Orientation.ModelViewMatrix[i][j] = MyViewOrientation.MyModelViewMatrix->Value(i,j);
1171             }
1172         }
1173
1174 #ifdef TRACE_TRSF
1175 cout << "Visual3d_View::SetViewOrientation\n";
1176         if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified)
1177                 cout <<   "VUPIsModified : " << VUPIsModified
1178                      << ", VRPIsModified : " << VRPIsModified
1179                      << ", VRUIsModified : " << VRUIsModified
1180                      << ", CustomIsModified : " << CustomIsModified << "\n" << flush;
1181         else
1182                 cout << "no modification\n" << flush;
1183 #endif
1184
1185         // restart if one of parameters is modified
1186         if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified) {
1187
1188           if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
1189                 MyMatOfOriIsModified    = Standard_True;
1190                 MyMatOfOriIsEvaluated   = Standard_False;
1191               }
1192
1193                 if (! IsDefined ()) return;
1194
1195 Standard_Boolean AWait = Standard_False;        // => immediate update
1196                 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1197
1198                 Compute ();
1199
1200                 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1201         }
1202
1203 }
1204
1205 Visual3d_ViewOrientation Visual3d_View::ViewOrientation () const {
1206
1207         return (MyViewOrientation);
1208
1209 }
1210
1211 Visual3d_ViewOrientation Visual3d_View::ViewOrientationDefault () const {
1212
1213         return (MyViewOrientationReset);
1214
1215 }
1216
1217 void Visual3d_View::SetViewOrientationDefault () {
1218
1219         MyViewOrientationReset.Assign (MyViewOrientation);
1220
1221 }
1222
1223 void Visual3d_View::ViewOrientationReset () {
1224
1225         if (IsDeleted ()) return;
1226
1227         MyViewOrientation       = MyViewOrientationReset;
1228
1229 Standard_Real X, Y, Z;
1230
1231         // Tests on modification of parameters.
1232 Standard_Boolean VUPIsModified  = Standard_False;
1233 Standard_Boolean VRPIsModified  = Standard_False;
1234 Standard_Boolean VRUIsModified  = Standard_False;
1235 Standard_Boolean ScaleIsModified  = Standard_False;
1236 Standard_Boolean CustomIsModified = Standard_False;
1237
1238         (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1239         VUPIsModified =
1240             MyCView.Orientation.ViewReferencePoint.x != float (X)
1241          || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1242          || MyCView.Orientation.ViewReferencePoint.y != float (Y);
1243         MyCView.Orientation.ViewReferencePoint.x        = float (X);
1244         MyCView.Orientation.ViewReferencePoint.y        = float (Y);
1245         MyCView.Orientation.ViewReferencePoint.z        = float (Z);
1246
1247         (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1248         VRPIsModified =
1249             MyCView.Orientation.ViewReferencePlane.x != float (X)
1250          || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1251          || MyCView.Orientation.ViewReferencePlane.y != float (Y);
1252         MyCView.Orientation.ViewReferencePlane.x        = float (X);
1253         MyCView.Orientation.ViewReferencePlane.y        = float (Y);
1254         MyCView.Orientation.ViewReferencePlane.z        = float (Z);
1255
1256         (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1257         VRUIsModified =
1258             MyCView.Orientation.ViewReferenceUp.x != float (X)
1259          || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1260          || MyCView.Orientation.ViewReferenceUp.y != float (Y);
1261         MyCView.Orientation.ViewReferenceUp.x           = float (X);
1262         MyCView.Orientation.ViewReferenceUp.y           = float (Y);
1263         MyCView.Orientation.ViewReferenceUp.z           = float (Z);
1264
1265 Standard_Real Sx, Sy, Sz;
1266
1267         MyViewOrientation.AxialScale(Sx, Sy, Sz);
1268         ScaleIsModified =
1269             MyCView.Orientation.ViewScaleX != float (X)
1270          || MyCView.Orientation.ViewScaleY != float (Y)
1271          || MyCView.Orientation.ViewScaleZ != float (Z);
1272         MyCView.Orientation.ViewScaleX                  = float (Sx);
1273         MyCView.Orientation.ViewScaleY                  = float (Sy);
1274         MyCView.Orientation.ViewScaleZ                  = float (Sz);
1275
1276         CustomIsModified =
1277           MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
1278         MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
1279         if ( MyViewOrientation.IsCustomMatrix() ) {
1280           Standard_Integer i, j;
1281           for (i = 0; i < 4; i++)
1282             for (j = 0; j < 4; j++) {
1283               if (!CustomIsModified) CustomIsModified =
1284                 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
1285               MyCView.Orientation.ModelViewMatrix[i][j] = MyViewOrientation.MyModelViewMatrix->Value(i,j);
1286             }
1287         }
1288
1289 #ifdef TRACE_TRSF
1290 cout << "Visual3d_View::ViewOrientationReset\n";
1291 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified)
1292 cout <<   "VUPIsModified : " << VUPIsModified
1293      << ", VRPIsModified : " << VRPIsModified
1294      << ", VRUIsModified : " << VRUIsModified
1295      << ", CustomIsModified : " << CustomIsModified << "\n" << flush;
1296 else
1297 cout << "no modification\n" << flush;
1298 #endif
1299
1300         // Restart if one of parameters is modified
1301         if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
1302
1303           if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
1304                 MyMatOfOriIsModified    = Standard_True;
1305                 MyMatOfOriIsEvaluated   = Standard_False;
1306               }
1307
1308                 if (! IsDefined ()) return;
1309
1310 Standard_Boolean AWait = Standard_False;        // => immediate update
1311                 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1312
1313                 Compute ();
1314
1315                 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1316         }
1317
1318 }
1319
1320 void Visual3d_View::SetViewMapping (const Visual3d_ViewMapping& VM) {
1321
1322         if (IsDeleted ()) return;
1323
1324 Visual3d_TypeOfProjection OldType = MyViewMapping.Projection ();
1325 Visual3d_TypeOfProjection NewType = VM.Projection ();
1326
1327         MyViewMapping   = VM;
1328
1329 Standard_Real X, Y, Z;
1330 Standard_Real um, vm, uM, vM;
1331
1332         MyCView.Mapping.Projection      = int (MyViewMapping.Projection ());
1333         (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1334         MyCView.Mapping.ProjectionReferencePoint.x      = float (X);
1335         MyCView.Mapping.ProjectionReferencePoint.y      = float (Y);
1336         MyCView.Mapping.ProjectionReferencePoint.z      = float (Z);
1337         MyCView.Mapping.ViewPlaneDistance       =
1338                         float (MyViewMapping.ViewPlaneDistance ());
1339         MyCView.Mapping.BackPlaneDistance       =
1340                         float (MyViewMapping.BackPlaneDistance ());
1341         MyCView.Mapping.FrontPlaneDistance      =
1342                         float (MyViewMapping.FrontPlaneDistance ());
1343         MyViewMapping.WindowLimit (um, vm, uM, vM);
1344         MyCView.Mapping.WindowLimit.um  = float (um);
1345         MyCView.Mapping.WindowLimit.vm  = float (vm);
1346         MyCView.Mapping.WindowLimit.uM  = float (uM);
1347         MyCView.Mapping.WindowLimit.vM  = float (vM);
1348
1349         MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1350         if (MyViewMapping.IsCustomMatrix()) {
1351           Standard_Integer i, j;
1352           for (i = 0; i < 4; i++)
1353             for (j = 0; j < 4; j++)
1354               MyCView.Mapping.ProjectionMatrix[i][j] =
1355                 MyViewMapping.MyProjectionMatrix->Value(i,j);
1356         }
1357
1358         MyMatOfMapIsModified    = Standard_True;
1359         MyMatOfMapIsEvaluated   = Standard_False;
1360
1361         if (! IsDefined ()) return;
1362
1363 Standard_Boolean AWait = Standard_False;        // => immediate update
1364         MyGraphicDriver->ViewMapping (MyCView, AWait);
1365
1366         // Passage Parallele/Perspective
1367         if (OldType != NewType)
1368                 Compute ();
1369
1370         if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1371
1372 }
1373
1374 Visual3d_ViewMapping Visual3d_View::ViewMapping () const {
1375
1376         return (MyViewMapping);
1377
1378 }
1379
1380 Visual3d_ViewMapping Visual3d_View::ViewMappingDefault () const {
1381
1382         return (MyViewMappingReset);
1383
1384 }
1385
1386 void Visual3d_View::SetViewMappingDefault () {
1387
1388         MyViewMappingReset.Assign (MyViewMapping);
1389
1390 }
1391
1392 void Visual3d_View::ViewMappingReset () {
1393
1394         if (IsDeleted ()) return;
1395
1396         MyViewMapping   = MyViewMappingReset;
1397
1398 Standard_Real X, Y, Z;
1399 Standard_Real um, vm, uM, vM;
1400
1401         MyCView.Mapping.Projection      = int (MyViewMapping.Projection ());
1402         (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1403         MyCView.Mapping.ProjectionReferencePoint.x      = float (X);
1404         MyCView.Mapping.ProjectionReferencePoint.y      = float (Y);
1405         MyCView.Mapping.ProjectionReferencePoint.z      = float (Z);
1406         MyCView.Mapping.ViewPlaneDistance       =
1407                         float (MyViewMapping.ViewPlaneDistance ());
1408         MyCView.Mapping.BackPlaneDistance       =
1409                         float (MyViewMapping.BackPlaneDistance ());
1410         MyCView.Mapping.FrontPlaneDistance      =
1411                         float (MyViewMapping.FrontPlaneDistance ());
1412         MyViewMapping.WindowLimit (um, vm, uM, vM);
1413         MyCView.Mapping.WindowLimit.um  = float (um);
1414         MyCView.Mapping.WindowLimit.vm  = float (vm);
1415         MyCView.Mapping.WindowLimit.uM  = float (uM);
1416         MyCView.Mapping.WindowLimit.vM  = float (vM);
1417
1418         MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1419         if (MyViewMapping.IsCustomMatrix()) {
1420           Standard_Integer i, j;
1421           for (i = 0; i < 4; i++)
1422             for (j = 0; j < 4; j++)
1423               MyCView.Mapping.ProjectionMatrix[i][j] =
1424                 MyViewMapping.MyProjectionMatrix->Value(i,j);
1425         }
1426
1427         MyMatOfMapIsModified    = Standard_True;
1428         MyMatOfMapIsEvaluated   = Standard_False;
1429
1430         if (! IsDefined ()) return;
1431
1432 Standard_Boolean AWait = Standard_False;        // => immediate update
1433         MyGraphicDriver->ViewMapping (MyCView, AWait);
1434
1435         if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1436
1437 }
1438
1439 void Visual3d_View::SetContext (const Visual3d_ContextView& CTX) {
1440
1441         if (IsDeleted ()) return;
1442
1443 Visual3d_TypeOfVisualization OldVisualMode;
1444 Visual3d_TypeOfVisualization NewVisualMode;
1445
1446         // To manage display only in case of 
1447         // change of visualisation mode.
1448         OldVisualMode   = MyContext.Visualization ();
1449         NewVisualMode   = CTX.Visualization ();
1450
1451 Visual3d_TypeOfModel OldModel;
1452 Visual3d_TypeOfModel NewModel;
1453
1454         // To manage change of visualisation only in case 
1455         // of change of mode of visualisation or of type of shading.
1456         OldModel        = MyContext.Model ();
1457         NewModel        = CTX.Model ();
1458
1459 Standard_Boolean OldAliasingMode;
1460 Standard_Boolean NewAliasingMode;
1461
1462         // To manage antialiasing only in case of change.
1463         OldAliasingMode = MyContext.AliasingIsOn ();
1464         NewAliasingMode = CTX.AliasingIsOn ();
1465
1466 Standard_Boolean OldDepthCueingMode;
1467 Standard_Boolean NewDepthCueingMode;
1468
1469 Standard_Real OldDepthCueingFrontPlane;
1470 Standard_Real NewDepthCueingFrontPlane;
1471 Standard_Real OldDepthCueingBackPlane;
1472 Standard_Real NewDepthCueingBackPlane;
1473
1474         // To manage the depth cueing only in case of change.
1475         OldDepthCueingMode              = MyContext.DepthCueingIsOn ();
1476         NewDepthCueingMode              = CTX.DepthCueingIsOn ();
1477
1478         OldDepthCueingFrontPlane        = MyContext.DepthCueingFrontPlane ();
1479         NewDepthCueingFrontPlane        = CTX.DepthCueingFrontPlane ();
1480         OldDepthCueingBackPlane         = MyContext.DepthCueingBackPlane ();
1481         NewDepthCueingBackPlane         = CTX.DepthCueingBackPlane ();
1482
1483 Standard_Boolean OldFrontZClippingMode;
1484 Standard_Boolean NewFrontZClippingMode;
1485 Standard_Boolean OldBackZClippingMode;
1486 Standard_Boolean NewBackZClippingMode;
1487
1488 Standard_Real OldZClippingFrontPlane;
1489 Standard_Real NewZClippingFrontPlane;
1490 Standard_Real OldZClippingBackPlane;
1491 Standard_Real NewZClippingBackPlane;
1492
1493         // To manage the Zclipping only in case of change.
1494         OldFrontZClippingMode   = MyContext.FrontZClippingIsOn ();
1495         NewFrontZClippingMode   = CTX.FrontZClippingIsOn ();
1496         OldBackZClippingMode    = MyContext.BackZClippingIsOn ();
1497         NewBackZClippingMode    = CTX.BackZClippingIsOn ();
1498
1499         OldZClippingFrontPlane  = MyContext.ZClippingFrontPlane ();
1500         NewZClippingFrontPlane  = CTX.ZClippingFrontPlane ();
1501         OldZClippingBackPlane   = MyContext.ZClippingBackPlane ();
1502         NewZClippingBackPlane   = CTX.ZClippingBackPlane ();
1503
1504 Standard_Integer OldTexEnvId;
1505 Standard_Integer NewTexEnvId;
1506 Visual3d_TypeOfSurfaceDetail OldSurfaceDetail;
1507 Visual3d_TypeOfSurfaceDetail NewSurfaceDetail;
1508
1509         Handle(Graphic3d_TextureEnv)    TempTextureEnv1 = MyContext.TextureEnv();
1510         if (! TempTextureEnv1.IsNull()) OldTexEnvId = TempTextureEnv1->TextureId();
1511         else                            OldTexEnvId = -1;
1512
1513         Handle(Graphic3d_TextureEnv)    TempTextureEnv2 = CTX.TextureEnv();
1514
1515         if (! TempTextureEnv2.IsNull()) NewTexEnvId = TempTextureEnv2->TextureId();
1516         else                            NewTexEnvId = -1;
1517
1518         OldSurfaceDetail = MyContext.SurfaceDetail();
1519         NewSurfaceDetail = CTX.SurfaceDetail();
1520
1521         MyContext       = CTX;
1522
1523         UpdateView ();
1524
1525 Standard_Boolean AWait = Standard_False;        // => immediate update
1526         if (IsDefined ()) {
1527                 // management of visualization modes and types of shading.
1528                 if ((OldVisualMode != NewVisualMode) || (OldModel != NewModel))
1529                         MyGraphicDriver->SetVisualisation (MyCView);
1530
1531                 // management of antialiasing.
1532                 if (OldAliasingMode != NewAliasingMode)
1533                 MyGraphicDriver->AntiAliasing (MyCView, NewAliasingMode);
1534
1535                 // management of depth_cueing.
1536                 if ((OldDepthCueingMode != NewDepthCueingMode) ||
1537                     (OldDepthCueingFrontPlane != NewDepthCueingFrontPlane) ||
1538                     (OldDepthCueingBackPlane != NewDepthCueingBackPlane)) {
1539 #ifdef BUC60572
1540                     if( NewDepthCueingMode &&
1541                         (NewDepthCueingBackPlane >= NewDepthCueingFrontPlane) )
1542                         Visual3d_DepthCueingDefinitionError::Raise
1543                         ("Bad value for DepthCueingPlanes position");
1544 #endif
1545                         MyGraphicDriver->DepthCueing
1546                                 (MyCView, NewDepthCueingMode);
1547                 }
1548
1549                 // management of Zclipping
1550                 if ((OldFrontZClippingMode != NewFrontZClippingMode) ||
1551                     (OldBackZClippingMode != NewBackZClippingMode) ||
1552                     (OldZClippingFrontPlane != NewZClippingFrontPlane) ||
1553                     (OldZClippingBackPlane != NewZClippingBackPlane)) {
1554 #ifdef BUC60572
1555                     if( NewBackZClippingMode && NewFrontZClippingMode &&
1556                         (NewZClippingBackPlane >= NewZClippingFrontPlane) )
1557                         Visual3d_ZClippingDefinitionError::Raise
1558                         ("Bad value for ZClippingPlanes position");
1559 #endif
1560                         MyGraphicDriver->ClipLimit (MyCView, AWait);
1561                 }
1562
1563                 // management of textures
1564                 if ( (OldTexEnvId != NewTexEnvId) ||
1565                      (OldSurfaceDetail != NewSurfaceDetail) )
1566                   MyGraphicDriver->Environment(MyCView);
1567
1568                 // Update of planes of model clipping
1569                 UpdatePlanes ();
1570
1571                 // Update of light sources 
1572                 UpdateLights ();
1573         }
1574
1575         if (OldVisualMode != NewVisualMode) {
1576
1577                 /*
1578                  * Change of context =>
1579                  * Remove structures that cannot be displayed
1580                  * in the new visualisation mode.
1581                  * It is not necessary to warn ViewManager as
1582                  * this structure should not disappear from
1583                  * the list of structures displayed in it.
1584                  */
1585 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
1586 Visual3d_TypeOfAnswer Answer;
1587
1588                 Standard_Integer i      = MyDisplayedStructure.Extent ();
1589
1590 Graphic3d_SequenceOfStructure FooSequence;
1591
1592                 while (S1Iterator.More ()) {
1593                         Answer  = AcceptDisplay (S1Iterator.Key ());
1594                         // If the structure can't be displayed in the 
1595                         // new context of the view, it is removed.
1596                         if ((Answer == Visual3d_TOA_NO) ||
1597                             (Answer == Visual3d_TOA_COMPUTE))
1598                                 //Erase (S1Iterator.Key (), Aspect_TOU_WAIT);
1599                                 FooSequence.Append (S1Iterator.Key ());
1600
1601                         // S1Iterator.Next () is located on the next structure
1602                         S1Iterator.Next ();
1603                 }
1604
1605 Standard_Integer Length = FooSequence.Length ();
1606                 // The stored structures are removed
1607                 for (i=1; i<=Length; i++)
1608                         Erase (FooSequence.Value (i), Aspect_TOU_WAIT);
1609                 if (Length != 0) FooSequence.Clear ();
1610
1611                 /*
1612                  * Change of context =>
1613                  * Display structures that can be displayed 
1614                  * with the new visualisation mode.
1615                  * All structures with status Displayed are removed from the ViewManager 
1616                  * and displayed in the view directly, if the structure is not already 
1617                  * displayed and if the view accepts it in its context.
1618                  */
1619
1620                 i       = MyViewManager->NumberOfDisplayedStructures ();
1621                 Graphic3d_MapOfStructure Map;
1622                 MyViewManager->DisplayedStructures(Map);
1623                 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1624
1625                 for (; it.More(); it.Next()) {
1626                   Handle(Graphic3d_Structure) SG = it.Key();
1627                     if (! IsDisplayed (SG)) {
1628                       Answer = AcceptDisplay(SG);
1629                         // If the structure can be displayed in the 
1630                         // new context of the view, it is displayed.
1631                         if ((Answer == Visual3d_TOA_YES) ||
1632                             (Answer == Visual3d_TOA_COMPUTE))
1633                             //Display (MyViewManager->DisplayedStructure (j),
1634                                 //Aspect_TOU_WAIT);
1635                         FooSequence.Append (SG);
1636                     }
1637                 }
1638
1639                 Length  = FooSequence.Length ();
1640                 // The stored structures are displayed
1641                 for (i=1; i<=Length; i++)
1642                         Display (FooSequence.Value (i), Aspect_TOU_WAIT);
1643                 if (Length != 0) FooSequence.Clear ();
1644         }
1645
1646         if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1647
1648 }
1649
1650 const Visual3d_ContextView& Visual3d_View::Context () const {
1651
1652         return (MyContext);
1653
1654 }
1655
1656 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& SG) const
1657 {
1658
1659   if (IsDeleted ()) return;
1660
1661   Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
1662
1663   while (Iterator.More ()) {
1664     SG.Add (Iterator.Key ());
1665
1666     // Iterator.Next () is located on the next structure
1667     Iterator.Next ();
1668   }
1669
1670 }
1671
1672 void Visual3d_View::Activate () {
1673
1674         if (IsDeleted ()) return;
1675
1676         if (! IsDefined ())
1677                 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1678
1679         if (! IsActive ()) {
1680
1681                 MyGraphicDriver->ActivateView (MyCView);
1682                 MyGraphicDriver->Background (MyCView);
1683                 MyGraphicDriver->Transparency
1684                         (MyCView, MyViewManager->Transparency ());
1685
1686                 MyCView.Active  = 1;
1687
1688                 /*
1689                  * Activation of a new view =>
1690                  * Display structures that can be displayed in this new view.
1691                  * All structures with status
1692                  * Displayed in ViewManager are returned and displayed in 
1693                  * the view directly, if the structure is not already 
1694                  * displayed and if the view accepts it in its context.
1695                  */
1696
1697                 Visual3d_TypeOfAnswer Answer;
1698                 Graphic3d_MapOfStructure Map;
1699                 MyViewManager->DisplayedStructures(Map);
1700                 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1701
1702                 for (; it.More(); it.Next()) {
1703                   Handle(Graphic3d_Structure) SG = it.Key();
1704                     if (! IsDisplayed (SG)) {
1705                       Answer    = AcceptDisplay(SG);
1706                         // If the structure can be displayed in the
1707                         // new context of the view, it is displayed.
1708                         if ((Answer == Visual3d_TOA_YES) ||
1709                             (Answer == Visual3d_TOA_COMPUTE))
1710                         Display (SG,Aspect_TOU_WAIT);
1711                     }
1712                 }
1713
1714         }
1715
1716         // If the activation/desactivation of ZBuffer should be automatic
1717         // depending on the presence or absence of facets.
1718         if (MyViewManager->ZBufferAuto ()) {
1719 Standard_Boolean BContainsFacet = ContainsFacet ();
1720 Standard_Boolean BZBuffer       = ZBufferIsActivated ();
1721                 // If the view contains facets
1722                 // and if ZBuffer is not active
1723                 if (BContainsFacet && ! BZBuffer)
1724                         SetZBufferActivity (1);
1725                 // If the view does not contain facets
1726                 // and if ZBuffer is active
1727                 if (! BContainsFacet && BZBuffer)
1728                         SetZBufferActivity (0);
1729         }
1730
1731         if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1732
1733 }
1734
1735 Standard_Boolean Visual3d_View::IsActive () const {
1736
1737         if (IsDeleted ()) return (Standard_False);
1738
1739         if (MyCView.Active)
1740                 return (Standard_True);
1741         else
1742                 return (Standard_False);
1743
1744 }
1745
1746 void Visual3d_View::Deactivate () {
1747
1748         if (IsDeleted ()) return;
1749
1750         if (! IsDefined ())
1751                 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1752
1753         if (IsActive ()) {
1754
1755                 MyGraphicDriver->DeactivateView (MyCView);
1756
1757                 /*
1758                  * Deactivation of a view =>
1759                  * Removal of structures displayed in this view.
1760                  * All structures with status
1761                  * Displayed in ViewManager are returned and removed from 
1762                  * the view directly, if the structure is not already 
1763                  * displayed and if the view accepts it in its context.
1764                 */
1765
1766                 Visual3d_TypeOfAnswer Answer;
1767                 Graphic3d_MapOfStructure Map;
1768                 MyViewManager->DisplayedStructures(Map);
1769                 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1770
1771                 for (; it.More(); it.Next()) {
1772                   Handle(Graphic3d_Structure) SG = it.Key();
1773                     if (! IsDisplayed (SG)) {
1774                         Answer  = AcceptDisplay(SG);
1775                         // If the structure was displayed it is removed.
1776                         if ((Answer == Visual3d_TOA_YES) ||
1777                             (Answer == Visual3d_TOA_COMPUTE))
1778                                 Erase (SG,Aspect_TOU_WAIT);
1779                     }
1780                 }
1781
1782                 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1783
1784                 // No action currently possible in the view
1785                 MyCView.Active  = 0;
1786         }
1787
1788 }
1789
1790 void Visual3d_View::Redraw () {
1791
1792         Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1793
1794 }
1795
1796 void Visual3d_View::Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
1797
1798         Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer (), x, y, width, height);
1799 }
1800
1801 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1802
1803         if (IsDeleted ()) return;
1804
1805         if ((! IsDefined ()) || (! IsActive ())) return;
1806
1807         if (! MyWindow->IsMapped ()) return;
1808
1809         // san - 14/04/2004 - set up Z buffer state before redrawing
1810        // If the activation/desactivation of ZBuffer should be automatic
1811         // depending on the presence or absence of facets.
1812         if (MyViewManager->ZBufferAuto ()) {
1813                 Standard_Boolean BContainsFacet = ContainsFacet ();
1814                 Standard_Boolean BZBuffer       = ZBufferIsActivated ();
1815                 // If the view contains facets
1816                 // and if ZBuffer is not active
1817                 if (BContainsFacet && ! BZBuffer)
1818                         SetZBufferActivity (1);
1819                 // If the view contains only facets
1820                 // and if ZBuffer is active
1821                 if (! BContainsFacet && BZBuffer)
1822                         SetZBufferActivity (0);
1823         }
1824
1825         Aspect_CLayer2d OverCLayer;
1826         Aspect_CLayer2d UnderCLayer;
1827         OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1828         if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1829         if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1830         MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer);
1831
1832 }
1833
1834 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer, const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
1835
1836         if (IsDeleted ()) return;
1837
1838         if ((! IsDefined ()) || (! IsActive ())) return;
1839
1840         if (! MyWindow->IsMapped ()) return;
1841
1842         // san - 14/04/2004 - set up Z buffer state before redrawing
1843           // If activation/desactivation of ZBuffer should be automatic
1844         // depending on the presence or absence of facets.
1845         if (MyViewManager->ZBufferAuto ()) {
1846         Standard_Boolean BContainsFacet = ContainsFacet ();
1847         Standard_Boolean BZBuffer       = ZBufferIsActivated ();
1848                 // If the view contains facets
1849                 // and if ZBuffer is not active
1850                 if (BContainsFacet && ! BZBuffer)
1851                         SetZBufferActivity (1);
1852                 // If the view contains only facets
1853                 // and if ZBuffer is active
1854                 if (! BContainsFacet && BZBuffer)
1855                         SetZBufferActivity (0);
1856         }
1857
1858         Aspect_CLayer2d OverCLayer;
1859         Aspect_CLayer2d UnderCLayer;
1860         OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1861         if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1862         if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1863         MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer, x, y, width, height);
1864
1865 }
1866
1867 void Visual3d_View::Update () {
1868
1869         Update (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1870
1871 }
1872
1873 void Visual3d_View::Update (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1874
1875         if (IsDeleted ()) return;
1876
1877         if ((! IsDefined ()) || (! IsActive ())) return;
1878
1879         if (! MyWindow->IsMapped ()) return;
1880
1881         // If activation/desactivation of ZBuffer should be automatic
1882         // depending on the presence or absence of facets.
1883         if (MyViewManager->ZBufferAuto ()) {
1884 Standard_Boolean BContainsFacet = ContainsFacet ();
1885 Standard_Boolean BZBuffer       = ZBufferIsActivated ();
1886                 // If the view contains facets
1887                 // and if ZBuffer is not active
1888                         if (BContainsFacet && ! BZBuffer)
1889                         SetZBufferActivity (1);
1890                    // If the view does not contain facets
1891                 // and if ZBuffer is active
1892                 if (! BContainsFacet && BZBuffer)
1893                         SetZBufferActivity (0);
1894         }
1895
1896 Aspect_CLayer2d OverCLayer;
1897 Aspect_CLayer2d UnderCLayer;
1898         OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1899         if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1900         if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1901         //OSD::SetSignal (Standard_False);
1902         MyGraphicDriver->Update (MyCView, UnderCLayer, OverCLayer);
1903         //OSD::SetSignal (Standard_True);
1904
1905         MyMatOfMapIsModified    = Standard_False;
1906         MyMatOfOriIsModified    = Standard_False;
1907
1908 }
1909
1910 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const {
1911
1912 // Return type of visualization of the view
1913 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
1914
1915 // Return type of visualization of the structure
1916 Graphic3d_TypeOfStructure StructType = AStructure->Visual ();
1917
1918 Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO;
1919
1920         if (StructType == Graphic3d_TOS_ALL)
1921                 // The structure accepts any type of view
1922                 Result  = Visual3d_TOA_YES;
1923         else {
1924                 if ((StructType == Graphic3d_TOS_SHADING)
1925                         && (ViewType == Visual3d_TOV_SHADING))
1926                         Result  = Visual3d_TOA_YES;
1927                 if ((StructType == Graphic3d_TOS_WIREFRAME)
1928                         && (ViewType == Visual3d_TOV_WIREFRAME))
1929                         Result  = Visual3d_TOA_YES;
1930                 if ((StructType == Graphic3d_TOS_COMPUTED)
1931                         && (ViewType == Visual3d_TOV_WIREFRAME))
1932                         Result  = Visual3d_TOA_COMPUTE;
1933                 if ((StructType == Graphic3d_TOS_COMPUTED)
1934                         && (ViewType == Visual3d_TOV_SHADING))
1935                         Result  = Visual3d_TOA_COMPUTE;
1936         }
1937
1938 #ifdef TRACE_ACCEPT
1939         if (Result == Visual3d_TOA_YES)
1940         cout << "YES = Visual3d_View" << MyCView.ViewId
1941              << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1942         if (Result == Visual3d_TOA_NO)
1943         cout << "NO = Visual3d_View" << MyCView.ViewId
1944              << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1945         if (Result == Visual3d_TOA_COMPUTE)
1946         cout << "COMPUTE = Visual3d_View" << MyCView.ViewId
1947              << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1948         cout << flush;
1949 #endif
1950
1951         return (Result);
1952
1953 }
1954
1955 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
1956
1957         if (IsDeleted ()) return;
1958         if (! IsDefined ()) return;
1959         if (! IsActive ()) return;
1960         if (! IsDisplayed (AStructure)) return;
1961
1962 Standard_Integer Index = IsComputed (AStructure);
1963 #ifdef G003
1964         if (  Index != 0 && ComputedMode () && !DegenerateModeIsOn ()  )
1965 #else
1966         if ((Index != 0) && (! DegenerateModeIsOn ()))
1967 #endif  // G003
1968         {
1969 #ifdef TRACE
1970         Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification ();
1971         cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1972              << AStructure->Identification () << "/" << StructId
1973              << ", " << OldPriority << ", " << NewPriority << ")\n";
1974         cout << flush;
1975 #endif
1976                 MyGraphicDriver->EraseStructure
1977                         (MyCView,
1978                          *(Graphic3d_CStructure *)
1979                             MyCOMPUTEDSequence.Value (Index)->CStructure ());
1980                 MyGraphicDriver->DisplayStructure
1981                         (MyCView,
1982                          *(Graphic3d_CStructure *)
1983                             MyCOMPUTEDSequence.Value (Index)->CStructure (),
1984                          int (NewPriority));
1985         }
1986         else {
1987 #ifdef TRACE
1988         Standard_Integer StructId = AStructure->Identification ();
1989         cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1990              << AStructure->Identification () << "/" << StructId
1991              << ", " << OldPriority << ", " << NewPriority << ")\n";
1992         cout << flush;
1993 #endif
1994                 MyGraphicDriver->EraseStructure
1995                         (MyCView,
1996                          *(Graphic3d_CStructure *)AStructure->CStructure ());
1997                 MyGraphicDriver->DisplayStructure
1998                         (MyCView,
1999                          *(Graphic3d_CStructure *)AStructure->CStructure (),
2000                          int (NewPriority));
2001         }
2002
2003 }
2004
2005 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
2006
2007 #ifdef TRACE_CLEAR
2008         cout << "Visual3d_View" << MyCView.ViewId << "::Clear ("
2009              << AStructure->Identification () << ")\n";
2010         cout << flush;
2011 #endif
2012
2013 Standard_Integer Index = IsComputed (AStructure);
2014         if (Index != 0) {
2015 #ifdef TRACE_CLEAR
2016         cout << "Structure " << AStructure->Identification ()
2017              << " calculated in the view "
2018              << Identification () << ", by structure "
2019              << MyCOMPUTEDSequence.Value (Index)->Identification ()
2020              << " is emptied.\n";
2021         cout << flush;
2022 #endif
2023                 MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction);
2024                 MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False);
2025         }
2026
2027 }
2028
2029 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
2030
2031 #ifdef TRACE_CONNECT
2032         cout << "Visual3d_View" << MyCView.ViewId << "::Connect ("
2033              << AMother->Identification ()
2034              << ADaughter->Identification () << ")\n";
2035         cout << flush;
2036 #endif
2037
2038 Standard_Integer IndexM = IsComputed (AMother);
2039 Standard_Integer IndexD = IsComputed (ADaughter);
2040
2041         if (IndexM != 0 && IndexD != 0) {
2042 #ifdef TRACE_CONNECT
2043         cout << "Structure " << AMother->Identification ()
2044              << " is connected to structure "
2045              << ADaughter->Identification () << endl;
2046         cout << "These structures are calculated.\n";
2047         cout << "In the view " << Identification ()
2048              << "Structure "
2049              << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
2050              << " is connected to the structure "
2051              << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
2052              << endl;
2053 #endif
2054                 MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD));
2055         }
2056
2057 }
2058
2059 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
2060
2061 #ifdef TRACE_CONNECT
2062         cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect ("
2063              << AMother->Identification ()
2064              << ADaughter->Identification () << ")\n";
2065         cout << flush;
2066 #endif
2067
2068 Standard_Integer IndexM = IsComputed (AMother);
2069 Standard_Integer IndexD = IsComputed (ADaughter);
2070
2071         if (IndexM != 0 && IndexD != 0) {
2072 #ifdef TRACE_CONNECT
2073         cout << "Structure " << AMother->Identification ()
2074              << " is disconnected from the structure "
2075              << ADaughter->Identification () << endl;
2076         cout << "These structures are calculated.\n";
2077         cout << "In the view " << Identification ()
2078              << "Structure "
2079              << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
2080              << " is disconnected from the structure "
2081              << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
2082              << endl;
2083 #endif
2084                 MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD));
2085         }
2086
2087 }
2088
2089 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure) {
2090
2091         Display (AStructure, MyViewManager->UpdateMode ());
2092
2093 }
2094
2095 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2096
2097         if (IsDeleted ()) return;
2098         if (! IsDefined ()) return;
2099         if (! IsActive ()) return;
2100
2101         // If Display on a structure present in the list
2102         // of calculated structures while it is not 
2103         // or more, of calculated type =>
2104         // - removes it as well as the associated old computed
2105         // THis happens when hlhsr becomes again of type e
2106         // non computed after SetVisual.
2107 Standard_Integer Index = IsComputed (AStructure);
2108
2109         if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) {
2110
2111 #ifdef TRACE_LENGTH
2112         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2113                 cout << "In Visual3d_View::Display, ";
2114                 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2115                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2116                      << "\n" << flush;
2117         }
2118 #endif
2119                 MyTOCOMPUTESequence.Remove (Index);
2120                 MyCOMPUTEDSequence.Remove (Index);
2121
2122 #ifdef TRACE_LENGTH
2123         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2124                 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2125                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2126                      << "\n" << flush;
2127 #endif
2128                 Index = 0;
2129         }
2130
2131         Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2132
2133 #ifdef TRACE_DISPLAY
2134         Standard_Integer StructId = AStructure->Identification ();
2135         cout << "Visual3d_View" << MyCView.ViewId << "::Display ("
2136              << StructId << ");\n";
2137         cout << flush;
2138 #endif
2139
2140         if (Answer == Visual3d_TOA_NO) {
2141 #ifdef TRACE_DISPLAY
2142                 cout << "Answer : Visual3d_TOA_NO\n";
2143                 cout << flush;
2144 #endif
2145                 return;
2146         }
2147
2148         // Mode degenerated active
2149 #ifdef G003
2150         if (  !ComputedMode () || DegenerateModeIsOn ()  )
2151                                         Answer = Visual3d_TOA_YES;
2152 #else
2153         if (DegenerateModeIsOn ()) Answer = Visual3d_TOA_YES;
2154 ;
2155 #endif  // G003
2156
2157         if (Answer == Visual3d_TOA_YES ) {
2158 #ifdef TRACE_DISPLAY
2159                 cout << "Answer : Visual3d_TOA_YES\n";
2160                 cout << flush;
2161 #endif
2162                 if (IsDisplayed (AStructure)) return;
2163                 MyGraphicDriver->DisplayStructure (
2164                         MyCView,
2165                         *(Graphic3d_CStructure *)AStructure->CStructure (),
2166                         int (AStructure->DisplayPriority ())
2167                 );
2168                 MyDisplayedStructure.Add (AStructure);
2169                 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2170         }
2171
2172         if (Answer == Visual3d_TOA_COMPUTE) {
2173 #ifdef TRACE_DISPLAY
2174             cout << "Answer : Visual3d_TOA_COMPUTE\n";
2175             cout << "Index : " << Index << "\n" << flush;
2176 #endif
2177             if (Index != 0) {
2178                 // Already computed, is COMPUTED still valid?
2179 #ifdef TRACE_DISPLAY
2180                 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2181                   cout << "Structure "
2182                      << MyTOCOMPUTESequence.Value (Index)->Identification ()
2183                      << "already calculated, in the view "
2184                      << Identification () << ", par la structure "
2185                      << MyCOMPUTEDSequence.Value (Index)->Identification ()
2186                      << "\n was not recalculated as HLR is valid\n";
2187                   cout << flush;
2188                 }
2189                 else {
2190                   cout << "Structure "
2191                      << MyTOCOMPUTESequence.Value (Index)->Identification ()
2192                      << " already calculated, in the view "
2193                      << Identification () << ", by the structure "
2194                      << MyCOMPUTEDSequence.Value (Index)->Identification ()
2195                      << "\n should be recalculated as HLR is invalid\n";
2196                   cout << flush;
2197                 }
2198 #endif
2199 Standard_Integer OldStructId =
2200         MyCOMPUTEDSequence.Value (Index)->Identification ();
2201
2202                 // Case COMPUTED valide
2203                 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2204                     // to be displayed
2205                     if (! IsDisplayed (AStructure)) {
2206                         MyDisplayedStructure.Add (AStructure);
2207                         MyGraphicDriver->DisplayStructure (
2208                             MyCView,
2209                             *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
2210                             int (AStructure->DisplayPriority ())
2211                         );
2212                         if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2213                     }
2214                     return;
2215                 }
2216
2217                 // Case COMPUTED invalid
2218                 else {
2219                     // Is there another valid representation ?
2220                     // Find in the sequence of already calculated structures
2221                     // 1/ Structure having the same Owner as <AStructure>
2222                     // 2/ That is not <AStructure>
2223                     // 3/ The COMPUTED which of is valid
2224                     Standard_Integer NewIndex = HaveTheSameOwner (AStructure);
2225
2226                     // Case of COMPUTED invalid, WITH a valid of replacement
2227                     if (NewIndex != 0) {
2228                         // to be displayed
2229                         if (! IsDisplayed (AStructure)) {
2230                             MyCOMPUTEDSequence.SetValue
2231                                 (Index, MyCOMPUTEDSequence.Value (NewIndex));
2232                             OldStructId = MyCOMPUTEDSequence.Value (NewIndex)->
2233                                                         Identification ();
2234                             MyDisplayedStructure.Add (AStructure);
2235                             MyGraphicDriver->DisplayStructure (
2236                                 MyCView,
2237                                 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (NewIndex)->CStructure (),
2238                                 int (AStructure->DisplayPriority ())
2239                             );
2240                             if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2241                         }
2242                         return;
2243                     }
2244
2245                     // Cas COMPUTED invalid, WITHOUT a valid of replacement
2246                     else {
2247                         // COMPUTED is removed if displayed 
2248                         if (IsDisplayed (AStructure))
2249                             MyGraphicDriver->EraseStructure (
2250                                 MyCView,
2251                                 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()
2252                             );
2253                     }
2254                 }
2255             } // if (Index != 0)
2256
2257             // Compute + Validation
2258 #ifdef OLD
2259 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
2260 #else
2261 Handle(Graphic3d_Structure) TheStructure;
2262 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
2263             AStructure->Transform (ATrsf);
2264             if (Index != 0) {
2265 TColStd_Array2OfReal Ident (0, 3, 0, 3);
2266 Standard_Integer ii, jj;
2267         for (ii=0; ii<=3; ii++)
2268             for (jj=0; jj<=3; jj++)
2269                 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
2270                 TheStructure = MyCOMPUTEDSequence.Value (Index);
2271                 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
2272                 if (AStructure->IsTransformed ()) {
2273                     AStructure->Compute (this, ATrsf, TheStructure);
2274                 }
2275                 else {
2276                     AStructure->Compute (this, TheStructure);
2277                 }
2278             }
2279             else {
2280                 if (AStructure->IsTransformed ()) {
2281                     TheStructure = AStructure->Compute (this, ATrsf);
2282                 }
2283                 else {
2284                     TheStructure = AStructure->Compute (this);
2285                 }
2286             }
2287 #endif
2288             TheStructure->SetHLRValidation (Standard_True);
2289
2290 #ifdef TRACE_LENGTH
2291         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2292                 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2293                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2294                      << "\n" << flush;
2295 #endif
2296
2297             // TOCOMPUTE and COMPUTED associated to sequences are added
2298             MyTOCOMPUTESequence.Append (AStructure);
2299             MyCOMPUTEDSequence.Append (TheStructure);
2300
2301 #ifdef TRACE_LENGTH
2302         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2303                 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2304                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2305                      << "\n" << flush;
2306 #endif
2307
2308             // The previous are removed if necessary
2309             if (Index != 0) {
2310                 MyTOCOMPUTESequence.Remove (Index);
2311                 MyCOMPUTEDSequence.Remove (Index);
2312             }
2313
2314 #ifdef TRACE_LENGTH
2315         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2316                 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2317                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2318                      << "\n" << flush;
2319 #endif
2320
2321 // Return type of visualisation of the view
2322 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
2323
2324 // Of which type will be the computed ?
2325 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
2326                 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
2327
2328 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
2329                 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
2330
2331             if (ComputeWireframe)
2332                 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
2333             if (ComputeShading)
2334                 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
2335
2336             if (! ComputeShading && ! ComputeWireframe)
2337                 Answer = Visual3d_TOA_NO;
2338             else
2339                 Answer = AcceptDisplay (TheStructure);
2340
2341             if (AStructure->IsHighlighted()) {
2342                 TheStructure->SetHighlightColor (AStructure->HighlightColor ());
2343                 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
2344             }
2345
2346 #ifdef TRACE_DISPLAY
2347             cout << "Structure " << StructId
2348                  << " in the view " << Identification ()
2349                  << " is calculated by the structure "
2350                  << TheStructure->Identification ();
2351             if (Answer == Visual3d_TOA_YES)
2352                 cout << " and displayed\n";
2353             else
2354                 cout << " but not displayed\n";
2355             cout << flush;
2356 #endif
2357
2358             // It is displayed only if the calculated structure 
2359             // has a proper type corresponding to the one of the view.
2360             if (Answer != Visual3d_TOA_NO) {
2361                 if (! IsDisplayed (AStructure))
2362                         MyDisplayedStructure.Add (AStructure);
2363                 MyGraphicDriver->DisplayStructure (
2364                         MyCView,
2365                         *(Graphic3d_CStructure *)TheStructure->CStructure (),
2366                         int (AStructure->DisplayPriority ())
2367                 );
2368                 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2369             }
2370         } // Visual3d_TOA_COMPUTE
2371 }
2372
2373 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure) {
2374
2375         if (IsDeleted ()) return;
2376
2377         Erase (AStructure, MyViewManager->UpdateMode ());
2378
2379 }
2380
2381 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2382
2383 Standard_Integer StructId;
2384
2385         if (IsDeleted ()) return;
2386
2387         // No test on window as the structure is displayed only if 
2388         // the window exists, so only one test is enough.
2389         if (IsDisplayed (AStructure)) {
2390 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2391
2392                 // Degenerated mode is active
2393 #ifdef G003
2394                 if (  !ComputedMode () || DegenerateModeIsOn ()  )
2395                                         Answer = Visual3d_TOA_YES;
2396 #else
2397                 if (DegenerateModeIsOn ()) Answer = Visual3d_TOA_YES;
2398 #endif  // G003
2399
2400                 if (Answer != Visual3d_TOA_COMPUTE) {
2401                         MyGraphicDriver->EraseStructure (
2402                                 MyCView,
2403                                 *(Graphic3d_CStructure *)AStructure->CStructure ()
2404                         );
2405                 }
2406
2407                 if (Answer == Visual3d_TOA_COMPUTE) {
2408 Standard_Integer Index = IsComputed (AStructure);
2409 #ifdef TRACE_COMP
2410         cout << "Visual3d_View" << MyCView.ViewId << "::Erase ("
2411              << AStructure->Identification () << ");\n";
2412         cout << "Index : " << Index << "\n";
2413         cout << flush;
2414 #endif
2415 #ifdef G003
2416                     if (  Index != 0 && ComputedMode () &&
2417                                                 !DegenerateModeIsOn ()  )
2418 #else
2419                     if ((Index != 0) && (! DegenerateModeIsOn ()))
2420 #endif  // G003
2421                     {
2422                         StructId =
2423                         MyCOMPUTEDSequence.Value (Index)->Identification ();
2424 #ifdef TRACE_COMP
2425         cout << "Structure " << AStructure->Identification ()
2426              << " calculated, in the view "
2427              << Identification () << ", by the structure "
2428              << StructId << " is removed. \n";
2429         cout << flush;
2430 #endif
2431                         MyGraphicDriver->EraseStructure
2432                                 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
2433                     }
2434                     // else is impossible
2435                 }
2436                 MyDisplayedStructure.Remove (AStructure);
2437                 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2438         }
2439
2440 }
2441
2442 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
2443
2444 #ifdef TRACE_HIGH
2445         cout << "Visual3d_View" << MyCView.ViewId << "::Highlight ("
2446              << AStructure->Identification () << ")\n";
2447         cout << flush;
2448 #endif
2449
2450 Standard_Integer Index = IsComputed (AStructure);
2451         if (Index != 0) {
2452 #ifdef TRACE_HIGH
2453         cout << "Structure " << AStructure->Identification ()
2454              << " calculated, in the view "
2455              << Identification () << ", by the structure "
2456              << MyCOMPUTEDSequence.Value (Index)->Identification ()
2457              << " passes in highlight mode.\n";
2458         cout << flush;
2459 #endif
2460                 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
2461                         (AStructure->HighlightColor ());
2462                 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod);
2463         }
2464
2465 }
2466
2467 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
2468
2469 #ifdef TRACE_TRSF
2470         cout << "Visual3d_View" << MyCView.ViewId << "::Transform ("
2471              << AStructure->Identification () << ")\n";
2472         cout << flush;
2473 #endif
2474
2475 Standard_Integer Index = IsComputed (AStructure);
2476         if (Index != 0) {
2477 #ifdef TRACE_TRSF
2478         cout << "The structure " << AStructure->Identification ()
2479              << " calculated, in the view "
2480              << Identification () << ", by the structure "
2481              << MyCOMPUTEDSequence.Value (Index)->Identification ()
2482              << " is transformed.\n";
2483         cout << flush;
2484 #endif
2485                 // Test is somewhat light !
2486                 // trsf is transferred only if it is :
2487                 // a translation
2488                 // a scale
2489                 if (ATrsf (0, 1) != 0. || ATrsf (0, 2) != 0.
2490                  || ATrsf (1, 0) != 0. || ATrsf (1, 2) != 0.
2491                  || ATrsf (2, 0) != 0. || ATrsf (2, 1) != 0.)
2492                     ReCompute (AStructure);
2493                 else
2494                     MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf);
2495         }
2496
2497 }
2498
2499 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
2500
2501 #ifdef TRACE_HIGH
2502         cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight ("
2503              << AStructure->Identification () << ")\n";
2504         cout << flush;
2505 #endif
2506
2507 Standard_Integer Index = IsComputed (AStructure);
2508         if (Index != 0) {
2509 #ifdef TRACE_HIGH
2510         cout << "Structure " << AStructure->Identification ()
2511              << " calculated, in the view "
2512              << Identification () << ", by the structure "
2513              << MyCOMPUTEDSequence.Value (Index)->Identification ()
2514              << " passes in unhighlight mode.\n";
2515         cout << flush;
2516 #endif
2517                 MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight ();
2518         }
2519
2520
2521 }
2522
2523 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const {
2524
2525 Standard_Integer StrId = AStructure->Identification ();
2526
2527 Standard_Integer Result = 0;
2528 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
2529
2530         // Recherche de la structure <AStructure> dans la
2531         // sequence des structures deja calculees
2532         for (Standard_Integer i=1; i<=Length && Result==0; i++)
2533                 if ((MyTOCOMPUTESequence.Value (i))->Identification ()
2534                         == StrId) Result        = i;
2535 #ifdef TRACE_ISCOMP
2536         cout << "\n In the view " << Identification () << " the structure ";
2537         if (Result != 0)
2538                 cout << StrId << " is calculated by "
2539                      << MyCOMPUTEDSequence.Value (Result)->Identification ()
2540                      << "\n" << flush;
2541         else
2542                 cout << StrId << " is not calculated\n" << flush;
2543 #endif
2544
2545 #ifdef TRACE_LENGTH
2546         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2547                 cout << "In Visual3d_View::IsComputed, ";
2548                 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2549                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2550                      << "\n" << flush;
2551         }
2552 #endif
2553
2554         return (Result);
2555
2556 }
2557
2558 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const {
2559
2560 Standard_Boolean Result = Standard_False;
2561
2562         if (IsDeleted ()) return Result;
2563
2564         Result  = MyDisplayedStructure.Contains (AStructure);
2565
2566         return Result;
2567
2568 }
2569
2570 #ifdef IMPLEMENTED
2571 Standard_Boolean Visual3d_View::ContainsComputedStructure () const {
2572
2573 Standard_Boolean Result = Standard_False;
2574
2575         if (MyDisplayedStructure.IsEmpty ()) return Result;
2576
2577 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
2578
2579         Standard_Integer i      = MyDisplayedStructure.Extent ();
2580
2581         // Stop at the first structure of type TOS_COMPUTED
2582         while (! Result && Iterator.More ()) {
2583                 Result  =
2584                 (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED);
2585
2586                 // Iterator.Next () is located on the 
2587                 // next structure
2588                 Iterator.Next ();
2589         }
2590
2591         return Result;
2592
2593 }
2594 #endif
2595
2596 Standard_Boolean Visual3d_View::ContainsFacet () const {
2597
2598         return ContainsFacet (MyDisplayedStructure);
2599
2600 }
2601
2602 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const {
2603
2604 Standard_Boolean Result = Standard_False;
2605
2606         if (ASet.IsEmpty ()) return Result;
2607
2608 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2609
2610         // Stop at the first structure containing a facet
2611         for ( Iterator.Initialize (ASet);
2612               Iterator.More () && ! Result;
2613               Iterator.Next ())
2614                 Result  = (Iterator.Key ())->ContainsFacet ();
2615
2616         return Result;
2617
2618 }
2619
2620 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
2621
2622         MinMaxValues
2623         (MyDisplayedStructure, XMin, YMin, ZMin, XMax, YMax, ZMax);
2624
2625 }
2626
2627 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
2628
2629   if (ASet.IsEmpty ()) {
2630     XMin = RealFirst ();
2631     YMin = RealFirst ();
2632     ZMin = RealFirst ();
2633
2634     XMax = RealLast ();
2635     YMax = RealLast ();
2636     ZMax = RealLast ();
2637   }
2638   else {
2639
2640   Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2641   Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2642
2643   XMin = RealLast ();
2644   YMin = RealLast ();
2645   ZMin = RealLast ();
2646
2647   XMax = RealFirst ();
2648   YMax = RealFirst ();
2649   ZMax = RealFirst ();
2650
2651   for ( Iterator.Initialize (ASet);
2652         Iterator.More ();
2653         Iterator.Next ()) {
2654
2655       if ( (Iterator.Key ())->IsInfinite ()){
2656         //XMin, YMin .... ZMax are initialized by means of infinite line data
2657         (Iterator.Key ())->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
2658         if ( Xm != RealFirst() && Xm < XMin )
2659           XMin = Xm ;
2660         if ( Ym != RealFirst() && Ym < YMin )
2661           YMin = Ym ;
2662         if ( Zm != RealFirst() && Zm < ZMin )
2663           ZMin = Zm ;
2664         if ( XM != RealLast()  && XM > XMax )
2665           XMax = XM ;
2666         if ( YM != RealLast()  && YM > YMax )
2667           YMax = YM ;
2668         if ( ZM != RealLast()  && ZM > ZMax )
2669           ZMax = ZM ;
2670       }
2671       // Only non-empty and non-infinite structures 
2672       // are taken into account for calculation of MinMax
2673       if (! (Iterator.Key ())->IsInfinite () &&
2674           ! (Iterator.Key ())->IsEmpty ()) {
2675             (Iterator.Key ())->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
2676           /* ABD 29/10/04  Transform Persistence of Presentation( pan, zoom, rotate ) */
2677           //"FitAll" operation ignores object with transform persitence parameter
2678           if( (Iterator.Key ())->TransformPersistenceMode() == Graphic3d_TMF_None )
2679           {
2680             if (Xm < XMin) XMin = Xm;
2681             if (Ym < YMin) YMin = Ym;
2682             if (Zm < ZMin) ZMin = Zm;
2683             if (XM > XMax) XMax = XM;
2684             if (YM > YMax) YMax = YM;
2685             if (ZM > ZMax) ZMax = ZM;
2686           }
2687         }
2688     }
2689
2690     // The following cases are relevant
2691     // For exemple if all structures are empty or infinite
2692     if (XMax < XMin) { Xm = XMin; XMin = XMax; XMax = Xm; }
2693     if (YMax < YMin) { Ym = YMin; YMin = YMax; YMax = Ym; }
2694     if (ZMax < ZMin) { Zm = ZMin; ZMin = ZMax; ZMax = Zm; }
2695   }
2696   Standard_Real Sx, Sy, Sz;
2697   MyViewOrientation.AxialScale(Sx, Sy, Sz);
2698   XMin = (Sx > 1. && XMin < RealFirst ()/Sx)?RealFirst (): XMin*Sx;
2699   XMax = (Sx > 1. && XMax > RealLast  ()/Sx)?RealLast  (): XMax*Sx;
2700   YMin = (Sy > 1. && YMin < RealFirst ()/Sy)?RealFirst (): YMin*Sy;
2701   YMax = (Sy > 1. && YMax > RealLast  ()/Sy)?RealLast  (): YMax*Sy;
2702   ZMin = (Sz > 1. && ZMin < RealFirst ()/Sz)?RealFirst (): ZMin*Sz;
2703   ZMax = (Sz > 1. && ZMax > RealLast  ()/Sz)?RealLast  (): ZMax*Sz;
2704 }
2705
2706 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2707
2708         MinMaxValues (MyDisplayedStructure, XMin, YMin, XMax, YMax);
2709
2710 }
2711
2712 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2713
2714 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2715 Standard_Real Xp, Yp, Zp;
2716
2717         MinMaxValues (ASet, Xm, Ym, Zm, XM, YM, ZM);
2718
2719         Projects (Xm, Ym, Zm, Xp, Yp, Zp);
2720         XMin    = Xp;
2721         YMin    = Yp;
2722
2723         Projects (XM, YM, ZM, Xp, Yp, Zp);
2724         XMax    = Xp;
2725         YMax    = Yp;
2726
2727         if (XMax < XMin) { Xp = XMax; XMax = XMin; XMin = Xp; }
2728         if (YMax < YMin) { Yp = YMax; YMax = YMin; YMin = Yp; }
2729 }
2730
2731 const TColStd_Array2OfReal& Visual3d_View::MatrixOfOrientation () {
2732
2733         if (! MyMatOfOriIsEvaluated) {
2734                 MyGraphicDriver->InquireMat
2735                     (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2736                 MyMatOfMapIsEvaluated   = Standard_True;
2737                 MyMatOfOriIsEvaluated   = Standard_True;
2738         }
2739
2740         return (MyMatrixOfOrientation);
2741
2742 }
2743
2744 const TColStd_Array2OfReal& Visual3d_View::MatrixOfMapping () {
2745
2746         if (! MyMatOfMapIsEvaluated) {
2747                 MyGraphicDriver->InquireMat
2748                     (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2749                 MyMatOfMapIsEvaluated   = Standard_True;
2750                 MyMatOfOriIsEvaluated   = Standard_True;
2751         }
2752
2753         return (MyMatrixOfMapping);
2754
2755 }
2756
2757 Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const {
2758
2759 Standard_Integer Result = MyDisplayedStructure.Extent ();
2760
2761         return (Result);
2762
2763 }
2764
2765 #ifdef OLD_METHOD
2766 void Visual3d_View::Projects (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ, Standard_Real& APX, Standard_Real& APY, Standard_Real& APZ) const {
2767
2768 math_Vector PtDC (0,3), PtWC (0,3);
2769
2770 // RLE method:
2771 // Otherwise use new on Visual3d_View (constructor+destructor)
2772 // as Projects is a const method or MatrixOfOrientation and
2773 // MatrixOfMapping is not.
2774 Visual3d_View * const newthis = (Visual3d_View * const) this;
2775         newthis->MatrixOfOrientation ();
2776         newthis->MatrixOfMapping ();
2777
2778 // World Coordinate Space
2779         PtWC (0) = AX;
2780         PtWC (1) = AY;
2781         PtWC (2) = AZ;
2782         PtWC (3) = 1.0;
2783
2784         // WCS -> View Reference Coordinate Space
2785         math_Vector PtVRC(0,3);
2786         PtVRC = MyMatrixOfOrientation.Multiplied (PtWC);
2787
2788         // VRCS -> Normalized Projection Coordinate Space
2789         math_Vector PtNPC(0,3);
2790         PtNPC = MyMatrixOfMapping.Multiplied (PtVRC);
2791         for (Standard_Integer i=0; i<3; i++) PtNPC (i) = PtNPC (i) / PtNPC (3);
2792
2793 #ifdef DEBUG
2794         printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2795                         PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2796 #endif // DEBUG
2797
2798         Standard_Real Ratio;
2799 #ifdef DEBUG
2800         // NPCS -> Device Coordinate Space
2801         Standard_Real Dx        = Standard_Real (MyCView.DefWindow.dx);
2802         Standard_Real Dy        = Standard_Real (MyCView.DefWindow.dy);
2803
2804         Ratio           = Dx / Dy;
2805         PtDC (0)        = PtNPC (0) * Dx;
2806         PtDC (1)        = Dy - PtNPC (1) * Dy * Ratio;
2807
2808         printf("Display coordinates : %f,%f,%f,%f\n",
2809                         PtDC(0),PtDC(1),PtDC(2),PtDC(3));
2810 #endif // DEBUG
2811
2812         // NPCS -> Window Space
2813 Standard_Real um, vm, uM, vM;
2814         MyViewMapping.WindowLimit (um, vm, uM, vM);
2815
2816         Ratio   = (uM - um) / (vM - vm);
2817         if (Ratio >= 1.0)
2818             PtNPC (1)   = PtNPC (1) * Ratio;
2819         else
2820             PtNPC (0)   = PtNPC (0) / Ratio;
2821
2822 #ifdef DEBUG
2823         printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2824                         PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2825 #endif // DEBUG
2826
2827         Standard_Real fpd       = MyViewMapping.FrontPlaneDistance ();
2828         Standard_Real bpd       = MyViewMapping.BackPlaneDistance ();
2829
2830         /*
2831          * Coordinates of PtNPC are described in the space
2832          * [0-1]x[0-1]x[0-1].
2833          * It is necessary to transform x and y in the window space.
2834          * It is necessary to transform z in the space of back and front
2835          * plane, taking into account clipping planes.
2836          * Z clipping planes are defined between 0 and 1.
2837         */
2838
2839         APX     = PtNPC (0) * (uM - um) + um;
2840         APY     = PtNPC (1) * (vM - vm) + vm;
2841         APZ     = PtNPC (2) * (fpd - bpd) + bpd;
2842
2843 #ifdef DEBUG
2844         Standard_Integer l,c;
2845         printf("OrientationMatrix :");
2846         for( l=0 ; l<4 ; l++ ) {
2847           printf("\n    %d->",l);
2848           for( c=0 ; c<4 ; c++ ) {
2849             printf(" %f ,",MyMatrixOfOrientation(c,l));
2850           }
2851         }
2852         printf("\n\n");
2853         printf("MappingMatrix :");
2854         for( l=0 ; l<4 ; l++ ) {
2855           printf("\n    %d->",l);
2856           for( c=0 ; c<4 ; c++ ) {
2857             printf(" %f ,",MyMatrixOfMapping(c,l));
2858           }
2859         }
2860         printf("\n\n");
2861         printf("World coordinates : %f,%f,%f,%f\n",
2862                         PtWC(0),PtWC(1),PtWC(2),PtWC(3));
2863         printf("View coordinates : %f,%f,%f,%f\n",
2864                         PtVRC(0),PtVRC(1),PtVRC(2),PtVRC(3));
2865         printf("Display coordinates : %f,%f,%f,%f\n",
2866                         PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2867         printf("Window limit : %f,%f,%f,%f\n",um,vm,uM,vM);
2868         printf("Ratio : %f\n",Ratio);
2869         printf("Front-plane : %f back-plane : %f\n",fpd,bpd);
2870         printf("Projection : %f,%f,%f\n \n",APX,APY,APZ);
2871 #endif
2872
2873 }
2874 #endif /* OLD_METHOD */
2875
2876 // OCC18942: This method is likely to duplicate Visual3d_ViewManager::ConvertCoord() one,
2877 // therefore it is necessary to consider merging the two methods or making them call the same
2878 // graphic driver's method after OCCT 6.3.
2879 void Visual3d_View::Projects (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ, Standard_Real& APX, Standard_Real& APY, Standard_Real& APZ) {
2880
2881 Standard_Real PtX, PtY, PtZ, PtT;
2882 Standard_Real APT;
2883 static Standard_Real Ratio, um, vm, uM, vM;
2884 static Standard_Real fpd, bpd;
2885
2886         if (! MyMatOfOriIsEvaluated || ! MyMatOfMapIsEvaluated) {
2887                 MyGraphicDriver->InquireMat
2888                     (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2889                 MyMatOfOriIsEvaluated = MyMatOfMapIsEvaluated = Standard_True;
2890         }
2891
2892         // WCS -> View Reference Coordinate Space
2893         PtX     = MyMatrixOfOrientation (0, 0) * AX
2894                 + MyMatrixOfOrientation (0, 1) * AY
2895                 + MyMatrixOfOrientation (0, 2) * AZ
2896                 + MyMatrixOfOrientation (0, 3);
2897         PtY     = MyMatrixOfOrientation (1, 0) * AX
2898                 + MyMatrixOfOrientation (1, 1) * AY
2899                 + MyMatrixOfOrientation (1, 2) * AZ
2900                 + MyMatrixOfOrientation (1, 3);
2901         PtZ     = MyMatrixOfOrientation (2, 0) * AX
2902                 + MyMatrixOfOrientation (2, 1) * AY
2903                 + MyMatrixOfOrientation (2, 2) * AZ
2904                 + MyMatrixOfOrientation (2, 3);
2905         PtT     = MyMatrixOfOrientation (3, 0) * AX
2906                 + MyMatrixOfOrientation (3, 1) * AY
2907                 + MyMatrixOfOrientation (3, 2) * AZ
2908                 + MyMatrixOfOrientation (3, 3);
2909
2910         // VRCS -> Normalized Projection Coordinate Space
2911         APX     = MyMatrixOfMapping (0, 0) * PtX
2912                 + MyMatrixOfMapping (0, 1) * PtY
2913                 + MyMatrixOfMapping (0, 2) * PtZ
2914                 + MyMatrixOfMapping (0, 3) * PtT;
2915         APY     = MyMatrixOfMapping (1, 0) * PtX
2916                 + MyMatrixOfMapping (1, 1) * PtY
2917                 + MyMatrixOfMapping (1, 2) * PtZ
2918                 + MyMatrixOfMapping (1, 3) * PtT;
2919         APZ     = MyMatrixOfMapping (2, 0) * PtX
2920                 + MyMatrixOfMapping (2, 1) * PtY
2921                 + MyMatrixOfMapping (2, 2) * PtZ
2922                 + MyMatrixOfMapping (2, 3) * PtT;
2923         APT     = MyMatrixOfMapping (3, 0) * PtX
2924                 + MyMatrixOfMapping (3, 1) * PtY
2925                 + MyMatrixOfMapping (3, 2) * PtZ
2926                 + MyMatrixOfMapping (3, 3) * PtT;
2927
2928         APX /= APT;
2929         APY /= APT;
2930         APZ /= APT;
2931
2932         // NPCS -> Window Space
2933         MyViewMapping.WindowLimit (um, vm, uM, vM);
2934         fpd     = MyViewMapping.FrontPlaneDistance ();
2935         bpd     = MyViewMapping.BackPlaneDistance ();
2936
2937         if(MyCView.Mapping.IsCustomMatrix) {
2938                 // OCC18942: SAN - If orientation and mapping matrices are those used by OpenGL
2939                 // visualization, then X, Y and Z coordinates normally vary between -1 and 1
2940                 APX     = ( APX + 1 ) * 0.5 * (uM - um) + um;
2941                 APY     = ( APY + 1 ) * 0.5 * (vM - vm) + vm;
2942         } else {
2943                 Ratio   = (uM - um) / (vM - vm);
2944                 if (Ratio >= 1.0)
2945                         APY *= Ratio;
2946                 else
2947                         APX /= Ratio;
2948
2949                 /*
2950          * Coordinates of APX, APY, APZ are described in the space
2951          * [0-1]x[0-1]x[0-1].
2952          * It is necessary to transform x and y in the window space.
2953          * It is necessary to transform z in the space of back and front
2954          * plane, taking into account clipping planes.
2955          * Z clipping planes are defined between 0 and 1.
2956                 */
2957             APX     = APX * (uM - um) + um;
2958             APY     = APY * (vM - vm) + vm;
2959         }
2960         APZ     = APZ * (fpd - bpd) + bpd;
2961 }
2962
2963 Standard_Integer Visual3d_View::Identification () const {
2964
2965         return (Standard_Integer (MyCView.ViewId));
2966
2967 }
2968
2969 void Visual3d_View::Exploration () const {
2970
2971         if (IsDeleted ()) return;
2972
2973         MyGraphicDriver->DumpView (MyCView);
2974
2975 }
2976
2977 Standard_Boolean Visual3d_View::ZBufferIsActivated () const {
2978
2979         if (IsDeleted ()) return (Standard_False);
2980
2981         if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);
2982
2983 // -1 => not forced by the programmer => depends on the type of visualisation
2984 //  0 ou 1 => forced by the programmer
2985
2986         if (MyCView.Context.ZBufferActivity == -1)
2987                 if (MyContext.Visualization () == Visual3d_TOV_SHADING)
2988                         return (Standard_True);
2989                 else
2990                         return (Standard_False);
2991         else
2992                 if (MyCView.Context.ZBufferActivity)
2993                         return (Standard_True);
2994                 else
2995                         return (Standard_False);
2996
2997 }
2998
2999 void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {
3000
3001         if (IsDeleted ()) return;
3002
3003         if ((! IsDefined ()) || (! IsActive ())) return;
3004
3005         MyGraphicDriver->Transparency (MyCView, AnActivity);
3006
3007 }
3008
3009 void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {
3010
3011         if (MyCView.Context.ZBufferActivity == AnActivity) return;
3012
3013         if (IsDeleted ()) return;
3014
3015         if ((! IsDefined ()) || (! IsActive ())) return;
3016
3017         MyCView.Context.ZBufferActivity = AnActivity;
3018         MyGraphicDriver->SetVisualisation (MyCView);
3019
3020 }
3021
3022 void Visual3d_View::UpdateView () {
3023
3024         MyCView.Context.Aliasing        = (MyContext.AliasingIsOn () ? 1:0);
3025         MyCView.Context.BackZClipping   =
3026                 (MyContext.BackZClippingIsOn () ? 1:0);
3027         MyCView.Context.FrontZClipping  =
3028                 (MyContext.FrontZClippingIsOn() ? 1:0);
3029         MyCView.Context.DepthCueing     =
3030                 (MyContext.DepthCueingIsOn () ? 1:0);
3031
3032         MyCView.Context.ZClipFrontPlane =
3033                                 float (MyContext.ZClippingFrontPlane ());
3034         MyCView.Context.ZClipBackPlane          =
3035                                 float (MyContext.ZClippingBackPlane ());
3036         MyCView.Context.DepthFrontPlane =
3037                                 float (MyContext.DepthCueingFrontPlane ());
3038         MyCView.Context.DepthBackPlane          =
3039                                 float (MyContext.DepthCueingBackPlane ());
3040
3041         MyCView.Context.Model           = int (MyContext.Model ());
3042         MyCView.Context.Visualization   = int (MyContext.Visualization ());
3043
3044         Handle(Graphic3d_TextureEnv)   TempTextureEnv = MyContext.TextureEnv();
3045         if (! TempTextureEnv.IsNull()) MyCView.Context.TexEnvId = TempTextureEnv->TextureId();
3046         else                           MyCView.Context.TexEnvId = -1;
3047         MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
3048
3049 }
3050
3051 void Visual3d_View::Compute () {
3052
3053 Standard_Integer i;
3054 Standard_Integer Length = MyCOMPUTEDSequence.Length ();
3055         for (i=1; i<=Length; i++)
3056             (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);
3057
3058         // if the degenerated node is active, nothing is recomputed
3059 #ifdef G003
3060         if (  DegenerateModeIsOn () || !ComputedMode ()  ) return;
3061 #else
3062         if (DegenerateModeIsOn ()) return;
3063 #endif  // G003
3064
3065         /*
3066          * Force HLRValidation to False on all structures
3067          * calculated in the view.
3068          */
3069 #ifdef TRACE_LENGTH
3070         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3071                 cout << "In Visual3d_View::Compute, ";
3072                 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3073                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3074                      << "\n" << flush;
3075         }
3076 #endif
3077
3078         /*
3079          * Change of orientation or of projection type =>
3080          * Remove structures that were calculated for the
3081          * previous orientation.
3082          * Recalculation of new structures.
3083          * Passage of the degenerated mode ON to OFF =>
3084          * Remove structures that were calculated before 
3085          * the degenerated mode passed to ON.
3086          * Recalculate new structures.
3087          */
3088 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3089 Visual3d_TypeOfAnswer Answer;
3090
3091         i       = MyDisplayedStructure.Extent ();
3092
3093 Graphic3d_SequenceOfStructure FooSequence;
3094
3095         while (S1Iterator.More ()) {
3096                 Answer  = AcceptDisplay (S1Iterator.Key ());
3097                 // If the structure was calculated, it is recalculated.
3098                 if (Answer == Visual3d_TOA_COMPUTE) {
3099 #ifdef TRACE
3100                         cout << "AcceptDisplay ("
3101                              << (S1Iterator.Key ())->Identification ()
3102                              << ") == Visual3d_TOA_COMPUTE;\n";
3103                         cout << flush;
3104 #endif
3105                         //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
3106                         FooSequence.Append (S1Iterator.Key ());
3107                 }
3108
3109                 // S1Iterator.Next () is located on the next structure
3110                 S1Iterator.Next ();
3111         }
3112
3113         Length  = FooSequence.Length ();
3114         // All stored structures are displayed
3115         for (i=1; i<=Length; i++)
3116                 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
3117         if (Length != 0) FooSequence.Clear ();
3118
3119 }
3120
3121 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
3122 #ifdef G003
3123         if ( DegenerateModeIsOn () || !ComputedMode () ) return;
3124 #else
3125         if (DegenerateModeIsOn()) return;
3126 #endif  // G003
3127
3128         if (IsDeleted ()) return;
3129
3130         if ((! IsDefined ()) || (! IsActive ())) return;
3131
3132         if (! MyWindow->IsMapped ()) return;
3133
3134         if (! AStructure->IsDisplayed ()) return;
3135
3136 Visual3d_TypeOfAnswer Answer;
3137
3138         Answer  = AcceptDisplay (AStructure);
3139
3140         if (Answer == Visual3d_TOA_COMPUTE) {
3141 Standard_Integer Index = IsComputed (AStructure);
3142                 if (Index == 0) {
3143 #ifdef TRACE_COMP
3144         cout << "Structure " << AStructure->Identification ()
3145              << " is not calculated in the view "
3146              << Identification () << "\n";
3147         cout << flush;
3148 #endif
3149                 }
3150                 else {
3151                   Standard_Integer OldStructId, NewStructId;
3152                         OldStructId =
3153                         MyCOMPUTEDSequence.Value (Index)->Identification ();
3154 #ifdef TRACE_COMP
3155         Standard_Integer StructId = AStructure->Identification ();
3156         cout << "Structure " << StructId
3157              << " calculated, in the view "
3158              << Identification () << ", by the structure "
3159              << OldStructId << " is recalculated.\n";
3160         cout << flush;
3161 #endif
3162
3163         // Compute + Validation
3164 #ifdef OLD
3165 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3166 #else
3167 Handle(Graphic3d_Structure) TheStructure;
3168 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3169         AStructure->Transform (ATrsf);
3170         if (Index != 0) {
3171 TColStd_Array2OfReal Ident (0, 3, 0, 3);
3172 Standard_Integer ii, jj;
3173         for (ii=0; ii<=3; ii++)
3174             for (jj=0; jj<=3; jj++)
3175                 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3176             TheStructure = MyCOMPUTEDSequence.Value (Index);
3177             TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3178             if (AStructure->IsTransformed ()) {
3179                 AStructure->Compute (this, ATrsf, TheStructure);
3180             }
3181             else {
3182                 AStructure->Compute (this, TheStructure);
3183             }
3184         }
3185         else {
3186             if (AStructure->IsTransformed ()) {
3187                 TheStructure = AStructure->Compute (this, ATrsf);
3188             }
3189             else {
3190                 TheStructure = AStructure->Compute (this);
3191             }
3192         }
3193 #endif
3194         TheStructure->SetHLRValidation (Standard_True);
3195
3196 // Return type of visualisation of the view
3197 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3198
3199 // Of which type will be the computed ?
3200 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3201         (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
3202
3203 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3204         (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3205
3206                         if (ComputeWireframe)
3207                             TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3208                         if (ComputeShading)
3209                             TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3210
3211                         if (AStructure->IsHighlighted ()) {
3212                             TheStructure->SetHighlightColor
3213                                 (AStructure->HighlightColor ());
3214                             TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3215                         }
3216
3217                         // Ot is ranged
3218                         // Find structure <AStructure>
3219                         // in the sequence of structures to be calculated.
3220                         NewStructId = TheStructure->Identification ();
3221
3222                         // The previous calculation is removed and the new one is dislayed
3223                         MyGraphicDriver->EraseStructure (
3224                                 MyCView,
3225                                 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3226                         MyGraphicDriver->DisplayStructure (
3227                                 MyCView,
3228                                 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3229                                 int (AStructure->DisplayPriority ())
3230                         );
3231
3232 #ifdef TRACE_LENGTH
3233         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3234                 cout << "In Visual3d_View::ReCompute, ";
3235                 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3236                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3237                      << "\n" << flush;
3238         }
3239 #endif
3240
3241                           // hlhsr and the new associated compute are added
3242                           MyTOCOMPUTESequence.Append (AStructure);
3243                           MyCOMPUTEDSequence.Append (TheStructure);
3244
3245 #ifdef TRACE_LENGTH
3246         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3247                 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3248                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3249                      << "\n" << flush;
3250 #endif
3251
3252                           // hlhsr and the new associated compute are removed 
3253
3254                           MyTOCOMPUTESequence.Remove (Index);
3255                           MyCOMPUTEDSequence.Remove (Index);
3256
3257 #ifdef TRACE_LENGTH
3258         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3259                 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3260                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3261                      << "\n" << flush;
3262 #endif
3263                 }
3264         }
3265
3266 }
3267
3268 void
3269 #ifdef G003
3270 Visual3d_View::SetAnimationModeOn ( const Standard_Boolean degenerate ) {
3271 #else
3272 Visual3d_View::SetAnimationModeOn () {
3273 #endif
3274
3275         if (AnimationModeIsOn ()) return;
3276
3277         AnimationModeIsActive   = Standard_True;
3278 #ifdef G003
3279         if ( degenerate )
3280           SetDegenerateModeOn ();
3281         else
3282           SetDegenerateModeOff ();
3283 #endif  // G003
3284         MyGraphicDriver->BeginAnimation (MyCView);
3285
3286 }
3287
3288 void Visual3d_View::SetAnimationModeOff () {
3289
3290         if (! AnimationModeIsOn ()) return;
3291
3292         AnimationModeIsActive   = Standard_False;
3293 #ifdef G003
3294         SetDegenerateModeOff ();
3295 #endif  // G003
3296         MyGraphicDriver->EndAnimation (MyCView);
3297
3298 }
3299
3300 Standard_Boolean Visual3d_View::AnimationModeIsOn () const {
3301
3302         return AnimationModeIsActive;
3303
3304 }
3305
3306 void Visual3d_View::SetDegenerateModeOn () {
3307
3308 #ifdef TRACE
3309         cout << "Visual3d_View" << MyCView.ViewId
3310              << "::SetDegenerateModeOn ();\n";
3311         cout << flush;
3312 #endif
3313
3314         // If the degenerated mode is already active, nothing is recalculated
3315         if (DegenerateModeIsOn ()) return;
3316         DegenerateModeIsActive = Standard_True;
3317
3318 #ifdef G003
3319         MyCView.IsDegenerates  = 1;
3320 #else
3321         /*
3322          * Change of activity of the degenerated mode
3323          * Remove structures that were calculated
3324          * and displayed when the mode was off.
3325          * Display of non-calculated structures.
3326          */
3327 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3328 Visual3d_TypeOfAnswer Answer;
3329 Standard_Integer StructId;
3330
3331         while (S1Iterator.More ()) {
3332
3333                 Answer  = AcceptDisplay (S1Iterator.Key ());
3334                 // If the structure was calculated, the previous one is 
3335                 // removed and the new one is displayed
3336                 // (This is the role of passage into degenerated mode)
3337
3338                 if (Answer == Visual3d_TOA_COMPUTE) {
3339 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3340                     if (Index != 0) {
3341                         StructId =
3342                         MyCOMPUTEDSequence.Value (Index)->Identification ();
3343 #ifdef TRACE_COMP
3344         cout << "Structure " << S1Iterator.Key ()->Identification ()
3345              << " calculated, in the view "
3346              << Identification () << ", by structure "
3347              << StructId << " passes in degenerated mode.\n";
3348         cout << "Remove" << StructId << " then display "
3349              << S1Iterator.Key ()->Identification () << "\n";
3350         cout << flush;
3351 #endif
3352                         MyGraphicDriver->EraseStructure
3353                                 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3354                         MyGraphicDriver->DisplayStructure (
3355                                 MyCView,
3356                                 *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure (),
3357                                 int (S1Iterator.Key ()->DisplayPriority ())
3358                         );
3359                     }
3360                     else {
3361                         // Else is impossible)
3362                         // If the mode was not degenerated previously, the
3363                         // calculated structure associated to S1Iterator.Key ()
3364                         // really exists and Index != 0
3365                     }
3366                 }
3367
3368                 // S1Iterator.Next () is located on the next structure
3369                 S1Iterator.Next ();
3370         }
3371 #endif  //G003
3372 }
3373
3374 void Visual3d_View::SetDegenerateModeOff () {
3375
3376 #ifdef TRACE
3377         cout << "Visual3d_View" << MyCView.ViewId
3378              << "::SetDegenerateModeOff ();\n";
3379         cout << flush;
3380 #endif
3381
3382         // If the degenerated mode is already inactive, nothing is recalculated
3383         if (! DegenerateModeIsOn ()) return;
3384
3385         DegenerateModeIsActive  = Standard_False;
3386
3387 #ifdef G003
3388         MyCView.IsDegenerates  = 0;
3389 #else
3390         /*
3391          * Change of activity of degenerated mode
3392          * Remove structures that were displayed
3393          * when the mode was on.
3394          * Calculation of structures.
3395          */
3396 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3397 Visual3d_TypeOfAnswer Answer;
3398 Standard_Integer StructId;
3399
3400         Standard_Integer i      = MyDisplayedStructure.Extent ();
3401
3402         while (S1Iterator.More ()) {
3403
3404                 Answer  = AcceptDisplay (S1Iterator.Key ());
3405                 // If the structure was calculated, the previous one is 
3406                 // removed and the new one is displayed
3407                 // (This is the role of passage into degenerated mode)
3408            
3409                 if (Answer == Visual3d_TOA_COMPUTE) {
3410 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3411                     if (Index != 0) {
3412                         StructId =
3413                         MyCOMPUTEDSequence.Value (Index)->Identification ();
3414 #ifdef TRACE_COMP
3415         cout << "Structure " << S1Iterator.Key ()->Identification ()
3416              << " calculated, in the view "
3417              << Identification () << ", by the structure "
3418              << StructId << " passes into normal mode.\n";
3419         cout << "Remove " << S1Iterator.Key ()->Identification ()
3420              << " then display " << StructId << "\n";
3421         cout << flush;
3422 #endif
3423                         MyGraphicDriver->EraseStructure
3424                                 (MyCView,
3425                                 *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure ());
3426                         MyGraphicDriver->DisplayStructure (
3427                                 MyCView,
3428                                 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
3429                                 int (S1Iterator.Key ()->DisplayPriority ())
3430                         );
3431
3432                         Display (S1Iterator.Key (), Aspect_TOU_WAIT);
3433
3434                         if ((S1Iterator.Key ())->IsHighlighted()) {
3435                            if (! (MyCOMPUTEDSequence.Value (Index))->IsHighlighted()) {
3436                                 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
3437                                         ((S1Iterator.Key ())->HighlightColor ());
3438                                 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (Aspect_TOHM_COLOR);
3439                             }
3440                         }
3441                     }
3442                     else {
3443                         // Else is impossible 
3444                         // Degenerated mode was activated before display of the
3445                         // structure. So the structure was displayed in the
3446                         // degenerated mode, but the calculated structure didn't exist.
3447                         // It is calculated.
3448
3449         // Compute + Validation
3450 Handle(Graphic3d_Structure) AStructure = (S1Iterator.Key ());
3451 #ifdef OLD
3452 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3453 #else
3454 Handle(Graphic3d_Structure) TheStructure;
3455 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3456         AStructure->Transform (ATrsf);
3457         if (Index != 0) {
3458 TColStd_Array2OfReal Ident (0, 3, 0, 3);
3459 Standard_Integer ii, jj;
3460         for (ii=0; ii<=3; ii++)
3461             for (jj=0; jj<=3; jj++)
3462                 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3463             TheStructure = MyCOMPUTEDSequence.Value (Index);
3464             TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3465             if (AStructure->IsTransformed ()) {
3466                 AStructure->Compute (this, ATrsf, TheStructure);
3467             }
3468             else {
3469                 AStructure->Compute (this, TheStructure);
3470             }
3471         }
3472         else {
3473             if (AStructure->IsTransformed ()) {
3474                 TheStructure = AStructure->Compute (this, ATrsf);
3475             }
3476             else {
3477                 TheStructure = AStructure->Compute (this);
3478             }
3479         }
3480 #endif
3481         TheStructure->SetHLRValidation (Standard_True);
3482
3483 // Return type of visualisation of the view
3484 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3485
3486 // Of which type will be the computed ?
3487 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3488         ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_SHADING));
3489
3490 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3491         ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3492
3493                         if (ComputeWireframe)
3494                             TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3495                         if (ComputeShading)
3496                             TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3497
3498                         if ((S1Iterator.Key ())->IsHighlighted()) {
3499                             TheStructure->SetHighlightColor
3500                                 ((S1Iterator.Key ())->HighlightColor ());
3501                             TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3502                         }
3503
3504                         // Make range
3505 Standard_Integer Result = 0;
3506 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3507                         // Find structure <S1Iterator.Key ()>
3508                         // in the sequence of structures to be calculated
3509                         StructId = (S1Iterator.Key ())->Identification ();
3510                         for (i=1; i<=Length && Result==0; i++)
3511                           if ((MyTOCOMPUTESequence.Value (i))->Identification () ==
3512                             StructId) Result    = i;
3513                         if (Result != 0)
3514                           MyCOMPUTEDSequence.ChangeValue (Result) = TheStructure;
3515                         else {
3516                           // hlhsr and the associated new compute are added
3517 #ifdef TRACE_LENGTH
3518         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3519                 cout << "In Visual3d_View::SetDegenerateModeOff, ";
3520                 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3521                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3522                      << "\n" << flush;
3523         }
3524 #endif
3525                           MyTOCOMPUTESequence.Append (S1Iterator.Key ());
3526                           MyCOMPUTEDSequence.Append (TheStructure);
3527 #ifdef TRACE_LENGTH
3528         if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3529                 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3530                      << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3531                      << "\n" << flush;
3532 #endif
3533                         }
3534
3535                         // The degenerated is removed and the calculated is displayed
3536                         MyGraphicDriver->EraseStructure
3537                                 (MyCView,
3538                                 *(Graphic3d_CStructure *)(S1Iterator.Key ()->CStructure ()));
3539                         MyGraphicDriver->DisplayStructure (
3540                                 MyCView,
3541                                 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3542                                 int (S1Iterator.Key ()->DisplayPriority ())
3543                         );
3544                     }
3545                 }
3546
3547                 // S1Iterator.Next () is located on the next structure
3548                 S1Iterator.Next ();
3549         }
3550
3551         if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
3552 #endif  //G003
3553 }
3554
3555 Standard_Boolean Visual3d_View::DegenerateModeIsOn () const {
3556
3557         return DegenerateModeIsActive;
3558
3559 }
3560
3561 Handle(Aspect_GraphicDriver) Visual3d_View::GraphicDriver () const {
3562
3563         return MyGraphicDriver;
3564
3565 }
3566
3567 void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& APlotter) const {
3568
3569 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3570
3571         while (S1Iterator.More ()) {
3572
3573                 if (DegenerateModeIsOn ())
3574                         // As the  mode is degenerated the displayed structure
3575                         // is plotted without taking into account if it is calculated or not
3576                         (S1Iterator.Key ())->Plot (APlotter);
3577                 else {
3578 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3579                         // As the  mode is not degenerated the displayed structure
3580                         // is plotted as if it was not calculated, otherwise the 
3581                         // associated calculated structure is plotted.
3582                         if (Index == 0)
3583                             (S1Iterator.Key ())->Plot (APlotter);
3584                         else
3585                             (MyCOMPUTEDSequence.Value (Index))->Plot (APlotter);
3586                 }
3587
3588                 // S1Iterator.Next () is located on the next structure
3589                 S1Iterator.Next ();
3590         }
3591
3592 }
3593
3594 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const {
3595
3596 Standard_Integer Result = 0;
3597 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3598
3599         // Find in the sequence of already calculated structures 
3600         // 1/ Structure with the same Owner as <AStructure>
3601         // 2/ Which is not <AStructure>
3602         // 3/ COMPUTED which of is valid
3603         for (Standard_Integer i=1; i<=Length && Result==0; i++)
3604            if ((MyTOCOMPUTESequence.Value (i)->Owner () == AStructure->Owner ())
3605             && (MyTOCOMPUTESequence.Value (i)->Identification () !=
3606                                                 AStructure->Identification ())
3607             && (MyCOMPUTEDSequence.Value (i)->HLRValidation ())) Result   = i;
3608
3609         return (Result);
3610
3611 }
3612
3613 Standard_Address Visual3d_View::CView () const {
3614
3615         return Standard_Address (&MyCView);
3616
3617 }
3618
3619
3620 // Triedron methods : the Triedron is a non-zoomable object.
3621
3622 void Visual3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
3623                                     const Quantity_NameOfColor YColor,
3624                                     const Quantity_NameOfColor ZColor,
3625                                     const Standard_Real        SizeRatio,
3626                                     const Standard_Real        AxisDiametr,
3627                                     const Standard_Integer     NbFacettes) {
3628   MyGraphicDriver->ZBufferTriedronSetup(XColor, YColor, ZColor,
3629                                         SizeRatio, AxisDiametr, NbFacettes);
3630 }
3631
3632
3633
3634 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
3635  const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) {
3636
3637         MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe);
3638
3639 }
3640
3641 void Visual3d_View::TriedronErase () {
3642
3643         MyGraphicDriver->TriedronErase (MyCView);
3644
3645
3646 }
3647
3648 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {
3649
3650         MyGraphicDriver->TriedronEcho (MyCView,AType);
3651
3652 }
3653
3654 Standard_Boolean checkFloat(const Standard_Real value)
3655 {
3656     return value > -FLT_MAX && value < FLT_MAX;
3657 }
3658
3659 void SetMinMaxValuesCallback(void* Visual3dView)
3660 {
3661     Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
3662
3663     Handle(Visual3d_View) view = (Handle(Visual3d_View)&) Visual3dView;
3664     view->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax);
3665
3666     if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) &&
3667         checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax))
3668     {
3669         Handle(Graphic3d_GraphicDriver) driver = Handle(Graphic3d_GraphicDriver)::DownCast(view->GraphicDriver());
3670         driver->GraduatedTrihedronMinMaxValues((Standard_ShortReal)xmin, (Standard_ShortReal)ymin, (Standard_ShortReal)zmin,
3671                                                (Standard_ShortReal)xmax, (Standard_ShortReal)ymax, (Standard_ShortReal)zmax);
3672     }
3673 }
3674
3675 Standard_Boolean Visual3d_View::GetGraduatedTrihedron
3676     (/* Names of axes */
3677      TCollection_ExtendedString& xname,
3678      TCollection_ExtendedString& yname,
3679      TCollection_ExtendedString& zname,
3680      /* Draw names */
3681      Standard_Boolean& xdrawname,
3682      Standard_Boolean& ydrawname,
3683      Standard_Boolean& zdrawname,
3684      /* Draw values */
3685      Standard_Boolean& xdrawvalues,
3686      Standard_Boolean& ydrawvalues,
3687      Standard_Boolean& zdrawvalues,
3688      /* Draw grid */
3689      Standard_Boolean& drawgrid,
3690      /* Draw axes */
3691      Standard_Boolean& drawaxes,
3692      /* Number of splits along axes */
3693      Standard_Integer& nbx,
3694      Standard_Integer& nby,
3695      Standard_Integer& nbz,
3696      /* Offset for drawing values */
3697      Standard_Integer& xoffset,
3698      Standard_Integer& yoffset,
3699      Standard_Integer& zoffset,
3700      /* Offset for drawing names of axes */
3701      Standard_Integer& xaxisoffset,
3702      Standard_Integer& yaxisoffset,
3703      Standard_Integer& zaxisoffset,
3704      /* Draw tickmarks */
3705      Standard_Boolean& xdrawtickmarks,
3706      Standard_Boolean& ydrawtickmarks,
3707      Standard_Boolean& zdrawtickmarks,
3708      /* Length of tickmarks */
3709      Standard_Integer& xtickmarklength,
3710      Standard_Integer& ytickmarklength,
3711      Standard_Integer& ztickmarklength,
3712      /* Grid color */
3713      Quantity_Color& gridcolor,
3714      /* Colors of axis names */
3715      Quantity_Color& xnamecolor,
3716      Quantity_Color& ynamecolor,
3717      Quantity_Color& znamecolor,
3718      /* Colors of axis and values */
3719      Quantity_Color& xcolor,
3720      Quantity_Color& ycolor,
3721      Quantity_Color& zcolor,
3722      /* Name of font for names of axes */
3723      TCollection_AsciiString& fontOfNames,
3724      /* Style of names of axes */
3725      OSD_FontAspect& styleOfNames,
3726      /* Size of names of axes */
3727      Standard_Integer& sizeOfNames,
3728      /* Name of font for values */
3729      TCollection_AsciiString& fontOfValues,
3730      /* Style of values */
3731      OSD_FontAspect& styleOfValues,
3732      /* Size of values */
3733      Standard_Integer& sizeOfValues) const
3734 {
3735     if (!MyGTrihedron.ptrVisual3dView)
3736         return Standard_False;
3737
3738     /* Names of axes */
3739     xname = MyGTrihedron.xname;
3740     yname = MyGTrihedron.yname; 
3741     zname = MyGTrihedron.zname;
3742     /* Draw names */
3743     xdrawname = MyGTrihedron.xdrawname; 
3744     ydrawname = MyGTrihedron.ydrawname; 
3745     zdrawname = MyGTrihedron.zdrawname;
3746     /* Draw values */
3747     xdrawvalues = MyGTrihedron.xdrawvalues; 
3748     ydrawvalues = MyGTrihedron.ydrawvalues; 
3749     zdrawvalues = MyGTrihedron.zdrawvalues;
3750     /* Draw grid */
3751     drawgrid = MyGTrihedron.drawgrid;
3752     /* Draw axes */
3753     drawaxes = MyGTrihedron.drawaxes;
3754     /* Number of splits along axes */
3755     nbx = MyGTrihedron.nbx;
3756     nby = MyGTrihedron.nby;
3757     nbz = MyGTrihedron.nbz;
3758     /* Offset for drawing values */
3759     xoffset = MyGTrihedron.xoffset;
3760     yoffset = MyGTrihedron.yoffset;
3761     zoffset = MyGTrihedron.zoffset;
3762     /* Offset for drawing names of axes */
3763     xaxisoffset = MyGTrihedron.xaxisoffset;
3764     yaxisoffset = MyGTrihedron.yaxisoffset;
3765     zaxisoffset = MyGTrihedron.zaxisoffset;
3766     /* Draw tickmarks */
3767     xdrawtickmarks = MyGTrihedron.xdrawtickmarks;
3768     ydrawtickmarks = MyGTrihedron.ydrawtickmarks;
3769     zdrawtickmarks = MyGTrihedron.zdrawtickmarks;
3770     /* Length of tickmarks */
3771     xtickmarklength = MyGTrihedron.xtickmarklength;
3772     ytickmarklength = MyGTrihedron.ytickmarklength;
3773     ztickmarklength = MyGTrihedron.ztickmarklength;
3774     /* Grid color */
3775     gridcolor = MyGTrihedron.gridcolor;
3776     /* Colors of axis names */
3777     xnamecolor = MyGTrihedron.xnamecolor;
3778     ynamecolor = MyGTrihedron.ynamecolor;
3779     znamecolor = MyGTrihedron.znamecolor;
3780     /* Colors of axis and values */
3781     xcolor = MyGTrihedron.xcolor;
3782     ycolor = MyGTrihedron.ycolor;
3783     zcolor = MyGTrihedron.zcolor;
3784     /* Name of font for names of axes */
3785     fontOfNames = MyGTrihedron.fontOfNames;
3786     /* Style of names of axes */
3787     styleOfNames = MyGTrihedron.styleOfNames;
3788     /* Size of names of axes */
3789     sizeOfNames = MyGTrihedron.sizeOfNames;
3790     /* Name of font for values */
3791     fontOfValues = MyGTrihedron.fontOfValues;
3792     /* Style of values */
3793     styleOfValues = MyGTrihedron.styleOfValues;
3794     /* Size of values */
3795     sizeOfValues = MyGTrihedron.sizeOfValues;
3796
3797     return Standard_True;
3798 }
3799
3800 void Visual3d_View::GraduatedTrihedronDisplay
3801     (/* Names of axes */
3802      const TCollection_ExtendedString &xname,
3803      const TCollection_ExtendedString &yname,
3804      const TCollection_ExtendedString &zname,
3805      /* Draw names */
3806      const Standard_Boolean xdrawname,
3807      const Standard_Boolean ydrawname,
3808      const Standard_Boolean zdrawname,
3809      /* Draw values */
3810      const Standard_Boolean xdrawvalues,
3811      const Standard_Boolean ydrawvalues,
3812      const Standard_Boolean zdrawvalues,
3813      /* Draw grid */
3814      const Standard_Boolean drawgrid,
3815      /* Draw axes */
3816      const Standard_Boolean drawaxes,
3817      /* Number of splits along axes */
3818      const Standard_Integer nbx,
3819      const Standard_Integer nby,
3820      const Standard_Integer nbz,
3821      /* Offset for drawing values */
3822      const Standard_Integer xoffset,
3823      const Standard_Integer yoffset,
3824      const Standard_Integer zoffset,
3825      /* Offset for drawing names of axes */
3826      const Standard_Integer xaxisoffset,
3827      const Standard_Integer yaxisoffset,
3828      const Standard_Integer zaxisoffset,
3829      /* Draw tickmarks */
3830      const Standard_Boolean xdrawtickmarks,
3831      const Standard_Boolean ydrawtickmarks,
3832      const Standard_Boolean zdrawtickmarks,
3833      /* Length of tickmarks */
3834      const Standard_Integer xtickmarklength,
3835      const Standard_Integer ytickmarklength,
3836      const Standard_Integer ztickmarklength,
3837      /* Grid color */
3838      const Quantity_Color& gridcolor,
3839      /* Colors of axis names */
3840      const Quantity_Color& xnamecolor,
3841      const Quantity_Color& ynamecolor,
3842      const Quantity_Color& znamecolor,
3843      /* Colors of axis and values */
3844      const Quantity_Color& xcolor,
3845      const Quantity_Color& ycolor,
3846      const Quantity_Color& zcolor,
3847      /* Name of font for names of axes */
3848      const TCollection_AsciiString &fontOfNames,
3849      /* Style of names of axes */
3850      const OSD_FontAspect styleOfNames,
3851      /* Size of names of axes */
3852      const Standard_Integer sizeOfNames,
3853      /* Name of font for values */
3854      const TCollection_AsciiString &fontOfValues,
3855      /* Style of values */
3856      const OSD_FontAspect styleOfValues,
3857      /* Size of values */
3858      const Standard_Integer sizeOfValues)
3859 {
3860     /* Names of axes */
3861     MyGTrihedron.xname = xname;
3862     MyGTrihedron.yname = yname;
3863     MyGTrihedron.zname = zname;
3864     /* Draw names */
3865     MyGTrihedron.xdrawname = xdrawname;
3866     MyGTrihedron.ydrawname = ydrawname;
3867     MyGTrihedron.zdrawname = zdrawname;
3868     /* Draw values */
3869     MyGTrihedron.xdrawvalues = xdrawvalues;
3870     MyGTrihedron.ydrawvalues = ydrawvalues;
3871     MyGTrihedron.zdrawvalues = zdrawvalues;
3872     /* Draw grid */
3873     MyGTrihedron.drawgrid = drawgrid;
3874     /* Draw axes */
3875     MyGTrihedron.drawaxes = drawaxes;
3876     /* Number of splits along axes */
3877     MyGTrihedron.nbx = nbx;
3878     MyGTrihedron.nby = nby;
3879     MyGTrihedron.nbz = nbz;
3880     /* Offset for drawing values */
3881     MyGTrihedron.xoffset = xoffset;
3882     MyGTrihedron.yoffset = yoffset;
3883     MyGTrihedron.zoffset = zoffset;
3884     /* Offset for drawing names of axes */
3885     MyGTrihedron.xaxisoffset = xaxisoffset;
3886     MyGTrihedron.yaxisoffset = yaxisoffset;
3887     MyGTrihedron.zaxisoffset = zaxisoffset;
3888     /* Draw tickmarks */
3889     MyGTrihedron.xdrawtickmarks = xdrawtickmarks;
3890     MyGTrihedron.ydrawtickmarks = ydrawtickmarks;
3891     MyGTrihedron.zdrawtickmarks = zdrawtickmarks;
3892     /* Length of tickmarks */
3893     MyGTrihedron.xtickmarklength = xtickmarklength;
3894     MyGTrihedron.ytickmarklength = ytickmarklength;
3895     MyGTrihedron.ztickmarklength = ztickmarklength;
3896     /* Grid color */
3897     MyGTrihedron.gridcolor = gridcolor;
3898     /* Colors of axis names */
3899     MyGTrihedron.xnamecolor = xnamecolor;
3900     MyGTrihedron.ynamecolor = ynamecolor;
3901     MyGTrihedron.znamecolor = znamecolor;
3902     /* Colors of axis and values */
3903     MyGTrihedron.xcolor = xcolor;
3904     MyGTrihedron.ycolor = ycolor;
3905     MyGTrihedron.zcolor = zcolor;
3906     /* Name of font for names of axes */
3907     MyGTrihedron.fontOfNames = fontOfNames;
3908     /* Style of names of axes */
3909     MyGTrihedron.styleOfNames = styleOfNames;
3910     /* Size of names of axes */
3911     MyGTrihedron.sizeOfNames = sizeOfNames;
3912     /* Name of font for values */
3913     MyGTrihedron.fontOfValues = fontOfValues;
3914     /* Style of values */
3915     MyGTrihedron.styleOfValues = styleOfValues;
3916     /* Size of values */
3917     MyGTrihedron.sizeOfValues = sizeOfValues;
3918
3919     MyGTrihedron.ptrVisual3dView = this;
3920     MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
3921     MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron);
3922 }
3923
3924 void Visual3d_View::GraduatedTrihedronErase()
3925 {
3926     MyGTrihedron.ptrVisual3dView = NULL;
3927     MyGraphicDriver->GraduatedTrihedronErase(MyCView);
3928 }
3929
3930 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer () const {
3931
3932         return (MyViewManager->UnderLayer ());
3933
3934 }
3935
3936 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer () const {
3937
3938         return (MyViewManager->OverLayer ());
3939
3940 }
3941
3942 Standard_Integer Visual3d_View::LightLimit() const {
3943
3944         Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit ();
3945 //      printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight);
3946         return maxlight;
3947 }
3948
3949 Standard_Integer Visual3d_View::PlaneLimit() const {
3950
3951         Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit ();
3952 //      printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane);
3953         return maxplane;
3954 }
3955
3956 #ifdef IMP140100
3957 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const {
3958
3959         return MyPtrViewManager;
3960 }
3961 #endif
3962
3963 #ifdef G003
3964 void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode ) {
3965
3966  if (  (  (aMode &&  ComputedModeIsActive) ||
3967          (!aMode && !ComputedModeIsActive)
3968        ) || DegenerateModeIsOn ()
3969  ) return;
3970
3971  Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure );
3972  Visual3d_TypeOfAnswer                 Answer;
3973  Standard_Integer                      StructId;
3974  Standard_Integer                      i = MyDisplayedStructure.Extent ();
3975
3976  if (  !( ComputedModeIsActive = aMode )  ) {
3977
3978   while (  S1Iterator.More ()  ) {
3979
3980    Answer = AcceptDisplay (  S1Iterator.Key ()  );
3981
3982    if ( Answer == Visual3d_TOA_COMPUTE ) {
3983
3984     Standard_Integer Index = IsComputed (  S1Iterator.Key ()  );
3985
3986     if ( Index != 0 ) {
3987
3988      StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3989
3990      MyGraphicDriver -> EraseStructure (
3991                          MyCView,
3992                          *( Graphic3d_CStructure* )
3993                           MyCOMPUTEDSequence.Value ( Index ) -> CStructure ()
3994                         );
3995      MyGraphicDriver -> DisplayStructure (
3996                          MyCView,
3997                                          *( Graphic3d_CStructure* )
3998                           S1Iterator.Key () -> CStructure (),
3999                          int (  S1Iterator.Key () -> DisplayPriority ()  )
4000                                     );
4001     }  // end if ( Index != 0 ) . . .
4002
4003    }  // end if ( Answer . . . )
4004
4005    S1Iterator.Next ();
4006
4007   }  // end while
4008
4009  } else {
4010
4011   while (  S1Iterator.More ()  ) {
4012
4013    Answer = AcceptDisplay (  S1Iterator.Key ()  );
4014
4015    if ( Answer == Visual3d_TOA_COMPUTE ) {
4016
4017     Standard_Integer Index = IsComputed (  S1Iterator.Key ()  );
4018
4019     if ( Index != 0 ) {
4020
4021      StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
4022
4023      MyGraphicDriver -> EraseStructure (
4024                          MyCView,
4025                          *( Graphic3d_CStructure* )
4026                           S1Iterator.Key () -> CStructure ()
4027                         );
4028      MyGraphicDriver -> DisplayStructure (
4029                          MyCView,
4030                                          *( Graphic3d_CStructure* )
4031                           MyCOMPUTEDSequence.Value ( Index ) -> CStructure (),
4032                                          int (  S1Iterator.Key () -> DisplayPriority ()  )
4033                         );
4034
4035      Display (  S1Iterator.Key (), Aspect_TOU_WAIT  );
4036
4037      if (  S1Iterator.Key () -> IsHighlighted ()  ) {
4038
4039       if (  !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted ()  ) {
4040
4041        MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor (
4042                                               S1Iterator.Key () ->
4043                                                HighlightColor ()
4044                                              );
4045        MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight (
4046                                               Aspect_TOHM_COLOR
4047                                              );
4048       }  // end if
4049
4050      }  // end if
4051
4052     } else {
4053
4054      Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key ();
4055 #ifdef OLD
4056      Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this );
4057 #else
4058      Handle( Graphic3d_Structure ) TheStructure;
4059      TColStd_Array2OfReal          ATrsf ( 0, 3, 0, 3 );
4060
4061      AStructure -> Transform ( ATrsf );
4062
4063      if ( Index != 0 ) {
4064
4065       TColStd_Array2OfReal Ident ( 0, 3, 0, 3 );
4066       Standard_Integer     ii, jj;
4067
4068       for ( ii = 0; ii <= 3; ++ii )
4069
4070        for ( jj = 0; jj <= 3; ++jj  )
4071
4072         Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 );
4073
4074       TheStructure = MyCOMPUTEDSequence.Value ( Index );
4075
4076       TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE );
4077
4078       if (  AStructure->IsTransformed ()  )
4079
4080        AStructure -> Compute ( this, ATrsf, TheStructure );
4081
4082       else
4083
4084        AStructure -> Compute ( this, TheStructure );
4085
4086      } else {
4087
4088       if ( AStructure -> IsTransformed ()  )
4089
4090        TheStructure = AStructure -> Compute ( this, ATrsf );
4091
4092       else
4093
4094        TheStructure = AStructure -> Compute ( this );
4095
4096      }  // end else
4097 #endif  // OLD
4098      TheStructure -> SetHLRValidation ( Standard_True );
4099
4100      Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
4101
4102      Standard_Boolean ComputeWireframe =
4103       (  ( ViewType == Visual3d_TOV_WIREFRAME ) &&
4104              (  S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING  )
4105       );
4106
4107      Standard_Boolean ComputeShading =
4108       (  ( ViewType == Visual3d_TOV_SHADING ) &&
4109              (  S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME  )
4110       );
4111
4112      if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME );
4113      if ( ComputeShading   ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING   );
4114
4115      if (  S1Iterator.Key () -> IsHighlighted ()  ) {
4116
4117       TheStructure -> SetHighlightColor (
4118                        S1Iterator.Key () -> HighlightColor ()
4119                       );
4120       TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR );
4121
4122      }  // end if
4123
4124      Standard_Integer Result = 0;
4125      Standard_Integer Length = MyTOCOMPUTESequence.Length ();
4126      StructId = S1Iterator.Key () -> Identification ();
4127
4128      for ( i = 1; i <= Length && Result == 0; ++i )
4129
4130       if (  MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId  )
4131
4132        Result = i;
4133
4134      if ( Result )
4135
4136       MyCOMPUTEDSequence.ChangeValue ( Result ) = TheStructure;
4137
4138      else {
4139
4140       MyTOCOMPUTESequence.Append (  S1Iterator.Key ()  );
4141       MyCOMPUTEDSequence.Append  ( TheStructure );
4142
4143      }  // end else
4144
4145      MyGraphicDriver -> EraseStructure (
4146                          MyCView,
4147                          *( Graphic3d_CStructure* )
4148                           S1Iterator.Key () -> CStructure ()
4149                         );
4150      MyGraphicDriver -> DisplayStructure (
4151                          MyCView,
4152                          *( Graphic3d_CStructure* )TheStructure -> CStructure (),
4153                          int (  S1Iterator.Key () -> DisplayPriority ()  )
4154                         );
4155     }  // end else
4156
4157    }  // end if
4158
4159    S1Iterator.Next ();
4160
4161   }  // end while
4162
4163   if (  MyViewManager -> UpdateMode () == Aspect_TOU_ASAP  ) Update ();
4164
4165  }  // end else
4166
4167 }  // end Visual3d_View :: SetComputedMode
4168
4169 Standard_Boolean Visual3d_View :: ComputedMode () const {
4170
4171  return ComputedModeIsActive;
4172
4173 }  // end Visual3d_View :: ComputedMode
4174
4175 void Visual3d_View :: SetBackFacingModel (
4176                        const Visual3d_TypeOfBackfacingModel aModel
4177                       ) {
4178  switch ( aModel ) {
4179
4180   default:
4181   case Visual3d_TOBM_AUTOMATIC:
4182    MyCView.Backfacing = 0;
4183    break;
4184
4185   case Visual3d_TOBM_FORCE:
4186    MyCView.Backfacing = 1;
4187    break;
4188
4189   case Visual3d_TOBM_DISABLE:
4190    MyCView.Backfacing = -1;
4191    break;
4192
4193  }  // end switch
4194
4195  MyGraphicDriver -> SetBackFacingModel ( MyCView );
4196
4197 }  // end Visual3d_View :: SetBackFacingModel
4198
4199 Visual3d_TypeOfBackfacingModel Visual3d_View :: BackFacingModel () const {
4200
4201  switch ( MyCView.Backfacing ) {
4202
4203   case 0:
4204    return Visual3d_TOBM_AUTOMATIC;
4205
4206   case 1:
4207    return Visual3d_TOBM_FORCE;
4208
4209  }  // end switch
4210
4211  return Visual3d_TOBM_DISABLE;
4212
4213 }  // end Visual3d_View :: BackFacingModel
4214 #endif  // G003
4215
4216 void Visual3d_View::EnableDepthTest( const Standard_Boolean enable ) const
4217 {
4218 #ifdef BUC61044
4219   MyGraphicDriver->SetDepthTestEnabled( MyCView, enable );
4220 #endif
4221 }
4222
4223 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
4224 {
4225 #ifdef BUC61044
4226   return MyGraphicDriver->IsDepthTestEnabled( MyCView );
4227 #else
4228   return Standard_True;
4229 #endif
4230 }
4231
4232 void Visual3d_View::ReadDepths(const Standard_Integer x,
4233                                const Standard_Integer y,
4234                                const Standard_Integer width,
4235                                const Standard_Integer height,
4236                                const Standard_Address buffer) const
4237 {
4238   MyGraphicDriver->ReadDepths( MyCView, x, y, width, height, buffer );
4239 }
4240
4241 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
4242                                                   const Standard_Integer theHeight)
4243 {
4244   return MyGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
4245 }
4246
4247 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
4248 {
4249   MyGraphicDriver->FBORelease( MyCView, theFBOPtr );
4250 }
4251
4252 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
4253                                      Standard_Integer& theWidth,    Standard_Integer& theHeight,
4254                                      Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
4255 {
4256   MyGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
4257                                      theWidth, theHeight,
4258                                      theWidthMax, theHeightMax );
4259 }
4260
4261 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
4262                                       const Standard_Integer theWidth, const Standard_Integer theHeight)
4263 {
4264   MyGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
4265                                      theWidth, theHeight );
4266 }
4267
4268 Standard_Boolean Visual3d_View::BufferDump (Image_CRawBufferData& theBuffer)
4269 {
4270   return MyGraphicDriver->BufferDump( MyCView, theBuffer);
4271 }
4272
4273 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
4274 {
4275 #ifdef BUC61045
4276   MyGraphicDriver->SetGLLightEnabled( MyCView, enable );
4277 #endif
4278 }
4279
4280
4281 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
4282 {
4283 #ifdef BUC61045
4284   return MyGraphicDriver->IsGLLightEnabled( MyCView );
4285 #else
4286   return Standard_True;
4287 #endif
4288 }
4289
4290 Standard_Boolean Visual3d_View::Export (const Standard_CString       theFileName,
4291                                         const Graphic3d_ExportFormat theFormat,
4292                                         const Graphic3d_SortType     theSortType,
4293                                         const Standard_Real          thePrecision,
4294                                         const Standard_Address       theProgressBarFunc,
4295                                         const Standard_Address       theProgressObject) const
4296 {
4297   Handle(Visual3d_Layer) anUnderLayer = MyViewManager->UnderLayer();
4298   Handle(Visual3d_Layer) anOverLayer  = MyViewManager->OverLayer();
4299
4300   Aspect_CLayer2d anOverCLayer;
4301   Aspect_CLayer2d anUnderCLayer;
4302   anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
4303
4304   if (!anOverLayer.IsNull())
4305     anOverCLayer = anOverLayer->CLayer();
4306   if (!anUnderLayer.IsNull())
4307     anUnderCLayer = anUnderLayer->CLayer();
4308
4309   Standard_Integer aWidth, aHeight;
4310   Window()->Size (aWidth, aHeight);
4311
4312   return MyGraphicDriver->Export (theFileName, theFormat, theSortType,
4313                                   aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
4314                                   thePrecision, theProgressBarFunc, theProgressObject);
4315 }