Revision 3513 branches/FMap_CAD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/FileEditableFeatureSource.java
FileEditableFeatureSource.java | ||
---|---|---|
1 | 1 |
package com.iver.cit.gvsig.fmap.edition; |
2 | 2 |
|
3 |
import java.awt.Component; |
|
4 |
import java.awt.geom.AffineTransform; |
|
5 |
import java.awt.geom.PathIterator; |
|
6 |
import java.awt.geom.Point2D; |
|
7 |
import java.io.File; |
|
8 |
import java.io.IOException; |
|
9 |
|
|
10 |
import javax.swing.JFileChooser; |
|
11 |
|
|
12 |
import org.cresques.geo.Ellipsoid; |
|
13 |
import org.cresques.geo.Projection; |
|
14 |
import org.cresques.geo.UtmZone; |
|
15 |
import org.cresques.io.DxfFile; |
|
16 |
import org.cresques.io.DxfGroup; |
|
17 |
import org.cresques.io.DxfGroupVector; |
|
18 |
import org.cresques.px.dxf.DxfEntityMaker; |
|
19 |
|
|
20 |
import com.iver.cit.gvsig.fmap.core.FArc2D; |
|
21 |
import com.iver.cit.gvsig.fmap.core.FCircle2D; |
|
22 |
import com.iver.cit.gvsig.fmap.core.FEllipse2D; |
|
23 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
|
24 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
25 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
|
26 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
27 |
import com.iver.cit.gvsig.fmap.core.GeneralPathXIterator; |
|
3 | 28 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
4 | 29 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
30 |
///import com.iver.cit.gvsig.fmap.drivers.dxf.write.DxfWriter; |
|
31 |
import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
|
5 | 32 |
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter; |
33 |
import com.iver.utiles.GenericFileFilter; |
|
6 | 34 |
|
7 | 35 |
|
8 | 36 |
/** |
... | ... | |
28 | 56 |
* @throws EditionException |
29 | 57 |
*/ |
30 | 58 |
public void startEdition() throws EditionException { |
31 |
/*TODO descomentar esto |
|
32 | 59 |
try { |
33 | 60 |
featureSource.start(); |
34 | 61 |
} catch (DriverIOException e) { |
35 | 62 |
throw new EditionException(e); |
36 | 63 |
} |
37 |
*/ |
|
38 | 64 |
} |
39 | 65 |
|
40 | 66 |
/** |
... | ... | |
44 | 70 |
* |
45 | 71 |
* @throws EditionException |
46 | 72 |
*/ |
47 |
public void stopEdition() throws EditionException { |
|
48 |
/*TODO descomentar esto |
|
73 |
public void stopEdition(EditableFeatureSource editedSource,File file) throws EditionException { |
|
49 | 74 |
try { |
75 |
// Comentado provisionalmente para evitar una excepci?n. |
|
50 | 76 |
featureSource.stop(); |
77 |
|
|
78 |
|
|
79 |
File destFile = file; |
|
80 |
//Crear nuevo fichero DXF2000. |
|
81 |
if (file==null){ |
|
82 |
file=featureSource.getFile(); |
|
83 |
} |
|
84 |
String dxfFileName = destFile.getAbsolutePath(); |
|
85 |
|
|
86 |
Projection currentProj = UtmZone.getProjection(Ellipsoid.hayford, 30, UtmZone.NORTH); |
|
87 |
DxfFile.EntityFactory entityMaker = new DxfEntityMaker(currentProj); |
|
88 |
DxfFile dxfEntityFile; |
|
89 |
|
|
90 |
for (int i=0;i<editedSource.getGeometryCount();i++){ |
|
91 |
if (editedSource.getGeometry(i) == null) continue; |
|
92 |
if (editedSource.getGeometry(i).getGeometryType()==FShape.POINT) { |
|
93 |
System.out.println("Punto encontrado."); |
|
94 |
FPoint2D point = new FPoint2D(0,0); |
|
95 |
double[] pointCoords = new double[6]; |
|
96 |
GeneralPathXIterator pointIt = editedSource.getGeometry(i).getGeneralPathXIterator(); |
|
97 |
while (!pointIt.isDone()) { |
|
98 |
int type = pointIt.currentSegment(pointCoords); |
|
99 |
point = new FPoint2D(pointCoords[0], pointCoords[1]); |
|
100 |
pointIt.next(); |
|
101 |
} |
|
102 |
Point2D pto = new Point2D.Double(point.getX(), point.getY()); |
|
103 |
DxfGroup pointLayer = new DxfGroup(8, "default"); |
|
104 |
DxfGroup px = new DxfGroup(); |
|
105 |
DxfGroup py = new DxfGroup(); |
|
106 |
px.setCode(10); |
|
107 |
px.setData(new Double(pto.getX())); |
|
108 |
py.setCode(20); |
|
109 |
py.setData(new Double(pto.getY())); |
|
110 |
DxfGroupVector pv = new DxfGroupVector(); |
|
111 |
pv.add(pointLayer); |
|
112 |
pv.add(px); |
|
113 |
pv.add(py); |
|
114 |
entityMaker.createPoint(pv); |
|
115 |
} else if (editedSource.getGeometry(i).getGeometryType()==FShape.LINE) { |
|
116 |
System.out.println("L?nea encontrada."); |
|
117 |
double[] lineCoords = new double[6]; |
|
118 |
GeneralPathXIterator lineIt = editedSource.getGeometry(i).getGeneralPathXIterator(); |
|
119 |
int j = 0; |
|
120 |
Point2D[] pts = new Point2D[2]; |
|
121 |
while (!lineIt.isDone()) { |
|
122 |
int type = lineIt.currentSegment(lineCoords); |
|
123 |
pts[j] = new Point2D.Double(lineCoords[0], lineCoords[1]); |
|
124 |
j++; |
|
125 |
lineIt.next(); |
|
126 |
} |
|
127 |
DxfGroupVector lv = new DxfGroupVector(); |
|
128 |
DxfGroup lineLayer = new DxfGroup(8, "default"); |
|
129 |
lv.add(lineLayer); |
|
130 |
DxfGroup x1 = new DxfGroup(); |
|
131 |
DxfGroup y1 = new DxfGroup(); |
|
132 |
DxfGroup x2 = new DxfGroup(); |
|
133 |
DxfGroup y2 = new DxfGroup(); |
|
134 |
DxfGroup ar = new DxfGroup(); |
|
135 |
x1.setCode(10); |
|
136 |
x1.setData(new Double(pts[0].getX())); |
|
137 |
y1.setCode(20); |
|
138 |
y1.setData(new Double(pts[0].getY())); |
|
139 |
x2.setCode(11); |
|
140 |
x2.setData(new Double(pts[1].getX())); |
|
141 |
y2.setCode(21); |
|
142 |
y2.setData(new Double(pts[1].getY())); |
|
143 |
lv.add(x1); |
|
144 |
lv.add(y1); |
|
145 |
lv.add(x2); |
|
146 |
lv.add(y2); |
|
147 |
entityMaker.createLine(lv); |
|
148 |
/*} else if (geoms[i].getGeometryType()==FShape.POLYLINE) { |
|
149 |
System.out.println("Polil?nea encontrada."); |
|
150 |
double[] lineCoords = new double[6]; |
|
151 |
GeneralPathXIterator polylineIt = geoms[i].getGeneralPathXIterator(); |
|
152 |
DxfGroupVector plv = new DxfGroupVector(); |
|
153 |
DxfGroup polylineLayer = new DxfGroup(8, "default"); |
|
154 |
plv.add(polylineLayer); |
|
155 |
entityMaker.createPolyline(plv); |
|
156 |
while (!polylineIt.isDone()) { |
|
157 |
int type = polylineIt.currentSegment(lineCoords); |
|
158 |
DxfGroupVector vxv = new DxfGroupVector(); |
|
159 |
DxfGroup vertex = new DxfGroup(0, "VERTEX"); |
|
160 |
DxfGroup vx = new DxfGroup(); |
|
161 |
DxfGroup vy = new DxfGroup(); |
|
162 |
vx.setCode(10); |
|
163 |
vx.setData(new Double(lineCoords[0])); |
|
164 |
System.out.println("lineCoords[0]" + lineCoords[0]); |
|
165 |
vy.setCode(20); |
|
166 |
vy.setData(new Double(lineCoords[1])); |
|
167 |
System.out.println("lineCoords[1]" + lineCoords[1]); |
|
168 |
vxv.add(vertex); |
|
169 |
vxv.add(vx); |
|
170 |
vxv.add(vy); |
|
171 |
entityMaker.addVertex(vxv); |
|
172 |
polylineIt.next(); |
|
173 |
} |
|
174 |
DxfGroupVector sev = new DxfGroupVector(); |
|
175 |
DxfGroup seqend = new DxfGroup(0, "SEQEND"); |
|
176 |
sev.add(seqend); |
|
177 |
sev.add(polylineLayer); |
|
178 |
entityMaker.endSeq();*/ |
|
179 |
/*} else if (geoms[i].getGeometryType()==FShape.POLYGON) { |
|
180 |
System.out.println("Pol?gono encontrado."); |
|
181 |
double[] polCoords = new double[6]; |
|
182 |
GeneralPathXIterator polIt = geoms[i].getGeneralPathXIterator(); |
|
183 |
DxfGroupVector polv = new DxfGroupVector(); |
|
184 |
DxfGroup polylineLayer = new DxfGroup(8, "default"); |
|
185 |
DxfGroup polylineFlag = new DxfGroup(); |
|
186 |
polylineFlag.setCode(70); |
|
187 |
polylineFlag.setData(new Integer(1)); |
|
188 |
polv.add(polylineLayer); |
|
189 |
polv.add(polylineFlag); |
|
190 |
entityMaker.createPolyline(polv); |
|
191 |
while (!polIt.isDone()) { |
|
192 |
int type = polIt.currentSegment(polCoords); |
|
193 |
DxfGroupVector vxv = new DxfGroupVector(); |
|
194 |
DxfGroup vertex = new DxfGroup(0, "VERTEX"); |
|
195 |
DxfGroup vx = new DxfGroup(); |
|
196 |
DxfGroup vy = new DxfGroup(); |
|
197 |
vx.setCode(10); |
|
198 |
vx.setData(new Double(polCoords[0])); |
|
199 |
System.out.println("lineCoords[0]" + polCoords[0]); |
|
200 |
vy.setCode(20); |
|
201 |
vy.setData(new Double(polCoords[1])); |
|
202 |
System.out.println("lineCoords[1]" + polCoords[1]); |
|
203 |
vxv.add(vertex); |
|
204 |
vxv.add(vx); |
|
205 |
vxv.add(vy); |
|
206 |
entityMaker.addVertex(vxv); |
|
207 |
polIt.next(); |
|
208 |
} |
|
209 |
DxfGroupVector sev = new DxfGroupVector(); |
|
210 |
DxfGroup seqend = new DxfGroup(0, "SEQEND"); |
|
211 |
sev.add(seqend); |
|
212 |
sev.add(polylineLayer); |
|
213 |
entityMaker.endSeq();*/ |
|
214 |
} else if (editedSource.getGeometry(i).getGeometryType()==FShape.ARC) { |
|
215 |
System.out.println("ARC encontrado."); |
|
216 |
FShape[] shapes = editedSource.getGeometry(i).getShapes(); |
|
217 |
FArc2D fArc = (FArc2D)(shapes[0]); |
|
218 |
Point2D[] pts = new Point2D[3]; |
|
219 |
pts[0] = fArc.getInit(); |
|
220 |
pts[1] = fArc.getMid(); |
|
221 |
pts[2] = fArc.getEnd(); |
|
222 |
Point2D center = fArc.getCenter(); |
|
223 |
double radius = center.distance(pts[0]); |
|
224 |
double initAngle=TrigonometricalFunctions.getAngle(center, pts[0]); |
|
225 |
initAngle = Math.toDegrees(initAngle); |
|
226 |
System.out.println("initAngle = " + initAngle); |
|
227 |
double midAngle=TrigonometricalFunctions.getAngle(center, pts[1]); |
|
228 |
midAngle = Math.toDegrees(midAngle); |
|
229 |
System.out.println("midAngle = " + midAngle); |
|
230 |
double endAngle=TrigonometricalFunctions.getAngle(center, pts[2]); |
|
231 |
endAngle = Math.toDegrees(endAngle); |
|
232 |
System.out.println("endAngle = " + endAngle); |
|
233 |
|
|
234 |
// 050307, jmorell: Resoluci?n de un bug sobre el sentido de |
|
235 |
// los arcos. |
|
236 |
if (!TrigonometricalFunctions.isCCW(pts[0],pts[1],pts[2])){ |
|
237 |
double aux=initAngle; |
|
238 |
initAngle=endAngle; |
|
239 |
endAngle=aux; |
|
240 |
} |
|
241 |
|
|
242 |
DxfGroup arcLayer = new DxfGroup(8, "default"); |
|
243 |
DxfGroup ax = new DxfGroup(); |
|
244 |
DxfGroup ay = new DxfGroup(); |
|
245 |
DxfGroup ac = new DxfGroup(); |
|
246 |
DxfGroup ai = new DxfGroup(); |
|
247 |
DxfGroup ae = new DxfGroup(); |
|
248 |
ax.setCode(10); |
|
249 |
ax.setData(new Double(center.getX())); |
|
250 |
ay.setCode(20); |
|
251 |
ay.setData(new Double(center.getY())); |
|
252 |
ac.setCode(40); |
|
253 |
ac.setData(new Double(radius)); |
|
254 |
ai.setCode(50); |
|
255 |
ai.setData(new Double(initAngle)); |
|
256 |
ae.setCode(51); |
|
257 |
ae.setData(new Double(endAngle)); |
|
258 |
DxfGroupVector av = new DxfGroupVector(); |
|
259 |
av.add(arcLayer); |
|
260 |
av.add(ax); |
|
261 |
av.add(ay); |
|
262 |
av.add(ac); |
|
263 |
av.add(ai); |
|
264 |
av.add(ae); |
|
265 |
entityMaker.createArc(av); |
|
266 |
} else if (editedSource.getGeometry(i).getGeometryType()==FShape.CIRCLE) { |
|
267 |
System.out.println("CIRCLE encontrado."); |
|
268 |
FShape[] shapes = editedSource.getGeometry(i).getShapes(); |
|
269 |
FCircle2D circle = (FCircle2D)(shapes[0]); |
|
270 |
Point2D center = circle.getCenter(); |
|
271 |
double radius = circle.getRadio(); |
|
272 |
DxfGroup arcLayer = new DxfGroup(8, "default"); |
|
273 |
DxfGroup ax = new DxfGroup(); |
|
274 |
DxfGroup ay = new DxfGroup(); |
|
275 |
DxfGroup ar = new DxfGroup(); |
|
276 |
ax.setCode(10); |
|
277 |
ax.setData(new Double(center.getX())); |
|
278 |
ay.setCode(20); |
|
279 |
ay.setData(new Double(center.getY())); |
|
280 |
ar.setCode(40); |
|
281 |
ar.setData(new Double(radius)); |
|
282 |
DxfGroupVector av = new DxfGroupVector(); |
|
283 |
av.add(arcLayer); |
|
284 |
av.add(ax); |
|
285 |
av.add(ay); |
|
286 |
av.add(ar); |
|
287 |
entityMaker.createCircle(av); |
|
288 |
} else if (editedSource.getGeometry(i).getGeometryType()==FShape.ELLIPSE) { |
|
289 |
System.out.println("ELLIPSE encontrada."); |
|
290 |
FShape[] shapes = editedSource.getGeometry(i).getShapes(); |
|
291 |
FEllipse2D fElip = (FEllipse2D)(shapes[0]); |
|
292 |
Point2D center = new Point2D.Double((fElip.getInit().getX()+fElip.getEnd().getX())/2, (fElip.getInit().getY()+fElip.getEnd().getY())/2); |
|
293 |
double mAxisL = fElip.getDist()*2; |
|
294 |
System.out.println("mAxisL = " + mAxisL); |
|
295 |
/*System.out.println("mAxisL/(center.distance(fElip.getEnd()))*2 = " + mAxisL/(center.distance(fElip.getEnd()))*2); |
|
296 |
minToMaj.setData(new Double(mAxisL/()*2));*/ |
|
297 |
double maAxisL = fElip.getInit().distance(fElip.getEnd()); |
|
298 |
|
|
299 |
Point2D endPointOfMajorAxis = fElip.getEnd(); |
|
300 |
double azimut = Math.atan2(endPointOfMajorAxis.getX()-center.getX(), endPointOfMajorAxis.getY()-center.getY()); |
|
301 |
double azimut2 = azimut + Math.PI/2.0; |
|
302 |
if (azimut2 >=Math.PI*2) azimut2 = azimut2 - Math.PI*2; |
|
303 |
Point2D endPointOfMinorAxis = new Point2D.Double(center.getX()+(fElip.getDist()*Math.sin(azimut2)), center.getY()+(fElip.getDist()*Math.cos(azimut2))); |
|
304 |
|
|
305 |
if (mAxisL>=maAxisL) { |
|
306 |
// El menor debe ser menor que el mayor. Los cambiamos. |
|
307 |
double aux = mAxisL; |
|
308 |
mAxisL = maAxisL; |
|
309 |
maAxisL = aux; |
|
310 |
// Tambi?n cambiamos los puntos finales de los ejes. |
|
311 |
Point2D pAux = endPointOfMinorAxis; |
|
312 |
endPointOfMinorAxis = endPointOfMajorAxis; |
|
313 |
endPointOfMajorAxis = pAux; |
|
314 |
} |
|
315 |
double mToMAR = mAxisL/maAxisL; |
|
316 |
System.out.println("mToMar = " + mToMAR); |
|
317 |
DxfGroup arcLayer = new DxfGroup(8, "default"); |
|
318 |
DxfGroup x = new DxfGroup(); |
|
319 |
DxfGroup y = new DxfGroup(); |
|
320 |
DxfGroup xc = new DxfGroup(); |
|
321 |
DxfGroup yc = new DxfGroup(); |
|
322 |
DxfGroup minToMaj = new DxfGroup(); |
|
323 |
//DxfGroup start = new DxfGroup(); |
|
324 |
//DxfGroup end = new DxfGroup(); |
|
325 |
x.setCode(10); |
|
326 |
x.setData(new Double(center.getX())); |
|
327 |
y.setCode(20); |
|
328 |
y.setData(new Double(center.getY())); |
|
329 |
xc.setCode(11); |
|
330 |
xc.setData(new Double(endPointOfMajorAxis.getX()-center.getX())); |
|
331 |
yc.setCode(21); |
|
332 |
yc.setData(new Double(endPointOfMajorAxis.getY()-center.getY())); |
|
333 |
minToMaj.setCode(40); |
|
334 |
minToMaj.setData(new Double(mToMAR)); |
|
335 |
DxfGroupVector av = new DxfGroupVector(); |
|
336 |
av.add(arcLayer); |
|
337 |
av.add(x); |
|
338 |
av.add(y); |
|
339 |
av.add(xc); |
|
340 |
av.add(yc); |
|
341 |
av.add(minToMaj); |
|
342 |
entityMaker.createEllipse(av); |
|
343 |
// Para escribir Polylines. |
|
344 |
/*} else if (geoms[i] instanceof FGeometryCollection) { |
|
345 |
System.out.println("Polil?nea encontrada (Soluci?n provisional)."); |
|
346 |
FGeometryCollection gc = (FGeometryCollection)geoms[i]; |
|
347 |
FShape[] fShapes = gc.getShapes(); |
|
348 |
//double[] lineCoords = new double[6]; |
|
349 |
//GeneralPathXIterator polylineIt = geoms[i].getGeneralPathXIterator(); |
|
350 |
DxfGroupVector plv = new DxfGroupVector(); |
|
351 |
DxfGroup polylineLayer = new DxfGroup(8, "default"); |
|
352 |
plv.add(polylineLayer); |
|
353 |
entityMaker.createPolyline(plv); |
|
354 |
//while (!polylineIt.isDone()) { |
|
355 |
for (int j=0;j<fShapes.length;j++) { |
|
356 |
if (fShapes[j] instanceof FPolyline2D) { |
|
357 |
System.out.println("L?nea encontrada dentro de la polil?nea."); |
|
358 |
FPolyline2D fLine = (FPolyline2D)fShapes[j]; |
|
359 |
double[] lineCoords = new double[6]; |
|
360 |
//GeneralPathXIterator lineIt = geoms[i].getGeneralPathXIterator(); |
|
361 |
PathIterator lineIt = fLine.getPathIterator(new AffineTransform()); |
|
362 |
int k = 0; |
|
363 |
Point2D[] pts = new Point2D[2]; |
|
364 |
while (!lineIt.isDone()) { |
|
365 |
int type = lineIt.currentSegment(lineCoords); |
|
366 |
pts[k] = new Point2D.Double(lineCoords[0], lineCoords[1]); |
|
367 |
k++; |
|
368 |
lineIt.next(); |
|
369 |
} |
|
370 |
//int type = polylineIt.currentSegment(lineCoords); |
|
371 |
DxfGroupVector vxv = new DxfGroupVector(); |
|
372 |
DxfGroup vertex = new DxfGroup(0, "VERTEX"); |
|
373 |
DxfGroup vx = new DxfGroup(); |
|
374 |
DxfGroup vy = new DxfGroup(); |
|
375 |
vx.setCode(10); |
|
376 |
vx.setData(new Double(pts[0].getX())); |
|
377 |
vy.setCode(20); |
|
378 |
vy.setData(new Double(pts[0].getY())); |
|
379 |
vxv.add(vertex); |
|
380 |
vxv.add(vx); |
|
381 |
vxv.add(vy); |
|
382 |
entityMaker.addVertex(vxv); |
|
383 |
//polylineIt.next(); |
|
384 |
if (j==fShapes.length-1) { |
|
385 |
//int type = polylineIt.currentSegment(lineCoords); |
|
386 |
DxfGroupVector vxvf = new DxfGroupVector(); |
|
387 |
DxfGroup vertexf = new DxfGroup(0, "VERTEX"); |
|
388 |
DxfGroup vxf = new DxfGroup(); |
|
389 |
DxfGroup vyf = new DxfGroup(); |
|
390 |
vxf.setCode(10); |
|
391 |
vxf.setData(new Double(pts[1].getX())); |
|
392 |
vyf.setCode(20); |
|
393 |
vyf.setData(new Double(pts[1].getY())); |
|
394 |
vxvf.add(vertex); |
|
395 |
vxvf.add(vx); |
|
396 |
vxvf.add(vy); |
|
397 |
entityMaker.addVertex(vxvf); |
|
398 |
//polylineIt.next(); |
|
399 |
} |
|
400 |
} else if (fShapes[j] instanceof FArc2D) { |
|
401 |
|
|
402 |
} else { |
|
403 |
System.out.println("Detectado elemento en polil?nea que no es ni arco ni l?nea."); |
|
404 |
} |
|
405 |
} |
|
406 |
DxfGroupVector sev = new DxfGroupVector(); |
|
407 |
DxfGroup seqend = new DxfGroup(0, "SEQEND"); |
|
408 |
sev.add(seqend); |
|
409 |
sev.add(polylineLayer); |
|
410 |
entityMaker.endSeq();*/ |
|
411 |
// Para escribir LwPolylines. |
|
412 |
} else if (editedSource.getGeometry(i) instanceof FGeometryCollection) { |
|
413 |
System.out.println("Polil?nea encontrada (Soluci?n provisional)."); |
|
414 |
FGeometryCollection gc = (FGeometryCollection)editedSource.getGeometry(i); |
|
415 |
FShape[] fShapes = gc.getShapes(); |
|
416 |
//double[] lineCoords = new double[6]; |
|
417 |
//GeneralPathXIterator polylineIt = geoms[i].getGeneralPathXIterator(); |
|
418 |
DxfGroupVector plv = new DxfGroupVector(); |
|
419 |
DxfGroup polylineLayer = new DxfGroup(8, "default"); |
|
420 |
DxfGroup vNum = new DxfGroup(); |
|
421 |
vNum.setCode(90); |
|
422 |
vNum.setData(new Integer(fShapes.length+1)); |
|
423 |
plv.add(polylineLayer); |
|
424 |
plv.add(vNum); |
|
425 |
Point2D first = new Point2D.Double(); |
|
426 |
Point2D last = new Point2D.Double(); |
|
427 |
for (int j=0;j<fShapes.length;j++) { |
|
428 |
if (fShapes[j] instanceof FPolyline2D && !(fShapes[j] instanceof FArc2D)) { |
|
429 |
System.out.println("L?nea encontrada dentro de la polil?nea."); |
|
430 |
FPolyline2D fLine = (FPolyline2D)fShapes[j]; |
|
431 |
double[] lineCoords = new double[6]; |
|
432 |
PathIterator lineIt = fLine.getPathIterator(new AffineTransform()); |
|
433 |
int k = 0; |
|
434 |
Point2D[] pts = new Point2D[2]; |
|
435 |
while (!lineIt.isDone()) { |
|
436 |
int type = lineIt.currentSegment(lineCoords); |
|
437 |
pts[k] = new Point2D.Double(lineCoords[0], lineCoords[1]); |
|
438 |
k++; |
|
439 |
lineIt.next(); |
|
440 |
} |
|
441 |
System.out.println("pts[0] = " + pts[0]); |
|
442 |
System.out.println("pts[1] = " + pts[1]); |
|
443 |
DxfGroup vx = new DxfGroup(); |
|
444 |
DxfGroup vy = new DxfGroup(); |
|
445 |
vx.setCode(10); |
|
446 |
vx.setData(new Double(pts[0].getX())); |
|
447 |
vy.setCode(20); |
|
448 |
vy.setData(new Double(pts[0].getY())); |
|
449 |
plv.add(vx); |
|
450 |
plv.add(vy); |
|
451 |
if (j==0) { |
|
452 |
first = new Point2D.Double(pts[0].getX(), pts[0].getY()); |
|
453 |
} |
|
454 |
if (j==fShapes.length-1) { |
|
455 |
last = new Point2D.Double(pts[1].getX(), pts[1].getY()); |
|
456 |
if (first.getX()==last.getX() && first.getY()==last.getY()) { |
|
457 |
System.out.println("Polil?nea cerrada."); |
|
458 |
} else { |
|
459 |
System.out.println("Polil?nea abierta."); |
|
460 |
DxfGroup vxf = new DxfGroup(); |
|
461 |
DxfGroup vyf = new DxfGroup(); |
|
462 |
vxf.setCode(10); |
|
463 |
vxf.setData(new Double(pts[1].getX())); |
|
464 |
vyf.setCode(20); |
|
465 |
vyf.setData(new Double(pts[1].getY())); |
|
466 |
plv.add(vxf); |
|
467 |
plv.add(vyf); |
|
468 |
} |
|
469 |
} |
|
470 |
} else if (fShapes[j] instanceof FArc2D) { |
|
471 |
System.out.println("Arco encontrada dentro de la polil?nea."); |
|
472 |
FArc2D fArc = (FArc2D)fShapes[j]; |
|
473 |
double[] lineCoords = new double[6]; |
|
474 |
/*PathIterator lineIt = fLine.getPathIterator(new AffineTransform()); |
|
475 |
int k = 0;*/ |
|
476 |
Point2D[] pts = new Point2D[3]; |
|
477 |
pts[0] = fArc.getInit(); |
|
478 |
pts[1] = fArc.getMid(); |
|
479 |
pts[2] = fArc.getEnd(); |
|
480 |
Point2D center = fArc.getCenter(); //TrigonometricalFunctions.getCenter(pts[0], pts[1], pts[2]); |
|
481 |
System.out.println("pts[0] = " + pts[0]); |
|
482 |
System.out.println("pts[1] = " + pts[1]); |
|
483 |
System.out.println("center = " + center); |
|
484 |
System.out.println("pts[2] = " + pts[2]); |
|
485 |
double initAngRad = TrigonometricalFunctions.getAngle(center, pts[0]); |
|
486 |
double endAngRad = TrigonometricalFunctions.getAngle(center, pts[2]); |
|
487 |
double angleRad = endAngRad-initAngRad; |
|
488 |
if (angleRad<0) angleRad = angleRad+2*Math.PI; |
|
489 |
// |
|
490 |
//boolean bulgeIsNegative = true; |
|
491 |
double bulge = 0; |
|
492 |
if (TrigonometricalFunctions.isCCW(pts[0], pts[1], pts[2])) { |
|
493 |
double angleRad2 = angleRad/4.0; |
|
494 |
bulge = Math.tan(angleRad2); |
|
495 |
} else { |
|
496 |
angleRad = 2*Math.PI-angleRad; |
|
497 |
double angleRad2 = angleRad/4.0; |
|
498 |
bulge = -1*Math.tan(angleRad2); |
|
499 |
} |
|
500 |
/*while (!lineIt.isDone()) { |
|
501 |
int type = lineIt.currentSegment(lineCoords); |
|
502 |
pts[k] = new Point2D.Double(lineCoords[0], lineCoords[1]); |
|
503 |
k++; |
|
504 |
lineIt.next(); |
|
505 |
}*/ |
|
506 |
DxfGroup vx = new DxfGroup(); |
|
507 |
DxfGroup vy = new DxfGroup(); |
|
508 |
DxfGroup vb = new DxfGroup(); |
|
509 |
vx.setCode(10); |
|
510 |
vx.setData(new Double(pts[0].getX())); |
|
511 |
vy.setCode(20); |
|
512 |
vy.setData(new Double(pts[0].getY())); |
|
513 |
vb.setCode(42); |
|
514 |
vb.setData(new Double(bulge)); |
|
515 |
plv.add(vx); |
|
516 |
plv.add(vy); |
|
517 |
plv.add(vb); |
|
518 |
if (j==0) { |
|
519 |
first = new Point2D.Double(pts[0].getX(), pts[0].getY()); |
|
520 |
} |
|
521 |
if (j==fShapes.length-1) { |
|
522 |
last = new Point2D.Double(pts[2].getX(), pts[2].getY()); |
|
523 |
if (first.getX()==last.getX() && first.getY()==last.getY()) { |
|
524 |
// Polil?nea cerrada. |
|
525 |
} else { |
|
526 |
DxfGroup vxf = new DxfGroup(); |
|
527 |
DxfGroup vyf = new DxfGroup(); |
|
528 |
vxf.setCode(10); |
|
529 |
vxf.setData(new Double(pts[2].getX())); |
|
530 |
vyf.setCode(20); |
|
531 |
vyf.setData(new Double(pts[2].getY())); |
|
532 |
plv.add(vxf); |
|
533 |
plv.add(vyf); |
|
534 |
} |
|
535 |
} |
|
536 |
} else { |
|
537 |
System.out.println("Detectado elemento en polil?nea que no es ni arco ni l?nea."); |
|
538 |
} |
|
539 |
} |
|
540 |
DxfGroup flag = new DxfGroup(); |
|
541 |
flag.setCode(70); |
|
542 |
if (first.getX()==last.getX() && first.getY()==last.getY()) { |
|
543 |
flag.setData(new Integer(1)); |
|
544 |
} else { |
|
545 |
flag.setData(new Integer(0)); |
|
546 |
} |
|
547 |
plv.add(flag); |
|
548 |
entityMaker.createLwPolyline(plv); |
|
549 |
} else { |
|
550 |
System.out.println("Detectado feature desconocido"); |
|
551 |
} |
|
552 |
} |
|
553 |
System.out.println("numero de entidades = " + entityMaker.getObjects().size()); |
|
554 |
dxfEntityFile = new DxfFile(currentProj, dxfFileName, entityMaker); |
|
555 |
|
|
556 |
//dxfFeatureFile.save(dxfFileName); |
|
557 |
dxfEntityFile.setCadFlag(true); |
|
558 |
dxfEntityFile.save(dxfFileName); |
|
51 | 559 |
} catch (DriverIOException e) { |
52 | 560 |
throw new EditionException(e); |
561 |
} catch (IOException ioe) { |
|
562 |
throw new EditionException(ioe); |
|
563 |
} catch (Exception ee) { |
|
564 |
throw new EditionException(ee); |
|
53 | 565 |
} |
54 |
*/ |
|
55 |
//Crear nuevo fichero shape. |
|
56 | 566 |
} |
57 | 567 |
|
58 | 568 |
/** |
Also available in: Unified diff