DXFDocument.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using FastReport.Export.Dxf.Sections;
  2. using FastReport.Export.Dxf.Sections.Tables;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Text;
  7. namespace FastReport.Export.Dxf
  8. {
  9. public class DxfDocument
  10. {
  11. #region Private Fields
  12. private SectionBlocks blocks;
  13. private StringBuilder docString;
  14. private SectionEntities entities;
  15. private SectionHeader header;
  16. private string name;
  17. private SectionTables tables;
  18. #endregion Private Fields
  19. #region Public Properties
  20. public SectionBlocks Blocks
  21. {
  22. get { return blocks; }
  23. set { blocks = value; }
  24. }
  25. public SectionEntities Entities
  26. {
  27. get { return entities; }
  28. set { entities = value; }
  29. }
  30. public SectionHeader Header
  31. {
  32. get { return header; }
  33. set { header = value; }
  34. }
  35. public string Name
  36. {
  37. get { return name; }
  38. set { name = value; }
  39. }
  40. public SectionTables Tables
  41. {
  42. get
  43. {
  44. if (tables == null)
  45. tables = new SectionTables();
  46. return tables;
  47. }
  48. set { tables = value; }
  49. }
  50. #endregion Public Properties
  51. #region Public Constructors
  52. public DxfDocument()
  53. {
  54. docString = new StringBuilder();
  55. header = new SectionHeader();
  56. blocks = new SectionBlocks();
  57. tables = new SectionTables();
  58. entities = new SectionEntities();
  59. TableLayer layer1 = new TableLayer();
  60. Tables.Tables.Add(layer1);
  61. }
  62. #endregion Public Constructors
  63. #region Public Methods
  64. public void Clear()
  65. {
  66. name = string.Empty;
  67. header.Clear();
  68. blocks.Clear();
  69. tables.Clear();
  70. entities.Clear();
  71. }
  72. public void DrawLine(float x1, float y1, float x2, float y2, Color strokeColor, float strokeThickness)
  73. {
  74. DrawLine(x1, y1, x2, y2, strokeColor, strokeThickness, LineStyle.Solid);
  75. }
  76. public void DrawLine(float x1, float y1, float x2, float y2, Color strokeColor, float strokeThickness, LineStyle lineStyle)
  77. {
  78. if (Entities == null)
  79. throw new Exception("Entities section hasn't found!");
  80. else
  81. {
  82. List<LineStyle> styles = Entities.AddLine(x1, y1, x2, y2, strokeColor, strokeThickness, lineStyle);
  83. foreach (LineStyle s in styles)
  84. {
  85. if (s == LineStyle.Dash)
  86. Tables.Ltype.AddDashType();
  87. else if (s == LineStyle.Dot)
  88. Tables.Ltype.AddDotType();
  89. else if (s == LineStyle.DashDot)
  90. Tables.Ltype.AddDashDotType();
  91. else if (s == LineStyle.DashDotDot)
  92. Tables.Ltype.AddDashDotDotType();
  93. }
  94. }
  95. }
  96. public void Finish()
  97. {
  98. //Header.EndSection();
  99. //Entities.EndSection();
  100. //if(Tables != null)
  101. // Tables.EndSection();
  102. }
  103. public override string ToString()
  104. {
  105. //StringBuilder DxfString = new StringBuilder();
  106. //DxfString.Append(Header.ToString()).Append("\n");
  107. //if (Tables != null)
  108. // DxfString.Append(Tables.ToString()).Append("\n");
  109. //DxfString.Append(Entities.ToString()).Append("\n");
  110. // return DxfString.ToString();
  111. docString.Append("999\nCreated by FastReport.Net\n");
  112. Header.AppendTo(docString);
  113. docString.Append("\n");
  114. if (Tables != null)
  115. {
  116. Tables.AppendTo(docString);
  117. docString.Append("\n");
  118. }
  119. Blocks.AppendTo(docString);
  120. docString.Append("\n");
  121. Entities.AppendTo(docString);
  122. docString.Append("\n");
  123. docString.Append("0\nEOF");
  124. return docString.ToString();
  125. }
  126. #endregion Public Methods
  127. #region Internal Methods
  128. internal void DrawEllipse(float x, float y, float width, float height, Color ellipseColor, float ellipseWidth, LineStyle ellipseStyle)
  129. {
  130. if (Entities == null)
  131. throw new Exception("Entities section hasn't found!");
  132. else
  133. {
  134. List<LineStyle> styles = Entities.AddEllipse(x, y, width, height, ellipseColor, ellipseWidth, ellipseStyle);
  135. foreach (LineStyle s in styles)
  136. {
  137. if (s == LineStyle.Dash)
  138. Tables.Ltype.AddDashType();
  139. else if (s == LineStyle.Dot)
  140. Tables.Ltype.AddDotType();
  141. else if (s == LineStyle.DashDot)
  142. Tables.Ltype.AddDashDotType();
  143. else if (s == LineStyle.DashDotDot)
  144. Tables.Ltype.AddDashDotDotType();
  145. }
  146. }
  147. }
  148. internal void DrawPolygon(float x, float y, PointF[] points, byte[] pointTypes, Color polyLineColor,
  149. float polyLineWidth, LineStyle polyLineStyle)
  150. {
  151. DrawPolyLine(x, y, points, pointTypes, polyLineColor, polyLineWidth, polyLineStyle, true);
  152. }
  153. internal void DrawPolyLine(float x, float y, PointF[] points, byte[] pointTypes, Color polyLineColor,
  154. float polyLineWidth, LineStyle polyLineStyle, bool isClosedPolyline)
  155. {
  156. if (Entities == null)
  157. throw new Exception("Entities section hasn't found!");
  158. else
  159. {
  160. List<LineStyle> styles = Entities.AddPolyLine(x, y, points, pointTypes, polyLineColor, polyLineWidth, polyLineStyle, isClosedPolyline);
  161. foreach (LineStyle s in styles)
  162. {
  163. if (s == LineStyle.Dash)
  164. Tables.Ltype.AddDashType();
  165. else if (s == LineStyle.Dot)
  166. Tables.Ltype.AddDotType();
  167. else if (s == LineStyle.DashDot)
  168. Tables.Ltype.AddDashDotType();
  169. else if (s == LineStyle.DashDotDot)
  170. Tables.Ltype.AddDashDotDotType();
  171. }
  172. }
  173. }
  174. internal void FillPolygon(float x, float y, PointF[] points, byte[] pointTypes, Color color)
  175. {
  176. Entities.AddHatch(x, y, points, pointTypes, color);
  177. }
  178. internal void FillRectangle(float x, float y, float width, float height, Color color)
  179. {
  180. //Entities.AddSolid(x, y, width, height, color);
  181. PointF[] points = new PointF[]
  182. {
  183. new PointF(0, 0),
  184. new PointF(width, 0),
  185. new PointF(width, height),
  186. new PointF(0, height)
  187. };
  188. FillPolygon(x, y, points, new byte[] { }, color);
  189. }
  190. #endregion Internal Methods
  191. }
  192. }