Revision 142 trunk/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfFeatureMaker.java
DxfFeatureMaker.java | ||
---|---|---|
25 | 25 |
public class DxfFeatureMaker implements DxfFile.EntityFactory, Projected { |
26 | 26 |
IProjection proj = null; |
27 | 27 |
//Feature lastFeature = null; |
28 |
|
|
29 | 28 |
Feature lastFeaBordes = null; |
30 | 29 |
Feature lastFeaFondos = null; |
31 | 30 |
boolean isDoubleFeatured = false; |
32 |
|
|
33 | 31 |
FeatureCollection features = null; |
34 | 32 |
double bulge = 0.0; |
35 | 33 |
double xtruX=0.0, xtruY=0.0, xtruZ=1.0; |
... | ... | |
329 | 327 |
double x = 0.0, y = 0.0; |
330 | 328 |
double elev = 0.0; |
331 | 329 |
DxfGroup g = null; |
332 |
//LineString lineString = new LineString(); |
|
333 |
//Polygon polygon = new Polygon(); |
|
334 |
Geometry geometria; |
|
335 |
Feature feature= new Feature(); |
|
330 |
LineString lineString = new LineString(); |
|
331 |
Polygon polygon = new Polygon(); |
|
332 |
//Geometry geometria; |
|
333 |
//Feature feature= new Feature(); |
|
334 |
Feature feaBordes= new Feature(); |
|
335 |
Feature feaFondos= new Feature(); |
|
336 | 336 |
int flags = 0; |
337 | 337 |
|
338 |
feature.setProp("dxfEntity", "LwPolyline"); |
|
338 |
//feature.setProp("dxfEntity", "LwPolyline"); |
|
339 |
feaBordes.setProp("dxfEntity", "LwPolyline"); |
|
340 |
feaFondos.setProp("dxfEntity", "LwPolyline"); |
|
339 | 341 |
if (grp.hasCode(8)) |
340 |
feature.setProp("layer", grp.getDataAsString(8)); |
|
342 |
//feature.setProp("layer", grp.getDataAsString(8)); |
|
343 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
|
344 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
|
341 | 345 |
if (grp.hasCode(38)) { |
342 | 346 |
elev = grp.getDataAsDouble(38); |
343 | 347 |
Double doub = new Double(elev); |
344 | 348 |
String string = doub.toString(); |
345 |
feature.setProp("elevation", string); |
|
349 |
//feature.setProp("elevation", string); |
|
350 |
feaBordes.setProp("elevation", string); |
|
351 |
feaFondos.setProp("elevation", string); |
|
346 | 352 |
} else { |
347 | 353 |
Double doub = new Double(0.0); |
348 |
feature.setProp("elevation", doub.toString()); |
|
354 |
//feature.setProp("elevation", doub.toString()); |
|
355 |
feaBordes.setProp("elevation", doub.toString()); |
|
356 |
feaFondos.setProp("elevation", doub.toString()); |
|
349 | 357 |
} |
350 | 358 |
if (grp.hasCode(39)) { |
351 | 359 |
Double doub = new Double(grp.getDataAsDouble(39)); |
352 | 360 |
String string = doub.toString(); |
353 |
feature.setProp("thickness", string); |
|
361 |
//feature.setProp("thickness", string); |
|
362 |
feaBordes.setProp("thickness", string); |
|
363 |
feaFondos.setProp("thickness", string); |
|
354 | 364 |
} else { |
355 | 365 |
Double doub = new Double(0.0); |
356 |
feature.setProp("thickness", doub.toString()); |
|
366 |
//feature.setProp("thickness", doub.toString()); |
|
367 |
feaBordes.setProp("thickness", doub.toString()); |
|
368 |
feaFondos.setProp("thickness", doub.toString()); |
|
357 | 369 |
} |
358 | 370 |
if (grp.hasCode(62)) { |
359 | 371 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
360 | 372 |
String string = integer.toString(); |
361 |
feature.setProp("color", string); |
|
373 |
//feature.setProp("color", string); |
|
374 |
feaBordes.setProp("color", string); |
|
375 |
feaFondos.setProp("color", string); |
|
362 | 376 |
} else { |
363 | 377 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8)); |
364 | 378 |
int clr = layer.colorNumber; |
365 | 379 |
Integer integer = new Integer(clr); |
366 | 380 |
String string = integer.toString(); |
367 |
feature.setProp("color", string); |
|
381 |
//feature.setProp("color", string); |
|
382 |
feaBordes.setProp("color", string); |
|
383 |
feaFondos.setProp("color", string); |
|
368 | 384 |
} |
369 |
// Las DxfLwpolylines no tienen el campo 1 correspondiente al texto en |
|
370 |
// los elementos DxfText. |
|
371 |
/*if (grp.hasCode(1)) { |
|
372 |
feature.setProp("text", grp.getDataAsString(1)); |
|
373 |
} else { |
|
374 |
feature.setProp("text", "No text"); |
|
375 |
}*/ |
|
376 | 385 |
if (grp.hasCode(70)) |
377 | 386 |
flags = grp.getDataAsInt(70); |
378 | 387 |
if ((flags & 0x01) == 0x01) { |
379 |
geometria = new Polygon(); |
|
380 |
feature.setGeometry(geometria); |
|
388 |
//geometria = new Polygon(); |
|
389 |
feaBordes.setGeometry(lineString); |
|
390 |
feaFondos.setGeometry(polygon); |
|
391 |
isDoubleFeatured = true; |
|
381 | 392 |
} else { |
382 |
geometria = new LineString(); |
|
383 |
feature.setGeometry(geometria); |
|
393 |
//geometria = new LineString(); |
|
394 |
feaBordes.setGeometry(lineString); |
|
395 |
isDoubleFeatured = false; |
|
384 | 396 |
} |
385 | 397 |
|
386 | 398 |
int j = 0; |
... | ... | |
396 | 408 |
//if (y <= 1.0) throw new Exception("Y == "+y); |
397 | 409 |
//lineString.add( proj.createPoint( x, y ) ); |
398 | 410 |
//polygon.add( proj.createPoint( x, y ) ); |
399 |
geometria.add( proj.createPoint( x, y ) ); |
|
411 |
//geometria.add( proj.createPoint( x, y ) ); |
|
412 |
lineString.add( proj.createPoint( x, y ) ); |
|
413 |
if (isDoubleFeatured) polygon.add( proj.createPoint( x, y ) ); |
|
400 | 414 |
if (j == 1) { |
401 | 415 |
firstX = x; |
402 | 416 |
firstY = y; |
... | ... | |
404 | 418 |
x = 0.0; y = 0.0; |
405 | 419 |
} |
406 | 420 |
} |
407 |
if (geometria instanceof Polygon) { |
|
408 |
geometria.add(proj.createPoint(firstX, firstY)); |
|
421 |
if (isDoubleFeatured) { |
|
422 |
//geometria.add(proj.createPoint(firstX, firstY)); |
|
423 |
lineString.add(proj.createPoint(firstX, firstY)); |
|
424 |
polygon.add(proj.createPoint(firstX, firstY)); |
|
409 | 425 |
} |
410 | 426 |
|
411 |
lastFeaBordes = feature; |
|
427 |
lastFeaBordes = feaBordes; |
|
428 |
if (isDoubleFeatured) lastFeaFondos = feaFondos; |
|
412 | 429 |
//features.add(feature); |
413 | 430 |
if (addingToBlock == false) { |
414 |
features.add(feature); |
|
431 |
features.add(feaBordes); |
|
432 |
if (isDoubleFeatured) features.add(feaFondos); |
|
415 | 433 |
} else { |
416 | 434 |
//System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator); |
417 |
blk.add(feature); |
|
435 |
blk.add(feaBordes); |
|
436 |
if (isDoubleFeatured) blk.add(feaFondos); |
|
418 | 437 |
} |
438 |
isDoubleFeatured = false; |
|
419 | 439 |
} |
420 | 440 |
|
421 |
/* (non-Javadoc) |
|
422 |
* @see org.cresques.io.DxfFile.EntityFactory#createLine(org.cresques.io.DxfGroupVector) |
|
423 |
*/ |
|
424 | 441 |
public void createLine(DxfGroupVector grp) throws Exception { |
425 | 442 |
double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0; |
426 | 443 |
double elev = 0.0; |
... | ... | |
451 | 468 |
String string = integer.toString(); |
452 | 469 |
feature.setProp("color", string); |
453 | 470 |
} |
454 |
// Las DxfLines no tienen el campo 1 correspondiente al texto en |
|
455 |
// los elementos DxfText. |
|
456 |
/*if (grp.hasCode(1)) { |
|
457 |
feature.setProp("text", grp.getDataAsString(1)); |
|
458 |
} else { |
|
459 |
feature.setProp("text", "No text"); |
|
460 |
}*/ |
|
461 | 471 |
x = grp.getDataAsDouble(10); |
462 | 472 |
y = grp.getDataAsDouble(20); |
463 | 473 |
if (grp.hasCode(30)) { |
... | ... | |
636 | 646 |
String string = integer.toString(); |
637 | 647 |
feature.setProp("color", string); |
638 | 648 |
} |
639 |
// Los DxfPoints no tienen el campo 1 correspondiente al texto en |
|
640 |
// los elementos DxfText. |
|
641 |
/*if (grp.hasCode(1)) { |
|
642 |
feature.setProp("text", grp.getDataAsString(1)); |
|
643 |
} else { |
|
644 |
feature.setProp("text", "No text"); |
|
645 |
}*/ |
|
646 | 649 |
x = grp.getDataAsDouble(10); |
647 | 650 |
y = grp.getDataAsDouble(20); |
648 | 651 |
if (grp.hasCode(30)) { |
... | ... | |
678 | 681 |
double x = 0.0, y = 0.0, z = 0.0; |
679 | 682 |
double r = 0.0; |
680 | 683 |
DxfGroup g = null; |
681 |
//LineString lineString = new LineString();
|
|
684 |
LineString lineString = new LineString(); |
|
682 | 685 |
Polygon polygon = new Polygon(); |
683 |
Feature feature = new Feature(); |
|
686 |
Feature feaBordes = new Feature(); |
|
687 |
Feature feaFondos = new Feature(); |
|
684 | 688 |
|
685 |
feature.setProp("dxfEntity", "Circle"); |
|
689 |
feaBordes.setProp("dxfEntity", "Circle"); |
|
690 |
feaFondos.setProp("dxfEntity", "Circle"); |
|
686 | 691 |
if (grp.hasCode(8)) |
687 |
feature.setProp("layer", grp.getDataAsString(8)); |
|
692 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
|
693 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
|
688 | 694 |
if (grp.hasCode(39)) { |
689 | 695 |
Double doub = new Double(grp.getDataAsDouble(39)); |
690 | 696 |
String string = doub.toString(); |
691 |
feature.setProp("thickness", string); |
|
697 |
feaBordes.setProp("thickness", string); |
|
698 |
feaFondos.setProp("thickness", string); |
|
692 | 699 |
} else { |
693 | 700 |
Double doub = new Double(0.0); |
694 |
feature.setProp("thickness", doub.toString()); |
|
701 |
feaBordes.setProp("thickness", doub.toString()); |
|
702 |
feaFondos.setProp("thickness", doub.toString()); |
|
695 | 703 |
} |
696 | 704 |
if (grp.hasCode(62)) { |
697 | 705 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
698 | 706 |
String string = integer.toString(); |
699 |
feature.setProp("color", string); |
|
707 |
feaBordes.setProp("color", string); |
|
708 |
feaFondos.setProp("color", string); |
|
700 | 709 |
} else { |
701 | 710 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8)); |
702 | 711 |
int clr = layer.colorNumber; |
703 | 712 |
Integer integer = new Integer(clr); |
704 | 713 |
String string = integer.toString(); |
705 |
feature.setProp("color", string); |
|
714 |
feaBordes.setProp("color", string); |
|
715 |
feaFondos.setProp("color", string); |
|
706 | 716 |
} |
707 |
// Los DxfCircles no tienen el campo 1 correspondiente al texto en |
|
708 |
// los elementos DxfText. |
|
709 |
/*if (grp.hasCode(1)) { |
|
710 |
feature.setProp("text", grp.getDataAsString(1)); |
|
711 |
} else { |
|
712 |
feature.setProp("text", "No text"); |
|
713 |
}*/ |
|
714 | 717 |
x = grp.getDataAsDouble(10); |
715 | 718 |
y = grp.getDataAsDouble(20); |
716 | 719 |
if (grp.hasCode(30)) { |
717 | 720 |
z = grp.getDataAsDouble(30); |
718 | 721 |
Double doub = new Double(z); |
719 | 722 |
String string = doub.toString(); |
720 |
feature.setProp("elevation", string); |
|
723 |
feaBordes.setProp("elevation", string); |
|
724 |
feaFondos.setProp("elevation", string); |
|
721 | 725 |
} |
722 | 726 |
if (grp.hasCode(40)) r = grp.getDataAsDouble(40); |
723 | 727 |
if (grp.hasCode(210)) |
... | ... | |
743 | 747 |
} |
744 | 748 |
} |
745 | 749 |
for (int i=0; i<pts.length; i++) { |
746 |
//lineString.add(pts[i]);
|
|
750 |
lineString.add(pts[i]); |
|
747 | 751 |
polygon.add(pts[i]); |
748 | 752 |
} |
749 | 753 |
|
750 |
//feature.setGeometry(lineString);
|
|
751 |
feature.setGeometry(polygon);
|
|
754 |
feaBordes.setGeometry(lineString);
|
|
755 |
feaFondos.setGeometry(polygon);
|
|
752 | 756 |
//features.add(feature); |
753 | 757 |
if (addingToBlock == false) { |
754 | 758 |
//System.out.println("createCircle(): A?ade un circulo a la lista de entidades"); |
755 |
features.add(feature); |
|
759 |
features.add(feaBordes); |
|
760 |
features.add(feaFondos); |
|
756 | 761 |
} else { |
757 | 762 |
//System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator); |
758 |
blk.add(feature); |
|
763 |
blk.add(feaBordes); |
|
764 |
blk.add(feaFondos); |
|
759 | 765 |
} |
760 | 766 |
} |
761 | 767 |
|
... | ... | |
788 | 794 |
String string = integer.toString(); |
789 | 795 |
feature.setProp("color", string); |
790 | 796 |
} |
791 |
// Los DxfArcs no tienen el campo 1 correspondiente al texto en |
|
792 |
// los elementos DxfText. |
|
793 |
/*if (grp.hasCode(1)) { |
|
794 |
feature.setProp("text", grp.getDataAsString(1)); |
|
795 |
} else { |
|
796 |
feature.setProp("text", "No text"); |
|
797 |
}*/ |
|
798 | 797 |
x = grp.getDataAsDouble(10); |
799 | 798 |
y = grp.getDataAsDouble(20); |
800 | 799 |
if (grp.hasCode(30)) { |
... | ... | |
906 | 905 |
feature.setProp("color", string); |
907 | 906 |
secondFeat.setProp("color", string); |
908 | 907 |
} |
909 |
// Los DxfInserts no tienen el campo 1 correspondiente al texto en |
|
910 |
// los elementos DxfText. |
|
911 |
/*if (grp.hasCode(1)) { |
|
912 |
feature.setProp("text", grp.getDataAsString(1)); |
|
913 |
secondFeat.setProp("text", grp.getDataAsString(1)); |
|
914 |
} else { |
|
915 |
feature.setProp("text", "No text"); |
|
916 |
secondFeat.setProp("text", "No text"); |
|
917 |
}*/ |
|
918 | 908 |
if (grp.hasCode(10)) x = grp.getDataAsDouble(10); |
919 | 909 |
if (grp.hasCode(20)) y = grp.getDataAsDouble(20); |
920 | 910 |
if (grp.hasCode(30)) { |
... | ... | |
987 | 977 |
} |
988 | 978 |
} |
989 | 979 |
|
990 |
/* (non-Javadoc) |
|
991 |
* @see org.cresques.io.DxfFile.EntityFactory#createSolid(org.cresques.io.DxfGroupVector) |
|
992 |
*/ |
|
993 | 980 |
public void createSolid(DxfGroupVector grp) throws Exception { |
994 | 981 |
double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0, z3 = 0.0, z4 = 0.0; |
995 | 982 |
DxfGroup g = null; |
... | ... | |
997 | 984 |
Point2D[] pts = new Point2D[4]; |
998 | 985 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8)); |
999 | 986 |
|
1000 |
//LineString lineString = new LineString();
|
|
987 |
LineString lineString = new LineString(); |
|
1001 | 988 |
Polygon polygon = new Polygon(); |
1002 |
Feature feature = new Feature(); |
|
989 |
Feature feaBordes = new Feature(); |
|
990 |
Feature feaFondos = new Feature(); |
|
1003 | 991 |
double elev = 0; |
1004 | 992 |
|
1005 |
feature.setProp("dxfEntity", "Solid"); |
|
993 |
feaBordes.setProp("dxfEntity", "Solid"); |
|
994 |
feaFondos.setProp("dxfEntity", "Solid"); |
|
1006 | 995 |
if (grp.hasCode(8)) |
1007 |
feature.setProp("layer", grp.getDataAsString(8)); |
|
996 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
|
997 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
|
1008 | 998 |
x = grp.getDataAsDouble(10); |
1009 | 999 |
y = grp.getDataAsDouble(20); |
1010 | 1000 |
if (grp.hasCode(30)) { |
... | ... | |
1012 | 1002 |
elev = z1; |
1013 | 1003 |
Double doub = new Double(elev); |
1014 | 1004 |
String string = doub.toString(); |
1015 |
feature.setProp("elevation", string); |
|
1005 |
feaBordes.setProp("elevation", string); |
|
1006 |
feaFondos.setProp("elevation", string); |
|
1016 | 1007 |
} |
1017 | 1008 |
pts[0] = proj.createPoint(x, y); |
1018 | 1009 |
x = grp.getDataAsDouble(11); |
... | ... | |
1030 | 1021 |
if (grp.hasCode(39)) { |
1031 | 1022 |
Double doub = new Double(grp.getDataAsDouble(39)); |
1032 | 1023 |
String string = doub.toString(); |
1033 |
feature.setProp("thickness", string); |
|
1024 |
feaBordes.setProp("thickness", string); |
|
1025 |
feaFondos.setProp("thickness", string); |
|
1034 | 1026 |
} else { |
1035 | 1027 |
Double doub = new Double(0.0); |
1036 |
feature.setProp("thickness", doub.toString()); |
|
1028 |
feaBordes.setProp("thickness", doub.toString()); |
|
1029 |
feaFondos.setProp("thickness", doub.toString()); |
|
1037 | 1030 |
} |
1038 | 1031 |
if (grp.hasCode(62)) { |
1039 | 1032 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1040 | 1033 |
String string = integer.toString(); |
1041 |
feature.setProp("color", string); |
|
1034 |
feaBordes.setProp("color", string); |
|
1035 |
feaFondos.setProp("color", string); |
|
1042 | 1036 |
} else { |
1043 | 1037 |
DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8)); |
1044 | 1038 |
int clr = layer.colorNumber; |
1045 | 1039 |
Integer integer = new Integer(clr); |
1046 | 1040 |
String string = integer.toString(); |
1047 |
feature.setProp("color", string); |
|
1041 |
feaBordes.setProp("color", string); |
|
1042 |
feaFondos.setProp("color", string); |
|
1048 | 1043 |
} |
1049 |
// Los DxfSolids no tienen el campo 1 correspondiente al texto en |
|
1050 |
// los elementos DxfText. |
|
1051 |
/*if (grp.hasCode(1)) { |
|
1052 |
feature.setProp("text", grp.getDataAsString(1)); |
|
1053 |
} else { |
|
1054 |
feature.setProp("text", "No text"); |
|
1055 |
}*/ |
|
1056 | 1044 |
if (grp.hasCode(210)) |
1057 | 1045 |
xtruX = grp.getDataAsDouble(210); |
1058 | 1046 |
if (grp.hasCode(220)) |
... | ... | |
1078 | 1066 |
pts[3] = aux; |
1079 | 1067 |
|
1080 | 1068 |
for (int i=0; i<pts.length; i++) { |
1081 |
//lineString.add(pts[i]);
|
|
1069 |
lineString.add(pts[i]); |
|
1082 | 1070 |
polygon.add(pts[i]); |
1083 | 1071 |
} |
1084 | 1072 |
|
1085 | 1073 |
// Para cerrarlos. |
1074 |
lineString.add(pts[0]); |
|
1086 | 1075 |
polygon.add(pts[0]); |
1087 | 1076 |
|
1088 |
//feature.setGeometry(lineString);
|
|
1089 |
feature.setGeometry(polygon);
|
|
1077 |
feaBordes.setGeometry(lineString);
|
|
1078 |
feaFondos.setGeometry(polygon);
|
|
1090 | 1079 |
//features.add(feature); |
1091 | 1080 |
if (addingToBlock == false) { |
1092 | 1081 |
//System.out.println("createSolid(): A?ade un solid a la lista de entidades"); |
1093 |
features.add(feature); |
|
1082 |
features.add(feaBordes); |
|
1083 |
features.add(feaFondos); |
|
1094 | 1084 |
} else { |
1095 | 1085 |
//System.out.println("createSolid(): A?adimos un circulo al bloque " + iterator); |
1096 |
blk.add(feature); |
|
1086 |
blk.add(feaBordes); |
|
1087 |
blk.add(feaFondos); |
|
1097 | 1088 |
} |
1098 | 1089 |
} |
1099 | 1090 |
|
Also available in: Unified diff