DxfSolid.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.fdkankan.dxf.generate.model;
  2. import com.fdkankan.dxf.generate.Vector3;
  3. import com.fdkankan.dxf.generate.model.base.DxfEntity;
  4. import com.fdkankan.dxf.generate.util.DxfLineBuilder;
  5. import com.fdkankan.dxf.generate.util.DxfUtil;
  6. import lombok.Getter;
  7. import lombok.Setter;
  8. import java.util.List;
  9. /**
  10. * 图案填充,目前仅仅支持实体颜色填充,不支持图案填充与渐变填充
  11. *
  12. * @author YTZJJ
  13. */
  14. @Getter
  15. @Setter
  16. public class DxfSolid {
  17. private DxfEntity dxfEntity;
  18. public String getDxfStr() {
  19. DxfLineBuilder builder = DxfLineBuilder.build(2, "SOLID")
  20. // 实体填充标志(实体填充 = 1;图案填充 = 0)
  21. .append(70, 1)
  22. // 关联性标志(关联 = 1;无关联 = 0)
  23. .append(71, 1)
  24. // 边界数
  25. .append(91, 1)
  26. // 边界路径类型标志0 = 默认;1 = 外部;2 = 多段线;4 = 导出;8 = 文本框;16 = 最外层
  27. .append(92, 1);
  28. // 顶点数(93=)?
  29. // 边界类型(72=) 1 = 直线;2 = 圆弧;3 = 椭圆弧;4 = 样条曲线
  30. if (dxfEntity instanceof DxfLwPolyLine) {
  31. builder.append(93, ((DxfLwPolyLine) dxfEntity).getPoints().size());
  32. int size = ((DxfLwPolyLine) dxfEntity).getPoints().size();
  33. List<Vector3> points = ((DxfLwPolyLine) dxfEntity).getPoints();
  34. for (int i = 0; i < size; i++) {
  35. builder.append(72, 1);
  36. builder.append(10, points.get(i).getX());
  37. builder.append(20, points.get(i).getY());
  38. builder.append(30, points.get(i).getZ());
  39. builder.append(11, points.get((i + 1) % size).getX());
  40. builder.append(21, points.get((i + 1) % size).getY());
  41. }
  42. } else if (dxfEntity instanceof DxfCircle) {
  43. builder.append(93, 1);
  44. builder.append(72, 2).append(10, ((DxfCircle) dxfEntity).getCenter().getX()).append(20, ((DxfCircle) dxfEntity).getCenter().getY()).append(30, ((DxfCircle) dxfEntity).getCenter().getZ())
  45. .append(40, ((DxfCircle) dxfEntity).getRadius());
  46. // 下面是圆弧的属性,50-起始角度,51-端点角度, 73-逆时针标志
  47. if (dxfEntity instanceof DxfArc) {
  48. builder.append(50, ((DxfArc) dxfEntity).getStartAngle());
  49. builder.append(51, ((DxfArc) dxfEntity).getEndAngle());
  50. } else {
  51. builder.append(50, 0.0).append(51, 360);
  52. }
  53. builder.append(73, 1);
  54. }
  55. // 源边界对象数
  56. builder.append(97, 1)
  57. // 源边界对象的参照
  58. .append(330, DxfUtil.formatMeta(dxfEntity.getMeta()))
  59. // 图案填充样式:,0 = 填充“奇数奇偶校验”区域(普通样式),1 = 仅填充最外层区域(“外部”样式),2 = 填充整个区域(“忽略”样式)
  60. .append(75, 0)
  61. // 填充图案类型:0 = 用户定义;1 = 预定义;2 = 自定义
  62. .append(76, 1)
  63. // 种子点数
  64. .append(98, 1);
  65. // 种子点位置 10-x, 20-y
  66. if (dxfEntity instanceof DxfCircle) {
  67. builder.append(10, ((DxfCircle) dxfEntity).getCenter().getX()).append(20, ((DxfCircle) dxfEntity).getCenter().getY());
  68. } else {
  69. builder.append(10, 0.);
  70. builder.append(20, 0.);
  71. }
  72. return builder.toString();
  73. }
  74. }