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