svn-gvsig-desktop / tags / v1_1_2_Build_1044 / prototypes / VectorialAvanzado / extensions / extGraph / src / com / iver / cit / gvsig / graph / ODMatrixExtension.java @ 20099
History | View | Annotate | Download (5.54 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.Component; |
44 |
import java.io.BufferedWriter; |
45 |
import java.io.FileWriter; |
46 |
import java.io.IOException; |
47 |
|
48 |
import javax.swing.JFileChooser; |
49 |
import javax.swing.JOptionPane; |
50 |
|
51 |
import com.iver.andami.PluginServices; |
52 |
import com.iver.andami.plugins.Extension; |
53 |
import com.iver.andami.ui.mdiManager.IWindow; |
54 |
import com.iver.cit.gvsig.fmap.MapContext; |
55 |
import com.iver.cit.gvsig.fmap.MapControl; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
57 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
58 |
import com.iver.cit.gvsig.graph.core.GraphException; |
59 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
60 |
import com.iver.cit.gvsig.graph.core.Network; |
61 |
import com.iver.cit.gvsig.graph.solvers.OneToManySolver; |
62 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
63 |
|
64 |
public class ODMatrixExtension extends Extension { |
65 |
|
66 |
|
67 |
|
68 |
public void initialize() { |
69 |
} |
70 |
|
71 |
public void execute(String actionCommand) { |
72 |
|
73 |
View v = (View) PluginServices.getMDIManager().getActiveWindow(); |
74 |
MapContext map = v.getMapControl().getMapContext(); |
75 |
SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
|
76 |
|
77 |
if (actionCommand.equals("ODMATRIX")) { |
78 |
while (it.hasNext())
|
79 |
{ |
80 |
FLayer aux = it.next(); |
81 |
if (!aux.isActive())
|
82 |
continue;
|
83 |
Network net = (Network) aux.getProperty("network");
|
84 |
|
85 |
if ( net != null) |
86 |
{ |
87 |
GvFlag[] flags = net.getFlags();
|
88 |
if(flags.length == 0) |
89 |
{ |
90 |
JOptionPane.showMessageDialog(null, "Primero carga las paradas."); |
91 |
return;
|
92 |
} |
93 |
|
94 |
// PluginServices.getMDIManager().addWindow(new RouteControlPanel(net));
|
95 |
JFileChooser dlg = new JFileChooser(); |
96 |
if (dlg.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) |
97 |
{ |
98 |
// RandomAccessFile file = null;
|
99 |
// try {
|
100 |
// file = new RandomAccessFile(dlg.getSelectedFile(), "rw");
|
101 |
// } catch (FileNotFoundException e1) {
|
102 |
// // TODO Auto-generated catch block
|
103 |
// e1.printStackTrace();
|
104 |
// }
|
105 |
BufferedWriter output;
|
106 |
try {
|
107 |
output = new BufferedWriter(new FileWriter(dlg.getSelectedFile())); |
108 |
// output.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
109 |
|
110 |
OneToManySolver solver = new OneToManySolver();
|
111 |
solver.setNetwork(net); |
112 |
solver.putDestinationsOnNetwork(); |
113 |
for (int i=0; i < flags.length; i++) |
114 |
{ |
115 |
|
116 |
solver.setSourceFlag(flags[i]); |
117 |
long t1 = System.currentTimeMillis(); |
118 |
|
119 |
solver.calculate(); |
120 |
long t2 = System.currentTimeMillis(); |
121 |
System.out.println("Punto " + i + " de " + flags.length + ". " + (t2-t1) + " msecs."); |
122 |
// Escribe el resultado
|
123 |
// idNodo1 idNodo2 tiempo distancia
|
124 |
|
125 |
for (int j=0; j < flags.length; j++) |
126 |
{ |
127 |
long secs = Math.round(flags[j].getCost()); |
128 |
long meters = Math.round(flags[j].getAccumulatedLength()); |
129 |
String strAux = i + "\t" + j + "\t" + secs + "\t" + meters; |
130 |
output.write(strAux); |
131 |
output.newLine(); |
132 |
|
133 |
} |
134 |
long t3 = System.currentTimeMillis(); |
135 |
System.out.println("T. de escritura: " + (t3-t2) + " msecs."); |
136 |
|
137 |
} |
138 |
solver.removeDestinationsFromNetwork(); |
139 |
output.flush(); |
140 |
output.close(); |
141 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
142 |
PluginServices.getText(this,"fichero_generado")); |
143 |
} catch (IOException e) { |
144 |
// TODO Auto-generated catch block
|
145 |
e.printStackTrace(); |
146 |
} catch (GraphException e) {
|
147 |
// TODO Auto-generated catch block
|
148 |
e.printStackTrace(); |
149 |
} |
150 |
} // if
|
151 |
|
152 |
return;
|
153 |
} |
154 |
} |
155 |
} |
156 |
|
157 |
|
158 |
} |
159 |
|
160 |
|
161 |
public boolean isEnabled() { |
162 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
163 |
if (window instanceof View) |
164 |
{ |
165 |
View v = (View) window; |
166 |
MapControl mapCtrl = v.getMapControl(); |
167 |
MapContext map = mapCtrl.getMapContext(); |
168 |
|
169 |
SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
|
170 |
while (it.hasNext())
|
171 |
{ |
172 |
FLayer aux = it.next(); |
173 |
if (!aux.isActive())
|
174 |
continue;
|
175 |
Network net = (Network) aux.getProperty("network");
|
176 |
|
177 |
if ( net != null) |
178 |
{ |
179 |
return true; |
180 |
} |
181 |
} |
182 |
} |
183 |
return false; |
184 |
} |
185 |
|
186 |
public boolean isVisible() { |
187 |
IWindow f = PluginServices.getMDIManager() |
188 |
.getActiveWindow(); |
189 |
if (f == null) { |
190 |
return false; |
191 |
} |
192 |
if (f instanceof View) { |
193 |
return true; |
194 |
} |
195 |
return false; |
196 |
|
197 |
} |
198 |
|
199 |
|
200 |
} |
201 |
|
202 |
|