svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfFeatureMaker.java @ 131
History | View | Annotate | Download (58 KB)
1 |
package org.cresques.px.dxf; |
---|---|
2 |
|
3 |
import org.cresques.cts.ICoordTrans; |
4 |
import org.cresques.cts.IProjection; |
5 |
import org.cresques.geo.Point3D; |
6 |
import org.cresques.geo.Projected; |
7 |
import org.cresques.geo.ViewPortData; |
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.IObjList; |
13 |
import org.cresques.px.gml.Feature; |
14 |
import org.cresques.px.gml.FeatureCollection; |
15 |
import org.cresques.px.gml.Geometry; |
16 |
import org.cresques.px.gml.InsPoint; |
17 |
import org.cresques.px.gml.LineString; |
18 |
import org.cresques.px.gml.Point; |
19 |
import org.cresques.px.gml.Polygon; |
20 |
import java.util.Iterator; |
21 |
import java.util.Vector; |
22 |
import java.awt.Graphics2D; |
23 |
import java.awt.geom.Point2D; |
24 |
|
25 |
public class DxfFeatureMaker implements DxfFile.EntityFactory, Projected { |
26 |
IProjection proj = null;
|
27 |
Feature lastFeature = null;
|
28 |
|
29 |
Feature lastFeaBordes = null;
|
30 |
Feature lastFeaFondos = null;
|
31 |
boolean isDoubleFeature = false; |
32 |
|
33 |
FeatureCollection features = null;
|
34 |
double bulge = 0.0; |
35 |
double xtruX=0.0, xtruY=0.0, xtruZ=1.0; |
36 |
int polylineFlag = 0; |
37 |
Point2D firstPt = new Point2D.Double(); |
38 |
|
39 |
boolean addingToBlock = false; |
40 |
int iterator = 0; |
41 |
FeatureCollection blk = null;
|
42 |
Vector blkList = null; |
43 |
DxfTable layers = null;
|
44 |
|
45 |
public DxfFeatureMaker(IProjection proj) {
|
46 |
this.proj = proj;
|
47 |
layers = new DxfTable();
|
48 |
features = new FeatureCollection(proj);
|
49 |
blkList = new Vector(); |
50 |
} |
51 |
|
52 |
public void setAddingToBlock(boolean a) { addingToBlock = a; } |
53 |
|
54 |
public void createLayer(DxfGroupVector v) throws Exception { |
55 |
int color = v.getDataAsInt(62); |
56 |
DxfLayer layer = new DxfLayer(v.getDataAsString(2), Math.abs(v.getDataAsInt(62))); |
57 |
if (color < 0) { |
58 |
layer.isOff = true;
|
59 |
} |
60 |
layer.lType = v.getDataAsString(6);
|
61 |
layer.setFlags(v.getDataAsInt(70));
|
62 |
// compruebo flags
|
63 |
if ((layer.flags & 0x01) == 0x01) { |
64 |
layer.frozen = true;
|
65 |
} |
66 |
if ((layer.flags & 0x02) == 0x02) { |
67 |
layer.frozen = true;
|
68 |
} |
69 |
System.out.println("LAYER color="+layer.getColor()); |
70 |
|
71 |
layers.add(layer); |
72 |
} |
73 |
|
74 |
public void createPolyline(DxfGroupVector grp) throws Exception { |
75 |
LineString lineString = new LineString();
|
76 |
Polygon polygon = new Polygon(); |
77 |
Feature feature= new Feature();
|
78 |
Feature feaBordes= new Feature();
|
79 |
Feature feaFondos= new Feature();
|
80 |
double x = 0.0, y = 0.0, z = 0.0; |
81 |
int flags = 0; |
82 |
|
83 |
feature.setProp("dxfEntity", "Polyline"); |
84 |
if (grp.hasCode(8)) { |
85 |
feature.setProp("layer", grp.getDataAsString(8)); |
86 |
} |
87 |
if (grp.hasCode(39)) { |
88 |
Double doub = new Double(grp.getDataAsDouble(39)); |
89 |
String string = doub.toString();
|
90 |
feature.setProp("thickness", string);
|
91 |
} else {
|
92 |
Double doub = new Double(0.0); |
93 |
feature.setProp("thickness", doub.toString());
|
94 |
} |
95 |
if (grp.hasCode(62)) { |
96 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
97 |
String string = integer.toString();
|
98 |
feature.setProp("color", string);
|
99 |
} else {
|
100 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
101 |
int clr = layer.colorNumber;
|
102 |
Integer integer = new Integer(clr); |
103 |
String string = integer.toString();
|
104 |
feature.setProp("color", string);
|
105 |
} |
106 |
if (grp.hasCode(10)) |
107 |
x = grp.getDataAsDouble(10);
|
108 |
if (grp.hasCode(20)) |
109 |
y = grp.getDataAsDouble(20);
|
110 |
if (grp.hasCode(30)) { |
111 |
z = grp.getDataAsDouble(30);
|
112 |
Double doub = new Double(z); |
113 |
String string = doub.toString();
|
114 |
feature.setProp("elevation", string);
|
115 |
} |
116 |
if (grp.hasCode(70)) |
117 |
flags = grp.getDataAsInt(70);
|
118 |
if (grp.hasCode(210)) |
119 |
xtruX = grp.getDataAsDouble(210);
|
120 |
if (grp.hasCode(220)) |
121 |
xtruY = grp.getDataAsDouble(220);
|
122 |
if (grp.hasCode(230)) |
123 |
xtruZ = grp.getDataAsDouble(230);
|
124 |
if ((flags & 0x01) == 0x00) { |
125 |
feature.setGeometry(lineString); |
126 |
lastFeature = feature; |
127 |
} else if ((flags & 0x01) == 0x01) { |
128 |
feaBordes = feature; |
129 |
feaFondos = feature; |
130 |
feaBordes.setGeometry(lineString); |
131 |
feaFondos.setGeometry(polygon); |
132 |
lastFeaBordes = feaBordes; |
133 |
lastFeaFondos = feaFondos; |
134 |
isDoubleFeature = true;
|
135 |
} else {
|
136 |
System.out.println("Detectada una Polyline Flag que no corresponde"); |
137 |
System.out.println("a una Polyline corriente, ni a una Closed Polyline"); |
138 |
} |
139 |
} |
140 |
|
141 |
public void endSeq() throws Exception { |
142 |
if (isDoubleFeature) {
|
143 |
Feature feaBordes = lastFeaBordes; |
144 |
Feature feaFondos = lastFeaFondos; |
145 |
LineString lineString = (LineString)feaBordes.getGeometry(); |
146 |
if (!(bulge==0)) { |
147 |
int cnt = lineString.pointNr();
|
148 |
Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
149 |
lineString.remove(cnt-1);
|
150 |
for (int i=0; i<arc.size(); i++) { |
151 |
Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
152 |
lineString.add(pt); |
153 |
if (lineString.pointNr() == 1) firstPt = pt; |
154 |
} |
155 |
bulge = 0.0;
|
156 |
} |
157 |
lastFeaBordes.setGeometry(lineString); |
158 |
|
159 |
Polygon polygon = (Polygon)feaFondos.getGeometry(); |
160 |
polygon.add(firstPt); |
161 |
if (!(bulge==0)) { |
162 |
int cnt = polygon.pointNr();
|
163 |
Vector arc = createArc((Point2D)(polygon.get(cnt-2)), (Point2D)(polygon.get(cnt-1)), bulge); |
164 |
polygon.remove(cnt-1);
|
165 |
for (int i=0; i<arc.size(); i++) { |
166 |
Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
167 |
polygon.add(pt); |
168 |
if (polygon.pointNr() == 1) firstPt = pt; |
169 |
} |
170 |
bulge = 0.0;
|
171 |
} |
172 |
lastFeaFondos.setGeometry(polygon); |
173 |
if (addingToBlock == false) { |
174 |
features.add(lastFeaBordes); |
175 |
features.add(lastFeaFondos); |
176 |
} else {
|
177 |
blk.add(lastFeaBordes); |
178 |
blk.add(lastFeaFondos); |
179 |
} |
180 |
lastFeaBordes = null;
|
181 |
lastFeaFondos = null;
|
182 |
} else {
|
183 |
Feature feature = lastFeature; |
184 |
LineString lineString = (LineString)feature.getGeometry(); |
185 |
if (!(bulge==0)) { |
186 |
int cnt = lineString.pointNr();
|
187 |
Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
188 |
lineString.remove(cnt-1);
|
189 |
for (int i=0; i<arc.size(); i++) { |
190 |
Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
191 |
lineString.add(pt); |
192 |
if (lineString.pointNr() == 1) firstPt = pt; |
193 |
} |
194 |
bulge = 0.0;
|
195 |
} |
196 |
lastFeature.setGeometry(lineString); |
197 |
if (addingToBlock == false) { |
198 |
features.add(lastFeature); |
199 |
} else {
|
200 |
blk.add(lastFeature); |
201 |
} |
202 |
lastFeature = null;
|
203 |
} |
204 |
/*if (feature.getGeometry() instanceof LineString) {
|
205 |
LineString lineString = (LineString)feature.getGeometry();
|
206 |
//lineString.add(firstPt);
|
207 |
if (!(bulge==0)) {
|
208 |
int cnt = lineString.pointNr();
|
209 |
Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge);
|
210 |
lineString.remove(cnt-1);
|
211 |
for (int i=0; i<arc.size(); i++) {
|
212 |
Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
|
213 |
lineString.add(pt);
|
214 |
if (lineString.pointNr() == 1) firstPt = pt;
|
215 |
}
|
216 |
bulge = 0.0;
|
217 |
}
|
218 |
lastFeature.setGeometry(lineString);
|
219 |
}
|
220 |
if (feature.getGeometry() instanceof Polygon) {
|
221 |
Polygon polygon = (Polygon)feature.getGeometry();
|
222 |
polygon.add(firstPt);
|
223 |
if (!(bulge==0)) {
|
224 |
int cnt = polygon.pointNr();
|
225 |
Vector arc = createArc((Point2D)(polygon.get(cnt-2)), (Point2D)(polygon.get(cnt-1)), bulge);
|
226 |
polygon.remove(cnt-1);
|
227 |
for (int i=0; i<arc.size(); i++) {
|
228 |
Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
|
229 |
polygon.add(pt);
|
230 |
if (polygon.pointNr() == 1) firstPt = pt;
|
231 |
}
|
232 |
bulge = 0.0;
|
233 |
}
|
234 |
lastFeature.setGeometry(polygon);
|
235 |
}*/
|
236 |
xtruX = 0.0;
|
237 |
xtruY = 0.0;
|
238 |
xtruZ = 1.0;
|
239 |
bulge = 0.0;
|
240 |
isDoubleFeature = false;
|
241 |
} |
242 |
|
243 |
public void addVertex(DxfGroupVector grp) throws Exception { |
244 |
double x = 0.0, y = 0.0, z = 0.0; |
245 |
if (isDoubleFeature) {
|
246 |
Feature feaBordes = lastFeaBordes; |
247 |
Feature feaFondos = lastFeaFondos; |
248 |
LineString lineString = (LineString)feaBordes.getGeometry(); |
249 |
if (grp.hasCode(8)) |
250 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
251 |
if (grp.hasCode(62)) { |
252 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
253 |
String string = integer.toString();
|
254 |
feaBordes.setProp("color", string);
|
255 |
} else {
|
256 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
257 |
int clr = layer.colorNumber;
|
258 |
Integer integer = new Integer(clr); |
259 |
String string = integer.toString();
|
260 |
feaBordes.setProp("color", string);
|
261 |
} |
262 |
x = grp.getDataAsDouble(10);
|
263 |
y = grp.getDataAsDouble(20);
|
264 |
if (grp.hasCode(30)) { |
265 |
z = grp.getDataAsDouble(30);
|
266 |
} |
267 |
Point3D point_in = new Point3D(x, y, z);
|
268 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
269 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
270 |
x = point_out.getX(); |
271 |
y = point_out.getY(); |
272 |
Point2D pt = proj.createPoint( x, y);
|
273 |
lineString.add(pt); |
274 |
if (lineString.pointNr() == 1) { |
275 |
firstPt = pt; |
276 |
} |
277 |
if (bulge == 0.0) { |
278 |
if (grp.hasCode(42)) { |
279 |
bulge = grp.getDataAsDouble(42);
|
280 |
} else { bulge = 0.0; } |
281 |
} else {
|
282 |
/*if (grp.hasCode(8))
|
283 |
feature.setProp("layer", grp.getDataAsString(8));
|
284 |
if (grp.hasCode(62)) {
|
285 |
Integer integer = new Integer(grp.getDataAsInt(62));
|
286 |
String string = integer.toString();
|
287 |
feature.setProp("color", string);
|
288 |
} else {
|
289 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
290 |
int clr = layer.colorNumber;
|
291 |
Integer integer = new Integer(clr);
|
292 |
String string = integer.toString();
|
293 |
feature.setProp("color", string);
|
294 |
}
|
295 |
x = grp.getDataAsDouble(10);
|
296 |
y = grp.getDataAsDouble(20);
|
297 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
|
298 |
Point3D point_in = new Point3D(x, y, z);
|
299 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
300 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
301 |
x = point_out.getX();
|
302 |
y = point_out.getY();
|
303 |
Point2D pt = proj.createPoint( x, y);
|
304 |
lineString.add(pt);
|
305 |
if (lineString.pointNr() == 1) {
|
306 |
firstPt = pt;
|
307 |
}*/
|
308 |
double bulge_aux = 0.0; |
309 |
if (grp.hasCode(42)) { |
310 |
bulge_aux = grp.getDataAsDouble(42);
|
311 |
} else { bulge_aux = 0.0; } |
312 |
int cnt = lineString.pointNr();
|
313 |
Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
314 |
lineString.remove(cnt-1);
|
315 |
for (int i=0; i<arc.size(); i++) { |
316 |
pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
317 |
lineString.add(pt); |
318 |
if (lineString.pointNr() == 1) firstPt = pt; |
319 |
} |
320 |
bulge = bulge_aux; |
321 |
} |
322 |
|
323 |
Polygon polygon = (Polygon)feaFondos.getGeometry(); |
324 |
if (grp.hasCode(8)) |
325 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
326 |
if (grp.hasCode(62)) { |
327 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
328 |
String string = integer.toString();
|
329 |
feaFondos.setProp("color", string);
|
330 |
} else {
|
331 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
332 |
int clr = layer.colorNumber;
|
333 |
Integer integer = new Integer(clr); |
334 |
String string = integer.toString();
|
335 |
feaFondos.setProp("color", string);
|
336 |
} |
337 |
x = grp.getDataAsDouble(10);
|
338 |
y = grp.getDataAsDouble(20);
|
339 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
340 |
point_in = new Point3D(x, y, z);
|
341 |
xtru = new Point3D(xtruX, xtruY, xtruZ);
|
342 |
point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
343 |
x = point_out.getX(); |
344 |
y = point_out.getY(); |
345 |
pt = proj.createPoint( x, y); |
346 |
polygon.add(pt); |
347 |
if (polygon.pointNr() == 1) { |
348 |
firstPt = pt; |
349 |
} |
350 |
if (bulge == 0.0) { |
351 |
if (grp.hasCode(42)) { |
352 |
bulge = grp.getDataAsDouble(42);
|
353 |
} else { bulge = 0.0; } |
354 |
} else {
|
355 |
/*if (grp.hasCode(8))
|
356 |
feature.setProp("layer", grp.getDataAsString(8));
|
357 |
if (grp.hasCode(62)) {
|
358 |
Integer integer = new Integer(grp.getDataAsInt(62));
|
359 |
String string = integer.toString();
|
360 |
feature.setProp("color", string);
|
361 |
} else {
|
362 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
363 |
int clr = layer.colorNumber;
|
364 |
Integer integer = new Integer(clr);
|
365 |
String string = integer.toString();
|
366 |
feature.setProp("color", string);
|
367 |
}
|
368 |
x = grp.getDataAsDouble(10);
|
369 |
y = grp.getDataAsDouble(20);
|
370 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
|
371 |
Point3D point_in = new Point3D(x, y, z);
|
372 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
373 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
374 |
x = point_out.getX();
|
375 |
y = point_out.getY();
|
376 |
Point2D pt = proj.createPoint( x, y);
|
377 |
polygon.add(pt);
|
378 |
if (polygon.pointNr() == 1) {
|
379 |
firstPt = pt;
|
380 |
}*/
|
381 |
double bulge_aux = 0.0; |
382 |
if (grp.hasCode(42)) { |
383 |
bulge_aux = grp.getDataAsDouble(42);
|
384 |
} else { bulge_aux = 0.0; } |
385 |
int cnt = polygon.pointNr();
|
386 |
System.out.println("cnt = " + cnt); |
387 |
Vector arc = createArc((Point2D)(polygon.get(cnt-2)), (Point2D)(polygon.get(cnt-1)), bulge); |
388 |
polygon.remove(cnt-1);
|
389 |
for (int i=0; i<arc.size(); i++) { |
390 |
pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
391 |
polygon.add(pt); |
392 |
if (polygon.pointNr() == 1) firstPt = pt; |
393 |
} |
394 |
bulge = bulge_aux; |
395 |
} |
396 |
} else {
|
397 |
Feature feature = lastFeature; |
398 |
LineString lineString = (LineString)feature.getGeometry(); |
399 |
if (grp.hasCode(8)) |
400 |
feature.setProp("layer", grp.getDataAsString(8)); |
401 |
if (grp.hasCode(62)) { |
402 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
403 |
String string = integer.toString();
|
404 |
feature.setProp("color", string);
|
405 |
} else {
|
406 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
407 |
int clr = layer.colorNumber;
|
408 |
Integer integer = new Integer(clr); |
409 |
String string = integer.toString();
|
410 |
feature.setProp("color", string);
|
411 |
} |
412 |
x = grp.getDataAsDouble(10);
|
413 |
y = grp.getDataAsDouble(20);
|
414 |
if (grp.hasCode(30)) { |
415 |
z = grp.getDataAsDouble(30);
|
416 |
} |
417 |
Point3D point_in = new Point3D(x, y, z);
|
418 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
419 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
420 |
x = point_out.getX(); |
421 |
y = point_out.getY(); |
422 |
Point2D pt = proj.createPoint( x, y);
|
423 |
lineString.add(pt); |
424 |
if (lineString.pointNr() == 1) { |
425 |
firstPt = pt; |
426 |
} |
427 |
if (bulge == 0.0) { |
428 |
if (grp.hasCode(42)) { |
429 |
bulge = grp.getDataAsDouble(42);
|
430 |
} else { bulge = 0.0; } |
431 |
} else {
|
432 |
double bulge_aux = 0.0; |
433 |
if (grp.hasCode(42)) { |
434 |
bulge_aux = grp.getDataAsDouble(42);
|
435 |
} else { bulge_aux = 0.0; } |
436 |
int cnt = lineString.pointNr();
|
437 |
Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
438 |
lineString.remove(cnt-1);
|
439 |
for (int i=0; i<arc.size(); i++) { |
440 |
pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
441 |
lineString.add(pt); |
442 |
if (lineString.pointNr() == 1) firstPt = pt; |
443 |
} |
444 |
bulge = bulge_aux; |
445 |
} |
446 |
} |
447 |
|
448 |
/*if (feature.getGeometry() instanceof LineString) {
|
449 |
LineString lineString = (LineString)feature.getGeometry();
|
450 |
if (bulge == 0.0) {
|
451 |
|
452 |
if (grp.hasCode(8))
|
453 |
feature.setProp("layer", grp.getDataAsString(8));
|
454 |
if (grp.hasCode(62)) {
|
455 |
Integer integer = new Integer(grp.getDataAsInt(62));
|
456 |
String string = integer.toString();
|
457 |
feature.setProp("color", string);
|
458 |
} else {
|
459 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
460 |
int clr = layer.colorNumber;
|
461 |
Integer integer = new Integer(clr);
|
462 |
String string = integer.toString();
|
463 |
feature.setProp("color", string);
|
464 |
}
|
465 |
x = grp.getDataAsDouble(10);
|
466 |
y = grp.getDataAsDouble(20);
|
467 |
if (grp.hasCode(30)) {
|
468 |
z = grp.getDataAsDouble(30);
|
469 |
}
|
470 |
if (grp.hasCode(42)) {
|
471 |
bulge = grp.getDataAsDouble(42);
|
472 |
} else { bulge = 0.0; }
|
473 |
Point3D point_in = new Point3D(x, y, z);
|
474 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
475 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
476 |
x = point_out.getX();
|
477 |
y = point_out.getY();
|
478 |
Point2D pt = proj.createPoint( x, y);
|
479 |
lineString.add(pt);
|
480 |
if (lineString.pointNr() == 1) {
|
481 |
firstPt = pt;
|
482 |
}
|
483 |
} else {
|
484 |
double bulge_aux = 0.0;
|
485 |
|
486 |
if (grp.hasCode(8))
|
487 |
feature.setProp("layer", grp.getDataAsString(8));
|
488 |
if (grp.hasCode(62)) {
|
489 |
Integer integer = new Integer(grp.getDataAsInt(62));
|
490 |
String string = integer.toString();
|
491 |
feature.setProp("color", string);
|
492 |
} else {
|
493 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
494 |
int clr = layer.colorNumber;
|
495 |
Integer integer = new Integer(clr);
|
496 |
String string = integer.toString();
|
497 |
feature.setProp("color", string);
|
498 |
}
|
499 |
x = grp.getDataAsDouble(10);
|
500 |
y = grp.getDataAsDouble(20);
|
501 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
|
502 |
if (grp.hasCode(42)) {
|
503 |
bulge_aux = grp.getDataAsDouble(42);
|
504 |
} else { bulge_aux = 0.0; }
|
505 |
Point3D point_in = new Point3D(x, y, z);
|
506 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
507 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
508 |
x = point_out.getX();
|
509 |
y = point_out.getY();
|
510 |
Point2D pt = proj.createPoint( x, y);
|
511 |
lineString.add(pt);
|
512 |
if (lineString.pointNr() == 1) {
|
513 |
firstPt = pt;
|
514 |
}
|
515 |
int cnt = lineString.pointNr();
|
516 |
Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge);
|
517 |
lineString.remove(cnt-1);
|
518 |
for (int i=0; i<arc.size(); i++) {
|
519 |
pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
|
520 |
lineString.add(pt);
|
521 |
if (lineString.pointNr() == 1) firstPt = pt;
|
522 |
}
|
523 |
bulge = bulge_aux;
|
524 |
}
|
525 |
}
|
526 |
if (feature.getGeometry() instanceof Polygon) {
|
527 |
Polygon polygon = (Polygon)feature.getGeometry();
|
528 |
if (bulge == 0.0) {
|
529 |
|
530 |
if (grp.hasCode(8))
|
531 |
feature.setProp("layer", grp.getDataAsString(8));
|
532 |
if (grp.hasCode(62)) {
|
533 |
Integer integer = new Integer(grp.getDataAsInt(62));
|
534 |
String string = integer.toString();
|
535 |
feature.setProp("color", string);
|
536 |
} else {
|
537 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
538 |
int clr = layer.colorNumber;
|
539 |
Integer integer = new Integer(clr);
|
540 |
String string = integer.toString();
|
541 |
feature.setProp("color", string);
|
542 |
}
|
543 |
x = grp.getDataAsDouble(10);
|
544 |
y = grp.getDataAsDouble(20);
|
545 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
|
546 |
if (grp.hasCode(42)) {
|
547 |
bulge = grp.getDataAsDouble(42);
|
548 |
} else { bulge = 0.0; }
|
549 |
Point3D point_in = new Point3D(x, y, z);
|
550 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
551 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
552 |
x = point_out.getX();
|
553 |
y = point_out.getY();
|
554 |
Point2D pt = proj.createPoint( x, y);
|
555 |
polygon.add(pt);
|
556 |
if (polygon.pointNr() == 1) {
|
557 |
firstPt = pt;
|
558 |
}
|
559 |
} else {
|
560 |
double bulge_aux = 0.0;
|
561 |
|
562 |
if (grp.hasCode(8))
|
563 |
feature.setProp("layer", grp.getDataAsString(8));
|
564 |
if (grp.hasCode(62)) {
|
565 |
Integer integer = new Integer(grp.getDataAsInt(62));
|
566 |
String string = integer.toString();
|
567 |
feature.setProp("color", string);
|
568 |
} else {
|
569 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
570 |
int clr = layer.colorNumber;
|
571 |
Integer integer = new Integer(clr);
|
572 |
String string = integer.toString();
|
573 |
feature.setProp("color", string);
|
574 |
}
|
575 |
x = grp.getDataAsDouble(10);
|
576 |
y = grp.getDataAsDouble(20);
|
577 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
|
578 |
if (grp.hasCode(42)) {
|
579 |
bulge_aux = grp.getDataAsDouble(42);
|
580 |
} else { bulge_aux = 0.0; }
|
581 |
Point3D point_in = new Point3D(x, y, z);
|
582 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
583 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
584 |
x = point_out.getX();
|
585 |
y = point_out.getY();
|
586 |
Point2D pt = proj.createPoint( x, y);
|
587 |
polygon.add(pt);
|
588 |
if (polygon.pointNr() == 1) {
|
589 |
firstPt = pt;
|
590 |
}
|
591 |
int cnt = polygon.pointNr();
|
592 |
System.out.println("cnt = " + cnt);
|
593 |
Vector arc = createArc((Point2D)(polygon.get(cnt-2)), (Point2D)(polygon.get(cnt-1)), bulge);
|
594 |
polygon.remove(cnt-1);
|
595 |
for (int i=0; i<arc.size(); i++) {
|
596 |
pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
|
597 |
polygon.add(pt);
|
598 |
if (polygon.pointNr() == 1) firstPt = pt;
|
599 |
}
|
600 |
bulge = bulge_aux;
|
601 |
}
|
602 |
}*/
|
603 |
} |
604 |
|
605 |
public void createLwPolyline(DxfGroupVector grp) throws Exception { |
606 |
double x = 0.0, y = 0.0; |
607 |
double elev = 0.0; |
608 |
DxfGroup g = null;
|
609 |
//LineString lineString = new LineString();
|
610 |
//Polygon polygon = new Polygon();
|
611 |
Geometry geometria; |
612 |
Feature feature= new Feature();
|
613 |
int flags = 0; |
614 |
|
615 |
feature.setProp("dxfEntity", "LwPolyline"); |
616 |
if (grp.hasCode(8)) |
617 |
feature.setProp("layer", grp.getDataAsString(8)); |
618 |
if (grp.hasCode(38)) { |
619 |
elev = grp.getDataAsDouble(38);
|
620 |
Double doub = new Double(elev); |
621 |
String string = doub.toString();
|
622 |
feature.setProp("elevation", string);
|
623 |
} else {
|
624 |
Double doub = new Double(0.0); |
625 |
feature.setProp("elevation", doub.toString());
|
626 |
} |
627 |
if (grp.hasCode(39)) { |
628 |
Double doub = new Double(grp.getDataAsDouble(39)); |
629 |
String string = doub.toString();
|
630 |
feature.setProp("thickness", string);
|
631 |
} else {
|
632 |
Double doub = new Double(0.0); |
633 |
feature.setProp("thickness", doub.toString());
|
634 |
} |
635 |
if (grp.hasCode(62)) { |
636 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
637 |
String string = integer.toString();
|
638 |
feature.setProp("color", string);
|
639 |
} else {
|
640 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
641 |
int clr = layer.colorNumber;
|
642 |
Integer integer = new Integer(clr); |
643 |
String string = integer.toString();
|
644 |
feature.setProp("color", string);
|
645 |
} |
646 |
// Las DxfLwpolylines no tienen el campo 1 correspondiente al texto en
|
647 |
// los elementos DxfText.
|
648 |
/*if (grp.hasCode(1)) {
|
649 |
feature.setProp("text", grp.getDataAsString(1));
|
650 |
} else {
|
651 |
feature.setProp("text", "No text");
|
652 |
}*/
|
653 |
if (grp.hasCode(70)) |
654 |
flags = grp.getDataAsInt(70);
|
655 |
if ((flags & 0x01) == 0x01) { |
656 |
geometria = new Polygon(); |
657 |
feature.setGeometry(geometria); |
658 |
} else {
|
659 |
geometria = new LineString();
|
660 |
feature.setGeometry(geometria); |
661 |
} |
662 |
|
663 |
int j = 0; |
664 |
double firstX = 0.0; |
665 |
double firstY = 0.0; |
666 |
for (int i=0; i<grp.size(); i++) { |
667 |
g = (DxfGroup) grp.get(i); |
668 |
if (g.getCode() == 10) { |
669 |
j++; |
670 |
x = ((Double) g.getData()).doubleValue();
|
671 |
} else if (g.getCode() == 20) { |
672 |
y = ((Double) g.getData()).doubleValue();
|
673 |
//if (y <= 1.0) throw new Exception("Y == "+y);
|
674 |
//lineString.add( proj.createPoint( x, y ) );
|
675 |
//polygon.add( proj.createPoint( x, y ) );
|
676 |
geometria.add( proj.createPoint( x, y ) ); |
677 |
if (j == 1) { |
678 |
firstX = x; |
679 |
firstY = y; |
680 |
} |
681 |
x = 0.0; y = 0.0; |
682 |
} |
683 |
} |
684 |
if (geometria instanceof Polygon) { |
685 |
geometria.add(proj.createPoint(firstX, firstY)); |
686 |
} |
687 |
|
688 |
lastFeature = feature; |
689 |
//features.add(feature);
|
690 |
if (addingToBlock == false) { |
691 |
features.add(feature); |
692 |
} else {
|
693 |
//System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
|
694 |
blk.add(feature); |
695 |
} |
696 |
} |
697 |
|
698 |
/* (non-Javadoc)
|
699 |
* @see org.cresques.io.DxfFile.EntityFactory#createLine(org.cresques.io.DxfGroupVector)
|
700 |
*/
|
701 |
public void createLine(DxfGroupVector grp) throws Exception { |
702 |
double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0; |
703 |
double elev = 0.0; |
704 |
DxfGroup g = null;
|
705 |
Point2D pt1 = null, pt2 = null; |
706 |
LineString lineString = new LineString();
|
707 |
Feature feature = new Feature();
|
708 |
|
709 |
feature.setProp("dxfEntity", "Line"); |
710 |
if (grp.hasCode(8)) |
711 |
feature.setProp("layer", grp.getDataAsString(8)); |
712 |
if (grp.hasCode(39)) { |
713 |
Double doub = new Double(grp.getDataAsDouble(39)); |
714 |
String string = doub.toString();
|
715 |
feature.setProp("thickness", string);
|
716 |
} else {
|
717 |
Double doub = new Double(0.0); |
718 |
feature.setProp("thickness", doub.toString());
|
719 |
} |
720 |
if (grp.hasCode(62)) { |
721 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
722 |
String string = integer.toString();
|
723 |
feature.setProp("color", string);
|
724 |
} else {
|
725 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
726 |
int clr = layer.colorNumber;
|
727 |
Integer integer = new Integer(clr); |
728 |
String string = integer.toString();
|
729 |
feature.setProp("color", string);
|
730 |
} |
731 |
// Las DxfLines no tienen el campo 1 correspondiente al texto en
|
732 |
// los elementos DxfText.
|
733 |
/*if (grp.hasCode(1)) {
|
734 |
feature.setProp("text", grp.getDataAsString(1));
|
735 |
} else {
|
736 |
feature.setProp("text", "No text");
|
737 |
}*/
|
738 |
x = grp.getDataAsDouble(10);
|
739 |
y = grp.getDataAsDouble(20);
|
740 |
if (grp.hasCode(30)) { |
741 |
z1 = grp.getDataAsDouble(30);
|
742 |
elev = z1; |
743 |
Double doub = new Double(elev); |
744 |
String string = doub.toString();
|
745 |
feature.setProp("elevation", string);
|
746 |
} |
747 |
pt1 = proj.createPoint(x, y); |
748 |
x = grp.getDataAsDouble(11);
|
749 |
y = grp.getDataAsDouble(21);
|
750 |
if (grp.hasCode(31)) { |
751 |
z2 = grp.getDataAsDouble(31);
|
752 |
} |
753 |
pt2 = proj.createPoint(x, y); |
754 |
if (grp.hasCode(210)) |
755 |
xtruX = grp.getDataAsDouble(210);
|
756 |
if (grp.hasCode(220)) |
757 |
xtruY = grp.getDataAsDouble(220);
|
758 |
if (grp.hasCode(230)) |
759 |
xtruZ = grp.getDataAsDouble(230);
|
760 |
Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
|
761 |
Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
|
762 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
763 |
Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
|
764 |
Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
|
765 |
pt1.setLocation(point_out1); |
766 |
pt2.setLocation(point_out2); |
767 |
lineString.add(pt1); |
768 |
lineString.add(pt2); |
769 |
|
770 |
feature.setGeometry(lineString); |
771 |
//features.add(feature);
|
772 |
if (addingToBlock == false) { |
773 |
//System.out.println("createLine(): A?adimos una linea a la lista de entidades");
|
774 |
features.add(feature); |
775 |
} else {
|
776 |
//System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
|
777 |
blk.add(feature); |
778 |
} |
779 |
} |
780 |
|
781 |
/* (non-Javadoc)
|
782 |
* @see org.cresques.io.DxfFile.EntityFactory#createText(org.cresques.io.DxfGroupVector)
|
783 |
*/
|
784 |
public void createText(DxfGroupVector grp) throws Exception { |
785 |
double x = 0.0, y = 0.0, z = 0.0, h= 0.0, rot= 0.0; |
786 |
DxfGroup g = null;
|
787 |
Point2D pt1 = null, pt2 = null; |
788 |
Point2D pt = null; |
789 |
Point point = new Point(); |
790 |
|
791 |
point.isText = true;
|
792 |
|
793 |
Feature feature = new Feature();
|
794 |
|
795 |
feature.setProp("dxfEntity", "Text"); |
796 |
if (grp.hasCode(8)) |
797 |
feature.setProp("layer", grp.getDataAsString(8)); |
798 |
if (grp.hasCode(39)) { |
799 |
Double doub = new Double(grp.getDataAsDouble(39)); |
800 |
String string = doub.toString();
|
801 |
feature.setProp("thickness", string);
|
802 |
} else {
|
803 |
Double doub = new Double(0.0); |
804 |
feature.setProp("thickness", doub.toString());
|
805 |
} |
806 |
if (grp.hasCode(62)) { |
807 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
808 |
String string = integer.toString();
|
809 |
feature.setProp("color", string);
|
810 |
//entity.dxfColor = grp.getDataAsInt(62);
|
811 |
} else {
|
812 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
813 |
int clr = layer.colorNumber;
|
814 |
Integer integer = new Integer(clr); |
815 |
String string = integer.toString();
|
816 |
feature.setProp("color", string);
|
817 |
} |
818 |
if (grp.hasCode(1)) { |
819 |
String strAux1 = grp.getDataAsString(1); |
820 |
strAux1 = DxfConvTexts.ConvertText(strAux1); |
821 |
feature.setProp("text", strAux1);
|
822 |
//txt = grp.getDataAsString(1);
|
823 |
} else {
|
824 |
feature.setProp("text", "No Text Code"); |
825 |
} |
826 |
if (grp.hasCode(40)) { |
827 |
Double heightD = new Double(grp.getDataAsDouble(40)); |
828 |
String heightS = heightD.toString();
|
829 |
feature.setProp("textHeight", heightS);
|
830 |
} else {
|
831 |
feature.setProp("textHeight", "20.0"); |
832 |
} |
833 |
if (grp.hasCode(50)) { |
834 |
Double rotD = new Double(grp.getDataAsDouble(50)); |
835 |
String rotS = rotD.toString();
|
836 |
feature.setProp("textRotation", rotS);
|
837 |
} else {
|
838 |
feature.setProp("textRotation", "0.0"); |
839 |
} |
840 |
x = grp.getDataAsDouble(10);
|
841 |
y = grp.getDataAsDouble(20);
|
842 |
if (grp.hasCode(30)){ |
843 |
z = grp.getDataAsDouble(30);
|
844 |
Double doub = new Double(z); |
845 |
String string = doub.toString();
|
846 |
feature.setProp("elevation", string);
|
847 |
} |
848 |
if (grp.hasCode(210)) |
849 |
xtruX = grp.getDataAsDouble(210);
|
850 |
if (grp.hasCode(220)) |
851 |
xtruY = grp.getDataAsDouble(220);
|
852 |
if (grp.hasCode(230)) |
853 |
xtruZ = grp.getDataAsDouble(230);
|
854 |
Point3D point_in = new Point3D(x, y, z);
|
855 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
856 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
857 |
x = point_out.getX(); |
858 |
y = point_out.getY(); |
859 |
//entity.setPt1(proj.createPoint(x, y));
|
860 |
//point.add(proj.createPoint(x, y));
|
861 |
//lineText.add(proj.createPoint(x, y));
|
862 |
/*if (grp.hasCode(11)) {
|
863 |
x = grp.getDataAsDouble(11);
|
864 |
y = grp.getDataAsDouble(21);
|
865 |
//entity.setPt2(proj.createPoint(x, y));
|
866 |
lineText.add(proj.createPoint(x, y));
|
867 |
}
|
868 |
entity.h = grp.getDataAsDouble(40);
|
869 |
if (grp.hasCode(50))
|
870 |
entity.rot = grp.getDataAsDouble(50);
|
871 |
if (grp.hasCode(62))
|
872 |
entity.dxfColor = grp.getDataAsInt(62);
|
873 |
if (grp.hasCode(72))
|
874 |
entity.align = grp.getDataAsInt(72);*/
|
875 |
point.add(new Point2D.Double(x, y)); |
876 |
feature.setGeometry(point); |
877 |
//entities.add(entity);
|
878 |
//features.add(feature);
|
879 |
if (addingToBlock == false) { |
880 |
features.add(feature); |
881 |
} else {
|
882 |
//System.out.println("createText(): A?adimos un text al bloque " + iterator);
|
883 |
blk.add(feature); |
884 |
} |
885 |
} |
886 |
|
887 |
public void createPoint(DxfGroupVector grp) throws Exception { |
888 |
double x = 0.0, y = 0.0, z = 0.0; |
889 |
DxfGroup g = null;
|
890 |
Point2D pt = null; |
891 |
Point point = new Point(); |
892 |
Feature feature = new Feature();
|
893 |
|
894 |
feature.setProp("dxfEntity", "Point"); |
895 |
if (grp.hasCode(8)) |
896 |
feature.setProp("layer", grp.getDataAsString(8)); |
897 |
if (grp.hasCode(39)) { |
898 |
Double doub = new Double(grp.getDataAsDouble(39)); |
899 |
String string = doub.toString();
|
900 |
feature.setProp("thickness", string);
|
901 |
} else {
|
902 |
Double doub = new Double(0.0); |
903 |
feature.setProp("thickness", doub.toString());
|
904 |
} |
905 |
if (grp.hasCode(62)) { |
906 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
907 |
String string = integer.toString();
|
908 |
feature.setProp("color", string);
|
909 |
} else {
|
910 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
911 |
int clr = layer.colorNumber;
|
912 |
Integer integer = new Integer(clr); |
913 |
String string = integer.toString();
|
914 |
feature.setProp("color", string);
|
915 |
} |
916 |
// Los DxfPoints no tienen el campo 1 correspondiente al texto en
|
917 |
// los elementos DxfText.
|
918 |
/*if (grp.hasCode(1)) {
|
919 |
feature.setProp("text", grp.getDataAsString(1));
|
920 |
} else {
|
921 |
feature.setProp("text", "No text");
|
922 |
}*/
|
923 |
x = grp.getDataAsDouble(10);
|
924 |
y = grp.getDataAsDouble(20);
|
925 |
if (grp.hasCode(30)) { |
926 |
z = grp.getDataAsDouble(30);
|
927 |
Double doub = new Double(z); |
928 |
String string = doub.toString();
|
929 |
feature.setProp("elevation", string);
|
930 |
} |
931 |
if (grp.hasCode(210)) |
932 |
xtruX = grp.getDataAsDouble(210);
|
933 |
if (grp.hasCode(220)) |
934 |
xtruY = grp.getDataAsDouble(220);
|
935 |
if (grp.hasCode(230)) |
936 |
xtruZ = grp.getDataAsDouble(230);
|
937 |
Point3D point_in = new Point3D(x, y, z);
|
938 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
939 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
940 |
x = point_out.getX(); |
941 |
y = point_out.getY(); |
942 |
point.add(new Point2D.Double(x, y)); |
943 |
|
944 |
feature.setGeometry(point); |
945 |
//features.add(feature);
|
946 |
if (addingToBlock == false) { |
947 |
features.add(feature); |
948 |
} else {
|
949 |
//System.out.println("createPoint(): A?adimos un punto al bloque " + iterator);
|
950 |
blk.add(feature); |
951 |
} |
952 |
} |
953 |
|
954 |
public void createCircle(DxfGroupVector grp) throws Exception { |
955 |
double x = 0.0, y = 0.0, z = 0.0; |
956 |
double r = 0.0; |
957 |
DxfGroup g = null;
|
958 |
//LineString lineString = new LineString();
|
959 |
Polygon polygon = new Polygon(); |
960 |
Feature feature = new Feature();
|
961 |
|
962 |
feature.setProp("dxfEntity", "Circle"); |
963 |
if (grp.hasCode(8)) |
964 |
feature.setProp("layer", grp.getDataAsString(8)); |
965 |
if (grp.hasCode(39)) { |
966 |
Double doub = new Double(grp.getDataAsDouble(39)); |
967 |
String string = doub.toString();
|
968 |
feature.setProp("thickness", string);
|
969 |
} else {
|
970 |
Double doub = new Double(0.0); |
971 |
feature.setProp("thickness", doub.toString());
|
972 |
} |
973 |
if (grp.hasCode(62)) { |
974 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
975 |
String string = integer.toString();
|
976 |
feature.setProp("color", string);
|
977 |
} else {
|
978 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
979 |
int clr = layer.colorNumber;
|
980 |
Integer integer = new Integer(clr); |
981 |
String string = integer.toString();
|
982 |
feature.setProp("color", string);
|
983 |
} |
984 |
// Los DxfCircles no tienen el campo 1 correspondiente al texto en
|
985 |
// los elementos DxfText.
|
986 |
/*if (grp.hasCode(1)) {
|
987 |
feature.setProp("text", grp.getDataAsString(1));
|
988 |
} else {
|
989 |
feature.setProp("text", "No text");
|
990 |
}*/
|
991 |
x = grp.getDataAsDouble(10);
|
992 |
y = grp.getDataAsDouble(20);
|
993 |
if (grp.hasCode(30)) { |
994 |
z = grp.getDataAsDouble(30);
|
995 |
Double doub = new Double(z); |
996 |
String string = doub.toString();
|
997 |
feature.setProp("elevation", string);
|
998 |
} |
999 |
if (grp.hasCode(40)) r = grp.getDataAsDouble(40); |
1000 |
if (grp.hasCode(210)) |
1001 |
xtruX = grp.getDataAsDouble(210);
|
1002 |
if (grp.hasCode(220)) |
1003 |
xtruY = grp.getDataAsDouble(220);
|
1004 |
if (grp.hasCode(230)) |
1005 |
xtruZ = grp.getDataAsDouble(230);
|
1006 |
Point3D point_in = new Point3D(x, y, z);
|
1007 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
1008 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
1009 |
x = point_out.getX(); |
1010 |
y = point_out.getY(); |
1011 |
|
1012 |
Point2D center = proj.createPoint( x, y);
|
1013 |
Point2D[] pts = new Point2D[360]; |
1014 |
int angulo = 0; |
1015 |
for (angulo=0; angulo<360; angulo++) { |
1016 |
pts[angulo] = new Point2D.Double(center.getX(), center.getY()); |
1017 |
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)); |
1018 |
if (pts.length == 1) { |
1019 |
firstPt = pts[angulo]; |
1020 |
} |
1021 |
} |
1022 |
for (int i=0; i<pts.length; i++) { |
1023 |
//lineString.add(pts[i]);
|
1024 |
polygon.add(pts[i]); |
1025 |
} |
1026 |
|
1027 |
//feature.setGeometry(lineString);
|
1028 |
feature.setGeometry(polygon); |
1029 |
//features.add(feature);
|
1030 |
if (addingToBlock == false) { |
1031 |
//System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
|
1032 |
features.add(feature); |
1033 |
} else {
|
1034 |
//System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
|
1035 |
blk.add(feature); |
1036 |
} |
1037 |
} |
1038 |
|
1039 |
public void createArc(DxfGroupVector grp) throws Exception { |
1040 |
double x = 0.0, y = 0.0, z = 0.0; |
1041 |
double r = 0.0, empieza = 0.0, acaba = 0.0; |
1042 |
DxfGroup g = null;
|
1043 |
LineString lineString = new LineString();
|
1044 |
Feature feature = new Feature();
|
1045 |
|
1046 |
feature.setProp("dxfEntity", "Arc"); |
1047 |
if (grp.hasCode(8)) |
1048 |
feature.setProp("layer", grp.getDataAsString(8)); |
1049 |
if (grp.hasCode(39)) { |
1050 |
Double doub = new Double(grp.getDataAsDouble(39)); |
1051 |
String string = doub.toString();
|
1052 |
feature.setProp("thickness", string);
|
1053 |
} else {
|
1054 |
Double doub = new Double(0.0); |
1055 |
feature.setProp("thickness", doub.toString());
|
1056 |
} |
1057 |
if (grp.hasCode(62)) { |
1058 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1059 |
String string = integer.toString();
|
1060 |
feature.setProp("color", string);
|
1061 |
} else {
|
1062 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
1063 |
int clr = layer.colorNumber;
|
1064 |
Integer integer = new Integer(clr); |
1065 |
String string = integer.toString();
|
1066 |
feature.setProp("color", string);
|
1067 |
} |
1068 |
// Los DxfArcs no tienen el campo 1 correspondiente al texto en
|
1069 |
// los elementos DxfText.
|
1070 |
/*if (grp.hasCode(1)) {
|
1071 |
feature.setProp("text", grp.getDataAsString(1));
|
1072 |
} else {
|
1073 |
feature.setProp("text", "No text");
|
1074 |
}*/
|
1075 |
x = grp.getDataAsDouble(10);
|
1076 |
y = grp.getDataAsDouble(20);
|
1077 |
if (grp.hasCode(30)) { |
1078 |
z = grp.getDataAsDouble(30);
|
1079 |
Double doub = new Double(z); |
1080 |
String string = doub.toString();
|
1081 |
feature.setProp("elevation", string);
|
1082 |
} |
1083 |
if (grp.hasCode(40)) r = grp.getDataAsDouble(40); |
1084 |
if (grp.hasCode(50)) empieza = grp.getDataAsDouble(50); |
1085 |
if (grp.hasCode(51)) acaba = grp.getDataAsDouble(51); |
1086 |
if (grp.hasCode(210)) |
1087 |
xtruX = grp.getDataAsDouble(210);
|
1088 |
if (grp.hasCode(220)) |
1089 |
xtruY = grp.getDataAsDouble(220);
|
1090 |
if (grp.hasCode(230)) |
1091 |
xtruZ = grp.getDataAsDouble(230);
|
1092 |
Point3D point_in = new Point3D(x, y, z);
|
1093 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
1094 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
1095 |
x = point_out.getX(); |
1096 |
y = point_out.getY(); |
1097 |
|
1098 |
Point2D center = proj.createPoint( x, y);
|
1099 |
//System.out.println("empieza = " + empieza + ", acaba = " + acaba);
|
1100 |
int iempieza = (int)empieza; |
1101 |
int iacaba = (int)acaba; |
1102 |
//System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba);
|
1103 |
double angulo = 0; |
1104 |
Point2D[] pts = null; |
1105 |
if (empieza <= acaba) {
|
1106 |
pts = new Point2D[(iacaba-iempieza)+2]; |
1107 |
angulo = empieza; |
1108 |
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)); |
1109 |
for (int i=1; i<=(iacaba-iempieza)+1; i++) { |
1110 |
angulo = (double)(iempieza+i);
|
1111 |
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)); |
1112 |
} |
1113 |
angulo = acaba; |
1114 |
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)); |
1115 |
} else {
|
1116 |
pts = new Point2D[(360-iempieza)+iacaba+2]; |
1117 |
angulo = empieza; |
1118 |
//System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo);
|
1119 |
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)); |
1120 |
for (int i=1; i<=(360-iempieza); i++) { |
1121 |
angulo = (double)(iempieza+i);
|
1122 |
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)); |
1123 |
} |
1124 |
for (int i=(360-iempieza)+1; i<=(360-iempieza)+iacaba; i++) { |
1125 |
angulo = (double)(i-(360-iempieza)); |
1126 |
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)); |
1127 |
} |
1128 |
angulo = acaba; |
1129 |
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)); |
1130 |
} |
1131 |
for (int i=0; i<pts.length; i++) { |
1132 |
lineString.add(pts[i]); |
1133 |
} |
1134 |
|
1135 |
feature.setGeometry(lineString); |
1136 |
//features.add(feature);
|
1137 |
if (addingToBlock == false) { |
1138 |
features.add(feature); |
1139 |
} else {
|
1140 |
//System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
|
1141 |
blk.add(feature); |
1142 |
} |
1143 |
} |
1144 |
|
1145 |
public void createInsert(DxfGroupVector grp) throws Exception { |
1146 |
double x = 0.0, y = 0.0, z = 0.0; |
1147 |
DxfGroup g = null;
|
1148 |
Point2D pt = new Point2D.Double(0.0, 0.0); |
1149 |
Point2D scaleFactor = new Point2D.Double(1.0, 1.0); |
1150 |
double rotAngle = 0.0; |
1151 |
String blockName = ""; |
1152 |
|
1153 |
InsPoint insert = new InsPoint();
|
1154 |
Feature feature = new Feature();
|
1155 |
Point secondGeom = new Point(); |
1156 |
Feature secondFeat = new Feature();
|
1157 |
|
1158 |
feature.setProp("dxfEntity", "Insert"); |
1159 |
secondFeat.setProp("dxfEntity", "Insert"); |
1160 |
if (grp.hasCode(2)) { |
1161 |
blockName = grp.getDataAsString(2);
|
1162 |
//feature.setProp("blockName", blockName);
|
1163 |
insert.setBlockName(blockName); |
1164 |
} |
1165 |
if (grp.hasCode(8)) { |
1166 |
feature.setProp("layer", grp.getDataAsString(8)); |
1167 |
secondFeat.setProp("layer", grp.getDataAsString(8)); |
1168 |
} |
1169 |
|
1170 |
Double doub = new Double(0.0); |
1171 |
secondFeat.setProp("thickness", doub.toString());
|
1172 |
|
1173 |
if (grp.hasCode(62)) { |
1174 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1175 |
String string = integer.toString();
|
1176 |
feature.setProp("color", string);
|
1177 |
secondFeat.setProp("color", string);
|
1178 |
} else {
|
1179 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
1180 |
int clr = layer.colorNumber;
|
1181 |
Integer integer = new Integer(clr); |
1182 |
String string = integer.toString();
|
1183 |
feature.setProp("color", string);
|
1184 |
secondFeat.setProp("color", string);
|
1185 |
} |
1186 |
// Los DxfInserts no tienen el campo 1 correspondiente al texto en
|
1187 |
// los elementos DxfText.
|
1188 |
/*if (grp.hasCode(1)) {
|
1189 |
feature.setProp("text", grp.getDataAsString(1));
|
1190 |
secondFeat.setProp("text", grp.getDataAsString(1));
|
1191 |
} else {
|
1192 |
feature.setProp("text", "No text");
|
1193 |
secondFeat.setProp("text", "No text");
|
1194 |
}*/
|
1195 |
if (grp.hasCode(10)) x = grp.getDataAsDouble(10); |
1196 |
if (grp.hasCode(20)) y = grp.getDataAsDouble(20); |
1197 |
if (grp.hasCode(30)) { |
1198 |
z = grp.getDataAsDouble(30);
|
1199 |
Double doubz = new Double(z); |
1200 |
String string = doubz.toString();
|
1201 |
feature.setProp("elevation", string);
|
1202 |
secondFeat.setProp("elevation", string);
|
1203 |
} |
1204 |
if (grp.hasCode(41)) { |
1205 |
scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
|
1206 |
//Double scaleFactorX = new Double(scaleFactor.getX());
|
1207 |
//feature.setProp("scaleFactorX", scaleFactorX.toString());
|
1208 |
insert.setScaleFactor(scaleFactor); |
1209 |
} else {
|
1210 |
//Double scaleFactorX = new Double(scaleFactor.getX());
|
1211 |
//feature.setProp("scaleFactorX", scaleFactorX.toString());
|
1212 |
insert.setScaleFactor(scaleFactor); |
1213 |
} |
1214 |
if (grp.hasCode(42)) { |
1215 |
scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
|
1216 |
//Double scaleFactorY = new Double(scaleFactor.getY());
|
1217 |
//feature.setProp("scaleFactorY", scaleFactorY.toString());
|
1218 |
insert.setScaleFactor(scaleFactor); |
1219 |
} else {
|
1220 |
//Double scaleFactorY = new Double(scaleFactor.getY());
|
1221 |
//feature.setProp("scaleFactorY", scaleFactorY.toString());
|
1222 |
insert.setScaleFactor(scaleFactor); |
1223 |
} |
1224 |
if (grp.hasCode(43)) { |
1225 |
// TODO La coordenada z
|
1226 |
} |
1227 |
if (grp.hasCode(50)) { |
1228 |
rotAngle = grp.getDataAsDouble(50);
|
1229 |
//Double objRotAngle = new Double(rotAngle);
|
1230 |
//feature.setProp("rotAngle", objRotAngle.toString());
|
1231 |
insert.setRotAngle(rotAngle); |
1232 |
} |
1233 |
if (grp.hasCode(210)) |
1234 |
xtruX = grp.getDataAsDouble(210);
|
1235 |
if (grp.hasCode(220)) |
1236 |
xtruY = grp.getDataAsDouble(220);
|
1237 |
if (grp.hasCode(230)) |
1238 |
xtruZ = grp.getDataAsDouble(230);
|
1239 |
Point3D point_in = new Point3D(x, y, z);
|
1240 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
1241 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
1242 |
x = point_out.getX(); |
1243 |
y = point_out.getY(); |
1244 |
|
1245 |
insert.setBlkList(blkList); |
1246 |
|
1247 |
insert.encuentraBloque(blockName); |
1248 |
|
1249 |
insert.add(new Point2D.Double(x, y)); |
1250 |
secondGeom.add(new Point2D.Double(x, y)); |
1251 |
|
1252 |
feature.setGeometry(insert); |
1253 |
secondFeat.setGeometry(secondGeom); |
1254 |
|
1255 |
gestionaInsert(feature); |
1256 |
|
1257 |
if (addingToBlock == false) { |
1258 |
features.add(secondFeat); |
1259 |
} |
1260 |
//if (addingToBlock == true && feature.getProp("blockFound").equals("true")) {
|
1261 |
if (addingToBlock == true && insert.getBlockFound() == true) { |
1262 |
//System.out.println("createInsert(): A?adimos un insert al bloque " + iterator);
|
1263 |
blk.add(feature); |
1264 |
} |
1265 |
} |
1266 |
|
1267 |
/* (non-Javadoc)
|
1268 |
* @see org.cresques.io.DxfFile.EntityFactory#createSolid(org.cresques.io.DxfGroupVector)
|
1269 |
*/
|
1270 |
public void createSolid(DxfGroupVector grp) throws Exception { |
1271 |
double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0, z3 = 0.0, z4 = 0.0; |
1272 |
DxfGroup g = null;
|
1273 |
//Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
|
1274 |
Point2D[] pts = new Point2D[4]; |
1275 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1276 |
|
1277 |
//LineString lineString = new LineString();
|
1278 |
Polygon polygon = new Polygon(); |
1279 |
Feature feature = new Feature();
|
1280 |
double elev = 0; |
1281 |
|
1282 |
feature.setProp("dxfEntity", "Solid"); |
1283 |
if (grp.hasCode(8)) |
1284 |
feature.setProp("layer", grp.getDataAsString(8)); |
1285 |
x = grp.getDataAsDouble(10);
|
1286 |
y = grp.getDataAsDouble(20);
|
1287 |
if (grp.hasCode(30)) { |
1288 |
z1 = grp.getDataAsDouble(30);
|
1289 |
elev = z1; |
1290 |
Double doub = new Double(elev); |
1291 |
String string = doub.toString();
|
1292 |
feature.setProp("elevation", string);
|
1293 |
} |
1294 |
pts[0] = proj.createPoint(x, y);
|
1295 |
x = grp.getDataAsDouble(11);
|
1296 |
y = grp.getDataAsDouble(21);
|
1297 |
if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31); |
1298 |
pts[1] = proj.createPoint(x, y);
|
1299 |
x = grp.getDataAsDouble(12);
|
1300 |
y = grp.getDataAsDouble(22);
|
1301 |
if (grp.hasCode(32)) z3 = grp.getDataAsDouble(32); |
1302 |
pts[2] = proj.createPoint(x, y);
|
1303 |
x = grp.getDataAsDouble(13);
|
1304 |
y = grp.getDataAsDouble(23);
|
1305 |
if (grp.hasCode(33)) z2 = grp.getDataAsDouble(33); |
1306 |
pts[3] = proj.createPoint(x, y);
|
1307 |
if (grp.hasCode(39)) { |
1308 |
Double doub = new Double(grp.getDataAsDouble(39)); |
1309 |
String string = doub.toString();
|
1310 |
feature.setProp("thickness", string);
|
1311 |
} else {
|
1312 |
Double doub = new Double(0.0); |
1313 |
feature.setProp("thickness", doub.toString());
|
1314 |
} |
1315 |
if (grp.hasCode(62)) { |
1316 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1317 |
String string = integer.toString();
|
1318 |
feature.setProp("color", string);
|
1319 |
} else {
|
1320 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
1321 |
int clr = layer.colorNumber;
|
1322 |
Integer integer = new Integer(clr); |
1323 |
String string = integer.toString();
|
1324 |
feature.setProp("color", string);
|
1325 |
} |
1326 |
// Los DxfSolids no tienen el campo 1 correspondiente al texto en
|
1327 |
// los elementos DxfText.
|
1328 |
/*if (grp.hasCode(1)) {
|
1329 |
feature.setProp("text", grp.getDataAsString(1));
|
1330 |
} else {
|
1331 |
feature.setProp("text", "No text");
|
1332 |
}*/
|
1333 |
if (grp.hasCode(210)) |
1334 |
xtruX = grp.getDataAsDouble(210);
|
1335 |
if (grp.hasCode(220)) |
1336 |
xtruY = grp.getDataAsInt(220);
|
1337 |
if (grp.hasCode(230)) |
1338 |
xtruZ = grp.getDataAsInt(230);
|
1339 |
Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1); |
1340 |
Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2); |
1341 |
Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3); |
1342 |
Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4); |
1343 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
1344 |
Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
|
1345 |
Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
|
1346 |
Point2D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru);
|
1347 |
Point2D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru);
|
1348 |
pts[0].setLocation(point_out1);
|
1349 |
pts[1].setLocation(point_out2);
|
1350 |
pts[2].setLocation(point_out3);
|
1351 |
pts[3].setLocation(point_out4);
|
1352 |
|
1353 |
Point2D aux = pts[2]; |
1354 |
pts[2] = pts[3]; |
1355 |
pts[3] = aux;
|
1356 |
|
1357 |
for (int i=0; i<pts.length; i++) { |
1358 |
//lineString.add(pts[i]);
|
1359 |
polygon.add(pts[i]); |
1360 |
} |
1361 |
|
1362 |
// Para cerrarlos.
|
1363 |
polygon.add(pts[0]);
|
1364 |
|
1365 |
//feature.setGeometry(lineString);
|
1366 |
feature.setGeometry(polygon); |
1367 |
//features.add(feature);
|
1368 |
if (addingToBlock == false) { |
1369 |
//System.out.println("createSolid(): A?ade un solid a la lista de entidades");
|
1370 |
features.add(feature); |
1371 |
} else {
|
1372 |
//System.out.println("createSolid(): A?adimos un circulo al bloque " + iterator);
|
1373 |
blk.add(feature); |
1374 |
} |
1375 |
} |
1376 |
|
1377 |
public void createBlock(DxfGroupVector grp) throws Exception { |
1378 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1379 |
blk = new FeatureCollection(proj);
|
1380 |
|
1381 |
Point2D basePoint = new Point2D.Double(); |
1382 |
String blockName = ""; |
1383 |
//System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator);
|
1384 |
|
1385 |
addingToBlock = true;
|
1386 |
//System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques");
|
1387 |
blkList.add(iterator, blk); |
1388 |
|
1389 |
//System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator);
|
1390 |
|
1391 |
if (grp.hasCode(8)) |
1392 |
blk.setProp("layer", grp.getDataAsString(8)); |
1393 |
if (grp.hasCode(62)) { |
1394 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1395 |
String string = integer.toString();
|
1396 |
blk.setProp("color", string);
|
1397 |
} else {
|
1398 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
1399 |
int clr = layer.colorNumber;
|
1400 |
Integer integer = new Integer(clr); |
1401 |
String string = integer.toString();
|
1402 |
blk.setProp("color", string);
|
1403 |
} |
1404 |
|
1405 |
if (grp.hasCode(1)) { |
1406 |
blockName = grp.getDataAsString(1);
|
1407 |
//blk.setBlkName(blockName);
|
1408 |
blk.setProp("blockName", blockName);
|
1409 |
} |
1410 |
if (grp.hasCode(2)) { |
1411 |
blockName = grp.getDataAsString(2);
|
1412 |
//blk.setBlkName(blockName);
|
1413 |
blk.setProp("blockName", blockName);
|
1414 |
} |
1415 |
if (grp.hasCode(3)) { |
1416 |
blockName = grp.getDataAsString(3);
|
1417 |
//blk.setBlkName(blockName);
|
1418 |
blk.setProp("blockName", blockName);
|
1419 |
} |
1420 |
if (grp.hasCode(10)) { |
1421 |
//basePoint.setLocation(grp.getDataAsDouble(10), basePoint.getY());
|
1422 |
//blk.setBPoint(basePoint);
|
1423 |
Double basePointX = new Double(grp.getDataAsDouble(10)); |
1424 |
blk.setProp("basePointX", basePointX.toString());
|
1425 |
} |
1426 |
if (grp.hasCode(20)) { |
1427 |
//basePoint.setLocation(basePoint.getX(), grp.getDataAsDouble(20));
|
1428 |
//blk.setBPoint(basePoint);
|
1429 |
Double basePointY = new Double(grp.getDataAsDouble(20)); |
1430 |
blk.setProp("basePointY", basePointY.toString());
|
1431 |
} |
1432 |
if (grp.hasCode(30)) { |
1433 |
//basePoint.setLocation(basePoint.getZ(), grp.getDataAsDouble(30));
|
1434 |
//blk.setBPoint(basePoint);
|
1435 |
Double basePointZ = new Double(grp.getDataAsDouble(30)); |
1436 |
blk.setProp("basePointZ", basePointZ.toString());
|
1437 |
} |
1438 |
if (grp.hasCode(70)) { |
1439 |
//blk.flags = grp.getDataAsInt(70);
|
1440 |
Integer blockFlags = new Integer(grp.getDataAsInt(70)); |
1441 |
blk.setProp("blockFlags", blockFlags.toString());
|
1442 |
} |
1443 |
} |
1444 |
|
1445 |
public void endBlk(DxfGroupVector grp) throws Exception { |
1446 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1447 |
setAddingToBlock(false);
|
1448 |
iterator = iterator + 1;
|
1449 |
} |
1450 |
|
1451 |
public void testBlocks() { |
1452 |
System.out.println("getBlkList() = " + getBlkList()); |
1453 |
Vector blkList = getBlkList();
|
1454 |
FeatureCollection block = null;
|
1455 |
Feature feature = null;
|
1456 |
InsPoint insert = null;
|
1457 |
Point2D point1 = new Point2D.Double(); |
1458 |
Point2D point2 = new Point2D.Double(); |
1459 |
System.out.println("blkList = " + blkList); |
1460 |
System.out.println("blkList.size() = " + blkList.size()); |
1461 |
for (int i=0; i<blkList.size(); i++) { |
1462 |
System.out.println("compruebaBloques(): Bloque " + i +" de " + blkList.size()); |
1463 |
block = (FeatureCollection) blkList.get(i); |
1464 |
int aux = block.size();
|
1465 |
for (int j=0; j<aux; j++) { |
1466 |
feature = (Feature)block.get(j); |
1467 |
//if (feature.getGeometry() instanceof InsPoint && feature.getProp("isAnInsert") == "true") {
|
1468 |
if (feature.getGeometry() instanceof InsPoint) { |
1469 |
insert = (InsPoint)feature.getGeometry(); |
1470 |
String nomBlock = insert.getBlockName();
|
1471 |
System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", inserta el bloque = " + nomBlock); |
1472 |
System.out.println("compruebaBloques(): insert.get(0) = " + insert.get(0)); |
1473 |
System.out.println("compruebaBloques(): feature.getProp(rotAngle) = " + insert.getRotAngle()); |
1474 |
System.out.println("compruebaBloques(): insert.getScaleFactor() = " + insert.getScaleFactor()); |
1475 |
//if (feature.getProp("blockFound") == "false") {
|
1476 |
if (insert.getBlockFound() == false) { |
1477 |
System.out.println("compruebaBloques(): Ahora se ocupa del DxfInsert " + nomBlock); |
1478 |
boolean aux_bool = insert.encuentraBloque(nomBlock);
|
1479 |
gestionaInsert(feature); |
1480 |
block.add(feature); |
1481 |
} |
1482 |
|
1483 |
} |
1484 |
} |
1485 |
} |
1486 |
} |
1487 |
|
1488 |
public void gestionaInsert(Feature feature) { |
1489 |
Feature feature2 = null;
|
1490 |
Point point = null; |
1491 |
LineString lineString = null;
|
1492 |
Polygon polygon = null; |
1493 |
InsPoint insert = new InsPoint();
|
1494 |
insert = (InsPoint)feature.getGeometry(); |
1495 |
double bPointX = 0.0; |
1496 |
double bPointY = 0.0; |
1497 |
if (insert.getBlockFound() == true) { |
1498 |
bPointX = Double.parseDouble(insert.getBlock().getProp("basePointX")); |
1499 |
bPointY = Double.parseDouble(insert.getBlock().getProp("basePointY")); |
1500 |
} |
1501 |
double sFactorX = insert.getScaleFactor().getX();
|
1502 |
double sFactorY = insert.getScaleFactor().getY();
|
1503 |
double rAngleGra = insert.getRotAngle();
|
1504 |
double rAngleRad = rAngleGra*Math.PI/180.0; |
1505 |
InsPoint insert2 = null;
|
1506 |
|
1507 |
for (int i=0; i<insert.getBlock().size(); i++) { |
1508 |
//System.out.println("gestionaInserts: insert.getBlock().features.size() = " + insert.getBlock().size());
|
1509 |
feature2 = (Feature)insert.getBlock().get(i); |
1510 |
|
1511 |
// Para que los elementos dentro del bloque tengan la misma layer
|
1512 |
// y color que el insert al que corresponden. Esto no debe funcionar
|
1513 |
// asi. Cada elemento tiene sus propias caracteristicas aunque
|
1514 |
// este dentro de un bloque.
|
1515 |
//feature2.setProp("layer", feature.getProp("layer"));
|
1516 |
//feature2.setProp("color", feature.getProp("color"));
|
1517 |
//feature2.setProp("text", feature.getProp("text"));
|
1518 |
|
1519 |
Point2D point1 = new Point2D.Double(); |
1520 |
Point2D point11 = new Point2D.Double(); |
1521 |
Point2D pointAux = null; |
1522 |
|
1523 |
if (feature2.getGeometry() instanceof InsPoint){ |
1524 |
insert2 = (InsPoint)feature2.getGeometry(); |
1525 |
point1 = insert2.get(0);
|
1526 |
|
1527 |
pointAux = new Point2D.Double(point1.getX() - bPointX, point1.getY() - bPointY); |
1528 |
double laX = insert.get(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad)); |
1529 |
double laY = insert.get(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad)); |
1530 |
point11.setLocation(laX, laY); |
1531 |
InsPoint insert3 = new InsPoint();
|
1532 |
|
1533 |
insert3.add(point11); |
1534 |
|
1535 |
insert3.setBlkList(insert2.getBlkList()); |
1536 |
insert3.setBlock(insert2.getBlock()); |
1537 |
insert3.setBlockName(insert2.getBlockName()); |
1538 |
insert3.setRotAngle(insert2.getRotAngle()); |
1539 |
Point2D newScale = new Point2D.Double(insert2.getScaleFactor().getX() * sFactorX, insert2.getScaleFactor().getY() * sFactorY); |
1540 |
insert3.setScaleFactor(newScale); |
1541 |
|
1542 |
Feature feature3 = new Feature();
|
1543 |
feature3.setProp("layer", feature2.getProp("layer")); |
1544 |
feature3.setProp("color", feature2.getProp("color")); |
1545 |
feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
1546 |
feature3.setProp("elevation", feature2.getProp("elevation")); |
1547 |
feature3.setGeometry(insert3); |
1548 |
|
1549 |
gestionaInsert(feature3); |
1550 |
} else if (feature2.getGeometry() instanceof LineString) { |
1551 |
lineString = (LineString)feature2.getGeometry(); |
1552 |
LineString lineString2 = new LineString();
|
1553 |
Point2D[] points = new Point2D[lineString.pointNr()]; |
1554 |
Point2D[] pointss = new Point2D[lineString.pointNr()]; |
1555 |
for (int j=0; j<lineString.pointNr(); j++) { |
1556 |
points[j] = (Point2D)lineString.get(j);
|
1557 |
pointss[j] = new Point2D.Double(); |
1558 |
|
1559 |
pointAux = new Point2D.Double(points[j].getX() - bPointX, points[j].getY() - bPointY); |
1560 |
double laX = insert.get(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad)); |
1561 |
double laY = insert.get(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad)); |
1562 |
pointss[j].setLocation(laX, laY); |
1563 |
lineString2.add(pointss[j]); |
1564 |
} |
1565 |
|
1566 |
Feature feature3 = new Feature();
|
1567 |
feature3.setProp("layer", feature2.getProp("layer")); |
1568 |
feature3.setProp("color", feature2.getProp("color")); |
1569 |
feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
1570 |
feature3.setProp("elevation", feature2.getProp("elevation")); |
1571 |
feature3.setProp("thickness", feature2.getProp("thickness")); |
1572 |
feature3.setGeometry(lineString2); |
1573 |
|
1574 |
if (addingToBlock == false) { |
1575 |
features.add(feature3); |
1576 |
} |
1577 |
} else if (feature2.getGeometry() instanceof Polygon) { |
1578 |
polygon = (Polygon)feature2.getGeometry();
|
1579 |
Polygon polygon2 = new Polygon(); |
1580 |
Point2D[] points = new Point2D[polygon.pointNr()]; |
1581 |
Point2D[] pointss = new Point2D[polygon.pointNr()]; |
1582 |
for (int j=0; j<polygon.pointNr(); j++) { |
1583 |
points[j] = (Point2D)polygon.get(j);
|
1584 |
pointss[j] = new Point2D.Double(); |
1585 |
|
1586 |
points[j].setLocation(points[j].getX() - bPointX, points[j].getY() - bPointY); |
1587 |
double laX = insert.get(0).getX() + ((points[j].getX()*sFactorX)*Math.cos(rAngleRad) + (points[j].getY()*sFactorY)*(-1)*Math.sin(rAngleRad)); |
1588 |
double laY = insert.get(0).getY() + ((points[j].getX()*sFactorX)*Math.sin(rAngleRad) + (points[j].getY()*sFactorY)*Math.cos(rAngleRad)); |
1589 |
pointss[j].setLocation(laX, laY); |
1590 |
polygon2.add(pointss[j]); |
1591 |
} |
1592 |
|
1593 |
Feature feature3 = new Feature();
|
1594 |
feature3.setProp("layer", feature2.getProp("layer")); |
1595 |
feature3.setProp("color", feature2.getProp("color")); |
1596 |
feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
1597 |
feature3.setProp("elevation", feature2.getProp("elevation")); |
1598 |
feature3.setProp("thickness", feature2.getProp("thickness")); |
1599 |
feature3.setGeometry(polygon2); |
1600 |
|
1601 |
if (addingToBlock == false) { |
1602 |
features.add(feature3); |
1603 |
} |
1604 |
} else if (feature2.getGeometry() instanceof Point) { |
1605 |
point = (Point)feature2.getGeometry();
|
1606 |
point1 = point.get(0);
|
1607 |
|
1608 |
pointAux = new Point2D.Double(point1.getX() - bPointX, point1.getY() - bPointY); |
1609 |
double laX = insert.get(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad)); |
1610 |
double laY = insert.get(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad)); |
1611 |
point11.setLocation(laX, laY); |
1612 |
Point pointt = new Point(); |
1613 |
pointt.add(point11); |
1614 |
|
1615 |
Feature feature3 = new Feature();
|
1616 |
feature3.setProp("layer", feature2.getProp("layer")); |
1617 |
feature3.setProp("color", feature2.getProp("color")); |
1618 |
feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
1619 |
feature3.setProp("elevation", feature2.getProp("elevation")); |
1620 |
feature3.setProp("thickness", feature2.getProp("thickness")); |
1621 |
if (point.isText) {
|
1622 |
feature3.setProp("text", feature2.getProp("text")); |
1623 |
} |
1624 |
feature3.setGeometry(pointt); |
1625 |
|
1626 |
if (addingToBlock == false) { |
1627 |
features.add(feature3); |
1628 |
} |
1629 |
} else {
|
1630 |
System.out.println("gestionaInserts: Encontrado elemento desconocido"); |
1631 |
} |
1632 |
} |
1633 |
} |
1634 |
|
1635 |
/* (non-Javadoc)
|
1636 |
* @see org.cresques.io.DxfFile.EntityFactory#getExtent()
|
1637 |
*/
|
1638 |
public Extent getExtent() {
|
1639 |
Feature feature = new Feature();
|
1640 |
Extent extent = new Extent();
|
1641 |
Iterator iter = features.iterator();
|
1642 |
while (iter.hasNext()) {
|
1643 |
feature = (Feature)iter.next(); |
1644 |
extent.add(feature.getExtent()); |
1645 |
} |
1646 |
return extent;
|
1647 |
} |
1648 |
|
1649 |
public void setProjection(IProjection p) { |
1650 |
proj = p; |
1651 |
} |
1652 |
|
1653 |
/* (non-Javadoc)
|
1654 |
* @see org.cresques.io.DxfFile.EntityFactory#reProject(org.cresques.geo.ReProjection)
|
1655 |
*/
|
1656 |
public void reProject(ICoordTrans rp) { |
1657 |
Feature feature = new Feature();
|
1658 |
Extent extent = new Extent();
|
1659 |
Iterator iter = features.iterator();
|
1660 |
while (iter.hasNext()) {
|
1661 |
feature = (Feature)iter.next(); |
1662 |
((Projected) feature).reProject(rp); |
1663 |
extent.add(feature.getExtent()); |
1664 |
} |
1665 |
setProjection(rp.getPDest()); |
1666 |
} |
1667 |
|
1668 |
/* (non-Javadoc)
|
1669 |
* @see org.cresques.geo.Projected#getProjection()
|
1670 |
*/
|
1671 |
public IProjection getProjection() {
|
1672 |
return proj;
|
1673 |
} |
1674 |
|
1675 |
public IObjList getObjects() { return features;} |
1676 |
|
1677 |
public void draw(Graphics2D g, ViewPortData vp) { |
1678 |
Iterator iter = features.iterator();
|
1679 |
Extent extent; |
1680 |
while (iter.hasNext()) {
|
1681 |
Feature feature = new Feature();
|
1682 |
feature = (Feature)iter.next(); |
1683 |
extent = feature.getExtent(); |
1684 |
if (vp.getExtent().minX()> extent.maxX()) continue; |
1685 |
if (vp.getExtent().minY()> extent.maxY()) continue; |
1686 |
if (vp.getExtent().maxX()< extent.minX()) continue; |
1687 |
if (vp.getExtent().maxY()< extent.minY()) continue; |
1688 |
//if (!feature.layer.frozen)
|
1689 |
feature.draw(g, vp); |
1690 |
} |
1691 |
} |
1692 |
|
1693 |
public static Vector createArc(Point2D coord1, Point2D coord2, double bulge) { |
1694 |
return new DxfCalArcs(coord1, coord2, bulge).getPoints(1); |
1695 |
} |
1696 |
|
1697 |
/* (non-Javadoc)
|
1698 |
* @see org.cresques.io.DxfFile.EntityFactory#getBlkList()
|
1699 |
*/
|
1700 |
public Vector getBlkList() { |
1701 |
return blkList;
|
1702 |
} |
1703 |
|
1704 |
/* (non-Javadoc)
|
1705 |
* @see org.cresques.io.DxfFile.EntityFactory#getDxfEntityList()
|
1706 |
*/
|
1707 |
public DxfEntityList getDxfEntityList() {
|
1708 |
// TODO Auto-generated method stub
|
1709 |
return null; |
1710 |
} |
1711 |
|
1712 |
/* (non-Javadoc)
|
1713 |
* @see org.cresques.io.DxfFile.EntityFactory#getBlk()
|
1714 |
*/
|
1715 |
public DxfBlock getBlk() {
|
1716 |
// TODO Auto-generated method stub
|
1717 |
return null; |
1718 |
} |
1719 |
|
1720 |
/* (non-Javadoc)
|
1721 |
* @see org.cresques.io.DxfFile.EntityFactory#createSpline(org.cresques.io.DxfGroupVector)
|
1722 |
*/
|
1723 |
public void createSpline(DxfGroupVector v) throws Exception { |
1724 |
// TODO Auto-generated method stub
|
1725 |
|
1726 |
} |
1727 |
|
1728 |
} |