Statistics
| Revision:

root / trunk / libraries / libFMap_dataFile / src / org / gvsig / data / datastores / vectorial / file / dgn / DGNStore.java @ 20660

History | View | Annotate | Download (34.5 KB)

1
package org.gvsig.data.datastores.vectorial.file.dgn;
2

    
3
import java.awt.geom.AffineTransform;
4
import java.awt.geom.Arc2D;
5
import java.io.File;
6
import java.lang.ref.WeakReference;
7
import java.sql.Types;
8
import java.util.ArrayList;
9
import java.util.Collection;
10
import java.util.Comparator;
11
import java.util.Iterator;
12
import java.util.List;
13
import java.util.TreeSet;
14

    
15
import org.gvsig.data.DataManager;
16
import org.gvsig.data.IDataCollection;
17
import org.gvsig.data.IDataExplorer;
18
import org.gvsig.data.IDataExplorerParameters;
19
import org.gvsig.data.IDataStoreParameters;
20
import org.gvsig.data.datastores.vectorial.IFeaturesWriter;
21
import org.gvsig.data.datastores.vectorial.base.MemoryStore;
22
import org.gvsig.data.datastores.vectorial.file.DataExplorerFileParameters;
23
import org.gvsig.data.datastores.vectorial.file.dbf.DBFDataExplorer;
24
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemArc;
25
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemCellHeader;
26
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemComplexHeader;
27
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemCore;
28
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemMultiPoint;
29
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemText;
30
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNFileHeader;
31
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNReader;
32
import org.gvsig.data.exception.CloseException;
33
import org.gvsig.data.exception.InitializeException;
34
import org.gvsig.data.exception.OpenException;
35
import org.gvsig.data.exception.ReadException;
36
import org.gvsig.data.exception.WriteException;
37
import org.gvsig.data.spatialprovisional.IExtent;
38
import org.gvsig.data.vectorial.AttributeDescriptor;
39
import org.gvsig.data.vectorial.FeatureType;
40
import org.gvsig.data.vectorial.Feature;
41
import org.gvsig.data.vectorial.FeatureStoreNotification;
42
import org.gvsig.data.vectorial.IFeature;
43
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
44
import org.gvsig.data.vectorial.IFeatureCollection;
45
import org.gvsig.data.vectorial.IFeatureID;
46
import org.gvsig.data.vectorial.IFeatureType;
47
import org.gvsig.data.vectorial.IsNotAttributeSettingException;
48
import org.gvsig.data.vectorial.IsNotFeatureSettingException;
49
import org.gvsig.data.vectorial.expressionevaluator.FeatureComparator;
50
import org.gvsig.data.vectorial.expressionevaluator.FeatureFilter;
51
import org.gvsig.exceptions.BaseException;
52
import org.gvsig.metadata.IMetadata;
53
import org.gvsig.metadata.IMetadataManager;
54
import org.gvsig.metadata.MetadataManager;
55

    
56
import com.iver.cit.gvsig.fmap.core.FShape;
57
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
58
import com.iver.cit.gvsig.fmap.core.IGeometry;
59
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
60
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
61
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
62
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
63
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
64
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy;
65

    
66
public class DGNStore extends MemoryStore{
67
        public static String DATASTORE_NAME = "DGNStore";
68
        private final int ID_FIELD_ID = 0;
69
        private final int ID_FIELD_ENTITY = 1;
70
        private final int ID_FIELD_LAYER = 2;
71
        private final int ID_FIELD_COLOR = 3;
72
        private final int ID_FIELD_HEIGHTTEXT = 4;
73
        private final int ID_FIELD_ROTATIONTEXT = 5;
74
        private final int ID_FIELD_TEXT = 6;
75
        private final int ID_FIELD_GEOMETRY = 7;
76

    
77
        private List featureTypes = new ArrayList();//<IFeatureType>
78
        private IFeatureType featureType;
79
        protected IMetadata metadata;
80
        private DGNStoreParameters dgnParameters=null;
81
        private File dgnFile;
82
        private AttrInTableLabelingStrategy labeling;
83
        private VectorialUniqueValueLegend defaultLegend;
84

    
85
        public void init(IDataStoreParameters parameters) throws InitializeException {
86
                super.init(parameters);
87
                dgnParameters=(DGNStoreParameters)parameters;
88
                dgnFile=dgnParameters.getFile();
89
        }
90

    
91
        static IFeatureType newFeatureType(){
92
                FeatureType fType= new FeatureType();
93
                try {
94
                        AttributeDescriptor descriptorID = new AttributeDescriptor();
95
                        descriptorID.loading();
96
                        descriptorID.setType(IFeatureAttributeDescriptor.TYPE_INT);
97
                        descriptorID.setName("ID");
98
                        descriptorID.setDefaultValue(new Integer(0));
99
                        descriptorID.stopLoading();
100
                        fType.add(descriptorID);
101
                        fType.setFieldsId(new String[] {"ID"});
102

    
103
                        AttributeDescriptor descriptorEntity = new AttributeDescriptor();
104
                        descriptorEntity.loading();
105
                        descriptorEntity.setType(IFeatureAttributeDescriptor.TYPE_STRING);
106
                        descriptorEntity.setName("Entity");
107
                        descriptorEntity.setDefaultValue("Entity");
108
                        descriptorEntity.stopLoading();
109
                        fType.add(descriptorEntity);
110

    
111
                        AttributeDescriptor descriptorLayer = new AttributeDescriptor();
112
                        descriptorLayer.loading();
113
                        descriptorLayer.setType(IFeatureAttributeDescriptor.TYPE_INT);
114
                        descriptorLayer.setName("Layer");
115
                        descriptorLayer.setDefaultValue(new Integer(0));
116
                        descriptorLayer.stopLoading();
117
                        fType.add(descriptorLayer);
118

    
119
                        AttributeDescriptor descriptorColor = new AttributeDescriptor();
120
                        descriptorColor.loading();
121
                        descriptorColor.setType(IFeatureAttributeDescriptor.TYPE_INT);
122
                        descriptorColor.setName("Color");
123
                        descriptorColor.setDefaultValue(new Integer(0));
124
                        descriptorColor.stopLoading();
125
                        fType.add(descriptorColor);
126

    
127
                        //                DefaultAttributeDescriptor descriptorElevation = new DefaultAttributeDescriptor();
128
                        //                descriptorElevation.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE);
129
                        //                descriptorElevation.setName("Elevation");
130
                        //                descriptorElevation.setDefaultValue(new Double(0));
131
                        //                featureType.add(descriptorElevation);
132
                        //
133
                        //                DefaultAttributeDescriptor descriptorThickness = new DefaultAttributeDescriptor();
134
                        //                descriptorThickness.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE);
135
                        //                descriptorThickness.setName("Thickness");
136
                        //                descriptorThickness.setDefaultValue(new Double(0));
137
                        //                featureType.add(descriptorThickness);
138

    
139
                        AttributeDescriptor descriptorHeightText = new AttributeDescriptor();
140
                        descriptorHeightText.loading();
141
                        descriptorHeightText.setType(IFeatureAttributeDescriptor.TYPE_FLOAT);
142
                        descriptorHeightText.setName("HeightText");
143
                        descriptorHeightText.setDefaultValue(new Float(0));
144
                        descriptorHeightText.stopLoading();
145
                        fType.add(descriptorHeightText);
146

    
147
                        AttributeDescriptor descriptorRotationText = new AttributeDescriptor();
148
                        descriptorRotationText.loading();
149
                        descriptorRotationText.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE);
150
                        descriptorRotationText.setName("RotationText");
151
                        descriptorRotationText.setDefaultValue(new Double(0));
152
                        descriptorRotationText.stopLoading();
153
                        fType.add(descriptorRotationText);
154

    
155
                        AttributeDescriptor descriptorText = new AttributeDescriptor();
156
                        descriptorText.loading();
157
                        descriptorText.setType(IFeatureAttributeDescriptor.TYPE_STRING);
158
                        descriptorText.setName("Text");
159
                        descriptorText.setDefaultValue("");
160
                        descriptorText.stopLoading();
161
                        fType.add(descriptorText);
162

    
163
                        AttributeDescriptor descriptorShape = new AttributeDescriptor();
164
                        descriptorShape.loading();
165

    
166
                        descriptorShape.setType(IFeatureAttributeDescriptor.TYPE_GEOMETRY);
167

    
168
                        descriptorShape.setName("GEOMETRY");
169
                        descriptorShape.setDefaultValue(null);
170
                        descriptorShape.stopLoading();
171
                        fType.add(descriptorShape);
172
                        fType.setDefaultGeometry("GEOMETRY");
173
                } catch (IsNotAttributeSettingException e) {
174
                        e.printStackTrace();
175
                }
176
                return fType;
177

    
178

    
179
        }
