Revision 702

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dxf/DXFDriver.java
13 13
import org.cresques.cts.IProjection;
14 14
import org.cresques.cts.ProjectionPool;
15 15
import org.cresques.io.DxfFile;
16
import org.cresques.px.Extent;
16 17
import org.cresques.px.IObjList;
17 18
import org.cresques.px.dxf.DxfFeatureMaker;
18 19
import org.cresques.px.gml.Feature;
20
import org.cresques.px.gml.Geometry;
19 21
import org.cresques.px.gml.InsPoint;
20 22
import org.cresques.px.gml.LineString;
21 23
import org.cresques.px.gml.Point;
22 24
import org.cresques.px.gml.Polygon;
23 25

  
26
import com.hardcode.gdbms.engine.data.DriverException;
27
import com.hardcode.gdbms.engine.data.FileDriver;
28
import com.hardcode.gdbms.engine.values.Value;
29
import com.iver.cit.gvsig.fmap.core.FShape;
24 30
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
25 31
import com.iver.cit.gvsig.fmap.core.IGeometry;
26 32
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
33
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
27 34
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
35
import com.iver.cit.gvsig.fmap.drivers.shp.SHP;
28 36

  
29 37
/**
30 38
 * @author jmorell (jose.morell@gmail.com)
31 39
 * @version 13-dic-2004
32 40
 */
33
public class DXFDriver implements VectorialFileDriver {
41
public class DXFDriver implements VectorialFileDriver, BoundedShapes, FileDriver {
34 42

  
35 43
	private String path;
36 44
	
......
50 58
	private IObjList.vector features;
51 59
	private File dxfFile = null;
52 60
	
61
    private int numReg;
62
	
53 63
	/* (non-Javadoc)
54 64
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
55 65
	 */
56 66
	public void open(File f) throws IOException {
57 67
		dxfFile = f;
68
		IProjection proj = ProjectionPool.get("ed50utm30");
69
		featureMaker = new DxfFeatureMaker(proj);
70
		dxfFeatureFile = new DxfFile(proj, dxfFile.getAbsolutePath(), featureMaker);
71
		dxfFeatureFile.load();
72
		features = (IObjList.vector)((DxfFeatureMaker)featureMaker).getObjects();
73
		numReg = features.size();
58 74
	}
59 75

  
60 76
	/* (non-Javadoc)
......
117 133
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShapeCount()
118 134
	 */
119 135
	public int getShapeCount() throws IOException {
120
		return features.size();
136
		return numReg;
121 137
	}
122 138

  
123 139
	/* (non-Javadoc)
......
131 147
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
132 148
	 */
133 149
	public void initialize() throws IOException {
134
		IProjection proj = ProjectionPool.get("ed50utm30");
150
		/*IProjection proj = ProjectionPool.get("ed50utm30");
135 151
		featureMaker = new DxfFeatureMaker(proj);
136 152
		dxfFeatureFile = new DxfFile(proj, dxfFile.getAbsolutePath(), featureMaker);
137 153
		dxfFeatureFile.load();
138 154
		features = (IObjList.vector)((DxfFeatureMaker)featureMaker).getObjects();
155
		numReg = features.size();*/
139 156
	}
140 157

  
141 158
	/* (non-Javadoc)
......
165 182
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
166 183
	 */
167 184
	public int getShapeType() {
168
		// TODO Auto-generated method stub
169 185
		return 1;
170 186
	}
171 187

  
......
176 192
		return "gvSIG DXF Driver";
177 193
	}
178 194

  
195
	/* (non-Javadoc)
196
	 * @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeBounds(int)
197
	 */
198
	public Rectangle2D getShapeBounds(int index) throws IOException {
199
		Feature fea = (Feature)features.get(index);
200
		Geometry geo = (Geometry)fea.getGeometry();
201
		return ((Extent)(geo.getExtent())).toRectangle2D();
202
	}
203

  
204
	/* (non-Javadoc)
205
	 * @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeType(int)
206
	 */
207
	public int getShapeType(int index) {
208
        int auxType = 0;
209
        Feature fea = (Feature)features.get(index);
210
		if (fea.getGeometry() instanceof Point) {
211
            auxType = auxType | FShape.POINT;
212
		} else if (fea.getGeometry() instanceof InsPoint) {
213
            auxType = auxType | FShape.POINT;
214
		} else if (fea.getGeometry() instanceof LineString) {
215
            auxType = auxType | FShape.LINE;
216
		} else if (fea.getGeometry() instanceof Polygon) {
217
            auxType = auxType | FShape.POLYGON;
218
		} else {
219
			System.out.println("getShape(): ERROR:Geometr?a desconocida.");
220
		}
221
        return auxType;
222
	}
223

  
224
	/* (non-Javadoc)
225
	 * @see com.hardcode.gdbms.engine.data.FileDriver#fileAccepted(java.io.File)
226
	 */
227
	public boolean fileAccepted(File f) {
228
		return f.getName().toUpperCase().endsWith("DXF");
229
	}
230

  
231
	/* (non-Javadoc)
232
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
233
	 */
234
	public Value getFieldValue(long arg0, int arg1) throws DriverException {
235
		// TODO Auto-generated method stub
236
		return null;
237
	}
238

  
239
	/* (non-Javadoc)
240
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
241
	 */
242
	public int getFieldCount() throws DriverException {
243
		// TODO Auto-generated method stub
244
		return 0;
245
	}
246

  
247
	/* (non-Javadoc)
248
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
249
	 */
250
	public String getFieldName(int arg0) throws DriverException {
251
		// TODO Auto-generated method stub
252
		return null;
253
	}
254

  
255
	/* (non-Javadoc)
256
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
257
	 */
258
	public long getRowCount() throws DriverException {
259
		try {
260
			return getShapeCount();
261
		} catch (IOException e) {
262
			e.printStackTrace();
263
		}
264
		return -1;
265
		//return 0;
266
	}
267

  
179 268
}

Also available in: Unified diff