Statistics
| Revision:

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

History | View | Annotate | Download (21.8 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.util.ArrayList;
60

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

    
83

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

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

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

    
116
                attr.setLoadedInMemory(true);
117

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

    
132
                getTableModel().setColumnIdentifiers(arrayFields.toArray());
133

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

    
147
                for (int id = 0; id < m_DgnReader.getNumEntities(); id++) {
148
                        // System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
149
                        m_DgnReader.DGNGotoElement(id);
150

    
151
                        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
                                //         m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,"");
167
                                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
                                                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
188
                                                                }
189

    
190
                                                                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
                                        case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
209
                                                bInsideCell = true;
210
                                                cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
211
                                                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
                                                break;
217

    
218
                                        case DGNFileHeader.DGNST_CELL_HEADER:
219
                                                bInsideCell = true;
220

    
221
                                                DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento;
222
                                                cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
223
                                                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
                                                break;
231

    
232
                                        case DGNFileHeader.DGNST_COMPLEX_HEADER:
233

    
234
                                                // bElementoCompuesto = true;
235
                                                // System.err.println("Complex Header");
236
                                                contadorSubElementos = 0;
237

    
238
                                                DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento;
239
                                                numSubElementos = psComplexHeader.numelems;
240
                                                complexRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
241
                                                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
                                                        bEsPoligono = true;
248

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

    
258
                                                                // System.err.println("complex shape fill color = " + elemento.color);
259
                                                                // }
260
                                                        }
261

    
262
                                                        bConnect = true;
263
                                                } else {
264
                                                        bEsPoligono = false;
265
                                                        bConnect = false;
266
                                                }
267

    
268
                                                break;
269

    
270
                                        case DGNFileHeader.DGNST_MULTIPOINT:
271

    
272
                                                // 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
                                                DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento;
279
                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
280
                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
281
                                                                "Multipoint");
282
                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
283
                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
284

    
285
                                                if ((psLine.num_vertices == 2) &&
286
                                                                (psLine.vertices[0].x == psLine.vertices[1].x) &&
287
                                                                (psLine.vertices[0].y == psLine.vertices[1].y)) {
288
                                                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
289
                                                                        "Point");
290
                                                        addShape(new FPoint3D(psLine.vertices[0].x,
291
                                                                        psLine.vertices[0].y, psLine.vertices[0].z),
292
                                                                auxRow);
293
                                                } else {
294
                                                        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
295

    
296
                                                        if (psLine.type == DGNFileHeader.DGNT_CURVE) {
297
                                                                psLine.num_vertices = psLine.num_vertices - 4;
298

    
299
                                                                for (int aux_n = 0;
300
                                                                                aux_n < psLine.num_vertices; aux_n++) {
301
                                                                        psLine.vertices[aux_n] = psLine.vertices[aux_n +
302
                                                                                2];
303
                                                                }
304
                                                        }
305

    
306
                                                        if ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
307
                                                                        ((psLine.properties & 0x8000) != 0)) {
308
                                                                // Invertimos el orden porque es un agujero
309
                                                                elShape.moveTo(psLine.vertices[psLine.num_vertices -
310
                                                                        1].x,
311
                                                                        psLine.vertices[psLine.num_vertices - 1].y);
312

    
313
                                                                for (int i = psLine.num_vertices - 2; i >= 0;
314
                                                                                i--)
315
                                                                        elShape.lineTo(psLine.vertices[i].x,
316
                                                                                psLine.vertices[i].y);
317
                                                        } else {
318
                                                                elShape.moveTo(psLine.vertices[0].x,
319
                                                                        psLine.vertices[0].y);
320

    
321
                                                                for (int i = 1; i < psLine.num_vertices; i++)
322
                                                                        elShape.lineTo(psLine.vertices[i].x,
323
                                                                                psLine.vertices[i].y);
324
                                                        }