180

    
181
        private void initializeFeatureType() {
182
                featureType = newFeatureType();
183
        }
184

    
185
        protected void doFinishEdition() throws WriteException, ReadException{
186
                IFeaturesWriter writer = getFeaturesWriter();
187
                writer.init(this);
188
                writer.updateFeatureType(featureType);
189
                writer.preProcess();
190
                Collection collection=getDataCollection();
191
                Iterator iterator=collection.iterator();
192
                IFeature feature;
193
                while (iterator.hasNext()) {
194
                        feature= (IFeature) iterator.next();
195
                        writer.insertFeature(feature);
196
                }
197
                writer.postProcess();
198

    
199
        }
200

    
201
        public IDataCollection getDataCollection(IFeatureType type, String filter, String order) throws ReadException {
202
                if (type==null){
203
                        type=getDefaultFeatureType();
204
                }
205
                IFeatureCollection coll;
206

    
207
                //TODO aplicar filtro, orden e incluso y el featureType
208
                FeatureFilter parser = null;
209
                if (filter!=null){
210
                        parser = new FeatureFilter(filter,type);
211
                }
212
                ArrayList originalFeatures=this.getFeatures();
213
                int num=0;
214
                if (featureManager!=null){
215
                        num=featureManager.getNum();
216
                }
217
                int originalSize=originalFeatures.size();
218
                Collection allFeatures=null;
219
                if (order!=null){
220
                        Comparator comparator = new FeatureComparator(type,order);
221
                        allFeatures = new TreeSet(comparator);
222
                }else{
223
                        allFeatures=new ArrayList();
224
                }
225
                int j=0;
226
                for (int i = 0; i < originalSize+num; i++) {
227
                        IFeature feature=null;
228
                        if (i<this.getFeatureCount()){
229
                                feature=this.getFeature(i);
230
                        }else{
231
                                feature=featureManager.getFeature(i-originalSize,this);
232
                        }
233
                        if (featureManager == null || !featureManager.isDeleted(feature)){
234

    
235
                                DGNFeature auxfeature=new DGNFeature(feature);
236
                                if (filter==null || parser.match(auxfeature)){
237
//                                        System.err.println(i);
238
//                                        j++;
239
//                                        System.err.println("j= "+j);
240
                                        if (!allFeatures.add(auxfeature)){
241
                                                //????
242
//                                                System.err.println("Fallo  " +auxfeature);
243
                                        }else{
244
//                                                System.out.println("Correcto  " +auxfeature);
245
                                        }
246
                                }
247

    
248
                        }
249

    
250
                }
251

    
252
                coll=new DGNFeatureCollection(allFeatures);
253
                this.addObserver(new WeakReference(coll));
254
                return coll;
255
        }
