e438a656276f32316d44a72df0a9e2a89de7ea3e
[public/netxms.git] / src / java / netxms-client / src / main / java / org / netxms / client / objects / NetworkMap.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2010 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.client.objects;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.UUID;
24 import org.netxms.base.GeoLocation;
25 import org.netxms.base.NXCPCodes;
26 import org.netxms.base.NXCPMessage;
27 import org.netxms.client.NXCSession;
28 import org.netxms.client.maps.NetworkMapLink;
29 import org.netxms.client.maps.NetworkMapPage;
30 import org.netxms.client.maps.elements.NetworkMapElement;
31
32 /**
33 * Network map object
34 *
35 */
36 public class NetworkMap extends GenericObject
37 {
38 public static final UUID GEOMAP_BACKGROUND = UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff");
39
40 public static final int TYPE_CUSTOM = 0;
41 public static final int TYPE_LAYER2_TOPOLOGY = 1;
42 public static final int TYPE_IP_TOPOLOGY = 2;
43
44 public static final int LAYOUT_MANUAL = 0x7FFF;
45 public static final int LAYOUT_SPRING = 0;
46 public static final int LAYOUT_RADIAL = 1;
47 public static final int LAYOUT_HTREE = 2;
48 public static final int LAYOUT_VTREE = 3;
49 public static final int LAYOUT_SPARSE_VTREE = 4;
50
51 public static final int MF_SHOW_STATUS_ICON = 0x000001;
52 public static final int MF_SHOW_STATUS_FRAME = 0x000002;
53 public static final int MF_SHOW_STATUS_BKGND = 0x000004;
54 public static final int MF_SHOW_END_NODES = 0x000008;
55
56 private int mapType;
57 private int layout;
58 private int flags;
59 private UUID background;
60 private GeoLocation backgroundLocation;
61 private int backgroundZoom;
62 private long seedObjectId;
63 private int defaultLinkColor;
64 private int defaultLinkRouting;
65 private int backgroundColor;
66 private int discoveryRadius;
67 private List<NetworkMapElement> elements;
68 private List<NetworkMapLink> links;
69
70 /**
71 * @param msg
72 * @param session
73 */
74 public NetworkMap(NXCPMessage msg, NXCSession session)
75 {
76 super(msg, session);
77 mapType = msg.getVariableAsInteger(NXCPCodes.VID_MAP_TYPE);
78 layout = msg.getVariableAsInteger(NXCPCodes.VID_LAYOUT);
79 flags = msg.getVariableAsInteger(NXCPCodes.VID_FLAGS);
80 background = msg.getVariableAsUUID(NXCPCodes.VID_BACKGROUND);
81 backgroundLocation = new GeoLocation(msg.getVariableAsReal(NXCPCodes.VID_BACKGROUND_LATITUDE), msg.getVariableAsReal(NXCPCodes.VID_BACKGROUND_LONGITUDE));
82 backgroundZoom = msg.getVariableAsInteger(NXCPCodes.VID_BACKGROUND_ZOOM);
83 seedObjectId = msg.getVariableAsInt64(NXCPCodes.VID_SEED_OBJECT);
84 defaultLinkColor = msg.getVariableAsInteger(NXCPCodes.VID_LINK_COLOR);
85 defaultLinkRouting = msg.getVariableAsInteger(NXCPCodes.VID_LINK_ROUTING);
86 backgroundColor = msg.getVariableAsInteger(NXCPCodes.VID_BACKGROUND_COLOR);
87 discoveryRadius = msg.getVariableAsInteger(NXCPCodes.VID_DISCOVERY_RADIUS);
88
89 int count = msg.getVariableAsInteger(NXCPCodes.VID_NUM_ELEMENTS);
90 elements = new ArrayList<NetworkMapElement>(count);
91 long varId = NXCPCodes.VID_ELEMENT_LIST_BASE;
92 for(int i = 0; i < count; i++)
93 {
94 elements.add(NetworkMapElement.createMapElement(msg, varId));
95 varId += 100;
96 }
97
98 count = msg.getVariableAsInteger(NXCPCodes.VID_NUM_LINKS);
99 links = new ArrayList<NetworkMapLink>(count);
100 varId = NXCPCodes.VID_LINK_LIST_BASE;
101 for(int i = 0; i < count; i++)
102 {
103 links.add(new NetworkMapLink(msg, varId));
104 varId += 10;
105 }
106 }
107
108 /* (non-Javadoc)
109 * @see org.netxms.client.objects.GenericObject#getObjectClassName()
110 */
111 @Override
112 public String getObjectClassName()
113 {
114 return "NetworkMap";
115 }
116
117 /**
118 * @return the mapType
119 */
120 public int getMapType()
121 {
122 return mapType;
123 }
124
125 /**
126 * @return the layout
127 */
128 public int getLayout()
129 {
130 return layout;
131 }
132
133 /**
134 * @return the background
135 */
136 public UUID getBackground()
137 {
138 return background;
139 }
140
141 /**
142 * @return the seedObjectId
143 */
144 public long getSeedObjectId()
145 {
146 return seedObjectId;
147 }
148
149 /**
150 * Create map page from map object's data
151 *
152 * @return new map page
153 */
154 public NetworkMapPage createMapPage()
155 {
156 NetworkMapPage page = new NetworkMapPage(getObjectName());
157 page.addAllElements(elements);
158 page.addAllLinks(links);
159 return page;
160 }
161
162 /**
163 * @return the backgroundLocation
164 */
165 public GeoLocation getBackgroundLocation()
166 {
167 return backgroundLocation;
168 }
169
170 /**
171 * @return the backgroundZoom
172 */
173 public int getBackgroundZoom()
174 {
175 return backgroundZoom;
176 }
177
178 /**
179 * @return the flags
180 */
181 public int getFlags()
182 {
183 return flags;
184 }
185
186 /**
187 * @return the defaultLinkColor
188 */
189 public int getDefaultLinkColor()
190 {
191 return defaultLinkColor;
192 }
193
194 /**
195 * @return the defaultLinkRouting
196 */
197 public int getDefaultLinkRouting()
198 {
199 return defaultLinkRouting;
200 }
201
202 /**
203 * @return the backgroundColor
204 */
205 public int getBackgroundColor()
206 {
207 return backgroundColor;
208 }
209
210 /**
211 * @return the discoveryRadius
212 */
213 public final int getDiscoveryRadius()
214 {
215 return discoveryRadius;
216 }
217 }