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