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_ClipPlane.hxx>
151 #include <Visual3d_SetOfClipPlane.hxx>
152 #include <Visual3d_HSetOfClipPlane.hxx>
153 #include <Visual3d_SetIteratorOfSetOfClipPlane.hxx>
155 #include <Visual3d_SetIteratorOfSetOfView.hxx>
157 #include <Graphic3d_TextureEnv.hxx>
159 #include <TColStd_HArray2OfReal.hxx>
161 #if (defined(_WIN32) || defined(__WIN32__))
162 #include <WNT_Window.hxx>
163 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
164 #include <Cocoa_Window.hxx>
166 #include <Xw_Window.hxx>
173 //-Global data definitions
177 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager):
180 MyViewMappingReset (),
181 MyViewOrientation (),
182 MyViewOrientationReset (),
183 MyTransformation (0, 3, 0, 3),
184 MyMatrixOfMapping (0, 3, 0, 3),
185 MyMatrixOfOrientation (0, 3, 0, 3),
186 MyTOCOMPUTESequence (),
187 MyCOMPUTEDSequence (),
188 MyDisplayedStructure ()
190 Standard_Integer i, j;
192 MyPtrViewManager = AManager.operator->();
193 MyCView.ViewId = int (AManager->Identification (this));
195 MyCView.IsDeleted = 0;
198 MyCView.DefWindow.IsDefined = 0;
200 MyCView.Context.NbActiveLight = 0;
201 MyCView.Context.NbActivePlane = 0;
203 MyCView.Context.ActivePlane = NULL;
208 if (i == j) MyTransformation (i, j) = 1.0;
209 else MyTransformation (i, j) = 0.0;
211 Standard_Real X, Y, Z;
213 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
214 MyCView.Orientation.ViewReferencePoint.x = float (X);
215 MyCView.Orientation.ViewReferencePoint.y = float (Y);
216 MyCView.Orientation.ViewReferencePoint.z = float (Z);
217 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
218 MyCView.Orientation.ViewReferencePlane.x = float (X);
219 MyCView.Orientation.ViewReferencePlane.y = float (Y);
220 MyCView.Orientation.ViewReferencePlane.z = float (Z);
221 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
222 MyCView.Orientation.ViewReferenceUp.x = float (X);
223 MyCView.Orientation.ViewReferenceUp.y = float (Y);
224 MyCView.Orientation.ViewReferenceUp.z = float (Z);
226 Standard_Real Sx, Sy, Sz;
228 MyViewOrientation.AxialScale(Sx, Sy, Sz);
229 MyCView.Orientation.ViewScaleX = float (Sx);
230 MyCView.Orientation.ViewScaleY = float (Sy);
231 MyCView.Orientation.ViewScaleZ = float (Sz);
233 // NKV : 23/07/07 - Define custom MODELVIEW matrix
234 MyCView.Orientation.IsCustomMatrix = 0;
235 memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
236 MyCView.Orientation.ModelViewMatrix[0][0] =
237 MyCView.Orientation.ModelViewMatrix[1][1] =
238 MyCView.Orientation.ModelViewMatrix[2][2] =
239 MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
242 Standard_Real um, vm, uM, vM;
244 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
245 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
246 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
247 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
248 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
249 MyCView.Mapping.ViewPlaneDistance =
250 float (MyViewMapping.ViewPlaneDistance ());
251 MyCView.Mapping.BackPlaneDistance =
252 float (MyViewMapping.BackPlaneDistance ());
253 MyCView.Mapping.FrontPlaneDistance =
254 float (MyViewMapping.FrontPlaneDistance ());
255 MyViewMapping.WindowLimit (um, vm, uM, vM);
256 MyCView.Mapping.WindowLimit.um = float (um);
257 MyCView.Mapping.WindowLimit.vm = float (vm);
258 MyCView.Mapping.WindowLimit.uM = float (uM);
259 MyCView.Mapping.WindowLimit.vM = float (vM);
261 // NKV : 23/07/07 - Define custom MODELVIEW matrix
262 MyCView.Mapping.IsCustomMatrix = 0;
263 memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
264 MyCView.Mapping.ProjectionMatrix[0][0] =
265 MyCView.Mapping.ProjectionMatrix[1][1] =
266 MyCView.Mapping.ProjectionMatrix[2][2] =
267 MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
270 MyCView.Context.ZBufferActivity = -1;
272 MyMatOfMapIsEvaluated = Standard_False;
273 MyMatOfOriIsEvaluated = Standard_False;
275 IsInitialized = Standard_False;
276 ComputedModeIsActive = Standard_False;
277 MyCView.Backfacing = 0;
279 MyCView.ptrUnderLayer = 0;
280 MyCView.ptrOverLayer = 0;
281 MyCView.GContext = 0;
282 MyCView.GDisplayCB = 0;
283 MyCView.GClientData = 0;
285 MyGraphicDriver = MyViewManager->GraphicDriver();
289 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager, const Visual3d_ViewOrientation& VO, const Visual3d_ViewMapping& VM, const Visual3d_ContextView& CTX):
290 MyTransformation (0, 3, 0, 3),
291 MyMatrixOfMapping (0, 3, 0, 3),
292 MyMatrixOfOrientation (0, 3, 0, 3),
293 MyTOCOMPUTESequence (),
294 MyCOMPUTEDSequence (),
295 MyDisplayedStructure ()
297 Standard_Integer i, j;
299 MyPtrViewManager = AManager.operator->();
300 MyViewOrientation = VO;
303 MyViewOrientationReset = VO;
304 MyViewMappingReset = VM;
306 MyCView.ViewId = int (AManager->Identification (this));
308 MyCView.IsDeleted = 0;
311 MyCView.DefWindow.IsDefined = 0;
313 MyCView.Context.NbActiveLight = 0;
314 MyCView.Context.NbActivePlane = 0;
316 MyCView.Context.ActivePlane = NULL;
321 if (i == j) MyTransformation (i, j) = 1.0;
322 else MyTransformation (i, j) = 0.0;
324 Standard_Real X, Y, Z;
326 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
327 MyCView.Orientation.ViewReferencePoint.x = float (X);
328 MyCView.Orientation.ViewReferencePoint.y = float (Y);
329 MyCView.Orientation.ViewReferencePoint.z = float (Z);
330 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
331 MyCView.Orientation.ViewReferencePlane.x = float (X);
332 MyCView.Orientation.ViewReferencePlane.y = float (Y);
333 MyCView.Orientation.ViewReferencePlane.z = float (Z);
334 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
335 MyCView.Orientation.ViewReferenceUp.x = float (X);
336 MyCView.Orientation.ViewReferenceUp.y = float (Y);
337 MyCView.Orientation.ViewReferenceUp.z = float (Z);
339 Standard_Real Sx, Sy, Sz;
341 MyViewOrientation.AxialScale(Sx, Sy, Sz);
342 MyCView.Orientation.ViewScaleX = float (Sx);
343 MyCView.Orientation.ViewScaleY = float (Sy);
344 MyCView.Orientation.ViewScaleZ = float (Sz);
346 // NKV : 23/07/07 - Define custom MODELVIEW matrix
347 if (MyViewOrientation.IsCustomMatrix()) {
348 MyCView.Orientation.IsCustomMatrix = 1;
349 for ( i = 0; i < 4; i++)
350 for ( j = 0; j < 4; j++)
351 MyCView.Orientation.ModelViewMatrix[i][j] =
352 (Standard_ShortReal)MyViewOrientation.MyModelViewMatrix->Value(i,j);
355 MyCView.Orientation.IsCustomMatrix = 0;
356 memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
357 MyCView.Orientation.ModelViewMatrix[0][0] =
358 MyCView.Orientation.ModelViewMatrix[1][1] =
359 MyCView.Orientation.ModelViewMatrix[2][2] =
360 MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
364 Standard_Real um, vm, uM, vM;
366 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
367 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
368 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
369 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
370 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
371 MyCView.Mapping.ViewPlaneDistance =
372 float (MyViewMapping.ViewPlaneDistance ());
373 MyCView.Mapping.BackPlaneDistance =
374 float (MyViewMapping.BackPlaneDistance ());
375 MyCView.Mapping.FrontPlaneDistance =
376 float (MyViewMapping.FrontPlaneDistance ());
377 MyViewMapping.WindowLimit (um, vm, uM, vM);
378 MyCView.Mapping.WindowLimit.um = float (um);
379 MyCView.Mapping.WindowLimit.vm = float (vm);
380 MyCView.Mapping.WindowLimit.uM = float (uM);
381 MyCView.Mapping.WindowLimit.vM = float (vM);
383 // NKV : 23/07/07 - Define custom MODELVIEW matrix
384 if (MyViewMapping.IsCustomMatrix()) {
385 MyCView.Mapping.IsCustomMatrix = 1;
386 for ( i = 0; i < 4; i++)
387 for ( j = 0; j < 4; j++)
388 MyCView.Mapping.ProjectionMatrix[i][j] =
389 (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j);
392 MyCView.Mapping.IsCustomMatrix = 0;
393 memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
394 MyCView.Mapping.ProjectionMatrix[0][0] =
395 MyCView.Mapping.ProjectionMatrix[1][1] =
396 MyCView.Mapping.ProjectionMatrix[2][2] =
397 MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
401 MyCView.Context.ZBufferActivity = -1;
403 MyMatOfMapIsEvaluated = Standard_False;
404 MyMatOfOriIsEvaluated = Standard_False;
406 IsInitialized = Standard_False;
407 ComputedModeIsActive = Standard_False;
409 MyCView.ptrUnderLayer = 0;
410 MyCView.ptrOverLayer = 0;
411 MyCView.GContext = 0;
412 MyCView.GDisplayCB = 0;
413 MyCView.GClientData = 0;
415 MyGraphicDriver = MyViewManager->GraphicDriver();
423 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow,
424 const Aspect_RenderingContext AContext,
425 const Aspect_GraphicCallbackProc& ADisplayCB,
426 const Standard_Address AClientData)
428 if (IsDeleted ()) return;
431 Visual3d_ViewDefinitionError::Raise ("Window already defined");
433 MyCView.GContext = AContext;
434 MyCView.GDisplayCB = ADisplayCB;
435 MyCView.GClientData = AClientData;
440 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
443 if (IsDeleted ()) return;
446 Visual3d_ViewDefinitionError::Raise ("Window already defined");
448 MyWindow = theWindow;
449 MyCView.WsId = MyCView.ViewId;
450 MyCView.DefWindow.IsDefined = 1;
452 #if (defined(_WIN32) || defined(__WIN32__))
453 const Handle(WNT_Window) aWin = Handle(WNT_Window)::DownCast (theWindow);
454 MyCView.DefWindow.XWindow = (HWND )(aWin->HWindow());
455 MyCView.DefWindow.XParentWindow = (HWND )(aWin->HParentWindow());
456 WNT_WindowData* aWinData = (WNT_WindowData* )GetWindowLongPtr ((HWND )(aWin->HWindow()), GWLP_USERDATA);
457 aWinData->WNT_WDriver_Ptr = (void* )this;
458 aWinData->WNT_VMgr = (void* )MyPtrViewManager;
459 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
460 const Handle(Cocoa_Window) aWin = Handle(Cocoa_Window)::DownCast (theWindow);
461 MyCView.DefWindow.XWindow = (Aspect_Drawable )aWin->HView();
462 MyCView.DefWindow.XParentWindow = NULL;
463 //MyCView.DefWindow.XParentWindow = aWin->HParentWindow();
465 const Handle(Xw_Window) aWin = Handle(Xw_Window)::DownCast (theWindow);
466 MyCView.DefWindow.XWindow = aWin->XWindow();
467 //MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
470 Standard_Integer Width, Height;
471 theWindow->Size (Width, Height);
473 MyCView.DefWindow.dx = float( Width );
474 MyCView.DefWindow.dy = float( Height );
476 Standard_Real R, G, B;
477 MyBackground = MyWindow->Background ();
478 (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
479 MyCView.DefWindow.Background.r = float (R);
480 MyCView.DefWindow.Background.g = float (G);
481 MyCView.DefWindow.Background.b = float (B);
484 if (! MyGraphicDriver->View (MyCView))
485 Visual3d_ViewDefinitionError::Raise ("Association failed");
487 MyGradientBackground = MyWindow->GradientBackground();
488 SetGradientBackground(MyGradientBackground,1);
490 Standard_Boolean AWait = Standard_False; // => immediate update
491 MyGraphicDriver->SetVisualisation (MyCView);
492 MyGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn ());
493 MyGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn ());
494 MyGraphicDriver->ClipLimit (MyCView, AWait);
495 MyGraphicDriver->Environment(MyCView);
497 // Make view manager z layer list consistent with the view's list.
498 MyViewManager->InstallZLayers (this);
500 // Update planses of model clipping
503 // Update light sources
507 * Association view-window does not cause the display
508 * of structures that can be displayed in the new view.
509 * In fact, association view-window is done, but the
510 * display is produced only if the view is activated (Activate).
517 Handle(Aspect_Window) Visual3d_View::Window () const {
520 Visual3d_ViewDefinitionError::Raise ("Window not defined");
526 Standard_Boolean Visual3d_View::IsDefined () const {
528 if (MyCView.DefWindow.IsDefined)
529 return (Standard_True);
531 return (Standard_False);
535 Standard_Boolean Visual3d_View::IsDeleted () const {
537 if (MyCView.IsDeleted)
538 return (Standard_True);
540 return (Standard_False);
544 void Visual3d_View::Destroy () {
547 cout << "Visual3d_View::Destroy (" << Identification () << ")\n";
550 // Since MyPtrViewManager can be already distroyed,
551 // avoid attempts to access it in SetBackground()
552 MyPtrViewManager = 0;
557 void Visual3d_View::Remove () {
560 cout << "Visual3d_View::Remove (" << Identification () << ")" << endl;
563 if (IsDeleted ()) return;
564 if (! IsDefined ()) return;
566 MyTOCOMPUTESequence.Clear ();
567 MyCOMPUTEDSequence.Clear ();
568 MyDisplayedStructure.Clear ();
570 Quantity_Color BlackColor (0.0, 0.0, 0.0, Quantity_TOC_RGB);
571 Aspect_Background BlackBackground (BlackColor);
572 SetBackground (BlackBackground);
574 Aspect_GradientBackground BlackGradBackground;
575 SetGradientBackground (BlackGradBackground,0);
577 if (MyPtrViewManager)
578 MyPtrViewManager->UnIdentification( MyCView.ViewId );
580 MyGraphicDriver->RemoveView (MyCView);
583 MyCView.IsDeleted = 1;
584 MyCView.DefWindow.IsDefined = 0;
586 MyMatOfMapIsEvaluated = Standard_False;
587 MyMatOfOriIsEvaluated = Standard_False;
589 IsInitialized = Standard_False;
595 void Visual3d_View::Resized () {
597 if (IsDeleted ()) return;
600 Visual3d_ViewDefinitionError::Raise ("Window not defined");
601 MyWindow->DoResize() ;
606 void Visual3d_View::SetRatio () {
608 if (IsDeleted ()) return;
610 Aspect_TypeOfUpdate UpdateMode = MyViewManager->UpdateMode ();
611 MyViewManager->SetUpdateMode (Aspect_TOU_WAIT);
613 Standard_Real Umin, Vmin, Umax, Vmax;
614 Standard_Integer Dxw, Dyw;
615 Standard_Real Dxv, Dyv;
616 Standard_Real Xc, Yc;
620 MyWindow->Size (Dxw, Dyw);
621 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
622 Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
623 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
624 if( Dxw > 0 && Dyw > 0 ) Rap = (Standard_Real)Dyw/(Standard_Real)Dxw ;
654 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
655 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
657 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
659 // Update before SetViewMapping.
661 MyCView.DefWindow.dx = float( Dxw );
662 MyCView.DefWindow.dy = float( Dyw );
664 SetViewMapping (MyViewMapping);
665 // SetViewMappingDefault ();
666 // FMN+ Update Ratio for MyViewMappingReset
668 MyViewMappingReset.WindowLimit(Umin,Vmin,Umax,Vmax) ;
669 Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
670 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
699 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
700 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
702 MyViewMappingReset.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
704 // FMN- Update Ratio for MyViewMappingReset
706 MyGraphicDriver->RatioWindow (MyCView);
709 // Force recalculation of 2 matrices.
711 // The current view can help to reconstruct a copied view
712 // that is itself. Owing to SetWindow and SetRatio the
713 // recalculation of matrices of this new view is imposed.
714 MyMatOfMapIsEvaluated = Standard_False;
715 MyMatOfOriIsEvaluated = Standard_False;
717 MyViewManager->SetUpdateMode (UpdateMode);
718 if (UpdateMode == Aspect_TOU_ASAP) Update ();
722 void Visual3d_View::UpdateLights () {
724 Standard_Integer i, j;
725 CALL_DEF_LIGHT *lights=NULL;
728 if( MyContext.Model() == Visual3d_TOM_NONE ) {
729 // Activates only a white ambient light
730 MyCView.Context.NbActiveLight = 1;
731 lights = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
732 MyCView.Context.ActiveLight = lights;
734 lights[0].WsId = MyCView.ViewId;
735 lights[0].ViewId = MyCView.ViewId;
736 lights[0].LightType = int (Visual3d_TOLS_AMBIENT);
737 lights[0].Active = 1;
738 lights[0].LightId = 0;
739 lights[0].Headlight = 0;
740 lights[0].Color.r = lights[0].Color.g = lights[0].Color.b = 1.;
743 i = MyContext.NumberOfActivatedLights ();
744 j = MyGraphicDriver->InquireLightLimit ();
745 MyCView.Context.NbActiveLight = (i > j ? j : i);
747 if (MyCView.Context.NbActiveLight > 0) {
749 // Dynamic Allocation
750 lights = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
752 MyCView.Context.ActiveLight = lights;
754 Standard_Real X, Y, Z;
756 Standard_Real LightConcentration;
757 Standard_Real LightAttenuation1;
758 Standard_Real LightAttenuation2;
759 Standard_Real LightAngle;
760 Quantity_Color LightColor;
761 Graphic3d_Vertex LightPosition;
762 Graphic3d_Vector LightDirection;
763 Visual3d_TypeOfLightSource LightType=Visual3d_TOLS_AMBIENT;
765 // Parcing of light sources
766 for (j=0; j<MyCView.Context.NbActiveLight; j++) {
767 LightType = (MyContext.ActivatedLight (j+1))->LightType ();
769 lights[j].WsId = MyCView.ViewId;
770 lights[j].ViewId = MyCView.ViewId;
772 lights[j].LightType = int (LightType);
773 lights[j].Active = 1;
775 int ((MyContext.ActivatedLight (j+1))->Identification ());
776 lights[j].Headlight = (MyContext.ActivatedLight (j+1))->Headlight ()? 1:0;
780 case Visual3d_TOLS_AMBIENT :
781 (MyContext.ActivatedLight (j+1))->Values (
786 case Visual3d_TOLS_POSITIONAL :
787 (MyContext.ActivatedLight (j+1))->Values (
795 case Visual3d_TOLS_DIRECTIONAL :
796 (MyContext.ActivatedLight (j+1))->Values (
802 case Visual3d_TOLS_SPOT :
803 (MyContext.ActivatedLight (j+1))->Values (
816 lights[j].Color.r = float (LightColor.Red ());
817 lights[j].Color.g = float (LightColor.Green ());
818 lights[j].Color.b = float (LightColor.Blue ());
820 if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
821 (LightType == Visual3d_TOLS_SPOT) ) {
822 LightPosition.Coord (X, Y, Z);
823 lights[j].Position.x = float (X);
824 lights[j].Position.y = float (Y);
825 lights[j].Position.z = float (Z);
828 if ( (LightType == Visual3d_TOLS_DIRECTIONAL) ||
829 (LightType == Visual3d_TOLS_SPOT) ) {
830 LightDirection.Coord (X, Y, Z);
831 lights[j].Direction.x = float (X);
832 lights[j].Direction.y = float (Y);
833 lights[j].Direction.z = float (Z);
836 if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
837 (LightType == Visual3d_TOLS_SPOT) ) {
838 lights[j].Attenuation[0] =
839 float (LightAttenuation1);
840 lights[j].Attenuation[1] =
841 float (LightAttenuation2);
844 if (LightType == Visual3d_TOLS_SPOT) {
845 lights[j].Concentration =
846 float (LightConcentration);
856 // management of light sources
859 MyGraphicDriver->SetLight (MyCView);
861 // Dynamic allocation
862 if (MyCView.Context.NbActiveLight > 0) delete [] lights;
866 void Visual3d_View::UpdatePlanes () {
868 Standard_Integer i, j;
869 CALL_DEF_PLANE *planes=NULL;
871 i = MyContext.NumberOfActivatedClipPlanes ();
872 j = MyGraphicDriver->InquirePlaneLimit ();
873 MyCView.Context.NbActivePlane = (i > j ? j : i);
875 if (MyCView.Context.NbActivePlane > 0) {
877 // Dynamic Allocation
878 #ifdef GER61454 //Keep the plane address for the next Update !
879 if( !MyCView.Context.ActivePlane )
880 MyCView.Context.ActivePlane = new CALL_DEF_PLANE [j];
881 planes = MyCView.Context.ActivePlane;
883 planes = new CALL_DEF_PLANE [MyCView.Context.NbActivePlane];
885 MyCView.Context.ActivePlane = planes;
887 Standard_Real A, B, C, D;
889 // Parcing of clipping planes
890 for (j=0; j<MyCView.Context.NbActivePlane; j++) {
892 planes[j].WsId = MyCView.ViewId;
893 planes[j].ViewId = MyCView.ViewId;
895 planes[j].Active = 1;
897 int ((MyContext.ActivatedClipPlane (j+1))->Identification ());
899 (MyContext.ActivatedClipPlane (j+1))->Plane (A, B, C, D);
900 planes[j].CoefA = float (A);
901 planes[j].CoefB = float (B);
902 planes[j].CoefC = float (C);
903 planes[j].CoefD = float (D);
908 // Management of planes of clipping model
911 MyGraphicDriver->SetPlane (MyCView);
913 // Dynamic allocation
915 if ( MyCView.Context.ActivePlane && (MyCView.Context.NbActivePlane == 0)
917 delete [] MyCView.Context.ActivePlane;
918 MyCView.Context.ActivePlane = NULL;
921 if (MyCView.Context.NbActivePlane > 0) delete [] planes;
926 void Visual3d_View::SetBackground (const Aspect_Background& ABack) {
928 if (IsDeleted ()) return;
931 Visual3d_ViewDefinitionError::Raise ("Window not defined");
933 // At this level, only GL can update the background.
934 // It is not necessary to call MyWindow->SetBackground (ABack); as
935 // this method starts update of window background by X
936 // (if the windowing is X)
938 Standard_Real R, G, B;
939 MyBackground = ABack;
940 (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
941 MyCView.DefWindow.Background.r = float (R);
942 MyCView.DefWindow.Background.g = float (G);
943 MyCView.DefWindow.Background.b = float (B);
945 MyGraphicDriver->Background (MyCView);
947 if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
952 void Visual3d_View::SetGradientBackground(const Aspect_GradientBackground& ABack, const Standard_Boolean update)
955 if (IsDeleted ()) return;
958 Visual3d_ViewDefinitionError::Raise ("Window not defined");
960 MyGradientBackground = ABack;
961 Quantity_Color aCol1,aCol2;
962 MyGradientBackground.Colors(aCol1,aCol2);
963 MyGraphicDriver->GradientBackground(MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
967 else if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
971 void Visual3d_View::SetBackgroundImage( const Standard_CString FileName,
972 const Aspect_FillMethod FillStyle,
973 const Standard_Boolean update )
978 Visual3d_ViewDefinitionError::Raise ("Window not defined");
980 MyGraphicDriver->BackgroundImage( FileName, MyCView, FillStyle );
984 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
988 void Visual3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
989 const Standard_Boolean update )
994 Visual3d_ViewDefinitionError::Raise ("Window not defined");
996 MyGraphicDriver->SetBgImageStyle( MyCView, FillStyle );
1000 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1004 Aspect_Background Visual3d_View::Background () const {
1006 return (MyBackground);
1010 void Visual3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
1011 const Standard_Boolean update )
1016 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1018 MyGraphicDriver->SetBgGradientStyle( MyCView, FillStyle );
1022 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1027 Aspect_GradientBackground Visual3d_View::GradientBackground () const {
1029 return MyGradientBackground;
1033 void Visual3d_View::SetTransform (const TColStd_Array2OfReal& AMatrix) {
1035 if (IsDeleted ()) return;
1037 Standard_Integer lr, ur, lc, uc;
1038 Standard_Integer i, j;
1040 // Assign the new transformation in an array [0..3][0..3]
1041 // Avoid problems if the has defined a matrice [1..4][1..4]
1042 // ou [3..6][-1..2] !!
1043 lr = AMatrix.LowerRow ();
1044 ur = AMatrix.UpperRow ();
1045 lc = AMatrix.LowerCol ();
1046 uc = AMatrix.UpperCol ();
1048 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
1049 Visual3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1051 for (i=0; i<=3; i++)
1052 for (j=0; j<=3; j++)
1053 MyTransformation (i, j) = AMatrix (lr + i, lc + j);
1055 Graphic3d_Vector VPN;
1056 Graphic3d_Vertex VRP;
1057 Graphic3d_Vector VUP;
1058 Standard_Real Sx, Sy, Sz;
1060 Visual3d_ViewOrientation NewViewOrientation;
1062 VPN = MyViewOrientation.ViewReferencePlane ();
1063 VRP = MyViewOrientation.ViewReferencePoint ();
1064 VUP = MyViewOrientation.ViewReferenceUp ();
1065 MyViewOrientation.AxialScale(Sx, Sy, Sz);
1067 NewViewOrientation.SetViewReferencePlane
1068 (Graphic3d_Structure::Transforms (Transform (), VPN));
1070 NewViewOrientation.SetViewReferencePoint
1071 (Graphic3d_Structure::Transforms (Transform (), VRP));
1073 NewViewOrientation.SetViewReferenceUp
1074 (Graphic3d_Structure::Transforms (Transform (), VUP));
1075 NewViewOrientation.SetAxialScale(Sx, Sy, Sz);
1077 SetViewOrientation (NewViewOrientation);
1079 MyMatOfOriIsEvaluated = Standard_False;
1083 const TColStd_Array2OfReal& Visual3d_View::Transform () const {
1085 return (MyTransformation);
1089 void Visual3d_View::SetViewOrientation (const Visual3d_ViewOrientation& VO) {
1091 if (IsDeleted ()) return;
1093 MyViewOrientation = VO;
1095 Standard_Real X, Y, Z;
1096 // Tests on modification of parameters.
1097 Standard_Boolean VUPIsModified = Standard_False;
1098 Standard_Boolean VRPIsModified = Standard_False;
1099 Standard_Boolean VRUIsModified = Standard_False;
1100 Standard_Boolean ScaleIsModified = Standard_False;
1101 Standard_Boolean CustomIsModified = Standard_False;
1103 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1105 MyCView.Orientation.ViewReferencePoint.x != float (X)
1106 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1107 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1108 MyCView.Orientation.ViewReferencePoint.x = float (X);
1109 MyCView.Orientation.ViewReferencePoint.y = float (Y);
1110 MyCView.Orientation.ViewReferencePoint.z = float (Z);
1112 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1114 MyCView.Orientation.ViewReferencePlane.x != float (X)
1115 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1116 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1117 MyCView.Orientation.ViewReferencePlane.x = float (X);
1118 MyCView.Orientation.ViewReferencePlane.y = float (Y);
1119 MyCView.Orientation.ViewReferencePlane.z = float (Z);
1121 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1123 MyCView.Orientation.ViewReferenceUp.x != float (X)
1124 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1125 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1126 MyCView.Orientation.ViewReferenceUp.x = float (X);
1127 MyCView.Orientation.ViewReferenceUp.y = float (Y);
1128 MyCView.Orientation.ViewReferenceUp.z = float (Z);
1130 MyViewOrientation.AxialScale(X, Y, Z);
1132 MyCView.Orientation.ViewScaleX != float (X)
1133 || MyCView.Orientation.ViewScaleY != float (Y)
1134 || MyCView.Orientation.ViewScaleZ != float (Z);
1135 MyCView.Orientation.ViewScaleX = float (X);
1136 MyCView.Orientation.ViewScaleY = float (Y);
1137 MyCView.Orientation.ViewScaleZ = float (Z);
1140 MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
1141 MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
1142 if ( MyViewOrientation.IsCustomMatrix() ) {
1143 Standard_Integer i, j;
1144 for (i = 0; i < 4; i++)
1145 for (j = 0; j < 4; j++) {
1146 if (!CustomIsModified) CustomIsModified =
1147 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
1152 cout << "Visual3d_View::SetViewOrientation\n";
1153 if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified)
1154 cout << "VUPIsModified : " << VUPIsModified
1155 << ", VRPIsModified : " << VRPIsModified
1156 << ", VRUIsModified : " << VRUIsModified
1157 << ", CustomIsModified : " << CustomIsModified
1158 << ", ScaleIsModified : " << ScaleIsModified << "\n" << flush;
1160 cout << "no modification\n" << flush;
1163 // restart if one of parameters is modified
1164 if (!IsInitialized || VUPIsModified || VRPIsModified
1165 || VRUIsModified || ScaleIsModified || CustomIsModified) {
1167 MyMatOfOriIsEvaluated = !VUPIsModified && !VRPIsModified
1168 && !VRUIsModified && !ScaleIsModified;
1170 if (! IsDefined ()) return;
1172 Standard_Boolean AWait = Standard_False; // => immediate update
1173 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1174 IsInitialized = Standard_True;
1177 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1182 Visual3d_ViewOrientation Visual3d_View::ViewOrientation () const {
1184 return (MyViewOrientation);
1188 Visual3d_ViewOrientation Visual3d_View::ViewOrientationDefault () const {
1190 return (MyViewOrientationReset);
1194 void Visual3d_View::SetViewOrientationDefault () {
1196 MyViewOrientationReset.Assign (MyViewOrientation);
1200 void Visual3d_View::ViewOrientationReset () {
1202 if (IsDeleted ()) return;
1204 MyViewOrientation = MyViewOrientationReset;
1206 Standard_Real X, Y, Z;
1208 // Tests on modification of parameters.
1209 Standard_Boolean VUPIsModified = Standard_False;
1210 Standard_Boolean VRPIsModified = Standard_False;
1211 Standard_Boolean VRUIsModified = Standard_False;
1212 Standard_Boolean ScaleIsModified = Standard_False;
1213 Standard_Boolean CustomIsModified = Standard_False;
1215 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1217 MyCView.Orientation.ViewReferencePoint.x != float (X)
1218 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1219 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1220 MyCView.Orientation.ViewReferencePoint.x = float (X);
1221 MyCView.Orientation.ViewReferencePoint.y = float (Y);
1222 MyCView.Orientation.ViewReferencePoint.z = float (Z);
1224 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1226 MyCView.Orientation.ViewReferencePlane.x != float (X)
1227 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1228 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1229 MyCView.Orientation.ViewReferencePlane.x = float (X);
1230 MyCView.Orientation.ViewReferencePlane.y = float (Y);
1231 MyCView.Orientation.ViewReferencePlane.z = float (Z);
1233 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1235 MyCView.Orientation.ViewReferenceUp.x != float (X)
1236 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1237 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1238 MyCView.Orientation.ViewReferenceUp.x = float (X);
1239 MyCView.Orientation.ViewReferenceUp.y = float (Y);
1240 MyCView.Orientation.ViewReferenceUp.z = float (Z);
1242 MyViewOrientation.AxialScale(X, Y, Z);
1244 MyCView.Orientation.ViewScaleX != float (X)
1245 || MyCView.Orientation.ViewScaleY != float (Y)
1246 || MyCView.Orientation.ViewScaleZ != float (Z);
1247 MyCView.Orientation.ViewScaleX = float (X);
1248 MyCView.Orientation.ViewScaleY = float (Y);
1249 MyCView.Orientation.ViewScaleZ = float (Z);
1252 MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
1253 MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
1254 if ( MyViewOrientation.IsCustomMatrix() ) {
1255 Standard_Integer i, j;
1256 for (i = 0; i < 4; i++)
1257 for (j = 0; j < 4; j++) {
1258 if (!CustomIsModified) CustomIsModified =
1259 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
1265 cout << "Visual3d_View::ViewOrientationReset\n";
1266 if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified)
1267 cout << "VUPIsModified : " << VUPIsModified
1268 << ", VRPIsModified : " << VRPIsModified
1269 << ", VRUIsModified : " << VRUIsModified
1270 << ", CustomIsModified : " << CustomIsModified
1271 << ", ScaleIsModified : " << ScaleIsModified << "\n" << flush;
1273 cout << "no modification\n" << flush;
1276 // Restart if one of parameters is modified
1277 if (!IsInitialized || VUPIsModified || VRPIsModified
1278 || VRUIsModified || ScaleIsModified || CustomIsModified) {
1280 MyMatOfOriIsEvaluated = !VUPIsModified && !VRPIsModified
1281 && !VRUIsModified && !ScaleIsModified;
1283 if (! IsDefined ()) return;
1285 Standard_Boolean AWait = Standard_False; // => immediate update
1286 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1287 IsInitialized = Standard_True;
1290 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1294 void Visual3d_View::SetViewMapping (const Visual3d_ViewMapping& VM) {
1296 if (IsDeleted ()) return;
1298 Visual3d_TypeOfProjection OldType = MyViewMapping.Projection ();
1299 Visual3d_TypeOfProjection NewType = VM.Projection ();
1303 Standard_Real X, Y, Z;
1304 Standard_Real um, vm, uM, vM;
1306 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
1307 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1308 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
1309 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
1310 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
1311 MyCView.Mapping.ViewPlaneDistance =
1312 float (MyViewMapping.ViewPlaneDistance ());
1313 MyCView.Mapping.BackPlaneDistance =
1314 float (MyViewMapping.BackPlaneDistance ());
1315 MyCView.Mapping.FrontPlaneDistance =
1316 float (MyViewMapping.FrontPlaneDistance ());
1317 MyViewMapping.WindowLimit (um, vm, uM, vM);
1318 MyCView.Mapping.WindowLimit.um = float (um);
1319 MyCView.Mapping.WindowLimit.vm = float (vm);
1320 MyCView.Mapping.WindowLimit.uM = float (uM);
1321 MyCView.Mapping.WindowLimit.vM = float (vM);
1323 MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1324 if (MyViewMapping.IsCustomMatrix()) {
1325 Standard_Integer i, j;
1326 for (i = 0; i < 4; i++)
1327 for (j = 0; j < 4; j++)
1328 MyCView.Mapping.ProjectionMatrix[i][j] =
1329 (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j);
1332 MyMatOfMapIsEvaluated = Standard_False;
1334 if (! IsDefined ()) return;
1336 Standard_Boolean AWait = Standard_False; // => immediate update
1337 MyGraphicDriver->ViewMapping (MyCView, AWait);
1339 // Passage Parallele/Perspective
1340 if (OldType != NewType)
1343 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1347 Visual3d_ViewMapping Visual3d_View::ViewMapping () const {
1349 return (MyViewMapping);
1353 Visual3d_ViewMapping Visual3d_View::ViewMappingDefault () const {
1355 return (MyViewMappingReset);
1359 void Visual3d_View::SetViewMappingDefault () {
1361 MyViewMappingReset.Assign (MyViewMapping);
1365 void Visual3d_View::ViewMappingReset () {
1367 if (IsDeleted ()) return;
1369 MyViewMapping = MyViewMappingReset;
1371 Standard_Real X, Y, Z;
1372 Standard_Real um, vm, uM, vM;
1374 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
1375 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1376 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
1377 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
1378 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
1379 MyCView.Mapping.ViewPlaneDistance =
1380 float (MyViewMapping.ViewPlaneDistance ());
1381 MyCView.Mapping.BackPlaneDistance =
1382 float (MyViewMapping.BackPlaneDistance ());
1383 MyCView.Mapping.FrontPlaneDistance =
1384 float (MyViewMapping.FrontPlaneDistance ());
1385 MyViewMapping.WindowLimit (um, vm, uM, vM);
1386 MyCView.Mapping.WindowLimit.um = float (um);
1387 MyCView.Mapping.WindowLimit.vm = float (vm);
1388 MyCView.Mapping.WindowLimit.uM = float (uM);
1389 MyCView.Mapping.WindowLimit.vM = float (vM);
1391 MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1392 if (MyViewMapping.IsCustomMatrix()) {
1393 Standard_Integer i, j;
1394 for (i = 0; i < 4; i++)
1395 for (j = 0; j < 4; j++)
1396 MyCView.Mapping.ProjectionMatrix[i][j] =
1397 (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j);
1400 MyMatOfMapIsEvaluated = Standard_False;
1402 if (! IsDefined ()) return;
1404 Standard_Boolean AWait = Standard_False; // => immediate update
1405 MyGraphicDriver->ViewMapping (MyCView, AWait);
1407 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1411 void Visual3d_View::SetContext (const Visual3d_ContextView& CTX) {
1413 if (IsDeleted ()) return;
1415 Visual3d_TypeOfVisualization OldVisualMode;
1416 Visual3d_TypeOfVisualization NewVisualMode;
1418 // To manage display only in case of
1419 // change of visualisation mode.
1420 OldVisualMode = MyContext.Visualization ();
1421 NewVisualMode = CTX.Visualization ();
1423 Visual3d_TypeOfModel OldModel;
1424 Visual3d_TypeOfModel NewModel;
1426 // To manage change of visualisation only in case
1427 // of change of mode of visualisation or of type of shading.
1428 OldModel = MyContext.Model ();
1429 NewModel = CTX.Model ();
1431 Standard_Boolean OldAliasingMode;
1432 Standard_Boolean NewAliasingMode;
1434 // To manage antialiasing only in case of change.
1435 OldAliasingMode = MyContext.AliasingIsOn ();
1436 NewAliasingMode = CTX.AliasingIsOn ();
1438 Standard_Boolean OldDepthCueingMode;
1439 Standard_Boolean NewDepthCueingMode;
1441 Standard_Real OldDepthCueingFrontPlane;
1442 Standard_Real NewDepthCueingFrontPlane;
1443 Standard_Real OldDepthCueingBackPlane;
1444 Standard_Real NewDepthCueingBackPlane;
1446 // To manage the depth cueing only in case of change.
1447 OldDepthCueingMode = MyContext.DepthCueingIsOn ();
1448 NewDepthCueingMode = CTX.DepthCueingIsOn ();
1450 OldDepthCueingFrontPlane = MyContext.DepthCueingFrontPlane ();
1451 NewDepthCueingFrontPlane = CTX.DepthCueingFrontPlane ();
1452 OldDepthCueingBackPlane = MyContext.DepthCueingBackPlane ();
1453 NewDepthCueingBackPlane = CTX.DepthCueingBackPlane ();
1455 Standard_Boolean OldFrontZClippingMode;
1456 Standard_Boolean NewFrontZClippingMode;
1457 Standard_Boolean OldBackZClippingMode;
1458 Standard_Boolean NewBackZClippingMode;
1460 Standard_Real OldZClippingFrontPlane;
1461 Standard_Real NewZClippingFrontPlane;
1462 Standard_Real OldZClippingBackPlane;
1463 Standard_Real NewZClippingBackPlane;
1465 // To manage the Zclipping only in case of change.
1466 OldFrontZClippingMode = MyContext.FrontZClippingIsOn ();
1467 NewFrontZClippingMode = CTX.FrontZClippingIsOn ();
1468 OldBackZClippingMode = MyContext.BackZClippingIsOn ();
1469 NewBackZClippingMode = CTX.BackZClippingIsOn ();
1471 OldZClippingFrontPlane = MyContext.ZClippingFrontPlane ();
1472 NewZClippingFrontPlane = CTX.ZClippingFrontPlane ();
1473 OldZClippingBackPlane = MyContext.ZClippingBackPlane ();
1474 NewZClippingBackPlane = CTX.ZClippingBackPlane ();
1476 Handle(Graphic3d_TextureEnv) aTexEnvOld = MyContext.TextureEnv();
1477 Handle(Graphic3d_TextureEnv) aTexEnvNew = CTX.TextureEnv();
1479 Visual3d_TypeOfSurfaceDetail OldSurfaceDetail = MyContext.SurfaceDetail();
1480 Visual3d_TypeOfSurfaceDetail NewSurfaceDetail = CTX.SurfaceDetail();
1486 Standard_Boolean AWait = Standard_False; // => immediate update
1488 // management of visualization modes and types of shading.
1489 if ((OldVisualMode != NewVisualMode) || (OldModel != NewModel))
1490 MyGraphicDriver->SetVisualisation (MyCView);
1492 // management of antialiasing.
1493 if (OldAliasingMode != NewAliasingMode)
1494 MyGraphicDriver->AntiAliasing (MyCView, NewAliasingMode);
1496 // management of depth_cueing.
1497 if ((OldDepthCueingMode != NewDepthCueingMode) ||
1498 (OldDepthCueingFrontPlane != NewDepthCueingFrontPlane) ||
1499 (OldDepthCueingBackPlane != NewDepthCueingBackPlane)) {
1501 if( NewDepthCueingMode &&
1502 (NewDepthCueingBackPlane >= NewDepthCueingFrontPlane) )
1503 Visual3d_DepthCueingDefinitionError::Raise
1504 ("Bad value for DepthCueingPlanes position");
1506 MyGraphicDriver->DepthCueing
1507 (MyCView, NewDepthCueingMode);
1510 // management of Zclipping
1511 if ((OldFrontZClippingMode != NewFrontZClippingMode) ||
1512 (OldBackZClippingMode != NewBackZClippingMode) ||
1513 (OldZClippingFrontPlane != NewZClippingFrontPlane) ||
1514 (OldZClippingBackPlane != NewZClippingBackPlane)) {
1516 if( NewBackZClippingMode && NewFrontZClippingMode &&
1517 (NewZClippingBackPlane >= NewZClippingFrontPlane) )
1518 Visual3d_ZClippingDefinitionError::Raise
1519 ("Bad value for ZClippingPlanes position");
1521 MyGraphicDriver->ClipLimit (MyCView, AWait);
1524 // management of textures
1525 if ((aTexEnvOld != aTexEnvNew) || (OldSurfaceDetail != NewSurfaceDetail))
1527 MyGraphicDriver->Environment(MyCView);
1530 // Update of planes of model clipping
1533 // Update of light sources
1537 if (OldVisualMode != NewVisualMode) {
1540 * Change of context =>
1541 * Remove structures that cannot be displayed
1542 * in the new visualisation mode.
1543 * It is not necessary to warn ViewManager as
1544 * this structure should not disappear from
1545 * the list of structures displayed in it.
1547 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
1548 Visual3d_TypeOfAnswer Answer;
1550 Standard_Integer i = MyDisplayedStructure.Extent ();
1552 Graphic3d_SequenceOfStructure FooSequence;
1554 while (S1Iterator.More ()) {
1555 Answer = AcceptDisplay (S1Iterator.Key ());
1556 // If the structure can't be displayed in the
1557 // new context of the view, it is removed.
1558 if ((Answer == Visual3d_TOA_NO) ||
1559 (Answer == Visual3d_TOA_COMPUTE))
1560 //Erase (S1Iterator.Key (), Aspect_TOU_WAIT);
1561 FooSequence.Append (S1Iterator.Key ());
1563 // S1Iterator.Next () is located on the next structure
1567 Standard_Integer Length = FooSequence.Length ();
1568 // The stored structures are removed
1569 for (i=1; i<=Length; i++)
1570 Erase (FooSequence.Value (i), Aspect_TOU_WAIT);
1571 if (Length != 0) FooSequence.Clear ();
1574 * Change of context =>
1575 * Display structures that can be displayed
1576 * with the new visualisation mode.
1577 * All structures with status Displayed are removed from the ViewManager
1578 * and displayed in the view directly, if the structure is not already
1579 * displayed and if the view accepts it in its context.
1582 i = MyViewManager->NumberOfDisplayedStructures ();
1583 Graphic3d_MapOfStructure Map;
1584 MyViewManager->DisplayedStructures(Map);
1585 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1587 for (; it.More(); it.Next()) {
1588 Handle(Graphic3d_Structure) SG = it.Key();
1589 if (! IsDisplayed (SG)) {
1590 Answer = AcceptDisplay(SG);
1591 // If the structure can be displayed in the
1592 // new context of the view, it is displayed.
1593 if ((Answer == Visual3d_TOA_YES) ||
1594 (Answer == Visual3d_TOA_COMPUTE))
1595 //Display (MyViewManager->DisplayedStructure (j),
1597 FooSequence.Append (SG);
1601 Length = FooSequence.Length ();
1602 // The stored structures are displayed
1603 for (i=1; i<=Length; i++)
1604 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
1605 if (Length != 0) FooSequence.Clear ();
1608 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1612 const Visual3d_ContextView& Visual3d_View::Context () const {
1618 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& SG) const
1621 if (IsDeleted ()) return;
1623 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
1625 while (Iterator.More ()) {
1626 SG.Add (Iterator.Key ());
1628 // Iterator.Next () is located on the next structure
1634 void Visual3d_View::Activate () {
1636 if (IsDeleted ()) return;
1639 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1641 if (! IsActive ()) {
1643 MyGraphicDriver->ActivateView (MyCView);
1644 MyGraphicDriver->Background (MyCView);
1645 MyGraphicDriver->Transparency
1646 (MyCView, MyViewManager->Transparency ());
1651 * Activation of a new view =>
1652 * Display structures that can be displayed in this new view.
1653 * All structures with status
1654 * Displayed in ViewManager are returned and displayed in
1655 * the view directly, if the structure is not already
1656 * displayed and if the view accepts it in its context.
1659 Visual3d_TypeOfAnswer Answer;
1660 Graphic3d_MapOfStructure Map;
1661 MyViewManager->DisplayedStructures(Map);
1662 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1664 for (; it.More(); it.Next()) {
1665 Handle(Graphic3d_Structure) SG = it.Key();
1666 if (! IsDisplayed (SG)) {
1667 Answer = AcceptDisplay(SG);
1668 // If the structure can be displayed in the
1669 // new context of the view, it is displayed.
1670 if ((Answer == Visual3d_TOA_YES) ||
1671 (Answer == Visual3d_TOA_COMPUTE))
1672 Display (SG,Aspect_TOU_WAIT);
1678 // If the activation/desactivation of ZBuffer should be automatic
1679 // depending on the presence or absence of facets.
1680 if (MyViewManager->ZBufferAuto ()) {
1681 Standard_Boolean BContainsFacet = ContainsFacet ();
1682 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1683 // If the view contains facets
1684 // and if ZBuffer is not active
1685 if (BContainsFacet && ! BZBuffer)
1686 SetZBufferActivity (1);
1687 // If the view does not contain facets
1688 // and if ZBuffer is active
1689 if (! BContainsFacet && BZBuffer)
1690 SetZBufferActivity (0);
1693 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1697 Standard_Boolean Visual3d_View::IsActive () const {
1699 if (IsDeleted ()) return (Standard_False);
1702 return (Standard_True);
1704 return (Standard_False);
1708 void Visual3d_View::Deactivate () {
1710 if (IsDeleted ()) return;
1713 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1717 MyGraphicDriver->DeactivateView (MyCView);
1720 * Deactivation of a view =>
1721 * Removal of structures displayed in this view.
1722 * All structures with status
1723 * Displayed in ViewManager are returned and removed from
1724 * the view directly, if the structure is not already
1725 * displayed and if the view accepts it in its context.
1728 Visual3d_TypeOfAnswer Answer;
1729 Graphic3d_MapOfStructure Map;
1730 MyViewManager->DisplayedStructures(Map);
1731 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1733 for (; it.More(); it.Next()) {
1734 Handle(Graphic3d_Structure) SG = it.Key();
1735 if (! IsDisplayed (SG)) {
1736 Answer = AcceptDisplay(SG);
1737 // If the structure was displayed it is removed.
1738 if ((Answer == Visual3d_TOA_YES) ||
1739 (Answer == Visual3d_TOA_COMPUTE))
1740 Erase (SG,Aspect_TOU_WAIT);
1744 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1746 // No action currently possible in the view
1752 void Visual3d_View::Redraw () {
1754 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1758 void Visual3d_View::Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
1760 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer (), x, y, width, height);
1763 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1765 if (IsDeleted ()) return;
1767 if ((! IsDefined ()) || (! IsActive ())) return;
1769 if (! MyWindow->IsMapped ()) return;
1771 // san - 14/04/2004 - set up Z buffer state before redrawing
1772 // If the activation/desactivation of ZBuffer should be automatic
1773 // depending on the presence or absence of facets.
1774 if (MyViewManager->ZBufferAuto ()) {
1775 Standard_Boolean BContainsFacet = ContainsFacet ();
1776 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1777 // If the view contains facets
1778 // and if ZBuffer is not active
1779 if (BContainsFacet && ! BZBuffer)
1780 SetZBufferActivity (1);
1781 // If the view contains only facets
1782 // and if ZBuffer is active
1783 if (! BContainsFacet && BZBuffer)
1784 SetZBufferActivity (0);
1787 Aspect_CLayer2d OverCLayer;
1788 Aspect_CLayer2d UnderCLayer;
1789 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1790 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1791 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1792 MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer);
1796 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) {
1798 if (IsDeleted ()) return;
1800 if ((! IsDefined ()) || (! IsActive ())) return;
1802 if (! MyWindow->IsMapped ()) return;
1804 // san - 14/04/2004 - set up Z buffer state before redrawing
1805 // If activation/desactivation of ZBuffer should be automatic
1806 // depending on the presence or absence of facets.
1807 if (MyViewManager->ZBufferAuto ()) {
1808 Standard_Boolean BContainsFacet = ContainsFacet ();
1809 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1810 // If the view contains facets
1811 // and if ZBuffer is not active
1812 if (BContainsFacet && ! BZBuffer)
1813 SetZBufferActivity (1);
1814 // If the view contains only facets
1815 // and if ZBuffer is active
1816 if (! BContainsFacet && BZBuffer)
1817 SetZBufferActivity (0);
1820 Aspect_CLayer2d OverCLayer;
1821 Aspect_CLayer2d UnderCLayer;
1822 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1823 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1824 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1825 MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer, x, y, width, height);
1829 void Visual3d_View::Update () {
1831 Update (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1835 void Visual3d_View::Update (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1837 if (IsDeleted ()) return;
1839 if ((! IsDefined ()) || (! IsActive ())) return;
1841 if (! MyWindow->IsMapped ()) return;
1843 // If activation/desactivation of ZBuffer should be automatic
1844 // depending on the presence or absence of facets.
1845 if (MyViewManager->ZBufferAuto ()) {
1846 Standard_Boolean BContainsFacet = ContainsFacet ();
1847 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1848 // If the view contains facets
1849 // and if ZBuffer is not active
1850 if (BContainsFacet && ! BZBuffer)
1851 SetZBufferActivity (1);
1852 // If the view does not contain facets
1853 // and if ZBuffer is active
1854 if (! BContainsFacet && BZBuffer)
1855 SetZBufferActivity (0);
1858 Aspect_CLayer2d OverCLayer;
1859 Aspect_CLayer2d UnderCLayer;
1860 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1861 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1862 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1863 //OSD::SetSignal (Standard_False);
1864 MyGraphicDriver->Update (MyCView, UnderCLayer, OverCLayer);
1865 //OSD::SetSignal (Standard_True);
1869 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const {
1871 // Return type of visualization of the view
1872 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
1874 // Return type of visualization of the structure
1875 Graphic3d_TypeOfStructure StructType = AStructure->Visual ();
1877 Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO;
1879 if (StructType == Graphic3d_TOS_ALL)
1880 // The structure accepts any type of view
1881 Result = Visual3d_TOA_YES;
1883 if ((StructType == Graphic3d_TOS_SHADING)
1884 && (ViewType == Visual3d_TOV_SHADING))
1885 Result = Visual3d_TOA_YES;
1886 if ((StructType == Graphic3d_TOS_WIREFRAME)
1887 && (ViewType == Visual3d_TOV_WIREFRAME))
1888 Result = Visual3d_TOA_YES;
1889 if ((StructType == Graphic3d_TOS_COMPUTED)
1890 && (ViewType == Visual3d_TOV_WIREFRAME))
1891 Result = Visual3d_TOA_COMPUTE;
1892 if ((StructType == Graphic3d_TOS_COMPUTED)
1893 && (ViewType == Visual3d_TOV_SHADING))
1894 Result = Visual3d_TOA_COMPUTE;
1898 if (Result == Visual3d_TOA_YES)
1899 cout << "YES = Visual3d_View" << MyCView.ViewId
1900 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1901 if (Result == Visual3d_TOA_NO)
1902 cout << "NO = Visual3d_View" << MyCView.ViewId
1903 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1904 if (Result == Visual3d_TOA_COMPUTE)
1905 cout << "COMPUTE = Visual3d_View" << MyCView.ViewId
1906 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1914 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer /*OldPriority*/, const Standard_Integer NewPriority) {
1916 if (IsDeleted ()) return;
1917 if (! IsDefined ()) return;
1918 if (! IsActive ()) return;
1919 if (! IsDisplayed (AStructure)) return;
1921 Standard_Integer Index = IsComputed (AStructure);
1922 if (Index != 0 && ComputedMode())
1925 Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification ();
1926 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1927 << AStructure->Identification () << "/" << StructId
1928 << ", " << OldPriority << ", " << NewPriority << ")\n";
1931 MyGraphicDriver->EraseStructure
1933 *(Graphic3d_CStructure *)
1934 MyCOMPUTEDSequence.Value (Index)->CStructure ());
1935 MyGraphicDriver->DisplayStructure
1937 *(Graphic3d_CStructure *)
1938 MyCOMPUTEDSequence.Value (Index)->CStructure (),
1943 Standard_Integer StructId = AStructure->Identification ();
1944 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1945 << AStructure->Identification () << "/" << StructId
1946 << ", " << OldPriority << ", " << NewPriority << ")\n";
1949 MyGraphicDriver->EraseStructure
1951 *(Graphic3d_CStructure *)AStructure->CStructure ());
1952 MyGraphicDriver->DisplayStructure
1954 *(Graphic3d_CStructure *)AStructure->CStructure (),
1960 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
1963 cout << "Visual3d_View" << MyCView.ViewId << "::Clear ("
1964 << AStructure->Identification () << ")\n";
1968 Standard_Integer Index = IsComputed (AStructure);
1971 cout << "Structure " << AStructure->Identification ()
1972 << " calculated in the view "
1973 << Identification () << ", by structure "
1974 << MyCOMPUTEDSequence.Value (Index)->Identification ()
1975 << " is emptied.\n";
1978 MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction);
1979 MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False);
1984 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
1986 #ifdef TRACE_CONNECT
1987 cout << "Visual3d_View" << MyCView.ViewId << "::Connect ("
1988 << AMother->Identification ()
1989 << ADaughter->Identification () << ")\n";
1993 Standard_Integer IndexM = IsComputed (AMother);
1994 Standard_Integer IndexD = IsComputed (ADaughter);
1996 if (IndexM != 0 && IndexD != 0) {
1997 #ifdef TRACE_CONNECT
1998 cout << "Structure " << AMother->Identification ()
1999 << " is connected to structure "
2000 << ADaughter->Identification () << endl;
2001 cout << "These structures are calculated.\n";
2002 cout << "In the view " << Identification ()
2004 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
2005 << " is connected to the structure "
2006 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
2009 MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD));
2014 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
2016 #ifdef TRACE_CONNECT
2017 cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect ("
2018 << AMother->Identification ()
2019 << ADaughter->Identification () << ")\n";
2023 Standard_Integer IndexM = IsComputed (AMother);
2024 Standard_Integer IndexD = IsComputed (ADaughter);
2026 if (IndexM != 0 && IndexD != 0) {
2027 #ifdef TRACE_CONNECT
2028 cout << "Structure " << AMother->Identification ()
2029 << " is disconnected from the structure "
2030 << ADaughter->Identification () << endl;
2031 cout << "These structures are calculated.\n";
2032 cout << "In the view " << Identification ()
2034 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
2035 << " is disconnected from the structure "
2036 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
2039 MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD));
2044 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure) {
2046 Display (AStructure, MyViewManager->UpdateMode ());
2050 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2052 if (IsDeleted ()) return;
2053 if (! IsDefined ()) return;
2054 if (! IsActive ()) return;
2056 // If Display on a structure present in the list
2057 // of calculated structures while it is not
2058 // or more, of calculated type =>
2059 // - removes it as well as the associated old computed
2060 // THis happens when hlhsr becomes again of type e
2061 // non computed after SetVisual.
2062 Standard_Integer Index = IsComputed (AStructure);
2064 if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) {
2067 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2068 cout << "In Visual3d_View::Display, ";
2069 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2070 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2074 MyTOCOMPUTESequence.Remove (Index);
2075 MyCOMPUTEDSequence.Remove (Index);
2078 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2079 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2080 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2086 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2088 #ifdef TRACE_DISPLAY
2089 Standard_Integer StructId = AStructure->Identification ();
2090 cout << "Visual3d_View" << MyCView.ViewId << "::Display ("
2091 << StructId << ");\n";
2095 if (Answer == Visual3d_TOA_NO) {
2096 #ifdef TRACE_DISPLAY
2097 cout << "Answer : Visual3d_TOA_NO\n";
2103 if (!ComputedMode())
2105 Answer = Visual3d_TOA_YES;
2108 if (Answer == Visual3d_TOA_YES ) {
2109 #ifdef TRACE_DISPLAY
2110 cout << "Answer : Visual3d_TOA_YES\n";
2113 if (IsDisplayed (AStructure)) return;
2114 MyGraphicDriver->DisplayStructure (
2116 *(Graphic3d_CStructure *)AStructure->CStructure (),
2117 int (AStructure->DisplayPriority ())
2119 MyDisplayedStructure.Add (AStructure);
2120 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2123 if (Answer == Visual3d_TOA_COMPUTE) {
2124 #ifdef TRACE_DISPLAY
2125 cout << "Answer : Visual3d_TOA_COMPUTE\n";
2126 cout << "Index : " << Index << "\n" << flush;
2129 // Already computed, is COMPUTED still valid?
2130 #ifdef TRACE_DISPLAY
2131 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2132 cout << "Structure "
2133 << MyTOCOMPUTESequence.Value (Index)->Identification ()
2134 << "already calculated, in the view "
2135 << Identification () << ", par la structure "
2136 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2137 << "\n was not recalculated as HLR is valid\n";
2141 cout << "Structure "
2142 << MyTOCOMPUTESequence.Value (Index)->Identification ()
2143 << " already calculated, in the view "
2144 << Identification () << ", by the structure "
2145 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2146 << "\n should be recalculated as HLR is invalid\n";
2150 Standard_Integer OldStructId =
2151 MyCOMPUTEDSequence.Value (Index)->Identification ();
2153 // Case COMPUTED valide
2154 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2156 if (! IsDisplayed (AStructure)) {
2157 MyDisplayedStructure.Add (AStructure);
2158 MyGraphicDriver->DisplayStructure (
2160 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
2161 int (AStructure->DisplayPriority ())
2163 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2168 // Case COMPUTED invalid
2170 // Is there another valid representation ?
2171 // Find in the sequence of already calculated structures
2172 // 1/ Structure having the same Owner as <AStructure>
2173 // 2/ That is not <AStructure>
2174 // 3/ The COMPUTED which of is valid
2175 Standard_Integer NewIndex = HaveTheSameOwner (AStructure);
2177 // Case of COMPUTED invalid, WITH a valid of replacement
2178 if (NewIndex != 0) {
2180 if (! IsDisplayed (AStructure)) {
2181 MyCOMPUTEDSequence.SetValue
2182 (Index, MyCOMPUTEDSequence.Value (NewIndex));
2183 OldStructId = MyCOMPUTEDSequence.Value (NewIndex)->
2185 MyDisplayedStructure.Add (AStructure);
2186 MyGraphicDriver->DisplayStructure (
2188 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (NewIndex)->CStructure (),
2189 int (AStructure->DisplayPriority ())
2191 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2196 // Cas COMPUTED invalid, WITHOUT a valid of replacement
2198 // COMPUTED is removed if displayed
2199 if (IsDisplayed (AStructure))
2200 MyGraphicDriver->EraseStructure (
2202 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()
2206 } // if (Index != 0)
2208 // Compute + Validation
2210 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
2212 Handle(Graphic3d_Structure) TheStructure;
2213 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
2214 AStructure->Transform (ATrsf);
2216 TColStd_Array2OfReal Ident (0, 3, 0, 3);
2217 Standard_Integer ii, jj;
2218 for (ii=0; ii<=3; ii++)
2219 for (jj=0; jj<=3; jj++)
2220 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
2221 TheStructure = MyCOMPUTEDSequence.Value (Index);
2222 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
2223 if (AStructure->IsTransformed ()) {
2224 AStructure->Compute (this, ATrsf, TheStructure);
2227 AStructure->Compute (this, TheStructure);
2231 if (AStructure->IsTransformed ()) {
2232 TheStructure = AStructure->Compute (this, ATrsf);
2235 TheStructure = AStructure->Compute (this);
2239 TheStructure->SetHLRValidation (Standard_True);
2242 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2243 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2244 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2248 // TOCOMPUTE and COMPUTED associated to sequences are added
2249 MyTOCOMPUTESequence.Append (AStructure);
2250 MyCOMPUTEDSequence.Append (TheStructure);
2253 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2254 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2255 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2259 // The previous are removed if necessary
2261 MyTOCOMPUTESequence.Remove (Index);
2262 MyCOMPUTEDSequence.Remove (Index);
2266 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2267 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2268 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2272 // Return type of visualisation of the view
2273 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
2275 // Of which type will be the computed ?
2276 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
2277 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
2279 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
2280 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
2282 if (ComputeWireframe)
2283 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
2285 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
2287 if (! ComputeShading && ! ComputeWireframe)
2288 Answer = Visual3d_TOA_NO;
2290 Answer = AcceptDisplay (TheStructure);
2292 if (AStructure->IsHighlighted()) {
2293 TheStructure->SetHighlightColor (AStructure->HighlightColor ());
2294 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
2297 #ifdef TRACE_DISPLAY
2298 cout << "Structure " << StructId
2299 << " in the view " << Identification ()
2300 << " is calculated by the structure "
2301 << TheStructure->Identification ();
2302 if (Answer == Visual3d_TOA_YES)
2303 cout << " and displayed\n";
2305 cout << " but not displayed\n";
2309 // It is displayed only if the calculated structure
2310 // has a proper type corresponding to the one of the view.
2311 if (Answer != Visual3d_TOA_NO) {
2312 if (! IsDisplayed (AStructure))
2313 MyDisplayedStructure.Add (AStructure);
2314 MyGraphicDriver->DisplayStructure (
2316 *(Graphic3d_CStructure *)TheStructure->CStructure (),
2317 int (AStructure->DisplayPriority ())
2319 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2321 } // Visual3d_TOA_COMPUTE
2324 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure) {
2326 if (IsDeleted ()) return;
2328 Erase (AStructure, MyViewManager->UpdateMode ());
2332 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2334 Standard_Integer StructId;
2336 if (IsDeleted ()) return;
2338 // No test on window as the structure is displayed only if
2339 // the window exists, so only one test is enough.
2340 if (IsDisplayed (AStructure)) {
2341 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2343 if (!ComputedMode())
2345 Answer = Visual3d_TOA_YES;
2348 if (Answer != Visual3d_TOA_COMPUTE) {
2349 MyGraphicDriver->EraseStructure (
2351 *(Graphic3d_CStructure *)AStructure->CStructure ()
2355 if (Answer == Visual3d_TOA_COMPUTE) {
2356 Standard_Integer Index = IsComputed (AStructure);
2358 cout << "Visual3d_View" << MyCView.ViewId << "::Erase ("
2359 << AStructure->Identification () << ");\n";
2360 cout << "Index : " << Index << "\n";
2364 if (Index != 0 && ComputedMode())
2367 MyCOMPUTEDSequence.Value (Index)->Identification ();
2369 cout << "Structure " << AStructure->Identification ()
2370 << " calculated, in the view "
2371 << Identification () << ", by the structure "
2372 << StructId << " is removed. \n";
2375 MyGraphicDriver->EraseStructure
2376 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
2378 // else is impossible
2380 MyDisplayedStructure.Remove (AStructure);
2381 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2386 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
2389 cout << "Visual3d_View" << MyCView.ViewId << "::Highlight ("
2390 << AStructure->Identification () << ")\n";
2394 Standard_Integer Index = IsComputed (AStructure);
2397 cout << "Structure " << AStructure->Identification ()
2398 << " calculated, in the view "
2399 << Identification () << ", by the structure "
2400 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2401 << " passes in highlight mode.\n";
2404 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
2405 (AStructure->HighlightColor ());
2406 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod);
2411 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
2414 cout << "Visual3d_View" << MyCView.ViewId << "::Transform ("
2415 << AStructure->Identification () << ")\n";
2419 Standard_Integer Index = IsComputed (AStructure);
2422 cout << "The structure " << AStructure->Identification ()
2423 << " calculated, in the view "
2424 << Identification () << ", by the structure "
2425 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2426 << " is transformed.\n";
2429 // Test is somewhat light !
2430 // trsf is transferred only if it is :
2433 if (ATrsf (0, 1) != 0. || ATrsf (0, 2) != 0.
2434 || ATrsf (1, 0) != 0. || ATrsf (1, 2) != 0.
2435 || ATrsf (2, 0) != 0. || ATrsf (2, 1) != 0.)
2436 ReCompute (AStructure);
2438 MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf);
2443 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
2446 cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight ("
2447 << AStructure->Identification () << ")\n";
2451 Standard_Integer Index = IsComputed (AStructure);
2454 cout << "Structure " << AStructure->Identification ()
2455 << " calculated, in the view "
2456 << Identification () << ", by the structure "
2457 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2458 << " passes in unhighlight mode.\n";
2461 MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight ();
2467 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const {
2469 Standard_Integer StrId = AStructure->Identification ();
2471 Standard_Integer Result = 0;
2472 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
2474 // Recherche de la structure <AStructure> dans la
2475 // sequence des structures deja calculees
2476 for (Standard_Integer i=1; i<=Length && Result==0; i++)
2477 if ((MyTOCOMPUTESequence.Value (i))->Identification ()
2478 == StrId) Result = i;
2480 cout << "\n In the view " << Identification () << " the structure ";
2482 cout << StrId << " is calculated by "
2483 << MyCOMPUTEDSequence.Value (Result)->Identification ()
2486 cout << StrId << " is not calculated\n" << flush;
2490 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2491 cout << "In Visual3d_View::IsComputed, ";
2492 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2493 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2502 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const {
2504 Standard_Boolean Result = Standard_False;
2506 if (IsDeleted ()) return Result;
2508 Result = MyDisplayedStructure.Contains (AStructure);
2515 Standard_Boolean Visual3d_View::ContainsComputedStructure () const {
2517 Standard_Boolean Result = Standard_False;
2519 if (MyDisplayedStructure.IsEmpty ()) return Result;
2521 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
2523 Standard_Integer i = MyDisplayedStructure.Extent ();
2525 // Stop at the first structure of type TOS_COMPUTED
2526 while (! Result && Iterator.More ()) {
2528 (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED);
2530 // Iterator.Next () is located on the
2540 Standard_Boolean Visual3d_View::ContainsFacet () const {
2542 return ContainsFacet (MyDisplayedStructure);
2546 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const {
2548 Standard_Boolean Result = Standard_False;
2550 if (ASet.IsEmpty ()) return Result;
2552 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2554 // Stop at the first structure containing a facet
2555 for ( Iterator.Initialize (ASet);
2556 Iterator.More () && ! Result;
2558 Result = (Iterator.Key ())->ContainsFacet ();
2564 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
2567 (MyDisplayedStructure, XMin, YMin, ZMin, XMax, YMax, ZMax);
2571 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 {
2573 if (ASet.IsEmpty ()) {
2574 XMin = RealFirst ();
2575 YMin = RealFirst ();
2576 ZMin = RealFirst ();
2584 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2585 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2591 XMax = RealFirst ();
2592 YMax = RealFirst ();
2593 ZMax = RealFirst ();
2595 for ( Iterator.Initialize (ASet);
2599 if ( (Iterator.Key ())->IsInfinite ()){
2600 //XMin, YMin .... ZMax are initialized by means of infinite line data
2601 (Iterator.Key ())->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
2602 if ( Xm != RealFirst() && Xm < XMin )
2604 if ( Ym != RealFirst() && Ym < YMin )
2606 if ( Zm != RealFirst() && Zm < ZMin )
2608 if ( XM != RealLast() && XM > XMax )
2610 if ( YM != RealLast() && YM > YMax )
2612 if ( ZM != RealLast() && ZM > ZMax )
2615 // Only non-empty and non-infinite structures
2616 // are taken into account for calculation of MinMax
2617 if (! (Iterator.Key ())->IsInfinite () &&
2618 ! (Iterator.Key ())->IsEmpty ()) {
2619 (Iterator.Key ())->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
2620 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
2621 //"FitAll" operation ignores object with transform persitence parameter
2622 if( (Iterator.Key ())->TransformPersistenceMode() == Graphic3d_TMF_None )
2624 if (Xm < XMin) XMin = Xm;
2625 if (Ym < YMin) YMin = Ym;
2626 if (Zm < ZMin) ZMin = Zm;
2627 if (XM > XMax) XMax = XM;
2628 if (YM > YMax) YMax = YM;
2629 if (ZM > ZMax) ZMax = ZM;
2634 // The following cases are relevant
2635 // For exemple if all structures are empty or infinite
2636 if (XMax < XMin) { Xm = XMin; XMin = XMax; XMax = Xm; }
2637 if (YMax < YMin) { Ym = YMin; YMin = YMax; YMax = Ym; }
2638 if (ZMax < ZMin) { Zm = ZMin; ZMin = ZMax; ZMax = Zm; }
2640 Standard_Real Sx, Sy, Sz;
2641 MyViewOrientation.AxialScale(Sx, Sy, Sz);
2642 XMin = (Sx > 1. && XMin < RealFirst ()/Sx)?RealFirst (): XMin*Sx;
2643 XMax = (Sx > 1. && XMax > RealLast ()/Sx)?RealLast (): XMax*Sx;
2644 YMin = (Sy > 1. && YMin < RealFirst ()/Sy)?RealFirst (): YMin*Sy;
2645 YMax = (Sy > 1. && YMax > RealLast ()/Sy)?RealLast (): YMax*Sy;
2646 ZMin = (Sz > 1. && ZMin < RealFirst ()/Sz)?RealFirst (): ZMin*Sz;
2647 ZMax = (Sz > 1. && ZMax > RealLast ()/Sz)?RealLast (): ZMax*Sz;
2650 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2652 MinMaxValues (MyDisplayedStructure, XMin, YMin, XMax, YMax);
2656 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2658 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2659 Standard_Real Xp, Yp, Zp;
2661 MinMaxValues (ASet, Xm, Ym, Zm, XM, YM, ZM);
2663 Projects (Xm, Ym, Zm, Xp, Yp, Zp);
2667 Projects (XM, YM, ZM, Xp, Yp, Zp);
2671 if (XMax < XMin) { Xp = XMax; XMax = XMin; XMin = Xp; }
2672 if (YMax < YMin) { Yp = YMax; YMax = YMin; YMin = Yp; }
2675 const TColStd_Array2OfReal& Visual3d_View::MatrixOfOrientation () {
2677 if (! MyMatOfOriIsEvaluated) {
2678 MyGraphicDriver->InquireMat
2679 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2680 MyMatOfMapIsEvaluated = Standard_True;
2681 MyMatOfOriIsEvaluated = Standard_True;
2684 return (MyMatrixOfOrientation);
2688 const TColStd_Array2OfReal& Visual3d_View::MatrixOfMapping () {
2690 if (! MyMatOfMapIsEvaluated) {
2691 MyGraphicDriver->InquireMat
2692 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2693 MyMatOfMapIsEvaluated = Standard_True;
2694 MyMatOfOriIsEvaluated = Standard_True;
2697 return (MyMatrixOfMapping);
2701 Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const {
2703 Standard_Integer Result = MyDisplayedStructure.Extent ();
2710 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 {
2712 math_Vector PtDC (0,3), PtWC (0,3);
2715 // Otherwise use new on Visual3d_View (constructor+destructor)
2716 // as Projects is a const method or MatrixOfOrientation and
2717 // MatrixOfMapping is not.
2718 Visual3d_View * const newthis = (Visual3d_View * const) this;
2719 newthis->MatrixOfOrientation ();
2720 newthis->MatrixOfMapping ();
2722 // World Coordinate Space
2728 // WCS -> View Reference Coordinate Space
2729 math_Vector PtVRC(0,3);
2730 PtVRC = MyMatrixOfOrientation.Multiplied (PtWC);
2732 // VRCS -> Normalized Projection Coordinate Space
2733 math_Vector PtNPC(0,3);
2734 PtNPC = MyMatrixOfMapping.Multiplied (PtVRC);
2735 for (Standard_Integer i=0; i<3; i++) PtNPC (i) = PtNPC (i) / PtNPC (3);
2738 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2739 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2742 Standard_Real Ratio;
2744 // NPCS -> Device Coordinate Space
2745 Standard_Real Dx = Standard_Real (MyCView.DefWindow.dx);
2746 Standard_Real Dy = Standard_Real (MyCView.DefWindow.dy);
2749 PtDC (0) = PtNPC (0) * Dx;
2750 PtDC (1) = Dy - PtNPC (1) * Dy * Ratio;
2752 printf("Display coordinates : %f,%f,%f,%f\n",
2753 PtDC(0),PtDC(1),PtDC(2),PtDC(3));
2756 // NPCS -> Window Space
2757 Standard_Real um, vm, uM, vM;
2758 MyViewMapping.WindowLimit (um, vm, uM, vM);
2760 Ratio = (uM - um) / (vM - vm);
2762 PtNPC (1) = PtNPC (1) * Ratio;
2764 PtNPC (0) = PtNPC (0) / Ratio;
2767 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2768 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2771 Standard_Real fpd = MyViewMapping.FrontPlaneDistance ();
2772 Standard_Real bpd = MyViewMapping.BackPlaneDistance ();
2775 * Coordinates of PtNPC are described in the space
2776 * [0-1]x[0-1]x[0-1].
2777 * It is necessary to transform x and y in the window space.
2778 * It is necessary to transform z in the space of back and front
2779 * plane, taking into account clipping planes.
2780 * Z clipping planes are defined between 0 and 1.
2783 APX = PtNPC (0) * (uM - um) + um;
2784 APY = PtNPC (1) * (vM - vm) + vm;
2785 APZ = PtNPC (2) * (fpd - bpd) + bpd;
2788 Standard_Integer l,c;
2789 printf("OrientationMatrix :");
2790 for( l=0 ; l<4 ; l++ ) {
2791 printf("\n %d->",l);
2792 for( c=0 ; c<4 ; c++ ) {
2793 printf(" %f ,",MyMatrixOfOrientation(c,l));
2797 printf("MappingMatrix :");
2798 for( l=0 ; l<4 ; l++ ) {
2799 printf("\n %d->",l);
2800 for( c=0 ; c<4 ; c++ ) {
2801 printf(" %f ,",MyMatrixOfMapping(c,l));
2805 printf("World coordinates : %f,%f,%f,%f\n",
2806 PtWC(0),PtWC(1),PtWC(2),PtWC(3));
2807 printf("View coordinates : %f,%f,%f,%f\n",
2808 PtVRC(0),PtVRC(1),PtVRC(2),PtVRC(3));
2809 printf("Display coordinates : %f,%f,%f,%f\n",
2810 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2811 printf("Window limit : %f,%f,%f,%f\n",um,vm,uM,vM);
2812 printf("Ratio : %f\n",Ratio);
2813 printf("Front-plane : %f back-plane : %f\n",fpd,bpd);
2814 printf("Projection : %f,%f,%f\n \n",APX,APY,APZ);
2818 #endif /* OLD_METHOD */
2820 // OCC18942: This method is likely to duplicate Visual3d_ViewManager::ConvertCoord() one,
2821 // therefore it is necessary to consider merging the two methods or making them call the same
2822 // graphic driver's method after OCCT 6.3.
2823 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) {
2825 Standard_Real PtX, PtY, PtZ, PtT;
2827 static Standard_Real Ratio, um, vm, uM, vM;
2828 static Standard_Real fpd, bpd;
2830 if (! MyMatOfOriIsEvaluated || ! MyMatOfMapIsEvaluated) {
2831 MyGraphicDriver->InquireMat
2832 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2833 MyMatOfOriIsEvaluated = MyMatOfMapIsEvaluated = Standard_True;
2836 // WCS -> View Reference Coordinate Space
2837 PtX = MyMatrixOfOrientation (0, 0) * AX
2838 + MyMatrixOfOrientation (0, 1) * AY
2839 + MyMatrixOfOrientation (0, 2) * AZ
2840 + MyMatrixOfOrientation (0, 3);
2841 PtY = MyMatrixOfOrientation (1, 0) * AX
2842 + MyMatrixOfOrientation (1, 1) * AY
2843 + MyMatrixOfOrientation (1, 2) * AZ
2844 + MyMatrixOfOrientation (1, 3);
2845 PtZ = MyMatrixOfOrientation (2, 0) * AX
2846 + MyMatrixOfOrientation (2, 1) * AY
2847 + MyMatrixOfOrientation (2, 2) * AZ
2848 + MyMatrixOfOrientation (2, 3);
2849 PtT = MyMatrixOfOrientation (3, 0) * AX
2850 + MyMatrixOfOrientation (3, 1) * AY
2851 + MyMatrixOfOrientation (3, 2) * AZ
2852 + MyMatrixOfOrientation (3, 3);
2854 // VRCS -> Normalized Projection Coordinate Space
2855 APX = MyMatrixOfMapping (0, 0) * PtX
2856 + MyMatrixOfMapping (0, 1) * PtY
2857 + MyMatrixOfMapping (0, 2) * PtZ
2858 + MyMatrixOfMapping (0, 3) * PtT;
2859 APY = MyMatrixOfMapping (1, 0) * PtX
2860 + MyMatrixOfMapping (1, 1) * PtY
2861 + MyMatrixOfMapping (1, 2) * PtZ
2862 + MyMatrixOfMapping (1, 3) * PtT;
2863 APZ = MyMatrixOfMapping (2, 0) * PtX
2864 + MyMatrixOfMapping (2, 1) * PtY
2865 + MyMatrixOfMapping (2, 2) * PtZ
2866 + MyMatrixOfMapping (2, 3) * PtT;
2867 APT = MyMatrixOfMapping (3, 0) * PtX
2868 + MyMatrixOfMapping (3, 1) * PtY
2869 + MyMatrixOfMapping (3, 2) * PtZ
2870 + MyMatrixOfMapping (3, 3) * PtT;
2876 // NPCS -> Window Space
2877 MyViewMapping.WindowLimit (um, vm, uM, vM);
2878 fpd = MyViewMapping.FrontPlaneDistance ();
2879 bpd = MyViewMapping.BackPlaneDistance ();
2881 if(MyCView.Mapping.IsCustomMatrix) {
2882 // OCC18942: SAN - If orientation and mapping matrices are those used by OpenGL
2883 // visualization, then X, Y and Z coordinates normally vary between -1 and 1
2884 APX = ( APX + 1 ) * 0.5 * (uM - um) + um;
2885 APY = ( APY + 1 ) * 0.5 * (vM - vm) + vm;
2887 Ratio = (uM - um) / (vM - vm);
2894 * Coordinates of APX, APY, APZ are described in the space
2895 * [0-1]x[0-1]x[0-1].
2896 * It is necessary to transform x and y in the window space.
2897 * It is necessary to transform z in the space of back and front
2898 * plane, taking into account clipping planes.
2899 * Z clipping planes are defined between 0 and 1.
2901 APX = APX * (uM - um) + um;
2902 APY = APY * (vM - vm) + vm;
2904 APZ = APZ * (fpd - bpd) + bpd;
2907 Standard_Integer Visual3d_View::Identification () const {
2909 return (Standard_Integer (MyCView.ViewId));
2914 Standard_Boolean Visual3d_View::ZBufferIsActivated () const {
2916 if (IsDeleted ()) return (Standard_False);
2918 if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);
2920 // -1 => not forced by the programmer => depends on the type of visualisation
2921 // 0 ou 1 => forced by the programmer
2923 if (MyCView.Context.ZBufferActivity == -1)
2924 if (MyContext.Visualization () == Visual3d_TOV_SHADING)
2925 return (Standard_True);
2927 return (Standard_False);
2929 if (MyCView.Context.ZBufferActivity)
2930 return (Standard_True);
2932 return (Standard_False);
2936 void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {
2938 if (IsDeleted ()) return;
2940 if ((! IsDefined ()) || (! IsActive ())) return;
2942 MyGraphicDriver->Transparency (MyCView, AnActivity);
2946 void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {
2948 if (MyCView.Context.ZBufferActivity == AnActivity) return;
2950 if (IsDeleted ()) return;
2952 if ((! IsDefined ()) || (! IsActive ())) return;
2954 MyCView.Context.ZBufferActivity = AnActivity;
2955 MyGraphicDriver->SetVisualisation (MyCView);
2959 void Visual3d_View::UpdateView () {
2961 MyCView.Context.Aliasing = (MyContext.AliasingIsOn () ? 1:0);
2962 MyCView.Context.BackZClipping =
2963 (MyContext.BackZClippingIsOn () ? 1:0);
2964 MyCView.Context.FrontZClipping =
2965 (MyContext.FrontZClippingIsOn() ? 1:0);
2966 MyCView.Context.DepthCueing =
2967 (MyContext.DepthCueingIsOn () ? 1:0);
2969 MyCView.Context.ZClipFrontPlane =
2970 float (MyContext.ZClippingFrontPlane ());
2971 MyCView.Context.ZClipBackPlane =
2972 float (MyContext.ZClippingBackPlane ());
2973 MyCView.Context.DepthFrontPlane =
2974 float (MyContext.DepthCueingFrontPlane ());
2975 MyCView.Context.DepthBackPlane =
2976 float (MyContext.DepthCueingBackPlane ());
2978 MyCView.Context.Model = int (MyContext.Model ());
2979 MyCView.Context.Visualization = int (MyContext.Visualization ());
2981 MyCView.Context.TextureEnv = MyContext.TextureEnv();
2982 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
2986 void Visual3d_View::Compute () {
2989 Standard_Integer Length = MyCOMPUTEDSequence.Length ();
2990 for (i=1; i<=Length; i++)
2991 (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);
2993 if (!ComputedMode())
2999 * Force HLRValidation to False on all structures
3000 * calculated in the view.
3003 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3004 cout << "In Visual3d_View::Compute, ";
3005 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3006 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3012 * Change of orientation or of projection type =>
3013 * Remove structures that were calculated for the
3014 * previous orientation.
3015 * Recalculation of new structures.
3017 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3018 Visual3d_TypeOfAnswer Answer;
3020 i = MyDisplayedStructure.Extent ();
3022 Graphic3d_SequenceOfStructure FooSequence;
3024 while (S1Iterator.More ()) {
3025 Answer = AcceptDisplay (S1Iterator.Key ());
3026 // If the structure was calculated, it is recalculated.
3027 if (Answer == Visual3d_TOA_COMPUTE) {
3029 cout << "AcceptDisplay ("
3030 << (S1Iterator.Key ())->Identification ()
3031 << ") == Visual3d_TOA_COMPUTE;\n";
3034 //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
3035 FooSequence.Append (S1Iterator.Key ());
3038 // S1Iterator.Next () is located on the next structure
3042 Length = FooSequence.Length ();
3043 // All stored structures are displayed
3044 for (i=1; i<=Length; i++)
3045 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
3046 if (Length != 0) FooSequence.Clear ();
3050 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
3051 if (!ComputedMode()) return;
3053 if (IsDeleted ()) return;
3055 if ((! IsDefined ()) || (! IsActive ())) return;
3057 if (! MyWindow->IsMapped ()) return;
3059 if (! AStructure->IsDisplayed ()) return;
3061 Visual3d_TypeOfAnswer Answer;
3063 Answer = AcceptDisplay (AStructure);
3065 if (Answer == Visual3d_TOA_COMPUTE) {
3066 Standard_Integer Index = IsComputed (AStructure);
3069 cout << "Structure " << AStructure->Identification ()
3070 << " is not calculated in the view "
3071 << Identification () << "\n";
3076 Standard_Integer OldStructId, NewStructId;
3078 MyCOMPUTEDSequence.Value (Index)->Identification ();
3080 Standard_Integer StructId = AStructure->Identification ();
3081 cout << "Structure " << StructId
3082 << " calculated, in the view "
3083 << Identification () << ", by the structure "
3084 << OldStructId << " is recalculated.\n";
3088 // Compute + Validation
3090 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3092 Handle(Graphic3d_Structure) TheStructure;
3093 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3094 AStructure->Transform (ATrsf);
3096 TColStd_Array2OfReal Ident (0, 3, 0, 3);
3097 Standard_Integer ii, jj;
3098 for (ii=0; ii<=3; ii++)
3099 for (jj=0; jj<=3; jj++)
3100 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3101 TheStructure = MyCOMPUTEDSequence.Value (Index);
3102 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3103 if (AStructure->IsTransformed ()) {
3104 AStructure->Compute (this, ATrsf, TheStructure);
3107 AStructure->Compute (this, TheStructure);
3111 if (AStructure->IsTransformed ()) {
3112 TheStructure = AStructure->Compute (this, ATrsf);
3115 TheStructure = AStructure->Compute (this);
3119 TheStructure->SetHLRValidation (Standard_True);
3121 // Return type of visualisation of the view
3122 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3124 // Of which type will be the computed ?
3125 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3126 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
3128 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3129 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3131 if (ComputeWireframe)
3132 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3134 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3136 if (AStructure->IsHighlighted ()) {
3137 TheStructure->SetHighlightColor
3138 (AStructure->HighlightColor ());
3139 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3143 // Find structure <AStructure>
3144 // in the sequence of structures to be calculated.
3145 NewStructId = TheStructure->Identification ();
3147 // The previous calculation is removed and the new one is dislayed
3148 MyGraphicDriver->EraseStructure (
3150 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3151 MyGraphicDriver->DisplayStructure (
3153 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3154 int (AStructure->DisplayPriority ())
3158 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3159 cout << "In Visual3d_View::ReCompute, ";
3160 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3161 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3166 // hlhsr and the new associated compute are added
3167 MyTOCOMPUTESequence.Append (AStructure);
3168 MyCOMPUTEDSequence.Append (TheStructure);
3171 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3172 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3173 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3177 // hlhsr and the new associated compute are removed
3179 MyTOCOMPUTESequence.Remove (Index);
3180 MyCOMPUTEDSequence.Remove (Index);
3183 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3184 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3185 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3193 const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver () const {
3195 return MyGraphicDriver;
3199 void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& thePlotter) const
3201 for (Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure); S1Iterator.More(); S1Iterator.Next())
3203 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3204 // displayed structure is plotted as if it was not calculated
3206 (S1Iterator.Key ())->Plot (thePlotter);
3208 (MyCOMPUTEDSequence.Value (Index))->Plot (thePlotter);
3212 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const {
3214 Standard_Integer Result = 0;
3215 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3217 // Find in the sequence of already calculated structures
3218 // 1/ Structure with the same Owner as <AStructure>
3219 // 2/ Which is not <AStructure>
3220 // 3/ COMPUTED which of is valid
3221 for (Standard_Integer i=1; i<=Length && Result==0; i++)
3222 if ((MyTOCOMPUTESequence.Value (i)->Owner () == AStructure->Owner ())
3223 && (MyTOCOMPUTESequence.Value (i)->Identification () !=
3224 AStructure->Identification ())
3225 && (MyCOMPUTEDSequence.Value (i)->HLRValidation ())) Result = i;
3231 Standard_Address Visual3d_View::CView () const {
3233 return Standard_Address (&MyCView);
3238 // Triedron methods : the Triedron is a non-zoomable object.
3240 void Visual3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
3241 const Quantity_NameOfColor YColor,
3242 const Quantity_NameOfColor ZColor,
3243 const Standard_Real SizeRatio,
3244 const Standard_Real AxisDiametr,
3245 const Standard_Integer NbFacettes) {
3246 MyGraphicDriver->ZBufferTriedronSetup(XColor, YColor, ZColor,
3247 SizeRatio, AxisDiametr, NbFacettes);
3252 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
3253 const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) {
3255 MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe);
3259 void Visual3d_View::TriedronErase () {
3261 MyGraphicDriver->TriedronErase (MyCView);
3266 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {
3268 MyGraphicDriver->TriedronEcho (MyCView,AType);
3272 Standard_Boolean checkFloat(const Standard_Real value)
3274 return value > -FLT_MAX && value < FLT_MAX;
3277 void SetMinMaxValuesCallback(void* Visual3dView)
3279 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
3281 Handle(Visual3d_View) view = (Handle(Visual3d_View)&) Visual3dView;
3282 view->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax);
3284 if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) &&
3285 checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax))
3287 Handle(Graphic3d_GraphicDriver) driver = Handle(Graphic3d_GraphicDriver)::DownCast(view->GraphicDriver());
3288 driver->GraduatedTrihedronMinMaxValues((Standard_ShortReal)xmin, (Standard_ShortReal)ymin, (Standard_ShortReal)zmin,
3289 (Standard_ShortReal)xmax, (Standard_ShortReal)ymax, (Standard_ShortReal)zmax);
3293 Standard_Boolean Visual3d_View::GetGraduatedTrihedron
3294 (/* Names of axes */
3295 TCollection_ExtendedString& xname,
3296 TCollection_ExtendedString& yname,
3297 TCollection_ExtendedString& zname,
3299 Standard_Boolean& xdrawname,
3300 Standard_Boolean& ydrawname,
3301 Standard_Boolean& zdrawname,
3303 Standard_Boolean& xdrawvalues,
3304 Standard_Boolean& ydrawvalues,
3305 Standard_Boolean& zdrawvalues,
3307 Standard_Boolean& drawgrid,
3309 Standard_Boolean& drawaxes,
3310 /* Number of splits along axes */
3311 Standard_Integer& nbx,
3312 Standard_Integer& nby,
3313 Standard_Integer& nbz,
3314 /* Offset for drawing values */
3315 Standard_Integer& xoffset,
3316 Standard_Integer& yoffset,
3317 Standard_Integer& zoffset,
3318 /* Offset for drawing names of axes */
3319 Standard_Integer& xaxisoffset,
3320 Standard_Integer& yaxisoffset,
3321 Standard_Integer& zaxisoffset,
3322 /* Draw tickmarks */
3323 Standard_Boolean& xdrawtickmarks,
3324 Standard_Boolean& ydrawtickmarks,
3325 Standard_Boolean& zdrawtickmarks,
3326 /* Length of tickmarks */
3327 Standard_Integer& xtickmarklength,
3328 Standard_Integer& ytickmarklength,
3329 Standard_Integer& ztickmarklength,
3331 Quantity_Color& gridcolor,
3332 /* Colors of axis names */
3333 Quantity_Color& xnamecolor,
3334 Quantity_Color& ynamecolor,
3335 Quantity_Color& znamecolor,
3336 /* Colors of axis and values */
3337 Quantity_Color& xcolor,
3338 Quantity_Color& ycolor,
3339 Quantity_Color& zcolor,
3340 /* Name of font for names of axes */
3341 TCollection_AsciiString& fontOfNames,
3342 /* Style of names of axes */
3343 Font_FontAspect& styleOfNames,
3344 /* Size of names of axes */
3345 Standard_Integer& sizeOfNames,
3346 /* Name of font for values */
3347 TCollection_AsciiString& fontOfValues,
3348 /* Style of values */
3349 Font_FontAspect& styleOfValues,
3350 /* Size of values */
3351 Standard_Integer& sizeOfValues) const
3353 if (!MyGTrihedron.ptrVisual3dView)
3354 return Standard_False;
3357 xname = MyGTrihedron.xname;
3358 yname = MyGTrihedron.yname;
3359 zname = MyGTrihedron.zname;
3361 xdrawname = MyGTrihedron.xdrawname;
3362 ydrawname = MyGTrihedron.ydrawname;
3363 zdrawname = MyGTrihedron.zdrawname;
3365 xdrawvalues = MyGTrihedron.xdrawvalues;
3366 ydrawvalues = MyGTrihedron.ydrawvalues;
3367 zdrawvalues = MyGTrihedron.zdrawvalues;
3369 drawgrid = MyGTrihedron.drawgrid;
3371 drawaxes = MyGTrihedron.drawaxes;
3372 /* Number of splits along axes */
3373 nbx = MyGTrihedron.nbx;
3374 nby = MyGTrihedron.nby;
3375 nbz = MyGTrihedron.nbz;
3376 /* Offset for drawing values */
3377 xoffset = MyGTrihedron.xoffset;
3378 yoffset = MyGTrihedron.yoffset;
3379 zoffset = MyGTrihedron.zoffset;
3380 /* Offset for drawing names of axes */
3381 xaxisoffset = MyGTrihedron.xaxisoffset;
3382 yaxisoffset = MyGTrihedron.yaxisoffset;
3383 zaxisoffset = MyGTrihedron.zaxisoffset;
3384 /* Draw tickmarks */
3385 xdrawtickmarks = MyGTrihedron.xdrawtickmarks;
3386 ydrawtickmarks = MyGTrihedron.ydrawtickmarks;
3387 zdrawtickmarks = MyGTrihedron.zdrawtickmarks;
3388 /* Length of tickmarks */
3389 xtickmarklength = MyGTrihedron.xtickmarklength;
3390 ytickmarklength = MyGTrihedron.ytickmarklength;
3391 ztickmarklength = MyGTrihedron.ztickmarklength;
3393 gridcolor = MyGTrihedron.gridcolor;
3394 /* Colors of axis names */
3395 xnamecolor = MyGTrihedron.xnamecolor;
3396 ynamecolor = MyGTrihedron.ynamecolor;
3397 znamecolor = MyGTrihedron.znamecolor;
3398 /* Colors of axis and values */
3399 xcolor = MyGTrihedron.xcolor;
3400 ycolor = MyGTrihedron.ycolor;
3401 zcolor = MyGTrihedron.zcolor;
3402 /* Name of font for names of axes */
3403 fontOfNames = MyGTrihedron.fontOfNames;
3404 /* Style of names of axes */
3405 styleOfNames = MyGTrihedron.styleOfNames;
3406 /* Size of names of axes */
3407 sizeOfNames = MyGTrihedron.sizeOfNames;
3408 /* Name of font for values */
3409 fontOfValues = MyGTrihedron.fontOfValues;
3410 /* Style of values */
3411 styleOfValues = MyGTrihedron.styleOfValues;
3412 /* Size of values */
3413 sizeOfValues = MyGTrihedron.sizeOfValues;
3415 return Standard_True;
3418 void Visual3d_View::GraduatedTrihedronDisplay
3419 (/* Names of axes */
3420 const TCollection_ExtendedString &xname,
3421 const TCollection_ExtendedString &yname,
3422 const TCollection_ExtendedString &zname,
3424 const Standard_Boolean xdrawname,
3425 const Standard_Boolean ydrawname,
3426 const Standard_Boolean zdrawname,
3428 const Standard_Boolean xdrawvalues,
3429 const Standard_Boolean ydrawvalues,
3430 const Standard_Boolean zdrawvalues,
3432 const Standard_Boolean drawgrid,
3434 const Standard_Boolean drawaxes,
3435 /* Number of splits along axes */
3436 const Standard_Integer nbx,
3437 const Standard_Integer nby,
3438 const Standard_Integer nbz,
3439 /* Offset for drawing values */
3440 const Standard_Integer xoffset,
3441 const Standard_Integer yoffset,
3442 const Standard_Integer zoffset,
3443 /* Offset for drawing names of axes */
3444 const Standard_Integer xaxisoffset,
3445 const Standard_Integer yaxisoffset,
3446 const Standard_Integer zaxisoffset,
3447 /* Draw tickmarks */
3448 const Standard_Boolean xdrawtickmarks,
3449 const Standard_Boolean ydrawtickmarks,
3450 const Standard_Boolean zdrawtickmarks,
3451 /* Length of tickmarks */
3452 const Standard_Integer xtickmarklength,
3453 const Standard_Integer ytickmarklength,
3454 const Standard_Integer ztickmarklength,
3456 const Quantity_Color& gridcolor,
3457 /* Colors of axis names */
3458 const Quantity_Color& xnamecolor,
3459 const Quantity_Color& ynamecolor,
3460 const Quantity_Color& znamecolor,
3461 /* Colors of axis and values */
3462 const Quantity_Color& xcolor,
3463 const Quantity_Color& ycolor,
3464 const Quantity_Color& zcolor,
3465 /* Name of font for names of axes */
3466 const TCollection_AsciiString &fontOfNames,
3467 /* Style of names of axes */
3468 const Font_FontAspect styleOfNames,
3469 /* Size of names of axes */
3470 const Standard_Integer sizeOfNames,
3471 /* Name of font for values */
3472 const TCollection_AsciiString &fontOfValues,
3473 /* Style of values */
3474 const Font_FontAspect styleOfValues,
3475 /* Size of values */
3476 const Standard_Integer sizeOfValues)
3479 MyGTrihedron.xname = xname;
3480 MyGTrihedron.yname = yname;
3481 MyGTrihedron.zname = zname;
3483 MyGTrihedron.xdrawname = xdrawname;
3484 MyGTrihedron.ydrawname = ydrawname;
3485 MyGTrihedron.zdrawname = zdrawname;
3487 MyGTrihedron.xdrawvalues = xdrawvalues;
3488 MyGTrihedron.ydrawvalues = ydrawvalues;
3489 MyGTrihedron.zdrawvalues = zdrawvalues;
3491 MyGTrihedron.drawgrid = drawgrid;
3493 MyGTrihedron.drawaxes = drawaxes;
3494 /* Number of splits along axes */
3495 MyGTrihedron.nbx = nbx;
3496 MyGTrihedron.nby = nby;
3497 MyGTrihedron.nbz = nbz;
3498 /* Offset for drawing values */
3499 MyGTrihedron.xoffset = xoffset;
3500 MyGTrihedron.yoffset = yoffset;
3501 MyGTrihedron.zoffset = zoffset;
3502 /* Offset for drawing names of axes */
3503 MyGTrihedron.xaxisoffset = xaxisoffset;
3504 MyGTrihedron.yaxisoffset = yaxisoffset;
3505 MyGTrihedron.zaxisoffset = zaxisoffset;
3506 /* Draw tickmarks */
3507 MyGTrihedron.xdrawtickmarks = xdrawtickmarks;
3508 MyGTrihedron.ydrawtickmarks = ydrawtickmarks;
3509 MyGTrihedron.zdrawtickmarks = zdrawtickmarks;
3510 /* Length of tickmarks */
3511 MyGTrihedron.xtickmarklength = xtickmarklength;
3512 MyGTrihedron.ytickmarklength = ytickmarklength;
3513 MyGTrihedron.ztickmarklength = ztickmarklength;
3515 MyGTrihedron.gridcolor = gridcolor;
3516 /* Colors of axis names */
3517 MyGTrihedron.xnamecolor = xnamecolor;
3518 MyGTrihedron.ynamecolor = ynamecolor;
3519 MyGTrihedron.znamecolor = znamecolor;
3520 /* Colors of axis and values */
3521 MyGTrihedron.xcolor = xcolor;
3522 MyGTrihedron.ycolor = ycolor;
3523 MyGTrihedron.zcolor = zcolor;
3524 /* Name of font for names of axes */
3525 MyGTrihedron.fontOfNames = fontOfNames;
3526 /* Style of names of axes */
3527 MyGTrihedron.styleOfNames = styleOfNames;
3528 /* Size of names of axes */
3529 MyGTrihedron.sizeOfNames = sizeOfNames;
3530 /* Name of font for values */
3531 MyGTrihedron.fontOfValues = fontOfValues;
3532 /* Style of values */
3533 MyGTrihedron.styleOfValues = styleOfValues;
3534 /* Size of values */
3535 MyGTrihedron.sizeOfValues = sizeOfValues;
3537 MyGTrihedron.ptrVisual3dView = this;
3538 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
3539 MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron);
3542 void Visual3d_View::GraduatedTrihedronErase()
3544 MyGTrihedron.ptrVisual3dView = NULL;
3545 MyGraphicDriver->GraduatedTrihedronErase(MyCView);
3548 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer () const {
3550 return (MyViewManager->UnderLayer ());
3554 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer () const {
3556 return (MyViewManager->OverLayer ());
3560 Standard_Integer Visual3d_View::LightLimit() const {
3562 Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit ();
3563 // printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight);
3567 Standard_Integer Visual3d_View::PlaneLimit() const {
3569 Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit ();
3570 // printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane);
3574 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
3576 return MyPtrViewManager;
3579 void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3581 if ((aMode && ComputedModeIsActive) ||
3582 (!aMode && !ComputedModeIsActive))
3587 Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure );
3588 Visual3d_TypeOfAnswer Answer;
3589 Standard_Integer StructId;
3590 Standard_Integer i = MyDisplayedStructure.Extent ();
3592 if ( !( ComputedModeIsActive = aMode ) ) {
3594 while ( S1Iterator.More () ) {
3596 Answer = AcceptDisplay ( S1Iterator.Key () );
3598 if ( Answer == Visual3d_TOA_COMPUTE ) {
3600 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
3604 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3606 MyGraphicDriver -> EraseStructure (
3608 *( Graphic3d_CStructure* )
3609 MyCOMPUTEDSequence.Value ( Index ) -> CStructure ()
3611 MyGraphicDriver -> DisplayStructure (
3613 *( Graphic3d_CStructure* )
3614 S1Iterator.Key () -> CStructure (),
3615 int ( S1Iterator.Key () -> DisplayPriority () )
3617 } // end if ( Index != 0 ) . . .
3619 } // end if ( Answer . . . )
3627 while ( S1Iterator.More () ) {
3629 Answer = AcceptDisplay ( S1Iterator.Key () );
3631 if ( Answer == Visual3d_TOA_COMPUTE ) {
3633 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
3637 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3639 MyGraphicDriver -> EraseStructure (
3641 *( Graphic3d_CStructure* )
3642 S1Iterator.Key () -> CStructure ()
3644 MyGraphicDriver -> DisplayStructure (
3646 *( Graphic3d_CStructure* )
3647 MyCOMPUTEDSequence.Value ( Index ) -> CStructure (),
3648 int ( S1Iterator.Key () -> DisplayPriority () )
3651 Display ( S1Iterator.Key (), Aspect_TOU_WAIT );
3653 if ( S1Iterator.Key () -> IsHighlighted () ) {
3655 if ( !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted () ) {
3657 MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor (
3658 S1Iterator.Key () ->
3661 MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight (
3670 Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key ();
3672 Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this );
3674 Handle( Graphic3d_Structure ) TheStructure;
3675 TColStd_Array2OfReal ATrsf ( 0, 3, 0, 3 );
3677 AStructure -> Transform ( ATrsf );
3681 TColStd_Array2OfReal Ident ( 0, 3, 0, 3 );
3682 Standard_Integer ii, jj;
3684 for ( ii = 0; ii <= 3; ++ii )
3686 for ( jj = 0; jj <= 3; ++jj )
3688 Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 );
3690 TheStructure = MyCOMPUTEDSequence.Value ( Index );
3692 TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE );
3694 if ( AStructure->IsTransformed () )
3696 AStructure -> Compute ( this, ATrsf, TheStructure );
3700 AStructure -> Compute ( this, TheStructure );
3704 if ( AStructure -> IsTransformed () )
3706 TheStructure = AStructure -> Compute ( this, ATrsf );
3710 TheStructure = AStructure -> Compute ( this );
3714 TheStructure -> SetHLRValidation ( Standard_True );
3716 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3718 Standard_Boolean ComputeWireframe =
3719 ( ( ViewType == Visual3d_TOV_WIREFRAME ) &&
3720 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING )
3723 Standard_Boolean ComputeShading =
3724 ( ( ViewType == Visual3d_TOV_SHADING ) &&
3725 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME )
3728 if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME );
3729 if ( ComputeShading ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING );
3731 if ( S1Iterator.Key () -> IsHighlighted () ) {
3733 TheStructure -> SetHighlightColor (
3734 S1Iterator.Key () -> HighlightColor ()
3736 TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR );
3740 Standard_Integer Result = 0;
3741 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3742 StructId = S1Iterator.Key () -> Identification ();
3744 for ( i = 1; i <= Length && Result == 0; ++i )
3746 if ( MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId )
3752 MyCOMPUTEDSequence.ChangeValue ( Result ) = TheStructure;
3756 MyTOCOMPUTESequence.Append ( S1Iterator.Key () );
3757 MyCOMPUTEDSequence.Append ( TheStructure );
3761 MyGraphicDriver -> EraseStructure (
3763 *( Graphic3d_CStructure* )
3764 S1Iterator.Key () -> CStructure ()
3766 MyGraphicDriver -> DisplayStructure (
3768 *( Graphic3d_CStructure* )TheStructure -> CStructure (),
3769 int ( S1Iterator.Key () -> DisplayPriority () )
3779 if ( MyViewManager -> UpdateMode () == Aspect_TOU_ASAP ) Update ();
3783 } // end Visual3d_View :: SetComputedMode
3785 Standard_Boolean Visual3d_View :: ComputedMode () const {
3787 return ComputedModeIsActive;
3789 } // end Visual3d_View :: ComputedMode
3791 void Visual3d_View :: SetBackFacingModel (
3792 const Visual3d_TypeOfBackfacingModel aModel
3797 case Visual3d_TOBM_AUTOMATIC:
3798 MyCView.Backfacing = 0;
3801 case Visual3d_TOBM_FORCE:
3802 MyCView.Backfacing = 1;
3805 case Visual3d_TOBM_DISABLE:
3806 MyCView.Backfacing = -1;
3811 MyGraphicDriver -> SetBackFacingModel ( MyCView );
3813 } // end Visual3d_View :: SetBackFacingModel
3815 Visual3d_TypeOfBackfacingModel Visual3d_View :: BackFacingModel () const {
3817 switch ( MyCView.Backfacing ) {
3820 return Visual3d_TOBM_AUTOMATIC;
3823 return Visual3d_TOBM_FORCE;
3827 return Visual3d_TOBM_DISABLE;
3829 } // end Visual3d_View :: BackFacingModel
3831 void Visual3d_View::EnableDepthTest( const Standard_Boolean enable ) const
3833 MyGraphicDriver->SetDepthTestEnabled( MyCView, enable );
3836 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
3838 return MyGraphicDriver->IsDepthTestEnabled( MyCView );
3841 void Visual3d_View::ReadDepths(const Standard_Integer x,
3842 const Standard_Integer y,
3843 const Standard_Integer width,
3844 const Standard_Integer height,
3845 const Standard_Address buffer) const
3847 MyGraphicDriver->ReadDepths( MyCView, x, y, width, height, buffer );
3850 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
3851 const Standard_Integer theHeight)
3853 return MyGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
3856 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
3858 MyGraphicDriver->FBORelease( MyCView, theFBOPtr );
3861 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
3862 Standard_Integer& theWidth, Standard_Integer& theHeight,
3863 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
3865 MyGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
3866 theWidth, theHeight,
3867 theWidthMax, theHeightMax );
3870 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
3871 const Standard_Integer theWidth, const Standard_Integer theHeight)
3873 MyGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
3874 theWidth, theHeight );
3877 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
3878 const Graphic3d_BufferType& theBufferType)
3880 return MyGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
3883 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
3885 MyGraphicDriver->SetGLLightEnabled( MyCView, enable );
3889 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
3891 return MyGraphicDriver->IsGLLightEnabled( MyCView );
3894 Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
3895 const Graphic3d_ExportFormat theFormat,
3896 const Graphic3d_SortType theSortType,
3897 const Standard_Real thePrecision,
3898 const Standard_Address theProgressBarFunc,
3899 const Standard_Address theProgressObject) const
3901 Handle(Visual3d_Layer) anUnderLayer = MyViewManager->UnderLayer();
3902 Handle(Visual3d_Layer) anOverLayer = MyViewManager->OverLayer();
3904 Aspect_CLayer2d anOverCLayer;
3905 Aspect_CLayer2d anUnderCLayer;
3906 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
3908 if (!anOverLayer.IsNull())
3909 anOverCLayer = anOverLayer->CLayer();
3910 if (!anUnderLayer.IsNull())
3911 anUnderCLayer = anUnderLayer->CLayer();
3913 Standard_Integer aWidth, aHeight;
3914 Window()->Size (aWidth, aHeight);
3916 return MyGraphicDriver->Export (theFileName, theFormat, theSortType,
3917 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
3918 thePrecision, theProgressBarFunc, theProgressObject);
3921 //=======================================================================
3922 //function : AddZLayer
3924 //=======================================================================
3926 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
3928 MyGraphicDriver->AddZLayer (MyCView, theLayerId);
3931 //=======================================================================
3932 //function : RemoveZLayer
3934 //=======================================================================
3936 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
3938 MyGraphicDriver->RemoveZLayer (MyCView, theLayerId);
3941 //=======================================================================
3942 //function : ChangeZLayer
3944 //=======================================================================
3946 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
3947 const Standard_Integer theLayerId)
3949 MyGraphicDriver->ChangeZLayer (
3950 (*(Graphic3d_CStructure*)theStructure->CStructure()), MyCView, theLayerId);