Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1011 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dgn / DgnMemoryDriver.java @ 12904

History | View | Annotate | Download (22.5 KB)

1
/* 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
 *
7
 * (Thanks, Frank :). For this, and for your very good job with
8
 * shapefiles. And also for GDAL!!!!
9
 */
10

    
11
/* 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
package com.iver.cit.gvsig.fmap.drivers.dgn;
52

    
53
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.sql.Types;
60
import java.util.ArrayList;
61

    
62
import javax.swing.table.DefaultTableModel;
63

    
64
import com.hardcode.gdbms.engine.data.driver.DriverException;
65
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
66
import com.hardcode.gdbms.engine.data.edition.DataWare;
67
import com.hardcode.gdbms.engine.values.IntValue;
68
import com.hardcode.gdbms.engine.values.Value;
69
import com.hardcode.gdbms.engine.values.ValueFactory;
70
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
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
77
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
78
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
79
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver;
80
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
81
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
82
import com.iver.cit.gvsig.fmap.rendering.Legend;
83
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
84
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
85

    
86

    
87
/**
88
 * Driver DGN que trabaja directamente cargando el fichero en memoria.
89
 *
90
 * @author Vicente Caballero Navarro
91
 */
92
public class DgnMemoryDriver extends MemoryDriver implements VectorialFileDriver, WithDefaultLegend {
93
        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
        DGNReader m_DgnReader;
101
        VectorialUniqueValueLegend defaultLegend;
102
        private String path;
103
        private File m_Fich;
104
        private DriverAttributes attr = new DriverAttributes();
105

    
106
        /**
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

    
113
        /**
114
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
115
         */
116
        public void initialize() throws IOException {
117
                float heightText = 10;
118

    
119
                attr.setLoadedInMemory(true);
120

    
121
                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
                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

    
135
                getTableModel().setColumnIdentifiers(arrayFields.toArray());
136

    
137
                // Ahora las rellenamos.
138
                FShape aux;
139
                boolean bElementoCompuesto = false;
140
                boolean bEsPoligono = false;
141
                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
                int contadorSubElementos = 0;
145
                int numSubElementos = 0;
146
                int complex_index_fill_color = -1;
147
                int nClass; // Para filtrar los elementos de construcci?n, etc.
148
                GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
149

    
150
                for (int id = 0; id < m_DgnReader.getNumEntities(); id++) {
151
                        // System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
152
                        m_DgnReader.DGNGotoElement(id);
153

    
154
                        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
                                //         m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,"");
170
                                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
                                                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
191
                                                                }
192

    
193
                                                                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
                                        case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
212
                                                bInsideCell = true;
213
                                                cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
214
                                                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
                                                break;
220

    
221
                                        case DGNFileHeader.DGNST_CELL_HEADER:
222
                                                bInsideCell = true;
223

    
224
                                                DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento;
225
                                                cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
226
                                                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
                                                break;
234

    
235
                                        case DGNFileHeader.DGNST_COMPLEX_HEADER:
236

    
237
                                                // bElementoCompuesto = true;
238
                                                // System.err.println("Complex Header");
239
                                                contadorSubElementos = 0;
240

    
241
                                                DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento;
242
                                                numSubElementos = psComplexHeader.numelems;
243
                                                complexRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
244
                                                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
                                                        bEsPoligono = true;
251

    
252
                                                        // Si es un agujero, no conectamos con el anterior
253
                                                        if ((psComplexHeader.properties & 0x8000) != 0) {
254
                                                                bFirstHoleEntity = true;
255
                                                        } else {
256
                                                                // Miramos si tiene color de relleno
257
                                                                // complex_index_fill_color = -1;
258
                                                                // if (elemento.attr_bytes > 0) {
259
                                                                complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento);
260

    
261
                                                                // System.err.println("complex shape fill color = " + elemento.color);
262
                                                                // }
263
                                                        }
264

    
265
                                                        bConnect = true;
266
                                                } else {
267
                                                        bEsPoligono = false;
268
                                                        bConnect = false;
269
                                                }
270

    
271
                                                break;
