root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / graph / ShortestPathExtension.java @ 8207
History | View | Annotate | Download (4.18 KB)
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.BasicStroke; |
44 |
import java.awt.Color; |
45 |
import java.awt.Frame; |
46 |
import java.util.Collection; |
47 |
import java.util.Iterator; |
48 |
|
49 |
import com.iver.andami.PluginServices; |
50 |
import com.iver.andami.plugins.Extension; |
51 |
import com.iver.cit.gvsig.fmap.MapContext; |
52 |
import com.iver.cit.gvsig.fmap.MapControl; |
53 |
import com.iver.cit.gvsig.fmap.core.FShape; |
54 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
55 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
56 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
58 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
59 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
60 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
61 |
import com.iver.cit.gvsig.graph.core.Network; |
62 |
import com.iver.cit.gvsig.graph.gui.DlgDirections; |
63 |
import com.iver.cit.gvsig.graph.solvers.Route; |
64 |
import com.iver.cit.gvsig.graph.solvers.ShortestPathSolver; |
65 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
66 |
|
67 |
public class ShortestPathExtension extends Extension { |
68 |
|
69 |
public static ShortestPathSolver solver = new ShortestPathSolver(); |
70 |
private int idSymbolLine = -1; |
71 |
|
72 |
public void initialize() { |
73 |
} |
74 |
|
75 |
public void execute(String actionCommand) { |
76 |
View v = (View) PluginServices.getMDIManager().getActiveWindow(); |
77 |
MapContext map = v.getMapControl().getMapContext(); |
78 |
SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
|
79 |
while (it.hasNext())
|
80 |
{ |
81 |
FLayer aux = it.next(); |
82 |
if (!aux.isActive())
|
83 |
continue;
|
84 |
Network net = (Network) aux.getProperty("network");
|
85 |
|
86 |
if ( net != null) |
87 |
{ |
88 |
Route route; |
89 |
try {
|
90 |
solver.setNetwork(net); |
91 |
// solver.setFielStreetName("STREET_NAM");
|
92 |
route = solver.calculateRoute(); |
93 |
|
94 |
DlgDirections dlg = new DlgDirections((Frame) PluginServices.getMainFrame(), false); |
95 |
dlg.setModel(route.getFeatureList()); |
96 |
// JOptionPane.showMessageDialog(null, route.getInstructions());
|
97 |
createGraphicsFrom(route.getFeatureList(), v.getMapControl()); |
98 |
dlg.setVisible(true);
|
99 |
|
100 |
} catch (GraphException e) {
|
101 |
// TODO Auto-generated catch block
|
102 |
e.printStackTrace(); |
103 |
} |
104 |
} |
105 |
} |
106 |
|
107 |
|
108 |
|
109 |
} |
110 |
|
111 |
private void createGraphicsFrom(Collection featureList, MapControl mapControl) { |
112 |
Iterator it = featureList.iterator();
|
113 |
GraphicLayer graphicLayer = mapControl.getMapContext().getGraphicsLayer(); |
114 |
// if (idSymbolLine == -1)
|
115 |
{ |
116 |
FSymbol lineSymbol = new FSymbol(FShape.LINE, Color.RED); |
117 |
lineSymbol.setStroke(new BasicStroke(3.0f)); |
118 |
idSymbolLine = graphicLayer.addSymbol(lineSymbol); |
119 |
} |
120 |
while (it.hasNext()) {
|
121 |
IFeature feat = (IFeature) it.next(); |
122 |
IGeometry gAux = feat.getGeometry(); |
123 |
FGraphic graphic = new FGraphic(gAux, idSymbolLine);
|
124 |
// Lo insertamos al principio de la lista para que los
|
125 |
// pushpins se dibujen despu?s.
|
126 |
graphicLayer.insertGraphic(0, graphic);
|
127 |
} |
128 |
mapControl.drawGraphics(); |
129 |
|
130 |
} |
131 |
|
132 |
public boolean isEnabled() { |
133 |
// TODO Auto-generated method stub
|
134 |
return true; |
135 |
} |
136 |
|
137 |
public boolean isVisible() { |
138 |
// TODO Auto-generated method stub
|
139 |
return true; |
140 |
} |
141 |
|
142 |
} |
143 |
|
144 |
|