325

    
326
                                                        if ((psLine.vertices[0].x == psLine.vertices[psLine.num_vertices -
327
                                                                        1].x) &&
328
                                                                        (psLine.vertices[0].y == psLine.vertices[psLine.num_vertices -
329
                                                                        1].y)) {
330
                                                                // Lo a?adimos tambi?n como pol?gono
331
                                                                bEsPoligono = true;
332

    
333
                                                                // Miramos si tiene color de relleno
334
                                                                if (elemento.attr_bytes > 0) {
335
                                                                        elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento);
336

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

    
343
                                                                if (elemento.complex == 0) {
344
                                                                        addShape(new FPolygon2D(elShape), auxRow);
345
                                                                }
346
                                                        }
347

    
348
                                                        if (elemento.complex != 0) {
349
                                                                // Si es un agujero o
350
                                                                // es la primera entidad del agujero, lo a?adimos sin unir al anterior
351
                                                                if (bFirstHoleEntity ||
352
                                                                                ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
353
                                                                                ((psLine.properties & 0x8000) != 0))) {
354
                                                                        elementoCompuesto.append(elShape, false);
355
                                                                        bFirstHoleEntity = false;
356
                                                                } else {
357
                                                                        elementoCompuesto.append(elShape, bConnect);
358
                                                                }
359
                                                        } else {
360
                                                                addShape(new FPolyline2D(elShape), auxRow);
361
                                                        }
362
                                                }
363

    
364
                                                break;
365

    
366
                                        case DGNFileHeader.DGNST_ARC:
367

    
368
                                                // m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
369
                                                DGNElemArc psArc = (DGNElemArc) elemento;
370

    
371
                                                // La definici?n de arco de MicroStation es distinta a la de Java.
372
                                                // En el dgn el origin se entiende que es el centro del arco,
373
                                                // y a la hora de crear un Arc2D las 2 primeras coordenadas son
374
                                                // la esquina inferior izquierda del rect?ngulo que rodea al arco.
375
                                                // 1.- Creamos la elipse sin rotaci?n.
376
                                                // 2.- Creamos el arco
377
                                                // 3.- Rotamos el resultado
378

    
379
                                                /* System.out.println("Arco con primari axis: " + psArc.primary_axis +
380
                                                   " start angle: " + psArc.startang + " sweepang = " + psArc.sweepang);
381
                                                   System.out.println("secondaria axis: " + psArc.secondary_axis +
382
                                                                                    " rotation = " + psArc.rotation); */
383
                                                AffineTransform mT = AffineTransform.getRotateInstance(Math.toRadians(
384
                                                                        psArc.rotation), psArc.origin.x,
385
                                                                psArc.origin.y);
386

    
387
                                                // mT.preConcatenate(AffineTransform.getScaleInstance(100.0,100.0));
388
                                                Arc2D.Double elArco = new Arc2D.Double(psArc.origin.x -
389
                                                                psArc.primary_axis,
390
                                                                psArc.origin.y - psArc.secondary_axis,
391
                                                                2.0 * psArc.primary_axis,
392
                                                                2.0 * psArc.secondary_axis, -psArc.startang,
393
                                                                -psArc.sweepang, Arc2D.OPEN);
394

    
395
                                                // Ellipse2D.Double elArco = new Ellipse2D.Double(psArc.origin.x - psArc.primary_axis,
396
                                                //                 psArc.origin.y - psArc.secondary_axis,2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis);
397
                                                GeneralPathX elShapeArc = new GeneralPathX(elArco);
398

    
399
                                                // Transformamos el GeneralPahtX porque si transformamos elArco nos lo convierte
400
                                                // a GeneralPath y nos guarda las coordenadas en float, con la correspondiente p?rdida de precisi?n
401
                                                elShapeArc.transform(mT);
402

    
403
                                                if (m_DgnReader.getInfo().dimension == 3) {
404
                                                        //Aqu? podr?amos hacer cosas con la coordenada Z
405
                                                }
406

    
407
                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
408
                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
409
                                                                "Arc");