256

    
257
        public IFeature getFeatureByID(IFeatureID id) throws ReadException {
258
                if (this.alterMode){
259
                        if (featureManager.contains(id)) {
260
                                return featureManager.getFeature(id,this);
261

    
262
                        }
263
                }
264
                return id.getFeature(featureType);
265
        }
266

    
267
        public List getFeatureTypes() {
268
                featureTypes.set(0,getDefaultFeatureType());
269
                return featureTypes;
270
        }
271

    
272
        public IFeatureType getDefaultFeatureType() {
273
                if (isEditing()){
274
//                        Aqu? hay que construir un FeatureType con los cambios que se hayan hecho en la edici?n.
275
                        return attributeManager.getFeatureType();
276
                }
277
                return featureType;
278
        }
279

    
280
        public boolean isWithDefaultLegend() {
281
                return false;
282
        }
283

    
284
        public Object getDefaultLegend() {
285
                return null;
286
        }
287

    
288
        public Object getDefaultLabelingStrategy() {
289
                return null;
290
        }
291

    
292
        public boolean canAlterFeatureType() {
293
                return true;
294
        }
295

    
296
        public String getName() {
297
                return DATASTORE_NAME;
298
        }
299

    
300
        protected void doOpen() throws OpenException {
301
                float heightText = 10;
302
//                attr.setLoadedInMemory(true);
303
                initializeFeatureType();
304
                DGNReader m_DgnReader;
305
                try {
306
                        m_DgnReader = new DGNReader(dgnFile.getAbsolutePath());
307
                } catch (ReadException e) {
308
                        throw new OpenException(getName(),e);
309
                }
310

    
311
                try{
312
//                        Value[] auxRow = new Value[7];
313
//                        Value[] cellRow = new Value[7];
314
//                        Value[] complexRow = new Value[7];
315
                        DGNFeature auxFeature=new DGNFeature(featureType,true);
316
                        auxFeature.loading();
317
                        DGNFeature cellFeature=new DGNFeature(featureType,false);
318
                        cellFeature.loading();
319
                        DGNFeature complexFeature=new DGNFeature(featureType,false);
320
                        complexFeature.loading();
321
                        initializeFeatureType();
322
//                        ArrayList arrayFields = new ArrayList();
323
//                        arrayFields.add("ID");
324
//                        arrayFields.add("Entity");
325
//                        arrayFields.add("Layer");
326
//                        arrayFields.add("Color");
327
//                        arrayFields.add("HeightText");
328
//                        arrayFields.add("RotationText");
329
//                        arrayFields.add("Text");
330

    
331
//                        getTableModel().setColumnIdentifiers(arrayFields.toArray());
332

    
333
                        // jaume
334
                        labeling = new AttrInTableLabelingStrategy();
335
                        ((AttrInTableLabelingStrategy) labeling).setTextFieldId(featureType.getFieldIndex("Text"));
336
                        ((AttrInTableLabelingStrategy) labeling).setRotationFieldId(featureType.getFieldIndex("RotationText"));
337
                        ((AttrInTableLabelingStrategy) labeling).setHeightFieldId(featureType.getFieldIndex("HeightText"));
338
                        ((AttrInTableLabelingStrategy) labeling).setUnit(1); //MapContext.NAMES[1] (meters)
339

    
340

    
341
                        // Ahora las rellenamos.
342
//                        FShape aux;
343
                        boolean bElementoCompuesto = false;
344
                        boolean bEsPoligono = false;
345
                        boolean bInsideCell = false;
346
                        boolean bFirstHoleEntity = false;
347
                        boolean bConnect = false; // Se usa para que los pol?gonos cierren bien cuando son formas compuestas
348
//                        int contadorSubElementos = 0;
349
//                        int numSubElementos = 0;
350
                        int complex_index_fill_color = -1;
351
                        int nClass; // Para filtrar los elementos de construcci?n, etc.
352
                        GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
353

    
354
                        for (int id = 0; id < m_DgnReader.getNumEntities(); id++) {
355

    
356
                                // System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
357
                                m_DgnReader.DGNGotoElement(id);
358

    
359
                                DGNElemCore elemento = m_DgnReader.DGNReadElement();
360
                                nClass = 0;
361
//                                auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
362
//                                auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
363
//                                auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
364

    
365
                                if (elemento.properties != 0) {
366
                                        nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS;
367
                                }
368

    
369
                                if ((elemento != null) && (elemento.deleted == 0) && (nClass == 0)) //Leer un elemento
370
                                {
371
//                                        aux = null;
372

    
373
                                        // if ((elemento.element_id > 3800) && (elemento.element_id < 3850))
374
                                        //         m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,"");
375
                                        if ((elemento.stype == DGNFileHeader.DGNST_MULTIPOINT) ||
376
                                                        (elemento.stype == DGNFileHeader.DGNST_ARC) ||
377
                                                        (elemento.stype == DGNFileHeader.DGNST_CELL_HEADER) ||
378
                                                        (elemento.stype == DGNFileHeader.DGNST_SHARED_CELL_DEFN) ||
379
                                                        (elemento.stype == DGNFileHeader.DGNST_COMPLEX_HEADER)) {
380
                                                if (elemento.complex != 0) {
381
                                                        bElementoCompuesto = true;
382
                                                } else {
383
                                                        if (bElementoCompuesto) {
384
                                                                if (bInsideCell) {
385
                                                                        auxFeature.set(ID_FIELD_ENTITY,cellFeature.get(ID_FIELD_ENTITY));
386
//                                                                        auxRow[ID_FIELD_ENTITY] = cellRow[ID_FIELD_ENTITY];
387
                                                                } else {
388
                                                                        auxFeature=complexFeature;
389
//                                                                        auxRow = complexRow;
390
                                                                }
391

    
392
                                                                // System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
393
                                                                IGeometry geom=ShapeFactory.createPolyline2D(elementoCompuesto);
394
                                                                auxFeature.set(ID_FIELD_GEOMETRY,geom);
395
//                                                                auxFeature.setDefaultGeometry(geom);
396
                                                                addDGNFeature(auxFeature);
397
//                                                                addShape(new FPolyline2D(elementoCompuesto), auxRow);
398

    
399
                                                                if (bEsPoligono) {
400
                                                                        if (complex_index_fill_color != -1) {
401
                                                                                auxFeature.set(ID_FIELD_COLOR,complex_index_fill_color);
402
//                                                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
403
                                                                        }
404
                                                                        geom=ShapeFactory.createPolygon2D(elementoCompuesto);
405
                                                                        auxFeature.set(ID_FIELD_GEOMETRY,geom);
406
//                                                                        auxFeature.setDefaultGeometry(geom);
407
                                                                        addDGNFeature(auxFeature);
408
//                                                                        addShape(new FPolygon2D(elementoCompuesto),        auxRow);
409
                                                                }
410

    
411
                                                                elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
412
                                                        }
413

    
414
                                                        // System.err.println("Entidad simple");
415
                                                        bElementoCompuesto = false;
416
                                                        bEsPoligono = false;
417
                                                        bConnect = false;
418

    
419
                                                        // elementoCompuesto = new GeneralPathX();
420
                                                        bInsideCell = false;
421
                                                }
422
                                        }
423

    
424
                                        switch (elemento.stype) {
425
                                        case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
426
                                                bInsideCell = true;
427
                                                cellFeature.set(ID_FIELD_ID,elemento.element_id);
428
//                                                cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
429
                                                cellFeature.set(ID_FIELD_LAYER,elemento.level);
430
//                                                cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
431
                                                cellFeature.set(ID_FIELD_COLOR,elemento.color);
432
//                                                cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
433
                                                cellFeature.set(ID_FIELD_ENTITY,"Shared Cell");
434
//                                                cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
435
//                                                "Shared Cell");
436

    
437
                                                break;
438

    
439
                                        case DGNFileHeader.DGNST_CELL_HEADER:
440
                                                bInsideCell = true;
441

    
442
                                                DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento;
443
                                                cellFeature.set(ID_FIELD_ID,elemento.element_id);
444
//                                                cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
445
                                                cellFeature.set(ID_FIELD_LAYER,elemento.level);
446
//                                                cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
447
                                                cellFeature.set(ID_FIELD_COLOR,elemento.color);
448
//                                                cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
449
                                                cellFeature.set(ID_FIELD_ENTITY,"Cell");
450
//                                                cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
451
//                                                "Cell");
452
                                                complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento);
453

    
454
                                                // System.err.println("Cell Header " + complex_index_fill_color);
455
                                                break;
456

    
457
                                        case DGNFileHeader.DGNST_COMPLEX_HEADER:
458

    
459
                                                // bElementoCompuesto = true;
460
                                                // System.err.println("Complex Header");
461
//                                                contadorSubElementos = 0;
462

    
463
                                                DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento;
464
//                                                numSubElementos = psComplexHeader.numelems;
465
                                                complexFeature.set(ID_FIELD_ID,elemento.element_id);
466
//                                                complexRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
467
                                                complexFeature.set(ID_FIELD_LAYER,elemento.level);
468
//                                                complexRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
469
                                                complexFeature.set(ID_FIELD_COLOR,elemento.color);
470
//                                                complexRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
471
                                                complexFeature.set(ID_FIELD_ENTITY,"Complex");
472
//                                                complexRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
473
//                                                "Complex");
474

    
475
                                                if (psComplexHeader.type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER) {
476
                                                        bEsPoligono = true;
477

    
478
                                                        // Si es un agujero, no conectamos con el anterior
479
                                                        if ((psComplexHeader.properties & 0x8000) != 0) {
480
                                                                bFirstHoleEntity = true;
481
                                                        } else {
482
                                                                // Miramos si tiene color de relleno
483
                                                                // complex_index_fill_color = -1;
484
                                                                // if (elemento.attr_bytes > 0) {
485
                                                                complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento);
486

    
487
                                                                // System.err.println("complex shape fill color = " + elemento.color);
488
                                                                // }
489
                                                        }
490

    
491
                                                        bConnect = true;
492
                                                } else {
493
                                                        bEsPoligono = false;
494
                                                        bConnect = false;
495
                                                }
496

    
497
                                                break;
498

    
499
                                        case DGNFileHeader.DGNST_MULTIPOINT:
500

    
501
                                                // OJO: Si lo que viene en este multipoint es un elemento con type=11 (curve), se trata de una "parametric
502
                                                // spline curve". La vamos a tratar como si no fuera curva, pero seg?n la documentaci?n, los 2 primeros puntos
503
                                                // y los 2 ?ltimos puntos definen "endpoint derivatives" y NO se muestran.
504
                                                // TODAV?A HAY UN PEQUE?O FALLO CON EL FICHERO dgn-sample.dgn, pero lo dejo por ahora.
505
                                                // Es posible que tenga que ver con lo de los arcos (arco distorsionado), que
506
                                                // todav?a no est? metido.
507
                                                DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento;
508
                                                auxFeature.set(ID_FIELD_ID,elemento.element_id);
509
//                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
510
                                                auxFeature.set(ID_FIELD_ENTITY,"Multipoint");
511
//                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
512
//                                                "Multipoint");
513
                                                auxFeature.set(ID_FIELD_LAYER,elemento.level);
514
//                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
515
                                                auxFeature.set(ID_FIELD_COLOR,elemento.color);
516
//                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
517

    
518
                                                if ((psLine.num_vertices == 2) &&
519
                                                                (psLine.vertices[0].x == psLine.vertices[1].x) &&
520
                                                                (psLine.vertices[0].y == psLine.vertices[1].y)) {
521
                                                        auxFeature.set(ID_FIELD_ENTITY,"Point");
522
//                                                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
523
//                                                        "Point");
524

    
525
                                                        IGeometry geom=ShapeFactory.createPoint3D(psLine.vertices[0].x,
526
                                                                        psLine.vertices[0].y, psLine.vertices[0].z);
527
                                                        auxFeature.set(ID_FIELD_GEOMETRY,geom);
528
//                                                        auxFeature.setDefaultGeometry(geom);
529
                                                        addDGNFeature(auxFeature);
530

    
531
//                                                        addShape(new FPoint3D(psLine.vertices[0].x,
532
//                                                        psLine.vertices[0].y, psLine.vertices[0].z),
533
//                                                        auxRow);
534
                                                } else {
535
                                                        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
536

    
537
                                                        if (psLine.type == DGNFileHeader.DGNT_CURVE) {
538
                                                                psLine.num_vertices = psLine.num_vertices - 4;
539

    
540
                                                                for (int aux_n = 0;
541
                                                                aux_n < psLine.num_vertices; aux_n++) {
542
                                                                        psLine.vertices[aux_n] = psLine.vertices[aux_n +
543
                                                                                                                 2];
544
                                                                }
545
                                                        }
546

    
547
                                                        if ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
548
                                                                        ((psLine.properties & 0x8000) != 0)) {
549
                                                                // Invertimos el orden porque es un agujero
550
                                                                elShape.moveTo(psLine.vertices[psLine.num_vertices -
551
                                                                                               1].x,
552
                                                                                               psLine.vertices[psLine.num_vertices - 1].y);
553

    
554
                                                                for (int i = psLine.num_vertices - 2; i >= 0;
555
                                                                i--)
556
                                                                        elShape.lineTo(psLine.vertices[i].x,
557
                                                                                        psLine.vertices[i].y);
558
                                                        } else {
559
                                                                elShape.moveTo(psLine.vertices[0].x,
560
                                                                                psLine.vertices[0].y);
561

    
562
                                                                for (int i = 1; i < psLine.num_vertices; i++)
563
                                                                        elShape.lineTo(psLine.vertices[i].x,
564
                                                                                        psLine.vertices[i].y);
565
                                                        }
566

    
567
                                                        if ((psLine.vertices[0].x == psLine.vertices[psLine.num_vertices -
568
                                                                                                     1].x) &&
569
                                                                                                     (psLine.vertices[0].y == psLine.vertices[psLine.num_vertices -
570
                                                                                                                                              1].y)) {
571
                                                                // Lo a?adimos tambi?n como pol?gono
572
                                                                bEsPoligono = true;
573

    
574
                                                                // Miramos si tiene color de relleno
575
                                                                if (elemento.attr_bytes > 0) {
576
                                                                        elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento);
577

    
578
                                                                        // System.err.println("fill color = " + elemento.color);
579
                                                                        if (elemento.color != -1) {
580
                                                                                auxFeature.set(ID_FIELD_COLOR,elemento.color);
581
//                                                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
582
                                                                        }
583
                                                                }
584

    
585
                                                                if (elemento.complex == 0) {
586
                                                                        IGeometry geom=ShapeFactory.createPolygon2D(elShape);
587
                                                                        auxFeature.set(ID_FIELD_GEOMETRY,geom);
588
//                                                                        auxFeature.setDefaultGeometry(geom);
589
                                                                        addDGNFeature(auxFeature);
590
//                                                                        addShape(new FPolygon2D(elShape), auxRow);
591
                                                                }
592
                                                        }
593

    
594
                                                        if (elemento.complex != 0) {
595
                                                                // Si es un agujero o
596
                                                                // es la primera entidad del agujero, lo a?adimos sin unir al anterior
597
                                                                if (bFirstHoleEntity ||
598
                                                                                ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
599
                                                                                                ((psLine.properties & 0x8000) != 0))) {
600
                                                                        elementoCompuesto.append(elShape, false);
601
                                                                        bFirstHoleEntity = false;
602
                                                                } else {
603
                                                                        elementoCompuesto.append(elShape, bConnect);
604
                                                                }
605
                                                        } else {
606
                                                                IGeometry geom=ShapeFactory.createPolyline2D(elShape);
607
                                                                auxFeature.set(ID_FIELD_GEOMETRY,geom);
608
//                                                                auxFeature.setDefaultGeometry(geom);
609
                                                                addDGNFeature(auxFeature);
610
//                                                                addShape(new FPolyline2D(elShape), auxRow);
611
                                                        }
612
                                                }
