Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dgn / DgnMemoryDriver.java @ 11853

History | View | Annotate | Download (23.1 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.geom.AffineTransform;
55
import java.awt.geom.Arc2D;
56
import java.io.File;
57
import java.util.ArrayList;
58

    
59
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
60
import com.hardcode.gdbms.driver.exceptions.OpenDriverException;
61
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
62
import com.hardcode.gdbms.driver.exceptions.WriteDriverException;
63
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
64
import com.hardcode.gdbms.engine.data.edition.DataWare;
65
import com.hardcode.gdbms.engine.values.IntValue;
66
import com.hardcode.gdbms.engine.values.StringValue;
67
import com.hardcode.gdbms.engine.values.Value;
68
import com.hardcode.gdbms.engine.values.ValueFactory;
69
import com.iver.cit.gvsig.fmap.core.FPoint2D;
70
import com.iver.cit.gvsig.fmap.core.FPoint3D;
71
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
72
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
73
import com.iver.cit.gvsig.fmap.core.FShape;
74
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
75
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
76
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol;
77
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
78
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
79
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
80
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
81
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver;
82
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
83
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
84
import com.iver.cit.gvsig.fmap.rendering.ILegend;
85
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
86
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
87
import com.iver.cit.gvsig.fmap.rendering.styling.AttrInTableLabeling;
88
import com.iver.cit.gvsig.fmap.rendering.styling.ILabelingStrategy;
89

    
90

    
91
/**
92
 * Driver DGN que trabaja directamente cargando el fichero en memoria.
93
 *
94
 * @author Vicente Caballero Navarro
95
 */
96
public class DgnMemoryDriver extends MemoryDriver implements VectorialFileDriver, WithDefaultLegend {
97
        private final int ID_FIELD_ID = 0;
98
        private final int ID_FIELD_ENTITY = 1;
99
        private final int ID_FIELD_LAYER = 2;
100
        private final int ID_FIELD_COLOR = 3;
101
        private final int ID_FIELD_HEIGHTTEXT = 4;
102
        private final int ID_FIELD_ROTATIONTEXT = 5;
103
        private final int ID_FIELD_TEXT = 6;
104
        DGNReader m_DgnReader;
105
        VectorialUniqueValueLegend defaultLegend;
106
        private String path;
107
        private File m_Fich;
108
        private DriverAttributes attr = new DriverAttributes();
109
        private ILabelingStrategy labeler;
110

    
111
        /**
112
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
113
         */
114
        public void open(File f) throws OpenDriverException {
115
                m_Fich = f;
116
        }
117

    
118
        /**
119
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
120
         */
121
        public void initialize() throws InitializeDriverException {
122
                float heightText = 10;
123
                attr.setLoadedInMemory(true);
124

    
125
                m_DgnReader = new DGNReader(m_Fich.getAbsolutePath());
126

    
127
                Value[] auxRow = new Value[7];
128
                Value[] cellRow = new Value[7];
129
                Value[] complexRow = new Value[7];
130
                ArrayList arrayFields = new ArrayList();
131
                arrayFields.add("ID");
132
                arrayFields.add("Entity");
133
                arrayFields.add("Layer");
134
                arrayFields.add("Color");
135
                arrayFields.add("HeightText");
136
                arrayFields.add("RotationText");
137
                arrayFields.add("Text");
138

    
139
                getTableModel().setColumnIdentifiers(arrayFields.toArray());
140

    
141
                // jaume
142
                labeler = new AttrInTableLabeling();
143
                ((AttrInTableLabeling) labeler).setTextFieldId(arrayFields.indexOf("Text"));
144
                ((AttrInTableLabeling) labeler).setRotationFieldId(arrayFields.indexOf("RotationText"));
145
                ((AttrInTableLabeling) labeler).setHeightFieldId(arrayFields.indexOf("HeightText"));
146
                ((AttrInTableLabeling) labeler).setUnit(1); //MapContext.NAMES[1] (meters)
147

    
148

    
149
                // Ahora las rellenamos.
150
                FShape aux;
151
                boolean bElementoCompuesto = false;
152
                boolean bEsPoligono = false;
153
                boolean bInsideCell = false;
154
                boolean bFirstHoleEntity = false;
155
                boolean bConnect = false; // Se usa para que los pol?gonos cierren bien cuando son formas compuestas
156
                int contadorSubElementos = 0;
157
                int numSubElementos = 0;
158
                int complex_index_fill_color = -1;
159
                int nClass; // Para filtrar los elementos de construcci?n, etc.
160
                GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
161

    
162
                for (int id = 0; id < m_DgnReader.getNumEntities(); id++) {
163
                        // System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
164
                        m_DgnReader.DGNGotoElement(id);
165

    
166
                        DGNElemCore elemento = m_DgnReader.DGNReadElement();
167
                        nClass = 0;
168
                        auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
169
                        auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
170
                        auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
171

    
172
                        if (elemento.properties != 0) {
173
                                nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS;
174
                        }
175

    
176
                        if ((elemento != null) && (elemento.deleted == 0) && (nClass == 0)) //Leer un elemento
177
                         {
178
                                aux = null;
179

    
180
                                // if ((elemento.element_id > 3800) && (elemento.element_id < 3850))
181
                                //         m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,"");
182
                                if ((elemento.stype == DGNFileHeader.DGNST_MULTIPOINT) ||
183
                                                (elemento.stype == DGNFileHeader.DGNST_ARC) ||
184
                                                (elemento.stype == DGNFileHeader.DGNST_CELL_HEADER) ||
185
                                                (elemento.stype == DGNFileHeader.DGNST_SHARED_CELL_DEFN) ||
186
                                                (elemento.stype == DGNFileHeader.DGNST_COMPLEX_HEADER)) {
187
                                        if (elemento.complex != 0) {
188
                                                bElementoCompuesto = true;
189
                                        } else {
190
                                                if (bElementoCompuesto) {
191
                                                        if (bInsideCell) {
192
                                                                auxRow[ID_FIELD_ENTITY] = cellRow[ID_FIELD_ENTITY];
193
                                                        } else {
194
                                                                auxRow = complexRow;
195
                                                        }
196

    
197
                                                        // System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
198
                                                        addShape(new FPolyline2D(elementoCompuesto), auxRow);
199

    
200
                                                        if (bEsPoligono) {
201
                                                                if (complex_index_fill_color != -1) {
202
                                                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
203
                                                                }
204

    
205
                                                                addShape(new FPolygon2D(elementoCompuesto),
206
                                                                        auxRow);
207
                                                        }
208

    
209
                                                        elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
210
                                                }
211

    
212
                                                // System.err.println("Entidad simple");
213
                                                bElementoCompuesto = false;
214
                                                bEsPoligono = false;
215
                                                bConnect = false;
216

    
217
                                                // elementoCompuesto = new GeneralPathX();
218
                                                bInsideCell = false;
219
                                        }
220
                                }
221

    
222
                                switch (elemento.stype) {
223
                                        case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
224
                                                bInsideCell = true;
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
                                                                "Shared Cell");
230

    
231
                                                break;
232

    
233
                                        case DGNFileHeader.DGNST_CELL_HEADER:
234
                                                bInsideCell = true;
235

    
236
                                                DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento;
237
                                                cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
238
                                                cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
239
                                                cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
240
                                                cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
241
                                                                "Cell");
242
                                                complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento);
243

    
244
                                                // System.err.println("Cell Header " + complex_index_fill_color);
245
                                                break;
246

    
247
                                        case DGNFileHeader.DGNST_COMPLEX_HEADER:
248

    
249
                                                // bElementoCompuesto = true;
250
                                                // System.err.println("Complex Header");
251
                                                contadorSubElementos = 0;
252

    
253
                                                DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento;
254
                                                numSubElementos = psComplexHeader.numelems;
255
                                                complexRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
256
                                                complexRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
257
                                                complexRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
258
                                                complexRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
259
                                                                "Complex");
260

    
261
                                                if (psComplexHeader.type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER) {
262
                                                        bEsPoligono = true;
263

    
264
                                                        // Si es un agujero, no conectamos con el anterior
265
                                                        if ((psComplexHeader.properties & 0x8000) != 0) {
266
                                                                bFirstHoleEntity = true;
267
                                                        } else {
268
                                                                // Miramos si tiene color de relleno
269
                                                                // complex_index_fill_color = -1;
270
                                                                // if (elemento.attr_bytes > 0) {
271
                                                                complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento);
272

    
273
                                                                // System.err.println("complex shape fill color = " + elemento.color);
274
                                                                // }
275
                                                        }
276

    
277
                                                        bConnect = true;
278
                                                } else {
279
                                                        bEsPoligono = false;
280
                                                        bConnect = false;
281
                                                }
282

    
283
                                                break;
284

    
285
                                        case DGNFileHeader.DGNST_MULTIPOINT:
286

    
287
                                                // OJO: Si lo que viene en este multipoint es un elemento con type=11 (curve), se trata de una "parametric
288
                                                // spline curve". La vamos a tratar como si no fuera curva, pero seg?n la documentaci?n, los 2 primeros puntos
289
                                                // y los 2 ?ltimos puntos definen "endpoint derivatives" y NO se muestran.
290
                                                // TODAV?A HAY UN PEQUE?O FALLO CON EL FICHERO dgn-sample.dgn, pero lo dejo por ahora.
291
                                                // Es posible que tenga que ver con lo de los arcos (arco distorsionado), que
292
                                                // todav?a no est? metido.
293
                                                DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento;
294
                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
295
                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
296

    
297
                                                if ((psLine.num_vertices == 2) &&
298
                                                                (psLine.vertices[0].x == psLine.vertices[1].x) &&
299
                                                                (psLine.vertices[0].y == psLine.vertices[1].y)) {
300
                                                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
301
                                                                        "Point");
302
                                                        addShape(new FPoint3D(psLine.vertices[0].x,
303
                                                                        psLine.vertices[0].y, psLine.vertices[0].z),
304
                                                                auxRow);
305
                                                } else {
306
                                                        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
307

    
308
                                                        if (psLine.type == DGNFileHeader.DGNT_CURVE) {
309
                                                                psLine.num_vertices = psLine.num_vertices - 4;
310

    
311
                                                                for (int aux_n = 0;
312
                                                                                aux_n < psLine.num_vertices; aux_n++) {
313
                                                                        psLine.vertices[aux_n] = psLine.vertices[aux_n +
314
                                                                                2];
315
                                                                }
316
                                                        }
317

    
318
                                                        if ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
319
                                                                        ((psLine.properties & 0x8000) != 0)) {
320
                                                                // Invertimos el orden porque es un agujero
321
                                                                elShape.moveTo(psLine.vertices[psLine.num_vertices -
322
                                                                        1].x,
323
                                                                        psLine.vertices[psLine.num_vertices - 1].y);
324

    
325
                                                                for (int i = psLine.num_vertices - 2; i >= 0;
326
                                                                                i--)
327
                                                                        elShape.lineTo(psLine.vertices[i].x,
328
                                                                                psLine.vertices[i].y);
329
                                                        } else {
330
                                                                elShape.moveTo(psLine.vertices[0].x,
331
                                                                        psLine.vertices[0].y);
332

    
333
                                                                for (int i = 1; i < psLine.num_vertices; i++)
334
                                                                        elShape.lineTo(psLine.vertices[i].x,
335
                                                                                psLine.vertices[i].y);
336
                                                        }
