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