0022751: Issues around Prs3d_TextAspect::Print()
[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
7fd59977 2967
2968Standard_Boolean Visual3d_View::ZBufferIsActivated () const {
2969
2970 if (IsDeleted ()) return (Standard_False);
2971
2972 if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);
2973
81bba717 2974// -1 => not forced by the programmer => depends on the type of visualisation
2975// 0 ou 1 => forced by the programmer
7fd59977 2976
2977 if (MyCView.Context.ZBufferActivity == -1)
2978 if (MyContext.Visualization () == Visual3d_TOV_SHADING)
2979 return (Standard_True);
2980 else
2981 return (Standard_False);
2982 else
2983 if (MyCView.Context.ZBufferActivity)
2984 return (Standard_True);
2985 else
2986 return (Standard_False);
2987
2988}
2989
2990void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {
2991
2992 if (IsDeleted ()) return;
2993
2994 if ((! IsDefined ()) || (! IsActive ())) return;
2995
2996 MyGraphicDriver->Transparency (MyCView, AnActivity);
2997
2998}
2999
3000void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {
3001
3002 if (MyCView.Context.ZBufferActivity == AnActivity) return;
3003
3004 if (IsDeleted ()) return;
3005
3006 if ((! IsDefined ()) || (! IsActive ())) return;
3007
3008 MyCView.Context.ZBufferActivity = AnActivity;
3009 MyGraphicDriver->SetVisualisation (MyCView);
3010
3011}
3012
3013void Visual3d_View::UpdateView () {
3014
3015 MyCView.Context.Aliasing = (MyContext.AliasingIsOn () ? 1:0);
3016 MyCView.Context.BackZClipping =
3017 (MyContext.BackZClippingIsOn () ? 1:0);
3018 MyCView.Context.FrontZClipping =
3019 (MyContext.FrontZClippingIsOn() ? 1:0);
3020 MyCView.Context.DepthCueing =
3021 (MyContext.DepthCueingIsOn () ? 1:0);
3022
3023 MyCView.Context.ZClipFrontPlane =
3024 float (MyContext.ZClippingFrontPlane ());
3025 MyCView.Context.ZClipBackPlane =
3026 float (MyContext.ZClippingBackPlane ());
3027 MyCView.Context.DepthFrontPlane =
3028 float (MyContext.DepthCueingFrontPlane ());
3029 MyCView.Context.DepthBackPlane =
3030 float (MyContext.DepthCueingBackPlane ());
3031
3032 MyCView.Context.Model = int (MyContext.Model ());
3033 MyCView.Context.Visualization = int (MyContext.Visualization ());
3034
3035 Handle(Graphic3d_TextureEnv) TempTextureEnv = MyContext.TextureEnv();
3036 if (! TempTextureEnv.IsNull()) MyCView.Context.TexEnvId = TempTextureEnv->TextureId();
3037 else MyCView.Context.TexEnvId = -1;
3038 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
3039
3040}
3041
3042void Visual3d_View::Compute () {
3043
3044Standard_Integer i;
3045Standard_Integer Length = MyCOMPUTEDSequence.Length ();
3046 for (i=1; i<=Length; i++)
3047 (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);
3048
81bba717 3049 // if the degenerated node is active, nothing is recomputed
7fd59977 3050#ifdef G003
3051 if ( DegenerateModeIsOn () || !ComputedMode () ) return;
3052#else
3053 if (DegenerateModeIsOn ()) return;
3054#endif // G003
3055
3056 /*
81bba717 3057 * Force HLRValidation to False on all structures
3058 * calculated in the view.
7fd59977 3059 */
3060#ifdef TRACE_LENGTH
3061 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3062 cout << "In Visual3d_View::Compute, ";
3063 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3064 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3065 << "\n" << flush;
3066 }
3067#endif
3068
3069 /*
81bba717 3070 * Change of orientation or of projection type =>
3071 * Remove structures that were calculated for the
3072 * previous orientation.
3073 * Recalculation of new structures.
3074 * Passage of the degenerated mode ON to OFF =>
3075 * Remove structures that were calculated before
3076 * the degenerated mode passed to ON.
3077 * Recalculate new structures.
7fd59977 3078 */
3079Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3080Visual3d_TypeOfAnswer Answer;
3081
3082 i = MyDisplayedStructure.Extent ();
3083
3084Graphic3d_SequenceOfStructure FooSequence;
3085
3086 while (S1Iterator.More ()) {
3087 Answer = AcceptDisplay (S1Iterator.Key ());
81bba717 3088 // If the structure was calculated, it is recalculated.
7fd59977 3089 if (Answer == Visual3d_TOA_COMPUTE) {
3090#ifdef TRACE
3091 cout << "AcceptDisplay ("
3092 << (S1Iterator.Key ())->Identification ()
3093 << ") == Visual3d_TOA_COMPUTE;\n";
3094 cout << flush;
3095#endif
3096 //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
3097 FooSequence.Append (S1Iterator.Key ());
3098 }
3099
81bba717 3100 // S1Iterator.Next () is located on the next structure
7fd59977 3101 S1Iterator.Next ();
3102 }
3103
3104 Length = FooSequence.Length ();
81bba717 3105 // All stored structures are displayed
7fd59977 3106 for (i=1; i<=Length; i++)
3107 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
3108 if (Length != 0) FooSequence.Clear ();
3109
3110}
3111
3112void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
3113#ifdef G003
3114 if ( DegenerateModeIsOn () || !ComputedMode () ) return;
3115#else
3116 if (DegenerateModeIsOn()) return;
3117#endif // G003
3118
3119 if (IsDeleted ()) return;
3120
3121 if ((! IsDefined ()) || (! IsActive ())) return;
3122
3123 if (! MyWindow->IsMapped ()) return;
3124
3125 if (! AStructure->IsDisplayed ()) return;
3126
3127Visual3d_TypeOfAnswer Answer;
3128
3129 Answer = AcceptDisplay (AStructure);
3130
3131 if (Answer == Visual3d_TOA_COMPUTE) {
3132Standard_Integer Index = IsComputed (AStructure);
3133 if (Index == 0) {
3134#ifdef TRACE_COMP
81bba717 3135 cout << "Structure " << AStructure->Identification ()
3136 << " is not calculated in the view "
7fd59977 3137 << Identification () << "\n";
3138 cout << flush;
3139#endif
3140 }
3141 else {
3142 Standard_Integer OldStructId, NewStructId;
3143 OldStructId =
3144 MyCOMPUTEDSequence.Value (Index)->Identification ();
3145#ifdef TRACE_COMP
3146 Standard_Integer StructId = AStructure->Identification ();
81bba717 3147 cout << "Structure " << StructId
3148 << " calculated, in the view "
3149 << Identification () << ", by the structure "
3150 << OldStructId << " is recalculated.\n";
7fd59977 3151 cout << flush;
3152#endif
3153
3154 // Compute + Validation
3155#ifdef OLD
3156Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3157#else
3158Handle(Graphic3d_Structure) TheStructure;
3159TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3160 AStructure->Transform (ATrsf);
3161 if (Index != 0) {
3162TColStd_Array2OfReal Ident (0, 3, 0, 3);
3163Standard_Integer ii, jj;
3164 for (ii=0; ii<=3; ii++)
3165 for (jj=0; jj<=3; jj++)
3166 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3167 TheStructure = MyCOMPUTEDSequence.Value (Index);
3168 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3169 if (AStructure->IsTransformed ()) {
3170 AStructure->Compute (this, ATrsf, TheStructure);
3171 }
3172 else {
3173 AStructure->Compute (this, TheStructure);
3174 }
3175 }
3176 else {
3177 if (AStructure->IsTransformed ()) {
3178 TheStructure = AStructure->Compute (this, ATrsf);
3179 }
3180 else {
3181 TheStructure = AStructure->Compute (this);
3182 }
3183 }
3184#endif
3185 TheStructure->SetHLRValidation (Standard_True);
3186
81bba717 3187// Return type of visualisation of the view
7fd59977 3188Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3189
81bba717 3190// Of which type will be the computed ?
7fd59977 3191Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3192 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
3193
3194Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3195 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3196
3197 if (ComputeWireframe)
3198 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3199 if (ComputeShading)
3200 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3201
3202 if (AStructure->IsHighlighted ()) {
3203 TheStructure->SetHighlightColor
3204 (AStructure->HighlightColor ());
3205 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3206 }
3207
81bba717 3208 // Ot is ranged
3209 // Find structure <AStructure>
3210 // in the sequence of structures to be calculated.
7fd59977 3211 NewStructId = TheStructure->Identification ();
3212
81bba717 3213 // The previous calculation is removed and the new one is dislayed
7fd59977 3214 MyGraphicDriver->EraseStructure (
3215 MyCView,
3216 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3217 MyGraphicDriver->DisplayStructure (
3218 MyCView,
3219 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3220 int (AStructure->DisplayPriority ())
3221 );
3222
3223#ifdef TRACE_LENGTH
3224 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3225 cout << "In Visual3d_View::ReCompute, ";
3226 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3227 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3228 << "\n" << flush;
3229 }
3230#endif
3231
81bba717 3232 // hlhsr and the new associated compute are added
7fd59977 3233 MyTOCOMPUTESequence.Append (AStructure);
3234 MyCOMPUTEDSequence.Append (TheStructure);
3235
3236#ifdef TRACE_LENGTH
3237 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3238 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3239 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3240 << "\n" << flush;
3241#endif
3242
81bba717 3243 // hlhsr and the new associated compute are removed
7fd59977 3244
3245 MyTOCOMPUTESequence.Remove (Index);
3246 MyCOMPUTEDSequence.Remove (Index);
3247
3248#ifdef TRACE_LENGTH
3249 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3250 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3251 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3252 << "\n" << flush;
3253#endif
3254 }
3255 }
3256
3257}
3258
3259void
3260#ifdef G003
3261Visual3d_View::SetAnimationModeOn ( const Standard_Boolean degenerate ) {
3262#else
3263Visual3d_View::SetAnimationModeOn () {
3264#endif
3265
3266 if (AnimationModeIsOn ()) return;
3267
3268 AnimationModeIsActive = Standard_True;
3269#ifdef G003
3270 if ( degenerate )
3271 SetDegenerateModeOn ();
3272 else
3273 SetDegenerateModeOff ();
3274#endif // G003
3275 MyGraphicDriver->BeginAnimation (MyCView);
3276
3277}
3278
3279void Visual3d_View::SetAnimationModeOff () {
3280
3281 if (! AnimationModeIsOn ()) return;
3282
3283 AnimationModeIsActive = Standard_False;
3284#ifdef G003
3285 SetDegenerateModeOff ();
3286#endif // G003
3287 MyGraphicDriver->EndAnimation (MyCView);
3288
3289}
3290
3291Standard_Boolean Visual3d_View::AnimationModeIsOn () const {
3292
3293 return AnimationModeIsActive;
3294
3295}
3296
3297void Visual3d_View::SetDegenerateModeOn () {
3298
3299#ifdef TRACE
3300 cout << "Visual3d_View" << MyCView.ViewId
3301 << "::SetDegenerateModeOn ();\n";
3302 cout << flush;
3303#endif
3304
81bba717 3305 // If the degenerated mode is already active, nothing is recalculated
7fd59977 3306 if (DegenerateModeIsOn ()) return;
3307 DegenerateModeIsActive = Standard_True;
3308
3309#ifdef G003
3310 MyCView.IsDegenerates = 1;
3311#else
3312 /*
81bba717 3313 * Change of activity of the degenerated mode
3314 * Remove structures that were calculated
3315 * and displayed when the mode was off.
3316 * Display of non-calculated structures.
7fd59977 3317 */
3318Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3319Visual3d_TypeOfAnswer Answer;
3320Standard_Integer StructId;
3321
3322 while (S1Iterator.More ()) {
3323
3324 Answer = AcceptDisplay (S1Iterator.Key ());
81bba717 3325 // If the structure was calculated, the previous one is
3326 // removed and the new one is displayed
3327 // (This is the role of passage into degenerated mode)
7fd59977 3328
3329 if (Answer == Visual3d_TOA_COMPUTE) {
3330Standard_Integer Index = IsComputed (S1Iterator.Key ());
3331 if (Index != 0) {
3332 StructId =
3333 MyCOMPUTEDSequence.Value (Index)->Identification ();
3334#ifdef TRACE_COMP
81bba717 3335 cout << "Structure " << S1Iterator.Key ()->Identification ()
3336 << " calculated, in the view "
3337 << Identification () << ", by structure "
3338 << StructId << " passes in degenerated mode.\n";
3339 cout << "Remove" << StructId << " then display "
7fd59977 3340 << S1Iterator.Key ()->Identification () << "\n";
3341 cout << flush;
3342#endif
3343 MyGraphicDriver->EraseStructure
3344 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3345 MyGraphicDriver->DisplayStructure (
3346 MyCView,
3347 *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure (),
3348 int (S1Iterator.Key ()->DisplayPriority ())
3349 );
3350 }
3351 else {
81bba717 3352 // Else is impossible)
3353 // If the mode was not degenerated previously, the
3354 // calculated structure associated to S1Iterator.Key ()
3355 // really exists and Index != 0
7fd59977 3356 }
3357 }
3358
81bba717 3359 // S1Iterator.Next () is located on the next structure
7fd59977 3360 S1Iterator.Next ();
3361 }
3362#endif //G003
3363}
3364
3365void Visual3d_View::SetDegenerateModeOff () {
3366
3367#ifdef TRACE
3368 cout << "Visual3d_View" << MyCView.ViewId
3369 << "::SetDegenerateModeOff ();\n";
3370 cout << flush;
3371#endif
3372
81bba717 3373 // If the degenerated mode is already inactive, nothing is recalculated
7fd59977 3374 if (! DegenerateModeIsOn ()) return;
3375
3376 DegenerateModeIsActive = Standard_False;
3377
3378#ifdef G003
3379 MyCView.IsDegenerates = 0;
3380#else
3381 /*
81bba717 3382 * Change of activity of degenerated mode
3383 * Remove structures that were displayed
3384 * when the mode was on.
3385 * Calculation of structures.
7fd59977 3386 */
3387Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3388Visual3d_TypeOfAnswer Answer;
3389Standard_Integer StructId;
3390
3391 Standard_Integer i = MyDisplayedStructure.Extent ();
3392
3393 while (S1Iterator.More ()) {
3394
3395 Answer = AcceptDisplay (S1Iterator.Key ());
81bba717 3396 // If the structure was calculated, the previous one is
3397 // removed and the new one is displayed
3398 // (This is the role of passage into degenerated mode)
3399
7fd59977 3400 if (Answer == Visual3d_TOA_COMPUTE) {
3401Standard_Integer Index = IsComputed (S1Iterator.Key ());
3402 if (Index != 0) {
3403 StructId =
3404 MyCOMPUTEDSequence.Value (Index)->Identification ();
3405#ifdef TRACE_COMP
81bba717 3406 cout << "Structure " << S1Iterator.Key ()->Identification ()
3407 << " calculated, in the view "
3408 << Identification () << ", by the structure "
3409 << StructId << " passes into normal mode.\n";
3410 cout << "Remove " << S1Iterator.Key ()->Identification ()
3411 << " then display " << StructId << "\n";
7fd59977 3412 cout << flush;
3413#endif
3414 MyGraphicDriver->EraseStructure
3415 (MyCView,
3416 *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure ());
3417 MyGraphicDriver->DisplayStructure (
3418 MyCView,
3419 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
3420 int (S1Iterator.Key ()->DisplayPriority ())
3421 );
3422
3423 Display (S1Iterator.Key (), Aspect_TOU_WAIT);
3424
3425 if ((S1Iterator.Key ())->IsHighlighted()) {
3426 if (! (MyCOMPUTEDSequence.Value (Index))->IsHighlighted()) {
3427 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
3428 ((S1Iterator.Key ())->HighlightColor ());
3429 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (Aspect_TOHM_COLOR);
3430 }
3431 }
3432 }
3433 else {
81bba717 3434 // Else is impossible
3435 // Degenerated mode was activated before display of the
3436 // structure. So the structure was displayed in the
3437 // degenerated mode, but the calculated structure didn't exist.
3438 // It is calculated.
7fd59977 3439
3440 // Compute + Validation
3441Handle(Graphic3d_Structure) AStructure = (S1Iterator.Key ());
3442#ifdef OLD
3443Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3444#else
3445Handle(Graphic3d_Structure) TheStructure;
3446TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3447 AStructure->Transform (ATrsf);
3448 if (Index != 0) {
3449TColStd_Array2OfReal Ident (0, 3, 0, 3);
3450Standard_Integer ii, jj;
3451 for (ii=0; ii<=3; ii++)
3452 for (jj=0; jj<=3; jj++)
3453 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3454 TheStructure = MyCOMPUTEDSequence.Value (Index);
3455 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3456 if (AStructure->IsTransformed ()) {
3457 AStructure->Compute (this, ATrsf, TheStructure);
3458 }
3459 else {
3460 AStructure->Compute (this, TheStructure);
3461 }
3462 }
3463 else {
3464 if (AStructure->IsTransformed ()) {
3465 TheStructure = AStructure->Compute (this, ATrsf);
3466 }
3467 else {
3468 TheStructure = AStructure->Compute (this);
3469 }
3470 }
3471#endif
3472 TheStructure->SetHLRValidation (Standard_True);
3473
81bba717 3474// Return type of visualisation of the view
7fd59977 3475Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3476
81bba717 3477// Of which type will be the computed ?
7fd59977 3478Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3479 ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_SHADING));
3480
3481Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3482 ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3483
3484 if (ComputeWireframe)
3485 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3486 if (ComputeShading)
3487 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3488
3489 if ((S1Iterator.Key ())->IsHighlighted()) {
3490 TheStructure->SetHighlightColor
3491 ((S1Iterator.Key ())->HighlightColor ());
3492 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3493 }
3494
81bba717 3495 // Make range
7fd59977 3496Standard_Integer Result = 0;
3497Standard_Integer Length = MyTOCOMPUTESequence.Length ();
81bba717 3498 // Find structure <S1Iterator.Key ()>
3499 // in the sequence of structures to be calculated
7fd59977 3500 StructId = (S1Iterator.Key ())->Identification ();
3501 for (i=1; i<=Length && Result==0; i++)
3502 if ((MyTOCOMPUTESequence.Value (i))->Identification () ==
3503 StructId) Result = i;
3504 if (Result != 0)
3505 MyCOMPUTEDSequence.ChangeValue (Result) = TheStructure;
3506 else {
81bba717 3507 // hlhsr and the associated new compute are added
7fd59977 3508#ifdef TRACE_LENGTH
3509 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3510 cout << "In Visual3d_View::SetDegenerateModeOff, ";
3511 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3512 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3513 << "\n" << flush;
3514 }
3515#endif
3516 MyTOCOMPUTESequence.Append (S1Iterator.Key ());
3517 MyCOMPUTEDSequence.Append (TheStructure);
3518#ifdef TRACE_LENGTH
3519 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3520 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3521 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3522 << "\n" << flush;
3523#endif
3524 }
3525
81bba717 3526 // The degenerated is removed and the calculated is displayed
7fd59977 3527 MyGraphicDriver->EraseStructure
3528 (MyCView,
3529 *(Graphic3d_CStructure *)(S1Iterator.Key ()->CStructure ()));
3530 MyGraphicDriver->DisplayStructure (
3531 MyCView,
3532 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3533 int (S1Iterator.Key ()->DisplayPriority ())
3534 );
3535 }
3536 }
3537
81bba717 3538 // S1Iterator.Next () is located on the next structure
7fd59977 3539 S1Iterator.Next ();
3540 }
3541
3542 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
3543#endif //G003
3544}
3545
3546Standard_Boolean Visual3d_View::DegenerateModeIsOn () const {
3547
3548 return DegenerateModeIsActive;
3549
3550}
3551
3552Handle(Aspect_GraphicDriver) Visual3d_View::GraphicDriver () const {
3553
3554 return MyGraphicDriver;
3555
3556}
3557
3558void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& APlotter) const {
3559
3560Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3561
3562 while (S1Iterator.More ()) {
3563
3564 if (DegenerateModeIsOn ())
81bba717 3565 // As the mode is degenerated the displayed structure
3566 // is plotted without taking into account if it is calculated or not
7fd59977 3567 (S1Iterator.Key ())->Plot (APlotter);
3568 else {
3569Standard_Integer Index = IsComputed (S1Iterator.Key ());
81bba717 3570 // As the mode is not degenerated the displayed structure
3571 // is plotted as if it was not calculated, otherwise the
3572 // associated calculated structure is plotted.
7fd59977 3573 if (Index == 0)
3574 (S1Iterator.Key ())->Plot (APlotter);