Revision 12977

View differences:

branches/v10/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/core/GvTurn.java
41 41
package com.iver.cit.gvsig.graph.core;
42 42

  
43 43
public class GvTurn {
44
	int idTramoOrigen;
45
	int idTramoDestino;
46
	double cost;
44
	private int idArcFrom;
45
	private int idArcTo;
46
	private double cost;
47
	public double getCost() {
48
		return cost;
49
	}
50
	public void setCost(double cost) {
51
		this.cost = cost;
52
	}
53
	public int getIdArcFrom() {
54
		return idArcFrom;
55
	}
56
	public void setIdArcFrom(int idArcFrom) {
57
		this.idArcFrom = idArcFrom;
58
	}
59
	public int getIdArcTo() {
60
		return idArcTo;
61
	}
62
	public void setIdArcTo(int idArcTo) {
63
		this.idArcTo = idArcTo;
64
	}
47 65
}
48 66

  
49 67

  
branches/v10/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/solvers/EdgesMemoryDriver.java
1
/*
2
 * Created on 06-nov-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
 *
46
 * $Id$
47
 * $Log$
48
 * Revision 1.1.2.1  2007-08-08 11:43:40  fjp
49
 * Principio de giros y area de influencia
50
 *
51
 * Revision 1.2  2006/11/08 19:32:36  azabala
52
 * *** empty log message ***
53
 *
54
 * Revision 1.1  2006/11/07 19:49:28  azabala
55
 * *** empty log message ***
56
 *
57
 *
58
 */
59
package com.iver.cit.gvsig.graph.solvers;
60

  
61
import java.awt.geom.Line2D;
62
import java.awt.geom.Rectangle2D;
63
import java.io.IOException;
64
import java.sql.Types;
65
import java.util.List;
66

  
67
import javax.swing.table.DefaultTableModel;
68

  
69
import com.hardcode.gdbms.engine.data.DataSourceFactory;
70
import com.hardcode.gdbms.engine.data.driver.DriverException;
71
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
72
import com.hardcode.gdbms.engine.data.edition.DataWare;
73
import com.hardcode.gdbms.engine.values.Value;
74
import com.hardcode.gdbms.engine.values.ValueFactory;
75
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
76
import com.iver.cit.gvsig.fmap.core.FShape;
77
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
78
import com.iver.cit.gvsig.fmap.core.IFeature;
79
import com.iver.cit.gvsig.fmap.core.IGeometry;
80
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
81
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
82
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
83
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver;
84
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
85
import com.iver.cit.gvsig.graph.core.GvEdge;
86
import com.iver.cit.gvsig.graph.core.GvNode;
87
import com.iver.cit.gvsig.graph.core.Network;
88

  
89
/**
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.
93
 * 
94
 * @author Fco. Jos? Pe?arrubia
95
 * 
96
 */
