root / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfFeatureMaker.java @ 75
History | View | Annotate | Download (36.8 KB)
1 |
package org.cresques.px.dxf; |
---|---|
2 |
|
3 |
import org.cresques.geo.Point3D; |
4 |
import org.cresques.geo.Projected; |
5 |
import org.cresques.geo.Projection; |
6 |
import org.cresques.geo.ReProjection; |
7 |
import org.cresques.geo.ViewPort; |
8 |
import org.cresques.io.DxfFile; |
9 |
import org.cresques.io.DxfGroup; |
10 |
import org.cresques.io.DxfGroupVector; |
11 |
import org.cresques.px.Extent; |
12 |
import org.cresques.px.gml.Feature; |
13 |
import org.cresques.px.gml.FeatureCollection; |
14 |
import org.cresques.px.gml.InsPoint; |
15 |
import org.cresques.px.gml.LineString; |
16 |
import org.cresques.px.gml.Point; |
17 |
import org.cresques.px.gml.Polygon; |
18 |
import java.util.Iterator; |
19 |
import java.util.Vector; |
20 |
import java.awt.Graphics2D; |
21 |
import java.awt.geom.Point2D; |
22 |
|
23 |
public class DxfFeatureMaker implements DxfFile.EntityFactory, Projected { |
24 |
|
25 |
Projection proj = null;
|
26 |
Feature lastFeature = null;
|
27 |
Vector features = null; |
28 |
double bulge = 0.0; |
29 |
double xtruX=0.0, xtruY=0.0, xtruZ=1.0; |
30 |
int polylineFlag = 0; |
31 |
Point2D firstPt = new Point2D.Double(); |
32 |
|
33 |
boolean addingToBlock = false; |
34 |
int iterator = 0; |
35 |
FeatureCollection blk = null;
|
36 |
Vector blkList = null; |
37 |
|
38 |
public DxfFeatureMaker(Projection proj) {
|
39 |
this.proj = proj;
|
40 |
features = new Vector(); |
41 |
blkList = new Vector(); |
42 |
} |
43 |
|
44 |
public void setAddingToBlock(boolean a) { addingToBlock = a; } |
45 |
|
46 |
/* (non-Javadoc)
|
47 |
* @see org.cresques.io.DxfFile.EntityFactory#createLayer(org.cresques.io.DxfGroupVector)
|
48 |
*/
|
49 |
public void createLayer(DxfGroupVector v) throws Exception { |
50 |
// TODO Auto-generated method stub
|
51 |
} |
52 |
|
53 |
/* (non-Javadoc)
|
54 |
* @see org.cresques.io.DxfFile.EntityFactory#createPolyline(org.cresques.io.DxfGroupVector)
|
55 |
*/
|
56 |
public void createPolyline(DxfGroupVector grp) throws Exception { |
57 |
LineString lineString = new LineString();
|
58 |
Polygon polygon = new Polygon(); |
59 |
Feature feature= new Feature();
|
60 |
double x = 0.0, y = 0.0, z = 0.0; |
61 |
int flags = 0; |
62 |
double thickness = 0; |
63 |
|
64 |
if (grp.hasCode(8)) |
65 |
feature.setProp("layer", grp.getDataAsString(8)); |
66 |
if (grp.hasCode(62)) { |
67 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
68 |
String string = integer.toString();
|
69 |
feature.setProp("color", string);
|
70 |
//entity.dxfColor = grp.getDataAsInt(62);
|
71 |
} else {
|
72 |
feature.setProp("color", "0"); |
73 |
} |
74 |
if (grp.hasCode(1)) { |
75 |
feature.setProp("text", grp.getDataAsString(1)); |
76 |
//txt = grp.getDataAsString(1);
|
77 |
} else {
|
78 |
feature.setProp("text", "No text"); |
79 |
} |
80 |
|
81 |
if (grp.hasCode(10)) |
82 |
x = grp.getDataAsDouble(10);
|
83 |
if (grp.hasCode(20)) |
84 |
y = grp.getDataAsDouble(20);
|
85 |
if (grp.hasCode(30)) |
86 |
z = grp.getDataAsDouble(30);
|
87 |
/*if (grp.hasCode(39))
|
88 |
System.out.println("Leer el thickness provoca un error");
|
89 |
thickness = grp.getDataAsDouble(39);*/
|
90 |
if (grp.hasCode(70)) |
91 |
flags = grp.getDataAsInt(70);
|
92 |
if (grp.hasCode(210)) |
93 |
xtruX = grp.getDataAsDouble(210);
|
94 |
if (grp.hasCode(220)) |
95 |
xtruY = grp.getDataAsDouble(220);
|
96 |
if (grp.hasCode(230)) |
97 |
xtruZ = grp.getDataAsDouble(230);
|
98 |
if ((flags & 0x01) == 0x01) { |
99 |
feature.setGeometry(polygon); |
100 |
} else {
|
101 |
feature.setGeometry(lineString); |
102 |
} |
103 |
lastFeature = feature; |
104 |
} |
105 |
|
106 |
/* (non-Javadoc)
|
107 |
* @see org.cresques.io.DxfFile.EntityFactory#endSeq()
|
108 |
*/
|
109 |
public void endSeq() throws Exception { |
110 |
Feature feature = lastFeature; |
111 |
if (feature.getGeometry() instanceof LineString) { |
112 |
LineString lineString = (LineString)feature.getGeometry(); |
113 |
//lineString.add(firstPt);
|
114 |
if (!(bulge==0)) { |
115 |
int cnt = lineString.pointNr();
|
116 |
Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
117 |
lineString.remove(cnt-1);
|
118 |
for (int i=0; i<arc.size(); i++) { |
119 |
Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
120 |
lineString.add(pt); |
121 |
if (lineString.pointNr() == 1) firstPt = pt; |
122 |
} |
123 |
bulge = 0.0;
|
124 |
} |
125 |
lastFeature.setGeometry(lineString); |
126 |
} |
127 |
if (feature.getGeometry() instanceof Polygon) { |
128 |
Polygon polygon = (Polygon)feature.getGeometry(); |
129 |
polygon.add(firstPt); |
130 |
if (!(bulge==0)) { |
131 |
int cnt = polygon.pointNr();
|
132 |
Vector arc = createArc((Point2D)(polygon.get(cnt-2)), (Point2D)(polygon.get(cnt-1)), bulge); |
133 |
polygon.remove(cnt-1);
|
134 |
for (int i=0; i<arc.size(); i++) { |
135 |
Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
136 |
polygon.add(pt); |
137 |
if (polygon.pointNr() == 1) firstPt = pt; |
138 |
} |
139 |
bulge = 0.0;
|
140 |
} |
141 |
lastFeature.setGeometry(polygon); |
142 |
} |
143 |
|
144 |
//features.add(lastFeature);
|
145 |
if (addingToBlock == false) { |
146 |
System.out.println("createPolyline: A?adimos una polilinea a la lista de entidades"); |
147 |
features.add(lastFeature); |
148 |
} else {
|
149 |
System.out.println("createPolyline: A?adimos una polilinea al bloque " + iterator); |
150 |
blk.add(lastFeature); |
151 |
} |
152 |
lastFeature = null;
|
153 |
xtruX = 0.0;
|
154 |
xtruY = 0.0;
|
155 |
xtruZ = 1.0;
|
156 |
bulge = 0.0;
|
157 |
} |
158 |
|
159 |
public void addVertex(DxfGroupVector grp) throws Exception { |
160 |
double x = 0.0, y = 0.0, z = 0.0; |
161 |
Feature feature = lastFeature; |
162 |
if (feature.getGeometry() instanceof LineString) { |
163 |
LineString lineString = (LineString)feature.getGeometry(); |
164 |
if (bulge == 0.0) { |
165 |
|
166 |
if (grp.hasCode(8)) |
167 |
feature.setProp("layer", grp.getDataAsString(8)); |
168 |
if (grp.hasCode(62)) { |
169 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
170 |
String string = integer.toString();
|
171 |
feature.setProp("color", string);
|
172 |
//entity.dxfColor = grp.getDataAsInt(62);
|
173 |
} else {
|
174 |
feature.setProp("color", "0"); |
175 |
} |
176 |
if (grp.hasCode(1)) { |
177 |
feature.setProp("text", grp.getDataAsString(1)); |
178 |
//txt = grp.getDataAsString(1);
|
179 |
} else {
|
180 |
feature.setProp("text", "No text"); |
181 |
} |
182 |
|
183 |
x = grp.getDataAsDouble(10);
|
184 |
y = grp.getDataAsDouble(20);
|
185 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
186 |
if (grp.hasCode(42)) { |
187 |
bulge = grp.getDataAsDouble(42);
|
188 |
} else { bulge = 0.0; } |
189 |
Point3D point_in = new Point3D(x, y, z);
|
190 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
191 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
192 |
x = point_out.getX(); |
193 |
y = point_out.getY(); |
194 |
Point2D pt = proj.createPoint( x, y);
|
195 |
lineString.add(pt); |
196 |
if (lineString.pointNr() == 1) { |
197 |
firstPt = pt; |
198 |
} |
199 |
} else {
|
200 |
double bulge_aux = 0.0; |
201 |
|
202 |
/**
|
203 |
* Pasando a FLyrDxfG la informacion
|
204 |
* alfanumerica contenida en un DXF. En concreto Entity, Layer,
|
205 |
* Color y Text.
|
206 |
*/
|
207 |
if (grp.hasCode(8)) |
208 |
feature.setProp("layer", grp.getDataAsString(8)); |
209 |
if (grp.hasCode(62)) { |
210 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
211 |
String string = integer.toString();
|
212 |
feature.setProp("color", string);
|
213 |
//entity.dxfColor = grp.getDataAsInt(62);
|
214 |
} else {
|
215 |
feature.setProp("color", "0"); |
216 |
} |
217 |
if (grp.hasCode(1)) { |
218 |
feature.setProp("text", grp.getDataAsString(1)); |
219 |
//txt = grp.getDataAsString(1);
|
220 |
} else {
|
221 |
feature.setProp("text", "No text"); |
222 |
} |
223 |
|
224 |
x = grp.getDataAsDouble(10);
|
225 |
y = grp.getDataAsDouble(20);
|
226 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
227 |
if (grp.hasCode(42)) { |
228 |
bulge_aux = grp.getDataAsDouble(42);
|
229 |
} else { bulge_aux = 0.0; } |
230 |
Point3D point_in = new Point3D(x, y, z);
|
231 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
232 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
233 |
x = point_out.getX(); |
234 |
y = point_out.getY(); |
235 |
Point2D pt = proj.createPoint( x, y);
|
236 |
lineString.add(pt); |
237 |
if (lineString.pointNr() == 1) { |
238 |
firstPt = pt; |
239 |
} |
240 |
int cnt = lineString.pointNr();
|
241 |
Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
242 |
lineString.remove(cnt-1);
|
243 |
for (int i=0; i<arc.size(); i++) { |
244 |
pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
245 |
lineString.add(pt); |
246 |
if (lineString.pointNr() == 1) firstPt = pt; |
247 |
} |
248 |
bulge = bulge_aux; |
249 |
} |
250 |
} |
251 |
if (feature.getGeometry() instanceof Polygon) { |
252 |
Polygon polygon = (Polygon)feature.getGeometry(); |
253 |
if (bulge == 0.0) { |
254 |
|
255 |
/**
|
256 |
* Pasando a FLyrDxfG la informacion
|
257 |
* alfanumerica contenida en un DXF. En concreto Entity, Layer,
|
258 |
* Color y Text.
|
259 |
*/
|
260 |
if (grp.hasCode(8)) |
261 |
feature.setProp("layer", grp.getDataAsString(8)); |
262 |
if (grp.hasCode(62)) { |
263 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
264 |
String string = integer.toString();
|
265 |
feature.setProp("color", string);
|
266 |
//entity.dxfColor = grp.getDataAsInt(62);
|
267 |
} else {
|
268 |
feature.setProp("color", "0"); |
269 |
} |
270 |
if (grp.hasCode(1)) { |
271 |
feature.setProp("text", grp.getDataAsString(1)); |
272 |
//txt = grp.getDataAsString(1);
|
273 |
} else {
|
274 |
feature.setProp("text", "No text"); |
275 |
} |
276 |
|
277 |
x = grp.getDataAsDouble(10);
|
278 |
y = grp.getDataAsDouble(20);
|
279 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
280 |
if (grp.hasCode(42)) { |
281 |
bulge = grp.getDataAsDouble(42);
|
282 |
} else { bulge = 0.0; } |
283 |
Point3D point_in = new Point3D(x, y, z);
|
284 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
285 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
286 |
x = point_out.getX(); |
287 |
y = point_out.getY(); |
288 |
Point2D pt = proj.createPoint( x, y);
|
289 |
polygon.add(pt); |
290 |
if (polygon.pointNr() == 1) { |
291 |
firstPt = pt; |
292 |
} |
293 |
} else {
|
294 |
double bulge_aux = 0.0; |
295 |
|
296 |
/**
|
297 |
* Pasando a FLyrDxfG la informacion
|
298 |
* alfanumerica contenida en un DXF. En concreto Entity, Layer,
|
299 |
* Color y Text.
|
300 |
*/
|
301 |
if (grp.hasCode(8)) |
302 |
feature.setProp("layer", grp.getDataAsString(8)); |
303 |
if (grp.hasCode(62)) { |
304 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
305 |
String string = integer.toString();
|
306 |
feature.setProp("color", string);
|
307 |
//entity.dxfColor = grp.getDataAsInt(62);
|
308 |
} else {
|
309 |
feature.setProp("color", "0"); |
310 |
} |
311 |
if (grp.hasCode(1)) { |
312 |
feature.setProp("text", grp.getDataAsString(1)); |
313 |
//txt = grp.getDataAsString(1);
|
314 |
} else {
|
315 |
feature.setProp("text", "No text"); |
316 |
} |
317 |
|
318 |
x = grp.getDataAsDouble(10);
|
319 |
y = grp.getDataAsDouble(20);
|
320 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
321 |
if (grp.hasCode(42)) { |
322 |
bulge_aux = grp.getDataAsDouble(42);
|
323 |
} else { bulge_aux = 0.0; } |
324 |
Point3D point_in = new Point3D(x, y, z);
|
325 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
326 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
327 |
x = point_out.getX(); |
328 |
y = point_out.getY(); |
329 |
Point2D pt = proj.createPoint( x, y);
|
330 |
polygon.add(pt); |
331 |
if (polygon.pointNr() == 1) { |
332 |
firstPt = pt; |
333 |
} |
334 |
int cnt = polygon.pointNr();
|
335 |
System.out.println("cnt = " + cnt); |
336 |
Vector arc = createArc((Point2D)(polygon.get(cnt-2)), (Point2D)(polygon.get(cnt-1)), bulge); |
337 |
polygon.remove(cnt-1);
|
338 |
for (int i=0; i<arc.size(); i++) { |
339 |
pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
340 |
polygon.add(pt); |
341 |
if (polygon.pointNr() == 1) firstPt = pt; |
342 |
} |
343 |
bulge = bulge_aux; |
344 |
} |
345 |
} |
346 |
} |
347 |
|
348 |
/* (non-Javadoc)
|
349 |
* @see org.cresques.io.DxfFile.EntityFactory#createLwPolyline(org.cresques.io.DxfGroupVector)
|
350 |
*/
|
351 |
public void createLwPolyline(DxfGroupVector grp) throws Exception { |
352 |
double x = 0.0, y = 0.0, elev=0.0; |
353 |
DxfGroup g = null;
|
354 |
LineString lineString = new LineString();
|
355 |
Polygon polygon = new Polygon(); |
356 |
Feature feature= new Feature();
|
357 |
int flags = 0; |
358 |
|
359 |
if (grp.hasCode(8)) |
360 |
feature.setProp("layer", grp.getDataAsString(8)); |
361 |
if (grp.hasCode(62)) { |
362 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
363 |
String string = integer.toString();
|
364 |
feature.setProp("color", string);
|
365 |
} else {
|
366 |
feature.setProp("color", "0"); |
367 |
} |
368 |
if (grp.hasCode(1)) { |
369 |
feature.setProp("text", grp.getDataAsString(1)); |
370 |
} else {
|
371 |
feature.setProp("text", "No text"); |
372 |
} |
373 |
|
374 |
if (grp.hasCode(38)) |
375 |
elev = grp.getDataAsDouble(38);
|
376 |
for (int i=0; i<grp.size(); i++) { |
377 |
g = (DxfGroup) grp.get(i); |
378 |
if (g.getCode() == 10) |
379 |
x = ((Float) g.getData()).doubleValue();
|
380 |
else if (g.getCode() == 20) { |
381 |
y = ((Float) g.getData()).doubleValue();
|
382 |
//if (y <= 1.0) throw new Exception("Y == "+y);
|
383 |
lineString.add( proj.createPoint( x, y ) ); |
384 |
polygon.add( proj.createPoint( x, y ) ); |
385 |
x = 0.0; y = 0.0; |
386 |
} |
387 |
} |
388 |
if (grp.hasCode(70)) |
389 |
flags = grp.getDataAsInt(70);
|
390 |
if ((flags & 0x01) == 0x01) { |
391 |
feature.setGeometry(polygon); |
392 |
} else {
|
393 |
feature.setGeometry(lineString); |
394 |
} |
395 |
lastFeature = feature; |
396 |
//features.add(feature);
|
397 |
if (addingToBlock == false) { |
398 |
features.add(feature); |
399 |
} else {
|
400 |
System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator); |
401 |
blk.add(feature); |
402 |
} |
403 |
} |
404 |
|
405 |
/* (non-Javadoc)
|
406 |
* @see org.cresques.io.DxfFile.EntityFactory#createLine(org.cresques.io.DxfGroupVector)
|
407 |
*/
|
408 |
public void createLine(DxfGroupVector grp) throws Exception { |
409 |
double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0; |
410 |
DxfGroup g = null;
|
411 |
Point2D pt1 = null, pt2 = null; |
412 |
LineString lineString = new LineString();
|
413 |
Feature feature = new Feature();
|
414 |
|
415 |
if (grp.hasCode(8)) |
416 |
feature.setProp("layer", grp.getDataAsString(8)); |
417 |
if (grp.hasCode(62)) { |
418 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
419 |
String string = integer.toString();
|
420 |
feature.setProp("color", string);
|
421 |
} else {
|
422 |
feature.setProp("color", "0"); |
423 |
} |
424 |
if (grp.hasCode(1)) { |
425 |
feature.setProp("text", grp.getDataAsString(1)); |
426 |
} else {
|
427 |
feature.setProp("text", "No text"); |
428 |
} |
429 |
|
430 |
x = grp.getDataAsDouble(10);
|
431 |
y = grp.getDataAsDouble(20);
|
432 |
if (grp.hasCode(30)) z1 = grp.getDataAsDouble(30); |
433 |
pt1 = proj.createPoint(x, y); |
434 |
x = grp.getDataAsDouble(11);
|
435 |
y = grp.getDataAsDouble(21);
|
436 |
if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31); |
437 |
pt2 = proj.createPoint(x, y); |
438 |
if (grp.hasCode(210)) |
439 |
xtruX = grp.getDataAsDouble(210);
|
440 |
if (grp.hasCode(220)) |
441 |
xtruY = grp.getDataAsDouble(220);
|
442 |
if (grp.hasCode(230)) |
443 |
xtruZ = grp.getDataAsDouble(230);
|
444 |
Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
|
445 |
Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
|
446 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
447 |
Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
|
448 |
Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
|
449 |
pt1.setLocation(point_out1); |
450 |
pt2.setLocation(point_out2); |
451 |
lineString.add(pt1); |
452 |
lineString.add(pt2); |
453 |
|
454 |
feature.setGeometry(lineString); |
455 |
//features.add(feature);
|
456 |
if (addingToBlock == false) { |
457 |
System.out.println("createLine(): A?adimos una linea a la lista de entidades"); |
458 |
features.add(feature); |
459 |
} else {
|
460 |
System.out.println("createLine(): A?adimos una linea al bloque " + iterator); |
461 |
blk.add(feature); |
462 |
} |
463 |
} |
464 |
|
465 |
/* (non-Javadoc)
|
466 |
* @see org.cresques.io.DxfFile.EntityFactory#createText(org.cresques.io.DxfGroupVector)
|
467 |
*/
|
468 |
public void createText(DxfGroupVector grp) throws Exception { |
469 |
double x = 0.0, y = 0.0, z = 0.0, h= 0.0, rot= 0.0; |
470 |
DxfGroup g = null;
|
471 |
Point2D pt1 = null, pt2 = null; |
472 |
Point2D pt = null; |
473 |
//String txt = null;
|
474 |
Point point = new Point(); |
475 |
//LineString lineText = new LineString();
|
476 |
Feature feature = new Feature();
|
477 |
|
478 |
//txt = grp.getDataAsString(1);
|
479 |
//DxfText entity = new DxfText(proj, layer, txt);
|
480 |
|
481 |
if (grp.hasCode(8)) |
482 |
feature.setProp("layer", grp.getDataAsString(8)); |
483 |
if (grp.hasCode(62)) { |
484 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
485 |
String string = integer.toString();
|
486 |
feature.setProp("color", string);
|
487 |
//entity.dxfColor = grp.getDataAsInt(62);
|
488 |
} else {
|
489 |
feature.setProp("color", "0"); |
490 |
} |
491 |
if (grp.hasCode(1)) { |
492 |
feature.setProp("text", grp.getDataAsString(1)); |
493 |
//txt = grp.getDataAsString(1);
|
494 |
} else {
|
495 |
feature.setProp("text", "No text"); |
496 |
} |
497 |
|
498 |
x = grp.getDataAsDouble(10);
|
499 |
y = grp.getDataAsDouble(20);
|
500 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
501 |
if (grp.hasCode(210)) |
502 |
xtruX = grp.getDataAsDouble(210);
|
503 |
if (grp.hasCode(220)) |
504 |
xtruY = grp.getDataAsDouble(220);
|
505 |
if (grp.hasCode(230)) |
506 |
xtruZ = grp.getDataAsDouble(230);
|
507 |
Point3D point_in = new Point3D(x, y, z);
|
508 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
509 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
510 |
x = point_out.getX(); |
511 |
y = point_out.getY(); |
512 |
//entity.setPt1(proj.createPoint(x, y));
|
513 |
//point.add(proj.createPoint(x, y));
|
514 |
//lineText.add(proj.createPoint(x, y));
|
515 |
/*if (grp.hasCode(11)) {
|
516 |
x = grp.getDataAsDouble(11);
|
517 |
y = grp.getDataAsDouble(21);
|
518 |
//entity.setPt2(proj.createPoint(x, y));
|
519 |
lineText.add(proj.createPoint(x, y));
|
520 |
}
|
521 |
entity.h = grp.getDataAsDouble(40);
|
522 |
if (grp.hasCode(50))
|
523 |
entity.rot = grp.getDataAsDouble(50);
|
524 |
if (grp.hasCode(62))
|
525 |
entity.dxfColor = grp.getDataAsInt(62);
|
526 |
if (grp.hasCode(72))
|
527 |
entity.align = grp.getDataAsInt(72);*/
|
528 |
point.add(new Point2D.Double(x, y)); |
529 |
feature.setGeometry(point); |
530 |
//entities.add(entity);
|
531 |
//features.add(feature);
|
532 |
if (addingToBlock == false) { |
533 |
features.add(feature); |
534 |
} else {
|
535 |
System.out.println("createText(): A?adimos un text al bloque " + iterator); |
536 |
blk.add(feature); |
537 |
} |
538 |
} |
539 |
|
540 |
public void createPoint(DxfGroupVector grp) throws Exception { |
541 |
double x = 0.0, y = 0.0, z = 0.0; |
542 |
DxfGroup g = null;
|
543 |
Point2D pt = null; |
544 |
Point point = new Point(); |
545 |
Feature feature = new Feature();
|
546 |
|
547 |
if (grp.hasCode(8)) |
548 |
feature.setProp("layer", grp.getDataAsString(8)); |
549 |
if (grp.hasCode(62)) { |
550 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
551 |
String string = integer.toString();
|
552 |
feature.setProp("color", string);
|
553 |
} else {
|
554 |
feature.setProp("color", "0"); |
555 |
} |
556 |
if (grp.hasCode(1)) { |
557 |
feature.setProp("text", grp.getDataAsString(1)); |
558 |
} else {
|
559 |
feature.setProp("text", "No text"); |
560 |
} |
561 |
|
562 |
x = grp.getDataAsDouble(10);
|
563 |
y = grp.getDataAsDouble(20);
|
564 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
565 |
if (grp.hasCode(210)) |
566 |
xtruX = grp.getDataAsDouble(210);
|
567 |
if (grp.hasCode(220)) |
568 |
xtruY = grp.getDataAsDouble(220);
|
569 |
if (grp.hasCode(230)) |
570 |
xtruZ = grp.getDataAsDouble(230);
|
571 |
Point3D point_in = new Point3D(x, y, z);
|
572 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
573 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
574 |
x = point_out.getX(); |
575 |
y = point_out.getY(); |
576 |
point.add(new Point2D.Double(x, y)); |
577 |
|
578 |
feature.setGeometry(point); |
579 |
//features.add(feature);
|
580 |
if (addingToBlock == false) { |
581 |
features.add(feature); |
582 |
} else {
|
583 |
System.out.println("createPoint(): A?adimos un punto al bloque " + iterator); |
584 |
blk.add(feature); |
585 |
} |
586 |
} |
587 |
|
588 |
public void createCircle(DxfGroupVector grp) throws Exception { |
589 |
double x = 0.0, y = 0.0, z = 0.0; |
590 |
double r = 0.0; |
591 |
DxfGroup g = null;
|
592 |
//LineString lineString = new LineString();
|
593 |
Polygon polygon = new Polygon(); |
594 |
Feature feature = new Feature();
|
595 |
|
596 |
if (grp.hasCode(8)) |
597 |
feature.setProp("layer", grp.getDataAsString(8)); |
598 |
if (grp.hasCode(62)) { |
599 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
600 |
String string = integer.toString();
|
601 |
feature.setProp("color", string);
|
602 |
} else {
|
603 |
feature.setProp("color", "0"); |
604 |
} |
605 |
if (grp.hasCode(1)) { |
606 |
feature.setProp("text", grp.getDataAsString(1)); |
607 |
} else {
|
608 |
feature.setProp("text", "No text"); |
609 |
} |
610 |
|
611 |
x = grp.getDataAsDouble(10);
|
612 |
y = grp.getDataAsDouble(20);
|
613 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
614 |
if (grp.hasCode(40)) r = grp.getDataAsDouble(40); |
615 |
if (grp.hasCode(210)) |
616 |
xtruX = grp.getDataAsDouble(210);
|
617 |
if (grp.hasCode(220)) |
618 |
xtruY = grp.getDataAsDouble(220);
|
619 |
if (grp.hasCode(230)) |
620 |
xtruZ = grp.getDataAsDouble(230);
|
621 |
Point3D point_in = new Point3D(x, y, z);
|
622 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
623 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
624 |
x = point_out.getX(); |
625 |
y = point_out.getY(); |
626 |
|
627 |
Point2D center = proj.createPoint( x, y);
|
628 |
Point2D[] pts = new Point2D[360]; |
629 |
int angulo = 0; |
630 |
for (angulo=0; angulo<360; angulo++) { |
631 |
pts[angulo] = new Point2D.Double(center.getX(), center.getY()); |
632 |
pts[angulo].setLocation(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0)); |
633 |
if (pts.length == 1) { |
634 |
firstPt = pts[angulo]; |
635 |
} |
636 |
} |
637 |
for (int i=0; i<pts.length; i++) { |
638 |
//lineString.add(pts[i]);
|
639 |
polygon.add(pts[i]); |
640 |
} |
641 |
|
642 |
//feature.setGeometry(lineString);
|
643 |
feature.setGeometry(polygon); |
644 |
//features.add(feature);
|
645 |
if (addingToBlock == false) { |
646 |
System.out.println("createCircle(): A?ade un circulo a la lista de entidades"); |
647 |
features.add(feature); |
648 |
} else {
|
649 |
System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator); |
650 |
blk.add(feature); |
651 |
} |
652 |
} |
653 |
|
654 |
public void createArc(DxfGroupVector grp) throws Exception { |
655 |
double x = 0.0, y = 0.0, z = 0.0; |
656 |
double r = 0.0, empieza = 0.0, acaba = 0.0; |
657 |
DxfGroup g = null;
|
658 |
LineString lineString = new LineString();
|
659 |
Feature feature = new Feature();
|
660 |
|
661 |
if (grp.hasCode(8)) |
662 |
feature.setProp("layer", grp.getDataAsString(8)); |
663 |
if (grp.hasCode(62)) { |
664 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
665 |
String string = integer.toString();
|
666 |
feature.setProp("color", string);
|
667 |
} else {
|
668 |
feature.setProp("color", "0"); |
669 |
} |
670 |
if (grp.hasCode(1)) { |
671 |
feature.setProp("text", grp.getDataAsString(1)); |
672 |
} else {
|
673 |
feature.setProp("text", "No text"); |
674 |
} |
675 |
|
676 |
x = grp.getDataAsDouble(10);
|
677 |
y = grp.getDataAsDouble(20);
|
678 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
679 |
if (grp.hasCode(40)) r = grp.getDataAsDouble(40); |
680 |
if (grp.hasCode(50)) empieza = grp.getDataAsDouble(50); |
681 |
if (grp.hasCode(51)) acaba = grp.getDataAsDouble(51); |
682 |
if (grp.hasCode(210)) |
683 |
xtruX = grp.getDataAsDouble(210);
|
684 |
if (grp.hasCode(220)) |
685 |
xtruY = grp.getDataAsDouble(220);
|
686 |
if (grp.hasCode(230)) |
687 |
xtruZ = grp.getDataAsDouble(230);
|
688 |
Point3D point_in = new Point3D(x, y, z);
|
689 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
690 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
691 |
x = point_out.getX(); |
692 |
y = point_out.getY(); |
693 |
|
694 |
Point2D center = proj.createPoint( x, y);
|
695 |
System.out.println("empieza = " + empieza + ", acaba = " + acaba); |
696 |
int iempieza = (int)empieza; |
697 |
int iacaba = (int)acaba; |
698 |
System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba); |
699 |
double angulo = 0; |
700 |
Point2D[] pts = null; |
701 |
if (empieza <= acaba) {
|
702 |
pts = new Point2D[(iacaba-iempieza)+2]; |
703 |
angulo = empieza; |
704 |
pts[0] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
705 |
for (int i=1; i<=(iacaba-iempieza)+1; i++) { |
706 |
angulo = (double)(iempieza+i);
|
707 |
pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
708 |
} |
709 |
angulo = acaba; |
710 |
pts[(iacaba-iempieza)+1] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
711 |
} else {
|
712 |
pts = new Point2D[(360-iempieza)+iacaba+2]; |
713 |
angulo = empieza; |
714 |
System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo); |
715 |
pts[0] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
716 |
for (int i=1; i<=(360-iempieza); i++) { |
717 |
angulo = (double)(iempieza+i);
|
718 |
pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
719 |
} |
720 |
for (int i=(360-iempieza)+1; i<=(360-iempieza)+iacaba; i++) { |
721 |
angulo = (double)(i-(360-iempieza)); |
722 |
pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
723 |
} |
724 |
angulo = acaba; |
725 |
pts[(360-iempieza)+iacaba+1] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
726 |
} |
727 |
for (int i=0; i<pts.length; i++) { |
728 |
lineString.add(pts[i]); |
729 |
} |
730 |
|
731 |
feature.setGeometry(lineString); |
732 |
//features.add(feature);
|
733 |
if (addingToBlock == false) { |
734 |
features.add(feature); |
735 |
} else {
|
736 |
System.out.println("createArc(): A?adimos un arco al bloque " + iterator); |
737 |
blk.add(feature); |
738 |
} |
739 |
} |
740 |
|
741 |
public void createInsert(DxfGroupVector grp) throws Exception { |
742 |
double x = 0.0, y = 0.0, z = 0.0; |
743 |
DxfGroup g = null;
|
744 |
Point2D pt = new Point2D.Double(0.0, 0.0); |
745 |
Point2D scaleFactor = new Point2D.Double(1.0, 1.0); |
746 |
double rotAngle = 0.0; |
747 |
String blockName = ""; |
748 |
|
749 |
//DxfEntityList blocks = new DxfEntityList(proj);
|
750 |
|
751 |
InsPoint insert = new InsPoint();
|
752 |
Feature feature = new Feature();
|
753 |
Point secondGeom = new Point(); |
754 |
Feature secondFeat = new Feature();
|
755 |
|
756 |
if (grp.hasCode(2)) { |
757 |
blockName = grp.getDataAsString(2);
|
758 |
//feature.setProp("blockName", blockName);
|
759 |
insert.setBlockName(blockName); |
760 |
} |
761 |
|
762 |
if (grp.hasCode(8)) { |
763 |
feature.setProp("layer", grp.getDataAsString(8)); |
764 |
secondFeat.setProp("layer", grp.getDataAsString(8)); |
765 |
} |
766 |
|
767 |
if (grp.hasCode(62)) { |
768 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
769 |
String string = integer.toString();
|
770 |
feature.setProp("color", string);
|
771 |
secondFeat.setProp("color", string);
|
772 |
} else {
|
773 |
feature.setProp("color", "0"); |
774 |
secondFeat.setProp("color", "0"); |
775 |
} |
776 |
if (grp.hasCode(1)) { |
777 |
feature.setProp("text", grp.getDataAsString(1)); |
778 |
secondFeat.setProp("text", grp.getDataAsString(1)); |
779 |
} else {
|
780 |
feature.setProp("text", "No text"); |
781 |
secondFeat.setProp("text", "No text"); |
782 |
} |
783 |
|
784 |
if (grp.hasCode(10)) x = grp.getDataAsDouble(10); |
785 |
if (grp.hasCode(20)) y = grp.getDataAsDouble(20); |
786 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
787 |
if (grp.hasCode(41)) { |
788 |
scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
|
789 |
//Double scaleFactorX = new Double(scaleFactor.getX());
|
790 |
//feature.setProp("scaleFactorX", scaleFactorX.toString());
|
791 |
insert.setScaleFactor(scaleFactor); |
792 |
} else {
|
793 |
//Double scaleFactorX = new Double(scaleFactor.getX());
|
794 |
//feature.setProp("scaleFactorX", scaleFactorX.toString());
|
795 |
insert.setScaleFactor(scaleFactor); |
796 |
} |
797 |
if (grp.hasCode(42)) { |
798 |
scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
|
799 |
//Double scaleFactorY = new Double(scaleFactor.getY());
|
800 |
//feature.setProp("scaleFactorY", scaleFactorY.toString());
|
801 |
insert.setScaleFactor(scaleFactor); |
802 |
} else {
|
803 |
//Double scaleFactorY = new Double(scaleFactor.getY());
|
804 |
//feature.setProp("scaleFactorY", scaleFactorY.toString());
|
805 |
insert.setScaleFactor(scaleFactor); |
806 |
} |
807 |
if (grp.hasCode(43)) { |
808 |
// TODO La coordenada z
|
809 |
} |
810 |
if (grp.hasCode(50)) { |
811 |
rotAngle = grp.getDataAsDouble(50);
|
812 |
//Double objRotAngle = new Double(rotAngle);
|
813 |
//feature.setProp("rotAngle", objRotAngle.toString());
|
814 |
insert.setRotAngle(rotAngle); |
815 |
System.out.println("OOOOOO: insert.getRotAngle() = " + insert.getRotAngle()); |
816 |
} |
817 |
if (grp.hasCode(210)) |
818 |
xtruX = grp.getDataAsDouble(210);
|
819 |
if (grp.hasCode(220)) |
820 |
xtruY = grp.getDataAsDouble(220);
|
821 |
if (grp.hasCode(230)) |
822 |
xtruZ = grp.getDataAsDouble(230);
|
823 |
Point3D point_in = new Point3D(x, y, z);
|
824 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
825 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
826 |
x = point_out.getX(); |
827 |
y = point_out.getY(); |
828 |
|
829 |
insert.setBlkList(blkList); |
830 |
|
831 |
insert.encuentraBloque(blockName); |
832 |
|
833 |
insert.add(new Point2D.Double(x, y)); |
834 |
secondGeom.add(new Point2D.Double(x, y)); |
835 |
|
836 |
feature.setGeometry(insert); |
837 |
secondFeat.setGeometry(secondGeom); |
838 |
|
839 |
gestionaInsert(feature); |
840 |
|
841 |
if (addingToBlock == false) { |
842 |
features.add(secondFeat); |
843 |
} |
844 |
//if (addingToBlock == true && feature.getProp("blockFound").equals("true")) {
|
845 |
if (addingToBlock == true && insert.getBlockFound() == true) { |
846 |
System.out.println("createArc(): A?adimos un insert al bloque " + iterator); |
847 |
blk.add(feature); |
848 |
} |
849 |
} |
850 |
|
851 |
/* (non-Javadoc)
|
852 |
* @see org.cresques.io.DxfFile.EntityFactory#createSolid(org.cresques.io.DxfGroupVector)
|
853 |
*/
|
854 |
public void createSolid(DxfGroupVector v) throws Exception { |
855 |
// TODO Auto-generated method stub
|
856 |
|
857 |
} |
858 |
|
859 |
public void createBlock(DxfGroupVector grp) throws Exception { |
860 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
861 |
blk = new FeatureCollection(proj);
|
862 |
|
863 |
Point2D basePoint = new Point2D.Double(); |
864 |
String blockName = ""; |
865 |
System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator); |
866 |
|
867 |
addingToBlock = true;
|
868 |
System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques"); |
869 |
blkList.add(iterator, blk); |
870 |
|
871 |
System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator); |
872 |
|
873 |
if (grp.hasCode(8)) |
874 |
blk.setProp("layer", grp.getDataAsString(8)); |
875 |
if (grp.hasCode(62)) { |
876 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
877 |
String string = integer.toString();
|
878 |
blk.setProp("color", string);
|
879 |
} else {
|
880 |
blk.setProp("color", "0"); |
881 |
} |
882 |
|
883 |
if (grp.hasCode(1)) { |
884 |
blockName = grp.getDataAsString(1);
|
885 |
//blk.setBlkName(blockName);
|
886 |
blk.setProp("blockName", blockName);
|
887 |
} |
888 |
if (grp.hasCode(2)) { |
889 |
blockName = grp.getDataAsString(2);
|
890 |
//blk.setBlkName(blockName);
|
891 |
blk.setProp("blockName", blockName);
|
892 |
} |
893 |
if (grp.hasCode(3)) { |
894 |
blockName = grp.getDataAsString(3);
|
895 |
//blk.setBlkName(blockName);
|
896 |
blk.setProp("blockName", blockName);
|
897 |
} |
898 |
if (grp.hasCode(10)) { |
899 |
//basePoint.setLocation(grp.getDataAsDouble(10), basePoint.getY());
|
900 |
//blk.setBPoint(basePoint);
|
901 |
Double basePointX = new Double(grp.getDataAsDouble(10)); |
902 |
blk.setProp("basePointX", basePointX.toString());
|
903 |
} |
904 |
if (grp.hasCode(20)) { |
905 |
//basePoint.setLocation(basePoint.getX(), grp.getDataAsDouble(20));
|
906 |
//blk.setBPoint(basePoint);
|
907 |
Double basePointY = new Double(grp.getDataAsDouble(20)); |
908 |
blk.setProp("basePointY", basePointY.toString());
|
909 |
} |
910 |
if (grp.hasCode(30)) { |
911 |
// TODO Contemplar la coordenada z
|
912 |
} |
913 |
if (grp.hasCode(70)) { |
914 |
//blk.flags = grp.getDataAsInt(70);
|
915 |
Integer blockFlags = new Integer(grp.getDataAsInt(70)); |
916 |
blk.setProp("blockFlags", blockFlags.toString());
|
917 |
} |
918 |
} |
919 |
|
920 |
public void endBlk(DxfGroupVector grp) throws Exception { |
921 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
922 |
setAddingToBlock(false);
|
923 |
iterator = iterator + 1;
|
924 |
} |
925 |
|
926 |
public void gestionaInsert(Feature feature) { |
927 |
Feature feature2 = null;
|
928 |
Point point = null; |
929 |
LineString lineString = null;
|
930 |
Polygon polygon = null; |
931 |
InsPoint insert = new InsPoint();
|
932 |
insert = (InsPoint)feature.getGeometry(); |
933 |
double bPointX = Double.parseDouble(insert.getBlock().getProp("basePointX")); |
934 |
double bPointY = Double.parseDouble(insert.getBlock().getProp("basePointY")); |
935 |
double sFactorX = insert.getScaleFactor().getX();
|
936 |
double sFactorY = insert.getScaleFactor().getY();
|
937 |
double rAngle = insert.getRotAngle();
|
938 |
InsPoint insert2 = null;
|
939 |
|
940 |
for (int i=0; i<insert.getBlock().features.size(); i++) { |
941 |
System.out.println("gestionaInserts: insert.getBlock().features.size() = " + insert.getBlock().features.size()); |
942 |
feature2 = (Feature)insert.getBlock().features.get(i); |
943 |
Point2D point1 = new Point2D.Double(); |
944 |
Point2D point2 = new Point2D.Double(); |
945 |
Point2D point11 = new Point2D.Double(); |
946 |
Point2D point22 = new Point2D.Double(); |
947 |
if (feature2.getGeometry() instanceof InsPoint){ |
948 |
insert2 = (InsPoint)feature2.getGeometry(); |
949 |
point1 = insert2.get(0);
|
950 |
point11.setLocation(insert.get(0).getX() - (bPointX * sFactorX) + ((point1.getX()*Math.cos((rAngle*Math.PI)/180) + point1.getY()*(-1)*Math.sin((rAngle*Math.PI)/180)) * sFactorX), insert.get(0).getY() - (bPointY * sFactorY) + ((point1.getX()*Math.sin((rAngle*Math.PI)/180) + point1.getY()*Math.cos((rAngle*Math.PI)/180)) * sFactorY)); |
951 |
InsPoint insert3 = new InsPoint();
|
952 |
|
953 |
insert3.add(point11); |
954 |
|
955 |
insert3.setBlkList(insert2.getBlkList()); |
956 |
insert3.setBlock(insert2.getBlock()); |
957 |
insert3.setBlockName(insert2.getBlockName()); |
958 |
insert3.setRotAngle(insert2.getRotAngle()); |
959 |
Point2D auxPoint = new Point2D.Double(insert2.getScaleFactor().getX() * sFactorX, insert2.getScaleFactor().getY() * sFactorY); |
960 |
insert3.setScaleFactor(auxPoint); |
961 |
|
962 |
Feature feature3 = new Feature();
|
963 |
feature3.setProp("layer", feature2.getProp("layer")); |
964 |
feature3.setProp("color", feature2.getProp("color")); |
965 |
feature3.setProp("text", feature2.getProp("text")); |
966 |
feature3.setGeometry(insert3); |
967 |
|
968 |
gestionaInsert(feature3); |
969 |
} else if (feature2.getGeometry() instanceof LineString) { |
970 |
lineString = (LineString)feature2.getGeometry(); |
971 |
LineString lineString2 = new LineString();
|
972 |
Point2D[] points = new Point2D[lineString.pointNr()]; |
973 |
Point2D[] pointss = new Point2D[lineString.pointNr()]; |
974 |
for (int j=0; j<lineString.pointNr(); j++) { |
975 |
points[j] = (Point2D)lineString.get(j);
|
976 |
pointss[j] = new Point2D.Double(); |
977 |
System.out.println("AAAAAAAAAA: rAngle = " + rAngle); |
978 |
pointss[j].setLocation(insert.get(0).getX() - (bPointX * sFactorX) + ((points[j].getX()*Math.cos((rAngle*Math.PI)/180) + points[j].getY()*(-1)*Math.sin((rAngle*Math.PI)/180)) * sFactorX), insert.get(0).getY() - (bPointY * sFactorY) + ((points[j].getX()*Math.sin((rAngle*Math.PI)/180) + points[j].getY()*Math.cos((rAngle*Math.PI)/180)) * sFactorY)); |
979 |
lineString2.add(pointss[j]); |
980 |
} |
981 |
|
982 |
Feature feature3 = new Feature();
|
983 |
feature3.setProp("layer", feature2.getProp("layer")); |
984 |
feature3.setProp("color", feature2.getProp("color")); |
985 |
feature3.setProp("text", feature2.getProp("text")); |
986 |
feature3.setGeometry(lineString2); |
987 |
|
988 |
if (addingToBlock == false) { |
989 |
features.add(feature3); |
990 |
} |
991 |
} else if (feature2.getGeometry() instanceof Polygon) { |
992 |
polygon = (Polygon)feature2.getGeometry();
|
993 |
Polygon polygon2 = new Polygon(); |
994 |
Point2D[] points = new Point2D[polygon.pointNr()]; |
995 |
Point2D[] pointss = new Point2D[polygon.pointNr()]; |
996 |
for (int j=0; j<polygon.pointNr(); j++) { |
997 |
points[j] = (Point2D)polygon.get(j);
|
998 |
pointss[j] = new Point2D.Double(); |
999 |
pointss[j].setLocation(insert.get(0).getX() - (bPointX * sFactorX) + ((points[j].getX()*Math.cos((rAngle*Math.PI)/180) + points[j].getY()*(-1)*Math.sin((rAngle*Math.PI)/180)) * sFactorX), insert.get(0).getY() - (bPointY * sFactorY) + ((points[j].getX()*Math.sin((rAngle*Math.PI)/180) + points[j].getY()*Math.cos((rAngle*Math.PI)/180)) * sFactorY)); |
1000 |
polygon2.add(pointss[j]); |
1001 |
} |
1002 |
|
1003 |
Feature feature3 = new Feature();
|
1004 |
feature3.setProp("layer", feature2.getProp("layer")); |
1005 |
feature3.setProp("color", feature2.getProp("color")); |
1006 |
feature3.setProp("text", feature2.getProp("text")); |
1007 |
feature3.setGeometry(polygon2); |
1008 |
|
1009 |
if (addingToBlock == false) { |
1010 |
features.add(feature3); |
1011 |
} |
1012 |
} else if (feature2.getGeometry() instanceof Point) { |
1013 |
point = (Point)feature2.getGeometry();
|
1014 |
point1 = point.get(0);
|
1015 |
point11.setLocation(insert.get(0).getX() - (bPointX * sFactorX) + ((point1.getX()*Math.cos((rAngle*Math.PI)/180) + point1.getY()*(-1)*Math.sin((rAngle*Math.PI)/180)) * sFactorX), insert.get(0).getX() - (bPointY * sFactorY) + ((point1.getX()*Math.sin((rAngle*Math.PI)/180) + point1.getY()*Math.cos((rAngle*Math.PI)/180)) * sFactorY)); |
1016 |
Point pointt = new Point(); |
1017 |
pointt.add(point11); |
1018 |
|
1019 |
Feature feature3 = new Feature();
|
1020 |
feature3.setProp("layer", feature2.getProp("layer")); |
1021 |
feature3.setProp("color", feature2.getProp("color")); |
1022 |
feature3.setProp("text", feature2.getProp("text")); |
1023 |
feature3.setGeometry(pointt); |
1024 |
|
1025 |
if (addingToBlock == false) { |
1026 |
features.add(feature3); |
1027 |
} |
1028 |
} else {
|
1029 |
System.out.println("gestionaInserts: Encontrado elemento desconocido"); |
1030 |
} |
1031 |
} |
1032 |
} |
1033 |
|
1034 |
/* (non-Javadoc)
|
1035 |
* @see org.cresques.io.DxfFile.EntityFactory#getExtent()
|
1036 |
*/
|
1037 |
public Extent getExtent() {
|
1038 |
Feature feature = new Feature();
|
1039 |
Extent extent = new Extent();
|
1040 |
Iterator iter = features.iterator();
|
1041 |
while (iter.hasNext()) {
|
1042 |
feature = (Feature)iter.next(); |
1043 |
extent.add(feature.getExtent()); |
1044 |
} |
1045 |
return extent;
|
1046 |
} |
1047 |
|
1048 |
public void setProjection(Projection p) { |
1049 |
proj = p; |
1050 |
} |
1051 |
|
1052 |
/* (non-Javadoc)
|
1053 |
* @see org.cresques.io.DxfFile.EntityFactory#reProject(org.cresques.geo.ReProjection)
|
1054 |
*/
|
1055 |
public void reProject(ReProjection rp) { |
1056 |
Feature feature = new Feature();
|
1057 |
Extent extent = new Extent();
|
1058 |
Iterator iter = features.iterator();
|
1059 |
while (iter.hasNext()) {
|
1060 |
feature = (Feature)iter.next(); |
1061 |
((Projected) feature).reProject(rp); |
1062 |
extent.add(feature.getExtent()); |
1063 |
} |
1064 |
setProjection(rp.getPDest()); |
1065 |
} |
1066 |
|
1067 |
/* (non-Javadoc)
|
1068 |
* @see org.cresques.geo.Projected#getProjection()
|
1069 |
*/
|
1070 |
public Projection getProjection() {
|
1071 |
return proj;
|
1072 |
} |
1073 |
|
1074 |
public Vector getFeatures() { return features;} |
1075 |
|
1076 |
public void draw(Graphics2D g, ViewPort vp) { |
1077 |
Iterator iter = features.iterator();
|
1078 |
Extent extent; |
1079 |
while (iter.hasNext()) {
|
1080 |
Feature feature = new Feature();
|
1081 |
feature = (Feature)iter.next(); |
1082 |
extent = feature.getExtent(); |
1083 |
if (vp.getExtent().minX()> extent.maxX()) continue; |
1084 |
if (vp.getExtent().minY()> extent.maxY()) continue; |
1085 |
if (vp.getExtent().maxX()< extent.minX()) continue; |
1086 |
if (vp.getExtent().maxY()< extent.minY()) continue; |
1087 |
//if (!feature.layer.frozen)
|
1088 |
feature.draw(g, vp); |
1089 |
} |
1090 |
} |
1091 |
|
1092 |
public static Vector createArc(Point2D coord1, Point2D coord2, double bulge) { |
1093 |
return new DxfCalArcs(coord1, coord2, bulge).getPoints(1); |
1094 |
} |
1095 |
|
1096 |
/* (non-Javadoc)
|
1097 |
* @see org.cresques.io.DxfFile.EntityFactory#getBlkList()
|
1098 |
*/
|
1099 |
public Vector getBlkList() { |
1100 |
// TODO Auto-generated method stub
|
1101 |
return null; |
1102 |
} |
1103 |
|
1104 |
/* (non-Javadoc)
|
1105 |
* @see org.cresques.io.DxfFile.EntityFactory#getDxfEntityList()
|
1106 |
*/
|
1107 |
public DxfEntityList getDxfEntityList() {
|
1108 |
// TODO Auto-generated method stub
|
1109 |
return null; |
1110 |
} |
1111 |
|
1112 |
/* (non-Javadoc)
|
1113 |
* @see org.cresques.io.DxfFile.EntityFactory#getBlk()
|
1114 |
*/
|
1115 |
public DxfBlock getBlk() {
|
1116 |
// TODO Auto-generated method stub
|
1117 |
return null; |
1118 |
} |
1119 |
|
1120 |
} |