Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dgn / DgnMemoryDriver.java @ 12079

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_ID] = ValueFactory.createValue(elemento.element_id);
295
                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
296
                                                                "Multipoint");                                                
297
                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
298
                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
299

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

    
311
                                                        if (psLine.type == DGNFileHeader.DGNT_CURVE) {
312
                                                                psLine.num_vertices = psLine.num_vertices - 4;
313

    
314
                                                                for (int aux_n = 0;
315
                                                                                aux_n < psLine.num_vertices; aux_n++) {
316
                                                                        psLine.vertices[aux_n] = psLine.vertices[aux_n +
317
                                                                                2];
318
                                                                }
319
                                                        }
320

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

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

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

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

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

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

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

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

    
379
                                                break;
380

    
381
                                        case DGNFileHeader.DGNST_ARC:
382

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
463
                                        case DGNFileHeader.DGNST_TEXT:
464

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

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

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

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

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

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

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

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

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

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

    
522

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

    
526
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
527

    
528

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

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

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

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

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

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

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

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

    
587
                                }
588

    
589

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

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

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

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

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

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

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

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

    
646
    }
647

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

    
654
    }
655

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

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

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