Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / mfc / standard / 04_Viewer3d / src / TrihedronDlg.cpp
1 // TrihedronDlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "Viewer3dApp.h"
6 #include "Viewer3dView.h"
7 #include "TrihedronDlg.h"
8
9 #ifdef _DEBUG
10 #define new DEBUG_NEW
11 #undef THIS_FILE
12 static char THIS_FILE[] = __FILE__;
13 #endif
14
15 void round(double &value, unsigned char digits) 
16
17 char neg = 1; 
18 if(value < 0){ 
19 neg = (-1); 
20 value *= (-1); 
21
22 double inc(1.0); 
23 while(digits){ inc*=10; --digits; } 
24 double dg(value*inc*100); 
25 value = floor(floor(dg)/100); 
26 if((dg-(value*100)) > 49.9) value+=1; 
27 value = (value*neg)/inc; 
28 }
29
30
31 /////////////////////////////////////////////////////////////////////////////
32 // CTrihedronDlg dialog
33
34
35 //CTrihedronDlg::CTrihedronDlg(CWnd* pParent /*=NULL*/)
36         //: CDialog(CTrihedronDlg::IDD, pParent)
37
38 CTrihedronDlg::CTrihedronDlg(Handle_V3d_View Current_V3d_View, CViewer3dDoc* pDoc, CWnd* pParent /*=NULL*/)
39         : CDialog(CTrihedronDlg::IDD, pParent)
40
41 {
42         //{{AFX_DATA_INIT(CTrihedronDlg)
43         m_TrihedronScale = 0.1;
44         myDoc=pDoc;
45         myCurrent_V3d_View = Current_V3d_View;
46         /*m_*/Color = Quantity_NOC_WHITE;
47         /*m_*/Position = Aspect_TOTP_LEFT_UPPER;
48
49                 // NOTE: the ClassWizard will add member initialization here
50         //}}AFX_DATA_INIT
51 }
52
53
54 void CTrihedronDlg::DoDataExchange(CDataExchange* pDX)
55 {
56         CDialog::DoDataExchange(pDX);
57         //{{AFX_DATA_MAP(CTrihedronDlg)
58         DDX_Control(pDX, IDC_COMBOTRIHEDRPOS, m_ComboTrihedronPosList);
59         DDX_Control(pDX, IDC_COMBOTRIHEDRCOLOR, m_ComboTrihedronColorList);
60         DDX_Text(pDX, IDC_EDITTRIHEDRSCALE, m_TrihedronScale);
61         DDV_MinMaxDouble(pDX, m_TrihedronScale, 0., 1.);
62         DDX_Control(pDX, IDC_SPINTRIHEDRSCALE, m_SpinTrihedronScale);
63         //}}AFX_DATA_MAP
64 }
65
66
67 BEGIN_MESSAGE_MAP(CTrihedronDlg, CDialog)
68         //{{AFX_MSG_MAP(CTrihedronDlg)
69         ON_CBN_SELCHANGE(IDC_COMBOTRIHEDRCOLOR, OnSelchangeCombotrihedrcolor)
70         ON_CBN_SELCHANGE(IDC_COMBOTRIHEDRPOS, OnSelchangeCombotrihedrpos)
71         ON_EN_CHANGE(IDC_EDITTRIHEDRSCALE, OnChangeEdittrihedrscale)
72         ON_NOTIFY(UDN_DELTAPOS, IDC_SPINTRIHEDRSCALE, OnDeltaposSpintrihedrscale)
73         //}}AFX_MSG_MAP
74 END_MESSAGE_MAP()
75
76
77
78
79
80 /////////////////////////////////////////////////////////////////////////////
81 // CTrihedronDlg message handlers
82
83 void CTrihedronDlg::OnSelchangeCombotrihedrcolor() 
84 {
85         UpdateData(TRUE);
86         int a = m_ComboTrihedronColorList.GetCurSel();
87         if(     a==0)
88                 Color=Quantity_NOC_BLACK;
89         else if(a==1)
90                 Color=Quantity_NOC_MATRABLUE;
91         else if(a==2)
92                 Color=Quantity_NOC_MATRAGRAY;
93 //      else if(a==3)
94 //              Color=Quantity_NOC_ALICEBLUE;
95         else if(a==3)
96                 Color=Quantity_NOC_ANTIQUEWHITE;
97         //else if(a==4)
98         //      Color=Quantity_NOC_BISQUE;
99
100         UpdateData(FALSE);
101
102         myCurrent_V3d_View->TriedronDisplay(Position, Color, m_TrihedronScale);
103         myCurrent_V3d_View->Update();
104
105 }
106
107 void CTrihedronDlg::OnSelchangeCombotrihedrpos() 
108 {
109         UpdateData(TRUE);
110         int b = m_ComboTrihedronPosList.GetCurSel();
111
112         if(     b==0)
113                 Position=Aspect_TOTP_CENTER;
114         else if(b==1)
115                 Position=Aspect_TOTP_LEFT_LOWER;
116         else if(b==2)
117                 Position=Aspect_TOTP_LEFT_UPPER;
118         else if(b==3)
119                 Position=Aspect_TOTP_RIGHT_LOWER;
120         else if(b==4)
121                 Position=Aspect_TOTP_RIGHT_UPPER;
122
123         UpdateData(FALSE);
124
125         myCurrent_V3d_View->TriedronDisplay(Position, Color, m_TrihedronScale);
126         myCurrent_V3d_View->Update();
127         
128 }
129
130
131 BOOL CTrihedronDlg::OnInitDialog() 
132 {
133         CDialog::OnInitDialog();
134         UpdateData(TRUE);
135
136 // Initializing the ComboBox : Position
137         m_ComboTrihedronPosList.InsertString(-1,"Center");
138         m_ComboTrihedronPosList.InsertString(-1,"Left Lower");
139         m_ComboTrihedronPosList.InsertString(-1,"Left Upper");
140         m_ComboTrihedronPosList.InsertString(-1,"Right Lower");
141         m_ComboTrihedronPosList.InsertString(-1,"Right Upper");
142
143 // Initializing the ComboBox : Color
144         /*
145         m_ComboTrihedronColorList.InsertString(-1,"BLACK");
146         m_ComboTrihedronColorList.InsertString(-1,"MATRABLUE");
147         m_ComboTrihedronColorList.InsertString(-1,"MATRAGRAY");
148         m_ComboTrihedronColorList.InsertString(-1,"ALICE BLUE");
149         m_ComboTrihedronColorList.InsertString(-1,"WHITE");
150         m_ComboTrihedronColorList.InsertString(-1,"BISQUE");
151         */
152         m_ComboTrihedronColorList.InsertString(-1,"Black");
153         m_ComboTrihedronColorList.InsertString(-1,"Blue");
154         m_ComboTrihedronColorList.InsertString(-1,"Gray");
155         m_ComboTrihedronColorList.InsertString(-1,"White");
156         //m_ComboTrihedronColorList.InsertString(-1,"Bisque");
157         
158
159
160         UpdateData(FALSE);
161         
162 /*      if (CDemoVisualizationView::slinitialisation())
163         {
164                 AfxMessageBox("debut");
165
166                 if(m_Position==Aspect_TOTP_CENTER)
167                         m_ComboTrihedronPosList.SetCurSel(0);
168                 else if(m_Position==Aspect_TOTP_LEFT_LOWER)
169                         m_ComboTrihedronPosList.SetCurSel(1);
170                 else if(m_Position==Aspect_TOTP_LEFT_UPPER)
171                         m_ComboTrihedronPosList.SetCurSel(2);
172                 else if(m_Position==Aspect_TOTP_RIGHT_LOWER)
173                         m_ComboTrihedronPosList.SetCurSel(3);
174                 else if(m_Position==Aspect_TOTP_RIGHT_UPPER)
175                         m_ComboTrihedronPosList.SetCurSel(4);
176
177                 if(m_Color==Quantity_NOC_BLACK)
178                         m_ComboTrihedronColorList.SetCurSel(0);
179                 else if(m_Color==Quantity_NOC_MATRABLUE)
180                         m_ComboTrihedronColorList.SetCurSel(1);
181                 else if(m_Color==Quantity_NOC_MATRAGRAY)
182                         m_ComboTrihedronColorList.SetCurSel(2);
183                 else if(m_Color==Quantity_NOC_ALICEBLUE)
184                         m_ComboTrihedronColorList.SetCurSel(3);
185                 else if(m_Color==Quantity_NOC_WHITE)
186                         m_ComboTrihedronColorList.SetCurSel(4);
187                 else if(m_Color==Quantity_NOC_BISQUE)
188                         m_ComboTrihedronColorList.SetCurSel(5);
189                 Position = m_Position;
190                 Color = m_Color;
191                 myCurrent_V3d_View->TriedronDisplay(Position, Color, m_TrihedronScale);
192                 myCurrent_V3d_View->Update();
193
194                 Initialisation = Standard_False;
195
196         }
197         else
198         {*/
199                 if(Position==Aspect_TOTP_CENTER)
200                         m_ComboTrihedronPosList.SetCurSel(0);
201                 else if(Position==Aspect_TOTP_LEFT_LOWER)
202                         m_ComboTrihedronPosList.SetCurSel(1);
203                 else if(Position==Aspect_TOTP_LEFT_UPPER)
204                         m_ComboTrihedronPosList.SetCurSel(2);
205                 else if(Position==Aspect_TOTP_RIGHT_LOWER)
206                         m_ComboTrihedronPosList.SetCurSel(3);
207                 else if(Position==Aspect_TOTP_RIGHT_UPPER)
208                         m_ComboTrihedronPosList.SetCurSel(4);
209
210                 if(Color==Quantity_NOC_BLACK)
211                         m_ComboTrihedronColorList.SetCurSel(0);
212                 else if(Color==Quantity_NOC_MATRABLUE)
213                         m_ComboTrihedronColorList.SetCurSel(1);
214                 else if(Color==Quantity_NOC_MATRAGRAY)
215                         m_ComboTrihedronColorList.SetCurSel(2);
216 //              else if(Color==Quantity_NOC_ALICEBLUE)
217 //                      m_ComboTrihedronColorList.SetCurSel(3);
218                 else if(Color==Quantity_NOC_WHITE)
219                         m_ComboTrihedronColorList.SetCurSel(3);
220                 //else if(Color==Quantity_NOC_BISQUE)
221                 //      m_ComboTrihedronColorList.SetCurSel(4); 
222
223                 myCurrent_V3d_View->TriedronDisplay(Position, Color, m_TrihedronScale);
224                 myCurrent_V3d_View->Update();
225 //      }
226
227
228         
229
230
231         return TRUE;  // return TRUE unless you set the focus to a control
232                       // EXCEPTION: OCX Property Pages should return FALSE
233 }
234
235
236 void CTrihedronDlg::OnDeltaposSpintrihedrscale(NMHDR* pNMHDR, LRESULT* pResult) 
237 {
238         NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
239
240         if (pNMUpDown->iDelta >= 1)
241                 pNMUpDown->iDelta = 1;
242         else 
243                 pNMUpDown->iDelta = -1;
244         
245         if ((pNMUpDown->iDelta > 0) && (m_TrihedronScale > 0)) 
246                 m_TrihedronScale = m_TrihedronScale - (pNMUpDown->iDelta)*0.01;
247         
248         if ((pNMUpDown->iDelta < 0) && (m_TrihedronScale < 1)) 
249                 m_TrihedronScale = m_TrihedronScale - (pNMUpDown->iDelta)*0.01;
250
251
252         m_TrihedronScale = m_TrihedronScale*100;
253         m_TrihedronScale = floor(m_TrihedronScale );
254         m_TrihedronScale  = m_TrihedronScale /100;
255
256 //      round(m_TrihedronScale,2);
257
258         if (fabs(m_TrihedronScale) < 0.001)
259                 m_TrihedronScale =0;
260         UpdateData(FALSE);
261         
262         myCurrent_V3d_View->TriedronDisplay(Position, Color, m_TrihedronScale);
263         *pResult = 0;
264
265         myCurrent_V3d_View->Update();
266
267 }
268
269 void CTrihedronDlg::OnChangeEdittrihedrscale() 
270 {
271         if (UpdateData()){
272                 myCurrent_V3d_View->TriedronDisplay(Position, Color, m_TrihedronScale);
273                 myCurrent_V3d_View->Update();
274         }
275 }
276
277 void CTrihedronDlg::OnCancel() 
278 {
279         myCurrent_V3d_View->TriedronErase();
280         myCurrent_V3d_View->Update();
281         myDoc -> SetMyStaticTrihedronAxisIsDisplayed(FALSE);
282 //      Initialisation = Standard_True;
283         CDialog::OnCancel();
284 }
285
286 void CTrihedronDlg::OnOK() 
287 {
288         myDoc -> SetMyStaticTrihedronAxisIsDisplayed(TRUE);
289         CDialog::OnOK();
290 }
291