97
public class EdgesMemoryDriver implements VectorialDriver, ObjectDriver {
98
	static FieldDescription[] fields = new FieldDescription[6];
99
	static {
100
		FieldDescription fieldDesc = new FieldDescription();
101
		fieldDesc.setFieldName("IDARC");
102
		fieldDesc.setFieldType(Types.INTEGER);
103
		fieldDesc.setFieldLength(20);
104
		fieldDesc.setFieldDecimalCount(0);
105
		fields[0] = fieldDesc;
106

  
107
		fieldDesc = new FieldDescription();
108
		fieldDesc.setFieldName("WEIGHT");
109
		fieldDesc.setFieldType(Types.DOUBLE);
110
		fieldDesc.setFieldLength(20);
111
		fieldDesc.setFieldDecimalCount(5);
112
		fields[1] = fieldDesc;
113

  
114
		fieldDesc = new FieldDescription();
115
		fieldDesc.setFieldName("LENGTH");
116
		fieldDesc.setFieldType(Types.DOUBLE);
117
		fieldDesc.setFieldLength(20);
118
		fieldDesc.setFieldDecimalCount(5);
119
		fields[2] = fieldDesc;
120

  
121
		fieldDesc = new FieldDescription();
122
		fieldDesc.setFieldName("TEXT");
123
		fieldDesc.setFieldType(Types.VARCHAR);
124
		fieldDesc.setFieldLength(25);
125
		fieldDesc.setFieldDecimalCount(0);
126
		fields[3] = fieldDesc;
127
		
128
		fieldDesc = new FieldDescription();
129
		fieldDesc.setFieldName("COSTN1");
130
		fieldDesc.setFieldType(Types.DOUBLE);
131
		fieldDesc.setFieldLength(20);
132
		fieldDesc.setFieldDecimalCount(5);
133
		fields[4] = fieldDesc;
134

  
135
		fieldDesc = new FieldDescription();
136
		fieldDesc.setFieldName("COSTN2");
137
		fieldDesc.setFieldType(Types.DOUBLE);
138
		fieldDesc.setFieldLength(20);
139
		fieldDesc.setFieldDecimalCount(5);
140
		fields[5] = fieldDesc;
141
	
142
	}
143

  
144
	
145
	Network net;
146

  
147
	Rectangle2D fullExtent;
148

  
149
	public EdgesMemoryDriver(Network net) {
150
		this.net = net;
151
	}
152

  
153
	public int getShapeType() {
154
		return FShape.LINE;
155
	}
156

  
157
	public String getName() {
158
		return "EdgeDriver";
159
	}
160

  
161
	public DriverAttributes getDriverAttributes() {
162
		return null;
163
	}
164

  
165
	public boolean isWritable() {
166
		return false;
167
	}
168

  
169
	public int[] getPrimaryKeys()
170
			throws com.hardcode.gdbms.engine.data.driver.DriverException {
171
		return null;
172
	}
173

  
174
	public void write(DataWare dataWare)
175
			throws com.hardcode.gdbms.engine.data.driver.DriverException {
176
	}
177

  
178
	/**
179
	 * Returns de field type of the specified field index.
180
	 * 
181
	 * @return field type of i field
182
	 */
183
	public int getFieldType(int i) throws DriverException {
184
		// azabala: we overwrite MemoryDriver because type resolution
185
		// is based in first register value (it could be null)
186
		if (i >= fields.length)
187
			throw new DriverException("Excedido el numero de campos");
188
		return fields[i].getFieldType();
189
	}
190

  
191
	public int getShapeCount() throws IOException {
192
		return net.getGraph().numEdges();
193
	}
194

  
195
	public Rectangle2D getFullExtent() throws IOException {
196
		try {
197
			return net.getLayer().getFullExtent();
198
		} catch (com.iver.cit.gvsig.fmap.DriverException e) {
199
			e.printStackTrace();
200
			throw new IOException(e.getMessage());
201
		}
202
	}
203

  
204
	public IGeometry getShape(int index) {
205
		GvEdge edge = net.getGraph().getEdgeByID(index);
206
		GvNode n1 = net.getGraph().getNodeByID(edge.getIdNodeOrig());
207
		GvNode n2 = net.getGraph().getNodeByID(edge.getIdNodeEnd());
208
		Line2D.Double line = new Line2D.Double(n1.getX(), n1.getY(), n2.getX(), n2.getY());
209
		return ShapeFactory.createPolyline2D(new GeneralPathX(line));
210
	}
211

  
212
	public void reload() throws IOException, DriverException {
213

  
214
	}
215
	
216

  
217
	/* (non-Javadoc)
218
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
219
	 */
220
	public Value getFieldValue(long rowIndex, int fieldId)
221
		throws DriverException {
222
		Value val = ValueFactory.createNullValue();
223
		GvEdge edge = net.getGraph().getEdgeByID((int) rowIndex);
224
		switch (fieldId)
225
		{
226
		case 0: // idArc
227
			return ValueFactory.createValue(edge.getIdArc());
228
		case 1: // weight
229
			return ValueFactory.createValue(edge.getWeight());
230
		case 2: // length
231
			return ValueFactory.createValue(edge.getDistance());
232
		case 3:
233
			return ValueFactory.createValue(edge.getType() + "");
234
		case 4: // cost node1
235
			GvNode n1 = net.getGraph().getNodeByID(edge.getIdNodeOrig());
236
			
237
			if (n1.getBestCost() == Double.MAX_VALUE)
238
				return ValueFactory.createValue(-1.0);
239
			else
240
				return ValueFactory.createValue(n1.getBestCost());
241
		case 5: // cost node2
242
			GvNode n2 = net.getGraph().getNodeByID(edge.getIdNodeOrig());
243
			if (n2.getBestCost() == Double.MAX_VALUE)
244
				return ValueFactory.createValue(-1.0);
245
			else
246
				return ValueFactory.createValue(n2.getBestCost());
247

  
248
			
249
		}
250
		return val;
251
	}
252

  
253
	
254
	public int getFieldCount() throws DriverException {
255
		return fields.length;
256
	}
257

  
258
	
259
	public String getFieldName(int fieldId) throws DriverException {
260
		return fields[fieldId].getFieldName();
261
	}
262

  
263
	/* (non-Javadoc)
264
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
265
	 */
266
	public long getRowCount() throws DriverException {
267
		return net.getGraph().numEdges();
268
	}
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
    public int getFieldWidth(int fieldId)
277
    {
278
    	return fields[fieldId].getFieldLength();
279
    }
280
}
0 281

  
branches/v10/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/solvers/ShortestPathSolverDijkstra.java
489 489
		boolean bGiroProhibido;
