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 05-01-98 : CAL ; Ajout de AnimationMode
52 15-01-98 : FMN ; FRA60019 calcul Ratio pour MyViewMappingReset
53 15-01-98 : CAL ; Ajout de la transformation d'une TOS_COMPUTED
54 26-01-98 : CAL ; Ajout de la methode HaveTheSameOwner
55 06-02-98 : FMN ; CTS19079: TOP TEN: Probleme de highlight dans EDesigner.
56 05-03-98 : CAL ; GraphicTransform que si Trsf non invalidante
57 27-03-98 : CAL ; Ajout de TheStructure = devant Compute (...) !!!!
58 16-04-98 : CAL ; Remise a ID de la Trsf sur la COMPUTED
59 20-05-98 : CAL ; Perfs. Connection entre structures COMPUTED.
60 24-06-98 : CAL ; PRO14526 SetTransparency sur une vue non active.
61 17-07-98 : CAL ; PRO14872 test sur aTrsf dans ::SetTransform.
62 16-09-98 : BGN ; Points d'entree du Triedre (S3819, Phase 1)
63 22-09-98 : BGN ; S3989 (anciennement S3819)
64 TypeOfTriedron* from Aspect (pas Visual3d)
65 06-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
66 16-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
67 02-11-98 : CAL ; Retrait de OSD::SetSignal.
68 18-11-98 : FMN ; Correction sur la gestion de la perspective
69 02-12-98 : CAL ; S4062. Ajout des layers.
70 13-09-99 : GG ; GER61454 Adds LightLimit() and PlaneLimit() methods
71 10-11-99 : GG ; PRO19603 Add Redraw( area ) method
72 14-01-00 : GG ; IMP140100 Add ViewManager( ) method
73 22-10-01 : SAV ; Added EnableDepthTest() method.
74 30-04-02 : JMB ; MyDisplayStructure : use a Map instead of a Set (very bad performance
75 in data access when a lot of objects are used)
76 Will improve performance of selection mechanisms
78 ************************************************************************/
80 #define BUC60572 //GG_03-08-99 Add protection on Zclipping & Zcueing planes
83 #define BUC60570 //GG 14-09-99 Don't activates lighting
84 // when the view shading model is NONE.
86 #define GER61454 //GG 14-09-99 Activates model clipping planes
88 #define IMP140100 //GG14-01-00 Add ViewManager( ) method
90 #define G003 //EUG 30-09-00 Degeneration management
91 // Backfacing management
93 #define RIC120302 //GG Add a NEW SetWindow method which enable
94 // to connect a graphic widget and context to OGL.
96 #define BUC61044 /* 25/10/01 SAV ; added functionality to control gl depth testing
98 #define BUC61045 /* 25/10/01 SAV ; added functionality to control gl lighting
101 #define OCC1188 //SAV Added methods to set background image
103 /*----------------------------------------------------------------------*/
111 #define NO_TRACE_ACCEPT
112 #define NO_TRACE_CLEAR
113 #define NO_TRACE_CONNECT
114 #define NO_TRACE_HIGH
115 #define NO_TRACE_COMP
116 #define NO_TRACE_TRSF
117 #define NO_TRACE_DISPLAY
118 #define NO_TRACE_ISCOMP
119 #define NO_TRACE_LENGTH
120 #define NO_TRACE_LAYER
122 /*----------------------------------------------------------------------*/
132 #include <Visual3d_View.ixx>
133 #include <Visual3d_View.pxx>
134 #include <Visual3d_DepthCueingDefinitionError.hxx>
135 #include <Visual3d_ZClippingDefinitionError.hxx>
138 #include <math_Vector.hxx>
139 #endif /* OLD_METHOD */
143 #include <Graphic3d_Structure.hxx>
144 #include <Graphic3d_MapOfStructure.hxx>
145 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
146 #include <Graphic3d_DataStructureManager.hxx>
148 #include <Graphic3d_GraphicDriver.hxx>
149 #include <Graphic3d_GraphicDevice.hxx>
151 #include <Graphic3d_Vector.hxx>
152 #include <Graphic3d_Vertex.hxx>
154 #include <Visual3d_Light.hxx>
155 #include <Visual3d_SetOfLight.hxx>
156 #include <Visual3d_HSetOfLight.hxx>
157 #include <Visual3d_SetIteratorOfSetOfLight.hxx>
159 #include <Visual3d_ClipPlane.hxx>
160 #include <Visual3d_SetOfClipPlane.hxx>
161 #include <Visual3d_HSetOfClipPlane.hxx>
162 #include <Visual3d_SetIteratorOfSetOfClipPlane.hxx>
164 #include <Visual3d_SetIteratorOfSetOfView.hxx>
166 #include <Graphic3d_TextureEnv.hxx>
168 #include <TColStd_HArray2OfReal.hxx>
171 # include <Xw_Window.hxx>
173 # include <WNT_Window.hxx>
180 //-Global data definitions
184 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager):
187 MyViewMappingReset (),
188 MyViewOrientation (),
189 MyViewOrientationReset (),
190 MyTransformation (0, 3, 0, 3),
191 MyMatrixOfMapping (0, 3, 0, 3),
192 MyMatrixOfOrientation (0, 3, 0, 3),
193 MyTOCOMPUTESequence (),
194 MyCOMPUTEDSequence (),
195 MyDisplayedStructure ()
197 Standard_Integer i, j;
200 MyPtrViewManager = AManager.operator->();
202 MyPtrViewManager = (void *) AManager.operator->();
205 memset (&MyCView, 0, sizeof(MyCView));
206 MyCView.ViewId = int (AManager->Identification (this));
208 MyCView.IsDeleted = 0;
211 MyCView.DefWindow.IsDefined = 0;
213 MyCView.Context.NbActiveLight = 0;
214 MyCView.Context.NbActivePlane = 0;
216 MyCView.Context.ActivePlane = NULL;
221 if (i == j) MyTransformation (i, j) = 1.0;
222 else MyTransformation (i, j) = 0.0;
224 Standard_Real X, Y, Z;
226 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
227 MyCView.Orientation.ViewReferencePoint.x = float (X);
228 MyCView.Orientation.ViewReferencePoint.y = float (Y);
229 MyCView.Orientation.ViewReferencePoint.z = float (Z);
230 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
231 MyCView.Orientation.ViewReferencePlane.x = float (X);
232 MyCView.Orientation.ViewReferencePlane.y = float (Y);
233 MyCView.Orientation.ViewReferencePlane.z = float (Z);
234 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
235 MyCView.Orientation.ViewReferenceUp.x = float (X);
236 MyCView.Orientation.ViewReferenceUp.y = float (Y);
237 MyCView.Orientation.ViewReferenceUp.z = float (Z);
239 Standard_Real Sx, Sy, Sz;
241 MyViewOrientation.AxialScale(Sx, Sy, Sz);
242 MyCView.Orientation.ViewScaleX = float (Sx);
243 MyCView.Orientation.ViewScaleY = float (Sy);
244 MyCView.Orientation.ViewScaleZ = float (Sz);
246 // NKV : 23/07/07 - Define custom MODELVIEW matrix
247 MyCView.Orientation.IsCustomMatrix = 0;
248 memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
249 MyCView.Orientation.ModelViewMatrix[0][0] =
250 MyCView.Orientation.ModelViewMatrix[1][1] =
251 MyCView.Orientation.ModelViewMatrix[2][2] =
252 MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
255 Standard_Real um, vm, uM, vM;
257 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
258 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
259 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
260 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
261 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
262 MyCView.Mapping.ViewPlaneDistance =
263 float (MyViewMapping.ViewPlaneDistance ());
264 MyCView.Mapping.BackPlaneDistance =
265 float (MyViewMapping.BackPlaneDistance ());
266 MyCView.Mapping.FrontPlaneDistance =
267 float (MyViewMapping.FrontPlaneDistance ());
268 MyViewMapping.WindowLimit (um, vm, uM, vM);
269 MyCView.Mapping.WindowLimit.um = float (um);
270 MyCView.Mapping.WindowLimit.vm = float (vm);
271 MyCView.Mapping.WindowLimit.uM = float (uM);
272 MyCView.Mapping.WindowLimit.vM = float (vM);
274 // NKV : 23/07/07 - Define custom MODELVIEW matrix
275 MyCView.Mapping.IsCustomMatrix = 0;
276 memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
277 MyCView.Mapping.ProjectionMatrix[0][0] =
278 MyCView.Mapping.ProjectionMatrix[1][1] =
279 MyCView.Mapping.ProjectionMatrix[2][2] =
280 MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
283 MyCView.Context.ZBufferActivity = -1;
285 MyMatOfMapIsModified = Standard_True;
286 MyMatOfOriIsModified = Standard_True;
287 MyMatOfMapIsEvaluated = Standard_False;
288 MyMatOfOriIsEvaluated = Standard_False;
290 DegenerateModeIsActive = Standard_False;
291 AnimationModeIsActive = Standard_False;
293 MyCView.IsDegenerates = 0;
294 MyCView.IsDegeneratesPrev = 0;
295 ComputedModeIsActive = Standard_False;
296 MyCView.Backfacing = 0;
299 MyCView.ptrUnderLayer = 0;
300 MyCView.ptrOverLayer = 0;
301 MyCView.GContext = 0;
302 MyCView.GDisplayCB = 0;
303 MyCView.GClientData = 0;
305 Handle(Aspect_GraphicDriver) agd =
306 (MyViewManager->GraphicDevice ())->GraphicDriver ();
308 MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
312 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager, const Visual3d_ViewOrientation& VO, const Visual3d_ViewMapping& VM, const Visual3d_ContextView& CTX):
313 MyTransformation (0, 3, 0, 3),
314 MyMatrixOfMapping (0, 3, 0, 3),
315 MyMatrixOfOrientation (0, 3, 0, 3),
316 MyTOCOMPUTESequence (),
317 MyCOMPUTEDSequence (),
318 MyDisplayedStructure ()
320 Standard_Integer i, j;
323 MyPtrViewManager = AManager.operator->();
325 MyPtrViewManager = (void *) AManager.operator->();
328 MyViewOrientation = VO;
331 MyViewOrientationReset = VO;
332 MyViewMappingReset = VM;
334 memset (&MyCView, 0, sizeof(MyCView));
335 MyCView.ViewId = int (AManager->Identification (this));
337 MyCView.IsDeleted = 0;
340 MyCView.DefWindow.IsDefined = 0;
342 MyCView.Context.NbActiveLight = 0;
343 MyCView.Context.NbActivePlane = 0;
345 MyCView.Context.ActivePlane = NULL;
350 if (i == j) MyTransformation (i, j) = 1.0;
351 else MyTransformation (i, j) = 0.0;
353 Standard_Real X, Y, Z;
355 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
356 MyCView.Orientation.ViewReferencePoint.x = float (X);
357 MyCView.Orientation.ViewReferencePoint.y = float (Y);
358 MyCView.Orientation.ViewReferencePoint.z = float (Z);
359 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
360 MyCView.Orientation.ViewReferencePlane.x = float (X);
361 MyCView.Orientation.ViewReferencePlane.y = float (Y);
362 MyCView.Orientation.ViewReferencePlane.z = float (Z);
363 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
364 MyCView.Orientation.ViewReferenceUp.x = float (X);
365 MyCView.Orientation.ViewReferenceUp.y = float (Y);
366 MyCView.Orientation.ViewReferenceUp.z = float (Z);
368 Standard_Real Sx, Sy, Sz;
370 MyViewOrientation.AxialScale(Sx, Sy, Sz);
371 MyCView.Orientation.ViewScaleX = float (Sx);
372 MyCView.Orientation.ViewScaleY = float (Sy);
373 MyCView.Orientation.ViewScaleZ = float (Sz);
375 // NKV : 23/07/07 - Define custom MODELVIEW matrix
376 if (MyViewOrientation.IsCustomMatrix()) {
377 MyCView.Orientation.IsCustomMatrix = 1;
378 for ( i = 0; i < 4; i++)
379 for ( j = 0; j < 4; j++)
380 MyCView.Orientation.ModelViewMatrix[i][j] = MyViewOrientation.MyModelViewMatrix->Value(i,j);
383 MyCView.Orientation.IsCustomMatrix = 0;
384 memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
385 MyCView.Orientation.ModelViewMatrix[0][0] =
386 MyCView.Orientation.ModelViewMatrix[1][1] =
387 MyCView.Orientation.ModelViewMatrix[2][2] =
388 MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
392 Standard_Real um, vm, uM, vM;
394 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
395 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
396 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
397 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
398 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
399 MyCView.Mapping.ViewPlaneDistance =
400 float (MyViewMapping.ViewPlaneDistance ());
401 MyCView.Mapping.BackPlaneDistance =
402 float (MyViewMapping.BackPlaneDistance ());
403 MyCView.Mapping.FrontPlaneDistance =
404 float (MyViewMapping.FrontPlaneDistance ());
405 MyViewMapping.WindowLimit (um, vm, uM, vM);
406 MyCView.Mapping.WindowLimit.um = float (um);
407 MyCView.Mapping.WindowLimit.vm = float (vm);
408 MyCView.Mapping.WindowLimit.uM = float (uM);
409 MyCView.Mapping.WindowLimit.vM = float (vM);
411 // NKV : 23/07/07 - Define custom MODELVIEW matrix
412 if (MyViewMapping.IsCustomMatrix()) {
413 MyCView.Mapping.IsCustomMatrix = 1;
414 for ( i = 0; i < 4; i++)
415 for ( j = 0; j < 4; j++)
416 MyCView.Mapping.ProjectionMatrix[i][j] = MyViewMapping.MyProjectionMatrix->Value(i,j);
419 MyCView.Mapping.IsCustomMatrix = 0;
420 memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
421 MyCView.Mapping.ProjectionMatrix[0][0] =
422 MyCView.Mapping.ProjectionMatrix[1][1] =
423 MyCView.Mapping.ProjectionMatrix[2][2] =
424 MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
428 MyCView.Context.ZBufferActivity = -1;
430 MyMatOfMapIsModified = Standard_True;
431 MyMatOfOriIsModified = Standard_True;
432 MyMatOfMapIsEvaluated = Standard_False;
433 MyMatOfOriIsEvaluated = Standard_False;
435 AnimationModeIsActive = Standard_False;
436 MyCView.IsDegenerates = 0;
437 MyCView.IsDegeneratesPrev = 0;
438 ComputedModeIsActive = Standard_False;
441 MyCView.ptrUnderLayer = 0;
442 MyCView.ptrOverLayer = 0;
443 MyCView.GContext = 0;
444 MyCView.GDisplayCB = 0;
445 MyCView.GClientData = 0;
447 Handle(Aspect_GraphicDriver) agd =
448 (MyViewManager->GraphicDevice ())->GraphicDriver ();
450 MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
458 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow,
459 const Aspect_RenderingContext AContext,
460 const Aspect_GraphicCallbackProc& ADisplayCB,
461 const Standard_Address AClientData)
463 if (IsDeleted ()) return;
466 Visual3d_ViewDefinitionError::Raise ("Window already defined");
468 MyCView.GContext = AContext;
469 MyCView.GDisplayCB = ADisplayCB;
470 MyCView.GClientData = AClientData;
475 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow) {
477 if (IsDeleted ()) return;
480 Visual3d_ViewDefinitionError::Raise ("Window already defined");
483 MyCView.WsId = MyCView.ViewId;
484 MyCView.DefWindow.IsDefined = 1;
486 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AWindow;
487 MyCView.DefWindow.XWindow = theWindow->XWindow ();
489 MyCView.DefWindow.XParentWindow = theWindow->XParentWindow ();
493 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AWindow;
494 MyCView.DefWindow.XWindow = ( HWND )(theWindow->HWindow());
496 MyCView.DefWindow.XParentWindow = ( HWND )(theWindow->HParentWindow());
498 wd = ( WNT_WindowData* )GetWindowLongPtr (( HWND )(theWindow->HWindow()), GWLP_USERDATA);
499 wd -> WNT_WDriver_Ptr = ( void* )this;
500 wd -> WNT_VMgr = ( void* )MyPtrViewManager;
503 Standard_Integer Width, Height;
504 AWindow->Size (Width, Height);
506 MyCView.DefWindow.dx = float( Width );
507 MyCView.DefWindow.dy = float( Height );
509 Standard_Real R, G, B;
510 MyBackground = MyWindow->Background ();
511 (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
512 MyCView.DefWindow.Background.r = float (R);
513 MyCView.DefWindow.Background.g = float (G);
514 MyCView.DefWindow.Background.b = float (B);
517 if (! MyGraphicDriver->View (MyCView))
518 Visual3d_ViewDefinitionError::Raise ("Association failed");
520 MyGradientBackground = MyWindow->GradientBackground();
521 SetGradientBackground(MyGradientBackground,1);
523 Standard_Boolean AWait = Standard_False; // => immediate update
524 MyGraphicDriver->SetVisualisation (MyCView);
525 MyGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn ());
526 MyGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn ());
527 MyGraphicDriver->ClipLimit (MyCView, AWait);
528 MyGraphicDriver->Environment(MyCView);
530 // Make view manager z layer list consistent with the view's list.
531 MyViewManager->InstallZLayers (this);
533 // Update planses of model clipping
536 // Update light sources
540 * Association view-window does not cause the display
541 * of structures that can be displayed in the new view.
542 * In fact, association view-window is done, but the
543 * display is produced only if the view is activated (Activate).
550 Handle(Aspect_Window) Visual3d_View::Window () const {
553 Visual3d_ViewDefinitionError::Raise ("Window not defined");
559 Standard_Boolean Visual3d_View::IsDefined () const {
561 if (MyCView.DefWindow.IsDefined)
562 return (Standard_True);
564 return (Standard_False);
568 Standard_Boolean Visual3d_View::IsDeleted () const {
570 if (MyCView.IsDeleted)
571 return (Standard_True);
573 return (Standard_False);
577 void Visual3d_View::Destroy () {
580 cout << "Visual3d_View::Destroy (" << Identification () << ")\n";
583 // Since MyPtrViewManager can be already distroyed,
584 // avoid attempts to access it in SetBackground()
585 MyPtrViewManager = 0;
590 void Visual3d_View::Remove () {
593 cout << "Visual3d_View::Remove (" << Identification () << ")" << endl;
596 if (IsDeleted ()) return;
597 if (! IsDefined ()) return;
599 MyTOCOMPUTESequence.Clear ();
600 MyCOMPUTEDSequence.Clear ();
601 MyDisplayedStructure.Clear ();
603 Quantity_Color BlackColor (0.0, 0.0, 0.0, Quantity_TOC_RGB);
604 Aspect_Background BlackBackground (BlackColor);
605 SetBackground (BlackBackground);
607 Aspect_GradientBackground BlackGradBackground;
608 SetGradientBackground (BlackGradBackground,0);
610 if (MyPtrViewManager)
611 MyPtrViewManager->UnIdentification( MyCView.ViewId );
613 MyGraphicDriver->RemoveView (MyCView);
616 MyCView.IsDeleted = 1;
617 MyCView.DefWindow.IsDefined = 0;
619 MyMatOfMapIsModified = Standard_True;
620 MyMatOfOriIsModified = Standard_True;
621 MyMatOfMapIsEvaluated = Standard_False;
622 MyMatOfOriIsEvaluated = Standard_False;
628 void Visual3d_View::Resized () {
630 if (IsDeleted ()) return;
633 Visual3d_ViewDefinitionError::Raise ("Window not defined");
634 MyWindow->DoResize() ;
639 void Visual3d_View::SetRatio () {
641 if (IsDeleted ()) return;
643 Aspect_TypeOfUpdate UpdateMode = MyViewManager->UpdateMode ();
644 MyViewManager->SetUpdateMode (Aspect_TOU_WAIT);
646 Standard_Real Umin, Vmin, Umax, Vmax;
647 Standard_Integer Dxw, Dyw;
648 Standard_Real Dxv, Dyv;
649 Standard_Real Xc, Yc;
653 MyWindow->Size (Dxw, Dyw);
654 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
655 Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
656 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
657 if( Dxw > 0 && Dyw > 0 ) Rap = (Standard_Real)Dyw/(Standard_Real)Dxw ;
687 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
688 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
690 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
692 // Update before SetViewMapping.
694 MyCView.DefWindow.dx = float( Dxw );
695 MyCView.DefWindow.dy = float( Dyw );
697 SetViewMapping (MyViewMapping);
698 // SetViewMappingDefault ();
699 // FMN+ Update Ratio for MyViewMappingReset
701 MyViewMappingReset.WindowLimit(Umin,Vmin,Umax,Vmax) ;
702 Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
703 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
732 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
733 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
735 MyViewMappingReset.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
737 // FMN- Update Ratio for MyViewMappingReset
739 MyGraphicDriver->RatioWindow (MyCView);
742 // Force recalculation of 2 matrices.
744 // The current view can help to reconstruct a copied view
745 // that is itself. Owing to SetWindow and SetRatio the
746 // recalculation of matrices of this new view is imposed.
747 MyMatOfMapIsEvaluated = Standard_False;
748 MyMatOfOriIsEvaluated = Standard_False;
750 MyViewManager->SetUpdateMode (UpdateMode);
751 if (UpdateMode == Aspect_TOU_ASAP) Update ();
755 void Visual3d_View::UpdateLights () {
757 Standard_Integer i, j;
758 CALL_DEF_LIGHT *lights=NULL;
761 if( MyContext.Model() == Visual3d_TOM_NONE ) {
762 // Activates only a white ambient light
763 MyCView.Context.NbActiveLight = 1;
764 lights = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
765 MyCView.Context.ActiveLight = lights;
767 lights[0].WsId = MyCView.ViewId;
768 lights[0].ViewId = MyCView.ViewId;
769 lights[0].LightType = int (Visual3d_TOLS_AMBIENT);
770 lights[0].Active = 1;
771 lights[0].LightId = 0;
772 lights[0].Headlight = 0;
773 lights[0].Color.r = lights[0].Color.g = lights[0].Color.b = 1.;
776 i = MyContext.NumberOfActivatedLights ();
777 j = MyGraphicDriver->InquireLightLimit ();
778 MyCView.Context.NbActiveLight = (i > j ? j : i);
780 if (MyCView.Context.NbActiveLight > 0) {
782 // Dynamic Allocation
783 lights = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
785 MyCView.Context.ActiveLight = lights;
787 Standard_Real X, Y, Z;
789 Standard_Real LightConcentration;
790 Standard_Real LightAttenuation1;
791 Standard_Real LightAttenuation2;
792 Standard_Real LightAngle;
793 Quantity_Color LightColor;
794 Graphic3d_Vertex LightPosition;
795 Graphic3d_Vector LightDirection;
796 Visual3d_TypeOfLightSource LightType=Visual3d_TOLS_AMBIENT;
798 // Parcing of light sources
799 for (j=0; j<MyCView.Context.NbActiveLight; j++) {
800 LightType = (MyContext.ActivatedLight (j+1))->LightType ();
802 lights[j].WsId = MyCView.ViewId;
803 lights[j].ViewId = MyCView.ViewId;
805 lights[j].LightType = int (LightType);
806 lights[j].Active = 1;
808 int ((MyContext.ActivatedLight (j+1))->Identification ());
809 lights[j].Headlight = (MyContext.ActivatedLight (j+1))->Headlight ()? 1:0;
813 case Visual3d_TOLS_AMBIENT :
814 (MyContext.ActivatedLight (j+1))->Values (
819 case Visual3d_TOLS_POSITIONAL :
820 (MyContext.ActivatedLight (j+1))->Values (
828 case Visual3d_TOLS_DIRECTIONAL :
829 (MyContext.ActivatedLight (j+1))->Values (
835 case Visual3d_TOLS_SPOT :
836 (MyContext.ActivatedLight (j+1))->Values (
849 lights[j].Color.r = float (LightColor.Red ());
850 lights[j].Color.g = float (LightColor.Green ());
851 lights[j].Color.b = float (LightColor.Blue ());
853 if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
854 (LightType == Visual3d_TOLS_SPOT) ) {
855 LightPosition.Coord (X, Y, Z);
856 lights[j].Position.x = float (X);
857 lights[j].Position.y = float (Y);
858 lights[j].Position.z = float (Z);
861 if ( (LightType == Visual3d_TOLS_DIRECTIONAL) ||
862 (LightType == Visual3d_TOLS_SPOT) ) {
863 LightDirection.Coord (X, Y, Z);
864 lights[j].Direction.x = float (X);
865 lights[j].Direction.y = float (Y);
866 lights[j].Direction.z = float (Z);
869 if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
870 (LightType == Visual3d_TOLS_SPOT) ) {
871 lights[j].Attenuation[0] =
872 float (LightAttenuation1);
873 lights[j].Attenuation[1] =
874 float (LightAttenuation2);
877 if (LightType == Visual3d_TOLS_SPOT) {
878 lights[j].Concentration =
879 float (LightConcentration);
889 // management of light sources
892 MyGraphicDriver->SetLight (MyCView);
894 // Dynamic allocation
895 if (MyCView.Context.NbActiveLight > 0) delete [] lights;
899 void Visual3d_View::UpdatePlanes () {
901 Standard_Integer i, j;
902 CALL_DEF_PLANE *planes=NULL;
904 i = MyContext.NumberOfActivatedClipPlanes ();
905 j = MyGraphicDriver->InquirePlaneLimit ();
906 MyCView.Context.NbActivePlane = (i > j ? j : i);
908 if (MyCView.Context.NbActivePlane > 0) {
910 // Dynamic Allocation
911 #ifdef GER61454 //Keep the plane address for the next Update !
912 if( !MyCView.Context.ActivePlane )
913 MyCView.Context.ActivePlane = new CALL_DEF_PLANE [j];
914 planes = MyCView.Context.ActivePlane;
916 planes = new CALL_DEF_PLANE [MyCView.Context.NbActivePlane];
918 MyCView.Context.ActivePlane = planes;
920 Standard_Real A, B, C, D;
922 // Parcing of clipping planes
923 for (j=0; j<MyCView.Context.NbActivePlane; j++) {
925 planes[j].WsId = MyCView.ViewId;
926 planes[j].ViewId = MyCView.ViewId;
928 planes[j].Active = 1;
930 int ((MyContext.ActivatedClipPlane (j+1))->Identification ());
932 (MyContext.ActivatedClipPlane (j+1))->Plane (A, B, C, D);
933 planes[j].CoefA = float (A);
934 planes[j].CoefB = float (B);
935 planes[j].CoefC = float (C);
936 planes[j].CoefD = float (D);
941 // Management of planes of clipping model
944 MyGraphicDriver->SetPlane (MyCView);
946 // Dynamic allocation
948 if ( MyCView.Context.ActivePlane && (MyCView.Context.NbActivePlane == 0)
950 delete [] MyCView.Context.ActivePlane;
951 MyCView.Context.ActivePlane = NULL;
954 if (MyCView.Context.NbActivePlane > 0) delete [] planes;
959 void Visual3d_View::SetBackground (const Aspect_Background& ABack) {
961 if (IsDeleted ()) return;
964 Visual3d_ViewDefinitionError::Raise ("Window not defined");
966 // At this level, only GL can update the background.
967 // It is not necessary to call MyWindow->SetBackground (ABack); as
968 // this method starts update of window background by X
969 // (if the windowing is X)
971 Standard_Real R, G, B;
972 MyBackground = ABack;
973 (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
974 MyCView.DefWindow.Background.r = float (R);
975 MyCView.DefWindow.Background.g = float (G);
976 MyCView.DefWindow.Background.b = float (B);
978 MyGraphicDriver->Background (MyCView);
980 if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
985 void Visual3d_View::SetGradientBackground(const Aspect_GradientBackground& ABack, const Standard_Boolean update)
988 if (IsDeleted ()) return;
991 Visual3d_ViewDefinitionError::Raise ("Window not defined");
993 MyGradientBackground = ABack;
994 Quantity_Color aCol1,aCol2;
995 MyGradientBackground.Colors(aCol1,aCol2);
996 MyGraphicDriver->GradientBackground(MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
1000 else if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
1004 void Visual3d_View::SetBackgroundImage( const Standard_CString FileName,
1005 const Aspect_FillMethod FillStyle,
1006 const Standard_Boolean update )
1012 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1014 MyGraphicDriver->BackgroundImage( FileName, MyCView, FillStyle );
1018 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1023 void Visual3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
1024 const Standard_Boolean update )
1030 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1032 MyGraphicDriver->SetBgImageStyle( MyCView, FillStyle );
1036 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1041 Aspect_Background Visual3d_View::Background () const {
1043 return (MyBackground);
1047 void Visual3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
1048 const Standard_Boolean update )
1053 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1055 MyGraphicDriver->SetBgGradientStyle( MyCView, FillStyle );
1059 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1064 Aspect_GradientBackground Visual3d_View::GradientBackground () const {
1066 return MyGradientBackground;
1070 void Visual3d_View::SetTransform (const TColStd_Array2OfReal& AMatrix) {
1072 if (IsDeleted ()) return;
1074 Standard_Integer lr, ur, lc, uc;
1075 Standard_Integer i, j;
1077 // Assign the new transformation in an array [0..3][0..3]
1078 // Avoid problems if the has defined a matrice [1..4][1..4]
1079 // ou [3..6][-1..2] !!
1080 lr = AMatrix.LowerRow ();
1081 ur = AMatrix.UpperRow ();
1082 lc = AMatrix.LowerCol ();
1083 uc = AMatrix.UpperCol ();
1085 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
1086 Visual3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1088 for (i=0; i<=3; i++)
1089 for (j=0; j<=3; j++)
1090 MyTransformation (i, j) = AMatrix (lr + i, lc + j);
1092 Graphic3d_Vector VPN;
1093 Graphic3d_Vertex VRP;
1094 Graphic3d_Vector VUP;
1095 Standard_Real Sx, Sy, Sz;
1097 Visual3d_ViewOrientation NewViewOrientation;
1099 VPN = MyViewOrientation.ViewReferencePlane ();
1100 VRP = MyViewOrientation.ViewReferencePoint ();
1101 VUP = MyViewOrientation.ViewReferenceUp ();
1102 MyViewOrientation.AxialScale(Sx, Sy, Sz);
1104 NewViewOrientation.SetViewReferencePlane
1105 (Graphic3d_Structure::Transforms (Transform (), VPN));
1107 NewViewOrientation.SetViewReferencePoint
1108 (Graphic3d_Structure::Transforms (Transform (), VRP));
1110 NewViewOrientation.SetViewReferenceUp
1111 (Graphic3d_Structure::Transforms (Transform (), VUP));
1112 NewViewOrientation.SetAxialScale(Sx, Sy, Sz);
1114 SetViewOrientation (NewViewOrientation);
1116 MyMatOfOriIsModified = Standard_True;
1117 MyMatOfOriIsEvaluated = Standard_False;
1121 const TColStd_Array2OfReal& Visual3d_View::Transform () const {
1123 return (MyTransformation);
1127 void Visual3d_View::SetViewOrientation (const Visual3d_ViewOrientation& VO) {
1129 if (IsDeleted ()) return;
1131 MyViewOrientation = VO;
1133 Standard_Real X, Y, Z;
1135 // Tests on modification of parameters.
1136 Standard_Boolean VUPIsModified = Standard_False;
1137 Standard_Boolean VRPIsModified = Standard_False;
1138 Standard_Boolean VRUIsModified = Standard_False;
1139 Standard_Boolean ScaleIsModified = Standard_False;
1140 Standard_Boolean CustomIsModified = Standard_False;
1142 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1144 MyCView.Orientation.ViewReferencePoint.x != float (X)
1145 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1146 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1147 MyCView.Orientation.ViewReferencePoint.x = float (X);
1148 MyCView.Orientation.ViewReferencePoint.y = float (Y);
1149 MyCView.Orientation.ViewReferencePoint.z = float (Z);
1151 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1153 MyCView.Orientation.ViewReferencePlane.x != float (X)
1154 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1155 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1156 MyCView.Orientation.ViewReferencePlane.x = float (X);
1157 MyCView.Orientation.ViewReferencePlane.y = float (Y);
1158 MyCView.Orientation.ViewReferencePlane.z = float (Z);
1160 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1162 MyCView.Orientation.ViewReferenceUp.x != float (X)
1163 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1164 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1165 MyCView.Orientation.ViewReferenceUp.x = float (X);
1166 MyCView.Orientation.ViewReferenceUp.y = float (Y);
1167 MyCView.Orientation.ViewReferenceUp.z = float (Z);
1169 Standard_Real Sx, Sy, Sz;
1171 MyViewOrientation.AxialScale(Sx, Sy, Sz);
1173 MyCView.Orientation.ViewScaleX != float (X)
1174 || MyCView.Orientation.ViewScaleY != float (Y)
1175 || MyCView.Orientation.ViewScaleZ != float (Z);
1176 MyCView.Orientation.ViewScaleX = float (Sx);
1177 MyCView.Orientation.ViewScaleY = float (Sy);
1178 MyCView.Orientation.ViewScaleZ = float (Sz);
1181 MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
1182 MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
1183 if ( MyViewOrientation.IsCustomMatrix() ) {
1184 Standard_Integer i, j;
1185 for (i = 0; i < 4; i++)
1186 for (j = 0; j < 4; j++) {
1187 if (!CustomIsModified) CustomIsModified =
1188 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
1189 MyCView.Orientation.ModelViewMatrix[i][j] = MyViewOrientation.MyModelViewMatrix->Value(i,j);
1194 cout << "Visual3d_View::SetViewOrientation\n";
1195 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified)
1196 cout << "VUPIsModified : " << VUPIsModified
1197 << ", VRPIsModified : " << VRPIsModified
1198 << ", VRUIsModified : " << VRUIsModified
1199 << ", CustomIsModified : " << CustomIsModified << "\n" << flush;
1201 cout << "no modification\n" << flush;
1204 // restart if one of parameters is modified
1205 if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified) {
1207 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
1208 MyMatOfOriIsModified = Standard_True;
1209 MyMatOfOriIsEvaluated = Standard_False;
1212 if (! IsDefined ()) return;
1214 Standard_Boolean AWait = Standard_False; // => immediate update
1215 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1219 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1224 Visual3d_ViewOrientation Visual3d_View::ViewOrientation () const {
1226 return (MyViewOrientation);
1230 Visual3d_ViewOrientation Visual3d_View::ViewOrientationDefault () const {
1232 return (MyViewOrientationReset);
1236 void Visual3d_View::SetViewOrientationDefault () {
1238 MyViewOrientationReset.Assign (MyViewOrientation);
1242 void Visual3d_View::ViewOrientationReset () {
1244 if (IsDeleted ()) return;
1246 MyViewOrientation = MyViewOrientationReset;
1248 Standard_Real X, Y, Z;
1250 // Tests on modification of parameters.
1251 Standard_Boolean VUPIsModified = Standard_False;
1252 Standard_Boolean VRPIsModified = Standard_False;
1253 Standard_Boolean VRUIsModified = Standard_False;
1254 Standard_Boolean ScaleIsModified = Standard_False;
1255 Standard_Boolean CustomIsModified = Standard_False;
1257 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1259 MyCView.Orientation.ViewReferencePoint.x != float (X)
1260 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1261 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1262 MyCView.Orientation.ViewReferencePoint.x = float (X);
1263 MyCView.Orientation.ViewReferencePoint.y = float (Y);
1264 MyCView.Orientation.ViewReferencePoint.z = float (Z);
1266 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1268 MyCView.Orientation.ViewReferencePlane.x != float (X)
1269 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1270 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1271 MyCView.Orientation.ViewReferencePlane.x = float (X);
1272 MyCView.Orientation.ViewReferencePlane.y = float (Y);
1273 MyCView.Orientation.ViewReferencePlane.z = float (Z);
1275 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1277 MyCView.Orientation.ViewReferenceUp.x != float (X)
1278 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1279 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1280 MyCView.Orientation.ViewReferenceUp.x = float (X);
1281 MyCView.Orientation.ViewReferenceUp.y = float (Y);
1282 MyCView.Orientation.ViewReferenceUp.z = float (Z);
1284 Standard_Real Sx, Sy, Sz;
1286 MyViewOrientation.AxialScale(Sx, Sy, Sz);
1288 MyCView.Orientation.ViewScaleX != float (X)
1289 || MyCView.Orientation.ViewScaleY != float (Y)
1290 || MyCView.Orientation.ViewScaleZ != float (Z);
1291 MyCView.Orientation.ViewScaleX = float (Sx);
1292 MyCView.Orientation.ViewScaleY = float (Sy);
1293 MyCView.Orientation.ViewScaleZ = float (Sz);
1296 MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
1297 MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
1298 if ( MyViewOrientation.IsCustomMatrix() ) {
1299 Standard_Integer i, j;
1300 for (i = 0; i < 4; i++)
1301 for (j = 0; j < 4; j++) {
1302 if (!CustomIsModified) CustomIsModified =
1303 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
1304 MyCView.Orientation.ModelViewMatrix[i][j] = MyViewOrientation.MyModelViewMatrix->Value(i,j);
1309 cout << "Visual3d_View::ViewOrientationReset\n";
1310 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified)
1311 cout << "VUPIsModified : " << VUPIsModified
1312 << ", VRPIsModified : " << VRPIsModified
1313 << ", VRUIsModified : " << VRUIsModified
1314 << ", CustomIsModified : " << CustomIsModified << "\n" << flush;
1316 cout << "no modification\n" << flush;
1319 // Restart if one of parameters is modified
1320 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
1322 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
1323 MyMatOfOriIsModified = Standard_True;
1324 MyMatOfOriIsEvaluated = Standard_False;
1327 if (! IsDefined ()) return;
1329 Standard_Boolean AWait = Standard_False; // => immediate update
1330 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1334 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1339 void Visual3d_View::SetViewMapping (const Visual3d_ViewMapping& VM) {
1341 if (IsDeleted ()) return;
1343 Visual3d_TypeOfProjection OldType = MyViewMapping.Projection ();
1344 Visual3d_TypeOfProjection NewType = VM.Projection ();
1348 Standard_Real X, Y, Z;
1349 Standard_Real um, vm, uM, vM;
1351 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
1352 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1353 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
1354 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
1355 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
1356 MyCView.Mapping.ViewPlaneDistance =
1357 float (MyViewMapping.ViewPlaneDistance ());
1358 MyCView.Mapping.BackPlaneDistance =
1359 float (MyViewMapping.BackPlaneDistance ());
1360 MyCView.Mapping.FrontPlaneDistance =
1361 float (MyViewMapping.FrontPlaneDistance ());
1362 MyViewMapping.WindowLimit (um, vm, uM, vM);
1363 MyCView.Mapping.WindowLimit.um = float (um);
1364 MyCView.Mapping.WindowLimit.vm = float (vm);
1365 MyCView.Mapping.WindowLimit.uM = float (uM);
1366 MyCView.Mapping.WindowLimit.vM = float (vM);
1368 MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1369 if (MyViewMapping.IsCustomMatrix()) {
1370 Standard_Integer i, j;
1371 for (i = 0; i < 4; i++)
1372 for (j = 0; j < 4; j++)
1373 MyCView.Mapping.ProjectionMatrix[i][j] =
1374 MyViewMapping.MyProjectionMatrix->Value(i,j);
1377 MyMatOfMapIsModified = Standard_True;
1378 MyMatOfMapIsEvaluated = Standard_False;
1380 if (! IsDefined ()) return;
1382 Standard_Boolean AWait = Standard_False; // => immediate update
1383 MyGraphicDriver->ViewMapping (MyCView, AWait);
1385 // Passage Parallele/Perspective
1386 if (OldType != NewType)
1389 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1393 Visual3d_ViewMapping Visual3d_View::ViewMapping () const {
1395 return (MyViewMapping);
1399 Visual3d_ViewMapping Visual3d_View::ViewMappingDefault () const {
1401 return (MyViewMappingReset);
1405 void Visual3d_View::SetViewMappingDefault () {
1407 MyViewMappingReset.Assign (MyViewMapping);
1411 void Visual3d_View::ViewMappingReset () {
1413 if (IsDeleted ()) return;
1415 MyViewMapping = MyViewMappingReset;
1417 Standard_Real X, Y, Z;
1418 Standard_Real um, vm, uM, vM;
1420 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
1421 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1422 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
1423 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
1424 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
1425 MyCView.Mapping.ViewPlaneDistance =
1426 float (MyViewMapping.ViewPlaneDistance ());
1427 MyCView.Mapping.BackPlaneDistance =
1428 float (MyViewMapping.BackPlaneDistance ());
1429 MyCView.Mapping.FrontPlaneDistance =
1430 float (MyViewMapping.FrontPlaneDistance ());
1431 MyViewMapping.WindowLimit (um, vm, uM, vM);
1432 MyCView.Mapping.WindowLimit.um = float (um);
1433 MyCView.Mapping.WindowLimit.vm = float (vm);
1434 MyCView.Mapping.WindowLimit.uM = float (uM);
1435 MyCView.Mapping.WindowLimit.vM = float (vM);
1437 MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1438 if (MyViewMapping.IsCustomMatrix()) {
1439 Standard_Integer i, j;
1440 for (i = 0; i < 4; i++)
1441 for (j = 0; j < 4; j++)
1442 MyCView.Mapping.ProjectionMatrix[i][j] =
1443 MyViewMapping.MyProjectionMatrix->Value(i,j);
1446 MyMatOfMapIsModified = Standard_True;
1447 MyMatOfMapIsEvaluated = Standard_False;
1449 if (! IsDefined ()) return;
1451 Standard_Boolean AWait = Standard_False; // => immediate update
1452 MyGraphicDriver->ViewMapping (MyCView, AWait);
1454 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1458 void Visual3d_View::SetContext (const Visual3d_ContextView& CTX) {
1460 if (IsDeleted ()) return;
1462 Visual3d_TypeOfVisualization OldVisualMode;
1463 Visual3d_TypeOfVisualization NewVisualMode;
1465 // To manage display only in case of
1466 // change of visualisation mode.
1467 OldVisualMode = MyContext.Visualization ();
1468 NewVisualMode = CTX.Visualization ();
1470 Visual3d_TypeOfModel OldModel;
1471 Visual3d_TypeOfModel NewModel;
1473 // To manage change of visualisation only in case
1474 // of change of mode of visualisation or of type of shading.
1475 OldModel = MyContext.Model ();
1476 NewModel = CTX.Model ();
1478 Standard_Boolean OldAliasingMode;
1479 Standard_Boolean NewAliasingMode;
1481 // To manage antialiasing only in case of change.
1482 OldAliasingMode = MyContext.AliasingIsOn ();
1483 NewAliasingMode = CTX.AliasingIsOn ();
1485 Standard_Boolean OldDepthCueingMode;
1486 Standard_Boolean NewDepthCueingMode;
1488 Standard_Real OldDepthCueingFrontPlane;
1489 Standard_Real NewDepthCueingFrontPlane;
1490 Standard_Real OldDepthCueingBackPlane;
1491 Standard_Real NewDepthCueingBackPlane;
1493 // To manage the depth cueing only in case of change.
1494 OldDepthCueingMode = MyContext.DepthCueingIsOn ();
1495 NewDepthCueingMode = CTX.DepthCueingIsOn ();
1497 OldDepthCueingFrontPlane = MyContext.DepthCueingFrontPlane ();
1498 NewDepthCueingFrontPlane = CTX.DepthCueingFrontPlane ();
1499 OldDepthCueingBackPlane = MyContext.DepthCueingBackPlane ();
1500 NewDepthCueingBackPlane = CTX.DepthCueingBackPlane ();
1502 Standard_Boolean OldFrontZClippingMode;
1503 Standard_Boolean NewFrontZClippingMode;
1504 Standard_Boolean OldBackZClippingMode;
1505 Standard_Boolean NewBackZClippingMode;
1507 Standard_Real OldZClippingFrontPlane;
1508 Standard_Real NewZClippingFrontPlane;
1509 Standard_Real OldZClippingBackPlane;
1510 Standard_Real NewZClippingBackPlane;
1512 // To manage the Zclipping only in case of change.
1513 OldFrontZClippingMode = MyContext.FrontZClippingIsOn ();
1514 NewFrontZClippingMode = CTX.FrontZClippingIsOn ();
1515 OldBackZClippingMode = MyContext.BackZClippingIsOn ();
1516 NewBackZClippingMode = CTX.BackZClippingIsOn ();
1518 OldZClippingFrontPlane = MyContext.ZClippingFrontPlane ();
1519 NewZClippingFrontPlane = CTX.ZClippingFrontPlane ();
1520 OldZClippingBackPlane = MyContext.ZClippingBackPlane ();
1521 NewZClippingBackPlane = CTX.ZClippingBackPlane ();
1523 Standard_Integer OldTexEnvId;
1524 Standard_Integer NewTexEnvId;
1525 Visual3d_TypeOfSurfaceDetail OldSurfaceDetail;
1526 Visual3d_TypeOfSurfaceDetail NewSurfaceDetail;
1528 Handle(Graphic3d_TextureEnv) TempTextureEnv1 = MyContext.TextureEnv();
1529 if (! TempTextureEnv1.IsNull()) OldTexEnvId = TempTextureEnv1->TextureId();
1530 else OldTexEnvId = -1;
1532 Handle(Graphic3d_TextureEnv) TempTextureEnv2 = CTX.TextureEnv();
1534 if (! TempTextureEnv2.IsNull()) NewTexEnvId = TempTextureEnv2->TextureId();
1535 else NewTexEnvId = -1;
1537 OldSurfaceDetail = MyContext.SurfaceDetail();
1538 NewSurfaceDetail = CTX.SurfaceDetail();
1544 Standard_Boolean AWait = Standard_False; // => immediate update
1546 // management of visualization modes and types of shading.
1547 if ((OldVisualMode != NewVisualMode) || (OldModel != NewModel))
1548 MyGraphicDriver->SetVisualisation (MyCView);
1550 // management of antialiasing.
1551 if (OldAliasingMode != NewAliasingMode)
1552 MyGraphicDriver->AntiAliasing (MyCView, NewAliasingMode);
1554 // management of depth_cueing.
1555 if ((OldDepthCueingMode != NewDepthCueingMode) ||
1556 (OldDepthCueingFrontPlane != NewDepthCueingFrontPlane) ||
1557 (OldDepthCueingBackPlane != NewDepthCueingBackPlane)) {
1559 if( NewDepthCueingMode &&
1560 (NewDepthCueingBackPlane >= NewDepthCueingFrontPlane) )
1561 Visual3d_DepthCueingDefinitionError::Raise
1562 ("Bad value for DepthCueingPlanes position");
1564 MyGraphicDriver->DepthCueing
1565 (MyCView, NewDepthCueingMode);
1568 // management of Zclipping
1569 if ((OldFrontZClippingMode != NewFrontZClippingMode) ||
1570 (OldBackZClippingMode != NewBackZClippingMode) ||
1571 (OldZClippingFrontPlane != NewZClippingFrontPlane) ||
1572 (OldZClippingBackPlane != NewZClippingBackPlane)) {
1574 if( NewBackZClippingMode && NewFrontZClippingMode &&
1575 (NewZClippingBackPlane >= NewZClippingFrontPlane) )
1576 Visual3d_ZClippingDefinitionError::Raise
1577 ("Bad value for ZClippingPlanes position");
1579 MyGraphicDriver->ClipLimit (MyCView, AWait);
1582 // management of textures
1583 if ( (OldTexEnvId != NewTexEnvId) ||
1584 (OldSurfaceDetail != NewSurfaceDetail) )
1585 MyGraphicDriver->Environment(MyCView);
1587 // Update of planes of model clipping
1590 // Update of light sources
1594 if (OldVisualMode != NewVisualMode) {
1597 * Change of context =>
1598 * Remove structures that cannot be displayed
1599 * in the new visualisation mode.
1600 * It is not necessary to warn ViewManager as
1601 * this structure should not disappear from
1602 * the list of structures displayed in it.
1604 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
1605 Visual3d_TypeOfAnswer Answer;
1607 Standard_Integer i = MyDisplayedStructure.Extent ();
1609 Graphic3d_SequenceOfStructure FooSequence;
1611 while (S1Iterator.More ()) {
1612 Answer = AcceptDisplay (S1Iterator.Key ());
1613 // If the structure can't be displayed in the
1614 // new context of the view, it is removed.
1615 if ((Answer == Visual3d_TOA_NO) ||
1616 (Answer == Visual3d_TOA_COMPUTE))
1617 //Erase (S1Iterator.Key (), Aspect_TOU_WAIT);
1618 FooSequence.Append (S1Iterator.Key ());
1620 // S1Iterator.Next () is located on the next structure
1624 Standard_Integer Length = FooSequence.Length ();
1625 // The stored structures are removed
1626 for (i=1; i<=Length; i++)
1627 Erase (FooSequence.Value (i), Aspect_TOU_WAIT);
1628 if (Length != 0) FooSequence.Clear ();
1631 * Change of context =>
1632 * Display structures that can be displayed
1633 * with the new visualisation mode.
1634 * All structures with status Displayed are removed from the ViewManager
1635 * and displayed in the view directly, if the structure is not already
1636 * displayed and if the view accepts it in its context.
1639 i = MyViewManager->NumberOfDisplayedStructures ();
1640 Graphic3d_MapOfStructure Map;
1641 MyViewManager->DisplayedStructures(Map);
1642 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1644 for (; it.More(); it.Next()) {
1645 Handle(Graphic3d_Structure) SG = it.Key();
1646 if (! IsDisplayed (SG)) {
1647 Answer = AcceptDisplay(SG);
1648 // If the structure can be displayed in the
1649 // new context of the view, it is displayed.
1650 if ((Answer == Visual3d_TOA_YES) ||
1651 (Answer == Visual3d_TOA_COMPUTE))
1652 //Display (MyViewManager->DisplayedStructure (j),
1654 FooSequence.Append (SG);
1658 Length = FooSequence.Length ();
1659 // The stored structures are displayed
1660 for (i=1; i<=Length; i++)
1661 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
1662 if (Length != 0) FooSequence.Clear ();
1665 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1669 const Visual3d_ContextView& Visual3d_View::Context () const {
1675 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& SG) const
1678 if (IsDeleted ()) return;
1680 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
1682 while (Iterator.More ()) {
1683 SG.Add (Iterator.Key ());
1685 // Iterator.Next () is located on the next structure
1691 void Visual3d_View::Activate () {
1693 if (IsDeleted ()) return;
1696 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1698 if (! IsActive ()) {
1700 MyGraphicDriver->ActivateView (MyCView);
1701 MyGraphicDriver->Background (MyCView);
1702 MyGraphicDriver->Transparency
1703 (MyCView, MyViewManager->Transparency ());
1708 * Activation of a new view =>
1709 * Display structures that can be displayed in this new view.
1710 * All structures with status
1711 * Displayed in ViewManager are returned and displayed in
1712 * the view directly, if the structure is not already
1713 * displayed and if the view accepts it in its context.
1716 Visual3d_TypeOfAnswer Answer;
1717 Graphic3d_MapOfStructure Map;
1718 MyViewManager->DisplayedStructures(Map);
1719 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1721 for (; it.More(); it.Next()) {
1722 Handle(Graphic3d_Structure) SG = it.Key();
1723 if (! IsDisplayed (SG)) {
1724 Answer = AcceptDisplay(SG);
1725 // If the structure can be displayed in the
1726 // new context of the view, it is displayed.
1727 if ((Answer == Visual3d_TOA_YES) ||
1728 (Answer == Visual3d_TOA_COMPUTE))
1729 Display (SG,Aspect_TOU_WAIT);
1735 // If the activation/desactivation of ZBuffer should be automatic
1736 // depending on the presence or absence of facets.
1737 if (MyViewManager->ZBufferAuto ()) {
1738 Standard_Boolean BContainsFacet = ContainsFacet ();
1739 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1740 // If the view contains facets
1741 // and if ZBuffer is not active
1742 if (BContainsFacet && ! BZBuffer)
1743 SetZBufferActivity (1);
1744 // If the view does not contain facets
1745 // and if ZBuffer is active
1746 if (! BContainsFacet && BZBuffer)
1747 SetZBufferActivity (0);
1750 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1754 Standard_Boolean Visual3d_View::IsActive () const {
1756 if (IsDeleted ()) return (Standard_False);
1759 return (Standard_True);
1761 return (Standard_False);
1765 void Visual3d_View::Deactivate () {
1767 if (IsDeleted ()) return;
1770 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1774 MyGraphicDriver->DeactivateView (MyCView);
1777 * Deactivation of a view =>
1778 * Removal of structures displayed in this view.
1779 * All structures with status
1780 * Displayed in ViewManager are returned and removed from
1781 * the view directly, if the structure is not already
1782 * displayed and if the view accepts it in its context.
1785 Visual3d_TypeOfAnswer Answer;
1786 Graphic3d_MapOfStructure Map;
1787 MyViewManager->DisplayedStructures(Map);
1788 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1790 for (; it.More(); it.Next()) {
1791 Handle(Graphic3d_Structure) SG = it.Key();
1792 if (! IsDisplayed (SG)) {
1793 Answer = AcceptDisplay(SG);
1794 // If the structure was displayed it is removed.
1795 if ((Answer == Visual3d_TOA_YES) ||
1796 (Answer == Visual3d_TOA_COMPUTE))
1797 Erase (SG,Aspect_TOU_WAIT);
1801 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1803 // No action currently possible in the view
1809 void Visual3d_View::Redraw () {
1811 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1815 void Visual3d_View::Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
1817 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer (), x, y, width, height);
1820 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1822 if (IsDeleted ()) return;
1824 if ((! IsDefined ()) || (! IsActive ())) return;
1826 if (! MyWindow->IsMapped ()) return;
1828 // san - 14/04/2004 - set up Z buffer state before redrawing
1829 // If the activation/desactivation of ZBuffer should be automatic
1830 // depending on the presence or absence of facets.
1831 if (MyViewManager->ZBufferAuto ()) {
1832 Standard_Boolean BContainsFacet = ContainsFacet ();
1833 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1834 // If the view contains facets
1835 // and if ZBuffer is not active
1836 if (BContainsFacet && ! BZBuffer)
1837 SetZBufferActivity (1);
1838 // If the view contains only facets
1839 // and if ZBuffer is active
1840 if (! BContainsFacet && BZBuffer)
1841 SetZBufferActivity (0);
1844 Aspect_CLayer2d OverCLayer;
1845 Aspect_CLayer2d UnderCLayer;
1846 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1847 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1848 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1849 MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer);
1853 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) {
1855 if (IsDeleted ()) return;
1857 if ((! IsDefined ()) || (! IsActive ())) return;
1859 if (! MyWindow->IsMapped ()) return;
1861 // san - 14/04/2004 - set up Z buffer state before redrawing
1862 // If activation/desactivation of ZBuffer should be automatic
1863 // depending on the presence or absence of facets.
1864 if (MyViewManager->ZBufferAuto ()) {
1865 Standard_Boolean BContainsFacet = ContainsFacet ();
1866 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1867 // If the view contains facets
1868 // and if ZBuffer is not active
1869 if (BContainsFacet && ! BZBuffer)
1870 SetZBufferActivity (1);
1871 // If the view contains only facets
1872 // and if ZBuffer is active
1873 if (! BContainsFacet && BZBuffer)
1874 SetZBufferActivity (0);
1877 Aspect_CLayer2d OverCLayer;
1878 Aspect_CLayer2d UnderCLayer;
1879 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1880 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1881 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1882 MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer, x, y, width, height);
1886 void Visual3d_View::Update () {
1888 Update (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1892 void Visual3d_View::Update (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1894 if (IsDeleted ()) return;
1896 if ((! IsDefined ()) || (! IsActive ())) return;
1898 if (! MyWindow->IsMapped ()) return;
1900 // If activation/desactivation of ZBuffer should be automatic
1901 // depending on the presence or absence of facets.
1902 if (MyViewManager->ZBufferAuto ()) {
1903 Standard_Boolean BContainsFacet = ContainsFacet ();
1904 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1905 // If the view contains facets
1906 // and if ZBuffer is not active
1907 if (BContainsFacet && ! BZBuffer)
1908 SetZBufferActivity (1);
1909 // If the view does not contain facets
1910 // and if ZBuffer is active
1911 if (! BContainsFacet && BZBuffer)
1912 SetZBufferActivity (0);
1915 Aspect_CLayer2d OverCLayer;
1916 Aspect_CLayer2d UnderCLayer;
1917 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1918 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1919 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1920 //OSD::SetSignal (Standard_False);
1921 MyGraphicDriver->Update (MyCView, UnderCLayer, OverCLayer);
1922 //OSD::SetSignal (Standard_True);
1924 MyMatOfMapIsModified = Standard_False;
1925 MyMatOfOriIsModified = Standard_False;
1929 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const {
1931 // Return type of visualization of the view
1932 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
1934 // Return type of visualization of the structure
1935 Graphic3d_TypeOfStructure StructType = AStructure->Visual ();
1937 Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO;
1939 if (StructType == Graphic3d_TOS_ALL)
1940 // The structure accepts any type of view
1941 Result = Visual3d_TOA_YES;
1943 if ((StructType == Graphic3d_TOS_SHADING)
1944 && (ViewType == Visual3d_TOV_SHADING))
1945 Result = Visual3d_TOA_YES;
1946 if ((StructType == Graphic3d_TOS_WIREFRAME)
1947 && (ViewType == Visual3d_TOV_WIREFRAME))
1948 Result = Visual3d_TOA_YES;
1949 if ((StructType == Graphic3d_TOS_COMPUTED)
1950 && (ViewType == Visual3d_TOV_WIREFRAME))
1951 Result = Visual3d_TOA_COMPUTE;
1952 if ((StructType == Graphic3d_TOS_COMPUTED)
1953 && (ViewType == Visual3d_TOV_SHADING))
1954 Result = Visual3d_TOA_COMPUTE;
1958 if (Result == Visual3d_TOA_YES)
1959 cout << "YES = Visual3d_View" << MyCView.ViewId
1960 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1961 if (Result == Visual3d_TOA_NO)
1962 cout << "NO = Visual3d_View" << MyCView.ViewId
1963 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1964 if (Result == Visual3d_TOA_COMPUTE)
1965 cout << "COMPUTE = Visual3d_View" << MyCView.ViewId
1966 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1974 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
1976 if (IsDeleted ()) return;
1977 if (! IsDefined ()) return;
1978 if (! IsActive ()) return;
1979 if (! IsDisplayed (AStructure)) return;
1981 Standard_Integer Index = IsComputed (AStructure);
1983 if ( Index != 0 && ComputedMode () && !DegenerateModeIsOn () )
1985 if ((Index != 0) && (! DegenerateModeIsOn ()))
1989 Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification ();
1990 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1991 << AStructure->Identification () << "/" << StructId
1992 << ", " << OldPriority << ", " << NewPriority << ")\n";
1995 MyGraphicDriver->EraseStructure
1997 *(Graphic3d_CStructure *)
1998 MyCOMPUTEDSequence.Value (Index)->CStructure ());
1999 MyGraphicDriver->DisplayStructure
2001 *(Graphic3d_CStructure *)
2002 MyCOMPUTEDSequence.Value (Index)->CStructure (),
2007 Standard_Integer StructId = AStructure->Identification ();
2008 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
2009 << AStructure->Identification () << "/" << StructId
2010 << ", " << OldPriority << ", " << NewPriority << ")\n";
2013 MyGraphicDriver->EraseStructure
2015 *(Graphic3d_CStructure *)AStructure->CStructure ());
2016 MyGraphicDriver->DisplayStructure
2018 *(Graphic3d_CStructure *)AStructure->CStructure (),
2024 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
2027 cout << "Visual3d_View" << MyCView.ViewId << "::Clear ("
2028 << AStructure->Identification () << ")\n";
2032 Standard_Integer Index = IsComputed (AStructure);
2035 cout << "Structure " << AStructure->Identification ()
2036 << " calculated in the view "
2037 << Identification () << ", by structure "
2038 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2039 << " is emptied.\n";
2042 MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction);
2043 MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False);
2048 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
2050 #ifdef TRACE_CONNECT
2051 cout << "Visual3d_View" << MyCView.ViewId << "::Connect ("
2052 << AMother->Identification ()
2053 << ADaughter->Identification () << ")\n";
2057 Standard_Integer IndexM = IsComputed (AMother);
2058 Standard_Integer IndexD = IsComputed (ADaughter);
2060 if (IndexM != 0 && IndexD != 0) {
2061 #ifdef TRACE_CONNECT
2062 cout << "Structure " << AMother->Identification ()
2063 << " is connected to structure "
2064 << ADaughter->Identification () << endl;
2065 cout << "These structures are calculated.\n";
2066 cout << "In the view " << Identification ()
2068 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
2069 << " is connected to the structure "
2070 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
2073 MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD));
2078 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
2080 #ifdef TRACE_CONNECT
2081 cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect ("
2082 << AMother->Identification ()
2083 << ADaughter->Identification () << ")\n";
2087 Standard_Integer IndexM = IsComputed (AMother);
2088 Standard_Integer IndexD = IsComputed (ADaughter);
2090 if (IndexM != 0 && IndexD != 0) {
2091 #ifdef TRACE_CONNECT
2092 cout << "Structure " << AMother->Identification ()
2093 << " is disconnected from the structure "
2094 << ADaughter->Identification () << endl;
2095 cout << "These structures are calculated.\n";
2096 cout << "In the view " << Identification ()
2098 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
2099 << " is disconnected from the structure "
2100 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
2103 MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD));
2108 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure) {
2110 Display (AStructure, MyViewManager->UpdateMode ());
2114 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2116 if (IsDeleted ()) return;
2117 if (! IsDefined ()) return;
2118 if (! IsActive ()) return;
2120 // If Display on a structure present in the list
2121 // of calculated structures while it is not
2122 // or more, of calculated type =>
2123 // - removes it as well as the associated old computed
2124 // THis happens when hlhsr becomes again of type e
2125 // non computed after SetVisual.
2126 Standard_Integer Index = IsComputed (AStructure);
2128 if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) {
2131 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2132 cout << "In Visual3d_View::Display, ";
2133 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2134 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2138 MyTOCOMPUTESequence.Remove (Index);
2139 MyCOMPUTEDSequence.Remove (Index);
2142 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2143 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2144 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2150 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2152 #ifdef TRACE_DISPLAY
2153 Standard_Integer StructId = AStructure->Identification ();
2154 cout << "Visual3d_View" << MyCView.ViewId << "::Display ("
2155 << StructId << ");\n";
2159 if (Answer == Visual3d_TOA_NO) {
2160 #ifdef TRACE_DISPLAY
2161 cout << "Answer : Visual3d_TOA_NO\n";
2167 // Mode degenerated active
2169 if ( !ComputedMode () || DegenerateModeIsOn () )
2170 Answer = Visual3d_TOA_YES;
2172 if (DegenerateModeIsOn ()) Answer = Visual3d_TOA_YES;
2176 if (Answer == Visual3d_TOA_YES ) {
2177 #ifdef TRACE_DISPLAY
2178 cout << "Answer : Visual3d_TOA_YES\n";
2181 if (IsDisplayed (AStructure)) return;
2182 MyGraphicDriver->DisplayStructure (
2184 *(Graphic3d_CStructure *)AStructure->CStructure (),
2185 int (AStructure->DisplayPriority ())
2187 MyDisplayedStructure.Add (AStructure);
2188 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2191 if (Answer == Visual3d_TOA_COMPUTE) {
2192 #ifdef TRACE_DISPLAY
2193 cout << "Answer : Visual3d_TOA_COMPUTE\n";
2194 cout << "Index : " << Index << "\n" << flush;
2197 // Already computed, is COMPUTED still valid?
2198 #ifdef TRACE_DISPLAY
2199 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2200 cout << "Structure "
2201 << MyTOCOMPUTESequence.Value (Index)->Identification ()
2202 << "already calculated, in the view "
2203 << Identification () << ", par la structure "
2204 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2205 << "\n was not recalculated as HLR is valid\n";
2209 cout << "Structure "
2210 << MyTOCOMPUTESequence.Value (Index)->Identification ()
2211 << " already calculated, in the view "
2212 << Identification () << ", by the structure "
2213 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2214 << "\n should be recalculated as HLR is invalid\n";
2218 Standard_Integer OldStructId =
2219 MyCOMPUTEDSequence.Value (Index)->Identification ();
2221 // Case COMPUTED valide
2222 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2224 if (! IsDisplayed (AStructure)) {
2225 MyDisplayedStructure.Add (AStructure);
2226 MyGraphicDriver->DisplayStructure (
2228 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
2229 int (AStructure->DisplayPriority ())
2231 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2236 // Case COMPUTED invalid
2238 // Is there another valid representation ?
2239 // Find in the sequence of already calculated structures
2240 // 1/ Structure having the same Owner as <AStructure>
2241 // 2/ That is not <AStructure>
2242 // 3/ The COMPUTED which of is valid
2243 Standard_Integer NewIndex = HaveTheSameOwner (AStructure);
2245 // Case of COMPUTED invalid, WITH a valid of replacement
2246 if (NewIndex != 0) {
2248 if (! IsDisplayed (AStructure)) {
2249 MyCOMPUTEDSequence.SetValue
2250 (Index, MyCOMPUTEDSequence.Value (NewIndex));
2251 OldStructId = MyCOMPUTEDSequence.Value (NewIndex)->
2253 MyDisplayedStructure.Add (AStructure);
2254 MyGraphicDriver->DisplayStructure (
2256 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (NewIndex)->CStructure (),
2257 int (AStructure->DisplayPriority ())
2259 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2264 // Cas COMPUTED invalid, WITHOUT a valid of replacement
2266 // COMPUTED is removed if displayed
2267 if (IsDisplayed (AStructure))
2268 MyGraphicDriver->EraseStructure (
2270 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()
2274 } // if (Index != 0)
2276 // Compute + Validation
2278 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
2280 Handle(Graphic3d_Structure) TheStructure;
2281 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
2282 AStructure->Transform (ATrsf);
2284 TColStd_Array2OfReal Ident (0, 3, 0, 3);
2285 Standard_Integer ii, jj;
2286 for (ii=0; ii<=3; ii++)
2287 for (jj=0; jj<=3; jj++)
2288 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
2289 TheStructure = MyCOMPUTEDSequence.Value (Index);
2290 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
2291 if (AStructure->IsTransformed ()) {
2292 AStructure->Compute (this, ATrsf, TheStructure);
2295 AStructure->Compute (this, TheStructure);
2299 if (AStructure->IsTransformed ()) {
2300 TheStructure = AStructure->Compute (this, ATrsf);
2303 TheStructure = AStructure->Compute (this);
2307 TheStructure->SetHLRValidation (Standard_True);
2310 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2311 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2312 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2316 // TOCOMPUTE and COMPUTED associated to sequences are added
2317 MyTOCOMPUTESequence.Append (AStructure);
2318 MyCOMPUTEDSequence.Append (TheStructure);
2321 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2322 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2323 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2327 // The previous are removed if necessary
2329 MyTOCOMPUTESequence.Remove (Index);
2330 MyCOMPUTEDSequence.Remove (Index);
2334 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2335 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2336 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2340 // Return type of visualisation of the view
2341 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
2343 // Of which type will be the computed ?
2344 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
2345 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
2347 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
2348 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
2350 if (ComputeWireframe)
2351 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
2353 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
2355 if (! ComputeShading && ! ComputeWireframe)
2356 Answer = Visual3d_TOA_NO;
2358 Answer = AcceptDisplay (TheStructure);
2360 if (AStructure->IsHighlighted()) {
2361 TheStructure->SetHighlightColor (AStructure->HighlightColor ());
2362 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
2365 #ifdef TRACE_DISPLAY
2366 cout << "Structure " << StructId
2367 << " in the view " << Identification ()
2368 << " is calculated by the structure "
2369 << TheStructure->Identification ();
2370 if (Answer == Visual3d_TOA_YES)
2371 cout << " and displayed\n";
2373 cout << " but not displayed\n";
2377 // It is displayed only if the calculated structure
2378 // has a proper type corresponding to the one of the view.
2379 if (Answer != Visual3d_TOA_NO) {
2380 if (! IsDisplayed (AStructure))
2381 MyDisplayedStructure.Add (AStructure);
2382 MyGraphicDriver->DisplayStructure (
2384 *(Graphic3d_CStructure *)TheStructure->CStructure (),
2385 int (AStructure->DisplayPriority ())
2387 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2389 } // Visual3d_TOA_COMPUTE
2392 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure) {
2394 if (IsDeleted ()) return;
2396 Erase (AStructure, MyViewManager->UpdateMode ());
2400 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2402 Standard_Integer StructId;
2404 if (IsDeleted ()) return;
2406 // No test on window as the structure is displayed only if
2407 // the window exists, so only one test is enough.
2408 if (IsDisplayed (AStructure)) {
2409 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2411 // Degenerated mode is active
2413 if ( !ComputedMode () || DegenerateModeIsOn () )
2414 Answer = Visual3d_TOA_YES;
2416 if (DegenerateModeIsOn ()) Answer = Visual3d_TOA_YES;
2419 if (Answer != Visual3d_TOA_COMPUTE) {
2420 MyGraphicDriver->EraseStructure (
2422 *(Graphic3d_CStructure *)AStructure->CStructure ()
2426 if (Answer == Visual3d_TOA_COMPUTE) {
2427 Standard_Integer Index = IsComputed (AStructure);
2429 cout << "Visual3d_View" << MyCView.ViewId << "::Erase ("
2430 << AStructure->Identification () << ");\n";
2431 cout << "Index : " << Index << "\n";
2435 if ( Index != 0 && ComputedMode () &&
2436 !DegenerateModeIsOn () )
2438 if ((Index != 0) && (! DegenerateModeIsOn ()))
2442 MyCOMPUTEDSequence.Value (Index)->Identification ();
2444 cout << "Structure " << AStructure->Identification ()
2445 << " calculated, in the view "
2446 << Identification () << ", by the structure "
2447 << StructId << " is removed. \n";
2450 MyGraphicDriver->EraseStructure
2451 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
2453 // else is impossible
2455 MyDisplayedStructure.Remove (AStructure);
2456 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2461 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
2464 cout << "Visual3d_View" << MyCView.ViewId << "::Highlight ("
2465 << AStructure->Identification () << ")\n";
2469 Standard_Integer Index = IsComputed (AStructure);
2472 cout << "Structure " << AStructure->Identification ()
2473 << " calculated, in the view "
2474 << Identification () << ", by the structure "
2475 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2476 << " passes in highlight mode.\n";
2479 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
2480 (AStructure->HighlightColor ());
2481 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod);
2486 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
2489 cout << "Visual3d_View" << MyCView.ViewId << "::Transform ("
2490 << AStructure->Identification () << ")\n";
2494 Standard_Integer Index = IsComputed (AStructure);
2497 cout << "The structure " << AStructure->Identification ()
2498 << " calculated, in the view "
2499 << Identification () << ", by the structure "
2500 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2501 << " is transformed.\n";
2504 // Test is somewhat light !
2505 // trsf is transferred only if it is :
2508 if (ATrsf (0, 1) != 0. || ATrsf (0, 2) != 0.
2509 || ATrsf (1, 0) != 0. || ATrsf (1, 2) != 0.
2510 || ATrsf (2, 0) != 0. || ATrsf (2, 1) != 0.)
2511 ReCompute (AStructure);
2513 MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf);
2518 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
2521 cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight ("
2522 << AStructure->Identification () << ")\n";
2526 Standard_Integer Index = IsComputed (AStructure);
2529 cout << "Structure " << AStructure->Identification ()
2530 << " calculated, in the view "
2531 << Identification () << ", by the structure "
2532 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2533 << " passes in unhighlight mode.\n";
2536 MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight ();
2542 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const {
2544 Standard_Integer StrId = AStructure->Identification ();
2546 Standard_Integer Result = 0;
2547 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
2549 // Recherche de la structure <AStructure> dans la
2550 // sequence des structures deja calculees
2551 for (Standard_Integer i=1; i<=Length && Result==0; i++)
2552 if ((MyTOCOMPUTESequence.Value (i))->Identification ()
2553 == StrId) Result = i;
2555 cout << "\n In the view " << Identification () << " the structure ";
2557 cout << StrId << " is calculated by "
2558 << MyCOMPUTEDSequence.Value (Result)->Identification ()
2561 cout << StrId << " is not calculated\n" << flush;
2565 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2566 cout << "In Visual3d_View::IsComputed, ";
2567 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2568 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2577 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const {
2579 Standard_Boolean Result = Standard_False;
2581 if (IsDeleted ()) return Result;
2583 Result = MyDisplayedStructure.Contains (AStructure);
2590 Standard_Boolean Visual3d_View::ContainsComputedStructure () const {
2592 Standard_Boolean Result = Standard_False;
2594 if (MyDisplayedStructure.IsEmpty ()) return Result;
2596 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
2598 Standard_Integer i = MyDisplayedStructure.Extent ();
2600 // Stop at the first structure of type TOS_COMPUTED
2601 while (! Result && Iterator.More ()) {
2603 (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED);
2605 // Iterator.Next () is located on the
2615 Standard_Boolean Visual3d_View::ContainsFacet () const {
2617 return ContainsFacet (MyDisplayedStructure);
2621 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const {
2623 Standard_Boolean Result = Standard_False;
2625 if (ASet.IsEmpty ()) return Result;
2627 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2629 // Stop at the first structure containing a facet
2630 for ( Iterator.Initialize (ASet);
2631 Iterator.More () && ! Result;
2633 Result = (Iterator.Key ())->ContainsFacet ();
2639 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
2642 (MyDisplayedStructure, XMin, YMin, ZMin, XMax, YMax, ZMax);
2646 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 {
2648 if (ASet.IsEmpty ()) {
2649 XMin = RealFirst ();
2650 YMin = RealFirst ();
2651 ZMin = RealFirst ();
2659 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2660 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2666 XMax = RealFirst ();
2667 YMax = RealFirst ();
2668 ZMax = RealFirst ();
2670 for ( Iterator.Initialize (ASet);
2674 if ( (Iterator.Key ())->IsInfinite ()){
2675 //XMin, YMin .... ZMax are initialized by means of infinite line data
2676 (Iterator.Key ())->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
2677 if ( Xm != RealFirst() && Xm < XMin )
2679 if ( Ym != RealFirst() && Ym < YMin )
2681 if ( Zm != RealFirst() && Zm < ZMin )
2683 if ( XM != RealLast() && XM > XMax )
2685 if ( YM != RealLast() && YM > YMax )
2687 if ( ZM != RealLast() && ZM > ZMax )
2690 // Only non-empty and non-infinite structures
2691 // are taken into account for calculation of MinMax
2692 if (! (Iterator.Key ())->IsInfinite () &&
2693 ! (Iterator.Key ())->IsEmpty ()) {
2694 (Iterator.Key ())->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
2695 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
2696 //"FitAll" operation ignores object with transform persitence parameter
2697 if( (Iterator.Key ())->TransformPersistenceMode() == Graphic3d_TMF_None )
2699 if (Xm < XMin) XMin = Xm;
2700 if (Ym < YMin) YMin = Ym;
2701 if (Zm < ZMin) ZMin = Zm;
2702 if (XM > XMax) XMax = XM;
2703 if (YM > YMax) YMax = YM;
2704 if (ZM > ZMax) ZMax = ZM;
2709 // The following cases are relevant
2710 // For exemple if all structures are empty or infinite
2711 if (XMax < XMin) { Xm = XMin; XMin = XMax; XMax = Xm; }
2712 if (YMax < YMin) { Ym = YMin; YMin = YMax; YMax = Ym; }
2713 if (ZMax < ZMin) { Zm = ZMin; ZMin = ZMax; ZMax = Zm; }
2715 Standard_Real Sx, Sy, Sz;
2716 MyViewOrientation.AxialScale(Sx, Sy, Sz);
2717 XMin = (Sx > 1. && XMin < RealFirst ()/Sx)?RealFirst (): XMin*Sx;
2718 XMax = (Sx > 1. && XMax > RealLast ()/Sx)?RealLast (): XMax*Sx;
2719 YMin = (Sy > 1. && YMin < RealFirst ()/Sy)?RealFirst (): YMin*Sy;
2720 YMax = (Sy > 1. && YMax > RealLast ()/Sy)?RealLast (): YMax*Sy;
2721 ZMin = (Sz > 1. && ZMin < RealFirst ()/Sz)?RealFirst (): ZMin*Sz;
2722 ZMax = (Sz > 1. && ZMax > RealLast ()/Sz)?RealLast (): ZMax*Sz;
2725 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2727 MinMaxValues (MyDisplayedStructure, XMin, YMin, XMax, YMax);
2731 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2733 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2734 Standard_Real Xp, Yp, Zp;
2736 MinMaxValues (ASet, Xm, Ym, Zm, XM, YM, ZM);
2738 Projects (Xm, Ym, Zm, Xp, Yp, Zp);
2742 Projects (XM, YM, ZM, Xp, Yp, Zp);
2746 if (XMax < XMin) { Xp = XMax; XMax = XMin; XMin = Xp; }
2747 if (YMax < YMin) { Yp = YMax; YMax = YMin; YMin = Yp; }
2750 const TColStd_Array2OfReal& Visual3d_View::MatrixOfOrientation () {
2752 if (! MyMatOfOriIsEvaluated) {
2753 MyGraphicDriver->InquireMat
2754 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2755 MyMatOfMapIsEvaluated = Standard_True;
2756 MyMatOfOriIsEvaluated = Standard_True;
2759 return (MyMatrixOfOrientation);
2763 const TColStd_Array2OfReal& Visual3d_View::MatrixOfMapping () {
2765 if (! MyMatOfMapIsEvaluated) {
2766 MyGraphicDriver->InquireMat
2767 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2768 MyMatOfMapIsEvaluated = Standard_True;
2769 MyMatOfOriIsEvaluated = Standard_True;
2772 return (MyMatrixOfMapping);
2776 Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const {
2778 Standard_Integer Result = MyDisplayedStructure.Extent ();
2785 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 {
2787 math_Vector PtDC (0,3), PtWC (0,3);
2790 // Otherwise use new on Visual3d_View (constructor+destructor)
2791 // as Projects is a const method or MatrixOfOrientation and
2792 // MatrixOfMapping is not.
2793 Visual3d_View * const newthis = (Visual3d_View * const) this;
2794 newthis->MatrixOfOrientation ();
2795 newthis->MatrixOfMapping ();
2797 // World Coordinate Space
2803 // WCS -> View Reference Coordinate Space
2804 math_Vector PtVRC(0,3);
2805 PtVRC = MyMatrixOfOrientation.Multiplied (PtWC);
2807 // VRCS -> Normalized Projection Coordinate Space
2808 math_Vector PtNPC(0,3);
2809 PtNPC = MyMatrixOfMapping.Multiplied (PtVRC);
2810 for (Standard_Integer i=0; i<3; i++) PtNPC (i) = PtNPC (i) / PtNPC (3);
2813 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2814 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2817 Standard_Real Ratio;
2819 // NPCS -> Device Coordinate Space
2820 Standard_Real Dx = Standard_Real (MyCView.DefWindow.dx);
2821 Standard_Real Dy = Standard_Real (MyCView.DefWindow.dy);
2824 PtDC (0) = PtNPC (0) * Dx;
2825 PtDC (1) = Dy - PtNPC (1) * Dy * Ratio;
2827 printf("Display coordinates : %f,%f,%f,%f\n",
2828 PtDC(0),PtDC(1),PtDC(2),PtDC(3));
2831 // NPCS -> Window Space
2832 Standard_Real um, vm, uM, vM;
2833 MyViewMapping.WindowLimit (um, vm, uM, vM);
2835 Ratio = (uM - um) / (vM - vm);
2837 PtNPC (1) = PtNPC (1) * Ratio;
2839 PtNPC (0) = PtNPC (0) / Ratio;
2842 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2843 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2846 Standard_Real fpd = MyViewMapping.FrontPlaneDistance ();
2847 Standard_Real bpd = MyViewMapping.BackPlaneDistance ();
2850 * Coordinates of PtNPC are described in the space
2851 * [0-1]x[0-1]x[0-1].
2852 * It is necessary to transform x and y in the window space.
2853 * It is necessary to transform z in the space of back and front
2854 * plane, taking into account clipping planes.
2855 * Z clipping planes are defined between 0 and 1.
2858 APX = PtNPC (0) * (uM - um) + um;
2859 APY = PtNPC (1) * (vM - vm) + vm;
2860 APZ = PtNPC (2) * (fpd - bpd) + bpd;
2863 Standard_Integer l,c;
2864 printf("OrientationMatrix :");
2865 for( l=0 ; l<4 ; l++ ) {
2866 printf("\n %d->",l);
2867 for( c=0 ; c<4 ; c++ ) {
2868 printf(" %f ,",MyMatrixOfOrientation(c,l));
2872 printf("MappingMatrix :");
2873 for( l=0 ; l<4 ; l++ ) {
2874 printf("\n %d->",l);
2875 for( c=0 ; c<4 ; c++ ) {
2876 printf(" %f ,",MyMatrixOfMapping(c,l));
2880 printf("World coordinates : %f,%f,%f,%f\n",
2881 PtWC(0),PtWC(1),PtWC(2),PtWC(3));
2882 printf("View coordinates : %f,%f,%f,%f\n",
2883 PtVRC(0),PtVRC(1),PtVRC(2),PtVRC(3));
2884 printf("Display coordinates : %f,%f,%f,%f\n",
2885 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2886 printf("Window limit : %f,%f,%f,%f\n",um,vm,uM,vM);
2887 printf("Ratio : %f\n",Ratio);
2888 printf("Front-plane : %f back-plane : %f\n",fpd,bpd);
2889 printf("Projection : %f,%f,%f\n \n",APX,APY,APZ);
2893 #endif /* OLD_METHOD */
2895 // OCC18942: This method is likely to duplicate Visual3d_ViewManager::ConvertCoord() one,
2896 // therefore it is necessary to consider merging the two methods or making them call the same
2897 // graphic driver's method after OCCT 6.3.
2898 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) {
2900 Standard_Real PtX, PtY, PtZ, PtT;
2902 static Standard_Real Ratio, um, vm, uM, vM;
2903 static Standard_Real fpd, bpd;
2905 if (! MyMatOfOriIsEvaluated || ! MyMatOfMapIsEvaluated) {
2906 MyGraphicDriver->InquireMat
2907 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2908 MyMatOfOriIsEvaluated = MyMatOfMapIsEvaluated = Standard_True;
2911 // WCS -> View Reference Coordinate Space
2912 PtX = MyMatrixOfOrientation (0, 0) * AX
2913 + MyMatrixOfOrientation (0, 1) * AY
2914 + MyMatrixOfOrientation (0, 2) * AZ
2915 + MyMatrixOfOrientation (0, 3);
2916 PtY = MyMatrixOfOrientation (1, 0) * AX
2917 + MyMatrixOfOrientation (1, 1) * AY
2918 + MyMatrixOfOrientation (1, 2) * AZ
2919 + MyMatrixOfOrientation (1, 3);
2920 PtZ = MyMatrixOfOrientation (2, 0) * AX
2921 + MyMatrixOfOrientation (2, 1) * AY
2922 + MyMatrixOfOrientation (2, 2) * AZ
2923 + MyMatrixOfOrientation (2, 3);
2924 PtT = MyMatrixOfOrientation (3, 0) * AX
2925 + MyMatrixOfOrientation (3, 1) * AY
2926 + MyMatrixOfOrientation (3, 2) * AZ
2927 + MyMatrixOfOrientation (3, 3);
2929 // VRCS -> Normalized Projection Coordinate Space
2930 APX = MyMatrixOfMapping (0, 0) * PtX
2931 + MyMatrixOfMapping (0, 1) * PtY
2932 + MyMatrixOfMapping (0, 2) * PtZ
2933 + MyMatrixOfMapping (0, 3) * PtT;
2934 APY = MyMatrixOfMapping (1, 0) * PtX
2935 + MyMatrixOfMapping (1, 1) * PtY
2936 + MyMatrixOfMapping (1, 2) * PtZ
2937 + MyMatrixOfMapping (1, 3) * PtT;
2938 APZ = MyMatrixOfMapping (2, 0) * PtX
2939 + MyMatrixOfMapping (2, 1) * PtY
2940 + MyMatrixOfMapping (2, 2) * PtZ
2941 + MyMatrixOfMapping (2, 3) * PtT;
2942 APT = MyMatrixOfMapping (3, 0) * PtX
2943 + MyMatrixOfMapping (3, 1) * PtY
2944 + MyMatrixOfMapping (3, 2) * PtZ
2945 + MyMatrixOfMapping (3, 3) * PtT;
2951 // NPCS -> Window Space
2952 MyViewMapping.WindowLimit (um, vm, uM, vM);
2953 fpd = MyViewMapping.FrontPlaneDistance ();
2954 bpd = MyViewMapping.BackPlaneDistance ();
2956 if(MyCView.Mapping.IsCustomMatrix) {
2957 // OCC18942: SAN - If orientation and mapping matrices are those used by OpenGL
2958 // visualization, then X, Y and Z coordinates normally vary between -1 and 1
2959 APX = ( APX + 1 ) * 0.5 * (uM - um) + um;
2960 APY = ( APY + 1 ) * 0.5 * (vM - vm) + vm;
2962 Ratio = (uM - um) / (vM - vm);
2969 * Coordinates of APX, APY, APZ are described in the space
2970 * [0-1]x[0-1]x[0-1].
2971 * It is necessary to transform x and y in the window space.
2972 * It is necessary to transform z in the space of back and front
2973 * plane, taking into account clipping planes.
2974 * Z clipping planes are defined between 0 and 1.
2976 APX = APX * (uM - um) + um;
2977 APY = APY * (vM - vm) + vm;
2979 APZ = APZ * (fpd - bpd) + bpd;
2982 Standard_Integer Visual3d_View::Identification () const {
2984 return (Standard_Integer (MyCView.ViewId));
2989 Standard_Boolean Visual3d_View::ZBufferIsActivated () const {
2991 if (IsDeleted ()) return (Standard_False);
2993 if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);
2995 // -1 => not forced by the programmer => depends on the type of visualisation
2996 // 0 ou 1 => forced by the programmer
2998 if (MyCView.Context.ZBufferActivity == -1)
2999 if (MyContext.Visualization () == Visual3d_TOV_SHADING)
3000 return (Standard_True);
3002 return (Standard_False);
3004 if (MyCView.Context.ZBufferActivity)
3005 return (Standard_True);
3007 return (Standard_False);
3011 void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {
3013 if (IsDeleted ()) return;
3015 if ((! IsDefined ()) || (! IsActive ())) return;
3017 MyGraphicDriver->Transparency (MyCView, AnActivity);
3021 void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {
3023 if (MyCView.Context.ZBufferActivity == AnActivity) return;
3025 if (IsDeleted ()) return;
3027 if ((! IsDefined ()) || (! IsActive ())) return;
3029 MyCView.Context.ZBufferActivity = AnActivity;
3030 MyGraphicDriver->SetVisualisation (MyCView);
3034 void Visual3d_View::UpdateView () {
3036 MyCView.Context.Aliasing = (MyContext.AliasingIsOn () ? 1:0);
3037 MyCView.Context.BackZClipping =
3038 (MyContext.BackZClippingIsOn () ? 1:0);
3039 MyCView.Context.FrontZClipping =
3040 (MyContext.FrontZClippingIsOn() ? 1:0);
3041 MyCView.Context.DepthCueing =
3042 (MyContext.DepthCueingIsOn () ? 1:0);
3044 MyCView.Context.ZClipFrontPlane =
3045 float (MyContext.ZClippingFrontPlane ());
3046 MyCView.Context.ZClipBackPlane =
3047 float (MyContext.ZClippingBackPlane ());
3048 MyCView.Context.DepthFrontPlane =
3049 float (MyContext.DepthCueingFrontPlane ());
3050 MyCView.Context.DepthBackPlane =
3051 float (MyContext.DepthCueingBackPlane ());
3053 MyCView.Context.Model = int (MyContext.Model ());
3054 MyCView.Context.Visualization = int (MyContext.Visualization ());
3056 Handle(Graphic3d_TextureEnv) TempTextureEnv = MyContext.TextureEnv();
3057 if (! TempTextureEnv.IsNull()) MyCView.Context.TexEnvId = TempTextureEnv->TextureId();
3058 else MyCView.Context.TexEnvId = -1;
3059 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
3063 void Visual3d_View::Compute () {
3066 Standard_Integer Length = MyCOMPUTEDSequence.Length ();
3067 for (i=1; i<=Length; i++)
3068 (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);
3070 // if the degenerated node is active, nothing is recomputed
3072 if ( DegenerateModeIsOn () || !ComputedMode () ) return;
3074 if (DegenerateModeIsOn ()) return;
3078 * Force HLRValidation to False on all structures
3079 * calculated in the view.
3082 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3083 cout << "In Visual3d_View::Compute, ";
3084 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3085 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3091 * Change of orientation or of projection type =>
3092 * Remove structures that were calculated for the
3093 * previous orientation.
3094 * Recalculation of new structures.
3095 * Passage of the degenerated mode ON to OFF =>
3096 * Remove structures that were calculated before
3097 * the degenerated mode passed to ON.
3098 * Recalculate new structures.
3100 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3101 Visual3d_TypeOfAnswer Answer;
3103 i = MyDisplayedStructure.Extent ();
3105 Graphic3d_SequenceOfStructure FooSequence;
3107 while (S1Iterator.More ()) {
3108 Answer = AcceptDisplay (S1Iterator.Key ());
3109 // If the structure was calculated, it is recalculated.
3110 if (Answer == Visual3d_TOA_COMPUTE) {
3112 cout << "AcceptDisplay ("
3113 << (S1Iterator.Key ())->Identification ()
3114 << ") == Visual3d_TOA_COMPUTE;\n";
3117 //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
3118 FooSequence.Append (S1Iterator.Key ());
3121 // S1Iterator.Next () is located on the next structure
3125 Length = FooSequence.Length ();
3126 // All stored structures are displayed
3127 for (i=1; i<=Length; i++)
3128 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
3129 if (Length != 0) FooSequence.Clear ();
3133 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
3135 if ( DegenerateModeIsOn () || !ComputedMode () ) return;
3137 if (DegenerateModeIsOn()) return;
3140 if (IsDeleted ()) return;
3142 if ((! IsDefined ()) || (! IsActive ())) return;
3144 if (! MyWindow->IsMapped ()) return;
3146 if (! AStructure->IsDisplayed ()) return;
3148 Visual3d_TypeOfAnswer Answer;
3150 Answer = AcceptDisplay (AStructure);
3152 if (Answer == Visual3d_TOA_COMPUTE) {
3153 Standard_Integer Index = IsComputed (AStructure);
3156 cout << "Structure " << AStructure->Identification ()
3157 << " is not calculated in the view "
3158 << Identification () << "\n";
3163 Standard_Integer OldStructId, NewStructId;
3165 MyCOMPUTEDSequence.Value (Index)->Identification ();
3167 Standard_Integer StructId = AStructure->Identification ();
3168 cout << "Structure " << StructId
3169 << " calculated, in the view "
3170 << Identification () << ", by the structure "
3171 << OldStructId << " is recalculated.\n";
3175 // Compute + Validation
3177 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3179 Handle(Graphic3d_Structure) TheStructure;
3180 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3181 AStructure->Transform (ATrsf);
3183 TColStd_Array2OfReal Ident (0, 3, 0, 3);
3184 Standard_Integer ii, jj;
3185 for (ii=0; ii<=3; ii++)
3186 for (jj=0; jj<=3; jj++)
3187 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3188 TheStructure = MyCOMPUTEDSequence.Value (Index);
3189 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3190 if (AStructure->IsTransformed ()) {
3191 AStructure->Compute (this, ATrsf, TheStructure);
3194 AStructure->Compute (this, TheStructure);
3198 if (AStructure->IsTransformed ()) {
3199 TheStructure = AStructure->Compute (this, ATrsf);
3202 TheStructure = AStructure->Compute (this);
3206 TheStructure->SetHLRValidation (Standard_True);
3208 // Return type of visualisation of the view
3209 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3211 // Of which type will be the computed ?
3212 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3213 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
3215 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3216 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3218 if (ComputeWireframe)
3219 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3221 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3223 if (AStructure->IsHighlighted ()) {
3224 TheStructure->SetHighlightColor
3225 (AStructure->HighlightColor ());
3226 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3230 // Find structure <AStructure>
3231 // in the sequence of structures to be calculated.
3232 NewStructId = TheStructure->Identification ();
3234 // The previous calculation is removed and the new one is dislayed
3235 MyGraphicDriver->EraseStructure (
3237 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3238 MyGraphicDriver->DisplayStructure (
3240 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3241 int (AStructure->DisplayPriority ())
3245 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3246 cout << "In Visual3d_View::ReCompute, ";
3247 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3248 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3253 // hlhsr and the new associated compute are added
3254 MyTOCOMPUTESequence.Append (AStructure);
3255 MyCOMPUTEDSequence.Append (TheStructure);
3258 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3259 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3260 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3264 // hlhsr and the new associated compute are removed
3266 MyTOCOMPUTESequence.Remove (Index);
3267 MyCOMPUTEDSequence.Remove (Index);
3270 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3271 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3272 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3282 Visual3d_View::SetAnimationModeOn ( const Standard_Boolean degenerate ) {
3284 Visual3d_View::SetAnimationModeOn () {
3287 if (AnimationModeIsOn ()) return;
3289 AnimationModeIsActive = Standard_True;
3292 SetDegenerateModeOn ();
3294 SetDegenerateModeOff ();
3296 MyGraphicDriver->BeginAnimation (MyCView);
3300 void Visual3d_View::SetAnimationModeOff () {
3302 if (! AnimationModeIsOn ()) return;
3304 AnimationModeIsActive = Standard_False;
3306 SetDegenerateModeOff ();
3308 MyGraphicDriver->EndAnimation (MyCView);
3312 Standard_Boolean Visual3d_View::AnimationModeIsOn () const {
3314 return AnimationModeIsActive;
3318 void Visual3d_View::SetDegenerateModeOn () {
3321 cout << "Visual3d_View" << MyCView.ViewId
3322 << "::SetDegenerateModeOn ();\n";
3326 // If the degenerated mode is already active, nothing is recalculated
3327 if (DegenerateModeIsOn ()) return;
3328 DegenerateModeIsActive = Standard_True;
3331 MyCView.IsDegenerates = 1;
3334 * Change of activity of the degenerated mode
3335 * Remove structures that were calculated
3336 * and displayed when the mode was off.
3337 * Display of non-calculated structures.
3339 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3340 Visual3d_TypeOfAnswer Answer;
3341 Standard_Integer StructId;
3343 while (S1Iterator.More ()) {
3345 Answer = AcceptDisplay (S1Iterator.Key ());
3346 // If the structure was calculated, the previous one is
3347 // removed and the new one is displayed
3348 // (This is the role of passage into degenerated mode)
3350 if (Answer == Visual3d_TOA_COMPUTE) {
3351 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3354 MyCOMPUTEDSequence.Value (Index)->Identification ();
3356 cout << "Structure " << S1Iterator.Key ()->Identification ()
3357 << " calculated, in the view "
3358 << Identification () << ", by structure "
3359 << StructId << " passes in degenerated mode.\n";
3360 cout << "Remove" << StructId << " then display "
3361 << S1Iterator.Key ()->Identification () << "\n";
3364 MyGraphicDriver->EraseStructure
3365 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3366 MyGraphicDriver->DisplayStructure (
3368 *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure (),
3369 int (S1Iterator.Key ()->DisplayPriority ())
3373 // Else is impossible)
3374 // If the mode was not degenerated previously, the
3375 // calculated structure associated to S1Iterator.Key ()
3376 // really exists and Index != 0
3380 // S1Iterator.Next () is located on the next structure
3386 void Visual3d_View::SetDegenerateModeOff () {
3389 cout << "Visual3d_View" << MyCView.ViewId
3390 << "::SetDegenerateModeOff ();\n";
3394 // If the degenerated mode is already inactive, nothing is recalculated
3395 if (! DegenerateModeIsOn ()) return;
3397 DegenerateModeIsActive = Standard_False;
3400 MyCView.IsDegenerates = 0;
3403 * Change of activity of degenerated mode
3404 * Remove structures that were displayed
3405 * when the mode was on.
3406 * Calculation of structures.
3408 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3409 Visual3d_TypeOfAnswer Answer;
3410 Standard_Integer StructId;
3412 Standard_Integer i = MyDisplayedStructure.Extent ();
3414 while (S1Iterator.More ()) {
3416 Answer = AcceptDisplay (S1Iterator.Key ());
3417 // If the structure was calculated, the previous one is
3418 // removed and the new one is displayed
3419 // (This is the role of passage into degenerated mode)
3421 if (Answer == Visual3d_TOA_COMPUTE) {
3422 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3425 MyCOMPUTEDSequence.Value (Index)->Identification ();
3427 cout << "Structure " << S1Iterator.Key ()->Identification ()
3428 << " calculated, in the view "
3429 << Identification () << ", by the structure "
3430 << StructId << " passes into normal mode.\n";
3431 cout << "Remove " << S1Iterator.Key ()->Identification ()
3432 << " then display " << StructId << "\n";
3435 MyGraphicDriver->EraseStructure
3437 *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure ());
3438 MyGraphicDriver->DisplayStructure (
3440 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
3441 int (S1Iterator.Key ()->DisplayPriority ())
3444 Display (S1Iterator.Key (), Aspect_TOU_WAIT);
3446 if ((S1Iterator.Key ())->IsHighlighted()) {
3447 if (! (MyCOMPUTEDSequence.Value (Index))->IsHighlighted()) {
3448 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
3449 ((S1Iterator.Key ())->HighlightColor ());
3450 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (Aspect_TOHM_COLOR);
3455 // Else is impossible
3456 // Degenerated mode was activated before display of the
3457 // structure. So the structure was displayed in the
3458 // degenerated mode, but the calculated structure didn't exist.
3459 // It is calculated.
3461 // Compute + Validation
3462 Handle(Graphic3d_Structure) AStructure = (S1Iterator.Key ());
3464 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3466 Handle(Graphic3d_Structure) TheStructure;
3467 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3468 AStructure->Transform (ATrsf);
3470 TColStd_Array2OfReal Ident (0, 3, 0, 3);
3471 Standard_Integer ii, jj;
3472 for (ii=0; ii<=3; ii++)
3473 for (jj=0; jj<=3; jj++)
3474 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3475 TheStructure = MyCOMPUTEDSequence.Value (Index);
3476 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3477 if (AStructure->IsTransformed ()) {
3478 AStructure->Compute (this, ATrsf, TheStructure);
3481 AStructure->Compute (this, TheStructure);
3485 if (AStructure->IsTransformed ()) {
3486 TheStructure = AStructure->Compute (this, ATrsf);
3489 TheStructure = AStructure->Compute (this);
3493 TheStructure->SetHLRValidation (Standard_True);
3495 // Return type of visualisation of the view
3496 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3498 // Of which type will be the computed ?
3499 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3500 ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_SHADING));
3502 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3503 ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3505 if (ComputeWireframe)
3506 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3508 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3510 if ((S1Iterator.Key ())->IsHighlighted()) {
3511 TheStructure->SetHighlightColor
3512 ((S1Iterator.Key ())->HighlightColor ());
3513 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3517 Standard_Integer Result = 0;
3518 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3519 // Find structure <S1Iterator.Key ()>
3520 // in the sequence of structures to be calculated
3521 StructId = (S1Iterator.Key ())->Identification ();
3522 for (i=1; i<=Length && Result==0; i++)
3523 if ((MyTOCOMPUTESequence.Value (i))->Identification () ==
3524 StructId) Result = i;
3526 MyCOMPUTEDSequence.ChangeValue (Result) = TheStructure;
3528 // hlhsr and the associated new compute are added
3530 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3531 cout << "In Visual3d_View::SetDegenerateModeOff, ";
3532 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3533 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3537 MyTOCOMPUTESequence.Append (S1Iterator.Key ());
3538 MyCOMPUTEDSequence.Append (TheStructure);
3540 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3541 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3542 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3547 // The degenerated is removed and the calculated is displayed
3548 MyGraphicDriver->EraseStructure
3550 *(Graphic3d_CStructure *)(S1Iterator.Key ()->CStructure ()));
3551 MyGraphicDriver->DisplayStructure (
3553 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3554 int (S1Iterator.Key ()->DisplayPriority ())
3559 // S1Iterator.Next () is located on the next structure
3563 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
3567 Standard_Boolean Visual3d_View::DegenerateModeIsOn () const {
3569 return DegenerateModeIsActive;
3573 Handle(Aspect_GraphicDriver) Visual3d_View::GraphicDriver () const {
3575 return MyGraphicDriver;
3579 void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& APlotter) const {
3581 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3583 while (S1Iterator.More ()) {
3585 if (DegenerateModeIsOn ())
3586 // As the mode is degenerated the displayed structure
3587 // is plotted without taking into account if it is calculated or not
3588 (S1Iterator.Key ())->Plot (APlotter);
3590 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3591 // As the mode is not degenerated the displayed structure
3592 // is plotted as if it was not calculated, otherwise the
3593 // associated calculated structure is plotted.
3595 (S1Iterator.Key ())->Plot (APlotter);
3597 (MyCOMPUTEDSequence.Value (Index))->Plot (APlotter);
3600 // S1Iterator.Next () is located on the next structure
3606 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const {
3608 Standard_Integer Result = 0;
3609 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3611 // Find in the sequence of already calculated structures
3612 // 1/ Structure with the same Owner as <AStructure>
3613 // 2/ Which is not <AStructure>
3614 // 3/ COMPUTED which of is valid
3615 for (Standard_Integer i=1; i<=Length && Result==0; i++)
3616 if ((MyTOCOMPUTESequence.Value (i)->Owner () == AStructure->Owner ())
3617 && (MyTOCOMPUTESequence.Value (i)->Identification () !=
3618 AStructure->Identification ())
3619 && (MyCOMPUTEDSequence.Value (i)->HLRValidation ())) Result = i;
3625 Standard_Address Visual3d_View::CView () const {
3627 return Standard_Address (&MyCView);
3632 // Triedron methods : the Triedron is a non-zoomable object.
3634 void Visual3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
3635 const Quantity_NameOfColor YColor,
3636 const Quantity_NameOfColor ZColor,
3637 const Standard_Real SizeRatio,
3638 const Standard_Real AxisDiametr,
3639 const Standard_Integer NbFacettes) {
3640 MyGraphicDriver->ZBufferTriedronSetup(XColor, YColor, ZColor,
3641 SizeRatio, AxisDiametr, NbFacettes);
3646 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
3647 const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) {
3649 MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe);
3653 void Visual3d_View::TriedronErase () {
3655 MyGraphicDriver->TriedronErase (MyCView);
3660 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {
3662 MyGraphicDriver->TriedronEcho (MyCView,AType);
3666 Standard_Boolean checkFloat(const Standard_Real value)
3668 return value > -FLT_MAX && value < FLT_MAX;
3671 void SetMinMaxValuesCallback(void* Visual3dView)
3673 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
3675 Handle(Visual3d_View) view = (Handle(Visual3d_View)&) Visual3dView;
3676 view->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax);
3678 if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) &&
3679 checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax))
3681 Handle(Graphic3d_GraphicDriver) driver = Handle(Graphic3d_GraphicDriver)::DownCast(view->GraphicDriver());
3682 driver->GraduatedTrihedronMinMaxValues((Standard_ShortReal)xmin, (Standard_ShortReal)ymin, (Standard_ShortReal)zmin,
3683 (Standard_ShortReal)xmax, (Standard_ShortReal)ymax, (Standard_ShortReal)zmax);
3687 Standard_Boolean Visual3d_View::GetGraduatedTrihedron
3688 (/* Names of axes */
3689 TCollection_ExtendedString& xname,
3690 TCollection_ExtendedString& yname,
3691 TCollection_ExtendedString& zname,
3693 Standard_Boolean& xdrawname,
3694 Standard_Boolean& ydrawname,
3695 Standard_Boolean& zdrawname,
3697 Standard_Boolean& xdrawvalues,
3698 Standard_Boolean& ydrawvalues,
3699 Standard_Boolean& zdrawvalues,
3701 Standard_Boolean& drawgrid,
3703 Standard_Boolean& drawaxes,
3704 /* Number of splits along axes */
3705 Standard_Integer& nbx,
3706 Standard_Integer& nby,
3707 Standard_Integer& nbz,
3708 /* Offset for drawing values */
3709 Standard_Integer& xoffset,
3710 Standard_Integer& yoffset,
3711 Standard_Integer& zoffset,
3712 /* Offset for drawing names of axes */
3713 Standard_Integer& xaxisoffset,
3714 Standard_Integer& yaxisoffset,
3715 Standard_Integer& zaxisoffset,
3716 /* Draw tickmarks */
3717 Standard_Boolean& xdrawtickmarks,
3718 Standard_Boolean& ydrawtickmarks,
3719 Standard_Boolean& zdrawtickmarks,
3720 /* Length of tickmarks */
3721 Standard_Integer& xtickmarklength,
3722 Standard_Integer& ytickmarklength,
3723 Standard_Integer& ztickmarklength,
3725 Quantity_Color& gridcolor,
3726 /* Colors of axis names */
3727 Quantity_Color& xnamecolor,
3728 Quantity_Color& ynamecolor,
3729 Quantity_Color& znamecolor,
3730 /* Colors of axis and values */
3731 Quantity_Color& xcolor,
3732 Quantity_Color& ycolor,
3733 Quantity_Color& zcolor,
3734 /* Name of font for names of axes */
3735 TCollection_AsciiString& fontOfNames,
3736 /* Style of names of axes */
3737 OSD_FontAspect& styleOfNames,
3738 /* Size of names of axes */
3739 Standard_Integer& sizeOfNames,
3740 /* Name of font for values */
3741 TCollection_AsciiString& fontOfValues,
3742 /* Style of values */
3743 OSD_FontAspect& styleOfValues,
3744 /* Size of values */
3745 Standard_Integer& sizeOfValues) const
3747 if (!MyGTrihedron.ptrVisual3dView)
3748 return Standard_False;
3751 xname = MyGTrihedron.xname;
3752 yname = MyGTrihedron.yname;
3753 zname = MyGTrihedron.zname;
3755 xdrawname = MyGTrihedron.xdrawname;
3756 ydrawname = MyGTrihedron.ydrawname;
3757 zdrawname = MyGTrihedron.zdrawname;
3759 xdrawvalues = MyGTrihedron.xdrawvalues;
3760 ydrawvalues = MyGTrihedron.ydrawvalues;
3761 zdrawvalues = MyGTrihedron.zdrawvalues;
3763 drawgrid = MyGTrihedron.drawgrid;
3765 drawaxes = MyGTrihedron.drawaxes;
3766 /* Number of splits along axes */
3767 nbx = MyGTrihedron.nbx;
3768 nby = MyGTrihedron.nby;
3769 nbz = MyGTrihedron.nbz;
3770 /* Offset for drawing values */
3771 xoffset = MyGTrihedron.xoffset;
3772 yoffset = MyGTrihedron.yoffset;
3773 zoffset = MyGTrihedron.zoffset;
3774 /* Offset for drawing names of axes */
3775 xaxisoffset = MyGTrihedron.xaxisoffset;
3776 yaxisoffset = MyGTrihedron.yaxisoffset;
3777 zaxisoffset = MyGTrihedron.zaxisoffset;
3778 /* Draw tickmarks */
3779 xdrawtickmarks = MyGTrihedron.xdrawtickmarks;
3780 ydrawtickmarks = MyGTrihedron.ydrawtickmarks;
3781 zdrawtickmarks = MyGTrihedron.zdrawtickmarks;
3782 /* Length of tickmarks */
3783 xtickmarklength = MyGTrihedron.xtickmarklength;
3784 ytickmarklength = MyGTrihedron.ytickmarklength;
3785 ztickmarklength = MyGTrihedron.ztickmarklength;
3787 gridcolor = MyGTrihedron.gridcolor;
3788 /* Colors of axis names */
3789 xnamecolor = MyGTrihedron.xnamecolor;
3790 ynamecolor = MyGTrihedron.ynamecolor;
3791 znamecolor = MyGTrihedron.znamecolor;
3792 /* Colors of axis and values */
3793 xcolor = MyGTrihedron.xcolor;
3794 ycolor = MyGTrihedron.ycolor;
3795 zcolor = MyGTrihedron.zcolor;
3796 /* Name of font for names of axes */
3797 fontOfNames = MyGTrihedron.fontOfNames;
3798 /* Style of names of axes */
3799 styleOfNames = MyGTrihedron.styleOfNames;
3800 /* Size of names of axes */
3801 sizeOfNames = MyGTrihedron.sizeOfNames;
3802 /* Name of font for values */
3803 fontOfValues = MyGTrihedron.fontOfValues;
3804 /* Style of values */
3805 styleOfValues = MyGTrihedron.styleOfValues;
3806 /* Size of values */
3807 sizeOfValues = MyGTrihedron.sizeOfValues;
3809 return Standard_True;
3812 void Visual3d_View::GraduatedTrihedronDisplay
3813 (/* Names of axes */
3814 const TCollection_ExtendedString &xname,
3815 const TCollection_ExtendedString &yname,
3816 const TCollection_ExtendedString &zname,
3818 const Standard_Boolean xdrawname,
3819 const Standard_Boolean ydrawname,
3820 const Standard_Boolean zdrawname,
3822 const Standard_Boolean xdrawvalues,
3823 const Standard_Boolean ydrawvalues,
3824 const Standard_Boolean zdrawvalues,
3826 const Standard_Boolean drawgrid,
3828 const Standard_Boolean drawaxes,
3829 /* Number of splits along axes */
3830 const Standard_Integer nbx,
3831 const Standard_Integer nby,
3832 const Standard_Integer nbz,
3833 /* Offset for drawing values */
3834 const Standard_Integer xoffset,
3835 const Standard_Integer yoffset,
3836 const Standard_Integer zoffset,
3837 /* Offset for drawing names of axes */
3838 const Standard_Integer xaxisoffset,
3839 const Standard_Integer yaxisoffset,
3840 const Standard_Integer zaxisoffset,
3841 /* Draw tickmarks */
3842 const Standard_Boolean xdrawtickmarks,
3843 const Standard_Boolean ydrawtickmarks,
3844 const Standard_Boolean zdrawtickmarks,
3845 /* Length of tickmarks */
3846 const Standard_Integer xtickmarklength,
3847 const Standard_Integer ytickmarklength,
3848 const Standard_Integer ztickmarklength,
3850 const Quantity_Color& gridcolor,
3851 /* Colors of axis names */
3852 const Quantity_Color& xnamecolor,
3853 const Quantity_Color& ynamecolor,
3854 const Quantity_Color& znamecolor,
3855 /* Colors of axis and values */
3856 const Quantity_Color& xcolor,
3857 const Quantity_Color& ycolor,
3858 const Quantity_Color& zcolor,
3859 /* Name of font for names of axes */
3860 const TCollection_AsciiString &fontOfNames,
3861 /* Style of names of axes */
3862 const OSD_FontAspect styleOfNames,
3863 /* Size of names of axes */
3864 const Standard_Integer sizeOfNames,
3865 /* Name of font for values */
3866 const TCollection_AsciiString &fontOfValues,
3867 /* Style of values */
3868 const OSD_FontAspect styleOfValues,
3869 /* Size of values */
3870 const Standard_Integer sizeOfValues)
3873 MyGTrihedron.xname = xname;
3874 MyGTrihedron.yname = yname;
3875 MyGTrihedron.zname = zname;
3877 MyGTrihedron.xdrawname = xdrawname;
3878 MyGTrihedron.ydrawname = ydrawname;
3879 MyGTrihedron.zdrawname = zdrawname;
3881 MyGTrihedron.xdrawvalues = xdrawvalues;
3882 MyGTrihedron.ydrawvalues = ydrawvalues;
3883 MyGTrihedron.zdrawvalues = zdrawvalues;
3885 MyGTrihedron.drawgrid = drawgrid;
3887 MyGTrihedron.drawaxes = drawaxes;
3888 /* Number of splits along axes */
3889 MyGTrihedron.nbx = nbx;
3890 MyGTrihedron.nby = nby;
3891 MyGTrihedron.nbz = nbz;
3892 /* Offset for drawing values */
3893 MyGTrihedron.xoffset = xoffset;
3894 MyGTrihedron.yoffset = yoffset;
3895 MyGTrihedron.zoffset = zoffset;
3896 /* Offset for drawing names of axes */
3897 MyGTrihedron.xaxisoffset = xaxisoffset;
3898 MyGTrihedron.yaxisoffset = yaxisoffset;
3899 MyGTrihedron.zaxisoffset = zaxisoffset;
3900 /* Draw tickmarks */
3901 MyGTrihedron.xdrawtickmarks = xdrawtickmarks;
3902 MyGTrihedron.ydrawtickmarks = ydrawtickmarks;
3903 MyGTrihedron.zdrawtickmarks = zdrawtickmarks;
3904 /* Length of tickmarks */
3905 MyGTrihedron.xtickmarklength = xtickmarklength;
3906 MyGTrihedron.ytickmarklength = ytickmarklength;
3907 MyGTrihedron.ztickmarklength = ztickmarklength;
3909 MyGTrihedron.gridcolor = gridcolor;
3910 /* Colors of axis names */
3911 MyGTrihedron.xnamecolor = xnamecolor;
3912 MyGTrihedron.ynamecolor = ynamecolor;
3913 MyGTrihedron.znamecolor = znamecolor;
3914 /* Colors of axis and values */
3915 MyGTrihedron.xcolor = xcolor;
3916 MyGTrihedron.ycolor = ycolor;
3917 MyGTrihedron.zcolor = zcolor;
3918 /* Name of font for names of axes */
3919 MyGTrihedron.fontOfNames = fontOfNames;
3920 /* Style of names of axes */
3921 MyGTrihedron.styleOfNames = styleOfNames;
3922 /* Size of names of axes */
3923 MyGTrihedron.sizeOfNames = sizeOfNames;
3924 /* Name of font for values */
3925 MyGTrihedron.fontOfValues = fontOfValues;
3926 /* Style of values */
3927 MyGTrihedron.styleOfValues = styleOfValues;
3928 /* Size of values */
3929 MyGTrihedron.sizeOfValues = sizeOfValues;
3931 MyGTrihedron.ptrVisual3dView = this;
3932 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
3933 MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron);
3936 void Visual3d_View::GraduatedTrihedronErase()
3938 MyGTrihedron.ptrVisual3dView = NULL;
3939 MyGraphicDriver->GraduatedTrihedronErase(MyCView);
3942 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer () const {
3944 return (MyViewManager->UnderLayer ());
3948 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer () const {
3950 return (MyViewManager->OverLayer ());
3954 Standard_Integer Visual3d_View::LightLimit() const {
3956 Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit ();
3957 // printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight);
3961 Standard_Integer Visual3d_View::PlaneLimit() const {
3963 Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit ();
3964 // printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane);
3969 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const {
3971 return MyPtrViewManager;
3976 void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode ) {
3978 if ( ( (aMode && ComputedModeIsActive) ||
3979 (!aMode && !ComputedModeIsActive)
3980 ) || DegenerateModeIsOn ()
3983 Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure );
3984 Visual3d_TypeOfAnswer Answer;
3985 Standard_Integer StructId;
3986 Standard_Integer i = MyDisplayedStructure.Extent ();
3988 if ( !( ComputedModeIsActive = aMode ) ) {
3990 while ( S1Iterator.More () ) {
3992 Answer = AcceptDisplay ( S1Iterator.Key () );
3994 if ( Answer == Visual3d_TOA_COMPUTE ) {
3996 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
4000 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
4002 MyGraphicDriver -> EraseStructure (
4004 *( Graphic3d_CStructure* )
4005 MyCOMPUTEDSequence.Value ( Index ) -> CStructure ()
4007 MyGraphicDriver -> DisplayStructure (
4009 *( Graphic3d_CStructure* )
4010 S1Iterator.Key () -> CStructure (),
4011 int ( S1Iterator.Key () -> DisplayPriority () )
4013 } // end if ( Index != 0 ) . . .
4015 } // end if ( Answer . . . )
4023 while ( S1Iterator.More () ) {
4025 Answer = AcceptDisplay ( S1Iterator.Key () );
4027 if ( Answer == Visual3d_TOA_COMPUTE ) {
4029 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
4033 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
4035 MyGraphicDriver -> EraseStructure (
4037 *( Graphic3d_CStructure* )
4038 S1Iterator.Key () -> CStructure ()
4040 MyGraphicDriver -> DisplayStructure (
4042 *( Graphic3d_CStructure* )
4043 MyCOMPUTEDSequence.Value ( Index ) -> CStructure (),
4044 int ( S1Iterator.Key () -> DisplayPriority () )
4047 Display ( S1Iterator.Key (), Aspect_TOU_WAIT );
4049 if ( S1Iterator.Key () -> IsHighlighted () ) {
4051 if ( !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted () ) {
4053 MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor (
4054 S1Iterator.Key () ->
4057 MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight (
4066 Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key ();
4068 Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this );
4070 Handle( Graphic3d_Structure ) TheStructure;
4071 TColStd_Array2OfReal ATrsf ( 0, 3, 0, 3 );
4073 AStructure -> Transform ( ATrsf );
4077 TColStd_Array2OfReal Ident ( 0, 3, 0, 3 );
4078 Standard_Integer ii, jj;
4080 for ( ii = 0; ii <= 3; ++ii )
4082 for ( jj = 0; jj <= 3; ++jj )
4084 Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 );
4086 TheStructure = MyCOMPUTEDSequence.Value ( Index );
4088 TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE );
4090 if ( AStructure->IsTransformed () )
4092 AStructure -> Compute ( this, ATrsf, TheStructure );
4096 AStructure -> Compute ( this, TheStructure );
4100 if ( AStructure -> IsTransformed () )
4102 TheStructure = AStructure -> Compute ( this, ATrsf );
4106 TheStructure = AStructure -> Compute ( this );
4110 TheStructure -> SetHLRValidation ( Standard_True );
4112 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
4114 Standard_Boolean ComputeWireframe =
4115 ( ( ViewType == Visual3d_TOV_WIREFRAME ) &&
4116 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING )
4119 Standard_Boolean ComputeShading =
4120 ( ( ViewType == Visual3d_TOV_SHADING ) &&
4121 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME )
4124 if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME );
4125 if ( ComputeShading ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING );
4127 if ( S1Iterator.Key () -> IsHighlighted () ) {
4129 TheStructure -> SetHighlightColor (
4130 S1Iterator.Key () -> HighlightColor ()
4132 TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR );
4136 Standard_Integer Result = 0;
4137 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
4138 StructId = S1Iterator.Key () -> Identification ();
4140 for ( i = 1; i <= Length && Result == 0; ++i )
4142 if ( MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId )
4148 MyCOMPUTEDSequence.ChangeValue ( Result ) = TheStructure;
4152 MyTOCOMPUTESequence.Append ( S1Iterator.Key () );
4153 MyCOMPUTEDSequence.Append ( TheStructure );
4157 MyGraphicDriver -> EraseStructure (
4159 *( Graphic3d_CStructure* )
4160 S1Iterator.Key () -> CStructure ()
4162 MyGraphicDriver -> DisplayStructure (
4164 *( Graphic3d_CStructure* )TheStructure -> CStructure (),
4165 int ( S1Iterator.Key () -> DisplayPriority () )
4175 if ( MyViewManager -> UpdateMode () == Aspect_TOU_ASAP ) Update ();
4179 } // end Visual3d_View :: SetComputedMode
4181 Standard_Boolean Visual3d_View :: ComputedMode () const {
4183 return ComputedModeIsActive;
4185 } // end Visual3d_View :: ComputedMode
4187 void Visual3d_View :: SetBackFacingModel (
4188 const Visual3d_TypeOfBackfacingModel aModel
4193 case Visual3d_TOBM_AUTOMATIC:
4194 MyCView.Backfacing = 0;
4197 case Visual3d_TOBM_FORCE:
4198 MyCView.Backfacing = 1;
4201 case Visual3d_TOBM_DISABLE:
4202 MyCView.Backfacing = -1;
4207 MyGraphicDriver -> SetBackFacingModel ( MyCView );
4209 } // end Visual3d_View :: SetBackFacingModel
4211 Visual3d_TypeOfBackfacingModel Visual3d_View :: BackFacingModel () const {
4213 switch ( MyCView.Backfacing ) {
4216 return Visual3d_TOBM_AUTOMATIC;
4219 return Visual3d_TOBM_FORCE;
4223 return Visual3d_TOBM_DISABLE;
4225 } // end Visual3d_View :: BackFacingModel
4228 void Visual3d_View::EnableDepthTest( const Standard_Boolean enable ) const
4231 MyGraphicDriver->SetDepthTestEnabled( MyCView, enable );
4235 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
4238 return MyGraphicDriver->IsDepthTestEnabled( MyCView );
4240 return Standard_True;
4244 void Visual3d_View::ReadDepths(const Standard_Integer x,
4245 const Standard_Integer y,
4246 const Standard_Integer width,
4247 const Standard_Integer height,
4248 const Standard_Address buffer) const
4250 MyGraphicDriver->ReadDepths( MyCView, x, y, width, height, buffer );
4253 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
4254 const Standard_Integer theHeight)
4256 return MyGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
4259 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
4261 MyGraphicDriver->FBORelease( MyCView, theFBOPtr );
4264 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
4265 Standard_Integer& theWidth, Standard_Integer& theHeight,
4266 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
4268 MyGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
4269 theWidth, theHeight,
4270 theWidthMax, theHeightMax );
4273 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
4274 const Standard_Integer theWidth, const Standard_Integer theHeight)
4276 MyGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
4277 theWidth, theHeight );
4280 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
4281 const Graphic3d_BufferType& theBufferType)
4283 return MyGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
4286 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
4289 MyGraphicDriver->SetGLLightEnabled( MyCView, enable );
4294 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
4297 return MyGraphicDriver->IsGLLightEnabled( MyCView );
4299 return Standard_True;
4303 Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
4304 const Graphic3d_ExportFormat theFormat,
4305 const Graphic3d_SortType theSortType,
4306 const Standard_Real thePrecision,
4307 const Standard_Address theProgressBarFunc,
4308 const Standard_Address theProgressObject) const
4310 Handle(Visual3d_Layer) anUnderLayer = MyViewManager->UnderLayer();
4311 Handle(Visual3d_Layer) anOverLayer = MyViewManager->OverLayer();
4313 Aspect_CLayer2d anOverCLayer;
4314 Aspect_CLayer2d anUnderCLayer;
4315 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
4317 if (!anOverLayer.IsNull())
4318 anOverCLayer = anOverLayer->CLayer();
4319 if (!anUnderLayer.IsNull())
4320 anUnderCLayer = anUnderLayer->CLayer();
4322 Standard_Integer aWidth, aHeight;
4323 Window()->Size (aWidth, aHeight);
4325 return MyGraphicDriver->Export (theFileName, theFormat, theSortType,
4326 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
4327 thePrecision, theProgressBarFunc, theProgressObject);
4330 //=======================================================================
4331 //function : AddZLayer
4333 //=======================================================================
4335 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
4337 MyGraphicDriver->AddZLayer (MyCView, theLayerId);
4340 //=======================================================================
4341 //function : RemoveZLayer
4343 //=======================================================================
4345 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
4347 MyGraphicDriver->RemoveZLayer (MyCView, theLayerId);
4350 //=======================================================================
4351 //function : ChangeZLayer
4353 //=======================================================================
4355 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
4356 const Standard_Integer theLayerId)
4358 MyGraphicDriver->ChangeZLayer (
4359 (*(Graphic3d_CStructure*)theStructure->CStructure()), MyCView, theLayerId);