613

    
614
                                                break;
615

    
616
                                        case DGNFileHeader.DGNST_ARC:
617

    
618
                                                // m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
619
                                                DGNElemArc psArc = (DGNElemArc) elemento;
620

    
621
                                                // La definici?n de arco de MicroStation es distinta a la de Java.
622
                                                // En el dgn el origin se entiende que es el centro del arco,
623
                                                // y a la hora de crear un Arc2D las 2 primeras coordenadas son
624
                                                // la esquina inferior izquierda del rect?ngulo que rodea al arco.
625
                                                // 1.- Creamos la elipse sin rotaci?n.
626
                                                // 2.- Creamos el arco
627
                                                // 3.- Rotamos el resultado
628

    
629
                                                /* System.out.println("Arco con primari axis: " + psArc.primary_axis +
630
                                                 " start angle: " + psArc.startang + " sweepang = " + psArc.sweepang);
631
                                                 System.out.println("secondaria axis: " + psArc.secondary_axis +
632
                                                 " rotation = " + psArc.rotation); */
633
                                                AffineTransform mT = AffineTransform.getRotateInstance(Math.toRadians(
634
                                                                psArc.rotation), psArc.origin.x,
635
                                                                psArc.origin.y);
636

    
637
                                                // mT.preConcatenate(AffineTransform.getScaleInstance(100.0,100.0));
