Revision 74

View differences:

trunk/org.gvsig.dwg/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/FMapUtil.java
13 13
import org.gvsig.fmap.geom.GeometryLocator;
14 14
import org.gvsig.fmap.geom.GeometryManager;
15 15
import org.gvsig.fmap.geom.aggregate.MultiCurve;
16
import org.gvsig.fmap.geom.aggregate.MultiLine;
16 17
import org.gvsig.fmap.geom.exception.CreateGeometryException;
17
import org.gvsig.fmap.geom.primitive.Curve;
18
import org.gvsig.fmap.geom.primitive.Line;
18 19
import org.gvsig.fmap.geom.primitive.Point;
20
import org.gvsig.fmap.geom.primitive.Polygon;
19 21
import org.gvsig.fmap.geom.primitive.Surface;
20 22

  
21

  
22 23
/**
23 24
 * @author alzabord
24 25
 *
25 26
 */
26 27
public class FMapUtil {
27 28

  
28
//	/**
29
//	 * Method that changes a Point3D array to a FPolyline3D. Is useful to
30
//	 * convert a polyline given by it points to a FPolyline3D, a polyline 3D in
31
//	 * the FMap model object
32
//	 *
33
//	 * @param pts
34
//	 *            Array of Point3D that defines the polyline 3D that will be
35
//	 *            converted in a FPolyline3D
36
//	 * @return FPolyline3D This FPolyline3D is build using the array of Point3D
37
//	 *         that is the argument of the method
38
//	 */
39
//	public static FPolyline3D points3DToFPolyline3D(List pts) {
40
//		GeneralPathX genPathX = getGeneralPathX(pts);
41
//		double[] elevations = new double[pts.size()];
42
//		for (int i = 0; i < pts.size(); i++) {
43
//			elevations[i] = ((double[])pts.get(i))[2];
44
//		}
45
//		return new FPolyline3D(genPathX, elevations);
46
//	}
29
    private static final GeometryManager gManager = GeometryLocator
30
            .getGeometryManager();
47 31

  
48
	private static GeometryManager gManager = GeometryLocator
49
			.getGeometryManager();
32
    public static MultiCurve ptsToMultiLine(List<double[]> pts, int subType)
33
            throws CreateGeometryException {
50 34

  
35
        if (pts.size() < 2) {
36
            throw new IllegalArgumentException();
37
        }
51 38

  
39
        Point point, prevPoint;
40
        Line line;
52 41

  
53
//	/**
54
//	 * Method that changes a Point2D array to a FPolyline2D. Is useful to
55
//	 * convert a polyline given by it points to a FPolyline2D, a polyline in the
56
//	 * FMap model object
57
//	 *
58
//	 * @param pts
59
//	 *            Array of Point2D that defines the polyline that will be
60
//	 *            converted in a FPolyline2D
61
//	 * @return FPolyline2D This FPolyline2D is build using the array of Point2D
62
//	 *         that is the argument of the method
63
//	 */
64
//	public static FPolyline2D points2DToFPolyline2D(List pts) {
65
//		GeneralPathX genPathX = getGeneralPathX(pts);
66
//		return new FPolyline2D(genPathX);
67
//	}
42
        MultiLine multi = gManager.createMultiLine(subType);
43
        prevPoint = FMapUtil.createPoint(subType, pts.get(0));
44
        for (int i = 1; i < pts.size(); i++) {
45
            point = FMapUtil.createPoint(subType, pts.get(i));
46
            line = gManager.createLine(subType);
47
            line.addVertex(prevPoint);
48
            line.addVertex(point);
49
            multi.addPrimitive(line);
50
            prevPoint = FMapUtil.createPoint(subType, pts.get(i));
51
        }
52
        return multi;
68 53

  
69
	public static MultiCurve ptsToMultiCurve(List pts, int subType)
70
			throws CreateGeometryException {
54
    }
71 55

  
72
		if (pts.size() < 2) {
73
			throw new IllegalArgumentException();
74
		}
56
    public static Surface ptsToPolygon(List<double[]> pts, int subType)
57
            throws CreateGeometryException {
75 58

  
76
		Point point, prevPoint;
77
		Curve curve;
59
        if (pts.size() < 3) {
60
            throw new IllegalArgumentException();
61
        }
78 62

  
79
		MultiCurve multi = (MultiCurve) gManager.create(
80
				Geometry.TYPES.MULTICURVE,
81
				subType);
82
		prevPoint = FMapUtil.createPoint(subType, pts.get(0));
83
		for (int i = 1; i < pts.size(); i++) {
84
			point = FMapUtil.createPoint(subType, pts.get(i));
85
			curve = (Curve) gManager.create(Geometry.TYPES.CURVE, subType);
86
			curve.setPoints(prevPoint, point);
87
			multi.addCurve(curve);
88
			prevPoint = FMapUtil.createPoint(subType, pts.get(i));
89
		}
90
		return multi;
63
        Polygon polygon = gManager.createPolygon(subType);
91 64

  
92
	}
65
        Iterator<double[]> iter = pts.iterator();
66
        while (iter.hasNext()) {
67
            Point vertex = createPoint(subType, iter.next());
68
            polygon.addVertex(vertex);
69
        }
70
        return polygon;
71
    }
93 72

  
94
	public static Surface ptsToPolygon(List pts, int subType)
95
			throws CreateGeometryException {
73
    public static Point createPoint(int subType, double[] point) throws CreateGeometryException {
74
        Point result = gManager.createPoint(point[0], point[1], subType);
75
        if (subType == Geometry.SUBTYPES.GEOM3D) {
76
            result.setCoordinateAt(Geometry.DIMENSIONS.Z, point[2]);
77
        }
78
        return result;
79
    }
96 80

  
81
    public static Point createPoint(int subType, Point2D point) throws CreateGeometryException {
82
        Point result = gManager.createPoint(point.getX(), point.getY(), subType);
83
        return result;
84
    }
97 85

  
98
		if (pts.size() < 3) {
99
			throw new IllegalArgumentException();
100
		}
86
    public static Point createPoint(int subType, IDwgVertex dwgvertex) throws CreateGeometryException {
87
        double[] point = dwgvertex.getPoint();
88
        Point result = gManager.createPoint(point[0], point[1], subType);
89
        if (subType == Geometry.SUBTYPES.GEOM3D) {
90
            result.setCoordinateAt(Geometry.DIMENSIONS.Z, point[2]);
91
        }
92
        return result;
93
    }
101 94

  
102
		Point cur;
103
		Surface surface = (Surface) gManager.create(Geometry.TYPES.SURFACE,
104
				subType);
105

  
106
		Iterator iter = pts.iterator();
107
		while (iter.hasNext()) {
108
			cur = createPoint(subType, iter.next());
109
			surface.addVertex(cur);
110
		}
111
		return surface;
112
	}
113

  
114
	public static Point createPoint(int subType,
115
			Object point)
116
			throws CreateGeometryException {
117
		Point result = (Point) gManager.create(Geometry.TYPES.POINT, subType);
118
		if (point instanceof double[]) {
119
			result.setCoordinates((double[]) point);
120
		} else if (point instanceof Point2D) {
121
			Point2D p = (Point2D) point;
122
			result.setX(p.getX());
123
			result.setY(p.getY());
124

  
125
		} else if (point instanceof IDwgVertex) {
126
			result.setCoordinates(((IDwgVertex) point).getPoint());
127
		} else {
128
			throw new IllegalArgumentException();
129
		}
130
		return result;
131
	}
132
	
133
	/**
134
	 * Devuelve la distancia desde angle1 a angle2. Angulo en radianes de
135
	 * diferencia entre angle1 y angle2 en sentido antihorario
136
	 *
137
	 * @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna
138
	 * 		  vuelta a la circunferencia
139
	 * @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna
140
	 * 		  vuelta a la circunferencia
141
	 *
142
	 * @return distancia entre los �ngulos
143
	 */
144
	public static double angleDistance(double angle1, double angle2) {
145
		if (angle1 < angle2) {
146
			return angle2 - angle1;
147
		} else {
148
			return ((Math.PI * 2) - angle1) + angle2;
149
		}
150
	}
95
    /**
96
     * Devuelve la distancia desde angle1 a angle2. Angulo en radianes de
97
     * diferencia entre angle1 y angle2 en sentido antihorario
98
     *
99
     * @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna
100
     * vuelta a la circunferencia
101
     * @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna
102
     * vuelta a la circunferencia
103
     *
104
     * @return distancia entre los �ngulos
105
     */
106
    public static double angleDistance(double angle1, double angle2) {
107
        if (angle1 < angle2) {
108
            return angle2 - angle1;
109
        } else {
110
            return ((Math.PI * 2) - angle1) + angle2;
111
        }
112
    }
151 113
}
trunk/org.gvsig.dwg/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/objects/DwgPolyline2D.java
492 492
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry(boolean)
493 493
	 */