337

    
338
                                                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
339
                                                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
340
                                                                        "Multipoint");
341

    
342
                                                        if ((psLine.vertices[0].x == psLine.vertices[psLine.num_vertices -
343
                                                                        1].x) &&
344
                                                                        (psLine.vertices[0].y == psLine.vertices[psLine.num_vertices -
345
                                                                        1].y)) {
346
                                                                // Lo a?adimos tambi?n como pol?gono
347
                                                                bEsPoligono = true;
348

    
349
                                                                // Miramos si tiene color de relleno
350
                                                                if (elemento.attr_bytes > 0) {
351
                                                                        elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento);
352

    
353
                                                                        // System.err.println("fill color = " + elemento.color);
354
                                                                        if (elemento.color != -1) {
355
                                                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
356
                                                                        }
357
                                                                }
358

    
359
                                                                if (elemento.complex == 0) {
360
                                                                        addShape(new FPolygon2D(elShape), auxRow);
361
                                                                }
362
                                                        }
363

    
364
                                                        if (elemento.complex != 0) {
365
                                                                // Si es un agujero o
366
                                                                // es la primera entidad del agujero, lo a?adimos sin unir al anterior
367
                                                                if (bFirstHoleEntity ||
368
                                                                                ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
369
                                                                                ((psLine.properties & 0x8000) != 0))) {
370
                                                                        elementoCompuesto.append(elShape, false);
371
                                                                        bFirstHoleEntity = false;
372
                                                                } else {
373
                                                                        elementoCompuesto.append(elShape, bConnect);
374
                                                                }