638
                                                Arc2D.Double elArco = new Arc2D.Double(psArc.origin.x -
639
                                                                psArc.primary_axis,
640
                                                                psArc.origin.y - psArc.secondary_axis,
641
                                                                2.0 * psArc.primary_axis,
642
                                                                2.0 * psArc.secondary_axis, -psArc.startang,
643
                                                                -psArc.sweepang, Arc2D.OPEN);
644

    
645
                                                // Ellipse2D.Double elArco = new Ellipse2D.Double(psArc.origin.x - psArc.primary_axis,
646
                                                //                 psArc.origin.y - psArc.secondary_axis,2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis);
647
                                                GeneralPathX elShapeArc = new GeneralPathX(elArco);
648

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

    
653
                                                if (m_DgnReader.getInfo().dimension == 3) {
654
                                                        //Aqu? podr?amos hacer cosas con la coordenada Z
655
                                                }
656

    
657
                                                auxFeature.set(ID_FIELD_ID,elemento.element_id);
658
//                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
659
                                                auxFeature.set(ID_FIELD_ENTITY,"Arc");
660
//                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
661
//                                                "Arc");
662
                                                auxFeature.set(ID_FIELD_LAYER,elemento.level);
663
//                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
664
                                                auxFeature.set(ID_FIELD_COLOR,elemento.color);
