root / branches / FMap_CAD / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dxf / write / DxfWriter.java @ 3513
History | View | Annotate | Download (20.6 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.drivers.dxf.write; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.core.FArc2D; |
44 |
import com.iver.cit.gvsig.fmap.core.FCircle2D; |
45 |
import com.iver.cit.gvsig.fmap.core.FEllipse2D; |
46 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
47 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
48 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
49 |
import com.iver.cit.gvsig.fmap.core.FShape; |
50 |
import com.iver.cit.gvsig.fmap.core.GeneralPathXIterator; |
51 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
52 |
import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
53 |
|
54 |
import java.awt.geom.AffineTransform; |
55 |
import java.awt.geom.CubicCurve2D; |
56 |
import java.awt.geom.Line2D; |
57 |
import java.awt.geom.PathIterator; |
58 |
import java.awt.geom.Point2D; |
59 |
import java.awt.geom.QuadCurve2D; |
60 |
import java.io.File; |
61 |
import java.util.Iterator; |
62 |
|
63 |
import org.cresques.geo.Ellipsoid; |
64 |
import org.cresques.geo.Projection; |
65 |
import org.cresques.geo.UtmZone; |
66 |
import org.cresques.io.DxfFile; |
67 |
import org.cresques.io.DxfGroup; |
68 |
import org.cresques.io.DxfGroupVector; |
69 |
import org.cresques.px.dxf.DxfEntityMaker; |
70 |
|
71 |
/**
|
72 |
* Escritor de ficheros DXF2000. Convierte las entidades del modelo de CAD de gvSIG
|
73 |
* en entidades DXF de jCMS que saben escribirse en formato DXF2000.
|
74 |
*
|
75 |
* @author jmorell (jose.morell@gmail.com)
|
76 |
*/
|
77 |
public class DxfWriter { |
78 |
//DxfFile.EntityFactory featureMaker = null;
|
79 |
//DxfFile dxfFeatureFile = null;
|
80 |
DxfFile.EntityFactory entityMaker = null;
|
81 |
DxfFile dxfEntityFile = null;
|
82 |
private Projection currentProj = null; |
83 |
|
84 |
public DxfWriter() {
|
85 |
} |
86 |
|
87 |
public void write(IGeometry[] geoms, File file) throws Exception { |
88 |
String dxfFileName;
|
89 |
String fname;
|
90 |
int loc;
|
91 |
dxfFileName = file.getAbsolutePath(); |
92 |
|
93 |
// 050218, jmorell: Escritura de DXFs.
|
94 |
currentProj = UtmZone.getProjection(Ellipsoid.hayford, 30, UtmZone.NORTH);
|
95 |
//featureMaker = new DxfFeatureMaker(currentProj);
|
96 |
entityMaker = new DxfEntityMaker(currentProj);
|
97 |
|
98 |
for (int i=0;i<geoms.length;i++) { |
99 |
if (geoms[i].getGeometryType()==FShape.POINT) {
|
100 |
//System.out.println("Punto encontrado.");
|
101 |
FPoint2D point = new FPoint2D(0,0); |
102 |
double[] pointCoords = new double[6]; |
103 |
GeneralPathXIterator pointIt = geoms[i].getGeneralPathXIterator(); |
104 |
while (!pointIt.isDone()) {
|
105 |
int type = pointIt.currentSegment(pointCoords);
|
106 |
point = new FPoint2D(pointCoords[0], pointCoords[1]); |
107 |
pointIt.next(); |
108 |
} |
109 |
Point2D pto = new Point2D.Double(point.getX(), point.getY()); |
110 |
DxfGroup pointLayer = new DxfGroup(8, "default"); |
111 |
DxfGroup px = new DxfGroup();
|
112 |
DxfGroup py = new DxfGroup();
|
113 |
px.setCode(10);
|
114 |
px.setData(new Double(pto.getX())); |
115 |
py.setCode(20);
|
116 |
py.setData(new Double(pto.getY())); |
117 |
DxfGroupVector pv = new DxfGroupVector();
|
118 |
pv.add(pointLayer); |
119 |
pv.add(px); |
120 |
pv.add(py); |
121 |
entityMaker.createPoint(pv); |
122 |
} else if (geoms[i].getGeometryType()==FShape.LINE) { |
123 |
//System.out.println("L?nea encontrada.");
|
124 |
double[] lineCoords = new double[6]; |
125 |
GeneralPathXIterator lineIt = geoms[i].getGeneralPathXIterator(); |
126 |
int j = 0; |
127 |
Point2D[] pts = new Point2D[2]; |
128 |
while (!lineIt.isDone()) {
|
129 |
int type = lineIt.currentSegment(lineCoords);
|
130 |
pts[j] = new Point2D.Double(lineCoords[0], lineCoords[1]); |
131 |
j++; |
132 |
lineIt.next(); |
133 |
} |
134 |
DxfGroupVector lv = new DxfGroupVector();
|
135 |
DxfGroup lineLayer = new DxfGroup(8, "default"); |
136 |
lv.add(lineLayer); |
137 |
DxfGroup x1 = new DxfGroup();
|
138 |
DxfGroup y1 = new DxfGroup();
|
139 |
DxfGroup x2 = new DxfGroup();
|
140 |
DxfGroup y2 = new DxfGroup();
|
141 |
DxfGroup ar = new DxfGroup();
|
142 |
x1.setCode(10);
|
143 |
x1.setData(new Double(pts[0].getX())); |
144 |
y1.setCode(20);
|
145 |
y1.setData(new Double(pts[0].getY())); |
146 |
x2.setCode(11);
|
147 |
x2.setData(new Double(pts[1].getX())); |
148 |
y2.setCode(21);
|
149 |
y2.setData(new Double(pts[1].getY())); |
150 |
lv.add(x1); |
151 |
lv.add(y1); |
152 |
lv.add(x2); |
153 |
lv.add(y2); |
154 |
entityMaker.createLine(lv); |
155 |
/*} else if (geoms[i].getGeometryType()==FShape.POLYLINE) {
|
156 |
System.out.println("Polil?nea encontrada.");
|
157 |
double[] lineCoords = new double[6];
|
158 |
GeneralPathXIterator polylineIt = geoms[i].getGeneralPathXIterator();
|
159 |
DxfGroupVector plv = new DxfGroupVector();
|
160 |
DxfGroup polylineLayer = new DxfGroup(8, "default");
|
161 |
plv.add(polylineLayer);
|
162 |
entityMaker.createPolyline(plv);
|
163 |
while (!polylineIt.isDone()) {
|
164 |
int type = polylineIt.currentSegment(lineCoords);
|
165 |
DxfGroupVector vxv = new DxfGroupVector();
|
166 |
DxfGroup vertex = new DxfGroup(0, "VERTEX");
|
167 |
DxfGroup vx = new DxfGroup();
|
168 |
DxfGroup vy = new DxfGroup();
|
169 |
vx.setCode(10);
|
170 |
vx.setData(new Double(lineCoords[0]));
|
171 |
System.out.println("lineCoords[0]" + lineCoords[0]);
|
172 |
vy.setCode(20);
|
173 |
vy.setData(new Double(lineCoords[1]));
|
174 |
System.out.println("lineCoords[1]" + lineCoords[1]);
|
175 |
vxv.add(vertex);
|
176 |
vxv.add(vx);
|
177 |
vxv.add(vy);
|
178 |
entityMaker.addVertex(vxv);
|
179 |
polylineIt.next();
|
180 |
}
|
181 |
DxfGroupVector sev = new DxfGroupVector();
|
182 |
DxfGroup seqend = new DxfGroup(0, "SEQEND");
|
183 |
sev.add(seqend);
|
184 |
sev.add(polylineLayer);
|
185 |
entityMaker.endSeq();*/
|
186 |
/*} else if (geoms[i].getGeometryType()==FShape.POLYGON) {
|
187 |
System.out.println("Pol?gono encontrado.");
|
188 |
double[] polCoords = new double[6];
|
189 |
GeneralPathXIterator polIt = geoms[i].getGeneralPathXIterator();
|
190 |
DxfGroupVector polv = new DxfGroupVector();
|
191 |
DxfGroup polylineLayer = new DxfGroup(8, "default");
|
192 |
DxfGroup polylineFlag = new DxfGroup();
|
193 |
polylineFlag.setCode(70);
|
194 |
polylineFlag.setData(new Integer(1));
|
195 |
polv.add(polylineLayer);
|
196 |
polv.add(polylineFlag);
|
197 |
entityMaker.createPolyline(polv);
|
198 |
while (!polIt.isDone()) {
|
199 |
int type = polIt.currentSegment(polCoords);
|
200 |
DxfGroupVector vxv = new DxfGroupVector();
|
201 |
DxfGroup vertex = new DxfGroup(0, "VERTEX");
|
202 |
DxfGroup vx = new DxfGroup();
|
203 |
DxfGroup vy = new DxfGroup();
|
204 |
vx.setCode(10);
|
205 |
vx.setData(new Double(polCoords[0]));
|
206 |
System.out.println("lineCoords[0]" + polCoords[0]);
|
207 |
vy.setCode(20);
|
208 |
vy.setData(new Double(polCoords[1]));
|
209 |
System.out.println("lineCoords[1]" + polCoords[1]);
|
210 |
vxv.add(vertex);
|
211 |
vxv.add(vx);
|
212 |
vxv.add(vy);
|
213 |
entityMaker.addVertex(vxv);
|
214 |
polIt.next();
|
215 |
}
|
216 |
DxfGroupVector sev = new DxfGroupVector();
|
217 |
DxfGroup seqend = new DxfGroup(0, "SEQEND");
|
218 |
sev.add(seqend);
|
219 |
sev.add(polylineLayer);
|
220 |
entityMaker.endSeq();*/
|
221 |
} else if (geoms[i].getGeometryType()==FShape.ARC) { |
222 |
//System.out.println("ARC encontrado.");
|
223 |
FShape[] shapes = geoms[i].getShapes();
|
224 |
FArc2D fArc = (FArc2D)(shapes[0]);
|
225 |
Point2D[] pts = new Point2D[3]; |
226 |
pts[0] = fArc.getInit();
|
227 |
pts[1] = fArc.getMid();
|
228 |
pts[2] = fArc.getEnd();
|
229 |
Point2D center = fArc.getCenter();
|
230 |
double radius = center.distance(pts[0]); |
231 |
double initAngle=TrigonometricalFunctions.getAngle(center, pts[0]); |
232 |
initAngle = Math.toDegrees(initAngle);
|
233 |
//System.out.println("initAngle = " + initAngle);
|
234 |
double midAngle=TrigonometricalFunctions.getAngle(center, pts[1]); |
235 |
midAngle = Math.toDegrees(midAngle);
|
236 |
//System.out.println("midAngle = " + midAngle);
|
237 |
double endAngle=TrigonometricalFunctions.getAngle(center, pts[2]); |
238 |
endAngle = Math.toDegrees(endAngle);
|
239 |
//System.out.println("endAngle = " + endAngle);
|
240 |
|
241 |
// 050307, jmorell: Resoluci?n de un bug sobre el sentido de
|
242 |
// los arcos.
|
243 |
/*if (!TrigonometricalFunctions.isCCW(pts[0],pts[1],pts[2])){
|
244 |
double aux=initAngle;
|
245 |
initAngle=endAngle;
|
246 |
endAngle=aux;
|
247 |
}*/
|
248 |
|
249 |
/*FArc2D arc = (FArc2D)(shapes[0]);
|
250 |
Point2D center = arc.getCenter();
|
251 |
Point2D init = arc.getInit();
|
252 |
Point2D end = arc.getEnd();
|
253 |
// C?lculo del radio:
|
254 |
double radius = Math.sqrt(Math.pow(init.getX()-center.getX(),2)+Math.pow(init.getY()-center.getY(),2));
|
255 |
//
|
256 |
double initAngle=TrigonometricalFunctions.getAngle(center, init);
|
257 |
initAngle = Math.toDegrees(initAngle);
|
258 |
double endAngle=TrigonometricalFunctions.getAngle(center, end);
|
259 |
endAngle = Math.toDegrees(endAngle);*/
|
260 |
DxfGroup arcLayer = new DxfGroup(8, "default"); |
261 |
DxfGroup ax = new DxfGroup();
|
262 |
DxfGroup ay = new DxfGroup();
|
263 |
DxfGroup ac = new DxfGroup();
|
264 |
DxfGroup ai = new DxfGroup();
|
265 |
DxfGroup ae = new DxfGroup();
|
266 |
ax.setCode(10);
|
267 |
ax.setData(new Double(center.getX())); |
268 |
ay.setCode(20);
|
269 |
ay.setData(new Double(center.getY())); |
270 |
ac.setCode(40);
|
271 |
ac.setData(new Double(radius)); |
272 |
ai.setCode(50);
|
273 |
ai.setData(new Double(initAngle)); |
274 |
ae.setCode(51);
|
275 |
ae.setData(new Double(endAngle)); |
276 |
DxfGroupVector av = new DxfGroupVector();
|
277 |
av.add(arcLayer); |
278 |
av.add(ax); |
279 |
av.add(ay); |
280 |
av.add(ac); |
281 |
av.add(ai); |
282 |
av.add(ae); |
283 |
entityMaker.createArc(av); |
284 |
} else if (geoms[i].getGeometryType()==FShape.CIRCLE) { |
285 |
//System.out.println("CIRCLE encontrado.");
|
286 |
FShape[] shapes = geoms[i].getShapes();
|
287 |
FCircle2D circle = (FCircle2D)(shapes[0]);
|
288 |
Point2D center = circle.getCenter();
|
289 |
double radius = circle.getRadio();
|
290 |
DxfGroup arcLayer = new DxfGroup(8, "default"); |
291 |
DxfGroup ax = new DxfGroup();
|
292 |
DxfGroup ay = new DxfGroup();
|
293 |
DxfGroup ar = new DxfGroup();
|
294 |
ax.setCode(10);
|
295 |
ax.setData(new Double(center.getX())); |
296 |
ay.setCode(20);
|
297 |
ay.setData(new Double(center.getY())); |
298 |
ar.setCode(40);
|
299 |
ar.setData(new Double(radius)); |
300 |
DxfGroupVector av = new DxfGroupVector();
|
301 |
av.add(arcLayer); |
302 |
av.add(ax); |
303 |
av.add(ay); |
304 |
av.add(ar); |
305 |
entityMaker.createCircle(av); |
306 |
} else if (geoms[i].getGeometryType()==FShape.ELLIPSE) { |
307 |
//System.out.println("ELLIPSE encontrada.");
|
308 |
FShape[] shapes = geoms[i].getShapes();
|
309 |
FEllipse2D fElip = (FEllipse2D)(shapes[0]);
|
310 |
Point2D center = new Point2D.Double((fElip.getInit().getX()+fElip.getEnd().getX())/2, (fElip.getInit().getY()+fElip.getEnd().getY())/2); |
311 |
double mAxisL = fElip.getDist()*2; |
312 |
//System.out.println("mAxisL = " + mAxisL);
|
313 |
/*System.out.println("mAxisL/(center.distance(fElip.getEnd()))*2 = " + mAxisL/(center.distance(fElip.getEnd()))*2);
|
314 |
minToMaj.setData(new Double(mAxisL/()*2));*/
|
315 |
double maAxisL = fElip.getInit().distance(fElip.getEnd());
|
316 |
|
317 |
Point2D endPointOfMajorAxis = fElip.getEnd();
|
318 |
double azimut = Math.atan2(endPointOfMajorAxis.getX()-center.getX(), endPointOfMajorAxis.getY()-center.getY()); |
319 |
double azimut2 = azimut + Math.PI/2.0; |
320 |
if (azimut2 >=Math.PI*2) azimut2 = azimut2 - Math.PI*2; |
321 |
Point2D endPointOfMinorAxis = new Point2D.Double(center.getX()+(fElip.getDist()*Math.sin(azimut2)), center.getY()+(fElip.getDist()*Math.cos(azimut2))); |
322 |
|
323 |
if (mAxisL>=maAxisL) {
|
324 |
// El menor debe ser menor que el mayor. Los cambiamos.
|
325 |
double aux = mAxisL;
|
326 |
mAxisL = maAxisL; |
327 |
maAxisL = aux; |
328 |
// Tambi?n cambiamos los puntos finales de los ejes.
|
329 |
Point2D pAux = endPointOfMinorAxis;
|
330 |
endPointOfMinorAxis = endPointOfMajorAxis; |
331 |
endPointOfMajorAxis = pAux; |
332 |
} |
333 |
double mToMAR = mAxisL/maAxisL;
|
334 |
//System.out.println("mToMar = " + mToMAR);
|
335 |
DxfGroup arcLayer = new DxfGroup(8, "default"); |
336 |
DxfGroup x = new DxfGroup();
|
337 |
DxfGroup y = new DxfGroup();
|
338 |
DxfGroup xc = new DxfGroup();
|
339 |
DxfGroup yc = new DxfGroup();
|
340 |
DxfGroup minToMaj = new DxfGroup();
|
341 |
//DxfGroup start = new DxfGroup();
|
342 |
//DxfGroup end = new DxfGroup();
|
343 |
x.setCode(10);
|
344 |
x.setData(new Double(center.getX())); |
345 |
y.setCode(20);
|
346 |
y.setData(new Double(center.getY())); |
347 |
xc.setCode(11);
|
348 |
xc.setData(new Double(endPointOfMajorAxis.getX()-center.getX())); |
349 |
yc.setCode(21);
|
350 |
yc.setData(new Double(endPointOfMajorAxis.getY()-center.getY())); |
351 |
minToMaj.setCode(40);
|
352 |
minToMaj.setData(new Double(mToMAR)); |
353 |
DxfGroupVector av = new DxfGroupVector();
|
354 |
av.add(arcLayer); |
355 |
av.add(x); |
356 |
av.add(y); |
357 |
av.add(xc); |
358 |
av.add(yc); |
359 |
av.add(minToMaj); |
360 |
entityMaker.createEllipse(av); |
361 |
// Para escribir Polylines.
|
362 |
/*} else if (geoms[i] instanceof FGeometryCollection) {
|
363 |
System.out.println("Polil?nea encontrada (Soluci?n provisional).");
|
364 |
FGeometryCollection gc = (FGeometryCollection)geoms[i];
|
365 |
FShape[] fShapes = gc.getShapes();
|
366 |
//double[] lineCoords = new double[6];
|
367 |
//GeneralPathXIterator polylineIt = geoms[i].getGeneralPathXIterator();
|
368 |
DxfGroupVector plv = new DxfGroupVector();
|
369 |
DxfGroup polylineLayer = new DxfGroup(8, "default");
|
370 |
plv.add(polylineLayer);
|
371 |
entityMaker.createPolyline(plv);
|
372 |
//while (!polylineIt.isDone()) {
|
373 |
for (int j=0;j<fShapes.length;j++) {
|
374 |
if (fShapes[j] instanceof FPolyline2D) {
|
375 |
System.out.println("L?nea encontrada dentro de la polil?nea.");
|
376 |
FPolyline2D fLine = (FPolyline2D)fShapes[j];
|
377 |
double[] lineCoords = new double[6];
|
378 |
//GeneralPathXIterator lineIt = geoms[i].getGeneralPathXIterator();
|
379 |
PathIterator lineIt = fLine.getPathIterator(new AffineTransform());
|
380 |
int k = 0;
|
381 |
Point2D[] pts = new Point2D[2];
|
382 |
while (!lineIt.isDone()) {
|
383 |
int type = lineIt.currentSegment(lineCoords);
|
384 |
pts[k] = new Point2D.Double(lineCoords[0], lineCoords[1]);
|
385 |
k++;
|
386 |
lineIt.next();
|
387 |
}
|
388 |
//int type = polylineIt.currentSegment(lineCoords);
|
389 |
DxfGroupVector vxv = new DxfGroupVector();
|
390 |
DxfGroup vertex = new DxfGroup(0, "VERTEX");
|
391 |
DxfGroup vx = new DxfGroup();
|
392 |
DxfGroup vy = new DxfGroup();
|
393 |
vx.setCode(10);
|
394 |
vx.setData(new Double(pts[0].getX()));
|
395 |
vy.setCode(20);
|
396 |
vy.setData(new Double(pts[0].getY()));
|
397 |
vxv.add(vertex);
|
398 |
vxv.add(vx);
|
399 |
vxv.add(vy);
|
400 |
entityMaker.addVertex(vxv);
|
401 |
//polylineIt.next();
|
402 |
if (j==fShapes.length-1) {
|
403 |
//int type = polylineIt.currentSegment(lineCoords);
|
404 |
DxfGroupVector vxvf = new DxfGroupVector();
|
405 |
DxfGroup vertexf = new DxfGroup(0, "VERTEX");
|
406 |
DxfGroup vxf = new DxfGroup();
|
407 |
DxfGroup vyf = new DxfGroup();
|
408 |
vxf.setCode(10);
|
409 |
vxf.setData(new Double(pts[1].getX()));
|
410 |
vyf.setCode(20);
|
411 |
vyf.setData(new Double(pts[1].getY()));
|
412 |
vxvf.add(vertex);
|
413 |
vxvf.add(vx);
|
414 |
vxvf.add(vy);
|
415 |
entityMaker.addVertex(vxvf);
|
416 |
//polylineIt.next();
|
417 |
}
|
418 |
} else if (fShapes[j] instanceof FArc2D) {
|
419 |
|
420 |
} else {
|
421 |
System.out.println("Detectado elemento en polil?nea que no es ni arco ni l?nea.");
|
422 |
}
|
423 |
}
|
424 |
DxfGroupVector sev = new DxfGroupVector();
|
425 |
DxfGroup seqend = new DxfGroup(0, "SEQEND");
|
426 |
sev.add(seqend);
|
427 |
sev.add(polylineLayer);
|
428 |
entityMaker.endSeq();*/
|
429 |
// Para escribir LwPolylines.
|
430 |
} else if (geoms[i] instanceof FGeometryCollection) { |
431 |
//System.out.println("Polil?nea encontrada (Soluci?n provisional).");
|
432 |
FGeometryCollection gc = (FGeometryCollection)geoms[i]; |
433 |
FShape[] fShapes = gc.getShapes();
|
434 |
//double[] lineCoords = new double[6];
|
435 |
//GeneralPathXIterator polylineIt = geoms[i].getGeneralPathXIterator();
|
436 |
DxfGroupVector plv = new DxfGroupVector();
|
437 |
DxfGroup polylineLayer = new DxfGroup(8, "default"); |
438 |
DxfGroup vNum = new DxfGroup();
|
439 |
vNum.setCode(90);
|
440 |
vNum.setData(new Integer(fShapes.length+1)); |
441 |
plv.add(polylineLayer); |
442 |
plv.add(vNum); |
443 |
Point2D first = new Point2D.Double(); |
444 |
Point2D last = new Point2D.Double(); |
445 |
for (int j=0;j<fShapes.length;j++) { |
446 |
if (fShapes[j] instanceof FPolyline2D && !(fShapes[j] instanceof FArc2D)) { |
447 |
//System.out.println("L?nea encontrada dentro de la polil?nea.");
|
448 |
FPolyline2D fLine = (FPolyline2D)fShapes[j]; |
449 |
double[] lineCoords = new double[6]; |
450 |
PathIterator lineIt = fLine.getPathIterator(new AffineTransform()); |
451 |
int k = 0; |
452 |
Point2D[] pts = new Point2D[2]; |
453 |
while (!lineIt.isDone()) {
|
454 |
int type = lineIt.currentSegment(lineCoords);
|
455 |
pts[k] = new Point2D.Double(lineCoords[0], lineCoords[1]); |
456 |
k++; |
457 |
lineIt.next(); |
458 |
} |
459 |
DxfGroup vx = new DxfGroup();
|
460 |
DxfGroup vy = new DxfGroup();
|
461 |
vx.setCode(10);
|
462 |
vx.setData(new Double(pts[0].getX())); |
463 |
vy.setCode(20);
|
464 |
vy.setData(new Double(pts[0].getY())); |
465 |
plv.add(vx); |
466 |
plv.add(vy); |
467 |
if (j==0) { |
468 |
first = new Point2D.Double(pts[0].getX(), pts[0].getY()); |
469 |
} |
470 |
if (j==fShapes.length-1) { |
471 |
last = new Point2D.Double(pts[1].getX(), pts[1].getY()); |
472 |
if (first.getX()==last.getX() && first.getY()==last.getY()) {
|
473 |
// Polil?nea cerrada.
|
474 |
} else {
|
475 |
DxfGroup vxf = new DxfGroup();
|
476 |
DxfGroup vyf = new DxfGroup();
|
477 |
vxf.setCode(10);
|
478 |
vxf.setData(new Double(pts[1].getX())); |
479 |
vyf.setCode(20);
|
480 |
vyf.setData(new Double(pts[1].getY())); |
481 |
plv.add(vxf); |
482 |
plv.add(vyf); |
483 |
} |
484 |
} |
485 |
} else if (fShapes[j] instanceof FArc2D) { |
486 |
//System.out.println("Arco encontrada dentro de la polil?nea.");
|
487 |
FArc2D fArc = (FArc2D)fShapes[j]; |
488 |
double[] lineCoords = new double[6]; |
489 |
/*PathIterator lineIt = fLine.getPathIterator(new AffineTransform());
|
490 |
int k = 0;*/
|
491 |
Point2D[] pts = new Point2D[3]; |
492 |
pts[0] = fArc.getInit();
|
493 |
pts[1] = fArc.getMid();
|
494 |
pts[2] = fArc.getEnd();
|
495 |
Point2D center = fArc.getCenter(); //TrigonometricalFunctions.getCenter(pts[0], pts[1], pts[2]); |
496 |
//System.out.println("pts[0] = " + pts[0]);
|
497 |
//System.out.println("pts[1] = " + pts[1]);
|
498 |
//System.out.println("center = " + center);
|
499 |
//System.out.println("pts[2] = " + pts[2]);
|
500 |
double initAngRad = TrigonometricalFunctions.getAngle(center, pts[0]); |
501 |
double endAngRad = TrigonometricalFunctions.getAngle(center, pts[2]); |
502 |
double angleRad = endAngRad-initAngRad;
|
503 |
if (angleRad<0) angleRad = angleRad+2*Math.PI; |
504 |
//
|
505 |
//boolean bulgeIsNegative = true;
|
506 |
double bulge = 0; |
507 |
if (TrigonometricalFunctions.isCCW(pts[0], pts[1], pts[2])) { |
508 |
double angleRad2 = angleRad/4.0; |
509 |
bulge = Math.tan(angleRad2);
|
510 |
} else {
|
511 |
angleRad = 2*Math.PI-angleRad; |
512 |
double angleRad2 = angleRad/4.0; |
513 |
bulge = -1*Math.tan(angleRad2); |
514 |
} |
515 |
/*while (!lineIt.isDone()) {
|
516 |
int type = lineIt.currentSegment(lineCoords);
|
517 |
pts[k] = new Point2D.Double(lineCoords[0], lineCoords[1]);
|
518 |
k++;
|
519 |
lineIt.next();
|
520 |
}*/
|
521 |
DxfGroup vx = new DxfGroup();
|
522 |
DxfGroup vy = new DxfGroup();
|
523 |
DxfGroup vb = new DxfGroup();
|
524 |
vx.setCode(10);
|
525 |
vx.setData(new Double(pts[0].getX())); |
526 |
vy.setCode(20);
|
527 |
vy.setData(new Double(pts[0].getY())); |
528 |
vb.setCode(42);
|
529 |
vb.setData(new Double(bulge)); |
530 |
plv.add(vx); |
531 |
plv.add(vy); |
532 |
plv.add(vb); |
533 |
if (j==0) { |
534 |
first = new Point2D.Double(pts[0].getX(), pts[0].getY()); |
535 |
} |
536 |
if (j==fShapes.length-1) { |
537 |
last = new Point2D.Double(pts[2].getX(), pts[2].getY()); |
538 |
if (first.getX()==last.getX() && first.getY()==last.getY()) {
|
539 |
// Polil?nea cerrada.
|
540 |
} else {
|
541 |
DxfGroup vxf = new DxfGroup();
|
542 |
DxfGroup vyf = new DxfGroup();
|
543 |
vxf.setCode(10);
|
544 |
vxf.setData(new Double(pts[2].getX())); |
545 |
vyf.setCode(20);
|
546 |
vyf.setData(new Double(pts[2].getY())); |
547 |
plv.add(vxf); |
548 |
plv.add(vyf); |
549 |
} |
550 |
} |
551 |
} else {
|
552 |
System.out.println("Detectado elemento en polil?nea que no es ni arco ni l?nea."); |
553 |
} |
554 |
} |
555 |
DxfGroup flag = new DxfGroup();
|
556 |
flag.setCode(70);
|
557 |
if (first.getX()==last.getX() && first.getY()==last.getY()) {
|
558 |
flag.setData(new Integer(1)); |
559 |
} else {
|
560 |
flag.setData(new Integer(0)); |
561 |
} |
562 |
plv.add(flag); |
563 |
entityMaker.createLwPolyline(plv); |
564 |
} else {
|
565 |
System.out.println("Detectado feature desconocido"); |
566 |
} |
567 |
} |
568 |
|
569 |
System.out.println("numero de entidades = " + entityMaker.getObjects().size()); |
570 |
dxfEntityFile = new DxfFile(currentProj, dxfFileName, entityMaker);
|
571 |
|
572 |
//dxfFeatureFile.save(dxfFileName);
|
573 |
dxfEntityFile.setCadFlag(true);
|
574 |
dxfEntityFile.save(dxfFileName); |
575 |
} |
576 |
} |