Revision 20692 trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dxf/DXFStore.java

View differences:

DXFStore.java
4 4
import java.awt.geom.Point2D;
5 5
import java.io.File;
6 6
import java.lang.ref.WeakReference;
7
import java.security.KeyException;
7 8
import java.sql.Types;
8 9
import java.util.ArrayList;
9 10
import java.util.Collection;
......
30 31
import org.gvsig.data.IDataExplorer;
31 32
import org.gvsig.data.IDataExplorerParameters;
32 33
import org.gvsig.data.IDataStoreParameters;
34
import org.gvsig.data.ResourceManager;
33 35
import org.gvsig.data.datastores.vectorial.IFeaturesWriter;
34
import org.gvsig.data.datastores.vectorial.base.MemoryStore;
35 36
import org.gvsig.data.datastores.vectorial.file.DataExplorerFileParameters;
36 37
import org.gvsig.data.exception.CloseException;
38
import org.gvsig.data.exception.DataException;
37 39
import org.gvsig.data.exception.InitializeException;
38 40
import org.gvsig.data.exception.OpenException;
39 41
import org.gvsig.data.exception.ReadException;
40 42
import org.gvsig.data.exception.WriteException;
41 43
import org.gvsig.data.spatialprovisional.IExtent;
42 44
import org.gvsig.data.vectorial.AttributeDescriptor;
45
import org.gvsig.data.vectorial.FeatureStore;
43 46
import org.gvsig.data.vectorial.FeatureType;
44
import org.gvsig.data.vectorial.FeatureStoreNotification;
45 47
import org.gvsig.data.vectorial.IFeature;
46 48
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
47 49
import org.gvsig.data.vectorial.IFeatureCollection;
......
64 66
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
65 67
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
66 68
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
67
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
68 69
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
69
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
70 70
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy;
71 71

  
72
public class DXFStore extends MemoryStore{
72
public class DXFStore extends FeatureStore{
73 73
	public static String DATASTORE_NAME = "DXFStore";
74
	protected final static int ID_FIELD_ID = 0;
75 74

  
76
	protected final static int ID_FIELD_FSHAPE = 1;
75
	private IFeatureType featureType;
76
	private List featureTypes = new ArrayList();
77
	private File dxfFile;
78
	protected IMetadata metadata;
77 79

  
78
	protected final static int ID_FIELD_ENTITY = 2;
80
	private IProjection projection;
81
	private DXFStoreParameters dxfParameters;
79 82

  
80
	protected final static int ID_FIELD_LAYER = 3;
83
	private DXFResource dxf;
81 84

  
82
	protected final static int ID_FIELD_COLOR = 4;
85
	public void init(IDataStoreParameters parameters) throws InitializeException {
83 86

  
84
	protected final static int ID_FIELD_ELEVATION = 5;
87
		dxfParameters=(DXFStoreParameters)parameters;
88
		dxfFile=((DXFStoreParameters)parameters).getFile();
89
		projection=((DXFStoreParameters)parameters).getProjection();
85 90

  
86
	protected final static int ID_FIELD_THICKNESS = 6;
91
		DXFResource tmpResource = new DXFResource(dxfParameters);
87 92

  
88
	protected final static int ID_FIELD_TEXT = 7;
93
		ResourceManager resMan = ResourceManager.getResourceManager();
89 94

  
90
	protected final static int ID_FIELD_HEIGHTTEXT = 8;
95
		try {
96
			this.dxf = (DXFResource)resMan.addResource(tmpResource);
97
		} catch (DataException e1) {
98
			throw new InitializeException(this.getName(),e1);
99
		}
91 100

  
92
	protected final static int ID_FIELD_ROTATIONTEXT = 9;
93
	private DxfFile dxfFeatureFile;
94
	private AttrInTableLabelingStrategy labeling;
101
		super.init(parameters,this.dxf);
95 102

  
96
	private VectorialUniqueValueLegend defaultLegend;
97

  
98
	private IFeatureType featureType;
99
	private List featureTypes = new ArrayList();//<IFeatureType>
100
	private File dxfFile;
101
//	protected ArrayList featuresAux=new ArrayList();
102
	protected IMetadata metadata;
103

  
104
    private IProjection projection;
105
	private DXFStoreParameters dxfParameters;
106

  
107
	 public void init(IDataStoreParameters parameters) throws InitializeException {
108
	        super.init(parameters);
109
	        dxfParameters=(DXFStoreParameters)parameters;
110
	        dxfFile=((DXFStoreParameters)parameters).getFile();
111
			projection=((DXFStoreParameters)parameters).getProjection();
103
		try {
104
			this.featureType = this.dxf.getFeatureType();
105
		} catch (ReadException e) {
106
			throw new InitializeException(this.getName(),e);
112 107
		}
113 108

  
109
	}
110

  
114 111
	 static IFeatureType newFeatureType(){
115 112
			FeatureType fType= new FeatureType();
116 113

  
......
203 200

  
204 201
	 }
205 202

  
206
	 private void initializeFeatureType() {
207
			featureType= newFeatureType();
208
		}
209 203

  
210 204
	protected void doFinishEdition() throws WriteException, ReadException {
211 205
		IFeaturesWriter writer = getFeaturesWriter();
......
220 214
			writer.insertFeature(feature);
221 215
		}
222 216
        writer.postProcess();
217
        this.dxf.changed(this);
223 218

  
224 219
	}
225 220

  
......
234 229
		if (filter!=null){
235 230
			parser = new FeatureFilter(filter,type);
236 231
		}
237
		ArrayList originalFeatures=this.getFeatures();
232
//		ArrayList originalFeatures=this.dxf.getFeatures();
238 233
		int num=0;
239 234
		if (featureManager!=null){
240 235
			num=featureManager.getNum();
241 236
		}
242
		int originalSize=originalFeatures.size();
237
		int originalSize=this.dxf.getFeatureCount();
243 238
		Collection allFeatures=null;
244 239
		if (order!=null){
245 240
			Comparator comparator = new FeatureComparator(type,order);
......
249 244
		}
250 245
		for (int i = 0; i < originalSize+num; i++) {
251 246
			IFeature feature=null;
252
			if (i<this.getFeatureCount()){
253
				feature=this.getFeature(i);
247
			if (i<this.dxf.getFeatureCount()){
248
				feature=this.dxf.getFeature(i);
254 249
			}else{
255 250
				feature=featureManager.getFeature(i-originalSize,this);
256 251
			}
......
331 326
	}
332 327

  
333 328
	protected void doOpen() throws OpenException {
334
		float heightText = 10;
335 329

  
336

  
337
		DxfFile.EntityFactory featureMaker = new DxfFeatureMaker(projection);
338
		DxfFile.VarSettings headerManager = new DxfHeaderManager();
339
		dxfFeatureFile = new DxfFile(projection, dxfFile.getAbsolutePath(),
340
				featureMaker, headerManager);
341
		try {
342
			dxfFeatureFile.load();
343
		} catch (Exception e1) {
344
			throw new OpenException(getName(),e1);
345
		}
346
		IObjList.vector features = (IObjList.vector) ((DxfFeatureMaker) featureMaker)
347
				.getObjects();
348
		String acadVersion = (String) ((DxfHeaderManager) headerManager)
349
				.getAcadVersion();
350
		System.out.println("initialize(): acadVersion = " + acadVersion);
351
		if (!featureMaker.isDxf3DFile() && !headerManager.isWritedDxf3D()) { // y no
352
																				// est?n
353
																				// todos
354
																				// a
355
																				// 9999
356
			Feature[] features2D = new Feature[features.size()];
357
			for (int i = 0; i < features.size(); i++) {
358
				Feature fea = (Feature) features.get(i);
359
				if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) {
360
					Point point = (Point) fea.getGeometry();
361
					Point point2 = new Point();
362
					for (int j = 0; j < point.pointNr(); j++) {
363
						point2.add(point.get(j));
364
					}
365
					point2.setTextPoint(point.isTextPoint());
366
					fea.setGeometry(point2);
367
					features2D[i] = fea;
368
					// } else if (fea.getGeometry() instanceof InsPoint3D) {
369
					// InsPoint insPoint = (InsPoint)fea.getGeometry();
370
					// InsPoint insPoint2 = new InsPoint();
371
					// for (int j=0;j<insPoint.pointNr();j++) {
372
					// insPoint2.add(insPoint.get(j));
373
					// }
374
					// fea.setGeometry(insPoint2);
375
					// features2D[i] = fea;
376
				} else if (fea.getGeometry() instanceof LineString3D) {
377
					LineString lineString = (LineString) fea.getGeometry();
378
					LineString lineString2 = new LineString();
379
					for (int j = 0; j < lineString.pointNr(); j++) {
380
						lineString2.add(lineString.get(j));
381
					}
382
					fea.setGeometry(lineString2);
383
					features2D[i] = fea;
384
				} else if (fea.getGeometry() instanceof Polygon3D) {
385
					Polygon polygon = (Polygon) fea.getGeometry();
386
					Polygon polygon2 = new Polygon();
387
					for (int j = 0; j < polygon.pointNr(); j++) {
388
						polygon2.add(polygon.get(j));
389
					}
390
					fea.setGeometry(polygon2);
391
					features2D[i] = fea;
392
				}
393
			}
394
			features.clear();
395
			for (int i = 0; i < features2D.length; i++) {
396
				features.add(features2D[i]);
397
			}
398
		}
399
		// String acadVersion =
400
		// (String)((DxfHeaderManager)headerManager).getAcadVersion();
401
		// System.out.println("initialize(): acadVersion = " + acadVersion);
402

  
403
		int nAtt = featureMaker.getAttributes().size();
404

  
405
		// Campos de las MemoryLayer:
406

  
407
//		Object[] auxRow = new Object[10 + nAtt];
408
//		ArrayList arrayFields = new ArrayList();
409
//		arrayFields.add("ID");
410
//		arrayFields.add("FShape");
411
//		arrayFields.add("Entity");
412
//		arrayFields.add("Layer");
413
//		arrayFields.add("Color");
414
//		arrayFields.add("Elevation");
415
//		arrayFields.add("Thickness");
416
//		arrayFields.add("Text");
417
//		arrayFields.add("HeightText");
418
//		arrayFields.add("RotationText");
419
		initializeFeatureType();
420

  
421

  
422

  
423

  
424
		for (int i = 0; i < nAtt; i++) {
425
			String att[] = new String[2];
426
			att = (String[]) featureMaker.getAttributes().get(i);
427

  
428
			AttributeDescriptor descriptorAux = new AttributeDescriptor();
429
			try {
430
				descriptorAux.loading();
431
				descriptorAux.setType(IFeatureAttributeDescriptor.TYPE_STRING);
432
				descriptorAux.setName(att[0]);
433
				descriptorAux.setDefaultValue("");
434
				descriptorAux.stopLoading();
435
			} catch (IsNotAttributeSettingException e) {
436
				e.printStackTrace();
437
			}
438
			featureType.add(descriptorAux);
439

  
440

  
441
//			arrayFields.add(att[0]);
442
		}
443

  
444
		labeling = new AttrInTableLabelingStrategy();
445
		((AttrInTableLabelingStrategy) labeling).setTextFieldId(ID_FIELD_TEXT);
446
		((AttrInTableLabelingStrategy) labeling).setRotationFieldId(ID_FIELD_ROTATIONTEXT);
447
		((AttrInTableLabelingStrategy) labeling).setHeightFieldId(ID_FIELD_HEIGHTTEXT);
448
		((AttrInTableLabelingStrategy) labeling).setUnit(1); //MapContext.NAMES[1] (meters)
449

  
450
//		getTableModel().setColumnIdentifiers(arrayFields.toArray());
451

  
452
		for (int i = 0; i < features.size(); i++) {
453

  
454
			MemoryFeature feature;
455
			try {
456
				feature = new DXFFeature(featureType,true);
457
			} catch (ReadException e1) {
458
				throw new OpenException(this.getName(),e1);
459
			}
460
//			auxRow[ID_FIELD_HEIGHTTEXT] = new Double(0.0);
461
//			auxRow[ID_FIELD_ROTATIONTEXT] = new Double(0.0);
462
//			auxRow[ID_FIELD_TEXT] = null;
463
			try{
464
				feature.loading();
465
				Feature fea = (Feature) features.get(i);
466
				if (fea.getGeometry() instanceof Point
467
						&& !(fea.getGeometry() instanceof org.cresques.px.gml.Point3D)) {
468
					Point point = (Point) fea.getGeometry();
469
					Point2D pto = new Point2D.Double();
470
					pto = point.get(0);
471
					FShape nuevoShp;
472
					if (point.isTextPoint()) {
473
						feature.set(ID_FIELD_ID,i);
474
//						auxRow[ID_FIELD_ID] = new Integer(i);
475
//						feature.set(ID_FIELD_FSHAPE,"Point2D");
476
//						auxRow[ID_FIELD_FSHAPE] = new String("FPoint2D");
477
						feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
478
//						auxRow[ID_FIELD_ENTITY] = new String(fea.getProp("dxfEntity"));
479
						feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
480
//						auxRow[ID_FIELD_LAYER] = new String(fea.getProp("layer"));
481
						int auxInt = Integer.parseInt(fea.getProp("color"));
482
						feature.set(ID_FIELD_COLOR,auxInt);
483
//						auxRow[ID_FIELD_COLOR] = new Integer(auxInt);
484
						feature.set(ID_FIELD_TEXT,fea.getProp("text"));
485
//						auxRow[ID_FIELD_TEXT] = ValueFactory
486
//						.createValue(new String(fea.getProp("text")));
487
						heightText = Float.parseFloat(fea.getProp("textHeight"));
488
						feature.set(ID_FIELD_HEIGHTTEXT,heightText);
489
//						auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
490
//						.createValue(heightText);
491
						double auxR = Double.parseDouble(fea
492
								.getProp("textRotation"));
493
						feature.set(ID_FIELD_ROTATIONTEXT,auxR);
494
//						auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory
495
//						.createValue(auxR);
496
						double auxE = Double.parseDouble(fea.getProp("elevation"));
497
						feature.set(ID_FIELD_ELEVATION,auxE);
498
//						auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
499
						double auxT = Double.parseDouble(fea.getProp("thickness"));
500
						feature.set(ID_FIELD_THICKNESS,auxT);
501
//						auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
502
						// Attributes
503
						for (int j = 0; j < nAtt; j++) {
504
							String[] attributes = new String[2];
505
							attributes = (String[]) featureMaker.getAttributes()
506
							.get(j);
507
							feature.set(10+j,attributes[1]);
508
//							auxRow[10 + j] = ValueFactory.createValue(new String(
509
//							attributes[1]));
510
							if (!fea.getProp(attributes[0]).equals(attributes[1])) {
511
								feature.set(10+j,fea.getProp(attributes[0]));
512
//								auxRow[10 + j] = ValueFactory
513
//								.createValue(new String(fea
514
//								.getProp(attributes[0])));
515
							}
516
						}
517
						IGeometry geom=ShapeFactory.createPoint2D(new FPoint2D(pto.getX(), pto.getY()));
518
						feature.set(ID_FIELD_FSHAPE,geom);
519
//						feature.setDefaultGeometry(geom);
520
						addFeature(feature);
521

  
522
//						addShape(nuevoShp, auxRow);
523
					} else {
524
						feature.set(ID_FIELD_ID,i);
525
//						auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
526
//						feature.set(ID_FIELD_FSHAPE,"Point2D");
527
//						auxRow[ID_FIELD_FSHAPE] = ValueFactory
528
//						.createValue(new String("FPoint2D"));
529
						feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
530
//						auxRow[ID_FIELD_ENTITY] = ValueFactory
531
//						.createValue(new String(fea.getProp("dxfEntity")));
532
						feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
533
//						auxRow[ID_FIELD_LAYER] = ValueFactory
534
//						.createValue(new String(fea.getProp("layer")));
535
						int auxInt = Integer.parseInt(fea.getProp("color"));
536
						feature.set(ID_FIELD_COLOR,auxInt);
537
//						auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
538
						double auxE = Double.parseDouble(fea.getProp("elevation"));
539
						feature.set(ID_FIELD_ELEVATION,auxE);
540
//						auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
541
						double auxT = Double.parseDouble(fea.getProp("thickness"));
542
						feature.set(ID_FIELD_THICKNESS,auxT);
543
//						auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
544
						// Attributes
545
						for (int j = 0; j < nAtt; j++) {
546
							String[] attributes = new String[2];
547
							attributes = (String[]) featureMaker.getAttributes()
548
							.get(j);
549
							feature.set(10+j,attributes[1]);
550
//							auxRow[10 + j] = ValueFactory.createValue(new String(
551
//							attributes[1]));
552
							if (!fea.getProp(attributes[0]).equals(attributes[1])) {
553
								feature.set(10+j,fea.getProp(attributes[0]));
554
//								auxRow[10 + j] = ValueFactory
555
//								.createValue(new String(fea
556
//								.getProp(attributes[0])));
557
							}
558
						}
559
						IGeometry geom=ShapeFactory.createPoint2D(new FPoint2D(pto.getX(), pto.getY()));
560
						feature.set(ID_FIELD_FSHAPE,geom);
561
//						feature.setDefaultGeometry(geom);
562
						addFeature(feature);
563
//						addShape(nuevoShp, auxRow);
564
					}
565
				} else if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) {
566
					org.cresques.px.gml.Point3D point = (org.cresques.px.gml.Point3D) fea
567
					.getGeometry();
568
					Point3D pto = new Point3D();
569
					pto = point.getPoint3D(0);
570
					FShape nuevoShp;
571
					if (point.isTextPoint()) {
572
						feature.set(ID_FIELD_ID,i);
573
//						auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
574
						feature.set(ID_FIELD_FSHAPE,"Point3D");
575
//						auxRow[ID_FIELD_FSHAPE] = ValueFactory
576
//						.createValue(new String("FPoint3D"));
577
						feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
578
//						auxRow[ID_FIELD_ENTITY] = ValueFactory
579
//						.createValue(new String(fea.getProp("dxfEntity")));
580
						feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
581
//						auxRow[ID_FIELD_LAYER] = ValueFactory
582
//						.createValue(new String(fea.getProp("layer")));
583
						int auxInt = Integer.parseInt(fea.getProp("color"));
584
						feature.set(ID_FIELD_COLOR,auxInt);
585
//						auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
586
						feature.set(ID_FIELD_TEXT,fea.getProp("text"));
587
//						auxRow[ID_FIELD_TEXT] = ValueFactory
588
//						.createValue(new String(fea.getProp("text")));
589
						heightText = Float.parseFloat(fea.getProp("textHeight"));
590
						feature.set(ID_FIELD_HEIGHTTEXT,heightText);
591
//						auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
592
//						.createValue(heightText);
593
						double auxR = Double.parseDouble(fea
594
								.getProp("textRotation"));
595
						feature.set(ID_FIELD_ROTATIONTEXT,auxR);
596
//						auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory
597
//						.createValue(auxR);
598
						double auxE = Double.parseDouble(fea.getProp("elevation"));
599
						feature.set(ID_FIELD_ELEVATION,auxE);
600
//						auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
601
						double auxT = Double.parseDouble(fea.getProp("thickness"));
602
						feature.set(ID_FIELD_THICKNESS,auxT);
603
//						auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
604
						// Attributes
605
						for (int j = 0; j < nAtt; j++) {
606
							String[] attributes = new String[2];
607
							attributes = (String[]) featureMaker.getAttributes()
608
							.get(j);
609
							feature.set(10+j,attributes[1]);
610
//							auxRow[10 + j] = ValueFactory.createValue(new String(
611
//							attributes[1]));
612
							if (!fea.getProp(attributes[0]).equals(attributes[1])) {
613
								feature.set(10+j,fea.getProp(attributes[0]));
614
//								auxRow[10 + j] = ValueFactory
615
//								.createValue(new String(fea
616
//								.getProp(attributes[0])));
617
							}
618
						}
619
						IGeometry geom=ShapeFactory.createPoint3D(pto.getX(), pto.getY(), pto.getZ());
620
						feature.set(ID_FIELD_FSHAPE,geom);
621
//						feature.setDefaultGeometry(geom);
622
						addFeature(feature);
623
//						addShape(nuevoShp, auxRow);
624
					} else {
625
						feature.set(ID_FIELD_ID,i);
626
//						auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
627
						feature.set(ID_FIELD_FSHAPE,"Point3D");
628
//						auxRow[ID_FIELD_FSHAPE] = ValueFactory
629
//						.createValue(new String("FPoint3D"));
630
						feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
631
//						auxRow[ID_FIELD_ENTITY] = ValueFactory
632
//						.createValue(new String(fea.getProp("dxfEntity")));
633
						feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
634
//						auxRow[ID_FIELD_LAYER] = ValueFactory
635
//						.createValue(new String(fea.getProp("layer")));
636
						int auxInt = Integer.parseInt(fea.getProp("color"));
637
						feature.set(ID_FIELD_COLOR,auxInt);
638
//						auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
639

  
640
						double auxE = Double.parseDouble(fea.getProp("elevation"));
641
						feature.set(ID_FIELD_ELEVATION,auxE);
642
//						auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
643
						double auxT = Double.parseDouble(fea.getProp("thickness"));
644
						feature.set(ID_FIELD_THICKNESS,auxT);
645
//						auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
646
						// Attributes
647
						for (int j = 0; j < nAtt; j++) {
648
							String[] attributes = new String[2];
649
							attributes = (String[]) featureMaker.getAttributes()
650
							.get(j);
651
							feature.set(10+j,attributes[1]);
652
//							auxRow[10 + j] = ValueFactory.createValue(new String(
653
//							attributes[1]));
654
							if (!fea.getProp(attributes[0]).equals(attributes[1])) {
655
								feature.set(10+j,fea.getProp(attributes[0]));
656
//								auxRow[10 + j] = ValueFactory
657
//								.createValue(new String(fea
658
//								.getProp(attributes[0])));
659
							}
660
						}
661
						IGeometry geom=ShapeFactory.createPoint3D(pto.getX(), pto.getY(), pto.getZ());
662
						feature.set(ID_FIELD_FSHAPE,geom);
663
//						feature.setDefaultGeometry(geom);
664
						addFeature(feature);
665
//						addShape(nuevoShp, auxRow);
666
					}
667
				} else if (fea.getGeometry() instanceof LineString
668
						&& !(fea.getGeometry() instanceof LineString3D)) {
669
					GeneralPathX genPathX = new GeneralPathX();
670
					Point2D[] pts = new Point2D[fea.getGeometry().pointNr()];
671
					for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
672
						pts[j] = fea.getGeometry().get(j);
673
					}
674
					genPathX.moveTo(pts[0].getX(), pts[0].getY());
675
					for (int j = 1; j < pts.length; j++) {
676
						genPathX.lineTo(pts[j].getX(), pts[j].getY());
677
					}
678
					feature.set(ID_FIELD_ID,i);
679
//					auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
680
					feature.set(ID_FIELD_FSHAPE,"Polyline2D");
681
//					auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
682
//					"FPolyline2D"));
683
					feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
684
//					auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
685
//					fea.getProp("dxfEntity")));
686
					feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
687
//					auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
688
//					fea.getProp("layer")));
689
					int auxInt = Integer.parseInt(fea.getProp("color"));
690
					feature.set(ID_FIELD_COLOR,auxInt);
691
//					auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
692
					double auxE = Double.parseDouble(fea.getProp("elevation"));
693
					feature.set(ID_FIELD_ELEVATION,auxE);
694
//					auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
695
					double auxT = Double.parseDouble(fea.getProp("thickness"));
696
					feature.set(ID_FIELD_THICKNESS,auxT);
697
//					auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
698
					// Attributes
699
					for (int j = 0; j < nAtt; j++) {
700
						String[] attributes = new String[2];
701
						attributes = (String[]) featureMaker.getAttributes().get(j);
702
						feature.set(10+j,attributes[1]);
703
//						auxRow[10 + j] = ValueFactory.createValue(new String(
704
//						attributes[1]));
705
						if (!fea.getProp(attributes[0]).equals(attributes[1])) {
706
							feature.set(10+j,fea.getProp(attributes[0]));
707
//							auxRow[10 + j] = ValueFactory.createValue(new String(
708
//							fea.getProp(attributes[0])));
709
						}
710
					}
711
					IGeometry geom=ShapeFactory.createPolyline2D(genPathX);
712
					feature.set(ID_FIELD_FSHAPE,geom);
713
//					feature.setDefaultGeometry(geom);
714
					addFeature(feature);
715
//					addShape(nuevoShp, auxRow);
716
				} else if (fea.getGeometry() instanceof LineString3D) {
717
					GeneralPathX genPathX = new GeneralPathX();
718
					Point3D[] pts = new Point3D[fea.getGeometry().pointNr()];
719
					for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
720
						pts[j] = ((LineString3D) fea.getGeometry()).getPoint3D(j);
721
					}
722
					genPathX.moveTo(pts[0].getX(), pts[0].getY());
723
					for (int j = 1; j < pts.length; j++) {
724
						genPathX.lineTo(pts[j].getX(), pts[j].getY());
725
					}
726
					double[] elevations = new double[pts.length];
727
					for (int j = 0; j < pts.length; j++) {
728
						elevations[j] = pts[j].getZ();
729
					}
730
					feature.set(ID_FIELD_ID,i);
731
//					auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
732
					feature.set(ID_FIELD_FSHAPE,"Polyline3D");
733
//					auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
734
//					"FPolyline3D"));
735
					feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
736
//					auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
737
//					fea.getProp("dxfEntity")));
738
					feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
739
//					auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
740
//					fea.getProp("layer")));
741
					int auxInt = Integer.parseInt(fea.getProp("color"));
742
					feature.set(ID_FIELD_COLOR,auxInt);
743
//					auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
744
					if (fea.getProp("elevation") != null) {
745
						double auxE = Double.parseDouble(fea.getProp("elevation"));
746
						feature.set(ID_FIELD_ELEVATION,auxE);
747
//						auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
748
					}
749
					double auxT = Double.parseDouble(fea.getProp("thickness"));
750
					feature.set(ID_FIELD_THICKNESS,auxT);
751
//					auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
752
					// Attributes
753
					for (int j = 0; j < nAtt; j++) {
754
						String[] attributes = new String[2];
755
						attributes = (String[]) featureMaker.getAttributes().get(j);
756
						feature.set(10+j,attributes[1]);
757
//						auxRow[10 + j] = ValueFactory.createValue(new String(
758
//						attributes[1]));
759
						if (!fea.getProp(attributes[0]).equals(attributes[1])) {
760
							feature.set(10+j,fea.getProp(attributes[0]));
761
//							auxRow[10 + j] = ValueFactory.createValue(new String(
762
//							fea.getProp(attributes[0])));
763
						}
764
					}
765
					IGeometry geom=ShapeFactory.createPolyline3D(genPathX,elevations);
766
					feature.set(ID_FIELD_FSHAPE,geom);
767
//					feature.setDefaultGeometry(geom);
768
					addFeature(feature);
769
//					addShape(nuevoShp, auxRow);
770
				} else if (fea.getGeometry() instanceof Polygon
771
						&& !(fea.getGeometry() instanceof Polygon3D)) {
772
					GeneralPathX genPathX = new GeneralPathX();
773
					// 050112: A?ado una posici?n m?s para el punto que cierra y
774
					// creo el objeto firstPt.
775
					Point2D firstPt = new Point2D.Double();
776
					firstPt = fea.getGeometry().get(0);
777
					Point2D[] pts = new Point2D[fea.getGeometry().pointNr() + 1];
778
					for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
779
						pts[j] = fea.getGeometry().get(j);
780
					}
781
					// 050112: A?ado el primer punto al final para cerrar los
782
					// pol?gonos.
783
					pts[fea.getGeometry().pointNr()] = firstPt;
784
					genPathX.moveTo(pts[0].getX(), pts[0].getY());
785
					for (int j = 1; j < pts.length; j++) {
786
						genPathX.lineTo(pts[j].getX(), pts[j].getY());
787
					}
788
					feature.set(ID_FIELD_ID,i);
789
//					auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
790
					feature.set(ID_FIELD_FSHAPE,"Polygon2D");
791
//					auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
792
//					"FPolygon2D"));
793
					feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
794
//					auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
795
//					fea.getProp("dxfEntity")));
796
					feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
797
//					auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
798
//					fea.getProp("layer")));
799
					int auxInt = Integer.parseInt(fea.getProp("color"));
800
					feature.set(ID_FIELD_COLOR,auxInt);
801
//					auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
802
					double auxE = Double.parseDouble(fea.getProp("elevation"));
803
					feature.set(ID_FIELD_ELEVATION,auxE);
804
//					auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
805
					double auxT = Double.parseDouble(fea.getProp("thickness"));
806
					feature.set(ID_FIELD_THICKNESS,auxT);
807
//					auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
808
					// Attributes
809
					for (int j = 0; j < nAtt; j++) {
810
						String[] attributes = new String[2];
811
						attributes = (String[]) featureMaker.getAttributes().get(j);
812
						feature.set(10+j,attributes[1]);
813
//						auxRow[10 + j] = ValueFactory.createValue(new String(
814
//						attributes[1]));
815
						if (!fea.getProp(attributes[0]).equals(attributes[1])) {
816
							feature.set(10+j,fea.getProp(attributes[0]));
817
//							auxRow[10 + j] = ValueFactory.createValue(new String(
818
//							fea.getProp(attributes[0])));
819
						}
820
					}
821
					IGeometry geom=ShapeFactory.createPolygon2D(genPathX);
822
					feature.set(ID_FIELD_FSHAPE,geom);
823
//					feature.setDefaultGeometry(geom);
824
					addFeature(feature);
825
//					addShape(nuevoShp, auxRow);
826
				} else if (fea.getGeometry() instanceof Polygon3D) {
827
					GeneralPathX genPathX = new GeneralPathX();
828
					// 050112: A?ado una posici?n m?s para el punto que cierra y
829
					// creo el objeto firstPt.
830
					Point3D firstPt = new Point3D();
831
					firstPt = ((Polygon3D) fea.getGeometry())
832
					.getPoint3D(0);
833
					Point3D[] pts = new Point3D[fea.getGeometry().pointNr() + 1];
834
					for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
835
						pts[j] = ((Polygon3D) fea.getGeometry())
836
						.getPoint3D(j);
837
					}
838
					// 050112: A?ado el primer punto al final para cerrar los
839
					// pol?gonos.
840
					pts[fea.getGeometry().pointNr()] = firstPt;
841
					genPathX.moveTo(pts[0].getX(), pts[0].getY());
842
					for (int j = 1; j < pts.length; j++) {
843
						genPathX.lineTo(pts[j].getX(), pts[j].getY());
844
					}
845
					double[] elevations = new double[pts.length];
846
					for (int j = 0; j < pts.length; j++) {
847
						elevations[j] = pts[j].getZ();
848
					}
849
					feature.set(ID_FIELD_ID,i);
850
//					auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
851
					feature.set(ID_FIELD_FSHAPE,"Polygon3D");
852
//					auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
853
//					"FPolygon3D"));
854
					feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
855
//					auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
856
//					fea.getProp("dxfEntity")));
857
					feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
858
//					auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
859
//					fea.getProp("layer")));
860
					int auxInt = Integer.parseInt(fea.getProp("color"));
861
					feature.set(ID_FIELD_COLOR,auxInt);
862
//					auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
863
					if (fea.getProp("elevation") != null) {
864
						double auxE = Double.parseDouble(fea.getProp("elevation"));
865
						feature.set(ID_FIELD_ELEVATION,auxE);
866
//						auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
867
					}
868
					double auxT = Double.parseDouble(fea.getProp("thickness"));
869
					feature.set(ID_FIELD_THICKNESS,auxT);
870
//					auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
871
					// Attributes
872
					for (int j = 0; j < nAtt; j++) {
873
						String[] attributes = new String[2];
874
						attributes = (String[]) featureMaker.getAttributes().get(j);
875
						feature.set(10+j,attributes[1]);
876
//						auxRow[10 + j] = ValueFactory.createValue(new String(
877
//						attributes[1]));
878
						if (!fea.getProp(attributes[0]).equals(attributes[1])) {
879
							feature.set(10+j,fea.getProp(attributes[0]));
880
//							auxRow[10 + j] = ValueFactory.createValue(new String(
881
//							fea.getProp(attributes[0])));
882
						}
883
					}
884
					IGeometry geom=ShapeFactory.createPolygon3D(genPathX,elevations);
885
					feature.set(ID_FIELD_FSHAPE,geom);
886
//					feature.setDefaultGeometry(geom);
887
					addFeature(feature);
888
//					addShape(nuevoShp, auxRow);
889
				} else {
890
					// System.out.println("Detectado feature desconocido");
891
				}