490 490
		ArrayList candidatos = new ArrayList();
491 491

  
492
		GvTurn elGiro;
492
		GvTurn theTurn;
493 493
		// char Mensaje[200];
494 494
		
495 495
		IGraph graph = net.getGraph();
496 496

  
497 497
		// NUEVO: 27-6-2003
498
		// Cada nodo y cada arco llevan un nuemero de soluci?n. Se supone
498
		// Cada nodo y cada arco llevan un numero de soluci?n. Se supone
499 499
		// que si lo del nodo y el arco no coincide con
500 500
		// este numero, todav?a no ha sido inicializado y hay que hacerlo.
501 501
		// Para evitar coincidencias cuando de la vuelta el contador, cada
......
597 597
					bGiroProhibido = false;
598 598
					for (int idGiro = 0; idGiro < node.getTurns().size(); idGiro++) {
599 599
						// Si est? prohibido, a por otro
600
						elGiro = (GvTurn) node.getTurns().get(idGiro);
601
						// TODO: HABILITAR ESTO
602
						// if ((elGiro.idTramoOrigen ==
603
						// Arcos[pNodo->from_link].idTramo) &&
604
						// (elGiro.idTramoDestino == pEnlace->idTramo))
605
						// {
606
						// if (elGiro.cost < 0)
607
						// {
608
						// bGiroProhibido = true;
609
						// // No podemos inicializar por completo el nodo porque
610
						// entonces
611
						// // perdemos el fromLink (el arco desde donde hemos
612
						// llegado hasta
613
						// // este nodo, que es necesario para calcular los
614
						// costes y generar
615
						// // el shape recorriendo hacia atr?s el camino
616
						// realizado.
617
						// // Si hab?a m?s de un nodo con costes prohibidos,
618
						// cab?a la posibilidad
619
						// // de que perdieramos este enlace.
620
						//									
621
						// // Para que pueda volver a entrar en c?lculos
622
						// pNodo->status = statNotInList;
623
						// pNodo->best_cost = INFINITO;
624
						//
625
						// }
626
						// else
627
						// newCost += elGiro.cost;
628
						// break; // Salimos del for porque ya hemos encontrado
629
						// el giro
630
						// }
600
						theTurn = (GvTurn) node.getTurns().get(idGiro);
601
						 if ((theTurn.getIdArcFrom() ==	 graph.getEdgeByID(node.getFromLink()).getIdArc()) &&
602
								 (theTurn.getIdArcTo() == link.getIdArc()))
603
						 {
604
							 if (theTurn.getCost() < 0)
605
							 {
606
								 bGiroProhibido = true;
607
								 // No podemos inicializar por completo el nodo porque entonces
608
								 // perdemos el fromLink (el arco desde donde hemos llegado hasta
609
								 // este nodo, que es necesario para calcular los costes y generar
610
								 // el shape recorriendo hacia atr?s el camino realizado.
611
								 // Si hab?a m?s de un nodo con costes prohibidos, cab?a la posibilidad
612
								 // de que perdieramos este enlace.
613
																	
614
								 // Para que pueda volver a entrar en c?lculos
615
								 node.setStatus(GvNode.statNotInList);
616
								 node.setBestCost(Double.MAX_VALUE);						
617
							 }
618
							 else
619
								 newCost += theTurn.getCost();
620
							 break; // Salimos del for porque ya hemos encontrado el giro
621
						 }
631 622
					}
