40 |
40 |
*/
|
41 |
41 |
package com.iver.cit.gvsig.graph;
|
42 |
42 |
|
|
43 |
import java.io.File;
|
|
44 |
|
|
45 |
import javax.swing.JOptionPane;
|
|
46 |
|
43 |
47 |
import com.iver.andami.PluginServices;
|
44 |
48 |
import com.iver.andami.plugins.Extension;
|
45 |
49 |
import com.iver.andami.ui.mdiManager.IWindow;
|
|
50 |
import com.iver.cit.gvsig.ProjectExtension;
|
46 |
51 |
import com.iver.cit.gvsig.fmap.DriverException;
|
47 |
52 |
import com.iver.cit.gvsig.fmap.MapContext;
|
48 |
53 |
import com.iver.cit.gvsig.fmap.MapControl;
|
49 |
54 |
import com.iver.cit.gvsig.fmap.core.FShape;
|
|
55 |
import com.iver.cit.gvsig.fmap.edition.EditionException;
|
|
56 |
import com.iver.cit.gvsig.fmap.edition.writers.dbf.DbfWriter;
|
50 |
57 |
import com.iver.cit.gvsig.fmap.layers.FLayer;
|
51 |
58 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
|
|
59 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
|
52 |
60 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator;
|
|
61 |
import com.iver.cit.gvsig.graph.core.NetworkLoader;
|
|
62 |
import com.iver.cit.gvsig.graph.core.NetworkWriter;
|
|
63 |
import com.iver.cit.gvsig.project.Project;
|
|
64 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
|
53 |
65 |
import com.iver.cit.gvsig.project.documents.view.IProjectView;
|
54 |
66 |
import com.iver.cit.gvsig.project.documents.view.gui.IView;
|
55 |
67 |
import com.iver.cit.gvsig.project.documents.view.gui.View;
|
56 |
68 |
|
|
69 |
import edu.uci.ics.jung.graph.Graph;
|
|
70 |
|
57 |
71 |
public class NetworkExtension extends Extension {
|
58 |
72 |
|
|
73 |
// private String fieldType;
|
|
74 |
// private String fieldDist;
|
|
75 |
// private String fieldSense;
|
|
76 |
|
59 |
77 |
public void initialize() {
|
60 |
78 |
}
|
61 |
79 |
|
... | ... | |
75 |
93 |
shapeType = lyrVect.getShapeType();
|
76 |
94 |
if (shapeType == FShape.LINE)
|
77 |
95 |
{
|
78 |
|
generateNetwork(lyrVect);
|
|
96 |
if (actionCommand.equalsIgnoreCase("GENERAR_RED")) {
|
|
97 |
generateNetwork(lyrVect);
|
|
98 |
}
|
|
99 |
if (actionCommand.equalsIgnoreCase("LOAD_RED")) {
|
|
100 |
loadNetwork(lyrVect);
|
|
101 |
}
|
79 |
102 |
}
|
80 |
103 |
} catch (DriverException e) {
|
81 |
104 |
// TODO Auto-generated catch block
|
... | ... | |
85 |
108 |
}
|
86 |
109 |
}
|
87 |
110 |
|
88 |
|
if (actionCommand.equalsIgnoreCase("GENERAR_RED")) {
|
89 |
111 |
|
90 |
|
}
|
91 |
|
if (actionCommand.equalsIgnoreCase("LOAD_RED")) {
|
|
112 |
}
|
92 |
113 |
|
93 |
|
}
|
94 |
|
|
|
114 |
/**
|
|
115 |
* Suponemos que en el proyecto hay 2 tablas, una con los nodos
|
|
116 |
* y otro con los edges.
|
|
117 |
* Cargamos la red a partir de esas tablas y se la
|
|
118 |
* asociamos a la capa. A partir de ah?, nuestras
|
|
119 |
* herramientas pueden ver si la capa activa tiene
|
|
120 |
* asociada o no una red y ponerse visibles / invisibles
|
|
121 |
* Otra posible soluci?n es llevar nuestra propia lista de capas
|
|
122 |
* con red (que ser? peque?ita), y as?, en lugar de recorrer
|
|
123 |
* el MapContext, recorremos nuestra lista para ver la
|
|
124 |
* capa que est? activa y con red. Me empieza a preocupar
|
|
125 |
* que todas las herramientas iteren por la colecci?n de
|
|
126 |
* capas para habilitarse/deshabilitarse:
|
|
127 |
* 100 herramientas * 100 capas = 10.000 comprobaciones
|
|
128 |
* Si comprobar algo cuesta 1 mseg => 10 segundos!!!
|
|
129 |
* @param lyrVect
|
|
130 |
*/
|
|
131 |
private void loadNetwork(FLyrVect lyrVect) {
|
|
132 |
// Aqu? mostrar un di?lgo para seleccionar las tablas
|
|
133 |
// de nodos y edges
|
|
134 |
// y hacer un mapping (si es necesario) entre los
|
|
135 |
// nombres de campos
|
|
136 |
String tableNodes = "Nodes";
|
|
137 |
String tableEdges = "Edges";
|
|
138 |
|
|
139 |
ProjectExtension projectExt = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
|
|
140 |
|
|
141 |
ProjectTable ptNodes = projectExt.getProject().getTable(tableNodes);
|
|
142 |
ProjectTable ptEdges = projectExt.getProject().getTable(tableEdges);
|
|
143 |
|
|
144 |
SelectableDataSource sdsNodes = ptNodes.getModelo().getRecordset();
|
|
145 |
SelectableDataSource sdsEdges = ptEdges.getModelo().getRecordset();
|
|
146 |
|
|
147 |
NetworkLoader netLoader = new NetworkLoader();
|
|
148 |
|
|
149 |
netLoader.setNodeReader(sdsNodes);
|
|
150 |
netLoader.setEdgeReader(sdsEdges);
|
|
151 |
|
|
152 |
|
|
153 |
Graph g = netLoader.loadNetwork();
|
|
154 |
|
|
155 |
System.out.println("Num nodos=" + g.numVertices() + " numEdges = " + g.numEdges());
|
|
156 |
|
|
157 |
lyrVect.setProperty("network", g);
|
|
158 |
|
95 |
159 |
}
|
96 |
160 |
|
97 |
|
private void generateNetwork(FLyrVect lyrVect) {
|
98 |
|
// TODO Auto-generated method stub
|
|
161 |
private void generateNetwork(FLyrVect lyr) {
|
|
162 |
NetworkWriter netBuilder = new NetworkWriter();
|
|
163 |
// Por ahora, a pelo, pero hay que sacar un cuadro
|
|
164 |
// de di?logo para hecer el mapping.
|
|
165 |
// Tambi?n un cuadro de di?logo para seleccionar
|
|
166 |
// en qu? tablas quiere escribir, y su formato
|
|
167 |
// (dbf, postgres, etc)
|
|
168 |
String fieldType = "tipored"; String fieldDist = "length"; String fieldSense = "sen";
|
|
169 |
try {
|
|
170 |
netBuilder.setLayer(lyr, fieldType, fieldDist, fieldSense);
|
|
171 |
DbfWriter nodeWriter = new DbfWriter();
|
|
172 |
nodeWriter.setFile(new File("c:/nodes.dbf"));
|
|
173 |
|
|
174 |
DbfWriter edgeWriter = new DbfWriter();
|
|
175 |
edgeWriter.setFile(new File("c:/edges.dbf"));
|
|
176 |
|
|
177 |
netBuilder.setEdgeWriter(edgeWriter);
|
|
178 |
netBuilder.setNodeWriter(nodeWriter);
|
|
179 |
|
|
180 |
netBuilder.writeNetwork();
|
|
181 |
} catch (DriverException e1) {
|
|
182 |
// TODO Auto-generated catch block
|
|
183 |
e1.printStackTrace();
|
|
184 |
} catch (EditionException e1) {
|
|
185 |
// TODO Auto-generated catch block
|
|
186 |
e1.printStackTrace();
|
|
187 |
}
|
|
188 |
JOptionPane.showMessageDialog(null, "Hecho. ");
|
99 |
189 |
|
|
190 |
|
100 |
191 |
}
|
101 |
192 |
|
102 |
193 |
public boolean isEnabled() {
|