unfinished work on new network maps
[public/netxms.git] / src / libnxmap / element.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Network Maps Library
4 ** Copyright (C) 2003-2010 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation; either version 3 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 Lesser 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: element.cpp
21 **
22 **/
23
24 #include "libnxmap.h"
25
26
27 //
28 // Generic element default constructor
29 //
30
31 NetworkMapElement::NetworkMapElement()
32 {
33 m_type = MAP_ELEMENT_GENERIC;
34 m_posX = 0;
35 m_posY = 0;
36 }
37
38
39 //
40 // Generic element config constructor
41 //
42
43 NetworkMapElement::NetworkMapElement(Config *config)
44 {
45 m_type = config->getValueInt(_T("/type"), MAP_ELEMENT_GENERIC);
46 m_posX = config->getValueInt(_T("/posX"), 0);
47 m_posY = config->getValueInt(_T("/posY"), 0);
48 }
49
50
51 //
52 // Generic element destructor
53 //
54
55 NetworkMapElement::~NetworkMapElement()
56 {
57 }
58
59
60 //
61 // Update element's persistent configuration
62 //
63
64 void NetworkMapElement::updateConfig(Config *config)
65 {
66 config->setValue(_T("/type"), m_type);
67 config->setValue(_T("/posX"), m_posX);
68 config->setValue(_T("/posY"), m_posY);
69 }
70
71
72 //
73 // Set element's position
74 //
75
76 void NetworkMapElement::setPosition(LONG x, LONG y)
77 {
78 m_posX = x;
79 m_posY = y;
80 }
81
82
83 //
84 // Object element default constructor
85 //
86
87 NetworkMapObject::NetworkMapObject(DWORD objectId) : NetworkMapElement()
88 {
89 m_type = MAP_ELEMENT_OBJECT;
90 m_objectId = objectId;
91 }
92
93
94 //
95 // Object element config constructor
96 //
97
98 NetworkMapObject::NetworkMapObject(Config *config) : NetworkMapElement(config)
99 {
100 m_objectId = config->getValueUInt(_T("/objectId"), 0);
101 }
102
103
104 //
105 // Object element destructor
106 //
107
108 NetworkMapObject::~NetworkMapObject()
109 {
110 }
111
112
113 //
114 // Update element's persistent configuration
115 //
116
117 void NetworkMapObject::updateConfig(Config *config)
118 {
119 NetworkMapElement::updateConfig(config);
120 config->setValue(_T("/objectId"), m_objectId);
121 }
122
123
124 //
125 // Decoration element default constructor
126 //
127
128 NetworkMapDecoration::NetworkMapDecoration(LONG decorationType) : NetworkMapElement()
129 {
130 m_type = MAP_ELEMENT_DECORATION;
131 m_decorationType = decorationType;
132 m_color = 0;
133 m_title = NULL;
134 }
135
136
137 //
138 // Decoration element config constructor
139 //
140
141 NetworkMapDecoration::NetworkMapDecoration(Config *config) : NetworkMapElement(config)
142 {
143 m_decorationType = config->getValueInt(_T("/decorationType"), 0);
144 m_color = config->getValueInt(_T("/color"), 0);
145 m_title = _tcsdup(config->getValue(_T("/title"), _T("")));
146 }
147
148
149 //
150 // Decoration element destructor
151 //
152
153 NetworkMapDecoration::~NetworkMapDecoration()
154 {
155 safe_free(m_title);
156 }
157
158
159 //
160 // Update decoration element's persistent configuration
161 //
162
163 void NetworkMapDecoration::updateConfig(Config *config)
164 {
165 NetworkMapElement::updateConfig(config);
166 config->setValue(_T("/decorationType"), m_decorationType);
167 config->setValue(_T("/color"), m_color);
168 config->setValue(_T("/title"), CHECK_NULL_EX(m_title));
169 }