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