Revision 8646
trunk/extensions/extGraph_predes/config/config.xml | ||
---|---|---|
15 | 15 |
/> |
16 | 16 |
|
17 | 17 |
</extension> --> |
18 |
<extension class-name="com.iver.cit.gvsig.graph.NetworkExtension" |
|
19 |
description="Network Extension for gvSIG." |
|
18 |
<extension class-name="com.iver.cit.gvsig.graph.GenerateNetworkExtension"
|
|
19 |
description="Generate Network Extension for gvSIG."
|
|
20 | 20 |
active="true"> |
21 | 21 |
<menu text="Network/Create_Network" tooltip="Generar_Red" |
22 | 22 |
action-command="GENERATE_RED" |
23 | 23 |
icon="images/build_graph.gif" /> |
24 | 24 |
|
25 |
</extension> |
|
26 |
<extension class-name="com.iver.cit.gvsig.graph.LoadNetworkExtension" |
|
27 |
description="Load Network for gvSIG." |
|
28 |
active="true"> |
|
29 |
|
|
25 | 30 |
<menu text="Network/Load_Network" tooltip="Load_Red" |
26 | 31 |
action-command="LOAD_RED" |
27 | 32 |
icon="images/network.png" /> |
... | ... | |
31 | 36 |
icon="images/network.png" /> --> |
32 | 37 |
|
33 | 38 |
</extension> |
39 |
|
|
34 | 40 |
<extension class-name="com.iver.cit.gvsig.graph.ManageFlagsExtension" |
35 | 41 |
description="Manage flags." |
36 | 42 |
active="true"> |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/NetworkExtension.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.graph; |
|
42 |
|
|
43 |
import java.awt.Component; |
|
44 |
import java.io.File; |
|
45 |
import java.sql.Types; |
|
46 |
import java.util.ArrayList; |
|
47 |
|
|
48 |
import javax.swing.ImageIcon; |
|
49 |
import javax.swing.JComponent; |
|
50 |
import javax.swing.JOptionPane; |
|
51 |
|
|
52 |
import com.iver.andami.PluginServices; |
|
53 |
import com.iver.andami.messages.NotificationManager; |
|
54 |
import com.iver.andami.plugins.Extension; |
|
55 |
import com.iver.andami.preferences.IPreference; |
|
56 |
import com.iver.andami.preferences.IPreferenceExtension; |
|
57 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
58 |
import com.iver.cit.gvsig.ProjectExtension; |
|
59 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
60 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
61 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
62 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
63 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
64 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
65 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
66 |
import com.iver.cit.gvsig.fmap.edition.writers.dbf.DbfWriter; |
|
67 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
68 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
69 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
70 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
|
71 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
|
72 |
import com.iver.cit.gvsig.graph.core.IGraph; |
|
73 |
import com.iver.cit.gvsig.graph.core.Network; |
|
74 |
import com.iver.cit.gvsig.graph.core.loaders.NetworkLoader; |
|
75 |
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader; |
|
76 |
import com.iver.cit.gvsig.graph.core.writers.NetworkFileRedWriter; |
|
77 |
import com.iver.cit.gvsig.graph.core.writers.NetworkGvTableWriter; |
|
78 |
import com.iver.cit.gvsig.graph.gui.RouteControlPanel; |
|
79 |
import com.iver.cit.gvsig.graph.gui.wizard.NetWizard; |
|
80 |
import com.iver.cit.gvsig.graph.preferences.RoutePage; |
|
81 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
|
82 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
|
83 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
|
84 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
85 |
import com.iver.cit.gvsig.util.GvSession; |
|
86 |
import com.iver.utiles.swing.threads.AbstractMonitorableTask; |
|
87 |
|
|
88 |
public class NetworkExtension extends Extension implements IPreferenceExtension { |
|
89 |
private static final IPreference thePreferencePage = new RoutePage(); |
|
90 |
|
|
91 |
/** |
|
92 |
* Component to control flags and routes |
|
93 |
* */ |
|
94 |
private RouteControlPanel controlPanel; |
|
95 |
|
|
96 |
// private String fieldType; |
|
97 |
// private String fieldDist; |
|
98 |
// private String fieldSense; |
|
99 |
|
|
100 |
public void initialize() { |
|
101 |
} |
|
102 |
|
|
103 |
public void execute(String actionCommand) { |
|
104 |
IView view = (View) PluginServices.getMDIManager().getActiveWindow(); |
|
105 |
MapControl mapControl = view.getMapControl(); |
|
106 |
MapContext map = mapControl.getMapContext(); |
|
107 |
SingleLayerIterator lyrIterator = new SingleLayerIterator(map |
|
108 |
.getLayers()); |
|
109 |
while (lyrIterator.hasNext()) { |
|
110 |
FLayer lyr = lyrIterator.next(); |
|
111 |
if ((lyr.isActive()) && (lyr instanceof FLyrVect)) |
|
112 |
{ |
|
113 |
FLyrVect lyrVect = (FLyrVect) lyr; |
|
114 |
int shapeType; |
|
115 |
try { |
|
116 |
shapeType = lyrVect.getShapeType(); |
|
117 |
if (shapeType == FShape.LINE) |
|
118 |
{ |
|
119 |
if (actionCommand.equalsIgnoreCase("GENERATE_RED")) { |
|
120 |
generateRedNetwork(lyrVect); |
|
121 |
return; |
|
122 |
} |
|
123 |
if (actionCommand.equalsIgnoreCase("LOAD_RED")) { |
|
124 |
loadNetwork(lyrVect); |
|
125 |
return; |
|
126 |
} |
|
127 |
if (actionCommand.equalsIgnoreCase("MANAGE_FLAGS")) { |
|
128 |
manageFlags(lyrVect, mapControl); |
|
129 |
return; |
|
130 |
} |
|
131 |
} |
|
132 |
} catch (DriverException e) { |
|
133 |
e.printStackTrace(); |
|
134 |
NotificationManager.addError(e); |
|
135 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
136 |
e.printStackTrace(); |
|
137 |
NotificationManager.addError(e); |
|
138 |
} |
|
139 |
|
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
|
|
144 |
} |
|
145 |
|
|
146 |
private void manageFlags(FLyrVect lyrVect, MapControl mapControl) { |
|
147 |
Network net = (Network) lyrVect.getProperty("network"); |
|
148 |
|
|
149 |
if ( net != null) |
|
150 |
{ |
|
151 |
if(controlPanel == null) |
|
152 |
{ |
|
153 |
|
|
154 |
controlPanel = new RouteControlPanel(net); |
|
155 |
} |
|
156 |
controlPanel.setMapControl(mapControl, net); |
|
157 |
//lo guardamos en una variable de sesion para poder recuperarlo |
|
158 |
//(ejemplo: cuando borremos los flags de la red de la capa activa |
|
159 |
//borraremos a su vez el contenido del control panel |
|
160 |
controlPanel = (RouteControlPanel) PluginServices.getMDIManager().addWindow(controlPanel); |
|
161 |
GvSession.getInstance().put(mapControl, "RouteControlPanel", controlPanel); |
|
162 |
} |
|
163 |
else |
|
164 |
{ |
|
165 |
JOptionPane.showMessageDialog((JComponent) PluginServices.getMDIManager().getActiveWindow(), |
|
166 |
PluginServices.getText(this, "la_capa_no_tiene_red_asociada")); |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* Suponemos que en el proyecto hay 2 tablas, una con los nodos |
|
172 |
* y otro con los edges. |
|
173 |
* Cargamos la red a partir de esas tablas y se la |
|
174 |
* asociamos a la capa. A partir de ah?, nuestras |
|
175 |
* herramientas pueden ver si la capa activa tiene |
|
176 |
* asociada o no una red y ponerse visibles / invisibles |
|
177 |
* Otra posible soluci?n es llevar nuestra propia lista de capas |
|
178 |
* con red (que ser? peque?ita), y as?, en lugar de recorrer |
|
179 |
* el MapContext, recorremos nuestra lista para ver la |
|
180 |
* capa que est? activa y con red. Me empieza a preocupar |
|
181 |
* que todas las herramientas iteren por la colecci?n de |
|
182 |
* capas para habilitarse/deshabilitarse: |
|
183 |
* 100 herramientas * 100 capas = 10.000 comprobaciones |
|
184 |
* Si comprobar algo cuesta 1 mseg => 10 segundos!!! |
|
185 |
* @param lyrVect |
|
186 |
*/ |
|
187 |
private void loadNetworkFromTables(FLyrVect lyrVect) { |
|
188 |
// Aqu? mostrar un di?lgo para seleccionar las tablas |
|
189 |
// de nodos y edges |
|
190 |
// y hacer un mapping (si es necesario) entre los |
|
191 |
// nombres de campos |
|
192 |
String tableNodes = "Nodes"; |
|
193 |
String tableEdges = "Edges"; |
|
194 |
|
|
195 |
ProjectExtension projectExt = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
|
196 |
|
|
197 |
ProjectTable ptNodes = projectExt.getProject().getTable(tableNodes); |
|
198 |
ProjectTable ptEdges = projectExt.getProject().getTable(tableEdges); |
|
199 |
|
|
200 |
SelectableDataSource sdsNodes = ptNodes.getModelo().getRecordset(); |
|
201 |
|
|
202 |
|
|
203 |
SelectableDataSource sdsEdges = ptEdges.getModelo().getRecordset(); |
|
204 |
|
|
205 |
NetworkLoader netLoader = new NetworkLoader(true); |
|
206 |
|
|
207 |
netLoader.setNodeReader(sdsNodes); |
|
208 |
netLoader.setEdgeReader(sdsEdges); |
|
209 |
|
|
210 |
IGraph g = netLoader.loadNetwork(); |
|
211 |
|
|
212 |
System.out.println("Num nodos=" + g.numVertices() + " numEdges = " + g.numEdges()); |
|
213 |
|
|
214 |
lyrVect.setProperty("network", g); |
|
215 |
|
|
216 |
} |
|
217 |
private void loadNetwork(FLyrVect lyrVect) throws com.hardcode.gdbms.engine.data.driver.DriverException, DriverException { |
|
218 |
// Aqu? mostrar un di?lgo para seleccionar las tablas |
|
219 |
// de nodos y edges |
|
220 |
// y hacer un mapping (si es necesario) entre los |
|
221 |
// nombres de campos |
|
222 |
|
|
223 |
// TODO: MOSTRAR UN CUADRO DE DI?LOGO CON UN COMBOBOX PARA QUE ESCOJA EL CAMPO DE NOMBRE DE CALLE. |
|
224 |
ArrayList aux = new ArrayList(); |
|
225 |
FieldDescription[] fields = lyrVect.getRecordset().getFieldsDescription(); |
|
226 |
for (int i=0; i<fields.length; i++) |
|
227 |
{ |
|
228 |
if (fields[i].getFieldType() == Types.VARCHAR) |
|
229 |
{ |
|
230 |
aux.add(fields[i].getFieldName()); |
|
231 |
} |
|
232 |
} |
|
233 |
String fieldStreetName = (String) JOptionPane.showInputDialog((Component) PluginServices.getMainFrame(), |
|
234 |
PluginServices.getText(this, "select_street_route_field_name"), |
|
235 |
"gvSIG", |
|
236 |
JOptionPane.QUESTION_MESSAGE, |
|
237 |
null, |
|
238 |
(Object[]) aux.toArray(new String[0]), |
|
239 |
"NOMBRE"); |
|
240 |
|
|
241 |
if (fieldStreetName == null) |
|
242 |
return; |
|
243 |
|
|
244 |
|
|
245 |
NetworkRedLoader netLoader = new NetworkRedLoader(); |
|
246 |
File redFile = new File("c:/" + lyrVect.getName().replaceAll("\\Q.shp\\E", ".red")); |
|
247 |
netLoader.setNetFile(redFile); |
|
248 |
|
|
249 |
IGraph g = netLoader.loadNetwork(); |
|
250 |
|
|
251 |
System.out.println("Num nodos=" + g.numVertices() + " numEdges = " + g.numEdges()); |
|
252 |
|
|
253 |
Network net = new Network(); |
|
254 |
// lyrVect.createSpatialIndex(); |
|
255 |
net.setGraph(g); |
|
256 |
net.setLayer(lyrVect); |
|
257 |
ShortestPathExtension.solver.setNetwork(net); |
|
258 |
ShortestPathExtension.solver.setFielStreetName(fieldStreetName); |
|
259 |
|
|
260 |
lyrVect.setProperty("network", net); |
|
261 |
|
|
262 |
} |
|
263 |
|
|
264 |
|
|
265 |
private void generateNetwork(FLyrVect lyr) { |
|
266 |
NetworkGvTableWriter netBuilder = new NetworkGvTableWriter(); |
|
267 |
// Por ahora, a pelo, pero hay que sacar un cuadro |
|
268 |
// de di?logo para hecer el mapping. |
|
269 |
// Tambi?n un cuadro de di?logo para seleccionar |
|
270 |
// en qu? tablas quiere escribir, y su formato |
|
271 |
// (dbf, postgres, etc) |
|
272 |
String fieldType = "tipored"; String fieldDist = "length"; String fieldSense = "sen"; |
|
273 |
String fieldCost = "cost"; |
|
274 |
try { |
|
275 |
netBuilder.setLayer(lyr); |
|
276 |
netBuilder.setFieldType(fieldType); |
|
277 |
netBuilder.setFieldDist(fieldDist); |
|
278 |
netBuilder.setFieldSense(fieldSense); |
|
279 |
netBuilder.setFieldCost(fieldCost); |
|
280 |
DbfWriter nodeWriter = new DbfWriter(); |
|
281 |
nodeWriter.setFile(new File("c:/nodes.dbf")); |
|
282 |
|
|
283 |
DbfWriter edgeWriter = new DbfWriter(); |
|
284 |
edgeWriter.setFile(new File("c:/edges.dbf")); |
|
285 |
|
|
286 |
netBuilder.setEdgeWriter(edgeWriter); |
|
287 |
netBuilder.setNodeWriter(nodeWriter); |
|
288 |
|
|
289 |
netBuilder.writeNetwork(); |
|
290 |
} catch (DriverException e1) { |
|
291 |
// TODO Auto-generated catch block |
|
292 |
e1.printStackTrace(); |
|
293 |
} catch (EditionException e1) { |
|
294 |
// TODO Auto-generated catch block |
|
295 |
e1.printStackTrace(); |
|
296 |
} |
|
297 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done")); |
|
298 |
} |
|
299 |
|
|
300 |
|
|
301 |
class GenerateRedNetworkTask extends AbstractMonitorableTask{ |
|
302 |
FLyrVect layer; |
|
303 |
File redFile; |
|
304 |
NetworkFileRedWriter netBuilder; |
|
305 |
/** |
|
306 |
* Constructor |
|
307 |
* */ |
|
308 |
GenerateRedNetworkTask(FLyrVect layer, File redFile, NetworkFileRedWriter netBuilder){ |
|
309 |
this.layer = layer; |
|
310 |
this.redFile = redFile; |
|
311 |
this.netBuilder = netBuilder; |
|
312 |
setInitialStep(0); |
|
313 |
int numShapes; |
|
314 |
try { |
|
315 |
numShapes = layer.getSource().getShapeCount(); |
|
316 |
setFinalStep(numShapes); |
|
317 |
setDeterminatedProcess(true); |
|
318 |
setStatusMessage(PluginServices. |
|
319 |
getText(this, "Generando_red_a_partir_de_capa_lineal")); |
|
320 |
} catch (DriverIOException e) { |
|
321 |
// TODO Auto-generated catch block |
|
322 |
e.printStackTrace(); |
|
323 |
} |
|
324 |
|
|
325 |
} |
|
326 |
|
|
327 |
public void run() throws Exception { |
|
328 |
netBuilder.setLayer(layer); |
|
329 |
netBuilder.setCancellableMonitorable(this); |
|
330 |
netBuilder.setRedFile(redFile); |
|
331 |
netBuilder.writeNetwork(); |
|
332 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done")); |
|
333 |
} |
|
334 |
|
|
335 |
public String getNote() { |
|
336 |
return "Procesando linea..." + |
|
337 |
" " + |
|
338 |
getCurrentStep()+ |
|
339 |
" "+ |
|
340 |
"de"+ |
|
341 |
" "+ |
|
342 |
getFinishStep(); |
|
343 |
} |
|
344 |
|
|
345 |
public void cancel() { |
|
346 |
setCanceled(true); |
|
347 |
} |
|
348 |
} |
|
349 |
|
|
350 |
|
|
351 |
private void generateRedNetwork(FLyrVect lyr) { |
|
352 |
lyr.createSpatialIndex(); |
|
353 |
NetworkFileRedWriter netBuilder = new NetworkFileRedWriter(); |
|
354 |
// Por ahora, a pelo, pero hay que sacar un cuadro |
|
355 |
// de di?logo para hecer el mapping. |
|
356 |
// Tambi?n un cuadro de di?logo para seleccionar |
|
357 |
// en qu? tablas quiere escribir, y su formato |
|
358 |
// (dbf, postgres, etc) |
|
359 |
|
|
360 |
ImageIcon icon = new ImageIcon(this. |
|
361 |
getClass(). |
|
362 |
getClassLoader(). |
|
363 |
getResource("images/net-wizard-logo.jpg")); |
|
364 |
|
|
365 |
NetWizard wiz = new NetWizard(icon, lyr); |
|
366 |
PluginServices.getMDIManager().addWindow(wiz); |
|
367 |
if(!wiz.wasFinishPressed()) |
|
368 |
return; |
|
369 |
// try { |
|
370 |
String fieldType = wiz.getFieldType(); |
|
371 |
String fieldLength = wiz.getFieldLength(); |
|
372 |
String fieldCost = wiz.getFieldCost(); |
|
373 |
String fieldSense = wiz.getFieldSense(); |
|
374 |
netBuilder.setLayer(lyr); |
|
375 |
netBuilder.setFieldType(fieldType); |
|
376 |
netBuilder.setFieldDist(fieldLength); |
|
377 |
netBuilder.setFieldSense(fieldSense); |
|
378 |
netBuilder.setFieldCost(fieldCost); |
|
379 |
File redFile = new File("c:/" + lyr.getName().replaceAll("\\Q.shp\\E", ".red")); |
|
380 |
|
|
381 |
|
|
382 |
// netBuilder.createRedFile(lyr, redFile); |
|
383 |
|
|
384 |
GenerateRedNetworkTask task = new GenerateRedNetworkTask(lyr, redFile, netBuilder); |
|
385 |
PluginServices.cancelableBackgroundExecution(task); |
|
386 |
|
|
387 |
|
|
388 |
// } catch (DriverException e1) { |
|
389 |
// // TODO Auto-generated catch block |
|
390 |
// e1.printStackTrace(); |
|
391 |
// |
|
392 |
// } |
|
393 |
// JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done")); |
|
394 |
|
|
395 |
} |
|
396 |
|
|
397 |
|
|
398 |
public boolean isEnabled() { |
|
399 |
return true; |
|
400 |
} |
|
401 |
|
|
402 |
public boolean isVisible() { |
|
403 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
|
404 |
|
|
405 |
if (f == null) { |
|
406 |
return false; |
|
407 |
} |
|
408 |
|
|
409 |
if (f instanceof View) { |
|
410 |
View vista = (View) f; |
|
411 |
IProjectView model = vista.getModel(); |
|
412 |
MapContext mapa = model.getMapContext(); |
|
413 |
FLayer[] activeLayers = mapa.getLayers().getActives(); |
|
414 |
if (activeLayers.length > 0) |
|
415 |
if (activeLayers[0] instanceof FLyrVect){ |
|
416 |
FLyrVect lyrVect = (FLyrVect) activeLayers[0]; |
|
417 |
int shapeType ; |
|
418 |
try { |
|
419 |
shapeType = lyrVect.getShapeType(); |
|
420 |
if (shapeType == FShape.LINE) |
|
421 |
return true; |
|
422 |
} catch (DriverException e) { |
|
423 |
// TODO Auto-generated catch block |
|
424 |
e.printStackTrace(); |
|
425 |
} |
|
426 |
} |
|
427 |
} |
|
428 |
return false; |
|
429 |
|
|
430 |
} |
|
431 |
|
|
432 |
public IPreference getPreferencesPage() { |
|
433 |
return thePreferencePage; |
|
434 |
} |
|
435 |
|
|
436 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/GenerateNetworkExtension.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.graph; |
|
42 |
|
|
43 |
import java.io.File; |
|
44 |
|
|
45 |
import javax.swing.ImageIcon; |
|
46 |
import javax.swing.JOptionPane; |
|
47 |
|
|
48 |
import com.iver.andami.PluginServices; |
|
49 |
import com.iver.andami.messages.NotificationManager; |
|
50 |
import com.iver.andami.plugins.Extension; |
|
51 |
import com.iver.andami.preferences.IPreference; |
|
52 |
import com.iver.andami.preferences.IPreferenceExtension; |
|
53 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
54 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
55 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
56 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
57 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
58 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
59 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
60 |
import com.iver.cit.gvsig.fmap.edition.writers.dbf.DbfWriter; |
|
61 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
62 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
63 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
|
64 |
import com.iver.cit.gvsig.graph.core.writers.NetworkFileRedWriter; |
|
65 |
import com.iver.cit.gvsig.graph.core.writers.NetworkGvTableWriter; |
|
66 |
import com.iver.cit.gvsig.graph.gui.wizard.NetWizard; |
|
67 |
import com.iver.cit.gvsig.graph.preferences.RoutePage; |
|
68 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
|
69 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
|
70 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
71 |
import com.iver.utiles.swing.threads.AbstractMonitorableTask; |
|
72 |
|
|
73 |
public class GenerateNetworkExtension extends Extension implements IPreferenceExtension { |
|
74 |
private static final IPreference thePreferencePage = new RoutePage(); |
|
75 |
|
|
76 |
|
|
77 |
public void initialize() { |
|
78 |
} |
|
79 |
|
|
80 |
public void execute(String actionCommand) { |
|
81 |
IView view = (View) PluginServices.getMDIManager().getActiveWindow(); |
|
82 |
MapControl mapControl = view.getMapControl(); |
|
83 |
MapContext map = mapControl.getMapContext(); |
|
84 |
SingleLayerIterator lyrIterator = new SingleLayerIterator(map |
|
85 |
.getLayers()); |
|
86 |
while (lyrIterator.hasNext()) { |
|
87 |
FLayer lyr = lyrIterator.next(); |
|
88 |
if ((lyr.isActive()) && (lyr instanceof FLyrVect)) |
|
89 |
{ |
|
90 |
FLyrVect lyrVect = (FLyrVect) lyr; |
|
91 |
int shapeType; |
|
92 |
try { |
|
93 |
shapeType = lyrVect.getShapeType(); |
|
94 |
if (shapeType == FShape.LINE) |
|
95 |
{ |
|
96 |
if (actionCommand.equalsIgnoreCase("GENERATE_RED")) { |
|
97 |
generateRedNetwork(lyrVect); |
|
98 |
return; |
|
99 |
} |
|
100 |
} |
|
101 |
} catch (DriverException e) { |
|
102 |
e.printStackTrace(); |
|
103 |
NotificationManager.addError(e); |
|
104 |
} |
|
105 |
|
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
private void generateNetwork(FLyrVect lyr) { |
|
114 |
NetworkGvTableWriter netBuilder = new NetworkGvTableWriter(); |
|
115 |
// Por ahora, a pelo, pero hay que sacar un cuadro |
|
116 |
// de di?logo para hecer el mapping. |
|
117 |
// Tambi?n un cuadro de di?logo para seleccionar |
|
118 |
// en qu? tablas quiere escribir, y su formato |
|
119 |
// (dbf, postgres, etc) |
|
120 |
String fieldType = "tipored"; String fieldDist = "length"; String fieldSense = "sen"; |
|
121 |
String fieldCost = "cost"; |
|
122 |
try { |
|
123 |
netBuilder.setLayer(lyr); |
|
124 |
netBuilder.setFieldType(fieldType); |
|
125 |
netBuilder.setFieldDist(fieldDist); |
|
126 |
netBuilder.setFieldSense(fieldSense); |
|
127 |
netBuilder.setFieldCost(fieldCost); |
|
128 |
DbfWriter nodeWriter = new DbfWriter(); |
|
129 |
nodeWriter.setFile(new File("c:/nodes.dbf")); |
|
130 |
|
|
131 |
DbfWriter edgeWriter = new DbfWriter(); |
|
132 |
edgeWriter.setFile(new File("c:/edges.dbf")); |
|
133 |
|
|
134 |
netBuilder.setEdgeWriter(edgeWriter); |
|
135 |
netBuilder.setNodeWriter(nodeWriter); |
|
136 |
|
|
137 |
netBuilder.writeNetwork(); |
|
138 |
} catch (DriverException e1) { |
|
139 |
// TODO Auto-generated catch block |
|
140 |
e1.printStackTrace(); |
|
141 |
} catch (EditionException e1) { |
|
142 |
// TODO Auto-generated catch block |
|
143 |
e1.printStackTrace(); |
|
144 |
} |
|
145 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done")); |
|
146 |
} |
|
147 |
|
|
148 |
|
|
149 |
class GenerateRedNetworkTask extends AbstractMonitorableTask{ |
|
150 |
FLyrVect layer; |
|
151 |
File redFile; |
|
152 |
NetworkFileRedWriter netBuilder; |
|
153 |
/** |
|
154 |
* Constructor |
|
155 |
* */ |
|
156 |
GenerateRedNetworkTask(FLyrVect layer, File redFile, NetworkFileRedWriter netBuilder){ |
|
157 |
this.layer = layer; |
|
158 |
this.redFile = redFile; |
|
159 |
this.netBuilder = netBuilder; |
|
160 |
setInitialStep(0); |
|
161 |
int numShapes; |
|
162 |
try { |
|
163 |
numShapes = layer.getSource().getShapeCount(); |
|
164 |
setFinalStep(numShapes); |
|
165 |
setDeterminatedProcess(true); |
|
166 |
setStatusMessage(PluginServices. |
|
167 |
getText(this, "Generando_red_a_partir_de_capa_lineal")); |
|
168 |
} catch (DriverIOException e) { |
|
169 |
// TODO Auto-generated catch block |
|
170 |
e.printStackTrace(); |
|
171 |
} |
|
172 |
|
|
173 |
} |
|
174 |
|
|
175 |
public void run() throws Exception { |
|
176 |
netBuilder.setLayer(layer); |
|
177 |
netBuilder.setCancellableMonitorable(this); |
|
178 |
netBuilder.setRedFile(redFile); |
|
179 |
netBuilder.writeNetwork(); |
|
180 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done")); |
|
181 |
} |
|
182 |
|
|
183 |
public String getNote() { |
|
184 |
return "Procesando linea..." + |
|
185 |
" " + |
|
186 |
getCurrentStep()+ |
|
187 |
" "+ |
|
188 |
"de"+ |
|
189 |
" "+ |
|
190 |
getFinishStep(); |
|
191 |
} |
|
192 |
|
|
193 |
public void cancel() { |
|
194 |
setCanceled(true); |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
private void generateRedNetwork(FLyrVect lyr) { |
|
200 |
lyr.createSpatialIndex(); |
|
201 |
NetworkFileRedWriter netBuilder = new NetworkFileRedWriter(); |
|
202 |
// Por ahora, a pelo, pero hay que sacar un cuadro |
|
203 |
// de di?logo para hecer el mapping. |
|
204 |
// Tambi?n un cuadro de di?logo para seleccionar |
|
205 |
// en qu? tablas quiere escribir, y su formato |
|
206 |
// (dbf, postgres, etc) |
|
207 |
|
|
208 |
ImageIcon icon = new ImageIcon(this. |
|
209 |
getClass(). |
|
210 |
getClassLoader(). |
|
211 |
getResource("images/net-wizard-logo.jpg")); |
|
212 |
|
|
213 |
NetWizard wiz = new NetWizard(icon, lyr); |
|
214 |
PluginServices.getMDIManager().addWindow(wiz); |
|
215 |
if(!wiz.wasFinishPressed()) |
|
216 |
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 |
|
|
230 |
// netBuilder.createRedFile(lyr, redFile); |
|
231 |
|
|
232 |
GenerateRedNetworkTask task = new GenerateRedNetworkTask(lyr, redFile, netBuilder); |
|
233 |
PluginServices.cancelableBackgroundExecution(task); |
|
234 |
|
|
235 |
|
|
236 |
// } catch (DriverException e1) { |
|
237 |
// // TODO Auto-generated catch block |
|
238 |
// e1.printStackTrace(); |
|
239 |
// |
|
240 |
// } |
|
241 |
// JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done")); |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
|
|
246 |
public boolean isEnabled() { |
|
247 |
return true; |
|
248 |
} |
|
249 |
|
|
250 |
public boolean isVisible() { |
|
251 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
|
252 |
|
|
253 |
if (f == null) { |
|
254 |
return false; |
|
255 |
} |
|
256 |
|
|
257 |
if (f instanceof View) { |
|
258 |
View vista = (View) f; |
|
259 |
IProjectView model = vista.getModel(); |
|
260 |
MapContext mapa = model.getMapContext(); |
|
261 |
FLayer[] activeLayers = mapa.getLayers().getActives(); |
|
262 |
if (activeLayers.length > 0) |
|
263 |
if (activeLayers[0] instanceof FLyrVect){ |
|
264 |
FLyrVect lyrVect = (FLyrVect) activeLayers[0]; |
|
265 |
int shapeType ; |
|
266 |
try { |
|
267 |
shapeType = lyrVect.getShapeType(); |
|
268 |
if (shapeType == FShape.LINE) |
|
269 |
return true; |
|
270 |
} catch (DriverException e) { |
|
271 |
// TODO Auto-generated catch block |
|
272 |
e.printStackTrace(); |
|
273 |
} |
|
274 |
} |
|
275 |
} |
|
276 |
return false; |
|
277 |
|
|
278 |
} |
|
279 |
|
|
280 |
public IPreference getPreferencesPage() { |
|
281 |
return thePreferencePage; |
|
282 |
} |
|
283 |
|
|
284 |
} |
|
0 | 285 |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/gui/HTMLEditorKit.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.1 2006-10-20 19:54:01 azabala |
|
48 |
* Revision 1.2 2006-11-09 12:25:06 fjp |
|
49 |
* El fichero de red pasa a llamarse .net y se escribe sobre el directorio temporal del usuario. Tambi?n se mira si existe ah? para habilitar/deshabilitar la opci?n de carga. |
|
50 |
* |
|
51 |
* Revision 1.1 2006/10/20 19:54:01 azabala |
|
49 | 52 |
* *** empty log message *** |
50 | 53 |
* |
51 | 54 |
* |
... | ... | |
58 | 61 |
import javax.swing.text.ViewFactory; |
59 | 62 |
import javax.swing.text.html.HTML; |
60 | 63 |
|
61 |
import com.iver.cit.gvsig.graph.NetworkExtension; |
|
64 |
import com.iver.cit.gvsig.graph.GenerateNetworkExtension;
|
|
62 | 65 |
|
63 | 66 |
|
64 | 67 |
public class HTMLEditorKit extends javax.swing.text.html.HTMLEditorKit { |
... | ... | |
76 | 79 |
if (o instanceof HTML.Tag) { |
77 | 80 |
HTML.Tag kind = (HTML.Tag) o; |
78 | 81 |
if (kind == HTML.Tag.IMG) |
79 |
return new ImageView(elem, NetworkExtension.class ); |
|
82 |
return new ImageView(elem, GenerateNetworkExtension.class );
|
|
80 | 83 |
} |
81 | 84 |
return super.create( elem ); |
82 | 85 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/NetworkUtils.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.cit.gvsig.graph; |
42 | 42 |
|
43 |
import java.io.File; |
|
44 |
|
|
43 | 45 |
import com.iver.cit.gvsig.fmap.MapControl; |
46 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
44 | 47 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
45 | 48 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
46 | 49 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
... | ... | |
81 | 84 |
graphics.removeGraphic(aux); |
82 | 85 |
} |
83 | 86 |
} |
87 |
|
|
88 |
public static File getNetworkFile(FLayer lyr) { |
|
89 |
String directoryName = System.getProperty("java.io.tmpdir"); |
|
90 |
String aux = lyr.getName().replaceAll("\\Q.shp\\E", ".net"); |
|
91 |
File newFile = new File(directoryName + |
|
92 |
File.separator + |
|
93 |
aux); |
|
94 |
return newFile; |
|
95 |
|
|
96 |
} |
|
84 | 97 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/LoadNetworkExtension.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.graph; |
|
42 |
|
|
43 |
import java.awt.Component; |
|
44 |
import java.io.File; |
|
45 |
import java.sql.Types; |
|
46 |
import java.util.ArrayList; |
|
47 |
|
|
48 |
import javax.swing.JOptionPane; |
|
49 |
|
|
50 |
import com.iver.andami.PluginServices; |
|
51 |
import com.iver.andami.messages.NotificationManager; |
|
52 |
import com.iver.andami.plugins.Extension; |
|
53 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
54 |
import com.iver.cit.gvsig.ProjectExtension; |
|
55 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
56 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
57 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
58 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
59 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
60 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
61 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
62 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
63 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
|
64 |
import com.iver.cit.gvsig.graph.core.IGraph; |
|
65 |
import com.iver.cit.gvsig.graph.core.Network; |
|
66 |
import com.iver.cit.gvsig.graph.core.loaders.NetworkLoader; |
|
67 |
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader; |
|
68 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
|
69 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
|
70 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
|
71 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
72 |
|
|
73 |
public class LoadNetworkExtension extends Extension { |
|
74 |
|
|
75 |
public void initialize() { |
|
76 |
} |
|
77 |
|
|
78 |
public void execute(String actionCommand) { |
|
79 |
IView view = (View) PluginServices.getMDIManager().getActiveWindow(); |
|
80 |
MapControl mapControl = view.getMapControl(); |
|
81 |
MapContext map = mapControl.getMapContext(); |
|
82 |
SingleLayerIterator lyrIterator = new SingleLayerIterator(map |
|
83 |
.getLayers()); |
|
84 |
while (lyrIterator.hasNext()) { |
|
85 |
FLayer lyr = lyrIterator.next(); |
|
86 |
if ((lyr.isActive()) && (lyr instanceof FLyrVect)) |
|
87 |
{ |
|
88 |
FLyrVect lyrVect = (FLyrVect) lyr; |
|
89 |
int shapeType; |
|
90 |
try { |
|
91 |
shapeType = lyrVect.getShapeType(); |
|
92 |
if (shapeType == FShape.LINE) |
|
93 |
{ |
|
94 |
if (actionCommand.equalsIgnoreCase("LOAD_RED")) { |
|
95 |
loadNetwork(lyrVect); |
|
96 |
return; |
|
97 |
} |
|
98 |
} |
|
99 |
} catch (DriverException e) { |
|
100 |
e.printStackTrace(); |
|
101 |
NotificationManager.addError(e); |
|
102 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
103 |
e.printStackTrace(); |
|
104 |
NotificationManager.addError(e); |
|
105 |
} |
|
106 |
|
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Suponemos que en el proyecto hay 2 tablas, una con los nodos |
|
115 |
* y otro con los edges. |
|
116 |
* Cargamos la red a partir de esas tablas y se la |
|
117 |
* asociamos a la capa. A partir de ah?, nuestras |
|
118 |
* herramientas pueden ver si la capa activa tiene |
|
119 |
* asociada o no una red y ponerse visibles / invisibles |
|
120 |
* Otra posible soluci?n es llevar nuestra propia lista de capas |
|
121 |
* con red (que ser? peque?ita), y as?, en lugar de recorrer |
|
122 |
* el MapContext, recorremos nuestra lista para ver la |
|
123 |
* capa que est? activa y con red. Me empieza a preocupar |
|
124 |
* que todas las herramientas iteren por la colecci?n de |
|
125 |
* capas para habilitarse/deshabilitarse: |
|
126 |
* 100 herramientas * 100 capas = 10.000 comprobaciones |
|
127 |
* Si comprobar algo cuesta 1 mseg => 10 segundos!!! |
|
128 |
* @param lyrVect |
|
129 |
*/ |
|
130 |
private void loadNetworkFromTables(FLyrVect lyrVect) { |
|
131 |
// Aqu? mostrar un di?lgo para seleccionar las tablas |
|
132 |
// de nodos y edges |
|
133 |
// y hacer un mapping (si es necesario) entre los |
|
134 |
// nombres de campos |
|
135 |
String tableNodes = "Nodes"; |
|
136 |
String tableEdges = "Edges"; |
|
137 |
|
|
138 |
ProjectExtension projectExt = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
|
139 |
|
|
140 |
ProjectTable ptNodes = projectExt.getProject().getTable(tableNodes); |
|
141 |
ProjectTable ptEdges = projectExt.getProject().getTable(tableEdges); |
|
142 |
|
|
143 |
SelectableDataSource sdsNodes = ptNodes.getModelo().getRecordset(); |
|
144 |
|
|
145 |
|
|
146 |
SelectableDataSource sdsEdges = ptEdges.getModelo().getRecordset(); |
|
147 |
|
|
148 |
NetworkLoader netLoader = new NetworkLoader(true); |
|
149 |
|
|
150 |
netLoader.setNodeReader(sdsNodes); |
|
151 |
netLoader.setEdgeReader(sdsEdges); |
|
152 |
|
|
153 |
IGraph g = netLoader.loadNetwork(); |
|
154 |
|
|
155 |
System.out.println("Num nodos=" + g.numVertices() + " numEdges = " + g.numEdges()); |
|
156 |
|
|
157 |
lyrVect.setProperty("network", g); |
|
158 |
|
|
159 |
} |
|
160 |
private void loadNetwork(FLyrVect lyrVect) throws com.hardcode.gdbms.engine.data.driver.DriverException, DriverException { |
|
161 |
// Aqu? mostrar un di?lgo para seleccionar las tablas |
|
162 |
// de nodos y edges |
|
163 |
// y hacer un mapping (si es necesario) entre los |
|
164 |
// nombres de campos |
|
165 |
|
|
166 |
// TODO: MOSTRAR UN CUADRO DE DI?LOGO CON UN COMBOBOX PARA QUE ESCOJA EL CAMPO DE NOMBRE DE CALLE. |
|
167 |
ArrayList aux = new ArrayList(); |
|
168 |
FieldDescription[] fields = lyrVect.getRecordset().getFieldsDescription(); |
|
169 |
for (int i=0; i<fields.length; i++) |
|
170 |
{ |
|
171 |
if (fields[i].getFieldType() == Types.VARCHAR) |
|
172 |
{ |
|
173 |
aux.add(fields[i].getFieldName()); |
|
174 |
} |
|
175 |
} |
|
176 |
String fieldStreetName = (String) JOptionPane.showInputDialog((Component) PluginServices.getMainFrame(), |
|
177 |
PluginServices.getText(this, "select_street_route_field_name"), |
|
178 |
"gvSIG", |
|
179 |
JOptionPane.QUESTION_MESSAGE, |
|
180 |
null, |
|
181 |
(Object[]) aux.toArray(new String[0]), |
|
182 |
"NOMBRE"); |
|
183 |
|
|
184 |
if (fieldStreetName == null) |
|
185 |
return; |
|
186 |
|
|
187 |
|
|
188 |
NetworkRedLoader netLoader = new NetworkRedLoader(); |
|
189 |
File redFile = NetworkUtils.getNetworkFile(lyrVect); |
|
190 |
netLoader.setNetFile(redFile); |
|
191 |
|
|
192 |
IGraph g = netLoader.loadNetwork(); |
|
193 |
|
|
194 |
System.out.println("Num nodos=" + g.numVertices() + " numEdges = " + g.numEdges()); |
|
195 |
|
|
196 |
Network net = new Network(); |
|
197 |
// lyrVect.createSpatialIndex(); |
|
198 |
net.setGraph(g); |
|
199 |
net.setLayer(lyrVect); |
|
200 |
ShortestPathExtension.solver.setNetwork(net); |
|
201 |
ShortestPathExtension.solver.setFielStreetName(fieldStreetName); |
|
202 |
|
|
203 |
lyrVect.setProperty("network", net); |
|
204 |
|
|
205 |
} |
|
206 |
|
|
207 |
public boolean isEnabled() { |
|
208 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
|
209 |
|
|
210 |
if (f == null) { |
|
211 |
return false; |
|
212 |
} |
|
213 |
|
|
214 |
if (f instanceof View) { |
|
215 |
View vista = (View) f; |
|
216 |
IProjectView model = vista.getModel(); |
|
217 |
MapContext mapa = model.getMapContext(); |
|
218 |
FLayer[] activeLayers = mapa.getLayers().getActives(); |
|
219 |
if (activeLayers.length > 0) |
|
220 |
if (activeLayers[0] instanceof FLyrVect){ |
|
221 |
FLyrVect lyrVect = (FLyrVect) activeLayers[0]; |
|
222 |
File netFile = NetworkUtils.getNetworkFile(lyrVect); |
|
223 |
if (netFile.exists()) |
|
224 |
return true; |
|
225 |
|
|
226 |
} |
|
227 |
} |
|
228 |
return false; |
|
229 |
} |
|
230 |
|
|
231 |
public boolean isVisible() { |
|
232 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
|
233 |
|
|
234 |
if (f == null) { |
|
235 |
return false; |
|
236 |
} |
|
237 |
|
|
238 |
if (f instanceof View) { |
|
239 |
View vista = (View) f; |
|
240 |
IProjectView model = vista.getModel(); |
|
241 |
MapContext mapa = model.getMapContext(); |
|
242 |
FLayer[] activeLayers = mapa.getLayers().getActives(); |
|
243 |
if (activeLayers.length > 0) |
|
244 |
if (activeLayers[0] instanceof FLyrVect){ |
|
245 |
FLyrVect lyrVect = (FLyrVect) activeLayers[0]; |
|
246 |
int shapeType ; |
|
247 |
try { |
|
248 |
shapeType = lyrVect.getShapeType(); |
|
249 |
if (shapeType == FShape.LINE) |
|
250 |
return true; |
|
251 |
} catch (DriverException e) { |
|
252 |
// TODO Auto-generated catch block |
|
253 |
e.printStackTrace(); |
|
254 |
} |
|
255 |
} |
|
256 |
} |
|
257 |
return false; |
|
258 |
|
|
259 |
} |
|
260 |
|
|
261 |
|
|
262 |
} |
|
0 | 263 |
Also available in: Unified diff