0022627: Change OCCT memory management defaults
[occt.git] / src / V3d / V3d_View.cxx
CommitLineData
7fd59977 1/***********************************************************************
2
3FONCTION :
4----------
5Classe V3d_View :
6
7HISTORIQUE DES MODIFICATIONS :
8--------------------------------
900-09-92 : GG ; Creation.
1002-10-96 : FMN ; Suppression appel Redraw sans MustBeResized()
1105-06-97 : FMN ; Correction FitAll()
1230-06-97 : GG ; Correction + Optimisation de Panning(...)
13On fait la translation + le zoom en une seule
14operation au lieu de 2 precedemment qui etait buggee.
1509-07-97 : FMN ; Correction FitAll() sur le Ratio
1616-07-97 : FMN ; Correction FitAll() sur le calcul de la Box
1722-07-97 : FMN ; Ajout mode RetainMode pour le Transient
1815-12-97 : FMN ; Ajout texture mapping
1917-12-97 : FMN ; CTS19129 Correction FitAll() multiple
2018-12-97 : FMN ; Ajout mode Ajout
2124-12-97 : FMN ; Remplacement de math par MathGra
2224-12-97 : CQO ; BUC50037 Xw_Window -> Aspect_Window
2331-12-97 : CAL ; Remplacement de MathGra par Array2OfReal
2407-01-98 : CAL ; Ajout de la methode DoMapping.
2507-01-98 : CAL ; Retrait de tous les "this->" inutiles
2621-01-98 : CAL ; Remplacement des Window->Position () par Window->Size ()
2727-01-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
2812-02-98 : GG ; Reactivation du Redraw dans MustBeResized()
2923-02-98 : FMN ; Remplacement PI par Standard_PI
3025-02-98 : FMN ; PERF.27: Optimisation of view creation from existing view
3111-03-98 : STT ; S3558
3219-03-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
33ne marche pas.
3408-04-98 : STT ; suppr. S3558
3510-04-98 : CAL ; Ajout des methodes RefToPix et PixToRef
3613-06-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
37ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int).
3816-08-98 : CAL ; S3892. Ajout grilles 3d.
3909-09-98 : CAL ; S3892. Generalisation de TrsPoint.
4024-09-98 : CAL ; Ajout d'un parametre a V3d_View::SetPlotter.
4106-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
4216-10-98 : CAL ; Retrait d'un TIMER si CSF_GraphicTimer est definie.
4306-11-98 : CAL ; PRO ?????. Probleme dans ZFitAll si un point dans la vue.
4413-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guinde)
4529-OCT-98 : DCB : Adding ScreenCopy () method.
4622-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
4710-11-99 : GG ; PRO19603 Add Redraw( area ) method
48IMP130100 : GG
49-> Don't increase too much the ZSize.
50-> Initialize correctly the Z clipping and D cueing
51planes.
52IMP100701 : SZV ; Add ToPixMap() method
53
54REMARQUES :
55-----------
56About FitAll() multiple. This probleme is caused by missing
57precision of transformation matrices. If it is supposed that
58projection is made in the plane (U,V), there is a difference
59after several Zoom - compared to the exact value (cf ZoomX).
60Don't forget that the matrices work in float and not in double.
61To solve the problem (for lack of a better solution) I make 2 passes.
62
63************************************************************************/
64
65#define GER61351 //GG_15/12/99 Add SetBackgroundColor()
66// and BackgroundColor() methods
67
68
69#define IMP240100 //GG
70// -> Remove PixToRef() method ,use
71// instead the equivalent Convert() method.
72// -> Rename RefToPix() to Convert() method.
73// -> Remove the grid computation in Convert()
74// method. Use instead the NEW ConvertToGrid() methods.
75// Reason is the Convert() method is call by
76// StdSelect_ViewSelector3d_Pick() from
77// AIS_InteractiveContext() and it's not possible
78// to select an object vertex when the grid is active!
79// -> Remove grid echo marker definition
80// (reported in the viewer)
81// -> Add SetProjModel() methods.
82
83#define G003 //EUG 04-10-99
84// -> computed mode management
85// Add SetComputedMode(..) method
86// -> animation mode management
87// Add SetAnimationMode()
88// -> backfacing management
89// Add SetBackFacingModel() method
90
91#define G004 //VKH 15-11-99
92// -> Add Dump() methods
93// -> GG 07/03/00 Use the new MMSize()
94// method from Aspect_Window class.
95
96#define IMP210200 //GG Add Transparency() method
97
98#define IMP250200 //GG With SetDepth() method, when the requested
99// depth is < 0.,
100// move the view ref point and the eye,instead
101// only the eye.
102
103#define IMP020300 //GG Don't use ZFitAll in during Rotation
104// for perf improvment
105
106#define IMP210600 //GG Avoid to have infinite loop when call Rotation() method
107// without call before StartRotation().
108// This problem occurs when CTRL MB3 is maintain press betwwen 2 views.
109
110#define IMP250900 //GG Enable rotation around screen Z axis when
111// rotation begin far the center of the screen.
112// Thanks to Patrick REGINSTER (SAMTECH)
113// GG 21/12/00 Due to a regression on the previous specifications
114// this new functionnality is right now deactivated
115// by default (see StartRotation(...,zRotationThreshold)
116// method.
117
118#define BUC60952 //GG Enable to rotate around the view axis
119// and the required view point
120
121#define RIC120302 //GG Add a NEW SetWindow method which enable
122// to connect a graphic widget and context to OGL.
123
124#define IMP260302 //GG To avoid conflicting in Window destructor
125// nullify this handle in Remove method
126
127#define OCC280 //SAV fix for FitAll problem in the perspective view.
128
129#define OCC1188 //SAV Added methods to set background image
130
131/*----------------------------------------------------------------------*/
132/*
133* Includes
134*/
135
136#include <Standard_TypeMismatch.hxx>
137#include <Visual3d_ViewManager.hxx>
138#include <Visual3d_Light.hxx>
139#include <Visual3d_ClipPlane.hxx>
140#include <Graphic3d_Structure.hxx>
141#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
142#include <Graphic3d_MapOfStructure.hxx>
143#include <Graphic3d_TextureEnv.hxx>
144#include <Image_PixMap.hxx>
145#include <V3d.hxx>
146#include <V3d_View.ixx>
147#include <Viewer_BadValue.hxx>
148#include <Standard_ShortReal.hxx>
149#include <gp_Dir.hxx>
150#include <TColStd_Array2OfReal.hxx>
151#include <Visual3d_TransientManager.hxx>
152#include <Precision.hxx>
153
154// S3892
155#include <Graphic3d_AspectMarker3d.hxx>
156
157// S3603
158#include <Aspect_GenericColorMap.hxx>
159#include <Aspect_TypeMap.hxx>
160#include <Aspect_WidthMap.hxx>
161#include <Aspect_MarkMap.hxx>
162#include <Aspect_FontMap.hxx>
163#include <PlotMgt_ImageDriver.hxx>
164#include <TColStd_HSequenceOfInteger.hxx>
165#ifdef WNT
166# include <WNT_WDriver.hxx>
167#else
168# include <Xw_Driver.hxx>
169#endif
170
171#ifdef G003
172# define V3d_FLAG_ANIMATION 0x00000001
173# define V3d_FLAG_DEGENERATION 0x00000002
174# define V3d_FLAG_COMPUTATION 0x00000004
175#endif // G003
176
177// Tumble
178#include <OSD_Timer.hxx>
179static OSD_Timer FullTimer;
180
181// Perspective
182#include <OSD_Environment.hxx>
183
184/*----------------------------------------------------------------------*/
185/*
186* Constant
187*/
188
189#define Zmargin 1.
c6541a0c 190#define DEUXPI (2. * M_PI)
7fd59977 191
192// in case of NO_TRACE_ECHO and NO_TRACE_POINTS, in V3d_View_4.cxx and in
193// V3d_View.cxx, change MyGridEchoStructure and MyGridEchoGroup in cdl
194#define NO_TRACE_ECHO
195#define NO_TRACE_POINTS
196
197/*----------------------------------------------------------------------*/
198/*
199* Local data definitions
200*/
201
202
203static Standard_Real MyXwindowCenter ;
204static Standard_Real MyYwindowCenter ;
205static Standard_Real MyWindowWidth ;
206static Standard_Real MyWindowHeight ;
207
208#define LOPTIM
209#ifndef LOPTIM
210static Graphic3d_Vector MyXscreenAxis ;
211static Graphic3d_Vector MyYscreenAxis ;
212static Graphic3d_Vector MyZscreenAxis ;
213static Graphic3d_Vector MyViewReferencePlane ;
214static Graphic3d_Vector MyViewReferenceUp ;
215static Graphic3d_Vector MyViewAxis ;
216static Graphic3d_Vertex MyViewReferencePoint ;
217static Graphic3d_Vertex MyGravityReferencePoint ;
218static Graphic3d_Vertex MyProjReferencePoint ;
219#else
220static Graphic3d_Vector& _MyXscreenAxis() {
221 static Graphic3d_Vector MyXscreenAxis;
222 return MyXscreenAxis;
223}
224#define MyXscreenAxis _MyXscreenAxis()
225
226static Graphic3d_Vector& _MyYscreenAxis() {
227 static Graphic3d_Vector MyYscreenAxis;
228 return MyYscreenAxis;
229}
230#define MyYscreenAxis _MyYscreenAxis()
231
232static Graphic3d_Vector& _MyZscreenAxis() {
233 static Graphic3d_Vector MyZscreenAxis;
234 return MyZscreenAxis;
235}
236#define MyZscreenAxis _MyZscreenAxis()
237
238static Graphic3d_Vector& _MyViewReferencePlane() {
239 static Graphic3d_Vector MyViewReferencePlane;
240 return MyViewReferencePlane;
241}
242#define MyViewReferencePlane _MyViewReferencePlane()
243
244static Graphic3d_Vector& _MyViewReferenceUp() {
245 static Graphic3d_Vector MyViewReferenceUp;
246 return MyViewReferenceUp;
247}
248#define MyViewReferenceUp _MyViewReferenceUp()
249
250static Graphic3d_Vector& _MyViewAxis() {
251 static Graphic3d_Vector MyViewAxis;
252 return MyViewAxis;
253}
254#define MyViewAxis _MyViewAxis()
255
256static Graphic3d_Vertex& _MyViewReferencePoint() {
257 static Graphic3d_Vertex MyViewReferencePoint;
258 return MyViewReferencePoint;
259}
260#define MyViewReferencePoint _MyViewReferencePoint()
261
262static Graphic3d_Vertex& _MyGravityReferencePoint() {
263 static Graphic3d_Vertex MyGravityReferencePoint;
264 return MyGravityReferencePoint;
265}
266#define MyGravityReferencePoint _MyGravityReferencePoint()
267
268static Graphic3d_Vertex& _MyProjReferencePoint() {
269 static Graphic3d_Vertex MyProjReferencePoint;
270 return MyProjReferencePoint;
271}
272#define MyProjReferencePoint _MyProjReferencePoint()
273#endif // LOPTIM
274
275/*----------------------------------------------------------------------*/
276//-Constructors
277
278V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
279MyType ( Type ),
280MyViewer(VM.operator->()),
281MyActiveLights(),
282MyActivePlanes(),
283MyViewContext (),
284myActiveLightsIterator(),
285myActivePlanesIterator(),
286SwitchSetFront(Standard_False),
287MyTrsf (1, 4, 1, 4), // S3892
288MyProjModel(V3d_TPM_SCREEN)
289#if defined(TRACE_POINTS)
290,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
291MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
292#endif
293{
294
295 myImmediateUpdate = Standard_False;
296 MyView = new Visual3d_View(MyViewer->Viewer());
297
298 // { Begin to retrieve the definition from ViewContext.
299 // Step MyViewContext = MyView->Context() ;
300 // to permit MyView->SetContext to compare
301 // the old and the new context.
302 // No problem for MyViewMapping, MyViewOrientation
303 // as MyView->SetViewMapping and MyView->SetViewOrientation
304 // don't try to optimize the modifications introduced to
305 // viewmapping and vieworientation.
306
307 // Aliasing
308 if ((MyView->Context ()).AliasingIsOn ())
309 MyViewContext.SetAliasingOn ();
310 else
311 MyViewContext.SetAliasingOff ();
312
313 // DepthCueing
314 MyViewContext.SetDepthCueingBackPlane
315 ((MyView->Context ()).DepthCueingBackPlane ());
316 MyViewContext.SetDepthCueingFrontPlane
317 ((MyView->Context ()).DepthCueingFrontPlane ());
318
319 if ((MyView->Context ()).DepthCueingIsOn ())
320 MyViewContext.SetDepthCueingOn ();
321 else
322 MyViewContext.SetDepthCueingOff ();
323
324 // ZClipping
325 MyViewContext.SetZClippingBackPlane
326 ((MyView->Context ()).ZClippingBackPlane ());
327 MyViewContext.SetZClippingFrontPlane
328 ((MyView->Context ()).ZClippingFrontPlane ());
329
330 if ((MyView->Context ()).FrontZClippingIsOn ())
331 MyViewContext.SetFrontZClippingOn ();
332 else
333 MyViewContext.SetFrontZClippingOff ();
334
335 if ((MyView->Context ()).BackZClippingIsOn ())
336 MyViewContext.SetBackZClippingOn ();
337 else
338 MyViewContext.SetBackZClippingOff ();
339
340 // Visualisation and Shading Model
341 MyViewContext.SetModel ((MyView->Context ()).Model ());
342 MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
343
344 // Texture Mapping
345 MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ());
346 MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ());
347 // } End of retrieval of the definition of ViewContext.
348
349 MyViewMapping = MyView->ViewMapping() ;
350 MyViewOrientation = MyView->ViewOrientation() ;
351 MyBackground = VM->GetBackgroundColor() ;
352 MyGradientBackground = VM->GetGradientBackground() ;
353
354 SetAxis(0.,0.,0.,1.,1.,1.) ;
355 SetVisualization(VM->DefaultVisualization()) ;
356 SetShadingModel(VM->DefaultShadingModel()) ;
357 SetSurfaceDetail(VM->DefaultSurfaceDetail()) ;
358 SetTwist(0.) ;
359 SetAt(0.,0.,0.) ;
360 SetProj(VM->DefaultViewProj()) ;
361 SetSize(VM->DefaultViewSize()) ;
362 Standard_Real zsize = VM->DefaultViewSize();
363 SetZSize(2.*zsize+zsize*Zmargin) ;
364 SetZClippingDepth(0.);
365 SetZClippingWidth(zsize);
366 SetZCueingDepth(0.);
367 SetZCueingWidth(zsize);
368 SetDepth(VM->DefaultViewSize()/2.) ;
369 SetCenter(0.,0.) ;
370 SetViewMappingDefault();
371 VM->AddView(this) ;
372 Init();
373 myImmediateUpdate = Standard_True;
374
375 // S3892
376#ifndef IMP240100
377#if defined(TRACE_POINTS)
378 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
379 MarkerAttrib->SetColor (Quantity_Color (Quantity_NOC_GRAY90));
380 MarkerAttrib->SetScale (3.0);
381 MarkerAttrib->SetType (Aspect_TOM_STAR);
382 MyGridEchoStructure->SetPrimitivesAspect (MarkerAttrib);
383#endif
384#endif //IMP240100
385
386#ifdef G003
387 MyAnimationFlags = 0;
388#endif // G003
389
390#ifdef IMP210200
391 MyTransparencyFlag = Standard_False;
392#endif
393
394}
395
396/*----------------------------------------------------------------------*/
397
398V3d_View::V3d_View(const Handle(V3d_Viewer)& VM,const Handle(V3d_View)& V, const V3d_TypeOfView Type ) :
399MyType ( Type ),
400MyViewer(VM.operator->()),
401MyActiveLights(),
402MyActivePlanes(),
403MyViewContext (),
404myActiveLightsIterator(),
405myActivePlanesIterator(),
406SwitchSetFront(Standard_False),
407MyTrsf (1, 4, 1, 4), // S3892
408MyProjModel(V3d_TPM_SCREEN)
409#if defined(TRACE_POINTS)
410,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())), // S3892
411MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure)) // S3892
412#endif
413{
414
415 Handle(Visual3d_View) FromView = V->View() ;
416
417 myImmediateUpdate = Standard_False;
418 MyView = new Visual3d_View(MyViewer->Viewer());
419
420 for (V->InitActiveLights();V->MoreActiveLights();V->NextActiveLights()){
421 MyActiveLights.Append(V->ActiveLight());}
422 for (V->InitActivePlanes();V->MoreActivePlanes();V->NextActivePlanes()){
423 MyActivePlanes.Append(V->ActivePlane());}
424
425 MyViewContext = FromView->Context() ;
426
427 MyViewMapping = FromView->ViewMapping() ;
428 MyViewOrientation = FromView->ViewOrientation() ;
429 MyBackground = FromView->Background() ;
430 MyGradientBackground = FromView->GradientBackground();
431
432 MyView->SetContext(MyViewContext) ;
433
434 SetAxis(0.,0.,0.,1.,1.,1.) ;
435 VM->AddView(this) ;
436 Init();
437 myImmediateUpdate = Standard_True;
438
439 // S3892
440#ifndef IMP240100
441#if defined(TRACE_ECHO)
442 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
443 MarkerAttrib->SetColor (Quantity_Color (Quantity_NOC_GRAY90));
444 MarkerAttrib->SetScale (3.0);
445 MarkerAttrib->SetType (Aspect_TOM_STAR);
446 MyGridEchoStructure->SetPrimitivesAspect (MarkerAttrib);
447#endif
448#endif //IMP240100
449
450#ifdef G003
451 MyAnimationFlags = 0;
452#endif
453
454}
455
456/*----------------------------------------------------------------------*/
457
458//-Methods, in order
459
460void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow,
461 const Handle(V3d_View)& aPreviousView,
462 const Standard_Integer x1,
463 const Standard_Integer y1,
464 const Standard_Integer x2,
465 const Standard_Integer y2)
466{
467
468 if( !MyView->IsDefined() ) {
469 Standard_Real a,b,c,d;
470 aPreviousView->Convert(x1,y1,a,b);
471 aPreviousView->Convert(x2,y2,c,d);
472 MyView->SetWindow(TheWindow) ;
473 FitAll(TheWindow,a,b,c,d);
474 MyView->SetContext(MyViewContext) ;
475 MyView->SetViewOrientation(MyViewOrientation) ;
476 MyView->SetBackground(MyBackground) ;
477 MyViewer->SetViewOn(this) ;
478 MyWindow = TheWindow;
479 MyView->Redraw() ;
480 SetViewMappingDefault();
481 }
482
483}
484
485/*----------------------------------------------------------------------*/
486
487void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
488{
489
490 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
491 "V3d_View::SetWindow, window of view already defined");
492
493 MyView->SetWindow(TheWindow) ;
cdc2203b
M
494 // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
495 // calling Redraw(). Otherwise it is impossible to call certain methods of
496 // V3d_View like Convert() inside the context of Redraw(),
497 // particularly in class NIS_View.
498 MyWindow = TheWindow;
7fd59977 499 // SetWindow carries out SetRatio and modifies
500 // ViewMapping and ViewMappingDefault of MyView.
501 MyViewMapping = MyView->ViewMapping() ;
502 MyView->SetContext(MyViewContext) ;
503 MyView->SetViewMapping(MyViewMapping) ;
504 MyView->SetViewOrientation(MyViewOrientation) ;
505 MyView->SetBackground(MyBackground) ;
506 MyViewer->SetViewOn(this) ;
507#ifdef TRACE_POINTS
508 MyGridEchoStructure->SetInfiniteState (Standard_True); // S3892
509 MyGridEchoStructure->Display (); // S3892
510#endif
511 MyView->Redraw() ;
7fd59977 512
513}
514
515// RIC120302
516/*----------------------------------------------------------------------*/
517
518void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow,
519 const Aspect_RenderingContext aContext,
520 const Aspect_GraphicCallbackProc& aDisplayCB,
521 const Standard_Address aClientData)
522{
523
524 Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
525 "V3d_View::SetWindow, "
526 "window of view already defined");
cdc2203b
M
527 // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
528 // calling Redraw(). Otherwise it is impossible to call certain methods of
529 // V3d_View like Convert() inside the context of Redraw(),
530 // particularly in class NIS_View.
531 MyWindow = aWindow;
7fd59977 532 MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ;
533 MyViewMapping = MyView->ViewMapping() ;
534 MyView->SetContext(MyViewContext) ;
535 MyView->SetViewMapping(MyViewMapping) ;
536 MyView->SetViewOrientation(MyViewOrientation) ;
537 MyView->SetBackground(MyBackground) ;
538 MyViewer->SetViewOn(this) ;
539 MyView->Redraw() ;
7fd59977 540
541}
542// RIC120302
543
544/*----------------------------------------------------------------------*/
545
546void V3d_View::Remove() const {
547
548 MyViewer->DelView(this) ;
549 MyView->Remove() ;
550#ifdef IMP260303
551 MyWindow.Nullify();
552#endif
553
554}
555
556/*----------------------------------------------------------------------*/
557
558void V3d_View::Update() const {
559 if( MyView->IsDefined() ) MyView->Update() ;
560}
561
562/*----------------------------------------------------------------------*/
563
564void V3d_View::Redraw() const {
565 if( MyView->IsDefined() ) MyView->Redraw() ;
566}
567/*----------------------------------------------------------------------*/
568
569void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
570 const Standard_Integer width,const Standard_Integer height) const
571{
572 if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ;
573}
574
575/*----------------------------------------------------------------------*/
576
577Standard_Boolean V3d_View::IsEmpty() const {
578
579 Standard_Boolean TheStatus = Standard_True ;
580 if( MyView->IsDefined() ) {
581 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
582 if( Nstruct > 0 ) TheStatus = Standard_False ;
583 }
584 return (TheStatus) ;
585
586}
587
588/*----------------------------------------------------------------------*/
589
590void V3d_View::UpdateLights() const {
591 MyView->SetContext(MyViewContext);
592 Update();
593}
594
595/*----------------------------------------------------------------------*/
596
597void V3d_View::DoMapping() {
598 if( MyView->IsDefined() ) {
599 (MyView->Window())->DoMapping() ;
600 }
601}
602
603/*----------------------------------------------------------------------*/
604
605void V3d_View::MustBeResized() {
606
607 if ( !MyLayerMgr.IsNull() )
608 MyLayerMgr->Resized();
609
610 if( MyView->IsDefined() ) {
611 MyView->Resized() ;
612 MyViewMapping = MyView->ViewMapping();
613 MyView->Redraw();
614 }
615
616}
617
618/*----------------------------------------------------------------------*/
619
620void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
621{
622 Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 );
623 Standard_Real V2 = Max( Min( v2, 1.0 ), 0.0 );
624 Standard_Real V3 = Max( Min( v3, 1.0 ), 0.0 );
625
626 Quantity_Color C( V1, V2, V3, Type );
627#ifdef GER61351
628 SetBackgroundColor( C );
629#else
630 MyBackground.SetColor( C );
631 if ( MyView->IsDefined() )
632 MyView->SetBackground( MyBackground );
633 if ( !MyLayerMgr.IsNull() )
634 MyLayerMgr->Resized();
635#endif
636}
637
638#ifdef GER61351
639/*----------------------------------------------------------------------*/
640
641void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
642{
643 MyBackground.SetColor( Color );
644 if ( MyView->IsDefined() )
645 MyView->SetBackground( MyBackground );
646 //szv: Why?
647 if ( !MyLayerMgr.IsNull() )
648 MyLayerMgr->Resized();
649}
650#endif
651
652/*----------------------------------------------------------------------*/
653
654void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
655{
656 Quantity_Color C( Name );
657#ifdef GER61351
658 SetBackgroundColor( C );
659#else
660 MyBackground.SetColor( C );
661 if ( MyView->IsDefined() )
662 MyView->SetBackground( MyBackground );
663 if ( !MyColorScale.IsNull() )
664 MyColorScale->Resized();
665#endif
666}
667
668/*----------------------------------------------------------------------*/
669
670void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
671 const Quantity_Color& Color2,
672 const Aspect_GradientFillMethod FillStyle,
673 const Standard_Boolean status)
674{
675
676 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
677 if ( MyView->IsDefined() )
678 MyView->SetGradientBackground( MyGradientBackground, status );
679
680}
681
682/*----------------------------------------------------------------------*/
683
684void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
685 const Quantity_NameOfColor Color2,
686 const Aspect_GradientFillMethod FillStyle,
687 const Standard_Boolean status )
688{
689 Quantity_Color C1( Color1 );
690 Quantity_Color C2( Color2 );
691 MyGradientBackground.SetColors( C1, C2, FillStyle );
692 if ( MyView->IsDefined() )
693 MyView->SetGradientBackground( MyGradientBackground, status );
694}
695
696/*----------------------------------------------------------------------*/
697
698void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
f8b2ed36 699 const Standard_Boolean update)
7fd59977 700{
f8b2ed36 701 Quantity_Color Color1, Color2;
702 MyGradientBackground.Colors( Color1, Color2 );
703 MyGradientBackground.SetColors( Color1, Color2, FillStyle );
7fd59977 704 if( MyView->IsDefined() )
f8b2ed36 705 MyView->SetBgGradientStyle( FillStyle, update ) ;
7fd59977 706}
707
708/*----------------------------------------------------------------------*/
709
710void V3d_View::SetBackgroundImage( const Standard_CString FileName,
711 const Aspect_FillMethod FillStyle,
712 const Standard_Boolean update )
713{
714#ifdef OCC1188
715 if( MyView->IsDefined() )
716 MyView->SetBackgroundImage( FileName, FillStyle, update ) ;
717#endif
718}
719
720/*----------------------------------------------------------------------*/
721
722void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
723 const Standard_Boolean update )
724{
725#ifdef OCC1188
726 if( MyView->IsDefined() )
727 MyView->SetBgImageStyle( FillStyle, update ) ;
728#endif
729}
730
731/*----------------------------------------------------------------------*/
732
733void V3d_View::SetAxis(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) {
734
735 Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ;
736
737 D = Sqrt( Vx*Vx + Vy*Vy + Vz*Vz ) ;
738 Viewer_BadValue_Raise_if ( D <= 0. , "V3d_View::SetAxis, bad axis");
739 Nx /= D ; Ny /= D ; Nz /= D ;
740 MyDefaultViewPoint.SetCoord(X,Y,Z) ;
741 MyDefaultViewAxis.SetCoord(Nx,Ny,Nz) ;
742 MyDefaultViewAxis.Normalize() ;
743
744}
745
746/*----------------------------------------------------------------------*/
747
748void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model) {
749
750 MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
751 MyView->SetContext(MyViewContext) ;
752
753}
754
755/*----------------------------------------------------------------------*/
756
757void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model) {
758
759 MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
760 MyView->SetContext(MyViewContext) ;
761
762}
763
764/*----------------------------------------------------------------------*/
765
766void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) {
767
768 MyViewContext.SetTextureEnv(ATexture) ;
769 MyView->SetContext(MyViewContext) ;
770
771}
772
773/*----------------------------------------------------------------------*/
774
775void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode) {
776
777 MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
778 MyView->SetContext(MyViewContext) ;
779
780}
781
782/*----------------------------------------------------------------------*/
783
784void V3d_View::SetFront() {
785
786 gp_Ax3 a = MyViewer->PrivilegedPlane();
787 Standard_Real xo,yo,zo,vx,vy,vz,xu,yu,zu;
788
789 a.Direction().Coord(vx,vy,vz);
790 a.YDirection().Coord(xu,yu,zu);
791 a.Location().Coord(xo,yo,zo);
792
793 if(SwitchSetFront)
794 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(-vx,-vy,-vz));
795 else
796 MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(vx,vy,vz));
797
798 SwitchSetFront = !SwitchSetFront;
799
800 MyViewOrientation.SetViewReferenceUp(Graphic3d_Vector(xu,yu,zu));
801 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(xo,yo,zo));
802
803 MyView->SetViewOrientation(MyViewOrientation) ;
804
805 ImmediateUpdate();
806
807}
808
809/*----------------------------------------------------------------------*/
810
811void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start) {
812
813 Standard_Real Ax = ax ;
814 Standard_Real Ay = ay ;
815 Standard_Real Az = az ;
816 Graphic3d_Vector Vpn,Vup ;
817 TColStd_Array2OfReal Matrix(0,3,0,3) ;
818 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
819
820 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
821 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
822 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
823 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
824 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
825 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
826
827 if( Start ) {
828 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
829 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
830 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
831 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
832 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
833 Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
834 }
835
836 InitMatrix(Matrix) ;
837
838 if( Ax != 0. ) RotAxis(MyViewReferencePoint,MyYscreenAxis,-Ax,Matrix);
839 if( Ay != 0. ) {
840 RotAxis(MyViewReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
841 Multiply(Matrix, Rmatrix, Matrix);
842 }
843 if( Az != 0. ) {
844 RotAxis(MyViewReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
845 Multiply(Matrix, Rmatrix, Matrix);
846 }
847 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
848 MyViewOrientation.SetViewReferencePlane(Vpn) ;
849 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
850 MyViewOrientation.SetViewReferenceUp(Vup) ;
851 MyView->SetViewOrientation(MyViewOrientation) ;
852#ifdef IMP020300
853 SetZSize(0.) ;
854#endif
855 ImmediateUpdate();
856
857}
858
859/*----------------------------------------------------------------------*/
860
861void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az,
862 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
863{
864
865 Standard_Real Ax = ax ;
866 Standard_Real Ay = ay ;
867 Standard_Real Az = az ;
868 Graphic3d_Vector Vpn,Vup ;
869 Graphic3d_Vertex Vrp ;
870 TColStd_Array2OfReal Matrix(0,3,0,3) ;
871 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
872
873 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
874 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
875 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
876 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
877 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
878 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
879
880 if( Start ) {
881 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
882 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
883 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
884 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
885 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
886 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
887 Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
888 }
889
890 InitMatrix(Matrix) ;
891
892 if( Ax != 0. ) RotAxis(MyGravityReferencePoint,MyYscreenAxis,-Ax,Matrix);
893 if( Ay != 0. ) {
894 RotAxis(MyGravityReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
895 Multiply(Matrix, Rmatrix, Matrix);
896 }
897 if( Az != 0. ) {
898 RotAxis(MyGravityReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
899 Multiply(Matrix, Rmatrix, Matrix);
900 }
901 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
902 MyViewOrientation.SetViewReferencePoint(Vrp) ;
903 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
904 MyViewOrientation.SetViewReferencePlane(Vpn) ;
905 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
906 MyViewOrientation.SetViewReferenceUp(Vup) ;
907 MyView->SetViewOrientation(MyViewOrientation) ;
908#ifdef IMP020300
909 SetZSize(0.) ;
910#endif
911 ImmediateUpdate();
912
913}
914
915/*----------------------------------------------------------------------*/
916
917void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) {
918
919 switch (Axe) {
920 case V3d_X :
921 Rotate(angle,0.,0.,Start);
922 break ;
923 case V3d_Y :
924 Rotate(0.,angle,0.,Start);
925 break ;
926 case V3d_Z :
927 Rotate(0.,0.,angle,Start);
928 break ;
929 }
930
931}
932
933/*----------------------------------------------------------------------*/
934
935void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
936 const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
937{
938
939 Standard_Real Angle = angle ;
940 Graphic3d_Vector Vpn,Vup ;
941 Graphic3d_Vertex Vrp ;
942 TColStd_Array2OfReal Matrix(0,3,0,3) ;
943
944 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
945 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
946
947 if( Start ) {
948 MyGravityReferencePoint.SetCoord(X,Y,Z) ;
949 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
950 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
951 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
952 switch (Axe) {
953 case V3d_X :
954 MyViewAxis.SetCoord(1.,0.,0.) ;
955 break ;
956 case V3d_Y :
957 MyViewAxis.SetCoord(0.,1.,0.) ;
958 break ;
959 case V3d_Z :
960 MyViewAxis.SetCoord(0.,0.,1.) ;
961 break ;
962 }
963 }
964
965 RotAxis(MyGravityReferencePoint,MyViewAxis,Angle,Matrix) ;
966 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
967 MyViewOrientation.SetViewReferencePoint(Vrp) ;
968 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
969 MyViewOrientation.SetViewReferencePlane(Vpn) ;
970 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
971 MyViewOrientation.SetViewReferenceUp(Vup) ;
972 MyView->SetViewOrientation(MyViewOrientation) ;
973#ifdef IMP020300
974 SetZSize(0.) ;
975#endif
976 ImmediateUpdate();
977
978}
979
980/*----------------------------------------------------------------------*/
981
982void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start) {
983
984 Standard_Real Angle = angle ;
985 Graphic3d_Vector Vpn,Vup ;
986 TColStd_Array2OfReal Matrix(0,3,0,3) ;
987
988 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
989 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
990
991 if( Start ) {
992 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
993 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
994 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
995 }
996
997 RotAxis(MyDefaultViewPoint,MyDefaultViewAxis,Angle,Matrix) ;
998#ifdef BUC60952
999 Graphic3d_Vertex Vrp ;
1000 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1001 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1002#endif
1003 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1004 MyViewOrientation.SetViewReferencePlane(Vpn) ;
1005 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1006 MyViewOrientation.SetViewReferenceUp(Vup) ;
1007 MyView->SetViewOrientation(MyViewOrientation) ;
1008#ifdef IMP020300
1009 SetZSize(0.) ;
1010#endif
1011 ImmediateUpdate();
1012
1013}
1014
1015/*----------------------------------------------------------------------*/
1016
1017void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
1018{
1019
1020 Standard_Real Ax = ax ;
1021 Standard_Real Ay = ay ;
1022 Standard_Real Az = az ;
1023 Graphic3d_Vertex Vrp,Eye ;
1024 Graphic3d_Vector Vpn,Vup ;
1025 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
1026 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1027 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
1028
1029 if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
1030 else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
1031 if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
1032 else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
1033 if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
1034 else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
1035
1036 if( Start ) {
1037 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1038 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1039 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1040 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1041 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1042 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
1043 Viewer_BadValue::Raise ("V3d_View::Turn, alignment of Eye,At,Up");
1044 }
1045
1046 InitMatrix(Matrix) ;
1047 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1048 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1049 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1050 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1051 Eye.SetCoord(Xeye,Yeye,Zeye) ;
1052 if( Ax != 0. ) RotAxis(Eye,MyYscreenAxis,-Ax,Matrix) ;
1053 if( Ay != 0. ) {
1054 RotAxis(Eye,MyXscreenAxis,Ay,Rmatrix) ;
1055 Multiply(Matrix, Rmatrix, Matrix);
1056 }
1057 if( Az != 0. ) {
1058 RotAxis(Eye,MyZscreenAxis,Az,Rmatrix) ;
1059 Multiply(Matrix, Rmatrix, Matrix);
1060 }
1061 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1062 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1063 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1064 MyViewOrientation.SetViewReferenceUp(Vpn) ;
1065 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1066 MyViewOrientation.SetViewReferenceUp(Vup) ;
1067 MyView->SetViewOrientation(MyViewOrientation) ;
1068#ifdef IMP020300
1069 SetZSize(0.) ;
1070#else
1071 // Check ZClipping planes
1072 Standard_Real Zmax ;
1073 Vrp.Coord(Xat,Yat,Zat) ;
1074 Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat) ;
1075 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1076 MyProjModel == V3d_TPM_SCREEN ) {
1077 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1078 }
1079#endif
1080 ImmediateUpdate();
1081
1082}
1083
1084/*----------------------------------------------------------------------*/
1085
1086void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
1087{
1088
1089 switch (Axe) {
1090 case V3d_X :
1091 Turn(angle,0.,0.,Start);
1092 break ;
1093 case V3d_Y :
1094 Turn(0.,angle,0.,Start);
1095 break ;
1096 case V3d_Z :
1097 Turn(0.,0.,angle,Start);
1098 break ;
1099 }
1100}
1101
1102void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start) {
1103 Standard_Real Angle = angle ;
1104 Graphic3d_Vertex Vrp,Eye ;
1105 Graphic3d_Vector Vpn,Vup ;
1106 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
1107 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1108
1109 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1110 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1111
1112 if( Start ) {
1113 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1114 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1115 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1116 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1117 }
1118 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1119 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1120 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1121 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1122 Eye.SetCoord(Xeye,Yeye,Zeye) ;
1123 RotAxis(Eye,MyDefaultViewAxis,Angle,Matrix) ;
1124 Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
1125 MyViewOrientation.SetViewReferencePoint(Vrp) ;
1126 Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
1127 MyViewOrientation.SetViewReferencePlane(Vpn) ;
1128 Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
1129 MyViewOrientation.SetViewReferenceUp(Vup) ;
1130 MyView->SetViewOrientation(MyViewOrientation) ;
1131#ifdef IMP020300
1132 SetZSize(0.) ;
1133#else
1134 // Check ZClipping planes
1135 Standard_Real Zmax ;
1136 Vrp.Coord(Xat,Yat,Zat) ;
1137 Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat ) ;
1138 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1139 MyProjModel == V3d_TPM_SCREEN ) {
1140 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1141 }
1142#endif
1143 ImmediateUpdate();
1144
1145}
1146
1147void V3d_View::SetTwist(const Standard_Real angle) {
1148
1149 Standard_Real Angle = angle ;
1150 TColStd_Array2OfReal Matrix(0,3,0,3) ;
1151 Standard_Boolean TheStatus ;
1152
1153 if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1154 else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1155
1156 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1157 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1158 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1159 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1160 if( !TheStatus ) {
1161 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1162 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1163 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1164 }
1165 if( !TheStatus ) {
1166 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1167 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1168 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1169 }
1170
1171 Viewer_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
1172
1173 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1174 RotAxis(MyViewReferencePoint,MyZscreenAxis,Angle,Matrix) ;
1175 MyViewReferenceUp = TrsPoint(MyYscreenAxis,Matrix) ;
1176 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1177 MyView->SetViewOrientation(MyViewOrientation) ;
1178 ImmediateUpdate();
1179
1180}
1181
1182#ifdef IMP240100
1183void V3d_View::SetProjModel( const V3d_TypeOfProjectionModel aModel )
1184{
1185
1186 MyProjModel = aModel;
1187
1188}
1189
1190V3d_TypeOfProjectionModel V3d_View::ProjModel() const {
1191
1192 return MyProjModel;
1193
1194}
1195#endif
1196
1197void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1198
1199 Standard_Real Angle,Xat,Yat,Zat,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn ;
1200 Angle = Twist() ;
1201 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1202 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1203 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1204 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1205 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
1206 Xpn = X - Xat ; Ypn = Y - Yat ; Zpn = Z - Zat ;
1207 Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
1208 Viewer_BadValue_Raise_if( Zrp <= 0. , "V3d_View::SetEye:: Eye,At are Confused");
1209
1210 Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
1211 MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
1212 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1213 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1214 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1215
1216 Standard_Boolean update = myImmediateUpdate;
1217 myImmediateUpdate = Standard_False;
1218 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1219 //FMN desactivation temp SetTwist(Angle) ;
1220 // Set infos.
1221 MyView->SetViewOrientation(MyViewOrientation) ;
1222 MyView->SetViewMapping(MyViewMapping) ;
1223 } else {
1224 SetTwist(Angle) ;
1225 }
1226#ifdef IMP020300
1227 SetZSize(0.) ;
1228#else
1229 // Check ZClipping planes
1230 Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
1231 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1232 MyProjModel == V3d_TPM_SCREEN ) {
1233 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1234 } else {
1235 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1236 MyView->SetViewMapping(MyViewMapping);
1237 }
1238#endif
1239 myImmediateUpdate = update;
1240 ImmediateUpdate();
1241
1242}
1243
1244void V3d_View::SetDepth(const Standard_Real Depth) {
1245
1246 Standard_Real Xrp,Yrp,Zrp ;
1247#ifdef IMP250200
1248 Viewer_BadValue_Raise_if( Depth == 0. ,"V3d_View::SetDepth, bad depth");
1249#else
1250 Viewer_BadValue_Raise_if( Depth <= 0. ,"V3d_View::SetDepth, bad depth");
1251#endif
1252
1253#ifdef DEB
1254 Standard_Real twist =
1255#endif
1256 Twist();
1257 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1258 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1259 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1260 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1261#ifdef IMP250200
1262 if( Depth > 0. )
1263#endif
1264 {
1265 Zrp = Depth;
1266 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1267 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1268 }
1269
1270 // Check ZClipping planes
1271 Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
1272 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1273 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1274#ifdef IMP250200
1275 if( Depth < 0. ) { // Move the view ref point instead of the eye.
1276 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1277 Zrp = Abs(Depth) ;
1278 Xat = Xeye - Xpn*Zrp ; Yat = Yeye - Ypn*Zrp ; Zat = Zeye - Zpn*Zrp;
1279 MyViewReferencePoint.SetCoord(Xat,Yat,Zat) ;
1280 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1281 MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
1282 MyView->SetViewOrientation(MyViewOrientation);
1283 }
1284#endif
1285#ifdef IMP020300
1286 MyView->SetViewMapping(MyViewMapping) ;
1287 SetZSize(0.) ;
1288#else
1289 Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
1290 Standard_Real Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1291
1292 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1293 MyProjModel == V3d_TPM_SCREEN ) {
1294 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1295 } else {
1296 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1297#ifdef IMP250200
1298 if( Depth > 0. )
1299#endif
1300 MyView->SetViewMapping(MyViewMapping) ;
1301 }
1302#endif
1303
1304 ImmediateUpdate();
1305
1306}
1307
1308
1309void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
1310{
1311
1312 Standard_Real Angle ;
1313
1314 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
1315 "V3d_View::SetProj, null projection vector");
1316
1317 Angle = Twist() ;
1318 MyViewReferencePlane.SetCoord(Vx,Vy,Vz) ;
1319 MyViewReferencePlane.Normalize() ;
1320 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1321 Standard_Boolean update = myImmediateUpdate;
1322 myImmediateUpdate = Standard_False;
1323 if( MyProjModel == V3d_TPM_SCREEN ) SetTwist(Angle) ;
1324#ifdef IMP020300
1325 SetZSize(0.) ;
1326#endif
1327 myImmediateUpdate = update;
1328 ImmediateUpdate();
1329
1330}
1331
1332void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation ) {
1333
1334 MyViewReferencePlane = V3d::GetProjAxis(Orientation) ;
1335 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1336 // MSV 14.03.2007: reset ViewReferencePoint to debug LH3D14955
1337 MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(0,0,0));
1338 Standard_Real Xpn=0;
1339 Standard_Real Ypn=0;
1340 Standard_Real Zpn=0;
1341
1342 switch (Orientation) {
1343 case V3d_Zpos :
1344 Ypn = 1. ;
1345 break ;
1346 case V3d_Zneg :
1347 Ypn = -1. ;
1348 break ;
1349 default:
1350 Zpn = 1.;
1351 }
1352 SetUp(Xpn,Ypn,Zpn);
1353#ifdef IMP020300
1354 SetZSize(0.) ;
1355#endif
1356 ImmediateUpdate();
1357
1358}
1359
1360void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
1361
1362 Standard_Real Angle,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
1363 Standard_Real Xeye,Yeye,Zeye ;
1364
1365 Angle = Twist() ;
1366 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1367 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1368 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1369 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1370 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
1371 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1372 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
1373 Xpn = Xeye - X ; Ypn = Yeye - Y ; Zpn = Zeye - Z ;
1374 Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
1375 Viewer_BadValue_Raise_if( Zrp <= 0.,
1376 "V3d_View::SetAt, Eye,At are Confused");
1377
1378 Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
1379 MyViewReferencePoint.SetCoord(X,Y,Z) ;
1380 MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
1381 MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
1382 MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
1383 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1384 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
1385 Standard_Boolean update = myImmediateUpdate;
1386 myImmediateUpdate = Standard_False;
1387 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
1388 //FMN desactivation temp SetTwist(Angle) ;
1389 // Set infos.
1390 MyView->SetViewOrientation(MyViewOrientation) ;
1391 MyView->SetViewMapping(MyViewMapping) ;
1392 } else {
1393 SetTwist(Angle) ;
1394 }
1395#ifdef IMP020300
1396 MyView->SetViewMapping(MyViewMapping);
1397 SetZSize(0.) ;
1398#else
1399 ImmediateUpdate();
1400 // Check ZClipping planes
1401 Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
1402 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
1403 MyProjModel == V3d_TPM_SCREEN ) {
1404 SetZSize(2.*Zmax+Zmax*Zmargin) ;
1405 } else {
1406 if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
1407 MyView->SetViewMapping(MyViewMapping);
1408 }
1409#endif
1410 myImmediateUpdate = update;
1411 ImmediateUpdate();
1412
1413}
1414
1415void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz) {
1416
1417 Standard_Boolean TheStatus ;
1418 Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
1419 "V3d_View::SetUp, nullUp vector");
1420
1421 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1422 MyViewReferenceUp.SetCoord(Vx,Vy,Vz) ;
1423 MyViewReferenceUp.Normalize() ;
1424 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1425 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1426 if( !TheStatus ) {
1427 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1428 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1429 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1430 }
1431 if( !TheStatus ) {
1432 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1433 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1434 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1435 }
1436 if( !TheStatus ) {
1437 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1438 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1439 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1440 }
1441 Viewer_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up");
1442
1443 MyViewReferenceUp = MyYscreenAxis ;
1444 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1445 MyView->SetViewOrientation(MyViewOrientation) ;
1446 ImmediateUpdate();
1447
1448}
1449
1450void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) {
1451
1452 Standard_Boolean TheStatus ;
1453
1454 MyViewReferenceUp = V3d::GetProjAxis(Orientation) ;
1455 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
1456 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1457 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1458 if( !TheStatus ) {
1459 MyViewReferenceUp.SetCoord(0.,0.,1.) ;
1460 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1461 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1462 }
1463 if( !TheStatus ) {
1464 MyViewReferenceUp.SetCoord(0.,1.,0.) ;
1465 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1466 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1467 }
1468 if( !TheStatus ) {
1469 MyViewReferenceUp.SetCoord(1.,0.,0.) ;
1470 TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
1471 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
1472 }
1473 Viewer_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up");
1474
1475 MyViewReferenceUp = MyYscreenAxis ;
1476 MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
1477 MyView->SetViewOrientation(MyViewOrientation) ;
1478 ImmediateUpdate();
1479
1480}
1481
1482void V3d_View::SetViewOrientation(const Visual3d_ViewOrientation& VO)
1483{
1484 MyViewOrientation = VO;
1485 MyView->SetViewOrientation(MyViewOrientation) ;
1486 ImmediateUpdate();
1487}
1488
1489void V3d_View::SetViewOrientationDefault() {
1490
1491 MyView->SetViewOrientation(MyViewOrientation) ;
1492 MyView->SetViewOrientationDefault() ;
1493 ImmediateUpdate();
1494}
1495
1496void V3d_View::ResetViewOrientation() {
1497
1498 MyView->ViewOrientationReset() ;
1499 MyViewOrientation = MyView->ViewOrientation() ;
1500 ImmediateUpdate();
1501}
1502
1503void V3d_View::Reset( const Standard_Boolean update ) {
1504
1505 MyView->ViewOrientationReset() ;
1506 MyViewOrientation = MyView->ViewOrientation() ;
1507 MyView->ViewMappingReset();
1508 MyViewMapping = MyView->ViewMapping() ;
1509
1510 ZFitAll (Zmargin);
1511 SwitchSetFront = Standard_False;
1512#ifdef IMP020300
1513 if( !myImmediateUpdate && update ) Update();
1514#else
1515 ImmediateUpdate();
1516#endif
1517
1518}
1519
1520void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start)
1521{
1522
1523 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp,Dxv,Dyv ;
1524 Viewer_BadValue_Raise_if( aZoomFactor <= 0.,"V3d_View::Panning, bad zoom factor");
1525
1526 if( Start ) {
1527 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1528 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1529 MyXwindowCenter = (Umin + Umax)/2. ;
1530 MyYwindowCenter = (Vmin + Vmax)/2. ;
1531 MyWindowWidth = Abs(Umax - Umin) ;
1532 MyWindowHeight = Abs(Vmax - Vmin) ;
1533 Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
1534 "V3d_View::Panning, Window Size is NULL");
1535 }
1536 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1537 Xrp = MyXwindowCenter - Dx ;
1538 Yrp = MyYwindowCenter - Dy ;
1539 Dxv = MyWindowWidth/aZoomFactor ; Dyv = MyWindowHeight/aZoomFactor ;
1540 Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
1541 Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
1542 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1543 if( MyType != V3d_PERSPECTIVE ) {
1544 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1545 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
1546 }
1547 MyView->SetViewMapping(MyViewMapping) ;
1548 ImmediateUpdate();
1549
1550}
1551void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y) {
1552 Standard_Real x,y;
1553 Convert(X,Y,x,y);
1554 SetCenter(x,y);
1555}
1556
1557void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc){
1558
1559 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp ;
1560
1561 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
1562 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1563 MyXwindowCenter = Xrp = Xc ; MyYwindowCenter = Yrp = Yc ;
1564 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1565 MyWindowWidth = Abs(Umax - Umin) ; MyWindowHeight = Abs(Vmax - Vmin) ;
1566 Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
1567 "V3d_View::SetCenter, Window Size is NULL");
1568
1569 Umin = Xc - MyWindowWidth/2. ; Vmin = Yc - MyWindowHeight/2. ;
1570 Umax = Xc + MyWindowWidth/2. ; Vmax = Yc + MyWindowHeight/2. ;
1571 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1572 if( MyType != V3d_PERSPECTIVE ) {
1573 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
1574 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
1575 }
1576 MyView->SetViewMapping(MyViewMapping) ;
1577 ImmediateUpdate();
1578
1579}
1580
1581void V3d_View::SetSize(const Standard_Real Size)
1582{
1583
1584 Standard_Real Umin,Vmin,Umax,Vmax,Rap ;
1585
1586 Viewer_BadValue_Raise_if( Size <= 0.,
1587 "V3d_View::SetSize, Window Size is NULL");
1588
1589
1590 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1591 MyWindowWidth = Abs(Umax - Umin) ;
1592 MyWindowHeight = Abs(Vmax - Vmin) ;
1593 MyXwindowCenter = (Umin + Umax)/2. ;
1594 MyYwindowCenter = (Vmin + Vmax)/2. ;
1595 Rap = MyWindowWidth/MyWindowHeight ;
1596 if( MyWindowWidth >= MyWindowHeight ) {
1597 MyWindowWidth = Size ; MyWindowHeight = Size/Rap ;
1598 } else {
1599 MyWindowHeight = Size ; MyWindowWidth = Size*Rap ;
1600 }
1601 Umin = MyXwindowCenter - MyWindowWidth/2. ;
1602 Vmin = MyYwindowCenter - MyWindowHeight/2. ;
1603 Umax = MyXwindowCenter + MyWindowWidth/2. ;
1604 Vmax = MyYwindowCenter + MyWindowHeight/2. ;
1605 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1606 MyView->SetViewMapping(MyViewMapping) ;
1607 ImmediateUpdate();
1608
1609}
1610
1611void V3d_View::SetZSize(const Standard_Real Size)
1612{
1613
1614 Standard_Real Zmax = Size/2.;
1615
1616#ifdef IMP020300
1617 if( Size <= 0. ) {
1618 Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye;
1619 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
1620 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
1621 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
1622 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat;
1623 Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
1624 if( Zmax <= MyViewMapping.FrontPlaneDistance() ) return;
1625 }
1626#else
1627 Viewer_BadValue_Raise_if( Size <= 0.,
1628 "V3d_View::SetZSize, Window ZSize is NULL");
1629#endif
1630
1631 Standard_Real Front = MyViewContext.ZClippingFrontPlane() ;
1632 Standard_Real Back = MyViewContext.ZClippingBackPlane() ;
1633 Standard_Real focale= Focale();
1634
1635 MyViewMapping.SetFrontPlaneDistance(Zmax) ;
1636 MyViewMapping.SetBackPlaneDistance(-Zmax) ;
1637
1638 // OCC18942
1639 if( MyProjModel != V3d_TPM_WALKTHROUGH ) {
1640 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : Zmax) ;
1641 }
1642
1643 MyView->SetViewMapping(MyViewMapping) ;
1644 if( MyViewContext.FrontZClippingIsOn() ||
1645 MyViewContext.BackZClippingIsOn() ) {
1646 MyViewContext.SetZClippingFrontPlane(Front) ;
1647 MyViewContext.SetZClippingBackPlane(Back) ;
1648 MyView->SetContext(MyViewContext) ;
1649 }
1650
1651}
1652
1653void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
1654{
1655
1656 Standard_Real Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
1657 Viewer_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
1658
1659 if( Start ) {
1660 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1661 MyXwindowCenter = (Umin + Umax)/2. ;
1662 MyYwindowCenter = (Vmin + Vmax)/2. ;
1663 MyWindowWidth = Abs(Umax - Umin) ;
1664 MyWindowHeight = Abs(Vmax - Vmin) ;
1665 }
1666
1667 // ensure that zoom will not be too small or too big
1668 Standard_Real coef = Coef;
1669 if ( MyWindowWidth < coef * Precision::Confusion() )
1670 coef = MyWindowWidth / Precision::Confusion();
1671 else if ( MyWindowWidth > coef * 1e12 )
1672 coef = MyWindowWidth / 1e12;
1673 if ( MyWindowHeight < coef * Precision::Confusion() )
1674 coef = MyWindowHeight / Precision::Confusion();
1675 else if ( MyWindowHeight > coef * 1e12 )
1676 coef = MyWindowHeight / 1e12;
1677
1678 Dxv = MyWindowWidth/coef;
1679 Dyv = MyWindowHeight/coef;
1680 Umin = MyXwindowCenter - Dxv/2. ; Umax = MyXwindowCenter + Dxv/2. ;
1681 Vmin = MyYwindowCenter - Dyv/2. ; Vmax = MyYwindowCenter + Dyv/2. ;
1682 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1683 MyView->SetViewMapping(MyViewMapping) ;
1684 ImmediateUpdate();
1685}
1686
1687void V3d_View::SetScale( const Standard_Real Coef ) {
1688 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Dxv,Dyv ;
1689 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
1690
1691 Viewer_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
1692
1693 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1694 Dxv = Abs(Umax - Umin) ; Dyv = Abs(Vmax - Vmin) ;
1695 Dxv /= Coef ; Dyv /= Coef ;
1696 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
1697 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
1698 Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
1699 Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
1700 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
1701 MyView->SetViewMapping(MyViewMapping) ;
1702 ImmediateUpdate();
1703
1704}
1705
1706void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz ) {
1707
1708 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1709 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1710 Viewer_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
1711
1712 MyViewOrientation.SetAxialScale( Sx, Sy, Sz );
1713 Aspect_TypeOfUpdate updateMode = MyView->ViewManager()->UpdateMode();
1714 MyView->ViewManager()->SetUpdateMode(Aspect_TOU_ASAP);
1715 MyView->SetViewOrientation(MyViewOrientation);
1716 MyView->ViewManager()->SetUpdateMode(updateMode);
1717
1718 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1719
1720 Standard_Real LIM = ShortRealLast() -1.;
1721 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1722 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
1723 return;
1724 }
1725
1726 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
1727 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
1728 Umax = Max(Umin,Umax) ; Vmax = Max(Vmin,Vmax) ;
1729 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
1730 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1731 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1732 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
1733 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1734 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1735 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
1736 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1737 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1738 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
1739 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1740 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1741 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
1742 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1743 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1744 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
1745 Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
1746 Umax = Max(Umax,Vmax) ;
1747 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1748 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1749 Wmax = Max(Abs(Umax),Abs(Wmax)) ;
1750
1751 if( Wmax > 0. ) {
1752 SetZSize(2.*Wmax + Wmax) ;
1753 }
1754
1755}
1756
1757void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean FitZ,
1758 const Standard_Boolean update)
1759{
35617823
K
1760 Standard_Real Umin, Umax, Vmin, Vmax, Xrp, Yrp, Zrp, U, V, W, U1, V1, W1;
1761 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
1762 Standard_Real DxvOld, DyvOld, DxvNew, DyvNew;
1763 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures();
7fd59977 1764
35617823
K
1765 if ((Nstruct <= 0) || (Coef < 0.0) || (Coef > 1.0))
1766 {
7fd59977 1767#ifndef IMP020300
1768 ImmediateUpdate();
1769#endif
35617823 1770 return;
7fd59977 1771 }
7fd59977 1772
35617823
K
1773 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
1774 MyProjReferencePoint.Coord (Xrp, Yrp, Zrp);
1775 if (MyView->IsDefined())
1776 {
1777 Standard_Integer Xpixel, Ypixel;
1778 MyWindow->Size (Xpixel, Ypixel);
1779 DxvOld = Xpixel;
1780 DyvOld = Ypixel;
7fd59977 1781 }
35617823
K
1782 else
1783 {
1784 MyViewMapping.WindowLimit (Umin, Vmin, Umax, Vmax);
1785 DxvOld = Abs (Umax - Umin);
1786 DyvOld = Abs (Vmax - Vmin);
7fd59977 1787 }
35617823
K
1788 if ((DxvOld == 0.0) || (DyvOld == 0.0))
1789 {
1790 return;
7fd59977 1791 }
1792
35617823
K
1793 Standard_Real aWinRatio = DxvOld / DyvOld;
1794
1795 // retrieve min / max values for current displayed objects
1796 MyView->MinMaxValues (Xmin, Ymin, Zmin,
1797 Xmax, Ymax, Zmax);
1798
1799 Standard_Real LIM = ShortRealLast() - 1.0;
1800 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1801 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM)
1802 {
7fd59977 1803#ifndef IMP020300
35617823 1804 ImmediateUpdate();
7fd59977 1805#endif
35617823
K
1806 return;
1807 }
7fd59977 1808
35617823
K
1809 // eliminate fluctuations between sequential FitAll() calls
1810 MyViewMapping.SetWindowLimit (-1.0 * aWinRatio, -1.0, 1.0 * aWinRatio, 1.0);
1811 if (MyType != V3d_PERSPECTIVE)
1812 {
1813 MyProjReferencePoint.SetCoord (0.0, 0.0, Zrp);
1814 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1815 }
1816 MyView->SetViewMapping (MyViewMapping);
1817
1818 // iterate 2 times to find optimal view plane size
1819 // (use view plane values computed on previous iteration)
1820 for (Standard_Integer aIteration = 2; aIteration > 0; --aIteration)
1821 {
1822 MyView->Projects (Xmin, Ymin, Zmin, U, V, W);
1823 MyView->Projects (Xmax, Ymax, Zmax, U1, V1, W1);
1824 Umin = Min (U, U1); Umax = Max (U, U1);
1825 Vmin = Min (V, V1); Vmax = Max (V, V1);
1826
1827 MyView->Projects (Xmin, Ymin, Zmax, U, V, W);
1828 Umin = Min (U, Umin); Umax = Max (U, Umax);
1829 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1830
1831 MyView->Projects (Xmax, Ymin, Zmax, U, V, W);
1832 Umin = Min (U, Umin); Umax = Max (U, Umax);
1833 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1834
1835 MyView->Projects (Xmax, Ymin, Zmin, U, V, W);
1836 Umin = Min (U, Umin); Umax = Max (U, Umax);
1837 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1838
1839 MyView->Projects (Xmax, Ymax, Zmin, U, V, W);
1840 Umin = Min (U, Umin); Umax = Max (U, Umax);
1841 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
7fd59977 1842
35617823
K
1843 MyView->Projects (Xmin, Ymax, Zmax, U, V, W);
1844 Umin = Min (U, Umin); Umax = Max (U, Umax);
1845 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
7fd59977 1846
35617823
K
1847 MyView->Projects (Xmin, Ymax, Zmin, U, V, W);
1848 Umin = Min (U, Umin); Umax = Max (U, Umax);
1849 Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
1850
1851 DxvNew = Abs (Umax - Umin);
1852 DyvNew = Abs (Vmax - Vmin);
1853
1854 if (DyvNew < 10.0 * Precision::Confusion())
1855 {
1856 if (DxvNew < 10.0 * Precision::Confusion())
1857 {
1858 // whole scene projected to point
1859 DxvNew = Max (Abs (Zmax - Zmin), (Max (Abs (Xmax - Xmin), Abs (Ymax - Ymin))));
1860 if (DxvNew < 10.0 * Precision::Confusion())
1861 {
1862 // this is really just one (!) point and zooming has no any effect
1863 // just center the view
1864 DyvNew = DyvOld;
1865 DxvNew = DxvOld;
7fd59977 1866 }
35617823
K
1867 else
1868 {
1869 // we look along some line
1870 // fit view like that to see whole scene on rotation
1871 DxvNew += Coef * DxvNew;
1872 DyvNew = DxvNew / aWinRatio;
1873 }
1874 }
1875 else
1876 {
1877 // whole scene projected to horizontal line
1878 DxvNew += Coef * DxvNew;
1879 DyvNew = DxvNew / aWinRatio;
7fd59977 1880 }
35617823
K
1881 }
1882 else
1883 {
1884 // general case (or DxvNew == 0.0 - vertical line)
1885 // safe original ratio
1886 Standard_Real aFitRatio = DxvNew / DyvNew;
1887 if (aFitRatio >= aWinRatio)
1888 {
1889 DxvNew += Coef * DxvNew;
1890 DyvNew = DxvNew / aWinRatio;
1891 }
1892 else
1893 {
1894 DyvNew += Coef * DyvNew;
1895 DxvNew = DyvNew * aWinRatio;
1896 }
1897 }
7fd59977 1898
35617823
K
1899 // new scene center
1900 Xrp = 0.5 * (Umin + Umax);
1901 Yrp = 0.5 * (Vmin + Vmax);
7fd59977 1902
35617823
K
1903 // new window limits
1904 Umin = Xrp - 0.5 * DxvNew;
1905 Umax = Xrp + 0.5 * DxvNew;
1906 Vmin = Yrp - 0.5 * DyvNew;
1907 Vmax = Yrp + 0.5 * DyvNew;
1908 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
1909
1910 if (MyType != V3d_PERSPECTIVE)
1911 {
1912 // center the view
1913 MyProjReferencePoint.SetCoord (Xrp, Yrp, Zrp);
1914 MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
1915 }
1916 MyView->SetViewMapping (MyViewMapping);
1917 }
1918
1919 if (FitZ)
1920 {
1921 ZFitAll (Zmargin);
7fd59977 1922#ifdef IMP020300
35617823
K
1923 }
1924 else
1925 {
1926 ImmediateUpdate();
7fd59977 1927#endif
35617823 1928 }
7fd59977 1929#ifdef IMP020300
35617823
K
1930 if (!myImmediateUpdate && update)
1931 {
1932 Update();
1933 }
7fd59977 1934#endif
1935}
1936
1937void V3d_View::ZFitAll(const Standard_Real Coef) {
1938
1939 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
1940 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1941 // CAL 6/11/98
1942 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1943
1944 if( MyType == V3d_PERSPECTIVE ) {
1945 ImmediateUpdate();
1946 return ;
1947 }
1948
1949 if( (Nstruct <= 0) || (Coef < 0.) ) {
1950 ImmediateUpdate();
1951 return ;
1952 }
1953
1954 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
1955
1956 Standard_Real LIM = ShortRealLast() -1.;
1957 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
1958 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
1959 ImmediateUpdate();
1960 return ;
1961 }
1962
7fd59977 1963 // CAL 6/11/98
1964 // Case when view contains only a point
1965 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
1966 ImmediateUpdate();
1967 return ;
1968 }
1969 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
1970 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
1971 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
1972 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1973 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
1974 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1975 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
1976 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1977 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
1978 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1979 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
1980 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1981 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
1982 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1983 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1984 if( Wmax > 0. ) {
1985 SetZSize(2.*Wmax + Coef * Wmax) ;
1986 }
1987 ImmediateUpdate();
1988}
1989
1990void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
1991 const Quantity_Coefficient Margin)
1992{
1993 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ;
1994 Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1995 Standard_Real Xrp,Yrp,Zrp,Dx,Dy,Dz,Size;
1996
1997 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
1998
1999 if( (Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
2000 ImmediateUpdate();
2001 return ;
2002 }
2003
2004 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2005 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2006
2007 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2008
2009 Standard_Real LIM = ShortRealLast() -1.;
2010 if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
2011 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
2012 ImmediateUpdate();
2013 return ;
2014 }
2015
7fd59977 2016 if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
2017 ImmediateUpdate();
2018 return ;
2019 }
2020 MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
2021 MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ;
2022 Umin = Min(U,U1) ; Umax = Max(U,U1) ;
2023 Vmin = Min(V,V1) ; Vmax = Max(V,V1) ;
2024 Wmin = Min(W,W1) ; Wmax = Max(W,W1) ;
2025 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2026 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2027 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2028 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2029 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2030 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2031 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2032 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2033 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2034 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2035 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2036 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2037 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2038 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2039 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2040 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2041 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2042 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2043 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2044 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2045 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2046 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2047 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2048 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2049
2050 // Adjust Z size
2051 Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
2052 Dz = 2.*Wmax + Margin * Wmax;
2053
2054 // Compute depth value
2055 Dx = Abs(Umax - Umin) ; Dy = Abs(Vmax - Vmin) ; // Dz = Abs(Wmax - Wmin);
2056 Dx += Margin * Dx; Dy += Margin * Dy;
2057 Size = Sqrt(Dx*Dx + Dy*Dy + Dz*Dz);
2058 if( Size > 0. ) {
2059 SetZSize(Size) ;
2060 SetDepth( Aspect * Size / 2.);
2061 }
2062
2063 ImmediateUpdate();
2064}
2065
2066void V3d_View::FitAll(const Standard_Real Xmin, const Standard_Real Ymin, const Standard_Real Xmax, const Standard_Real Ymax) {
2067 FitAll(MyWindow,Xmin,Ymin,Xmax,Ymax);
2068#ifndef IMP020300
2069 ImmediateUpdate();
2070#endif
2071}
2072
2073void V3d_View::WindowFitAll(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) {
2074 WindowFit(Xmin,Ymin,Xmax,Ymax);
2075
2076}
2077void V3d_View::WindowFit(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) {
2078 Standard_Real x1,y1,x2,y2;
2079 Convert(Xmin,Ymin,x1,y1);
2080 Convert(Xmax,Ymax,x2,y2);
2081 FitAll(x1,y1,x2,y2);
2082}
2083
2084void V3d_View::SetViewMapping(const Visual3d_ViewMapping& VM)
2085{
2086 MyViewMapping = VM;
2087 // ajust view type according to mapping projection
2088 // NOTE: Might be dangerous, potentially conflicts with the C++ view class
2089 // (orthographic or perspective)! Use with care!
2090 if ( VM.Projection() == Visual3d_TOP_PERSPECTIVE )
2091 MyType = V3d_PERSPECTIVE;
2092 else MyType = V3d_ORTHOGRAPHIC;
2093
2094 MyView->SetViewMapping(MyViewMapping) ;
2095 ImmediateUpdate();
2096}
2097
2098void V3d_View::SetViewMappingDefault() {
2099 MyView->SetViewMapping(MyViewMapping) ;
2100 MyView->SetViewMappingDefault();
2101 ImmediateUpdate();
2102}
2103
2104void V3d_View::ResetViewMapping() {
2105
2106 MyView->ViewMappingReset();
2107 MyViewMapping = MyView->ViewMapping() ;
2108#ifdef IMP020300
2109 ZFitAll (Zmargin);
2110 Update();
2111#else
2112 ImmediateUpdate();
2113#endif
2114}
2115
2116Standard_Real V3d_View::Convert(const Standard_Integer Vp) const {
2117 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Vv ;
2118 Standard_Integer Dxw,Dyw ;
2119
2120 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2121
2122 MyWindow->Size(Dxw,Dyw);
2123 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2124 Dxv = Umax - Umin ;
2125 Vv = Dxv*(Standard_Real)Vp/(Standard_Real)Dxw ;
2126
2127 return Vv ;
2128}
2129
2130void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xv, Standard_Real& Yv) const {
2131 Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Dyv ;
2132 Standard_Integer Dxw,Dyw ;
2133
2134 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2135
2136 MyWindow->Size(Dxw,Dyw);
2137 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2138 Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
2139 Xv = Umin + Dxv*(Standard_Real)Xp/(Standard_Real)Dxw ;
2140 Yv = Vmin + Dyv*(Standard_Real)(Dyw-Yp)/(Standard_Real)Dyw ;
2141}
2142
2143Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
2144{
2145 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2146
2147 Standard_Integer Dxw, Dyw;
2148 MyWindow->Size(Dxw,Dyw);
2149
2150 Standard_Real Umin,Umax,Vmin,Vmax;
2151 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2152 Standard_Real Dxv = Umax - Umin;
2153 return RealToInt ( Dxw * Vv / Dxv );
2154}
2155
2156void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const
2157{
2158 V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
2159
2160 Standard_Integer Dxw, Dyw;
2161 MyWindow->Size(Dxw,Dyw);
2162
2163 Standard_Real Umin,Umax,Vmin,Vmax;
2164 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2165 Standard_Real Dxv = Umax - Umin;
2166 Standard_Real Dyv = Vmax - Vmin;
2167
2168 // CAL 15/12/93 warning: double assigned to int
2169 Xp = RealToInt (Dxw*(Xv - Umin)/Dxv);
2170 // CAL 15/12/93 warning: double assigned to int
2171 Yp = Dyw - RealToInt (Dyw*(Yv - Vmin)/Dyv);
2172}
2173
2174void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2175
2176 Graphic3d_Vertex Vrp ;
2177 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2178 Vrp.Coord(X,Y,Z) ;
2179#ifndef IMP240100
2180 if( MyViewer->Grid()->IsActive() ) {
2181 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2182 NewVrp.Coord(X,Y,Z) ;
2183 }
2184#endif
2185}
2186
2187void V3d_View::ConvertWithProj(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z, Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
2188{
2189 Graphic3d_Vertex Vrp ;
2190 Graphic3d_Vector Proj ;
2191 (MyViewer->Viewer())->ConvertCoordWithProj(MyWindow,Xp,Yp, Vrp, Proj) ;
2192 Vrp.Coord(X,Y,Z) ;
2193 Proj.Coord(Dx,Dy,Dz) ;
2194#ifndef IMP240100
2195 if( MyViewer->Grid()->IsActive() ) {
2196 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2197 NewVrp.Coord(X,Y,Z) ;
2198 }
2199#endif
2200}
2201
2202#ifdef IMP240100
2203void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const {
2204
2205 Graphic3d_Vertex Vrp ;
2206 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2207 if( MyViewer->Grid()->IsActive() ) {
2208 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2209 NewVrp.Coord(Xg,Yg,Zg) ;
2210 } else
2211 Vrp.Coord(Xg,Yg,Zg) ;
2212}
2213
2214void V3d_View::ConvertToGrid(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const {
2215
2216 if( MyViewer->Grid()->IsActive() ) {
2217 Graphic3d_Vertex Vrp(X,Y,Z) ;
2218 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2219 NewVrp.Coord(Xg,Yg,Zg) ;
2220 } else {
2221 Xg = X; Yg = Y; Zg = Z;
2222 }
2223}
2224#endif
2225
2226#ifndef IMP240100
2227void V3d_View::PixToRef(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2228
2229 Graphic3d_Vertex Vrp ;
2230 Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
2231 Vrp.Coord(X,Y,Z) ;
2232 if( MyViewer->Grid()->IsActive() ) {
2233 Graphic3d_Vertex NewVrp = Compute(Vrp) ;
2234 NewVrp.Coord(X,Y,Z) ;
2235 }
2236}
2237#endif
2238
2239#ifdef IMP240100
2240void V3d_View::Convert(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2241#else
2242void V3d_View::RefToPix(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
2243#endif
2244
2245 Graphic3d_Vertex Vrp(X,Y,Z) ;
2246 (MyViewer->Viewer())->ConvertCoord(MyWindow,Vrp,Xp,Yp) ;
2247}
2248
2249void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const
2250{
2251 if ( MyType != V3d_PERSPECTIVE )
2252 {
2253 // use old implementation
2254 Standard_Real Zp;
2255 MyView->Projects( X, Y, Z, Xp, Yp, Zp );
2256 }
2257 else
2258 {
2259 // NKV - Using raster projection
2260 Standard_Integer Xpx, Ypx;
2261 Convert(X, Y, Z, Xpx, Ypx);
2262 Convert(Xpx, Ypx, Xp, Yp);
2263 }
2264}
2265
2266void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3)const {
2267
2268#ifdef GER61351
2269 Quantity_Color C = BackgroundColor() ;
2270#else
2271 Quantity_Color C ;
2272 C = MyBackground.Color() ;
2273#endif
2274 C.Values(V1,V2,V3,Type) ;
2275}
2276
2277#ifdef GER61351
2278Quantity_Color V3d_View::BackgroundColor() const {
2279
2280 return MyBackground.Color() ;
2281}
2282#endif
2283
2284void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const{
2285 MyGradientBackground.Colors(Color1, Color2);
2286}
2287
2288Aspect_GradientBackground V3d_View::GradientBackground() const {
2289 return MyGradientBackground;
2290}
2291
2292Standard_Real V3d_View::Scale()const {
2293 Standard_Real Umin,Vmin,Umax,Vmax,Dxv ;
2294 Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
2295 Standard_Real S = 0. ;
2296
2297 VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2298 Dxv = Umax - Umin ;
2299 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2300 if( Umax > Umin && Vmax > Vmin ) S = Dxv/(Umax - Umin) ;
2301 return S ;
2302}
2303
2304void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz)const {
2305 MyViewOrientation.AxialScale( Sx, Sy, Sz );
2306}
2307
2308void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const {
2309
2310 Standard_Real Umin,Vmin,Umax,Vmax ;
2311
2312 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2313 Xc = (Umin + Umax)/2. ;
2314 Yc = (Vmin + Vmax)/2. ;
2315}
2316
2317void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const {
2318
2319 Standard_Real Umin,Vmin,Umax,Vmax ;
2320
2321 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2322 Width = Umax - Umin ;
2323 Height = Vmax - Vmin ;
2324}
2325
2326Standard_Real V3d_View::ZSize() const {
2327
2328 Standard_Real Wmin,Wmax,Depth ;
2329
2330 Wmax = MyViewMapping.FrontPlaneDistance() ;
2331 Wmin = MyViewMapping.BackPlaneDistance() ;
2332 Depth = 2. * Max(Wmin,Wmax) ;
2333 return (Depth) ;
2334}
2335
2336Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const {
2337
2338 Standard_Real Wmin,Wmax,U,V,W ;
2339 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
2340 // CAL 6/11/98
2341 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2342
2343 if( Nstruct ) {
2344 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2345 MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
2346 MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
2347 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2348 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2349 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2350 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2351 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2352 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2353 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2354 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2355 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2356 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2357 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2358 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2359 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2360 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2361 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2362 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2363 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2364 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2365 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2366 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2367 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2368 Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2369 Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2370 Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2371 }
2372 return Nstruct ;
2373}
2374
2375Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Standard_Real& Zmin, Standard_Real& Xmax, Standard_Real& Ymax, Standard_Real& Zmax) const {
2376 // CAL 6/11/98
2377 // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
2378 Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
2379
2380 if( Nstruct ) {
2381 MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
2382 }
2383 return Nstruct ;
2384}
2385
2386Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2387
2388 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
2389 Standard_Real Umin,Vmin,Umax,Vmax ;
2390 Standard_Integer Nstruct,Npoint ;
2391 Graphic3d_MapOfStructure MySetOfStructures;
2392
2393 MyView->DisplayedStructures (MySetOfStructures);
2394 Nstruct = MySetOfStructures.Extent() ;
2395
2396 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
2397
2398 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
2399 Npoint = 0 ; X = Y = Z = 0. ;
2400 for( ; MyIterator.More(); MyIterator.Next()) {
2401 if (!(MyIterator.Key())->IsEmpty()) {
2402 (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
2403 Xmax,Ymax,Zmax) ;
2404
2405 Standard_Real LIM = ShortRealLast() -1.;
2406 if (! (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
2407 || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM )) {
2408
2409 MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
2410 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2411 Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmin ;
2412 }
2413 MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
2414 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2415 Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmin ;
2416 }
2417 MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
2418 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2419 Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmin ;
2420 }
2421 MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
2422 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2423 Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmin ;
2424 }
2425 MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
2426 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2427 Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmax ;
2428 }
2429 MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
2430 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2431 Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmax ;
2432 }
2433 MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
2434 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2435 Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmax ;
2436 }
2437 MyView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
2438 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
2439 Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmax ;
2440 }
2441 }
2442 }
2443 }
2444 if( Npoint > 0 ) {
2445 X /= Npoint ; Y /= Npoint ; Z /= Npoint ;
2446 }
2447
2448 return Nstruct ;
2449}
2450
2451void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2452 Graphic3d_Vertex Prp ;
2453 Graphic3d_Vector Vpn ;
2454 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
2455
2456 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
2457 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
2458 Prp = MyViewMapping.ProjectionReferencePoint() ;
2459 Prp.Coord(Xrp,Yrp,Zrp) ;
2460 Vpn = MyViewOrientation.ViewReferencePlane() ;
2461 Vpn.Coord(Xpn,Ypn,Zpn) ;
2462 X = Zrp*Xpn + Xat; Y = Zrp*Ypn + Yat; Z = Zrp*Zpn + Zat;
2463}
2464
2465void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const {
2466
2467 Graphic3d_Vertex PRP,VRPoint;
2468 Graphic3d_Vector VRPlane;
2469 Standard_Real FPD,Xprp,Yprp,Zprp;
2470 Standard_Real Xvrp,Yvrp,Zvrp,DXvrp,DYvrp,DZvrp;
2471
2472 if ( MyType == V3d_PERSPECTIVE ) {
2473 PRP = MyViewMapping.ProjectionReferencePoint() ;
2474 FPD = MyViewMapping.FrontPlaneDistance();
2475 PRP.Coord(Xprp,Yprp,Zprp);
2476 VRPoint = MyViewOrientation.ViewReferencePoint();
2477 VRPoint.Coord(Xvrp,Yvrp,Zvrp);
2478 VRPlane = MyViewOrientation.ViewReferencePlane();
2479 VRPlane.Coord(DXvrp,DYvrp,DZvrp);
2480 X = (FPD + Zprp) * DXvrp + Xvrp;
2481 Y = (FPD + Zprp) * DYvrp + Yvrp;
2482 Z = (FPD + Zprp) * DZvrp + Zvrp;
2483 }
2484 else Eye(X,Y,Z);
2485}
2486
2487void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix, const Standard_Integer Ypix, Standard_Real& XP, Standard_Real& YP, Standard_Real& ZP, Standard_Real& VX, Standard_Real& VY, Standard_Real& VZ) const {
2488
2489 Standard_Real Xo,Yo,Zo;
2490
2491 Convert(Xpix,Ypix,XP,YP,ZP);
2492 if ( MyType == V3d_PERSPECTIVE ) {
2493 FocalReferencePoint(Xo,Yo,Zo);
2494 VX = Xo - XP;
2495 VY = Yo - YP;
2496 VZ = Zo - ZP;
2497 }
2498 else {
2499 Proj(VX,VY,VZ);
2500 }
2501}
2502
2503
2504Standard_Real V3d_View::Depth() const {
2505 Graphic3d_Vertex Prp ;
2506 Standard_Real Xrp,Yrp,Zrp ;
2507
2508 Prp = MyViewMapping.ProjectionReferencePoint() ;
2509 Prp.Coord(Xrp,Yrp,Zrp) ;
2510 return Zrp ;
2511}
2512
2513void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const {
2514 Graphic3d_Vector Vpn ;
2515
2516 Vpn = MyViewOrientation.ViewReferencePlane() ;
2517 Vpn.Coord(Dx,Dy,Dz) ;
2518}
2519
2520void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
2521 Graphic3d_Vertex Vrp ;
2522
2523 Vrp = MyViewOrientation.ViewReferencePoint() ;
2524 Vrp.Coord(X,Y,Z) ;
2525}
2526
2527void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const {
2528 Graphic3d_Vector Vup ;
2529
2530 Vup = MyViewOrientation.ViewReferenceUp() ;
2531 Vup.Coord(Vx,Vy,Vz) ;
2532}
2533
2534Standard_Real V3d_View::Twist()const {
2535 Standard_Real Xup,Yup,Zup,Xpn,Ypn,Zpn,X0,Y0,Z0 ;
2536 Standard_Real pvx,pvy,pvz,pvn,sca,angle ;
2537 Graphic3d_Vector Vpn,Vup,Xaxis,Yaxis,Zaxis ;
2538 Standard_Boolean TheStatus ;
2539
2540 Vpn = MyViewOrientation.ViewReferencePlane() ;
2541 Vpn.Coord(Xpn,Ypn,Zpn) ;
2542 Vup.SetCoord(0.,0.,1.) ;
2543 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2544 if( !TheStatus ) {
2545 Vup.SetCoord(0.,1.,0.) ;
2546 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2547 }
2548 if( !TheStatus ) {
2549 Vup.SetCoord(1.,0.,0.) ;
2550 TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
2551 }
2552 Yaxis.Coord(X0,Y0,Z0) ;
2553 Vup = MyViewOrientation.ViewReferenceUp() ;
2554 Vup.Coord(Xup,Yup,Zup) ;
2555 /* Compute Cross Vector From Up & Origin */
2556 pvx = Y0*Zup - Z0*Yup ;
2557 pvy = Z0*Xup - X0*Zup ;
2558 pvz = X0*Yup - Y0*Xup ;
2559 pvn = pvx*pvx + pvy*pvy + pvz*pvz ;
2560 sca = X0*Xup + Y0*Yup + Z0*Zup ;
2561 /* Compute Angle */
2562 angle = Sqrt(pvn) ;
2563 if( angle > 1. ) angle = 1. ;
2564 else if( angle < -1. ) angle = -1. ;
2565 angle = asin(angle) ;
c6541a0c
D
2566 if( sca < 0. ) angle = M_PI - angle ;
2567 if( angle > 0. && angle < M_PI ) {
7fd59977 2568 sca = pvx*Xpn + pvy*Ypn + pvz*Zpn ;
2569 if( sca < 0. ) angle = DEUXPI - angle ;
2570 }
2571 return angle ;
2572}
2573
2574V3d_TypeOfShadingModel V3d_View::ShadingModel()const {
2575 V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
2576 return SM ;
2577}
2578
2579V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail()const {
2580 V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
2581 return SM ;
2582}
2583
2584
2585Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const {
2586 Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
2587 return SM ;
2588}
2589
2590V3d_TypeOfVisualization V3d_View::Visualization()const {
2591 V3d_TypeOfVisualization V =
2592 (V3d_TypeOfVisualization)MyViewContext.Visualization() ;
2593 return V ;
2594}
2595
2596Standard_Boolean V3d_View::Antialiasing()const {
2597 Standard_Boolean A = MyViewContext.AliasingIsOn() ;
2598 return A ;
2599}
2600
2601Handle(V3d_Viewer) V3d_View::Viewer() const {
2602 return MyViewer ;
2603}
2604
2605Standard_Boolean V3d_View::IfWindow() const {
2606 Standard_Boolean TheStatus = MyView->IsDefined() ;
2607 return TheStatus ;
2608}
2609
2610Handle(Aspect_Window) V3d_View::Window() const {
2611 return MyWindow;
2612}
2613
2614V3d_TypeOfView V3d_View::Type() const {
2615
2616 return (MyType) ;
2617}
2618
2619void V3d_View::SetFocale( const Standard_Real focale ) {
2620
2621 Standard_TypeMismatch_Raise_if (MyType != V3d_PERSPECTIVE,
2622 "the view is not a perspective view");
2623 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2624 Graphic3d_Vertex Prp ;
2625 Prp = MyViewMapping.ProjectionReferencePoint() ;
2626 Prp.Coord(Xrp,Yrp,Zrp) ;
2627 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
2628 ViewPlane = Zrp - focale ;
2629 } else {
2630 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2631 ViewPlane = FrontPlane + Zrp - focale ;
2632 }
2633 MyViewMapping.SetViewPlaneDistance(ViewPlane) ;
2634 MyView->SetViewMapping(MyViewMapping) ;
2635
2636 ImmediateUpdate();
2637}
2638
2639Standard_Real V3d_View::Focale( ) const {
2640 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
2641 Standard_Real focale = 0.0 ;
2642 Graphic3d_Vertex Prp ;
2643
2644 if( MyType == V3d_PERSPECTIVE ) {
2645 Prp = MyViewMapping.ProjectionReferencePoint() ;
2646 Prp.Coord(Xrp,Yrp,Zrp) ;
2647 ViewPlane = MyViewMapping.ViewPlaneDistance() ;
2648 if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
2649 focale = Zrp - ViewPlane ;
2650 } else {
2651 FrontPlane = MyViewMapping.FrontPlaneDistance() ;
2652 focale = FrontPlane + Zrp - ViewPlane ;
2653 }
2654 }
2655 return (focale) ;
2656}
2657
2658void V3d_View::SetViewingVolume(const Standard_Real Left, const Standard_Real Right,
2659 const Standard_Real Bottom, const Standard_Real Top,
2660 const Standard_Real ZNear, const Standard_Real ZFar)
2661{
2662 Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp;
2663
2664 Viewer_BadValue_Raise_if ( ZNear <= 0. || ZFar <= 0. || ZNear >= ZFar, "V3d_View::SetVolume, bad distances");
2665
2666 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
2667 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
2668 Zrp = ZNear;
2669
2670 Standard_Real size = (ZFar - ZNear) / 2.;
2671
2672 MyViewMapping.SetFrontPlaneDistance(size);
2673 MyViewMapping.SetBackPlaneDistance(-size);
2674
2675 // keep view plane at front plane distance
2676 MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : size);
2677
2678 // set window limits
2679 Umin = Left; Umax = Right;
2680 Vmin = Bottom; Vmax = Top;
2681 MyViewMapping.SetWindowLimit(Left, Bottom, Right, Top);
2682
2683 // Update window center
2684 if ( MyType == V3d_PERSPECTIVE ) {
2685 Xrp = Yrp = 0.0;
2686 }
2687 else {
2688 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
2689 }
2690 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
2691 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
2692
2693 MyView->SetViewMapping(MyViewMapping) ;
2694 // SetZSize(0.);
2695 ImmediateUpdate();
2696}
2697
2698Handle(Visual3d_View) V3d_View::View() const
2699{
2700 return MyView ;
2701}
2702
2703Visual3d_ViewMapping V3d_View::ViewMapping() const
2704{
2705 return MyViewMapping;
2706}
2707
2708Visual3d_ViewOrientation V3d_View::ViewOrientation() const
2709{
2710 return MyViewOrientation;
2711}
2712
2713Standard_Boolean V3d_View::ScreenAxis( const Graphic3d_Vector &Vpn, const Graphic3d_Vector &Vup, Graphic3d_Vector &Xaxe, Graphic3d_Vector &Yaxe, Graphic3d_Vector &Zaxe) {
2714 Standard_Real Xpn,Ypn,Zpn,Xup,Yup,Zup ;
2715 Standard_Real dx1,dy1,dz1,dx2,dy2,dz2,xx,yy,zz ;
2716
2717 Vpn.Coord(Xpn,Ypn,Zpn) ;
2718 Vup.Coord(Xup,Yup,Zup) ;
2719 xx = Yup*Zpn - Zup*Ypn ;
2720 yy = Zup*Xpn - Xup*Zpn ;
2721 zz = Xup*Ypn - Yup*Xpn ;
2722 Xaxe.SetCoord(xx,yy,zz) ;
2723 if( Xaxe.LengthZero() ) return Standard_False;
2724 Xaxe.Normalize() ; Xaxe.Coord(dx1,dy1,dz1) ;
2725 xx = Ypn*dz1 - Zpn*dy1 ;
2726 yy = Zpn*dx1 - Xpn*dz1 ;
2727 zz = Xpn*dy1 - Ypn*dx1 ;
2728 Yaxe.SetCoord(xx,yy,zz) ;
2729 if( Yaxe.LengthZero() ) return Standard_False;
2730 Yaxe.Normalize() ; Yaxe.Coord(dx2,dy2,dz2) ;
2731 xx = dy1*dz2 - dz1*dy2 ;
2732 yy = dz1*dx2 - dx1*dz2 ;
2733 zz = dx1*dy2 - dy1*dx2 ;
2734 Zaxe.SetCoord(xx,yy,zz) ;
2735 if( Zaxe.LengthZero() ) return Standard_False;
2736 Zaxe.Normalize() ;
2737 return Standard_True ;
2738}
2739
2740void V3d_View::InitMatrix( TColStd_Array2OfReal& Matrix ) {
2741 Standard_Integer LR = Matrix.LowerRow() ;
2742 Standard_Integer UR = Matrix.UpperRow() ;
2743 Standard_Integer LC = Matrix.LowerCol() ;
2744 Standard_Integer UC = Matrix.UpperCol() ;
2745 Standard_Integer I,J ;
2746
2747 for( I=LR ; I<=UR ; I++ ) {
2748 for( J=LC ; J<=UC ; J++ ) Matrix(I,J) = 0. ;
2749 }
2750 for( I=LR,J=LC ; I<=UR ; I++,J++ ) Matrix(I,J) = 1. ;
2751}
2752
2753Standard_Boolean V3d_View::Multiply (const TColStd_Array2OfReal& Left, const TColStd_Array2OfReal& Right, TColStd_Array2OfReal& Matrix) {
2754
2755 Standard_Integer llr = Left.LowerRow ();
2756 Standard_Integer llc = Left.LowerCol ();
2757 Standard_Integer luc = Left.UpperCol ();
2758
2759 Standard_Integer rlr = Right.LowerRow ();
2760 Standard_Integer rur = Right.UpperRow ();
2761 Standard_Integer rlc = Right.LowerCol ();
2762
2763 Standard_Integer mlr = Matrix.LowerRow ();
2764 Standard_Integer mur = Matrix.UpperRow ();
2765 Standard_Integer mlc = Matrix.LowerCol ();
2766 Standard_Integer muc = Matrix.UpperCol ();
2767
2768 TColStd_Array2OfReal Result (mlr, mur, mlc, muc);
2769
2770 InitMatrix (Result);
2771
2772 // Left et Right incompatibles
2773 if (luc - llc + 1 != rur - rlr + 1)
2774 return Standard_False;
2775
2776 Standard_Integer i, j, k;
2777
2778 Standard_Real Som;
2779 Standard_Integer I1 = llr;
2780
2781 for (i=mlr; i<=mur; i++) {
2782 Standard_Integer J2 = rlc;
2783 for (j=mlc; j<=muc; j++) {
2784 Som = 0.0;
2785 Standard_Integer J1 = llc;
2786 Standard_Integer I2 = rlr;
2787 for (k=llc; k<=luc; k++) {
2788 Som = Som + Left (I1, J1) * Right (I2, J2);
2789 J1++;
2790 I2++;
2791 }
2792 Result (i, j) = Som;
2793 J2++;
2794 }
2795 I1++;
2796 }
2797
2798 for (i=mlr; i<=mur; i++)
2799 for (j=mlc; j<=muc; j++)
2800 Matrix (i, j) = Result (i, j);
2801
2802 return Standard_True;
2803}
2804
2805/*----------------------------------------------------------------------*/
2806
2807void V3d_View::RotAxis( const Graphic3d_Vertex &Vrp, const Graphic3d_Vector &Axe, const Standard_Real angle, TColStd_Array2OfReal& Matrix ) {
2808 Standard_Real Xrp,Yrp,Zrp,Xaxe,Yaxe,Zaxe ;
2809 Standard_Real sina,cosa,cos1m,terms1,terms2,terms3 ;
2810 Standard_Real termc12,termc13,termc23,vcal ;
2811 TColStd_Array2OfReal Tmatrix(0,3,0,3) ;
2812 TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
2813
2814 InitMatrix(Matrix) ;
2815 InitMatrix(Tmatrix) ;
2816
2817 Vrp.Coord(Xrp,Yrp,Zrp) ;
2818 Axe.Coord(Xaxe,Yaxe,Zaxe) ;
2819 /* translation of x,y,z */
2820 Tmatrix(0,3) = Xrp ; Tmatrix(1,3) = Yrp ; Tmatrix(2,3) = Zrp ;
2821 /* rotation around an axis */
2822 cosa = cos(angle); sina = sin(angle); cos1m = 1. - cosa ;
2823 termc12 = Xaxe * Yaxe * cos1m ;
2824 termc13 = Xaxe * Zaxe * cos1m ;
2825 termc23 = Yaxe * Zaxe * cos1m ;
2826 terms1 = Xaxe * sina ;
2827 terms2 = Yaxe * sina ;
2828 terms3 = Zaxe * sina ;
2829
2830 vcal = Xaxe * Xaxe ;
2831 Rmatrix(0,0) = vcal + ( 1. - vcal ) * cosa ;
2832 Rmatrix(1,0) = termc12 + terms3 ;
2833 Rmatrix(2,0) = termc13 - terms2 ;
2834 Rmatrix(3,0) = 0. ;
2835 Rmatrix(0,1) = termc12 - terms3 ;
2836 vcal = Yaxe * Yaxe ;
2837 Rmatrix(1,1) = vcal + ( 1. - vcal ) * cosa ;
2838 Rmatrix(2,1) = termc23 + terms1 ;
2839 Rmatrix(3,1) = 0. ;
2840 Rmatrix(0,2) = termc13 + terms2 ;
2841 Rmatrix(1,2) = termc23 - terms1 ;
2842 vcal = Zaxe * Zaxe ;
2843 Rmatrix(2,2) = vcal + ( 1. - vcal ) * cosa ;
2844 Rmatrix(3,2) = 0. ;
2845 Rmatrix(0,3) = 0. ;
2846 Rmatrix(1,3) = 0. ;
2847 Rmatrix(2,3) = 0. ;
2848 Rmatrix(3,3) = 1. ;
2849 /* produced by two matrices */
2850 Multiply(Tmatrix, Rmatrix, Matrix);
2851 /* translation invert */
2852 Tmatrix(0,3) = -Xrp;
2853 Tmatrix(1,3) = -Yrp;
2854 Tmatrix(2,3) = -Zrp;
2855 /* product final */
2856 Multiply(Matrix, Tmatrix, Matrix);
2857}
2858
2859/*----------------------------------------------------------------------*/
2860
2861Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Array2OfReal &Matrix ) {
2862 Graphic3d_Vertex PP ;
2863 Standard_Real X,Y,Z,XX,YY,ZZ ;
2864
2865 // CAL. S3892
2866 Standard_Integer lr, ur, lc, uc;
2867 lr = Matrix.LowerRow ();
2868 ur = Matrix.UpperRow ();
2869 lc = Matrix.LowerCol ();
2870 uc = Matrix.UpperCol ();
2871 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
2872 P.Coord(X,Y,Z) ;
2873 PP.SetCoord(X,Y,Z) ;
2874 return PP ;
2875 }
2876 P.Coord(X,Y,Z) ;
2877 XX = (Matrix(lr,lc+3) + X*Matrix(lr,lc) + Y*Matrix(lr,lc+1)+
2878 Z*Matrix(lr,lc+2))/Matrix(lr+3,lc+3) ;
2879
2880 YY = (Matrix(lr+1,lc+3) + X*Matrix(lr+1,lc) + Y*Matrix(lr+1,lc+1) +
2881 Z*Matrix(lr+1,lc+2))/Matrix(lr+3,lc+3) ;
2882
2883 ZZ = (Matrix(lr+2,lc+3) + X*Matrix(lr+2,lc) + Y*Matrix(lr+2,lc+1) +
2884 Z*Matrix(lr+2,lc+2))/Matrix(lr+3,lc+3) ;
2885 PP.SetCoord(XX,YY,ZZ) ;
2886 return PP ;
2887}
2888
2889Graphic3d_Vector V3d_View::TrsPoint( const Graphic3d_Vector& V, const TColStd_Array2OfReal& Matrix ) {
2890 Graphic3d_Vector VV ;
2891 Standard_Real X,Y,Z,XX,YY,ZZ ;
2892
2893 // CAL. S3892
2894 Standard_Integer lr, ur, lc, uc;
2895 lr = Matrix.LowerRow ();
2896 ur = Matrix.UpperRow ();
2897 lc = Matrix.LowerCol ();
2898 uc = Matrix.UpperCol ();
2899 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
2900 V.Coord(X,Y,Z) ;
2901 VV.SetCoord(X,Y,Z) ;
2902 return VV ;
2903 }
2904 V.Coord(X,Y,Z) ;
2905 XX = X*Matrix(lr,lc)+Y*Matrix(lr,lc+1)+Z*Matrix(lr,lc+2) ;
2906 YY = X*Matrix(lr+1,lc)+Y*Matrix(lr+1,lc+1)+Z*Matrix(lr+1,lc+2) ;
2907 ZZ = X*Matrix(lr+2,lc)+Y*Matrix(lr+2,lc+1)+Z*Matrix(lr+2,lc+2) ;
2908 VV.SetCoord(XX,YY,ZZ) ; VV.Normalize() ;
2909 return VV ;
2910}
2911
2912
2913void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor) {
2914
2915 Panning(Convert(Dx),Convert(Dy),aZoomFactor,Standard_True);
2916
2917}
2918
2919void V3d_View::Zoom (const Standard_Integer X1,
2920 const Standard_Integer Y1,
2921 const Standard_Integer X2,
2922 const Standard_Integer Y2)
2923{
2924
2925 Standard_Real dx = Standard_Real (X2-X1);
2926 Standard_Real dy = Standard_Real (Y2-Y1);
2927 if ( dx != 0. || dy != 0. ) {
2928 Standard_Real dzoom = Sqrt(dx*dx + dy*dy) / 100. + 1;
2929 dzoom = (dx > 0) ? dzoom : 1./dzoom;
2930 SetZoom(dzoom, Standard_True);
2931 }
2932}
2933
2934void V3d_View::Zoom (const Standard_Integer X1,
2935 const Standard_Integer Y1)
2936{
2937 Standard_Real x,y;
2938 Center(x,y);
2939 Standard_Integer ix,iy;
2940 Convert(x,y,ix,iy);
2941 Zoom(ix,iy,X1,Y1);
2942}
2943
2944// Defines the point (pixel) of zooming (for the method ZoomAtPoint()).
2945void V3d_View::StartZoomAtPoint(const Standard_Integer xpix, const Standard_Integer ypix)
2946{
2947 MyZoomAtPointX = xpix;
2948 MyZoomAtPointY = ypix;
2949}
2950
2951// Zooms the model at a pixel defined by the method StartZoomAtPoint().
2952void V3d_View::ZoomAtPoint(const Standard_Integer mouseStartX,
2953 const Standard_Integer mouseStartY,
2954 const Standard_Integer mouseEndX,
2955 const Standard_Integer mouseEndY)
2956{
2957 Standard_Boolean update;
2958 V3d_Coordinate X0, Y0, XS, YS;
2959
2960 // Forbid any update.
2961 update = SetImmediateUpdate(Standard_False);
2962
2963 // Get center point
2964 Center(X0, Y0);
2965
2966 // Pan the point to the center of window.
2967 Convert(MyZoomAtPointX, MyZoomAtPointY, XS, YS);
2968 Panning(X0-XS, Y0-YS);
2969
2970 // Zoom
2971 Standard_Real d = Standard_Real ((mouseEndX + mouseEndY) - (mouseStartX + mouseStartY));
2972
2973 Standard_Real dzoom = fabs(d) / 100.0 + 1.0;
2974 dzoom = (d > 0) ? dzoom : 1.0 / dzoom;
2975 Viewer_BadValue_Raise_if( dzoom <= 0.,"V3d_View::ZoomAtPoint, bad coefficient");
2976
2977 Standard_Real Umin,Vmin,Umax,Vmax;
2978 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax);
2979
2980 MyXwindowCenter = (Umin + Umax) / 2.0;
2981 MyYwindowCenter = (Vmin + Vmax) / 2.0;
2982 MyWindowWidth = Abs(Umax - Umin);
2983 MyWindowHeight = Abs(Vmax - Vmin);
2984
2985 // Ensure that zoom will not be too small or too big.
2986 Standard_Real coef = dzoom;
2987 if (MyWindowWidth < coef * Precision::Confusion())
2988 coef = MyWindowWidth / Precision::Confusion();
2989 else if (MyWindowWidth > coef * 1e12)
2990 coef = MyWindowWidth / 1e12;
2991 if (MyWindowHeight < coef * Precision::Confusion())
2992 coef = MyWindowHeight / Precision::Confusion();
2993 else if (MyWindowHeight > coef * 1e12)
2994 coef = MyWindowHeight / 1e12;
2995
2996 Standard_Real Dxv = MyWindowWidth / coef;
2997 Standard_Real Dyv = MyWindowHeight / coef;
2998
2999 Umin = MyXwindowCenter - Dxv/2.0; Umax = MyXwindowCenter + Dxv/2.0;
3000 Vmin = MyYwindowCenter - Dyv/2.0; Vmax = MyYwindowCenter + Dyv/2.0;
3001
3002 // Pan the point backwards.
3003 Dxv = (XS - X0) / coef;
3004 Dyv = (YS - Y0) / coef;
3005
3006 MyXwindowCenter = (Umin + Umax) / 2.0;
3007 MyYwindowCenter = (Vmin + Vmax) / 2.0;
3008 MyWindowWidth = Abs(Umax - Umin);
3009 MyWindowHeight = Abs(Vmax - Vmin);
3010
3011 Standard_Real Xrp,Yrp,Zrp;
3012 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
3013 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp);
3014
3015 Xrp = MyXwindowCenter - Dxv;
3016 Yrp = MyYwindowCenter - Dyv;
3017
3018 Umin = Xrp - MyWindowWidth / 2.0; Umax = Xrp + MyWindowWidth / 2.0;
3019 Vmin = Yrp - MyWindowHeight / 2.0; Vmax = Yrp + MyWindowHeight / 2.0;
3020
3021 // Set new reference plane coordintes of the window.
3022 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax);
3023 if (MyType != V3d_PERSPECTIVE)
3024 {
3025 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp);
3026 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
3027 }
3028 MyView->SetViewMapping(MyViewMapping);
3029
3030 // Update the view.
3031 SetImmediateUpdate(update);
3032 ImmediateUpdate();
3033}
3034
3035void V3d_View::AxialScale (const Standard_Integer Dx,
3036 const Standard_Integer Dy,
3037 const V3d_TypeOfAxe Axis)
3038{
3039 if( Dx != 0. || Dy != 0. ) {
3040 Standard_Real Sx, Sy, Sz;
3041 AxialScale( Sx, Sy, Sz );
3042 Standard_Real dscale = Sqrt(Dx*Dx + Dy*Dy) / 100. + 1;
3043 dscale = (Dx > 0) ? dscale : 1./dscale;
3044 if( Axis == V3d_X ) Sx = dscale;
3045 if( Axis == V3d_Y ) Sy = dscale;
3046 if( Axis == V3d_Z ) Sz = dscale;
3047 SetAxialScale( Sx, Sy, Sz );
3048 }
3049}
3050
3051void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow,
3052 const Standard_Real Xmin,
3053 const Standard_Real Ymin,
3054 const Standard_Real Xmax,
3055 const Standard_Real Ymax)
3056{
3057
3058 Standard_Real Umin,Umax,Vmin,Vmax,Xrp,Yrp,Zrp ;
3059 Standard_Real DxvOld,DyvOld,DxvNew,DyvNew,RapOld,RapNew ;
3060 Standard_Integer Xpixel,Ypixel;
3061 //Standard_Integer Xleft,Yup,Xright,Ylow ;
3062
3063 Viewer_BadValue_Raise_if( (Xmin == Xmax) || (Ymin == Ymax) ,
3064 "V3d_View::FitAll, Window Size is NULL");
3065
3066 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
3067 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
3068 aWindow->Size(Xpixel,Ypixel);
3069 DxvOld = Xpixel; DyvOld = Ypixel;
3070
3071 if( (DxvOld == 0.) || (DyvOld == 0.) ) return ;
3072 RapOld = DxvOld/DyvOld ;
3073 DxvNew = Abs(Xmax - Xmin) ; DyvNew = Abs(Ymax - Ymin) ;
3074 RapNew = DxvNew/DyvNew ;
3075 if( RapNew >= RapOld ) {
3076 DyvNew = DxvNew/RapOld ;
3077 } else {
3078 DxvNew = DyvNew*RapOld ;
3079 }
3080 Xrp = (Xmin + Xmax)/2. ; Yrp = (Ymin + Ymax)/2. ;
3081 Umin = Xrp - DxvNew/2. ; Vmin = Yrp - DyvNew/2. ;
3082 Umax = Xrp + DxvNew/2. ; Vmax = Yrp + DyvNew/2. ;
3083 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
3084 if( MyType != V3d_PERSPECTIVE ) {
3085 MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
3086 MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
3087 }
3088 MyView->SetViewMapping(MyViewMapping) ;
3089#ifdef IMP020300
3090 Update();
3091#else
3092 ImmediateUpdate();
3093#endif
3094}
3095
3096#ifdef IMP250900
3097static Standard_Boolean zRotation = Standard_False;
3098#endif
3099void V3d_View::StartRotation(const Standard_Integer X,
3100 const Standard_Integer Y,
3101 const Quantity_Ratio zRotationThreshold)
3102{
3103
3104 sx = X; sy = Y;
3105 Standard_Real x,y;
3106 Size(x,y);
3107 rx = Standard_Real(Convert(x));
3108 ry = Standard_Real(Convert(y));
3109 Gravity(gx,gy,gz);
3110 Rotate(0.,0.,0.,gx,gy,gz,Standard_True);
3111#ifdef IMP250900
3112 zRotation = Standard_False;
3113 if( zRotationThreshold > 0. ) {
3114 Standard_Real dx = Abs(sx - rx/2.);
3115 Standard_Real dy = Abs(sy - ry/2.);
3116 // if( dx > rx/3. || dy > ry/3. ) zRotation = Standard_True;
3117 Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
3118 if( dx > dd || dy > dd ) zRotation = Standard_True;
3119 }
3120#endif
3121
3122}
3123
3124void V3d_View::Rotation(const Standard_Integer X,
3125 const Standard_Integer Y)
3126{
3127
3128#ifdef IMP210600
3129 if( rx == 0. || ry == 0. ) {
3130 StartRotation(X,Y);
3131 return;
3132 }
3133#endif
3134#ifdef IMP250900
3135 Standard_Real dx=0.,dy=0.,dz=0.;
3136 if( zRotation ) {
3137 dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
3138 atan2(sx-rx/2.,ry/2.-sy);
3139 } else {
c6541a0c
D
3140 dx = (Standard_Real(X) - sx) * M_PI / rx;
3141 dy = (sy - Standard_Real(Y)) * M_PI / ry;
7fd59977 3142 }
3143 Rotate(dx, dy, dz, gx, gy, gz, Standard_False);
3144#else
c6541a0c
D
3145 Standard_Real dx = (Standard_Real(X - sx)) * M_PI;
3146 Standard_Real dy = (Standard_Real(sy - Y)) * M_PI;
7fd59977 3147 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3148#endif
3149#ifdef IMP020300
3150 if( !myImmediateUpdate ) Update();
3151#else
3152 myImmediateUpdate = Standard_False;
3153 Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
3154 ZFitAll (Zmargin); //Don't do that, perf improvment
3155 myImmediateUpdate = Standard_True;
3156 ImmediateUpdate();
3157#endif
3158}
3159
3160void V3d_View::SetAnimationModeOn () {
3161#ifdef G003
3162 if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
3163 if( ComputedMode() ) { // Deactivates computed mode during animation
3164 MyAnimationFlags |= V3d_FLAG_COMPUTATION;
3165 Standard_Boolean immediatUpdate = myImmediateUpdate;
3166 myImmediateUpdate = Standard_False;
3167 SetComputedMode(Standard_False);
3168 myImmediateUpdate = immediatUpdate;
3169 }
3170 MyView -> SetAnimationModeOn ( MyAnimationFlags & V3d_FLAG_DEGENERATION );
3171 }
3172#else
3173 MyView->SetAnimationModeOn();
3174#endif
3175}
3176
3177void V3d_View::SetAnimationModeOff () {
3178#ifdef G003
3179 if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
3180 MyView -> SetAnimationModeOff ();
3181 if ( MyAnimationFlags & V3d_FLAG_COMPUTATION ) {
3182 // Reactivates computed mode after animation
3183 MyAnimationFlags &= ~V3d_FLAG_COMPUTATION;
3184 SetComputedMode(Standard_True);
3185 } else if( MyAnimationFlags & V3d_FLAG_DEGENERATION ) {
3186 Update();
3187 }
3188 }
3189#else
3190 MyView->SetAnimationModeOff();
3191#endif
3192}
3193
3194Standard_Boolean V3d_View::AnimationModeIsOn () const {
3195 return MyView->AnimationModeIsOn();
3196}
3197
3198#ifdef G003
3199void V3d_View :: SetAnimationMode
3200(
3201 const Standard_Boolean anAnimationFlag,
3202 const Standard_Boolean aDegenerationFlag
3203 )
3204{
3205
3206 if ( anAnimationFlag )
3207 MyAnimationFlags |= V3d_FLAG_ANIMATION;
3208 else
3209 MyAnimationFlags &= ~V3d_FLAG_ANIMATION;
3210
3211 if ( aDegenerationFlag )
3212 MyAnimationFlags |= V3d_FLAG_DEGENERATION;
3213 else
3214 MyAnimationFlags &= ~V3d_FLAG_DEGENERATION;
3215
3216} // end V3d_View :: SetAnimationMode
3217
3218Standard_Boolean V3d_View::AnimationMode( Standard_Boolean& isDegenerate ) const
3219{
3220
3221 isDegenerate = MyAnimationFlags & V3d_FLAG_DEGENERATION;
3222 return MyAnimationFlags & V3d_FLAG_ANIMATION;
3223}
3224#endif
3225
3226void V3d_View::SetDegenerateModeOn() {
3227#ifdef G003
3228 SetComputedMode(Standard_False);
3229#else
3230 MyView->SetDegenerateModeOn();
3231 ImmediateUpdate();
3232#endif
3233}
3234
3235void V3d_View::SetDegenerateModeOff()
3236{
3237#ifdef G003
3238 SetComputedMode(Standard_True);
3239#else
3240 if(myComputedMode) {
3241 MyView->SetDegenerateModeOff();
3242 ImmediateUpdate();
3243 }
3244#endif
3245}
3246
3247Standard_Boolean V3d_View::DegenerateModeIsOn() const
3248{
3249#ifdef G003
3250 return !ComputedMode();
3251#else
3252 return MyView->DegenerateModeIsOn();
3253#endif
3254}
3255
3256#ifdef G003
3257void V3d_View :: SetComputedMode ( const Standard_Boolean aMode )
3258{
3259
3260 if( aMode ) {
3261 if( myComputedMode ) {
3262 MyView -> SetComputedMode ( Standard_True );
3263 Update ();
3264 }
3265 } else {
3266 MyView -> SetComputedMode ( Standard_False );
3267 Update ();
3268 }
3269
3270} // end V3d_View :: SetComputedMode
3271
3272Standard_Boolean V3d_View :: ComputedMode () const
3273{
3274
3275 return MyView -> ComputedMode ();
3276
3277} // end V3d_View :: ComputedMode
3278
3279void V3d_View :: SetBackFacingModel (
3280 const V3d_TypeOfBackfacingModel aModel)
3281{
3282
3283 MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) );
3284 Redraw();
3285} // end V3d_View :: SetBackFacingModel
3286
3287V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const {
3288
3289 return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
3290
3291} // end V3d_View :: BackFacingModel
3292#endif
3293
3294Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const {
3295 return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode);
3296}
3297
3298void V3d_View::TransientManagerClearDraw() const {
3299 Visual3d_TransientManager::ClearDraw(MyView);
3300}
3301
3302Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const {
3303 return Visual3d_TransientManager::BeginAddDraw(MyView);
3304}
3305
3306void V3d_View::Init() {
3307 myComputedMode = MyViewer->ComputedMode();
3308#ifdef G003
3309 if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
3310 SetComputedMode(Standard_False);
3311 }
3312#else
3313 if(!myComputedMode)
3314 MyView->SetDegenerateModeOn();
3315 else
3316 if(!MyViewer->DefaultComputedMode()) MyView->SetDegenerateModeOn();
3317#endif
3318
3319#ifdef IMP240100
3320 OSD_Environment env_walkthrow("CSF_WALKTHROUGH");
3321 env_walkthrow.SetName( "CSF_WALKTHROUGH" );
3322 if ( env_walkthrow.Value () != "" ) MyProjModel = V3d_TPM_WALKTHROUGH;
3323 else MyProjModel = V3d_TPM_SCREEN;
3324#endif
3325
3326}
3327
3328void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter) {
3329 MyPlotter = aPlotter;
3330}
3331
3332void V3d_View::Plot()
3333{
3334
3335 Viewer_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter");
3336
3337 MyView->Plot(MyPlotter);
3338}
3339
3340Standard_Real V3d_View::Tumble (const Standard_Integer NbImages, const Standard_Boolean AnimationMode)
3341{
3342
3343 FullTimer.Reset ();
3344 FullTimer.Start ();
3345
3346 if (AnimationMode) MyView->SetAnimationModeOn();
3347 Standard_Integer i;
3348 Standard_Real delta = 0.01;
3349 Standard_Real xangle, yangle;
3350 xangle = yangle = delta*int(NbImages/3);
3351
3352 Rotate (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_True);
3353 for (i=1; i<=int(NbImages/3); i++)
3354 Rotate (delta*i, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_False);
3355 for (i=1; i<=int(NbImages/3); i++)
3356 Rotate (xangle, delta*i, 0.0, 0.0, 0.0, 0.0, Standard_False);
3357 for (i=1; i<=int(NbImages/3); i++)
3358 Rotate (xangle, yangle, delta*i, 0.0, 0.0, 0.0, Standard_False);
3359 if (AnimationMode) MyView->SetAnimationModeOff();
3360
3361 FullTimer.Stop ();
3362 cout << "For " << NbImages << " Images : " << endl;
3363 FullTimer.Show (cout);
3364 cout << flush;
3365
3366 Standard_Real Seconds, CPUtime;
3367 Standard_Integer Minutes, Hours;
3368
3369 FullTimer.Show (Seconds, Minutes, Hours, CPUtime);
3370 cout << "Result " << (AnimationMode ? "with " : "without ")
3371 << "display list : " << NbImages/CPUtime << " images/Second."
3372 << endl;
3373
3374 return NbImages/CPUtime;
3375
3376}
3377
3378#define SCREENCOPY_FILENAME "screencopy3d.gif"
3379void V3d_View::ScreenCopy (const Handle(PlotMgt_PlotterDriver)& aPlotterDriver,
3380 const Standard_Boolean fWhiteBackground,
3381 const Quantity_Factor aPlotScale)
3382{
3383 TCollection_AsciiString aFileToDump;
3384 Handle(Aspect_WindowDriver) aWindowDriver =
3385#ifdef WNT
3386 new WNT_WDriver (Handle(WNT_Window)::DownCast(MyWindow));
3387#else
3388 new Xw_Driver (Handle(Xw_Window)::DownCast(MyWindow));
3389#endif // WNT
3390 Quantity_Factor aScale;
3391 Quantity_Length thePixel;
3392 Quantity_Parameter theWWidth, theWHeight;
3393 Quantity_Parameter thePWidth, thePHeight;
3394 aPlotterDriver -> WorkSpace (thePWidth, thePHeight);
3395 aWindowDriver -> WorkSpace (theWWidth, theWHeight);
3396 thePixel = aWindowDriver -> Convert (1);
3397
3398 if (theWWidth * theWHeight != 0.) {
3399 if (aPlotScale == 0.) {
3400 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3401 } else {
3402 // To be changed !!!!!!!!!!!!!!!
3403 aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
3404 }
3405
3406 // Set default maps (color, type, etc) for plotter driver
3407 aPlotterDriver -> SetColorMap ( new Aspect_GenericColorMap () );
3408 aPlotterDriver -> SetTypeMap ( new Aspect_TypeMap () );
3409 aPlotterDriver -> SetWidthMap ( new Aspect_WidthMap () );
3410 aPlotterDriver -> SetFontMap ( new Aspect_FontMap () );
3411 aPlotterDriver -> SetMarkMap ( new Aspect_MarkMap () );
3412
3413 // Set backgroung to white, unihiglight if any
3414 Quantity_Parameter theRed, theGreen, theBlue;
3415 Handle(TColStd_HSequenceOfInteger) theFlags;
3416 Graphic3d_MapOfStructure theStructures;
3417 BackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
3418 if (fWhiteBackground)
3419 SetBackgroundColor (Quantity_NOC_WHITE);
3420 MyView -> DisplayedStructures (theStructures);
3421 theFlags = new TColStd_HSequenceOfInteger ();
3422 Graphic3d_MapIteratorOfMapOfStructure Iterator (theStructures);
3423 while (Iterator.More ()) {
3424 Handle(Graphic3d_Structure) aStructure = Iterator.Key();
3425 if (aStructure -> IsHighlighted()) {
3426 theFlags -> Append (1);
3427 aStructure -> UnHighlight ();
3428 } else {
3429 theFlags -> Append (0);
3430 }
3431 Iterator.Next ();
3432 }
3433 Redraw ();
3434
3435 // Dump the view
3436 if (aPlotterDriver->IsKind(STANDARD_TYPE(PlotMgt_ImageDriver))) {
3437 aFileToDump = aPlotterDriver->PlotFileName();
3438 } else {
3439 aFileToDump = aPlotterDriver->SpoolDirectory();
3440 aFileToDump += SCREENCOPY_FILENAME;
3441 }
3442 MyWindow -> Dump (aFileToDump.ToCString());
3443
3444 Standard_Integer theCurStruct = 1;
3445 Iterator = Graphic3d_MapIteratorOfMapOfStructure (theStructures);
3446 while (Iterator.More ()) {
3447 if (theFlags -> Value(theCurStruct))
3448 Iterator.Key() -> Highlight (Aspect_TOHM_COLOR);
3449 Iterator.Next ();
3450 theCurStruct++;
3451 }
3452 if (fWhiteBackground)
3453 SetBackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
3454 Redraw ();
3455
3456 // Draw imagefile by plotter driver
3457 aPlotterDriver -> SetPixelSize (thePixel);
3458 aPlotterDriver -> BeginDraw ();
3459 aPlotterDriver -> DrawImageFile (
3460 aFileToDump.ToCString(), (float)(thePWidth / 2.), (float)(thePHeight / 2.), aScale);
3461 aPlotterDriver -> EndDraw ();
3462 }
3463}
3464#undef SCREENCOPY_FILENAME
3465
3466#include <Aspect.hxx>
3467#include <Visual3d_Layer.hxx>
3468
3469////////////////////////////////////////////////////////////////
3470Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3471 const Image_TypeOfImage theBufferType)
3472{
3473 Standard_Integer aWinWidth, aWinHeight;
3474 MyWindow->Size (aWinWidth, aWinHeight);
3475
3476 Handle(Aspect_PixMap) aPixMap = ToPixMap (aWinWidth, aWinHeight, theBufferType);
3477 return !aPixMap.IsNull() && aPixMap->Dump (theFile);
3478}
3479
3480////////////////////////////////////////////////////////////////
3481Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
3482 const Aspect_FormatOfSheetPaper theFormat,
3483 const Image_TypeOfImage theBufferType)
3484{
3485 Standard_Boolean isDone = Standard_False;
3486 // convert Aspect_FormatOfSheetPaper size to pixel ...
3487 Quantity_Length anSPWidth, anSPHeight;
3488 Aspect::ValuesOfFOSP (theFormat, anSPWidth, anSPHeight);
3489
3490 // adjusting to the ratio width/height ...
3491 Quantity_Length aWinWidth, aWinHeight;
3492 MyWindow->MMSize (aWinWidth, aWinHeight);
3493 Standard_Integer aPixelWidth, aPixelHeight;
3494 MyWindow->Size (aPixelWidth, aPixelHeight);
3495
3496 Quantity_Factor aScale = Min (anSPWidth / aWinWidth, anSPHeight / aWinHeight);
3497 aPixelWidth = Standard_Integer (aPixelWidth * aScale);
3498 aPixelHeight = Standard_Integer (aPixelHeight * aScale);
3499 {
3500 Handle(Aspect_PixMap) aBitmap = ToPixMap (aPixelWidth, aPixelHeight, theBufferType);
3501 Standard_Real aGammaValue = 1.0;
3502 OSD_Environment anEnvGamma ("CSF_GAMMA_CORRECTION");
3503 TCollection_AsciiString strGamma (anEnvGamma.Value());
3504 if (!strGamma.IsEmpty()) aGammaValue = strGamma.RealValue();
3505 isDone = !aBitmap.IsNull() && aBitmap->Dump (theFile, aGammaValue);
3506 }
3507 return isDone;
3508}
3509
3510////////////////////////////////////////////////////////////////
3511Handle(Image_PixMap) V3d_View::ToPixMap (const Standard_Integer theWidth,
3512 const Standard_Integer theHeight,
3513 const Image_TypeOfImage theBufferType,
3514 const Standard_Boolean theIsForceCentred)
3515{
3516 // always prefer hardware accelerated offscreen buffer
3517 Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView();
3518 Graphic3d_PtrFrameBuffer aFBOPtr = NULL;
3519 Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO;
3520 Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0);
3521 if (aPrevFBOPtr != NULL)
3522 {
3523 MyView->FBOGetDimensions (aPrevFBOPtr,
3524 aPrevFBOVPSizeX, aPrevFBOVPSizeY,
3525 aPrevFBOSizeXMax, aPrevFBOSizeYMax);
3526 if (theWidth <= aPrevFBOSizeXMax && theHeight <= aPrevFBOSizeYMax)
3527 {
3528 MyView->FBOChangeViewport (aPrevFBOPtr, theWidth, theHeight);
3529 aFBOPtr = aPrevFBOPtr;
3530 }
3531 }
3532
3533 if (aFBOPtr == NULL)
3534 {
3535 // Try to create hardware accelerated buffer
3536 aFBOPtr = MyView->FBOCreate (theWidth, theHeight);
3537 }
3538 cView->ptrFBO = aFBOPtr;
3539
3540 // If hardware accelerated buffer - try to use onscreen buffer
3541 // Results may be bad!
3542 if (aFBOPtr == NULL)
3543 {
3544 // retrieve window sizes
3545 Standard_Integer aWinWidth, aWinHeight;
3546 MyWindow->Size (aWinWidth, aWinHeight);
3547
3548 // technically we can reduce existing viewport...
3549 // but currently allow only dumping the window itself
3550 if (theWidth != aWinWidth || theHeight != aWinHeight)
3551 {
3552 return Handle(Image_PixMap)();
3553 }
3554 }
3555
3556 //szv: save mapping
3557 Visual3d_ViewMapping prevMapping = MyView->ViewMapping();
3558 Standard_Real Umin, Vmin, Umax, Vmax;
3559
3560 if (theIsForceCentred)
3561 {
3562 //szv: get mapping frame
3563 Standard_Real PUmin, PVmin, PUmax, PVmax;
3564 prevMapping.WindowLimit (PUmin, PVmin, PUmax, PVmax);
3565
3566 //szv: calculate expansion
3567 Umin = PUmin; Vmin = PVmin; Umax = PUmax; Vmax = PVmax;
3568 Standard_Real oldWidth = (PUmax - PUmin), oldHeight = (PVmax - PVmin);
3569 Standard_Real newWidth = (oldHeight * theWidth) / theHeight;
3570 if (newWidth < oldWidth)
3571 {
3572 Standard_Real newHeight = (oldWidth * theHeight) / theWidth;
3573 // Expand height
3574 Standard_Real delta = 0.5 * (newHeight - oldHeight);
3575 Vmin = PVmin - delta;
3576 Vmax = PVmax + delta;
3577 }
3578 else
3579 {
3580 // Expand width
3581 Standard_Real delta = 0.5 * (newWidth - oldWidth);
3582 Umin = PUmin - delta;
3583 Umax = PUmax + delta;
3584 }
3585
3586 //szv: apply expanded mapping
3587 MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
3588 MyView->SetViewMapping (MyViewMapping);
3589 }
3590
3591 //workround for rendering list of Over and Under Layers
3592 if (!MyLayerMgr.IsNull())
3593 {
3594 MyLayerMgr->Compute();
3595 }
3596 Redraw();
3597
3598 //szv: restore mapping
3599 MyViewMapping = prevMapping;
3600 MyView->SetViewMapping (prevMapping);
3601
3602 // allocate image buffer for dumping
3603 Image_CRawBufferData aRawBuffer;
3604 Handle(Image_PixMap) anImageBitmap = new Image_PixMap (theWidth, theHeight, theBufferType);
3605 anImageBitmap->AccessBuffer (aRawBuffer);
3606 if (!MyView->BufferDump (aRawBuffer))
3607 {
3608 // dump is failed!
3609 anImageBitmap = Handle(Image_PixMap)();
3610 }
3611
3612 // FBO now useless, free resources
3613 if (aFBOPtr != aPrevFBOPtr)
3614 {
3615 MyView->FBORelease (aFBOPtr);
3616 }
3617 else if (aPrevFBOPtr != NULL)
3618 {
3619 MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
3620 }
3621 cView->ptrFBO = aPrevFBOPtr;
3622 return anImageBitmap;
3623}