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->InitCurrent();aAISContext->MoreCurrent ();aAISContext->NextCurrent ())
139 if (aAISContext->IsDisplayed(aAISContext->Current())) OneOrMoreCurrentIsDisplayed=true;
141 if(OneOrMoreCurrentIsDisplayed){
142 if((aAISContext->IsCurrent(aOverlappedBox) || aAISContext->IsCurrent(aBox))
143 && aAISContext->IsDisplayed(aOverlappedBox)){
144 aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
145 Message = "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
146 //myDoc -> AddTextInDialog(Message);
149 if((aAISContext->IsCurrent(aOverlappedCylinder) || aAISContext->IsCurrent(aCylinder))
150 && aAISContext->IsDisplayed(aOverlappedCylinder)){
151 aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
152 Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
153 //myDoc -> AddTextInDialog(Message);
156 if((aAISContext->IsCurrent(aOverlappedSphere) || aAISContext->IsCurrent(aSphere))
157 && aAISContext->IsDisplayed(aOverlappedSphere)){
158 aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
159 Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
160 //myDoc -> AddTextInDialog(Message);
164 if(aAISContext->IsDisplayed(aOverlappedBox)){
165 aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
166 Message = Message + "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
167 //myDoc -> AddTextInDialog(Message);
170 if(aAISContext->IsDisplayed(aOverlappedCylinder)){
171 aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
172 Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
173 //myDoc -> AddTextInDialog(Message);
176 if(aAISContext->IsDisplayed(aOverlappedSphere)){
177 aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,aFactor,aUnits);
178 Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n";
179 //myDoc -> AddTextInDialog(Message);
183 CString aTextInDialog = myDoc -> GetDialogText();
184 if (aTextInDialog != Message.ToCString())
185 myDoc -> UpdateResultMessageDlg("Set offsets", Message);
186 aAISContext->UpdateCurrentViewer();
189 void COffsetDlg::UpdateValues()
191 Standard_Integer aOffsetMode;
192 Standard_ShortReal aBoxFactor = 0;
193 Standard_ShortReal aCylFactor = 0;
194 Standard_ShortReal aSphereFactor = 0;
195 Standard_ShortReal aCylUnits = 0;
196 Standard_ShortReal aSphereUnits = 0;
197 Standard_ShortReal aBoxUnits = 0;
199 Handle(AIS_InteractiveContext) aAISContext = myDoc->GetAISContext();
201 Handle(AIS_Shape) aOverlappedBox = myDoc->GetOverlappedBox();
202 Handle(AIS_Shape) aOverlappedCylinder = myDoc->GetOverlappedCylinder();
203 Handle(AIS_Shape) aOverlappedSphere = myDoc->GetOverlappedSphere();
204 Handle(AIS_Shape) aBox = myDoc->GetBox();
205 Handle(User_Cylinder) aCylinder = myDoc->GetCylinder();
206 Handle(AIS_Shape) aSphere = myDoc->GetSphere();
208 BOOL IsOverlappedCylinderDisplayed = aAISContext->IsDisplayed(aOverlappedCylinder);
209 BOOL IsOverlappedSphereDisplayed = aAISContext->IsDisplayed(aOverlappedSphere);
210 BOOL IsOverlappedBoxDisplayed = aAISContext->IsDisplayed(aOverlappedBox);
212 BOOL IsOverlappedCylinderCurrent = aAISContext->IsCurrent(aOverlappedCylinder);
213 BOOL IsOverlappedSphereCurrent = aAISContext->IsCurrent(aOverlappedSphere);
214 BOOL IsOverlappedBoxCurrent = aAISContext->IsCurrent(aOverlappedBox);
217 /*BOOL IsAnyOverlappedObjectCurrent =
218 IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent;*/
221 BOOL IsCylinderCurrent = aAISContext->IsCurrent(aCylinder);
222 BOOL IsSphereCurrent = aAISContext->IsCurrent(aSphere);
223 BOOL IsBoxCurrent = aAISContext->IsCurrent(aBox);
225 BOOL IsAnyObjectCurrent =
226 IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent
227 || IsCylinderCurrent || IsSphereCurrent || IsBoxCurrent;
229 BOOL IsAnyOverlappedObjectDisplayed =
230 IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed;
232 Standard_Boolean OneOrMoreCurrentIsDisplayed=false;
233 for (aAISContext->InitCurrent();aAISContext->MoreCurrent ();aAISContext->NextCurrent ())
234 if (aAISContext->IsDisplayed(aAISContext->Current())) OneOrMoreCurrentIsDisplayed=true;
236 if(OneOrMoreCurrentIsDisplayed){
237 if(IsOverlappedBoxDisplayed && (IsBoxCurrent || IsOverlappedBoxCurrent)){
238 aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits);
241 if(IsOverlappedCylinderDisplayed && (IsCylinderCurrent || IsOverlappedCylinderCurrent)){
242 aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits);
245 if(IsOverlappedSphereDisplayed && (IsSphereCurrent || IsOverlappedSphereCurrent)){
246 aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits);
251 if(IsOverlappedBoxDisplayed){
252 aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits);
255 if(IsOverlappedCylinderDisplayed){
256 aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits);
259 if(IsOverlappedSphereDisplayed){
260 aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits);
264 Standard_Real Max = aBoxFactor;
265 if (Max < aCylFactor) Max = aCylFactor;
266 if (Max < aSphereFactor) Max = aSphereFactor;
271 if (Max < aCylUnits) Max = aCylUnits;
272 if (Max < aSphereUnits) Max = aSphereUnits;
276 m_FactorSlidCtrl.SetPos( (int) floor(m_Factor));
279 m_UnitsSlidCtrl.SetPos( (int) floor(m_Units));
282 if( (IsOverlappedBoxCurrent || (IsBoxCurrent && IsOverlappedBoxDisplayed)) ||
283 (IsOverlappedCylinderCurrent || (IsCylinderCurrent && IsOverlappedCylinderDisplayed)) ||
284 (IsOverlappedSphereCurrent || (IsSphereCurrent && IsOverlappedSphereDisplayed)) ||
285 (!IsAnyObjectCurrent && IsAnyOverlappedObjectDisplayed)
288 m_FactorSlidCtrl.EnableWindow();
289 m_UnitsSlidCtrl.EnableWindow();
290 GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow();
291 GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow();
294 m_FactorSlidCtrl.EnableWindow(false);
295 m_UnitsSlidCtrl.EnableWindow(false);
296 GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow(false);
297 GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow(false);