0023346: MSVC++ Error C2664: 'AIS_InteractiveObject::PolygonOffsets': conversion...
[occt.git] / samples / mfc / standard / 04_Viewer3d / src / OffsetDlg.cpp
1 // OffsetDlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "resource.h"
6 #include "offsetdlg.h"
7 #include "Viewer3dView.h"
8
9 #ifdef _DEBUG
10 #define new DEBUG_NEW
11 #undef THIS_FILE
12 static char THIS_FILE[] = __FILE__;
13 #endif
14
15 #define FactorMinValue 0
16 #define FactorMaxValue 20
17
18 #define UnitsMinValue 0
19 #define UnitsMaxValue 20
20
21
22 /////////////////////////////////////////////////////////////////////////////
23 // COffsetDlg dialog
24
25
26 COffsetDlg::COffsetDlg(CViewer3dDoc* theDoc, CWnd* pParent /*=NULL*/)
27         : CDialog(COffsetDlg::IDD, pParent)
28 {
29         //{{AFX_DATA_INIT(COffsetDlg)
30         m_Factor = 1.;
31         m_Units = 0.;
32         //}}AFX_DATA_INIT
33         myDoc = theDoc;
34 }
35
36
37 void COffsetDlg::DoDataExchange(CDataExchange* pDX)
38 {
39         CDialog::DoDataExchange(pDX);
40         //{{AFX_DATA_MAP(COffsetDlg)
41         DDX_Control(pDX, IDC_SLIDER_OFFSETUNITS, m_UnitsSlidCtrl);
42         DDX_Control(pDX, IDC_SLIDER_OFFSETFACTOR, m_FactorSlidCtrl);
43         DDX_Text(pDX, IDC_EDIT_OFFSETFACTOR, m_Factor);
44         DDV_MinMaxDouble(pDX, m_Factor, FactorMinValue, FactorMaxValue);
45         DDX_Text(pDX, IDC_EDIT_OFFSETUNITS, m_Units);
46         DDV_MinMaxDouble(pDX, m_Units, UnitsMinValue, UnitsMaxValue);
47         //}}AFX_DATA_MAP
48 }
49
50
51 BEGIN_MESSAGE_MAP(COffsetDlg, CDialog)
52         //{{AFX_MSG_MAP(COffsetDlg)
53         ON_WM_HSCROLL()
54         ON_EN_CHANGE(IDC_EDIT_OFFSETFACTOR, OnChangeEditOffsetFactor)
55         ON_EN_CHANGE(IDC_EDIT_OFFSETUNITS, OnChangeEditOffsetUnits)
56         //}}AFX_MSG_MAP
57 END_MESSAGE_MAP()
58
59 /////////////////////////////////////////////////////////////////////////////
60 // COffsetDlg message handlers
61
62 BOOL COffsetDlg::OnInitDialog() 
63 {
64         CDialog::OnInitDialog();
65
66 // Initializing the ComboBox
67         SetOffsets(m_Factor,m_Units);
68
69 // Setting the m_FactorSlidCtrl position at floor(m_Factor) value (because slider position is an integer)
70         m_FactorSlidCtrl.SetRange(FactorMinValue, FactorMaxValue, TRUE);
71         m_FactorSlidCtrl.SetPos( (int) floor(m_Factor));
72
73 // Setting the m_UnitsSlidCtrl position at floor(m_Units) value (because slider position is an integer)
74         m_UnitsSlidCtrl.SetRange(UnitsMinValue, UnitsMaxValue, TRUE);
75         m_UnitsSlidCtrl.SetPos( (int) floor(m_Units));
76
77         UpdateData(FALSE);
78                         
79                 
80         return TRUE;  // return TRUE unless you set the focus to a control
81                       // EXCEPTION: OCX Property Pages should return FALSE
82 }
83
84 void COffsetDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
85 {
86
87 // Setting the m_Factor value at m_FactorSlidCtrl position
88         m_Factor = m_FactorSlidCtrl.GetPos();
89 // Setting the m_Units value at m_UnitsSlidCtrl position
90         m_Units = m_UnitsSlidCtrl.GetPos();
91
92         UpdateData(FALSE);
93
94
95         SetOffsets(m_Factor,m_Units);
96         
97         CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
98 }
99
100 void COffsetDlg::OnChangeEditOffsetFactor() 
101 {
102         UpdateData();
103
104         m_FactorSlidCtrl.SetPos(int(m_Units));
105
106         SetOffsets(m_Factor,m_Units);
107 }
108
109 void COffsetDlg::OnChangeEditOffsetUnits() 
110 {
111         UpdateData();
112
113         m_UnitsSlidCtrl.SetPos(int(m_Units));
114
115         SetOffsets(m_Factor,m_Units);
116 }
117
118 void COffsetDlg::SetOffsets(Standard_Real theFactor, Standard_Real theUnits)
119 {
120         Handle(AIS_InteractiveContext) aAISContext = myDoc->GetAISContext();
121
122         Handle(AIS_Shape) aOverlappedBox = myDoc->GetOverlappedBox();
123         Handle(AIS_Shape) aOverlappedCylinder = myDoc->GetOverlappedCylinder();
124         Handle(AIS_Shape) aOverlappedSphere = myDoc->GetOverlappedSphere();
125         Handle(AIS_Shape) aBox = myDoc->GetBox();
126         Handle(User_Cylinder) aCylinder = myDoc->GetCylinder();
127         Handle(AIS_Shape) aSphere = myDoc->GetSphere();
128
129
130         myDoc->SetDialogTitle("Set offsets");
131
132         TCollection_AsciiString Message;
133
134         Standard_Boolean OneOrMoreCurrentIsDisplayed=false;
135         
136         for (aAISContext->InitCurrent();aAISContext->MoreCurrent ();aAISContext->NextCurrent ())
137                 if (aAISContext->IsDisplayed(aAISContext->Current())) OneOrMoreCurrentIsDisplayed=true;
138
139         if(OneOrMoreCurrentIsDisplayed){
140                 if((aAISContext->IsCurrent(aOverlappedBox) || aAISContext->IsCurrent(aBox))
141                                 && aAISContext->IsDisplayed(aOverlappedBox)){
142                         aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits);
143                         Message = "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
144                         //myDoc -> AddTextInDialog(Message);
145                 }
146
147                 if((aAISContext->IsCurrent(aOverlappedCylinder) || aAISContext->IsCurrent(aCylinder)) 
148                                 && aAISContext->IsDisplayed(aOverlappedCylinder)){
149                         aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits);
150                         Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
151                         //myDoc -> AddTextInDialog(Message);
152                 }
153
154                 if((aAISContext->IsCurrent(aOverlappedSphere) || aAISContext->IsCurrent(aSphere))
155                                 && aAISContext->IsDisplayed(aOverlappedSphere)){
156                         aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits);
157                         Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
158                         //myDoc -> AddTextInDialog(Message);
159                 }       
160         }
161         else{
162                 if(aAISContext->IsDisplayed(aOverlappedBox)){
163                         aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits);
164                         Message = Message + "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
165                         //myDoc -> AddTextInDialog(Message);
166                 }
167
168                 if(aAISContext->IsDisplayed(aOverlappedCylinder)){
169                         aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits);
170                         Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
171                         //myDoc -> AddTextInDialog(Message);
172                 }
173
174                 if(aAISContext->IsDisplayed(aOverlappedSphere)){
175                         aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits);
176                         Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
177                         //myDoc -> AddTextInDialog(Message);
178                 }
179         }
180         
181         CString aTextInDialog = myDoc -> GetDialogText();
182         if (strcmp(aTextInDialog, Message.ToCString()))
183                 myDoc -> UpdateResultMessageDlg("Set offsets", Message);
184         aAISContext->UpdateCurrentViewer();
185 }
186
187 void COffsetDlg::UpdateValues()
188 {
189         Standard_Integer aOffsetMode;
190         Standard_ShortReal aBoxFactor = 0;
191         Standard_ShortReal aCylFactor = 0;
192         Standard_ShortReal aSphereFactor = 0;
193         Standard_ShortReal aCylUnits = 0;
194         Standard_ShortReal aSphereUnits = 0;
195         Standard_ShortReal aBoxUnits = 0;
196
197         Handle(AIS_InteractiveContext) aAISContext = myDoc->GetAISContext();
198
199         Handle(AIS_Shape) aOverlappedBox = myDoc->GetOverlappedBox();
200         Handle(AIS_Shape) aOverlappedCylinder = myDoc->GetOverlappedCylinder();
201         Handle(AIS_Shape) aOverlappedSphere = myDoc->GetOverlappedSphere();
202         Handle(AIS_Shape) aBox = myDoc->GetBox();
203         Handle(User_Cylinder) aCylinder = myDoc->GetCylinder();
204         Handle(AIS_Shape) aSphere = myDoc->GetSphere();
205
206         BOOL IsOverlappedCylinderDisplayed = aAISContext->IsDisplayed(aOverlappedCylinder);
207         BOOL IsOverlappedSphereDisplayed = aAISContext->IsDisplayed(aOverlappedSphere);
208         BOOL IsOverlappedBoxDisplayed = aAISContext->IsDisplayed(aOverlappedBox);
209
210         BOOL IsOverlappedCylinderCurrent = aAISContext->IsCurrent(aOverlappedCylinder);
211         BOOL IsOverlappedSphereCurrent = aAISContext->IsCurrent(aOverlappedSphere);
212         BOOL IsOverlappedBoxCurrent = aAISContext->IsCurrent(aOverlappedBox);
213
214
215         BOOL IsAnyOverlappedObjectCurrent = 
216                 IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent;
217
218
219         BOOL IsCylinderCurrent = aAISContext->IsCurrent(aCylinder);
220         BOOL IsSphereCurrent = aAISContext->IsCurrent(aSphere);
221         BOOL IsBoxCurrent = aAISContext->IsCurrent(aBox);
222
223         BOOL IsAnyObjectCurrent = 
224                 IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent
225                 || IsCylinderCurrent || IsSphereCurrent || IsBoxCurrent;
226
227         BOOL IsAnyOverlappedObjectDisplayed = 
228                 IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed;
229
230         Standard_Boolean OneOrMoreCurrentIsDisplayed=false;
231         for (aAISContext->InitCurrent();aAISContext->MoreCurrent ();aAISContext->NextCurrent ())
232                 if (aAISContext->IsDisplayed(aAISContext->Current())) OneOrMoreCurrentIsDisplayed=true;
233
234         if(OneOrMoreCurrentIsDisplayed){
235                 if(IsOverlappedBoxDisplayed && (IsBoxCurrent || IsOverlappedBoxCurrent)){
236                         aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits);
237                 }
238
239                 if(IsOverlappedCylinderDisplayed && (IsCylinderCurrent || IsOverlappedCylinderCurrent)){
240                         aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits);
241                 }
242
243                 if(IsOverlappedSphereDisplayed && (IsSphereCurrent || IsOverlappedSphereCurrent)){
244                         aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits);
245                 }
246
247         }
248         else{
249         if(IsOverlappedBoxDisplayed){
250                         aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits);
251                 }
252
253                 if(IsOverlappedCylinderDisplayed){
254                         aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits);
255                 }
256
257                 if(IsOverlappedSphereDisplayed){
258                         aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits);
259                 }
260         }
261
262         Standard_Real Max = aBoxFactor;
263         if (Max < aCylFactor) Max = aCylFactor;
264         if (Max < aSphereFactor) Max = aSphereFactor;
265
266         m_Factor = Max;
267
268         Max = aBoxUnits;
269         if (Max < aCylUnits) Max = aCylUnits;
270         if (Max < aSphereUnits) Max = aSphereUnits;
271
272         m_Units = Max;
273
274         m_FactorSlidCtrl.SetPos( (int) floor(m_Factor));
275
276
277         m_UnitsSlidCtrl.SetPos( (int) floor(m_Units));
278         UpdateData(FALSE);
279
280         if(             (IsOverlappedBoxCurrent || (IsBoxCurrent && IsOverlappedBoxDisplayed)) ||
281                         (IsOverlappedCylinderCurrent || (IsCylinderCurrent && IsOverlappedCylinderDisplayed)) ||
282                         (IsOverlappedSphereCurrent || (IsSphereCurrent && IsOverlappedSphereDisplayed))  ||
283                         (!IsAnyObjectCurrent && IsAnyOverlappedObjectDisplayed)
284         )
285         {
286                 m_FactorSlidCtrl.EnableWindow();
287                 m_UnitsSlidCtrl.EnableWindow();
288                 GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow();
289                 GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow();
290         }
291         else{
292                 m_FactorSlidCtrl.EnableWindow(false);
293                 m_UnitsSlidCtrl.EnableWindow(false);
294                 GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow(false);
295                 GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow(false);
296         }
297
298 }