375
                                                        } else {
376
                                                                addShape(new FPolyline2D(elShape), auxRow);
377
                                                        }
378
                                                }
379

    
380
                                                break;
381

    
382
                                        case DGNFileHeader.DGNST_ARC:
383

    
384
                                                // m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
385
                                                DGNElemArc psArc = (DGNElemArc) elemento;
386

    
387
                                                // La definici?n de arco de MicroStation es distinta a la de Java.
388
                                                // En el dgn el origin se entiende que es el centro del arco,
389
                                                // y a la hora de crear un Arc2D las 2 primeras coordenadas son
390
                                                // la esquina inferior izquierda del rect?ngulo que rodea al arco.
391
                                                // 1.- Creamos la elipse sin rotaci?n.
392
                                                // 2.- Creamos el arco
393
                                                // 3.- Rotamos el resultado
394

    
395
                                                /* System.out.println("Arco con primari axis: " + psArc.primary_axis +
396
                                                   " start angle: " + psArc.startang + " sweepang = " + psArc.sweepang);
397
                                                   System.out.println("secondaria axis: " + psArc.secondary_axis +
398
                                                                                    " rotation = " + psArc.rotation); */
399
                                                AffineTransform mT = AffineTransform.getRotateInstance(Math.toRadians(
400
                                                                        psArc.rotation), psArc.origin.x,
401
                                                                psArc.origin.y);
