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