632 623
					// Si est? prohibido, vamos a por otro enlace, PERO
633 624
					// MARCAMOS EL NODO
branches/v10/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/ServiceAreaExtension.java
48 48

  
49 49
import com.iver.andami.PluginServices;
50 50
import com.iver.andami.plugins.Extension;
51
import com.iver.andami.ui.mdiManager.IWindow;
51 52
import com.iver.cit.gvsig.fmap.MapContext;
52 53
import com.iver.cit.gvsig.fmap.MapControl;
53 54
import com.iver.cit.gvsig.fmap.core.IGeometry;
......
57 58
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
58 59
import com.iver.cit.gvsig.fmap.layers.FLayer;
59 60
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
61
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
60 62
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator;
61 63
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
62 64
import com.iver.cit.gvsig.fmap.rendering.FGraphicLabel;
......
65 67
import com.iver.cit.gvsig.graph.core.GvNode;
66 68
import com.iver.cit.gvsig.graph.core.IGraph;
67 69
import com.iver.cit.gvsig.graph.core.Network;
70
import com.iver.cit.gvsig.graph.solvers.EdgesMemoryDriver;
68 71
import com.iver.cit.gvsig.graph.solvers.OneToManySolver;
69 72
import com.iver.cit.gvsig.project.documents.view.gui.View;
70 73

  
......
105 108
								"Primero carga las paradas.");
106 109
						return;
107 110
					}
108
					setVelocities(net);
111
//					setVelocities(net);
109 112
					try {
110 113
						OneToManySolver solver = new OneToManySolver();
111 114
						solver.setNetwork(net);
......
125 128
									+ " msecs.");
126 129
							// Despu?s de esto, los nodos de la red est?n
127 130
							// etiquetados con los costes al nodo or?gen
128
							doLabeling(mapCtrl, net, flags[i]);
131
							EdgesMemoryDriver driver = new EdgesMemoryDriver(net);
132
							FLayer lyr = LayerFactory.createLayer("Edges", driver, null);
133
							map.getLayers().addLayer(lyr);
134
							// doLabeling(mapCtrl, net, flags[i]);
129 135

  
130 136
						}
131 137

  
......
185 191

  
186 192
	}
187 193

  
188
	/**
189
	 * Asignamos el coste en funci?n de un array de velocidades y el tipo de
190
	 * via. Las velocidades, en metros/seg
191
	 * 
192
	 * @param net
193
	 */
194
	private void setVelocities(Network net) {
195
		double[] veloKm = { 120, 110, 90, 80, 70, 60, 50, 40 };
196
		ArrayList veloMeters = new ArrayList();
197
		for (int i = 0; i < veloKm.length; i++) {
198
			veloMeters.add(new Double(veloKm[i] / 3.6));
194
	public boolean isEnabled() {
195
		IWindow window = PluginServices.getMDIManager().getActiveWindow();
196
		if (window instanceof View)
197
		{
198
			View v = (View) window;
199
	        MapControl mapCtrl = v.getMapControl();
200
			MapContext map = mapCtrl.getMapContext();
201
			
202
			SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
203
			while (it.hasNext())
204
			{
205
				FLayer aux = it.next();
206
				if (!aux.isActive())
207
					continue;
208
				Network net = (Network) aux.getProperty("network");
209
				
210
				if ( net != null)
211
				{
212
					return true;
213
				}
214
			}
199 215
		}
216
		return false;
217
	}
200 218

  
201
		for (int i = 0; i < net.getGraph().numEdges(); i++) {
202
			GvEdge edge = net.getGraph().getEdgeByID(i);
203
			Double vel = (Double) veloMeters.get(edge.getType());
204
			edge.setWeight(edge.getDistance() / vel.doubleValue()); // segundos
219
	public boolean isVisible() {
220
		IWindow f = PluginServices.getMDIManager()
221
		 .getActiveWindow();
222
		if (f == null) {
223
		    return false;
205 224
		}
225
		if (f instanceof View) {
226
			return true;
227
		}
228
		return false;
206 229

  
207 230
	}
208 231

  
209
	public boolean isEnabled() {
210
		// TODO Auto-generated method stub
211
		return true;
212
	}
213

  
214
	public boolean isVisible() {
215
		// TODO Auto-generated method stub
216
		return true;
217
	}
218

  
219 232
}

Also available in: Unified diff