Revision 8659

View differences:

trunk/extensions/extGraph_predes/src/com/vividsolutions/jts/geomgraph/SnappingNodeMap.java
42 42
 */
43 43
public class SnappingNodeMap extends NodeMap {
44 44

  
45
	// private Quadtree spatialIndex;
45
	
46 46

  
47
	// Esto es una mierda, y va a ir muy lento
47
	// Esto  va a ir muy lento
48 48
	// buscar otros mecanismos (indice espacial, o hashmap)
49 49
	protected HashMap nodeMap;
50 50

  
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/GenerateNetworkExtension.java
40 40
 */
41 41
package com.iver.cit.gvsig.graph;
42 42

  
43
import java.awt.Component;
43 44
import java.io.File;
45
import java.io.FileNotFoundException;
46
import java.util.HashMap;
44 47

  
45 48
import javax.swing.ImageIcon;
49
import javax.swing.JFileChooser;
46 50
import javax.swing.JOptionPane;
47 51

  
48 52
import com.iver.andami.PluginServices;
......
56 60
import com.iver.cit.gvsig.fmap.MapControl;
57 61
import com.iver.cit.gvsig.fmap.core.FShape;
58 62
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
63
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
59 64
import com.iver.cit.gvsig.fmap.edition.EditionException;
65
import com.iver.cit.gvsig.fmap.edition.IWriter;
66
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
60 67
import com.iver.cit.gvsig.fmap.edition.writers.dbf.DbfWriter;
68
import com.iver.cit.gvsig.fmap.edition.writers.shp.MultiShpWriter;
69
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter;
61 70
import com.iver.cit.gvsig.fmap.layers.FLayer;
71
import com.iver.cit.gvsig.fmap.layers.FLayers;
62 72
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
63 73
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator;
74
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
75
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes;
76
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
64 77
import com.iver.cit.gvsig.graph.core.writers.NetworkFileRedWriter;
65 78
import com.iver.cit.gvsig.graph.core.writers.NetworkGvTableWriter;
66 79
import com.iver.cit.gvsig.graph.gui.wizard.NetWizard;
......
68 81
import com.iver.cit.gvsig.project.documents.view.IProjectView;
69 82
import com.iver.cit.gvsig.project.documents.view.gui.IView;
70 83
import com.iver.cit.gvsig.project.documents.view.gui.View;
84
import com.iver.cit.gvsig.topology.lineclean.fmap.LineCleanGeoprocess;
85
import com.iver.utiles.SimpleFileFilter;
71 86
import com.iver.utiles.swing.threads.AbstractMonitorableTask;
87
import com.iver.utiles.swing.threads.IMonitorableTask;
88
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
89
import com.iver.utiles.swing.threads.MonitorableTaskQueue;
72 90

  
73
public class GenerateNetworkExtension extends Extension implements IPreferenceExtension {
91
public class GenerateNetworkExtension extends Extension implements
92
		IPreferenceExtension {
74 93
	private static final IPreference thePreferencePage = new RoutePage();
75
	
76 94

  
77 95
	public void initialize() {
78 96
	}
......
81 99
		IView view = (View) PluginServices.getMDIManager().getActiveWindow();
82 100
		MapControl mapControl = view.getMapControl();
83 101
		MapContext map = mapControl.getMapContext();
84
		SingleLayerIterator lyrIterator = new SingleLayerIterator(map
85
				.getLayers());
102
		FLayers tocLyrs = map.getLayers();
103
		SingleLayerIterator lyrIterator = new SingleLayerIterator(tocLyrs);
86 104
		while (lyrIterator.hasNext()) {
87 105
			FLayer lyr = lyrIterator.next();
88
			if ((lyr.isActive()) && (lyr instanceof FLyrVect))
89
			{
106
			if ((lyr.isActive()) && (lyr instanceof FLyrVect)) {
90 107
				FLyrVect lyrVect = (FLyrVect) lyr;
91 108
				int shapeType;
92 109
				try {
93 110
					shapeType = lyrVect.getShapeType();
94
					if (shapeType == FShape.LINE)
95
					{
111
					if (shapeType == FShape.LINE) {
96 112
						if (actionCommand.equalsIgnoreCase("GENERATE_RED")) {
97
							generateRedNetwork(lyrVect);
113
							generateRedNetwork(lyrVect, tocLyrs);
98 114
							return;
99 115
						}
100 116
					}
......
106 122
			}
107 123
		}
108 124

  
109

  
110 125
	}
111 126

  
112

  
113 127
	private void generateNetwork(FLyrVect lyr) {
114 128
		NetworkGvTableWriter netBuilder = new NetworkGvTableWriter();
115 129
		// Por ahora, a pelo, pero hay que sacar un cuadro
......
117 131
		// Tambi?n un cuadro de di?logo para seleccionar
118 132
		// en qu? tablas quiere escribir, y su formato
119 133
		// (dbf, postgres, etc)
120
		String fieldType = "tipored"; String fieldDist = "length"; String fieldSense = "sen";
134
		String fieldType = "tipored";
135
		String fieldDist = "length";
136
		String fieldSense = "sen";
121 137
		String fieldCost = "cost";
122 138
		try {
123 139
			netBuilder.setLayer(lyr);
......
142 158
			// TODO Auto-generated catch block
143 159
			e1.printStackTrace();
144 160
		}
145
		JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done"));
161
		JOptionPane.showMessageDialog(null, PluginServices
162
				.getText(this, "done"));
146 163
	}
164
	
165
	class GenerateRedNetworkAfterCleanTask extends AbstractMonitorableTask {
166
		IMonitorableTask cleanTask;
167
		LineCleanGeoprocess cleanGeoprocess;
147 168

  
169
		File redFile;
170

  
171
		NetworkFileRedWriter netBuilder;
172
		
173
		
174

  
175
		/**
176
		 * Constructor
177
		 */
178
		GenerateRedNetworkAfterCleanTask(FLyrVect layer, File redFile,
179
				NetworkFileRedWriter netBuilder, 
180
				IMonitorableTask cleanTask, LineCleanGeoprocess geoprocess) {
181
			this.redFile = redFile;
182
			this.netBuilder = netBuilder;
183
			this.cleanTask = cleanTask;
184
			this.cleanGeoprocess = geoprocess;
185
			setInitialStep(0);
186
			setDeterminatedProcess(true);
187
			setStatusMessage(PluginServices.getText(this,
188
			"Generando_red_a_partir_de_capa_lineal"));
189
		}
190

  
191
		public void run() throws Exception {
192
			//TODO Esto creo que no vale, porque estamos esperando a que el thread del CLEAN acabe
193
			//y esto come mucho procesador
194
			
195
			//Probar a crear un PluginServices.enqueue(Task1, Task2)
196
			//de forma que el thread de la task2 se quede esperando al de la task1
197
			
198
			while(! cleanTask.isFinished() || ! cleanTask.isCanceled()){
199
				Thread.sleep(1000);
200
			}
201
			if(cleanTask.isCanceled())
202
				return;
203
			FLyrVect layer = (FLyrVect) cleanGeoprocess.getResult();
204
			int numShapes;
205
			try { 	
206
				numShapes = layer.getSource().getShapeCount();
207
				setFinalStep(numShapes);
208
				
209
				
210
			} catch (DriverIOException e) {
211
				// TODO Auto-generated catch block
212
				e.printStackTrace();
213
			}
214
			
215
			
216
			netBuilder.setLayer(layer);
217
			netBuilder.setCancellableMonitorable(this);
218
			netBuilder.setRedFile(redFile);
219
			netBuilder.writeNetwork();
220
			JOptionPane.showMessageDialog(null, PluginServices.getText(this,
221
					"done"));
222
		}
223

  
224
		public String getNote() {
225
			return "Procesando linea..." + " " + getCurrentStep() + " " + "de"
226
					+ " " + getFinishStep();
227
		}
228

  
229
		public void cancel() {
230
			setCanceled(true);
231
		}
232
	}
148 233
	
149
	class GenerateRedNetworkTask extends AbstractMonitorableTask{
234
	
235
	
236

  
237
	class GenerateRedNetworkTask extends AbstractMonitorableTask {
150 238
		FLyrVect layer;
239

  
151 240
		File redFile;
241

  
152 242
		NetworkFileRedWriter netBuilder;
243
		
244
		
245

  
153 246
		/**
154 247
		 * Constructor
155
		 * */
156
		GenerateRedNetworkTask(FLyrVect layer, File redFile, NetworkFileRedWriter netBuilder){
248
		 */
249
		GenerateRedNetworkTask(FLyrVect layer, File redFile,
250
				NetworkFileRedWriter netBuilder) {
157 251
			this.layer = layer;
158 252
			this.redFile = redFile;
159 253
			this.netBuilder = netBuilder;
......
163 257
				numShapes = layer.getSource().getShapeCount();
164 258
				setFinalStep(numShapes);
165 259
				setDeterminatedProcess(true);
166
				setStatusMessage(PluginServices.
167
						getText(this, "Generando_red_a_partir_de_capa_lineal"));
260
				setStatusMessage(PluginServices.getText(this,
261
						"Generando_red_a_partir_de_capa_lineal"));
168 262
			} catch (DriverIOException e) {
169 263
				// TODO Auto-generated catch block
170 264
				e.printStackTrace();
171 265
			}
172
			
266

  
173 267
		}
174
		
268

  
175 269
		public void run() throws Exception {
176 270
			netBuilder.setLayer(layer);
177 271
			netBuilder.setCancellableMonitorable(this);
178 272
			netBuilder.setRedFile(redFile);
179 273
			netBuilder.writeNetwork();
180
			JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done"));
181
		}	
182
		
274
			JOptionPane.showMessageDialog(null, PluginServices.getText(this,
275
					"done"));
276
		}
277

  
183 278
		public String getNote() {
184
			return "Procesando linea..."  + 
185
			" " +
186
			getCurrentStep()+ 
187
			" "+
188
			"de"+
189
			" "+
190
			getFinishStep();
279
			return "Procesando linea..." + " " + getCurrentStep() + " " + "de"
280
					+ " " + getFinishStep();
191 281
		}
192 282

  
193 283
		public void cancel() {
194 284
			setCanceled(true);
195 285
		}
196 286
	}
197
	
198
	
199
	private void generateRedNetwork(FLyrVect lyr) {
287

  
288
	/**
289
	 * It returns a geoprocess to make a CLEAN of the input layer 
290
	 * */
291
	private LineCleanGeoprocess createCleanGeoprocess(FLyrVect lineLyr) {
292
		 File outputFile = null;
293
		 JOptionPane.showMessageDialog(null,
294
				PluginServices.getText(null, "Especifique_fichero_shp_resultante"),
295
				PluginServices.getText(null, "Fichero_para_capa_corregida"),
296
				JOptionPane.INFORMATION_MESSAGE);
297
		 JFileChooser jfc = new JFileChooser();
298
		SimpleFileFilter filterShp = new SimpleFileFilter("shp", PluginServices
299
				.getText(this, "shp_files"));
300
		jfc.setFileFilter(filterShp);
301
		if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
302
			File newFile = jfc.getSelectedFile();
303
			String path = newFile.getAbsolutePath();
304
			if (newFile.exists()) {
305
				int resp = JOptionPane.showConfirmDialog(
306
						(Component) PluginServices.getMainFrame(),
307
						PluginServices.getText(this,
308
								"fichero_ya_existe_seguro_desea_guardarlo"),
309
						PluginServices.getText(this, "guardar"),
310
						JOptionPane.YES_NO_OPTION);
311
				if (resp != JOptionPane.YES_OPTION) {
312
					return null;
313
				}
314
			}// if
315
			if (!(path.toLowerCase().endsWith(".shp"))) {
316
				path = path + ".shp";
317
			}
318
			outputFile = new File(path);
319
		} else {
320
			return null;
321
		}
322
		LineCleanGeoprocess geoprocess = new LineCleanGeoprocess(lineLyr);
323
		SHPLayerDefinition definition = (SHPLayerDefinition) geoprocess
324
				.createLayerDefinition();
325
		definition.setFile(outputFile);
326
		ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile
327
				.getAbsolutePath());
328
		IWriter writer = null;
329
		try {
330
			int shapeType = definition.getShapeType();
331
			if (shapeType != XTypes.MULTI) {
332
				writer = new ShpWriter();
333
				((ShpWriter) writer).setFile(definition.getFile());
334
				writer.initialize(definition);
335
			} else {
336
				writer = new MultiShpWriter();
337
				((MultiShpWriter) writer).setFile(definition.getFile());
338
				writer.initialize(definition);
339
			}
340
		} catch (Exception e1) {
341
			String error = PluginServices.getText(this,
342
					"Error_escritura_resultados");
343
			String errorDescription = PluginServices.getText(this,
344
					"Error_preparar_escritura_resultados");
345
		}
346
		geoprocess.setResultLayerProperties(writer, schemaManager);
347
		HashMap params = new HashMap();
348
		params.put("layer_selection", new Boolean(false));
349
		try {
350
			geoprocess.setParameters(params);
351
			geoprocess.checkPreconditions();
352
			return geoprocess;
353
			
354
		} catch (GeoprocessException e) {
355
			String error = PluginServices.getText(this, "Error_ejecucion");
356
			String errorDescription = PluginServices.getText(this,
357
					"Error_fallo_geoproceso");
358
			return null;
359
		}
360

  
361
	}
362

  
363
	private void generateRedNetwork(FLyrVect lyr, FLayers tocLyrs) {
200 364
		lyr.createSpatialIndex();
201 365
		NetworkFileRedWriter netBuilder = new NetworkFileRedWriter();
202 366
		// Por ahora, a pelo, pero hay que sacar un cuadro
......
205 369
		// en qu? tablas quiere escribir, y su formato
206 370
		// (dbf, postgres, etc)
207 371

  
208
		ImageIcon icon = new ImageIcon(this.
209
				getClass().
210
				getClassLoader().
211
				getResource("images/net-wizard-logo.jpg"));
372
		ImageIcon icon = new ImageIcon(this.getClass().getClassLoader()
373
				.getResource("images/net-wizard-logo.jpg"));
212 374

  
213 375
		NetWizard wiz = new NetWizard(icon, lyr);
214 376
		PluginServices.getMDIManager().addWindow(wiz);
215
		if(!wiz.wasFinishPressed())
377
		if (!wiz.wasFinishPressed())
216 378
			return;
217
//		try {
218
			String fieldType = wiz.getFieldType();
219
			String fieldLength = wiz.getFieldLength();
220
			String fieldCost = wiz.getFieldCost();
221
			String fieldSense = wiz.getFieldSense();
222
			netBuilder.setLayer(lyr);
223
			netBuilder.setFieldType(fieldType);
224
			netBuilder.setFieldDist(fieldLength);
225
			netBuilder.setFieldSense(fieldSense);
226
			netBuilder.setFieldCost(fieldCost);
227
			File redFile = NetworkUtils.getNetworkFile(lyr);
228
			
229
			boolean cleanOrigLyr = wiz.getCleanOriginalLayer();
230
			boolean applySnap = wiz.getApplySnapTolerance();
379
		// try {
380
		String fieldType = wiz.getFieldType();
381
		String fieldLength = wiz.getFieldLength();
382
		String fieldCost = wiz.getFieldCost();
383
		String fieldSense = wiz.getFieldSense();
384
		netBuilder.setLayer(lyr);
385
		netBuilder.setFieldType(fieldType);
386
		netBuilder.setFieldDist(fieldLength);
387
		netBuilder.setFieldSense(fieldSense);
388
		netBuilder.setFieldCost(fieldCost);
389
		File redFile = NetworkUtils.getNetworkFile(lyr);
390

  
391
		boolean cleanOrigLyr = wiz.getCleanOriginalLayer();
392
		LineCleanGeoprocess clean = null;
393
		if(cleanOrigLyr)
394
			clean = createCleanGeoprocess(lyr);
395
		boolean applySnap = wiz.getApplySnapTolerance();
396
		if(applySnap){
231 397
			double snapTolerance = wiz.getSnapTolerance();
398
			netBuilder.setSnapTolerance(snapTolerance);
399
		}	
400
		if(clean != null){
401
			//we wont start the process of network creation
402
			//until clean geoprocess will be finished
403
			IMonitorableTask cleanTask = clean.createTask();
404
			GenerateRedNetworkAfterCleanTask task = new 
405
			GenerateRedNetworkAfterCleanTask(lyr, redFile,
406
					netBuilder, cleanTask, clean );
407
			PluginServices.cancelableBackgroundExecution(cleanTask);
408
			PluginServices.cancelableBackgroundExecution(task);
232 409
			
233
//			netBuilder.createRedFile(lyr, redFile);
234
			
235
			GenerateRedNetworkTask task = new GenerateRedNetworkTask(lyr, redFile, netBuilder);
410
		}else{
411
			GenerateRedNetworkTask task = new GenerateRedNetworkTask(lyr, redFile,
412
					netBuilder);
236 413
			PluginServices.cancelableBackgroundExecution(task);
237
			
238
			
239
//		} catch (DriverException e1) {
240
//			// TODO Auto-generated catch block
241
//			e1.printStackTrace();
242
//
243
//		}
244
//		JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done"));
245

  
414
		}
246 415
	}
247 416

  
248

  
249 417
	public boolean isEnabled() {
250 418
		return true;
251 419
	}
......
263 431
			MapContext mapa = model.getMapContext();
264 432
			FLayer[] activeLayers = mapa.getLayers().getActives();
265 433
			if (activeLayers.length > 0)
266
				if (activeLayers[0] instanceof FLyrVect){
434
				if (activeLayers[0] instanceof FLyrVect) {
267 435
					FLyrVect lyrVect = (FLyrVect) activeLayers[0];
268
					int shapeType ;
436
					int shapeType;
269 437
					try {
270 438
						shapeType = lyrVect.getShapeType();
271 439
						if (shapeType == FShape.LINE)
......
274 442
						// TODO Auto-generated catch block
275 443
						e.printStackTrace();
276 444
					}
277
				}	
445
				}
278 446
		}
279 447
		return false;
280 448

  
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/ClearRouteExtension.java
40 40
 */
41 41
package com.iver.cit.gvsig.graph;
42 42

  
43
import java.util.List;
44

  
43 45
import com.iver.andami.PluginServices;
44 46
import com.iver.andami.plugins.Extension;
45 47
import com.iver.andami.ui.mdiManager.IWindow;
......
50 52
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator;
51 53
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
52 54
import com.iver.cit.gvsig.graph.core.Network;
55
import com.iver.cit.gvsig.graph.gui.RouteReportPanel;
53 56
import com.iver.cit.gvsig.project.documents.view.gui.View;
57
import com.iver.cit.gvsig.util.GvSession;
54 58

  
55 59
public class ClearRouteExtension extends Extension {
56 60

  
......
80 84
					if (actionCommand.equalsIgnoreCase("CLEAR_ROUTES"))
81 85
					{
82 86
						NetworkUtils.clearRouteFromGraphics(mapCtrl);
87
						GvSession.getInstance().delete(mapCtrl, "Route");
88
						List reportPanels = (List) GvSession.
89
												getInstance().
90
												get(mapCtrl, "RouteReport");
91
						if(reportPanels != null){
92
							for(int i = 0; i < reportPanels.size(); i++){
93
								PluginServices.getMDIManager().
94
								closeWindow((RouteReportPanel)reportPanels.get(i));
95
							}
96
						}
97
				
98
						GvSession.getInstance().delete(mapCtrl, "RouteReport");
83 99
						mapCtrl.drawMap(false);
84 100
					}
85 101
					
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/gui/RouteControlPanel.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.20  2006-11-09 12:51:12  jaume
46
 * Revision 1.21  2006-11-09 21:08:32  azabala
47 47
 * *** empty log message ***
48 48
 *
49
 * Revision 1.20  2006/11/09 12:51:12  jaume
50
 * *** empty log message ***
51
 *
49 52
 * Revision 1.19  2006/11/09 11:00:43  jaume
50 53
 * *** empty log message ***
51 54
 *
......
134 137
import javax.swing.ImageIcon;
135 138
import javax.swing.JComboBox;
136 139
import javax.swing.JLabel;
140
import javax.swing.JOptionPane;
137 141
import javax.swing.JPanel;
138 142
import javax.swing.JScrollPane;
139 143
import javax.swing.JTable;
......
602 606
			aux.add(getBtnLoadStage());
603 607
			aux.add(getBtnSaveStage());
604 608
			aux.add(getBtnSaveRoute());
605
			aux.add(getBtnGenerateReport());
609
//			aux.add(getBtnGenerateReport());
606 610
			layout.setRows(aux.getComponentCount());
607 611
			aux.setLayout(layout);
608 612
			eastPanel = new GridBagLayoutPanel();
......
611 615
		return eastPanel;
612 616
	}
613 617

  
614
	private JButton getBtnGenerateReport() {
615
		if (btnGenerateRoute == null) {
616
			btnGenerateRoute = new JButton();
617
			btnGenerateRoute.setText(PluginServices.getText(this,
618
					"generate_report"));
619
			btnGenerateRoute.addActionListener(this);
620
		}
621
		return btnGenerateRoute;
622
	}
618
//	private JButton getBtnGenerateReport() {
619
//		if (btnGenerateRoute == null) {
620
//			btnGenerateRoute = new JButton();
621
//			btnGenerateRoute.setText(PluginServices.getText(this,
622
//					"generate_report"));
623
//			btnGenerateRoute.addActionListener(this);
624
//		}
625
//		return btnGenerateRoute;
626
//	}
623 627

  
624 628
	private JButton getBtnSaveRoute() {
625 629
		if (btnSaveRoute == null) {
......
753 757
			removeStage();
754 758
		} else if (c.equals(getBtnSaveRoute())) {
755 759
			saveRoute();
756
		} else if (c.equals(getBtnGenerateReport())) {
757

  
758
		}
760
		}/* 
761
		else if (c.equals(getBtnGenerateReport())) {
762
			RouteReportPanel reportPanel = (RouteReportPanel) GvSession.
763
									getInstance().
764
									get(mapCtrl, "RouteReport");
765
			if(reportPanel != null)
766
				PluginServices.getMDIManager().addWindow(reportPanel);
767
			else
768
				JOptionPane.showMessageDialog(this, PluginServices.getText(this, "Ruta_borrada_o_inexistente"),
769
						PluginServices.getText(this, "Ruta_no_encontrada"),
770
						JOptionPane.ERROR_MESSAGE);
771
		}*/
759 772
		repaint();
760 773
	}
761 774

  
......
840 853
			return;
841 854
		IView view = (View) window;
842 855
		MapControl mapControl = view.getMapControl();
843
		Route route = (Route) GvSession.getInstance().get(mapControl, "Route");
844
		if(route == null)
856
		List routes = (List) GvSession.getInstance().get(mapControl, "Route");
857
		if(routes == null || routes.size() == 0){
858
			JOptionPane.showMessageDialog(this, PluginServices.getText(this, "Ruta_borrada_o_inexistente"),
859
					PluginServices.getText(this, "Ruta_no_encontrada"),
860
					JOptionPane.ERROR_MESSAGE);
845 861
			return;
846
		RouteMemoryDriver driver = new RouteMemoryDriver(route.getFeatureList());
862
		}	
863
		Route lastRoute = (Route) routes.get(routes.size() - 1);
864
		RouteMemoryDriver driver = new RouteMemoryDriver(lastRoute.getFeatureList());
847 865
		IProjection projection = FOpenDialog.getLastProjection();
848 866
		FLyrVect routeLayer = (FLyrVect) LayerFactory.createLayer("Route",
849 867
				driver, projection);
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/gui/wizard/NetPage0.java
1 1
/*
2
 * Created on 07-nov-2006 by azabala
2
 * Created on 09-nov-2006
3 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
4 43
 */
44
/* CVS MESSAGES:
45
 *
46
 * $Id$
47
 * $Log$
48
 * Revision 1.7  2006-11-09 21:08:32  azabala
49
 * *** empty log message ***
50
 *
51
 *
52
 */
5 53
package com.iver.cit.gvsig.graph.gui.wizard;
6 54

  
7 55
import javax.swing.ButtonGroup;
8 56
import javax.swing.JEditorPane;
9 57
import javax.swing.JRadioButton;
10 58
import javax.swing.JSpinner;
11
import javax.swing.SpinnerModel;
12 59
import javax.swing.SpinnerNumberModel;
13 60

  
14 61
import jwizardcomponent.JWizardPanel;
......
113 160
		
114 161
		snappedCoordinatesBtn = new JRadioButton(PluginServices.getText(this, "Aplicar_tolerancia_de_snap"));
115 162
		SpinnerNumberModel spinnerModel =
116
			new SpinnerNumberModel(0.01, 0d, 100d, 0.0001 );
163
			new SpinnerNumberModel(0.01, 0d, 100d, 0.01 );
117 164
		snapTolerance = new JSpinner(spinnerModel);
118 165
		
119 166
		
......
125 172
		contentPane.addComponent(snappedCoordinatesBtn, snapTolerance);
126 173
		
127 174
		
128
//		contentPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
129
//				PluginServices.getText(this, "length (esto ho llevare)"),
130
//				javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
131
//				javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
132
		
133
		
134 175
		this.add(contentPane);
135 176
	}
136 177

  
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/core/writers/NetworkFileRedWriter.java
63 63
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
64 64
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
65 65
import com.iver.cit.gvsig.graph.core.NodeGv;
66
import com.iver.cit.gvsig.util.SnappingCoordinateMap;
66 67
import com.iver.utiles.swing.threads.CancellableMonitorable;
67 68
import com.vividsolutions.jts.geom.Coordinate;
68 69
import com.vividsolutions.jts.geom.Geometry;
......
75 76
public class NetworkFileRedWriter extends AbstractNetworkWriter {
76 77
	File redFile;
77 78
	CancellableMonitorable cancel;
79
	private double snapTolerance = 0d;
78 80
	public NetworkFileRedWriter() {
79 81
		
80 82
		// Set up fields for table nodes
......
173 175
		// SE UTILIZA PARA LOS CALCULOS POR IDTRAMO Y
174 176
		// PORCENTAJE
175 177
		// PARA SABER SI EST? M?S CERCA DE UN NODO O DEL OTRO.
176

  
177
		Hashtable nodeHash = new Hashtable();
178
		Hashtable nodeHash = null;
179
		if(snapTolerance != 0d)
180
			nodeHash = new SnappingCoordinateMap(snapTolerance);
181
		else
182
			nodeHash = new Hashtable();
178 183
		ArrayList nodes = new ArrayList();
179 184

  
180 185
		try {
......
396 401

  
397 402
	}
398 403

  
404
	public void setSnapTolerance(double snapTolerance) {
405
		this.snapTolerance = snapTolerance;
406
	}
407

  
399 408
}
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/NetworkUtils.java
84 84
				if (aux.getTag().equalsIgnoreCase("ROUTE"))
85 85
					graphics.removeGraphic(aux);
86 86
		}
87
		GvSession.getInstance().delete(mc, "Route");
88 87
	}
