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