svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dxf / DXFMemoryDriver.java @ 2944
History | View | Annotate | Download (29.3 KB)
1 |
/*
|
---|---|
2 |
* @(#)DXFMemoryDriver 29-dic-2004
|
3 |
*
|
4 |
* @author jmorell (jose.morell@gmail.com)
|
5 |
*/
|
6 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
7 |
*
|
8 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
9 |
*
|
10 |
* This program is free software; you can redistribute it and/or
|
11 |
* modify it under the terms of the GNU General Public License
|
12 |
* as published by the Free Software Foundation; either version 2
|
13 |
* of the License, or (at your option) any later version.
|
14 |
*
|
15 |
* This program is distributed in the hope that it will be useful,
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
* GNU General Public License for more details.
|
19 |
*
|
20 |
* You should have received a copy of the GNU General Public License
|
21 |
* along with this program; if not, write to the Free Software
|
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
23 |
*
|
24 |
* For more information, contact:
|
25 |
*
|
26 |
* Generalitat Valenciana
|
27 |
* Conselleria d'Infraestructures i Transport
|
28 |
* Av. Blasco Ib??ez, 50
|
29 |
* 46010 VALENCIA
|
30 |
* SPAIN
|
31 |
*
|
32 |
* +34 963862235
|
33 |
* gvsig@gva.es
|
34 |
* www.gvsig.gva.es
|
35 |
*
|
36 |
* or
|
37 |
*
|
38 |
* IVER T.I. S.A
|
39 |
* Salamanca 50
|
40 |
* 46005 Valencia
|
41 |
* Spain
|
42 |
*
|
43 |
* +34 963163400
|
44 |
* dac@iver.es
|
45 |
*/
|
46 |
package com.iver.cit.gvsig.fmap.drivers.dxf; |
47 |
|
48 |
import java.awt.Color; |
49 |
import java.awt.Font; |
50 |
import java.awt.geom.Point2D; |
51 |
import java.io.File; |
52 |
import java.io.IOException; |
53 |
import java.util.ArrayList; |
54 |
|
55 |
import org.cresques.cts.IProjection; |
56 |
import org.cresques.cts.ProjectionPool; |
57 |
import org.cresques.geo.Point3D; |
58 |
import org.cresques.io.DxfFile; |
59 |
import org.cresques.px.IObjList; |
60 |
import org.cresques.px.dxf.AcadColor; |
61 |
import org.cresques.px.dxf.DxfFeatureMaker; |
62 |
import org.cresques.px.gml.Feature; |
63 |
import org.cresques.px.gml.InsPoint; |
64 |
import org.cresques.px.gml.InsPoint3D; |
65 |
import org.cresques.px.gml.LineString; |
66 |
import org.cresques.px.gml.LineString3D; |
67 |
import org.cresques.px.gml.Point; |
68 |
import org.cresques.px.gml.Polygon; |
69 |
import org.cresques.px.gml.Polygon3D; |
70 |
|
71 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
72 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
73 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
74 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
75 |
import com.hardcode.gdbms.engine.values.IntValue; |
76 |
import com.hardcode.gdbms.engine.values.Value; |
77 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
78 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
79 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
80 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
81 |
import com.iver.cit.gvsig.fmap.core.FPolygon3D; |
82 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
83 |
import com.iver.cit.gvsig.fmap.core.FPolyline3D; |
84 |
import com.iver.cit.gvsig.fmap.core.FShape; |
85 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
86 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
87 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
88 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
89 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
90 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
91 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
92 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
93 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
94 |
|
95 |
/**
|
96 |
* @author jmorell (jose.morell@gmail.com)
|
97 |
* @version 29-dic-2004
|
98 |
*/
|
99 |
public class DXFMemoryDriver extends MemoryDriver implements WithDefaultLegend { |
100 |
private final int ID_FIELD_ID=0; |
101 |
private final int ID_FIELD_FSHAPE=1; |
102 |
private final int ID_FIELD_ENTITY=2; |
103 |
private final int ID_FIELD_LAYER=3; |
104 |
private final int ID_FIELD_COLOR=4; |
105 |
private final int ID_FIELD_ELEVATION=5; |
106 |
private final int ID_FIELD_THICKNESS=6; |
107 |
private final int ID_FIELD_TEXT=7; |
108 |
private final int ID_FIELD_HEIGHTTEXT=8; |
109 |
private final int ID_FIELD_ROTATIONTEXT=9; |
110 |
|
111 |
VectorialUniqueValueLegend defaultLegend; |
112 |
private String path; |
113 |
private File m_Fich; |
114 |
|
115 |
private DxfFile.EntityFactory featureMaker;
|
116 |
private DxfFile dxfFeatureFile;
|
117 |
private IObjList.vector features;
|
118 |
private DriverAttributes attr = new DriverAttributes(); |
119 |
|
120 |
/**
|
121 |
* Habilita la utilizaci?n del lector del HEADER del DXF.
|
122 |
*/
|
123 |
private DxfFile.VarSettings headerManager;
|
124 |
|
125 |
/* (non-Javadoc)
|
126 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
|
127 |
*/
|
128 |
public void open(File f) throws IOException { |
129 |
m_Fich = f; |
130 |
} |
131 |
|
132 |
public void initialize() throws IOException { |
133 |
float heightText = 10; |
134 |
|
135 |
attr.setLoadedInMemory(true);
|
136 |
|
137 |
IProjection proj = ProjectionPool.get("EPSG:23030");
|
138 |
featureMaker = new DxfFeatureMaker(proj);
|
139 |
dxfFeatureFile = new DxfFile(proj, m_Fich.getAbsolutePath(), featureMaker);
|
140 |
dxfFeatureFile.load(); |
141 |
features = (IObjList.vector)((DxfFeatureMaker)featureMaker).getObjects(); |
142 |
if (!featureMaker.isDxf3DFile()) {
|
143 |
Feature[] features2D = new Feature[features.size()]; |
144 |
for (int i=0;i<features.size();i++) { |
145 |
Feature fea = (Feature)features.get(i); |
146 |
if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
147 |
Point point = (Point)fea.getGeometry(); |
148 |
Point point2 = new Point(); |
149 |
for (int j=0;j<point.pointNr();j++) { |
150 |
point2.add(point.get(j)); |
151 |
} |
152 |
point2.setTextPoint(point.isTextPoint()); |
153 |
fea.setGeometry(point2); |
154 |
features2D[i] = fea; |
155 |
//} else if (fea.getGeometry() instanceof InsPoint3D) {
|
156 |
// InsPoint insPoint = (InsPoint)fea.getGeometry();
|
157 |
// InsPoint insPoint2 = new InsPoint();
|
158 |
// for (int j=0;j<insPoint.pointNr();j++) {
|
159 |
// insPoint2.add(insPoint.get(j));
|
160 |
// }
|
161 |
// fea.setGeometry(insPoint2);
|
162 |
// features2D[i] = fea;
|
163 |
} else if (fea.getGeometry() instanceof LineString3D) { |
164 |
LineString lineString = (LineString)fea.getGeometry(); |
165 |
LineString lineString2 = new LineString();
|
166 |
for (int j=0;j<lineString.pointNr();j++) { |
167 |
lineString2.add(lineString.get(j)); |
168 |
} |
169 |
fea.setGeometry(lineString2); |
170 |
features2D[i] = fea; |
171 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
172 |
Polygon polygon = (Polygon)fea.getGeometry(); |
173 |
Polygon polygon2 = new Polygon(); |
174 |
for (int j=0;j<polygon.pointNr();j++) { |
175 |
polygon2.add(polygon.get(j)); |
176 |
} |
177 |
fea.setGeometry(polygon2); |
178 |
features2D[i] = fea; |
179 |
} |
180 |
} |
181 |
features.clear(); |
182 |
for (int i=0;i<features2D.length;i++) { |
183 |
features.add(features2D[i]); |
184 |
} |
185 |
} |
186 |
//String acadVersion = (String)((DxfHeaderManager)headerManager).getAcadVersion();
|
187 |
//System.out.println("initialize(): acadVersion = " + acadVersion);
|
188 |
|
189 |
int nAtt = featureMaker.getAttributes().size();
|
190 |
|
191 |
// Campos de las MemoryLayer:
|
192 |
Value[] auxRow = new Value[10+nAtt]; |
193 |
ArrayList arrayFields = new ArrayList(); |
194 |
arrayFields.add("ID");
|
195 |
arrayFields.add("FShape");
|
196 |
arrayFields.add("Entity");
|
197 |
arrayFields.add("Layer");
|
198 |
arrayFields.add("Color");
|
199 |
arrayFields.add("Elevation");
|
200 |
arrayFields.add("Thickness");
|
201 |
arrayFields.add("Text");
|
202 |
arrayFields.add("HeightText");
|
203 |
arrayFields.add("RotationText");
|
204 |
for (int i=0;i<nAtt;i++) { |
205 |
String att[] = new String[2]; |
206 |
att = (String[])featureMaker.getAttributes().get(i); |
207 |
arrayFields.add(att[0]);
|
208 |
} |
209 |
|
210 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
211 |
|
212 |
for (int i=0;i<features.size();i++) { |
213 |
|
214 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
|
215 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
|
216 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
217 |
|
218 |
Feature fea = (Feature)features.get(i); |
219 |
if (fea.getGeometry() instanceof Point && !(fea.getGeometry() instanceof org.cresques.px.gml.Point3D)) { |
220 |
Point point = (Point)fea.getGeometry(); |
221 |
Point2D pto = new Point2D.Double(); |
222 |
pto = (Point2D)point.get(0); |
223 |
FShape nuevoShp; |
224 |
if (point.isTextPoint()) {
|
225 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
226 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
227 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity"))); |
228 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer"))); |
229 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
230 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
231 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(new String(fea.getProp("text"))); |
232 |
heightText = Float.parseFloat(fea.getProp("textHeight")); |
233 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText); |
234 |
double auxR = Double.parseDouble(fea.getProp("textRotation")); |
235 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(auxR); |
236 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
237 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
238 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
239 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
240 |
// Attributes
|
241 |
for (int j=0;j<nAtt;j++) { |
242 |
String[] attributes = new String[2]; |
243 |
attributes = (String[])featureMaker.getAttributes().get(j); |
244 |
auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1])); |
245 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
246 |
auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
247 |
} |
248 |
} |
249 |
nuevoShp = new FPoint2D(pto.getX(),pto.getY());
|
250 |
addShape(nuevoShp, auxRow); |
251 |
} else {
|
252 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
253 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
254 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity"))); |
255 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer"))); |
256 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
257 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
258 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
259 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
260 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
261 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
262 |
// Attributes
|
263 |
for (int j=0;j<nAtt;j++) { |
264 |
String[] attributes = new String[2]; |
265 |
attributes = (String[])featureMaker.getAttributes().get(j); |
266 |
auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1])); |
267 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
268 |
auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
269 |
} |
270 |
} |
271 |
nuevoShp = new FPoint2D(pto.getX(),pto.getY());
|
272 |
addShape(nuevoShp, auxRow); |
273 |
} |
274 |
} else if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
275 |
org.cresques.px.gml.Point3D point = (org.cresques.px.gml.Point3D)fea.getGeometry(); |
276 |
Point3D pto = new Point3D();
|
277 |
pto = (Point3D)point.getPoint3D(0);
|
278 |
FShape nuevoShp; |
279 |
if (point.isTextPoint()) {
|
280 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
281 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
282 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity"))); |
283 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer"))); |
284 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
285 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
286 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(new String(fea.getProp("text"))); |
287 |
heightText = Float.parseFloat(fea.getProp("textHeight")); |
288 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText); |
289 |
double auxR = Double.parseDouble(fea.getProp("textRotation")); |
290 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(auxR); |
291 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
292 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
293 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
294 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
295 |
// Attributes
|
296 |
for (int j=0;j<nAtt;j++) { |
297 |
String[] attributes = new String[2]; |
298 |
attributes = (String[])featureMaker.getAttributes().get(j); |
299 |
auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1])); |
300 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
301 |
auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
302 |
} |
303 |
} |
304 |
nuevoShp = new FPoint3D(pto.getX(),pto.getY(),pto.getZ());
|
305 |
addShape(nuevoShp, auxRow); |
306 |
} else {
|
307 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
308 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
309 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity"))); |
310 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer"))); |
311 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
312 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
313 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
314 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
315 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
316 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
317 |
// Attributes
|
318 |
for (int j=0;j<nAtt;j++) { |
319 |
String[] attributes = new String[2]; |
320 |
attributes = (String[])featureMaker.getAttributes().get(j); |
321 |
auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1])); |
322 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
323 |
auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
324 |
} |
325 |
} |
326 |
nuevoShp = new FPoint3D(pto.getX(),pto.getY(),pto.getZ());
|
327 |
addShape(nuevoShp, auxRow); |
328 |
} |
329 |
/*} else if (fea.getGeometry() instanceof InsPoint && !(fea.getGeometry() instanceof InsPoint3D)) {
|
330 |
InsPoint insPoint = (InsPoint)fea.getGeometry();
|
331 |
Point2D pto = new Point2D.Double();
|
332 |
pto = (Point2D)insPoint.get(0);
|
333 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
334 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("PointZ"));
|
335 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
|
336 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
|
337 |
int auxInt = Integer.parseInt(fea.getProp("color"));
|
338 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
339 |
double auxE = Double.parseDouble(fea.getProp("elevation"));
|
340 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
341 |
// Attributes
|
342 |
for (int j=0;j<nAtt;j++) {
|
343 |
String[] attributes = new String[2];
|
344 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
345 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
346 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
347 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
348 |
}
|
349 |
}
|
350 |
FShape nuevoShp = new FPoint2D(pto.getX(),pto.getY());
|
351 |
addShape(nuevoShp, auxRow);
|
352 |
} else if (fea.getGeometry() instanceof InsPoint3D) {
|
353 |
InsPoint3D insPoint = (InsPoint3D)fea.getGeometry();
|
354 |
Point3D pto = new Point3D();
|
355 |
pto = (Point3D)insPoint.getPoint3D(0);
|
356 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
357 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("PointZ"));
|
358 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
|
359 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
|
360 |
int auxInt = Integer.parseInt(fea.getProp("color"));
|
361 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
362 |
double auxE = Double.parseDouble(fea.getProp("elevation"));
|
363 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
364 |
// Attributes
|
365 |
for (int j=0;j<nAtt;j++) {
|
366 |
String[] attributes = new String[2];
|
367 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
368 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
369 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
370 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
371 |
}
|
372 |
}
|
373 |
FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),pto.getZ());
|
374 |
addShape(nuevoShp, auxRow);*/
|
375 |
} else if (fea.getGeometry() instanceof LineString && !(fea.getGeometry() instanceof LineString3D)) { |
376 |
GeneralPathX genPathX = new GeneralPathX();
|
377 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr()]; |
378 |
for (int j=0; j<fea.getGeometry().pointNr(); j++) { |
379 |
pts[j] = (Point2D)fea.getGeometry().get(j);
|
380 |
} |
381 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
382 |
for (int j=1;j<pts.length;j++) { |
383 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
384 |
} |
385 |
//double[] elevations = new double[pts.length];
|
386 |
//for (int j=0;j<pts.length;j++) {
|
387 |
// elevations[j]=pts[j].getZ();
|
388 |
//}
|
389 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
390 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
391 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity"))); |
392 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer"))); |
393 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
394 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
395 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
396 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
397 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
398 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
399 |
// Attributes
|
400 |
for (int j=0;j<nAtt;j++) { |
401 |
String[] attributes = new String[2]; |
402 |
attributes = (String[])featureMaker.getAttributes().get(j); |
403 |
auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1])); |
404 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
405 |
auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
406 |
} |
407 |
} |
408 |
FShape nuevoShp = new FPolyline2D(genPathX);
|
409 |
addShape(nuevoShp, auxRow); |
410 |
} else if (fea.getGeometry() instanceof LineString3D) { |
411 |
GeneralPathX genPathX = new GeneralPathX();
|
412 |
Point3D[] pts = new Point3D[fea.getGeometry().pointNr()]; |
413 |
for (int j=0; j<fea.getGeometry().pointNr(); j++) { |
414 |
pts[j] = ((LineString3D)fea.getGeometry()).getPoint3D(j); |
415 |
} |
416 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
417 |
for (int j=1;j<pts.length;j++) { |
418 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
419 |
} |
420 |
double[] elevations = new double[pts.length]; |
421 |
for (int j=0;j<pts.length;j++) { |
422 |
elevations[j]=pts[j].getZ(); |
423 |
} |
424 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
425 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
426 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity"))); |
427 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer"))); |
428 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
429 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
430 |
if (fea.getProp("elevation")!=null) { |
431 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
432 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
433 |
} |
434 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
435 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
436 |
// Attributes
|
437 |
for (int j=0;j<nAtt;j++) { |
438 |
String[] attributes = new String[2]; |
439 |
attributes = (String[])featureMaker.getAttributes().get(j); |
440 |
auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1])); |
441 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
442 |
auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
443 |
} |
444 |
} |
445 |
FShape nuevoShp = new FPolyline3D(genPathX, elevations);
|
446 |
addShape(nuevoShp, auxRow); |
447 |
} else if (fea.getGeometry() instanceof Polygon && !(fea.getGeometry() instanceof Polygon3D)) { |
448 |
GeneralPathX genPathX = new GeneralPathX();
|
449 |
// 050112: A?ado una posici?n m?s para el punto que cierra y
|
450 |
// creo el objeto firstPt.
|
451 |
Point2D firstPt = new Point2D.Double(); |
452 |
firstPt = (Point2D)fea.getGeometry().get(0); |
453 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr()+1]; |
454 |
for (int j=0; j<fea.getGeometry().pointNr(); j++) { |
455 |
pts[j] = (Point2D)fea.getGeometry().get(j);
|
456 |
} |
457 |
// 050112: A?ado el primer punto al final para cerrar los pol?gonos.
|
458 |
pts[fea.getGeometry().pointNr()] = firstPt; |
459 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
460 |
for (int j=1; j < pts.length; j++) { |
461 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
462 |
} |
463 |
//double[] elevations = new double[pts.length];
|
464 |
//for (int j=0;j<pts.length;j++) {
|
465 |
// elevations[j]=pts[j].getZ();
|
466 |
//}
|
467 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
468 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolygon2D")); |
469 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity"))); |
470 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer"))); |
471 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
472 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
473 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
474 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
475 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
476 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
477 |
// Attributes
|
478 |
for (int j=0;j<nAtt;j++) { |
479 |
String[] attributes = new String[2]; |
480 |
attributes = (String[])featureMaker.getAttributes().get(j); |
481 |
auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1])); |
482 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
483 |
auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
484 |
} |
485 |
} |
486 |
FShape nuevoShp = new FPolygon2D(genPathX);
|
487 |
addShape(nuevoShp, auxRow); |
488 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
489 |
GeneralPathX genPathX = new GeneralPathX();
|
490 |
// 050112: A?ado una posici?n m?s para el punto que cierra y
|
491 |
// creo el objeto firstPt.
|
492 |
Point3D firstPt = new Point3D();
|
493 |
firstPt = (Point3D)((Polygon3D)fea.getGeometry()).getPoint3D(0);
|
494 |
Point3D[] pts = new Point3D[fea.getGeometry().pointNr()+1]; |
495 |
for (int j=0; j<fea.getGeometry().pointNr(); j++) { |
496 |
pts[j] = (Point3D)((Polygon3D)fea.getGeometry()).getPoint3D(j); |
497 |
} |
498 |
// 050112: A?ado el primer punto al final para cerrar los pol?gonos.
|
499 |
pts[fea.getGeometry().pointNr()] = firstPt; |
500 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
501 |
for (int j=1; j < pts.length; j++) { |
502 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
503 |
} |
504 |
double[] elevations = new double[pts.length]; |
505 |
for (int j=0;j<pts.length;j++) { |
506 |
elevations[j]=pts[j].getZ(); |
507 |
} |
508 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
509 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolygon3D")); |
510 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity"))); |
511 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer"))); |
512 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
513 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
514 |
if (fea.getProp("elevation")!=null) { |
515 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
516 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
517 |
} |
518 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
519 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
520 |
// Attributes
|
521 |
for (int j=0;j<nAtt;j++) { |
522 |
String[] attributes = new String[2]; |
523 |
attributes = (String[])featureMaker.getAttributes().get(j); |
524 |
auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1])); |
525 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
526 |
auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
527 |
} |
528 |
} |
529 |
FShape nuevoShp = new FPolygon3D(genPathX, elevations);
|
530 |
addShape(nuevoShp, auxRow); |
531 |
} else {
|
532 |
//System.out.println("Detectado feature desconocido");
|
533 |
} |
534 |
} |
535 |
|
536 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
537 |
defaultLegend.setFieldName("Color");
|
538 |
defaultLegend.setLabelField("Text");
|
539 |
defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
|
540 |
defaultLegend.getDefaultSymbol().setShapeVisible(false);
|
541 |
defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
|
542 |
defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9)); |
543 |
defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
|
544 |
defaultLegend.getDefaultSymbol().setFontSize(heightText); |
545 |
defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
546 |
defaultLegend.getDefaultSymbol().setSize(3);
|
547 |
defaultLegend.getDefaultSymbol().setSizeInPixels(true);
|
548 |
|
549 |
defaultLegend.setLabelHeightField("HeightText");
|
550 |
defaultLegend.setLabelRotationField("RotationText");
|
551 |
|
552 |
ObjectDriver rs = this;
|
553 |
IntValue clave; |
554 |
FSymbol theSymbol = null;
|
555 |
|
556 |
try {
|
557 |
// TODO: Provisional hasta que cambiemos los s?mbolos.
|
558 |
/* BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
|
559 |
Graphics2D big = bi.createGraphics();
|
560 |
Color color=new Color(0,0,0,0);
|
561 |
big.setBackground(color);
|
562 |
big.clearRect(0, 0, 5, 5);
|
563 |
Paint fillProv = null;
|
564 |
Rectangle2D rProv = new Rectangle();
|
565 |
rProv.setFrame(0, 0,5,5);
|
566 |
fillProv = new TexturePaint(bi,rProv); */
|
567 |
|
568 |
for (long j = 0; j < rs.getRowCount(); j++) |
569 |
{ |
570 |
clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR); |
571 |
if (defaultLegend.getSymbolByValue(clave) == null) |
572 |
{ |
573 |
theSymbol = new FSymbol(getShapeType());
|
574 |
theSymbol.setDescription(clave.toString()); |
575 |
theSymbol.setColor(AcadColor.getColor(clave.getValue())); |
576 |
// theSymbol.setFill(fillProv);
|
577 |
// 050202, jmorell: Asigna los colores de Autocad a los bordes
|
578 |
// de los pol?gonos.
|
579 |
theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue())); |
580 |
|
581 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
582 |
theSymbol.setSize(3);
|
583 |
theSymbol.setSizeInPixels(true);
|
584 |
|
585 |
defaultLegend.addSymbol(clave, theSymbol); |
586 |
} |
587 |
} // for
|
588 |
} catch (DriverException e) {
|
589 |
e.printStackTrace(); |
590 |
throw new IOException("Error al poner la leyenda por defecto en el DXF"); |
591 |
} |
592 |
} |
593 |
|
594 |
/* (non-Javadoc)
|
595 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
|
596 |
*/
|
597 |
public boolean accept(File f) { |
598 |
return f.getName().toUpperCase().endsWith("DXF"); |
599 |
} |
600 |
|
601 |
/* (non-Javadoc)
|
602 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
|
603 |
*/
|
604 |
public int getShapeType() { |
605 |
return FShape.MULTI;
|
606 |
} |
607 |
|
608 |
/* (non-Javadoc)
|
609 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
|
610 |
*/
|
611 |
public String getName() { |
612 |
return "gvSIG DXF Memory Driver"; |
613 |
} |
614 |
|
615 |
/* (non-Javadoc)
|
616 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
617 |
*/
|
618 |
public Legend getDefaultLegend() {
|
619 |
return defaultLegend;
|
620 |
} |
621 |
|
622 |
/* (non-Javadoc)
|
623 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
624 |
*/
|
625 |
public DriverAttributes getDriverAttributes() {
|
626 |
return attr;
|
627 |
} |
628 |
/**
|
629 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
630 |
*/
|
631 |
public int[] getPrimaryKeys() throws DriverException { |
632 |
return null; |
633 |
} |
634 |
|
635 |
/**
|
636 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
637 |
*/
|
638 |
public void write(DataWare arg0) throws DriverException { |
639 |
// TODO Auto-generated method stub
|
640 |
|
641 |
} |
642 |
|
643 |
|
644 |
} |