665
//                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
666

    
667
                                                /* Line2D.Double ejeMayor = new Line2D.Double(psArc.origin.x - psArc.primary_axis, psArc.origin.y,
668
                                                 psArc.origin.x + psArc.primary_axis, psArc.origin.y);
669

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

    
672
                                                // lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, elShapeArc), auxRow);
673
                                                if (elemento.complex != 0) {
674
                                                        // Esto es una posible fuente de fallos si detr?s de una
675
                                                        // elipse vienen m?s cosas pegadas. Deber?amos volver
676
                                                        // a conectar una vez pasada la elipse.
677
                                                        if (elemento.type == DGNFileHeader.DGNT_ELLIPSE) {
678
                                                                bConnect = false;
679
                                                        }
680

    
681
                                                        // SI LA ELIPSE ES UN AGUJERO, SE A?ADE SIN PEGAR
682
                                                        // Y EL ELEMENTO ES UN POLIGONO
683
                                                        if (bFirstHoleEntity ||
684
                                                                        ((elemento.type == DGNFileHeader.DGNT_SHAPE) &&
685
                                                                                        ((elemento.properties & 0x8000) != 0))) {
686
                                                                elementoCompuesto.append(elShapeArc, false);
687
                                                                bFirstHoleEntity = false;
688
                                                        } else {
689
                                                                elementoCompuesto.append(elShapeArc, bConnect);
690
                                                        }
691
                                                } else {
692
                                                        IGeometry geom=ShapeFactory.createPolyline2D(elShapeArc);
693
                                                        auxFeature.set(ID_FIELD_GEOMETRY,geom);
694
//                                                        auxFeature.setDefaultGeometry(geom);
695
                                                        addDGNFeature(auxFeature);
696

    
697
//                                                        addShape(new FPolyline2D(elShapeArc), auxRow);
698

    
699
                                                        if (psArc.type == DGNFileHeader.DGNT_ELLIPSE) {
700
                                                                geom=ShapeFactory.createPolygon2D(elShapeArc);
701
                                                                auxFeature.set(ID_FIELD_GEOMETRY,geom);
702
//                                                                auxFeature.setDefaultGeometry(geom);
703
                                                                addDGNFeature(auxFeature);
704
//                                                                addShape(new FPolygon2D(elShapeArc), auxRow);
705
                                                        }
706
                                                }
707

    
708
                                                // System.err.println("Entra un Arco");
709
                                                break;
710

    
711
                                        case DGNFileHeader.DGNST_TEXT:
712

    
713
                                                DGNElemText psText = (DGNElemText) elemento;
714

    
715

    
716
                                                auxFeature.set(ID_FIELD_ID,elemento.element_id);
717
//                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
718
                                                auxFeature.set(ID_FIELD_ENTITY,"Text");
719
//                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
720
//                                                "Text");
721
                                                auxFeature.set(ID_FIELD_LAYER,elemento.level);
722
//                                                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
723
                                                auxFeature.set(ID_FIELD_COLOR,elemento.color);
724
//                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
725
                                                heightText = (float) psText.height_mult;
726
                                                auxFeature.set(ID_FIELD_HEIGHTTEXT,heightText);
727
//                                                auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
728
                                                auxFeature.set(ID_FIELD_ROTATIONTEXT,psText.rotation);
729
//                                                auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(psText.rotation);
730
                                                auxFeature.set(ID_FIELD_TEXT,psText.string);
731
//                                                auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(psText.string); // .trim();
732

    
733
                                                IGeometry geom=ShapeFactory.createPoint3D(psText.origin.x,
734
                                                                psText.origin.y, psText.origin.z);
735
                                                auxFeature.set(ID_FIELD_GEOMETRY,geom);
736
//                                                auxFeature.setDefaultGeometry(geom);
737
                                                addDGNFeature(auxFeature);
738

    
739
//                                                addShape(elShapeTxt, auxRow);
740

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

    
743
                                                /* System.out.println("  origin=(" + psText.origin.x +
744
                                                 ", " + psText.origin.y + ") rotation=" +
745
                                                 psText.rotation + "\n" + "  font=" +
746
                                                 psText.font_id + " just=" +
747
                                                 psText.justification + "length_mult=" +
748
                                                 psText.length_mult + " height_mult=" +
749
                                                 psText.height_mult + "\n" + "  string =" +
750
                                                 new String(psText.string).toString().trim() +
751
                                                 "\n"); */
