Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // OffsetDlg.cpp : implementation file |
2 | // | |
3 | ||
4 | #include "stdafx.h" | |
47162471 | 5 | #include "..\res\resource.h" |
7fd59977 | 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; | |
23bbd9d3 | 135 | Standard_ShortReal aFactor = (Standard_ShortReal)theFactor; |
136 | Standard_ShortReal aUnits = (Standard_ShortReal)theUnits; | |
7fd59977 | 137 | |
404c8936 | 138 | for (aAISContext->InitSelected(); aAISContext->MoreSelected(); aAISContext->NextSelected()) |
139 | if (aAISContext->IsDisplayed(aAISContext->SelectedInteractive())) OneOrMoreCurrentIsDisplayed=true; | |
7fd59977 | 140 | |
141 | if(OneOrMoreCurrentIsDisplayed){ | |
a110c4a3 | 142 | // A small trick to avoid compiler error (C2668). |
404c8936 | 143 | const Handle(AIS_InteractiveObject)& anIOOverlappedBox = aOverlappedBox; |
144 | const Handle(AIS_InteractiveObject)& anIOBox = aBox; | |
145 | if((aAISContext->IsSelected(anIOOverlappedBox) || aAISContext->IsSelected(anIOBox)) | |
7fd59977 | 146 | && aAISContext->IsDisplayed(aOverlappedBox)){ |
23bbd9d3 | 147 | aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits); |
7fd59977 | 148 | Message = "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; |
149 | //myDoc -> AddTextInDialog(Message); | |
150 | } | |
151 | ||
a110c4a3 | 152 | // A small trick to avoid compiler error (C2668). |
404c8936 | 153 | const Handle(AIS_InteractiveObject)& anIOOverlappedCylinder = aOverlappedCylinder; |
154 | const Handle(AIS_InteractiveObject)& anIOCylinder = aCylinder; | |
155 | if((aAISContext->IsSelected(anIOOverlappedCylinder) || aAISContext->IsSelected(anIOCylinder)) | |
7fd59977 | 156 | && aAISContext->IsDisplayed(aOverlappedCylinder)){ |
23bbd9d3 | 157 | aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits); |
7fd59977 | 158 | Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; |
159 | //myDoc -> AddTextInDialog(Message); | |
160 | } | |
161 | ||
a110c4a3 | 162 | // A small trick to avoid compiler error (C2668). |
404c8936 | 163 | const Handle(AIS_InteractiveObject)& anIOOverlappedSphere = aOverlappedSphere; |
164 | const Handle(AIS_InteractiveObject)& anIOSphere = aSphere; | |
165 | if((aAISContext->IsSelected(anIOOverlappedSphere) || aAISContext->IsSelected(anIOSphere)) | |
7fd59977 | 166 | && aAISContext->IsDisplayed(aOverlappedSphere)){ |
23bbd9d3 | 167 | aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits); |
7fd59977 | 168 | Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; |
169 | //myDoc -> AddTextInDialog(Message); | |
170 | } | |
171 | } | |
172 | else{ | |
173 | if(aAISContext->IsDisplayed(aOverlappedBox)){ | |
23bbd9d3 | 174 | aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits); |
7fd59977 | 175 | Message = Message + "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; |
176 | //myDoc -> AddTextInDialog(Message); | |
177 | } | |
178 | ||
179 | if(aAISContext->IsDisplayed(aOverlappedCylinder)){ | |
23bbd9d3 | 180 | aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits); |
7fd59977 | 181 | Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; |
182 | //myDoc -> AddTextInDialog(Message); | |
183 | } | |
184 | ||
185 | if(aAISContext->IsDisplayed(aOverlappedSphere)){ | |
23bbd9d3 | 186 | aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits); |
7fd59977 | 187 | Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; |
188 | //myDoc -> AddTextInDialog(Message); | |
189 | } | |
190 | } | |
191 | ||
192 | CString aTextInDialog = myDoc -> GetDialogText(); | |
576f8b11 | 193 | if (aTextInDialog != Message.ToCString()) |
7fd59977 | 194 | myDoc -> UpdateResultMessageDlg("Set offsets", Message); |
195 | aAISContext->UpdateCurrentViewer(); | |
196 | } | |
197 | ||
198 | void COffsetDlg::UpdateValues() | |
199 | { | |
200 | Standard_Integer aOffsetMode; | |
e145d04c PK |
201 | Standard_ShortReal aBoxFactor = 0; |
202 | Standard_ShortReal aCylFactor = 0; | |
203 | Standard_ShortReal aSphereFactor = 0; | |
204 | Standard_ShortReal aCylUnits = 0; | |
205 | Standard_ShortReal aSphereUnits = 0; | |
206 | Standard_ShortReal aBoxUnits = 0; | |
7fd59977 | 207 | |
208 | Handle(AIS_InteractiveContext) aAISContext = myDoc->GetAISContext(); | |
209 | ||
210 | Handle(AIS_Shape) aOverlappedBox = myDoc->GetOverlappedBox(); | |
211 | Handle(AIS_Shape) aOverlappedCylinder = myDoc->GetOverlappedCylinder(); | |
212 | Handle(AIS_Shape) aOverlappedSphere = myDoc->GetOverlappedSphere(); | |
213 | Handle(AIS_Shape) aBox = myDoc->GetBox(); | |
214 | Handle(User_Cylinder) aCylinder = myDoc->GetCylinder(); | |
215 | Handle(AIS_Shape) aSphere = myDoc->GetSphere(); | |
216 | ||
217 | BOOL IsOverlappedCylinderDisplayed = aAISContext->IsDisplayed(aOverlappedCylinder); | |
218 | BOOL IsOverlappedSphereDisplayed = aAISContext->IsDisplayed(aOverlappedSphere); | |
219 | BOOL IsOverlappedBoxDisplayed = aAISContext->IsDisplayed(aOverlappedBox); | |
220 | ||
404c8936 | 221 | const Handle(AIS_InteractiveObject)& anIOOverlappedCylinder = aOverlappedCylinder; |
222 | const Handle(AIS_InteractiveObject)& anIOOverlappedSphere = aOverlappedSphere; | |
223 | const Handle(AIS_InteractiveObject)& anIOOverlappedBox = aOverlappedBox; | |
224 | BOOL IsOverlappedCylinderCurrent = aAISContext->IsSelected(anIOOverlappedCylinder); | |
225 | BOOL IsOverlappedSphereCurrent = aAISContext->IsSelected(anIOOverlappedSphere); | |
226 | BOOL IsOverlappedBoxCurrent = aAISContext->IsSelected(anIOOverlappedBox); | |
7fd59977 | 227 | |
228 | ||
5c573e69 | 229 | /*BOOL IsAnyOverlappedObjectCurrent = |
230 | IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent;*/ | |
7fd59977 | 231 | |
404c8936 | 232 | const Handle(AIS_InteractiveObject)& anIOCylinder = aCylinder; |
233 | const Handle(AIS_InteractiveObject)& anIOSphere = aSphere; | |
234 | const Handle(AIS_InteractiveObject)& anIOBox = aBox; | |
235 | BOOL IsCylinderCurrent = aAISContext->IsSelected(anIOCylinder); | |
236 | BOOL IsSphereCurrent = aAISContext->IsSelected(anIOSphere); | |
237 | BOOL IsBoxCurrent = aAISContext->IsSelected(anIOBox); | |
7fd59977 | 238 | |
239 | BOOL IsAnyObjectCurrent = | |
240 | IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent | |
241 | || IsCylinderCurrent || IsSphereCurrent || IsBoxCurrent; | |
242 | ||
243 | BOOL IsAnyOverlappedObjectDisplayed = | |
244 | IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed; | |
245 | ||
246 | Standard_Boolean OneOrMoreCurrentIsDisplayed=false; | |
404c8936 | 247 | for (aAISContext->InitSelected();aAISContext->MoreSelected ();aAISContext->NextSelected ()) |
248 | if (aAISContext->IsDisplayed(aAISContext->SelectedInteractive())) OneOrMoreCurrentIsDisplayed=true; | |
7fd59977 | 249 | |
250 | if(OneOrMoreCurrentIsDisplayed){ | |
251 | if(IsOverlappedBoxDisplayed && (IsBoxCurrent || IsOverlappedBoxCurrent)){ | |
252 | aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits); | |
253 | } | |
254 | ||
255 | if(IsOverlappedCylinderDisplayed && (IsCylinderCurrent || IsOverlappedCylinderCurrent)){ | |
256 | aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits); | |
257 | } | |
258 | ||
259 | if(IsOverlappedSphereDisplayed && (IsSphereCurrent || IsOverlappedSphereCurrent)){ | |
260 | aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits); | |
261 | } | |
262 | ||
263 | } | |
264 | else{ | |
265 | if(IsOverlappedBoxDisplayed){ | |
266 | aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits); | |
267 | } | |
268 | ||
269 | if(IsOverlappedCylinderDisplayed){ | |
270 | aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits); | |
271 | } | |
272 | ||
273 | if(IsOverlappedSphereDisplayed){ | |
274 | aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits); | |
275 | } | |
276 | } | |
277 | ||
278 | Standard_Real Max = aBoxFactor; | |
279 | if (Max < aCylFactor) Max = aCylFactor; | |
280 | if (Max < aSphereFactor) Max = aSphereFactor; | |
281 | ||
282 | m_Factor = Max; | |
283 | ||
284 | Max = aBoxUnits; | |
285 | if (Max < aCylUnits) Max = aCylUnits; | |
286 | if (Max < aSphereUnits) Max = aSphereUnits; | |
287 | ||
288 | m_Units = Max; | |
289 | ||
290 | m_FactorSlidCtrl.SetPos( (int) floor(m_Factor)); | |
291 | ||
292 | ||
293 | m_UnitsSlidCtrl.SetPos( (int) floor(m_Units)); | |
294 | UpdateData(FALSE); | |
295 | ||
296 | if( (IsOverlappedBoxCurrent || (IsBoxCurrent && IsOverlappedBoxDisplayed)) || | |
297 | (IsOverlappedCylinderCurrent || (IsCylinderCurrent && IsOverlappedCylinderDisplayed)) || | |
298 | (IsOverlappedSphereCurrent || (IsSphereCurrent && IsOverlappedSphereDisplayed)) || | |
299 | (!IsAnyObjectCurrent && IsAnyOverlappedObjectDisplayed) | |
300 | ) | |
301 | { | |
302 | m_FactorSlidCtrl.EnableWindow(); | |
303 | m_UnitsSlidCtrl.EnableWindow(); | |
304 | GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow(); | |
305 | GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow(); | |
306 | } | |
307 | else{ | |
308 | m_FactorSlidCtrl.EnableWindow(false); | |
309 | m_UnitsSlidCtrl.EnableWindow(false); | |
310 | GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow(false); | |
311 | GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow(false); | |
312 | } | |
313 | ||
314 | } |