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