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