1 ///////////////////////////////////////////////////////////////////////////////
2 // OCC_StereoConfigDlg.cpp : source file
3 ///////////////////////////////////////////////////////////////////////////////
6 #include "OCC_StereoConfigDlg.h"
7 #include <Graphic3d_Camera.hxx>
9 BEGIN_MESSAGE_MAP (OCC_StereoConfigDlg, CDialog)
12 ON_NOTIFY (UDN_DELTAPOS, IDC_SPIN_FOCUS, OnSpinFocus)
13 ON_NOTIFY (UDN_DELTAPOS, IDC_SPIN_IOD, OnSpinIOD)
14 ON_BN_CLICKED (IDC_CHECK_FOCUS_RELATIVE, OnCheckFocus)
15 ON_BN_CLICKED (IDC_CHECK_IOD_RELATIVE, OnCheckIOD)
16 ON_EN_CHANGE (IDC_EDIT_FOCUS, OnChangeFocus)
17 ON_EN_CHANGE (IDC_EDIT_IOD, OnChangeIOD)
21 // round up value macro
22 #define ROUND_UP(X) X = (Round(X * 10000.0) / 10000.0)
24 // slider tick conversion
25 #define TO_SLIDER(X) (Standard_Integer)Round(X * 10)
27 // back conversion from slider ticks
28 #define FROM_SLIDER(X) X / 10.0
30 // ============================================================================
33 // ============================================================================
34 void OCC_StereoConfigDlg::SetView (const Handle(V3d_View)& theView)
38 // access initial values
39 myIOD = myView->Camera()->IOD();
40 myFocus = myView->Camera()->ZFocus();
41 mySliderFocus = TO_SLIDER(myFocus);
42 myIsRelativeIOD = (myView->Camera()->GetIODType() == Graphic3d_Camera::IODType_Relative);
43 myIsRelativeFocus = (myView->Camera()->ZFocusType() == Graphic3d_Camera::FocusType_Relative);
46 // ============================================================================
47 // function: DoDataExchange
49 // ============================================================================
50 void OCC_StereoConfigDlg::DoDataExchange(CDataExchange* theDX)
52 CDialog::DoDataExchange(theDX);
54 DDX_Text (theDX, IDC_EDIT_IOD, myIOD);
55 DDV_MinMaxDouble (theDX, myIOD, -DBL_MAX, DBL_MAX);
57 if (myIsRelativeFocus)
59 // do slider data exchange
60 DDX_Slider (theDX, IDC_SLIDER_FOCUS, (int&)mySliderFocus);
61 DDV_MinMaxSlider (theDX, mySliderFocus, TO_SLIDER(0.1), TO_SLIDER(10));
63 // show up value in edit field
64 Standard_Real aEditValue = FROM_SLIDER (mySliderFocus);
65 DDX_Text (theDX, IDC_EDIT_FOCUS, aEditValue);
67 // update focus value correspondingly
68 myFocus = FROM_SLIDER (mySliderFocus);
72 DDX_Text (theDX, IDC_EDIT_FOCUS, myFocus);
73 DDV_MinMaxDouble (theDX, myFocus, 50, DBL_MAX);
75 mySliderFocus = TO_SLIDER(1.0);
76 DDX_Slider (theDX, IDC_SLIDER_FOCUS, (int&)mySliderFocus);
79 DDX_Check (theDX, IDC_CHECK_FOCUS_RELATIVE, (int&)myIsRelativeFocus);
80 DDX_Check (theDX, IDC_CHECK_IOD_RELATIVE, (int&)myIsRelativeIOD);
82 CEdit* aFocusEdit = (CEdit*) GetDlgItem (IDC_EDIT_FOCUS);
83 aFocusEdit->EnableWindow (myIsRelativeFocus != Standard_True);
85 CSliderCtrl* aSlider = (CSliderCtrl*) GetDlgItem (IDC_SLIDER_FOCUS);
86 aSlider->EnableWindow (myIsRelativeFocus == Standard_True);
89 // ============================================================================
90 // function: OnHScroll
92 // ============================================================================
93 void OCC_StereoConfigDlg::OnHScroll(UINT theSBCode, UINT thePos, CScrollBar* theScrollBar)
98 CWnd::OnHScroll(theSBCode, thePos, theScrollBar);
101 // ============================================================================
102 // function: UpdateCamera
104 // ============================================================================
105 void OCC_StereoConfigDlg::UpdateCamera()
107 // update camera properties and redraw view
108 Handle(Graphic3d_Camera)& aCamera = myView->Camera();
109 if (aCamera.IsNull())
113 Graphic3d_Camera::IODType aIODType =
114 myIsRelativeIOD ? Graphic3d_Camera::IODType_Relative :
115 Graphic3d_Camera::IODType_Absolute;
117 aCamera->SetIOD (aIODType, myIOD);
120 Graphic3d_Camera::FocusType aFocusType =
121 myIsRelativeFocus ? Graphic3d_Camera::FocusType_Relative :
122 Graphic3d_Camera::FocusType_Absolute;
124 aCamera->SetZFocus (aFocusType, myFocus);
130 // ============================================================================
131 // function: OnCheckFocus
133 // ============================================================================
134 void OCC_StereoConfigDlg::OnCheckFocus()
138 // change focus to some predefined values
139 if (myIsRelativeFocus)
148 // ============================================================================
149 // function: OnCheckIOD
151 // ============================================================================
152 void OCC_StereoConfigDlg::OnCheckIOD()
158 // ============================================================================
159 // function: OnChangeFocus
161 // ============================================================================
162 void OCC_StereoConfigDlg::OnChangeFocus()
164 // keep previous value
165 Standard_Real aPrevFocus = myFocus;
167 // read data from ui controls
168 if (UpdateData (true))
175 myFocus = aPrevFocus;
180 // ============================================================================
181 // function: OnChangeIOD
183 // ============================================================================
184 void OCC_StereoConfigDlg::OnChangeIOD()
186 // keep previous value
187 Standard_Real aPrevIOD = myIOD;
189 // read data from ui controls
190 if (UpdateData (true))
202 // ============================================================================
203 // function: OnSpinFocus
205 // ============================================================================
206 void OCC_StereoConfigDlg::OnSpinFocus (NMHDR* theNMHDR, LRESULT* theResult)
208 NM_UPDOWN* aNMUpDown = (NM_UPDOWN*)theNMHDR;
210 const double aStep = 0.1; // use small incremental step
211 const double aDelta = aNMUpDown->iDelta * aStep; // get delta
214 myFocus -= (Standard_Real)aDelta;
219 // actualize view & ui controls
226 // ============================================================================
227 // function: OnSpinIOD
229 // ============================================================================
230 void OCC_StereoConfigDlg::OnSpinIOD (NMHDR* theNMHDR, LRESULT* theResult)
232 NM_UPDOWN* aNMUpDown = (NM_UPDOWN*)theNMHDR;
234 const double aStep = 0.01; // use small incremental step
235 const double aDelta = aNMUpDown->iDelta * aStep; // get delta
238 myIOD -= (Standard_Real)aDelta;
243 // actualize view & ui controls