1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 /***********************************************************************
23 Classe Visual3d_View.cxx :
26 Declaration of variables specific to views.
28 A view is defined by :
34 HISTORIQUE DES MODIFICATIONS :
35 --------------------------------
36 Mars 1992 : NW,JPB,CAL ; Creation.
37 04-02-97 : FMN ; Suppression de PSOutput, XWDOutput ...
38 22-04-97 : CAL ; Ajout du Plot.
39 03-06-97 : FMN ; Correction calcul SetRatio
40 06-05-97 : CAL ; Ajout du Clear sur les TOS_COMPUTED.
41 28-07-97 : PCT ; Ajout lumiere frontale headlight.
42 19-09-97 : CAL ; Remplacement de Window->Position par Window->Size;
43 17-10-97 : CAL ; Le Projects nouveau est arrive. (NewProjects)
44 24-10-97 : CAL ; Retrait de DownCast.
45 24-10-97 : CAL ; Retrait des DataStructure (Vieille maquette inutilisee).
46 17-11-97 : FMN ; Ajout DoResize dans Resized()
47 20-11-97 : CAL ; Disparition de la dependance avec math
48 ??-11-97 : CAL ; Retrait de la dependance avec math. Calcul developpe.
49 ??-11-97 : CAL ; Ajout de NumberOfDisplayedStructures
50 07-08-97 : PCT ; ajout support texture mapping
51 15-01-98 : FMN ; FRA60019 calcul Ratio pour MyViewMappingReset
52 15-01-98 : CAL ; Ajout de la transformation d'une TOS_COMPUTED
53 26-01-98 : CAL ; Ajout de la methode HaveTheSameOwner
54 06-02-98 : FMN ; CTS19079: TOP TEN: Probleme de highlight dans EDesigner.
55 05-03-98 : CAL ; GraphicTransform que si Trsf non invalidante
56 27-03-98 : CAL ; Ajout de TheStructure = devant Compute (...) !!!!
57 16-04-98 : CAL ; Remise a ID de la Trsf sur la COMPUTED
58 20-05-98 : CAL ; Perfs. Connection entre structures COMPUTED.
59 24-06-98 : CAL ; PRO14526 SetTransparency sur une vue non active.
60 17-07-98 : CAL ; PRO14872 test sur aTrsf dans ::SetTransform.
61 16-09-98 : BGN ; Points d'entree du Triedre (S3819, Phase 1)
62 22-09-98 : BGN ; S3989 (anciennement S3819)
63 TypeOfTriedron* from Aspect (pas Visual3d)
64 06-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
65 16-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
66 02-11-98 : CAL ; Retrait de OSD::SetSignal.
67 18-11-98 : FMN ; Correction sur la gestion de la perspective
68 02-12-98 : CAL ; S4062. Ajout des layers.
69 13-09-99 : GG ; GER61454 Adds LightLimit() and PlaneLimit() methods
70 10-11-99 : GG ; PRO19603 Add Redraw( area ) method
71 14-01-00 : GG ; IMP140100 Add ViewManager( ) method
72 22-10-01 : SAV ; Added EnableDepthTest() method.
73 30-04-02 : JMB ; MyDisplayStructure : use a Map instead of a Set (very bad performance
74 in data access when a lot of objects are used)
75 Will improve performance of selection mechanisms
77 ************************************************************************/
79 #define BUC60572 //GG_03-08-99 Add protection on Zclipping & Zcueing planes
82 #define GER61454 //GG 14-09-99 Activates model clipping planes
84 #define RIC120302 //GG Add a NEW SetWindow method which enable
85 // to connect a graphic widget and context to OGL.
87 //BUC61044 25/10/01 SAV ; added functionality to control gl depth testing from higher API
88 //BUC61045 25/10/01 SAV ; added functionality to control gl lighting from higher API
90 //OCC1188 SAV Added methods to set background image
92 /*----------------------------------------------------------------------*/
100 #define NO_TRACE_ACCEPT
101 #define NO_TRACE_CLEAR
102 #define NO_TRACE_CONNECT
103 #define NO_TRACE_HIGH
104 #define NO_TRACE_COMP
105 #define NO_TRACE_TRSF
106 #define NO_TRACE_DISPLAY
107 #define NO_TRACE_ISCOMP
108 #define NO_TRACE_LENGTH
109 #define NO_TRACE_LAYER
111 /*----------------------------------------------------------------------*/
121 #include <Visual3d_View.ixx>
122 #include <Visual3d_View.pxx>
123 #include <Visual3d_DepthCueingDefinitionError.hxx>
124 #include <Visual3d_ZClippingDefinitionError.hxx>
127 #include <math_Vector.hxx>
128 #endif /* OLD_METHOD */
132 #include <Graphic3d_Structure.hxx>
133 #include <Graphic3d_MapOfStructure.hxx>
134 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
135 #include <Graphic3d_DataStructureManager.hxx>
137 #include <Graphic3d_GraphicDriver.hxx>
139 #include <Graphic3d_Vector.hxx>
140 #include <Graphic3d_Vertex.hxx>
142 #include <Visual3d_Light.hxx>
143 #include <Visual3d_SetOfLight.hxx>
144 #include <Visual3d_HSetOfLight.hxx>
145 #include <Visual3d_SetIteratorOfSetOfLight.hxx>
147 #include <Visual3d_SetIteratorOfSetOfView.hxx>
149 #include <Graphic3d_TextureEnv.hxx>
151 #include <TColStd_HArray2OfReal.hxx>
153 #if (defined(_WIN32) || defined(__WIN32__))
154 #include <WNT_Window.hxx>
155 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
156 #include <Cocoa_Window.hxx>
158 #include <Xw_Window.hxx>
165 //-Global data definitions
169 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager):
172 MyViewMappingReset (),
173 MyViewOrientation (),
174 MyViewOrientationReset (),
175 MyTransformation (0, 3, 0, 3),
176 MyMatrixOfMapping (0, 3, 0, 3),
177 MyMatrixOfOrientation (0, 3, 0, 3),
178 MyTOCOMPUTESequence (),
179 MyCOMPUTEDSequence (),
180 MyDisplayedStructure ()
182 Standard_Integer i, j;
184 MyPtrViewManager = AManager.operator->();
185 MyCView.ViewId = int (AManager->Identification (this));
187 MyCView.IsDeleted = 0;
190 MyCView.DefWindow.IsDefined = 0;
192 MyCView.Context.NbActiveLight = 0;
196 if (i == j) MyTransformation (i, j) = 1.0;
197 else MyTransformation (i, j) = 0.0;
199 Standard_Real X, Y, Z;
201 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
202 MyCView.Orientation.ViewReferencePoint.x = float (X);
203 MyCView.Orientation.ViewReferencePoint.y = float (Y);
204 MyCView.Orientation.ViewReferencePoint.z = float (Z);
205 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
206 MyCView.Orientation.ViewReferencePlane.x = float (X);
207 MyCView.Orientation.ViewReferencePlane.y = float (Y);
208 MyCView.Orientation.ViewReferencePlane.z = float (Z);
209 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
210 MyCView.Orientation.ViewReferenceUp.x = float (X);
211 MyCView.Orientation.ViewReferenceUp.y = float (Y);
212 MyCView.Orientation.ViewReferenceUp.z = float (Z);
214 Standard_Real Sx, Sy, Sz;
216 MyViewOrientation.AxialScale(Sx, Sy, Sz);
217 MyCView.Orientation.ViewScaleX = float (Sx);
218 MyCView.Orientation.ViewScaleY = float (Sy);
219 MyCView.Orientation.ViewScaleZ = float (Sz);
221 // NKV : 23/07/07 - Define custom MODELVIEW matrix
222 MyCView.Orientation.IsCustomMatrix = 0;
223 memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
224 MyCView.Orientation.ModelViewMatrix[0][0] =
225 MyCView.Orientation.ModelViewMatrix[1][1] =
226 MyCView.Orientation.ModelViewMatrix[2][2] =
227 MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
230 Standard_Real um, vm, uM, vM;
232 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
233 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
234 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
235 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
236 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
237 MyCView.Mapping.ViewPlaneDistance =
238 float (MyViewMapping.ViewPlaneDistance ());
239 MyCView.Mapping.BackPlaneDistance =
240 float (MyViewMapping.BackPlaneDistance ());
241 MyCView.Mapping.FrontPlaneDistance =
242 float (MyViewMapping.FrontPlaneDistance ());
243 MyViewMapping.WindowLimit (um, vm, uM, vM);
244 MyCView.Mapping.WindowLimit.um = float (um);
245 MyCView.Mapping.WindowLimit.vm = float (vm);
246 MyCView.Mapping.WindowLimit.uM = float (uM);
247 MyCView.Mapping.WindowLimit.vM = float (vM);
249 // NKV : 23/07/07 - Define custom MODELVIEW matrix
250 MyCView.Mapping.IsCustomMatrix = 0;
251 memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
252 MyCView.Mapping.ProjectionMatrix[0][0] =
253 MyCView.Mapping.ProjectionMatrix[1][1] =
254 MyCView.Mapping.ProjectionMatrix[2][2] =
255 MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
258 MyCView.Context.ZBufferActivity = -1;
260 MyMatOfMapIsEvaluated = Standard_False;
261 MyMatOfOriIsEvaluated = Standard_False;
263 IsInitialized = Standard_False;
264 ComputedModeIsActive = Standard_False;
265 MyCView.Backfacing = 0;
267 MyCView.ptrUnderLayer = 0;
268 MyCView.ptrOverLayer = 0;
269 MyCView.GContext = 0;
270 MyCView.GDisplayCB = 0;
271 MyCView.GClientData = 0;
273 MyGraphicDriver = MyViewManager->GraphicDriver();
277 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager, const Visual3d_ViewOrientation& VO, const Visual3d_ViewMapping& VM, const Visual3d_ContextView& CTX):
278 MyTransformation (0, 3, 0, 3),
279 MyMatrixOfMapping (0, 3, 0, 3),
280 MyMatrixOfOrientation (0, 3, 0, 3),
281 MyTOCOMPUTESequence (),
282 MyCOMPUTEDSequence (),
283 MyDisplayedStructure ()
285 Standard_Integer i, j;
287 MyPtrViewManager = AManager.operator->();
288 MyViewOrientation = VO;
291 MyViewOrientationReset = VO;
292 MyViewMappingReset = VM;
294 MyCView.ViewId = int (AManager->Identification (this));
296 MyCView.IsDeleted = 0;
299 MyCView.DefWindow.IsDefined = 0;
301 MyCView.Context.NbActiveLight = 0;
305 if (i == j) MyTransformation (i, j) = 1.0;
306 else MyTransformation (i, j) = 0.0;
308 Standard_Real X, Y, Z;
310 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
311 MyCView.Orientation.ViewReferencePoint.x = float (X);
312 MyCView.Orientation.ViewReferencePoint.y = float (Y);
313 MyCView.Orientation.ViewReferencePoint.z = float (Z);
314 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
315 MyCView.Orientation.ViewReferencePlane.x = float (X);
316 MyCView.Orientation.ViewReferencePlane.y = float (Y);
317 MyCView.Orientation.ViewReferencePlane.z = float (Z);
318 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
319 MyCView.Orientation.ViewReferenceUp.x = float (X);
320 MyCView.Orientation.ViewReferenceUp.y = float (Y);
321 MyCView.Orientation.ViewReferenceUp.z = float (Z);
323 Standard_Real Sx, Sy, Sz;
325 MyViewOrientation.AxialScale(Sx, Sy, Sz);
326 MyCView.Orientation.ViewScaleX = float (Sx);
327 MyCView.Orientation.ViewScaleY = float (Sy);
328 MyCView.Orientation.ViewScaleZ = float (Sz);
330 // NKV : 23/07/07 - Define custom MODELVIEW matrix
331 if (MyViewOrientation.IsCustomMatrix()) {
332 MyCView.Orientation.IsCustomMatrix = 1;
333 for ( i = 0; i < 4; i++)
334 for ( j = 0; j < 4; j++)
335 MyCView.Orientation.ModelViewMatrix[i][j] =
336 (Standard_ShortReal)MyViewOrientation.MyModelViewMatrix->Value(i,j);
339 MyCView.Orientation.IsCustomMatrix = 0;
340 memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
341 MyCView.Orientation.ModelViewMatrix[0][0] =
342 MyCView.Orientation.ModelViewMatrix[1][1] =
343 MyCView.Orientation.ModelViewMatrix[2][2] =
344 MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
348 Standard_Real um, vm, uM, vM;
350 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
351 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
352 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
353 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
354 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
355 MyCView.Mapping.ViewPlaneDistance =
356 float (MyViewMapping.ViewPlaneDistance ());
357 MyCView.Mapping.BackPlaneDistance =
358 float (MyViewMapping.BackPlaneDistance ());
359 MyCView.Mapping.FrontPlaneDistance =
360 float (MyViewMapping.FrontPlaneDistance ());
361 MyViewMapping.WindowLimit (um, vm, uM, vM);
362 MyCView.Mapping.WindowLimit.um = float (um);
363 MyCView.Mapping.WindowLimit.vm = float (vm);
364 MyCView.Mapping.WindowLimit.uM = float (uM);
365 MyCView.Mapping.WindowLimit.vM = float (vM);
367 // NKV : 23/07/07 - Define custom MODELVIEW matrix
368 if (MyViewMapping.IsCustomMatrix()) {
369 MyCView.Mapping.IsCustomMatrix = 1;
370 for ( i = 0; i < 4; i++)
371 for ( j = 0; j < 4; j++)
372 MyCView.Mapping.ProjectionMatrix[i][j] =
373 (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j);
376 MyCView.Mapping.IsCustomMatrix = 0;
377 memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
378 MyCView.Mapping.ProjectionMatrix[0][0] =
379 MyCView.Mapping.ProjectionMatrix[1][1] =
380 MyCView.Mapping.ProjectionMatrix[2][2] =
381 MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
385 MyCView.Context.ZBufferActivity = -1;
387 MyMatOfMapIsEvaluated = Standard_False;
388 MyMatOfOriIsEvaluated = Standard_False;
390 IsInitialized = Standard_False;
391 ComputedModeIsActive = Standard_False;
393 MyCView.ptrUnderLayer = 0;
394 MyCView.ptrOverLayer = 0;
395 MyCView.GContext = 0;
396 MyCView.GDisplayCB = 0;
397 MyCView.GClientData = 0;
399 MyGraphicDriver = MyViewManager->GraphicDriver();
407 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow,
408 const Aspect_RenderingContext AContext,
409 const Aspect_GraphicCallbackProc& ADisplayCB,
410 const Standard_Address AClientData)
412 if (IsDeleted ()) return;
415 Visual3d_ViewDefinitionError::Raise ("Window already defined");
417 MyCView.GContext = AContext;
418 MyCView.GDisplayCB = ADisplayCB;
419 MyCView.GClientData = AClientData;
424 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
427 if (IsDeleted ()) return;
430 Visual3d_ViewDefinitionError::Raise ("Window already defined");
432 MyWindow = theWindow;
433 MyCView.WsId = MyCView.ViewId;
434 MyCView.DefWindow.IsDefined = 1;
436 #if (defined(_WIN32) || defined(__WIN32__))
437 const Handle(WNT_Window) aWin = Handle(WNT_Window)::DownCast (theWindow);
438 MyCView.DefWindow.XWindow = (HWND )(aWin->HWindow());
439 MyCView.DefWindow.XParentWindow = (HWND )(aWin->HParentWindow());
440 WNT_WindowData* aWinData = (WNT_WindowData* )GetWindowLongPtr ((HWND )(aWin->HWindow()), GWLP_USERDATA);
441 aWinData->WNT_WDriver_Ptr = (void* )this;
442 aWinData->WNT_VMgr = (void* )MyPtrViewManager;
443 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
444 const Handle(Cocoa_Window) aWin = Handle(Cocoa_Window)::DownCast (theWindow);
445 MyCView.DefWindow.XWindow = (Aspect_Drawable )aWin->HView();
446 MyCView.DefWindow.XParentWindow = NULL;
447 //MyCView.DefWindow.XParentWindow = aWin->HParentWindow();
449 const Handle(Xw_Window) aWin = Handle(Xw_Window)::DownCast (theWindow);
450 MyCView.DefWindow.XWindow = aWin->XWindow();
451 //MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
454 Standard_Integer Width, Height;
455 theWindow->Size (Width, Height);
457 MyCView.DefWindow.dx = float( Width );
458 MyCView.DefWindow.dy = float( Height );
460 Standard_Real R, G, B;
461 MyBackground = MyWindow->Background ();
462 (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
463 MyCView.DefWindow.Background.r = float (R);
464 MyCView.DefWindow.Background.g = float (G);
465 MyCView.DefWindow.Background.b = float (B);
468 if (! MyGraphicDriver->View (MyCView))
469 Visual3d_ViewDefinitionError::Raise ("Association failed");
471 MyGradientBackground = MyWindow->GradientBackground();
472 SetGradientBackground(MyGradientBackground,1);
474 Standard_Boolean AWait = Standard_False; // => immediate update
475 MyGraphicDriver->SetVisualisation (MyCView);
476 MyGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn ());
477 MyGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn ());
478 MyGraphicDriver->ClipLimit (MyCView, AWait);
479 MyGraphicDriver->Environment(MyCView);
481 // Make view manager z layer list consistent with the view's list.
482 MyViewManager->InstallZLayers (this);
484 // Update planses of model clipping
487 // Update light sources
491 * Association view-window does not cause the display
492 * of structures that can be displayed in the new view.
493 * In fact, association view-window is done, but the
494 * display is produced only if the view is activated (Activate).
501 Handle(Aspect_Window) Visual3d_View::Window () const {
504 Visual3d_ViewDefinitionError::Raise ("Window not defined");
510 Standard_Boolean Visual3d_View::IsDefined () const {
512 if (MyCView.DefWindow.IsDefined)
513 return (Standard_True);
515 return (Standard_False);
519 Standard_Boolean Visual3d_View::IsDeleted () const {
521 if (MyCView.IsDeleted)
522 return (Standard_True);
524 return (Standard_False);
528 void Visual3d_View::Destroy () {
531 cout << "Visual3d_View::Destroy (" << Identification () << ")\n";
534 // Since MyPtrViewManager can be already distroyed,
535 // avoid attempts to access it in SetBackground()
536 MyPtrViewManager = 0;
541 void Visual3d_View::Remove () {
544 cout << "Visual3d_View::Remove (" << Identification () << ")" << endl;
547 if (IsDeleted ()) return;
548 if (! IsDefined ()) return;
550 MyTOCOMPUTESequence.Clear ();
551 MyCOMPUTEDSequence.Clear ();
552 MyDisplayedStructure.Clear ();
554 Quantity_Color BlackColor (0.0, 0.0, 0.0, Quantity_TOC_RGB);
555 Aspect_Background BlackBackground (BlackColor);
556 SetBackground (BlackBackground);
558 Aspect_GradientBackground BlackGradBackground;
559 SetGradientBackground (BlackGradBackground,0);
561 if (MyPtrViewManager)
562 MyPtrViewManager->UnIdentification( MyCView.ViewId );
564 MyGraphicDriver->RemoveView (MyCView);
567 MyCView.IsDeleted = 1;
568 MyCView.DefWindow.IsDefined = 0;
570 MyMatOfMapIsEvaluated = Standard_False;
571 MyMatOfOriIsEvaluated = Standard_False;
573 IsInitialized = Standard_False;
579 void Visual3d_View::Resized () {
581 if (IsDeleted ()) return;
584 Visual3d_ViewDefinitionError::Raise ("Window not defined");
585 MyWindow->DoResize() ;
590 void Visual3d_View::SetRatio () {
592 if (IsDeleted ()) return;
594 Aspect_TypeOfUpdate UpdateMode = MyViewManager->UpdateMode ();
595 MyViewManager->SetUpdateMode (Aspect_TOU_WAIT);
597 Standard_Real Umin, Vmin, Umax, Vmax;
598 Standard_Integer Dxw, Dyw;
599 Standard_Real Dxv, Dyv;
600 Standard_Real Xc, Yc;
604 MyWindow->Size (Dxw, Dyw);
605 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
606 Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
607 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
608 if( Dxw > 0 && Dyw > 0 ) Rap = (Standard_Real)Dyw/(Standard_Real)Dxw ;
638 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
639 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
641 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
643 // Update before SetViewMapping.
645 MyCView.DefWindow.dx = float( Dxw );
646 MyCView.DefWindow.dy = float( Dyw );
648 SetViewMapping (MyViewMapping);
649 // SetViewMappingDefault ();
650 // FMN+ Update Ratio for MyViewMappingReset
652 MyViewMappingReset.WindowLimit(Umin,Vmin,Umax,Vmax) ;
653 Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
654 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
683 Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ;
684 Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ;
686 MyViewMappingReset.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
688 // FMN- Update Ratio for MyViewMappingReset
690 MyGraphicDriver->RatioWindow (MyCView);
693 // Force recalculation of 2 matrices.
695 // The current view can help to reconstruct a copied view
696 // that is itself. Owing to SetWindow and SetRatio the
697 // recalculation of matrices of this new view is imposed.
698 MyMatOfMapIsEvaluated = Standard_False;
699 MyMatOfOriIsEvaluated = Standard_False;
701 MyViewManager->SetUpdateMode (UpdateMode);
702 if (UpdateMode == Aspect_TOU_ASAP) Update ();
706 void Visual3d_View::UpdateLights()
714 if (MyContext.Model() == Visual3d_TOM_NONE)
716 // activate only a white ambient light
717 Graphic3d_CLight aCLight;
718 aCLight.Type = Visual3d_TOLS_AMBIENT;
719 aCLight.IsHeadlight = Standard_False;
720 aCLight.Color.r() = aCLight.Color.g() = aCLight.Color.b() = 1.0f;
722 MyCView.Context.NbActiveLight = 1;
723 MyCView.Context.ActiveLight = &aCLight;
724 MyGraphicDriver->SetLight (MyCView);
725 MyCView.Context.ActiveLight = NULL;
729 MyCView.Context.NbActiveLight = Min (MyContext.NumberOfActivatedLights(),
730 MyGraphicDriver->InquireLightLimit());
731 if (MyCView.Context.NbActiveLight < 1)
736 // parcing of light sources
737 MyCView.Context.ActiveLight = new Graphic3d_CLight[MyCView.Context.NbActiveLight];
738 for (Standard_Integer aLightIter = 0; aLightIter < MyCView.Context.NbActiveLight; ++aLightIter)
740 MyCView.Context.ActiveLight[aLightIter] = MyContext.ActivatedLight (aLightIter + 1)->CLight();
742 MyGraphicDriver->SetLight (MyCView);
743 delete[] MyCView.Context.ActiveLight;
744 MyCView.Context.ActiveLight = NULL;
747 void Visual3d_View::UpdatePlanes()
749 MyCView.Context.ClipPlanes = MyContext.GetClipPlanes();
751 if (IsDeleted() || !IsDefined())
754 MyGraphicDriver->SetClipPlanes (MyCView);
757 void Visual3d_View::SetBackground (const Aspect_Background& ABack) {
759 if (IsDeleted ()) return;
762 Visual3d_ViewDefinitionError::Raise ("Window not defined");
764 // At this level, only GL can update the background.
765 // It is not necessary to call MyWindow->SetBackground (ABack); as
766 // this method starts update of window background by X
767 // (if the windowing is X)
769 Standard_Real R, G, B;
770 MyBackground = ABack;
771 (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
772 MyCView.DefWindow.Background.r = float (R);
773 MyCView.DefWindow.Background.g = float (G);
774 MyCView.DefWindow.Background.b = float (B);
776 MyGraphicDriver->Background (MyCView);
778 if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
783 void Visual3d_View::SetGradientBackground(const Aspect_GradientBackground& ABack, const Standard_Boolean update)
786 if (IsDeleted ()) return;
789 Visual3d_ViewDefinitionError::Raise ("Window not defined");
791 MyGradientBackground = ABack;
792 Quantity_Color aCol1,aCol2;
793 MyGradientBackground.Colors(aCol1,aCol2);
794 MyGraphicDriver->GradientBackground(MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
798 else if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
802 void Visual3d_View::SetBackgroundImage( const Standard_CString FileName,
803 const Aspect_FillMethod FillStyle,
804 const Standard_Boolean update )
809 Visual3d_ViewDefinitionError::Raise ("Window not defined");
811 MyGraphicDriver->BackgroundImage( FileName, MyCView, FillStyle );
815 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
819 void Visual3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
820 const Standard_Boolean update )
825 Visual3d_ViewDefinitionError::Raise ("Window not defined");
827 MyGraphicDriver->SetBgImageStyle( MyCView, FillStyle );
831 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
835 Aspect_Background Visual3d_View::Background () const {
837 return (MyBackground);
841 void Visual3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
842 const Standard_Boolean update )
847 Visual3d_ViewDefinitionError::Raise ("Window not defined");
849 MyGraphicDriver->SetBgGradientStyle( MyCView, FillStyle );
853 else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
858 Aspect_GradientBackground Visual3d_View::GradientBackground () const {
860 return MyGradientBackground;
864 void Visual3d_View::SetTransform (const TColStd_Array2OfReal& AMatrix) {
866 if (IsDeleted ()) return;
868 Standard_Integer lr, ur, lc, uc;
869 Standard_Integer i, j;
871 // Assign the new transformation in an array [0..3][0..3]
872 // Avoid problems if the has defined a matrice [1..4][1..4]
873 // ou [3..6][-1..2] !!
874 lr = AMatrix.LowerRow ();
875 ur = AMatrix.UpperRow ();
876 lc = AMatrix.LowerCol ();
877 uc = AMatrix.UpperCol ();
879 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
880 Visual3d_TransformError::Raise ("Transform : not a 4x4 matrix");
884 MyTransformation (i, j) = AMatrix (lr + i, lc + j);
886 Graphic3d_Vector VPN;
887 Graphic3d_Vertex VRP;
888 Graphic3d_Vector VUP;
889 Standard_Real Sx, Sy, Sz;
891 Visual3d_ViewOrientation NewViewOrientation;
893 VPN = MyViewOrientation.ViewReferencePlane ();
894 VRP = MyViewOrientation.ViewReferencePoint ();
895 VUP = MyViewOrientation.ViewReferenceUp ();
896 MyViewOrientation.AxialScale(Sx, Sy, Sz);
898 NewViewOrientation.SetViewReferencePlane
899 (Graphic3d_Structure::Transforms (Transform (), VPN));
901 NewViewOrientation.SetViewReferencePoint
902 (Graphic3d_Structure::Transforms (Transform (), VRP));
904 NewViewOrientation.SetViewReferenceUp
905 (Graphic3d_Structure::Transforms (Transform (), VUP));
906 NewViewOrientation.SetAxialScale(Sx, Sy, Sz);
908 SetViewOrientation (NewViewOrientation);
910 MyMatOfOriIsEvaluated = Standard_False;
914 const TColStd_Array2OfReal& Visual3d_View::Transform () const {
916 return (MyTransformation);
920 void Visual3d_View::SetViewOrientation (const Visual3d_ViewOrientation& VO) {
922 if (IsDeleted ()) return;
924 MyViewOrientation = VO;
926 Standard_Real X, Y, Z;
927 // Tests on modification of parameters.
928 Standard_Boolean VUPIsModified = Standard_False;
929 Standard_Boolean VRPIsModified = Standard_False;
930 Standard_Boolean VRUIsModified = Standard_False;
931 Standard_Boolean ScaleIsModified = Standard_False;
932 Standard_Boolean CustomIsModified = Standard_False;
934 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
936 MyCView.Orientation.ViewReferencePoint.x != float (X)
937 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
938 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
939 MyCView.Orientation.ViewReferencePoint.x = float (X);
940 MyCView.Orientation.ViewReferencePoint.y = float (Y);
941 MyCView.Orientation.ViewReferencePoint.z = float (Z);
943 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
945 MyCView.Orientation.ViewReferencePlane.x != float (X)
946 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
947 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
948 MyCView.Orientation.ViewReferencePlane.x = float (X);
949 MyCView.Orientation.ViewReferencePlane.y = float (Y);
950 MyCView.Orientation.ViewReferencePlane.z = float (Z);
952 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
954 MyCView.Orientation.ViewReferenceUp.x != float (X)
955 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
956 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
957 MyCView.Orientation.ViewReferenceUp.x = float (X);
958 MyCView.Orientation.ViewReferenceUp.y = float (Y);
959 MyCView.Orientation.ViewReferenceUp.z = float (Z);
961 MyViewOrientation.AxialScale(X, Y, Z);
963 MyCView.Orientation.ViewScaleX != float (X)
964 || MyCView.Orientation.ViewScaleY != float (Y)
965 || MyCView.Orientation.ViewScaleZ != float (Z);
966 MyCView.Orientation.ViewScaleX = float (X);
967 MyCView.Orientation.ViewScaleY = float (Y);
968 MyCView.Orientation.ViewScaleZ = float (Z);
971 (MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix());
972 MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
973 if ( MyViewOrientation.IsCustomMatrix() ) {
974 Standard_Integer i, j;
975 for (i = 0; i < 4; i++)
976 for (j = 0; j < 4; j++) {
977 if (!CustomIsModified) CustomIsModified =
978 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
983 cout << "Visual3d_View::SetViewOrientation\n";
984 if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified)
985 cout << "VUPIsModified : " << VUPIsModified
986 << ", VRPIsModified : " << VRPIsModified
987 << ", VRUIsModified : " << VRUIsModified
988 << ", CustomIsModified : " << CustomIsModified
989 << ", ScaleIsModified : " << ScaleIsModified << "\n" << flush;
991 cout << "no modification\n" << flush;
994 // restart if one of parameters is modified
995 if (!IsInitialized || VUPIsModified || VRPIsModified
996 || VRUIsModified || ScaleIsModified || CustomIsModified) {
998 MyMatOfOriIsEvaluated = !VUPIsModified && !VRPIsModified
999 && !VRUIsModified && !ScaleIsModified;
1001 if (! IsDefined ()) return;
1003 Standard_Boolean AWait = Standard_False; // => immediate update
1004 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1005 IsInitialized = Standard_True;
1008 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1013 Visual3d_ViewOrientation Visual3d_View::ViewOrientation () const {
1015 return (MyViewOrientation);
1019 Visual3d_ViewOrientation Visual3d_View::ViewOrientationDefault () const {
1021 return (MyViewOrientationReset);
1025 void Visual3d_View::SetViewOrientationDefault () {
1027 MyViewOrientationReset.Assign (MyViewOrientation);
1031 void Visual3d_View::ViewOrientationReset () {
1033 if (IsDeleted ()) return;
1035 MyViewOrientation = MyViewOrientationReset;
1037 Standard_Real X, Y, Z;
1039 // Tests on modification of parameters.
1040 Standard_Boolean VUPIsModified = Standard_False;
1041 Standard_Boolean VRPIsModified = Standard_False;
1042 Standard_Boolean VRUIsModified = Standard_False;
1043 Standard_Boolean ScaleIsModified = Standard_False;
1044 Standard_Boolean CustomIsModified = Standard_False;
1046 (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
1048 MyCView.Orientation.ViewReferencePoint.x != float (X)
1049 || MyCView.Orientation.ViewReferencePoint.y != float (Y)
1050 || MyCView.Orientation.ViewReferencePoint.z != float (Z);
1051 MyCView.Orientation.ViewReferencePoint.x = float (X);
1052 MyCView.Orientation.ViewReferencePoint.y = float (Y);
1053 MyCView.Orientation.ViewReferencePoint.z = float (Z);
1055 (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
1057 MyCView.Orientation.ViewReferencePlane.x != float (X)
1058 || MyCView.Orientation.ViewReferencePlane.y != float (Y)
1059 || MyCView.Orientation.ViewReferencePlane.z != float (Z);
1060 MyCView.Orientation.ViewReferencePlane.x = float (X);
1061 MyCView.Orientation.ViewReferencePlane.y = float (Y);
1062 MyCView.Orientation.ViewReferencePlane.z = float (Z);
1064 (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
1066 MyCView.Orientation.ViewReferenceUp.x != float (X)
1067 || MyCView.Orientation.ViewReferenceUp.y != float (Y)
1068 || MyCView.Orientation.ViewReferenceUp.z != float (Z);
1069 MyCView.Orientation.ViewReferenceUp.x = float (X);
1070 MyCView.Orientation.ViewReferenceUp.y = float (Y);
1071 MyCView.Orientation.ViewReferenceUp.z = float (Z);
1073 MyViewOrientation.AxialScale(X, Y, Z);
1075 MyCView.Orientation.ViewScaleX != float (X)
1076 || MyCView.Orientation.ViewScaleY != float (Y)
1077 || MyCView.Orientation.ViewScaleZ != float (Z);
1078 MyCView.Orientation.ViewScaleX = float (X);
1079 MyCView.Orientation.ViewScaleY = float (Y);
1080 MyCView.Orientation.ViewScaleZ = float (Z);
1083 MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix();
1084 MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
1085 if ( MyViewOrientation.IsCustomMatrix() ) {
1086 Standard_Integer i, j;
1087 for (i = 0; i < 4; i++)
1088 for (j = 0; j < 4; j++) {
1089 if (!CustomIsModified) CustomIsModified =
1090 MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
1096 cout << "Visual3d_View::ViewOrientationReset\n";
1097 if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified)
1098 cout << "VUPIsModified : " << VUPIsModified
1099 << ", VRPIsModified : " << VRPIsModified
1100 << ", VRUIsModified : " << VRUIsModified
1101 << ", CustomIsModified : " << CustomIsModified
1102 << ", ScaleIsModified : " << ScaleIsModified << "\n" << flush;
1104 cout << "no modification\n" << flush;
1107 // Restart if one of parameters is modified
1108 if (!IsInitialized || VUPIsModified || VRPIsModified
1109 || VRUIsModified || ScaleIsModified || CustomIsModified) {
1111 MyMatOfOriIsEvaluated = !VUPIsModified && !VRPIsModified
1112 && !VRUIsModified && !ScaleIsModified;
1114 if (! IsDefined ()) return;
1116 Standard_Boolean AWait = Standard_False; // => immediate update
1117 MyGraphicDriver->ViewOrientation (MyCView, AWait);
1118 IsInitialized = Standard_True;
1121 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1125 void Visual3d_View::SetViewMapping (const Visual3d_ViewMapping& VM) {
1127 if (IsDeleted ()) return;
1129 Visual3d_TypeOfProjection OldType = MyViewMapping.Projection ();
1130 Visual3d_TypeOfProjection NewType = VM.Projection ();
1134 Standard_Real X, Y, Z;
1135 Standard_Real um, vm, uM, vM;
1137 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
1138 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1139 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
1140 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
1141 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
1142 MyCView.Mapping.ViewPlaneDistance =
1143 float (MyViewMapping.ViewPlaneDistance ());
1144 MyCView.Mapping.BackPlaneDistance =
1145 float (MyViewMapping.BackPlaneDistance ());
1146 MyCView.Mapping.FrontPlaneDistance =
1147 float (MyViewMapping.FrontPlaneDistance ());
1148 MyViewMapping.WindowLimit (um, vm, uM, vM);
1149 MyCView.Mapping.WindowLimit.um = float (um);
1150 MyCView.Mapping.WindowLimit.vm = float (vm);
1151 MyCView.Mapping.WindowLimit.uM = float (uM);
1152 MyCView.Mapping.WindowLimit.vM = float (vM);
1154 MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1155 if (MyViewMapping.IsCustomMatrix()) {
1156 Standard_Integer i, j;
1157 for (i = 0; i < 4; i++)
1158 for (j = 0; j < 4; j++)
1159 MyCView.Mapping.ProjectionMatrix[i][j] =
1160 (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j);
1163 MyMatOfMapIsEvaluated = Standard_False;
1165 if (! IsDefined ()) return;
1167 Standard_Boolean AWait = Standard_False; // => immediate update
1168 MyGraphicDriver->ViewMapping (MyCView, AWait);
1170 // Passage Parallele/Perspective
1171 if (OldType != NewType)
1174 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1178 Visual3d_ViewMapping Visual3d_View::ViewMapping () const {
1180 return (MyViewMapping);
1184 Visual3d_ViewMapping Visual3d_View::ViewMappingDefault () const {
1186 return (MyViewMappingReset);
1190 void Visual3d_View::SetViewMappingDefault () {
1192 MyViewMappingReset.Assign (MyViewMapping);
1196 void Visual3d_View::ViewMappingReset () {
1198 if (IsDeleted ()) return;
1200 MyViewMapping = MyViewMappingReset;
1202 Standard_Real X, Y, Z;
1203 Standard_Real um, vm, uM, vM;
1205 MyCView.Mapping.Projection = int (MyViewMapping.Projection ());
1206 (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
1207 MyCView.Mapping.ProjectionReferencePoint.x = float (X);
1208 MyCView.Mapping.ProjectionReferencePoint.y = float (Y);
1209 MyCView.Mapping.ProjectionReferencePoint.z = float (Z);
1210 MyCView.Mapping.ViewPlaneDistance =
1211 float (MyViewMapping.ViewPlaneDistance ());
1212 MyCView.Mapping.BackPlaneDistance =
1213 float (MyViewMapping.BackPlaneDistance ());
1214 MyCView.Mapping.FrontPlaneDistance =
1215 float (MyViewMapping.FrontPlaneDistance ());
1216 MyViewMapping.WindowLimit (um, vm, uM, vM);
1217 MyCView.Mapping.WindowLimit.um = float (um);
1218 MyCView.Mapping.WindowLimit.vm = float (vm);
1219 MyCView.Mapping.WindowLimit.uM = float (uM);
1220 MyCView.Mapping.WindowLimit.vM = float (vM);
1222 MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
1223 if (MyViewMapping.IsCustomMatrix()) {
1224 Standard_Integer i, j;
1225 for (i = 0; i < 4; i++)
1226 for (j = 0; j < 4; j++)
1227 MyCView.Mapping.ProjectionMatrix[i][j] =
1228 (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j);
1231 MyMatOfMapIsEvaluated = Standard_False;
1233 if (! IsDefined ()) return;
1235 Standard_Boolean AWait = Standard_False; // => immediate update
1236 MyGraphicDriver->ViewMapping (MyCView, AWait);
1238 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1242 void Visual3d_View::SetContext (const Visual3d_ContextView& CTX) {
1244 if (IsDeleted ()) return;
1246 Visual3d_TypeOfVisualization OldVisualMode;
1247 Visual3d_TypeOfVisualization NewVisualMode;
1249 // To manage display only in case of
1250 // change of visualisation mode.
1251 OldVisualMode = MyContext.Visualization ();
1252 NewVisualMode = CTX.Visualization ();
1254 Visual3d_TypeOfModel OldModel;
1255 Visual3d_TypeOfModel NewModel;
1257 // To manage change of visualisation only in case
1258 // of change of mode of visualisation or of type of shading.
1259 OldModel = MyContext.Model ();
1260 NewModel = CTX.Model ();
1262 Standard_Boolean OldAliasingMode;
1263 Standard_Boolean NewAliasingMode;
1265 // To manage antialiasing only in case of change.
1266 OldAliasingMode = MyContext.AliasingIsOn ();
1267 NewAliasingMode = CTX.AliasingIsOn ();
1269 Standard_Boolean OldDepthCueingMode;
1270 Standard_Boolean NewDepthCueingMode;
1272 Standard_Real OldDepthCueingFrontPlane;
1273 Standard_Real NewDepthCueingFrontPlane;
1274 Standard_Real OldDepthCueingBackPlane;
1275 Standard_Real NewDepthCueingBackPlane;
1277 // To manage the depth cueing only in case of change.
1278 OldDepthCueingMode = MyContext.DepthCueingIsOn ();
1279 NewDepthCueingMode = CTX.DepthCueingIsOn ();
1281 OldDepthCueingFrontPlane = MyContext.DepthCueingFrontPlane ();
1282 NewDepthCueingFrontPlane = CTX.DepthCueingFrontPlane ();
1283 OldDepthCueingBackPlane = MyContext.DepthCueingBackPlane ();
1284 NewDepthCueingBackPlane = CTX.DepthCueingBackPlane ();
1286 Standard_Boolean OldFrontZClippingMode;
1287 Standard_Boolean NewFrontZClippingMode;
1288 Standard_Boolean OldBackZClippingMode;
1289 Standard_Boolean NewBackZClippingMode;
1291 Standard_Real OldZClippingFrontPlane;
1292 Standard_Real NewZClippingFrontPlane;
1293 Standard_Real OldZClippingBackPlane;
1294 Standard_Real NewZClippingBackPlane;
1296 // To manage the Zclipping only in case of change.
1297 OldFrontZClippingMode = MyContext.FrontZClippingIsOn ();
1298 NewFrontZClippingMode = CTX.FrontZClippingIsOn ();
1299 OldBackZClippingMode = MyContext.BackZClippingIsOn ();
1300 NewBackZClippingMode = CTX.BackZClippingIsOn ();
1302 OldZClippingFrontPlane = MyContext.ZClippingFrontPlane ();
1303 NewZClippingFrontPlane = CTX.ZClippingFrontPlane ();
1304 OldZClippingBackPlane = MyContext.ZClippingBackPlane ();
1305 NewZClippingBackPlane = CTX.ZClippingBackPlane ();
1307 Handle(Graphic3d_TextureEnv) aTexEnvOld = MyContext.TextureEnv();
1308 Handle(Graphic3d_TextureEnv) aTexEnvNew = CTX.TextureEnv();
1310 Visual3d_TypeOfSurfaceDetail OldSurfaceDetail = MyContext.SurfaceDetail();
1311 Visual3d_TypeOfSurfaceDetail NewSurfaceDetail = CTX.SurfaceDetail();
1317 Standard_Boolean AWait = Standard_False; // => immediate update
1319 // management of visualization modes and types of shading.
1320 if ((OldVisualMode != NewVisualMode) || (OldModel != NewModel))
1321 MyGraphicDriver->SetVisualisation (MyCView);
1323 // management of antialiasing.
1324 if (OldAliasingMode != NewAliasingMode)
1325 MyGraphicDriver->AntiAliasing (MyCView, NewAliasingMode);
1327 // management of depth_cueing.
1328 if ((OldDepthCueingMode != NewDepthCueingMode) ||
1329 (OldDepthCueingFrontPlane != NewDepthCueingFrontPlane) ||
1330 (OldDepthCueingBackPlane != NewDepthCueingBackPlane)) {
1332 if( NewDepthCueingMode &&
1333 (NewDepthCueingBackPlane >= NewDepthCueingFrontPlane) )
1334 Visual3d_DepthCueingDefinitionError::Raise
1335 ("Bad value for DepthCueingPlanes position");
1337 MyGraphicDriver->DepthCueing
1338 (MyCView, NewDepthCueingMode);
1341 // management of Zclipping
1342 if ((OldFrontZClippingMode != NewFrontZClippingMode) ||
1343 (OldBackZClippingMode != NewBackZClippingMode) ||
1344 (OldZClippingFrontPlane != NewZClippingFrontPlane) ||
1345 (OldZClippingBackPlane != NewZClippingBackPlane)) {
1347 if( NewBackZClippingMode && NewFrontZClippingMode &&
1348 (NewZClippingBackPlane >= NewZClippingFrontPlane) )
1349 Visual3d_ZClippingDefinitionError::Raise
1350 ("Bad value for ZClippingPlanes position");
1352 MyGraphicDriver->ClipLimit (MyCView, AWait);
1355 // management of textures
1356 if ((aTexEnvOld != aTexEnvNew) || (OldSurfaceDetail != NewSurfaceDetail))
1358 MyGraphicDriver->Environment(MyCView);
1361 // Update of planes of model clipping
1364 // Update of light sources
1368 if (OldVisualMode != NewVisualMode) {
1371 * Change of context =>
1372 * Remove structures that cannot be displayed
1373 * in the new visualisation mode.
1374 * It is not necessary to warn ViewManager as
1375 * this structure should not disappear from
1376 * the list of structures displayed in it.
1378 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
1379 Visual3d_TypeOfAnswer Answer;
1381 Standard_Integer i = MyDisplayedStructure.Extent ();
1383 Graphic3d_SequenceOfStructure FooSequence;
1385 while (S1Iterator.More ()) {
1386 Answer = AcceptDisplay (S1Iterator.Key ());
1387 // If the structure can't be displayed in the
1388 // new context of the view, it is removed.
1389 if ((Answer == Visual3d_TOA_NO) ||
1390 (Answer == Visual3d_TOA_COMPUTE))
1391 //Erase (S1Iterator.Key (), Aspect_TOU_WAIT);
1392 FooSequence.Append (S1Iterator.Key ());
1394 // S1Iterator.Next () is located on the next structure
1398 Standard_Integer Length = FooSequence.Length ();
1399 // The stored structures are removed
1400 for (i=1; i<=Length; i++)
1401 Erase (FooSequence.Value (i), Aspect_TOU_WAIT);
1402 if (Length != 0) FooSequence.Clear ();
1405 * Change of context =>
1406 * Display structures that can be displayed
1407 * with the new visualisation mode.
1408 * All structures with status Displayed are removed from the ViewManager
1409 * and displayed in the view directly, if the structure is not already
1410 * displayed and if the view accepts it in its context.
1413 i = MyViewManager->NumberOfDisplayedStructures ();
1414 Graphic3d_MapOfStructure Map;
1415 MyViewManager->DisplayedStructures(Map);
1416 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1418 for (; it.More(); it.Next()) {
1419 Handle(Graphic3d_Structure) SG = it.Key();
1420 if (! IsDisplayed (SG)) {
1421 Answer = AcceptDisplay(SG);
1422 // If the structure can be displayed in the
1423 // new context of the view, it is displayed.
1424 if ((Answer == Visual3d_TOA_YES) ||
1425 (Answer == Visual3d_TOA_COMPUTE))
1426 //Display (MyViewManager->DisplayedStructure (j),
1428 FooSequence.Append (SG);
1432 Length = FooSequence.Length ();
1433 // The stored structures are displayed
1434 for (i=1; i<=Length; i++)
1435 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
1436 if (Length != 0) FooSequence.Clear ();
1439 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1443 const Visual3d_ContextView& Visual3d_View::Context () const {
1449 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& SG) const
1452 if (IsDeleted ()) return;
1454 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
1456 while (Iterator.More ()) {
1457 SG.Add (Iterator.Key ());
1459 // Iterator.Next () is located on the next structure
1465 void Visual3d_View::Activate () {
1467 if (IsDeleted ()) return;
1470 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1472 if (! IsActive ()) {
1474 MyGraphicDriver->ActivateView (MyCView);
1475 MyGraphicDriver->Background (MyCView);
1476 MyGraphicDriver->Transparency
1477 (MyCView, MyViewManager->Transparency ());
1482 * Activation of a new view =>
1483 * Display structures that can be displayed in this new view.
1484 * All structures with status
1485 * Displayed in ViewManager are returned and displayed in
1486 * the view directly, if the structure is not already
1487 * displayed and if the view accepts it in its context.
1490 Visual3d_TypeOfAnswer Answer;
1491 Graphic3d_MapOfStructure Map;
1492 MyViewManager->DisplayedStructures(Map);
1493 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1495 for (; it.More(); it.Next()) {
1496 Handle(Graphic3d_Structure) SG = it.Key();
1497 if (! IsDisplayed (SG)) {
1498 Answer = AcceptDisplay(SG);
1499 // If the structure can be displayed in the
1500 // new context of the view, it is displayed.
1501 if ((Answer == Visual3d_TOA_YES) ||
1502 (Answer == Visual3d_TOA_COMPUTE))
1503 Display (SG,Aspect_TOU_WAIT);
1509 // If the activation/desactivation of ZBuffer should be automatic
1510 // depending on the presence or absence of facets.
1511 if (MyViewManager->ZBufferAuto ()) {
1512 Standard_Boolean BContainsFacet = ContainsFacet ();
1513 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1514 // If the view contains facets
1515 // and if ZBuffer is not active
1516 if (BContainsFacet && ! BZBuffer)
1517 SetZBufferActivity (1);
1518 // If the view does not contain facets
1519 // and if ZBuffer is active
1520 if (! BContainsFacet && BZBuffer)
1521 SetZBufferActivity (0);
1524 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1528 Standard_Boolean Visual3d_View::IsActive () const {
1530 if (IsDeleted ()) return (Standard_False);
1533 return (Standard_True);
1535 return (Standard_False);
1539 void Visual3d_View::Deactivate () {
1541 if (IsDeleted ()) return;
1544 Visual3d_ViewDefinitionError::Raise ("Window not defined");
1548 MyGraphicDriver->DeactivateView (MyCView);
1551 * Deactivation of a view =>
1552 * Removal of structures displayed in this view.
1553 * All structures with status
1554 * Displayed in ViewManager are returned and removed from
1555 * the view directly, if the structure is not already
1556 * displayed and if the view accepts it in its context.
1559 Visual3d_TypeOfAnswer Answer;
1560 Graphic3d_MapOfStructure Map;
1561 MyViewManager->DisplayedStructures(Map);
1562 Graphic3d_MapIteratorOfMapOfStructure it(Map);
1564 for (; it.More(); it.Next()) {
1565 Handle(Graphic3d_Structure) SG = it.Key();
1566 if (! IsDisplayed (SG)) {
1567 Answer = AcceptDisplay(SG);
1568 // If the structure was displayed it is removed.
1569 if ((Answer == Visual3d_TOA_YES) ||
1570 (Answer == Visual3d_TOA_COMPUTE))
1571 Erase (SG,Aspect_TOU_WAIT);
1575 if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
1577 // No action currently possible in the view
1583 void Visual3d_View::Redraw () {
1585 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1589 void Visual3d_View::Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
1591 Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer (), x, y, width, height);
1594 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1596 if (IsDeleted ()) return;
1598 if ((! IsDefined ()) || (! IsActive ())) return;
1600 if (! MyWindow->IsMapped ()) return;
1602 // san - 14/04/2004 - set up Z buffer state before redrawing
1603 // If the activation/desactivation of ZBuffer should be automatic
1604 // depending on the presence or absence of facets.
1605 if (MyViewManager->ZBufferAuto ()) {
1606 Standard_Boolean BContainsFacet = ContainsFacet ();
1607 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1608 // If the view contains facets
1609 // and if ZBuffer is not active
1610 if (BContainsFacet && ! BZBuffer)
1611 SetZBufferActivity (1);
1612 // If the view contains only facets
1613 // and if ZBuffer is active
1614 if (! BContainsFacet && BZBuffer)
1615 SetZBufferActivity (0);
1618 Aspect_CLayer2d OverCLayer;
1619 Aspect_CLayer2d UnderCLayer;
1620 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1621 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1622 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1623 MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer);
1627 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) {
1629 if (IsDeleted ()) return;
1631 if ((! IsDefined ()) || (! IsActive ())) return;
1633 if (! MyWindow->IsMapped ()) return;
1635 // san - 14/04/2004 - set up Z buffer state before redrawing
1636 // If activation/desactivation of ZBuffer should be automatic
1637 // depending on the presence or absence of facets.
1638 if (MyViewManager->ZBufferAuto ()) {
1639 Standard_Boolean BContainsFacet = ContainsFacet ();
1640 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1641 // If the view contains facets
1642 // and if ZBuffer is not active
1643 if (BContainsFacet && ! BZBuffer)
1644 SetZBufferActivity (1);
1645 // If the view contains only facets
1646 // and if ZBuffer is active
1647 if (! BContainsFacet && BZBuffer)
1648 SetZBufferActivity (0);
1651 Aspect_CLayer2d OverCLayer;
1652 Aspect_CLayer2d UnderCLayer;
1653 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1654 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1655 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1656 MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer, x, y, width, height);
1660 void Visual3d_View::Update () {
1662 Update (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
1666 void Visual3d_View::Update (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
1668 if (IsDeleted ()) return;
1670 if ((! IsDefined ()) || (! IsActive ())) return;
1672 if (! MyWindow->IsMapped ()) return;
1674 if (MyGraphicDriver->IsDeviceLost())
1676 MyViewManager->ReComputeStructures();
1677 MyGraphicDriver->ResetDeviceLostFlag();
1680 // If activation/desactivation of ZBuffer should be automatic
1681 // depending on the presence or absence of facets.
1682 if (MyViewManager->ZBufferAuto ()) {
1683 Standard_Boolean BContainsFacet = ContainsFacet ();
1684 Standard_Boolean BZBuffer = ZBufferIsActivated ();
1685 // If the view contains facets
1686 // and if ZBuffer is not active
1687 if (BContainsFacet && ! BZBuffer)
1688 SetZBufferActivity (1);
1689 // If the view does not contain facets
1690 // and if ZBuffer is active
1691 if (! BContainsFacet && BZBuffer)
1692 SetZBufferActivity (0);
1695 Aspect_CLayer2d OverCLayer;
1696 Aspect_CLayer2d UnderCLayer;
1697 OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
1698 if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
1699 if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
1700 //OSD::SetSignal (Standard_False);
1701 MyGraphicDriver->Update (MyCView, UnderCLayer, OverCLayer);
1702 //OSD::SetSignal (Standard_True);
1706 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const {
1708 // Return type of visualization of the view
1709 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
1711 // Return type of visualization of the structure
1712 Graphic3d_TypeOfStructure StructType = AStructure->Visual ();
1714 Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO;
1716 if (StructType == Graphic3d_TOS_ALL)
1717 // The structure accepts any type of view
1718 Result = Visual3d_TOA_YES;
1720 if ((StructType == Graphic3d_TOS_SHADING)
1721 && (ViewType == Visual3d_TOV_SHADING))
1722 Result = Visual3d_TOA_YES;
1723 if ((StructType == Graphic3d_TOS_WIREFRAME)
1724 && (ViewType == Visual3d_TOV_WIREFRAME))
1725 Result = Visual3d_TOA_YES;
1726 if ((StructType == Graphic3d_TOS_COMPUTED)
1727 && (ViewType == Visual3d_TOV_WIREFRAME))
1728 Result = Visual3d_TOA_COMPUTE;
1729 if ((StructType == Graphic3d_TOS_COMPUTED)
1730 && (ViewType == Visual3d_TOV_SHADING))
1731 Result = Visual3d_TOA_COMPUTE;
1735 if (Result == Visual3d_TOA_YES)
1736 cout << "YES = Visual3d_View" << MyCView.ViewId
1737 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1738 if (Result == Visual3d_TOA_NO)
1739 cout << "NO = Visual3d_View" << MyCView.ViewId
1740 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1741 if (Result == Visual3d_TOA_COMPUTE)
1742 cout << "COMPUTE = Visual3d_View" << MyCView.ViewId
1743 << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
1751 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer /*OldPriority*/, const Standard_Integer NewPriority) {
1753 if (IsDeleted ()) return;
1754 if (! IsDefined ()) return;
1755 if (! IsActive ()) return;
1756 if (! IsDisplayed (AStructure)) return;
1758 Standard_Integer Index = IsComputed (AStructure);
1759 if (Index != 0 && ComputedMode())
1762 Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification ();
1763 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1764 << AStructure->Identification () << "/" << StructId
1765 << ", " << OldPriority << ", " << NewPriority << ")\n";
1768 MyGraphicDriver->EraseStructure
1770 *(Graphic3d_CStructure *)
1771 MyCOMPUTEDSequence.Value (Index)->CStructure ());
1772 MyGraphicDriver->DisplayStructure
1774 *(Graphic3d_CStructure *)
1775 MyCOMPUTEDSequence.Value (Index)->CStructure (),
1780 Standard_Integer StructId = AStructure->Identification ();
1781 cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
1782 << AStructure->Identification () << "/" << StructId
1783 << ", " << OldPriority << ", " << NewPriority << ")\n";
1786 MyGraphicDriver->EraseStructure
1788 *(Graphic3d_CStructure *)AStructure->CStructure ());
1789 MyGraphicDriver->DisplayStructure
1791 *(Graphic3d_CStructure *)AStructure->CStructure (),
1797 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
1800 cout << "Visual3d_View" << MyCView.ViewId << "::Clear ("
1801 << AStructure->Identification () << ")\n";
1805 Standard_Integer Index = IsComputed (AStructure);
1808 cout << "Structure " << AStructure->Identification ()
1809 << " calculated in the view "
1810 << Identification () << ", by structure "
1811 << MyCOMPUTEDSequence.Value (Index)->Identification ()
1812 << " is emptied.\n";
1815 MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction);
1816 MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False);
1821 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
1823 #ifdef TRACE_CONNECT
1824 cout << "Visual3d_View" << MyCView.ViewId << "::Connect ("
1825 << AMother->Identification ()
1826 << ADaughter->Identification () << ")\n";
1830 Standard_Integer IndexM = IsComputed (AMother);
1831 Standard_Integer IndexD = IsComputed (ADaughter);
1833 if (IndexM != 0 && IndexD != 0) {
1834 #ifdef TRACE_CONNECT
1835 cout << "Structure " << AMother->Identification ()
1836 << " is connected to structure "
1837 << ADaughter->Identification () << endl;
1838 cout << "These structures are calculated.\n";
1839 cout << "In the view " << Identification ()
1841 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
1842 << " is connected to the structure "
1843 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
1846 MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD));
1851 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
1853 #ifdef TRACE_CONNECT
1854 cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect ("
1855 << AMother->Identification ()
1856 << ADaughter->Identification () << ")\n";
1860 Standard_Integer IndexM = IsComputed (AMother);
1861 Standard_Integer IndexD = IsComputed (ADaughter);
1863 if (IndexM != 0 && IndexD != 0) {
1864 #ifdef TRACE_CONNECT
1865 cout << "Structure " << AMother->Identification ()
1866 << " is disconnected from the structure "
1867 << ADaughter->Identification () << endl;
1868 cout << "These structures are calculated.\n";
1869 cout << "In the view " << Identification ()
1871 << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
1872 << " is disconnected from the structure "
1873 << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
1876 MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD));
1881 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure) {
1883 Display (AStructure, MyViewManager->UpdateMode ());
1887 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
1889 if (IsDeleted ()) return;
1890 if (! IsDefined ()) return;
1891 if (! IsActive ()) return;
1893 // If Display on a structure present in the list
1894 // of calculated structures while it is not
1895 // or more, of calculated type =>
1896 // - removes it as well as the associated old computed
1897 // THis happens when hlhsr becomes again of type e
1898 // non computed after SetVisual.
1899 Standard_Integer Index = IsComputed (AStructure);
1901 if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) {
1902 MyTOCOMPUTESequence.Remove (Index);
1903 MyCOMPUTEDSequence.Remove (Index);
1907 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
1909 if (Answer == Visual3d_TOA_NO) {
1913 if (!ComputedMode())
1915 Answer = Visual3d_TOA_YES;
1918 if (Answer == Visual3d_TOA_YES ) {
1919 if (IsDisplayed (AStructure)) return;
1920 MyGraphicDriver->DisplayStructure (
1922 *(Graphic3d_CStructure *)AStructure->CStructure (),
1923 int (AStructure->DisplayPriority ())
1925 MyDisplayedStructure.Add (AStructure);
1926 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
1929 if (Answer == Visual3d_TOA_COMPUTE) {
1931 // Already computed, is COMPUTED still valid?
1932 Standard_Integer OldStructId =
1933 MyCOMPUTEDSequence.Value (Index)->Identification ();
1935 // Case COMPUTED valide
1936 if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
1938 if (! IsDisplayed (AStructure)) {
1939 MyDisplayedStructure.Add (AStructure);
1940 MyGraphicDriver->DisplayStructure (
1942 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
1943 int (AStructure->DisplayPriority ())
1945 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
1950 // Case COMPUTED invalid
1952 // Is there another valid representation ?
1953 // Find in the sequence of already calculated structures
1954 // 1/ Structure having the same Owner as <AStructure>
1955 // 2/ That is not <AStructure>
1956 // 3/ The COMPUTED which of is valid
1957 Standard_Integer NewIndex = HaveTheSameOwner (AStructure);
1959 // Case of COMPUTED invalid, WITH a valid of replacement
1960 if (NewIndex != 0) {
1962 if (! IsDisplayed (AStructure)) {
1963 MyCOMPUTEDSequence.SetValue
1964 (Index, MyCOMPUTEDSequence.Value (NewIndex));
1965 OldStructId = MyCOMPUTEDSequence.Value (NewIndex)->
1967 MyDisplayedStructure.Add (AStructure);
1968 MyGraphicDriver->DisplayStructure (
1970 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (NewIndex)->CStructure (),
1971 int (AStructure->DisplayPriority ())
1973 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
1978 // Cas COMPUTED invalid, WITHOUT a valid of replacement
1980 // COMPUTED is removed if displayed
1981 if (IsDisplayed (AStructure))
1982 MyGraphicDriver->EraseStructure (
1984 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()
1988 } // if (Index != 0)
1990 // Compute + Validation
1992 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
1994 Handle(Graphic3d_Structure) TheStructure;
1995 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
1996 AStructure->Transform (ATrsf);
1998 TColStd_Array2OfReal Ident (0, 3, 0, 3);
1999 Standard_Integer ii, jj;
2000 for (ii=0; ii<=3; ii++)
2001 for (jj=0; jj<=3; jj++)
2002 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
2003 TheStructure = MyCOMPUTEDSequence.Value (Index);
2004 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
2005 if (AStructure->IsTransformed ()) {
2006 AStructure->Compute (this, ATrsf, TheStructure);
2009 AStructure->Compute (this, TheStructure);
2013 if (AStructure->IsTransformed ()) {
2014 TheStructure = AStructure->Compute (this, ATrsf);
2017 TheStructure = AStructure->Compute (this);
2021 TheStructure->SetHLRValidation (Standard_True);
2023 // TOCOMPUTE and COMPUTED associated to sequences are added
2024 MyTOCOMPUTESequence.Append (AStructure);
2025 MyCOMPUTEDSequence.Append (TheStructure);
2027 // The previous are removed if necessary
2029 MyTOCOMPUTESequence.Remove (Index);
2030 MyCOMPUTEDSequence.Remove (Index);
2033 // Return type of visualisation of the view
2034 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
2036 // Of which type will be the computed ?
2037 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
2038 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
2040 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
2041 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
2043 if (ComputeWireframe)
2044 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
2046 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
2048 if (! ComputeShading && ! ComputeWireframe)
2049 Answer = Visual3d_TOA_NO;
2051 Answer = AcceptDisplay (TheStructure);
2053 if (AStructure->IsHighlighted()) {
2054 TheStructure->SetHighlightColor (AStructure->HighlightColor ());
2055 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
2058 // It is displayed only if the calculated structure
2059 // has a proper type corresponding to the one of the view.
2060 if (Answer != Visual3d_TOA_NO) {
2061 if (! IsDisplayed (AStructure))
2062 MyDisplayedStructure.Add (AStructure);
2063 MyGraphicDriver->DisplayStructure (
2065 *(Graphic3d_CStructure *)TheStructure->CStructure (),
2066 int (AStructure->DisplayPriority ())
2068 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2070 } // Visual3d_TOA_COMPUTE
2073 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure) {
2075 if (IsDeleted ()) return;
2077 Erase (AStructure, MyViewManager->UpdateMode ());
2081 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
2083 Standard_Integer StructId;
2085 if (IsDeleted ()) return;
2087 // No test on window as the structure is displayed only if
2088 // the window exists, so only one test is enough.
2089 if (IsDisplayed (AStructure)) {
2090 Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
2092 if (!ComputedMode())
2094 Answer = Visual3d_TOA_YES;
2097 if (Answer != Visual3d_TOA_COMPUTE) {
2098 MyGraphicDriver->EraseStructure (
2100 *(Graphic3d_CStructure *)AStructure->CStructure ()
2104 if (Answer == Visual3d_TOA_COMPUTE) {
2105 Standard_Integer Index = IsComputed (AStructure);
2107 cout << "Visual3d_View" << MyCView.ViewId << "::Erase ("
2108 << AStructure->Identification () << ");\n";
2109 cout << "Index : " << Index << "\n";
2113 if (Index != 0 && ComputedMode())
2116 MyCOMPUTEDSequence.Value (Index)->Identification ();
2118 cout << "Structure " << AStructure->Identification ()
2119 << " calculated, in the view "
2120 << Identification () << ", by the structure "
2121 << StructId << " is removed. \n";
2124 MyGraphicDriver->EraseStructure
2125 (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
2127 // else is impossible
2129 MyDisplayedStructure.Remove (AStructure);
2130 if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
2135 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
2138 cout << "Visual3d_View" << MyCView.ViewId << "::Highlight ("
2139 << AStructure->Identification () << ")\n";
2143 Standard_Integer Index = IsComputed (AStructure);
2146 cout << "Structure " << AStructure->Identification ()
2147 << " calculated, in the view "
2148 << Identification () << ", by the structure "
2149 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2150 << " passes in highlight mode.\n";
2153 (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
2154 (AStructure->HighlightColor ());
2155 (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod);
2160 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
2163 cout << "Visual3d_View" << MyCView.ViewId << "::Transform ("
2164 << AStructure->Identification () << ")\n";
2168 Standard_Integer Index = IsComputed (AStructure);
2171 cout << "The structure " << AStructure->Identification ()
2172 << " calculated, in the view "
2173 << Identification () << ", by the structure "
2174 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2175 << " is transformed.\n";
2178 // Test is somewhat light !
2179 // trsf is transferred only if it is :
2182 if (ATrsf (0, 1) != 0. || ATrsf (0, 2) != 0.
2183 || ATrsf (1, 0) != 0. || ATrsf (1, 2) != 0.
2184 || ATrsf (2, 0) != 0. || ATrsf (2, 1) != 0.)
2185 ReCompute (AStructure);
2187 MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf);
2192 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
2195 cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight ("
2196 << AStructure->Identification () << ")\n";
2200 Standard_Integer Index = IsComputed (AStructure);
2203 cout << "Structure " << AStructure->Identification ()
2204 << " calculated, in the view "
2205 << Identification () << ", by the structure "
2206 << MyCOMPUTEDSequence.Value (Index)->Identification ()
2207 << " passes in unhighlight mode.\n";
2210 MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight ();
2216 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const {
2218 Standard_Integer StrId = AStructure->Identification ();
2220 Standard_Integer Result = 0;
2221 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
2223 // Recherche de la structure <AStructure> dans la
2224 // sequence des structures deja calculees
2225 for (Standard_Integer i=1; i<=Length && Result==0; i++)
2226 if ((MyTOCOMPUTESequence.Value (i))->Identification ()
2227 == StrId) Result = i;
2229 cout << "\n In the view " << Identification () << " the structure ";
2231 cout << StrId << " is calculated by "
2232 << MyCOMPUTEDSequence.Value (Result)->Identification ()
2235 cout << StrId << " is not calculated\n" << flush;
2239 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2240 cout << "In Visual3d_View::IsComputed, ";
2241 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2242 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2251 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const {
2253 Standard_Boolean Result = Standard_False;
2255 if (IsDeleted ()) return Result;
2257 Result = MyDisplayedStructure.Contains (AStructure);
2264 Standard_Boolean Visual3d_View::ContainsComputedStructure () const {
2266 Standard_Boolean Result = Standard_False;
2268 if (MyDisplayedStructure.IsEmpty ()) return Result;
2270 Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
2272 Standard_Integer i = MyDisplayedStructure.Extent ();
2274 // Stop at the first structure of type TOS_COMPUTED
2275 while (! Result && Iterator.More ()) {
2277 (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED);
2279 // Iterator.Next () is located on the
2289 Standard_Boolean Visual3d_View::ContainsFacet () const {
2291 return ContainsFacet (MyDisplayedStructure);
2295 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const {
2297 Standard_Boolean Result = Standard_False;
2299 if (ASet.IsEmpty ()) return Result;
2301 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2303 // Stop at the first structure containing a facet
2304 for ( Iterator.Initialize (ASet);
2305 Iterator.More () && ! Result;
2307 Result = (Iterator.Key ())->ContainsFacet ();
2313 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
2316 (MyDisplayedStructure, XMin, YMin, ZMin, XMax, YMax, ZMax);
2320 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 {
2322 if (ASet.IsEmpty ()) {
2323 XMin = RealFirst ();
2324 YMin = RealFirst ();
2325 ZMin = RealFirst ();
2333 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2334 Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
2340 XMax = RealFirst ();
2341 YMax = RealFirst ();
2342 ZMax = RealFirst ();
2344 for ( Iterator.Initialize (ASet);
2348 if (!Iterator.Key()->IsVisible())
2353 if ( (Iterator.Key ())->IsInfinite ()){
2354 //XMin, YMin .... ZMax are initialized by means of infinite line data
2355 (Iterator.Key ())->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
2356 if ( Xm != RealFirst() && Xm < XMin )
2358 if ( Ym != RealFirst() && Ym < YMin )
2360 if ( Zm != RealFirst() && Zm < ZMin )
2362 if ( XM != RealLast() && XM > XMax )
2364 if ( YM != RealLast() && YM > YMax )
2366 if ( ZM != RealLast() && ZM > ZMax )
2369 // Only non-empty and non-infinite structures
2370 // are taken into account for calculation of MinMax
2371 if (! (Iterator.Key ())->IsInfinite () &&
2372 ! (Iterator.Key ())->IsEmpty ()) {
2373 (Iterator.Key ())->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
2374 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
2375 //"FitAll" operation ignores object with transform persitence parameter
2376 if( (Iterator.Key ())->TransformPersistenceMode() == Graphic3d_TMF_None )
2378 if (Xm < XMin) XMin = Xm;
2379 if (Ym < YMin) YMin = Ym;
2380 if (Zm < ZMin) ZMin = Zm;
2381 if (XM > XMax) XMax = XM;
2382 if (YM > YMax) YMax = YM;
2383 if (ZM > ZMax) ZMax = ZM;
2388 // The following cases are relevant
2389 // For exemple if all structures are empty or infinite
2390 if (XMax < XMin) { Xm = XMin; XMin = XMax; XMax = Xm; }
2391 if (YMax < YMin) { Ym = YMin; YMin = YMax; YMax = Ym; }
2392 if (ZMax < ZMin) { Zm = ZMin; ZMin = ZMax; ZMax = Zm; }
2394 Standard_Real Sx, Sy, Sz;
2395 MyViewOrientation.AxialScale(Sx, Sy, Sz);
2396 XMin = (Sx > 1. && XMin < RealFirst ()/Sx)?RealFirst (): XMin*Sx;
2397 XMax = (Sx > 1. && XMax > RealLast ()/Sx)?RealLast (): XMax*Sx;
2398 YMin = (Sy > 1. && YMin < RealFirst ()/Sy)?RealFirst (): YMin*Sy;
2399 YMax = (Sy > 1. && YMax > RealLast ()/Sy)?RealLast (): YMax*Sy;
2400 ZMin = (Sz > 1. && ZMin < RealFirst ()/Sz)?RealFirst (): ZMin*Sz;
2401 ZMax = (Sz > 1. && ZMax > RealLast ()/Sz)?RealLast (): ZMax*Sz;
2404 void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2406 MinMaxValues (MyDisplayedStructure, XMin, YMin, XMax, YMax);
2410 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {
2412 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2413 Standard_Real Xp, Yp, Zp;
2415 MinMaxValues (ASet, Xm, Ym, Zm, XM, YM, ZM);
2417 Projects (Xm, Ym, Zm, Xp, Yp, Zp);
2421 Projects (XM, YM, ZM, Xp, Yp, Zp);
2425 if (XMax < XMin) { Xp = XMax; XMax = XMin; XMin = Xp; }
2426 if (YMax < YMin) { Yp = YMax; YMax = YMin; YMin = Yp; }
2429 const TColStd_Array2OfReal& Visual3d_View::MatrixOfOrientation () {
2431 if (! MyMatOfOriIsEvaluated) {
2432 MyGraphicDriver->InquireMat
2433 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2434 MyMatOfMapIsEvaluated = Standard_True;
2435 MyMatOfOriIsEvaluated = Standard_True;
2438 return (MyMatrixOfOrientation);
2442 const TColStd_Array2OfReal& Visual3d_View::MatrixOfMapping () {
2444 if (! MyMatOfMapIsEvaluated) {
2445 MyGraphicDriver->InquireMat
2446 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2447 MyMatOfMapIsEvaluated = Standard_True;
2448 MyMatOfOriIsEvaluated = Standard_True;
2451 return (MyMatrixOfMapping);
2455 Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const {
2457 Standard_Integer Result = MyDisplayedStructure.Extent ();
2464 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 {
2466 math_Vector PtDC (0,3), PtWC (0,3);
2469 // Otherwise use new on Visual3d_View (constructor+destructor)
2470 // as Projects is a const method or MatrixOfOrientation and
2471 // MatrixOfMapping is not.
2472 Visual3d_View * const newthis = (Visual3d_View * const) this;
2473 newthis->MatrixOfOrientation ();
2474 newthis->MatrixOfMapping ();
2476 // World Coordinate Space
2482 // WCS -> View Reference Coordinate Space
2483 math_Vector PtVRC(0,3);
2484 PtVRC = MyMatrixOfOrientation.Multiplied (PtWC);
2486 // VRCS -> Normalized Projection Coordinate Space
2487 math_Vector PtNPC(0,3);
2488 PtNPC = MyMatrixOfMapping.Multiplied (PtVRC);
2489 for (Standard_Integer i=0; i<3; i++) PtNPC (i) = PtNPC (i) / PtNPC (3);
2492 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2493 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2496 Standard_Real Ratio;
2498 // NPCS -> Device Coordinate Space
2499 Standard_Real Dx = Standard_Real (MyCView.DefWindow.dx);
2500 Standard_Real Dy = Standard_Real (MyCView.DefWindow.dy);
2503 PtDC (0) = PtNPC (0) * Dx;
2504 PtDC (1) = Dy - PtNPC (1) * Dy * Ratio;
2506 printf("Display coordinates : %f,%f,%f,%f\n",
2507 PtDC(0),PtDC(1),PtDC(2),PtDC(3));
2510 // NPCS -> Window Space
2511 Standard_Real um, vm, uM, vM;
2512 MyViewMapping.WindowLimit (um, vm, uM, vM);
2514 Ratio = (uM - um) / (vM - vm);
2516 PtNPC (1) = PtNPC (1) * Ratio;
2518 PtNPC (0) = PtNPC (0) / Ratio;
2521 printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
2522 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2525 Standard_Real fpd = MyViewMapping.FrontPlaneDistance ();
2526 Standard_Real bpd = MyViewMapping.BackPlaneDistance ();
2529 * Coordinates of PtNPC are described in the space
2530 * [0-1]x[0-1]x[0-1].
2531 * It is necessary to transform x and y in the window space.
2532 * It is necessary to transform z in the space of back and front
2533 * plane, taking into account clipping planes.
2534 * Z clipping planes are defined between 0 and 1.
2537 APX = PtNPC (0) * (uM - um) + um;
2538 APY = PtNPC (1) * (vM - vm) + vm;
2539 APZ = PtNPC (2) * (fpd - bpd) + bpd;
2542 Standard_Integer l,c;
2543 printf("OrientationMatrix :");
2544 for( l=0 ; l<4 ; l++ ) {
2545 printf("\n %d->",l);
2546 for( c=0 ; c<4 ; c++ ) {
2547 printf(" %f ,",MyMatrixOfOrientation(c,l));
2551 printf("MappingMatrix :");
2552 for( l=0 ; l<4 ; l++ ) {
2553 printf("\n %d->",l);
2554 for( c=0 ; c<4 ; c++ ) {
2555 printf(" %f ,",MyMatrixOfMapping(c,l));
2559 printf("World coordinates : %f,%f,%f,%f\n",
2560 PtWC(0),PtWC(1),PtWC(2),PtWC(3));
2561 printf("View coordinates : %f,%f,%f,%f\n",
2562 PtVRC(0),PtVRC(1),PtVRC(2),PtVRC(3));
2563 printf("Display coordinates : %f,%f,%f,%f\n",
2564 PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
2565 printf("Window limit : %f,%f,%f,%f\n",um,vm,uM,vM);
2566 printf("Ratio : %f\n",Ratio);
2567 printf("Front-plane : %f back-plane : %f\n",fpd,bpd);
2568 printf("Projection : %f,%f,%f\n \n",APX,APY,APZ);
2572 #endif /* OLD_METHOD */
2574 // OCC18942: This method is likely to duplicate Visual3d_ViewManager::ConvertCoord() one,
2575 // therefore it is necessary to consider merging the two methods or making them call the same
2576 // graphic driver's method after OCCT 6.3.
2577 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) {
2579 Standard_Real PtX, PtY, PtZ, PtT;
2581 static Standard_Real Ratio, um, vm, uM, vM;
2582 static Standard_Real fpd, bpd;
2584 if (! MyMatOfOriIsEvaluated || ! MyMatOfMapIsEvaluated) {
2585 MyGraphicDriver->InquireMat
2586 (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
2587 MyMatOfOriIsEvaluated = MyMatOfMapIsEvaluated = Standard_True;
2590 // WCS -> View Reference Coordinate Space
2591 PtX = MyMatrixOfOrientation (0, 0) * AX
2592 + MyMatrixOfOrientation (0, 1) * AY
2593 + MyMatrixOfOrientation (0, 2) * AZ
2594 + MyMatrixOfOrientation (0, 3);
2595 PtY = MyMatrixOfOrientation (1, 0) * AX
2596 + MyMatrixOfOrientation (1, 1) * AY
2597 + MyMatrixOfOrientation (1, 2) * AZ
2598 + MyMatrixOfOrientation (1, 3);
2599 PtZ = MyMatrixOfOrientation (2, 0) * AX
2600 + MyMatrixOfOrientation (2, 1) * AY
2601 + MyMatrixOfOrientation (2, 2) * AZ
2602 + MyMatrixOfOrientation (2, 3);
2603 PtT = MyMatrixOfOrientation (3, 0) * AX
2604 + MyMatrixOfOrientation (3, 1) * AY
2605 + MyMatrixOfOrientation (3, 2) * AZ
2606 + MyMatrixOfOrientation (3, 3);
2608 // VRCS -> Normalized Projection Coordinate Space
2609 APX = MyMatrixOfMapping (0, 0) * PtX
2610 + MyMatrixOfMapping (0, 1) * PtY
2611 + MyMatrixOfMapping (0, 2) * PtZ
2612 + MyMatrixOfMapping (0, 3) * PtT;
2613 APY = MyMatrixOfMapping (1, 0) * PtX
2614 + MyMatrixOfMapping (1, 1) * PtY
2615 + MyMatrixOfMapping (1, 2) * PtZ
2616 + MyMatrixOfMapping (1, 3) * PtT;
2617 APZ = MyMatrixOfMapping (2, 0) * PtX
2618 + MyMatrixOfMapping (2, 1) * PtY
2619 + MyMatrixOfMapping (2, 2) * PtZ
2620 + MyMatrixOfMapping (2, 3) * PtT;
2621 APT = MyMatrixOfMapping (3, 0) * PtX
2622 + MyMatrixOfMapping (3, 1) * PtY
2623 + MyMatrixOfMapping (3, 2) * PtZ
2624 + MyMatrixOfMapping (3, 3) * PtT;
2630 // NPCS -> Window Space
2631 MyViewMapping.WindowLimit (um, vm, uM, vM);
2632 fpd = MyViewMapping.FrontPlaneDistance ();
2633 bpd = MyViewMapping.BackPlaneDistance ();
2635 if(MyCView.Mapping.IsCustomMatrix) {
2636 // OCC18942: SAN - If orientation and mapping matrices are those used by OpenGL
2637 // visualization, then X, Y and Z coordinates normally vary between -1 and 1
2638 APX = ( APX + 1 ) * 0.5 * (uM - um) + um;
2639 APY = ( APY + 1 ) * 0.5 * (vM - vm) + vm;
2641 Ratio = (uM - um) / (vM - vm);
2648 * Coordinates of APX, APY, APZ are described in the space
2649 * [0-1]x[0-1]x[0-1].
2650 * It is necessary to transform x and y in the window space.
2651 * It is necessary to transform z in the space of back and front
2652 * plane, taking into account clipping planes.
2653 * Z clipping planes are defined between 0 and 1.
2655 APX = APX * (uM - um) + um;
2656 APY = APY * (vM - vm) + vm;
2658 APZ = APZ * (fpd - bpd) + bpd;
2661 Standard_Integer Visual3d_View::Identification () const {
2663 return (Standard_Integer (MyCView.ViewId));
2668 Standard_Boolean Visual3d_View::ZBufferIsActivated () const {
2670 if (IsDeleted ()) return (Standard_False);
2672 if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);
2674 // -1 => not forced by the programmer => depends on the type of visualisation
2675 // 0 ou 1 => forced by the programmer
2677 if (MyCView.Context.ZBufferActivity == -1)
2678 if (MyContext.Visualization () == Visual3d_TOV_SHADING)
2679 return (Standard_True);
2681 return (Standard_False);
2683 if (MyCView.Context.ZBufferActivity)
2684 return (Standard_True);
2686 return (Standard_False);
2690 void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {
2692 if (IsDeleted ()) return;
2694 if ((! IsDefined ()) || (! IsActive ())) return;
2696 MyGraphicDriver->Transparency (MyCView, AnActivity);
2700 void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {
2702 if (MyCView.Context.ZBufferActivity == AnActivity) return;
2704 if (IsDeleted ()) return;
2706 if ((! IsDefined ()) || (! IsActive ())) return;
2708 MyCView.Context.ZBufferActivity = AnActivity;
2709 MyGraphicDriver->SetVisualisation (MyCView);
2713 void Visual3d_View::UpdateView () {
2715 MyCView.Context.Aliasing = (MyContext.AliasingIsOn () ? 1:0);
2716 MyCView.Context.BackZClipping =
2717 (MyContext.BackZClippingIsOn () ? 1:0);
2718 MyCView.Context.FrontZClipping =
2719 (MyContext.FrontZClippingIsOn() ? 1:0);
2720 MyCView.Context.DepthCueing =
2721 (MyContext.DepthCueingIsOn () ? 1:0);
2723 MyCView.Context.ZClipFrontPlane =
2724 float (MyContext.ZClippingFrontPlane ());
2725 MyCView.Context.ZClipBackPlane =
2726 float (MyContext.ZClippingBackPlane ());
2727 MyCView.Context.DepthFrontPlane =
2728 float (MyContext.DepthCueingFrontPlane ());
2729 MyCView.Context.DepthBackPlane =
2730 float (MyContext.DepthCueingBackPlane ());
2732 MyCView.Context.Model = int (MyContext.Model ());
2733 MyCView.Context.Visualization = int (MyContext.Visualization ());
2735 MyCView.Context.TextureEnv = MyContext.TextureEnv();
2736 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
2740 void Visual3d_View::Compute () {
2743 Standard_Integer Length = MyCOMPUTEDSequence.Length ();
2744 for (i=1; i<=Length; i++)
2745 (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);
2747 if (!ComputedMode())
2753 * Force HLRValidation to False on all structures
2754 * calculated in the view.
2757 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2758 cout << "In Visual3d_View::Compute, ";
2759 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2760 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2766 * Change of orientation or of projection type =>
2767 * Remove structures that were calculated for the
2768 * previous orientation.
2769 * Recalculation of new structures.
2771 Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
2772 Visual3d_TypeOfAnswer Answer;
2774 i = MyDisplayedStructure.Extent ();
2776 Graphic3d_SequenceOfStructure FooSequence;
2778 while (S1Iterator.More ()) {
2779 Answer = AcceptDisplay (S1Iterator.Key ());
2780 // If the structure was calculated, it is recalculated.
2781 if (Answer == Visual3d_TOA_COMPUTE) {
2783 cout << "AcceptDisplay ("
2784 << (S1Iterator.Key ())->Identification ()
2785 << ") == Visual3d_TOA_COMPUTE;\n";
2788 //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
2789 FooSequence.Append (S1Iterator.Key ());
2792 // S1Iterator.Next () is located on the next structure
2796 Length = FooSequence.Length ();
2797 // All stored structures are displayed
2798 for (i=1; i<=Length; i++)
2799 Display (FooSequence.Value (i), Aspect_TOU_WAIT);
2800 if (Length != 0) FooSequence.Clear ();
2804 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
2805 if (!ComputedMode()) return;
2807 if (IsDeleted ()) return;
2809 if ((! IsDefined ()) || (! IsActive ())) return;
2811 if (! MyWindow->IsMapped ()) return;
2813 if (! AStructure->IsDisplayed ()) return;
2815 Visual3d_TypeOfAnswer Answer;
2817 Answer = AcceptDisplay (AStructure);
2819 if (Answer == Visual3d_TOA_COMPUTE) {
2820 Standard_Integer Index = IsComputed (AStructure);
2823 cout << "Structure " << AStructure->Identification ()
2824 << " is not calculated in the view "
2825 << Identification () << "\n";
2830 Standard_Integer OldStructId, NewStructId;
2832 MyCOMPUTEDSequence.Value (Index)->Identification ();
2834 Standard_Integer StructId = AStructure->Identification ();
2835 cout << "Structure " << StructId
2836 << " calculated, in the view "
2837 << Identification () << ", by the structure "
2838 << OldStructId << " is recalculated.\n";
2842 // Compute + Validation
2844 Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
2846 Handle(Graphic3d_Structure) TheStructure;
2847 TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
2848 AStructure->Transform (ATrsf);
2850 TColStd_Array2OfReal Ident (0, 3, 0, 3);
2851 Standard_Integer ii, jj;
2852 for (ii=0; ii<=3; ii++)
2853 for (jj=0; jj<=3; jj++)
2854 Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
2855 TheStructure = MyCOMPUTEDSequence.Value (Index);
2856 TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
2857 if (AStructure->IsTransformed ()) {
2858 AStructure->Compute (this, ATrsf, TheStructure);
2861 AStructure->Compute (this, TheStructure);
2865 if (AStructure->IsTransformed ()) {
2866 TheStructure = AStructure->Compute (this, ATrsf);
2869 TheStructure = AStructure->Compute (this);
2873 TheStructure->SetHLRValidation (Standard_True);
2875 // Return type of visualisation of the view
2876 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
2878 // Of which type will be the computed ?
2879 Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
2880 (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
2882 Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
2883 (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
2885 if (ComputeWireframe)
2886 TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
2888 TheStructure->SetVisual (Graphic3d_TOS_SHADING);
2890 if (AStructure->IsHighlighted ()) {
2891 TheStructure->SetHighlightColor
2892 (AStructure->HighlightColor ());
2893 TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
2897 // Find structure <AStructure>
2898 // in the sequence of structures to be calculated.
2899 NewStructId = TheStructure->Identification ();
2901 // The previous calculation is removed and the new one is dislayed
2902 MyGraphicDriver->EraseStructure (
2904 *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
2905 MyGraphicDriver->DisplayStructure (
2907 *(Graphic3d_CStructure *)TheStructure->CStructure (),
2908 int (AStructure->DisplayPriority ())
2912 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
2913 cout << "In Visual3d_View::ReCompute, ";
2914 cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2915 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2920 // hlhsr and the new associated compute are added
2921 MyTOCOMPUTESequence.Append (AStructure);
2922 MyCOMPUTEDSequence.Append (TheStructure);
2925 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2926 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2927 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2931 // hlhsr and the new associated compute are removed
2933 MyTOCOMPUTESequence.Remove (Index);
2934 MyCOMPUTEDSequence.Remove (Index);
2937 if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
2938 cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
2939 << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
2947 const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver () const {
2949 return MyGraphicDriver;
2953 void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& thePlotter) const
2955 for (Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure); S1Iterator.More(); S1Iterator.Next())
2957 Standard_Integer Index = IsComputed (S1Iterator.Key ());
2958 // displayed structure is plotted as if it was not calculated
2960 (S1Iterator.Key ())->Plot (thePlotter);
2962 (MyCOMPUTEDSequence.Value (Index))->Plot (thePlotter);
2966 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const {
2968 Standard_Integer Result = 0;
2969 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
2971 // Find in the sequence of already calculated structures
2972 // 1/ Structure with the same Owner as <AStructure>
2973 // 2/ Which is not <AStructure>
2974 // 3/ COMPUTED which of is valid
2975 for (Standard_Integer i=1; i<=Length && Result==0; i++)
2976 if ((MyTOCOMPUTESequence.Value (i)->Owner () == AStructure->Owner ())
2977 && (MyTOCOMPUTESequence.Value (i)->Identification () !=
2978 AStructure->Identification ())
2979 && (MyCOMPUTEDSequence.Value (i)->HLRValidation ())) Result = i;
2985 Standard_Address Visual3d_View::CView () const {
2987 return Standard_Address (&MyCView);
2992 // Triedron methods : the Triedron is a non-zoomable object.
2994 void Visual3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
2995 const Quantity_NameOfColor YColor,
2996 const Quantity_NameOfColor ZColor,
2997 const Standard_Real SizeRatio,
2998 const Standard_Real AxisDiametr,
2999 const Standard_Integer NbFacettes) {
3000 MyGraphicDriver->ZBufferTriedronSetup(XColor, YColor, ZColor,
3001 SizeRatio, AxisDiametr, NbFacettes);
3006 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
3007 const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) {
3009 MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe);
3013 void Visual3d_View::TriedronErase () {
3015 MyGraphicDriver->TriedronErase (MyCView);
3020 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {
3022 MyGraphicDriver->TriedronEcho (MyCView,AType);
3026 Standard_Boolean checkFloat(const Standard_Real value)
3028 return value > -FLT_MAX && value < FLT_MAX;
3031 void SetMinMaxValuesCallback(void* Visual3dView)
3033 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
3035 Handle(Visual3d_View) view = (Handle(Visual3d_View)&) Visual3dView;
3036 view->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax);
3038 if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) &&
3039 checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax))
3041 Handle(Graphic3d_GraphicDriver) driver = Handle(Graphic3d_GraphicDriver)::DownCast(view->GraphicDriver());
3042 driver->GraduatedTrihedronMinMaxValues((Standard_ShortReal)xmin, (Standard_ShortReal)ymin, (Standard_ShortReal)zmin,
3043 (Standard_ShortReal)xmax, (Standard_ShortReal)ymax, (Standard_ShortReal)zmax);
3047 Standard_Boolean Visual3d_View::GetGraduatedTrihedron
3048 (/* Names of axes */
3049 TCollection_ExtendedString& xname,
3050 TCollection_ExtendedString& yname,
3051 TCollection_ExtendedString& zname,
3053 Standard_Boolean& xdrawname,
3054 Standard_Boolean& ydrawname,
3055 Standard_Boolean& zdrawname,
3057 Standard_Boolean& xdrawvalues,
3058 Standard_Boolean& ydrawvalues,
3059 Standard_Boolean& zdrawvalues,
3061 Standard_Boolean& drawgrid,
3063 Standard_Boolean& drawaxes,
3064 /* Number of splits along axes */
3065 Standard_Integer& nbx,
3066 Standard_Integer& nby,
3067 Standard_Integer& nbz,
3068 /* Offset for drawing values */
3069 Standard_Integer& xoffset,
3070 Standard_Integer& yoffset,
3071 Standard_Integer& zoffset,
3072 /* Offset for drawing names of axes */
3073 Standard_Integer& xaxisoffset,
3074 Standard_Integer& yaxisoffset,
3075 Standard_Integer& zaxisoffset,
3076 /* Draw tickmarks */
3077 Standard_Boolean& xdrawtickmarks,
3078 Standard_Boolean& ydrawtickmarks,
3079 Standard_Boolean& zdrawtickmarks,
3080 /* Length of tickmarks */
3081 Standard_Integer& xtickmarklength,
3082 Standard_Integer& ytickmarklength,
3083 Standard_Integer& ztickmarklength,
3085 Quantity_Color& gridcolor,
3086 /* Colors of axis names */
3087 Quantity_Color& xnamecolor,
3088 Quantity_Color& ynamecolor,
3089 Quantity_Color& znamecolor,
3090 /* Colors of axis and values */
3091 Quantity_Color& xcolor,
3092 Quantity_Color& ycolor,
3093 Quantity_Color& zcolor,
3094 /* Name of font for names of axes */
3095 TCollection_AsciiString& fontOfNames,
3096 /* Style of names of axes */
3097 Font_FontAspect& styleOfNames,
3098 /* Size of names of axes */
3099 Standard_Integer& sizeOfNames,
3100 /* Name of font for values */
3101 TCollection_AsciiString& fontOfValues,
3102 /* Style of values */
3103 Font_FontAspect& styleOfValues,
3104 /* Size of values */
3105 Standard_Integer& sizeOfValues) const
3107 if (!MyGTrihedron.ptrVisual3dView)
3108 return Standard_False;
3111 xname = MyGTrihedron.xname;
3112 yname = MyGTrihedron.yname;
3113 zname = MyGTrihedron.zname;
3115 xdrawname = MyGTrihedron.xdrawname;
3116 ydrawname = MyGTrihedron.ydrawname;
3117 zdrawname = MyGTrihedron.zdrawname;
3119 xdrawvalues = MyGTrihedron.xdrawvalues;
3120 ydrawvalues = MyGTrihedron.ydrawvalues;
3121 zdrawvalues = MyGTrihedron.zdrawvalues;
3123 drawgrid = MyGTrihedron.drawgrid;
3125 drawaxes = MyGTrihedron.drawaxes;
3126 /* Number of splits along axes */
3127 nbx = MyGTrihedron.nbx;
3128 nby = MyGTrihedron.nby;
3129 nbz = MyGTrihedron.nbz;
3130 /* Offset for drawing values */
3131 xoffset = MyGTrihedron.xoffset;
3132 yoffset = MyGTrihedron.yoffset;
3133 zoffset = MyGTrihedron.zoffset;
3134 /* Offset for drawing names of axes */
3135 xaxisoffset = MyGTrihedron.xaxisoffset;
3136 yaxisoffset = MyGTrihedron.yaxisoffset;
3137 zaxisoffset = MyGTrihedron.zaxisoffset;
3138 /* Draw tickmarks */
3139 xdrawtickmarks = MyGTrihedron.xdrawtickmarks;
3140 ydrawtickmarks = MyGTrihedron.ydrawtickmarks;
3141 zdrawtickmarks = MyGTrihedron.zdrawtickmarks;
3142 /* Length of tickmarks */
3143 xtickmarklength = MyGTrihedron.xtickmarklength;
3144 ytickmarklength = MyGTrihedron.ytickmarklength;
3145 ztickmarklength = MyGTrihedron.ztickmarklength;
3147 gridcolor = MyGTrihedron.gridcolor;
3148 /* Colors of axis names */
3149 xnamecolor = MyGTrihedron.xnamecolor;
3150 ynamecolor = MyGTrihedron.ynamecolor;
3151 znamecolor = MyGTrihedron.znamecolor;
3152 /* Colors of axis and values */
3153 xcolor = MyGTrihedron.xcolor;
3154 ycolor = MyGTrihedron.ycolor;
3155 zcolor = MyGTrihedron.zcolor;
3156 /* Name of font for names of axes */
3157 fontOfNames = MyGTrihedron.fontOfNames;
3158 /* Style of names of axes */
3159 styleOfNames = MyGTrihedron.styleOfNames;
3160 /* Size of names of axes */
3161 sizeOfNames = MyGTrihedron.sizeOfNames;
3162 /* Name of font for values */
3163 fontOfValues = MyGTrihedron.fontOfValues;
3164 /* Style of values */
3165 styleOfValues = MyGTrihedron.styleOfValues;
3166 /* Size of values */
3167 sizeOfValues = MyGTrihedron.sizeOfValues;
3169 return Standard_True;
3172 void Visual3d_View::GraduatedTrihedronDisplay
3173 (/* Names of axes */
3174 const TCollection_ExtendedString &xname,
3175 const TCollection_ExtendedString &yname,
3176 const TCollection_ExtendedString &zname,
3178 const Standard_Boolean xdrawname,
3179 const Standard_Boolean ydrawname,
3180 const Standard_Boolean zdrawname,
3182 const Standard_Boolean xdrawvalues,
3183 const Standard_Boolean ydrawvalues,
3184 const Standard_Boolean zdrawvalues,
3186 const Standard_Boolean drawgrid,
3188 const Standard_Boolean drawaxes,
3189 /* Number of splits along axes */
3190 const Standard_Integer nbx,
3191 const Standard_Integer nby,
3192 const Standard_Integer nbz,
3193 /* Offset for drawing values */
3194 const Standard_Integer xoffset,
3195 const Standard_Integer yoffset,
3196 const Standard_Integer zoffset,
3197 /* Offset for drawing names of axes */
3198 const Standard_Integer xaxisoffset,
3199 const Standard_Integer yaxisoffset,
3200 const Standard_Integer zaxisoffset,
3201 /* Draw tickmarks */
3202 const Standard_Boolean xdrawtickmarks,
3203 const Standard_Boolean ydrawtickmarks,
3204 const Standard_Boolean zdrawtickmarks,
3205 /* Length of tickmarks */
3206 const Standard_Integer xtickmarklength,
3207 const Standard_Integer ytickmarklength,
3208 const Standard_Integer ztickmarklength,
3210 const Quantity_Color& gridcolor,
3211 /* Colors of axis names */
3212 const Quantity_Color& xnamecolor,
3213 const Quantity_Color& ynamecolor,
3214 const Quantity_Color& znamecolor,
3215 /* Colors of axis and values */
3216 const Quantity_Color& xcolor,
3217 const Quantity_Color& ycolor,
3218 const Quantity_Color& zcolor,
3219 /* Name of font for names of axes */
3220 const TCollection_AsciiString &fontOfNames,
3221 /* Style of names of axes */
3222 const Font_FontAspect styleOfNames,
3223 /* Size of names of axes */
3224 const Standard_Integer sizeOfNames,
3225 /* Name of font for values */
3226 const TCollection_AsciiString &fontOfValues,
3227 /* Style of values */
3228 const Font_FontAspect styleOfValues,
3229 /* Size of values */
3230 const Standard_Integer sizeOfValues)
3233 MyGTrihedron.xname = xname;
3234 MyGTrihedron.yname = yname;
3235 MyGTrihedron.zname = zname;
3237 MyGTrihedron.xdrawname = xdrawname;
3238 MyGTrihedron.ydrawname = ydrawname;
3239 MyGTrihedron.zdrawname = zdrawname;
3241 MyGTrihedron.xdrawvalues = xdrawvalues;
3242 MyGTrihedron.ydrawvalues = ydrawvalues;
3243 MyGTrihedron.zdrawvalues = zdrawvalues;
3245 MyGTrihedron.drawgrid = drawgrid;
3247 MyGTrihedron.drawaxes = drawaxes;
3248 /* Number of splits along axes */
3249 MyGTrihedron.nbx = nbx;
3250 MyGTrihedron.nby = nby;
3251 MyGTrihedron.nbz = nbz;
3252 /* Offset for drawing values */
3253 MyGTrihedron.xoffset = xoffset;
3254 MyGTrihedron.yoffset = yoffset;
3255 MyGTrihedron.zoffset = zoffset;
3256 /* Offset for drawing names of axes */
3257 MyGTrihedron.xaxisoffset = xaxisoffset;
3258 MyGTrihedron.yaxisoffset = yaxisoffset;
3259 MyGTrihedron.zaxisoffset = zaxisoffset;
3260 /* Draw tickmarks */
3261 MyGTrihedron.xdrawtickmarks = xdrawtickmarks;
3262 MyGTrihedron.ydrawtickmarks = ydrawtickmarks;
3263 MyGTrihedron.zdrawtickmarks = zdrawtickmarks;
3264 /* Length of tickmarks */
3265 MyGTrihedron.xtickmarklength = xtickmarklength;
3266 MyGTrihedron.ytickmarklength = ytickmarklength;
3267 MyGTrihedron.ztickmarklength = ztickmarklength;
3269 MyGTrihedron.gridcolor = gridcolor;
3270 /* Colors of axis names */
3271 MyGTrihedron.xnamecolor = xnamecolor;
3272 MyGTrihedron.ynamecolor = ynamecolor;
3273 MyGTrihedron.znamecolor = znamecolor;
3274 /* Colors of axis and values */
3275 MyGTrihedron.xcolor = xcolor;
3276 MyGTrihedron.ycolor = ycolor;
3277 MyGTrihedron.zcolor = zcolor;
3278 /* Name of font for names of axes */
3279 MyGTrihedron.fontOfNames = fontOfNames;
3280 /* Style of names of axes */
3281 MyGTrihedron.styleOfNames = styleOfNames;
3282 /* Size of names of axes */
3283 MyGTrihedron.sizeOfNames = sizeOfNames;
3284 /* Name of font for values */
3285 MyGTrihedron.fontOfValues = fontOfValues;
3286 /* Style of values */
3287 MyGTrihedron.styleOfValues = styleOfValues;
3288 /* Size of values */
3289 MyGTrihedron.sizeOfValues = sizeOfValues;
3291 MyGTrihedron.ptrVisual3dView = this;
3292 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
3293 MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron);
3296 void Visual3d_View::GraduatedTrihedronErase()
3298 MyGTrihedron.ptrVisual3dView = NULL;
3299 MyGraphicDriver->GraduatedTrihedronErase(MyCView);
3302 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer () const {
3304 return (MyViewManager->UnderLayer ());
3308 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer () const {
3310 return (MyViewManager->OverLayer ());
3314 Standard_Integer Visual3d_View::LightLimit() const {
3316 Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit ();
3317 // printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight);
3321 Standard_Integer Visual3d_View::PlaneLimit() const {
3323 Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit ();
3324 // printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane);
3328 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
3330 return MyPtrViewManager;
3333 void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3335 if ((aMode && ComputedModeIsActive) ||
3336 (!aMode && !ComputedModeIsActive))
3341 Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure );
3342 Visual3d_TypeOfAnswer Answer;
3343 Standard_Integer StructId;
3344 Standard_Integer i = MyDisplayedStructure.Extent ();
3345 ComputedModeIsActive = aMode;
3346 if (!ComputedModeIsActive) {
3348 while ( S1Iterator.More () ) {
3350 Answer = AcceptDisplay ( S1Iterator.Key () );
3352 if ( Answer == Visual3d_TOA_COMPUTE ) {
3354 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
3358 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3360 MyGraphicDriver -> EraseStructure (
3362 *( Graphic3d_CStructure* )
3363 MyCOMPUTEDSequence.Value ( Index ) -> CStructure ()
3365 MyGraphicDriver -> DisplayStructure (
3367 *( Graphic3d_CStructure* )
3368 S1Iterator.Key () -> CStructure (),
3369 int ( S1Iterator.Key () -> DisplayPriority () )
3371 } // end if ( Index != 0 ) . . .
3373 } // end if ( Answer . . . )
3381 while ( S1Iterator.More () ) {
3383 Answer = AcceptDisplay ( S1Iterator.Key () );
3385 if ( Answer == Visual3d_TOA_COMPUTE ) {
3387 Standard_Integer Index = IsComputed ( S1Iterator.Key () );
3391 StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
3393 MyGraphicDriver -> EraseStructure (
3395 *( Graphic3d_CStructure* )
3396 S1Iterator.Key () -> CStructure ()
3398 MyGraphicDriver -> DisplayStructure (
3400 *( Graphic3d_CStructure* )
3401 MyCOMPUTEDSequence.Value ( Index ) -> CStructure (),
3402 int ( S1Iterator.Key () -> DisplayPriority () )
3405 Display ( S1Iterator.Key (), Aspect_TOU_WAIT );
3407 if ( S1Iterator.Key () -> IsHighlighted () ) {
3409 if ( !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted () ) {
3411 MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor (
3412 S1Iterator.Key () ->
3415 MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight (
3424 Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key ();
3426 Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this );
3428 Handle( Graphic3d_Structure ) TheStructure;
3429 TColStd_Array2OfReal ATrsf ( 0, 3, 0, 3 );
3431 AStructure -> Transform ( ATrsf );
3435 TColStd_Array2OfReal Ident ( 0, 3, 0, 3 );
3436 Standard_Integer ii, jj;
3438 for ( ii = 0; ii <= 3; ++ii )
3440 for ( jj = 0; jj <= 3; ++jj )
3442 Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 );
3444 TheStructure = MyCOMPUTEDSequence.Value ( Index );
3446 TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE );
3448 if ( AStructure->IsTransformed () )
3450 AStructure -> Compute ( this, ATrsf, TheStructure );
3454 AStructure -> Compute ( this, TheStructure );
3458 if ( AStructure -> IsTransformed () )
3460 TheStructure = AStructure -> Compute ( this, ATrsf );
3464 TheStructure = AStructure -> Compute ( this );
3468 TheStructure -> SetHLRValidation ( Standard_True );
3470 Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
3472 Standard_Boolean ComputeWireframe =
3473 ( ( ViewType == Visual3d_TOV_WIREFRAME ) &&
3474 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING )
3477 Standard_Boolean ComputeShading =
3478 ( ( ViewType == Visual3d_TOV_SHADING ) &&
3479 ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME )
3482 if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME );
3483 if ( ComputeShading ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING );
3485 if ( S1Iterator.Key () -> IsHighlighted () ) {
3487 TheStructure -> SetHighlightColor (
3488 S1Iterator.Key () -> HighlightColor ()
3490 TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR );
3494 Standard_Integer Result = 0;
3495 Standard_Integer Length = MyTOCOMPUTESequence.Length ();
3496 StructId = S1Iterator.Key () -> Identification ();
3498 for ( i = 1; i <= Length && Result == 0; ++i )
3500 if ( MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId )
3506 MyCOMPUTEDSequence.ChangeValue ( Result ) = TheStructure;
3510 MyTOCOMPUTESequence.Append ( S1Iterator.Key () );
3511 MyCOMPUTEDSequence.Append ( TheStructure );
3515 MyGraphicDriver -> EraseStructure (
3517 *( Graphic3d_CStructure* )
3518 S1Iterator.Key () -> CStructure ()
3520 MyGraphicDriver -> DisplayStructure (
3522 *( Graphic3d_CStructure* )TheStructure -> CStructure (),
3523 int ( S1Iterator.Key () -> DisplayPriority () )
3533 if ( MyViewManager -> UpdateMode () == Aspect_TOU_ASAP ) Update ();
3537 } // end Visual3d_View :: SetComputedMode
3539 Standard_Boolean Visual3d_View :: ComputedMode () const {
3541 return ComputedModeIsActive;
3543 } // end Visual3d_View :: ComputedMode
3545 void Visual3d_View :: SetBackFacingModel (
3546 const Visual3d_TypeOfBackfacingModel aModel
3551 case Visual3d_TOBM_AUTOMATIC:
3552 MyCView.Backfacing = 0;
3555 case Visual3d_TOBM_FORCE:
3556 MyCView.Backfacing = 1;
3559 case Visual3d_TOBM_DISABLE:
3560 MyCView.Backfacing = -1;
3565 MyGraphicDriver -> SetBackFacingModel ( MyCView );
3567 } // end Visual3d_View :: SetBackFacingModel
3569 Visual3d_TypeOfBackfacingModel Visual3d_View :: BackFacingModel () const {
3571 switch ( MyCView.Backfacing ) {
3574 return Visual3d_TOBM_AUTOMATIC;
3577 return Visual3d_TOBM_FORCE;
3581 return Visual3d_TOBM_DISABLE;
3583 } // end Visual3d_View :: BackFacingModel
3585 void Visual3d_View::EnableDepthTest( const Standard_Boolean enable ) const
3587 MyGraphicDriver->SetDepthTestEnabled( MyCView, enable );
3590 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
3592 return MyGraphicDriver->IsDepthTestEnabled( MyCView );
3595 void Visual3d_View::ReadDepths(const Standard_Integer x,
3596 const Standard_Integer y,
3597 const Standard_Integer width,
3598 const Standard_Integer height,
3599 const Standard_Address buffer) const
3601 MyGraphicDriver->ReadDepths( MyCView, x, y, width, height, buffer );
3604 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
3605 const Standard_Integer theHeight)
3607 return MyGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
3610 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
3612 MyGraphicDriver->FBORelease( MyCView, theFBOPtr );
3615 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
3616 Standard_Integer& theWidth, Standard_Integer& theHeight,
3617 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
3619 MyGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
3620 theWidth, theHeight,
3621 theWidthMax, theHeightMax );
3624 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
3625 const Standard_Integer theWidth, const Standard_Integer theHeight)
3627 MyGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
3628 theWidth, theHeight );
3631 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
3632 const Graphic3d_BufferType& theBufferType)
3634 return MyGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
3637 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
3639 MyGraphicDriver->SetGLLightEnabled( MyCView, enable );
3643 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
3645 return MyGraphicDriver->IsGLLightEnabled( MyCView );
3648 Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
3649 const Graphic3d_ExportFormat theFormat,
3650 const Graphic3d_SortType theSortType,
3651 const Standard_Real thePrecision,
3652 const Standard_Address theProgressBarFunc,
3653 const Standard_Address theProgressObject) const
3655 Handle(Visual3d_Layer) anUnderLayer = MyViewManager->UnderLayer();
3656 Handle(Visual3d_Layer) anOverLayer = MyViewManager->OverLayer();
3658 Aspect_CLayer2d anOverCLayer;
3659 Aspect_CLayer2d anUnderCLayer;
3660 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
3662 if (!anOverLayer.IsNull())
3663 anOverCLayer = anOverLayer->CLayer();
3664 if (!anUnderLayer.IsNull())
3665 anUnderCLayer = anUnderLayer->CLayer();
3667 Standard_Integer aWidth, aHeight;
3668 Window()->Size (aWidth, aHeight);
3670 return MyGraphicDriver->Export (theFileName, theFormat, theSortType,
3671 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
3672 thePrecision, theProgressBarFunc, theProgressObject);
3675 //=======================================================================
3676 //function : AddZLayer
3678 //=======================================================================
3680 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
3682 MyGraphicDriver->AddZLayer (MyCView, theLayerId);
3685 //=======================================================================
3686 //function : RemoveZLayer
3688 //=======================================================================
3690 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
3692 MyGraphicDriver->RemoveZLayer (MyCView, theLayerId);
3695 //=======================================================================
3696 //function : ChangeZLayer
3698 //=======================================================================
3700 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
3701 const Standard_Integer theLayerId)
3703 MyGraphicDriver->ChangeZLayer (
3704 (*(Graphic3d_CStructure*)theStructure->CStructure()), MyCView, theLayerId);