89 88
	
90 89
	public static File getNetworkFile(FLayer lyr) {
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/solvers/Route.java
69 69
	
70 70
	
71 71
	
72
	
73
	
74
	
72 75
	public IFeature addRouteFeature(IGeometry geom, int idArc, double weight, double length, String text)
73 76
	{
74 77
		Value[] values = new Value[4];
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/ShortestPathExtension.java
42 42

  
43 43
import java.awt.BasicStroke;
44 44
import java.awt.Color;
45
import java.util.ArrayList;
45 46
import java.util.Collection;
46 47
import java.util.Iterator;
48
import java.util.List;
47 49

  
48 50
import javax.swing.JComponent;
49 51
import javax.swing.JOptionPane;
......
101 103
								PluginServices.getText(this, "shortest_path_not_found"));
102 104
						return;
103 105
					}
104
					GvSession.getInstance().put(mapCtrl, "Route", route);
106
					List routes = (List) GvSession.getInstance().get(mapCtrl, "Route");
107
					if(routes == null){
108
						routes = new ArrayList();
109
						GvSession.getInstance().put(mapCtrl, "Route", routes);
110
					}
111
					routes.add(route);
105 112
					
106 113
					createGraphicsFrom(route.getFeatureList(), v.getMapControl());
107
					
108 114
					RouteReportPanel routeReport = new RouteReportPanel(route, v.getMapControl());
