Rollback from r3608 to r3606
[public/netxms.git] / src / console / PocketPC / GraphView.cpp
1 // GraphView.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "nxpc.h"
6 #include "GraphView.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 // Static data
16 //
17
18 static DWORD m_dwTimeUnitSize[MAX_TIME_UNITS] = { 60, 3600, 86400 };
19
20
21 /////////////////////////////////////////////////////////////////////////////
22 // CGraphView
23
24 CGraphView::CGraphView()
25 {
26 m_dwNumItems = 0;
27 memset(m_pdwItemList, 0, sizeof(DWORD) * MAX_GRAPH_ITEMS);
28 m_dwRefreshInterval = 30;
29 // m_dwFlags = 0;
30 // m_hTimer = 0;
31 m_dwSeconds = 0;
32 m_iTimeFrameType = 1; // Back from now
33 m_iTimeUnit = 1; // Hours
34 m_dwNumTimeUnits = 1;
35 m_dwTimeFrame = 3600; // By default, graph covers 3600 seconds
36 }
37
38 CGraphView::~CGraphView()
39 {
40 }
41
42
43 BEGIN_MESSAGE_MAP(CGraphView, CDynamicView)
44 //{{AFX_MSG_MAP(CGraphView)
45 ON_WM_CREATE()
46 ON_WM_SIZE()
47 ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
48 ON_COMMAND(ID_GRAPH_PRESETS_LAST10MINUTES, OnGraphPresetsLast10minutes)
49 ON_COMMAND(ID_GRAPH_PRESETS_LAST30MINUTES, OnGraphPresetsLast30minutes)
50 ON_COMMAND(ID_GRAPH_PRESETS_LASTHOUR, OnGraphPresetsLasthour)
51 ON_COMMAND(ID_GRAPH_PRESETS_LAST2HOURS, OnGraphPresetsLast2hours)
52 ON_COMMAND(ID_GRAPH_PRESETS_LAST4HOURS, OnGraphPresetsLast4hours)
53 ON_COMMAND(ID_GRAPH_PRESETS_LASTDAY, OnGraphPresetsLastday)
54 ON_COMMAND(ID_GRAPH_PRESETS_LASTWEEK, OnGraphPresetsLastweek)
55 ON_WM_CONTEXTMENU()
56 ON_COMMAND(ID_GRAPH_FULLSCREEN, OnGraphFullscreen)
57 //}}AFX_MSG_MAP
58 END_MESSAGE_MAP()
59
60
61 //
62 // Get view's fingerprint
63 //
64
65 QWORD CGraphView::GetFingerprint()
66 {
67 return CREATE_VIEW_FINGERPRINT(VIEW_CLASS_GRAPH, m_dwSum1, m_dwSum2);
68 }
69
70
71 //
72 // Initialize view. Called after view object creation, but
73 // before WM_CREATE. Data is a pointer to object.
74 //
75
76 void CGraphView::InitView(void *pData)
77 {
78 BYTE hash[MD5_DIGEST_SIZE];
79
80 m_dwNodeId = ((GRAPH_VIEW_INIT *)pData)->dwNodeId;
81 m_dwNumItems = ((GRAPH_VIEW_INIT *)pData)->dwNumItems;
82 memcpy(m_pdwItemList, ((GRAPH_VIEW_INIT *)pData)->pdwItemList, sizeof(DWORD) * m_dwNumItems);
83 CalculateMD5Hash((BYTE *)pData, sizeof(GRAPH_VIEW_INIT), hash);
84 memcpy(&m_dwSum1, hash, sizeof(DWORD));
85 memcpy(&m_dwSum2, &hash[sizeof(DWORD)], sizeof(DWORD));
86 }
87
88
89 /////////////////////////////////////////////////////////////////////////////
90 // CGraphView message handlers
91
92 int CGraphView::OnCreate(LPCREATESTRUCT lpCreateStruct)
93 {
94 RECT rect;
95
96 if (CDynamicView::OnCreate(lpCreateStruct) == -1)
97 return -1;
98
99 GetClientRect(&rect);
100
101 m_wndGraph.SetTimeFrame(m_dwTimeFrom, m_dwTimeTo);
102 m_wndGraph.Create(WS_CHILD | WS_VISIBLE, rect, this, IDC_GRAPH);
103
104 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
105 //if (m_dwFlags & GF_AUTOUPDATE)
106 // m_hTimer = SetTimer(1, 1000, NULL);
107
108 return 0;
109 }
110
111
112 //
113 // WM_SIZE message handler
114 //
115
116 void CGraphView::OnSize(UINT nType, int cx, int cy)
117 {
118 CDynamicView::OnSize(nType, cx, cy);
119 m_wndGraph.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOZORDER);
120 }
121
122
123 //
124 // WM_COMMAND::ID_VIEW_REFRESH message handler
125 //
126
127 void CGraphView::OnViewRefresh()
128 {
129 DWORD i, dwResult;
130 NXC_DCI_DATA *pData;
131
132 // Set new time frame
133 if (m_iTimeFrameType == 1)
134 {
135 m_dwTimeTo = WCE_FCTN(time)(NULL);
136 m_dwTimeTo -= m_dwTimeTo % 60; // Round to minute boundary
137 m_dwTimeFrom = m_dwTimeTo - m_dwTimeFrame;
138 }
139 m_wndGraph.SetTimeFrame(m_dwTimeFrom, m_dwTimeTo);
140
141 for(i = 0; i < m_dwNumItems; i++)
142 {
143 dwResult = DoRequestArg7(NXCGetDCIData, g_hSession, (void *)m_dwNodeId,
144 (void *)m_pdwItemList[i], 0, (void *)m_dwTimeFrom,
145 (void *)m_dwTimeTo, &pData, _T("Loading item data..."));
146 if (dwResult == RCC_SUCCESS)
147 {
148 m_wndGraph.SetData(i, pData);
149 }
150 else
151 {
152 theApp.ErrorBox(dwResult, _T("Unable to retrieve colected data: %s"));
153 }
154 }
155 m_wndGraph.Invalidate(FALSE);
156 }
157
158
159 //
160 // Set time frame to given preset
161 //
162
163 void CGraphView::Preset(int nTimeUnit, DWORD dwNumUnits)
164 {
165 m_iTimeFrameType = 1; // Back from now
166 m_iTimeUnit = nTimeUnit;
167 m_dwNumTimeUnits = dwNumUnits;
168 m_dwTimeFrame = m_dwNumTimeUnits * m_dwTimeUnitSize[m_iTimeUnit];
169 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
170 }
171
172
173 //
174 // Presets handlers
175 //
176
177 void CGraphView::OnGraphPresetsLast10minutes()
178 {
179 Preset(TIME_UNIT_MINUTE, 10);
180 }
181
182 void CGraphView::OnGraphPresetsLast30minutes()
183 {
184 Preset(TIME_UNIT_MINUTE, 30);
185 }
186
187 void CGraphView::OnGraphPresetsLasthour()
188 {
189 Preset(TIME_UNIT_HOUR, 1);
190 }
191
192 void CGraphView::OnGraphPresetsLast2hours()
193 {
194 Preset(TIME_UNIT_HOUR, 2);
195 }
196
197 void CGraphView::OnGraphPresetsLast4hours()
198 {
199 Preset(TIME_UNIT_HOUR, 4);
200 }
201
202 void CGraphView::OnGraphPresetsLastday()
203 {
204 Preset(TIME_UNIT_DAY, 1);
205 }
206
207 void CGraphView::OnGraphPresetsLastweek()
208 {
209 Preset(TIME_UNIT_DAY, 7);
210 }
211
212
213 //
214 // WM_CONTEXTMENU message handler
215 //
216
217 void CGraphView::OnContextMenu(CWnd* pWnd, CPoint point)
218 {
219 CMenu *pMenu;
220
221 pMenu = theApp.GetContextMenu(3);
222
223 // Disable or check some menu items
224 pMenu->EnableMenuItem(ID_GRAPH_PROPERTIES, MF_BYCOMMAND | MF_GRAYED);
225 pMenu->CheckMenuItem(ID_GRAPH_FULLSCREEN,
226 MF_BYCOMMAND | (((CMainFrame *)theApp.m_pMainWnd)->IsFullScreen() ? MF_CHECKED : 0));
227
228 pMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this, NULL);
229 }
230
231
232 //
233 // WM_COMMAND::ID_GRAPH_FULLSCREEN message handler
234 //
235
236 void CGraphView::OnGraphFullscreen()
237 {
238 ((CMainFrame *)theApp.m_pMainWnd)->ToggleFullScreen();
239 }