Advanced status calculation fully implemented
[public/netxms.git] / src / console / win32 / ObjectPropsStatus.cpp
1 // ObjectPropsStatus.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "nxcon.h"
6 #include "ObjectPropsStatus.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 /////////////////////////////////////////////////////////////////////////////
15 // CObjectPropsStatus property page
16
17 IMPLEMENT_DYNCREATE(CObjectPropsStatus, CPropertyPage)
18
19 CObjectPropsStatus::CObjectPropsStatus() : CPropertyPage(CObjectPropsStatus::IDD)
20 {
21 //{{AFX_DATA_INIT(CObjectPropsStatus)
22 m_iRelChange = 0;
23 m_dSingleThreshold = 0.0;
24 m_dThreshold1 = 0.0;
25 m_dThreshold2 = 0.0;
26 m_dThreshold3 = 0.0;
27 m_dThreshold4 = 0.0;
28 m_iCalcAlg = -1;
29 m_iPropAlg = -1;
30 m_iFixedStatus = -1;
31 m_iStatusTranslation1 = -1;
32 m_iStatusTranslation2 = -1;
33 m_iStatusTranslation3 = -1;
34 m_iStatusTranslation4 = -1;
35 //}}AFX_DATA_INIT
36 m_iFixedStatus = 0;
37 m_iStatusTranslation1 = 0;
38 m_iStatusTranslation2 = 0;
39 m_iStatusTranslation3 = 0;
40 m_iStatusTranslation4 = 0;
41 }
42
43 CObjectPropsStatus::~CObjectPropsStatus()
44 {
45 }
46
47 void CObjectPropsStatus::DoDataExchange(CDataExchange* pDX)
48 {
49 CPropertyPage::DoDataExchange(pDX);
50 //{{AFX_DATA_MAP(CObjectPropsStatus)
51 DDX_Control(pDX, IDC_COMBO_S4, m_wndComboS4);
52 DDX_Control(pDX, IDC_COMBO_S3, m_wndComboS3);
53 DDX_Control(pDX, IDC_COMBO_S2, m_wndComboS2);
54 DDX_Control(pDX, IDC_COMBO_S1, m_wndComboS1);
55 DDX_Control(pDX, IDC_COMBO_FIXED, m_wndComboFixed);
56 DDX_Text(pDX, IDC_EDIT_RELATIVE, m_iRelChange);
57 DDV_MinMaxInt(pDX, m_iRelChange, -4, 4);
58 DDX_Text(pDX, IDC_EDIT_THRESHOLD, m_dSingleThreshold);
59 DDV_MinMaxDouble(pDX, m_dSingleThreshold, 0., 1.);
60 DDX_Text(pDX, IDC_EDIT_T1, m_dThreshold1);
61 DDV_MinMaxDouble(pDX, m_dThreshold1, 0., 1.);
62 DDX_Text(pDX, IDC_EDIT_T2, m_dThreshold2);
63 DDV_MinMaxDouble(pDX, m_dThreshold2, 0., 1.);
64 DDX_Text(pDX, IDC_EDIT_T3, m_dThreshold3);
65 DDV_MinMaxDouble(pDX, m_dThreshold3, 0., 1.);
66 DDX_Text(pDX, IDC_EDIT_T4, m_dThreshold4);
67 DDV_MinMaxDouble(pDX, m_dThreshold4, 0., 1.);
68 DDX_Radio(pDX, IDC_RADIO_CALC_DEFAULT, m_iCalcAlg);
69 DDX_Radio(pDX, IDC_RADIO_PROP_DEFAULT, m_iPropAlg);
70 DDX_CBIndex(pDX, IDC_COMBO_FIXED, m_iFixedStatus);
71 DDX_CBIndex(pDX, IDC_COMBO_S1, m_iStatusTranslation1);
72 DDX_CBIndex(pDX, IDC_COMBO_S2, m_iStatusTranslation2);
73 DDX_CBIndex(pDX, IDC_COMBO_S3, m_iStatusTranslation3);
74 DDX_CBIndex(pDX, IDC_COMBO_S4, m_iStatusTranslation4);
75 //}}AFX_DATA_MAP
76 }
77
78
79 BEGIN_MESSAGE_MAP(CObjectPropsStatus, CPropertyPage)
80 //{{AFX_MSG_MAP(CObjectPropsStatus)
81 //}}AFX_MSG_MAP
82 END_MESSAGE_MAP()
83
84 /////////////////////////////////////////////////////////////////////////////
85 // CObjectPropsStatus message handlers
86
87
88 //
89 // WM_INITDIALOG message handler
90 //
91
92 BOOL CObjectPropsStatus::OnInitDialog()
93 {
94 int i;
95
96 CPropertyPage::OnInitDialog();
97
98 m_pUpdate = ((CObjectPropSheet *)GetParent())->GetUpdateStruct();
99 m_bIsModified = FALSE;
100
101 // Setup combo boxes
102 for(i = 0; i < 5; i++)
103 {
104 m_wndComboFixed.AddString(g_szStatusTextSmall[i]);
105 m_wndComboS1.AddString(g_szStatusTextSmall[i]);
106 m_wndComboS2.AddString(g_szStatusTextSmall[i]);
107 m_wndComboS3.AddString(g_szStatusTextSmall[i]);
108 m_wndComboS4.AddString(g_szStatusTextSmall[i]);
109 }
110 m_wndComboFixed.SelectString(-1, g_szStatusTextSmall[m_iFixedStatus]);
111 m_wndComboS1.SelectString(-1, g_szStatusTextSmall[m_iStatusTranslation1]);
112 m_wndComboS2.SelectString(-1, g_szStatusTextSmall[m_iStatusTranslation2]);
113 m_wndComboS3.SelectString(-1, g_szStatusTextSmall[m_iStatusTranslation3]);
114 m_wndComboS4.SelectString(-1, g_szStatusTextSmall[m_iStatusTranslation4]);
115
116 OnPropAlgChange();
117 OnCalcAlgChange();
118
119 return TRUE;
120 }
121
122
123 //
124 // "OK" handler
125 //
126
127 void CObjectPropsStatus::OnOK()
128 {
129 CPropertyPage::OnOK();
130
131 if (m_bIsModified)
132 {
133 m_pUpdate->dwFlags |= OBJ_UPDATE_STATUS_ALG;
134 m_pUpdate->iStatusCalcAlg = m_iCalcAlg;
135 m_pUpdate->iStatusPropAlg = m_iPropAlg;
136 m_pUpdate->iFixedStatus = m_iFixedStatus;
137 m_pUpdate->iStatusShift = m_iRelChange;
138 m_pUpdate->iStatusTrans[0] = m_iStatusTranslation1;
139 m_pUpdate->iStatusTrans[1] = m_iStatusTranslation2;
140 m_pUpdate->iStatusTrans[2] = m_iStatusTranslation3;
141 m_pUpdate->iStatusTrans[3] = m_iStatusTranslation4;
142 m_pUpdate->iStatusSingleTh = (int)(m_dSingleThreshold * 100);
143 m_pUpdate->iStatusThresholds[0] = (int)(m_dThreshold1 * 100);
144 m_pUpdate->iStatusThresholds[1] = (int)(m_dThreshold2 * 100);
145 m_pUpdate->iStatusThresholds[2] = (int)(m_dThreshold3 * 100);
146 m_pUpdate->iStatusThresholds[3] = (int)(m_dThreshold4 * 100);
147 }
148 }
149
150
151 //
152 // WM_COMMAND message handler
153 //
154
155 BOOL CObjectPropsStatus::OnCommand(WPARAM wParam, LPARAM lParam)
156 {
157 WORD wCtrl;
158
159 switch(HIWORD(wParam))
160 {
161 case BN_CLICKED:
162 wCtrl = LOWORD(wParam);
163 if ((wCtrl == IDC_RADIO_PROP_DEFAULT) ||
164 (wCtrl == IDC_RADIO_UNCHANGED) ||
165 (wCtrl == IDC_RADIO_FIXED) ||
166 (wCtrl == IDC_RADIO_RELATIVE) ||
167 (wCtrl == IDC_RADIO_SEVERITY))
168 {
169 OnPropAlgChange();
170 }
171 else if ((wCtrl == IDC_RADIO_CALC_DEFAULT) ||
172 (wCtrl == IDC_RADIO_MOST_CRITICAL) ||
173 (wCtrl == IDC_RADIO_SINGLE) ||
174 (wCtrl == IDC_RADIO_MULTIPLE))
175 {
176 OnCalcAlgChange();
177 }
178 case CBN_SELCHANGE:
179 case EN_CHANGE:
180 m_bIsModified = TRUE;
181 break;
182 default:
183 break;
184 }
185 return CPropertyPage::OnCommand(wParam, lParam);
186 }
187
188
189 //
190 // Handle propagation algorithm change
191 //
192
193 void CObjectPropsStatus::OnPropAlgChange()
194 {
195 BOOL bEnable;
196
197 EnableDlgItem(this, IDC_COMBO_FIXED, IsButtonChecked(this, IDC_RADIO_FIXED));
198 EnableDlgItem(this, IDC_EDIT_RELATIVE, IsButtonChecked(this, IDC_RADIO_RELATIVE));
199 bEnable = IsButtonChecked(this, IDC_RADIO_SEVERITY);
200 EnableDlgItem(this, IDC_COMBO_S1, bEnable);
201 EnableDlgItem(this, IDC_COMBO_S2, bEnable);
202 EnableDlgItem(this, IDC_COMBO_S3, bEnable);
203 EnableDlgItem(this, IDC_COMBO_S4, bEnable);
204 }
205
206
207 //
208 // Handle calculation algorithm change
209 //
210
211 void CObjectPropsStatus::OnCalcAlgChange()
212 {
213 BOOL bEnable;
214
215 EnableDlgItem(this, IDC_EDIT_THRESHOLD, IsButtonChecked(this, IDC_RADIO_SINGLE));
216 bEnable = IsButtonChecked(this, IDC_RADIO_MULTIPLE);
217 EnableDlgItem(this, IDC_EDIT_T1, bEnable);
218 EnableDlgItem(this, IDC_EDIT_T2, bEnable);
219 EnableDlgItem(this, IDC_EDIT_T3, bEnable);
220 EnableDlgItem(this, IDC_EDIT_T4, bEnable);
221 }