752
                                                break;
753

    
754
                                                /* default:
755
                                                 m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento, "");
756
                                                 */
757
                                        } // switch
758
                                } // if
759
                        } // for
760

    
761
                        if (bElementoCompuesto) {
762
                                if (bInsideCell) {
763
                                        auxFeature=cellFeature;
764
//                                        auxRow = cellRow;
765
                                } else {
766
                                        auxFeature=complexFeature;
767
//                                        auxRow = complexRow;
768
                                }
769

    
770
                                // System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
771
                                IGeometry geom=ShapeFactory.createPolyline2D(elementoCompuesto);
772
                                auxFeature.set(ID_FIELD_GEOMETRY,geom);
773
//                                auxFeature.setDefaultGeometry(geom);
774
                                addDGNFeature(auxFeature);
775

    
776
//                                addShape(new FPolyline2D(elementoCompuesto), auxRow);
777

    
778
                                if (bEsPoligono) {
779
                                        if (complex_index_fill_color != -1) {
780
                                                auxFeature.set(ID_FIELD_COLOR,complex_index_fill_color);
781
//                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
782
                                        }
783
                                        geom=ShapeFactory.createPolygon2D(elementoCompuesto);
784
                                        auxFeature.set(ID_FIELD_GEOMETRY,geom);
785
//                                        auxFeature.setDefaultGeometry(geom);
786
                                        addDGNFeature(auxFeature);
787
//                                        addShape(new FPolygon2D(elementoCompuesto), auxRow);
788
                                }
789
                        }
790
                        cellFeature.stopLoading();
791
                        auxFeature.stopLoading();
792
                        complexFeature.stopLoading();
793
                        defaultLegend = LegendFactory.createVectorialUniqueValueLegend(FShape.MULTI);
794
                        defaultLegend.setClassifyingFieldNames(new String[] {"Color"} );
795
                        defaultLegend.setClassifyingFieldTypes(new int[]{Types.INTEGER,Types.VARCHAR,Types.INTEGER,Types.INTEGER,Types.FLOAT,Types.DOUBLE,Types.VARCHAR});
