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