Statistics
| Revision:

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

History | View | Annotate | Download (24.6 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.sql.Types;
58
import java.util.ArrayList;
59

    
60
import javax.swing.table.DefaultTableModel;
61

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

    
93

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

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

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

    
128
                m_DgnReader = new DGNReader(m_Fich.getAbsolutePath());
129

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

    
142
                getTableModel().setColumnIdentifiers(arrayFields.toArray());
143

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

    
151

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

    
165
                for (int id = 0; id < m_DgnReader.getNumEntities(); id++) {
166
                        // System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
167
                        m_DgnReader.DGNGotoElement(id);
168

    
169
                        DGNElemCore elemento = m_DgnReader.DGNReadElement();
170
                        nClass = 0;
171
                        auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
172
                        auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
173
                        auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
174

    
175
                        if (elemento.properties != 0) {
176
                                nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS;
177
                        }
178

    
179
                        if ((elemento != null) && (elemento.deleted == 0) && (nClass == 0)) //Leer un elemento
180
                         {
181
                                aux = null;
182

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

    
200
                                                        // System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
201
                                                        addShape(new FPolyline2D(elementoCompuesto), auxRow);
202

    
203
                                                        if (bEsPoligono) {
204
                                                                if (complex_index_fill_color != -1) {
205
                                                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
206
                                                                }
207

    
208
                                                                addShape(new FPolygon2D(elementoCompuesto),
209
                                                                        auxRow);
210
                                                        }
211

    
212
                                                        elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
213
                                                }
214

    
215
                                                // System.err.println("Entidad simple");
216
                                                bElementoCompuesto = false;
217
                                                bEsPoligono = false;
218
                                                bConnect = false;
219

    
220
                                                // elementoCompuesto = new GeneralPathX();
221
                                                bInsideCell = false;
222
                                        }
223
                                }
224

    
225
                                switch (elemento.stype) {
226
                                        case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
227
                                                bInsideCell = true;
228
                                                cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
229
                                                cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
230
                                                cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
231
                                                cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
232
                                                                "Shared Cell");
233

    
234
                                                break;
235

    
236
                                        case DGNFileHeader.DGNST_CELL_HEADER:
237
                                                bInsideCell = true;
238

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

    
247
                                                // System.err.println("Cell Header " + complex_index_fill_color);
248
                                                break;
249

    
250
                                        case DGNFileHeader.DGNST_COMPLEX_HEADER:
251

    
252
                                                // bElementoCompuesto = true;
253
                                                // System.err.println("Complex Header");
254
                                                contadorSubElementos = 0;
255

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

    
264
                                                if (psComplexHeader.type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER) {
265
                                                        bEsPoligono = true;
266

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

    
276
                                                                // System.err.println("complex shape fill color = " + elemento.color);
277
                                                                // }
278
                                                        }
279

    
280
                                                        bConnect = true;
281
                                                } else {
282
                                                        bEsPoligono = false;
283
                                                        bConnect = false;
284
                                                }
285

    
286
                                                break;
287

    
288
                                        case DGNFileHeader.DGNST_MULTIPOINT:
289

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

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

    
314
                                                        if (psLine.type == DGNFileHeader.DGNT_CURVE) {
315
                                                                psLine.num_vertices = psLine.num_vertices - 4;
316

    
317
                                                                for (int aux_n = 0;
318
                                                                                aux_n < psLine.num_vertices; aux_n++) {
319
                                                                        psLine.vertices[aux_n] = psLine.vertices[aux_n +
320
                                                                                2];
321
                                                                }
322
                                                        }
323

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

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

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

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

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

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

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

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

    
382
                                                break;
383

    
384
                                        case DGNFileHeader.DGNST_ARC:
385

    
386
                                                // m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
387
                                                DGNElemArc psArc = (DGNElemArc) elemento;
388

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

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

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

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

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

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

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

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

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

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

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

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

    
463
                                                // System.err.println("Entra un Arco");
464
                                                break;
465

    
466
                                        case DGNFileHeader.DGNST_TEXT:
467

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

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

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

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

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

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

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

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

    
518
                                addShape(new FPolygon2D(elementoCompuesto), auxRow);
519
                        }
520
                }
521

    
522
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
523
                defaultLegend.setClassifyingFieldNames(new String[] {"Color"} );
524
                defaultLegend.setClassifyingFieldTypes(new int[]{Types.INTEGER,Types.VARCHAR,Types.INTEGER,Types.INTEGER,Types.FLOAT,Types.DOUBLE,Types.VARCHAR});
525

    
526

    
527
                ISymbol myDefaultSymbol = SymbologyFactory.
528
                        createDefaultSymbolByShapeType(getShapeType());
529

    
530
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
531

    
532

    
533
                ObjectDriver rs = this;
534
                IntValue clave;
535
                ISymbol theSymbol = null;
536

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

    
565
                                        Color c = m_DgnReader.DGNLookupColor(
566
                                                        clave.getValue());
567
                                        theSymbol =        SymbologyFactory.
568
                                                createDefaultSymbolByShapeType(getShapeType(), c);
569
                                        theSymbol.setDescription(clave.toString());
570

    
571
                                        if (theSymbol instanceof IMarkerSymbol) {
572
                                                ((IMarkerSymbol) theSymbol).setSize(1);
573
                                        }
574

    
575
                                        if (theSymbol instanceof ILineSymbol) {
576
                                                ((ILineSymbol) theSymbol).setLineWidth(1);
577
                                        }
578

    
579
                                        if (theSymbol instanceof IFillSymbol) {
580
                                                ((IFillSymbol) theSymbol).getOutline().setLineColor(c);
581
                                                ((IFillSymbol) theSymbol).getOutline().setLineWidth(1);
582
                                                ((IFillSymbol) theSymbol).setFillColor(null);
583
                                        }
584

    
585
                                        // theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
586
                                        defaultLegend.addSymbol(clave, theSymbol);
587
                                }
588

    
589
                                if ("Text".equalsIgnoreCase(((StringValue) rs.getFieldValue(j, ID_FIELD_ENTITY)).toString())) {
590

    
591
                                }
592

    
593

    
594
                        } // for
595
                } catch (ReadDriverException e) {
596
                        throw new InitializeDriverException(getName(),e);
597
                }
598
        }
599

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

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

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

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

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

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

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

    
650
    }
651

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

    
658
    }
659

    
660
        public File getFile() {
661
                return m_Fich;
662
        }
663

    
664
        public boolean isWritable() {
665
                return m_Fich.canWrite();
666
        }
667

    
668
        public ILabelingStrategy getDefaultLabelingStrategy() {
669
                return labeler;
670
        }
671
        public int getFieldType(int i) {
672
            DefaultTableModel dtm=getTableModel();
673
                String columnName=dtm.getColumnName(i);
674
            if (columnName.equals("ID")){
675
                    return Types.INTEGER;
676
            }else if (columnName.equals("Entity")){
677
                    return Types.VARCHAR;
678
            }else if (columnName.equals("Layer")){
679
                    return Types.INTEGER;
680
            }else if (columnName.equals("Color")){
681
                    return Types.INTEGER;
682
            }else if (columnName.equals("HeightText")){
683
                    return Types.FLOAT;
684
            }else if (columnName.equals("RotationText")){
685
                    return Types.DOUBLE;
686
            }else if (columnName.equals("Text")){
687
                    return Types.VARCHAR;
688
            }else{
689
                    return Types.VARCHAR;
690
            }
691
        }
692
}