svn-gvsig-desktop / trunk / libraries / libDataSourceBaseDrivers / src / org / gvsig / data / datastores / vectorial / driver / dxf / DXFFeaturesWriter.java @ 19603
History | View | Annotate | Download (27.8 KB)
1 |
package org.gvsig.data.datastores.vectorial.driver.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.util.Vector; |
8 |
|
9 |
import org.cresques.cts.IProjection; |
10 |
import org.cresques.geo.Point3D; |
11 |
import org.cresques.io.DxfFile; |
12 |
import org.cresques.io.DxfGroup; |
13 |
import org.cresques.io.DxfGroupVector; |
14 |
import org.cresques.px.dxf.DxfEntityMaker; |
15 |
import org.gvsig.data.datastores.vectorial.driver.IDriver; |
16 |
import org.gvsig.data.datastores.vectorial.driver.IFeaturesWriter; |
17 |
import org.gvsig.data.exception.InitializeWriterException; |
18 |
import org.gvsig.data.exception.WriteException; |
19 |
import org.gvsig.data.vectorial.IFeature; |
20 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
21 |
import org.gvsig.data.vectorial.IFeatureType; |
22 |
|
23 |
import com.iver.cit.gvsig.exceptions.visitors.ProcessWriterVisitorException; |
24 |
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException; |
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.IGeometry; |
33 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
34 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
35 |
import com.iver.cit.gvsig.fmap.edition.writers.dxf.DxfFieldsMapping; |
36 |
|
37 |
public class DXFFeaturesWriter implements IFeaturesWriter { |
38 |
private String DEFAULT_LAYER="default"; |
39 |
private Integer DEFAULT_COLOR=new Integer(0); |
40 |
private Double DEFAULT_ELEVATION=new Double(0); |
41 |
private Double DEFAULT_THICKNESS=new Double(0); |
42 |
private String DEFAULT_TEXT=""; |
43 |
private Double DEFAULT_HEIGHTTEXT=new Double(10); |
44 |
private Double DEFAULT_ROTATIONTEXT=new Double(0); |
45 |
|
46 |
private DxfFieldsMapping fieldsMapping = null; |
47 |
|
48 |
private File file; |
49 |
|
50 |
private DxfFile.EntityFactory entityMaker;
|
51 |
|
52 |
private IProjection proj = null; |
53 |
|
54 |
private DxfFile dxfFile;
|
55 |
|
56 |
int handle = 40; // Revisar porqu? es 40. |
57 |
|
58 |
int k = 0; |
59 |
|
60 |
boolean dxf3DFile = false; |
61 |
private int indexText=-1;//En DXF es 7. |
62 |
private int indexHeightText=-1;//En DXF es 8. |
63 |
private int indexRotationText=-1;//En DXF es 9. |
64 |
private IFeatureType featureType;
|
65 |
|
66 |
public void init(IDriver driver) { |
67 |
DXFDriverParameters dxfParameters=(DXFDriverParameters)driver.getParameters(); |
68 |
file=dxfParameters.getDXFFile(); |
69 |
proj=dxfParameters.getProjection(); |
70 |
featureType=driver.getFeatureType(); |
71 |
fieldsMapping = new DxfFieldsMapping();
|
72 |
fieldsMapping.setLayerField("Layer");
|
73 |
fieldsMapping.setColorField("Color");
|
74 |
fieldsMapping.setElevationField("Elevation");
|
75 |
fieldsMapping.setThicknessField("Thickness");
|
76 |
fieldsMapping.setTextField("Text");
|
77 |
fieldsMapping.setHeightText("HeightText");
|
78 |
fieldsMapping.setRotationText("Layer");
|
79 |
} |
80 |
|
81 |
public void postProcess() throws WriteException { |
82 |
// Escribimos realmente lo que hemos montado en memoria.
|
83 |
dxfFile = new DxfFile(null, file.getAbsolutePath(), entityMaker); |
84 |
dxfFile.setCadFlag(true);
|
85 |
if (dxf3DFile)
|
86 |
dxfFile.setDxf3DFlag(true);
|
87 |
try {
|
88 |
dxfFile.save(file.getAbsolutePath()); |
89 |
} catch (IOException e) { |
90 |
throw new WriteException("DXF Writer",e); |
91 |
} |
92 |
} |
93 |
|
94 |
public void preProcess() throws InitializeWriterException { |
95 |
if (fieldsMapping == null) { |
96 |
throw new InitializeWriterException ("DXF Writer",null); |
97 |
} |
98 |
// NOTA: La proyecci?n no se usa absolutamente para nada (al menos
|
99 |
// por ahora). Las entidades se escribir?n con las coordenadas con
|
100 |
// las que se crean.
|
101 |
// if (proj == null) {
|
102 |
// throw new StartWriterVisitorException (getName(),null);
|
103 |
// }
|
104 |
|
105 |
entityMaker = new DxfEntityMaker(proj);
|
106 |
// FieldDescription[] fieldDescriptions=getTableDefinition().getFieldsDesc();
|
107 |
for (int i=0;i<featureType.size();i++){ |
108 |
IFeatureAttributeDescriptor fad=(IFeatureAttributeDescriptor)featureType.get(i); |
109 |
if (fad.getName().equals("Text")){ |
110 |
indexText=i; |
111 |
}else if (fad.getName().equals("HeightText")){ |
112 |
indexHeightText=i; |
113 |
}else if (fad.getName().equals("RotationText")){ |
114 |
indexRotationText=i; |
115 |
} |
116 |
} |
117 |
} |
118 |
|
119 |
public void insertFeature(IFeature feature) throws WriteException { |
120 |
try {
|
121 |
IGeometry geom = (IGeometry)feature.getDefaultGeometry(); |
122 |
// Value[] values=row.getAttributes();
|
123 |
// TODO: Tratamiento de los campos
|
124 |
// y modificar los createXXX para que acepten como par?metro
|
125 |
// los datos de LAYER, COLOR, ELEVATION, THICKNESS, TEXT
|
126 |
// HEIGHTTEXT, ROTATIONTEXT y el resto que puedan hacer
|
127 |
// falta.
|
128 |
|
129 |
if (geom.getGeometryType()==FShape.POINT) {
|
130 |
k=createPoint2D(handle, k, feature); |
131 |
} else if (geom.getGeometryType()==(FShape.POINT | FShape.Z)) { |
132 |
dxf3DFile = true;
|
133 |
k=createPoint3D(handle, k, feature); |
134 |
} else if (geom.getGeometryType()==FShape.LINE) { |
135 |
k=createLwPolyline2D(handle, k, feature, false);
|
136 |
} else if (geom.getGeometryType()==(FShape.LINE | FShape.Z)) { |
137 |
dxf3DFile = true;
|
138 |
k = createPolyline3D(handle, k, feature); |
139 |
} else if (geom.getGeometryType()==FShape.POLYGON) { |
140 |
// createPolygon2D(handle, k, geom);
|
141 |
k=createLwPolyline2D(handle, k, feature, true);
|
142 |
} else if (geom.getGeometryType()==(FShape.POLYGON | FShape.Z)) { |
143 |
dxf3DFile = true;
|
144 |
k = createPolyline3D(handle, k, feature); |
145 |
// k = createPolygon3D(handle, k, geom);
|
146 |
} else if (geom.getGeometryType()==FShape.CIRCLE) { |
147 |
// FCircle2D circle = (FCircle2D) geom.getInternalShape();
|
148 |
k=createCircle2D(handle, k, feature); |
149 |
} else if (geom.getGeometryType()==FShape.ARC) { |
150 |
// FArc2D arc = (FArc2D) geom.getInternalShape();
|
151 |
k=createArc2D(handle, k, feature); |
152 |
} else if (geom.getGeometryType()==FShape.ELLIPSE) { |
153 |
// FEllipse2D ellipse = (FEllipse2D) geom.getInternalShape();
|
154 |
k=createEllipse2D(handle, k, feature); |
155 |
} else {
|
156 |
System.out.println("IGeometry not supported yet"); |
157 |
k++; |
158 |
} |
159 |
} |
160 |
catch(Exception e){ |
161 |
throw new WriteException("DXF Writer",e); |
162 |
} |
163 |
|
164 |
|
165 |
} |
166 |
public void updateFeatureType(IFeatureType featureType) { |
167 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
168 |
|
169 |
} |
170 |
|
171 |
|
172 |
private int createPoint2D(int handle, int k, IFeature feature) throws Exception { |
173 |
|
174 |
if (indexText!= -1 && !(feature.get(indexText) == null)){ |
175 |
return createText2D(handle,k,feature);
|
176 |
} |
177 |
FPoint2D point = new FPoint2D(0, 0); |
178 |
double[] pointCoords = new double[6]; |
179 |
PathIterator pointIt = ((IGeometry)feature.getDefaultGeometry()).getPathIterator(null); |
180 |
while (!pointIt.isDone()) {
|
181 |
pointIt.currentSegment(pointCoords); |
182 |
point = new FPoint2D(pointCoords[0], pointCoords[1]); |
183 |
pointIt.next(); |
184 |
} |
185 |
Point2D pto = new Point2D.Double(point.getX(), point.getY()); |
186 |
|
187 |
DxfGroup px = new DxfGroup();
|
188 |
DxfGroup py = new DxfGroup();
|
189 |
DxfGroup pz = new DxfGroup();
|
190 |
px.setCode(10);
|
191 |
px.setData(new Double(pto.getX())); |
192 |
py.setCode(20);
|
193 |
py.setData(new Double(pto.getY())); |
194 |
pz.setCode(30);
|
195 |
// POINT del DXF tiene cota. Le asigno cero arbitrariamente.
|
196 |
pz.setData(new Double(0.0)); |
197 |
DxfGroupVector pv = updateProperties(feature,k); |
198 |
// pv.add(pointLayer);
|
199 |
// pv.add(handleGroup);
|
200 |
// pv.add(handleColor);
|
201 |
// pv.add(handleElevation);
|
202 |
// pv.add(handleThickness);
|
203 |
pv.add(px); |
204 |
pv.add(py); |
205 |
pv.add(pz); |
206 |
entityMaker.createPoint(pv); |
207 |
k++; |
208 |
return k;
|
209 |
} |
210 |
private int createText2D(int handle, int k, IFeature feature) throws Exception { |
211 |
String text=DEFAULT_TEXT;
|
212 |
Double heightText=DEFAULT_HEIGHTTEXT;
|
213 |
Double rotationText=DEFAULT_ROTATIONTEXT;
|
214 |
|
215 |
if (indexText!=-1 && !(feature.get(indexText) == null)) { |
216 |
text = feature.get(indexText).toString(); |
217 |
} |
218 |
if (indexHeightText!=-1 && !(feature.get(indexHeightText) instanceof Number)) { |
219 |
heightText = new Double(((Number) feature.get(indexHeightText)) |
220 |
.doubleValue()); |
221 |
} |
222 |
if (indexRotationText!=-1 && !(feature.get(indexRotationText) instanceof Number)) { |
223 |
rotationText = new Double(((Number) feature.get(indexRotationText)) |
224 |
.doubleValue()); |
225 |
} |
226 |
DxfGroup handleText = new DxfGroup();
|
227 |
handleText.setCode(1);
|
228 |
handleText.setData(text); |
229 |
|
230 |
DxfGroup handleHeightText = new DxfGroup();
|
231 |
handleHeightText.setCode(40);
|
232 |
handleHeightText.setData(heightText); |
233 |
|
234 |
DxfGroup handleRotationText = new DxfGroup();
|
235 |
handleRotationText.setCode(50);
|
236 |
handleRotationText.setData(rotationText); |
237 |
|
238 |
// DxfGroup handleColor = new DxfGroup();
|
239 |
// handleColor.setCode(62);
|
240 |
// handleColor.setData(color);
|
241 |
|
242 |
// DxfGroup handleElevation = new DxfGroup();
|
243 |
// handleElevation.setCode(38);
|
244 |
// handleElevation.setData(elevation);
|
245 |
|
246 |
// DxfGroup handleThickness = new DxfGroup();
|
247 |
// handleThickness.setCode(39);
|
248 |
// handleThickness.setData(thickness);
|
249 |
|
250 |
|
251 |
FPoint2D point = new FPoint2D(0, 0); |
252 |
double[] pointCoords = new double[6]; |
253 |
PathIterator pointIt = ((IGeometry)feature.getDefaultGeometry()).getPathIterator(null); |
254 |
while (!pointIt.isDone()) {
|
255 |
pointIt.currentSegment(pointCoords); |
256 |
point = new FPoint2D(pointCoords[0], pointCoords[1]); |
257 |
pointIt.next(); |
258 |
} |
259 |
Point2D pto = new Point2D.Double(point.getX(), point.getY()); |
260 |
// DxfGroup pointLayer = new DxfGroup(8, layer);
|
261 |
DxfGroup handleGroup = new DxfGroup();
|
262 |
handleGroup.setCode(5);
|
263 |
handleGroup.setData(new Integer(handle + k).toString()); |
264 |
DxfGroup px = new DxfGroup();
|
265 |
DxfGroup py = new DxfGroup();
|
266 |
DxfGroup pz = new DxfGroup();
|
267 |
px.setCode(10);
|
268 |
px.setData(new Double(pto.getX())); |
269 |
py.setCode(20);
|
270 |
py.setData(new Double(pto.getY())); |
271 |
pz.setCode(30);
|
272 |
// POINT del DXF tiene cota. Le asigno cero arbitrariamente.
|
273 |
pz.setData(new Double(0.0)); |
274 |
DxfGroupVector pv = updateProperties(feature,k); |
275 |
// pv.add(pointLayer);
|
276 |
// pv.add(handleColor);
|
277 |
// pv.add(handleElevation);
|
278 |
// pv.add(handleThickness);
|
279 |
pv.add(handleText); |
280 |
pv.add(handleHeightText); |
281 |
pv.add(handleRotationText); |
282 |
pv.add(handleGroup); |
283 |
pv.add(px); |
284 |
pv.add(py); |
285 |
pv.add(pz); |
286 |
entityMaker.createText(pv); |
287 |
k++; |
288 |
return k;
|
289 |
} |
290 |
private DxfGroupVector updateProperties(IFeature feature,int k){ |
291 |
DxfGroupVector polv = new DxfGroupVector();
|
292 |
String layer=DEFAULT_LAYER;
|
293 |
Integer color=DEFAULT_COLOR;
|
294 |
// Double elevation=DEFAULT_ELEVATION;
|
295 |
Double thickness=DEFAULT_THICKNESS;
|
296 |
if (featureType.size() > 6) { |
297 |
IFeatureAttributeDescriptor fad=(IFeatureAttributeDescriptor)featureType.get(3);
|
298 |
if (fad.getName().equals("Layer") && |
299 |
!(feature.get(3) == null) && |
300 |
feature.get(3) instanceof String) { |
301 |
layer = feature.get(3).toString();
|
302 |
} |
303 |
fad=(IFeatureAttributeDescriptor)featureType.get(4);
|
304 |
if (fad.getName().equals("Color") |
305 |
&& !(feature.get(4) == null) && |
306 |
feature.get(4) instanceof Number) { |
307 |
color = new Integer(((Number) feature.get(4)).intValue()); |
308 |
} |
309 |
// if (!(values[5] instanceof NullValue)){
|
310 |
// elevation= new Double(((NumericValue)values[5]).doubleValue());
|
311 |
// }
|
312 |
fad=(IFeatureAttributeDescriptor)featureType.get(6);
|
313 |
if (fad.getName().equals("Thickness") && |
314 |
!(feature.get(6) == null) && |
315 |
feature.get(6) instanceof Number) { |
316 |
thickness = new Double(((Number) feature.get(6)).doubleValue()); |
317 |
} |
318 |
} |
319 |
DxfGroup geometryLayer = new DxfGroup(8, layer); |
320 |
|
321 |
DxfGroup handleGroup = new DxfGroup();
|
322 |
handleGroup.setCode(5);
|
323 |
handleGroup.setData(new Integer(handle + k).toString()); |
324 |
|
325 |
DxfGroup handleColor = new DxfGroup();
|
326 |
handleColor.setCode(62);
|
327 |
handleColor.setData(color); |
328 |
|
329 |
// DxfGroup handleElevation = new DxfGroup();
|
330 |
// handleElevation.setCode(38);
|
331 |
// handleElevation.setData(elevation);
|
332 |
|
333 |
DxfGroup handleThickness = new DxfGroup();
|
334 |
handleThickness.setCode(39);
|
335 |
handleThickness.setData(thickness); |
336 |
|
337 |
|
338 |
polv.add(geometryLayer); |
339 |
// polv.add(handleElevation);
|
340 |
polv.add(handleGroup); |
341 |
polv.add(handleColor); |
342 |
return polv;
|
343 |
} |
344 |
private int createPoint3D(int handle, int k, IFeature feature) throws Exception { |
345 |
if (indexText!=-1 && !(feature.get(indexText) == null)){ |
346 |
return createText3D(handle,k,feature);
|
347 |
} |
348 |
FPoint3D point = new FPoint3D(0, 0, 0); |
349 |
double[] pointCoords = new double[6]; |
350 |
PathIterator pointIt = ((IGeometry)feature.getDefaultGeometry()).getPathIterator(null); |
351 |
while (!pointIt.isDone()) {
|
352 |
pointIt.currentSegment(pointCoords); |
353 |
point = new FPoint3D(pointCoords[0], pointCoords[1], pointCoords[2]); |
354 |
pointIt.next(); |
355 |
} |
356 |
Point3D pto = new Point3D(point.getX(), point.getY(), point.getZs()[0]); |
357 |
// DxfGroup pointLayer = new DxfGroup(8, "default");
|
358 |
// DxfGroup handleGroup = new DxfGroup();
|
359 |
// handleGroup.setCode(5);
|
360 |
// handleGroup.setData(new Integer(handle + k).toString());
|
361 |
DxfGroup px = new DxfGroup();
|
362 |
DxfGroup py = new DxfGroup();
|
363 |
DxfGroup pz = new DxfGroup();
|
364 |
px.setCode(10);
|
365 |
px.setData(new Double(pto.getX())); |
366 |
py.setCode(20);
|
367 |
py.setData(new Double(pto.getY())); |
368 |
pz.setCode(30);
|
369 |
pz.setData(new Double(pto.getZ())); |
370 |
double[] velev = ((FGeometry) feature.getDefaultGeometry()).getZs(); |
371 |
Double elevation= DEFAULT_ELEVATION;
|
372 |
elevation = new Double(velev[0]); |
373 |
DxfGroup handleElevation = new DxfGroup();
|
374 |
handleElevation.setCode(38);
|
375 |
handleElevation.setData(elevation); |
376 |
|
377 |
DxfGroupVector pv = updateProperties(feature,k); |
378 |
pv.add(handleElevation); |
379 |
// pv.add(pointLayer);
|
380 |
// pv.add(handleGroup);
|
381 |
pv.add(px); |
382 |
pv.add(py); |
383 |
pv.add(pz); |
384 |
entityMaker.createPoint(pv); |
385 |
k++; |
386 |
return k;
|
387 |
} |
388 |
private int createText3D(int handle, int k, IFeature feature) throws Exception { |
389 |
Double elevation = DEFAULT_ELEVATION;
|
390 |
String text = DEFAULT_TEXT;
|
391 |
Double heightText = DEFAULT_HEIGHTTEXT;
|
392 |
Double rotationText = DEFAULT_ROTATIONTEXT;
|
393 |
|
394 |
double[] velev = ((FGeometry) feature.getDefaultGeometry()).getZs(); |
395 |
elevation = new Double(velev[0]); |
396 |
|
397 |
if (indexText!=-1 && !(feature.get(indexText) == null)) { |
398 |
text = feature.get(indexText).toString(); |
399 |
} |
400 |
if (indexHeightText!=-1 && feature.get(indexHeightText) instanceof Number) { |
401 |
heightText = new Double(((Number) feature.get(indexHeightText)).doubleValue()); |
402 |
} |
403 |
if (indexRotationText!=-1 && feature.get(indexRotationText) instanceof Number) { |
404 |
rotationText = new Double(((Number) feature.get(indexRotationText)).doubleValue()); |
405 |
} |
406 |
|
407 |
DxfGroup handleText = new DxfGroup();
|
408 |
handleText.setCode(1);
|
409 |
handleText.setData(text); |
410 |
|
411 |
DxfGroup handleHeightText = new DxfGroup();
|
412 |
handleHeightText.setCode(40);
|
413 |
handleHeightText.setData(heightText); |
414 |
|
415 |
DxfGroup handleRotationText = new DxfGroup();
|
416 |
handleRotationText.setCode(50);
|
417 |
handleRotationText.setData(rotationText); |
418 |
|
419 |
// DxfGroup handleColor = new DxfGroup();
|
420 |
// handleColor.setCode(62);
|
421 |
// handleColor.setData(color);
|
422 |
|
423 |
DxfGroup handleElevation = new DxfGroup();
|
424 |
handleElevation.setCode(38);
|
425 |
handleElevation.setData(elevation); |
426 |
|
427 |
// DxfGroup handleThickness = new DxfGroup();
|
428 |
// handleThickness.setCode(39);
|
429 |
// handleThickness.setData(thickness);
|
430 |
|
431 |
// FPoint3D point = new FPoint3D(0, 0, 0);
|
432 |
// double[] pointCoords = new double[6];
|
433 |
FPoint3D point = (FPoint3D)((IGeometry)feature.getDefaultGeometry()).getInternalShape(); |
434 |
// while (!pointIt.isDone()) {
|
435 |
// pointIt.currentSegment(pointCoords);
|
436 |
// point = new FPoint3D(pointCoords[0], pointCoords[1]);
|
437 |
// pointIt.next();
|
438 |
// }
|
439 |
// Point2D pto = new Point2D.Double(point.getX(), point.getY());
|
440 |
// DxfGroup pointLayer = new DxfGroup(8, layer);
|
441 |
DxfGroup handleGroup = new DxfGroup();
|
442 |
handleGroup.setCode(5);
|
443 |
handleGroup.setData(new Integer(handle + k).toString()); |
444 |
DxfGroup px = new DxfGroup();
|
445 |
DxfGroup py = new DxfGroup();
|
446 |
DxfGroup pz = new DxfGroup();
|
447 |
px.setCode(10);
|
448 |
px.setData(new Double(point.getX())); |
449 |
py.setCode(20);
|
450 |
py.setData(new Double(point.getY())); |
451 |
pz.setCode(30);
|
452 |
pz.setData(new Double(point.getZs()[0])); |
453 |
DxfGroupVector pv = updateProperties(feature,k); |
454 |
// pv.add(pointLayer);
|
455 |
// pv.add(handleColor);
|
456 |
pv.add(handleElevation); |
457 |
// pv.add(handleThickness);
|
458 |
pv.add(handleText); |
459 |
pv.add(handleHeightText); |
460 |
pv.add(handleRotationText); |
461 |
pv.add(handleGroup); |
462 |
pv.add(px); |
463 |
pv.add(py); |
464 |
pv.add(pz); |
465 |
entityMaker.createText(pv); |
466 |
k++; |
467 |
return k;
|
468 |
} |
469 |
private int createLwPolyline2D(int handle, int k, IFeature feature, boolean isPolygon) |
470 |
throws Exception { |
471 |
boolean first=true; |
472 |
DxfGroupVector polv = updateProperties(feature,k); |
473 |
Vector vpoints = new Vector(); |
474 |
|
475 |
DxfGroup polylineFlag = new DxfGroup();
|
476 |
polylineFlag.setCode(70);
|
477 |
if (isPolygon)
|
478 |
polylineFlag.setData(new Integer(1)); // cerrada |
479 |
else
|
480 |
polylineFlag.setData(new Integer(0)); // abierta |
481 |
|
482 |
PathIterator theIterator = ((IGeometry)feature.getDefaultGeometry()).getPathIterator(null, FConverter.FLATNESS); // polyLine.getPathIterator(null, |
483 |
// flatness);
|
484 |
|
485 |
double[] theData = new double[6]; |
486 |
while (!theIterator.isDone()) {
|
487 |
int theType = theIterator.currentSegment(theData);
|
488 |
switch (theType) {
|
489 |
case PathIterator.SEG_MOVETO: |
490 |
if (!first)
|
491 |
{ |
492 |
for (int j = 0; j < vpoints.size(); j++) { |
493 |
DxfGroup xvertex = new DxfGroup();
|
494 |
xvertex.setCode(10);
|
495 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
496 |
DxfGroup yvertex = new DxfGroup();
|
497 |
yvertex.setCode(20);
|
498 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
499 |
polv.add(xvertex); |
500 |
polv.add(yvertex); |
501 |
} |
502 |
|
503 |
entityMaker.createLwPolyline(polv); |
504 |
k++; |
505 |
polv = updateProperties(feature,k); |
506 |
|
507 |
} |
508 |
first=false;
|
509 |
polv.add(polylineFlag); |
510 |
vpoints.clear(); |
511 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
512 |
break;
|
513 |
case PathIterator.SEG_LINETO: |
514 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
515 |
break;
|
516 |
case PathIterator.SEG_QUADTO: |
517 |
// vpoints.add(new FPoint2D(theData[0], theData[1]));
|
518 |
// vpoints.add(new FPoint2D(theData[2], theData[3]));
|
519 |
break;
|
520 |
case PathIterator.SEG_CUBICTO: |
521 |
// vpoints.add(new FPoint2D(theData[0], theData[1]));
|
522 |
// vpoints.add(new FPoint2D(theData[2], theData[3]));
|
523 |
// vpoints.add(new FPoint2D(theData[4], theData[5]));
|
524 |
break;
|
525 |
case PathIterator.SEG_CLOSE: |
526 |
polylineFlag.setData(new Integer(1)); // cerrada |
527 |
break;
|
528 |
|
529 |
} |
530 |
theIterator.next(); |
531 |
} |
532 |
|
533 |
for (int j = 0; j < vpoints.size(); j++) { |
534 |
DxfGroup xvertex = new DxfGroup();
|
535 |
xvertex.setCode(10);
|
536 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
537 |
DxfGroup yvertex = new DxfGroup();
|
538 |
yvertex.setCode(20);
|
539 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
540 |
polv.add(xvertex); |
541 |
polv.add(yvertex); |
542 |
} |
543 |
|
544 |
entityMaker.createLwPolyline(polv); |
545 |
k++; |
546 |
return k;
|
547 |
} |
548 |
|
549 |
private int createPolyline3D(int handle, int k, IFeature feature) |
550 |
throws Exception { |
551 |
DxfGroupVector polv = updateProperties(feature,k); |
552 |
Vector vpoints = new Vector(); |
553 |
PathIterator theIterator = ((IGeometry)feature.getDefaultGeometry()).getPathIterator(null, FConverter.FLATNESS); // polyLine.getPathIterator(null, |
554 |
// flatness);
|
555 |
double[] theData = new double[6]; |
556 |
double[] velev = ((FGeometry) feature.getDefaultGeometry()).getZs(); |
557 |
while (!theIterator.isDone()) {
|
558 |
int theType = theIterator.currentSegment(theData);
|
559 |
switch (theType) {
|
560 |
case PathIterator.SEG_MOVETO: |
561 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
562 |
break;
|
563 |
case PathIterator.SEG_LINETO: |
564 |
vpoints.add(new FPoint2D(theData[0], theData[1])); |
565 |
break;
|
566 |
} |
567 |
theIterator.next(); |
568 |
} |
569 |
if (constantElevation(velev)) {
|
570 |
DxfGroup polylineFlag = new DxfGroup();
|
571 |
polylineFlag.setCode(70);
|
572 |
polylineFlag.setData(new Integer(0)); |
573 |
polv.add(polylineFlag); |
574 |
DxfGroup elevation = new DxfGroup();
|
575 |
elevation.setCode(38);
|
576 |
elevation.setData(new Double(velev[0])); |
577 |
polv.add(elevation); |
578 |
for (int j = 0; j < vpoints.size(); j++) { |
579 |
DxfGroup xvertex = new DxfGroup();
|
580 |
xvertex.setCode(10);
|
581 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
582 |
DxfGroup yvertex = new DxfGroup();
|
583 |
yvertex.setCode(20);
|
584 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
585 |
polv.add(xvertex); |
586 |
polv.add(yvertex); |
587 |
} |
588 |
entityMaker.createLwPolyline(polv); |
589 |
k++; |
590 |
} else {
|
591 |
DxfGroup polylineFlag = new DxfGroup();
|
592 |
polylineFlag.setCode(70);
|
593 |
polylineFlag.setData(new Integer(8)); |
594 |
polv.add(polylineFlag); |
595 |
DxfGroup xgroup = new DxfGroup();
|
596 |
xgroup.setCode(10);
|
597 |
xgroup.setData(new Double(0.0)); |
598 |
polv.add(xgroup); |
599 |
DxfGroup ygroup = new DxfGroup();
|
600 |
ygroup.setCode(20);
|
601 |
ygroup.setData(new Double(0.0)); |
602 |
polv.add(ygroup); |
603 |
DxfGroup elevation = new DxfGroup();
|
604 |
elevation.setCode(30);
|
605 |
elevation.setData(new Double(0.0)); |
606 |
polv.add(elevation); |
607 |
DxfGroup subclassMarker = new DxfGroup(100, "AcDb3dPolyline"); |
608 |
polv.add(subclassMarker); |
609 |
entityMaker.createPolyline(polv); |
610 |
k++; |
611 |
for (int j = 0; j < vpoints.size(); j++) { |
612 |
DxfGroupVector verv = new DxfGroupVector();
|
613 |
DxfGroup entityType = new DxfGroup(0, "VERTEX"); |
614 |
verv.add(entityType); |
615 |
DxfGroup generalSubclassMarker = new DxfGroup(100, "AcDbEntity"); |
616 |
verv.add(generalSubclassMarker); |
617 |
DxfGroup layerName = new DxfGroup(8, "default"); |
618 |
verv.add(layerName); |
619 |
DxfGroup vertexSubclassMarker = new DxfGroup(100, "AcDbVertex"); |
620 |
verv.add(vertexSubclassMarker); |
621 |
// DxfGroup vertex3DSubclassMarker = new DxfGroup(100,
|
622 |
// "AcDb3dPolylineVertex");
|
623 |
// verv.add(vertex3DSubclassMarker);
|
624 |
DxfGroup xvertex = new DxfGroup();
|
625 |
xvertex.setCode(10);
|
626 |
xvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getX())); |
627 |
DxfGroup yvertex = new DxfGroup();
|
628 |
yvertex.setCode(20);
|
629 |
yvertex.setData(new Double(((FPoint2D) vpoints.get(j)).getY())); |
630 |
DxfGroup zvertex = new DxfGroup();
|
631 |
zvertex.setCode(30);
|
632 |
zvertex.setData(new Double(velev[j])); |
633 |
verv.add(xvertex); |
634 |
verv.add(yvertex); |
635 |
verv.add(zvertex); |
636 |
entityMaker.addVertex(verv); |
637 |
k++; |
638 |
} |
639 |
DxfGroupVector seqv = new DxfGroupVector();
|
640 |
DxfGroup entityType = new DxfGroup(0, "SEQEND"); |
641 |
seqv.add(entityType); |
642 |
// DxfGroup handle = new DxfGroup();
|
643 |
// elevation.setCode(5);
|
644 |
// elevation.setData(new Integer(getHandle()));
|
645 |
// seqv.add(handle);
|
646 |
DxfGroup generalSubclassMarker = new DxfGroup(100, "AcDbEntity"); |
647 |
seqv.add(generalSubclassMarker); |
648 |
DxfGroup layerName = new DxfGroup(8, "default"); |
649 |
seqv.add(layerName); |
650 |
DxfGroup handleSeqGroup = new DxfGroup();
|
651 |
handleSeqGroup.setCode(5);
|
652 |
handleSeqGroup.setData(new Integer(handle + k).toString()); |
653 |
seqv.add(handleSeqGroup); |
654 |
entityMaker.endSeq(); |
655 |
k++; |
656 |
} |
657 |
return k;
|
658 |
} |
659 |
|
660 |
private boolean constantElevation(double[] velev) { |
661 |
boolean constant = true; |
662 |
for (int i = 0; i < velev.length; i++) { |
663 |
for (int j = 0; j < velev.length; j++) { |
664 |
if (j > i) {
|
665 |
if (velev[i] != velev[j]) {
|
666 |
constant = false;
|
667 |
break;
|
668 |
} |
669 |
} |
670 |
} |
671 |
break;
|
672 |
} |
673 |
return constant;
|
674 |
} |
675 |
private int createCircle2D(int handle, int k, IFeature feature) throws Exception { |
676 |
DxfGroupVector polv = updateProperties(feature,k); |
677 |
DxfGroup circleFlag = new DxfGroup();
|
678 |
circleFlag.setCode(100);
|
679 |
polv.add(circleFlag); |
680 |
|
681 |
DxfGroup xvertex = new DxfGroup();
|
682 |
xvertex.setCode(10);
|
683 |
FCircle2D circle = (FCircle2D) ((IGeometry)feature.getDefaultGeometry()).getInternalShape(); |
684 |
xvertex.setData(new Double(circle.getCenter().getX())); |
685 |
DxfGroup yvertex = new DxfGroup();
|
686 |
yvertex.setCode(20);
|
687 |
yvertex.setData(new Double(circle.getCenter().getY())); |
688 |
DxfGroup zvertex = new DxfGroup();
|
689 |
zvertex.setCode(30);
|
690 |
zvertex.setData(new Double(0)); // TODO: COORDENADA Z. REVISAR ESTO PARA |
691 |
// ENTIDADES 3D
|
692 |
|
693 |
DxfGroup radius = new DxfGroup();
|
694 |
radius.setCode(40);
|
695 |
radius.setData(new Double(circle.getRadio())); |
696 |
|
697 |
polv.add(xvertex); |
698 |
polv.add(yvertex); |
699 |
polv.add(zvertex); |
700 |
polv.add(radius); |
701 |
|
702 |
entityMaker.createCircle(polv); |
703 |
k++; |
704 |
return k;
|
705 |
} |
706 |
private int createArc2D(int handle, int k,IFeature feature) throws Exception { |
707 |
FArc2D arc = (FArc2D) ((IGeometry)feature.getDefaultGeometry()).getInternalShape(); |
708 |
Point2D[] pts = new Point2D[3]; |
709 |
pts[0] = arc.getInit();
|
710 |
pts[1] = arc.getMid();
|
711 |
pts[2] = arc.getEnd();
|
712 |
Point2D center = arc.getCenter();
|
713 |
double radius = center.distance(pts[0]); |
714 |
double initAngle = UtilFunctions.getAngle(center, pts[0]); |
715 |
initAngle = Math.toDegrees(initAngle);
|
716 |
// System.out.println("initAngle = " + initAngle);
|
717 |
double midAngle = UtilFunctions.getAngle(center, pts[1]); |
718 |
midAngle = Math.toDegrees(midAngle);
|
719 |
// System.out.println("midAngle = " + midAngle);
|
720 |
double endAngle = UtilFunctions.getAngle(center, pts[2]); |
721 |
endAngle = Math.toDegrees(endAngle);
|
722 |
|
723 |
// if (!UtilFunctions.isCCW(pts[0],pts[1],pts[2])){
|
724 |
if (!FConverter.isCCW(pts)){
|
725 |
double aux=initAngle;
|
726 |
initAngle=endAngle; |
727 |
endAngle=aux; |
728 |
} |
729 |
// DxfGroup arcLayer = new DxfGroup(8, "default");
|
730 |
DxfGroup ax = new DxfGroup();
|
731 |
DxfGroup ay = new DxfGroup();
|
732 |
DxfGroup ac = new DxfGroup();
|
733 |
DxfGroup ai = new DxfGroup();
|
734 |
DxfGroup ae = new DxfGroup();
|
735 |
ax.setCode(10);
|
736 |
ax.setData(new Double(center.getX())); |
737 |
ay.setCode(20);
|
738 |
ay.setData(new Double(center.getY())); |
739 |
ac.setCode(40);
|
740 |
ac.setData(new Double(radius)); |
741 |
ai.setCode(50);
|
742 |
ai.setData(new Double(initAngle)); |
743 |
ae.setCode(51);
|
744 |
ae.setData(new Double(endAngle)); |
745 |
DxfGroupVector av = updateProperties(feature,k); |
746 |
// av.add(arcLayer);
|
747 |
av.add(ax); |
748 |
av.add(ay); |
749 |
av.add(ac); |
750 |
av.add(ai); |
751 |
av.add(ae); |
752 |
entityMaker.createArc(av); |
753 |
k++; |
754 |
return k;
|
755 |
} |
756 |
private int createEllipse2D(int handle, int k,IFeature feature) throws Exception { |
757 |
FEllipse2D ellipse = (FEllipse2D)((IGeometry)feature.getDefaultGeometry()).getInternalShape(); |
758 |
|
759 |
Point2D center = new Point2D.Double((ellipse.getInit().getX() + ellipse |
760 |
.getEnd().getX()) / 2, (ellipse.getInit().getY() + ellipse.getEnd()
|
761 |
.getY()) / 2);
|
762 |
double mAxisL = ellipse.getDist() * 2; |
763 |
// System.out.println("mAxisL = " + mAxisL);
|
764 |
/*
|
765 |
* System.out.println("mAxisL/(center.distance(fElip.getEnd()))*2 = " +
|
766 |
* mAxisL/(center.distance(fElip.getEnd()))*2); minToMaj.setData(new
|
767 |
* Double(mAxisL/()*2));
|
768 |
*/
|
769 |
double maAxisL = ellipse.getInit().distance(ellipse.getEnd());
|
770 |
|
771 |
Point2D endPointOfMajorAxis = ellipse.getEnd();
|
772 |
double azimut = Math.atan2(endPointOfMajorAxis.getX() - center.getX(), |
773 |
endPointOfMajorAxis.getY() - center.getY()); |
774 |
double azimut2 = azimut + Math.PI / 2.0; |
775 |
if (azimut2 >= Math.PI * 2) |
776 |
azimut2 = azimut2 - Math.PI * 2; |
777 |
Point2D endPointOfMinorAxis = new Point2D.Double(center.getX() |
778 |
+ (ellipse.getDist() * Math.sin(azimut2)), center.getY()
|
779 |
+ (ellipse.getDist() * Math.cos(azimut2)));
|
780 |
|
781 |
if (mAxisL >= maAxisL) {
|
782 |
// El menor debe ser menor que el mayor. Los cambiamos.
|
783 |
double aux = mAxisL;
|
784 |
mAxisL = maAxisL; |
785 |
maAxisL = aux; |
786 |
// Tambi?n cambiamos los puntos finales de los ejes.
|
787 |
Point2D pAux = endPointOfMinorAxis;
|
788 |
endPointOfMinorAxis = endPointOfMajorAxis; |
789 |
endPointOfMajorAxis = pAux; |
790 |
} |
791 |
double mToMAR = mAxisL / maAxisL;
|
792 |
// System.out.println("mToMar = " + mToMAR);
|
793 |
// DxfGroup arcLayer = new DxfGroup(8, "default");
|
794 |
DxfGroup x = new DxfGroup();
|
795 |
DxfGroup y = new DxfGroup();
|
796 |
DxfGroup xc = new DxfGroup();
|
797 |
DxfGroup yc = new DxfGroup();
|
798 |
DxfGroup minToMaj = new DxfGroup();
|
799 |
// DxfGroup start = new DxfGroup();
|
800 |
// DxfGroup end = new DxfGroup();
|
801 |
x.setCode(10);
|
802 |
x.setData(new Double(center.getX())); |
803 |
y.setCode(20);
|
804 |
y.setData(new Double(center.getY())); |
805 |
xc.setCode(11);
|
806 |
xc.setData(new Double(endPointOfMajorAxis.getX() - center.getX())); |
807 |
yc.setCode(21);
|
808 |
yc.setData(new Double(endPointOfMajorAxis.getY() - center.getY())); |
809 |
minToMaj.setCode(40);
|
810 |
minToMaj.setData(new Double(mToMAR)); |
811 |
DxfGroupVector av = updateProperties(feature,k); |
812 |
// av.add(arcLayer);
|
813 |
av.add(x); |
814 |
av.add(y); |
815 |
av.add(xc); |
816 |
av.add(yc); |
817 |
av.add(minToMaj); |
818 |
entityMaker.createEllipse(av); |
819 |
k++; |
820 |
return k;
|
821 |
} |
822 |
} |