1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
19 /***********************************************************************
23 Classe Visual3d_View.cxx :
26 Declaration of variables specific to views.
28 A view is defined by :
34 HISTORIQUE DES MODIFICATIONS :
35 --------------------------------
36 Mars 1992 : NW,JPB,CAL ; Creation.
37 04-02-97 : FMN ; Suppression de PSOutput, XWDOutput ...
38 22-04-97 : CAL ; Ajout du Plot.
39 03-06-97 : FMN ; Correction calcul SetRatio
40 06-05-97 : CAL ; Ajout du Clear sur les TOS_COMPUTED.
41 28-07-97 : PCT ; Ajout lumiere frontale headlight.
42 19-09-97 : CAL ; Remplacement de Window->Position par Window->Size;
43 17-10-97 : CAL ; Le Projects nouveau est arrive. (NewProjects)
44 24-10-97 : CAL ; Retrait de DownCast.
45 24-10-97 : CAL ; Retrait des DataStructure (Vieille maquette inutilisee).
46 17-11-97 : FMN ; Ajout DoResize dans Resized()
47 20-11-97 : CAL ; Disparition de la dependance avec math
48 ??-11-97 : CAL ; Retrait de la dependance avec math. Calcul developpe.
49 ??-11-97 : CAL ; Ajout de NumberOfDisplayedStructures
50 07-08-97 : PCT ; ajout support texture mapping
51 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
77 ************************************************************************/
79 #define BUC60572 //GG_03-08-99 Add protection on Zclipping & Zcueing planes
82 #define BUC60570 //GG 14-09-99 Don't activates lighting
83 // when the view shading model is NONE.
85 #define GER61454 //GG 14-09-99 Activates model clipping planes
87 #define RIC120302 //GG Add a NEW SetWindow method which enable
88 // to connect a graphic widget and context to OGL.
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
93 //OCC1188 SAV Added methods to set background image
95 /*----------------------------------------------------------------------*/
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
114 /*----------------------------------------------------------------------*/
124 #include <Visual3d_View.ixx>
125 #include <Visual3d_View.pxx>
126 #include <Visual3d_DepthCueingDefinitionError.hxx>
127 #include <Visual3d_ZClippingDefinitionError.hxx>
130 #include <math_Vector.hxx>
131 #endif /* OLD_METHOD */
135 #include <Graphic3d_Structure.hxx>
136 #include <Graphic3d_MapOfStructure.hxx>
137 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
138 #include <Graphic3d_DataStructureManager.hxx>
140 #include <Graphic3d_GraphicDriver.hxx>
142 #include <Graphic3d_Vector.hxx>
143 #include <Graphic3d_Vertex.hxx>
145 #include <Visual3d_Light.hxx>
146 #include <Visual3d_SetOfLight.hxx>
147 #include <Visual3d_HSetOfLight.hxx>
148 #include <Visual3d_SetIteratorOfSetOfLight.hxx>
150 #include <Visual3d_SetIteratorOfSetOfView.hxx>
152 #include <Graphic3d_TextureEnv.hxx>
154 #include <TColStd_HArray2OfReal.hxx>
156 #if (defined(_WIN32) || defined(__WIN32__))
157 #include <WNT_Window.hxx>
158 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
159 #include <Cocoa_Window.hxx>
161 #include <Xw_Window.hxx>
168 //-Global data definitions
172 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager):
175 MyViewMappingReset (),
176 MyViewOrientation (),
177 MyViewOrientationReset (),
178 MyTransformation (0, 3, 0, 3),
179 MyMatrixOfMapping (0, 3, 0, 3),
180 MyMatrixOfOrientation (0, 3, 0, 3),
181 MyTOCOMPUTESequence (),
182 MyCOMPUTEDSequence (),
183 MyDisplayedStructure ()
185 Standard_Integer i, j;
187 MyPtrViewManager = AManager.operator->();
188 MyCView.ViewId = int (AManager->Identification (this));
190 MyCView.IsDeleted = 0;
193 MyCView.DefWindow.IsDefined = 0;
195 MyCView.Context.NbActiveLight = 0;
199 if (i == j) MyTransformation (i, j) = 1.0;
200 else MyTransformation (i, j) = 0.0;
202 Standard_Real X, Y, Z;
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);
217 Standard_Real Sx, Sy, Sz;
219 MyViewOrientation.AxialScale(Sx, Sy, Sz);
220 MyCView.Orientation.ViewScaleX = float (Sx);
221 MyCView.Orientation.ViewScaleY = float (Sy);
222 MyCView.Orientation.ViewScaleZ = float (Sz);
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.;
233 Standard_Real um, vm, uM, vM;
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);
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.;
261 MyCView.Context.ZBufferActivity = -1;
263 MyMatOfMapIsEvaluated = Standard_False;
264 MyMatOfOriIsEvaluated = Standard_False;
266 IsInitialized = Standard_False;
267 ComputedModeIsActive = Standard_False;
268 MyCView.Backfacing = 0;
270 MyCView.ptrUnderLayer = 0;
271 MyCView.ptrOverLayer = 0;
272 MyCView.GContext = 0;
273 MyCView.GDisplayCB = 0;
274 MyCView.GClientData = 0;
276 MyGraphicDriver = MyViewManager->GraphicDriver();
280 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager, const Visual3d_ViewOrientation& VO, const Visual3d_ViewMapping& VM, const Visual3d_ContextView& CTX):
281 MyTransformation (0, 3, 0, 3),
282 MyMatrixOfMapping (0, 3, 0, 3),
283 MyMatrixOfOrientation (0, 3, 0, 3),
284 MyTOCOMPUTESequence (),
285 MyCOMPUTEDSequence (),
286 MyDisplayedStructure ()
288 Standard_Integer i, j;
290 MyPtrViewManager = AManager.operator->();
291 MyViewOrientation = VO;
294 MyViewOrientationReset = VO;
295 MyViewMappingReset = VM;
297 MyCView.ViewId = int (AManager->Identification (this));
299 MyCView.IsDeleted = 0;
302 MyCView.DefWindow.IsDefined = 0;
304 MyCView.Context.NbActiveLight = 0;
308 if (i == j) MyTransformation (i, j) = 1.0;
309 else MyTransformation (i, j) = 0.0;
311 Standard_Real X, Y, Z;
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);
326 Standard_Real Sx, Sy, Sz;
328 MyViewOrientation.AxialScale(Sx, Sy, Sz);
329 MyCView.Orientation.ViewScaleX = float (Sx);
330 MyCView.Orientation.ViewScaleY = float (Sy);
331 MyCView.Orientation.ViewScaleZ = float (Sz);
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++)
338 MyCView.Orientation.ModelViewMatrix[i][j] =
339 (Standard_ShortReal)MyViewOrientation.MyModelViewMatrix->Value(i,j);
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.;
351 Standard_Real um, vm, uM, vM;
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);
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++)
375 MyCView.Mapping.ProjectionMatrix[i][j] =
376 (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j);
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.;
388 MyCView.Context.ZBufferActivity = -1;
390 MyMatOfMapIsEvaluated = Standard_False;
391 MyMatOfOriIsEvaluated = Standard_False;
393 IsInitialized = Standard_False;
394 ComputedModeIsActive = Standard_False;
396 MyCView.ptrUnderLayer = 0;
397 MyCView.ptrOverLayer = 0;
398 MyCView.GContext = 0;
399 MyCView.GDisplayCB = 0;
400 MyCView.GClientData = 0;
402 MyGraphicDriver = MyViewManager->GraphicDriver();
410 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow,
411 const Aspect_RenderingContext AContext,
412 const Aspect_GraphicCallbackProc& ADisplayCB,
413 const Standard_Address AClientData)
415 if (IsDeleted ()) return;
418 Visual3d_ViewDefinitionError::Raise ("Window already defined");
420 MyCView.GContext = AContext;
421 MyCView.GDisplayCB = ADisplayCB;
422 MyCView.GClientData = AClientData;
427 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
430 if (IsDeleted ()) return;
433 Visual3d_ViewDefinitionError::Raise ("Window already defined");
435 MyWindow = theWindow;
436 MyCView.WsId = MyCView.ViewId;
437 MyCView.DefWindow.IsDefined = 1;
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();
452 const Handle(Xw_Window) aWin = Handle(Xw_Window)::DownCast (theWindow);
453 MyCView.DefWindow.XWindow = aWin->XWindow();
454 //MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
457 Standard_Integer Width, Height;
458 theWindow->Size (Width, Height);
460 MyCView.DefWindow.dx = float( Width );
461 MyCView.DefWindow.dy = float( Height );
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);
471 if (! MyGraphicDriver->View (MyCView))
472 Visual3d_ViewDefinitionError::Raise ("Association failed");
474 MyGradientBackground = MyWindow->GradientBackground();
475 SetGradientBackground(MyGradientBackground,1);
477 Standard_Boolean AWait = Standard_False; // => immediate update
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);
484 // Make view manager z layer list consistent with the view's list.
485 MyViewManager->InstallZLayers (this);
487 // Update planses of model clipping
490 // Update light sources
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).
504 Handle(Aspect_Window) Visual3d_View::Window () const {
507 Visual3d_ViewDefinitionError::Raise ("Window not defined");
513 Standard_Boolean Visual3d_View::IsDefined () const {
515 if (MyCView.DefWindow.IsDefined)
516 return (Standard_True);
518 return (Standard_False);
522 Standard_Boolean Visual3d_View::IsDeleted () const {
524 if (MyCView.IsDeleted)
525 return (Standard_True);
527 return (Standard_False);
531 void Visual3d_View::Destroy () {
534 cout << "Visual3d_View::Destroy (" << Identification () << ")\n";
537 // Since MyPtrViewManager can be already distroyed,
538 // avoid attempts to access it in SetBackground()
539 MyPtrViewManager = 0;
544 void Visual3d_View::Remove () {
547 cout << "Visual3d_View::Remove (" << Identification () << ")" << endl;
550 if (IsDeleted ()) return;
551 if (! IsDefined ()) return;
553 MyTOCOMPUTESequence.Clear ();
554 MyCOMPUTEDSequence.Clear ();
555 MyDisplayedStructure.Clear ();
557 Quantity_Color BlackColor (0.0, 0.0, 0.0, Quantity_TOC_RGB);
558 Aspect_Background BlackBackground (BlackColor);
559 SetBackground (BlackBackground);
561 Aspect_GradientBackground BlackGradBackground;
562 SetGradientBackground (BlackGradBackground,0);
564 if (MyPtrViewManager)
565 MyPtrViewManager->UnIdentification( MyCView.ViewId );
567 MyGraphicDriver->RemoveView (MyCView);
570 MyCView.IsDeleted = 1;
571 MyCView.DefWindow.IsDefined = 0;
573 MyMatOfMapIsEvaluated = Standard_False;
574 MyMatOfOriIsEvaluated = Standard_False;
576 IsInitialized = Standard_False;
582 void Visual3d_View::Resized () {
584 if (IsDeleted ()) return;
587 Visual3d_ViewDefinitionError::Raise ("Window not defined");
588 MyWindow->DoResize() ;
593 void Visual3d_View::SetRatio () {
595 if (IsDeleted ()) return;
597 Aspect_TypeOfUpdate UpdateMode = MyViewManager->UpdateMode ();
598 MyViewManager->SetUpdateMode (Aspect_TOU_WAIT);
600 Standard_Real Umin, Vmin, Umax, Vmax;
601 Standard_Integer Dxw, Dyw;
602 Standard_Real Dxv, Dyv;
603 Standard_Real Xc, Yc;
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 ;
641 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
642 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
644 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
646 // Update before SetViewMapping.
648 MyCView.DefWindow.dx = float( Dxw );
649 MyCView.DefWindow.dy = float( Dyw );
651 SetViewMapping (MyViewMapping);
652 // SetViewMappingDefault ();
653 // FMN+ Update Ratio for MyViewMappingReset
655 MyViewMappingReset.WindowLimit(Umin,Vmin,Umax,Vmax) ;
656 Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
657 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
686 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
687 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
689 MyViewMappingReset.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
691 // FMN- Update Ratio for MyViewMappingReset
693 MyGraphicDriver->RatioWindow (MyCView);
696 // Force recalculation of 2 matrices.
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.
701 MyMatOfMapIsEvaluated = Standard_False;
702 MyMatOfOriIsEvaluated = Standard_False;
704 MyViewManager->SetUpdateMode (UpdateMode);
705 if (UpdateMode == Aspect_TOU_ASAP) Update ();
709 void Visual3d_View::UpdateLights () {
711 Standard_Integer i, j;
712 CALL_DEF_LIGHT *lights=NULL;
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;
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.;
730 i = MyContext.NumberOfActivatedLights ();
731 j = MyGraphicDriver->InquireLightLimit ();
732 MyCView.Context.NbActiveLight = (i > j ? j : i);
734 if (MyCView.Context.NbActiveLight > 0) {
736 // Dynamic Allocation
737 lights = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
739 MyCView.Context.ActiveLight = lights;
741 Standard_Real X, Y, Z;
743 Standard_Real LightConcentration = 0.;
744 Standard_Real LightAttenuation1 = 0.;
745 Standard_Real LightAttenuation2 = 0.;
746 Standard_Real LightAngle = 0.;
747 Quantity_Color LightColor;
748 Graphic3d_Vertex LightPosition;
749 Graphic3d_Vector LightDirection;
750 Visual3d_TypeOfLightSource LightType=Visual3d_TOLS_AMBIENT;
752 // Parcing of light sources
753 for (j=0; j<MyCView.Context.NbActiveLight; j++) {
754 LightType = (MyContext.ActivatedLight (j+1))->LightType ();
756 lights[j].WsId = MyCView.ViewId;
757 lights[j].ViewId = MyCView.ViewId;
759 lights[j].LightType = int (LightType);
760 lights[j].Active = 1;
762 int ((MyContext.ActivatedLight (j+1))->Identification ());
763 lights[j].Headlight = (MyContext.ActivatedLight (j+1))->Headlight ()? 1:0;
767 case Visual3d_TOLS_AMBIENT :
768 (MyContext.ActivatedLight (j+1))->Values (
773 case Visual3d_TOLS_POSITIONAL :
774 (MyContext.ActivatedLight (j+1))->Values (
782 case Visual3d_TOLS_DIRECTIONAL :
783 (MyContext.ActivatedLight (j+1))->Values (
789 case Visual3d_TOLS_SPOT :
790 (MyContext.ActivatedLight (j+1))->Values (
803 lights[j].Color.r = float (LightColor.Red ());
804 lights[j].Color.g = float (LightColor.Green ());
805 lights[j].Color.b = float (LightColor.Blue ());
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);
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);
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);
831 if (LightType == Visual3d_TOLS_SPOT) {
832 lights[j].Concentration =
833 float (LightConcentration);
843 // management of light sources
846 MyGraphicDriver->SetLight (MyCView);
848 // Dynamic allocation
849 if (MyCView.Context.NbActiveLight > 0) delete [] lights;
853 void Visual3d_View::UpdatePlanes()
855 MyCView.Context.ClipPlanes = MyContext.GetClipPlanes();
857 if (IsDeleted() || !IsDefined())
860 MyGraphicDriver->SetClipPlanes (MyCView);
863 void Visual3d_View::SetBackground (const Aspect_Background& ABack) {
865 if (IsDeleted ()) return;
868 Visual3d_ViewDefinitionError::Raise ("Window not defined");
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)
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);
882 MyGraphicDriver->Background (MyCView);
884 if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
889 void Visual3d_View::SetGradientBackground(const Aspect_GradientBackground& ABack, const Standard_Boolean update)
892 if (IsDeleted ()) return;
895 Visual3d_ViewDefinitionError::Raise ("Window not defined");
897 MyGradientBackground = ABack;
898 Quantity_Color aCol1,aCol2;
899 MyGradientBackground.Colors(aCol1,aCol2);
900 MyGraphicDriver->GradientBackground(MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
904 else if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
908 void Visual3d_View::SetBackgroundImage( const Standard_CString FileName,
909 const Aspect_FillMethod FillStyle,
910 const Standard_Boolean update )
915 Visual3d_ViewDefinitionError::Raise ("Window not defined");
917 MyGraphicDriver->BackgroundImage( FileName, MyCView, FillStyle );
921 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
925 void Visual3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
926 const Standard_Boolean update )
931 Visual3d_ViewDefinitionError::Raise ("Window not defined");
933 MyGraphicDriver->SetBgImageStyle( MyCView, FillStyle );
937 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
941 Aspect_Background Visual3d_View::Background () const {
943 return (MyBackground);
947 void Visual3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
948 const Standard_Boolean update )
953 Visual3d_ViewDefinitionError::Raise ("Window not defined");
955 MyGraphicDriver->SetBgGradientStyle( MyCView, FillStyle );
959 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
964 Aspect_GradientBackground Visual3d_View::GradientBackground () const {
966 return MyGradientBackground;
970 void Visual3d_View::SetTransform (const TColStd_Array2OfReal& AMatrix) {
972 if (IsDeleted ()) return;
974 Standard_Integer lr, ur, lc, uc;
975 Standard_Integer i, j;
977 // Assign the new transformation in an array [0..3][0..3]
978 // Avoid problems if the has defined a matrice [1..4][1..4]
979 // ou [3..6][-1..2] !!
980 lr = AMatrix.LowerRow ();
981 ur = AMatrix.UpperRow ();
982 lc = AMatrix.LowerCol ();
983 uc = AMatrix.UpperCol ();
985 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
986 Visual3d_TransformError::Raise ("Transform : not a 4x4 matrix");
990 MyTransformation (i, j) = AMatrix (lr + i, lc + j);
992 Graphic3d_Vector VPN;
993 Graphic3d_Vertex VRP;
994 Graphic3d_Vector VUP;
995 Standard_Real Sx, Sy, Sz;
997 Visual3d_ViewOrientation NewViewOrientation;
999 VPN = MyViewOrientation.ViewReferencePlane ();
1000 VRP = MyViewOrientation.ViewReferencePoint ();
1001 VUP = MyViewOrientation.ViewReferenceUp ();
1002 MyViewOrientation.AxialScale(Sx, Sy, Sz);
1004 NewViewOrientation.SetViewReferencePlane
1005 (Graphic3d_Structure::Transforms (Transform (), VPN));
1007 NewViewOrientation.SetViewReferencePoint
1008 (Graphic3d_Structure::Transforms (Transform (), VRP));
1010 NewViewOrientation.SetViewReferenceUp
1011 (Graphic3d_Structure::Transforms (Transform (), VUP));
1012 NewViewOrientation.SetAxialScale(Sx, Sy, Sz);
1014 SetViewOrientation (NewViewOrientation);
1016 MyMatOfOriIsEvaluated = Standard_False;
1020 const TColStd_Array2OfReal& Visual3d_View::Transform () const {
1022 return (MyTransformation);
1026 void Visual3d_View::SetViewOrientation (const Visual3d_ViewOrientation& VO) {
1028 if (IsDeleted ()) return;
1030 MyViewOrientation = VO;
1032 Standard_Real X, Y, Z;
1033 // Tests on modification of parameters.
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;
1040 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1042 MyCView.Orientation.ViewReferencePoint.x != float (X)
1043 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1044 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1045 MyCView.Orientation.ViewReferencePoint.x = float (X);
1046 MyCView.Orientation.ViewReferencePoint.y = float (Y);
1047 MyCView.Orientation.ViewReferencePoint.z = float (Z);
1049 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1051 MyCView.Orientation.ViewReferencePlane.x != float (X)
1052 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1053 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1054 MyCView.Orientation.ViewReferencePlane.x = float (X);
1055 MyCView.Orientation.ViewReferencePlane.y = float (Y);
1056 MyCView.Orientation.ViewReferencePlane.z = float (Z);
1058 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1060 MyCView.Orientation.ViewReferenceUp.x != float (X)
1061 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1062 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1063 MyCView.Orientation.ViewReferenceUp.x = float (X);
1064 MyCView.Orientation.ViewReferenceUp.y = float (Y);
1065 MyCView.Orientation.ViewReferenceUp.z = float (Z);
1067 MyViewOrientation.AxialScale(X, Y, Z);
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);
1077 (MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix());
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++) {
1083 if (!CustomIsModified) CustomIsModified =
1084 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
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;
1097 cout << "no modification\n" << flush;
1100 // restart if one of parameters is modified
1101 if (!IsInitialized || VUPIsModified || VRPIsModified
1102 || VRUIsModified || ScaleIsModified || CustomIsModified) {
1104 MyMatOfOriIsEvaluated = !VUPIsModified && !VRPIsModified
1105 && !VRUIsModified && !ScaleIsModified;
1107 if (! IsDefined ()) return;
1109 Standard_Boolean AWait = Standard_False; // => immediate update
1110 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1111 IsInitialized = Standard_True;
1114 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1119 Visual3d_ViewOrientation Visual3d_View::ViewOrientation () const {
1121 return (MyViewOrientation);
1125 Visual3d_ViewOrientation Visual3d_View::ViewOrientationDefault () const {
1127 return (MyViewOrientationReset);
1131 void Visual3d_View::SetViewOrientationDefault () {
1133 MyViewOrientationReset.Assign (MyViewOrientation);
1137 void Visual3d_View::ViewOrientationReset () {
1139 if (IsDeleted ()) return;
1141 MyViewOrientation = MyViewOrientationReset;
1143 Standard_Real X, Y, Z;
1145 // Tests on modification of parameters.
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;
1152 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1154 MyCView.Orientation.ViewReferencePoint.x != float (X)
1155 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1156 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1157 MyCView.Orientation.ViewReferencePoint.x = float (X);
1158 MyCView.Orientation.ViewReferencePoint.y = float (Y);
1159 MyCView.Orientation.ViewReferencePoint.z = float (Z);
1161 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1163 MyCView.Orientation.ViewReferencePlane.x != float (X)
1164 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1165 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1166 MyCView.Orientation.ViewReferencePlane.x = float (X);
1167 MyCView.Orientation.ViewReferencePlane.y = float (Y);
1168 MyCView.Orientation.ViewReferencePlane.z = float (Z);
1170 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1172 MyCView.Orientation.ViewReferenceUp.x != float (X)
1173 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1174 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1175 MyCView.Orientation.ViewReferenceUp.x = float (X);
1176 MyCView.Orientation.ViewReferenceUp.y = float (Y);
1177 MyCView.Orientation.ViewReferenceUp.z = float (Z);
1179 MyViewOrientation.AxialScale(X, Y, Z);
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);
1189 MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
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++) {
1195 if (!CustomIsModified) CustomIsModified =
1196 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
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;
1210 cout << "no modification\n" << flush;
1213 // Restart if one of parameters is modified
1214 if (!IsInitialized || VUPIsModified || VRPIsModified
1215 || VRUIsModified || ScaleIsModified || CustomIsModified) {
1217 MyMatOfOriIsEvaluated = !VUPIsModified && !VRPIsModified
1218 && !VRUIsModified && !ScaleIsModified;
1220 if (! IsDefined ()) return;
1222 Standard_Boolean AWait = Standard_False; // => immediate update
1223 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1224 IsInitialized = Standard_True;
1227 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1231 void Visual3d_View::SetViewMapping (const Visual3d_ViewMapping& VM) {
1233 if (IsDeleted ()) return;
1235 Visual3d_TypeOfProjection OldType = MyViewMapping.Projection ();
1236 Visual3d_TypeOfProjection NewType = VM.Projection ();
1240 Standard_Real X, Y, Z;
1241 Standard_Real um, vm, uM, vM;
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);
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] =
1266 (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j);
1269 MyMatOfMapIsEvaluated = Standard_False;
1271 if (! IsDefined ()) return;
1273 Standard_Boolean AWait = Standard_False; // => immediate update
1274 MyGraphicDriver->ViewMapping (MyCView, AWait);
1276 // Passage Parallele/Perspective
1277 if (OldType != NewType)
1280 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1284 Visual3d_ViewMapping Visual3d_View::ViewMapping () const {
1286 return (MyViewMapping);
1290 Visual3d_ViewMapping Visual3d_View::ViewMappingDefault () const {
1292 return (MyViewMappingReset);
1296 void Visual3d_View::SetViewMappingDefault () {
1298 MyViewMappingReset.Assign (MyViewMapping);
1302 void Visual3d_View::ViewMappingReset () {
1304 if (IsDeleted ()) return;
1306 MyViewMapping = MyViewMappingReset;
1308 Standard_Real X, Y, Z;
1309 Standard_Real um, vm, uM, vM;
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);
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] =
1334 (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j);
1337 MyMatOfMapIsEvaluated = Standard_False;
1339 if (! IsDefined ()) return;
1341 Standard_Boolean AWait = Standard_False; // => immediate update
1342 MyGraphicDriver->ViewMapping (MyCView, AWait);
1344 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1348 void Visual3d_View::SetContext (const Visual3d_ContextView& CTX) {
1350 if (IsDeleted ()) return;
1352 Visual3d_TypeOfVisualization OldVisualMode;
1353 Visual3d_TypeOfVisualization NewVisualMode;
1355 // To manage display only in case of
1356 // change of visualisation mode.
1357 OldVisualMode = MyContext.Visualization ();
1358 NewVisualMode = CTX.Visualization ();
1360 Visual3d_TypeOfModel OldModel;
1361 Visual3d_TypeOfModel NewModel;
1363 // To manage change of visualisation only in case
1364 // of change of mode of visualisation or of type of shading.
1365 OldModel = MyContext.Model ();
1366 NewModel = CTX.Model ();
1368 Standard_Boolean OldAliasingMode;
1369 Standard_Boolean NewAliasingMode;
1371 // To manage antialiasing only in case of change.
1372 OldAliasingMode = MyContext.AliasingIsOn ();
1373 NewAliasingMode = CTX.AliasingIsOn ();
1375 Standard_Boolean OldDepthCueingMode;
1376 Standard_Boolean NewDepthCueingMode;
1378 Standard_Real OldDepthCueingFrontPlane;
1379 Standard_Real NewDepthCueingFrontPlane;
1380 Standard_Real OldDepthCueingBackPlane;
1381 Standard_Real NewDepthCueingBackPlane;
1383 // To manage the depth cueing only in case of change.
1384 OldDepthCueingMode = MyContext.DepthCueingIsOn ();
1385 NewDepthCueingMode = CTX.DepthCueingIsOn ();
1387 OldDepthCueingFrontPlane = MyContext.DepthCueingFrontPlane ();
1388 NewDepthCueingFrontPlane = CTX.DepthCueingFrontPlane ();
1389 OldDepthCueingBackPlane = MyContext.DepthCueingBackPlane ();
1390 NewDepthCueingBackPlane = CTX.DepthCueingBackPlane ();
1392 Standard_Boolean OldFrontZClippingMode;
1393 Standard_Boolean NewFrontZClippingMode;
1394 Standard_Boolean OldBackZClippingMode;
1395 Standard_Boolean NewBackZClippingMode;
1397 Standard_Real OldZClippingFrontPlane;
1398 Standard_Real NewZClippingFrontPlane;
1399 Standard_Real OldZClippingBackPlane;
1400 Standard_Real NewZClippingBackPlane;
1402 // To manage the Zclipping only in case of change.
1403 OldFrontZClippingMode = MyContext.FrontZClippingIsOn ();
1404 NewFrontZClippingMode = CTX.FrontZClippingIsOn ();
1405 OldBackZClippingMode = MyContext.BackZClippingIsOn ();
1406 NewBackZClippingMode = CTX.BackZClippingIsOn ();
1408 OldZClippingFrontPlane = MyContext.ZClippingFrontPlane ();
1409 NewZClippingFrontPlane = CTX.ZClippingFrontPlane ();
1410 OldZClippingBackPlane = MyContext.ZClippingBackPlane ();
1411 NewZClippingBackPlane = CTX.ZClippingBackPlane ();
1413 Handle(Graphic3d_TextureEnv) aTexEnvOld = MyContext.TextureEnv();
1414 Handle(Graphic3d_TextureEnv) aTexEnvNew = CTX.TextureEnv();
1416 Visual3d_TypeOfSurfaceDetail OldSurfaceDetail = MyContext.SurfaceDetail();
1417 Visual3d_TypeOfSurfaceDetail NewSurfaceDetail = CTX.SurfaceDetail();
1423 Standard_Boolean AWait = Standard_False; // => immediate update
1425 // management of visualization modes and types of shading.
1426 if ((OldVisualMode != NewVisualMode) || (OldModel != NewModel))
1427 MyGraphicDriver->SetVisualisation (MyCView);
1429 // management of antialiasing.
1430 if (OldAliasingMode != NewAliasingMode)
1431 MyGraphicDriver->AntiAliasing (MyCView, NewAliasingMode);
1433 // management of depth_cueing.
1434 if ((OldDepthCueingMode != NewDepthCueingMode) ||
1435 (OldDepthCueingFrontPlane != NewDepthCueingFrontPlane) ||
1436 (OldDepthCueingBackPlane != NewDepthCueingBackPlane)) {
1438 if( NewDepthCueingMode &&
1439 (NewDepthCueingBackPlane >= NewDepthCueingFrontPlane) )
1440 Visual3d_DepthCueingDefinitionError::Raise
1441 ("Bad value for DepthCueingPlanes position");
1443 MyGraphicDriver->DepthCueing
1444 (MyCView, NewDepthCueingMode);
1447 // management of Zclipping
1448 if ((OldFrontZClippingMode != NewFrontZClippingMode) ||
1449 (OldBackZClippingMode != NewBackZClippingMode) ||
1450 (OldZClippingFrontPlane != NewZClippingFrontPlane) ||
1451 (OldZClippingBackPlane != NewZClippingBackPlane)) {
1453 if( NewBackZClippingMode && NewFrontZClippingMode &&
1454 (NewZClippingBackPlane >= NewZClippingFrontPlane) )
1455 Visual3d_ZClippingDefinitionError::Raise
1456 ("Bad value for ZClippingPlanes position");
1458 MyGraphicDriver->ClipLimit (MyCView, AWait);
1461 // management of textures
1462 if ((aTexEnvOld != aTexEnvNew) || (OldSurfaceDetail != NewSurfaceDetail))
1464 MyGraphicDriver->Environment(MyCView);
1467 // Update of planes of model clipping
1470 // Update of light sources
1474 if (OldVisualMode != NewVisualMode) {
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.
1484 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
1485 Visual3d_TypeOfAnswer Answer;
1487 Standard_Integer i = MyDisplayedStructure.Extent ();
1489 Graphic3d_SequenceOfStructure FooSequence;
1491 while (S1Iterator.More ()) {
1492 Answer = AcceptDisplay (S1Iterator.Key ());
1493 // If the structure can't be displayed in the
1494 // new context of the view, it is removed.
1495 if ((Answer == Visual3d_TOA_NO) ||
1496 (Answer == Visual3d_TOA_COMPUTE))
1497 //Erase (S1Iterator.Key (), Aspect_TOU_WAIT);
1498 FooSequence.Append (S1Iterator.Key ());
1500 // S1Iterator.Next () is located on the next structure
1504 Standard_Integer Length = FooSequence.Length ();
1505 // The stored structures are removed
1506 for (i=1; i<=Length; i++)
1507 Erase (FooSequence.Value (i), Aspect_TOU_WAIT);
1508 if (Length != 0) FooSequence.Clear ();
1511 * Change of context =>
1512 * Display structures that can be displayed
1513 * with the new visualisation mode.
1514 * All structures with status Displayed are removed from the ViewManager
1515 * and displayed in the view directly, if the structure is not already
1516 * displayed and if the view accepts it in its context.
1519 i = MyViewManager->NumberOfDisplayedStructures ();
1520 Graphic3d_MapOfStructure Map;
1521 MyViewManager->DisplayedStructures(Map);
1522 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1524 for (; it.More(); it.Next()) {
1525 Handle(Graphic3d_Structure) SG = it.Key();
1526 if (! IsDisplayed (SG)) {
1527 Answer = AcceptDisplay(SG);
1528 // If the structure can be displayed in the
1529 // new context of the view, it is displayed.
1530 if ((Answer == Visual3d_TOA_YES) ||
1531 (Answer == Visual3d_TOA_COMPUTE))
1532 //Display (MyViewManager->DisplayedStructure (j),
1534 FooSequence.Append (SG);
1538 Length = FooSequence.Length ();
1539 // The stored structures are displayed
1540 for (i=1; i<=Length; i++)
1541 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
1542 if (Length != 0) FooSequence.Clear ();
1545 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1549 const Visual3d_ContextView& Visual3d_View::Context () const {
1555 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& SG) const
1558 if (IsDeleted ()) return;
1560 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
1562 while (Iterator.More ()) {
1563 SG.Add (Iterator.Key ());
1565 // Iterator.Next () is located on the next structure
1571 void Visual3d_View::Activate () {
1573 if (IsDeleted ()) return;
1576 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1578 if (! IsActive ()) {
1580 MyGraphicDriver->ActivateView (MyCView);
1581 MyGraphicDriver->Background (MyCView);
1582 MyGraphicDriver->Transparency
1583 (MyCView, MyViewManager->Transparency ());
1588 * Activation of a new view =>
1589 * Display structures that can be displayed in this new view.
1590 * All structures with status
1591 * Displayed in ViewManager are returned and displayed in
1592 * the view directly, if the structure is not already
1593 * displayed and if the view accepts it in its context.
1596 Visual3d_TypeOfAnswer Answer;
1597 Graphic3d_MapOfStructure Map;
1598 MyViewManager->DisplayedStructures(Map);
1599 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1601 for (; it.More(); it.Next()) {
1602 Handle(Graphic3d_Structure) SG = it.Key();
1603 if (! IsDisplayed (SG)) {
1604 Answer = AcceptDisplay(SG);
1605 // If the structure can be displayed in the
1606 // new context of the view, it is displayed.
1607 if ((Answer == Visual3d_TOA_YES) ||
1608 (Answer == Visual3d_TOA_COMPUTE))
1609 Display (SG,Aspect_TOU_WAIT);
1615 // If the activation/desactivation of ZBuffer should be automatic
1616 // depending on the presence or absence of facets.
1617 if (MyViewManager->ZBufferAuto ()) {
1618 Standard_Boolean BContainsFacet = ContainsFacet ();
1619 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1620 // If the view contains facets
1621 // and if ZBuffer is not active
1622 if (BContainsFacet && ! BZBuffer)
1623 SetZBufferActivity (1);
1624 // If the view does not contain facets
1625 // and if ZBuffer is active
1626 if (! BContainsFacet && BZBuffer)
1627 SetZBufferActivity (0);
1630 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1634 Standard_Boolean Visual3d_View::IsActive () const {
1636 if (IsDeleted ()) return (Standard_False);
1639 return (Standard_True);
1641 return (Standard_False);
1645 void Visual3d_View::Deactivate () {
1647 if (IsDeleted ()) return;
1650 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1654 MyGraphicDriver->DeactivateView (MyCView);
1657 * Deactivation of a view =>
1658 * Removal of structures displayed in this view.
1659 * All structures with status
1660 * Displayed in ViewManager are returned and removed from
1661 * the view directly, if the structure is not already
1662 * displayed and if the view accepts it in its context.
1665 Visual3d_TypeOfAnswer Answer;
1666 Graphic3d_MapOfStructure Map;
1667 MyViewManager->DisplayedStructures(Map);
1668 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1670 for (; it.More(); it.Next()) {
1671 Handle(Graphic3d_Structure) SG = it.Key();
1672 if (! IsDisplayed (SG)) {
1673 Answer = AcceptDisplay(SG);
1674 // If the structure was displayed it is removed.
1675 if ((Answer == Visual3d_TOA_YES) ||
1676 (Answer == Visual3d_TOA_COMPUTE))
1677 Erase (SG,Aspect_TOU_WAIT);
1681 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1683 // No action currently possible in the view
1689 void Visual3d_View::Redraw () {
1691 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1695 void Visual3d_View::Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
1697 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer (), x, y, width, height);
1700 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1702 if (IsDeleted ()) return;
1704 if ((! IsDefined ()) || (! IsActive ())) return;
1706 if (! MyWindow->IsMapped ()) return;
1708 // san - 14/04/2004 - set up Z buffer state before redrawing
1709 // If the activation/desactivation of ZBuffer should be automatic
1710 // depending on the presence or absence of facets.
1711 if (MyViewManager->ZBufferAuto ()) {
1712 Standard_Boolean BContainsFacet = ContainsFacet ();
1713 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1714 // If the view contains facets
1715 // and if ZBuffer is not active
1716 if (BContainsFacet && ! BZBuffer)
1717 SetZBufferActivity (1);
1718 // If the view contains only facets
1719 // and if ZBuffer is active
1720 if (! BContainsFacet && BZBuffer)
1721 SetZBufferActivity (0);
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);
1733 void 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) {
1735 if (IsDeleted ()) return;
1737 if ((! IsDefined ()) || (! IsActive ())) return;
1739 if (! MyWindow->IsMapped ()) return;
1741 // san - 14/04/2004 - set up Z buffer state before redrawing
1742 // If activation/desactivation of ZBuffer should be automatic
1743 // depending on the presence or absence of facets.
1744 if (MyViewManager->ZBufferAuto ()) {
1745 Standard_Boolean BContainsFacet = ContainsFacet ();
1746 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1747 // If the view contains facets
1748 // and if ZBuffer is not active
1749 if (BContainsFacet && ! BZBuffer)
1750 SetZBufferActivity (1);
1751 // If the view contains only facets
1752 // and if ZBuffer is active
1753 if (! BContainsFacet && BZBuffer)
1754 SetZBufferActivity (0);
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);
1766 void Visual3d_View::Update () {
1768 Update (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1772 void Visual3d_View::Update (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1774 if (IsDeleted ()) return;
1776 if ((! IsDefined ()) || (! IsActive ())) return;
1778 if (! MyWindow->IsMapped ()) return;
1780 if (MyGraphicDriver->IsDeviceLost())
1782 MyViewManager->ReComputeStructures();
1783 MyGraphicDriver->ResetDeviceLostFlag();
1786 // If activation/desactivation of ZBuffer should be automatic
1787 // depending on the presence or absence of facets.
1788 if (MyViewManager->ZBufferAuto ()) {
1789 Standard_Boolean BContainsFacet = ContainsFacet ();
1790 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1791 // If the view contains facets
1792 // and if ZBuffer is not active
1793 if (BContainsFacet && ! BZBuffer)
1794 SetZBufferActivity (1);
1795 // If the view does not contain facets
1796 // and if ZBuffer is active
1797 if (! BContainsFacet && BZBuffer)
1798 SetZBufferActivity (0);
1801 Aspect_CLayer2d OverCLayer;
1802 Aspect_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);
1812 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const {
1814 // Return type of visualization of the view
1815 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
1817 // Return type of visualization of the structure
1818 Graphic3d_TypeOfStructure StructType = AStructure->Visual ();
1820 Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO;
1822 if (StructType == Graphic3d_TOS_ALL)
1823 // The structure accepts any type of view
1824 Result = Visual3d_TOA_YES;
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;
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";
1857 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer /*OldPriority*/, const Standard_Integer NewPriority) {
1859 if (IsDeleted ()) return;
1860 if (! IsDefined ()) return;
1861 if (! IsActive ()) return;
1862 if (! IsDisplayed (AStructure)) return;
1864 Standard_Integer Index = IsComputed (AStructure);
1865 if (Index != 0 && ComputedMode())
1868 Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification ();
1869 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1870 << AStructure->Identification () << "/" << StructId
1871 << ", " << OldPriority << ", " << NewPriority << ")\n";
1874 MyGraphicDriver->EraseStructure
1876 *(Graphic3d_CStructure *)
1877 MyCOMPUTEDSequence.Value (Index)->CStructure ());
1878 MyGraphicDriver->DisplayStructure
1880 *(Graphic3d_CStructure *)
1881 MyCOMPUTEDSequence.Value (Index)->CStructure (),
1886 Standard_Integer StructId = AStructure->Identification ();
1887 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1888 << AStructure->Identification () << "/" << StructId
1889 << ", " << OldPriority << ", " << NewPriority << ")\n";
1892 MyGraphicDriver->EraseStructure
1894 *(Graphic3d_CStructure *)AStructure->CStructure ());
1895 MyGraphicDriver->DisplayStructure
1897 *(Graphic3d_CStructure *)AStructure->CStructure (),
1903 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
1906 cout << "Visual3d_View" << MyCView.ViewId << "::Clear ("
1907 << AStructure->Identification () << ")\n";
1911 Standard_Integer Index = IsComputed (AStructure);
1914 cout << "Structure " << AStructure->Identification ()
1915 << " calculated in the view "
1916 << Identification () << ", by structure "
1917 << MyCOMPUTEDSequence.Value (Index)->Identification ()
1918 << " is emptied.\n";
1921 MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction);
1922 MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False);
1927 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
1929 #ifdef TRACE_CONNECT
1930 cout << "Visual3d_View" << MyCView.ViewId << "::Connect ("
1931 << AMother->Identification ()
1932 << ADaughter->Identification () << ")\n";
1936 Standard_Integer IndexM = IsComputed (AMother);
1937 Standard_Integer IndexD = IsComputed (ADaughter);
1939 if (IndexM != 0 && IndexD != 0) {
1940 #ifdef TRACE_CONNECT
1941 cout << "Structure " << AMother->Identification ()
1942 << " is connected to structure "
1943 << ADaughter->Identification () << endl;
1944 cout << "These structures are calculated.\n";
1945 cout << "In the view " << Identification ()
1947 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
1948 << " is connected to the structure "
1949 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
1952 MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD));
1957 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
1959 #ifdef TRACE_CONNECT
1960 cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect ("
1961 << AMother->Identification ()
1962 << ADaughter->Identification () << ")\n";
1966 Standard_Integer IndexM = IsComputed (AMother);
1967 Standard_Integer IndexD = IsComputed (ADaughter);
1969 if (IndexM != 0 && IndexD != 0) {
1970 #ifdef TRACE_CONNECT
1971 cout << "Structure " << AMother->Identification ()
1972 << " is disconnected from the structure "
1973 << ADaughter->Identification () << endl;
1974 cout << "These structures are calculated.\n";
1975 cout << "In the view " << Identification ()
1977 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
1978 << " is disconnected from the structure "
1979 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
1982 MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD));
1987 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure) {
1989 Display (AStructure, MyViewManager->UpdateMode ());
1993 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
1995 if (IsDeleted ()) return;
1996 if (! IsDefined ()) return;
1997 if (! IsActive ()) return;
1999 // If Display on a structure present in the list
2000 // of calculated structures while it is not
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.
2005 Standard_Integer Index = IsComputed (AStructure);
2007 if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) {
2008 MyTOCOMPUTESequence.Remove (Index);
2009 MyCOMPUTEDSequence.Remove (Index);
2013 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2015 if (Answer == Visual3d_TOA_NO) {
2019 if (!ComputedMode())
2021 Answer = Visual3d_TOA_YES;
2024 if (Answer == Visual3d_TOA_YES ) {
2025 if (IsDisplayed (AStructure)) return;
2026 MyGraphicDriver->DisplayStructure (
2028 *(Graphic3d_CStructure *)AStructure->CStructure (),
2029 int (AStructure->DisplayPriority ())
2031 MyDisplayedStructure.Add (AStructure);
2032 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2035 if (Answer == Visual3d_TOA_COMPUTE) {
2037 // Already computed, is COMPUTED still valid?
2038 Standard_Integer OldStructId =
2039 MyCOMPUTEDSequence.Value (Index)->Identification ();
2041 // Case COMPUTED valide
2042 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2044 if (! IsDisplayed (AStructure)) {
2045 MyDisplayedStructure.Add (AStructure);
2046 MyGraphicDriver->DisplayStructure (
2048 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
2049 int (AStructure->DisplayPriority ())
2051 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2056 // Case COMPUTED invalid
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
2063 Standard_Integer NewIndex = HaveTheSameOwner (AStructure);
2065 // Case of COMPUTED invalid, WITH a valid of replacement
2066 if (NewIndex != 0) {
2068 if (! IsDisplayed (AStructure)) {
2069 MyCOMPUTEDSequence.SetValue
2070 (Index, MyCOMPUTEDSequence.Value (NewIndex));
2071 OldStructId = MyCOMPUTEDSequence.Value (NewIndex)->
2073 MyDisplayedStructure.Add (AStructure);
2074 MyGraphicDriver->DisplayStructure (
2076 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (NewIndex)->CStructure (),
2077 int (AStructure->DisplayPriority ())
2079 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2084 // Cas COMPUTED invalid, WITHOUT a valid of replacement
2086 // COMPUTED is removed if displayed
2087 if (IsDisplayed (AStructure))
2088 MyGraphicDriver->EraseStructure (
2090 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()
2094 } // if (Index != 0)
2096 // Compute + Validation
2098 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
2100 Handle(Graphic3d_Structure) TheStructure;
2101 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
2102 AStructure->Transform (ATrsf);
2104 TColStd_Array2OfReal Ident (0, 3, 0, 3);
2105 Standard_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);
2115 AStructure->Compute (this, TheStructure);
2119 if (AStructure->IsTransformed ()) {
2120 TheStructure = AStructure->Compute (this, ATrsf);
2123 TheStructure = AStructure->Compute (this);
2127 TheStructure->SetHLRValidation (Standard_True);
2129 // TOCOMPUTE and COMPUTED associated to sequences are added
2130 MyTOCOMPUTESequence.Append (AStructure);
2131 MyCOMPUTEDSequence.Append (TheStructure);
2133 // The previous are removed if necessary
2135 MyTOCOMPUTESequence.Remove (Index);
2136 MyCOMPUTEDSequence.Remove (Index);
2139 // Return type of visualisation of the view
2140 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
2142 // Of which type will be the computed ?
2143 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
2144 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
2146 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
2147 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
2149 if (ComputeWireframe)
2150 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
2152 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
2154 if (! ComputeShading && ! ComputeWireframe)
2155 Answer = Visual3d_TOA_NO;
2157 Answer = AcceptDisplay (TheStructure);
2159 if (AStructure->IsHighlighted()) {
2160 TheStructure->SetHighlightColor (AStructure->HighlightColor ());
2161 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
2164 // It is displayed only if the calculated structure
2165 // has a proper type corresponding to the one of the view.
2166 if (Answer != Visual3d_TOA_NO) {
2167 if (! IsDisplayed (AStructure))
2168 MyDisplayedStructure.Add (AStructure);
2169 MyGraphicDriver->DisplayStructure (
2171 *(Graphic3d_CStructure *)TheStructure->CStructure (),
2172 int (AStructure->DisplayPriority ())
2174 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2176 } // Visual3d_TOA_COMPUTE
2179 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure) {
2181 if (IsDeleted ()) return;
2183 Erase (AStructure, MyViewManager->UpdateMode ());
2187 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2189 Standard_Integer StructId;
2191 if (IsDeleted ()) return;
2193 // No test on window as the structure is displayed only if
2194 // the window exists, so only one test is enough.
2195 if (IsDisplayed (AStructure)) {
2196 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2198 if (!ComputedMode())
2200 Answer = Visual3d_TOA_YES;
2203 if (Answer != Visual3d_TOA_COMPUTE) {
2204 MyGraphicDriver->EraseStructure (
2206 *(Graphic3d_CStructure *)AStructure->CStructure ()
2210 if (Answer == Visual3d_TOA_COMPUTE) {
2211 Standard_Integer Index = IsComputed (AStructure);
2213 cout << "Visual3d_View" << MyCView.ViewId << "::Erase ("
2214 << AStructure->Identification () << ");\n";
2215 cout << "Index : " << Index << "\n";
2219 if (Index != 0 && ComputedMode())
2222 MyCOMPUTEDSequence.Value (Index)->Identification ();
2224 cout << "Structure " << AStructure->Identification ()
2225 << " calculated, in the view "
2226 << Identification () << ", by the structure "
2227 << StructId << " is removed. \n";
2230 MyGraphicDriver->EraseStructure
2231 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
2233 // else is impossible
2235 MyDisplayedStructure.Remove (AStructure);
2236 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2241 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
2244 cout << "Visual3d_View" << MyCView.ViewId << "::Highlight ("
2245 << AStructure->Identification () << ")\n";
2249 Standard_Integer Index = IsComputed (AStructure);
2252 cout << "Structure " << AStructure->Identification ()
2253 << " calculated, in the view "
2254 << Identification () << ", by the structure "
2255 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2256 << " passes in highlight mode.\n";
2259 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
2260 (AStructure->HighlightColor ());
2261 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod);
2266 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
2269 cout << "Visual3d_View" << MyCView.ViewId << "::Transform ("
2270 << AStructure->Identification () << ")\n";
2274 Standard_Integer Index = IsComputed (AStructure);
2277 cout << "The structure " << AStructure->Identification ()
2278 << " calculated, in the view "
2279 << Identification () << ", by the structure "
2280 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2281 << " is transformed.\n";
2284 // Test is somewhat light !
2285 // trsf is transferred only if it is :
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);
2293 MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf);
2298 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
2301 cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight ("
2302 << AStructure->Identification () << ")\n";
2306 Standard_Integer Index = IsComputed (AStructure);
2309 cout << "Structure " << AStructure->Identification ()
2310 << " calculated, in the view "
2311 << Identification () << ", by the structure "
2312 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2313 << " passes in unhighlight mode.\n";
2316 MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight ();
2322 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const {
2324 Standard_Integer StrId = AStructure->Identification ();
2326 Standard_Integer Result = 0;
2327 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
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;
2335 cout << "\n In the view " << Identification () << " the structure ";
2337 cout << StrId << " is calculated by "
2338 << MyCOMPUTEDSequence.Value (Result)->Identification ()
2341 cout << StrId << " is not calculated\n" << flush;
2345 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2346 cout << "In Visual3d_View::IsComputed, ";
2347 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2348 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2357 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const {
2359 Standard_Boolean Result = Standard_False;
2361 if (IsDeleted ()) return Result;
2363 Result = MyDisplayedStructure.Contains (AStructure);
2370 Standard_Boolean Visual3d_View::ContainsComputedStructure () const {
2372 Standard_Boolean Result = Standard_False;
2374 if (MyDisplayedStructure.IsEmpty ()) return Result;
2376 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
2378 Standard_Integer i = MyDisplayedStructure.Extent ();
2380 // Stop at the first structure of type TOS_COMPUTED
2381 while (! Result && Iterator.More ()) {
2383 (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED);
2385 // Iterator.Next () is located on the
2395 Standard_Boolean Visual3d_View::ContainsFacet () const {
2397 return ContainsFacet (MyDisplayedStructure);
2401 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const {
2403 Standard_Boolean Result = Standard_False;
2405 if (ASet.IsEmpty ()) return Result;
2407 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2409 // Stop at the first structure containing a facet
2410 for ( Iterator.Initialize (ASet);
2411 Iterator.More () && ! Result;
2413 Result = (Iterator.Key ())->ContainsFacet ();
2419 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
2422 (MyDisplayedStructure, XMin, YMin, ZMin, XMax, YMax, ZMax);
2426 void 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 {
2428 if (ASet.IsEmpty ()) {
2429 XMin = RealFirst ();
2430 YMin = RealFirst ();
2431 ZMin = RealFirst ();
2439 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2440 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2446 XMax = RealFirst ();
2447 YMax = RealFirst ();
2448 ZMax = RealFirst ();
2450 for ( Iterator.Initialize (ASet);
2454 if (!Iterator.Key()->IsVisible())
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 )
2464 if ( Ym != RealFirst() && Ym < YMin )
2466 if ( Zm != RealFirst() && Zm < ZMin )
2468 if ( XM != RealLast() && XM > XMax )
2470 if ( YM != RealLast() && YM > YMax )
2472 if ( ZM != RealLast() && ZM > ZMax )
2475 // Only non-empty and non-infinite structures
2476 // are taken into account for calculation of MinMax
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 )
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;
2494 // The following cases are relevant
2495 // For exemple if all structures are empty or infinite
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; }
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;
2510 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2512 MinMaxValues (MyDisplayedStructure, XMin, YMin, XMax, YMax);
2516 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2518 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2519 Standard_Real Xp, Yp, Zp;
2521 MinMaxValues (ASet, Xm, Ym, Zm, XM, YM, ZM);
2523 Projects (Xm, Ym, Zm, Xp, Yp, Zp);
2527 Projects (XM, YM, ZM, Xp, Yp, Zp);
2531 if (XMax < XMin) { Xp = XMax; XMax = XMin; XMin = Xp; }
2532 if (YMax < YMin) { Yp = YMax; YMax = YMin; YMin = Yp; }
2535 const TColStd_Array2OfReal& Visual3d_View::MatrixOfOrientation () {
2537 if (! MyMatOfOriIsEvaluated) {
2538 MyGraphicDriver->InquireMat
2539 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2540 MyMatOfMapIsEvaluated = Standard_True;
2541 MyMatOfOriIsEvaluated = Standard_True;
2544 return (MyMatrixOfOrientation);
2548 const TColStd_Array2OfReal& Visual3d_View::MatrixOfMapping () {
2550 if (! MyMatOfMapIsEvaluated) {
2551 MyGraphicDriver->InquireMat
2552 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2553 MyMatOfMapIsEvaluated = Standard_True;
2554 MyMatOfOriIsEvaluated = Standard_True;
2557 return (MyMatrixOfMapping);
2561 Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const {
2563 Standard_Integer Result = MyDisplayedStructure.Extent ();
2570 void 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 {
2572 math_Vector PtDC (0,3), PtWC (0,3);
2575 // Otherwise use new on Visual3d_View (constructor+destructor)
2576 // as Projects is a const method or MatrixOfOrientation and
2577 // MatrixOfMapping is not.
2578 Visual3d_View * const newthis = (Visual3d_View * const) this;
2579 newthis->MatrixOfOrientation ();
2580 newthis->MatrixOfMapping ();
2582 // World Coordinate Space
2588 // WCS -> View Reference Coordinate Space
2589 math_Vector PtVRC(0,3);
2590 PtVRC = MyMatrixOfOrientation.Multiplied (PtWC);
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);
2598 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2599 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2602 Standard_Real Ratio;
2604 // NPCS -> Device Coordinate Space
2605 Standard_Real Dx = Standard_Real (MyCView.DefWindow.dx);
2606 Standard_Real Dy = Standard_Real (MyCView.DefWindow.dy);
2609 PtDC (0) = PtNPC (0) * Dx;
2610 PtDC (1) = Dy - PtNPC (1) * Dy * Ratio;
2612 printf("Display coordinates : %f,%f,%f,%f\n",
2613 PtDC(0),PtDC(1),PtDC(2),PtDC(3));
2616 // NPCS -> Window Space
2617 Standard_Real um, vm, uM, vM;
2618 MyViewMapping.WindowLimit (um, vm, uM, vM);
2620 Ratio = (uM - um) / (vM - vm);
2622 PtNPC (1) = PtNPC (1) * Ratio;
2624 PtNPC (0) = PtNPC (0) / Ratio;
2627 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2628 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2631 Standard_Real fpd = MyViewMapping.FrontPlaneDistance ();
2632 Standard_Real bpd = MyViewMapping.BackPlaneDistance ();
2635 * Coordinates of PtNPC are described in the space
2636 * [0-1]x[0-1]x[0-1].
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.
2643 APX = PtNPC (0) * (uM - um) + um;
2644 APY = PtNPC (1) * (vM - vm) + vm;
2645 APZ = PtNPC (2) * (fpd - bpd) + bpd;
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));
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));
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);
2678 #endif /* OLD_METHOD */
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.
2683 void Visual3d_View::Projects (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ, Standard_Real& APX, Standard_Real& APY, Standard_Real& APZ) {
2685 Standard_Real PtX, PtY, PtZ, PtT;
2687 static Standard_Real Ratio, um, vm, uM, vM;
2688 static Standard_Real fpd, bpd;
2690 if (! MyMatOfOriIsEvaluated || ! MyMatOfMapIsEvaluated) {
2691 MyGraphicDriver->InquireMat
2692 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2693 MyMatOfOriIsEvaluated = MyMatOfMapIsEvaluated = Standard_True;
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);
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;
2736 // NPCS -> Window Space
2737 MyViewMapping.WindowLimit (um, vm, uM, vM);
2738 fpd = MyViewMapping.FrontPlaneDistance ();
2739 bpd = MyViewMapping.BackPlaneDistance ();
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;
2747 Ratio = (uM - um) / (vM - vm);
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.
2761 APX = APX * (uM - um) + um;
2762 APY = APY * (vM - vm) + vm;
2764 APZ = APZ * (fpd - bpd) + bpd;
2767 Standard_Integer Visual3d_View::Identification () const {
2769 return (Standard_Integer (MyCView.ViewId));
2774 Standard_Boolean Visual3d_View::ZBufferIsActivated () const {
2776 if (IsDeleted ()) return (Standard_False);
2778 if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);
2780 // -1 => not forced by the programmer => depends on the type of visualisation
2781 // 0 ou 1 => forced by the programmer
2783 if (MyCView.Context.ZBufferActivity == -1)
2784 if (MyContext.Visualization () == Visual3d_TOV_SHADING)
2785 return (Standard_True);
2787 return (Standard_False);
2789 if (MyCView.Context.ZBufferActivity)
2790 return (Standard_True);
2792 return (Standard_False);
2796 void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {
2798 if (IsDeleted ()) return;
2800 if ((! IsDefined ()) || (! IsActive ())) return;
2802 MyGraphicDriver->Transparency (MyCView, AnActivity);
2806 void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {
2808 if (MyCView.Context.ZBufferActivity == AnActivity) return;
2810 if (IsDeleted ()) return;
2812 if ((! IsDefined ()) || (! IsActive ())) return;
2814 MyCView.Context.ZBufferActivity = AnActivity;
2815 MyGraphicDriver->SetVisualisation (MyCView);
2819 void Visual3d_View::UpdateView () {
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);
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 ());
2838 MyCView.Context.Model = int (MyContext.Model ());
2839 MyCView.Context.Visualization = int (MyContext.Visualization ());
2841 MyCView.Context.TextureEnv = MyContext.TextureEnv();
2842 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
2846 void Visual3d_View::Compute () {
2849 Standard_Integer Length = MyCOMPUTEDSequence.Length ();
2850 for (i=1; i<=Length; i++)
2851 (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);
2853 if (!ComputedMode())
2859 * Force HLRValidation to False on all structures
2860 * calculated in the view.
2863 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2864 cout << "In Visual3d_View::Compute, ";
2865 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2866 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2872 * Change of orientation or of projection type =>
2873 * Remove structures that were calculated for the
2874 * previous orientation.
2875 * Recalculation of new structures.
2877 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
2878 Visual3d_TypeOfAnswer Answer;
2880 i = MyDisplayedStructure.Extent ();
2882 Graphic3d_SequenceOfStructure FooSequence;
2884 while (S1Iterator.More ()) {
2885 Answer = AcceptDisplay (S1Iterator.Key ());
2886 // If the structure was calculated, it is recalculated.
2887 if (Answer == Visual3d_TOA_COMPUTE) {
2889 cout << "AcceptDisplay ("
2890 << (S1Iterator.Key ())->Identification ()
2891 << ") == Visual3d_TOA_COMPUTE;\n";
2894 //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
2895 FooSequence.Append (S1Iterator.Key ());
2898 // S1Iterator.Next () is located on the next structure
2902 Length = FooSequence.Length ();
2903 // All stored structures are displayed
2904 for (i=1; i<=Length; i++)
2905 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
2906 if (Length != 0) FooSequence.Clear ();
2910 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
2911 if (!ComputedMode()) return;
2913 if (IsDeleted ()) return;
2915 if ((! IsDefined ()) || (! IsActive ())) return;
2917 if (! MyWindow->IsMapped ()) return;
2919 if (! AStructure->IsDisplayed ()) return;
2921 Visual3d_TypeOfAnswer Answer;
2923 Answer = AcceptDisplay (AStructure);
2925 if (Answer == Visual3d_TOA_COMPUTE) {
2926 Standard_Integer Index = IsComputed (AStructure);
2929 cout << "Structure " << AStructure->Identification ()
2930 << " is not calculated in the view "
2931 << Identification () << "\n";
2936 Standard_Integer OldStructId, NewStructId;
2938 MyCOMPUTEDSequence.Value (Index)->Identification ();
2940 Standard_Integer StructId = AStructure->Identification ();
2941 cout << "Structure " << StructId
2942 << " calculated, in the view "
2943 << Identification () << ", by the structure "
2944 << OldStructId << " is recalculated.\n";
2948 // Compute + Validation
2950 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
2952 Handle(Graphic3d_Structure) TheStructure;
2953 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
2954 AStructure->Transform (ATrsf);
2956 TColStd_Array2OfReal Ident (0, 3, 0, 3);
2957 Standard_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);
2967 AStructure->Compute (this, TheStructure);
2971 if (AStructure->IsTransformed ()) {
2972 TheStructure = AStructure->Compute (this, ATrsf);
2975 TheStructure = AStructure->Compute (this);
2979 TheStructure->SetHLRValidation (Standard_True);
2981 // Return type of visualisation of the view
2982 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
2984 // Of which type will be the computed ?
2985 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
2986 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
2988 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
2989 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
2991 if (ComputeWireframe)
2992 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
2994 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
2996 if (AStructure->IsHighlighted ()) {
2997 TheStructure->SetHighlightColor
2998 (AStructure->HighlightColor ());
2999 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3003 // Find structure <AStructure>
3004 // in the sequence of structures to be calculated.
3005 NewStructId = TheStructure->Identification ();
3007 // The previous calculation is removed and the new one is dislayed
3008 MyGraphicDriver->EraseStructure (
3010 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3011 MyGraphicDriver->DisplayStructure (
3013 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3014 int (AStructure->DisplayPriority ())
3018 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3019 cout << "In Visual3d_View::ReCompute, ";
3020 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3021 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3026 // hlhsr and the new associated compute are added
3027 MyTOCOMPUTESequence.Append (AStructure);
3028 MyCOMPUTEDSequence.Append (TheStructure);
3031 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3032 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3033 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3037 // hlhsr and the new associated compute are removed
3039 MyTOCOMPUTESequence.Remove (Index);
3040 MyCOMPUTEDSequence.Remove (Index);
3043 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3044 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3045 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3053 const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver () const {
3055 return MyGraphicDriver;
3059 void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& thePlotter) const
3061 for (Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure); S1Iterator.More(); S1Iterator.Next())
3063 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3064 // displayed structure is plotted as if it was not calculated
3066 (S1Iterator.Key ())->Plot (thePlotter);
3068 (MyCOMPUTEDSequence.Value (Index))->Plot (thePlotter);
3072 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const {
3074 Standard_Integer Result = 0;
3075 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3077 // Find in the sequence of already calculated structures
3078 // 1/ Structure with the same Owner as <AStructure>
3079 // 2/ Which is not <AStructure>
3080 // 3/ COMPUTED which of is valid
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;
3091 Standard_Address Visual3d_View::CView () const {
3093 return Standard_Address (&MyCView);
3098 // Triedron methods : the Triedron is a non-zoomable object.
3100 void 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);
3112 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
3113 const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) {
3115 MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe);
3119 void Visual3d_View::TriedronErase () {
3121 MyGraphicDriver->TriedronErase (MyCView);
3126 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {
3128 MyGraphicDriver->TriedronEcho (MyCView,AType);
3132 Standard_Boolean checkFloat(const Standard_Real value)
3134 return value > -FLT_MAX && value < FLT_MAX;
3137 void SetMinMaxValuesCallback(void* Visual3dView)
3139 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
3141 Handle(Visual3d_View) view = (Handle(Visual3d_View)&) Visual3dView;
3142 view->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax);
3144 if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) &&
3145 checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax))
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);
3153 Standard_Boolean Visual3d_View::GetGraduatedTrihedron
3154 (/* Names of axes */
3155 TCollection_ExtendedString& xname,
3156 TCollection_ExtendedString& yname,
3157 TCollection_ExtendedString& zname,
3159 Standard_Boolean& xdrawname,
3160 Standard_Boolean& ydrawname,
3161 Standard_Boolean& zdrawname,
3163 Standard_Boolean& xdrawvalues,
3164 Standard_Boolean& ydrawvalues,
3165 Standard_Boolean& zdrawvalues,
3167 Standard_Boolean& drawgrid,
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,
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 */
3203 Font_FontAspect& styleOfNames,
3204 /* Size of names of axes */
3205 Standard_Integer& sizeOfNames,
3206 /* Name of font for values */
3207 TCollection_AsciiString& fontOfValues,
3208 /* Style of values */
3209 Font_FontAspect& styleOfValues,
3210 /* Size of values */
3211 Standard_Integer& sizeOfValues) const
3213 if (!MyGTrihedron.ptrVisual3dView)
3214 return Standard_False;
3217 xname = MyGTrihedron.xname;
3218 yname = MyGTrihedron.yname;
3219 zname = MyGTrihedron.zname;
3221 xdrawname = MyGTrihedron.xdrawname;
3222 ydrawname = MyGTrihedron.ydrawname;
3223 zdrawname = MyGTrihedron.zdrawname;
3225 xdrawvalues = MyGTrihedron.xdrawvalues;
3226 ydrawvalues = MyGTrihedron.ydrawvalues;
3227 zdrawvalues = MyGTrihedron.zdrawvalues;
3229 drawgrid = MyGTrihedron.drawgrid;
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;
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;
3275 return Standard_True;
3278 void Visual3d_View::GraduatedTrihedronDisplay
3279 (/* Names of axes */
3280 const TCollection_ExtendedString &xname,
3281 const TCollection_ExtendedString &yname,
3282 const TCollection_ExtendedString &zname,
3284 const Standard_Boolean xdrawname,
3285 const Standard_Boolean ydrawname,
3286 const Standard_Boolean zdrawname,
3288 const Standard_Boolean xdrawvalues,
3289 const Standard_Boolean ydrawvalues,
3290 const Standard_Boolean zdrawvalues,
3292 const Standard_Boolean drawgrid,
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,
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 */
3328 const Font_FontAspect styleOfNames,
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 */
3334 const Font_FontAspect styleOfValues,
3335 /* Size of values */
3336 const Standard_Integer sizeOfValues)
3339 MyGTrihedron.xname = xname;
3340 MyGTrihedron.yname = yname;
3341 MyGTrihedron.zname = zname;
3343 MyGTrihedron.xdrawname = xdrawname;
3344 MyGTrihedron.ydrawname = ydrawname;
3345 MyGTrihedron.zdrawname = zdrawname;
3347 MyGTrihedron.xdrawvalues = xdrawvalues;
3348 MyGTrihedron.ydrawvalues = ydrawvalues;
3349 MyGTrihedron.zdrawvalues = zdrawvalues;
3351 MyGTrihedron.drawgrid = drawgrid;
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;
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;
3397 MyGTrihedron.ptrVisual3dView = this;
3398 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
3399 MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron);
3402 void Visual3d_View::GraduatedTrihedronErase()
3404 MyGTrihedron.ptrVisual3dView = NULL;
3405 MyGraphicDriver->GraduatedTrihedronErase(MyCView);
3408 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer () const {
3410 return (MyViewManager->UnderLayer ());
3414 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer () const {
3416 return (MyViewManager->OverLayer ());
3420 Standard_Integer Visual3d_View::LightLimit() const {
3422 Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit ();
3423 // printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight);
3427 Standard_Integer Visual3d_View::PlaneLimit() const {
3429 Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit ();
3430 // printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane);
3434 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
3436 return MyPtrViewManager;
3439 void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3441 if ((aMode && ComputedModeIsActive) ||
3442 (!aMode && !ComputedModeIsActive))
3447 Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure );
3448 Visual3d_TypeOfAnswer Answer;
3449 Standard_Integer StructId;
3450 Standard_Integer i = MyDisplayedStructure.Extent ();
3451 ComputedModeIsActive = aMode;
3452 if (!ComputedModeIsActive) {
3454 while ( S1Iterator.More () ) {
3456 Answer = AcceptDisplay ( S1Iterator.Key () );
3458 if ( Answer == Visual3d_TOA_COMPUTE ) {
3460 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
3464 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3466 MyGraphicDriver -> EraseStructure (
3468 *( Graphic3d_CStructure* )
3469 MyCOMPUTEDSequence.Value ( Index ) -> CStructure ()
3471 MyGraphicDriver -> DisplayStructure (
3473 *( Graphic3d_CStructure* )
3474 S1Iterator.Key () -> CStructure (),
3475 int ( S1Iterator.Key () -> DisplayPriority () )
3477 } // end if ( Index != 0 ) . . .
3479 } // end if ( Answer . . . )
3487 while ( S1Iterator.More () ) {
3489 Answer = AcceptDisplay ( S1Iterator.Key () );
3491 if ( Answer == Visual3d_TOA_COMPUTE ) {
3493 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
3497 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3499 MyGraphicDriver -> EraseStructure (
3501 *( Graphic3d_CStructure* )
3502 S1Iterator.Key () -> CStructure ()
3504 MyGraphicDriver -> DisplayStructure (
3506 *( Graphic3d_CStructure* )
3507 MyCOMPUTEDSequence.Value ( Index ) -> CStructure (),
3508 int ( S1Iterator.Key () -> DisplayPriority () )
3511 Display ( S1Iterator.Key (), Aspect_TOU_WAIT );
3513 if ( S1Iterator.Key () -> IsHighlighted () ) {
3515 if ( !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted () ) {
3517 MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor (
3518 S1Iterator.Key () ->
3521 MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight (
3530 Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key ();
3532 Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this );
3534 Handle( Graphic3d_Structure ) TheStructure;
3535 TColStd_Array2OfReal ATrsf ( 0, 3, 0, 3 );
3537 AStructure -> Transform ( ATrsf );
3541 TColStd_Array2OfReal Ident ( 0, 3, 0, 3 );
3542 Standard_Integer ii, jj;
3544 for ( ii = 0; ii <= 3; ++ii )
3546 for ( jj = 0; jj <= 3; ++jj )
3548 Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 );
3550 TheStructure = MyCOMPUTEDSequence.Value ( Index );
3552 TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE );
3554 if ( AStructure->IsTransformed () )
3556 AStructure -> Compute ( this, ATrsf, TheStructure );
3560 AStructure -> Compute ( this, TheStructure );
3564 if ( AStructure -> IsTransformed () )
3566 TheStructure = AStructure -> Compute ( this, ATrsf );
3570 TheStructure = AStructure -> Compute ( this );
3574 TheStructure -> SetHLRValidation ( Standard_True );
3576 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3578 Standard_Boolean ComputeWireframe =
3579 ( ( ViewType == Visual3d_TOV_WIREFRAME ) &&
3580 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING )
3583 Standard_Boolean ComputeShading =
3584 ( ( ViewType == Visual3d_TOV_SHADING ) &&
3585 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME )
3588 if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME );
3589 if ( ComputeShading ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING );
3591 if ( S1Iterator.Key () -> IsHighlighted () ) {
3593 TheStructure -> SetHighlightColor (
3594 S1Iterator.Key () -> HighlightColor ()
3596 TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR );
3600 Standard_Integer Result = 0;
3601 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3602 StructId = S1Iterator.Key () -> Identification ();
3604 for ( i = 1; i <= Length && Result == 0; ++i )
3606 if ( MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId )
3612 MyCOMPUTEDSequence.ChangeValue ( Result ) = TheStructure;
3616 MyTOCOMPUTESequence.Append ( S1Iterator.Key () );
3617 MyCOMPUTEDSequence.Append ( TheStructure );
3621 MyGraphicDriver -> EraseStructure (
3623 *( Graphic3d_CStructure* )
3624 S1Iterator.Key () -> CStructure ()
3626 MyGraphicDriver -> DisplayStructure (
3628 *( Graphic3d_CStructure* )TheStructure -> CStructure (),
3629 int ( S1Iterator.Key () -> DisplayPriority () )
3639 if ( MyViewManager -> UpdateMode () == Aspect_TOU_ASAP ) Update ();
3643 } // end Visual3d_View :: SetComputedMode
3645 Standard_Boolean Visual3d_View :: ComputedMode () const {
3647 return ComputedModeIsActive;
3649 } // end Visual3d_View :: ComputedMode
3651 void Visual3d_View :: SetBackFacingModel (
3652 const Visual3d_TypeOfBackfacingModel aModel
3657 case Visual3d_TOBM_AUTOMATIC:
3658 MyCView.Backfacing = 0;
3661 case Visual3d_TOBM_FORCE:
3662 MyCView.Backfacing = 1;
3665 case Visual3d_TOBM_DISABLE:
3666 MyCView.Backfacing = -1;
3671 MyGraphicDriver -> SetBackFacingModel ( MyCView );
3673 } // end Visual3d_View :: SetBackFacingModel
3675 Visual3d_TypeOfBackfacingModel Visual3d_View :: BackFacingModel () const {
3677 switch ( MyCView.Backfacing ) {
3680 return Visual3d_TOBM_AUTOMATIC;
3683 return Visual3d_TOBM_FORCE;
3687 return Visual3d_TOBM_DISABLE;
3689 } // end Visual3d_View :: BackFacingModel
3691 void Visual3d_View::EnableDepthTest( const Standard_Boolean enable ) const
3693 MyGraphicDriver->SetDepthTestEnabled( MyCView, enable );
3696 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
3698 return MyGraphicDriver->IsDepthTestEnabled( MyCView );
3701 void Visual3d_View::ReadDepths(const Standard_Integer x,
3702 const Standard_Integer y,
3703 const Standard_Integer width,
3704 const Standard_Integer height,
3705 const Standard_Address buffer) const
3707 MyGraphicDriver->ReadDepths( MyCView, x, y, width, height, buffer );
3710 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
3711 const Standard_Integer theHeight)
3713 return MyGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
3716 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
3718 MyGraphicDriver->FBORelease( MyCView, theFBOPtr );
3721 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
3722 Standard_Integer& theWidth, Standard_Integer& theHeight,
3723 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
3725 MyGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
3726 theWidth, theHeight,
3727 theWidthMax, theHeightMax );
3730 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
3731 const Standard_Integer theWidth, const Standard_Integer theHeight)
3733 MyGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
3734 theWidth, theHeight );
3737 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
3738 const Graphic3d_BufferType& theBufferType)
3740 return MyGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
3743 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
3745 MyGraphicDriver->SetGLLightEnabled( MyCView, enable );
3749 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
3751 return MyGraphicDriver->IsGLLightEnabled( MyCView );
3754 Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
3755 const Graphic3d_ExportFormat theFormat,
3756 const Graphic3d_SortType theSortType,
3757 const Standard_Real thePrecision,
3758 const Standard_Address theProgressBarFunc,
3759 const Standard_Address theProgressObject) const
3761 Handle(Visual3d_Layer) anUnderLayer = MyViewManager->UnderLayer();
3762 Handle(Visual3d_Layer) anOverLayer = MyViewManager->OverLayer();
3764 Aspect_CLayer2d anOverCLayer;
3765 Aspect_CLayer2d anUnderCLayer;
3766 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
3768 if (!anOverLayer.IsNull())
3769 anOverCLayer = anOverLayer->CLayer();
3770 if (!anUnderLayer.IsNull())
3771 anUnderCLayer = anUnderLayer->CLayer();
3773 Standard_Integer aWidth, aHeight;
3774 Window()->Size (aWidth, aHeight);
3776 return MyGraphicDriver->Export (theFileName, theFormat, theSortType,
3777 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
3778 thePrecision, theProgressBarFunc, theProgressObject);
3781 //=======================================================================
3782 //function : AddZLayer
3784 //=======================================================================
3786 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
3788 MyGraphicDriver->AddZLayer (MyCView, theLayerId);
3791 //=======================================================================
3792 //function : RemoveZLayer
3794 //=======================================================================
3796 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
3798 MyGraphicDriver->RemoveZLayer (MyCView, theLayerId);
3801 //=======================================================================
3802 //function : ChangeZLayer
3804 //=======================================================================
3806 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
3807 const Standard_Integer theLayerId)
3809 MyGraphicDriver->ChangeZLayer (
3810 (*(Graphic3d_CStructure*)theStructure->CStructure()), MyCView, theLayerId);