109 115
					PluginServices.getMDIManager().addWindow(routeReport);
116
					List reportsPanels = (List) GvSession.getInstance().get(mapCtrl, "RouteReport");
117
					if(reportsPanels == null){
118
						reportsPanels = new ArrayList();
119
						GvSession.getInstance().put(mapCtrl, "RouteReport", reportsPanels);
120
					}	
121
					reportsPanels.add(routeReport);
110 122
					
111

  
112 123
				} catch (GraphException e) {
113 124
					// TODO Auto-generated catch block
114 125
					e.printStackTrace();
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/topology/lineclean/fmap/LineCleanGeoprocess.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.3  2006-10-19 16:06:48  azabala
48
* Revision 1.4  2006-11-09 21:08:32  azabala
49 49
* *** empty log message ***
50 50
*
51
* Revision 1.3  2006/10/19 16:06:48  azabala
52
* *** empty log message ***
53
*
51 54
* Revision 1.2  2006/10/17 18:25:53  azabala
52 55
* *** empty log message ***
53 56
*
......
231 234
			try {
232 235
				strategy.process(visitor, this);
233 236
			} catch (Exception e) {
234
				throw new GeoprocessException("Error al ejecutar el geoproceso line clean ");
237
				throw new GeoprocessException("Error al ejecutar el geoproceso line clean ", e);
235 238
			}
236 239
		}
