Revision 13000 branches/v10/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/solvers/EdgesMemoryDriver.java
EdgesMemoryDriver.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.1.2.1 2007-08-08 11:43:40 fjp |
|
48 |
* Revision 1.1.2.2 2007-08-09 12:18:27 fjp |
|
49 |
* Area de influencia con leyenda |
|
50 |
* |
|
51 |
* Revision 1.1.2.1 2007/08/08 11:43:40 fjp |
|
49 | 52 |
* Principio de giros y area de influencia |
50 | 53 |
* |
51 | 54 |
* Revision 1.2 2006/11/08 19:32:36 azabala |
... | ... | |
58 | 61 |
*/ |
59 | 62 |
package com.iver.cit.gvsig.graph.solvers; |
60 | 63 |
|
64 |
import java.awt.Color; |
|
61 | 65 |
import java.awt.geom.Line2D; |
62 | 66 |
import java.awt.geom.Rectangle2D; |
63 | 67 |
import java.io.IOException; |
64 | 68 |
import java.sql.Types; |
65 |
import java.util.List;
|
|
69 |
import java.text.NumberFormat;
|
|
66 | 70 |
|
67 |
import javax.swing.table.DefaultTableModel;
|
|
71 |
import javax.swing.JOptionPane;
|
|
68 | 72 |
|
69 | 73 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
70 | 74 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
... | ... | |
72 | 76 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
73 | 77 |
import com.hardcode.gdbms.engine.values.Value; |
74 | 78 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
75 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
|
|
79 |
import com.iver.andami.PluginServices;
|
|
76 | 80 |
import com.iver.cit.gvsig.fmap.core.FShape; |
77 | 81 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
78 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
79 | 82 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
80 | 83 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
84 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
|
81 | 85 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
82 | 86 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
83 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
|
84 | 87 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
88 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
|
89 |
import com.iver.cit.gvsig.fmap.rendering.FInterval; |
|
90 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
|
91 |
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
|
85 | 92 |
import com.iver.cit.gvsig.graph.core.GvEdge; |
86 | 93 |
import com.iver.cit.gvsig.graph.core.GvNode; |
87 | 94 |
import com.iver.cit.gvsig.graph.core.Network; |
88 | 95 |
|
89 | 96 |
/** |
90 |
* Driver wrapper around arcs from a network. It may be useful to show |
|
91 |
* the arcs as a layer without consuming more memory. Maybe it could be useful
|
|
92 |
* also to have an Edges version instead of Arcs.
|
|
97 |
* Driver wrapper around arcs from a network. It may be useful to show the arcs
|
|
98 |
* as a layer without consuming more memory. Maybe it could be useful also to
|
|
99 |
* have an Edges version instead of Arcs. |
|
93 | 100 |
* |
94 | 101 |
* @author Fco. Jos? Pe?arrubia |
95 | 102 |
* |
96 | 103 |
*/ |
97 |
public class EdgesMemoryDriver implements VectorialDriver, ObjectDriver { |
|
104 |
public class EdgesMemoryDriver implements VectorialDriver, ObjectDriver, |
|
105 |
WithDefaultLegend { |
|
98 | 106 |
static FieldDescription[] fields = new FieldDescription[6]; |
99 | 107 |
static { |
100 | 108 |
FieldDescription fieldDesc = new FieldDescription(); |
... | ... | |
124 | 132 |
fieldDesc.setFieldLength(25); |
125 | 133 |
fieldDesc.setFieldDecimalCount(0); |
126 | 134 |
fields[3] = fieldDesc; |
127 |
|
|
135 |
|
|
128 | 136 |
fieldDesc = new FieldDescription(); |
129 | 137 |
fieldDesc.setFieldName("COSTN1"); |
130 | 138 |
fieldDesc.setFieldType(Types.DOUBLE); |
... | ... | |
138 | 146 |
fieldDesc.setFieldLength(20); |
139 | 147 |
fieldDesc.setFieldDecimalCount(5); |
140 | 148 |
fields[5] = fieldDesc; |
141 |
|
|
149 |
|
|
142 | 150 |
} |
143 | 151 |
|
144 |
|
|
145 | 152 |
Network net; |
146 | 153 |
|
147 | 154 |
Rectangle2D fullExtent; |
... | ... | |
205 | 212 |
GvEdge edge = net.getGraph().getEdgeByID(index); |
206 | 213 |
GvNode n1 = net.getGraph().getNodeByID(edge.getIdNodeOrig()); |
207 | 214 |
GvNode n2 = net.getGraph().getNodeByID(edge.getIdNodeEnd()); |
208 |
Line2D.Double line = new Line2D.Double(n1.getX(), n1.getY(), n2.getX(), n2.getY()); |
|
215 |
Line2D.Double line = new Line2D.Double(n1.getX(), n1.getY(), n2.getX(), |
|
216 |
n2.getY()); |
|
209 | 217 |
return ShapeFactory.createPolyline2D(new GeneralPathX(line)); |
210 | 218 |
} |
211 | 219 |
|
212 | 220 |
public void reload() throws IOException, DriverException { |
213 | 221 |
|
214 | 222 |
} |
215 |
|
|
216 | 223 |
|
217 |
/* (non-Javadoc) |
|
224 |
/* |
|
225 |
* (non-Javadoc) |
|
226 |
* |
|
218 | 227 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int) |
219 | 228 |
*/ |
220 | 229 |
public Value getFieldValue(long rowIndex, int fieldId) |
221 |
throws DriverException { |
|
230 |
throws DriverException {
|
|
222 | 231 |
Value val = ValueFactory.createNullValue(); |
223 | 232 |
GvEdge edge = net.getGraph().getEdgeByID((int) rowIndex); |
224 |
switch (fieldId) |
|
225 |
{ |
|
233 |
switch (fieldId) { |
|
226 | 234 |
case 0: // idArc |
227 | 235 |
return ValueFactory.createValue(edge.getIdArc()); |
228 | 236 |
case 1: // weight |
... | ... | |
233 | 241 |
return ValueFactory.createValue(edge.getType() + ""); |
234 | 242 |
case 4: // cost node1 |
235 | 243 |
GvNode n1 = net.getGraph().getNodeByID(edge.getIdNodeOrig()); |
236 |
|
|
244 |
|
|
237 | 245 |
if (n1.getBestCost() == Double.MAX_VALUE) |
238 | 246 |
return ValueFactory.createValue(-1.0); |
239 | 247 |
else |
... | ... | |
245 | 253 |
else |
246 | 254 |
return ValueFactory.createValue(n2.getBestCost()); |
247 | 255 |
|
248 |
|
|
249 | 256 |
} |
250 | 257 |
return val; |
251 | 258 |
} |
252 | 259 |
|
253 |
|
|
254 | 260 |
public int getFieldCount() throws DriverException { |
255 | 261 |
return fields.length; |
256 | 262 |
} |
257 | 263 |
|
258 |
|
|
259 | 264 |
public String getFieldName(int fieldId) throws DriverException { |
260 | 265 |
return fields[fieldId].getFieldName(); |
261 | 266 |
} |
262 | 267 |
|
263 |
/* (non-Javadoc) |
|
268 |
/* |
|
269 |
* (non-Javadoc) |
|
270 |
* |
|
264 | 271 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount() |
265 | 272 |
*/ |
266 | 273 |
public long getRowCount() throws DriverException { |
267 | 274 |
return net.getGraph().numEdges(); |
268 | 275 |
} |
269 |
|
|
270 |
/* (non-Javadoc) |
|
271 |
* @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory) |
|
272 |
*/ |
|
273 |
public void setDataSourceFactory(DataSourceFactory dsf) { |
|
274 |
} |
|
275 | 276 |
|
276 |
public int getFieldWidth(int fieldId) |
|
277 |
{ |
|
278 |
return fields[fieldId].getFieldLength(); |
|
279 |
} |
|
277 |
/* |
|
278 |
* (non-Javadoc) |
|
279 |
* |
|
280 |
* @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory) |
|
281 |
*/ |
|
282 |
public void setDataSourceFactory(DataSourceFactory dsf) { |
|
283 |
} |
|
284 |
|
|
285 |
public int getFieldWidth(int fieldId) { |
|
286 |
return fields[fieldId].getFieldLength(); |
|
287 |
} |
|
288 |
|
|
289 |
private FInterval[] calculateEqualIntervals(int numIntervals, |
|
290 |
double minValue, double maxValue) { |
|
291 |
FInterval[] theIntervalArray = new FInterval[numIntervals]; |
|
292 |
double step = (maxValue - minValue) / numIntervals; |
|
293 |
|
|
294 |
if (numIntervals > 1) { |
|
295 |
theIntervalArray[0] = new FInterval(minValue, minValue + step); |
|
296 |
|
|
297 |
for (int i = 1; i < (numIntervals - 1); i++) { |
|
298 |
theIntervalArray[i] = new FInterval(minValue + (i * step) |
|
299 |
+ 0.01, minValue + ((i + 1) * step)); |
|
300 |
} |
|
301 |
|
|
302 |
theIntervalArray[numIntervals - 1] = new FInterval(minValue |
|
303 |
+ ((numIntervals - 1) * step) + 0.01, maxValue); |
|
304 |
} else { |
|
305 |
theIntervalArray[0] = new FInterval(minValue, maxValue); |
|
306 |
} |
|
307 |
|
|
308 |
return theIntervalArray; |
|
309 |
} |
|
310 |
|
|
311 |
public Legend getDefaultLegend() { |
|
312 |
VectorialIntervalLegend legend = new VectorialIntervalLegend( |
|
313 |
FShape.LINE); |
|
314 |
legend.setFieldName("COSTN1"); |
|
315 |
legend.setStartColor(Color.RED); |
|
316 |
legend.setEndColor(Color.BLUE); |
|
317 |
FInterval[] arrayIntervalos = calculateEqualIntervals(20, 0, 20000); |
|
318 |
FInterval elIntervalo; |
|
319 |
NumberFormat.getInstance().setMaximumFractionDigits(2); |
|
320 |
|
|
321 |
int r; |
|
322 |
int g; |
|
323 |
int b; |
|
324 |
int stepR; |
|
325 |
int stepG; |
|
326 |
int stepB; |
|
327 |
r = legend.getStartColor().getRed(); |
|
328 |
g = legend.getStartColor().getGreen(); |
|
329 |
b = legend.getStartColor().getBlue(); |
|
330 |
stepR = (legend.getEndColor().getRed() - r) / arrayIntervalos.length; |
|
331 |
stepG = (legend.getEndColor().getGreen() - g) / arrayIntervalos.length; |
|
332 |
stepB = (legend.getEndColor().getBlue() - b) / arrayIntervalos.length; |
|
333 |
|
|
334 |
for (int k = 0; k < arrayIntervalos.length; k++) { |
|
335 |
elIntervalo = arrayIntervalos[k]; |
|
336 |
|
|
337 |
// clave = elIntervalo; // elIntervalo.getMin() + " - " + |
|
338 |
// elIntervalo.getMax(); |
|
339 |
// System.out.println("k = " + k + " clave = " + clave); |
|
340 |
// //Comprobar que no esta repetido y no hace falta introducir en el |
|
341 |
// hashtable el campo junto con el simbolo. |
|
342 |
// if (!m_Renderer.m_symbolList.containsKey(elIntervalo)) { |
|
343 |
// si no esta creado el simbolo se crea |
|
344 |
FSymbol theSymbol = new FSymbol(FShape.LINE, new Color(r, g, b)); |
|
345 |
theSymbol.setDescription(NumberFormat.getInstance().format(elIntervalo.getMin()) + |
|
346 |
" - " + |
|
347 |
NumberFormat.getInstance().format(elIntervalo.getMax())); |
|
348 |
|
|
349 |
// //////////////////////////////////// |
|
350 |
// CALCULAMOS UN COLOR APROPIADO |
|
351 |
r = r + stepR; |
|
352 |
g = g + stepG; |
|
353 |
b = b + stepB; |
|
354 |
|
|
355 |
// /////////////////////////////// |
|
356 |
legend.addSymbol(elIntervalo, theSymbol); |
|
357 |
} // for |
|
358 |
|
|
359 |
return legend; |
|
360 |
} |
|
280 | 361 |
} |
Also available in: Unified diff