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