410
                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
411
                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
412

    
413
                                                /* Line2D.Double ejeMayor = new Line2D.Double(psArc.origin.x - psArc.primary_axis, psArc.origin.y,
414
                                                   psArc.origin.x + psArc.primary_axis, psArc.origin.y);
415

416
                                                   lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, new GeneralPathX(ejeMayor)), auxRow); */
417

    
418
                                                // lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, elShapeArc), auxRow);
419
                                                if (elemento.complex != 0) {
420
                                                        // Esto es una posible fuente de fallos si detr?s de una
421
                                                        // elipse vienen m?s cosas pegadas. Deber?amos volver
422
                                                        // a conectar una vez pasada la elipse.
423
                                                        if (elemento.type == DGNFileHeader.DGNT_ELLIPSE) {
424
                                                                bConnect = false;
425
                                                        }
426

    
427
                                                        // SI LA ELIPSE ES UN AGUJERO, SE A?ADE SIN PEGAR
428
                                                        // Y EL ELEMENTO ES UN POLIGONO
429
                                                        if (bFirstHoleEntity ||
430
                                                                        ((elemento.type == DGNFileHeader.DGNT_SHAPE) &&
431
                                                                        ((elemento.properties & 0x8000) != 0))) {
432
                                                                elementoCompuesto.append(elShapeArc, false);
433
                                                                bFirstHoleEntity = false;
434
                                                        } else {
435
                                                                elementoCompuesto.append(elShapeArc, bConnect);
436
                                                        }
437
                                                } else {
438
                                                        addShape(new FPolyline2D(elShapeArc), auxRow);
439

    
440
                                                        if (psArc.type == DGNFileHeader.DGNT_ELLIPSE) {
441
                                                                addShape(new FPolygon2D(elShapeArc), auxRow);
442
                                                        }
443
                                                }
444

    
445
                                                // System.err.println("Entra un Arco");
446
                                                break;
447

    
448
                                        case DGNFileHeader.DGNST_TEXT:
449

    
450
                                                DGNElemText psText = (DGNElemText) elemento;
451
                                                FPoint2D elShapeTxt = new FPoint3D(psText.origin.x,
452
                                                                psText.origin.y, psText.origin.z);
453

    
454
                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
455
                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
456
                                                                "Text");
457
                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
458
                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
459
                                                heightText = (float) psText.height_mult;
460
                                                auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
461
                                                auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(psText.rotation);
462
                                                auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(psText.string); // .trim();
463
                                                addShape(elShapeTxt, auxRow);
464

    
465
                                                // System.out.println("Rotaci?n texto: " + psText.rotation + "Altura Texto = " + heightText);
466

    
467
                                                /* System.out.println("  origin=(" + psText.origin.x +
468
                                                   ", " + psText.origin.y + ") rotation=" +
469
                                                   psText.rotation + "\n" + "  font=" +
470
                                                   psText.font_id + " just=" +
471
                                                   psText.justification + "length_mult=" +
472
                                                   psText.length_mult + " height_mult=" +
473
                                                   psText.height_mult + "\n" + "  string =" +
474
                                                   new String(psText.string).toString().trim() +
475
                                                   "\n"); */
476
                                                break;
477

    
478
                                        /* default:
479
                                           m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento, "");
480
                                         */
481
                                } // switch
482
                        } // if
483
                } // for
484

    
485
                if (bElementoCompuesto) {
486
                        if (bInsideCell) {
487
                                auxRow = cellRow;
488
                        } else {
489
                                auxRow = complexRow;
490
                        }
491

    
492
                        // System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
493
                        addShape(new FPolyline2D(elementoCompuesto), auxRow);
494

    
495
                        if (bEsPoligono) {
496
                                if (complex_index_fill_color != -1) {
497
                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
498
                                }
499

    
500
                                addShape(new FPolygon2D(elementoCompuesto), auxRow);
501
                        }
502
                }
503

    
504
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
505
                defaultLegend.setFieldName("Color");
