svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dxf / DXFMemoryDriver.java @ 6164
History | View | Annotate | Download (31.9 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.FileInputStream; |
53 |
import java.io.FileNotFoundException; |
54 |
import java.io.FileOutputStream; |
55 |
import java.io.IOException; |
56 |
import java.nio.channels.FileChannel; |
57 |
import java.util.ArrayList; |
58 |
import java.util.Properties; |
59 |
|
60 |
import org.cresques.cts.IProjection; |
61 |
import org.cresques.geo.Point3D; |
62 |
import org.cresques.io.DxfFile; |
63 |
import org.cresques.px.IObjList; |
64 |
import org.cresques.px.dxf.AcadColor; |
65 |
import org.cresques.px.dxf.DxfFeatureMaker; |
66 |
import org.cresques.px.dxf.DxfHeaderManager; |
67 |
import org.cresques.px.gml.Feature; |
68 |
import org.cresques.px.gml.LineString; |
69 |
import org.cresques.px.gml.LineString3D; |
70 |
import org.cresques.px.gml.Point; |
71 |
import org.cresques.px.gml.Polygon; |
72 |
import org.cresques.px.gml.Polygon3D; |
73 |
|
74 |
import com.hardcode.gdbms.driver.DriverUtilities; |
75 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
76 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
77 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
78 |
import com.hardcode.gdbms.engine.values.IntValue; |
79 |
import com.hardcode.gdbms.engine.values.Value; |
80 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
81 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
82 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
83 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
84 |
import com.iver.cit.gvsig.fmap.core.FPolygon3D; |
85 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
86 |
import com.iver.cit.gvsig.fmap.core.FPolyline3D; |
87 |
import com.iver.cit.gvsig.fmap.core.FShape; |
88 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
89 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
90 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
91 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
92 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
93 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
94 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
95 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
96 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
97 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
98 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
99 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
100 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
101 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
102 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
103 |
import com.iver.cit.gvsig.fmap.edition.writers.dxf.DxfFieldsMapping; |
104 |
import com.iver.cit.gvsig.fmap.edition.writers.dxf.DxfWriter; |
105 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
106 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
107 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
108 |
|
109 |
/**
|
110 |
* @author jmorell (jose.morell@gmail.com)
|
111 |
* @version 29-dic-2004
|
112 |
*/
|
113 |
public class DXFMemoryDriver extends MemoryDriver implements |
114 |
VectorialFileDriver, WithDefaultLegend, ISpatialWriter, IWriteable { |
115 |
private static String tempDirectoryPath = System |
116 |
.getProperty("java.io.tmpdir");
|
117 |
|
118 |
private final int ID_FIELD_ID = 0; |
119 |
|
120 |
private final int ID_FIELD_FSHAPE = 1; |
121 |
|
122 |
private final int ID_FIELD_ENTITY = 2; |
123 |
|
124 |
private final int ID_FIELD_LAYER = 3; |
125 |
|
126 |
private final int ID_FIELD_COLOR = 4; |
127 |
|
128 |
private final int ID_FIELD_ELEVATION = 5; |
129 |
|
130 |
private final int ID_FIELD_THICKNESS = 6; |
131 |
|
132 |
private final int ID_FIELD_TEXT = 7; |
133 |
|
134 |
private final int ID_FIELD_HEIGHTTEXT = 8; |
135 |
|
136 |
private final int ID_FIELD_ROTATIONTEXT = 9; |
137 |
|
138 |
private DxfWriter dxfWriter = new DxfWriter(); |
139 |
|
140 |
private File fTemp; |
141 |
|
142 |
VectorialUniqueValueLegend defaultLegend; |
143 |
|
144 |
private String path; |
145 |
|
146 |
private File m_Fich; |
147 |
|
148 |
private DxfFile.EntityFactory featureMaker;
|
149 |
|
150 |
private DxfFile dxfFeatureFile;
|
151 |
|
152 |
private IObjList.vector features;
|
153 |
|
154 |
private DriverAttributes attr = new DriverAttributes(); |
155 |
|
156 |
/**
|
157 |
* Habilita la utilizaci?n del lector del HEADER del DXF.
|
158 |
*/
|
159 |
private DxfFile.VarSettings headerManager;
|
160 |
|
161 |
/*
|
162 |
* (non-Javadoc)
|
163 |
*
|
164 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
|
165 |
*/
|
166 |
public void open(File f) throws IOException { |
167 |
m_Fich = f; |
168 |
} |
169 |
|
170 |
public void initialize() throws IOException { |
171 |
float heightText = 10; |
172 |
|
173 |
attr.setLoadedInMemory(true);
|
174 |
|
175 |
IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
176 |
featureMaker = new DxfFeatureMaker(proj);
|
177 |
headerManager = new DxfHeaderManager();
|
178 |
dxfFeatureFile = new DxfFile(proj, m_Fich.getAbsolutePath(),
|
179 |
featureMaker, headerManager); |
180 |
dxfFeatureFile.load(); |
181 |
features = (IObjList.vector) ((DxfFeatureMaker) featureMaker) |
182 |
.getObjects(); |
183 |
String acadVersion = (String) ((DxfHeaderManager) headerManager) |
184 |
.getAcadVersion(); |
185 |
System.out.println("initialize(): acadVersion = " + acadVersion); |
186 |
if (!featureMaker.isDxf3DFile() && !headerManager.isWritedDxf3D()) { // y no |
187 |
// est?n
|
188 |
// todos
|
189 |
// a
|
190 |
// 9999
|
191 |
Feature[] features2D = new Feature[features.size()]; |
192 |
for (int i = 0; i < features.size(); i++) { |
193 |
Feature fea = (Feature) features.get(i); |
194 |
if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
195 |
Point point = (Point) fea.getGeometry(); |
196 |
Point point2 = new Point(); |
197 |
for (int j = 0; j < point.pointNr(); j++) { |
198 |
point2.add(point.get(j)); |
199 |
} |
200 |
point2.setTextPoint(point.isTextPoint()); |
201 |
fea.setGeometry(point2); |
202 |
features2D[i] = fea; |
203 |
// } else if (fea.getGeometry() instanceof InsPoint3D) {
|
204 |
// InsPoint insPoint = (InsPoint)fea.getGeometry();
|
205 |
// InsPoint insPoint2 = new InsPoint();
|
206 |
// for (int j=0;j<insPoint.pointNr();j++) {
|
207 |
// insPoint2.add(insPoint.get(j));
|
208 |
// }
|
209 |
// fea.setGeometry(insPoint2);
|
210 |
// features2D[i] = fea;
|
211 |
} else if (fea.getGeometry() instanceof LineString3D) { |
212 |
LineString lineString = (LineString) fea.getGeometry(); |
213 |
LineString lineString2 = new LineString();
|
214 |
for (int j = 0; j < lineString.pointNr(); j++) { |
215 |
lineString2.add(lineString.get(j)); |
216 |
} |
217 |
fea.setGeometry(lineString2); |
218 |
features2D[i] = fea; |
219 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
220 |
Polygon polygon = (Polygon) fea.getGeometry(); |
221 |
Polygon polygon2 = new Polygon(); |
222 |
for (int j = 0; j < polygon.pointNr(); j++) { |
223 |
polygon2.add(polygon.get(j)); |
224 |
} |
225 |
fea.setGeometry(polygon2); |
226 |
features2D[i] = fea; |
227 |
} |
228 |
} |
229 |
features.clear(); |
230 |
for (int i = 0; i < features2D.length; i++) { |
231 |
features.add(features2D[i]); |
232 |
} |
233 |
} |
234 |
// String acadVersion =
|
235 |
// (String)((DxfHeaderManager)headerManager).getAcadVersion();
|
236 |
// System.out.println("initialize(): acadVersion = " + acadVersion);
|
237 |
|
238 |
int nAtt = featureMaker.getAttributes().size();
|
239 |
|
240 |
// Campos de las MemoryLayer:
|
241 |
Value[] auxRow = new Value[10 + nAtt]; |
242 |
ArrayList arrayFields = new ArrayList(); |
243 |
arrayFields.add("ID");
|
244 |
arrayFields.add("FShape");
|
245 |
arrayFields.add("Entity");
|
246 |
arrayFields.add("Layer");
|
247 |
arrayFields.add("Color");
|
248 |
arrayFields.add("Elevation");
|
249 |
arrayFields.add("Thickness");
|
250 |
arrayFields.add("Text");
|
251 |
arrayFields.add("HeightText");
|
252 |
arrayFields.add("RotationText");
|
253 |
for (int i = 0; i < nAtt; i++) { |
254 |
String att[] = new String[2]; |
255 |
att = (String[]) featureMaker.getAttributes().get(i); |
256 |
arrayFields.add(att[0]);
|
257 |
} |
258 |
|
259 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
260 |
|
261 |
for (int i = 0; i < features.size(); i++) { |
262 |
|
263 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
|
264 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
|
265 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
266 |
|
267 |
Feature fea = (Feature) features.get(i); |
268 |
if (fea.getGeometry() instanceof Point |
269 |
&& !(fea.getGeometry() instanceof org.cresques.px.gml.Point3D)) {
|
270 |
Point point = (Point) fea.getGeometry(); |
271 |
Point2D pto = new Point2D.Double(); |
272 |
pto = (Point2D) point.get(0); |
273 |
FShape nuevoShp; |
274 |
if (point.isTextPoint()) {
|
275 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
276 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory |
277 |
.createValue(new String("FPoint2D")); |
278 |
auxRow[ID_FIELD_ENTITY] = ValueFactory |
279 |
.createValue(new String(fea.getProp("dxfEntity"))); |
280 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
281 |
.createValue(new String(fea.getProp("layer"))); |
282 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
283 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
284 |
auxRow[ID_FIELD_TEXT] = ValueFactory |
285 |
.createValue(new String(fea.getProp("text"))); |
286 |
heightText = Float.parseFloat(fea.getProp("textHeight")); |
287 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
288 |
.createValue(heightText); |
289 |
double auxR = Double.parseDouble(fea |
290 |
.getProp("textRotation"));
|
291 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
292 |
.createValue(auxR); |
293 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
294 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
295 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
296 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
297 |
// Attributes
|
298 |
for (int j = 0; j < nAtt; j++) { |
299 |
String[] attributes = new String[2]; |
300 |
attributes = (String[]) featureMaker.getAttributes() |
301 |
.get(j); |
302 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
303 |
(String) attributes[1])); |
304 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
305 |
auxRow[10 + j] = ValueFactory
|
306 |
.createValue(new String(fea |
307 |
.getProp(attributes[0])));
|
308 |
} |
309 |
} |
310 |
nuevoShp = new FPoint2D(pto.getX(), pto.getY());
|
311 |
addShape(nuevoShp, auxRow); |
312 |
} else {
|
313 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
314 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory |
315 |
.createValue(new String("FPoint2D")); |
316 |
auxRow[ID_FIELD_ENTITY] = ValueFactory |
317 |
.createValue(new String(fea.getProp("dxfEntity"))); |
318 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
319 |
.createValue(new String(fea.getProp("layer"))); |
320 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
321 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
322 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
323 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
324 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
325 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
326 |
// Attributes
|
327 |
for (int j = 0; j < nAtt; j++) { |
328 |
String[] attributes = new String[2]; |
329 |
attributes = (String[]) featureMaker.getAttributes() |
330 |
.get(j); |
331 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
332 |
(String) attributes[1])); |
333 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
334 |
auxRow[10 + j] = ValueFactory
|
335 |
.createValue(new String(fea |
336 |
.getProp(attributes[0])));
|
337 |
} |
338 |
} |
339 |
nuevoShp = new FPoint2D(pto.getX(), pto.getY());
|
340 |
addShape(nuevoShp, auxRow); |
341 |
} |
342 |
} else if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
343 |
org.cresques.px.gml.Point3D point = (org.cresques.px.gml.Point3D) fea |
344 |
.getGeometry(); |
345 |
Point3D pto = new Point3D();
|
346 |
pto = (Point3D) point.getPoint3D(0);
|
347 |
FShape nuevoShp; |
348 |
if (point.isTextPoint()) {
|
349 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
350 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory |
351 |
.createValue(new String("FPoint3D")); |
352 |
auxRow[ID_FIELD_ENTITY] = ValueFactory |
353 |
.createValue(new String(fea.getProp("dxfEntity"))); |
354 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
355 |
.createValue(new String(fea.getProp("layer"))); |
356 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
357 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
358 |
auxRow[ID_FIELD_TEXT] = ValueFactory |
359 |
.createValue(new String(fea.getProp("text"))); |
360 |
heightText = Float.parseFloat(fea.getProp("textHeight")); |
361 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
362 |
.createValue(heightText); |
363 |
double auxR = Double.parseDouble(fea |
364 |
.getProp("textRotation"));
|
365 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
366 |
.createValue(auxR); |
367 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
368 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
369 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
370 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
371 |
// Attributes
|
372 |
for (int j = 0; j < nAtt; j++) { |
373 |
String[] attributes = new String[2]; |
374 |
attributes = (String[]) featureMaker.getAttributes() |
375 |
.get(j); |
376 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
377 |
(String) attributes[1])); |
378 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
379 |
auxRow[10 + j] = ValueFactory
|
380 |
.createValue(new String(fea |
381 |
.getProp(attributes[0])));
|
382 |
} |
383 |
} |
384 |
nuevoShp = new FPoint3D(pto.getX(), pto.getY(), pto.getZ());
|
385 |
addShape(nuevoShp, auxRow); |
386 |
} else {
|
387 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
388 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory |
389 |
.createValue(new String("FPoint3D")); |
390 |
auxRow[ID_FIELD_ENTITY] = ValueFactory |
391 |
.createValue(new String(fea.getProp("dxfEntity"))); |
392 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
393 |
.createValue(new String(fea.getProp("layer"))); |
394 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
395 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
396 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
397 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
398 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
399 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
400 |
// Attributes
|
401 |
for (int j = 0; j < nAtt; j++) { |
402 |
String[] attributes = new String[2]; |
403 |
attributes = (String[]) featureMaker.getAttributes() |
404 |
.get(j); |
405 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
406 |
(String) attributes[1])); |
407 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
408 |
auxRow[10 + j] = ValueFactory
|
409 |
.createValue(new String(fea |
410 |
.getProp(attributes[0])));
|
411 |
} |
412 |
} |
413 |
nuevoShp = new FPoint3D(pto.getX(), pto.getY(), pto.getZ());
|
414 |
addShape(nuevoShp, auxRow); |
415 |
} |
416 |
/*
|
417 |
* } else if (fea.getGeometry() instanceof InsPoint &&
|
418 |
* !(fea.getGeometry() instanceof InsPoint3D)) { InsPoint
|
419 |
* insPoint = (InsPoint)fea.getGeometry(); Point2D pto = new
|
420 |
* Point2D.Double(); pto = (Point2D)insPoint.get(0);
|
421 |
* auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
422 |
* auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new
|
423 |
* String("PointZ")); auxRow[ID_FIELD_ENTITY] =
|
424 |
* ValueFactory.createValue(new
|
425 |
* String(fea.getProp("dxfEntity"))); auxRow[ID_FIELD_LAYER] =
|
426 |
* ValueFactory.createValue(new String(fea.getProp("layer")));
|
427 |
* int auxInt = Integer.parseInt(fea.getProp("color"));
|
428 |
* auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
429 |
* double auxE = Double.parseDouble(fea.getProp("elevation"));
|
430 |
* auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); //
|
431 |
* Attributes for (int j=0;j<nAtt;j++) { String[] attributes =
|
432 |
* new String[2]; attributes =
|
433 |
* (String[])featureMaker.getAttributes().get(j); auxRow[9+j] =
|
434 |
* ValueFactory.createValue(new String((String)attributes[1]));
|
435 |
* if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
436 |
* auxRow[9+j] = ValueFactory.createValue(new
|
437 |
* String(fea.getProp(attributes[0]))); } } FShape nuevoShp =
|
438 |
* new FPoint2D(pto.getX(),pto.getY()); addShape(nuevoShp,
|
439 |
* auxRow); } else if (fea.getGeometry() instanceof InsPoint3D) {
|
440 |
* InsPoint3D insPoint = (InsPoint3D)fea.getGeometry(); Point3D
|
441 |
* pto = new Point3D(); pto = (Point3D)insPoint.getPoint3D(0);
|
442 |
* auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
443 |
* auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new
|
444 |
* String("PointZ")); auxRow[ID_FIELD_ENTITY] =
|
445 |
* ValueFactory.createValue(new
|
446 |
* String(fea.getProp("dxfEntity"))); auxRow[ID_FIELD_LAYER] =
|
447 |
* ValueFactory.createValue(new String(fea.getProp("layer")));
|
448 |
* int auxInt = Integer.parseInt(fea.getProp("color"));
|
449 |
* auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
450 |
* double auxE = Double.parseDouble(fea.getProp("elevation"));
|
451 |
* auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); //
|
452 |
* Attributes for (int j=0;j<nAtt;j++) { String[] attributes =
|
453 |
* new String[2]; attributes =
|
454 |
* (String[])featureMaker.getAttributes().get(j); auxRow[9+j] =
|
455 |
* ValueFactory.createValue(new String((String)attributes[1]));
|
456 |
* if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
457 |
* auxRow[9+j] = ValueFactory.createValue(new
|
458 |
* String(fea.getProp(attributes[0]))); } } FShape nuevoShp =
|
459 |
* new FPoint3D(pto.getX(),pto.getY(),pto.getZ());
|
460 |
* addShape(nuevoShp, auxRow);
|
461 |
*/
|
462 |
} else if (fea.getGeometry() instanceof LineString |
463 |
&& !(fea.getGeometry() instanceof LineString3D)) {
|
464 |
GeneralPathX genPathX = new GeneralPathX();
|
465 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr()]; |
466 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
467 |
pts[j] = (Point2D) fea.getGeometry().get(j);
|
468 |
} |
469 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
470 |
for (int j = 1; j < pts.length; j++) { |
471 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
472 |
} |
473 |
// double[] elevations = new double[pts.length];
|
474 |
// for (int j=0;j<pts.length;j++) {
|
475 |
// elevations[j]=pts[j].getZ();
|
476 |
// }
|
477 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
478 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String( |
479 |
"FPolyline2D"));
|
480 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String( |
481 |
fea.getProp("dxfEntity")));
|
482 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String( |
483 |
fea.getProp("layer")));
|
484 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
485 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
486 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
487 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
488 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
489 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
490 |
// Attributes
|
491 |
for (int j = 0; j < nAtt; j++) { |
492 |
String[] attributes = new String[2]; |
493 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
494 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
495 |
(String) attributes[1])); |
496 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
497 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
498 |
fea.getProp(attributes[0])));
|
499 |
} |
500 |
} |
501 |
FShape nuevoShp = new FPolyline2D(genPathX);
|
502 |
addShape(nuevoShp, auxRow); |
503 |
} else if (fea.getGeometry() instanceof LineString3D) { |
504 |
GeneralPathX genPathX = new GeneralPathX();
|
505 |
Point3D[] pts = new Point3D[fea.getGeometry().pointNr()]; |
506 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
507 |
pts[j] = ((LineString3D) fea.getGeometry()).getPoint3D(j); |
508 |
} |
509 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
510 |
for (int j = 1; j < pts.length; j++) { |
511 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
512 |
} |
513 |
double[] elevations = new double[pts.length]; |
514 |
for (int j = 0; j < pts.length; j++) { |
515 |
elevations[j] = pts[j].getZ(); |
516 |
} |
517 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
518 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String( |
519 |
"FPolyline3D"));
|
520 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String( |
521 |
fea.getProp("dxfEntity")));
|
522 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String( |
523 |
fea.getProp("layer")));
|
524 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
525 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
526 |
if (fea.getProp("elevation") != null) { |
527 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
528 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
529 |
} |
530 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
531 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
532 |
// Attributes
|
533 |
for (int j = 0; j < nAtt; j++) { |
534 |
String[] attributes = new String[2]; |
535 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
536 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
537 |
(String) attributes[1])); |
538 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
539 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
540 |
fea.getProp(attributes[0])));
|
541 |
} |
542 |
} |
543 |
FShape nuevoShp = new FPolyline3D(genPathX, elevations);
|
544 |
addShape(nuevoShp, auxRow); |
545 |
} else if (fea.getGeometry() instanceof Polygon |
546 |
&& !(fea.getGeometry() instanceof Polygon3D)) {
|
547 |
GeneralPathX genPathX = new GeneralPathX();
|
548 |
// 050112: A?ado una posici?n m?s para el punto que cierra y
|
549 |
// creo el objeto firstPt.
|
550 |
Point2D firstPt = new Point2D.Double(); |
551 |
firstPt = (Point2D) fea.getGeometry().get(0); |
552 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr() + 1]; |
553 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
554 |
pts[j] = (Point2D) fea.getGeometry().get(j);
|
555 |
} |
556 |
// 050112: A?ado el primer punto al final para cerrar los
|
557 |
// pol?gonos.
|
558 |
pts[fea.getGeometry().pointNr()] = firstPt; |
559 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
560 |
for (int j = 1; j < pts.length; j++) { |
561 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
562 |
} |
563 |
// double[] elevations = new double[pts.length];
|
564 |
// for (int j=0;j<pts.length;j++) {
|
565 |
// elevations[j]=pts[j].getZ();
|
566 |
// }
|
567 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
568 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String( |
569 |
"FPolygon2D"));
|
570 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String( |
571 |
fea.getProp("dxfEntity")));
|
572 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String( |
573 |
fea.getProp("layer")));
|
574 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
575 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
576 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
577 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
578 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
579 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
580 |
// Attributes
|
581 |
for (int j = 0; j < nAtt; j++) { |
582 |
String[] attributes = new String[2]; |
583 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
584 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
585 |
(String) attributes[1])); |
586 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
587 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
588 |
fea.getProp(attributes[0])));
|
589 |
} |
590 |
} |
591 |
FShape nuevoShp = new FPolygon2D(genPathX);
|
592 |
addShape(nuevoShp, auxRow); |
593 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
594 |
GeneralPathX genPathX = new GeneralPathX();
|
595 |
// 050112: A?ado una posici?n m?s para el punto que cierra y
|
596 |
// creo el objeto firstPt.
|
597 |
Point3D firstPt = new Point3D();
|
598 |
firstPt = (Point3D) ((Polygon3D) fea.getGeometry()) |
599 |
.getPoint3D(0);
|
600 |
Point3D[] pts = new Point3D[fea.getGeometry().pointNr() + 1]; |
601 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
602 |
pts[j] = (Point3D) ((Polygon3D) fea.getGeometry()) |
603 |
.getPoint3D(j); |
604 |
} |
605 |
// 050112: A?ado el primer punto al final para cerrar los
|
606 |
// pol?gonos.
|
607 |
pts[fea.getGeometry().pointNr()] = firstPt; |
608 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
609 |
for (int j = 1; j < pts.length; j++) { |
610 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
611 |
} |
612 |
double[] elevations = new double[pts.length]; |
613 |
for (int j = 0; j < pts.length; j++) { |
614 |
elevations[j] = pts[j].getZ(); |
615 |
} |
616 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
617 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String( |
618 |
"FPolygon3D"));
|
619 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String( |
620 |
fea.getProp("dxfEntity")));
|
621 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String( |
622 |
fea.getProp("layer")));
|
623 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
624 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
625 |
if (fea.getProp("elevation") != null) { |
626 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
627 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
628 |
} |
629 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
630 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
631 |
// Attributes
|
632 |
for (int j = 0; j < nAtt; j++) { |
633 |
String[] attributes = new String[2]; |
634 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
635 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
636 |
(String) attributes[1])); |
637 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
638 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
639 |
fea.getProp(attributes[0])));
|
640 |
} |
641 |
} |
642 |
FShape nuevoShp = new FPolygon3D(genPathX, elevations);
|
643 |
addShape(nuevoShp, auxRow); |
644 |
} else {
|
645 |
// System.out.println("Detectado feature desconocido");
|
646 |
} |
647 |
} |
648 |
|
649 |
defaultLegend = LegendFactory |
650 |
.createVectorialUniqueValueLegend(getShapeType()); |
651 |
defaultLegend.setFieldName("Color");
|
652 |
defaultLegend.setLabelField("Text");
|
653 |
defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
|
654 |
defaultLegend.getDefaultSymbol().setShapeVisible(false);
|
655 |
defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
|
656 |
defaultLegend.getDefaultSymbol().setFont( |
657 |
new Font("SansSerif", Font.PLAIN, 9)); |
658 |
defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
|
659 |
defaultLegend.getDefaultSymbol().setFontSize(heightText); |
660 |
defaultLegend.getDefaultSymbol().setStyle( |
661 |
FConstant.SYMBOL_STYLE_DGNSPECIAL); |
662 |
defaultLegend.getDefaultSymbol().setSize(3);
|
663 |
defaultLegend.getDefaultSymbol().setSizeInPixels(true);
|
664 |
|
665 |
defaultLegend.setLabelHeightField("HeightText");
|
666 |
defaultLegend.setLabelRotationField("RotationText");
|
667 |
|
668 |
ObjectDriver rs = this;
|
669 |
IntValue clave; |
670 |
FSymbol theSymbol = null;
|
671 |
|
672 |
try {
|
673 |
// TODO: Provisional hasta que cambiemos los s?mbolos.
|
674 |
/*
|
675 |
* BufferedImage bi= new BufferedImage(5, 5,
|
676 |
* BufferedImage.TYPE_INT_ARGB); Graphics2D big =
|
677 |
* bi.createGraphics(); Color color=new Color(0,0,0,0);
|
678 |
* big.setBackground(color); big.clearRect(0, 0, 5, 5); Paint
|
679 |
* fillProv = null; Rectangle2D rProv = new Rectangle();
|
680 |
* rProv.setFrame(0, 0,5,5); fillProv = new TexturePaint(bi,rProv);
|
681 |
*/
|
682 |
|
683 |
for (long j = 0; j < rs.getRowCount(); j++) { |
684 |
clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR); |
685 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
686 |
theSymbol = new FSymbol(getShapeType());
|
687 |
theSymbol.setDescription(clave.toString()); |
688 |
theSymbol.setColor(AcadColor.getColor(clave.getValue())); |
689 |
// theSymbol.setFill(fillProv);
|
690 |
// 050202, jmorell: Asigna los colores de Autocad a los
|
691 |
// bordes
|
692 |
// de los pol?gonos.
|
693 |
theSymbol.setOutlineColor(AcadColor.getColor(clave |
694 |
.getValue())); |
695 |
|
696 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
697 |
theSymbol.setSize(3);
|
698 |
theSymbol.setSizeInPixels(true);
|
699 |
|
700 |
defaultLegend.addSymbol(clave, theSymbol); |
701 |
} |
702 |
} // for
|
703 |
} catch (DriverException e) {
|
704 |
e.printStackTrace(); |
705 |
throw new IOException( |
706 |
"Error al poner la leyenda por defecto en el DXF");
|
707 |
} |
708 |
} |
709 |
|
710 |
/*
|
711 |
* (non-Javadoc)
|
712 |
*
|
713 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
|
714 |
*/
|
715 |
public boolean accept(File f) { |
716 |
return f.getName().toUpperCase().endsWith("DXF"); |
717 |
} |
718 |
|
719 |
/*
|
720 |
* (non-Javadoc)
|
721 |
*
|
722 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
|
723 |
*/
|
724 |
public int getShapeType() { |
725 |
return FShape.MULTI;
|
726 |
} |
727 |
|
728 |
/*
|
729 |
* (non-Javadoc)
|
730 |
*
|
731 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
|
732 |
*/
|
733 |
public String getName() { |
734 |
return "gvSIG DXF Memory Driver"; |
735 |
} |
736 |
|
737 |
/*
|
738 |
* (non-Javadoc)
|
739 |
*
|
740 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
741 |
*/
|
742 |
public Legend getDefaultLegend() {
|
743 |
return defaultLegend;
|
744 |
} |
745 |
|
746 |
/*
|
747 |
* (non-Javadoc)
|
748 |
*
|
749 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
750 |
*/
|
751 |
public DriverAttributes getDriverAttributes() {
|
752 |
return attr;
|
753 |
} |
754 |
|
755 |
/**
|
756 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
757 |
*/
|
758 |
public int[] getPrimaryKeys() throws DriverException { |
759 |
return null; |
760 |
} |
761 |
|
762 |
/**
|
763 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
764 |
*/
|
765 |
public void write(DataWare arg0) throws DriverException { |
766 |
// TODO Auto-generated method stub
|
767 |
|
768 |
} |
769 |
|
770 |
/*
|
771 |
* (non-Javadoc)
|
772 |
*
|
773 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
774 |
*/
|
775 |
public void close() throws IOException { |
776 |
// TODO Auto-generated method stub
|
777 |
|
778 |
} |
779 |
|
780 |
public File getFile() { |
781 |
return m_Fich;
|
782 |
} |
783 |
|
784 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
785 |
return dxfWriter.canWriteGeometry(gvSIGgeometryType);
|
786 |
} |
787 |
|
788 |
public void initialize(ITableDefinition layerDef) throws EditionException { |
789 |
int aux = (int) (Math.random() * 1000); |
790 |
fTemp = new File(tempDirectoryPath + "/tmpDxf" + aux + ".dxf"); |
791 |
dxfWriter.setFile(fTemp); |
792 |
|
793 |
dxfWriter.initialize(layerDef); |
794 |
/*
|
795 |
* arrayFields.add("ID"); arrayFields.add("FShape");
|
796 |
* arrayFields.add("Entity"); arrayFields.add("Layer");
|
797 |
* arrayFields.add("Color"); arrayFields.add("Elevation");
|
798 |
* arrayFields.add("Thickness"); arrayFields.add("Text");
|
799 |
* arrayFields.add("HeightText"); arrayFields.add("RotationText");
|
800 |
*/
|
801 |
|
802 |
DxfFieldsMapping fieldsMapping = new DxfFieldsMapping();
|
803 |
fieldsMapping.setLayerField("Layer");
|
804 |
fieldsMapping.setColorField("Color");
|
805 |
fieldsMapping.setElevationField("Elevation");
|
806 |
fieldsMapping.setThicknessField("Thickness");
|
807 |
fieldsMapping.setTextField("Text");
|
808 |
fieldsMapping.setHeightText("HeightText");
|
809 |
fieldsMapping.setRotationText("Layer");
|
810 |
dxfWriter.setFieldMapping(fieldsMapping); |
811 |
dxfWriter.setProjection(((ILayerDefinition)layerDef).getProjection()); |
812 |
} |
813 |
|
814 |
public void preProcess() throws EditionException { |
815 |
dxfWriter.preProcess(); |
816 |
} |
817 |
|
818 |
public void process(IRowEdited row) throws EditionException { |
819 |
dxfWriter.process(row); |
820 |
} |
821 |
|
822 |
public void postProcess() throws EditionException { |
823 |
dxfWriter.postProcess(); |
824 |
try {
|
825 |
|
826 |
// close();
|
827 |
|
828 |
// Dxf
|
829 |
FileChannel fcinDxf = new FileInputStream(fTemp).getChannel(); |
830 |
FileChannel fcoutDxf = new FileOutputStream(m_Fich).getChannel(); |
831 |
DriverUtilities.copy(fcinDxf, fcoutDxf); |
832 |
|
833 |
// Borramos los temporales
|
834 |
fTemp.delete(); |
835 |
reLoad(); |
836 |
|
837 |
} catch (FileNotFoundException e) { |
838 |
e.printStackTrace(); |
839 |
throw new EditionException(e); |
840 |
} catch (IOException e) { |
841 |
e.printStackTrace(); |
842 |
throw new EditionException(e); |
843 |
} |
844 |
|
845 |
} |
846 |
|
847 |
public String getCapability(String capability) { |
848 |
return dxfWriter.getCapability(capability);
|
849 |
} |
850 |
|
851 |
public void setCapabilities(Properties capabilities) { |
852 |
dxfWriter.setCapabilities(capabilities); |
853 |
|
854 |
} |
855 |
|
856 |
public boolean canWriteAttribute(int sqlType) { |
857 |
return dxfWriter.canWriteAttribute(sqlType);
|
858 |
} |
859 |
|
860 |
/*
|
861 |
* (non-Javadoc)
|
862 |
*
|
863 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#reLoad()
|
864 |
*/
|
865 |
public void reLoad() throws IOException { |
866 |
super.reLoad();
|
867 |
try {
|
868 |
initialize(); |
869 |
} catch (IOException e) { |
870 |
e.printStackTrace(); |
871 |
throw new IOException("DXF: Error reloading " + path + " file."); |
872 |
} |
873 |
} |
874 |
|
875 |
public void setFlatness(double flatness) { |
876 |
// TODO Auto-generated method stub
|
877 |
|
878 |
} |
879 |
|
880 |
public boolean isWritable() { |
881 |
return m_Fich.canWrite();
|
882 |
} |
883 |
|
884 |
public IWriter getWriter() {
|
885 |
return this; |
886 |
} |
887 |
|
888 |
} |