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