892
				feature.stopLoading();
893
			}catch (IsNotFeatureSettingException e) {
894
				e.printStackTrace();
895
			}
896
		}
897

  
898
		defaultLegend = LegendFactory
899
				.createVectorialUniqueValueLegend(FShape.MULTI);
900
		defaultLegend.setClassifyingFieldNames(new String[] {"Color"});
901
		defaultLegend.setClassifyingFieldTypes(new int[]{Types.INTEGER,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.INTEGER,Types.DOUBLE,Types.DOUBLE});
902

  
903
		Logger.getAnonymousLogger().info("DXFStore: should check if this is a text symbol");
904
		ISymbol myDefaultSymbol = SymbologyFactory.
905
			createDefaultSymbolByShapeType(FShape.MULTI, Color.BLACK);
906

  
907
		defaultLegend.setDefaultSymbol(myDefaultSymbol);
908

  
909
//		ISymbol theSymbol = null;
910
//
911
//			for (long j = 0; j < featuresAux.size(); j++) {
912
//				IFeature feat=(IFeature)featuresAux.get((int)j);
913
//				int clave=feat.getInt(ID_FIELD_COLOR);
914
////				clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR);
915
//				if (defaultLegend.getSymbolByValue(clave) == null) {
916
//					theSymbol = SymbologyFactory.
917
//						createDefaultSymbolByShapeType(
918
//								FShape.MULTI,
919
//								AcadColor.getColor(clave.getValue()));
920
//					theSymbol.setDescription(clave.toString());
921
//					// Asigna los colores de Autocad a los
922
//					// bordes
923
//					// de los pol?gonos.
924
//					if (theSymbol instanceof IFillSymbol) {
925
//						((IFillSymbol) theSymbol).getOutline().setLineColor(AcadColor.getColor(clave
926
//								.getValue()));
927
//
928
//					}
929
//					defaultLegend.addSymbol(clave, theSymbol);
930
//				}
931
//			} // for
932

  
933

  
934 330
	}
935 331

  
936 332
	protected void doClose() throws CloseException {
937
		super.doClose();
333
		this.dxf.close();
938 334
	}
939 335

  
940 336
	protected void doDispose() throws CloseException {
941
		close();
942 337
		super.doDispose();
338
		ResourceManager resMan = ResourceManager.getResourceManager();
339

  
340
    	try {
341
			resMan.remove(this.dxf);
342
		} catch (DataException e1) {
343
			throw new CloseException(this.getName(),e1);
344
		} catch (KeyException e) {
345
			// TODO Auto-generated catch block
346
			throw new CloseException(this.getName(),e);
347
		}
348

  
349
		this.dxf = null;
350
		this.featureType=null;
351
		this.metadata=null;
943 352
	}
944 353

  
945 354
	public boolean isEditable() {
......
950 359
		if (metadata==null){
951 360
			IMetadataManager manager=MetadataManager.getManager();
952 361
			metadata=manager.create(DATASTORE_NAME);
953
			IExtent extent=getFullExtent();
362
			IExtent extent=this.dxf.getFullExtent();
954 363
			metadata.set("extent",extent);
955 364
			String srs=getSRS();
956 365
			metadata.set("srs",srs);

Also available in: Unified diff