svn-gvsig-desktop / tags / v1_1_Build_1008 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dgn / DgnMemoryDriver.java @ 12520
History | View | Annotate | Download (22.5 KB)
1 | 1517 | fjp | /* ALL THIS WORK ABOUT DGN IS BASED IN DGNLib, from Frank Warmerdam
|
---|---|---|---|
2 | * It is a java port, and is incompleted, just to let gvSIG
|
||
3 | * display DGN's. His DGNLib is more advanced, and must be
|
||
4 | * used as reference.
|
||
5 | * DGNLib: http://dgnlib.maptools.org/
|
||
6 | 5521 | caballero | *
|
7 | * (Thanks, Frank :). For this, and for your very good job with
|
||
8 | 1517 | fjp | * shapefiles. And also for GDAL!!!!
|
9 | */
|
||
10 | |||
11 | 1100 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
12 | *
|
||
13 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
14 | *
|
||
15 | * This program is free software; you can redistribute it and/or
|
||
16 | * modify it under the terms of the GNU General Public License
|
||
17 | * as published by the Free Software Foundation; either version 2
|
||
18 | * of the License, or (at your option) any later version.
|
||
19 | *
|
||
20 | * This program is distributed in the hope that it will be useful,
|
||
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
23 | * GNU General Public License for more details.
|
||
24 | *
|
||
25 | * You should have received a copy of the GNU General Public License
|
||
26 | * along with this program; if not, write to the Free Software
|
||
27 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
28 | *
|
||
29 | * For more information, contact:
|
||
30 | *
|
||
31 | * Generalitat Valenciana
|
||
32 | * Conselleria d'Infraestructures i Transport
|
||
33 | * Av. Blasco Ib??ez, 50
|
||
34 | * 46010 VALENCIA
|
||
35 | * SPAIN
|
||
36 | *
|
||
37 | * +34 963862235
|
||
38 | * gvsig@gva.es
|
||
39 | * www.gvsig.gva.es
|
||
40 | *
|
||
41 | * or
|
||
42 | *
|
||
43 | * IVER T.I. S.A
|
||
44 | * Salamanca 50
|
||
45 | * 46005 Valencia
|
||
46 | * Spain
|
||
47 | *
|
||
48 | * +34 963163400
|
||
49 | * dac@iver.es
|
||
50 | */
|
||
51 | 695 | fjp | package com.iver.cit.gvsig.fmap.drivers.dgn; |
52 | |||
53 | 1828 | fernando | import java.awt.Color; |
54 | import java.awt.Font; |
||
55 | import java.awt.geom.AffineTransform; |
||
56 | import java.awt.geom.Arc2D; |
||
57 | import java.io.File; |
||
58 | import java.io.IOException; |
||
59 | 12290 | caballero | import java.sql.Types; |
60 | 1828 | fernando | import java.util.ArrayList; |
61 | |||
62 | 12290 | caballero | import javax.swing.table.DefaultTableModel; |
63 | |||
64 | 1828 | fernando | import com.hardcode.gdbms.engine.data.driver.DriverException; |
65 | import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
||
66 | 2217 | fernando | import com.hardcode.gdbms.engine.data.edition.DataWare; |
67 | 711 | fjp | import com.hardcode.gdbms.engine.values.IntValue; |
68 | import com.hardcode.gdbms.engine.values.Value; |
||
69 | import com.hardcode.gdbms.engine.values.ValueFactory; |
||
70 | 695 | fjp | import com.iver.cit.gvsig.fmap.core.FPoint2D; |
71 | import com.iver.cit.gvsig.fmap.core.FPoint3D; |
||
72 | import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
||
73 | import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
||
74 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
75 | import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
||
76 | 843 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
77 | 695 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
78 | 1233 | fjp | import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
79 | 695 | fjp | import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
80 | 3271 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
81 | 714 | fjp | import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
82 | 695 | fjp | import com.iver.cit.gvsig.fmap.rendering.Legend; |
83 | 714 | fjp | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
84 | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
||
85 | 695 | fjp | |
86 | |||
87 | /**
|
||
88 | 1005 | vcaballero | * Driver DGN que trabaja directamente cargando el fichero en memoria.
|
89 | 695 | fjp | *
|
90 | * @author Vicente Caballero Navarro
|
||
91 | */
|
||
92 | 3271 | fjp | public class DgnMemoryDriver extends MemoryDriver implements VectorialFileDriver, WithDefaultLegend { |
93 | 1005 | vcaballero | private final int ID_FIELD_ID = 0; |
94 | private final int ID_FIELD_ENTITY = 1; |
||
95 | private final int ID_FIELD_LAYER = 2; |
||
96 | private final int ID_FIELD_COLOR = 3; |
||
97 | private final int ID_FIELD_HEIGHTTEXT = 4; |
||
98 | private final int ID_FIELD_ROTATIONTEXT = 5; |
||
99 | private final int ID_FIELD_TEXT = 6; |
||
100 | 695 | fjp | DGNReader m_DgnReader; |
101 | 714 | fjp | VectorialUniqueValueLegend defaultLegend; |
102 | 695 | fjp | private String path; |
103 | private File m_Fich; |
||
104 | 1233 | fjp | private DriverAttributes attr = new DriverAttributes(); |
105 | 5521 | caballero | |
106 | 1005 | vcaballero | /**
|
107 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
|
||
108 | */
|
||
109 | public void open(File f) throws IOException { |
||
110 | m_Fich = f; |
||
111 | } |
||
112 | 695 | fjp | |
113 | 1005 | vcaballero | /**
|
114 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
|
||
115 | */
|
||
116 | public void initialize() throws IOException { |
||
117 | 695 | fjp | float heightText = 10; |
118 | 5521 | caballero | |
119 | 1233 | fjp | attr.setLoadedInMemory(true);
|
120 | 695 | fjp | |
121 | 1005 | vcaballero | m_DgnReader = new DGNReader(m_Fich.getAbsolutePath());
|
122 | |||
123 | Value[] auxRow = new Value[7]; |
||
124 | Value[] cellRow = new Value[7]; |
||
125 | Value[] complexRow = new Value[7]; |
||
126 | 695 | fjp | ArrayList arrayFields = new ArrayList(); |
127 | arrayFields.add("ID");
|
||
128 | arrayFields.add("Entity");
|
||
129 | arrayFields.add("Layer");
|
||
130 | arrayFields.add("Color");
|
||
131 | arrayFields.add("HeightText");
|
||
132 | arrayFields.add("RotationText");
|
||
133 | arrayFields.add("Text");
|
||
134 | 1005 | vcaballero | |
135 | getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
||
136 | |||
137 | 695 | fjp | // Ahora las rellenamos.
|
138 | FShape aux; |
||
139 | 1005 | vcaballero | boolean bElementoCompuesto = false; |
140 | boolean bEsPoligono = false; |
||
141 | 695 | fjp | boolean bInsideCell = false; |
142 | boolean bFirstHoleEntity = false; |
||
143 | boolean bConnect = false; // Se usa para que los pol?gonos cierren bien cuando son formas compuestas |
||
144 | 1005 | vcaballero | int contadorSubElementos = 0; |
145 | int numSubElementos = 0; |
||
146 | int complex_index_fill_color = -1; |
||
147 | 695 | fjp | int nClass; // Para filtrar los elementos de construcci?n, etc. |
148 | GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
||
149 | 1005 | vcaballero | |
150 | for (int id = 0; id < m_DgnReader.getNumEntities(); id++) { |
||
151 | 695 | fjp | // System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
|
152 | m_DgnReader.DGNGotoElement(id); |
||
153 | 801 | fjp | |
154 | 1005 | vcaballero | DGNElemCore elemento = m_DgnReader.DGNReadElement(); |
155 | nClass = 0;
|
||
156 | auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
|
||
157 | auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
|
||
158 | auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
||
159 | |||
160 | if (elemento.properties != 0) { |
||
161 | nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS; |
||
162 | } |
||
163 | |||
164 | if ((elemento != null) && (elemento.deleted == 0) && (nClass == 0)) //Leer un elemento |
||
165 | { |
||
166 | aux = null;
|
||
167 | |||
168 | // if ((elemento.element_id > 3800) && (elemento.element_id < 3850))
|
||
169 | 5521 | caballero | // m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,"");
|
170 | 1005 | vcaballero | if ((elemento.stype == DGNFileHeader.DGNST_MULTIPOINT) ||
|
171 | (elemento.stype == DGNFileHeader.DGNST_ARC) || |
||
172 | (elemento.stype == DGNFileHeader.DGNST_CELL_HEADER) || |
||
173 | (elemento.stype == DGNFileHeader.DGNST_SHARED_CELL_DEFN) || |
||
174 | (elemento.stype == DGNFileHeader.DGNST_COMPLEX_HEADER)) { |
||
175 | if (elemento.complex != 0) { |
||
176 | bElementoCompuesto = true;
|
||
177 | } else {
|
||
178 | if (bElementoCompuesto) {
|
||
179 | if (bInsideCell) {
|
||
180 | auxRow[ID_FIELD_ENTITY] = cellRow[ID_FIELD_ENTITY]; |
||
181 | } else {
|
||
182 | auxRow = complexRow; |
||
183 | } |
||
184 | |||
185 | // System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
||
186 | addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
||
187 | |||
188 | if (bEsPoligono) {
|
||
189 | if (complex_index_fill_color != -1) { |
||
190 | 711 | fjp | auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color); |
191 | 1005 | vcaballero | } |
192 | 695 | fjp | |
193 | 1005 | vcaballero | addShape(new FPolygon2D(elementoCompuesto),
|
194 | auxRow); |
||
195 | } |
||
196 | |||
197 | elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
||
198 | } |
||
199 | |||
200 | // System.err.println("Entidad simple");
|
||
201 | bElementoCompuesto = false;
|
||
202 | bEsPoligono = false;
|
||
203 | bConnect = false;
|
||
204 | |||
205 | // elementoCompuesto = new GeneralPathX();
|
||
206 | bInsideCell = false;
|
||
207 | } |
||
208 | } |
||
209 | |||
210 | switch (elemento.stype) {
|
||
211 | 695 | fjp | case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
|
212 | bInsideCell = true;
|
||
213 | 711 | fjp | cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
214 | 1005 | vcaballero | cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
215 | cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
||
216 | cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
||
217 | "Shared Cell");
|
||
218 | |||
219 | 695 | fjp | break;
|
220 | 1005 | vcaballero | |
221 | 695 | fjp | case DGNFileHeader.DGNST_CELL_HEADER:
|
222 | bInsideCell = true;
|
||
223 | 1005 | vcaballero | |
224 | 695 | fjp | DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento; |
225 | 711 | fjp | cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
226 | 1005 | vcaballero | cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
227 | cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
||
228 | cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
||
229 | "Cell");
|
||
230 | complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
||
231 | |||
232 | // System.err.println("Cell Header " + complex_index_fill_color);
|
||
233 | 695 | fjp | break;
|
234 | 1005 | vcaballero | |
235 | 695 | fjp | case DGNFileHeader.DGNST_COMPLEX_HEADER:
|
236 | 1005 | vcaballero | |
237 | 695 | fjp | // bElementoCompuesto = true;
|
238 | // System.err.println("Complex Header");
|
||
239 | contadorSubElementos = 0;
|
||
240 | 1005 | vcaballero | |
241 | 695 | fjp | DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento; |
242 | numSubElementos = psComplexHeader.numelems; |
||
243 | 711 | fjp | complexRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
244 | 1005 | vcaballero | complexRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
245 | complexRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
||
246 | complexRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
||
247 | "Complex");
|
||
248 | |||
249 | if (psComplexHeader.type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER) {
|
||
250 | 695 | fjp | bEsPoligono = true;
|
251 | 1005 | vcaballero | |
252 | 695 | fjp | // Si es un agujero, no conectamos con el anterior
|
253 | 1005 | vcaballero | if ((psComplexHeader.properties & 0x8000) != 0) { |
254 | 695 | fjp | bFirstHoleEntity = true;
|
255 | 1005 | vcaballero | } else {
|
256 | 695 | fjp | // Miramos si tiene color de relleno
|
257 | // complex_index_fill_color = -1;
|
||
258 | // if (elemento.attr_bytes > 0) {
|
||
259 | 1005 | vcaballero | complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
260 | |||
261 | // System.err.println("complex shape fill color = " + elemento.color);
|
||
262 | 695 | fjp | // }
|
263 | } |
||
264 | 1005 | vcaballero | |
265 | 695 | fjp | bConnect = true;
|
266 | 1005 | vcaballero | } else {
|
267 | 695 | fjp | bEsPoligono = false;
|
268 | bConnect = false;
|
||
269 | } |
||
270 | 1005 | vcaballero | |
271 | 695 | fjp | break;
|
272 | 1005 | vcaballero | |
273 | 695 | fjp | case DGNFileHeader.DGNST_MULTIPOINT:
|
274 | 1005 | vcaballero | |
275 | 695 | fjp | // OJO: Si lo que viene en este multipoint es un elemento con type=11 (curve), se trata de una "parametric
|
276 | // spline curve". La vamos a tratar como si no fuera curva, pero seg?n la documentaci?n, los 2 primeros puntos
|
||
277 | // y los 2 ?ltimos puntos definen "endpoint derivatives" y NO se muestran.
|
||
278 | // TODAV?A HAY UN PEQUE?O FALLO CON EL FICHERO dgn-sample.dgn, pero lo dejo por ahora.
|
||
279 | // Es posible que tenga que ver con lo de los arcos (arco distorsionado), que
|
||
280 | // todav?a no est? metido.
|
||
281 | 1005 | vcaballero | DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento; |
282 | 12077 | jmvivo | auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
283 | auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
||
284 | "Multipoint");
|
||
285 | 12078 | jmvivo | auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
286 | 1005 | vcaballero | auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
287 | |||
288 | if ((psLine.num_vertices == 2) && |
||
289 | (psLine.vertices[0].x == psLine.vertices[1].x) && |
||
290 | (psLine.vertices[0].y == psLine.vertices[1].y)) { |
||
291 | auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
||
292 | "Point");
|
||
293 | addShape(new FPoint3D(psLine.vertices[0].x, |
||
294 | psLine.vertices[0].y, psLine.vertices[0].z), |
||
295 | auxRow); |
||
296 | } else {
|
||
297 | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
||
298 | |||
299 | if (psLine.type == DGNFileHeader.DGNT_CURVE) {
|
||
300 | psLine.num_vertices = psLine.num_vertices - 4;
|
||
301 | |||
302 | for (int aux_n = 0; |
||
303 | aux_n < psLine.num_vertices; aux_n++) { |
||
304 | psLine.vertices[aux_n] = psLine.vertices[aux_n + |
||
305 | 2];
|
||
306 | } |
||
307 | } |
||
308 | |||
309 | if ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
|
||
310 | ((psLine.properties & 0x8000) != 0)) { |
||
311 | // Invertimos el orden porque es un agujero
|
||
312 | elShape.moveTo(psLine.vertices[psLine.num_vertices - |
||
313 | 1].x,
|
||
314 | psLine.vertices[psLine.num_vertices - 1].y);
|
||
315 | |||
316 | for (int i = psLine.num_vertices - 2; i >= 0; |
||
317 | i--) |
||
318 | elShape.lineTo(psLine.vertices[i].x, |
||
319 | psLine.vertices[i].y); |
||
320 | } else {
|
||
321 | elShape.moveTo(psLine.vertices[0].x,
|
||
322 | psLine.vertices[0].y);
|
||
323 | |||
324 | for (int i = 1; i < psLine.num_vertices; i++) |
||
325 | elShape.lineTo(psLine.vertices[i].x, |
||
326 | psLine.vertices[i].y); |
||
327 | } |
||
328 | |||
329 | if ((psLine.vertices[0].x == psLine.vertices[psLine.num_vertices - |
||
330 | 1].x) &&
|
||
331 | (psLine.vertices[0].y == psLine.vertices[psLine.num_vertices -
|
||
332 | 1].y)) {
|
||
333 | // Lo a?adimos tambi?n como pol?gono
|
||
334 | bEsPoligono = true;
|
||
335 | |||
336 | 695 | fjp | // Miramos si tiene color de relleno
|
337 | if (elemento.attr_bytes > 0) { |
||
338 | elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
||
339 | 1005 | vcaballero | |
340 | 695 | fjp | // System.err.println("fill color = " + elemento.color);
|
341 | 1005 | vcaballero | if (elemento.color != -1) { |
342 | 711 | fjp | auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
343 | 1005 | vcaballero | } |
344 | 695 | fjp | } |
345 | |||
346 | 1005 | vcaballero | if (elemento.complex == 0) { |
347 | addShape(new FPolygon2D(elShape), auxRow);
|
||
348 | } |
||
349 | } |
||
350 | 695 | fjp | |
351 | 1005 | vcaballero | if (elemento.complex != 0) { |
352 | 5521 | caballero | // Si es un agujero o
|
353 | 1005 | vcaballero | // es la primera entidad del agujero, lo a?adimos sin unir al anterior
|
354 | if (bFirstHoleEntity ||
|
||
355 | ((psLine.type == DGNFileHeader.DGNT_SHAPE) && |
||
356 | ((psLine.properties & 0x8000) != 0))) { |
||
357 | elementoCompuesto.append(elShape, false);
|
||
358 | bFirstHoleEntity = false;
|
||
359 | } else {
|
||
360 | elementoCompuesto.append(elShape, bConnect); |
||
361 | } |
||
362 | } else {
|
||
363 | addShape(new FPolyline2D(elShape), auxRow);
|
||
364 | } |
||
365 | } |
||
366 | 695 | fjp | |
367 | 1005 | vcaballero | break;
|
368 | 695 | fjp | |
369 | 1005 | vcaballero | case DGNFileHeader.DGNST_ARC:
|
370 | |||
371 | // m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
|
||
372 | DGNElemArc psArc = (DGNElemArc) elemento; |
||
373 | |||
374 | // La definici?n de arco de MicroStation es distinta a la de Java.
|
||
375 | // En el dgn el origin se entiende que es el centro del arco,
|
||
376 | // y a la hora de crear un Arc2D las 2 primeras coordenadas son
|
||
377 | // la esquina inferior izquierda del rect?ngulo que rodea al arco.
|
||
378 | // 1.- Creamos la elipse sin rotaci?n.
|
||
379 | // 2.- Creamos el arco
|
||
380 | // 3.- Rotamos el resultado
|
||
381 | |||
382 | /* System.out.println("Arco con primari axis: " + psArc.primary_axis +
|
||
383 | " start angle: " + psArc.startang + " sweepang = " + psArc.sweepang);
|
||
384 | System.out.println("secondaria axis: " + psArc.secondary_axis +
|
||
385 | " rotation = " + psArc.rotation); */
|
||
386 | AffineTransform mT = AffineTransform.getRotateInstance(Math.toRadians( |
||
387 | psArc.rotation), psArc.origin.x, |
||
388 | psArc.origin.y); |
||
389 | |||
390 | // mT.preConcatenate(AffineTransform.getScaleInstance(100.0,100.0));
|
||
391 | Arc2D.Double elArco = new Arc2D.Double(psArc.origin.x - |
||
392 | psArc.primary_axis, |
||
393 | psArc.origin.y - psArc.secondary_axis, |
||
394 | 2.0 * psArc.primary_axis,
|
||
395 | 2.0 * psArc.secondary_axis, -psArc.startang,
|
||
396 | -psArc.sweepang, Arc2D.OPEN);
|
||
397 | |||
398 | // Ellipse2D.Double elArco = new Ellipse2D.Double(psArc.origin.x - psArc.primary_axis,
|
||
399 | // psArc.origin.y - psArc.secondary_axis,2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis);
|
||
400 | GeneralPathX elShapeArc = new GeneralPathX(elArco);
|
||
401 | |||
402 | // Transformamos el GeneralPahtX porque si transformamos elArco nos lo convierte
|
||
403 | // a GeneralPath y nos guarda las coordenadas en float, con la correspondiente p?rdida de precisi?n
|
||
404 | elShapeArc.transform(mT); |
||
405 | |||
406 | if (m_DgnReader.getInfo().dimension == 3) { |
||
407 | //Aqu? podr?amos hacer cosas con la coordenada Z
|
||
408 | } |
||
409 | |||
410 | auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
||
411 | auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
||
412 | "Arc");
|
||
413 | auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
||
414 | auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
||
415 | |||
416 | /* Line2D.Double ejeMayor = new Line2D.Double(psArc.origin.x - psArc.primary_axis, psArc.origin.y,
|
||
417 | psArc.origin.x + psArc.primary_axis, psArc.origin.y);
|
||
418 | 5521 | caballero | |
419 | 1005 | vcaballero | lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, new GeneralPathX(ejeMayor)), auxRow); */
|
420 | |||
421 | // lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, elShapeArc), auxRow);
|
||
422 | if (elemento.complex != 0) { |
||
423 | // Esto es una posible fuente de fallos si detr?s de una
|
||
424 | // elipse vienen m?s cosas pegadas. Deber?amos volver
|
||
425 | // a conectar una vez pasada la elipse.
|
||
426 | if (elemento.type == DGNFileHeader.DGNT_ELLIPSE) {
|
||
427 | bConnect = false;
|
||
428 | } |
||
429 | |||
430 | // SI LA ELIPSE ES UN AGUJERO, SE A?ADE SIN PEGAR
|
||
431 | 5521 | caballero | // Y EL ELEMENTO ES UN POLIGONO
|
432 | 1005 | vcaballero | if (bFirstHoleEntity ||
|
433 | ((elemento.type == DGNFileHeader.DGNT_SHAPE) && |
||
434 | ((elemento.properties & 0x8000) != 0))) { |
||
435 | elementoCompuesto.append(elShapeArc, false);
|
||
436 | bFirstHoleEntity = false;
|
||
437 | } else {
|
||
438 | elementoCompuesto.append(elShapeArc, bConnect); |
||
439 | } |
||
440 | } else {
|
||
441 | addShape(new FPolyline2D(elShapeArc), auxRow);
|
||
442 | |||
443 | if (psArc.type == DGNFileHeader.DGNT_ELLIPSE) {
|
||
444 | addShape(new FPolygon2D(elShapeArc), auxRow);
|
||
445 | } |
||
446 | } |
||
447 | |||
448 | // System.err.println("Entra un Arco");
|
||
449 | break;
|
||
450 | |||
451 | case DGNFileHeader.DGNST_TEXT:
|
||
452 | |||
453 | DGNElemText psText = (DGNElemText) elemento; |
||
454 | FPoint2D elShapeTxt = new FPoint3D(psText.origin.x,
|
||
455 | psText.origin.y, psText.origin.z); |
||
456 | |||
457 | auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
||
458 | auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
||
459 | "Text");
|
||
460 | auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
||
461 | auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
||
462 | heightText = (float) psText.height_mult;
|
||
463 | auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText); |
||
464 | auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(psText.rotation); |
||
465 | auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(psText.string); // .trim();
|
||
466 | addShape(elShapeTxt, auxRow); |
||
467 | |||
468 | // System.out.println("Rotaci?n texto: " + psText.rotation + "Altura Texto = " + heightText);
|
||
469 | |||
470 | /* System.out.println(" origin=(" + psText.origin.x +
|
||
471 | ", " + psText.origin.y + ") rotation=" +
|
||
472 | psText.rotation + "\n" + " font=" +
|
||
473 | psText.font_id + " just=" +
|
||
474 | psText.justification + "length_mult=" +
|
||
475 | psText.length_mult + " height_mult=" +
|
||
476 | psText.height_mult + "\n" + " string =" +
|
||
477 | new String(psText.string).toString().trim() +
|
||
478 | "\n"); */
|
||
479 | break;
|
||
480 | |||
481 | /* default:
|
||
482 | m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento, "");
|
||
483 | */
|
||
484 | } // switch
|
||
485 | } // if
|
||
486 | 695 | fjp | } // for
|
487 | |||
488 | 1005 | vcaballero | if (bElementoCompuesto) {
|
489 | if (bInsideCell) {
|
||
490 | 695 | fjp | auxRow = cellRow; |
491 | 1005 | vcaballero | } else {
|
492 | 695 | fjp | auxRow = complexRow; |
493 | } |
||
494 | 1005 | vcaballero | |
495 | 5521 | caballero | // System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
496 | 695 | fjp | addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
497 | 1005 | vcaballero | |
498 | if (bEsPoligono) {
|
||
499 | if (complex_index_fill_color != -1) { |
||
500 | 711 | fjp | auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color); |
501 | 1005 | vcaballero | } |
502 | 695 | fjp | |
503 | addShape(new FPolygon2D(elementoCompuesto), auxRow);
|
||
504 | } |
||
505 | } |
||
506 | 1005 | vcaballero | |
507 | 714 | fjp | defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
508 | defaultLegend.setFieldName("Color");
|
||
509 | 801 | fjp | defaultLegend.setLabelField("Text");
|
510 | 10720 | caballero | FSymbol myDefaultSymbol = new FSymbol(getShapeType());
|
511 | myDefaultSymbol.setShapeVisible(true);
|
||
512 | 8765 | jjdelcerro | myDefaultSymbol.setFontSizeInPixels(false);
|
513 | myDefaultSymbol.setFont(new Font("SansSerif",Font.PLAIN, 9)); |
||
514 | myDefaultSymbol.setFontColor(Color.BLACK);
|
||
515 | myDefaultSymbol.setFontSize(heightText); |
||
516 | myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
||
517 | myDefaultSymbol.setSize(3);
|
||
518 | myDefaultSymbol.setSizeInPixels(true);
|
||
519 | 10720 | caballero | |
520 | 8765 | jjdelcerro | defaultLegend.setDefaultSymbol(myDefaultSymbol); |
521 | 1005 | vcaballero | |
522 | 801 | fjp | defaultLegend.setLabelHeightField("HeightText");
|
523 | defaultLegend.setLabelRotationField("RotationText");
|
||
524 | 1005 | vcaballero | |
525 | 1828 | fernando | ObjectDriver rs = this;
|
526 | 714 | fjp | IntValue clave; |
527 | 695 | fjp | FSymbol theSymbol = null;
|
528 | 1005 | vcaballero | |
529 | 714 | fjp | try {
|
530 | 1255 | fjp | // TODO: Provisional hasta que cambiemos los s?mbolos.
|
531 | 1402 | fjp | /* BufferedImage bi= new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
|
532 | 1255 | fjp | Graphics2D big = bi.createGraphics();
|
533 | Color color=new Color(0,0,0,0);
|
||
534 | big.setBackground(color);
|
||
535 | 1402 | fjp | big.clearRect(0, 0, 1, 1);
|
536 | 5521 | caballero | Paint fillProv = null;
|
537 | 1255 | fjp | Rectangle2D rProv = new Rectangle();
|
538 | 5521 | caballero | rProv.setFrame(0, 0,1,1);
|
539 | fillProv = new TexturePaint(bi,rProv); */
|
||
540 | 1005 | vcaballero | for (long j = 0; j < rs.getRowCount(); j++) { |
541 | clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR); |
||
542 | |||
543 | if (defaultLegend.getSymbolByValue(clave) == null) { |
||
544 | theSymbol = new FSymbol(getShapeType());
|
||
545 | 714 | fjp | theSymbol.setDescription(clave.toString()); |
546 | 1172 | fjp | Color c = m_DgnReader.DGNLookupColor(
|
547 | clave.getValue()); |
||
548 | // Le ponemos transparencia para que los pol?gonos no
|
||
549 | // tapen del todo. (Est? dentro del DGNLookupColor
|
||
550 | // c.
|
||
551 | theSymbol.setColor(c); |
||
552 | 1402 | fjp | // theSymbol.setFill(fillProv);
|
553 | theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
||
554 | theSymbol.setSize(3);
|
||
555 | theSymbol.setSizeInPixels(true);
|
||
556 | 5521 | caballero | |
557 | 1255 | fjp | // theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
|
558 | 714 | fjp | defaultLegend.addSymbol(clave, theSymbol); |
559 | } |
||
560 | } // for
|
||
561 | } catch (DriverException e) {
|
||
562 | e.printStackTrace(); |
||
563 | 1005 | vcaballero | throw new IOException( |
564 | 1175 | fjp | "Error al poner la leyenda por defecto en el DGN");
|
565 | 714 | fjp | } |
566 | 1005 | vcaballero | } |
567 | |||
568 | /**
|
||
569 | * Devuelve el tipo de shape que contiene el formato DGN.
|
||
570 | *
|
||
571 | * @return Entero que representa el tipo de shape.
|
||
572 | */
|
||
573 | public int getShapeType() { |
||
574 | 801 | fjp | return FShape.MULTI;
|
575 | 714 | fjp | } |
576 | 1005 | vcaballero | |
577 | /**
|
||
578 | 695 | fjp | * @see com.hardcode.driverManager.Driver#getType()
|
579 | */
|
||
580 | public String getName() { |
||
581 | return "gvSIG DGN Memory Driver"; |
||
582 | } |
||
583 | |||
584 | /**
|
||
585 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
|
||
586 | */
|
||
587 | public boolean accept(File f) { |
||
588 | return f.getName().toUpperCase().endsWith("DGN"); |
||
589 | } |
||
590 | |||
591 | 714 | fjp | /* (non-Javadoc)
|
592 | * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
||
593 | */
|
||
594 | public Legend getDefaultLegend() {
|
||
595 | return defaultLegend;
|
||
596 | } |
||
597 | 1233 | fjp | |
598 | /* (non-Javadoc)
|
||
599 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
||
600 | */
|
||
601 | public DriverAttributes getDriverAttributes() {
|
||
602 | return attr;
|
||
603 | } |
||
604 | 2183 | fernando | |
605 | /**
|
||
606 | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
||
607 | */
|
||
608 | public int[] getPrimaryKeys() throws DriverException { |
||
609 | return null; |
||
610 | } |
||
611 | 2217 | fernando | |
612 | /**
|
||
613 | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
||
614 | */
|
||
615 | public void write(DataWare arg0) throws DriverException { |
||
616 | // TODO Auto-generated method stub
|
||
617 | 5521 | caballero | |
618 | 2217 | fernando | } |
619 | 2880 | fernando | |
620 | 3271 | fjp | /* (non-Javadoc)
|
621 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
||
622 | */
|
||
623 | public void close() throws IOException { |
||
624 | // TODO Auto-generated method stub
|
||
625 | 5521 | caballero | |
626 | 3271 | fjp | } |
627 | |||
628 | 3720 | fjp | public File getFile() { |
629 | return m_Fich;
|
||
630 | } |
||
631 | |||
632 | 5521 | caballero | public boolean isWritable() { |
633 | return m_Fich.canWrite();
|
||
634 | } |
||
635 | 12290 | caballero | public int getFieldType(int i) throws DriverException { |
636 | DefaultTableModel dtm=getTableModel();
|
||
637 | String columnName=dtm.getColumnName(i);
|
||
638 | if (columnName.equals("ID")){ |
||
639 | return Types.INTEGER; |
||
640 | }else if (columnName.equals("Entity")){ |
||
641 | return Types.VARCHAR; |
||
642 | }else if (columnName.equals("Layer")){ |
||
643 | return Types.INTEGER; |
||
644 | }else if (columnName.equals("Color")){ |
||
645 | return Types.INTEGER; |
||
646 | }else if (columnName.equals("HeightText")){ |
||
647 | return Types.FLOAT; |
||
648 | }else if (columnName.equals("RotationText")){ |
||
649 | return Types.DOUBLE; |
||
650 | }else if (columnName.equals("Text")){ |
||
651 | return Types.VARCHAR; |
||
652 | }else{
|
||
653 | return Types.VARCHAR; |
||
654 | } |
||
655 | } |
||
656 | 695 | fjp | } |