494 494
	public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException {
495
		return FMapUtil.ptsToMultiCurve(getPts(), getGeometrySubType(is3DFile));
495
		return FMapUtil.ptsToMultiLine(getPts(), getGeometrySubType(is3DFile));
496 496
	}
497 497
	/* (non-Javadoc)
498 498
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
trunk/org.gvsig.dwg/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/objects/DwgPolyline3D.java
391 391
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry(boolean)
392 392
	 */
393 393
	public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException {
394
		return FMapUtil.ptsToMultiCurve(getPts(), getGeometrySubType(is3DFile));
394
		return FMapUtil.ptsToMultiLine(getPts(), getGeometrySubType(is3DFile));
395 395
	}
396 396
//	public Geometry toFMapGeometry_old(boolean is3DFile) {
397 397
//		FPolyline2D pline = null;
trunk/org.gvsig.dwg/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/objects/DwgLine.java
49 49
import org.gvsig.fmap.geom.GeometryManager;
50 50
import org.gvsig.fmap.geom.exception.CreateGeometryException;
51 51
import org.gvsig.fmap.geom.primitive.Curve;
52
import org.gvsig.fmap.geom.primitive.Line;
52 53
import org.gvsig.fmap.geom.primitive.Point;
53 54

  
54 55

  
......
201 202
	}
202 203
	public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException {
203 204
		GeometryManager gMan = GeometryLocator.getGeometryManager();
205
                Line line;
206
                if( is3DFile ) {
207
                    line = gMan.createLine(Geometry.SUBTYPES.GEOM3D);
208
                    line.addVertex(p1[0],p1[1],p1[2]);
209
                    line.addVertex(p2[0],p2[1],p2[2]);
210
                } else {
211
                    line = gMan.createLine(Geometry.SUBTYPES.GEOM2D);
212
                    line.addVertex(p1[0],p1[1]);
213
                    line.addVertex(p2[0],p2[1]);
214
                }
215
                return line;
204 216

  
205
		double[] p1 = getP1();
206
		double[] p2 = getP2();
207

  
208
		Point point1 = (Point) gMan.create(Geometry.TYPES.POINT,
209
				getGeometrySubType(is3DFile));
210
		point1.setCoordinates(p1);
211

  
212
		Point point2 = (Point) gMan.create(Geometry.TYPES.POINT,
213
				getGeometrySubType(is3DFile));
214
		point2.setCoordinates(p2);
215

  
216
		Curve line = (Curve) gMan.create(getGeometryType(),
217
				getGeometrySubType(is3DFile));
218
		line.setPoints(point1, point2);
219
		return line;
220

  
221 217
	}
