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