402

    
403
                                                // mT.preConcatenate(AffineTransform.getScaleInstance(100.0,100.0));
404
                                                Arc2D.Double elArco = new Arc2D.Double(psArc.origin.x -
405
                                                                psArc.primary_axis,
406
                                                                psArc.origin.y - psArc.secondary_axis,
407
                                                                2.0 * psArc.primary_axis,
408
                                                                2.0 * psArc.secondary_axis, -psArc.startang,
409
                                                                -psArc.sweepang, Arc2D.OPEN);
410

    
411
                                                // Ellipse2D.Double elArco = new Ellipse2D.Double(psArc.origin.x - psArc.primary_axis,
412
                                                //                 psArc.origin.y - psArc.secondary_axis,2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis);
413
                                                GeneralPathX elShapeArc = new GeneralPathX(elArco);
414

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

    
419
                                                if (m_DgnReader.getInfo().dimension == 3) {
420
                                                        //Aqu? podr?amos hacer cosas con la coordenada Z
421
                                                }
422

    
423
                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
424
                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
425
                                                                "Arc");
426
                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
427
                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
428

    
429
                                                /* Line2D.Double ejeMayor = new Line2D.Double(psArc.origin.x - psArc.primary_axis, psArc.origin.y,
430
                                                   psArc.origin.x + psArc.primary_axis, psArc.origin.y);
431

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

    
434
                                                // lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, elShapeArc), auxRow);
435
                                                if (elemento.complex != 0) {
436
                                                        // Esto es una posible fuente de fallos si detr?s de una
437
                                                        // elipse vienen m?s cosas pegadas. Deber?amos volver
438
                                                        // a conectar una vez pasada la elipse.
439
                                                        if (elemento.type == DGNFileHeader.DGNT_ELLIPSE) {
440
                                                                bConnect = false;
441
                                                        }
442

    
443
                                                        // SI LA ELIPSE ES UN AGUJERO, SE A?ADE SIN PEGAR
444
                                                        // Y EL ELEMENTO ES UN POLIGONO
445
                                                        if (bFirstHoleEntity ||
446
                                                                        ((elemento.type == DGNFileHeader.DGNT_SHAPE) &&
447
                                                                        ((elemento.properties & 0x8000) != 0))) {
448
                                                                elementoCompuesto.append(elShapeArc, false);
449
                                                                bFirstHoleEntity = false;
450
                                                        } else {
451
                                                                elementoCompuesto.append(elShapeArc, bConnect);
452
                                                        }
453
                                                } else {
454
                                                        addShape(new FPolyline2D(elShapeArc), auxRow);
455

    
456
                                                        if (psArc.type == DGNFileHeader.DGNT_ELLIPSE) {
457
                                                                addShape(new FPolygon2D(elShapeArc), auxRow);
458
                                                        }
459
                                                }
460

    
461
                                                // System.err.println("Entra un Arco");
462
                                                break;
463

    
464
                                        case DGNFileHeader.DGNST_TEXT:
465

    
466
                                                DGNElemText psText = (DGNElemText) elemento;
467
                                                FPoint2D elShapeTxt = new FPoint3D(psText.origin.x,
468
                                                                psText.origin.y, psText.origin.z);
469

    
470
                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
471
                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
472
                                                                "Text");
473
                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
474
                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
475
                                                heightText = (float) psText.height_mult;
476
                                                auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
477
                                                auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(psText.rotation);
478
                                                auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(psText.string); // .trim();
479
                                                addShape(elShapeTxt, auxRow);
480

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

    
483
                                                /* System.out.println("  origin=(" + psText.origin.x +
484
                                                   ", " + psText.origin.y + ") rotation=" +
485
                                                   psText.rotation + "\n" + "  font=" +
486
                                                   psText.font_id + " just=" +
487
                                                   psText.justification + "length_mult=" +
488
                                                   psText.length_mult + " height_mult=" +
489
                                                   psText.height_mult + "\n" + "  string =" +
490
                                                   new String(psText.string).toString().trim() +
491
                                                   "\n"); */
