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