796

    
797

    
798
                        ISymbol myDefaultSymbol = SymbologyFactory.
799
                        createDefaultSymbolByShapeType(FShape.MULTI);
800

    
801
                        defaultLegend.setDefaultSymbol(myDefaultSymbol);
802
                }catch (IsNotFeatureSettingException e) {
803
                        throw new OpenException(this.getName(),e);
804
                } catch (ReadException e) {
805
                        throw new OpenException(this.getName(),e);
806
                }
807

    
808
//                ISymbol theSymbol = null;
809

    
810
//                try {
811
//                for (long j = 0; j < getFeatureCount(); j++) {
812
//                IFeature feat=(IFeature)getFeature((int)j);
813
//                int clave=feat.getInt(ID_FIELD_COLOR);
814
//                if (defaultLegend.getSymbolByValue(clave) == null) {
815

    
816
//                Color c = m_DgnReader.DGNLookupColor(
817
//                clave.getValue());
818
//                theSymbol =        SymbologyFactory.
819
//                createDefaultSymbolByShapeType(featureType.getGeometryTypes()[0], c);
820
//                theSymbol.setDescription(clave.toString());
821

    
822
//                if (theSymbol instanceof IMarkerSymbol) {
823
//                ((IMarkerSymbol) theSymbol).setSize(1);
824
//                }
825

    
826
//                if (theSymbol instanceof ILineSymbol) {
827
//                ((ILineSymbol) theSymbol).setLineWidth(1);
828
//                }
829

    
830
//                if (theSymbol instanceof IFillSymbol) {
831
//                ((IFillSymbol) theSymbol).getOutline().setLineColor(c);
832
//                ((IFillSymbol) theSymbol).getOutline().setLineWidth(1);
833
//                ((IFillSymbol) theSymbol).setFillColor(null);
834
//                }
835

    
836
//                // theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
837
//                defaultLegend.addSymbol(clave, theSymbol);
838
//                }
839

    
840
//                if ("Text".equalsIgnoreCase(((StringValue) rs.getFieldValue(j, ID_FIELD_ENTITY)).toString())) {
841

    
842
//                }
843

    
844

    
845
//                } // for
846
//                } catch (ReadException e) {
847
//                throw new OpenException(getName(),e);
848
//                }
849

    
850

    
851
        }
852

    
853
        protected void doClose() throws CloseException {
854
                super.doClose();
855

    
856
        }
857

    
858
        protected void doDispose() throws CloseException {
859
                close();
860
                this.metadata=null;
861
                this.featureType=null;
862
                this.defaultLegend=null;
863
                super.doDispose();
864

    
865
        }
866

    
867
        public boolean isEditable() {
868
                return false;
869
        }
870

    
871
        public IMetadata getMetadata() throws BaseException {
872
                if (metadata==null){
873
                        IMetadataManager manager=MetadataManager.getManager();
874
                        metadata=manager.create(DATASTORE_NAME);
875
                        IExtent extent=getFullExtent();
876
                        metadata.set("extent",extent);
877
                        String srs=getSRS();
878
                        metadata.set("srs",srs);
879
                }
880
                if (this.alterMode){
881
                        IExtent extent=(IExtent)metadata.get("extent");
882
                        IFeatureCollection featureCollection=(IFeatureCollection)getDataCollection();
883
                        if (spatialManager.isFullExtentDirty()){
884
                                if (!featureCollection.isEmpty()){
885
                                        Iterator featureIterator=featureCollection.iterator();
886
                                        extent = ((IFeature)featureIterator.next()).getExtent();
887
                                        while(featureIterator.hasNext()){
888
                                                IFeature feature=(IFeature)featureIterator.next();
889
                                                IExtent boundExtent=feature.getExtent();
890
                                                if (boundExtent!=null)
891
                                                        extent.add(boundExtent);
892
                                        }
893
                                }
894
                        }
895
                        metadata.set("extent",extent);
896
                }
897
                return metadata;
898
        }
899
        private String getSRS() {
900
                // TODO Auto-generated method stub
901
                return null;
902
        }
903

    
904

    
905
        protected IFeaturesWriter getFeaturesWriter() {
906
                return null;
907
        }
908
        public IDataStoreParameters getParameters() {
909
                return parameters;
910
        }
911

    
912
        public IDataExplorer getExplorer() {
913
                DataManager dsm=DataManager.getManager();
914
                IDataExplorerParameters dsp = dsm.createDataExplorerParameters(
915
                                DGNDataExplorer.DATASOURCE_NAME);
916
                ((DataExplorerFileParameters)dsp).setSource(dgnParameters.getFile().getParentFile());
917

    
918
                IDataExplorer src=null;
919
                try {
920
                        src = dsm.createDataExplorer(dsp);
921
                } catch (InitializeException e1) {
922
                        e1.printStackTrace();
923
                }
924
                return src;
925
        }
926

    
927
        private void addDGNFeature(IFeature feature) throws ReadException{
928
                this.addFeature(new DGNFeature(feature));
929
        }
930

    
931
        /* (non-Javadoc)
932
         * @see org.gvsig.data.vectorial.FeatureStore#doRefresh()
933
         */
934
        protected void doRefresh() throws OpenException, InitializeException {
935
                // TODO Auto-generated method stub
936
        }
937

    
938
}