492
                                                break;
493

    
494
                                        /* default:
495
                                           m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento, "");
496
                                         */
497
                                } // switch
498
                        } // if
499
                } // for
500

    
501
                if (bElementoCompuesto) {
502
                        if (bInsideCell) {
503
                                auxRow = cellRow;
504
                        } else {
505
                                auxRow = complexRow;
506
                        }
507

    
508
                        // System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
509
                        addShape(new FPolyline2D(elementoCompuesto), auxRow);
510

    
511
                        if (bEsPoligono) {
512
                                if (complex_index_fill_color != -1) {
513
                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
514
                                }
515

    
516
                                addShape(new FPolygon2D(elementoCompuesto), auxRow);
517
                        }
518
                }
519

    
520
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
521
                defaultLegend.setFieldNames(new String[] {"Color"} );
522

    
523

    
524
                ISymbol myDefaultSymbol = SymbologyFactory.
525
                        createDefaultSymbolByShapeType(getShapeType());
526

    
527
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
528

    
529

    
530
                ObjectDriver rs = this;
531
                IntValue clave;
532
                ISymbol theSymbol = null;
533

    
534
                try {
535
                    // TODO: Provisional hasta que cambiemos los s?mbolos.
536
                    /* BufferedImage bi= new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
537
                   Graphics2D big = bi.createGraphics();
538
                   Color color=new Color(0,0,0,0);
539
                   big.setBackground(color);
540
                   big.clearRect(0, 0, 1, 1);
541
                   Paint fillProv = null;
542
                   Rectangle2D rProv = new Rectangle();
543
                   rProv.setFrame(0, 0,1,1);
544
                   fillProv = new TexturePaint(bi,rProv); */
545
                        for (long j = 0; j < rs.getRowCount(); j++) {
546
                                clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR);
547
                                if (defaultLegend.getSymbolByValue(clave) == null) {
548
//
549
//                                        theSymbol = new FSymbol(getShapeType());
550
//                                        theSymbol.setDescription(clave.toString());
551
//                                        Color c = m_DgnReader.DGNLookupColor(
552
//                                                        clave.getValue());
553
//                                        // Le ponemos transparencia para que los pol?gonos no
554
//                                        // tapen del todo. (Est? dentro del DGNLookupColor
555
//                                        // c.
556
//                                        theSymbol.setColor(c);
557
//                                        // theSymbol.setFill(fillProv);
558
//                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
559
//                                        theSymbol.setSize(3);
560
//                                        theSymbol.setSizeInPixels(true);
561

    
562
                                        Color c = m_DgnReader.DGNLookupColor(
563
                                                        clave.getValue());
564
                                        theSymbol =        SymbologyFactory.
565
                                                createDefaultSymbolByShapeType(getShapeType(), c);
566
                                        theSymbol.setDescription(clave.toString());
567

    
568
                                        if (theSymbol instanceof IMarkerSymbol) {
569
                                                ((IMarkerSymbol) theSymbol).setSize(1);
570
                                        }
571

    
572
                                        if (theSymbol instanceof ILineSymbol) {
573
                                                ((ILineSymbol) theSymbol).setLineWidth(1);
574
                                        }
575

    
576
                                        if (theSymbol instanceof IFillSymbol) {
577
                                                ((IFillSymbol) theSymbol).getOutline().setLineColor(c);
578
                                                ((IFillSymbol) theSymbol).getOutline().setLineWidth(1);
579
                                                ((IFillSymbol) theSymbol).setFillColor(null);
580
                                        }
581

    
582
                                        // theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
583
                                        defaultLegend.addSymbol(clave, theSymbol);
584
                                }
585

    
586
                                if ("Text".equalsIgnoreCase(((StringValue) rs.getFieldValue(j, ID_FIELD_ENTITY)).toString())) {
587

    
588
                                }
589

    
590

    
591
                        } // for
