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 activation/desactivation of ZBuffer should be automatic
1781 // depending on the presence or absence of facets.
1782 if (MyViewManager->ZBufferAuto ()) {
1783 Standard_Boolean BContainsFacet = ContainsFacet ();
1784 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1785 // If the view contains facets
1786 // and if ZBuffer is not active
1787 if (BContainsFacet && ! BZBuffer)
1788 SetZBufferActivity (1);
1789 // If the view does not contain facets
1790 // and if ZBuffer is active
1791 if (! BContainsFacet && BZBuffer)
1792 SetZBufferActivity (0);
1795 Aspect_CLayer2d OverCLayer;
1796 Aspect_CLayer2d UnderCLayer;
1797 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1798 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1799 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1800 //OSD::SetSignal (Standard_False);
1801 MyGraphicDriver->Update (MyCView, UnderCLayer, OverCLayer);
1802 //OSD::SetSignal (Standard_True);
1806 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const {
1808 // Return type of visualization of the view
1809 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
1811 // Return type of visualization of the structure
1812 Graphic3d_TypeOfStructure StructType = AStructure->Visual ();
1814 Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO;
1816 if (StructType == Graphic3d_TOS_ALL)
1817 // The structure accepts any type of view
1818 Result = Visual3d_TOA_YES;
1820 if ((StructType == Graphic3d_TOS_SHADING)
1821 && (ViewType == Visual3d_TOV_SHADING))
1822 Result = Visual3d_TOA_YES;
1823 if ((StructType == Graphic3d_TOS_WIREFRAME)
1824 && (ViewType == Visual3d_TOV_WIREFRAME))
1825 Result = Visual3d_TOA_YES;
1826 if ((StructType == Graphic3d_TOS_COMPUTED)
1827 && (ViewType == Visual3d_TOV_WIREFRAME))
1828 Result = Visual3d_TOA_COMPUTE;
1829 if ((StructType == Graphic3d_TOS_COMPUTED)
1830 && (ViewType == Visual3d_TOV_SHADING))
1831 Result = Visual3d_TOA_COMPUTE;
1835 if (Result == Visual3d_TOA_YES)
1836 cout << "YES = Visual3d_View" << MyCView.ViewId
1837 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1838 if (Result == Visual3d_TOA_NO)
1839 cout << "NO = Visual3d_View" << MyCView.ViewId
1840 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1841 if (Result == Visual3d_TOA_COMPUTE)
1842 cout << "COMPUTE = Visual3d_View" << MyCView.ViewId
1843 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1851 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer /*OldPriority*/, const Standard_Integer NewPriority) {
1853 if (IsDeleted ()) return;
1854 if (! IsDefined ()) return;
1855 if (! IsActive ()) return;
1856 if (! IsDisplayed (AStructure)) return;
1858 Standard_Integer Index = IsComputed (AStructure);
1859 if (Index != 0 && ComputedMode())
1862 Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification ();
1863 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1864 << AStructure->Identification () << "/" << StructId
1865 << ", " << OldPriority << ", " << NewPriority << ")\n";
1868 MyGraphicDriver->EraseStructure
1870 *(Graphic3d_CStructure *)
1871 MyCOMPUTEDSequence.Value (Index)->CStructure ());
1872 MyGraphicDriver->DisplayStructure
1874 *(Graphic3d_CStructure *)
1875 MyCOMPUTEDSequence.Value (Index)->CStructure (),
1880 Standard_Integer StructId = AStructure->Identification ();
1881 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1882 << AStructure->Identification () << "/" << StructId
1883 << ", " << OldPriority << ", " << NewPriority << ")\n";
1886 MyGraphicDriver->EraseStructure
1888 *(Graphic3d_CStructure *)AStructure->CStructure ());
1889 MyGraphicDriver->DisplayStructure
1891 *(Graphic3d_CStructure *)AStructure->CStructure (),
1897 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
1900 cout << "Visual3d_View" << MyCView.ViewId << "::Clear ("
1901 << AStructure->Identification () << ")\n";
1905 Standard_Integer Index = IsComputed (AStructure);
1908 cout << "Structure " << AStructure->Identification ()
1909 << " calculated in the view "
1910 << Identification () << ", by structure "
1911 << MyCOMPUTEDSequence.Value (Index)->Identification ()
1912 << " is emptied.\n";
1915 MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction);
1916 MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False);
1921 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
1923 #ifdef TRACE_CONNECT
1924 cout << "Visual3d_View" << MyCView.ViewId << "::Connect ("
1925 << AMother->Identification ()
1926 << ADaughter->Identification () << ")\n";
1930 Standard_Integer IndexM = IsComputed (AMother);
1931 Standard_Integer IndexD = IsComputed (ADaughter);
1933 if (IndexM != 0 && IndexD != 0) {
1934 #ifdef TRACE_CONNECT
1935 cout << "Structure " << AMother->Identification ()
1936 << " is connected to structure "
1937 << ADaughter->Identification () << endl;
1938 cout << "These structures are calculated.\n";
1939 cout << "In the view " << Identification ()
1941 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
1942 << " is connected to the structure "
1943 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
1946 MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD));
1951 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
1953 #ifdef TRACE_CONNECT
1954 cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect ("
1955 << AMother->Identification ()
1956 << ADaughter->Identification () << ")\n";
1960 Standard_Integer IndexM = IsComputed (AMother);
1961 Standard_Integer IndexD = IsComputed (ADaughter);
1963 if (IndexM != 0 && IndexD != 0) {
1964 #ifdef TRACE_CONNECT
1965 cout << "Structure " << AMother->Identification ()
1966 << " is disconnected from the structure "
1967 << ADaughter->Identification () << endl;
1968 cout << "These structures are calculated.\n";
1969 cout << "In the view " << Identification ()
1971 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
1972 << " is disconnected from the structure "
1973 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
1976 MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD));
1981 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure) {
1983 Display (AStructure, MyViewManager->UpdateMode ());
1987 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
1989 if (IsDeleted ()) return;
1990 if (! IsDefined ()) return;
1991 if (! IsActive ()) return;
1993 // If Display on a structure present in the list
1994 // of calculated structures while it is not
1995 // or more, of calculated type =>
1996 // - removes it as well as the associated old computed
1997 // THis happens when hlhsr becomes again of type e
1998 // non computed after SetVisual.
1999 Standard_Integer Index = IsComputed (AStructure);
2001 if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) {
2004 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2005 cout << "In Visual3d_View::Display, ";
2006 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2007 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2011 MyTOCOMPUTESequence.Remove (Index);
2012 MyCOMPUTEDSequence.Remove (Index);
2015 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2016 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2017 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2023 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2025 #ifdef TRACE_DISPLAY
2026 Standard_Integer StructId = AStructure->Identification ();
2027 cout << "Visual3d_View" << MyCView.ViewId << "::Display ("
2028 << StructId << ");\n";
2032 if (Answer == Visual3d_TOA_NO) {
2033 #ifdef TRACE_DISPLAY
2034 cout << "Answer : Visual3d_TOA_NO\n";
2040 if (!ComputedMode())
2042 Answer = Visual3d_TOA_YES;
2045 if (Answer == Visual3d_TOA_YES ) {
2046 #ifdef TRACE_DISPLAY
2047 cout << "Answer : Visual3d_TOA_YES\n";
2050 if (IsDisplayed (AStructure)) return;
2051 MyGraphicDriver->DisplayStructure (
2053 *(Graphic3d_CStructure *)AStructure->CStructure (),
2054 int (AStructure->DisplayPriority ())
2056 MyDisplayedStructure.Add (AStructure);
2057 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2060 if (Answer == Visual3d_TOA_COMPUTE) {
2061 #ifdef TRACE_DISPLAY
2062 cout << "Answer : Visual3d_TOA_COMPUTE\n";
2063 cout << "Index : " << Index << "\n" << flush;
2066 // Already computed, is COMPUTED still valid?
2067 #ifdef TRACE_DISPLAY
2068 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2069 cout << "Structure "
2070 << MyTOCOMPUTESequence.Value (Index)->Identification ()
2071 << "already calculated, in the view "
2072 << Identification () << ", par la structure "
2073 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2074 << "\n was not recalculated as HLR is valid\n";
2078 cout << "Structure "
2079 << MyTOCOMPUTESequence.Value (Index)->Identification ()
2080 << " already calculated, in the view "
2081 << Identification () << ", by the structure "
2082 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2083 << "\n should be recalculated as HLR is invalid\n";
2087 Standard_Integer OldStructId =
2088 MyCOMPUTEDSequence.Value (Index)->Identification ();
2090 // Case COMPUTED valide
2091 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2093 if (! IsDisplayed (AStructure)) {
2094 MyDisplayedStructure.Add (AStructure);
2095 MyGraphicDriver->DisplayStructure (
2097 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
2098 int (AStructure->DisplayPriority ())
2100 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2105 // Case COMPUTED invalid
2107 // Is there another valid representation ?
2108 // Find in the sequence of already calculated structures
2109 // 1/ Structure having the same Owner as <AStructure>
2110 // 2/ That is not <AStructure>
2111 // 3/ The COMPUTED which of is valid
2112 Standard_Integer NewIndex = HaveTheSameOwner (AStructure);
2114 // Case of COMPUTED invalid, WITH a valid of replacement
2115 if (NewIndex != 0) {
2117 if (! IsDisplayed (AStructure)) {
2118 MyCOMPUTEDSequence.SetValue
2119 (Index, MyCOMPUTEDSequence.Value (NewIndex));
2120 OldStructId = MyCOMPUTEDSequence.Value (NewIndex)->
2122 MyDisplayedStructure.Add (AStructure);
2123 MyGraphicDriver->DisplayStructure (
2125 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (NewIndex)->CStructure (),
2126 int (AStructure->DisplayPriority ())
2128 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2133 // Cas COMPUTED invalid, WITHOUT a valid of replacement
2135 // COMPUTED is removed if displayed
2136 if (IsDisplayed (AStructure))
2137 MyGraphicDriver->EraseStructure (
2139 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()
2143 } // if (Index != 0)
2145 // Compute + Validation
2147 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
2149 Handle(Graphic3d_Structure) TheStructure;
2150 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
2151 AStructure->Transform (ATrsf);
2153 TColStd_Array2OfReal Ident (0, 3, 0, 3);
2154 Standard_Integer ii, jj;
2155 for (ii=0; ii<=3; ii++)
2156 for (jj=0; jj<=3; jj++)
2157 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
2158 TheStructure = MyCOMPUTEDSequence.Value (Index);
2159 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
2160 if (AStructure->IsTransformed ()) {
2161 AStructure->Compute (this, ATrsf, TheStructure);
2164 AStructure->Compute (this, TheStructure);
2168 if (AStructure->IsTransformed ()) {
2169 TheStructure = AStructure->Compute (this, ATrsf);
2172 TheStructure = AStructure->Compute (this);
2176 TheStructure->SetHLRValidation (Standard_True);
2179 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2180 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2181 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2185 // TOCOMPUTE and COMPUTED associated to sequences are added
2186 MyTOCOMPUTESequence.Append (AStructure);
2187 MyCOMPUTEDSequence.Append (TheStructure);
2190 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2191 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2192 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2196 // The previous are removed if necessary
2198 MyTOCOMPUTESequence.Remove (Index);
2199 MyCOMPUTEDSequence.Remove (Index);
2203 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2204 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2205 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2209 // Return type of visualisation of the view
2210 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
2212 // Of which type will be the computed ?
2213 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
2214 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
2216 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
2217 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
2219 if (ComputeWireframe)
2220 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
2222 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
2224 if (! ComputeShading && ! ComputeWireframe)
2225 Answer = Visual3d_TOA_NO;
2227 Answer = AcceptDisplay (TheStructure);
2229 if (AStructure->IsHighlighted()) {
2230 TheStructure->SetHighlightColor (AStructure->HighlightColor ());
2231 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
2234 #ifdef TRACE_DISPLAY
2235 cout << "Structure " << StructId
2236 << " in the view " << Identification ()
2237 << " is calculated by the structure "
2238 << TheStructure->Identification ();
2239 if (Answer == Visual3d_TOA_YES)
2240 cout << " and displayed\n";
2242 cout << " but not displayed\n";
2246 // It is displayed only if the calculated structure
2247 // has a proper type corresponding to the one of the view.
2248 if (Answer != Visual3d_TOA_NO) {
2249 if (! IsDisplayed (AStructure))
2250 MyDisplayedStructure.Add (AStructure);
2251 MyGraphicDriver->DisplayStructure (
2253 *(Graphic3d_CStructure *)TheStructure->CStructure (),
2254 int (AStructure->DisplayPriority ())
2256 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2258 } // Visual3d_TOA_COMPUTE
2261 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure) {
2263 if (IsDeleted ()) return;
2265 Erase (AStructure, MyViewManager->UpdateMode ());
2269 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2271 Standard_Integer StructId;
2273 if (IsDeleted ()) return;
2275 // No test on window as the structure is displayed only if
2276 // the window exists, so only one test is enough.
2277 if (IsDisplayed (AStructure)) {
2278 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2280 if (!ComputedMode())
2282 Answer = Visual3d_TOA_YES;
2285 if (Answer != Visual3d_TOA_COMPUTE) {
2286 MyGraphicDriver->EraseStructure (
2288 *(Graphic3d_CStructure *)AStructure->CStructure ()
2292 if (Answer == Visual3d_TOA_COMPUTE) {
2293 Standard_Integer Index = IsComputed (AStructure);
2295 cout << "Visual3d_View" << MyCView.ViewId << "::Erase ("
2296 << AStructure->Identification () << ");\n";
2297 cout << "Index : " << Index << "\n";
2301 if (Index != 0 && ComputedMode())
2304 MyCOMPUTEDSequence.Value (Index)->Identification ();
2306 cout << "Structure " << AStructure->Identification ()
2307 << " calculated, in the view "
2308 << Identification () << ", by the structure "
2309 << StructId << " is removed. \n";
2312 MyGraphicDriver->EraseStructure
2313 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
2315 // else is impossible
2317 MyDisplayedStructure.Remove (AStructure);
2318 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2323 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
2326 cout << "Visual3d_View" << MyCView.ViewId << "::Highlight ("
2327 << AStructure->Identification () << ")\n";
2331 Standard_Integer Index = IsComputed (AStructure);
2334 cout << "Structure " << AStructure->Identification ()
2335 << " calculated, in the view "
2336 << Identification () << ", by the structure "
2337 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2338 << " passes in highlight mode.\n";
2341 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
2342 (AStructure->HighlightColor ());
2343 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod);
2348 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
2351 cout << "Visual3d_View" << MyCView.ViewId << "::Transform ("
2352 << AStructure->Identification () << ")\n";
2356 Standard_Integer Index = IsComputed (AStructure);
2359 cout << "The structure " << AStructure->Identification ()
2360 << " calculated, in the view "
2361 << Identification () << ", by the structure "
2362 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2363 << " is transformed.\n";
2366 // Test is somewhat light !
2367 // trsf is transferred only if it is :
2370 if (ATrsf (0, 1) != 0. || ATrsf (0, 2) != 0.
2371 || ATrsf (1, 0) != 0. || ATrsf (1, 2) != 0.
2372 || ATrsf (2, 0) != 0. || ATrsf (2, 1) != 0.)
2373 ReCompute (AStructure);
2375 MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf);
2380 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
2383 cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight ("
2384 << AStructure->Identification () << ")\n";
2388 Standard_Integer Index = IsComputed (AStructure);
2391 cout << "Structure " << AStructure->Identification ()
2392 << " calculated, in the view "
2393 << Identification () << ", by the structure "
2394 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2395 << " passes in unhighlight mode.\n";
2398 MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight ();
2404 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const {
2406 Standard_Integer StrId = AStructure->Identification ();
2408 Standard_Integer Result = 0;
2409 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
2411 // Recherche de la structure <AStructure> dans la
2412 // sequence des structures deja calculees
2413 for (Standard_Integer i=1; i<=Length && Result==0; i++)
2414 if ((MyTOCOMPUTESequence.Value (i))->Identification ()
2415 == StrId) Result = i;
2417 cout << "\n In the view " << Identification () << " the structure ";
2419 cout << StrId << " is calculated by "
2420 << MyCOMPUTEDSequence.Value (Result)->Identification ()
2423 cout << StrId << " is not calculated\n" << flush;
2427 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2428 cout << "In Visual3d_View::IsComputed, ";
2429 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2430 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2439 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const {
2441 Standard_Boolean Result = Standard_False;
2443 if (IsDeleted ()) return Result;
2445 Result = MyDisplayedStructure.Contains (AStructure);
2452 Standard_Boolean Visual3d_View::ContainsComputedStructure () const {
2454 Standard_Boolean Result = Standard_False;
2456 if (MyDisplayedStructure.IsEmpty ()) return Result;
2458 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
2460 Standard_Integer i = MyDisplayedStructure.Extent ();
2462 // Stop at the first structure of type TOS_COMPUTED
2463 while (! Result && Iterator.More ()) {
2465 (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED);
2467 // Iterator.Next () is located on the
2477 Standard_Boolean Visual3d_View::ContainsFacet () const {
2479 return ContainsFacet (MyDisplayedStructure);
2483 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const {
2485 Standard_Boolean Result = Standard_False;
2487 if (ASet.IsEmpty ()) return Result;
2489 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2491 // Stop at the first structure containing a facet
2492 for ( Iterator.Initialize (ASet);
2493 Iterator.More () && ! Result;
2495 Result = (Iterator.Key ())->ContainsFacet ();
2501 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
2504 (MyDisplayedStructure, XMin, YMin, ZMin, XMax, YMax, ZMax);
2508 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 {
2510 if (ASet.IsEmpty ()) {
2511 XMin = RealFirst ();
2512 YMin = RealFirst ();
2513 ZMin = RealFirst ();
2521 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2522 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2528 XMax = RealFirst ();
2529 YMax = RealFirst ();
2530 ZMax = RealFirst ();
2532 for ( Iterator.Initialize (ASet);
2536 if ( (Iterator.Key ())->IsInfinite ()){
2537 //XMin, YMin .... ZMax are initialized by means of infinite line data
2538 (Iterator.Key ())->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
2539 if ( Xm != RealFirst() && Xm < XMin )
2541 if ( Ym != RealFirst() && Ym < YMin )
2543 if ( Zm != RealFirst() && Zm < ZMin )
2545 if ( XM != RealLast() && XM > XMax )
2547 if ( YM != RealLast() && YM > YMax )
2549 if ( ZM != RealLast() && ZM > ZMax )
2552 // Only non-empty and non-infinite structures
2553 // are taken into account for calculation of MinMax
2554 if (! (Iterator.Key ())->IsInfinite () &&
2555 ! (Iterator.Key ())->IsEmpty ()) {
2556 (Iterator.Key ())->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
2557 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
2558 //"FitAll" operation ignores object with transform persitence parameter
2559 if( (Iterator.Key ())->TransformPersistenceMode() == Graphic3d_TMF_None )
2561 if (Xm < XMin) XMin = Xm;
2562 if (Ym < YMin) YMin = Ym;
2563 if (Zm < ZMin) ZMin = Zm;
2564 if (XM > XMax) XMax = XM;
2565 if (YM > YMax) YMax = YM;
2566 if (ZM > ZMax) ZMax = ZM;
2571 // The following cases are relevant
2572 // For exemple if all structures are empty or infinite
2573 if (XMax < XMin) { Xm = XMin; XMin = XMax; XMax = Xm; }
2574 if (YMax < YMin) { Ym = YMin; YMin = YMax; YMax = Ym; }
2575 if (ZMax < ZMin) { Zm = ZMin; ZMin = ZMax; ZMax = Zm; }
2577 Standard_Real Sx, Sy, Sz;
2578 MyViewOrientation.AxialScale(Sx, Sy, Sz);
2579 XMin = (Sx > 1. && XMin < RealFirst ()/Sx)?RealFirst (): XMin*Sx;
2580 XMax = (Sx > 1. && XMax > RealLast ()/Sx)?RealLast (): XMax*Sx;
2581 YMin = (Sy > 1. && YMin < RealFirst ()/Sy)?RealFirst (): YMin*Sy;
2582 YMax = (Sy > 1. && YMax > RealLast ()/Sy)?RealLast (): YMax*Sy;
2583 ZMin = (Sz > 1. && ZMin < RealFirst ()/Sz)?RealFirst (): ZMin*Sz;
2584 ZMax = (Sz > 1. && ZMax > RealLast ()/Sz)?RealLast (): ZMax*Sz;
2587 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2589 MinMaxValues (MyDisplayedStructure, XMin, YMin, XMax, YMax);
2593 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2595 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2596 Standard_Real Xp, Yp, Zp;
2598 MinMaxValues (ASet, Xm, Ym, Zm, XM, YM, ZM);
2600 Projects (Xm, Ym, Zm, Xp, Yp, Zp);
2604 Projects (XM, YM, ZM, Xp, Yp, Zp);
2608 if (XMax < XMin) { Xp = XMax; XMax = XMin; XMin = Xp; }
2609 if (YMax < YMin) { Yp = YMax; YMax = YMin; YMin = Yp; }
2612 const TColStd_Array2OfReal& Visual3d_View::MatrixOfOrientation () {
2614 if (! MyMatOfOriIsEvaluated) {
2615 MyGraphicDriver->InquireMat
2616 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2617 MyMatOfMapIsEvaluated = Standard_True;
2618 MyMatOfOriIsEvaluated = Standard_True;
2621 return (MyMatrixOfOrientation);
2625 const TColStd_Array2OfReal& Visual3d_View::MatrixOfMapping () {
2627 if (! MyMatOfMapIsEvaluated) {
2628 MyGraphicDriver->InquireMat
2629 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2630 MyMatOfMapIsEvaluated = Standard_True;
2631 MyMatOfOriIsEvaluated = Standard_True;
2634 return (MyMatrixOfMapping);
2638 Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const {
2640 Standard_Integer Result = MyDisplayedStructure.Extent ();
2647 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 {
2649 math_Vector PtDC (0,3), PtWC (0,3);
2652 // Otherwise use new on Visual3d_View (constructor+destructor)
2653 // as Projects is a const method or MatrixOfOrientation and
2654 // MatrixOfMapping is not.
2655 Visual3d_View * const newthis = (Visual3d_View * const) this;
2656 newthis->MatrixOfOrientation ();
2657 newthis->MatrixOfMapping ();
2659 // World Coordinate Space
2665 // WCS -> View Reference Coordinate Space
2666 math_Vector PtVRC(0,3);
2667 PtVRC = MyMatrixOfOrientation.Multiplied (PtWC);
2669 // VRCS -> Normalized Projection Coordinate Space
2670 math_Vector PtNPC(0,3);
2671 PtNPC = MyMatrixOfMapping.Multiplied (PtVRC);
2672 for (Standard_Integer i=0; i<3; i++) PtNPC (i) = PtNPC (i) / PtNPC (3);
2675 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2676 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2679 Standard_Real Ratio;
2681 // NPCS -> Device Coordinate Space
2682 Standard_Real Dx = Standard_Real (MyCView.DefWindow.dx);
2683 Standard_Real Dy = Standard_Real (MyCView.DefWindow.dy);
2686 PtDC (0) = PtNPC (0) * Dx;
2687 PtDC (1) = Dy - PtNPC (1) * Dy * Ratio;
2689 printf("Display coordinates : %f,%f,%f,%f\n",
2690 PtDC(0),PtDC(1),PtDC(2),PtDC(3));
2693 // NPCS -> Window Space
2694 Standard_Real um, vm, uM, vM;
2695 MyViewMapping.WindowLimit (um, vm, uM, vM);
2697 Ratio = (uM - um) / (vM - vm);
2699 PtNPC (1) = PtNPC (1) * Ratio;
2701 PtNPC (0) = PtNPC (0) / Ratio;
2704 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2705 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2708 Standard_Real fpd = MyViewMapping.FrontPlaneDistance ();
2709 Standard_Real bpd = MyViewMapping.BackPlaneDistance ();
2712 * Coordinates of PtNPC are described in the space
2713 * [0-1]x[0-1]x[0-1].
2714 * It is necessary to transform x and y in the window space.
2715 * It is necessary to transform z in the space of back and front
2716 * plane, taking into account clipping planes.
2717 * Z clipping planes are defined between 0 and 1.
2720 APX = PtNPC (0) * (uM - um) + um;
2721 APY = PtNPC (1) * (vM - vm) + vm;
2722 APZ = PtNPC (2) * (fpd - bpd) + bpd;
2725 Standard_Integer l,c;
2726 printf("OrientationMatrix :");
2727 for( l=0 ; l<4 ; l++ ) {
2728 printf("\n %d->",l);
2729 for( c=0 ; c<4 ; c++ ) {
2730 printf(" %f ,",MyMatrixOfOrientation(c,l));
2734 printf("MappingMatrix :");
2735 for( l=0 ; l<4 ; l++ ) {
2736 printf("\n %d->",l);
2737 for( c=0 ; c<4 ; c++ ) {
2738 printf(" %f ,",MyMatrixOfMapping(c,l));
2742 printf("World coordinates : %f,%f,%f,%f\n",
2743 PtWC(0),PtWC(1),PtWC(2),PtWC(3));
2744 printf("View coordinates : %f,%f,%f,%f\n",
2745 PtVRC(0),PtVRC(1),PtVRC(2),PtVRC(3));
2746 printf("Display coordinates : %f,%f,%f,%f\n",
2747 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2748 printf("Window limit : %f,%f,%f,%f\n",um,vm,uM,vM);
2749 printf("Ratio : %f\n",Ratio);
2750 printf("Front-plane : %f back-plane : %f\n",fpd,bpd);
2751 printf("Projection : %f,%f,%f\n \n",APX,APY,APZ);
2755 #endif /* OLD_METHOD */
2757 // OCC18942: This method is likely to duplicate Visual3d_ViewManager::ConvertCoord() one,
2758 // therefore it is necessary to consider merging the two methods or making them call the same
2759 // graphic driver's method after OCCT 6.3.
2760 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) {
2762 Standard_Real PtX, PtY, PtZ, PtT;
2764 static Standard_Real Ratio, um, vm, uM, vM;
2765 static Standard_Real fpd, bpd;
2767 if (! MyMatOfOriIsEvaluated || ! MyMatOfMapIsEvaluated) {
2768 MyGraphicDriver->InquireMat
2769 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2770 MyMatOfOriIsEvaluated = MyMatOfMapIsEvaluated = Standard_True;
2773 // WCS -> View Reference Coordinate Space
2774 PtX = MyMatrixOfOrientation (0, 0) * AX
2775 + MyMatrixOfOrientation (0, 1) * AY
2776 + MyMatrixOfOrientation (0, 2) * AZ
2777 + MyMatrixOfOrientation (0, 3);
2778 PtY = MyMatrixOfOrientation (1, 0) * AX
2779 + MyMatrixOfOrientation (1, 1) * AY
2780 + MyMatrixOfOrientation (1, 2) * AZ
2781 + MyMatrixOfOrientation (1, 3);
2782 PtZ = MyMatrixOfOrientation (2, 0) * AX
2783 + MyMatrixOfOrientation (2, 1) * AY
2784 + MyMatrixOfOrientation (2, 2) * AZ
2785 + MyMatrixOfOrientation (2, 3);
2786 PtT = MyMatrixOfOrientation (3, 0) * AX
2787 + MyMatrixOfOrientation (3, 1) * AY
2788 + MyMatrixOfOrientation (3, 2) * AZ
2789 + MyMatrixOfOrientation (3, 3);
2791 // VRCS -> Normalized Projection Coordinate Space
2792 APX = MyMatrixOfMapping (0, 0) * PtX
2793 + MyMatrixOfMapping (0, 1) * PtY
2794 + MyMatrixOfMapping (0, 2) * PtZ
2795 + MyMatrixOfMapping (0, 3) * PtT;
2796 APY = MyMatrixOfMapping (1, 0) * PtX
2797 + MyMatrixOfMapping (1, 1) * PtY
2798 + MyMatrixOfMapping (1, 2) * PtZ
2799 + MyMatrixOfMapping (1, 3) * PtT;
2800 APZ = MyMatrixOfMapping (2, 0) * PtX
2801 + MyMatrixOfMapping (2, 1) * PtY
2802 + MyMatrixOfMapping (2, 2) * PtZ
2803 + MyMatrixOfMapping (2, 3) * PtT;
2804 APT = MyMatrixOfMapping (3, 0) * PtX
2805 + MyMatrixOfMapping (3, 1) * PtY
2806 + MyMatrixOfMapping (3, 2) * PtZ
2807 + MyMatrixOfMapping (3, 3) * PtT;
2813 // NPCS -> Window Space
2814 MyViewMapping.WindowLimit (um, vm, uM, vM);
2815 fpd = MyViewMapping.FrontPlaneDistance ();
2816 bpd = MyViewMapping.BackPlaneDistance ();
2818 if(MyCView.Mapping.IsCustomMatrix) {
2819 // OCC18942: SAN - If orientation and mapping matrices are those used by OpenGL
2820 // visualization, then X, Y and Z coordinates normally vary between -1 and 1
2821 APX = ( APX + 1 ) * 0.5 * (uM - um) + um;
2822 APY = ( APY + 1 ) * 0.5 * (vM - vm) + vm;
2824 Ratio = (uM - um) / (vM - vm);
2831 * Coordinates of APX, APY, APZ are described in the space
2832 * [0-1]x[0-1]x[0-1].
2833 * It is necessary to transform x and y in the window space.
2834 * It is necessary to transform z in the space of back and front
2835 * plane, taking into account clipping planes.
2836 * Z clipping planes are defined between 0 and 1.
2838 APX = APX * (uM - um) + um;
2839 APY = APY * (vM - vm) + vm;
2841 APZ = APZ * (fpd - bpd) + bpd;
2844 Standard_Integer Visual3d_View::Identification () const {
2846 return (Standard_Integer (MyCView.ViewId));
2851 Standard_Boolean Visual3d_View::ZBufferIsActivated () const {
2853 if (IsDeleted ()) return (Standard_False);
2855 if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);
2857 // -1 => not forced by the programmer => depends on the type of visualisation
2858 // 0 ou 1 => forced by the programmer
2860 if (MyCView.Context.ZBufferActivity == -1)
2861 if (MyContext.Visualization () == Visual3d_TOV_SHADING)
2862 return (Standard_True);
2864 return (Standard_False);
2866 if (MyCView.Context.ZBufferActivity)
2867 return (Standard_True);
2869 return (Standard_False);
2873 void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {
2875 if (IsDeleted ()) return;
2877 if ((! IsDefined ()) || (! IsActive ())) return;
2879 MyGraphicDriver->Transparency (MyCView, AnActivity);
2883 void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {
2885 if (MyCView.Context.ZBufferActivity == AnActivity) return;
2887 if (IsDeleted ()) return;
2889 if ((! IsDefined ()) || (! IsActive ())) return;
2891 MyCView.Context.ZBufferActivity = AnActivity;
2892 MyGraphicDriver->SetVisualisation (MyCView);
2896 void Visual3d_View::UpdateView () {
2898 MyCView.Context.Aliasing = (MyContext.AliasingIsOn () ? 1:0);
2899 MyCView.Context.BackZClipping =
2900 (MyContext.BackZClippingIsOn () ? 1:0);
2901 MyCView.Context.FrontZClipping =
2902 (MyContext.FrontZClippingIsOn() ? 1:0);
2903 MyCView.Context.DepthCueing =
2904 (MyContext.DepthCueingIsOn () ? 1:0);
2906 MyCView.Context.ZClipFrontPlane =
2907 float (MyContext.ZClippingFrontPlane ());
2908 MyCView.Context.ZClipBackPlane =
2909 float (MyContext.ZClippingBackPlane ());
2910 MyCView.Context.DepthFrontPlane =
2911 float (MyContext.DepthCueingFrontPlane ());
2912 MyCView.Context.DepthBackPlane =
2913 float (MyContext.DepthCueingBackPlane ());
2915 MyCView.Context.Model = int (MyContext.Model ());
2916 MyCView.Context.Visualization = int (MyContext.Visualization ());
2918 MyCView.Context.TextureEnv = MyContext.TextureEnv();
2919 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
2923 void Visual3d_View::Compute () {
2926 Standard_Integer Length = MyCOMPUTEDSequence.Length ();
2927 for (i=1; i<=Length; i++)
2928 (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);
2930 if (!ComputedMode())
2936 * Force HLRValidation to False on all structures
2937 * calculated in the view.
2940 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2941 cout << "In Visual3d_View::Compute, ";
2942 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2943 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2949 * Change of orientation or of projection type =>
2950 * Remove structures that were calculated for the
2951 * previous orientation.
2952 * Recalculation of new structures.
2954 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
2955 Visual3d_TypeOfAnswer Answer;
2957 i = MyDisplayedStructure.Extent ();
2959 Graphic3d_SequenceOfStructure FooSequence;
2961 while (S1Iterator.More ()) {
2962 Answer = AcceptDisplay (S1Iterator.Key ());
2963 // If the structure was calculated, it is recalculated.
2964 if (Answer == Visual3d_TOA_COMPUTE) {
2966 cout << "AcceptDisplay ("
2967 << (S1Iterator.Key ())->Identification ()
2968 << ") == Visual3d_TOA_COMPUTE;\n";
2971 //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
2972 FooSequence.Append (S1Iterator.Key ());
2975 // S1Iterator.Next () is located on the next structure
2979 Length = FooSequence.Length ();
2980 // All stored structures are displayed
2981 for (i=1; i<=Length; i++)
2982 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
2983 if (Length != 0) FooSequence.Clear ();
2987 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
2988 if (!ComputedMode()) return;
2990 if (IsDeleted ()) return;
2992 if ((! IsDefined ()) || (! IsActive ())) return;
2994 if (! MyWindow->IsMapped ()) return;
2996 if (! AStructure->IsDisplayed ()) return;
2998 Visual3d_TypeOfAnswer Answer;
3000 Answer = AcceptDisplay (AStructure);
3002 if (Answer == Visual3d_TOA_COMPUTE) {
3003 Standard_Integer Index = IsComputed (AStructure);
3006 cout << "Structure " << AStructure->Identification ()
3007 << " is not calculated in the view "
3008 << Identification () << "\n";
3013 Standard_Integer OldStructId, NewStructId;
3015 MyCOMPUTEDSequence.Value (Index)->Identification ();
3017 Standard_Integer StructId = AStructure->Identification ();
3018 cout << "Structure " << StructId
3019 << " calculated, in the view "
3020 << Identification () << ", by the structure "
3021 << OldStructId << " is recalculated.\n";
3025 // Compute + Validation
3027 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3029 Handle(Graphic3d_Structure) TheStructure;
3030 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3031 AStructure->Transform (ATrsf);
3033 TColStd_Array2OfReal Ident (0, 3, 0, 3);
3034 Standard_Integer ii, jj;
3035 for (ii=0; ii<=3; ii++)
3036 for (jj=0; jj<=3; jj++)
3037 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3038 TheStructure = MyCOMPUTEDSequence.Value (Index);
3039 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3040 if (AStructure->IsTransformed ()) {
3041 AStructure->Compute (this, ATrsf, TheStructure);
3044 AStructure->Compute (this, TheStructure);
3048 if (AStructure->IsTransformed ()) {
3049 TheStructure = AStructure->Compute (this, ATrsf);
3052 TheStructure = AStructure->Compute (this);
3056 TheStructure->SetHLRValidation (Standard_True);
3058 // Return type of visualisation of the view
3059 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3061 // Of which type will be the computed ?
3062 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3063 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
3065 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3066 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3068 if (ComputeWireframe)
3069 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3071 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3073 if (AStructure->IsHighlighted ()) {
3074 TheStructure->SetHighlightColor
3075 (AStructure->HighlightColor ());
3076 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3080 // Find structure <AStructure>
3081 // in the sequence of structures to be calculated.
3082 NewStructId = TheStructure->Identification ();
3084 // The previous calculation is removed and the new one is dislayed
3085 MyGraphicDriver->EraseStructure (
3087 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3088 MyGraphicDriver->DisplayStructure (
3090 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3091 int (AStructure->DisplayPriority ())
3095 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3096 cout << "In Visual3d_View::ReCompute, ";
3097 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3098 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3103 // hlhsr and the new associated compute are added
3104 MyTOCOMPUTESequence.Append (AStructure);
3105 MyCOMPUTEDSequence.Append (TheStructure);
3108 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3109 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3110 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3114 // hlhsr and the new associated compute are removed
3116 MyTOCOMPUTESequence.Remove (Index);
3117 MyCOMPUTEDSequence.Remove (Index);
3120 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3121 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3122 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3130 const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver () const {
3132 return MyGraphicDriver;
3136 void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& thePlotter) const
3138 for (Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure); S1Iterator.More(); S1Iterator.Next())
3140 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3141 // displayed structure is plotted as if it was not calculated
3143 (S1Iterator.Key ())->Plot (thePlotter);
3145 (MyCOMPUTEDSequence.Value (Index))->Plot (thePlotter);
3149 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const {
3151 Standard_Integer Result = 0;
3152 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3154 // Find in the sequence of already calculated structures
3155 // 1/ Structure with the same Owner as <AStructure>
3156 // 2/ Which is not <AStructure>
3157 // 3/ COMPUTED which of is valid
3158 for (Standard_Integer i=1; i<=Length && Result==0; i++)
3159 if ((MyTOCOMPUTESequence.Value (i)->Owner () == AStructure->Owner ())
3160 && (MyTOCOMPUTESequence.Value (i)->Identification () !=
3161 AStructure->Identification ())
3162 && (MyCOMPUTEDSequence.Value (i)->HLRValidation ())) Result = i;
3168 Standard_Address Visual3d_View::CView () const {
3170 return Standard_Address (&MyCView);
3175 // Triedron methods : the Triedron is a non-zoomable object.
3177 void Visual3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
3178 const Quantity_NameOfColor YColor,
3179 const Quantity_NameOfColor ZColor,
3180 const Standard_Real SizeRatio,
3181 const Standard_Real AxisDiametr,
3182 const Standard_Integer NbFacettes) {
3183 MyGraphicDriver->ZBufferTriedronSetup(XColor, YColor, ZColor,
3184 SizeRatio, AxisDiametr, NbFacettes);
3189 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
3190 const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) {
3192 MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe);
3196 void Visual3d_View::TriedronErase () {
3198 MyGraphicDriver->TriedronErase (MyCView);
3203 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {
3205 MyGraphicDriver->TriedronEcho (MyCView,AType);
3209 Standard_Boolean checkFloat(const Standard_Real value)
3211 return value > -FLT_MAX && value < FLT_MAX;
3214 void SetMinMaxValuesCallback(void* Visual3dView)
3216 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
3218 Handle(Visual3d_View) view = (Handle(Visual3d_View)&) Visual3dView;
3219 view->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax);
3221 if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) &&
3222 checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax))
3224 Handle(Graphic3d_GraphicDriver) driver = Handle(Graphic3d_GraphicDriver)::DownCast(view->GraphicDriver());
3225 driver->GraduatedTrihedronMinMaxValues((Standard_ShortReal)xmin, (Standard_ShortReal)ymin, (Standard_ShortReal)zmin,
3226 (Standard_ShortReal)xmax, (Standard_ShortReal)ymax, (Standard_ShortReal)zmax);
3230 Standard_Boolean Visual3d_View::GetGraduatedTrihedron
3231 (/* Names of axes */
3232 TCollection_ExtendedString& xname,
3233 TCollection_ExtendedString& yname,
3234 TCollection_ExtendedString& zname,
3236 Standard_Boolean& xdrawname,
3237 Standard_Boolean& ydrawname,
3238 Standard_Boolean& zdrawname,
3240 Standard_Boolean& xdrawvalues,
3241 Standard_Boolean& ydrawvalues,
3242 Standard_Boolean& zdrawvalues,
3244 Standard_Boolean& drawgrid,
3246 Standard_Boolean& drawaxes,
3247 /* Number of splits along axes */
3248 Standard_Integer& nbx,
3249 Standard_Integer& nby,
3250 Standard_Integer& nbz,
3251 /* Offset for drawing values */
3252 Standard_Integer& xoffset,
3253 Standard_Integer& yoffset,
3254 Standard_Integer& zoffset,
3255 /* Offset for drawing names of axes */
3256 Standard_Integer& xaxisoffset,
3257 Standard_Integer& yaxisoffset,
3258 Standard_Integer& zaxisoffset,
3259 /* Draw tickmarks */
3260 Standard_Boolean& xdrawtickmarks,
3261 Standard_Boolean& ydrawtickmarks,
3262 Standard_Boolean& zdrawtickmarks,
3263 /* Length of tickmarks */
3264 Standard_Integer& xtickmarklength,
3265 Standard_Integer& ytickmarklength,
3266 Standard_Integer& ztickmarklength,
3268 Quantity_Color& gridcolor,
3269 /* Colors of axis names */
3270 Quantity_Color& xnamecolor,
3271 Quantity_Color& ynamecolor,
3272 Quantity_Color& znamecolor,
3273 /* Colors of axis and values */
3274 Quantity_Color& xcolor,
3275 Quantity_Color& ycolor,
3276 Quantity_Color& zcolor,
3277 /* Name of font for names of axes */
3278 TCollection_AsciiString& fontOfNames,
3279 /* Style of names of axes */
3280 Font_FontAspect& styleOfNames,
3281 /* Size of names of axes */
3282 Standard_Integer& sizeOfNames,
3283 /* Name of font for values */
3284 TCollection_AsciiString& fontOfValues,
3285 /* Style of values */
3286 Font_FontAspect& styleOfValues,
3287 /* Size of values */
3288 Standard_Integer& sizeOfValues) const
3290 if (!MyGTrihedron.ptrVisual3dView)
3291 return Standard_False;
3294 xname = MyGTrihedron.xname;
3295 yname = MyGTrihedron.yname;
3296 zname = MyGTrihedron.zname;
3298 xdrawname = MyGTrihedron.xdrawname;
3299 ydrawname = MyGTrihedron.ydrawname;
3300 zdrawname = MyGTrihedron.zdrawname;
3302 xdrawvalues = MyGTrihedron.xdrawvalues;
3303 ydrawvalues = MyGTrihedron.ydrawvalues;
3304 zdrawvalues = MyGTrihedron.zdrawvalues;
3306 drawgrid = MyGTrihedron.drawgrid;
3308 drawaxes = MyGTrihedron.drawaxes;
3309 /* Number of splits along axes */
3310 nbx = MyGTrihedron.nbx;
3311 nby = MyGTrihedron.nby;
3312 nbz = MyGTrihedron.nbz;
3313 /* Offset for drawing values */
3314 xoffset = MyGTrihedron.xoffset;
3315 yoffset = MyGTrihedron.yoffset;
3316 zoffset = MyGTrihedron.zoffset;
3317 /* Offset for drawing names of axes */
3318 xaxisoffset = MyGTrihedron.xaxisoffset;
3319 yaxisoffset = MyGTrihedron.yaxisoffset;
3320 zaxisoffset = MyGTrihedron.zaxisoffset;
3321 /* Draw tickmarks */
3322 xdrawtickmarks = MyGTrihedron.xdrawtickmarks;
3323 ydrawtickmarks = MyGTrihedron.ydrawtickmarks;
3324 zdrawtickmarks = MyGTrihedron.zdrawtickmarks;
3325 /* Length of tickmarks */
3326 xtickmarklength = MyGTrihedron.xtickmarklength;
3327 ytickmarklength = MyGTrihedron.ytickmarklength;
3328 ztickmarklength = MyGTrihedron.ztickmarklength;
3330 gridcolor = MyGTrihedron.gridcolor;
3331 /* Colors of axis names */
3332 xnamecolor = MyGTrihedron.xnamecolor;
3333 ynamecolor = MyGTrihedron.ynamecolor;
3334 znamecolor = MyGTrihedron.znamecolor;
3335 /* Colors of axis and values */
3336 xcolor = MyGTrihedron.xcolor;
3337 ycolor = MyGTrihedron.ycolor;
3338 zcolor = MyGTrihedron.zcolor;
3339 /* Name of font for names of axes */
3340 fontOfNames = MyGTrihedron.fontOfNames;
3341 /* Style of names of axes */
3342 styleOfNames = MyGTrihedron.styleOfNames;
3343 /* Size of names of axes */
3344 sizeOfNames = MyGTrihedron.sizeOfNames;
3345 /* Name of font for values */
3346 fontOfValues = MyGTrihedron.fontOfValues;
3347 /* Style of values */
3348 styleOfValues = MyGTrihedron.styleOfValues;
3349 /* Size of values */
3350 sizeOfValues = MyGTrihedron.sizeOfValues;
3352 return Standard_True;
3355 void Visual3d_View::GraduatedTrihedronDisplay
3356 (/* Names of axes */
3357 const TCollection_ExtendedString &xname,
3358 const TCollection_ExtendedString &yname,
3359 const TCollection_ExtendedString &zname,
3361 const Standard_Boolean xdrawname,
3362 const Standard_Boolean ydrawname,
3363 const Standard_Boolean zdrawname,
3365 const Standard_Boolean xdrawvalues,
3366 const Standard_Boolean ydrawvalues,
3367 const Standard_Boolean zdrawvalues,
3369 const Standard_Boolean drawgrid,
3371 const Standard_Boolean drawaxes,
3372 /* Number of splits along axes */
3373 const Standard_Integer nbx,
3374 const Standard_Integer nby,
3375 const Standard_Integer nbz,
3376 /* Offset for drawing values */
3377 const Standard_Integer xoffset,
3378 const Standard_Integer yoffset,
3379 const Standard_Integer zoffset,
3380 /* Offset for drawing names of axes */
3381 const Standard_Integer xaxisoffset,
3382 const Standard_Integer yaxisoffset,
3383 const Standard_Integer zaxisoffset,
3384 /* Draw tickmarks */
3385 const Standard_Boolean xdrawtickmarks,
3386 const Standard_Boolean ydrawtickmarks,
3387 const Standard_Boolean zdrawtickmarks,
3388 /* Length of tickmarks */
3389 const Standard_Integer xtickmarklength,
3390 const Standard_Integer ytickmarklength,
3391 const Standard_Integer ztickmarklength,
3393 const Quantity_Color& gridcolor,
3394 /* Colors of axis names */
3395 const Quantity_Color& xnamecolor,
3396 const Quantity_Color& ynamecolor,
3397 const Quantity_Color& znamecolor,
3398 /* Colors of axis and values */
3399 const Quantity_Color& xcolor,
3400 const Quantity_Color& ycolor,
3401 const Quantity_Color& zcolor,
3402 /* Name of font for names of axes */
3403 const TCollection_AsciiString &fontOfNames,
3404 /* Style of names of axes */
3405 const Font_FontAspect styleOfNames,
3406 /* Size of names of axes */
3407 const Standard_Integer sizeOfNames,
3408 /* Name of font for values */
3409 const TCollection_AsciiString &fontOfValues,
3410 /* Style of values */
3411 const Font_FontAspect styleOfValues,
3412 /* Size of values */
3413 const Standard_Integer sizeOfValues)
3416 MyGTrihedron.xname = xname;
3417 MyGTrihedron.yname = yname;
3418 MyGTrihedron.zname = zname;
3420 MyGTrihedron.xdrawname = xdrawname;
3421 MyGTrihedron.ydrawname = ydrawname;
3422 MyGTrihedron.zdrawname = zdrawname;
3424 MyGTrihedron.xdrawvalues = xdrawvalues;
3425 MyGTrihedron.ydrawvalues = ydrawvalues;
3426 MyGTrihedron.zdrawvalues = zdrawvalues;
3428 MyGTrihedron.drawgrid = drawgrid;
3430 MyGTrihedron.drawaxes = drawaxes;
3431 /* Number of splits along axes */
3432 MyGTrihedron.nbx = nbx;
3433 MyGTrihedron.nby = nby;
3434 MyGTrihedron.nbz = nbz;
3435 /* Offset for drawing values */
3436 MyGTrihedron.xoffset = xoffset;
3437 MyGTrihedron.yoffset = yoffset;
3438 MyGTrihedron.zoffset = zoffset;
3439 /* Offset for drawing names of axes */
3440 MyGTrihedron.xaxisoffset = xaxisoffset;
3441 MyGTrihedron.yaxisoffset = yaxisoffset;
3442 MyGTrihedron.zaxisoffset = zaxisoffset;
3443 /* Draw tickmarks */
3444 MyGTrihedron.xdrawtickmarks = xdrawtickmarks;
3445 MyGTrihedron.ydrawtickmarks = ydrawtickmarks;
3446 MyGTrihedron.zdrawtickmarks = zdrawtickmarks;
3447 /* Length of tickmarks */
3448 MyGTrihedron.xtickmarklength = xtickmarklength;
3449 MyGTrihedron.ytickmarklength = ytickmarklength;
3450 MyGTrihedron.ztickmarklength = ztickmarklength;
3452 MyGTrihedron.gridcolor = gridcolor;
3453 /* Colors of axis names */
3454 MyGTrihedron.xnamecolor = xnamecolor;
3455 MyGTrihedron.ynamecolor = ynamecolor;
3456 MyGTrihedron.znamecolor = znamecolor;
3457 /* Colors of axis and values */
3458 MyGTrihedron.xcolor = xcolor;
3459 MyGTrihedron.ycolor = ycolor;
3460 MyGTrihedron.zcolor = zcolor;
3461 /* Name of font for names of axes */
3462 MyGTrihedron.fontOfNames = fontOfNames;
3463 /* Style of names of axes */
3464 MyGTrihedron.styleOfNames = styleOfNames;
3465 /* Size of names of axes */
3466 MyGTrihedron.sizeOfNames = sizeOfNames;
3467 /* Name of font for values */
3468 MyGTrihedron.fontOfValues = fontOfValues;
3469 /* Style of values */
3470 MyGTrihedron.styleOfValues = styleOfValues;
3471 /* Size of values */
3472 MyGTrihedron.sizeOfValues = sizeOfValues;
3474 MyGTrihedron.ptrVisual3dView = this;
3475 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
3476 MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron);
3479 void Visual3d_View::GraduatedTrihedronErase()
3481 MyGTrihedron.ptrVisual3dView = NULL;
3482 MyGraphicDriver->GraduatedTrihedronErase(MyCView);
3485 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer () const {
3487 return (MyViewManager->UnderLayer ());
3491 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer () const {
3493 return (MyViewManager->OverLayer ());
3497 Standard_Integer Visual3d_View::LightLimit() const {
3499 Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit ();
3500 // printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight);
3504 Standard_Integer Visual3d_View::PlaneLimit() const {
3506 Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit ();
3507 // printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane);
3511 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
3513 return MyPtrViewManager;
3516 void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3518 if ((aMode && ComputedModeIsActive) ||
3519 (!aMode && !ComputedModeIsActive))
3524 Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure );
3525 Visual3d_TypeOfAnswer Answer;
3526 Standard_Integer StructId;
3527 Standard_Integer i = MyDisplayedStructure.Extent ();
3528 ComputedModeIsActive = aMode;
3529 if (!ComputedModeIsActive) {
3531 while ( S1Iterator.More () ) {
3533 Answer = AcceptDisplay ( S1Iterator.Key () );
3535 if ( Answer == Visual3d_TOA_COMPUTE ) {
3537 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
3541 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3543 MyGraphicDriver -> EraseStructure (
3545 *( Graphic3d_CStructure* )
3546 MyCOMPUTEDSequence.Value ( Index ) -> CStructure ()
3548 MyGraphicDriver -> DisplayStructure (
3550 *( Graphic3d_CStructure* )
3551 S1Iterator.Key () -> CStructure (),
3552 int ( S1Iterator.Key () -> DisplayPriority () )
3554 } // end if ( Index != 0 ) . . .
3556 } // end if ( Answer . . . )
3564 while ( S1Iterator.More () ) {
3566 Answer = AcceptDisplay ( S1Iterator.Key () );
3568 if ( Answer == Visual3d_TOA_COMPUTE ) {
3570 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
3574 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3576 MyGraphicDriver -> EraseStructure (
3578 *( Graphic3d_CStructure* )
3579 S1Iterator.Key () -> CStructure ()
3581 MyGraphicDriver -> DisplayStructure (
3583 *( Graphic3d_CStructure* )
3584 MyCOMPUTEDSequence.Value ( Index ) -> CStructure (),
3585 int ( S1Iterator.Key () -> DisplayPriority () )
3588 Display ( S1Iterator.Key (), Aspect_TOU_WAIT );
3590 if ( S1Iterator.Key () -> IsHighlighted () ) {
3592 if ( !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted () ) {
3594 MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor (
3595 S1Iterator.Key () ->
3598 MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight (
3607 Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key ();
3609 Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this );
3611 Handle( Graphic3d_Structure ) TheStructure;
3612 TColStd_Array2OfReal ATrsf ( 0, 3, 0, 3 );
3614 AStructure -> Transform ( ATrsf );
3618 TColStd_Array2OfReal Ident ( 0, 3, 0, 3 );
3619 Standard_Integer ii, jj;
3621 for ( ii = 0; ii <= 3; ++ii )
3623 for ( jj = 0; jj <= 3; ++jj )
3625 Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 );
3627 TheStructure = MyCOMPUTEDSequence.Value ( Index );
3629 TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE );
3631 if ( AStructure->IsTransformed () )
3633 AStructure -> Compute ( this, ATrsf, TheStructure );
3637 AStructure -> Compute ( this, TheStructure );
3641 if ( AStructure -> IsTransformed () )
3643 TheStructure = AStructure -> Compute ( this, ATrsf );
3647 TheStructure = AStructure -> Compute ( this );
3651 TheStructure -> SetHLRValidation ( Standard_True );
3653 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3655 Standard_Boolean ComputeWireframe =
3656 ( ( ViewType == Visual3d_TOV_WIREFRAME ) &&
3657 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING )
3660 Standard_Boolean ComputeShading =
3661 ( ( ViewType == Visual3d_TOV_SHADING ) &&
3662 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME )
3665 if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME );
3666 if ( ComputeShading ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING );
3668 if ( S1Iterator.Key () -> IsHighlighted () ) {
3670 TheStructure -> SetHighlightColor (
3671 S1Iterator.Key () -> HighlightColor ()
3673 TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR );
3677 Standard_Integer Result = 0;
3678 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3679 StructId = S1Iterator.Key () -> Identification ();
3681 for ( i = 1; i <= Length && Result == 0; ++i )
3683 if ( MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId )
3689 MyCOMPUTEDSequence.ChangeValue ( Result ) = TheStructure;
3693 MyTOCOMPUTESequence.Append ( S1Iterator.Key () );
3694 MyCOMPUTEDSequence.Append ( TheStructure );
3698 MyGraphicDriver -> EraseStructure (
3700 *( Graphic3d_CStructure* )
3701 S1Iterator.Key () -> CStructure ()
3703 MyGraphicDriver -> DisplayStructure (
3705 *( Graphic3d_CStructure* )TheStructure -> CStructure (),
3706 int ( S1Iterator.Key () -> DisplayPriority () )
3716 if ( MyViewManager -> UpdateMode () == Aspect_TOU_ASAP ) Update ();
3720 } // end Visual3d_View :: SetComputedMode
3722 Standard_Boolean Visual3d_View :: ComputedMode () const {
3724 return ComputedModeIsActive;
3726 } // end Visual3d_View :: ComputedMode
3728 void Visual3d_View :: SetBackFacingModel (
3729 const Visual3d_TypeOfBackfacingModel aModel
3734 case Visual3d_TOBM_AUTOMATIC:
3735 MyCView.Backfacing = 0;
3738 case Visual3d_TOBM_FORCE:
3739 MyCView.Backfacing = 1;
3742 case Visual3d_TOBM_DISABLE:
3743 MyCView.Backfacing = -1;
3748 MyGraphicDriver -> SetBackFacingModel ( MyCView );
3750 } // end Visual3d_View :: SetBackFacingModel
3752 Visual3d_TypeOfBackfacingModel Visual3d_View :: BackFacingModel () const {
3754 switch ( MyCView.Backfacing ) {
3757 return Visual3d_TOBM_AUTOMATIC;
3760 return Visual3d_TOBM_FORCE;
3764 return Visual3d_TOBM_DISABLE;
3766 } // end Visual3d_View :: BackFacingModel
3768 void Visual3d_View::EnableDepthTest( const Standard_Boolean enable ) const
3770 MyGraphicDriver->SetDepthTestEnabled( MyCView, enable );
3773 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
3775 return MyGraphicDriver->IsDepthTestEnabled( MyCView );
3778 void Visual3d_View::ReadDepths(const Standard_Integer x,
3779 const Standard_Integer y,
3780 const Standard_Integer width,
3781 const Standard_Integer height,
3782 const Standard_Address buffer) const
3784 MyGraphicDriver->ReadDepths( MyCView, x, y, width, height, buffer );
3787 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
3788 const Standard_Integer theHeight)
3790 return MyGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
3793 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
3795 MyGraphicDriver->FBORelease( MyCView, theFBOPtr );
3798 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
3799 Standard_Integer& theWidth, Standard_Integer& theHeight,
3800 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
3802 MyGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
3803 theWidth, theHeight,
3804 theWidthMax, theHeightMax );
3807 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
3808 const Standard_Integer theWidth, const Standard_Integer theHeight)
3810 MyGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
3811 theWidth, theHeight );
3814 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
3815 const Graphic3d_BufferType& theBufferType)
3817 return MyGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
3820 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
3822 MyGraphicDriver->SetGLLightEnabled( MyCView, enable );
3826 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
3828 return MyGraphicDriver->IsGLLightEnabled( MyCView );
3831 Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
3832 const Graphic3d_ExportFormat theFormat,
3833 const Graphic3d_SortType theSortType,
3834 const Standard_Real thePrecision,
3835 const Standard_Address theProgressBarFunc,
3836 const Standard_Address theProgressObject) const
3838 Handle(Visual3d_Layer) anUnderLayer = MyViewManager->UnderLayer();
3839 Handle(Visual3d_Layer) anOverLayer = MyViewManager->OverLayer();
3841 Aspect_CLayer2d anOverCLayer;
3842 Aspect_CLayer2d anUnderCLayer;
3843 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
3845 if (!anOverLayer.IsNull())
3846 anOverCLayer = anOverLayer->CLayer();
3847 if (!anUnderLayer.IsNull())
3848 anUnderCLayer = anUnderLayer->CLayer();
3850 Standard_Integer aWidth, aHeight;
3851 Window()->Size (aWidth, aHeight);
3853 return MyGraphicDriver->Export (theFileName, theFormat, theSortType,
3854 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
3855 thePrecision, theProgressBarFunc, theProgressObject);
3858 //=======================================================================
3859 //function : AddZLayer
3861 //=======================================================================
3863 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
3865 MyGraphicDriver->AddZLayer (MyCView, theLayerId);
3868 //=======================================================================
3869 //function : RemoveZLayer
3871 //=======================================================================
3873 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
3875 MyGraphicDriver->RemoveZLayer (MyCView, theLayerId);
3878 //=======================================================================
3879 //function : ChangeZLayer
3881 //=======================================================================
3883 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
3884 const Standard_Integer theLayerId)
3886 MyGraphicDriver->ChangeZLayer (
3887 (*(Graphic3d_CStructure*)theStructure->CStructure()), MyCView, theLayerId);