root / tags / v1_1_Build_1006 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / writers / dxf / DxfWriter.java @ 12458
History | View | Annotate | Download (43.5 KB)
1 |
package com.iver.cit.gvsig.fmap.edition.writers.dxf; |
---|---|
2 |
|
3 |
import java.awt.geom.PathIterator; |
4 |
import java.awt.geom.Point2D; |
5 |
import java.io.File; |
6 |
import java.io.IOException; |
7 |
import java.sql.Types; |
8 |
import java.util.Vector; |
9 |
|
10 |
import org.cresques.cts.IProjection; |
11 |
import org.cresques.geo.Point3D; |
12 |
import org.cresques.io.DxfFile; |
13 |
import org.cresques.io.DxfGroup; |
14 |
import org.cresques.io.DxfGroupVector; |
15 |
import org.cresques.px.dxf.DxfEntityMaker; |
16 |
|
17 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
18 |
import com.hardcode.gdbms.engine.values.IntValue; |
19 |
import com.hardcode.gdbms.engine.values.NullValue; |
20 |
import com.hardcode.gdbms.engine.values.NumericValue; |
21 |
import com.hardcode.gdbms.engine.values.StringValue; |
22 |
import com.hardcode.gdbms.engine.values.Value; |
23 |
import com.iver.cit.gvsig.fmap.DriverException; |
24 |
import com.iver.cit.gvsig.fmap.core.FArc2D; |
25 |
import com.iver.cit.gvsig.fmap.core.FCircle2D; |
26 |
import com.iver.cit.gvsig.fmap.core.FEllipse2D; |
27 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
28 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
29 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
30 |
import com.iver.cit.gvsig.fmap.core.FShape; |
31 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
32 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
33 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
34 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
35 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
36 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
37 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
38 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
39 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
40 |
import com.iver.cit.gvsig.fmap.edition.writers.AbstractWriter; |
41 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
42 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
43 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
44 |
|
45 |
public class DxfWriter extends AbstractWriter implements ISpatialWriter { |
46 |
|
47 |
private String DEFAULT_LAYER="default"; |
48 |
private Integer DEFAULT_COLOR=new Integer(0); |
49 |
private Double DEFAULT_ELEVATION=new Double(0); |
50 |
private Double DEFAULT_THICKNESS=new Double(0); |
51 |
private String DEFAULT_TEXT=""; |
52 |
private Double DEFAULT_HEIGHTTEXT=new Double(0); |
53 |
private Double DEFAULT_ROTATIONTEXT=new Double(0); |
54 |
|
55 |
private DxfFieldsMapping fieldMapping = null; |
56 |
|
57 |
private File file; |
58 |
|
59 |
private FieldDescription[] fieldsDesc = null; |
60 |
|
61 |
private DxfFile.EntityFactory entityMaker;
|
62 |
|
63 |
private IProjection proj = null; |
64 |
|
65 |
private DxfFile dxfFile;
|
66 |
|
67 |
int handle = 40; // Revisar porqu? es 40. |
68 |
|
69 |
int k = 0; |
70 |
|
71 |
boolean dxf3DFile = false; |
72 |
|
73 |
public void setFile(File f) { |
74 |
file = f; |
75 |
} |
76 |
|
77 |
public boolean canWriteAttribute(int sqlType) { |
78 |
return false; |
79 |
} |
80 |
|
81 |
public boolean canAlterTable() { |
82 |
return false; |
83 |
} |
84 |
|
85 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
86 |
return true; // I guess all geometries can be here... |
87 |
} |
88 |
|
89 |
public void initialize(FLayer layer) throws EditionException { |
90 |
try {
|
91 |
SelectableDataSource sds = ((FLyrVect) layer).getRecordset(); |
92 |
// Aqu? hay que revisar los campos de sds y compararlos con los
|
93 |
// que podemos escribir. (Layer, Color, etc).
|
94 |
fieldsDesc = sds.getFieldsDescription(); |
95 |
} catch (DriverException e) {
|
96 |
e.printStackTrace(); |
97 |
throw new EditionException(e); |
98 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
99 |
e.printStackTrace(); |
100 |
throw new EditionException(e); |
101 |
} |
102 |
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* Useful to create a layer from scratch Call setFile before using this
|
107 |
* function
|
108 |
*
|
109 |
* @param lyrDef
|
110 |
* @throws EditionException
|
111 |
*/
|
112 |
public void initialize(ITableDefinition lyrDef) throws EditionException { |
113 |
super.initialize(lyrDef);
|
114 |
fieldsDesc = lyrDef.getFieldsDesc(); |
115 |
} |
116 |
|
117 |
public void preProcess() throws EditionException { |
118 |
if (fieldMapping == null) { |
119 |
throw new EditionException( |
120 |
"DXFWriter: You MUST specify the fieldMapping first!!.");
|
121 |
} |
122 |
// NOTA: La proyecci?n no se usa absolutamente para nada (al menos
|
123 |
// por ahora). Las entidades se escribir?n con las coordenadas con
|
124 |
// las que se crean.
|
125 |
if (proj == null) { |
126 |
throw new EditionException( |
127 |
"DXFWriter: You MUST specify the projection first!!.");
|
128 |
} |
129 |
|
130 |
entityMaker = new DxfEntityMaker(proj);
|
131 |
|
132 |
} |
133 |
|
134 |
public void process(IRowEdited row) throws EditionException { |
135 |
if (row.getStatus() == IRowEdited.STATUS_DELETED) return; |
136 |
|
137 |
try
|
138 |
{ |
139 |
IFeature feat = (IFeature) row.getLinkedRow(); |
140 |
IGeometry geom = feat.getGeometry(); |
141 |
Value[] values=row.getAttributes();
|
142 |
// TODO: Tratamiento de los campos
|
143 |
// y modificar los createXXX para que acepten como par?metro
|
144 |
// los datos de LAYER, COLOR, ELEVATION, THICKNESS, TEXT
|
145 |
// HEIGHTTEXT, ROTATIONTEXT y el resto que puedan hacer
|
146 |
// falta.
|
147 |
|
148 |
|
149 |
// ////////////////
|
150 |
if (geom.getGeometryType()==FShape.POINT) {
|
151 |
createPoint2D(handle, k, geom, values); |
152 |
k++; |
153 |
} else if (geom.getGeometryType()==(FShape.POINT | FShape.Z)) { |
154 |
dxf3DFile = true;
|
155 |
createPoint3D(handle, k, geom, values); |
156 |
k++; |
157 |
} else if (geom.getGeometryType()==FShape.LINE) { |
158 |
createLwPolyline2D(handle, k, geom, false,values);
|
159 |
k++; |
160 |
} else if (geom.getGeometryType()==(FShape.LINE | FShape.Z)) { |
161 |
dxf3DFile = true;
|
162 |
k = createPolyline3D(handle, k, geom, values); |
163 |
} else if (geom.getGeometryType()==FShape.POLYGON) { |
164 |
// createPolygon2D(handle, k, geom);
|
165 |
createLwPolyline2D(handle, k, geom, true,values);
|
166 |
k++; |
167 |
} else if (geom.getGeometryType()==(FShape.POLYGON | FShape.Z)) { |
168 |
dxf3DFile = true;
|
169 |
k = createPolyline3D(handle, k, geom, values); |
170 |
// k = createPolygon3D(handle, k, geom);
|
171 |
} else if (geom.getGeometryType()==FShape.CIRCLE) { |
172 |
FCircle2D circle = (FCircle2D) geom.getInternalShape(); |
173 |
createCircle2D(handle, k, circle, values); |
174 |
k++; |
175 |
} else if (geom.getGeometryType()==FShape.ARC) { |
176 |
FArc2D arc = (FArc2D) geom.getInternalShape(); |
177 |
createArc2D(arc, values); |
178 |
k++; |
179 |
} else if (geom.getGeometryType()==FShape.ELLIPSE) { |
180 |
FEllipse2D ellipse = (FEllipse2D) geom.getInternalShape(); |
181 |
createEllipse2D(ellipse, values); |
182 |
k++; |
183 |
/* } else if (geom instanceof FGeometryCollection) {
|
184 |
// System.out.println("Polil?nea encontrada (Soluci?n
|
185 |
// provisional).");
|
186 |
FGeometryCollection gc = (FGeometryCollection)geom;
|
187 |
IGeometry[] geoms = gc.getGeometries();
|
188 |
// double[] lineCoords = new double[6];
|
189 |
// GeneralPathXIterator polylineIt =
|
190 |
// geoms[i].getGeneralPathXIterator();
|
191 |
DxfGroupVector plv = new DxfGroupVector();
|
192 |
DxfGroup polylineLayer = new DxfGroup(8, "default");
|
193 |
DxfGroup vNum = new DxfGroup();
|
194 |
vNum.setCode(90);
|
195 |
vNum.setData(new Integer(fShapes.length+1));
|
196 |
plv.add(polylineLayer);
|
197 |
plv.add(vNum);
|
198 |
Point2D first = new Point2D.Double();
|
199 |
Point2D last = new Point2D.Double();
|
200 |
for (int j=0;j<geoms.length;j++) {
|
201 |
if (geom.getInternalShape() instanceof FPolyline2D && !(geom.getInternalShape() instanceof FArc2D)) {
|
202 |
// System.out.println("L?nea encontrada dentro de la
|
203 |
// polil?nea.");
|
204 |
FPolyline2D fLine = (FPolyline2D)geom.getInternalShape();
|
205 |
double[] lineCoords = new double[6];
|
206 |
PathIterator lineIt = fLine.getPathIterator(new AffineTransform());
|
207 |
int k = 0;
|
208 |
Point2D[] pts = new Point2D[2];
|
209 |
while (!lineIt.isDone()) {
|
210 |
int type = lineIt.currentSegment(lineCoords);
|
211 |
pts[k] = new Point2D.Double(lineCoords[0], lineCoords[1]);
|
212 |
k++;
|
213 |
lineIt.next();
|
214 |
}
|
215 |
DxfGroup vx = new DxfGroup();
|
216 |
DxfGroup vy = new DxfGroup();
|
217 |
vx.setCode(10);
|
218 |
vx.setData(new Double(pts[0].getX()));
|
219 |
vy.setCode(20);
|
220 |
vy.setData(new Double(pts[0].getY()));
|
221 |
plv.add(vx);
|
222 |
plv.add(vy);
|
223 |
if (j==0) {
|
224 |
first = new Point2D.Double(pts[0].getX(), pts[0].getY());
|
225 |
}
|
226 |
if (j==fShapes.length-1) {
|
227 |
last = new Point2D.Double(pts[1].getX(), pts[1].getY());
|
228 |
if (first.getX()==last.getX() && first.getY()==last.getY()) {
|
229 |
// Polil?nea cerrada.
|
230 |
} else {
|
231 |
DxfGroup vxf = new DxfGroup();
|
232 |
DxfGroup vyf = new DxfGroup();
|
233 |
vxf.setCode(10);
|
234 |
vxf.setData(new Double(pts[1].getX()));
|
235 |
vyf.setCode(20);
|
236 |
vyf.setData(new Double(pts[1].getY()));
|
237 |
plv.add(vxf);
|
238 |
plv.add(vyf);
|
239 |
}
|
240 |
}
|
241 |
} else if (fShapes[j] instanceof FArc2D) {
|
242 |
// System.out.println("Arco encontrada dentro de la
|
243 |
// polil?nea.");
|
244 |
FArc2D fArc = (FArc2D)fShapes[j];
|
245 |
double[] lineCoords = new double[6];
|
246 |
Point2D[] pts = new Point2D[3];
|
247 |
pts[0] = fArc.getInit();
|
248 |
pts[1] = fArc.getMid();
|
249 |
pts[2] = fArc.getEnd();
|
250 |
Point2D center = fArc.getCenter(); // TrigonometricalFunctions.getCenter(pts[0],
|
251 |
// pts[1], pts[2]);
|
252 |
// System.out.println("pts[0] = " + pts[0]);
|
253 |
// System.out.println("pts[1] = " + pts[1]);
|
254 |
// System.out.println("center = " + center);
|
255 |
// System.out.println("pts[2] = " + pts[2]);
|
256 |
double initAngRad = TrigonometricalFunctions.getAngle(center, pts[0]);
|
257 |
double endAngRad = TrigonometricalFunctions.getAngle(center, pts[2]);
|
258 |
double angleRad = endAngRad-initAngRad;
|
259 |
if (angleRad<0) angleRad = angleRad+2*Math.PI;
|
260 |
//
|
261 |
// boolean bulgeIsNegative = true;
|
262 |
double bulge = 0;
|
263 |
if (TrigonometricalFunctions.isCCW(pts[0], pts[1], pts[2])) {
|
264 |
double angleRad2 = angleRad/4.0;
|
265 |
bulge = Math.tan(angleRad2);
|
266 |
} else {
|
267 |
angleRad = 2*Math.PI-angleRad;
|
268 |
double angleRad2 = angleRad/4.0;
|
269 |
bulge = -1*Math.tan(angleRad2);
|
270 |
}
|
271 |
DxfGroup vx = new DxfGroup();
|
272 |
DxfGroup vy = new DxfGroup();
|
273 |
DxfGroup vb = new DxfGroup();
|
274 |
vx.setCode(10);
|
275 |
vx.setData(new Double(pts[0].getX()));
|
276 |
vy.setCode(20);
|
277 |
vy.setData(new Double(pts[0].getY()));
|
278 |
vb.setCode(42);
|
279 |
vb.setData(new Double(bulge));
|
280 |
plv.add(vx);
|
281 |
plv.add(vy);
|
282 |
plv.add(vb);
|
283 |
if (j==0) {
|
284 |
first = new Point2D.Double(pts[0].getX(), pts[0].getY());
|
285 |
}
|
286 |
if (j==fShapes.length-1) {
|
287 |
last = new Point2D.Double(pts[2].getX(), pts[2].getY());
|
288 |
if (first.getX()==last.getX() && first.getY()==last.getY()) {
|
289 |
// Polil?nea cerrada.
|
290 |
} else {
|
291 |
DxfGroup vxf = new DxfGroup();
|
292 |
DxfGroup vyf = new DxfGroup();
|
293 |
vxf.setCode(10);
|
294 |
vxf.setData(new Double(pts[2].getX()));
|
295 |
vyf.setCode(20);
|
296 |
vyf.setData(new Double(pts[2].getY()));
|
297 |
plv.add(vxf);
|
298 |
plv.add(vyf);
|
299 |
}
|
300 |
}
|
301 |
}
|
302 |
} */
|
303 |
} else {
|
304 |
System.out.println("IGeometry not supported yet"); |
305 |
k++; |
306 |
} |
307 |
} |
308 |
catch(Exception e) |
309 |
{ |
310 |
throw new EditionException(e); |
311 |
} |
312 |
|
313 |
|
314 |
} |
315 |
private void createArc2D(FArc2D fArc,Value[] values) throws Exception { |
316 |
Point2D[] pts = new Point2D[3]; |
317 |
pts[0] = fArc.getInit();
|
318 |
pts[1] = fArc.getMid();
|
319 |
pts[2] = fArc.getEnd();
|
320 |
Point2D center = fArc.getCenter();
|
321 |
double radius = center.distance(pts[0]); |
322 |
double initAngle = UtilFunctions.getAngle(center, pts[0]); |
323 |
initAngle = Math.toDegrees(initAngle);
|
324 |
// System.out.println("initAngle = " + initAngle);
|
325 |
double midAngle = UtilFunctions.getAngle(center, pts[1]); |
326 |
midAngle = Math.toDegrees(midAngle);
|
327 |
// System.out.println("midAngle = " + midAngle);
|
328 |
double endAngle = UtilFunctions.getAngle(center, pts[2]); |
329 |
endAngle = Math.toDegrees(endAngle);
|
330 |
// System.out.println("endAngle = " + endAngle);
|
331 |
|
332 |
// 050307, jmorell: Resoluci?n de un bug sobre el sentido de
|
333 |
// los arcos.
|
334 |
|
335 |
// if (!UtilFunctions.isCCW(pts[0],pts[1],pts[2])){
|
336 |
if (!FConverter.isCCW(pts)){
|
337 |
double aux=initAngle;
|
338 |
initAngle=endAngle; |
339 |
endAngle=aux; |
340 |
} |
341 |
|
342 |
|
343 |
/*
|
344 |
* FArc2D arc = (FArc2D)(shapes[0]); Point2D center = arc.getCenter();
|
345 |
* Point2D init = arc.getInit(); Point2D end = arc.getEnd(); // C?lculo
|
346 |
* del radio: double radius =
|
347 |
* Math.sqrt(Math.pow(init.getX()-center.getX(),2)+Math.pow(init.getY()-center.getY(),2)); //
|
348 |
* double initAngle=TrigonometricalFunctions.getAngle(center, init);
|
349 |
* initAngle = Math.toDegrees(initAngle); double
|
350 |
* endAngle=TrigonometricalFunctions.getAngle(center, end); endAngle =
|
351 |
* Math.toDegrees(endAngle);
|
352 |
*/
|
353 |
// DxfGroup arcLayer = new DxfGroup(8, "default");
|
354 |
DxfGroup ax = new DxfGroup();
|
355 |
DxfGroup ay = new DxfGroup();
|
356 |
DxfGroup ac = new DxfGroup();
|
357 |
DxfGroup ai = new DxfGroup();
|
358 |
DxfGroup ae = new DxfGroup();
|
359 |
ax.setCode(10);
|
360 |
ax.setData(new Double(center.getX())); |
361 |
ay.setCode(20);
|
362 |
ay.setData(new Double(center.getY())); |
363 |
ac.setCode(40);
|
364 |
ac.setData(new Double(radius)); |
365 |
ai.setCode(50);
|
366 |
ai.setData(new Double(initAngle)); |
367 |
ae.setCode(51);
|
368 |
ae.setData(new Double(endAngle)); |
369 |
DxfGroupVector av = updateProperties(values); |
370 |
// av.add(arcLayer);
|
371 |
av.add(ax); |
372 |
av.add(ay); |
373 |
av.add(ac); |
374 |
av.add(ai); |
375 |
av.add(ae); |
376 |
entityMaker.createArc(av); |
377 |
|
378 |
} |
379 |
|
380 |
private void createCircle2D(int handle, int k2, FCircle2D geom,Value[] values) |
381 |
throws Exception { |
382 |
DxfGroupVector polv = updateProperties(values); |
383 |
// DxfGroup polylineLayer = new DxfGroup(8, "default");
|
384 |
// polv.add(polylineLayer);
|
385 |
// DxfGroup handleGroup = new DxfGroup();
|
386 |
// handleGroup.setCode(5);
|
387 |
// handleGroup.setData(new Integer(handle + k).toString());
|
388 |
// polv.add(handleGroup);
|
389 |
DxfGroup circleFlag = new DxfGroup();
|
390 |
circleFlag.setCode(100);
|
391 |
polv.add(circleFlag); |
392 |
|
393 |
DxfGroup xvertex = new DxfGroup();
|
394 |
xvertex.setCode(10);
|
395 |
xvertex.setData(new Double(geom.getCenter().getX())); |
396 |
DxfGroup yvertex = new DxfGroup();
|
397 |
yvertex.setCode(20);
|
398 |
yvertex.setData(new Double(geom.getCenter().getY())); |
399 |
DxfGroup zvertex = new DxfGroup();
|
400 |
zvertex.setCode(30);
|
401 |
zvertex.setData(new Double(0)); // TODO: COORDENADA Z. REVISAR ESTO PARA |
402 |
// ENTIDADES 3D
|
403 |
|
404 |
DxfGroup radius = new DxfGroup();
|
405 |
radius.setCode(40);
|
406 |
radius.setData(new Double(geom.getRadio())); |
407 |
|
408 |
polv.add(xvertex); |
409 |
polv.add(yvertex); |
410 |
polv.add(zvertex); |
411 |
polv.add(radius); |
412 |
|
413 |
entityMaker.createCircle(polv); |
414 |
|
415 |
} |
416 |
|
417 |
private void createEllipse2D(FEllipse2D fElip, Value[] values) throws Exception { |
418 |
Point2D center = new Point2D.Double((fElip.getInit().getX() + fElip |
419 |
.getEnd().getX()) / 2, (fElip.getInit().getY() + fElip.getEnd()
|
420 |
.getY()) / 2);
|
421 |
double mAxisL = fElip.getDist() * 2; |
422 |
// System.out.println("mAxisL = " + mAxisL);
|
423 |
/*
|
424 |
* System.out.println("mAxisL/(center.distance(fElip.getEnd()))*2 = " +
|
425 |
* mAxisL/(center.distance(fElip.getEnd()))*2); minToMaj.setData(new
|
426 |
* Double(mAxisL/()*2));
|
427 |
*/
|
428 |
double maAxisL = fElip.getInit().distance(fElip.getEnd());
|
429 |
|
430 |
Point2D endPointOfMajorAxis = fElip.getEnd();
|
431 |
double azimut = Math.atan2(endPointOfMajorAxis.getX() - center.getX(), |
432 |
endPointOfMajorAxis.getY() - center.getY()); |
433 |
double azimut2 = azimut + Math.PI / 2.0; |
434 |
if (azimut2 >= Math.PI * 2) |
435 |
azimut2 = azimut2 - Math.PI * 2; |
436 |
Point2D endPointOfMinorAxis = new Point2D.Double(center.getX() |
437 |
+ (fElip.getDist() * Math.sin(azimut2)), center.getY()
|
438 |
+ (fElip.getDist() * Math.cos(azimut2)));
|
439 |
|
440 |
if (mAxisL >= maAxisL) {
|
441 |
// El menor debe ser menor que el mayor. Los cambiamos.
|
442 |
double aux = mAxisL;
|
443 |
mAxisL = maAxisL; |
444 |
maAxisL = aux; |
445 |
// Tambi?n cambiamos los puntos finales de los ejes.
|
446 |
Point2D pAux = endPointOfMinorAxis;
|
447 |
endPointOfMinorAxis = endPointOfMajorAxis; |
448 |
endPointOfMajorAxis = pAux; |
449 |
} |
450 |
double mToMAR = mAxisL / maAxisL;
|
451 |
// System.out.println("mToMar = " + mToMAR);
|
452 |
// DxfGroup arcLayer = new DxfGroup(8, "default");
|
453 |
DxfGroup x = new DxfGroup();
|
454 |
DxfGroup y = new DxfGroup();
|
455 |
DxfGroup xc = new DxfGroup();
|
456 |
DxfGroup yc = new DxfGroup();
|
457 |
DxfGroup minToMaj = new DxfGroup();
|
458 |
// DxfGroup start = new DxfGroup();
|
459 |
// DxfGroup end = new DxfGroup();
|
460 |
x.setCode(10);
|
461 |
x.setData(new Double(center.getX())); |
462 |
y.setCode(20);
|
463 |
y.setData(new Double(center.getY())); |
464 |
xc.setCode(11);
|
465 |
xc.setData(new Double(endPointOfMajorAxis.getX() - center.getX())); |
466 |
yc.setCode(21);
|
467 |
yc.setData(new Double(endPointOfMajorAxis.getY() - center.getY())); |
468 |
minToMaj.setCode(40);
|
469 |
minToMaj.setData(new Double(mToMAR)); |
470 |
DxfGroupVector av = updateProperties(values); |
471 |
// av.add(arcLayer);
|
472 |
av.add(x); |
473 |
av.add(y); |
474 |
av.add(xc); |
475 |
av.add(yc); |
476 |
av.add(minToMaj); |
477 |
entityMaker.createEllipse(av); |
478 |
} |
479 |
|
480 |
public void postProcess() throws EditionException { |
481 |
// Escribimos realmente lo que hemos montado en memoria.
|
482 |
dxfFile = new DxfFile(null, file.getAbsolutePath(), entityMaker); |
483 |
dxfFile.setCadFlag(true);
|
484 |
if (dxf3DFile)
|
485 |
dxfFile.setDxf3DFlag(true);
|
486 |
try {
|
487 |
dxfFile.save(file.getAbsolutePath()); |
488 |
} catch (IOException e) { |
489 |
e.printStackTrace(); |
490 |
throw new EditionException(e); |
491 |
} |
492 |
|
493 |
} |
494 |
|
495 |
public String getName() { |
496 |
return "DXF Writer"; |
497 |
} |
498 |
|
499 |
/**
|
500 |
* @return Returns the fieldMapping.
|
501 |
*/
|
502 |
public DxfFieldsMapping getFieldMapping() {
|
503 |
return fieldMapping;
|
504 |
} |
505 |
|
506 |
/**
|
507 |
* Use this method BEFORE preProcess.
|
508 |
*
|
509 |
* @param fieldMapping
|
510 |
* The fieldMapping to set.
|
511 |
*/
|
512 |
public void setFieldMapping(DxfFieldsMapping fieldMapping) { |
513 |
this.fieldMapping = fieldMapping;
|
514 |
} |
515 |
|
516 |
public void write(IGeometry[] geometries, File file) throws Exception { |
517 |
int handle = 40; // Revisar porqu? es 40. |
518 |
int k = 0; |
519 |
boolean dxf3DFile = false; |
520 |
for (int i = 0; i < geometries.length; i++) { |
521 |
IGeometry geom = geometries[i]; |
522 |
if (geom.getGeometryType() == FShape.POINT) {
|
523 |
createPoint2D(handle, k, geom, null);
|
524 |
k++; |
525 |
} else if (geom.getGeometryType() == (FShape.POINT | FShape.Z)) { |
526 |
dxf3DFile = true;
|
527 |
createPoint3D(handle, k, geom, null);
|
528 |
k++; |
529 |
} else if (geom.getGeometryType() == FShape.LINE) { |
530 |
createLwPolyline2D(handle, k, geom, false, null); |
531 |
k++; |
532 |
} else if (geom.getGeometryType() == (FShape.LINE | FShape.Z)) { |
533 |
dxf3DFile = true;
|
534 |
k = createPolyline3D(handle, k, geom, null);
|
535 |
} else if (geom.getGeometryType() == FShape.POLYGON) { |
536 |
// createPolygon2D(handle, k, geom);
|
537 |
createLwPolyline2D(handle, k, geom, true,null); |
538 |
k++; |
539 |
} else if (geom.getGeometryType() == (FShape.POLYGON | FShape.Z)) { |
540 |
dxf3DFile = true;
|
541 |
k = createPolygon3D(handle, k, geom, null);
|
542 |
} else {
|
543 |
System.out.println("IGeometry not supported yet"); |
544 |
k++; |
545 |
} |
546 |
} |
547 |
dxfFile = new DxfFile(null, file.getAbsolutePath(), entityMaker); |
548 |
dxfFile.setCadFlag(true);
|
549 |
if (dxf3DFile)
|
550 |
dxfFile.setDxf3DFlag(true);
|
551 |
dxfFile.save(file.getAbsolutePath()); |
552 |
} |
553 |
|
554 |
/**
|
555 |
* @param handle
|
556 |
* @param k
|
557 |
* @param geom
|
558 |
* @return
|
559 |
* @throws Exception
|
560 |
*/
|
561 |
private int createPolygon3D(int handle, int k, IGeometry geom, Value[] values) |
562 |
throws Exception { |
563 |
DxfGroupVector polv = updateProperties(values); |
564 |
// DxfGroup polylineLayer = new DxfGroup(8, "default");
|
565 |
// polv.add(polylineLayer);
|
566 |
// DxfGroup handleGroup = new DxfGroup();
|
567 |
// handleGroup.setCode(5);
|
568 |
// handleGroup.setData(new Integer(handle + k).toString());
|
569 |
// polv.add(handleGroup);
|
570 |
Vector vpoints = new Vector(); |
571 |
PathIterator theIterator = geom.getPathIterator(null); // polyLine.getPathIterator(null, |
572 |
// flatness);
|
573 |
double[] theData = new double[6]; |
574 |
double[] velev = ((FGeometry) geom).getZs(); |
575 |
while (!theIterator.isDone()) {
|
576 |
int theType = theIterator.currentSegment(theData);
|
577 |
switch (theType) {
|
578 |
case PathIterator.SEG_MOVETO: |
579 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
580 |
break;
|
581 |
case PathIterator.SEG_LINETO: |
582 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
583 |
break;
|
584 |
} |
585 |
theIterator.next(); |
586 |
} |
587 |
if (constantElevation(velev)) {
|
588 |
DxfGroup polylineFlag = new DxfGroup();
|
589 |
polylineFlag.setCode(70);
|
590 |
polylineFlag.setData(new Integer(1)); |
591 |
polv.add(polylineFlag); |
592 |
DxfGroup elevation = new DxfGroup();
|
593 |
elevation.setCode(38);
|
594 |
elevation.setData(new Double(velev[0])); |
595 |
polv.add(elevation); |
596 |
for (int j = 0; j < vpoints.size(); j++) { |
597 |
DxfGroup xvertex = new DxfGroup();
|
598 |
xvertex.setCode(10);
|
599 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
600 |
DxfGroup yvertex = new DxfGroup();
|
601 |
yvertex.setCode(20);
|
602 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
603 |
polv.add(xvertex); |
604 |
polv.add(yvertex); |
605 |
} |
606 |
entityMaker.createLwPolyline(polv); |
607 |
k++; |
608 |
} else {
|
609 |
DxfGroup polylineFlag = new DxfGroup();
|
610 |
polylineFlag.setCode(70);
|
611 |
polylineFlag.setData(new Integer(9)); |
612 |
polv.add(polylineFlag); |
613 |
DxfGroup xgroup = new DxfGroup();
|
614 |
xgroup.setCode(10);
|
615 |
xgroup.setData(new Double(0.0)); |
616 |
polv.add(xgroup); |
617 |
DxfGroup ygroup = new DxfGroup();
|
618 |
ygroup.setCode(20);
|
619 |
ygroup.setData(new Double(0.0)); |
620 |
polv.add(ygroup); |
621 |
DxfGroup elevation = new DxfGroup();
|
622 |
elevation.setCode(30);
|
623 |
elevation.setData(new Double(0.0)); |
624 |
polv.add(elevation); |
625 |
DxfGroup subclassMarker = new DxfGroup(100, "AcDb3dPolyline"); |
626 |
polv.add(subclassMarker); |
627 |
entityMaker.createPolyline(polv); |
628 |
k++; |
629 |
for (int j = 0; j < vpoints.size(); j++) { |
630 |
DxfGroupVector verv = new DxfGroupVector();
|
631 |
DxfGroup entityType = new DxfGroup(0, "VERTEX"); |
632 |
verv.add(entityType); |
633 |
DxfGroup generalSubclassMarker = new DxfGroup(100, "AcDbEntity"); |
634 |
verv.add(generalSubclassMarker); |
635 |
DxfGroup layerName = new DxfGroup(8, "default"); |
636 |
verv.add(layerName); |
637 |
DxfGroup vertexSubclassMarker = new DxfGroup(100, "AcDbVertex"); |
638 |
verv.add(vertexSubclassMarker); |
639 |
// DxfGroup vertex3DSubclassMarker = new DxfGroup(100,
|
640 |
// "AcDb3dPolylineVertex");
|
641 |
// verv.add(vertex3DSubclassMarker);
|
642 |
DxfGroup xvertex = new DxfGroup();
|
643 |
xvertex.setCode(10);
|
644 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
645 |
DxfGroup yvertex = new DxfGroup();
|
646 |
yvertex.setCode(20);
|
647 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
648 |
DxfGroup zvertex = new DxfGroup();
|
649 |
zvertex.setCode(30);
|
650 |
zvertex.setData(new Double(velev[j])); |
651 |
verv.add(xvertex); |
652 |
verv.add(yvertex); |
653 |
verv.add(zvertex); |
654 |
entityMaker.addVertex(verv); |
655 |
k++; |
656 |
} |
657 |
DxfGroupVector seqv = new DxfGroupVector();
|
658 |
DxfGroup entityType = new DxfGroup(0, "SEQEND"); |
659 |
seqv.add(entityType); |
660 |
// DxfGroup handle = new DxfGroup();
|
661 |
// elevation.setCode(5);
|
662 |
// elevation.setData(new Integer(getHandle()));
|
663 |
// seqv.add(handle);
|
664 |
DxfGroup generalSubclassMarker = new DxfGroup(100, "AcDbEntity"); |
665 |
seqv.add(generalSubclassMarker); |
666 |
DxfGroup layerName = new DxfGroup(8, "default"); |
667 |
seqv.add(layerName); |
668 |
DxfGroup handleSeqGroup = new DxfGroup();
|
669 |
handleSeqGroup.setCode(5);
|
670 |
handleSeqGroup.setData(new Integer(handle + k).toString()); |
671 |
seqv.add(handleSeqGroup); |
672 |
entityMaker.endSeq(); |
673 |
k++; |
674 |
} |
675 |
return k;
|
676 |
} |
677 |
|
678 |
/**
|
679 |
* @deprecated
|
680 |
* @param handle
|
681 |
* @param k
|
682 |
* @param geom
|
683 |
* @throws Exception
|
684 |
*/
|
685 |
private void createPolygon2D(int handle, int k, IGeometry geom,Value[] values) |
686 |
throws Exception { |
687 |
DxfGroupVector polv = updateProperties(values); |
688 |
// DxfGroup polylineLayer = new DxfGroup(8, "default");
|
689 |
// polv.add(polylineLayer);
|
690 |
// DxfGroup handleGroup = new DxfGroup();
|
691 |
// handleGroup.setCode(5);
|
692 |
// handleGroup.setData(new Integer(handle + k).toString());
|
693 |
// polv.add(handleGroup);
|
694 |
DxfGroup polylineFlag = new DxfGroup();
|
695 |
polylineFlag.setCode(70);
|
696 |
polylineFlag.setData(new Integer(1)); |
697 |
polv.add(polylineFlag); |
698 |
|
699 |
Vector vpoints = new Vector(); |
700 |
PathIterator theIterator = geom.getPathIterator(null); // polyLine.getPathIterator(null, |
701 |
// flatness);
|
702 |
double[] theData = new double[6]; |
703 |
while (!theIterator.isDone()) {
|
704 |
int theType = theIterator.currentSegment(theData);
|
705 |
switch (theType) {
|
706 |
case PathIterator.SEG_MOVETO: |
707 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
708 |
break;
|
709 |
case PathIterator.SEG_LINETO: |
710 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
711 |
break;
|
712 |
} |
713 |
theIterator.next(); |
714 |
} |
715 |
for (int j = 0; j < vpoints.size(); j++) { |
716 |
DxfGroup xvertex = new DxfGroup();
|
717 |
xvertex.setCode(10);
|
718 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
719 |
DxfGroup yvertex = new DxfGroup();
|
720 |
yvertex.setCode(20);
|
721 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
722 |
polv.add(xvertex); |
723 |
polv.add(yvertex); |
724 |
} |
725 |
entityMaker.createLwPolyline(polv); |
726 |
} |
727 |
|
728 |
/**
|
729 |
* @param handle
|
730 |
* @param k
|
731 |
* @param geom
|
732 |
* @return
|
733 |
* @throws Exception
|
734 |
*/
|
735 |
private int createPolyline3D(int handle, int k, IGeometry geom, Value[] values) |
736 |
throws Exception { |
737 |
DxfGroupVector polv = updateProperties(values); |
738 |
// DxfGroup polylineLayer = new DxfGroup(8, "default");
|
739 |
// polv.add(polylineLayer);
|
740 |
// DxfGroup handleGroup = new DxfGroup();
|
741 |
// handleGroup.setCode(5);
|
742 |
// handleGroup.setData(new Integer(handle + k).toString());
|
743 |
// polv.add(handleGroup);
|
744 |
Vector vpoints = new Vector(); |
745 |
PathIterator theIterator = geom.getPathIterator(null); // polyLine.getPathIterator(null, |
746 |
// flatness);
|
747 |
double[] theData = new double[6]; |
748 |
double[] velev = ((FGeometry) geom).getZs(); |
749 |
while (!theIterator.isDone()) {
|
750 |
int theType = theIterator.currentSegment(theData);
|
751 |
switch (theType) {
|
752 |
case PathIterator.SEG_MOVETO: |
753 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
754 |
break;
|
755 |
case PathIterator.SEG_LINETO: |
756 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
757 |
break;
|
758 |
} |
759 |
theIterator.next(); |
760 |
} |
761 |
if (constantElevation(velev)) {
|
762 |
DxfGroup polylineFlag = new DxfGroup();
|
763 |
polylineFlag.setCode(70);
|
764 |
polylineFlag.setData(new Integer(0)); |
765 |
polv.add(polylineFlag); |
766 |
DxfGroup elevation = new DxfGroup();
|
767 |
elevation.setCode(38);
|
768 |
elevation.setData(new Double(velev[0])); |
769 |
polv.add(elevation); |
770 |
for (int j = 0; j < vpoints.size(); j++) { |
771 |
DxfGroup xvertex = new DxfGroup();
|
772 |
xvertex.setCode(10);
|
773 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
774 |
DxfGroup yvertex = new DxfGroup();
|
775 |
yvertex.setCode(20);
|
776 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
777 |
polv.add(xvertex); |
778 |
polv.add(yvertex); |
779 |
} |
780 |
entityMaker.createLwPolyline(polv); |
781 |
k++; |
782 |
} else {
|
783 |
DxfGroup polylineFlag = new DxfGroup();
|
784 |
polylineFlag.setCode(70);
|
785 |
polylineFlag.setData(new Integer(8)); |
786 |
polv.add(polylineFlag); |
787 |
DxfGroup xgroup = new DxfGroup();
|
788 |
xgroup.setCode(10);
|
789 |
xgroup.setData(new Double(0.0)); |
790 |
polv.add(xgroup); |
791 |
DxfGroup ygroup = new DxfGroup();
|
792 |
ygroup.setCode(20);
|
793 |
ygroup.setData(new Double(0.0)); |
794 |
polv.add(ygroup); |
795 |
DxfGroup elevation = new DxfGroup();
|
796 |
elevation.setCode(30);
|
797 |
elevation.setData(new Double(0.0)); |
798 |
polv.add(elevation); |
799 |
DxfGroup subclassMarker = new DxfGroup(100, "AcDb3dPolyline"); |
800 |
polv.add(subclassMarker); |
801 |
entityMaker.createPolyline(polv); |
802 |
k++; |
803 |
for (int j = 0; j < vpoints.size(); j++) { |
804 |
DxfGroupVector verv = new DxfGroupVector();
|
805 |
DxfGroup entityType = new DxfGroup(0, "VERTEX"); |
806 |
verv.add(entityType); |
807 |
DxfGroup generalSubclassMarker = new DxfGroup(100, "AcDbEntity"); |
808 |
verv.add(generalSubclassMarker); |
809 |
DxfGroup layerName = new DxfGroup(8, "default"); |
810 |
verv.add(layerName); |
811 |
DxfGroup vertexSubclassMarker = new DxfGroup(100, "AcDbVertex"); |
812 |
verv.add(vertexSubclassMarker); |
813 |
// DxfGroup vertex3DSubclassMarker = new DxfGroup(100,
|
814 |
// "AcDb3dPolylineVertex");
|
815 |
// verv.add(vertex3DSubclassMarker);
|
816 |
DxfGroup xvertex = new DxfGroup();
|
817 |
xvertex.setCode(10);
|
818 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
819 |
DxfGroup yvertex = new DxfGroup();
|
820 |
yvertex.setCode(20);
|
821 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
822 |
DxfGroup zvertex = new DxfGroup();
|
823 |
zvertex.setCode(30);
|
824 |
zvertex.setData(new Double(velev[j])); |
825 |
verv.add(xvertex); |
826 |
verv.add(yvertex); |
827 |
verv.add(zvertex); |
828 |
entityMaker.addVertex(verv); |
829 |
k++; |
830 |
} |
831 |
DxfGroupVector seqv = new DxfGroupVector();
|
832 |
DxfGroup entityType = new DxfGroup(0, "SEQEND"); |
833 |
seqv.add(entityType); |
834 |
// DxfGroup handle = new DxfGroup();
|
835 |
// elevation.setCode(5);
|
836 |
// elevation.setData(new Integer(getHandle()));
|
837 |
// seqv.add(handle);
|
838 |
DxfGroup generalSubclassMarker = new DxfGroup(100, "AcDbEntity"); |
839 |
seqv.add(generalSubclassMarker); |
840 |
DxfGroup layerName = new DxfGroup(8, "default"); |
841 |
seqv.add(layerName); |
842 |
DxfGroup handleSeqGroup = new DxfGroup();
|
843 |
handleSeqGroup.setCode(5);
|
844 |
handleSeqGroup.setData(new Integer(handle + k).toString()); |
845 |
seqv.add(handleSeqGroup); |
846 |
entityMaker.endSeq(); |
847 |
k++; |
848 |
} |
849 |
return k;
|
850 |
} |
851 |
|
852 |
private DxfGroupVector updateProperties(Value[] values){ |
853 |
DxfGroupVector polv = new DxfGroupVector();
|
854 |
String layer=DEFAULT_LAYER;
|
855 |
Integer color=DEFAULT_COLOR;
|
856 |
// Double elevation=DEFAULT_ELEVATION;
|
857 |
Double thickness=DEFAULT_THICKNESS;
|
858 |
if (fieldsDesc.length > 6) { |
859 |
if (fieldsDesc[3].getFieldName().equals("Layer") && |
860 |
!(values[3] instanceof NullValue) && |
861 |
values[3] instanceof StringValue) { |
862 |
layer = values[3].toString();
|
863 |
} |
864 |
if (fieldsDesc[4].getFieldName().equals("Color") |
865 |
&& !(values[4] instanceof NullValue) && |
866 |
values[4] instanceof IntValue) { |
867 |
color = new Integer(((NumericValue) values[4]).intValue()); |
868 |
} |
869 |
// if (!(values[5] instanceof NullValue)){
|
870 |
// elevation= new Double(((NumericValue)values[5]).doubleValue());
|
871 |
// }
|
872 |
if (fieldsDesc[6].getFieldName().equals("Thickness") && |
873 |
!(values[6] instanceof NullValue) && |
874 |
values[6] instanceof DoubleValue) { |
875 |
thickness = new Double(((NumericValue) values[6]).doubleValue()); |
876 |
} |
877 |
} |
878 |
DxfGroup geometryLayer = new DxfGroup(8, layer); |
879 |
|
880 |
DxfGroup handleGroup = new DxfGroup();
|
881 |
handleGroup.setCode(5);
|
882 |
handleGroup.setData(new Integer(handle + k).toString()); |
883 |
|
884 |
DxfGroup handleColor = new DxfGroup();
|
885 |
handleColor.setCode(62);
|
886 |
handleColor.setData(color); |
887 |
|
888 |
// DxfGroup handleElevation = new DxfGroup();
|
889 |
// handleElevation.setCode(38);
|
890 |
// handleElevation.setData(elevation);
|
891 |
|
892 |
DxfGroup handleThickness = new DxfGroup();
|
893 |
handleThickness.setCode(39);
|
894 |
handleThickness.setData(thickness); |
895 |
|
896 |
|
897 |
polv.add(geometryLayer); |
898 |
// polv.add(handleElevation);
|
899 |
polv.add(handleGroup); |
900 |
polv.add(handleColor); |
901 |
return polv;
|
902 |
} |
903 |
/**
|
904 |
* @param handle
|
905 |
* @param k
|
906 |
* @param geom
|
907 |
* @throws Exception
|
908 |
*/
|
909 |
private void createLwPolyline2D(int handle, int k, IGeometry geom, boolean isPolygon, Value[] values) |
910 |
throws Exception { |
911 |
// arrayFields.add("ID");
|
912 |
// arrayFields.add("FShape");
|
913 |
// arrayFields.add("Entity");
|
914 |
// String layer=DEFAULT_LAYER;
|
915 |
// Integer color=DEFAULT_COLOR;
|
916 |
// Double elevation=DEFAULT_ELEVATION;
|
917 |
// Double thickness=DEFAULT_THICKNESS;
|
918 |
// if (!(values[3] instanceof NullValue)){
|
919 |
// layer = values[3].toString();
|
920 |
// }
|
921 |
// if (!(values[4] instanceof NullValue)){
|
922 |
// color = new Integer(((NumericValue)values[4]).intValue());
|
923 |
// }
|
924 |
// if (!(values[5] instanceof NullValue)){
|
925 |
// elevation= new Double(((NumericValue)values[5]).doubleValue());
|
926 |
// }
|
927 |
// if (!(values[6] instanceof NullValue)){
|
928 |
// thickness= new Double(((NumericValue)values[6]).doubleValue());
|
929 |
// }
|
930 |
// if (!(values[7] instanceof NullValue)){
|
931 |
// text = values[7].toString();
|
932 |
// }
|
933 |
// String heightText=values[8].toString();
|
934 |
// String rotationText=values[9].toString();
|
935 |
|
936 |
|
937 |
DxfGroupVector polv = null;
|
938 |
// DxfGroup polylineLayer = new DxfGroup(8, layer);
|
939 |
|
940 |
// DxfGroup handleGroup = new DxfGroup();
|
941 |
// handleGroup.setCode(5);
|
942 |
// handleGroup.setData(new Integer(handle + k).toString());
|
943 |
|
944 |
Vector vpoints = new Vector(); |
945 |
|
946 |
DxfGroup polylineFlag = new DxfGroup();
|
947 |
polylineFlag.setCode(70);
|
948 |
if (isPolygon)
|
949 |
polylineFlag.setData(new Integer(1)); // cerrada |
950 |
else
|
951 |
polylineFlag.setData(new Integer(0)); // abierta |
952 |
|
953 |
// DxfGroup handleColor = new DxfGroup();
|
954 |
// handleColor.setCode(62);
|
955 |
// handleColor.setData(color);
|
956 |
//
|
957 |
// DxfGroup handleElevation = new DxfGroup();
|
958 |
// handleElevation.setCode(38);
|
959 |
// handleElevation.setData(elevation);
|
960 |
//
|
961 |
// DxfGroup handleThickness = new DxfGroup();
|
962 |
// handleThickness.setCode(39);
|
963 |
// handleThickness.setData(thickness);
|
964 |
|
965 |
PathIterator theIterator = geom.getPathIterator(null); // polyLine.getPathIterator(null, |
966 |
// flatness);
|
967 |
|
968 |
double[] theData = new double[6]; |
969 |
while (!theIterator.isDone()) {
|
970 |
int theType = theIterator.currentSegment(theData);
|
971 |
switch (theType) {
|
972 |
case PathIterator.SEG_MOVETO: |
973 |
if (polv != null) |
974 |
{ |
975 |
for (int j = 0; j < vpoints.size(); j++) { |
976 |
DxfGroup xvertex = new DxfGroup();
|
977 |
xvertex.setCode(10);
|
978 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
979 |
DxfGroup yvertex = new DxfGroup();
|
980 |
yvertex.setCode(20);
|
981 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
982 |
polv.add(xvertex); |
983 |
polv.add(yvertex); |
984 |
} |
985 |
entityMaker.createLwPolyline(polv); |
986 |
} |
987 |
polv = updateProperties(values); |
988 |
polv.add(polylineFlag); |
989 |
vpoints.clear(); |
990 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
991 |
break;
|
992 |
case PathIterator.SEG_LINETO: |
993 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
994 |
break;
|
995 |
case PathIterator.SEG_QUADTO: |
996 |
break;
|
997 |
case PathIterator.SEG_CUBICTO: |
998 |
break;
|
999 |
case PathIterator.SEG_CLOSE: |
1000 |
polylineFlag.setData(new Integer(1)); // cerrada |
1001 |
break;
|
1002 |
|
1003 |
} |
1004 |
theIterator.next(); |
1005 |
} |
1006 |
|
1007 |
for (int j = 0; j < vpoints.size(); j++) { |
1008 |
DxfGroup xvertex = new DxfGroup();
|
1009 |
xvertex.setCode(10);
|
1010 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
1011 |
DxfGroup yvertex = new DxfGroup();
|
1012 |
yvertex.setCode(20);
|
1013 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
1014 |
polv.add(xvertex); |
1015 |
polv.add(yvertex); |
1016 |
} |
1017 |
entityMaker.createLwPolyline(polv); |
1018 |
} |
1019 |
|
1020 |
/**
|
1021 |
* @param handle
|
1022 |
* @param k
|
1023 |
* @param geom
|
1024 |
* @throws Exception
|
1025 |
*/
|
1026 |
private void createPoint3D(int handle, int k, IGeometry geom, Value[] values) |
1027 |
throws Exception { |
1028 |
if (!(values[7] instanceof NullValue)){ |
1029 |
createText3D(handle,k,geom,values); |
1030 |
return;
|
1031 |
} |
1032 |
FPoint3D point = new FPoint3D(0, 0, 0); |
1033 |
double[] pointCoords = new double[6]; |
1034 |
PathIterator pointIt = geom.getPathIterator(null); |
1035 |
while (!pointIt.isDone()) {
|
1036 |
pointIt.currentSegment(pointCoords); |
1037 |
point = new FPoint3D(pointCoords[0], pointCoords[1], pointCoords[2]); |
1038 |
pointIt.next(); |
1039 |
} |
1040 |
Point3D pto = new Point3D(point.getX(), point.getY(), point.getZs()[0]); |
1041 |
// DxfGroup pointLayer = new DxfGroup(8, "default");
|
1042 |
// DxfGroup handleGroup = new DxfGroup();
|
1043 |
// handleGroup.setCode(5);
|
1044 |
// handleGroup.setData(new Integer(handle + k).toString());
|
1045 |
DxfGroup px = new DxfGroup();
|
1046 |
DxfGroup py = new DxfGroup();
|
1047 |
DxfGroup pz = new DxfGroup();
|
1048 |
px.setCode(10);
|
1049 |
px.setData(new Double(pto.getX())); |
1050 |
py.setCode(20);
|
1051 |
py.setData(new Double(pto.getY())); |
1052 |
pz.setCode(30);
|
1053 |
pz.setData(new Double(pto.getZ())); |
1054 |
double[] velev = ((FGeometry) geom).getZs(); |
1055 |
Double elevation= DEFAULT_ELEVATION;
|
1056 |
elevation = new Double(velev[0]); |
1057 |
DxfGroup handleElevation = new DxfGroup();
|
1058 |
handleElevation.setCode(38);
|
1059 |
handleElevation.setData(elevation); |
1060 |
|
1061 |
DxfGroupVector pv = updateProperties(values); |
1062 |
pv.add(handleElevation); |
1063 |
// pv.add(pointLayer);
|
1064 |
// pv.add(handleGroup);
|
1065 |
pv.add(px); |
1066 |
pv.add(py); |
1067 |
pv.add(pz); |
1068 |
entityMaker.createPoint(pv); |
1069 |
} |
1070 |
|
1071 |
/**
|
1072 |
* @param handle
|
1073 |
* @param k
|
1074 |
* @param geom
|
1075 |
* @throws Exception
|
1076 |
*/
|
1077 |
private void createPoint2D(int handle, int k, IGeometry geom, Value[] values) |
1078 |
throws Exception { |
1079 |
|
1080 |
if (!(values[7] instanceof NullValue)){ |
1081 |
createText2D(handle,k,geom,values); |
1082 |
return;
|
1083 |
} |
1084 |
// String layer=DEFAULT_LAYER;
|
1085 |
// Integer color=DEFAULT_COLOR;
|
1086 |
// Double elevation=DEFAULT_ELEVATION;
|
1087 |
// Double thickness=DEFAULT_THICKNESS;
|
1088 |
// if (!(values[3] instanceof NullValue)){
|
1089 |
// layer = values[3].toString();
|
1090 |
// }
|
1091 |
// if (!(values[4] instanceof NullValue)){
|
1092 |
// color = new Integer(((NumericValue)values[4]).intValue());
|
1093 |
// }
|
1094 |
// if (!(values[5] instanceof NullValue)){
|
1095 |
// elevation= new Double(((NumericValue)values[5]).doubleValue());
|
1096 |
// }
|
1097 |
// if (!(values[6] instanceof NullValue)){
|
1098 |
// thickness= new Double(((NumericValue)values[6]).doubleValue());
|
1099 |
// }
|
1100 |
|
1101 |
FPoint2D point = new FPoint2D(0, 0); |
1102 |
double[] pointCoords = new double[6]; |
1103 |
PathIterator pointIt = geom.getPathIterator(null); |
1104 |
while (!pointIt.isDone()) {
|
1105 |
pointIt.currentSegment(pointCoords); |
1106 |
point = new FPoint2D(pointCoords[0], pointCoords[1]); |
1107 |
pointIt.next(); |
1108 |
} |
1109 |
Point2D pto = new Point2D.Double(point.getX(), point.getY()); |
1110 |
// DxfGroup pointLayer = new DxfGroup(8, layer);
|
1111 |
// DxfGroup handleGroup = new DxfGroup();
|
1112 |
// handleGroup.setCode(5);
|
1113 |
// handleGroup.setData(new Integer(handle + k).toString());
|
1114 |
//
|
1115 |
// DxfGroup handleColor = new DxfGroup();
|
1116 |
// handleColor.setCode(62);
|
1117 |
// handleColor.setData(color);
|
1118 |
//
|
1119 |
// DxfGroup handleElevation = new DxfGroup();
|
1120 |
// handleElevation.setCode(38);
|
1121 |
// handleElevation.setData(elevation);
|
1122 |
//
|
1123 |
// DxfGroup handleThickness = new DxfGroup();
|
1124 |
// handleThickness.setCode(39);
|
1125 |
// handleThickness.setData(thickness);
|
1126 |
|
1127 |
DxfGroup px = new DxfGroup();
|
1128 |
DxfGroup py = new DxfGroup();
|
1129 |
DxfGroup pz = new DxfGroup();
|
1130 |
px.setCode(10);
|
1131 |
px.setData(new Double(pto.getX())); |
1132 |
py.setCode(20);
|
1133 |
py.setData(new Double(pto.getY())); |
1134 |
pz.setCode(30);
|
1135 |
// POINT del DXF tiene cota. Le asigno cero arbitrariamente.
|
1136 |
pz.setData(new Double(0.0)); |
1137 |
DxfGroupVector pv = updateProperties(values); |
1138 |
// pv.add(pointLayer);
|
1139 |
// pv.add(handleGroup);
|
1140 |
// pv.add(handleColor);
|
1141 |
// pv.add(handleElevation);
|
1142 |
// pv.add(handleThickness);
|
1143 |
pv.add(px); |
1144 |
pv.add(py); |
1145 |
pv.add(pz); |
1146 |
entityMaker.createPoint(pv); |
1147 |
} |
1148 |
/**
|
1149 |
* @param handle
|
1150 |
* @param k
|
1151 |
* @param geom
|
1152 |
* @throws Exception
|
1153 |
*/
|
1154 |
private void createText2D(int handle, int k, IGeometry geom, Value[] values) |
1155 |
throws Exception { |
1156 |
// String layer=DEFAULT_LAYER;
|
1157 |
// Integer color=DEFAULT_COLOR;
|
1158 |
// Double elevation=DEFAULT_ELEVATION;
|
1159 |
// Double thickness=DEFAULT_THICKNESS;
|
1160 |
String text=DEFAULT_TEXT;
|
1161 |
Double heightText=DEFAULT_HEIGHTTEXT;
|
1162 |
Double rotationText=DEFAULT_ROTATIONTEXT;
|
1163 |
|
1164 |
// if (!(values[3] instanceof NullValue)){
|
1165 |
// layer = values[3].toString();
|
1166 |
// }
|
1167 |
// if (!(values[4] instanceof NullValue)){
|
1168 |
// color = new Integer(((NumericValue)values[4]).intValue());
|
1169 |
// }
|
1170 |
// double[] velev = ((FGeometry) geom).getZs();
|
1171 |
// elevation = new Double(velev[0]);
|
1172 |
|
1173 |
// if (!(values[6] instanceof NullValue)){
|
1174 |
// thickness= new Double(((NumericValue)values[6]).doubleValue());
|
1175 |
// }
|
1176 |
if (fieldsDesc.length > 9) { |
1177 |
if (fieldsDesc[7].getFieldName().equals("Text") |
1178 |
&& !(values[7] instanceof NullValue)) { |
1179 |
text = values[7].toString();
|
1180 |
} |
1181 |
if (fieldsDesc[8].getFieldName().equals("HeightText") && |
1182 |
!(values[8] instanceof NullValue && |
1183 |
values[8] instanceof DoubleValue)) { |
1184 |
heightText = new Double(((NumericValue) values[8]) |
1185 |
.doubleValue()); |
1186 |
} |
1187 |
if (fieldsDesc[9].getFieldName().equals("RotationText") && |
1188 |
!(values[9] instanceof NullValue && |
1189 |
values[9] instanceof DoubleValue)) { |
1190 |
rotationText = new Double(((NumericValue) values[9]) |
1191 |
.doubleValue()); |
1192 |
} |
1193 |
} |
1194 |
DxfGroup handleText = new DxfGroup();
|
1195 |
handleText.setCode(1);
|
1196 |
handleText.setData(text); |
1197 |
|
1198 |
DxfGroup handleHeightText = new DxfGroup();
|
1199 |
handleHeightText.setCode(40);
|
1200 |
handleHeightText.setData(heightText); |
1201 |
|
1202 |
DxfGroup handleRotationText = new DxfGroup();
|
1203 |
handleRotationText.setCode(50);
|
1204 |
handleRotationText.setData(rotationText); |
1205 |
|
1206 |
// DxfGroup handleColor = new DxfGroup();
|
1207 |
// handleColor.setCode(62);
|
1208 |
// handleColor.setData(color);
|
1209 |
|
1210 |
// DxfGroup handleElevation = new DxfGroup();
|
1211 |
// handleElevation.setCode(38);
|
1212 |
// handleElevation.setData(elevation);
|
1213 |
|
1214 |
// DxfGroup handleThickness = new DxfGroup();
|
1215 |
// handleThickness.setCode(39);
|
1216 |
// handleThickness.setData(thickness);
|
1217 |
|
1218 |
|
1219 |
FPoint2D point = new FPoint2D(0, 0); |
1220 |
double[] pointCoords = new double[6]; |
1221 |
PathIterator pointIt = geom.getPathIterator(null); |
1222 |
while (!pointIt.isDone()) {
|
1223 |
pointIt.currentSegment(pointCoords); |
1224 |
point = new FPoint2D(pointCoords[0], pointCoords[1]); |
1225 |
pointIt.next(); |
1226 |
} |
1227 |
Point2D pto = new Point2D.Double(point.getX(), point.getY()); |
1228 |
// DxfGroup pointLayer = new DxfGroup(8, layer);
|
1229 |
DxfGroup handleGroup = new DxfGroup();
|
1230 |
handleGroup.setCode(5);
|
1231 |
handleGroup.setData(new Integer(handle + k).toString()); |
1232 |
DxfGroup px = new DxfGroup();
|
1233 |
DxfGroup py = new DxfGroup();
|
1234 |
DxfGroup pz = new DxfGroup();
|
1235 |
px.setCode(10);
|
1236 |
px.setData(new Double(pto.getX())); |
1237 |
py.setCode(20);
|
1238 |
py.setData(new Double(pto.getY())); |
1239 |
pz.setCode(30);
|
1240 |
// POINT del DXF tiene cota. Le asigno cero arbitrariamente.
|
1241 |
pz.setData(new Double(0.0)); |
1242 |
DxfGroupVector pv = updateProperties(values); |
1243 |
// pv.add(pointLayer);
|
1244 |
// pv.add(handleColor);
|
1245 |
// pv.add(handleElevation);
|
1246 |
// pv.add(handleThickness);
|
1247 |
pv.add(handleText); |
1248 |
pv.add(handleHeightText); |
1249 |
pv.add(handleRotationText); |
1250 |
pv.add(handleGroup); |
1251 |
pv.add(px); |
1252 |
pv.add(py); |
1253 |
pv.add(pz); |
1254 |
entityMaker.createText(pv); |
1255 |
} |
1256 |
private void createText3D(int handle, int k, IGeometry geom, Value[] values) |
1257 |
throws Exception { |
1258 |
// String layer=DEFAULT_LAYER;
|
1259 |
// Integer color=DEFAULT_COLOR;
|
1260 |
Double elevation = DEFAULT_ELEVATION;
|
1261 |
// Double thickness=DEFAULT_THICKNESS;
|
1262 |
String text = DEFAULT_TEXT;
|
1263 |
Double heightText = DEFAULT_HEIGHTTEXT;
|
1264 |
Double rotationText = DEFAULT_ROTATIONTEXT;
|
1265 |
|
1266 |
// if (!(values[3] instanceof NullValue)){
|
1267 |
// layer = values[3].toString();
|
1268 |
// }
|
1269 |
// if (!(values[4] instanceof NullValue)){
|
1270 |
// color = new Integer(((NumericValue)values[4]).intValue());
|
1271 |
// }
|
1272 |
double[] velev = ((FGeometry) geom).getZs(); |
1273 |
elevation = new Double(velev[0]); |
1274 |
|
1275 |
// if (!(values[6] instanceof NullValue)){
|
1276 |
// thickness= new Double(((NumericValue)values[6]).doubleValue());
|
1277 |
// }
|
1278 |
if (!(values[7] instanceof NullValue)) { |
1279 |
text = values[7].toString();
|
1280 |
} |
1281 |
if (!(values[8] instanceof NullValue && values[8] instanceof DoubleValue)) { |
1282 |
heightText = new Double(((NumericValue) values[8]).doubleValue()); |
1283 |
} |
1284 |
if (!(values[9] instanceof NullValue && values[9] instanceof DoubleValue)) { |
1285 |
rotationText = new Double(((NumericValue) values[9]).doubleValue()); |
1286 |
} |
1287 |
|
1288 |
DxfGroup handleText = new DxfGroup();
|
1289 |
handleText.setCode(1);
|
1290 |
handleText.setData(text); |
1291 |
|
1292 |
DxfGroup handleHeightText = new DxfGroup();
|
1293 |
handleHeightText.setCode(40);
|
1294 |
handleHeightText.setData(heightText); |
1295 |
|
1296 |
DxfGroup handleRotationText = new DxfGroup();
|
1297 |
handleRotationText.setCode(50);
|
1298 |
handleRotationText.setData(rotationText); |
1299 |
|
1300 |
// DxfGroup handleColor = new DxfGroup();
|
1301 |
// handleColor.setCode(62);
|
1302 |
// handleColor.setData(color);
|
1303 |
|
1304 |
DxfGroup handleElevation = new DxfGroup();
|
1305 |
handleElevation.setCode(38);
|
1306 |
handleElevation.setData(elevation); |
1307 |
|
1308 |
// DxfGroup handleThickness = new DxfGroup();
|
1309 |
// handleThickness.setCode(39);
|
1310 |
// handleThickness.setData(thickness);
|
1311 |
|
1312 |
//FPoint3D point = new FPoint3D(0, 0, 0);
|
1313 |
// double[] pointCoords = new double[6];
|
1314 |
FPoint3D point = (FPoint3D)geom.getInternalShape(); |
1315 |
// while (!pointIt.isDone()) {
|
1316 |
// pointIt.currentSegment(pointCoords);
|
1317 |
// point = new FPoint3D(pointCoords[0], pointCoords[1]);
|
1318 |
// pointIt.next();
|
1319 |
// }
|
1320 |
// Point2D pto = new Point2D.Double(point.getX(), point.getY());
|
1321 |
// DxfGroup pointLayer = new DxfGroup(8, layer);
|
1322 |
DxfGroup handleGroup = new DxfGroup();
|
1323 |
handleGroup.setCode(5);
|
1324 |
handleGroup.setData(new Integer(handle + k).toString()); |
1325 |
DxfGroup px = new DxfGroup();
|
1326 |
DxfGroup py = new DxfGroup();
|
1327 |
DxfGroup pz = new DxfGroup();
|
1328 |
px.setCode(10);
|
1329 |
px.setData(new Double(point.getX())); |
1330 |
py.setCode(20);
|
1331 |
py.setData(new Double(point.getY())); |
1332 |
pz.setCode(30);
|
1333 |
pz.setData(new Double(point.getZs()[0])); |
1334 |
DxfGroupVector pv = updateProperties(values); |
1335 |
// pv.add(pointLayer);
|
1336 |
// pv.add(handleColor);
|
1337 |
pv.add(handleElevation); |
1338 |
// pv.add(handleThickness);
|
1339 |
pv.add(handleText); |
1340 |
pv.add(handleHeightText); |
1341 |
pv.add(handleRotationText); |
1342 |
pv.add(handleGroup); |
1343 |
pv.add(px); |
1344 |
pv.add(py); |
1345 |
pv.add(pz); |
1346 |
entityMaker.createText(pv); |
1347 |
} |
1348 |
private boolean constantElevation(double[] velev) { |
1349 |
boolean constant = true; |
1350 |
for (int i = 0; i < velev.length; i++) { |
1351 |
for (int j = 0; j < velev.length; j++) { |
1352 |
if (j > i) {
|
1353 |
if (velev[i] != velev[j]) {
|
1354 |
constant = false;
|
1355 |
break;
|
1356 |
} |
1357 |
} |
1358 |
} |
1359 |
break;
|
1360 |
} |
1361 |
return constant;
|
1362 |
} |
1363 |
|
1364 |
/**
|
1365 |
* @return Returns the proj.
|
1366 |
*/
|
1367 |
public IProjection getProjection() {
|
1368 |
return proj;
|
1369 |
} |
1370 |
|
1371 |
/**
|
1372 |
* Util solo para el entity maker. Yo creo que esto no es necesario pero por
|
1373 |
* ahora lo necesito para que funcione. TODO: Hablar con Luis para que lo
|
1374 |
* aclare.
|
1375 |
*
|
1376 |
* @param proj
|
1377 |
* The proj to set.
|
1378 |
*/
|
1379 |
public void setProjection(IProjection proj) { |
1380 |
this.proj = proj;
|
1381 |
} |
1382 |
|
1383 |
public boolean canSaveEdits() { |
1384 |
if (file.canWrite()) return true; |
1385 |
return false; |
1386 |
} |
1387 |
|
1388 |
} |