592
                } catch (ReadDriverException e) {
593
                        throw new InitializeDriverException(getName(),e);
594
                }
595
        }
596

    
597
        /**
598
         * Devuelve el tipo de shape que contiene el formato DGN.
599
         *
600
         * @return Entero que representa el tipo de shape.
601
         */
602
        public int getShapeType() {
603
                return FShape.MULTI;
604
        }
605

    
606
        /**
607
         * @see com.hardcode.driverManager.Driver#getType()
608
         */
609
        public String getName() {
610
                return "gvSIG DGN Memory Driver";
611
        }
612

    
613
        /**
614
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
615
         */
616
        public boolean accept(File f) {
617
                return f.getName().toUpperCase().endsWith("DGN");
618
        }
619

    
620
        /* (non-Javadoc)
621
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
622
         */
623
        public ILegend getDefaultLegend() {
624
                return defaultLegend;
625
        }
626

    
627
    /* (non-Javadoc)
628
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
629
     */
630
    public DriverAttributes getDriverAttributes() {
631
        return attr;
632
    }
633

    
634
    /**
635
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
636
     */
637
    public int[] getPrimaryKeys() throws ReadDriverException {
638
        return null;
639
    }
640

    
641
    /**
642
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
643
     */
644
    public void write(DataWare arg0) throws WriteDriverException {
645
        // TODO Auto-generated method stub
646

    
647
    }
648

    
649
    /* (non-Javadoc)
650
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
651
     */
652
    public void close() {
653
        // TODO Auto-generated method stub
654

    
655
    }
656

    
657
        public File getFile() {
658
                return m_Fich;
659
        }
660

    
661
        public boolean isWritable() {
662
                return m_Fich.canWrite();
663
        }
664

    
665
        public ILabelingStrategy getDefaultLabelingStrategy() {
666
                return labeler;
667
        }
668
}