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