1 // OffsetDlg.cpp : implementation file
5 #include "..\res\resource.h"
7 #include "Viewer3dView.h"
12 static char THIS_FILE[] = __FILE__;
15 #define FactorMinValue 0
16 #define FactorMaxValue 20
18 #define UnitsMinValue 0
19 #define UnitsMaxValue 20
22 /////////////////////////////////////////////////////////////////////////////
26 COffsetDlg::COffsetDlg(CViewer3dDoc* theDoc, CWnd* pParent /*=NULL*/)
27 : CDialog(COffsetDlg::IDD, pParent)
29 //{{AFX_DATA_INIT(COffsetDlg)
37 void COffsetDlg::DoDataExchange(CDataExchange* pDX)
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);
51 BEGIN_MESSAGE_MAP(COffsetDlg, CDialog)
52 //{{AFX_MSG_MAP(COffsetDlg)
54 ON_EN_CHANGE(IDC_EDIT_OFFSETFACTOR, OnChangeEditOffsetFactor)
55 ON_EN_CHANGE(IDC_EDIT_OFFSETUNITS, OnChangeEditOffsetUnits)
59 /////////////////////////////////////////////////////////////////////////////
60 // COffsetDlg message handlers
62 BOOL COffsetDlg::OnInitDialog()
64 CDialog::OnInitDialog();
66 // Initializing the ComboBox
67 SetOffsets(m_Factor,m_Units);
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));
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));
80 return TRUE; // return TRUE unless you set the focus to a control
81 // EXCEPTION: OCX Property Pages should return FALSE
84 void COffsetDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
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();
95 SetOffsets(m_Factor,m_Units);
97 CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
100 void COffsetDlg::OnChangeEditOffsetFactor()
104 m_FactorSlidCtrl.SetPos(int(m_Units));
106 SetOffsets(m_Factor,m_Units);
109 void COffsetDlg::OnChangeEditOffsetUnits()
113 m_UnitsSlidCtrl.SetPos(int(m_Units));
115 SetOffsets(m_Factor,m_Units);
118 void COffsetDlg::SetOffsets(Standard_Real theFactor, Standard_Real theUnits)
120 Handle(AIS_InteractiveContext) aAISContext = myDoc->GetAISContext();
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();
130 myDoc->SetDialogTitle("Set offsets");
132 TCollection_AsciiString Message;
134 Standard_Boolean OneOrMoreCurrentIsDisplayed=false;
135 Standard_ShortReal aFactor = (Standard_ShortReal)theFactor;
136 Standard_ShortReal aUnits = (Standard_ShortReal)theUnits;
138 for (aAISContext->InitSelected(); aAISContext->MoreSelected(); aAISContext->NextSelected())
139 if (aAISContext->IsDisplayed(aAISContext->SelectedInteractive())) OneOrMoreCurrentIsDisplayed=true;
141 if(OneOrMoreCurrentIsDisplayed){
142 // A small trick to avoid complier error (C2668).
143 const Handle(AIS_InteractiveObject)& anIOOverlappedBox = aOverlappedBox;
144 const Handle(AIS_InteractiveObject)& anIOBox = aBox;
145 if((aAISContext->IsSelected(anIOOverlappedBox) || aAISContext->IsSelected(anIOBox))
146 && aAISContext->IsDisplayed(aOverlappedBox)){
147 aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
148 Message = "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
149 //myDoc -> AddTextInDialog(Message);
152 // A small trick to avoid complier error (C2668).
153 const Handle(AIS_InteractiveObject)& anIOOverlappedCylinder = aOverlappedCylinder;
154 const Handle(AIS_InteractiveObject)& anIOCylinder = aCylinder;
155 if((aAISContext->IsSelected(anIOOverlappedCylinder) || aAISContext->IsSelected(anIOCylinder))
156 && aAISContext->IsDisplayed(aOverlappedCylinder)){
157 aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
158 Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
159 //myDoc -> AddTextInDialog(Message);
162 // A small trick to avoid complier error (C2668).
163 const Handle(AIS_InteractiveObject)& anIOOverlappedSphere = aOverlappedSphere;
164 const Handle(AIS_InteractiveObject)& anIOSphere = aSphere;
165 if((aAISContext->IsSelected(anIOOverlappedSphere) || aAISContext->IsSelected(anIOSphere))
166 && aAISContext->IsDisplayed(aOverlappedSphere)){
167 aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
168 Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
169 //myDoc -> AddTextInDialog(Message);
173 if(aAISContext->IsDisplayed(aOverlappedBox)){
174 aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
175 Message = Message + "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
176 //myDoc -> AddTextInDialog(Message);
179 if(aAISContext->IsDisplayed(aOverlappedCylinder)){
180 aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
181 Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
182 //myDoc -> AddTextInDialog(Message);
185 if(aAISContext->IsDisplayed(aOverlappedSphere)){
186 aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
187 Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
188 //myDoc -> AddTextInDialog(Message);
192 CString aTextInDialog = myDoc -> GetDialogText();
193 if (aTextInDialog != Message.ToCString())
194 myDoc -> UpdateResultMessageDlg("Set offsets", Message);
195 aAISContext->UpdateCurrentViewer();
198 void COffsetDlg::UpdateValues()
200 Standard_Integer aOffsetMode;
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;
208 Handle(AIS_InteractiveContext) aAISContext = myDoc->GetAISContext();
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();
217 BOOL IsOverlappedCylinderDisplayed = aAISContext->IsDisplayed(aOverlappedCylinder);
218 BOOL IsOverlappedSphereDisplayed = aAISContext->IsDisplayed(aOverlappedSphere);
219 BOOL IsOverlappedBoxDisplayed = aAISContext->IsDisplayed(aOverlappedBox);
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);
229 /*BOOL IsAnyOverlappedObjectCurrent =
230 IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent;*/
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);
239 BOOL IsAnyObjectCurrent =
240 IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent
241 || IsCylinderCurrent || IsSphereCurrent || IsBoxCurrent;
243 BOOL IsAnyOverlappedObjectDisplayed =
244 IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed;
246 Standard_Boolean OneOrMoreCurrentIsDisplayed=false;
247 for (aAISContext->InitSelected();aAISContext->MoreSelected ();aAISContext->NextSelected ())
248 if (aAISContext->IsDisplayed(aAISContext->SelectedInteractive())) OneOrMoreCurrentIsDisplayed=true;
250 if(OneOrMoreCurrentIsDisplayed){
251 if(IsOverlappedBoxDisplayed && (IsBoxCurrent || IsOverlappedBoxCurrent)){
252 aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits);
255 if(IsOverlappedCylinderDisplayed && (IsCylinderCurrent || IsOverlappedCylinderCurrent)){
256 aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits);
259 if(IsOverlappedSphereDisplayed && (IsSphereCurrent || IsOverlappedSphereCurrent)){
260 aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits);
265 if(IsOverlappedBoxDisplayed){
266 aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits);
269 if(IsOverlappedCylinderDisplayed){
270 aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits);
273 if(IsOverlappedSphereDisplayed){
274 aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits);
278 Standard_Real Max = aBoxFactor;
279 if (Max < aCylFactor) Max = aCylFactor;
280 if (Max < aSphereFactor) Max = aSphereFactor;
285 if (Max < aCylUnits) Max = aCylUnits;
286 if (Max < aSphereUnits) Max = aSphereUnits;
290 m_FactorSlidCtrl.SetPos( (int) floor(m_Factor));
293 m_UnitsSlidCtrl.SetPos( (int) floor(m_Units));
296 if( (IsOverlappedBoxCurrent || (IsBoxCurrent && IsOverlappedBoxDisplayed)) ||
297 (IsOverlappedCylinderCurrent || (IsCylinderCurrent && IsOverlappedCylinderDisplayed)) ||
298 (IsOverlappedSphereCurrent || (IsSphereCurrent && IsOverlappedSphereDisplayed)) ||
299 (!IsAnyObjectCurrent && IsAnyOverlappedObjectDisplayed)
302 m_FactorSlidCtrl.EnableWindow();
303 m_UnitsSlidCtrl.EnableWindow();
304 GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow();
305 GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow();
308 m_FactorSlidCtrl.EnableWindow(false);
309 m_UnitsSlidCtrl.EnableWindow(false);
310 GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow(false);
311 GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow(false);