222 218
	public String toFMapString(boolean is3DFile) {
223 219
		if(is3DFile){
trunk/org.gvsig.dwg/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/objects/DwgLwPolyline.java
311 311
	}
312 312

  
313 313
	public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException {
314
		return FMapUtil.ptsToMultiCurve(getVertices(),
314
		return FMapUtil.ptsToMultiLine(getVertices(),
315 315
				getGeometrySubType(is3DFile));
316 316
	}
317 317

  
318 318

  
trunk/org.gvsig.dwg/org.gvsig.dwg.provider/src/main/java/org/gvsig/dwg/fmap/dal/store/dwg/DWGStoreProvider.java
58 58
import org.slf4j.LoggerFactory;
59 59

  
60 60
public class DWGStoreProvider extends AbstractMemoryStoreProvider implements
61
		ResourceConsumer {
62
	private static final Logger logger = LoggerFactory.getLogger(DWGStoreProvider.class);
61
        ResourceConsumer {
63 62

  
64
	public static final String NAME = "DWG";
65
	public static final String DESCRIPTION = "DWG file";
66
	public static final String METADATA_DEFINITION_NAME = NAME;
63
    private static final Logger logger = LoggerFactory.getLogger(DWGStoreProvider.class);
67 64

  
68
	public static final String NAME_FIELD_ID = "ID";
69
	public static final String NAME_FIELD_GEOMETRY = "Geometry";
70
	public static final String NAME_FIELD_ENTITY = "Entity";
71
	public static final String NAME_FIELD_LAYER = "Layer";
72
	public static final String NAME_FIELD_COLOR = "Color";
73
	public static final String NAME_FIELD_ELEVATION = "Elevation";
74
	public static final String NAME_FIELD_THICKNESS = "Thickness";
75
	public static final String NAME_FIELD_TEXT = "Text";
76
	public static final String NAME_FIELD_HEIGHTTEXT = "HeightText";
77
	public static final String NAME_FIELD_ROTATIONTEXT = "Rotation";
65
    public static final String NAME = "DWG";
66
    public static final String DESCRIPTION = "DWG file";
67
    public static final String METADATA_DEFINITION_NAME = NAME;
78 68

  
79
	private int ID_FIELD_ID = 0;
80
	private int ID_FIELD_GEOMETRY = 1;
81
	private int ID_FIELD_ENTITY = 2;
82
	private int ID_FIELD_LAYER = 3;
83
	private int ID_FIELD_COLOR = 4;
84
	private int ID_FIELD_ELEVATION = 5;
85
	private int ID_FIELD_THICKNESS = 6;
86
	private int ID_FIELD_TEXT = 7;
87
	private int ID_FIELD_HEIGHTTEXT = 8;
88
	private int ID_FIELD_ROTATIONTEXT = 9;
69
    public static final String NAME_FIELD_ID = "ID";
70
    public static final String NAME_FIELD_GEOMETRY = "Geometry";
71
    public static final String NAME_FIELD_ENTITY = "Entity";
72
    public static final String NAME_FIELD_LAYER = "Layer";
73
    public static final String NAME_FIELD_COLOR = "Color";
74
    public static final String NAME_FIELD_ELEVATION = "Elevation";
75
    public static final String NAME_FIELD_THICKNESS = "Thickness";
76
    public static final String NAME_FIELD_TEXT = "Text";
77
    public static final String NAME_FIELD_HEIGHTTEXT = "HeightText";
78
    public static final String NAME_FIELD_ROTATIONTEXT = "Rotation";
89 79

  
90
	private IProjection projection;
91
	private ResourceProvider resource;
92
	private LegendBuilder legendBuilder;
80
    private int ID_FIELD_ID = 0;
81
    private int ID_FIELD_GEOMETRY = 1;
82
    private int ID_FIELD_ENTITY = 2;
83
    private int ID_FIELD_LAYER = 3;
84
    private int ID_FIELD_COLOR = 4;
85
    private int ID_FIELD_ELEVATION = 5;
86
    private int ID_FIELD_THICKNESS = 6;
87
    private int ID_FIELD_TEXT = 7;
88
    private int ID_FIELD_HEIGHTTEXT = 8;
89
    private int ID_FIELD_ROTATIONTEXT = 9;
93 90

  
94
	private long counterNewsOIDs = 0;
95
	protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
91
    private IProjection projection;
92
    private ResourceProvider resource;
93
    private LegendBuilder legendBuilder;
96 94

  
97
	public DWGStoreProvider(DWGStoreParameters parameters,
98
			DataStoreProviderServices storeServices) throws InitializeException {
99
		super(parameters, storeServices, FileHelper
100
				.newMetadataContainer(METADATA_DEFINITION_NAME));
95
    private long counterNewsOIDs = 0;
96
    protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
101 97

  
102
		counterNewsOIDs = 0;
103
		//		projection = CRSFactory.getCRS(getParameters().getSRSID());
98
    public DWGStoreProvider(DWGStoreParameters parameters,
99
            DataStoreProviderServices storeServices) throws InitializeException {
100
        super(parameters, storeServices, FileHelper
101
                .newMetadataContainer(METADATA_DEFINITION_NAME));
104 102

  
105
		File file = getDWGParameters().getFile();
106
		resource = this.createResource(
107
				FileResource.NAME,
108
				new Object[] { file.getAbsolutePath() }
109
			);
103
        counterNewsOIDs = 0;
104
        //		projection = CRSFactory.getCRS(getParameters().getSRSID());
110 105

  
111
		resource.addConsumer(this);
106
        File file = getDWGParameters().getFile();
107
        resource = this.createResource(
108
                FileResource.NAME,
109
                new Object[]{file.getAbsolutePath()}
110
        );
112 111

  
113
		this.projection = this.getDWGParameters().getCRS();
112
        resource.addConsumer(this);
114 113

  
114
        this.projection = this.getDWGParameters().getCRS();
115 115

  
116
		try {
117
			legendBuilder = (LegendBuilder) this.invokeDynMethod(
118
					LegendBuilder.DYNMETHOD_BUILDER_NAME, null);
119
		} catch (DynMethodException e) {
120
			legendBuilder = null;
121
		} catch (Exception e) {
122
			throw new InitializeException(e);
123
		}
116
        try {
117
            legendBuilder = (LegendBuilder) this.invokeDynMethod(
118
                    LegendBuilder.DYNMETHOD_BUILDER_NAME, null);
119
        } catch (DynMethodException e) {
120
            legendBuilder = null;
121
        } catch (Exception e) {
122
            throw new InitializeException(e);
123
        }
124 124

  
125
		this.initializeFeatureTypes();
126
	}
125
        this.initializeFeatureTypes();
126
    }
127 127

  
128
	private DWGStoreParameters getDWGParameters() {
129
		return (DWGStoreParameters) this.getParameters();
130
	}
128
    private DWGStoreParameters getDWGParameters() {
129
        return (DWGStoreParameters) this.getParameters();
130
    }
131 131

  
132
    public String getProviderName() {
133
        return NAME;
134
    }
132 135

  
133
	public String getProviderName() {
134
		return NAME;
135
	}
136
    public boolean allowWrite() {
137
        return false;
138
    }
136 139

  
137
	public boolean allowWrite() {
138
		return false;
139
	}
140
    public Object getLegend() throws OpenException {
141
        this.open();
142
        if (legendBuilder == null) {
143
            return null;
144
        }
145
        return legendBuilder.getLegend();
146
    }
140 147

  
141
	public Object getLegend() throws OpenException {
142
		this.open();
143
		if (legendBuilder == null) {
144
			return null;
145
		}
146
		return legendBuilder.getLegend();
147
	}
148
    public Object getLabeling() throws OpenException {
149
        this.open();
150
        if (legendBuilder == null) {
151
            return null;
152
        }
153
        return legendBuilder.getLabeling();
154
    }
148 155

  
149
	public Object getLabeling() throws OpenException {
150
		this.open();
151
		if (legendBuilder == null) {
152
			return null;
153
		}
154
		return legendBuilder.getLabeling();
155
	}
156
    private class DWGData {
156 157

  
157
	private class DWGData {
158
		public ArrayList data = null;
159
		public FeatureType defaultFType = null;
160
		public List fTypes = null;
161
		public Envelope envelope = null;
162
		public IProjection projection;
163
		public LegendBuilder legendBuilder = null;
164
		public Envelope getEnvelopeCopy() throws CreateEnvelopeException {
165
			if (envelope == null) {
166
				return null;
167
			}
168
			Envelope newEnvelope;
169
			if (envelope.getDimension() == 2) {
170
				newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
171
			} else {
172
				newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
158
        public ArrayList data = null;
159
        public FeatureType defaultFType = null;
160
        public List fTypes = null;
161
        public Envelope envelope = null;
162
        public IProjection projection;
163
        public LegendBuilder legendBuilder = null;
173 164

  
174
			}
175
			newEnvelope.setLowerCorner(envelope.getLowerCorner());
176
			newEnvelope.setUpperCorner(envelope.getUpperCorner());
177
			return newEnvelope;
178
		}
179
	}
165
        public Envelope getEnvelopeCopy() throws CreateEnvelopeException {
166
            if (envelope == null) {
167
                return null;
168
            }
169
            Envelope newEnvelope;
170
            if (envelope.getDimension() == 2) {
171
                newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
172
            } else {
173
                newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
180 174

  
181
	private AbstractMemoryStoreProvider getStoreProvider() {
182
		return this;
183
	}
175
            }
176
            newEnvelope.setLowerCorner(envelope.getLowerCorner());
177
            newEnvelope.setUpperCorner(envelope.getUpperCorner());
178
            return newEnvelope;
179
        }
180
    }
184 181

  
185
	public void open() throws OpenException {
186
		if (this.data != null) {
187
			return;
188
		}
182
    private AbstractMemoryStoreProvider getStoreProvider() {
183
        return this;
184
    }
185

  
186
    public void open() throws OpenException {
187
        if (this.data != null) {
188
            return;
189
        }
189 190
		// try {
190
		// this.resource.begin();
191
		// } catch (ResourceExecuteException e2) {
192
		// try {
193
		// throw new OpenException(resource.getName(), e2);
194
		// } catch (AccessResourceException e1) {
195
		// throw new OpenException(this.getName(), e2);
196
		// }
197
		//
198
		// }
199
		try {
200
			getResource().execute(new ResourceAction() {
201
				public Object run() throws Exception {
202
					ResourceProvider resource = getResource();
203
					DWGData dwgData = null;
204
					FeatureStoreProviderServices store = getStoreServices();
205
					if (resource.getData() != null) {
206
						dwgData =
207
								(DWGData) ((Map) resource.getData()).get(projection.getAbrev());
191
        // this.resource.begin();
192
        // } catch (ResourceExecuteException e2) {
193
        // try {
194
        // throw new OpenException(resource.getName(), e2);
195
        // } catch (AccessResourceException e1) {
196
        // throw new OpenException(this.getName(), e2);
197
        // }
198
        //
199
        // }
200
        try {
201
            getResource().execute(new ResourceAction() {
202
                public Object run() throws Exception {
203
                    ResourceProvider resource = getResource();
204
                    DWGData dwgData = null;
205
                    FeatureStoreProviderServices store = getStoreServices();
206
                    if (resource.getData() != null) {
207
                        dwgData
208
                                = (DWGData) ((Map) resource.getData()).get(projection.getAbrev());
208 209
						// OJO no es del todo correcto (puede llevar
209
						// reproyeccion)
210
					} else {
211
						resource.setData(new HashMap());
212
					}
213
					if (dwgData == null) {
214
						dwgData = new DWGData();
215
						dwgData.data = new ArrayList();
216
						data = dwgData.data;
217
						counterNewsOIDs = 0;
218
						Reader reader =
219
								new Reader().initialice(getStoreProvider(),
220
										(File)resource.get(),
221
										projection, legendBuilder);
222
						reader.begin(store);
223
						dwgData.defaultFType =
224
								reader.getDefaultType().getNotEditableCopy();
225
						ArrayList types = new ArrayList();
226
						Iterator it = reader.getTypes().iterator();
227
						EditableFeatureType fType;
228
						while (it.hasNext()) {
229
							fType = (EditableFeatureType) it.next();
230
							if (fType.getId().equals(
231
									dwgData.defaultFType.getId())) {
232
								types.add(dwgData.defaultFType);
233
							} else {
234
								types.add(fType.getNotEditableCopy());
235
							}
236
						}
237
						dwgData.fTypes = types;
238
						dwgData.legendBuilder = legendBuilder;
210
                        // reproyeccion)
211
                    } else {
212
                        resource.setData(new HashMap());
213
                    }
214
                    if (dwgData == null) {
215
                        dwgData = new DWGData();
216
                        dwgData.data = new ArrayList();
217
                        data = dwgData.data;
218
                        counterNewsOIDs = 0;
219
                        Reader reader
220
                                = new Reader().initialice(getStoreProvider(),
221
                                        (File) resource.get(),
222
                                        projection, legendBuilder);
223
                        reader.begin(store);
224
                        dwgData.defaultFType
225
                                = reader.getDefaultType().getNotEditableCopy();
226
                        ArrayList types = new ArrayList();
227
                        Iterator it = reader.getTypes().iterator();
228
                        EditableFeatureType fType;
229
                        while (it.hasNext()) {
230
                            fType = (EditableFeatureType) it.next();
231
                            if (fType.getId().equals(
232
                                    dwgData.defaultFType.getId())) {
233
                                types.add(dwgData.defaultFType);
234
                            } else {
235
                                types.add(fType.getNotEditableCopy());
236
                            }
237
                        }
238
                        dwgData.fTypes = types;
239
                        dwgData.legendBuilder = legendBuilder;
239 240

  
240
						resource.notifyOpen();
241
						store.setFeatureTypes(dwgData.fTypes,
242
								dwgData.defaultFType);
243
						reader.load();
244
						// this.envelope = reader.getEnvelope();
241
                        resource.notifyOpen();
242
                        store.setFeatureTypes(dwgData.fTypes,
243
                                dwgData.defaultFType);
244
                        reader.load();
245
                        // this.envelope = reader.getEnvelope();
245 246

  
246
						dwgData.envelope = reader.getEnvelope();
247
                        dwgData.envelope = reader.getEnvelope();
247 248

  
249
                        dwgData.projection = projection;
248 250

  
249
						dwgData.projection = projection;
251
                        reader.end();
252
                        resource.notifyClose();
253
                        ((Map) resource.getData()).put(projection.getAbrev(),
254
                                dwgData); // OJO la reproyeccion
255
                    }
250 256

  
251
						reader.end();
252
						resource.notifyClose();
253
						((Map) resource.getData()).put(projection.getAbrev(),
254
								dwgData); // OJO la reproyeccion
255
					}
256

  
257
					data = dwgData.data;
258
					store.setFeatureTypes(dwgData.fTypes, dwgData.defaultFType);
259
					legendBuilder = dwgData.legendBuilder;
260
					setDynValue("Envelope", dwgData.getEnvelopeCopy());
261
					setDynValue("CRS", projection);
262
					counterNewsOIDs = data.size();
263
					return null;
264
				}
265
			});
266
		} catch (Exception e) {
267
			this.data = null;
268
			try {
269
				throw new OpenException(resource.getName(), e);
270
			} catch (AccessResourceException e1) {
271
				throw new OpenException(this.getProviderName(), e);
272
			}
257
                    data = dwgData.data;
258
                    store.setFeatureTypes(dwgData.fTypes, dwgData.defaultFType);
259
                    legendBuilder = dwgData.legendBuilder;
260
                    setDynValue("Envelope", dwgData.getEnvelopeCopy());
261
                    setDynValue("CRS", projection);
262
                    counterNewsOIDs = data.size();
263
                    return null;
264
                }
265
            });
266
        } catch (Exception e) {
267
            this.data = null;
268
            try {
269
                throw new OpenException(resource.getName(), e);
270
            } catch (AccessResourceException e1) {
271
                throw new OpenException(this.getProviderName(), e);
272
            }
273 273
			// } finally {
274
			// this.resource.end();
275
		}
276
	}
274
            // this.resource.end();
275
        }
276
    }
277 277

  
278
    public DataServerExplorer getExplorer() throws ReadException {
279
        DataManager manager = DALLocator.getDataManager();
280
        FilesystemServerExplorerParameters params;
281
        try {
282
            params = (FilesystemServerExplorerParameters) manager
283
                    .createServerExplorerParameters(FilesystemServerExplorer.NAME);
284
            params.setRoot(this.getDWGParameters().getFile().getParent());
285
            return manager.createServerExplorer(params);
286
        } catch (DataException e) {
287
            throw new ReadException(this.getProviderName(), e);
288
        } catch (ValidateDataParametersException e) {
289
            throw new ReadException(this.getProviderName(), e);
290
        }
278 291

  
279
	public DataServerExplorer getExplorer() throws ReadException {
280
		DataManager manager = DALLocator.getDataManager();
281
		FilesystemServerExplorerParameters params;
282
		try {
283
			params = (FilesystemServerExplorerParameters) manager
284
				.createServerExplorerParameters(FilesystemServerExplorer.NAME);
285
			params.setRoot(this.getDWGParameters().getFile().getParent());
286
			return manager.createServerExplorer(params);
287
		} catch (DataException e) {
288
			throw new ReadException(this.getProviderName(), e);
289
		} catch (ValidateDataParametersException e) {
290
			throw new ReadException(this.getProviderName(), e);
291
		}
292
    }
292 293

  
293
	}
294
    public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException {
295
        // FIXME Exception
296
        throw new UnsupportedOperationException();
297
    }
294 298

  
299
    public class Reader {
295 300

  
301
        private File file;
302
        private String fileName;
303
        private IProjection projection;
304
        private List types;
305
        private LegendBuilder leyendBuilder;
306
        private AbstractMemoryStoreProvider store;
307
        private Envelope envelope;
308
        private DwgFile dwgFeatureFile;
296 309

  
297
	public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException {
298
		// FIXME Exception
299
		throw new UnsupportedOperationException();
300
	}
310
        public Reader initialice(AbstractMemoryStoreProvider store, File file,
311
                IProjection projection,
312
                LegendBuilder leyendBuilder) {
313
            this.store = store;
314
            this.file = file;
315
            this.fileName = file.getAbsolutePath();
316
            this.projection = projection;
317
            this.leyendBuilder = leyendBuilder;
318
            if (leyendBuilder != null) {
319
                leyendBuilder.initialize(store);
320
            }
321
            return this;
322
        }
301 323

  
302
	public class Reader {
303
		private File file;
304
		private String fileName;
305
		private IProjection projection;
306
		private List types;
307
		private LegendBuilder leyendBuilder;
308
		private AbstractMemoryStoreProvider store;
309
		private Envelope envelope;
310
		private DwgFile dwgFeatureFile;
324
        public Envelope getEnvelope() {
325
            return this.envelope;
326
        }
311 327

  
312
		public Reader initialice(AbstractMemoryStoreProvider store, File file,
313
				IProjection projection,
314
				LegendBuilder leyendBuilder) {
315
			this.store = store;
316
			this.file = file;
317
			this.fileName = file.getAbsolutePath();
318
			this.projection = projection;
319
			this.leyendBuilder = leyendBuilder;
320
			if (leyendBuilder != null) {
321
				leyendBuilder.initialize(store);
322
			}
323
			return this;
324
		}
328
        public void begin(FeatureStoreProviderServices store) throws UnsupportedDWGVersionException, ReadException {
329
            dwgFeatureFile = new DwgFile(file.getAbsolutePath());
325 330

  
326
		public Envelope getEnvelope() {
327
			return this.envelope;
328
		}
329

  
330
		public void begin(FeatureStoreProviderServices store) throws UnsupportedDWGVersionException, ReadException {
331
		    dwgFeatureFile = new DwgFile(file.getAbsolutePath());
332

  
333 331
            try {
334 332
                dwgFeatureFile.read();
335 333
            } catch (DwgVersionNotSupportedException e1) {
......
338 336
                throw new ReadException(NAME, e);
339 337
            }
340 338

  
341
			EditableFeatureType featureType = store.createFeatureType(getName());
339
            EditableFeatureType featureType = store.createFeatureType(getName());
342 340

  
343
			featureType.setHasOID(true);
341
            featureType.setHasOID(true);
344 342

  
345
			ID_FIELD_ID = featureType.add(NAME_FIELD_ID, DataTypes.INT)
346
					.setDefaultValue(Integer.valueOf(0))
347
				.getIndex();
343
            ID_FIELD_ID = featureType.add(NAME_FIELD_ID, DataTypes.INT)
344
                    .setDefaultValue(Integer.valueOf(0))
345
                    .getIndex();
348 346

  
349
			EditableFeatureAttributeDescriptor attr = featureType.add(
350
					NAME_FIELD_GEOMETRY, DataTypes.GEOMETRY);
351
			attr.setSRS(this.projection);
352
			attr.setGeometryType(Geometry.TYPES.GEOMETRY);
353
			boolean is3dFile = dwgFeatureFile.isDwg3DFile();
354
			if (is3dFile){
355
			    attr.setGeometrySubType(Geometry.SUBTYPES.GEOM3D);
356
			}else{
357
			    attr.setGeometrySubType(Geometry.SUBTYPES.GEOM2D);
358
			}
359
			ID_FIELD_GEOMETRY = attr.getIndex();
347
            EditableFeatureAttributeDescriptor attr = featureType.add(
348
                    NAME_FIELD_GEOMETRY, DataTypes.GEOMETRY);
349
            attr.setSRS(this.projection);
350
            attr.setGeometryType(Geometry.TYPES.GEOMETRY);
351
            boolean is3dFile = dwgFeatureFile.isDwg3DFile();
352
            if (is3dFile) {
353
                attr.setGeometrySubType(Geometry.SUBTYPES.GEOM3D);
354
            } else {
355
                attr.setGeometrySubType(Geometry.SUBTYPES.GEOM2D);
356
            }
357
            ID_FIELD_GEOMETRY = attr.getIndex();
360 358

  
361
			featureType.setDefaultGeometryAttributeName(NAME_FIELD_GEOMETRY);
359
            featureType.setDefaultGeometryAttributeName(NAME_FIELD_GEOMETRY);
362 360

  
363
			// FIXME: Cual es el size y el valor por defecto para Entity ?
364
			ID_FIELD_ENTITY = featureType.add(NAME_FIELD_ENTITY,
365
					DataTypes.STRING, 100)
366
					.setDefaultValue("")
367
					.getIndex();
361
            // FIXME: Cual es el size y el valor por defecto para Entity ?
362
            ID_FIELD_ENTITY = featureType.add(NAME_FIELD_ENTITY,
363
                    DataTypes.STRING, 100)
364
                    .setDefaultValue("")
365
                    .getIndex();
368 366

  
369
			// FIXME: Cual es el size de Layer ?
370
			ID_FIELD_LAYER = featureType.add(NAME_FIELD_LAYER,
371
					DataTypes.STRING, 100)
372
					.setDefaultValue(
373
					"default").getIndex();
367
            // FIXME: Cual es el size de Layer ?
368
            ID_FIELD_LAYER = featureType.add(NAME_FIELD_LAYER,
369
                    DataTypes.STRING, 100)
370
                    .setDefaultValue(
371
                            "default").getIndex();
374 372

  
375
			ID_FIELD_COLOR = featureType.add(NAME_FIELD_COLOR,
376
					DataTypes.INT)
377
					.setDefaultValue(
378
					Integer.valueOf(0)).getIndex();
373
            ID_FIELD_COLOR = featureType.add(NAME_FIELD_COLOR,
374
                    DataTypes.INT)
375
                    .setDefaultValue(
376
                            Integer.valueOf(0)).getIndex();
379 377

  
380
			ID_FIELD_ELEVATION = featureType.add(NAME_FIELD_ELEVATION,
381
					DataTypes.DOUBLE)
382
					.setDefaultValue(
383
					Double.valueOf(0)).getIndex();
378
            ID_FIELD_ELEVATION = featureType.add(NAME_FIELD_ELEVATION,
379
                    DataTypes.DOUBLE)
380
                    .setDefaultValue(
381
                            Double.valueOf(0)).getIndex();
384 382

  
385
			ID_FIELD_THICKNESS = featureType.add(NAME_FIELD_THICKNESS,
386
					DataTypes.DOUBLE)
387
					.setDefaultValue(
388
					Double.valueOf(0)).getIndex();
383
            ID_FIELD_THICKNESS = featureType.add(NAME_FIELD_THICKNESS,
384
                    DataTypes.DOUBLE)
385
                    .setDefaultValue(
386
                            Double.valueOf(0)).getIndex();
389 387

  
390
			// FIXME: Cual es el size de Text ?
391
			ID_FIELD_TEXT = featureType.add(NAME_FIELD_TEXT,
392
					DataTypes.STRING, 100)
393
					.setDefaultValue("")
394
					.getIndex();
388
            // FIXME: Cual es el size de Text ?
389
            ID_FIELD_TEXT = featureType.add(NAME_FIELD_TEXT,
390
                    DataTypes.STRING, 100)
391
                    .setDefaultValue("")
392
                    .getIndex();
395 393

  
396
			ID_FIELD_HEIGHTTEXT = featureType.add(NAME_FIELD_HEIGHTTEXT,
397
					DataTypes.DOUBLE).setDefaultValue(
398
					Double.valueOf(10)).getIndex();
394
            ID_FIELD_HEIGHTTEXT = featureType.add(NAME_FIELD_HEIGHTTEXT,
395
                    DataTypes.DOUBLE).setDefaultValue(
396
                            Double.valueOf(10)).getIndex();
399 397

  
400
			ID_FIELD_ROTATIONTEXT = featureType.add(NAME_FIELD_ROTATIONTEXT,
401
					DataTypes.DOUBLE).setDefaultValue(
402
					Double.valueOf(0)).getIndex();
398
            ID_FIELD_ROTATIONTEXT = featureType.add(NAME_FIELD_ROTATIONTEXT,
399
                    DataTypes.DOUBLE).setDefaultValue(
400
                            Double.valueOf(0)).getIndex();
403 401

  
404

  
405

  
406 402
			// FIXME: Parece que el DXF puede tener mas atributos opcionales.
407
			// Habria que ver de pillarlos ?
403
            // Habria que ver de pillarlos ?
404
            types = new ArrayList();
405
            types.add(featureType);
408 406

  
409
			types = new ArrayList();
410
			types.add(featureType);
407
            if (leyendBuilder != null) {
408
                leyendBuilder.begin();
409
            }
411 410

  
412
			if (leyendBuilder != null) {
413
				leyendBuilder.begin();
414
			}
411
        }
415 412

  
416
		}
413
        public void end() {
414
            if (leyendBuilder != null) {
415
                leyendBuilder.end();
416
            }
417
        }
417 418

  
418
		public void end() {
419
			if (leyendBuilder != null) {
420
				leyendBuilder.end();
421
			}
422
		}
419
        public List getTypes() {
420
            return types;
421
        }
423 422

  
424
		public List getTypes() {
425
			return types;
426
		}
423
        public EditableFeatureType getDefaultType() {
424
            return (EditableFeatureType) types.get(0);
425
        }
427 426

  
428
		public EditableFeatureType getDefaultType() {
429
			return (EditableFeatureType) types.get(0);
430
		}
427
        private Double toDouble(String value) {
428
            if (value == null) {
429
                return Double.valueOf(0);
430
            }
431
            return Double.valueOf(value);
432
        }
431 433

  
432
		private Double toDouble(String value) {
433
			if (value == null) {
434
				return Double.valueOf(0);
435
			}
436
			return Double.valueOf(value);
437
		}
434
        public void load() throws DataException {
438 435

  
439
		public void load() throws DataException {
436
            this.envelope = null;
440 437

  
441
			this.envelope = null;
442

  
443 438
            long count_not_fmap_interface = 0;
444 439
            long count_null_geometry = 0;
445 440
            long count_bad_envelope = 0;
446 441
            long count_envelope_out_of_aoi = 0;
447 442

  
448
			dwgFeatureFile.calculateGisModelDwgPolylines();
449
			dwgFeatureFile.blockManagement2();
450
			List entities = dwgFeatureFile.getDwgObjects();
443
            dwgFeatureFile.calculateGisModelDwgPolylines();
444
            dwgFeatureFile.blockManagement2();
445
            List entities = dwgFeatureFile.getDwgObjects();
451 446

  
452
			int id = -1;
453
			try{
454
				int envelopeSubType = Geometry.SUBTYPES.GEOM2D;
455
				boolean is3dFile = dwgFeatureFile.isDwg3DFile();
447
            int id = -1;
448
            try {
449
                int envelopeSubType = Geometry.SUBTYPES.GEOM2D;
450
                boolean is3dFile = dwgFeatureFile.isDwg3DFile();
456 451

  
457
				this.envelope = geomManager.createEnvelope(envelopeSubType);
452
                this.envelope = geomManager.createEnvelope(envelopeSubType);
458 453

  
459
				boolean updateEnvelope = true;
454
                boolean updateEnvelope = true;
460 455

  
461
				double[] extMin = (double[]) dwgFeatureFile
462
						.getHeader("MSPACE_EXTMIN");
463
				double[] extMax = (double[]) dwgFeatureFile
464
						.getHeader("MSPACE_EXTMAX");
465
				if (extMin != null && extMax != null) {
466
					updateEnvelope = false;
467
					Point point = (Point) geomManager.create(
468
							Geometry.TYPES.POINT, envelopeSubType);
469
					point.setCoordinates(extMin);
470
					this.envelope.setLowerCorner(point);
471
					point = (Point) geomManager.create(Geometry.TYPES.POINT,
472
							envelopeSubType);
473
					point.setCoordinates(extMax);
474
					this.envelope.setUpperCorner(point);
475
				}
456
                double[] extMin = (double[]) dwgFeatureFile
457
                        .getHeader("MSPACE_EXTMIN");
458
                double[] extMax = (double[]) dwgFeatureFile
459
                        .getHeader("MSPACE_EXTMAX");
460
                if (extMin != null && extMax != null) {
461
                    updateEnvelope = false;
462
                    Point point = (Point) geomManager.create(
463
                            Geometry.TYPES.POINT, envelopeSubType);
464
                    point.setCoordinates(extMin);
465
                    this.envelope.setLowerCorner(point);
466
                    point = (Point) geomManager.create(Geometry.TYPES.POINT,
467
                            envelopeSubType);
468
                    point.setCoordinates(extMax);
469
                    this.envelope.setUpperCorner(point);
470
                }
476 471

  
472
                Iterator iter = entities.iterator();
477 473

  
478
				Iterator iter = entities.iterator();
474
                FeatureProvider featureProvider;
475
                Envelope gEnvelope;
479 476

  
480
				FeatureProvider featureProvider;
481
				Envelope gEnvelope;
477
                while (iter.hasNext()) {
478
                    id++;
479
                    DwgObject entity = (DwgObject) iter.next();
482 480

  
483
				while (iter.hasNext()) {
484
					id++;
485
					DwgObject entity = (DwgObject) iter.next();
481
                    if (!(entity instanceof IDwg2FMap)) {
482
                        count_not_fmap_interface++;
483
                        /*
484
                         logger.warn("load: entity type {}(id:{}) not loadded",
485
                         new Object[] { entity.getType() }, id);
486
                         */
487
                        continue;
488
                    }
486 489

  
487
					if (!(entity instanceof IDwg2FMap)) {
488
					    count_not_fmap_interface++;
489
					    /*
490
						logger.warn("load: entity type {}(id:{}) not loadded",
491
						new Object[] { entity.getType() }, id);
492
						*/
493
						continue;
494
					}
495

  
496
					IDwg2FMap dwgEnt = (IDwg2FMap) entity;
497
					Geometry geometry = dwgEnt.toFMapGeometry(is3dFile);
498
					if (geometry == null) {
499
					    count_null_geometry++;
500
					    /*
501
						logger.warn("load: entity {}(id:{}) with null geometry",
502
						    new Object[] { entity.getType(), id });
503
						    */
504
						continue;
505
					}
490
                    IDwg2FMap dwgEnt = (IDwg2FMap) entity;
491
                    Geometry geometry = dwgEnt.toFMapGeometry(is3dFile);
492
                    if (geometry == null) {
493
                        count_null_geometry++;
494
                        /*
495
                         logger.warn("load: entity {}(id:{}) with null geometry",
496
                         new Object[] { entity.getType(), id });
497
                         */
498
                        continue;
499
                    }
506 500
					// FIXME: Estas 6 lineas es por si la geometr�a no se ha
507
					// creado correctamente
508
					gEnvelope = null;
509
					try {
510
						gEnvelope = geometry.getEnvelope();
511
					} catch (Exception e) {
512
						gEnvelope = null;
513
					}
514
					if (gEnvelope == null) {
515
					    count_bad_envelope++;
516
					    /*
517
						logger.warn("load: entity {}(id:{}) with null envelope",
518
						    new Object[] { entity.getType(), id });
519
						    */
520
						continue;
521
					}
522
					// we check for Region of Interest of the CAD file
523
					if (!this.envelope.intersects(geometry.getEnvelope())) {
524
					    count_envelope_out_of_aoi++;
525
					    /*
526
						logger.warn("load: entity {}(id:{}) out of envelope",
527
						    new Object[] { entity.getType(), id });
528
						    */
529
						continue;
530
					}
531
					featureProvider = store.createFeatureProvider(store
532
							.getStoreServices().getDefaultFeatureType());
501
                    // creado correctamente
502
                    gEnvelope = null;
503
                    try {
504
                        gEnvelope = geometry.getEnvelope();
505
                    } catch (Exception e) {
506
                        gEnvelope = null;
507
                    }
508
                    if (gEnvelope == null) {
509
                        count_bad_envelope++;
510
                        /*
511
                         logger.warn("load: entity {}(id:{}) with null envelope",
512
                         new Object[] { entity.getType(), id });
513
                         */
514
                        continue;
515
                    }
516
                    // we check for Region of Interest of the CAD file
517
                    if (!this.envelope.intersects(geometry.getEnvelope())) {
518
                        count_envelope_out_of_aoi++;
519
                        /*
520
                         logger.warn("load: entity {}(id:{}) out of envelope",
521
                         new Object[] { entity.getType(), id });
522
                         */
523
                        continue;
524
                    }
525
                    featureProvider = store.createFeatureProvider(store
526
                            .getStoreServices().getDefaultFeatureType());
533 527

  
534
					featureProvider.set(ID_FIELD_ID, id);
528
                    featureProvider.set(ID_FIELD_ID, id);
535 529

  
536
					featureProvider.set(ID_FIELD_ENTITY, dwgEnt.toString());
530
                    featureProvider.set(ID_FIELD_ENTITY, dwgEnt.toString());
537 531

  
538
					featureProvider.set(ID_FIELD_LAYER, dwgFeatureFile
539
							.getLayerName(entity));
532
                    featureProvider.set(ID_FIELD_LAYER, dwgFeatureFile
533
                            .getLayerName(entity));
540 534

  
541
					int colorByLayer = dwgFeatureFile.getColorByLayer(entity);
542
					int color = entity.getColor();
543
					if (color < 0) {
544
						color = Math.abs(color);
545
					}
546
					if (color > 255) {
547
						color = colorByLayer;
548
					}
535
                    int colorByLayer = dwgFeatureFile.getColorByLayer(entity);
536
                    int color = entity.getColor();
537
                    if (color < 0) {
538
                        color = Math.abs(color);
539
                    }
540
                    if (color > 255) {
541
                        color = colorByLayer;
542
                    }
549 543

  
550
					featureProvider.set(ID_FIELD_COLOR, color);
544
                    featureProvider.set(ID_FIELD_COLOR, color);
551 545

  
552
					if (entity instanceof IDwg3DTestable) {
553
						featureProvider.set(ID_FIELD_ELEVATION,
554
								((IDwg3DTestable) entity).getZ());
555
					}
546
                    if (entity instanceof IDwg3DTestable) {
547
                        featureProvider.set(ID_FIELD_ELEVATION,
548
                                ((IDwg3DTestable) entity).getZ());
549
                    }
556 550

  
557
					featureProvider.set(ID_FIELD_THICKNESS, 0.0);
558
					featureProvider.set(ID_FIELD_HEIGHTTEXT, 0.0);
559
					featureProvider.set(ID_FIELD_ROTATIONTEXT, 0.0);
560
					featureProvider.set(ID_FIELD_TEXT, "");
551
                    featureProvider.set(ID_FIELD_THICKNESS, 0.0);
552
                    featureProvider.set(ID_FIELD_HEIGHTTEXT, 0.0);
553
                    featureProvider.set(ID_FIELD_ROTATIONTEXT, 0.0);
554
                    featureProvider.set(ID_FIELD_TEXT, "");
561 555

  
562
					if (entity instanceof DwgMText) {
563
						DwgMText mtext = (DwgMText) entity;
564
						featureProvider.set(ID_FIELD_HEIGHTTEXT, mtext.getHeight());
565
						featureProvider.set(ID_FIELD_TEXT, mtext.getText());
566
					} else if (entity instanceof DwgText) {
567
						DwgText text = (DwgText) entity;
568
						featureProvider
569
								.set(ID_FIELD_THICKNESS, text.getThickness());
570
						featureProvider.set(ID_FIELD_HEIGHTTEXT, text.getHeight());
571
						featureProvider.set(ID_FIELD_ROTATIONTEXT, text
572
								.getRotationAngle());
573
						featureProvider.set(ID_FIELD_TEXT, text.getText());
574
					}// if-else
556
                    if (entity instanceof DwgMText) {
557
                        DwgMText mtext = (DwgMText) entity;
558
                        featureProvider.set(ID_FIELD_HEIGHTTEXT, mtext.getHeight());
559
                        featureProvider.set(ID_FIELD_TEXT, mtext.getText());
560
                    } else if (entity instanceof DwgText) {
561
                        DwgText text = (DwgText) entity;
562
                        featureProvider
563
                                .set(ID_FIELD_THICKNESS, text.getThickness());
564
                        featureProvider.set(ID_FIELD_HEIGHTTEXT, text.getHeight());
565
                        featureProvider.set(ID_FIELD_ROTATIONTEXT, text
566
                                .getRotationAngle());
567
                        featureProvider.set(ID_FIELD_TEXT, text.getText());
568
                    }// if-else
575 569

  
576
					featureProvider.setDefaultGeometry(geometry);
570
                    featureProvider.setDefaultGeometry(geometry);
577 571

  
578
					store.addFeatureProvider(featureProvider);
579
					if (this.leyendBuilder != null) {
580
						this.leyendBuilder.process(featureProvider);
581
					}
572
                    store.addFeatureProvider(featureProvider);
573
                    if (this.leyendBuilder != null) {
574
                        this.leyendBuilder.process(featureProvider);
575
                    }
582 576

  
583
				}
577
                }
584 578

  
585
				logger.info("Issues while loading DWG entities:+\n"
586
	                + "    Entities not implementing IDwg2FMap interface: " + count_not_fmap_interface + "\n"
587
	                + "    Entities with non-convertible geometry: " + count_null_geometry + "\n"
588
	                + "    Entities without valid envelope: " + count_bad_envelope + "\n"
589
	                + "    Entities with envelope out of global envelope: " + count_envelope_out_of_aoi);
579
                logger.info("Issues while loading DWG entities:+\n"
580
                        + "    Entities not implementing IDwg2FMap interface: " + count_not_fmap_interface + "\n"
581
                        + "    Entities with non-convertible geometry: " + count_null_geometry + "\n"
582
                        + "    Entities without valid envelope: " + count_bad_envelope + "\n"
583
                        + "    Entities with envelope out of global envelope: " + count_envelope_out_of_aoi);
590 584

  
591
			} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
592
				throw new CreateGeometryException(e);
593
			} catch (org.gvsig.fmap.geom.exception.CreateEnvelopeException e) {
594
				throw new CreateGeometryException(e);
595
			}
596
		}
585
            } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
586
                throw new CreateGeometryException(e);
587
            } catch (org.gvsig.fmap.geom.exception.CreateEnvelopeException e) {
588
                throw new CreateGeometryException(e);
589
            }
590
        }
597 591

  
598
	}
592
    }
599 593

  
594
    public boolean closeResourceRequested(ResourceProvider resource) {
595
        return true;
596
    }
600 597

  
601
	public boolean closeResourceRequested(ResourceProvider resource) {
602
		return true;
603
	}
598
    public int getOIDType() {
599
        return DataTypes.LONG;
600
    }
604 601

  
605
	public int getOIDType() {
606
		return DataTypes.LONG;
607
	}
602
    public boolean supportsAppendMode() {
603
        return false;
604
    }
608 605

  
609
	public boolean supportsAppendMode() {
610
		return false;
611
	}
606
    public void append(FeatureProvider featureProvider) {
607
        // FIXME Exception
608
        throw new UnsupportedOperationException();
609
    }
612 610

  
613
	public void append(FeatureProvider featureProvider) {
614
		// FIXME Exception
615
		throw new UnsupportedOperationException();
616
	}
611
    public void beginAppend() {
612
        // FIXME Exception
613
        throw new UnsupportedOperationException();
617 614

  
618
	public void beginAppend() {
619
		// FIXME Exception
620
		throw new UnsupportedOperationException();
615
    }
621 616

  
622
	}
617
    public void endAppend() {
618
        // FIXME Exception
619
        throw new UnsupportedOperationException();
620
    }
623 621

  
624
	public void endAppend() {
625
		// FIXME Exception
626
		throw new UnsupportedOperationException();
627
	}
622
    public void saveToState(PersistentState state) throws PersistenceException {
623
        // TODO Auto-generated method stub
624
        throw new NotYetImplemented();
625
    }
628 626

  
629
	public void saveToState(PersistentState state) throws PersistenceException {
630
		// TODO Auto-generated method stub
631
		throw new NotYetImplemented();
632
	}
627
    public void loadFromState(PersistentState state) throws PersistenceException {
628
        // TODO Auto-generated method stub
629
        throw new NotYetImplemented();
630
    }
633 631

  
634
	public void loadFromState(PersistentState state) throws PersistenceException {
635
		// TODO Auto-generated method stub
636
		throw new NotYetImplemented();
637
	}
632
    public Object createNewOID() {
633
        return new Long(counterNewsOIDs++);
634
    }
638 635

  
639
	public Object createNewOID() {
640
		return new Long(counterNewsOIDs++);
641
	}
636
    protected void initializeFeatureTypes() throws InitializeException {
637
        try {
638
            this.open();
639
        } catch (OpenException e) {
640
            throw new InitializeException(this.getProviderName(), e);
641
        }
642
    }
642 643

  
643
	protected void initializeFeatureTypes() throws InitializeException {
644
		try {
645
			this.open();
646
		} catch (OpenException e) {
647
			throw new InitializeException(this.getProviderName(), e);
648
		}
649
	}
644
    public Envelope getEnvelope() throws DataException {
645
        this.open();
646
        return (Envelope) this.getDynValue("Envelope");
647
    }
650 648

  
651
	public Envelope getEnvelope() throws DataException {
652
		this.open();
653
		return (Envelope) this.getDynValue("Envelope");
654
	}
655 649

  
650
    /*
651
     * (non-Javadoc)
652
     *
653
     * @see
654
     * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
655
     * gvsig.fmap.dal.resource.spi.ResourceProvider)
656
     */
657
    public void resourceChanged(ResourceProvider resource) {
658
        this.getStoreServices().notifyChange(
659
                DataStoreNotification.RESOURCE_CHANGED,
660
                resource);
661
    }
656 662

  
657
	/*
658
	 * (non-Javadoc)
659
	 *
660
	 * @see
661
	 * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
662
	 * gvsig.fmap.dal.resource.spi.ResourceProvider)
663
	 */
664
	public void resourceChanged(ResourceProvider resource) {
665
		this.getStoreServices().notifyChange(
666
				DataStoreNotification.RESOURCE_CHANGED,
667
				resource);
668
	}
663
    public Object getSourceId() {
664
        return this.getDWGParameters().getFile();
665
    }
669 666

  
670
	public Object getSourceId() {
671
		return this.getDWGParameters().getFile();
672
	}
667
    public String getName() {
668
        String name = this.getDWGParameters().getFile().getName();
669
        int n = name.lastIndexOf(".");
670
        if (n < 1) {
671
            return name;
672
        }
673
        return name.substring(0, n);
674
    }
673 675

  
676
    public String getFullName() {
677
        return this.getDWGParameters().getFile().getAbsolutePath();
678
    }
674 679

  
675
	public String getName() {
676
		String name = this.getDWGParameters().getFile().getName();
677
		int n = name.lastIndexOf(".");
678
		if( n<1 ) {
679
			return name;
680
		}
681
		return name.substring(0, n);
682
	}
683
	
684
	public String getFullName() {
685
		return this.getDWGParameters().getFile().getAbsolutePath();
686
	}
687
	
680
    public ResourceProvider getResource() {
681
        return resource;
682
    }
688 683

  
689
	
690
	public ResourceProvider getResource() {
691
		return resource;
692
	}
693

  
694
}
684
}
695 685

  

Also available in: Unified diff