272

    
273
                                        case DGNFileHeader.DGNST_MULTIPOINT:
274

    
275
                                                // 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
                                                DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento;
282
                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
283
                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
284
                                                                "Multipoint");
285
                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
286
                                                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
                                                                // Miramos si tiene color de relleno
337
                                                                if (elemento.attr_bytes > 0) {
338
                                                                        elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento);
339

    
340
                                                                        // System.err.println("fill color = " + elemento.color);
341
                                                                        if (elemento.color != -1) {
342
                                                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
343
                                                                        }
344
                                                                }
345

    
346
                                                                if (elemento.complex == 0) {
347
                                                                        addShape(new FPolygon2D(elShape), auxRow);
348
                                                                }
349
                                                        }
350

    
351
                                                        if (elemento.complex != 0) {
352
                                                                // Si es un agujero o
353
                                                                // 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

    
367
                                                break;
368

    
369
                                        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

419
                                                   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
                                                        // Y EL ELEMENTO ES UN POLIGONO
432
                                                        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
                } // for
487

    
488
                if (bElementoCompuesto) {
489
                        if (bInsideCell) {
490
                                auxRow = cellRow;
491
                        } else {
492
                                auxRow = complexRow;
493
                        }
494

    
495
                        // System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
496
                        addShape(new FPolyline2D(elementoCompuesto), auxRow);
497

    
498
                        if (bEsPoligono) {
499
                                if (complex_index_fill_color != -1) {
500
                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
501
                                }
502

    
503
                                addShape(new FPolygon2D(elementoCompuesto), auxRow);
504
                        }
505
                }
506

    
507
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
508
                defaultLegend.setFieldName("Color");
509
                defaultLegend.setLabelField("Text");
510
                FSymbol myDefaultSymbol = new FSymbol(getShapeType());
511
                myDefaultSymbol.setShapeVisible(true);
512
                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

    
520
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
521

    
522
                defaultLegend.setLabelHeightField("HeightText");
523
                defaultLegend.setLabelRotationField("RotationText");
524

    
525
                ObjectDriver rs = this;
526
                IntValue clave;
527
                FSymbol theSymbol = null;
528

    
529
                try {
530
                    // TODO: Provisional hasta que cambiemos los s?mbolos.
531
                    /* BufferedImage bi= new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
532
                   Graphics2D big = bi.createGraphics();
533
                   Color color=new Color(0,0,0,0);
534
                   big.setBackground(color);
535
                   big.clearRect(0, 0, 1, 1);
536
                   Paint fillProv = null;
537
                   Rectangle2D rProv = new Rectangle();
538
                   rProv.setFrame(0, 0,1,1);
539
                   fillProv = new TexturePaint(bi,rProv); */
540
                        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
                                        theSymbol.setDescription(clave.toString());
546
                                        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
                                        // theSymbol.setFill(fillProv);
553
                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
554
                                        theSymbol.setSize(3);
555
                                        theSymbol.setSizeInPixels(true);
556

    
557
                                        // theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
558
                                        defaultLegend.addSymbol(clave, theSymbol);
559
                                }
560
                        } // for
561
                } catch (DriverException e) {
562
                        e.printStackTrace();
563
                        throw new IOException(
564
                                "Error al poner la leyenda por defecto en el DGN");
565
                }
566
        }
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
                return FShape.MULTI;
575
        }
576

    
577
        /**
578
         * @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
        /* (non-Javadoc)
592
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
593
         */
594
        public Legend getDefaultLegend() {
595
                return defaultLegend;
596
        }
597

    
598
    /* (non-Javadoc)
599
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
600
     */
601
    public DriverAttributes getDriverAttributes() {
602
        return attr;
603
    }
604

    
605
    /**
606
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
607
     */
608
    public int[] getPrimaryKeys() throws DriverException {
609
        return null;
610
    }
611

    
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

    
618
    }
619

    
620
    /* (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

    
626
    }
627

    
628
        public File getFile() {
629
                return m_Fich;
630
        }
631

    
632
        public boolean isWritable() {
633
                return m_Fich.canWrite();
634
        }
635
        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
}