1 // OffsetDlg.cpp : implementation file
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;
136 for (aAISContext->InitCurrent();aAISContext->MoreCurrent ();aAISContext->NextCurrent ())
137 if (aAISContext->IsDisplayed(aAISContext->Current())) OneOrMoreCurrentIsDisplayed=true;
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);
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);
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);
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);
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);
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);
181 CString aTextInDialog = myDoc -> GetDialogText();
182 if (strcmp(aTextInDialog, Message.ToCString()))
183 myDoc -> UpdateResultMessageDlg("Set offsets", Message);
184 aAISContext->UpdateCurrentViewer();
187 void COffsetDlg::UpdateValues()
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;
197 Handle(AIS_InteractiveContext) aAISContext = myDoc->GetAISContext();
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();
206 BOOL IsOverlappedCylinderDisplayed = aAISContext->IsDisplayed(aOverlappedCylinder);
207 BOOL IsOverlappedSphereDisplayed = aAISContext->IsDisplayed(aOverlappedSphere);
208 BOOL IsOverlappedBoxDisplayed = aAISContext->IsDisplayed(aOverlappedBox);
210 BOOL IsOverlappedCylinderCurrent = aAISContext->IsCurrent(aOverlappedCylinder);
211 BOOL IsOverlappedSphereCurrent = aAISContext->IsCurrent(aOverlappedSphere);
212 BOOL IsOverlappedBoxCurrent = aAISContext->IsCurrent(aOverlappedBox);
215 BOOL IsAnyOverlappedObjectCurrent =
216 IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent;
219 BOOL IsCylinderCurrent = aAISContext->IsCurrent(aCylinder);
220 BOOL IsSphereCurrent = aAISContext->IsCurrent(aSphere);
221 BOOL IsBoxCurrent = aAISContext->IsCurrent(aBox);
223 BOOL IsAnyObjectCurrent =
224 IsOverlappedCylinderCurrent || IsOverlappedSphereCurrent || IsOverlappedBoxCurrent
225 || IsCylinderCurrent || IsSphereCurrent || IsBoxCurrent;
227 BOOL IsAnyOverlappedObjectDisplayed =
228 IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed;
230 Standard_Boolean OneOrMoreCurrentIsDisplayed=false;
231 for (aAISContext->InitCurrent();aAISContext->MoreCurrent ();aAISContext->NextCurrent ())
232 if (aAISContext->IsDisplayed(aAISContext->Current())) OneOrMoreCurrentIsDisplayed=true;
234 if(OneOrMoreCurrentIsDisplayed){
235 if(IsOverlappedBoxDisplayed && (IsBoxCurrent || IsOverlappedBoxCurrent)){
236 aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits);
239 if(IsOverlappedCylinderDisplayed && (IsCylinderCurrent || IsOverlappedCylinderCurrent)){
240 aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits);
243 if(IsOverlappedSphereDisplayed && (IsSphereCurrent || IsOverlappedSphereCurrent)){
244 aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits);
249 if(IsOverlappedBoxDisplayed){
250 aOverlappedBox->PolygonOffsets(aOffsetMode,aBoxFactor,aBoxUnits);
253 if(IsOverlappedCylinderDisplayed){
254 aOverlappedCylinder->PolygonOffsets(aOffsetMode,aCylFactor,aCylUnits);
257 if(IsOverlappedSphereDisplayed){
258 aOverlappedSphere->PolygonOffsets(aOffsetMode,aSphereFactor,aSphereUnits);
262 Standard_Real Max = aBoxFactor;
263 if (Max < aCylFactor) Max = aCylFactor;
264 if (Max < aSphereFactor) Max = aSphereFactor;
269 if (Max < aCylUnits) Max = aCylUnits;
270 if (Max < aSphereUnits) Max = aSphereUnits;
274 m_FactorSlidCtrl.SetPos( (int) floor(m_Factor));
277 m_UnitsSlidCtrl.SetPos( (int) floor(m_Units));
280 if( (IsOverlappedBoxCurrent || (IsBoxCurrent && IsOverlappedBoxDisplayed)) ||
281 (IsOverlappedCylinderCurrent || (IsCylinderCurrent && IsOverlappedCylinderDisplayed)) ||
282 (IsOverlappedSphereCurrent || (IsSphereCurrent && IsOverlappedSphereDisplayed)) ||
283 (!IsAnyObjectCurrent && IsAnyOverlappedObjectDisplayed)
286 m_FactorSlidCtrl.EnableWindow();
287 m_UnitsSlidCtrl.EnableWindow();
288 GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow();
289 GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow();
292 m_FactorSlidCtrl.EnableWindow(false);
293 m_UnitsSlidCtrl.EnableWindow(false);
294 GetDlgItem(IDC_EDIT_OFFSETFACTOR)->EnableWindow(false);
295 GetDlgItem(IDC_EDIT_OFFSETUNITS)->EnableWindow(false);