dffd6465e966eeed08b082f31df0948b869dcc88
[public/netxms.git] / src / client / console / plugins / Dashboard / node_overview.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Portable management console - Dashboard plugin
4 ** Copyright (C) 2008 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: node_overview.cpp
21 **
22 **/
23
24 #include "dashboard.h"
25
26
27 //
28 // Event table
29 //
30
31 BEGIN_EVENT_TABLE(nxNodeOverview, nxView)
32 EVT_PAINT(nxNodeOverview::OnPaint)
33 END_EVENT_TABLE()
34
35
36 //
37 // Constructor
38 //
39
40 nxNodeOverview::nxNodeOverview(wxWindow *parent)
41 : nxView(parent)
42 {
43 memset(m_count, 0, sizeof(int) * 7);
44
45 nxHeading *heading = new nxHeading(this, _T("Node Status Distribution"), wxDefaultPosition, wxSize(PIE_CHART_SIZE + 150, 20));
46
47 m_pie = new wxPieCtrl(this, -1, wxPoint(0, heading->GetSize().y), wxSize(PIE_CHART_SIZE, PIE_CHART_SIZE));
48 m_pie->SetHeight(15);
49 // m_pie->SetAngle(90);
50
51 SetMinSize(wxSize(PIE_CHART_SIZE + 150, PIE_CHART_SIZE));
52 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
53
54 NXMCEvtConnect(nxEVT_NXC_OBJECT_CHANGE, wxCommandEventHandler(nxNodeOverview::OnObjectChange), this);
55 }
56
57
58 //
59 // Destructor
60 //
61
62 nxNodeOverview::~nxNodeOverview()
63 {
64 NXMCEvtDisconnect(nxEVT_NXC_OBJECT_CHANGE, wxCommandEventHandler(nxNodeOverview::OnObjectChange), this);
65 }
66
67
68 //
69 // Refresh view
70 //
71
72 void nxNodeOverview::RefreshView()
73 {
74 wxPiePart part;
75 DWORD i, numObjects;
76 NXC_OBJECT_INDEX *index;
77
78 memset(m_count, 0, sizeof(int) * 7);
79 NXCLockObjectIndex(NXMCGetSession());
80 index = (NXC_OBJECT_INDEX *)NXCGetObjectIndex(NXMCGetSession(), &numObjects);
81 for(i = 0; i < numObjects; i++)
82 if ((!index[i].object->bIsDeleted) && (index[i].object->iClass == OBJECT_NODE))
83 {
84 m_count[index[i].object->iStatus]++;
85 }
86 NXCUnlockObjectIndex(NXMCGetSession());
87
88 m_pie->m_Series.Clear();
89
90 for(i = STATUS_NORMAL; i <= STATUS_UNMANAGED; i++)
91 {
92 part.SetLabel(NXMCGetStatusTextSmall(i));
93 part.SetValue(m_count[i]);
94 part.SetColour(NXMCGetStatusColor(i));
95 m_pie->m_Series.Add(part);
96 }
97
98 Refresh();
99 m_pie->Refresh(false);
100 }
101
102
103 //
104 // Paint event handler
105 //
106
107 void nxNodeOverview::OnPaint(wxPaintEvent &event)
108 {
109 wxPaintDC dc(this);
110 wxSize size = GetClientSize();
111 int i, y;
112 TCHAR text[256];
113
114 for(i = STATUS_NORMAL, y = 25; i <= STATUS_UNMANAGED; i++, y += 20)
115 {
116 wxBrush *brush = new wxBrush(NXMCGetStatusColor(i));
117 dc.SetBrush(*brush);
118 dc.DrawRectangle(PIE_CHART_SIZE + 10, y + 2, 16, 16);
119 dc.SetBrush(wxNullBrush);
120 delete brush;
121
122 _stprintf(text, _T("%s (%d)"), NXMCGetStatusTextSmall(i), m_count[i]);
123 dc.DrawLabel(text, wxRect(PIE_CHART_SIZE + 35, y, size.x, 20), wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
124 }
125 }
126
127
128 //
129 // Handler for object change events
130 //
131
132 void nxNodeOverview::OnObjectChange(wxCommandEvent &event)
133 {
134 NXC_OBJECT *object = (NXC_OBJECT *)event.GetClientData();
135
136 if (object->iClass == OBJECT_NODE)
137 RefreshView();
138 event.Skip();
139 }
140