readDXF
1 private string[] ReadPair() 2 { 3 string code = sr.ReadLine().Trim(); 4 string codedata = sr.ReadLine().Trim(); 5 count += 2; 6 string[] result = new string[2] { code, codedata }; 7 return result; 8 } 9 10 private void Read() 11 { 12 while (sr.Peek() != -1) 13 { 14 str = ReadPair(); 15 if (str[1] == "SECTION") 16 { 17 str = ReadPair(); 18 switch (str[1]) 19 { 20 case "HEADER": ReadHeader(); 21 break; 22 case "TABLES": ReadTable(); 23 break; 24 case "ENTITIES": ReadEntities(); 25 break; 26 } 27 } 28 } 29 sr.Close(); 30 fs.Close(); 31 btDraw.Enabled = true; 32 label1.Text = count.ToString(); 33 count = 0; 34 35 } 36 37 private void ReadTable() 38 { 39 while (str[1] != "ENDSEC") 40 { 41 while (str[0] != "2" || str[1] != "LAYER") 42 { 43 str = ReadPair(); 44 } 45 while (str[0] != "0" || str[1] != "LAYER") 46 { 47 str = ReadPair(); 48 } 49 while (str[0] == "0" && str[1] == "LAYER") 50 { 51 ReadLAYER(); 52 } 53 while (str[1] != "ENDSEC") 54 { 55 str = ReadPair(); 56 } 57 } 58 } 59 60 private void ReadLAYER() 61 { 62 LAYER newlayer = new LAYER(); 63 while (str[1] != "ENDTAB") 64 { 65 str = ReadPair(); 66 switch (str[0]) 67 { 68 case "2": newlayer.name = str[1]; 69 break; 70 case "62": newlayer.colornum = str[1]; 71 break; 72 case "6": newlayer.lstyle = str[1]; 73 break; 74 case "370": newlayer.lwidth = str[1]; 75 break; 76 } 77 if (str[0] == "0" && str[1] == "LAYER") 78 { 79 LayerList.Add(newlayer); 80 return; 81 } 82 } 83 LayerList.Add(newlayer); 84 } 85 86 private void ReadEntities() 87 { 88 while (str[1] != "ENDSEC") 89 { 90 switch (str[1]) 91 { 92 case "LINE": ReadLine(); 93 break; 94 case "ARC": ReadArc(); 95 break; 96 case "CIRCLE": ReadArc(); 97 break; 98 case "ELLIPSE": ReadEllipse(); 99 break; 100 case "LWPOLYLINE": ReadLwpolyline(); 101 break; 102 case "SPLINE": ReadSpline(); 103 break; 104 default: str = ReadPair(); 105 break; 106 } 107 108 } 109 } 110 111 private void ReadArc() 112 { 113 ARC newarc = new ARC(); 114 while (str[1] != "ENDSEC") 115 { 116 str = ReadPair(); 117 switch (str[0]) 118 { 119 case "8": newarc.LName = str[1]; 120 break; 121 case "10": newarc.CenterX = Double.Parse(str[1]); 122 break; 123 case "20": newarc.CenterY = Double.Parse(str[1]); 124 break; 125 case "40": newarc.Radiu = Double.Parse(str[1]); 126 break; 127 case "50": newarc.SAngle = Double.Parse(str[1]); 128 break; 129 case "51": newarc.EAngle = Double.Parse(str[1]); 130 break; 131 case "370": newarc.lwidth = str[1]; 132 break; 133 case "0": ArcList.Add(newarc); 134 return; 135 } 136 } 137 } 138 139 private void ReadLine() 140 { 141 LINE newline = new LINE(); 142 while (str[1] != "ENDSEC") 143 { 144 str = ReadPair(); 145 switch (str[0]) 146 { 147 case "8": newline.LName = str[1]; 148 break; 149 case "10": newline.StartX = Double.Parse(str[1]); 150 break; 151 case "20": newline.StartY = Double.Parse(str[1]); 152 break; 153 case "11": newline.EndX = Double.Parse(str[1]); 154 break; 155 case "21": newline.EndY = Double.Parse(str[1]); 156 break; 157 case "62": newline.colornum = str[1]; 158 break; 159 case "370": newline.lwidth = str[1]; 160 break; 161 case "0": LineList.Add(newline); 162 return; 163 } 164 } 165 } 166 167 private void ReadEllipse() 168 { 169 ELLIPSE newellipse = new ELLIPSE(); 170 while (str[1] != "ENDSEC") 171 { 172 str = ReadPair(); 173 switch (str[0]) 174 { 175 case "8": newellipse.LName = str[1]; 176 break; 177 case "10": newellipse.CenterX = Double.Parse(str[1]); 178 break; 179 case "20": newellipse.CenterY = Double.Parse(str[1]); 180 break; 181 case "11": newellipse.DeltaX = Double.Parse(str[1]); 182 break; 183 case "21": newellipse.DeltaY = Double.Parse(str[1]); 184 break; 185 case "40": newellipse.Radio = Double.Parse(str[1]); 186 break; 187 case "41": newellipse.PSAngle = Double.Parse(str[1]); 188 break; 189 case "42": newellipse.PEAngle = Double.Parse(str[1]); 190 break; 191 case "370": newellipse.lwidth = str[1]; 192 break; 193 case "0": EllipseList.Add(newellipse); 194 return; 195 } 196 } 197 } 198 199 private void ReadLwpolyline() 200 { 201 LWPOLYLINE newlw = new LWPOLYLINE(); 202 while (str[1] != "ENDSEC") 203 { 204 str = ReadPair(); 205 switch (str[0]) 206 { 207 case "8": newlw.LName = str[1]; 208 break; 209 case "370": newlw.lwidth = str[1]; 210 break; 211 case "62": newlw.colornum = str[1]; 212 break; 213 case "90": newlw.PointCount = Int32.Parse(str[1]); 214 break; 215 case "70": newlw.Flag = Int32.Parse(str[1]); 216 break; 217 case "10": newlw.pointx = new double[newlw.PointCount]; 218 newlw.pointy = new double[newlw.PointCount]; 219 //if (newlw.Flag == 1) 220 newlw.converxity = new double[newlw.PointCount]; 221 //else 222 //newlw.converxity = new double[newlw.PointCount - 1]; 223 newlw.pointx[0] = Double.Parse(str[1]); 224 str=ReadPair(); 225 newlw.pointy[0] = Double.Parse(str[1]); 226 for (int i = 1; i < newlw.PointCount; i++) 227 { 228 string temp = sr.ReadLine().Trim(); 229 if (temp == "42") 230 { 231 newlw.converxity[i - 1] = Double.Parse(sr.ReadLine().Trim()); 232 i--; 233 } 234 else if (temp == "20") 235 { 236 string r = sr.ReadLine().Trim(); 237 newlw.pointy[i] = Double.Parse(r); 238 } 239 else 240 { 241 string r = sr.ReadLine().Trim(); 242 newlw.pointx[i] = Double.Parse(r); 243 i--; 244 } 245 } 246 string s = sr.ReadLine().Trim(); 247 if (s == "42") 248 newlw.converxity[newlw.PointCount - 1] = Double.Parse(sr.ReadLine().Trim()); 249 else if (s == "0") 250 { 251 sr.ReadLine(); 252 LwopolylineList.Add(newlw); 253 return; 254 } 255 else sr.ReadLine(); 256 break; 257 case "0": LwopolylineList.Add(newlw); 258 return; 259 } 260 } 261 } 262 263 public void ReadSpline() 264 { 265 SPLINE newspline = new SPLINE(); 266 while (str[1] != "ENDSEC") 267 { 268 str = ReadPair(); 269 switch (str[0]) 270 { 271 case "8": newspline.LName = str[1]; 272 break; 273 case "370": newspline.lwidth = str[1]; 274 break; 275 case "62": newspline.colornum = str[1]; 276 break; 277 case "70": newspline.Flag = Int32.Parse(str[1]); 278 break; 279 case "74": newspline.Count = Int32.Parse(str[1]); 280 newspline.throughpx = new double[Int32.Parse(str[1])]; 281 newspline.throughpy = new double[Int32.Parse(str[1])]; 282 break; 283 case "12": newspline.SVertorX = Double.Parse(str[1]); 284 break; 285 case "22": newspline.SVertorY = Double.Parse(str[1]); 286 break; 287 case "13": newspline.EVertorX = Double.Parse(str[1]); 288 break; 289 case "23": newspline.EVertorY = Double.Parse(str[1]); 290 break; 291 case "11": newspline.throughpx[0] = Double.Parse(str[1]); 292 str = ReadPair(); 293 newspline.throughpy[0] = Double.Parse(str[1]); 294 str = ReadPair(); 295 for(int i=1;i<newspline.throughpx.Length;i++) 296 { 297 str=ReadPair(); 298 if(str[0]=="11") 299 { 300 newspline.throughpx[i]=Double.Parse(str[1]); 301 i--; 302 } 303 else if(str[0]=="21") 304 { 305 newspline.throughpy[i]=Double.Parse(str[1]); 306 i--; 307 } 308 } 309 if(newspline.Flag==11) 310 { 311 for(int i=0;i<3;i++) 312 { 313 str=ReadPair(); 314 } 315 } 316 break; 317 case "0": SplineList.Add(newspline); 318 return; 319 } 320 } 321 } 322 323 public void ReadHeader() 324 { 325 while (str[1] != "ENDSEC") 326 { 327 str = ReadPair(); 328 switch (str[1]) 329 { 330 case "$EXTMIN": str = ReadPair(); 331 leftx = Double.Parse(str[1]); 332 str = ReadPair(); 333 lefty = Double.Parse(str[1]); 334 break; 335 case "$EXTMAX": str = ReadPair(); 336 rightx = Double.Parse(str[1]); 337 str = ReadPair(); 338 righty = Double.Parse(str[1]); 339 break; 340 } 341 } 342 }