506
                defaultLegend.setLabelField("Text");
507
                FSymbol myDefaultSymbol = new FSymbol(getShapeType());
508
                myDefaultSymbol.setShapeVisible(true);
509
                myDefaultSymbol.setFontSizeInPixels(false);
510
                myDefaultSymbol.setFont(new Font("SansSerif",Font.PLAIN, 9));
511
                myDefaultSymbol.setFontColor(Color.BLACK);
512
                myDefaultSymbol.setFontSize(heightText);
513
                myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
514
                myDefaultSymbol.setSize(3);
515
                myDefaultSymbol.setSizeInPixels(true);
516

    
517
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
518

    
519
                defaultLegend.setLabelHeightField("HeightText");
520
                defaultLegend.setLabelRotationField("RotationText");
521

    
522
                ObjectDriver rs = this;
523
                IntValue clave;
524
                FSymbol theSymbol = null;
525

    
526
                try {
527
                    // TODO: Provisional hasta que cambiemos los s?mbolos.
528
                    /* BufferedImage bi= new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
529
                   Graphics2D big = bi.createGraphics();
530
                   Color color=new Color(0,0,0,0);
531
                   big.setBackground(color);
532
                   big.clearRect(0, 0, 1, 1);
533
                   Paint fillProv = null;
534
                   Rectangle2D rProv = new Rectangle();
535
                   rProv.setFrame(0, 0,1,1);
536
                   fillProv = new TexturePaint(bi,rProv); */
537
                        for (long j = 0; j < rs.getRowCount(); j++) {
538
                                clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR);
539

    
540
                                if (defaultLegend.getSymbolByValue(clave) == null) {
541
                                        theSymbol = new FSymbol(getShapeType());
542
                                        theSymbol.setDescription(clave.toString());
543
                                        Color c = m_DgnReader.DGNLookupColor(
544
                                                        clave.getValue());
545
                                        // Le ponemos transparencia para que los pol?gonos no
546
                                        // tapen del todo. (Est? dentro del DGNLookupColor
547
                                        // c.
548
                                        theSymbol.setColor(c);
549
                                        // theSymbol.setFill(fillProv);
550
                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
551
                                        theSymbol.setSize(3);
552
                                        theSymbol.setSizeInPixels(true);
553

    
554
                                        // theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
555
                                        defaultLegend.addSymbol(clave, theSymbol);
556
                                }
557
                        } // for
558
                } catch (DriverException e) {
559
                        e.printStackTrace();
560
                        throw new IOException(
561
                                "Error al poner la leyenda por defecto en el DGN");
562
                }
563
        }
564

    
565
        /**
566
         * Devuelve el tipo de shape que contiene el formato DGN.
567
         *
568
         * @return Entero que representa el tipo de shape.
569
         */
570
        public int getShapeType() {
571
                return FShape.MULTI;
572
        }
573

    
574
        /**
575
         * @see com.hardcode.driverManager.Driver#getType()
576
         */
577
        public String getName() {
578
                return "gvSIG DGN Memory Driver";
579
        }
580

    
581
        /**
582
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
583
         */
584
        public boolean accept(File f) {
585
                return f.getName().toUpperCase().endsWith("DGN");
586
        }
587

    
588
        /* (non-Javadoc)
589
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
590
         */
591
        public Legend getDefaultLegend() {
592
                return defaultLegend;
593
        }
594

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

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

    
609
    /**
610
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
611
     */
612
    public void write(DataWare arg0) throws DriverException {
613
        // TODO Auto-generated method stub
614

    
615
    }
616

    
617
    /* (non-Javadoc)
618
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
619
     */
620
    public void close() throws IOException {
621
        // TODO Auto-generated method stub
622

    
623
    }
624

    
625
        public File getFile() {
626
                return m_Fich;
627
        }
628

    
629
        public boolean isWritable() {
630
                return m_Fich.canWrite();
631
        }
632

    
633
}