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 G003 //EUG 30-09-00 Degeneration management
89 // Backfacing management
91 #define RIC120302 //GG Add a NEW SetWindow method which enable
92 // to connect a graphic widget and context to OGL.
94 #define BUC61044 /* 25/10/01 SAV ; added functionality to control gl depth testing
96 #define BUC61045 /* 25/10/01 SAV ; added functionality to control gl lighting
99 #define OCC1188 //SAV Added methods to set background image
101 /*----------------------------------------------------------------------*/
109 #define NO_TRACE_ACCEPT
110 #define NO_TRACE_CLEAR
111 #define NO_TRACE_CONNECT
112 #define NO_TRACE_HIGH
113 #define NO_TRACE_COMP
114 #define NO_TRACE_TRSF
115 #define NO_TRACE_DISPLAY
116 #define NO_TRACE_ISCOMP
117 #define NO_TRACE_LENGTH
118 #define NO_TRACE_LAYER
120 /*----------------------------------------------------------------------*/
130 #include <Visual3d_View.ixx>
131 #include <Visual3d_View.pxx>
132 #include <Visual3d_DepthCueingDefinitionError.hxx>
133 #include <Visual3d_ZClippingDefinitionError.hxx>
136 #include <math_Vector.hxx>
137 #endif /* OLD_METHOD */
141 #include <Graphic3d_Structure.hxx>
142 #include <Graphic3d_MapOfStructure.hxx>
143 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
144 #include <Graphic3d_DataStructureManager.hxx>
146 #include <Graphic3d_GraphicDriver.hxx>
147 #include <Graphic3d_GraphicDevice.hxx>
149 #include <Graphic3d_Vector.hxx>
150 #include <Graphic3d_Vertex.hxx>
152 #include <Visual3d_Light.hxx>
153 #include <Visual3d_SetOfLight.hxx>
154 #include <Visual3d_HSetOfLight.hxx>
155 #include <Visual3d_SetIteratorOfSetOfLight.hxx>
157 #include <Visual3d_ClipPlane.hxx>
158 #include <Visual3d_SetOfClipPlane.hxx>
159 #include <Visual3d_HSetOfClipPlane.hxx>
160 #include <Visual3d_SetIteratorOfSetOfClipPlane.hxx>
162 #include <Visual3d_SetIteratorOfSetOfView.hxx>
164 #include <Graphic3d_TextureEnv.hxx>
166 #include <TColStd_HArray2OfReal.hxx>
169 # include <Xw_Window.hxx>
171 # include <WNT_Window.hxx>
178 //-Global data definitions
182 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager):
185 MyViewMappingReset (),
186 MyViewOrientation (),
187 MyViewOrientationReset (),
188 MyTransformation (0, 3, 0, 3),
189 MyMatrixOfMapping (0, 3, 0, 3),
190 MyMatrixOfOrientation (0, 3, 0, 3),
191 MyTOCOMPUTESequence (),
192 MyCOMPUTEDSequence (),
193 MyDisplayedStructure ()
195 Standard_Integer i, j;
197 MyPtrViewManager = AManager.operator->();
198 MyCView.ViewId = int (AManager->Identification (this));
200 MyCView.IsDeleted = 0;
203 MyCView.DefWindow.IsDefined = 0;
205 MyCView.Context.NbActiveLight = 0;
206 MyCView.Context.NbActivePlane = 0;
208 MyCView.Context.ActivePlane = NULL;
213 if (i == j) MyTransformation (i, j) = 1.0;
214 else MyTransformation (i, j) = 0.0;
216 Standard_Real X, Y, Z;
218 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
219 MyCView.Orientation.ViewReferencePoint.x = float (X);
220 MyCView.Orientation.ViewReferencePoint.y = float (Y);
221 MyCView.Orientation.ViewReferencePoint.z = float (Z);
222 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
223 MyCView.Orientation.ViewReferencePlane.x = float (X);
224 MyCView.Orientation.ViewReferencePlane.y = float (Y);
225 MyCView.Orientation.ViewReferencePlane.z = float (Z);
226 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
227 MyCView.Orientation.ViewReferenceUp.x = float (X);
228 MyCView.Orientation.ViewReferenceUp.y = float (Y);
229 MyCView.Orientation.ViewReferenceUp.z = float (Z);
231 Standard_Real Sx, Sy, Sz;
233 MyViewOrientation.AxialScale(Sx, Sy, Sz);
234 MyCView.Orientation.ViewScaleX = float (Sx);
235 MyCView.Orientation.ViewScaleY = float (Sy);
236 MyCView.Orientation.ViewScaleZ = float (Sz);
238 // NKV : 23/07/07 - Define custom MODELVIEW matrix
239 MyCView.Orientation.IsCustomMatrix = 0;
240 memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
241 MyCView.Orientation.ModelViewMatrix[0][0] =
242 MyCView.Orientation.ModelViewMatrix[1][1] =
243 MyCView.Orientation.ModelViewMatrix[2][2] =
244 MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
247 Standard_Real um, vm, uM, vM;
249 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
250 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
251 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
252 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
253 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
254 MyCView.Mapping.ViewPlaneDistance =
255 float (MyViewMapping.ViewPlaneDistance ());
256 MyCView.Mapping.BackPlaneDistance =
257 float (MyViewMapping.BackPlaneDistance ());
258 MyCView.Mapping.FrontPlaneDistance =
259 float (MyViewMapping.FrontPlaneDistance ());
260 MyViewMapping.WindowLimit (um, vm, uM, vM);
261 MyCView.Mapping.WindowLimit.um = float (um);
262 MyCView.Mapping.WindowLimit.vm = float (vm);
263 MyCView.Mapping.WindowLimit.uM = float (uM);
264 MyCView.Mapping.WindowLimit.vM = float (vM);
266 // NKV : 23/07/07 - Define custom MODELVIEW matrix
267 MyCView.Mapping.IsCustomMatrix = 0;
268 memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
269 MyCView.Mapping.ProjectionMatrix[0][0] =
270 MyCView.Mapping.ProjectionMatrix[1][1] =
271 MyCView.Mapping.ProjectionMatrix[2][2] =
272 MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
275 MyCView.Context.ZBufferActivity = -1;
277 MyMatOfMapIsModified = Standard_True;
278 MyMatOfOriIsModified = Standard_True;
279 MyMatOfMapIsEvaluated = Standard_False;
280 MyMatOfOriIsEvaluated = Standard_False;
282 DegenerateModeIsActive = Standard_False;
283 AnimationModeIsActive = Standard_False;
285 MyCView.IsDegenerates = 0;
286 MyCView.IsDegeneratesPrev = 0;
287 ComputedModeIsActive = Standard_False;
288 MyCView.Backfacing = 0;
291 MyCView.ptrUnderLayer = 0;
292 MyCView.ptrOverLayer = 0;
293 MyCView.GContext = 0;
294 MyCView.GDisplayCB = 0;
295 MyCView.GClientData = 0;
297 Handle(Aspect_GraphicDriver) agd =
298 (MyViewManager->GraphicDevice ())->GraphicDriver ();
300 MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
304 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager, const Visual3d_ViewOrientation& VO, const Visual3d_ViewMapping& VM, const Visual3d_ContextView& CTX):
305 MyTransformation (0, 3, 0, 3),
306 MyMatrixOfMapping (0, 3, 0, 3),
307 MyMatrixOfOrientation (0, 3, 0, 3),
308 MyTOCOMPUTESequence (),
309 MyCOMPUTEDSequence (),
310 MyDisplayedStructure ()
312 Standard_Integer i, j;
314 MyPtrViewManager = AManager.operator->();
315 MyViewOrientation = VO;
318 MyViewOrientationReset = VO;
319 MyViewMappingReset = VM;
321 MyCView.ViewId = int (AManager->Identification (this));
323 MyCView.IsDeleted = 0;
326 MyCView.DefWindow.IsDefined = 0;
328 MyCView.Context.NbActiveLight = 0;
329 MyCView.Context.NbActivePlane = 0;
331 MyCView.Context.ActivePlane = NULL;
336 if (i == j) MyTransformation (i, j) = 1.0;
337 else MyTransformation (i, j) = 0.0;
339 Standard_Real X, Y, Z;
341 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
342 MyCView.Orientation.ViewReferencePoint.x = float (X);
343 MyCView.Orientation.ViewReferencePoint.y = float (Y);
344 MyCView.Orientation.ViewReferencePoint.z = float (Z);
345 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
346 MyCView.Orientation.ViewReferencePlane.x = float (X);
347 MyCView.Orientation.ViewReferencePlane.y = float (Y);
348 MyCView.Orientation.ViewReferencePlane.z = float (Z);
349 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
350 MyCView.Orientation.ViewReferenceUp.x = float (X);
351 MyCView.Orientation.ViewReferenceUp.y = float (Y);
352 MyCView.Orientation.ViewReferenceUp.z = float (Z);
354 Standard_Real Sx, Sy, Sz;
356 MyViewOrientation.AxialScale(Sx, Sy, Sz);
357 MyCView.Orientation.ViewScaleX = float (Sx);
358 MyCView.Orientation.ViewScaleY = float (Sy);
359 MyCView.Orientation.ViewScaleZ = float (Sz);
361 // NKV : 23/07/07 - Define custom MODELVIEW matrix
362 if (MyViewOrientation.IsCustomMatrix()) {
363 MyCView.Orientation.IsCustomMatrix = 1;
364 for ( i = 0; i < 4; i++)
365 for ( j = 0; j < 4; j++)
366 MyCView.Orientation.ModelViewMatrix[i][j] = MyViewOrientation.MyModelViewMatrix->Value(i,j);
369 MyCView.Orientation.IsCustomMatrix = 0;
370 memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
371 MyCView.Orientation.ModelViewMatrix[0][0] =
372 MyCView.Orientation.ModelViewMatrix[1][1] =
373 MyCView.Orientation.ModelViewMatrix[2][2] =
374 MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
378 Standard_Real um, vm, uM, vM;
380 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
381 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
382 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
383 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
384 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
385 MyCView.Mapping.ViewPlaneDistance =
386 float (MyViewMapping.ViewPlaneDistance ());
387 MyCView.Mapping.BackPlaneDistance =
388 float (MyViewMapping.BackPlaneDistance ());
389 MyCView.Mapping.FrontPlaneDistance =
390 float (MyViewMapping.FrontPlaneDistance ());
391 MyViewMapping.WindowLimit (um, vm, uM, vM);
392 MyCView.Mapping.WindowLimit.um = float (um);
393 MyCView.Mapping.WindowLimit.vm = float (vm);
394 MyCView.Mapping.WindowLimit.uM = float (uM);
395 MyCView.Mapping.WindowLimit.vM = float (vM);
397 // NKV : 23/07/07 - Define custom MODELVIEW matrix
398 if (MyViewMapping.IsCustomMatrix()) {
399 MyCView.Mapping.IsCustomMatrix = 1;
400 for ( i = 0; i < 4; i++)
401 for ( j = 0; j < 4; j++)
402 MyCView.Mapping.ProjectionMatrix[i][j] = MyViewMapping.MyProjectionMatrix->Value(i,j);
405 MyCView.Mapping.IsCustomMatrix = 0;
406 memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
407 MyCView.Mapping.ProjectionMatrix[0][0] =
408 MyCView.Mapping.ProjectionMatrix[1][1] =
409 MyCView.Mapping.ProjectionMatrix[2][2] =
410 MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
414 MyCView.Context.ZBufferActivity = -1;
416 MyMatOfMapIsModified = Standard_True;
417 MyMatOfOriIsModified = Standard_True;
418 MyMatOfMapIsEvaluated = Standard_False;
419 MyMatOfOriIsEvaluated = Standard_False;
421 AnimationModeIsActive = Standard_False;
422 MyCView.IsDegenerates = 0;
423 MyCView.IsDegeneratesPrev = 0;
424 ComputedModeIsActive = Standard_False;
427 MyCView.ptrUnderLayer = 0;
428 MyCView.ptrOverLayer = 0;
429 MyCView.GContext = 0;
430 MyCView.GDisplayCB = 0;
431 MyCView.GClientData = 0;
433 Handle(Aspect_GraphicDriver) agd =
434 (MyViewManager->GraphicDevice ())->GraphicDriver ();
436 MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
444 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow,
445 const Aspect_RenderingContext AContext,
446 const Aspect_GraphicCallbackProc& ADisplayCB,
447 const Standard_Address AClientData)
449 if (IsDeleted ()) return;
452 Visual3d_ViewDefinitionError::Raise ("Window already defined");
454 MyCView.GContext = AContext;
455 MyCView.GDisplayCB = ADisplayCB;
456 MyCView.GClientData = AClientData;
461 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow) {
463 if (IsDeleted ()) return;
466 Visual3d_ViewDefinitionError::Raise ("Window already defined");
469 MyCView.WsId = MyCView.ViewId;
470 MyCView.DefWindow.IsDefined = 1;
472 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AWindow;
473 MyCView.DefWindow.XWindow = theWindow->XWindow ();
475 MyCView.DefWindow.XParentWindow = theWindow->XParentWindow ();
479 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AWindow;
480 MyCView.DefWindow.XWindow = ( HWND )(theWindow->HWindow());
482 MyCView.DefWindow.XParentWindow = ( HWND )(theWindow->HParentWindow());
484 wd = ( WNT_WindowData* )GetWindowLongPtr (( HWND )(theWindow->HWindow()), GWLP_USERDATA);
485 wd -> WNT_WDriver_Ptr = ( void* )this;
486 wd -> WNT_VMgr = ( void* )MyPtrViewManager;
489 Standard_Integer Width, Height;
490 AWindow->Size (Width, Height);
492 MyCView.DefWindow.dx = float( Width );
493 MyCView.DefWindow.dy = float( Height );
495 Standard_Real R, G, B;
496 MyBackground = MyWindow->Background ();
497 (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
498 MyCView.DefWindow.Background.r = float (R);
499 MyCView.DefWindow.Background.g = float (G);
500 MyCView.DefWindow.Background.b = float (B);
503 if (! MyGraphicDriver->View (MyCView))
504 Visual3d_ViewDefinitionError::Raise ("Association failed");
506 MyGradientBackground = MyWindow->GradientBackground();
507 SetGradientBackground(MyGradientBackground,1);
509 Standard_Boolean AWait = Standard_False; // => immediate update
510 MyGraphicDriver->SetVisualisation (MyCView);
511 MyGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn ());
512 MyGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn ());
513 MyGraphicDriver->ClipLimit (MyCView, AWait);
514 MyGraphicDriver->Environment(MyCView);
516 // Make view manager z layer list consistent with the view's list.
517 MyViewManager->InstallZLayers (this);
519 // Update planses of model clipping
522 // Update light sources
526 * Association view-window does not cause the display
527 * of structures that can be displayed in the new view.
528 * In fact, association view-window is done, but the
529 * display is produced only if the view is activated (Activate).
536 Handle(Aspect_Window) Visual3d_View::Window () const {
539 Visual3d_ViewDefinitionError::Raise ("Window not defined");
545 Standard_Boolean Visual3d_View::IsDefined () const {
547 if (MyCView.DefWindow.IsDefined)
548 return (Standard_True);
550 return (Standard_False);
554 Standard_Boolean Visual3d_View::IsDeleted () const {
556 if (MyCView.IsDeleted)
557 return (Standard_True);
559 return (Standard_False);
563 void Visual3d_View::Destroy () {
566 cout << "Visual3d_View::Destroy (" << Identification () << ")\n";
569 // Since MyPtrViewManager can be already distroyed,
570 // avoid attempts to access it in SetBackground()
571 MyPtrViewManager = 0;
576 void Visual3d_View::Remove () {
579 cout << "Visual3d_View::Remove (" << Identification () << ")" << endl;
582 if (IsDeleted ()) return;
583 if (! IsDefined ()) return;
585 MyTOCOMPUTESequence.Clear ();
586 MyCOMPUTEDSequence.Clear ();
587 MyDisplayedStructure.Clear ();
589 Quantity_Color BlackColor (0.0, 0.0, 0.0, Quantity_TOC_RGB);
590 Aspect_Background BlackBackground (BlackColor);
591 SetBackground (BlackBackground);
593 Aspect_GradientBackground BlackGradBackground;
594 SetGradientBackground (BlackGradBackground,0);
596 if (MyPtrViewManager)
597 MyPtrViewManager->UnIdentification( MyCView.ViewId );
599 MyGraphicDriver->RemoveView (MyCView);
602 MyCView.IsDeleted = 1;
603 MyCView.DefWindow.IsDefined = 0;
605 MyMatOfMapIsModified = Standard_True;
606 MyMatOfOriIsModified = Standard_True;
607 MyMatOfMapIsEvaluated = Standard_False;
608 MyMatOfOriIsEvaluated = Standard_False;
614 void Visual3d_View::Resized () {
616 if (IsDeleted ()) return;
619 Visual3d_ViewDefinitionError::Raise ("Window not defined");
620 MyWindow->DoResize() ;
625 void Visual3d_View::SetRatio () {
627 if (IsDeleted ()) return;
629 Aspect_TypeOfUpdate UpdateMode = MyViewManager->UpdateMode ();
630 MyViewManager->SetUpdateMode (Aspect_TOU_WAIT);
632 Standard_Real Umin, Vmin, Umax, Vmax;
633 Standard_Integer Dxw, Dyw;
634 Standard_Real Dxv, Dyv;
635 Standard_Real Xc, Yc;
639 MyWindow->Size (Dxw, Dyw);
640 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
641 Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
642 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
643 if( Dxw > 0 && Dyw > 0 ) Rap = (Standard_Real)Dyw/(Standard_Real)Dxw ;
673 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
674 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
676 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
678 // Update before SetViewMapping.
680 MyCView.DefWindow.dx = float( Dxw );
681 MyCView.DefWindow.dy = float( Dyw );
683 SetViewMapping (MyViewMapping);
684 // SetViewMappingDefault ();
685 // FMN+ Update Ratio for MyViewMappingReset
687 MyViewMappingReset.WindowLimit(Umin,Vmin,Umax,Vmax) ;
688 Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
689 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
718 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
719 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
721 MyViewMappingReset.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
723 // FMN- Update Ratio for MyViewMappingReset
725 MyGraphicDriver->RatioWindow (MyCView);
728 // Force recalculation of 2 matrices.
730 // The current view can help to reconstruct a copied view
731 // that is itself. Owing to SetWindow and SetRatio the
732 // recalculation of matrices of this new view is imposed.
733 MyMatOfMapIsEvaluated = Standard_False;
734 MyMatOfOriIsEvaluated = Standard_False;
736 MyViewManager->SetUpdateMode (UpdateMode);
737 if (UpdateMode == Aspect_TOU_ASAP) Update ();
741 void Visual3d_View::UpdateLights () {
743 Standard_Integer i, j;
744 CALL_DEF_LIGHT *lights=NULL;
747 if( MyContext.Model() == Visual3d_TOM_NONE ) {
748 // Activates only a white ambient light
749 MyCView.Context.NbActiveLight = 1;
750 lights = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
751 MyCView.Context.ActiveLight = lights;
753 lights[0].WsId = MyCView.ViewId;
754 lights[0].ViewId = MyCView.ViewId;
755 lights[0].LightType = int (Visual3d_TOLS_AMBIENT);
756 lights[0].Active = 1;
757 lights[0].LightId = 0;
758 lights[0].Headlight = 0;
759 lights[0].Color.r = lights[0].Color.g = lights[0].Color.b = 1.;
762 i = MyContext.NumberOfActivatedLights ();
763 j = MyGraphicDriver->InquireLightLimit ();
764 MyCView.Context.NbActiveLight = (i > j ? j : i);
766 if (MyCView.Context.NbActiveLight > 0) {
768 // Dynamic Allocation
769 lights = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
771 MyCView.Context.ActiveLight = lights;
773 Standard_Real X, Y, Z;
775 Standard_Real LightConcentration;
776 Standard_Real LightAttenuation1;
777 Standard_Real LightAttenuation2;
778 Standard_Real LightAngle;
779 Quantity_Color LightColor;
780 Graphic3d_Vertex LightPosition;
781 Graphic3d_Vector LightDirection;
782 Visual3d_TypeOfLightSource LightType=Visual3d_TOLS_AMBIENT;
784 // Parcing of light sources
785 for (j=0; j<MyCView.Context.NbActiveLight; j++) {
786 LightType = (MyContext.ActivatedLight (j+1))->LightType ();
788 lights[j].WsId = MyCView.ViewId;
789 lights[j].ViewId = MyCView.ViewId;
791 lights[j].LightType = int (LightType);
792 lights[j].Active = 1;
794 int ((MyContext.ActivatedLight (j+1))->Identification ());
795 lights[j].Headlight = (MyContext.ActivatedLight (j+1))->Headlight ()? 1:0;
799 case Visual3d_TOLS_AMBIENT :
800 (MyContext.ActivatedLight (j+1))->Values (
805 case Visual3d_TOLS_POSITIONAL :
806 (MyContext.ActivatedLight (j+1))->Values (
814 case Visual3d_TOLS_DIRECTIONAL :
815 (MyContext.ActivatedLight (j+1))->Values (
821 case Visual3d_TOLS_SPOT :
822 (MyContext.ActivatedLight (j+1))->Values (
835 lights[j].Color.r = float (LightColor.Red ());
836 lights[j].Color.g = float (LightColor.Green ());
837 lights[j].Color.b = float (LightColor.Blue ());
839 if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
840 (LightType == Visual3d_TOLS_SPOT) ) {
841 LightPosition.Coord (X, Y, Z);
842 lights[j].Position.x = float (X);
843 lights[j].Position.y = float (Y);
844 lights[j].Position.z = float (Z);
847 if ( (LightType == Visual3d_TOLS_DIRECTIONAL) ||
848 (LightType == Visual3d_TOLS_SPOT) ) {
849 LightDirection.Coord (X, Y, Z);
850 lights[j].Direction.x = float (X);
851 lights[j].Direction.y = float (Y);
852 lights[j].Direction.z = float (Z);
855 if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
856 (LightType == Visual3d_TOLS_SPOT) ) {
857 lights[j].Attenuation[0] =
858 float (LightAttenuation1);
859 lights[j].Attenuation[1] =
860 float (LightAttenuation2);
863 if (LightType == Visual3d_TOLS_SPOT) {
864 lights[j].Concentration =
865 float (LightConcentration);
875 // management of light sources
878 MyGraphicDriver->SetLight (MyCView);
880 // Dynamic allocation
881 if (MyCView.Context.NbActiveLight > 0) delete [] lights;
885 void Visual3d_View::UpdatePlanes () {
887 Standard_Integer i, j;
888 CALL_DEF_PLANE *planes=NULL;
890 i = MyContext.NumberOfActivatedClipPlanes ();
891 j = MyGraphicDriver->InquirePlaneLimit ();
892 MyCView.Context.NbActivePlane = (i > j ? j : i);
894 if (MyCView.Context.NbActivePlane > 0) {
896 // Dynamic Allocation
897 #ifdef GER61454 //Keep the plane address for the next Update !
898 if( !MyCView.Context.ActivePlane )
899 MyCView.Context.ActivePlane = new CALL_DEF_PLANE [j];
900 planes = MyCView.Context.ActivePlane;
902 planes = new CALL_DEF_PLANE [MyCView.Context.NbActivePlane];
904 MyCView.Context.ActivePlane = planes;
906 Standard_Real A, B, C, D;
908 // Parcing of clipping planes
909 for (j=0; j<MyCView.Context.NbActivePlane; j++) {
911 planes[j].WsId = MyCView.ViewId;
912 planes[j].ViewId = MyCView.ViewId;
914 planes[j].Active = 1;
916 int ((MyContext.ActivatedClipPlane (j+1))->Identification ());
918 (MyContext.ActivatedClipPlane (j+1))->Plane (A, B, C, D);
919 planes[j].CoefA = float (A);
920 planes[j].CoefB = float (B);
921 planes[j].CoefC = float (C);
922 planes[j].CoefD = float (D);
927 // Management of planes of clipping model
930 MyGraphicDriver->SetPlane (MyCView);
932 // Dynamic allocation
934 if ( MyCView.Context.ActivePlane && (MyCView.Context.NbActivePlane == 0)
936 delete [] MyCView.Context.ActivePlane;
937 MyCView.Context.ActivePlane = NULL;
940 if (MyCView.Context.NbActivePlane > 0) delete [] planes;
945 void Visual3d_View::SetBackground (const Aspect_Background& ABack) {
947 if (IsDeleted ()) return;
950 Visual3d_ViewDefinitionError::Raise ("Window not defined");
952 // At this level, only GL can update the background.
953 // It is not necessary to call MyWindow->SetBackground (ABack); as
954 // this method starts update of window background by X
955 // (if the windowing is X)
957 Standard_Real R, G, B;
958 MyBackground = ABack;
959 (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
960 MyCView.DefWindow.Background.r = float (R);
961 MyCView.DefWindow.Background.g = float (G);
962 MyCView.DefWindow.Background.b = float (B);
964 MyGraphicDriver->Background (MyCView);
966 if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
971 void Visual3d_View::SetGradientBackground(const Aspect_GradientBackground& ABack, const Standard_Boolean update)
974 if (IsDeleted ()) return;
977 Visual3d_ViewDefinitionError::Raise ("Window not defined");
979 MyGradientBackground = ABack;
980 Quantity_Color aCol1,aCol2;
981 MyGradientBackground.Colors(aCol1,aCol2);
982 MyGraphicDriver->GradientBackground(MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
986 else if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
990 void Visual3d_View::SetBackgroundImage( const Standard_CString FileName,
991 const Aspect_FillMethod FillStyle,
992 const Standard_Boolean update )
998 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1000 MyGraphicDriver->BackgroundImage( FileName, MyCView, FillStyle );
1004 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1009 void Visual3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
1010 const Standard_Boolean update )
1016 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1018 MyGraphicDriver->SetBgImageStyle( MyCView, FillStyle );
1022 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1027 Aspect_Background Visual3d_View::Background () const {
1029 return (MyBackground);
1033 void Visual3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
1034 const Standard_Boolean update )
1039 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1041 MyGraphicDriver->SetBgGradientStyle( MyCView, FillStyle );
1045 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
1050 Aspect_GradientBackground Visual3d_View::GradientBackground () const {
1052 return MyGradientBackground;
1056 void Visual3d_View::SetTransform (const TColStd_Array2OfReal& AMatrix) {
1058 if (IsDeleted ()) return;
1060 Standard_Integer lr, ur, lc, uc;
1061 Standard_Integer i, j;
1063 // Assign the new transformation in an array [0..3][0..3]
1064 // Avoid problems if the has defined a matrice [1..4][1..4]
1065 // ou [3..6][-1..2] !!
1066 lr = AMatrix.LowerRow ();
1067 ur = AMatrix.UpperRow ();
1068 lc = AMatrix.LowerCol ();
1069 uc = AMatrix.UpperCol ();
1071 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
1072 Visual3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1074 for (i=0; i<=3; i++)
1075 for (j=0; j<=3; j++)
1076 MyTransformation (i, j) = AMatrix (lr + i, lc + j);
1078 Graphic3d_Vector VPN;
1079 Graphic3d_Vertex VRP;
1080 Graphic3d_Vector VUP;
1081 Standard_Real Sx, Sy, Sz;
1083 Visual3d_ViewOrientation NewViewOrientation;
1085 VPN = MyViewOrientation.ViewReferencePlane ();
1086 VRP = MyViewOrientation.ViewReferencePoint ();
1087 VUP = MyViewOrientation.ViewReferenceUp ();
1088 MyViewOrientation.AxialScale(Sx, Sy, Sz);
1090 NewViewOrientation.SetViewReferencePlane
1091 (Graphic3d_Structure::Transforms (Transform (), VPN));
1093 NewViewOrientation.SetViewReferencePoint
1094 (Graphic3d_Structure::Transforms (Transform (), VRP));
1096 NewViewOrientation.SetViewReferenceUp
1097 (Graphic3d_Structure::Transforms (Transform (), VUP));
1098 NewViewOrientation.SetAxialScale(Sx, Sy, Sz);
1100 SetViewOrientation (NewViewOrientation);
1102 MyMatOfOriIsModified = Standard_True;
1103 MyMatOfOriIsEvaluated = Standard_False;
1107 const TColStd_Array2OfReal& Visual3d_View::Transform () const {
1109 return (MyTransformation);
1113 void Visual3d_View::SetViewOrientation (const Visual3d_ViewOrientation& VO) {
1115 if (IsDeleted ()) return;
1117 MyViewOrientation = VO;
1119 Standard_Real X, Y, Z;
1121 // Tests on modification of parameters.
1122 Standard_Boolean VUPIsModified = Standard_False;
1123 Standard_Boolean VRPIsModified = Standard_False;
1124 Standard_Boolean VRUIsModified = Standard_False;
1125 Standard_Boolean ScaleIsModified = Standard_False;
1126 Standard_Boolean CustomIsModified = Standard_False;
1128 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1130 MyCView.Orientation.ViewReferencePoint.x != float (X)
1131 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1132 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1133 MyCView.Orientation.ViewReferencePoint.x = float (X);
1134 MyCView.Orientation.ViewReferencePoint.y = float (Y);
1135 MyCView.Orientation.ViewReferencePoint.z = float (Z);
1137 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1139 MyCView.Orientation.ViewReferencePlane.x != float (X)
1140 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1141 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1142 MyCView.Orientation.ViewReferencePlane.x = float (X);
1143 MyCView.Orientation.ViewReferencePlane.y = float (Y);
1144 MyCView.Orientation.ViewReferencePlane.z = float (Z);
1146 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1148 MyCView.Orientation.ViewReferenceUp.x != float (X)
1149 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1150 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1151 MyCView.Orientation.ViewReferenceUp.x = float (X);
1152 MyCView.Orientation.ViewReferenceUp.y = float (Y);
1153 MyCView.Orientation.ViewReferenceUp.z = float (Z);
1155 Standard_Real Sx, Sy, Sz;
1157 MyViewOrientation.AxialScale(Sx, Sy, Sz);
1159 MyCView.Orientation.ViewScaleX != float (X)
1160 || MyCView.Orientation.ViewScaleY != float (Y)
1161 || MyCView.Orientation.ViewScaleZ != float (Z);
1162 MyCView.Orientation.ViewScaleX = float (Sx);
1163 MyCView.Orientation.ViewScaleY = float (Sy);
1164 MyCView.Orientation.ViewScaleZ = float (Sz);
1167 MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
1168 MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
1169 if ( MyViewOrientation.IsCustomMatrix() ) {
1170 Standard_Integer i, j;
1171 for (i = 0; i < 4; i++)
1172 for (j = 0; j < 4; j++) {
1173 if (!CustomIsModified) CustomIsModified =
1174 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
1175 MyCView.Orientation.ModelViewMatrix[i][j] = MyViewOrientation.MyModelViewMatrix->Value(i,j);
1180 cout << "Visual3d_View::SetViewOrientation\n";
1181 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified)
1182 cout << "VUPIsModified : " << VUPIsModified
1183 << ", VRPIsModified : " << VRPIsModified
1184 << ", VRUIsModified : " << VRUIsModified
1185 << ", CustomIsModified : " << CustomIsModified << "\n" << flush;
1187 cout << "no modification\n" << flush;
1190 // restart if one of parameters is modified
1191 if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified) {
1193 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
1194 MyMatOfOriIsModified = Standard_True;
1195 MyMatOfOriIsEvaluated = Standard_False;
1198 if (! IsDefined ()) return;
1200 Standard_Boolean AWait = Standard_False; // => immediate update
1201 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1205 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1210 Visual3d_ViewOrientation Visual3d_View::ViewOrientation () const {
1212 return (MyViewOrientation);
1216 Visual3d_ViewOrientation Visual3d_View::ViewOrientationDefault () const {
1218 return (MyViewOrientationReset);
1222 void Visual3d_View::SetViewOrientationDefault () {
1224 MyViewOrientationReset.Assign (MyViewOrientation);
1228 void Visual3d_View::ViewOrientationReset () {
1230 if (IsDeleted ()) return;
1232 MyViewOrientation = MyViewOrientationReset;
1234 Standard_Real X, Y, Z;
1236 // Tests on modification of parameters.
1237 Standard_Boolean VUPIsModified = Standard_False;
1238 Standard_Boolean VRPIsModified = Standard_False;
1239 Standard_Boolean VRUIsModified = Standard_False;
1240 Standard_Boolean ScaleIsModified = Standard_False;
1241 Standard_Boolean CustomIsModified = Standard_False;
1243 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1245 MyCView.Orientation.ViewReferencePoint.x != float (X)
1246 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1247 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1248 MyCView.Orientation.ViewReferencePoint.x = float (X);
1249 MyCView.Orientation.ViewReferencePoint.y = float (Y);
1250 MyCView.Orientation.ViewReferencePoint.z = float (Z);
1252 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1254 MyCView.Orientation.ViewReferencePlane.x != float (X)
1255 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1256 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1257 MyCView.Orientation.ViewReferencePlane.x = float (X);
1258 MyCView.Orientation.ViewReferencePlane.y = float (Y);
1259 MyCView.Orientation.ViewReferencePlane.z = float (Z);
1261 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1263 MyCView.Orientation.ViewReferenceUp.x != float (X)
1264 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1265 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1266 MyCView.Orientation.ViewReferenceUp.x = float (X);
1267 MyCView.Orientation.ViewReferenceUp.y = float (Y);
1268 MyCView.Orientation.ViewReferenceUp.z = float (Z);
1270 Standard_Real Sx, Sy, Sz;
1272 MyViewOrientation.AxialScale(Sx, Sy, Sz);
1274 MyCView.Orientation.ViewScaleX != float (X)
1275 || MyCView.Orientation.ViewScaleY != float (Y)
1276 || MyCView.Orientation.ViewScaleZ != float (Z);
1277 MyCView.Orientation.ViewScaleX = float (Sx);
1278 MyCView.Orientation.ViewScaleY = float (Sy);
1279 MyCView.Orientation.ViewScaleZ = float (Sz);
1282 MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
1283 MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
1284 if ( MyViewOrientation.IsCustomMatrix() ) {
1285 Standard_Integer i, j;
1286 for (i = 0; i < 4; i++)
1287 for (j = 0; j < 4; j++) {
1288 if (!CustomIsModified) CustomIsModified =
1289 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
1290 MyCView.Orientation.ModelViewMatrix[i][j] = MyViewOrientation.MyModelViewMatrix->Value(i,j);
1295 cout << "Visual3d_View::ViewOrientationReset\n";
1296 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified)
1297 cout << "VUPIsModified : " << VUPIsModified
1298 << ", VRPIsModified : " << VRPIsModified
1299 << ", VRUIsModified : " << VRUIsModified
1300 << ", CustomIsModified : " << CustomIsModified << "\n" << flush;
1302 cout << "no modification\n" << flush;
1305 // Restart if one of parameters is modified
1306 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
1308 if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
1309 MyMatOfOriIsModified = Standard_True;
1310 MyMatOfOriIsEvaluated = Standard_False;
1313 if (! IsDefined ()) return;
1315 Standard_Boolean AWait = Standard_False; // => immediate update
1316 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1320 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1325 void Visual3d_View::SetViewMapping (const Visual3d_ViewMapping& VM) {
1327 if (IsDeleted ()) return;
1329 Visual3d_TypeOfProjection OldType = MyViewMapping.Projection ();
1330 Visual3d_TypeOfProjection NewType = VM.Projection ();
1334 Standard_Real X, Y, Z;
1335 Standard_Real um, vm, uM, vM;
1337 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
1338 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1339 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
1340 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
1341 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
1342 MyCView.Mapping.ViewPlaneDistance =
1343 float (MyViewMapping.ViewPlaneDistance ());
1344 MyCView.Mapping.BackPlaneDistance =
1345 float (MyViewMapping.BackPlaneDistance ());
1346 MyCView.Mapping.FrontPlaneDistance =
1347 float (MyViewMapping.FrontPlaneDistance ());
1348 MyViewMapping.WindowLimit (um, vm, uM, vM);
1349 MyCView.Mapping.WindowLimit.um = float (um);
1350 MyCView.Mapping.WindowLimit.vm = float (vm);
1351 MyCView.Mapping.WindowLimit.uM = float (uM);
1352 MyCView.Mapping.WindowLimit.vM = float (vM);
1354 MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1355 if (MyViewMapping.IsCustomMatrix()) {
1356 Standard_Integer i, j;
1357 for (i = 0; i < 4; i++)
1358 for (j = 0; j < 4; j++)
1359 MyCView.Mapping.ProjectionMatrix[i][j] =
1360 MyViewMapping.MyProjectionMatrix->Value(i,j);
1363 MyMatOfMapIsModified = Standard_True;
1364 MyMatOfMapIsEvaluated = Standard_False;
1366 if (! IsDefined ()) return;
1368 Standard_Boolean AWait = Standard_False; // => immediate update
1369 MyGraphicDriver->ViewMapping (MyCView, AWait);
1371 // Passage Parallele/Perspective
1372 if (OldType != NewType)
1375 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1379 Visual3d_ViewMapping Visual3d_View::ViewMapping () const {
1381 return (MyViewMapping);
1385 Visual3d_ViewMapping Visual3d_View::ViewMappingDefault () const {
1387 return (MyViewMappingReset);
1391 void Visual3d_View::SetViewMappingDefault () {
1393 MyViewMappingReset.Assign (MyViewMapping);
1397 void Visual3d_View::ViewMappingReset () {
1399 if (IsDeleted ()) return;
1401 MyViewMapping = MyViewMappingReset;
1403 Standard_Real X, Y, Z;
1404 Standard_Real um, vm, uM, vM;
1406 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
1407 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1408 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
1409 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
1410 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
1411 MyCView.Mapping.ViewPlaneDistance =
1412 float (MyViewMapping.ViewPlaneDistance ());
1413 MyCView.Mapping.BackPlaneDistance =
1414 float (MyViewMapping.BackPlaneDistance ());
1415 MyCView.Mapping.FrontPlaneDistance =
1416 float (MyViewMapping.FrontPlaneDistance ());
1417 MyViewMapping.WindowLimit (um, vm, uM, vM);
1418 MyCView.Mapping.WindowLimit.um = float (um);
1419 MyCView.Mapping.WindowLimit.vm = float (vm);
1420 MyCView.Mapping.WindowLimit.uM = float (uM);
1421 MyCView.Mapping.WindowLimit.vM = float (vM);
1423 MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1424 if (MyViewMapping.IsCustomMatrix()) {
1425 Standard_Integer i, j;
1426 for (i = 0; i < 4; i++)
1427 for (j = 0; j < 4; j++)
1428 MyCView.Mapping.ProjectionMatrix[i][j] =
1429 MyViewMapping.MyProjectionMatrix->Value(i,j);
1432 MyMatOfMapIsModified = Standard_True;
1433 MyMatOfMapIsEvaluated = Standard_False;
1435 if (! IsDefined ()) return;
1437 Standard_Boolean AWait = Standard_False; // => immediate update
1438 MyGraphicDriver->ViewMapping (MyCView, AWait);
1440 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1444 void Visual3d_View::SetContext (const Visual3d_ContextView& CTX) {
1446 if (IsDeleted ()) return;
1448 Visual3d_TypeOfVisualization OldVisualMode;
1449 Visual3d_TypeOfVisualization NewVisualMode;
1451 // To manage display only in case of
1452 // change of visualisation mode.
1453 OldVisualMode = MyContext.Visualization ();
1454 NewVisualMode = CTX.Visualization ();
1456 Visual3d_TypeOfModel OldModel;
1457 Visual3d_TypeOfModel NewModel;
1459 // To manage change of visualisation only in case
1460 // of change of mode of visualisation or of type of shading.
1461 OldModel = MyContext.Model ();
1462 NewModel = CTX.Model ();
1464 Standard_Boolean OldAliasingMode;
1465 Standard_Boolean NewAliasingMode;
1467 // To manage antialiasing only in case of change.
1468 OldAliasingMode = MyContext.AliasingIsOn ();
1469 NewAliasingMode = CTX.AliasingIsOn ();
1471 Standard_Boolean OldDepthCueingMode;
1472 Standard_Boolean NewDepthCueingMode;
1474 Standard_Real OldDepthCueingFrontPlane;
1475 Standard_Real NewDepthCueingFrontPlane;
1476 Standard_Real OldDepthCueingBackPlane;
1477 Standard_Real NewDepthCueingBackPlane;
1479 // To manage the depth cueing only in case of change.
1480 OldDepthCueingMode = MyContext.DepthCueingIsOn ();
1481 NewDepthCueingMode = CTX.DepthCueingIsOn ();
1483 OldDepthCueingFrontPlane = MyContext.DepthCueingFrontPlane ();
1484 NewDepthCueingFrontPlane = CTX.DepthCueingFrontPlane ();
1485 OldDepthCueingBackPlane = MyContext.DepthCueingBackPlane ();
1486 NewDepthCueingBackPlane = CTX.DepthCueingBackPlane ();
1488 Standard_Boolean OldFrontZClippingMode;
1489 Standard_Boolean NewFrontZClippingMode;
1490 Standard_Boolean OldBackZClippingMode;
1491 Standard_Boolean NewBackZClippingMode;
1493 Standard_Real OldZClippingFrontPlane;
1494 Standard_Real NewZClippingFrontPlane;
1495 Standard_Real OldZClippingBackPlane;
1496 Standard_Real NewZClippingBackPlane;
1498 // To manage the Zclipping only in case of change.
1499 OldFrontZClippingMode = MyContext.FrontZClippingIsOn ();
1500 NewFrontZClippingMode = CTX.FrontZClippingIsOn ();
1501 OldBackZClippingMode = MyContext.BackZClippingIsOn ();
1502 NewBackZClippingMode = CTX.BackZClippingIsOn ();
1504 OldZClippingFrontPlane = MyContext.ZClippingFrontPlane ();
1505 NewZClippingFrontPlane = CTX.ZClippingFrontPlane ();
1506 OldZClippingBackPlane = MyContext.ZClippingBackPlane ();
1507 NewZClippingBackPlane = CTX.ZClippingBackPlane ();
1509 Handle(Graphic3d_TextureEnv) aTexEnvOld = MyContext.TextureEnv();
1510 Handle(Graphic3d_TextureEnv) aTexEnvNew = CTX.TextureEnv();
1512 Visual3d_TypeOfSurfaceDetail OldSurfaceDetail = MyContext.SurfaceDetail();
1513 Visual3d_TypeOfSurfaceDetail NewSurfaceDetail = CTX.SurfaceDetail();
1519 Standard_Boolean AWait = Standard_False; // => immediate update
1521 // management of visualization modes and types of shading.
1522 if ((OldVisualMode != NewVisualMode) || (OldModel != NewModel))
1523 MyGraphicDriver->SetVisualisation (MyCView);
1525 // management of antialiasing.
1526 if (OldAliasingMode != NewAliasingMode)
1527 MyGraphicDriver->AntiAliasing (MyCView, NewAliasingMode);
1529 // management of depth_cueing.
1530 if ((OldDepthCueingMode != NewDepthCueingMode) ||
1531 (OldDepthCueingFrontPlane != NewDepthCueingFrontPlane) ||
1532 (OldDepthCueingBackPlane != NewDepthCueingBackPlane)) {
1534 if( NewDepthCueingMode &&
1535 (NewDepthCueingBackPlane >= NewDepthCueingFrontPlane) )
1536 Visual3d_DepthCueingDefinitionError::Raise
1537 ("Bad value for DepthCueingPlanes position");
1539 MyGraphicDriver->DepthCueing
1540 (MyCView, NewDepthCueingMode);
1543 // management of Zclipping
1544 if ((OldFrontZClippingMode != NewFrontZClippingMode) ||
1545 (OldBackZClippingMode != NewBackZClippingMode) ||
1546 (OldZClippingFrontPlane != NewZClippingFrontPlane) ||
1547 (OldZClippingBackPlane != NewZClippingBackPlane)) {
1549 if( NewBackZClippingMode && NewFrontZClippingMode &&
1550 (NewZClippingBackPlane >= NewZClippingFrontPlane) )
1551 Visual3d_ZClippingDefinitionError::Raise
1552 ("Bad value for ZClippingPlanes position");
1554 MyGraphicDriver->ClipLimit (MyCView, AWait);
1557 // management of textures
1558 if ((aTexEnvOld != aTexEnvNew) || (OldSurfaceDetail != NewSurfaceDetail))
1560 MyGraphicDriver->Environment(MyCView);
1563 // Update of planes of model clipping
1566 // Update of light sources
1570 if (OldVisualMode != NewVisualMode) {
1573 * Change of context =>
1574 * Remove structures that cannot be displayed
1575 * in the new visualisation mode.
1576 * It is not necessary to warn ViewManager as
1577 * this structure should not disappear from
1578 * the list of structures displayed in it.
1580 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
1581 Visual3d_TypeOfAnswer Answer;
1583 Standard_Integer i = MyDisplayedStructure.Extent ();
1585 Graphic3d_SequenceOfStructure FooSequence;
1587 while (S1Iterator.More ()) {
1588 Answer = AcceptDisplay (S1Iterator.Key ());
1589 // If the structure can't be displayed in the
1590 // new context of the view, it is removed.
1591 if ((Answer == Visual3d_TOA_NO) ||
1592 (Answer == Visual3d_TOA_COMPUTE))
1593 //Erase (S1Iterator.Key (), Aspect_TOU_WAIT);
1594 FooSequence.Append (S1Iterator.Key ());
1596 // S1Iterator.Next () is located on the next structure
1600 Standard_Integer Length = FooSequence.Length ();
1601 // The stored structures are removed
1602 for (i=1; i<=Length; i++)
1603 Erase (FooSequence.Value (i), Aspect_TOU_WAIT);
1604 if (Length != 0) FooSequence.Clear ();
1607 * Change of context =>
1608 * Display structures that can be displayed
1609 * with the new visualisation mode.
1610 * All structures with status Displayed are removed from the ViewManager
1611 * and displayed in the view directly, if the structure is not already
1612 * displayed and if the view accepts it in its context.
1615 i = MyViewManager->NumberOfDisplayedStructures ();
1616 Graphic3d_MapOfStructure Map;
1617 MyViewManager->DisplayedStructures(Map);
1618 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1620 for (; it.More(); it.Next()) {
1621 Handle(Graphic3d_Structure) SG = it.Key();
1622 if (! IsDisplayed (SG)) {
1623 Answer = AcceptDisplay(SG);
1624 // If the structure can be displayed in the
1625 // new context of the view, it is displayed.
1626 if ((Answer == Visual3d_TOA_YES) ||
1627 (Answer == Visual3d_TOA_COMPUTE))
1628 //Display (MyViewManager->DisplayedStructure (j),
1630 FooSequence.Append (SG);
1634 Length = FooSequence.Length ();
1635 // The stored structures are displayed
1636 for (i=1; i<=Length; i++)
1637 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
1638 if (Length != 0) FooSequence.Clear ();
1641 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1645 const Visual3d_ContextView& Visual3d_View::Context () const {
1651 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& SG) const
1654 if (IsDeleted ()) return;
1656 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
1658 while (Iterator.More ()) {
1659 SG.Add (Iterator.Key ());
1661 // Iterator.Next () is located on the next structure
1667 void Visual3d_View::Activate () {
1669 if (IsDeleted ()) return;
1672 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1674 if (! IsActive ()) {
1676 MyGraphicDriver->ActivateView (MyCView);
1677 MyGraphicDriver->Background (MyCView);
1678 MyGraphicDriver->Transparency
1679 (MyCView, MyViewManager->Transparency ());
1684 * Activation of a new view =>
1685 * Display structures that can be displayed in this new view.
1686 * All structures with status
1687 * Displayed in ViewManager are returned and displayed in
1688 * the view directly, if the structure is not already
1689 * displayed and if the view accepts it in its context.
1692 Visual3d_TypeOfAnswer Answer;
1693 Graphic3d_MapOfStructure Map;
1694 MyViewManager->DisplayedStructures(Map);
1695 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1697 for (; it.More(); it.Next()) {
1698 Handle(Graphic3d_Structure) SG = it.Key();
1699 if (! IsDisplayed (SG)) {
1700 Answer = AcceptDisplay(SG);
1701 // If the structure can be displayed in the
1702 // new context of the view, it is displayed.
1703 if ((Answer == Visual3d_TOA_YES) ||
1704 (Answer == Visual3d_TOA_COMPUTE))
1705 Display (SG,Aspect_TOU_WAIT);
1711 // If the activation/desactivation of ZBuffer should be automatic
1712 // depending on the presence or absence of facets.
1713 if (MyViewManager->ZBufferAuto ()) {
1714 Standard_Boolean BContainsFacet = ContainsFacet ();
1715 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1716 // If the view contains facets
1717 // and if ZBuffer is not active
1718 if (BContainsFacet && ! BZBuffer)
1719 SetZBufferActivity (1);
1720 // If the view does not contain facets
1721 // and if ZBuffer is active
1722 if (! BContainsFacet && BZBuffer)
1723 SetZBufferActivity (0);
1726 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1730 Standard_Boolean Visual3d_View::IsActive () const {
1732 if (IsDeleted ()) return (Standard_False);
1735 return (Standard_True);
1737 return (Standard_False);
1741 void Visual3d_View::Deactivate () {
1743 if (IsDeleted ()) return;
1746 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1750 MyGraphicDriver->DeactivateView (MyCView);
1753 * Deactivation of a view =>
1754 * Removal of structures displayed in this view.
1755 * All structures with status
1756 * Displayed in ViewManager are returned and removed from
1757 * the view directly, if the structure is not already
1758 * displayed and if the view accepts it in its context.
1761 Visual3d_TypeOfAnswer Answer;
1762 Graphic3d_MapOfStructure Map;
1763 MyViewManager->DisplayedStructures(Map);
1764 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1766 for (; it.More(); it.Next()) {
1767 Handle(Graphic3d_Structure) SG = it.Key();
1768 if (! IsDisplayed (SG)) {
1769 Answer = AcceptDisplay(SG);
1770 // If the structure was displayed it is removed.
1771 if ((Answer == Visual3d_TOA_YES) ||
1772 (Answer == Visual3d_TOA_COMPUTE))
1773 Erase (SG,Aspect_TOU_WAIT);
1777 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1779 // No action currently possible in the view
1785 void Visual3d_View::Redraw () {
1787 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1791 void Visual3d_View::Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
1793 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer (), x, y, width, height);
1796 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1798 if (IsDeleted ()) return;
1800 if ((! IsDefined ()) || (! IsActive ())) return;
1802 if (! MyWindow->IsMapped ()) return;
1804 // san - 14/04/2004 - set up Z buffer state before redrawing
1805 // If the activation/desactivation of ZBuffer should be automatic
1806 // depending on the presence or absence of facets.
1807 if (MyViewManager->ZBufferAuto ()) {
1808 Standard_Boolean BContainsFacet = ContainsFacet ();
1809 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1810 // If the view contains facets
1811 // and if ZBuffer is not active
1812 if (BContainsFacet && ! BZBuffer)
1813 SetZBufferActivity (1);
1814 // If the view contains only facets
1815 // and if ZBuffer is active
1816 if (! BContainsFacet && BZBuffer)
1817 SetZBufferActivity (0);
1820 Aspect_CLayer2d OverCLayer;
1821 Aspect_CLayer2d UnderCLayer;
1822 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1823 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1824 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1825 MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer);
1829 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) {
1831 if (IsDeleted ()) return;
1833 if ((! IsDefined ()) || (! IsActive ())) return;
1835 if (! MyWindow->IsMapped ()) return;
1837 // san - 14/04/2004 - set up Z buffer state before redrawing
1838 // If activation/desactivation of ZBuffer should be automatic
1839 // depending on the presence or absence of facets.
1840 if (MyViewManager->ZBufferAuto ()) {
1841 Standard_Boolean BContainsFacet = ContainsFacet ();
1842 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1843 // If the view contains facets
1844 // and if ZBuffer is not active
1845 if (BContainsFacet && ! BZBuffer)
1846 SetZBufferActivity (1);
1847 // If the view contains only facets
1848 // and if ZBuffer is active
1849 if (! BContainsFacet && BZBuffer)
1850 SetZBufferActivity (0);
1853 Aspect_CLayer2d OverCLayer;
1854 Aspect_CLayer2d UnderCLayer;
1855 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1856 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1857 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1858 MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer, x, y, width, height);
1862 void Visual3d_View::Update () {
1864 Update (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1868 void Visual3d_View::Update (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1870 if (IsDeleted ()) return;
1872 if ((! IsDefined ()) || (! IsActive ())) return;
1874 if (! MyWindow->IsMapped ()) return;
1876 // If activation/desactivation of ZBuffer should be automatic
1877 // depending on the presence or absence of facets.
1878 if (MyViewManager->ZBufferAuto ()) {
1879 Standard_Boolean BContainsFacet = ContainsFacet ();
1880 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1881 // If the view contains facets
1882 // and if ZBuffer is not active
1883 if (BContainsFacet && ! BZBuffer)
1884 SetZBufferActivity (1);
1885 // If the view does not contain facets
1886 // and if ZBuffer is active
1887 if (! BContainsFacet && BZBuffer)
1888 SetZBufferActivity (0);
1891 Aspect_CLayer2d OverCLayer;
1892 Aspect_CLayer2d UnderCLayer;
1893 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1894 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1895 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1896 //OSD::SetSignal (Standard_False);
1897 MyGraphicDriver->Update (MyCView, UnderCLayer, OverCLayer);
1898 //OSD::SetSignal (Standard_True);
1900 MyMatOfMapIsModified = Standard_False;
1901 MyMatOfOriIsModified = Standard_False;
1905 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const {
1907 // Return type of visualization of the view
1908 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
1910 // Return type of visualization of the structure
1911 Graphic3d_TypeOfStructure StructType = AStructure->Visual ();
1913 Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO;
1915 if (StructType == Graphic3d_TOS_ALL)
1916 // The structure accepts any type of view
1917 Result = Visual3d_TOA_YES;
1919 if ((StructType == Graphic3d_TOS_SHADING)
1920 && (ViewType == Visual3d_TOV_SHADING))
1921 Result = Visual3d_TOA_YES;
1922 if ((StructType == Graphic3d_TOS_WIREFRAME)
1923 && (ViewType == Visual3d_TOV_WIREFRAME))
1924 Result = Visual3d_TOA_YES;
1925 if ((StructType == Graphic3d_TOS_COMPUTED)
1926 && (ViewType == Visual3d_TOV_WIREFRAME))
1927 Result = Visual3d_TOA_COMPUTE;
1928 if ((StructType == Graphic3d_TOS_COMPUTED)
1929 && (ViewType == Visual3d_TOV_SHADING))
1930 Result = Visual3d_TOA_COMPUTE;
1934 if (Result == Visual3d_TOA_YES)
1935 cout << "YES = Visual3d_View" << MyCView.ViewId
1936 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1937 if (Result == Visual3d_TOA_NO)
1938 cout << "NO = Visual3d_View" << MyCView.ViewId
1939 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1940 if (Result == Visual3d_TOA_COMPUTE)
1941 cout << "COMPUTE = Visual3d_View" << MyCView.ViewId
1942 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1950 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
1952 if (IsDeleted ()) return;
1953 if (! IsDefined ()) return;
1954 if (! IsActive ()) return;
1955 if (! IsDisplayed (AStructure)) return;
1957 Standard_Integer Index = IsComputed (AStructure);
1959 if ( Index != 0 && ComputedMode () && !DegenerateModeIsOn () )
1961 if ((Index != 0) && (! DegenerateModeIsOn ()))
1965 Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification ();
1966 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1967 << AStructure->Identification () << "/" << StructId
1968 << ", " << OldPriority << ", " << NewPriority << ")\n";
1971 MyGraphicDriver->EraseStructure
1973 *(Graphic3d_CStructure *)
1974 MyCOMPUTEDSequence.Value (Index)->CStructure ());
1975 MyGraphicDriver->DisplayStructure
1977 *(Graphic3d_CStructure *)
1978 MyCOMPUTEDSequence.Value (Index)->CStructure (),
1983 Standard_Integer StructId = AStructure->Identification ();
1984 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1985 << AStructure->Identification () << "/" << StructId
1986 << ", " << OldPriority << ", " << NewPriority << ")\n";
1989 MyGraphicDriver->EraseStructure
1991 *(Graphic3d_CStructure *)AStructure->CStructure ());
1992 MyGraphicDriver->DisplayStructure
1994 *(Graphic3d_CStructure *)AStructure->CStructure (),
2000 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
2003 cout << "Visual3d_View" << MyCView.ViewId << "::Clear ("
2004 << AStructure->Identification () << ")\n";
2008 Standard_Integer Index = IsComputed (AStructure);
2011 cout << "Structure " << AStructure->Identification ()
2012 << " calculated in the view "
2013 << Identification () << ", by structure "
2014 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2015 << " is emptied.\n";
2018 MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction);
2019 MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False);
2024 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
2026 #ifdef TRACE_CONNECT
2027 cout << "Visual3d_View" << MyCView.ViewId << "::Connect ("
2028 << AMother->Identification ()
2029 << ADaughter->Identification () << ")\n";
2033 Standard_Integer IndexM = IsComputed (AMother);
2034 Standard_Integer IndexD = IsComputed (ADaughter);
2036 if (IndexM != 0 && IndexD != 0) {
2037 #ifdef TRACE_CONNECT
2038 cout << "Structure " << AMother->Identification ()
2039 << " is connected to structure "
2040 << ADaughter->Identification () << endl;
2041 cout << "These structures are calculated.\n";
2042 cout << "In the view " << Identification ()
2044 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
2045 << " is connected to the structure "
2046 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
2049 MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD));
2054 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
2056 #ifdef TRACE_CONNECT
2057 cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect ("
2058 << AMother->Identification ()
2059 << ADaughter->Identification () << ")\n";
2063 Standard_Integer IndexM = IsComputed (AMother);
2064 Standard_Integer IndexD = IsComputed (ADaughter);
2066 if (IndexM != 0 && IndexD != 0) {
2067 #ifdef TRACE_CONNECT
2068 cout << "Structure " << AMother->Identification ()
2069 << " is disconnected from the structure "
2070 << ADaughter->Identification () << endl;
2071 cout << "These structures are calculated.\n";
2072 cout << "In the view " << Identification ()
2074 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
2075 << " is disconnected from the structure "
2076 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
2079 MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD));
2084 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure) {
2086 Display (AStructure, MyViewManager->UpdateMode ());
2090 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2092 if (IsDeleted ()) return;
2093 if (! IsDefined ()) return;
2094 if (! IsActive ()) return;
2096 // If Display on a structure present in the list
2097 // of calculated structures while it is not
2098 // or more, of calculated type =>
2099 // - removes it as well as the associated old computed
2100 // THis happens when hlhsr becomes again of type e
2101 // non computed after SetVisual.
2102 Standard_Integer Index = IsComputed (AStructure);
2104 if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) {
2107 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2108 cout << "In Visual3d_View::Display, ";
2109 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2110 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2114 MyTOCOMPUTESequence.Remove (Index);
2115 MyCOMPUTEDSequence.Remove (Index);
2118 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2119 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2120 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2126 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2128 #ifdef TRACE_DISPLAY
2129 Standard_Integer StructId = AStructure->Identification ();
2130 cout << "Visual3d_View" << MyCView.ViewId << "::Display ("
2131 << StructId << ");\n";
2135 if (Answer == Visual3d_TOA_NO) {
2136 #ifdef TRACE_DISPLAY
2137 cout << "Answer : Visual3d_TOA_NO\n";
2143 // Mode degenerated active
2145 if ( !ComputedMode () || DegenerateModeIsOn () )
2146 Answer = Visual3d_TOA_YES;
2148 if (DegenerateModeIsOn ()) Answer = Visual3d_TOA_YES;
2152 if (Answer == Visual3d_TOA_YES ) {
2153 #ifdef TRACE_DISPLAY
2154 cout << "Answer : Visual3d_TOA_YES\n";
2157 if (IsDisplayed (AStructure)) return;
2158 MyGraphicDriver->DisplayStructure (
2160 *(Graphic3d_CStructure *)AStructure->CStructure (),
2161 int (AStructure->DisplayPriority ())
2163 MyDisplayedStructure.Add (AStructure);
2164 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2167 if (Answer == Visual3d_TOA_COMPUTE) {
2168 #ifdef TRACE_DISPLAY
2169 cout << "Answer : Visual3d_TOA_COMPUTE\n";
2170 cout << "Index : " << Index << "\n" << flush;
2173 // Already computed, is COMPUTED still valid?
2174 #ifdef TRACE_DISPLAY
2175 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2176 cout << "Structure "
2177 << MyTOCOMPUTESequence.Value (Index)->Identification ()
2178 << "already calculated, in the view "
2179 << Identification () << ", par la structure "
2180 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2181 << "\n was not recalculated as HLR is valid\n";
2185 cout << "Structure "
2186 << MyTOCOMPUTESequence.Value (Index)->Identification ()
2187 << " already calculated, in the view "
2188 << Identification () << ", by the structure "
2189 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2190 << "\n should be recalculated as HLR is invalid\n";
2194 Standard_Integer OldStructId =
2195 MyCOMPUTEDSequence.Value (Index)->Identification ();
2197 // Case COMPUTED valide
2198 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
2200 if (! IsDisplayed (AStructure)) {
2201 MyDisplayedStructure.Add (AStructure);
2202 MyGraphicDriver->DisplayStructure (
2204 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
2205 int (AStructure->DisplayPriority ())
2207 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2212 // Case COMPUTED invalid
2214 // Is there another valid representation ?
2215 // Find in the sequence of already calculated structures
2216 // 1/ Structure having the same Owner as <AStructure>
2217 // 2/ That is not <AStructure>
2218 // 3/ The COMPUTED which of is valid
2219 Standard_Integer NewIndex = HaveTheSameOwner (AStructure);
2221 // Case of COMPUTED invalid, WITH a valid of replacement
2222 if (NewIndex != 0) {
2224 if (! IsDisplayed (AStructure)) {
2225 MyCOMPUTEDSequence.SetValue
2226 (Index, MyCOMPUTEDSequence.Value (NewIndex));
2227 OldStructId = MyCOMPUTEDSequence.Value (NewIndex)->
2229 MyDisplayedStructure.Add (AStructure);
2230 MyGraphicDriver->DisplayStructure (
2232 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (NewIndex)->CStructure (),
2233 int (AStructure->DisplayPriority ())
2235 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2240 // Cas COMPUTED invalid, WITHOUT a valid of replacement
2242 // COMPUTED is removed if displayed
2243 if (IsDisplayed (AStructure))
2244 MyGraphicDriver->EraseStructure (
2246 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()
2250 } // if (Index != 0)
2252 // Compute + Validation
2254 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
2256 Handle(Graphic3d_Structure) TheStructure;
2257 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
2258 AStructure->Transform (ATrsf);
2260 TColStd_Array2OfReal Ident (0, 3, 0, 3);
2261 Standard_Integer ii, jj;
2262 for (ii=0; ii<=3; ii++)
2263 for (jj=0; jj<=3; jj++)
2264 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
2265 TheStructure = MyCOMPUTEDSequence.Value (Index);
2266 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
2267 if (AStructure->IsTransformed ()) {
2268 AStructure->Compute (this, ATrsf, TheStructure);
2271 AStructure->Compute (this, TheStructure);
2275 if (AStructure->IsTransformed ()) {
2276 TheStructure = AStructure->Compute (this, ATrsf);
2279 TheStructure = AStructure->Compute (this);
2283 TheStructure->SetHLRValidation (Standard_True);
2286 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2287 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2288 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2292 // TOCOMPUTE and COMPUTED associated to sequences are added
2293 MyTOCOMPUTESequence.Append (AStructure);
2294 MyCOMPUTEDSequence.Append (TheStructure);
2297 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2298 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2299 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2303 // The previous are removed if necessary
2305 MyTOCOMPUTESequence.Remove (Index);
2306 MyCOMPUTEDSequence.Remove (Index);
2310 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2311 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2312 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2316 // Return type of visualisation of the view
2317 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
2319 // Of which type will be the computed ?
2320 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
2321 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
2323 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
2324 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
2326 if (ComputeWireframe)
2327 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
2329 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
2331 if (! ComputeShading && ! ComputeWireframe)
2332 Answer = Visual3d_TOA_NO;
2334 Answer = AcceptDisplay (TheStructure);
2336 if (AStructure->IsHighlighted()) {
2337 TheStructure->SetHighlightColor (AStructure->HighlightColor ());
2338 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
2341 #ifdef TRACE_DISPLAY
2342 cout << "Structure " << StructId
2343 << " in the view " << Identification ()
2344 << " is calculated by the structure "
2345 << TheStructure->Identification ();
2346 if (Answer == Visual3d_TOA_YES)
2347 cout << " and displayed\n";
2349 cout << " but not displayed\n";
2353 // It is displayed only if the calculated structure
2354 // has a proper type corresponding to the one of the view.
2355 if (Answer != Visual3d_TOA_NO) {
2356 if (! IsDisplayed (AStructure))
2357 MyDisplayedStructure.Add (AStructure);
2358 MyGraphicDriver->DisplayStructure (
2360 *(Graphic3d_CStructure *)TheStructure->CStructure (),
2361 int (AStructure->DisplayPriority ())
2363 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2365 } // Visual3d_TOA_COMPUTE
2368 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure) {
2370 if (IsDeleted ()) return;
2372 Erase (AStructure, MyViewManager->UpdateMode ());
2376 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2378 Standard_Integer StructId;
2380 if (IsDeleted ()) return;
2382 // No test on window as the structure is displayed only if
2383 // the window exists, so only one test is enough.
2384 if (IsDisplayed (AStructure)) {
2385 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2387 // Degenerated mode is active
2389 if ( !ComputedMode () || DegenerateModeIsOn () )
2390 Answer = Visual3d_TOA_YES;
2392 if (DegenerateModeIsOn ()) Answer = Visual3d_TOA_YES;
2395 if (Answer != Visual3d_TOA_COMPUTE) {
2396 MyGraphicDriver->EraseStructure (
2398 *(Graphic3d_CStructure *)AStructure->CStructure ()
2402 if (Answer == Visual3d_TOA_COMPUTE) {
2403 Standard_Integer Index = IsComputed (AStructure);
2405 cout << "Visual3d_View" << MyCView.ViewId << "::Erase ("
2406 << AStructure->Identification () << ");\n";
2407 cout << "Index : " << Index << "\n";
2411 if ( Index != 0 && ComputedMode () &&
2412 !DegenerateModeIsOn () )
2414 if ((Index != 0) && (! DegenerateModeIsOn ()))
2418 MyCOMPUTEDSequence.Value (Index)->Identification ();
2420 cout << "Structure " << AStructure->Identification ()
2421 << " calculated, in the view "
2422 << Identification () << ", by the structure "
2423 << StructId << " is removed. \n";
2426 MyGraphicDriver->EraseStructure
2427 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
2429 // else is impossible
2431 MyDisplayedStructure.Remove (AStructure);
2432 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2437 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
2440 cout << "Visual3d_View" << MyCView.ViewId << "::Highlight ("
2441 << AStructure->Identification () << ")\n";
2445 Standard_Integer Index = IsComputed (AStructure);
2448 cout << "Structure " << AStructure->Identification ()
2449 << " calculated, in the view "
2450 << Identification () << ", by the structure "
2451 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2452 << " passes in highlight mode.\n";
2455 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
2456 (AStructure->HighlightColor ());
2457 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod);
2462 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
2465 cout << "Visual3d_View" << MyCView.ViewId << "::Transform ("
2466 << AStructure->Identification () << ")\n";
2470 Standard_Integer Index = IsComputed (AStructure);
2473 cout << "The structure " << AStructure->Identification ()
2474 << " calculated, in the view "
2475 << Identification () << ", by the structure "
2476 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2477 << " is transformed.\n";
2480 // Test is somewhat light !
2481 // trsf is transferred only if it is :
2484 if (ATrsf (0, 1) != 0. || ATrsf (0, 2) != 0.
2485 || ATrsf (1, 0) != 0. || ATrsf (1, 2) != 0.
2486 || ATrsf (2, 0) != 0. || ATrsf (2, 1) != 0.)
2487 ReCompute (AStructure);
2489 MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf);
2494 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
2497 cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight ("
2498 << AStructure->Identification () << ")\n";
2502 Standard_Integer Index = IsComputed (AStructure);
2505 cout << "Structure " << AStructure->Identification ()
2506 << " calculated, in the view "
2507 << Identification () << ", by the structure "
2508 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2509 << " passes in unhighlight mode.\n";
2512 MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight ();
2518 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const {
2520 Standard_Integer StrId = AStructure->Identification ();
2522 Standard_Integer Result = 0;
2523 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
2525 // Recherche de la structure <AStructure> dans la
2526 // sequence des structures deja calculees
2527 for (Standard_Integer i=1; i<=Length && Result==0; i++)
2528 if ((MyTOCOMPUTESequence.Value (i))->Identification ()
2529 == StrId) Result = i;
2531 cout << "\n In the view " << Identification () << " the structure ";
2533 cout << StrId << " is calculated by "
2534 << MyCOMPUTEDSequence.Value (Result)->Identification ()
2537 cout << StrId << " is not calculated\n" << flush;
2541 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2542 cout << "In Visual3d_View::IsComputed, ";
2543 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2544 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2553 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const {
2555 Standard_Boolean Result = Standard_False;
2557 if (IsDeleted ()) return Result;
2559 Result = MyDisplayedStructure.Contains (AStructure);
2566 Standard_Boolean Visual3d_View::ContainsComputedStructure () const {
2568 Standard_Boolean Result = Standard_False;
2570 if (MyDisplayedStructure.IsEmpty ()) return Result;
2572 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
2574 Standard_Integer i = MyDisplayedStructure.Extent ();
2576 // Stop at the first structure of type TOS_COMPUTED
2577 while (! Result && Iterator.More ()) {
2579 (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED);
2581 // Iterator.Next () is located on the
2591 Standard_Boolean Visual3d_View::ContainsFacet () const {
2593 return ContainsFacet (MyDisplayedStructure);
2597 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const {
2599 Standard_Boolean Result = Standard_False;
2601 if (ASet.IsEmpty ()) return Result;
2603 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2605 // Stop at the first structure containing a facet
2606 for ( Iterator.Initialize (ASet);
2607 Iterator.More () && ! Result;
2609 Result = (Iterator.Key ())->ContainsFacet ();
2615 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
2618 (MyDisplayedStructure, XMin, YMin, ZMin, XMax, YMax, ZMax);
2622 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 {
2624 if (ASet.IsEmpty ()) {
2625 XMin = RealFirst ();
2626 YMin = RealFirst ();
2627 ZMin = RealFirst ();
2635 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2636 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2642 XMax = RealFirst ();
2643 YMax = RealFirst ();
2644 ZMax = RealFirst ();
2646 for ( Iterator.Initialize (ASet);
2650 if ( (Iterator.Key ())->IsInfinite ()){
2651 //XMin, YMin .... ZMax are initialized by means of infinite line data
2652 (Iterator.Key ())->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
2653 if ( Xm != RealFirst() && Xm < XMin )
2655 if ( Ym != RealFirst() && Ym < YMin )
2657 if ( Zm != RealFirst() && Zm < ZMin )
2659 if ( XM != RealLast() && XM > XMax )
2661 if ( YM != RealLast() && YM > YMax )
2663 if ( ZM != RealLast() && ZM > ZMax )
2666 // Only non-empty and non-infinite structures
2667 // are taken into account for calculation of MinMax
2668 if (! (Iterator.Key ())->IsInfinite () &&
2669 ! (Iterator.Key ())->IsEmpty ()) {
2670 (Iterator.Key ())->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
2671 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
2672 //"FitAll" operation ignores object with transform persitence parameter
2673 if( (Iterator.Key ())->TransformPersistenceMode() == Graphic3d_TMF_None )
2675 if (Xm < XMin) XMin = Xm;
2676 if (Ym < YMin) YMin = Ym;
2677 if (Zm < ZMin) ZMin = Zm;
2678 if (XM > XMax) XMax = XM;
2679 if (YM > YMax) YMax = YM;
2680 if (ZM > ZMax) ZMax = ZM;
2685 // The following cases are relevant
2686 // For exemple if all structures are empty or infinite
2687 if (XMax < XMin) { Xm = XMin; XMin = XMax; XMax = Xm; }
2688 if (YMax < YMin) { Ym = YMin; YMin = YMax; YMax = Ym; }
2689 if (ZMax < ZMin) { Zm = ZMin; ZMin = ZMax; ZMax = Zm; }
2691 Standard_Real Sx, Sy, Sz;
2692 MyViewOrientation.AxialScale(Sx, Sy, Sz);
2693 XMin = (Sx > 1. && XMin < RealFirst ()/Sx)?RealFirst (): XMin*Sx;
2694 XMax = (Sx > 1. && XMax > RealLast ()/Sx)?RealLast (): XMax*Sx;
2695 YMin = (Sy > 1. && YMin < RealFirst ()/Sy)?RealFirst (): YMin*Sy;
2696 YMax = (Sy > 1. && YMax > RealLast ()/Sy)?RealLast (): YMax*Sy;
2697 ZMin = (Sz > 1. && ZMin < RealFirst ()/Sz)?RealFirst (): ZMin*Sz;
2698 ZMax = (Sz > 1. && ZMax > RealLast ()/Sz)?RealLast (): ZMax*Sz;
2701 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2703 MinMaxValues (MyDisplayedStructure, XMin, YMin, XMax, YMax);
2707 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2709 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2710 Standard_Real Xp, Yp, Zp;
2712 MinMaxValues (ASet, Xm, Ym, Zm, XM, YM, ZM);
2714 Projects (Xm, Ym, Zm, Xp, Yp, Zp);
2718 Projects (XM, YM, ZM, Xp, Yp, Zp);
2722 if (XMax < XMin) { Xp = XMax; XMax = XMin; XMin = Xp; }
2723 if (YMax < YMin) { Yp = YMax; YMax = YMin; YMin = Yp; }
2726 const TColStd_Array2OfReal& Visual3d_View::MatrixOfOrientation () {
2728 if (! MyMatOfOriIsEvaluated) {
2729 MyGraphicDriver->InquireMat
2730 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2731 MyMatOfMapIsEvaluated = Standard_True;
2732 MyMatOfOriIsEvaluated = Standard_True;
2735 return (MyMatrixOfOrientation);
2739 const TColStd_Array2OfReal& Visual3d_View::MatrixOfMapping () {
2741 if (! MyMatOfMapIsEvaluated) {
2742 MyGraphicDriver->InquireMat
2743 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2744 MyMatOfMapIsEvaluated = Standard_True;
2745 MyMatOfOriIsEvaluated = Standard_True;
2748 return (MyMatrixOfMapping);
2752 Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const {
2754 Standard_Integer Result = MyDisplayedStructure.Extent ();
2761 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 {
2763 math_Vector PtDC (0,3), PtWC (0,3);
2766 // Otherwise use new on Visual3d_View (constructor+destructor)
2767 // as Projects is a const method or MatrixOfOrientation and
2768 // MatrixOfMapping is not.
2769 Visual3d_View * const newthis = (Visual3d_View * const) this;
2770 newthis->MatrixOfOrientation ();
2771 newthis->MatrixOfMapping ();
2773 // World Coordinate Space
2779 // WCS -> View Reference Coordinate Space
2780 math_Vector PtVRC(0,3);
2781 PtVRC = MyMatrixOfOrientation.Multiplied (PtWC);
2783 // VRCS -> Normalized Projection Coordinate Space
2784 math_Vector PtNPC(0,3);
2785 PtNPC = MyMatrixOfMapping.Multiplied (PtVRC);
2786 for (Standard_Integer i=0; i<3; i++) PtNPC (i) = PtNPC (i) / PtNPC (3);
2789 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2790 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2793 Standard_Real Ratio;
2795 // NPCS -> Device Coordinate Space
2796 Standard_Real Dx = Standard_Real (MyCView.DefWindow.dx);
2797 Standard_Real Dy = Standard_Real (MyCView.DefWindow.dy);
2800 PtDC (0) = PtNPC (0) * Dx;
2801 PtDC (1) = Dy - PtNPC (1) * Dy * Ratio;
2803 printf("Display coordinates : %f,%f,%f,%f\n",
2804 PtDC(0),PtDC(1),PtDC(2),PtDC(3));
2807 // NPCS -> Window Space
2808 Standard_Real um, vm, uM, vM;
2809 MyViewMapping.WindowLimit (um, vm, uM, vM);
2811 Ratio = (uM - um) / (vM - vm);
2813 PtNPC (1) = PtNPC (1) * Ratio;
2815 PtNPC (0) = PtNPC (0) / Ratio;
2818 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2819 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2822 Standard_Real fpd = MyViewMapping.FrontPlaneDistance ();
2823 Standard_Real bpd = MyViewMapping.BackPlaneDistance ();
2826 * Coordinates of PtNPC are described in the space
2827 * [0-1]x[0-1]x[0-1].
2828 * It is necessary to transform x and y in the window space.
2829 * It is necessary to transform z in the space of back and front
2830 * plane, taking into account clipping planes.
2831 * Z clipping planes are defined between 0 and 1.
2834 APX = PtNPC (0) * (uM - um) + um;
2835 APY = PtNPC (1) * (vM - vm) + vm;
2836 APZ = PtNPC (2) * (fpd - bpd) + bpd;
2839 Standard_Integer l,c;
2840 printf("OrientationMatrix :");
2841 for( l=0 ; l<4 ; l++ ) {
2842 printf("\n %d->",l);
2843 for( c=0 ; c<4 ; c++ ) {
2844 printf(" %f ,",MyMatrixOfOrientation(c,l));
2848 printf("MappingMatrix :");
2849 for( l=0 ; l<4 ; l++ ) {
2850 printf("\n %d->",l);
2851 for( c=0 ; c<4 ; c++ ) {
2852 printf(" %f ,",MyMatrixOfMapping(c,l));
2856 printf("World coordinates : %f,%f,%f,%f\n",
2857 PtWC(0),PtWC(1),PtWC(2),PtWC(3));
2858 printf("View coordinates : %f,%f,%f,%f\n",
2859 PtVRC(0),PtVRC(1),PtVRC(2),PtVRC(3));
2860 printf("Display coordinates : %f,%f,%f,%f\n",
2861 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2862 printf("Window limit : %f,%f,%f,%f\n",um,vm,uM,vM);
2863 printf("Ratio : %f\n",Ratio);
2864 printf("Front-plane : %f back-plane : %f\n",fpd,bpd);
2865 printf("Projection : %f,%f,%f\n \n",APX,APY,APZ);
2869 #endif /* OLD_METHOD */
2871 // OCC18942: This method is likely to duplicate Visual3d_ViewManager::ConvertCoord() one,
2872 // therefore it is necessary to consider merging the two methods or making them call the same
2873 // graphic driver's method after OCCT 6.3.
2874 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) {
2876 Standard_Real PtX, PtY, PtZ, PtT;
2878 static Standard_Real Ratio, um, vm, uM, vM;
2879 static Standard_Real fpd, bpd;
2881 if (! MyMatOfOriIsEvaluated || ! MyMatOfMapIsEvaluated) {
2882 MyGraphicDriver->InquireMat
2883 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2884 MyMatOfOriIsEvaluated = MyMatOfMapIsEvaluated = Standard_True;
2887 // WCS -> View Reference Coordinate Space
2888 PtX = MyMatrixOfOrientation (0, 0) * AX
2889 + MyMatrixOfOrientation (0, 1) * AY
2890 + MyMatrixOfOrientation (0, 2) * AZ
2891 + MyMatrixOfOrientation (0, 3);
2892 PtY = MyMatrixOfOrientation (1, 0) * AX
2893 + MyMatrixOfOrientation (1, 1) * AY
2894 + MyMatrixOfOrientation (1, 2) * AZ
2895 + MyMatrixOfOrientation (1, 3);
2896 PtZ = MyMatrixOfOrientation (2, 0) * AX
2897 + MyMatrixOfOrientation (2, 1) * AY
2898 + MyMatrixOfOrientation (2, 2) * AZ
2899 + MyMatrixOfOrientation (2, 3);
2900 PtT = MyMatrixOfOrientation (3, 0) * AX
2901 + MyMatrixOfOrientation (3, 1) * AY
2902 + MyMatrixOfOrientation (3, 2) * AZ
2903 + MyMatrixOfOrientation (3, 3);
2905 // VRCS -> Normalized Projection Coordinate Space
2906 APX = MyMatrixOfMapping (0, 0) * PtX
2907 + MyMatrixOfMapping (0, 1) * PtY
2908 + MyMatrixOfMapping (0, 2) * PtZ
2909 + MyMatrixOfMapping (0, 3) * PtT;
2910 APY = MyMatrixOfMapping (1, 0) * PtX
2911 + MyMatrixOfMapping (1, 1) * PtY
2912 + MyMatrixOfMapping (1, 2) * PtZ
2913 + MyMatrixOfMapping (1, 3) * PtT;
2914 APZ = MyMatrixOfMapping (2, 0) * PtX
2915 + MyMatrixOfMapping (2, 1) * PtY
2916 + MyMatrixOfMapping (2, 2) * PtZ
2917 + MyMatrixOfMapping (2, 3) * PtT;
2918 APT = MyMatrixOfMapping (3, 0) * PtX
2919 + MyMatrixOfMapping (3, 1) * PtY
2920 + MyMatrixOfMapping (3, 2) * PtZ
2921 + MyMatrixOfMapping (3, 3) * PtT;
2927 // NPCS -> Window Space
2928 MyViewMapping.WindowLimit (um, vm, uM, vM);
2929 fpd = MyViewMapping.FrontPlaneDistance ();
2930 bpd = MyViewMapping.BackPlaneDistance ();
2932 if(MyCView.Mapping.IsCustomMatrix) {
2933 // OCC18942: SAN - If orientation and mapping matrices are those used by OpenGL
2934 // visualization, then X, Y and Z coordinates normally vary between -1 and 1
2935 APX = ( APX + 1 ) * 0.5 * (uM - um) + um;
2936 APY = ( APY + 1 ) * 0.5 * (vM - vm) + vm;
2938 Ratio = (uM - um) / (vM - vm);
2945 * Coordinates of APX, APY, APZ are described in the space
2946 * [0-1]x[0-1]x[0-1].
2947 * It is necessary to transform x and y in the window space.
2948 * It is necessary to transform z in the space of back and front
2949 * plane, taking into account clipping planes.
2950 * Z clipping planes are defined between 0 and 1.
2952 APX = APX * (uM - um) + um;
2953 APY = APY * (vM - vm) + vm;
2955 APZ = APZ * (fpd - bpd) + bpd;
2958 Standard_Integer Visual3d_View::Identification () const {
2960 return (Standard_Integer (MyCView.ViewId));
2965 Standard_Boolean Visual3d_View::ZBufferIsActivated () const {
2967 if (IsDeleted ()) return (Standard_False);
2969 if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);
2971 // -1 => not forced by the programmer => depends on the type of visualisation
2972 // 0 ou 1 => forced by the programmer
2974 if (MyCView.Context.ZBufferActivity == -1)
2975 if (MyContext.Visualization () == Visual3d_TOV_SHADING)
2976 return (Standard_True);
2978 return (Standard_False);
2980 if (MyCView.Context.ZBufferActivity)
2981 return (Standard_True);
2983 return (Standard_False);
2987 void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {
2989 if (IsDeleted ()) return;
2991 if ((! IsDefined ()) || (! IsActive ())) return;
2993 MyGraphicDriver->Transparency (MyCView, AnActivity);
2997 void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {
2999 if (MyCView.Context.ZBufferActivity == AnActivity) return;
3001 if (IsDeleted ()) return;
3003 if ((! IsDefined ()) || (! IsActive ())) return;
3005 MyCView.Context.ZBufferActivity = AnActivity;
3006 MyGraphicDriver->SetVisualisation (MyCView);
3010 void Visual3d_View::UpdateView () {
3012 MyCView.Context.Aliasing = (MyContext.AliasingIsOn () ? 1:0);
3013 MyCView.Context.BackZClipping =
3014 (MyContext.BackZClippingIsOn () ? 1:0);
3015 MyCView.Context.FrontZClipping =
3016 (MyContext.FrontZClippingIsOn() ? 1:0);
3017 MyCView.Context.DepthCueing =
3018 (MyContext.DepthCueingIsOn () ? 1:0);
3020 MyCView.Context.ZClipFrontPlane =
3021 float (MyContext.ZClippingFrontPlane ());
3022 MyCView.Context.ZClipBackPlane =
3023 float (MyContext.ZClippingBackPlane ());
3024 MyCView.Context.DepthFrontPlane =
3025 float (MyContext.DepthCueingFrontPlane ());
3026 MyCView.Context.DepthBackPlane =
3027 float (MyContext.DepthCueingBackPlane ());
3029 MyCView.Context.Model = int (MyContext.Model ());
3030 MyCView.Context.Visualization = int (MyContext.Visualization ());
3032 MyCView.Context.TextureEnv = MyContext.TextureEnv();
3033 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
3037 void Visual3d_View::Compute () {
3040 Standard_Integer Length = MyCOMPUTEDSequence.Length ();
3041 for (i=1; i<=Length; i++)
3042 (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);
3044 // if the degenerated node is active, nothing is recomputed
3046 if ( DegenerateModeIsOn () || !ComputedMode () ) return;
3048 if (DegenerateModeIsOn ()) return;
3052 * Force HLRValidation to False on all structures
3053 * calculated in the view.
3056 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3057 cout << "In Visual3d_View::Compute, ";
3058 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3059 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3065 * Change of orientation or of projection type =>
3066 * Remove structures that were calculated for the
3067 * previous orientation.
3068 * Recalculation of new structures.
3069 * Passage of the degenerated mode ON to OFF =>
3070 * Remove structures that were calculated before
3071 * the degenerated mode passed to ON.
3072 * Recalculate new structures.
3074 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3075 Visual3d_TypeOfAnswer Answer;
3077 i = MyDisplayedStructure.Extent ();
3079 Graphic3d_SequenceOfStructure FooSequence;
3081 while (S1Iterator.More ()) {
3082 Answer = AcceptDisplay (S1Iterator.Key ());
3083 // If the structure was calculated, it is recalculated.
3084 if (Answer == Visual3d_TOA_COMPUTE) {
3086 cout << "AcceptDisplay ("
3087 << (S1Iterator.Key ())->Identification ()
3088 << ") == Visual3d_TOA_COMPUTE;\n";
3091 //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
3092 FooSequence.Append (S1Iterator.Key ());
3095 // S1Iterator.Next () is located on the next structure
3099 Length = FooSequence.Length ();
3100 // All stored structures are displayed
3101 for (i=1; i<=Length; i++)
3102 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
3103 if (Length != 0) FooSequence.Clear ();
3107 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
3109 if ( DegenerateModeIsOn () || !ComputedMode () ) return;
3111 if (DegenerateModeIsOn()) return;
3114 if (IsDeleted ()) return;
3116 if ((! IsDefined ()) || (! IsActive ())) return;
3118 if (! MyWindow->IsMapped ()) return;
3120 if (! AStructure->IsDisplayed ()) return;
3122 Visual3d_TypeOfAnswer Answer;
3124 Answer = AcceptDisplay (AStructure);
3126 if (Answer == Visual3d_TOA_COMPUTE) {
3127 Standard_Integer Index = IsComputed (AStructure);
3130 cout << "Structure " << AStructure->Identification ()
3131 << " is not calculated in the view "
3132 << Identification () << "\n";
3137 Standard_Integer OldStructId, NewStructId;
3139 MyCOMPUTEDSequence.Value (Index)->Identification ();
3141 Standard_Integer StructId = AStructure->Identification ();
3142 cout << "Structure " << StructId
3143 << " calculated, in the view "
3144 << Identification () << ", by the structure "
3145 << OldStructId << " is recalculated.\n";
3149 // Compute + Validation
3151 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3153 Handle(Graphic3d_Structure) TheStructure;
3154 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3155 AStructure->Transform (ATrsf);
3157 TColStd_Array2OfReal Ident (0, 3, 0, 3);
3158 Standard_Integer ii, jj;
3159 for (ii=0; ii<=3; ii++)
3160 for (jj=0; jj<=3; jj++)
3161 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3162 TheStructure = MyCOMPUTEDSequence.Value (Index);
3163 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3164 if (AStructure->IsTransformed ()) {
3165 AStructure->Compute (this, ATrsf, TheStructure);
3168 AStructure->Compute (this, TheStructure);
3172 if (AStructure->IsTransformed ()) {
3173 TheStructure = AStructure->Compute (this, ATrsf);
3176 TheStructure = AStructure->Compute (this);
3180 TheStructure->SetHLRValidation (Standard_True);
3182 // Return type of visualisation of the view
3183 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3185 // Of which type will be the computed ?
3186 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3187 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
3189 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3190 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3192 if (ComputeWireframe)
3193 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3195 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3197 if (AStructure->IsHighlighted ()) {
3198 TheStructure->SetHighlightColor
3199 (AStructure->HighlightColor ());
3200 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3204 // Find structure <AStructure>
3205 // in the sequence of structures to be calculated.
3206 NewStructId = TheStructure->Identification ();
3208 // The previous calculation is removed and the new one is dislayed
3209 MyGraphicDriver->EraseStructure (
3211 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3212 MyGraphicDriver->DisplayStructure (
3214 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3215 int (AStructure->DisplayPriority ())
3219 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3220 cout << "In Visual3d_View::ReCompute, ";
3221 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3222 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3227 // hlhsr and the new associated compute are added
3228 MyTOCOMPUTESequence.Append (AStructure);
3229 MyCOMPUTEDSequence.Append (TheStructure);
3232 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3233 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3234 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3238 // hlhsr and the new associated compute are removed
3240 MyTOCOMPUTESequence.Remove (Index);
3241 MyCOMPUTEDSequence.Remove (Index);
3244 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3245 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3246 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3256 Visual3d_View::SetAnimationModeOn ( const Standard_Boolean degenerate ) {
3258 Visual3d_View::SetAnimationModeOn () {
3261 if (AnimationModeIsOn ()) return;
3263 AnimationModeIsActive = Standard_True;
3266 SetDegenerateModeOn ();
3268 SetDegenerateModeOff ();
3270 MyGraphicDriver->BeginAnimation (MyCView);
3274 void Visual3d_View::SetAnimationModeOff () {
3276 if (! AnimationModeIsOn ()) return;
3278 AnimationModeIsActive = Standard_False;
3280 SetDegenerateModeOff ();
3282 MyGraphicDriver->EndAnimation (MyCView);
3286 Standard_Boolean Visual3d_View::AnimationModeIsOn () const {
3288 return AnimationModeIsActive;
3292 void Visual3d_View::SetDegenerateModeOn () {
3295 cout << "Visual3d_View" << MyCView.ViewId
3296 << "::SetDegenerateModeOn ();\n";
3300 // If the degenerated mode is already active, nothing is recalculated
3301 if (DegenerateModeIsOn ()) return;
3302 DegenerateModeIsActive = Standard_True;
3305 MyCView.IsDegenerates = 1;
3308 * Change of activity of the degenerated mode
3309 * Remove structures that were calculated
3310 * and displayed when the mode was off.
3311 * Display of non-calculated structures.
3313 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3314 Visual3d_TypeOfAnswer Answer;
3315 Standard_Integer StructId;
3317 while (S1Iterator.More ()) {
3319 Answer = AcceptDisplay (S1Iterator.Key ());
3320 // If the structure was calculated, the previous one is
3321 // removed and the new one is displayed
3322 // (This is the role of passage into degenerated mode)
3324 if (Answer == Visual3d_TOA_COMPUTE) {
3325 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3328 MyCOMPUTEDSequence.Value (Index)->Identification ();
3330 cout << "Structure " << S1Iterator.Key ()->Identification ()
3331 << " calculated, in the view "
3332 << Identification () << ", by structure "
3333 << StructId << " passes in degenerated mode.\n";
3334 cout << "Remove" << StructId << " then display "
3335 << S1Iterator.Key ()->Identification () << "\n";
3338 MyGraphicDriver->EraseStructure
3339 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
3340 MyGraphicDriver->DisplayStructure (
3342 *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure (),
3343 int (S1Iterator.Key ()->DisplayPriority ())
3347 // Else is impossible)
3348 // If the mode was not degenerated previously, the
3349 // calculated structure associated to S1Iterator.Key ()
3350 // really exists and Index != 0
3354 // S1Iterator.Next () is located on the next structure
3360 void Visual3d_View::SetDegenerateModeOff () {
3363 cout << "Visual3d_View" << MyCView.ViewId
3364 << "::SetDegenerateModeOff ();\n";
3368 // If the degenerated mode is already inactive, nothing is recalculated
3369 if (! DegenerateModeIsOn ()) return;
3371 DegenerateModeIsActive = Standard_False;
3374 MyCView.IsDegenerates = 0;
3377 * Change of activity of degenerated mode
3378 * Remove structures that were displayed
3379 * when the mode was on.
3380 * Calculation of structures.
3382 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3383 Visual3d_TypeOfAnswer Answer;
3384 Standard_Integer StructId;
3386 Standard_Integer i = MyDisplayedStructure.Extent ();
3388 while (S1Iterator.More ()) {
3390 Answer = AcceptDisplay (S1Iterator.Key ());
3391 // If the structure was calculated, the previous one is
3392 // removed and the new one is displayed
3393 // (This is the role of passage into degenerated mode)
3395 if (Answer == Visual3d_TOA_COMPUTE) {
3396 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3399 MyCOMPUTEDSequence.Value (Index)->Identification ();
3401 cout << "Structure " << S1Iterator.Key ()->Identification ()
3402 << " calculated, in the view "
3403 << Identification () << ", by the structure "
3404 << StructId << " passes into normal mode.\n";
3405 cout << "Remove " << S1Iterator.Key ()->Identification ()
3406 << " then display " << StructId << "\n";
3409 MyGraphicDriver->EraseStructure
3411 *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure ());
3412 MyGraphicDriver->DisplayStructure (
3414 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
3415 int (S1Iterator.Key ()->DisplayPriority ())
3418 Display (S1Iterator.Key (), Aspect_TOU_WAIT);
3420 if ((S1Iterator.Key ())->IsHighlighted()) {
3421 if (! (MyCOMPUTEDSequence.Value (Index))->IsHighlighted()) {
3422 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
3423 ((S1Iterator.Key ())->HighlightColor ());
3424 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (Aspect_TOHM_COLOR);
3429 // Else is impossible
3430 // Degenerated mode was activated before display of the
3431 // structure. So the structure was displayed in the
3432 // degenerated mode, but the calculated structure didn't exist.
3433 // It is calculated.
3435 // Compute + Validation
3436 Handle(Graphic3d_Structure) AStructure = (S1Iterator.Key ());
3438 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
3440 Handle(Graphic3d_Structure) TheStructure;
3441 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
3442 AStructure->Transform (ATrsf);
3444 TColStd_Array2OfReal Ident (0, 3, 0, 3);
3445 Standard_Integer ii, jj;
3446 for (ii=0; ii<=3; ii++)
3447 for (jj=0; jj<=3; jj++)
3448 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
3449 TheStructure = MyCOMPUTEDSequence.Value (Index);
3450 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
3451 if (AStructure->IsTransformed ()) {
3452 AStructure->Compute (this, ATrsf, TheStructure);
3455 AStructure->Compute (this, TheStructure);
3459 if (AStructure->IsTransformed ()) {
3460 TheStructure = AStructure->Compute (this, ATrsf);
3463 TheStructure = AStructure->Compute (this);
3467 TheStructure->SetHLRValidation (Standard_True);
3469 // Return type of visualisation of the view
3470 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3472 // Of which type will be the computed ?
3473 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
3474 ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_SHADING));
3476 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
3477 ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
3479 if (ComputeWireframe)
3480 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
3482 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
3484 if ((S1Iterator.Key ())->IsHighlighted()) {
3485 TheStructure->SetHighlightColor
3486 ((S1Iterator.Key ())->HighlightColor ());
3487 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
3491 Standard_Integer Result = 0;
3492 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3493 // Find structure <S1Iterator.Key ()>
3494 // in the sequence of structures to be calculated
3495 StructId = (S1Iterator.Key ())->Identification ();
3496 for (i=1; i<=Length && Result==0; i++)
3497 if ((MyTOCOMPUTESequence.Value (i))->Identification () ==
3498 StructId) Result = i;
3500 MyCOMPUTEDSequence.ChangeValue (Result) = TheStructure;
3502 // hlhsr and the associated new compute are added
3504 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
3505 cout << "In Visual3d_View::SetDegenerateModeOff, ";
3506 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3507 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3511 MyTOCOMPUTESequence.Append (S1Iterator.Key ());
3512 MyCOMPUTEDSequence.Append (TheStructure);
3514 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
3515 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
3516 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
3521 // The degenerated is removed and the calculated is displayed
3522 MyGraphicDriver->EraseStructure
3524 *(Graphic3d_CStructure *)(S1Iterator.Key ()->CStructure ()));
3525 MyGraphicDriver->DisplayStructure (
3527 *(Graphic3d_CStructure *)TheStructure->CStructure (),
3528 int (S1Iterator.Key ()->DisplayPriority ())
3533 // S1Iterator.Next () is located on the next structure
3537 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
3541 Standard_Boolean Visual3d_View::DegenerateModeIsOn () const {
3543 return DegenerateModeIsActive;
3547 Handle(Aspect_GraphicDriver) Visual3d_View::GraphicDriver () const {
3549 return MyGraphicDriver;
3553 void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& APlotter) const {
3555 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
3557 while (S1Iterator.More ()) {
3559 if (DegenerateModeIsOn ())
3560 // As the mode is degenerated the displayed structure
3561 // is plotted without taking into account if it is calculated or not
3562 (S1Iterator.Key ())->Plot (APlotter);
3564 Standard_Integer Index = IsComputed (S1Iterator.Key ());
3565 // As the mode is not degenerated the displayed structure
3566 // is plotted as if it was not calculated, otherwise the
3567 // associated calculated structure is plotted.
3569 (S1Iterator.Key ())->Plot (APlotter);
3571 (MyCOMPUTEDSequence.Value (Index))->Plot (APlotter);
3574 // S1Iterator.Next () is located on the next structure
3580 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const {
3582 Standard_Integer Result = 0;
3583 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3585 // Find in the sequence of already calculated structures
3586 // 1/ Structure with the same Owner as <AStructure>
3587 // 2/ Which is not <AStructure>
3588 // 3/ COMPUTED which of is valid
3589 for (Standard_Integer i=1; i<=Length && Result==0; i++)
3590 if ((MyTOCOMPUTESequence.Value (i)->Owner () == AStructure->Owner ())
3591 && (MyTOCOMPUTESequence.Value (i)->Identification () !=
3592 AStructure->Identification ())
3593 && (MyCOMPUTEDSequence.Value (i)->HLRValidation ())) Result = i;
3599 Standard_Address Visual3d_View::CView () const {
3601 return Standard_Address (&MyCView);
3606 // Triedron methods : the Triedron is a non-zoomable object.
3608 void Visual3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
3609 const Quantity_NameOfColor YColor,
3610 const Quantity_NameOfColor ZColor,
3611 const Standard_Real SizeRatio,
3612 const Standard_Real AxisDiametr,
3613 const Standard_Integer NbFacettes) {
3614 MyGraphicDriver->ZBufferTriedronSetup(XColor, YColor, ZColor,
3615 SizeRatio, AxisDiametr, NbFacettes);
3620 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
3621 const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) {
3623 MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe);
3627 void Visual3d_View::TriedronErase () {
3629 MyGraphicDriver->TriedronErase (MyCView);
3634 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {
3636 MyGraphicDriver->TriedronEcho (MyCView,AType);
3640 Standard_Boolean checkFloat(const Standard_Real value)
3642 return value > -FLT_MAX && value < FLT_MAX;
3645 void SetMinMaxValuesCallback(void* Visual3dView)
3647 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
3649 Handle(Visual3d_View) view = (Handle(Visual3d_View)&) Visual3dView;
3650 view->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax);
3652 if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) &&
3653 checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax))
3655 Handle(Graphic3d_GraphicDriver) driver = Handle(Graphic3d_GraphicDriver)::DownCast(view->GraphicDriver());
3656 driver->GraduatedTrihedronMinMaxValues((Standard_ShortReal)xmin, (Standard_ShortReal)ymin, (Standard_ShortReal)zmin,
3657 (Standard_ShortReal)xmax, (Standard_ShortReal)ymax, (Standard_ShortReal)zmax);
3661 Standard_Boolean Visual3d_View::GetGraduatedTrihedron
3662 (/* Names of axes */
3663 TCollection_ExtendedString& xname,
3664 TCollection_ExtendedString& yname,
3665 TCollection_ExtendedString& zname,
3667 Standard_Boolean& xdrawname,
3668 Standard_Boolean& ydrawname,
3669 Standard_Boolean& zdrawname,
3671 Standard_Boolean& xdrawvalues,
3672 Standard_Boolean& ydrawvalues,
3673 Standard_Boolean& zdrawvalues,
3675 Standard_Boolean& drawgrid,
3677 Standard_Boolean& drawaxes,
3678 /* Number of splits along axes */
3679 Standard_Integer& nbx,
3680 Standard_Integer& nby,
3681 Standard_Integer& nbz,
3682 /* Offset for drawing values */
3683 Standard_Integer& xoffset,
3684 Standard_Integer& yoffset,
3685 Standard_Integer& zoffset,
3686 /* Offset for drawing names of axes */
3687 Standard_Integer& xaxisoffset,
3688 Standard_Integer& yaxisoffset,
3689 Standard_Integer& zaxisoffset,
3690 /* Draw tickmarks */
3691 Standard_Boolean& xdrawtickmarks,
3692 Standard_Boolean& ydrawtickmarks,
3693 Standard_Boolean& zdrawtickmarks,
3694 /* Length of tickmarks */
3695 Standard_Integer& xtickmarklength,
3696 Standard_Integer& ytickmarklength,
3697 Standard_Integer& ztickmarklength,
3699 Quantity_Color& gridcolor,
3700 /* Colors of axis names */
3701 Quantity_Color& xnamecolor,
3702 Quantity_Color& ynamecolor,
3703 Quantity_Color& znamecolor,
3704 /* Colors of axis and values */
3705 Quantity_Color& xcolor,
3706 Quantity_Color& ycolor,
3707 Quantity_Color& zcolor,
3708 /* Name of font for names of axes */
3709 TCollection_AsciiString& fontOfNames,
3710 /* Style of names of axes */
3711 Font_FontAspect& styleOfNames,
3712 /* Size of names of axes */
3713 Standard_Integer& sizeOfNames,
3714 /* Name of font for values */
3715 TCollection_AsciiString& fontOfValues,
3716 /* Style of values */
3717 Font_FontAspect& styleOfValues,
3718 /* Size of values */
3719 Standard_Integer& sizeOfValues) const
3721 if (!MyGTrihedron.ptrVisual3dView)
3722 return Standard_False;
3725 xname = MyGTrihedron.xname;
3726 yname = MyGTrihedron.yname;
3727 zname = MyGTrihedron.zname;
3729 xdrawname = MyGTrihedron.xdrawname;
3730 ydrawname = MyGTrihedron.ydrawname;
3731 zdrawname = MyGTrihedron.zdrawname;
3733 xdrawvalues = MyGTrihedron.xdrawvalues;
3734 ydrawvalues = MyGTrihedron.ydrawvalues;
3735 zdrawvalues = MyGTrihedron.zdrawvalues;
3737 drawgrid = MyGTrihedron.drawgrid;
3739 drawaxes = MyGTrihedron.drawaxes;
3740 /* Number of splits along axes */
3741 nbx = MyGTrihedron.nbx;
3742 nby = MyGTrihedron.nby;
3743 nbz = MyGTrihedron.nbz;
3744 /* Offset for drawing values */
3745 xoffset = MyGTrihedron.xoffset;
3746 yoffset = MyGTrihedron.yoffset;
3747 zoffset = MyGTrihedron.zoffset;
3748 /* Offset for drawing names of axes */
3749 xaxisoffset = MyGTrihedron.xaxisoffset;
3750 yaxisoffset = MyGTrihedron.yaxisoffset;
3751 zaxisoffset = MyGTrihedron.zaxisoffset;
3752 /* Draw tickmarks */
3753 xdrawtickmarks = MyGTrihedron.xdrawtickmarks;
3754 ydrawtickmarks = MyGTrihedron.ydrawtickmarks;
3755 zdrawtickmarks = MyGTrihedron.zdrawtickmarks;
3756 /* Length of tickmarks */
3757 xtickmarklength = MyGTrihedron.xtickmarklength;
3758 ytickmarklength = MyGTrihedron.ytickmarklength;
3759 ztickmarklength = MyGTrihedron.ztickmarklength;
3761 gridcolor = MyGTrihedron.gridcolor;
3762 /* Colors of axis names */
3763 xnamecolor = MyGTrihedron.xnamecolor;
3764 ynamecolor = MyGTrihedron.ynamecolor;
3765 znamecolor = MyGTrihedron.znamecolor;
3766 /* Colors of axis and values */
3767 xcolor = MyGTrihedron.xcolor;
3768 ycolor = MyGTrihedron.ycolor;
3769 zcolor = MyGTrihedron.zcolor;
3770 /* Name of font for names of axes */
3771 fontOfNames = MyGTrihedron.fontOfNames;
3772 /* Style of names of axes */
3773 styleOfNames = MyGTrihedron.styleOfNames;
3774 /* Size of names of axes */
3775 sizeOfNames = MyGTrihedron.sizeOfNames;
3776 /* Name of font for values */
3777 fontOfValues = MyGTrihedron.fontOfValues;
3778 /* Style of values */
3779 styleOfValues = MyGTrihedron.styleOfValues;
3780 /* Size of values */
3781 sizeOfValues = MyGTrihedron.sizeOfValues;
3783 return Standard_True;
3786 void Visual3d_View::GraduatedTrihedronDisplay
3787 (/* Names of axes */
3788 const TCollection_ExtendedString &xname,
3789 const TCollection_ExtendedString &yname,
3790 const TCollection_ExtendedString &zname,
3792 const Standard_Boolean xdrawname,
3793 const Standard_Boolean ydrawname,
3794 const Standard_Boolean zdrawname,
3796 const Standard_Boolean xdrawvalues,
3797 const Standard_Boolean ydrawvalues,
3798 const Standard_Boolean zdrawvalues,
3800 const Standard_Boolean drawgrid,
3802 const Standard_Boolean drawaxes,
3803 /* Number of splits along axes */
3804 const Standard_Integer nbx,
3805 const Standard_Integer nby,
3806 const Standard_Integer nbz,
3807 /* Offset for drawing values */
3808 const Standard_Integer xoffset,
3809 const Standard_Integer yoffset,
3810 const Standard_Integer zoffset,
3811 /* Offset for drawing names of axes */
3812 const Standard_Integer xaxisoffset,
3813 const Standard_Integer yaxisoffset,
3814 const Standard_Integer zaxisoffset,
3815 /* Draw tickmarks */
3816 const Standard_Boolean xdrawtickmarks,
3817 const Standard_Boolean ydrawtickmarks,
3818 const Standard_Boolean zdrawtickmarks,
3819 /* Length of tickmarks */
3820 const Standard_Integer xtickmarklength,
3821 const Standard_Integer ytickmarklength,
3822 const Standard_Integer ztickmarklength,
3824 const Quantity_Color& gridcolor,
3825 /* Colors of axis names */
3826 const Quantity_Color& xnamecolor,
3827 const Quantity_Color& ynamecolor,
3828 const Quantity_Color& znamecolor,
3829 /* Colors of axis and values */
3830 const Quantity_Color& xcolor,
3831 const Quantity_Color& ycolor,
3832 const Quantity_Color& zcolor,
3833 /* Name of font for names of axes */
3834 const TCollection_AsciiString &fontOfNames,
3835 /* Style of names of axes */
3836 const Font_FontAspect styleOfNames,
3837 /* Size of names of axes */
3838 const Standard_Integer sizeOfNames,
3839 /* Name of font for values */
3840 const TCollection_AsciiString &fontOfValues,
3841 /* Style of values */
3842 const Font_FontAspect styleOfValues,
3843 /* Size of values */
3844 const Standard_Integer sizeOfValues)
3847 MyGTrihedron.xname = xname;
3848 MyGTrihedron.yname = yname;
3849 MyGTrihedron.zname = zname;
3851 MyGTrihedron.xdrawname = xdrawname;
3852 MyGTrihedron.ydrawname = ydrawname;
3853 MyGTrihedron.zdrawname = zdrawname;
3855 MyGTrihedron.xdrawvalues = xdrawvalues;
3856 MyGTrihedron.ydrawvalues = ydrawvalues;
3857 MyGTrihedron.zdrawvalues = zdrawvalues;
3859 MyGTrihedron.drawgrid = drawgrid;
3861 MyGTrihedron.drawaxes = drawaxes;
3862 /* Number of splits along axes */
3863 MyGTrihedron.nbx = nbx;
3864 MyGTrihedron.nby = nby;
3865 MyGTrihedron.nbz = nbz;
3866 /* Offset for drawing values */
3867 MyGTrihedron.xoffset = xoffset;
3868 MyGTrihedron.yoffset = yoffset;
3869 MyGTrihedron.zoffset = zoffset;
3870 /* Offset for drawing names of axes */
3871 MyGTrihedron.xaxisoffset = xaxisoffset;
3872 MyGTrihedron.yaxisoffset = yaxisoffset;
3873 MyGTrihedron.zaxisoffset = zaxisoffset;
3874 /* Draw tickmarks */
3875 MyGTrihedron.xdrawtickmarks = xdrawtickmarks;
3876 MyGTrihedron.ydrawtickmarks = ydrawtickmarks;
3877 MyGTrihedron.zdrawtickmarks = zdrawtickmarks;
3878 /* Length of tickmarks */
3879 MyGTrihedron.xtickmarklength = xtickmarklength;
3880 MyGTrihedron.ytickmarklength = ytickmarklength;
3881 MyGTrihedron.ztickmarklength = ztickmarklength;
3883 MyGTrihedron.gridcolor = gridcolor;
3884 /* Colors of axis names */
3885 MyGTrihedron.xnamecolor = xnamecolor;
3886 MyGTrihedron.ynamecolor = ynamecolor;
3887 MyGTrihedron.znamecolor = znamecolor;
3888 /* Colors of axis and values */
3889 MyGTrihedron.xcolor = xcolor;
3890 MyGTrihedron.ycolor = ycolor;
3891 MyGTrihedron.zcolor = zcolor;
3892 /* Name of font for names of axes */
3893 MyGTrihedron.fontOfNames = fontOfNames;
3894 /* Style of names of axes */
3895 MyGTrihedron.styleOfNames = styleOfNames;
3896 /* Size of names of axes */
3897 MyGTrihedron.sizeOfNames = sizeOfNames;
3898 /* Name of font for values */
3899 MyGTrihedron.fontOfValues = fontOfValues;
3900 /* Style of values */
3901 MyGTrihedron.styleOfValues = styleOfValues;
3902 /* Size of values */
3903 MyGTrihedron.sizeOfValues = sizeOfValues;
3905 MyGTrihedron.ptrVisual3dView = this;
3906 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
3907 MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron);
3910 void Visual3d_View::GraduatedTrihedronErase()
3912 MyGTrihedron.ptrVisual3dView = NULL;
3913 MyGraphicDriver->GraduatedTrihedronErase(MyCView);
3916 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer () const {
3918 return (MyViewManager->UnderLayer ());
3922 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer () const {
3924 return (MyViewManager->OverLayer ());
3928 Standard_Integer Visual3d_View::LightLimit() const {
3930 Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit ();
3931 // printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight);
3935 Standard_Integer Visual3d_View::PlaneLimit() const {
3937 Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit ();
3938 // printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane);
3942 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
3944 return MyPtrViewManager;
3948 void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode ) {
3950 if ( ( (aMode && ComputedModeIsActive) ||
3951 (!aMode && !ComputedModeIsActive)
3952 ) || DegenerateModeIsOn ()
3955 Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure );
3956 Visual3d_TypeOfAnswer Answer;
3957 Standard_Integer StructId;
3958 Standard_Integer i = MyDisplayedStructure.Extent ();
3960 if ( !( ComputedModeIsActive = aMode ) ) {
3962 while ( S1Iterator.More () ) {
3964 Answer = AcceptDisplay ( S1Iterator.Key () );
3966 if ( Answer == Visual3d_TOA_COMPUTE ) {
3968 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
3972 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3974 MyGraphicDriver -> EraseStructure (
3976 *( Graphic3d_CStructure* )
3977 MyCOMPUTEDSequence.Value ( Index ) -> CStructure ()
3979 MyGraphicDriver -> DisplayStructure (
3981 *( Graphic3d_CStructure* )
3982 S1Iterator.Key () -> CStructure (),
3983 int ( S1Iterator.Key () -> DisplayPriority () )
3985 } // end if ( Index != 0 ) . . .
3987 } // end if ( Answer . . . )
3995 while ( S1Iterator.More () ) {
3997 Answer = AcceptDisplay ( S1Iterator.Key () );
3999 if ( Answer == Visual3d_TOA_COMPUTE ) {
4001 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
4005 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
4007 MyGraphicDriver -> EraseStructure (
4009 *( Graphic3d_CStructure* )
4010 S1Iterator.Key () -> CStructure ()
4012 MyGraphicDriver -> DisplayStructure (
4014 *( Graphic3d_CStructure* )
4015 MyCOMPUTEDSequence.Value ( Index ) -> CStructure (),
4016 int ( S1Iterator.Key () -> DisplayPriority () )
4019 Display ( S1Iterator.Key (), Aspect_TOU_WAIT );
4021 if ( S1Iterator.Key () -> IsHighlighted () ) {
4023 if ( !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted () ) {
4025 MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor (
4026 S1Iterator.Key () ->
4029 MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight (
4038 Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key ();
4040 Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this );
4042 Handle( Graphic3d_Structure ) TheStructure;
4043 TColStd_Array2OfReal ATrsf ( 0, 3, 0, 3 );
4045 AStructure -> Transform ( ATrsf );
4049 TColStd_Array2OfReal Ident ( 0, 3, 0, 3 );
4050 Standard_Integer ii, jj;
4052 for ( ii = 0; ii <= 3; ++ii )
4054 for ( jj = 0; jj <= 3; ++jj )
4056 Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 );
4058 TheStructure = MyCOMPUTEDSequence.Value ( Index );
4060 TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE );
4062 if ( AStructure->IsTransformed () )
4064 AStructure -> Compute ( this, ATrsf, TheStructure );
4068 AStructure -> Compute ( this, TheStructure );
4072 if ( AStructure -> IsTransformed () )
4074 TheStructure = AStructure -> Compute ( this, ATrsf );
4078 TheStructure = AStructure -> Compute ( this );
4082 TheStructure -> SetHLRValidation ( Standard_True );
4084 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
4086 Standard_Boolean ComputeWireframe =
4087 ( ( ViewType == Visual3d_TOV_WIREFRAME ) &&
4088 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING )
4091 Standard_Boolean ComputeShading =
4092 ( ( ViewType == Visual3d_TOV_SHADING ) &&
4093 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME )
4096 if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME );
4097 if ( ComputeShading ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING );
4099 if ( S1Iterator.Key () -> IsHighlighted () ) {
4101 TheStructure -> SetHighlightColor (
4102 S1Iterator.Key () -> HighlightColor ()
4104 TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR );
4108 Standard_Integer Result = 0;
4109 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
4110 StructId = S1Iterator.Key () -> Identification ();
4112 for ( i = 1; i <= Length && Result == 0; ++i )
4114 if ( MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId )
4120 MyCOMPUTEDSequence.ChangeValue ( Result ) = TheStructure;
4124 MyTOCOMPUTESequence.Append ( S1Iterator.Key () );
4125 MyCOMPUTEDSequence.Append ( TheStructure );
4129 MyGraphicDriver -> EraseStructure (
4131 *( Graphic3d_CStructure* )
4132 S1Iterator.Key () -> CStructure ()
4134 MyGraphicDriver -> DisplayStructure (
4136 *( Graphic3d_CStructure* )TheStructure -> CStructure (),
4137 int ( S1Iterator.Key () -> DisplayPriority () )
4147 if ( MyViewManager -> UpdateMode () == Aspect_TOU_ASAP ) Update ();
4151 } // end Visual3d_View :: SetComputedMode
4153 Standard_Boolean Visual3d_View :: ComputedMode () const {
4155 return ComputedModeIsActive;
4157 } // end Visual3d_View :: ComputedMode
4159 void Visual3d_View :: SetBackFacingModel (
4160 const Visual3d_TypeOfBackfacingModel aModel
4165 case Visual3d_TOBM_AUTOMATIC:
4166 MyCView.Backfacing = 0;
4169 case Visual3d_TOBM_FORCE:
4170 MyCView.Backfacing = 1;
4173 case Visual3d_TOBM_DISABLE:
4174 MyCView.Backfacing = -1;
4179 MyGraphicDriver -> SetBackFacingModel ( MyCView );
4181 } // end Visual3d_View :: SetBackFacingModel
4183 Visual3d_TypeOfBackfacingModel Visual3d_View :: BackFacingModel () const {
4185 switch ( MyCView.Backfacing ) {
4188 return Visual3d_TOBM_AUTOMATIC;
4191 return Visual3d_TOBM_FORCE;
4195 return Visual3d_TOBM_DISABLE;
4197 } // end Visual3d_View :: BackFacingModel
4200 void Visual3d_View::EnableDepthTest( const Standard_Boolean enable ) const
4203 MyGraphicDriver->SetDepthTestEnabled( MyCView, enable );
4207 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
4210 return MyGraphicDriver->IsDepthTestEnabled( MyCView );
4212 return Standard_True;
4216 void Visual3d_View::ReadDepths(const Standard_Integer x,
4217 const Standard_Integer y,
4218 const Standard_Integer width,
4219 const Standard_Integer height,
4220 const Standard_Address buffer) const
4222 MyGraphicDriver->ReadDepths( MyCView, x, y, width, height, buffer );
4225 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
4226 const Standard_Integer theHeight)
4228 return MyGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
4231 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
4233 MyGraphicDriver->FBORelease( MyCView, theFBOPtr );
4236 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
4237 Standard_Integer& theWidth, Standard_Integer& theHeight,
4238 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
4240 MyGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
4241 theWidth, theHeight,
4242 theWidthMax, theHeightMax );
4245 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
4246 const Standard_Integer theWidth, const Standard_Integer theHeight)
4248 MyGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
4249 theWidth, theHeight );
4252 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
4253 const Graphic3d_BufferType& theBufferType)
4255 return MyGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
4258 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
4261 MyGraphicDriver->SetGLLightEnabled( MyCView, enable );
4266 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
4269 return MyGraphicDriver->IsGLLightEnabled( MyCView );
4271 return Standard_True;
4275 Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
4276 const Graphic3d_ExportFormat theFormat,
4277 const Graphic3d_SortType theSortType,
4278 const Standard_Real thePrecision,
4279 const Standard_Address theProgressBarFunc,
4280 const Standard_Address theProgressObject) const
4282 Handle(Visual3d_Layer) anUnderLayer = MyViewManager->UnderLayer();
4283 Handle(Visual3d_Layer) anOverLayer = MyViewManager->OverLayer();
4285 Aspect_CLayer2d anOverCLayer;
4286 Aspect_CLayer2d anUnderCLayer;
4287 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
4289 if (!anOverLayer.IsNull())
4290 anOverCLayer = anOverLayer->CLayer();
4291 if (!anUnderLayer.IsNull())
4292 anUnderCLayer = anUnderLayer->CLayer();
4294 Standard_Integer aWidth, aHeight;
4295 Window()->Size (aWidth, aHeight);
4297 return MyGraphicDriver->Export (theFileName, theFormat, theSortType,
4298 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
4299 thePrecision, theProgressBarFunc, theProgressObject);
4302 //=======================================================================
4303 //function : AddZLayer
4305 //=======================================================================
4307 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
4309 MyGraphicDriver->AddZLayer (MyCView, theLayerId);
4312 //=======================================================================
4313 //function : RemoveZLayer
4315 //=======================================================================
4317 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
4319 MyGraphicDriver->RemoveZLayer (MyCView, theLayerId);
4322 //=======================================================================
4323 //function : ChangeZLayer
4325 //=======================================================================
4327 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
4328 const Standard_Integer theLayerId)
4330 MyGraphicDriver->ChangeZLayer (
4331 (*(Graphic3d_CStructure*)theStructure->CStructure()), MyCView, theLayerId);