237 240

  
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/util/SnappingCoordinateMap.java
1
/*
2
 * Created on 09-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  2006-11-09 21:08:32  azabala
49
 * *** empty log message ***
50
 *
51
 *
52
 */
53
package com.iver.cit.gvsig.util;
54

  
55
import java.util.Comparator;
56
import java.util.Hashtable;
57

  
58
import com.vividsolutions.jts.geom.Coordinate;
59
import com.vividsolutions.jts.geomgraph.Node;
60

  
61
public class SnappingCoordinateMap extends Hashtable {
62
	class SnapCoordinate extends Coordinate {
63
		public SnapCoordinate(Coordinate arg0) {
64
			super(arg0);
65
		}
66

  
67
		public boolean equals(Object obj) {
68
			SnapCoordinate other = (SnapCoordinate) obj;
69
			return other.distance(this) <= snapTolerance;
70
		}
71

  
72
		public int hashCode() {
73
			return 1; // esto no es eficiente
74
		}
75
	}
76

  
77
	private double snapTolerance;
78

  
79
	public SnappingCoordinateMap(double snapTolerance) {
80
		super();
81
		this.snapTolerance = snapTolerance;
82
	}
83

  
84
	class MinDistCoordComparator implements Comparator {
85
		Coordinate coord;
86

  
87
		MinDistCoordComparator(Coordinate coord) {
88
			this.coord = coord;
89
		}
90

  
91
		public int compare(Object arg0, Object arg1) {
92
			Coordinate c1 = ((Node) arg0).getCoordinate();
93
			Coordinate c2 = ((Node) arg1).getCoordinate();
94

  
95
			double d1 = c1.distance(coord);
96
			double d2 = c2.distance(coord);
97

  
98
			if (d1 < d2)
99
				return 1;
100
			if (d1 > d2)
101
				return -1;
102
			else
103
				return 0;
104
		}
105
	}
106
	
107
	
108
	public Object put(Object key, Object obj){
109
		if(! (key instanceof Coordinate) )
110
			return null;
111
		return super.put(new SnapCoordinate((Coordinate)key),
112
				obj);
113
	}
114
	
115
	public Object get(Object key){
116
		if(! (key instanceof Coordinate) )
117
			return null;
118
		return get(new SnapCoordinate((Coordinate)key));
119
	}
120
	
121
	public boolean containsKey(Object key){
122
		if(! (key instanceof Coordinate) )
123
			return false;
124
		return super.containsKey(new SnapCoordinate((Coordinate)key));
125
	}
126
	
127
	public static void main(String[] args){
128
		SnappingCoordinateMap map = 
129
			new SnappingCoordinateMap(0.1);
130
		Coordinate c0 = new Coordinate(0, 0);
131
		Coordinate c1 = new Coordinate(0.01, 0.01);
132
		Coordinate c2 = new Coordinate(0.31, 0.41);
133
		map.put(c0, c0);
134
		map.put(c1, c1);
135
		map.put(c2, c2);
136
		System.out.println(map.size());
137
		java.util.Set values = map.entrySet();
138
		System.out.println(values.size());
139
	}
140

  
141
}
0 142

  

Also available in: Unified diff