public MarkGeometryCircle(netDxf.Entities.Circle circle) : base() { Radius = circle.Radius; CentrePoint = new MarkGeometryPoint(circle.Center); Update(); }
Entity ReadCircle(netDxf.Entities.Circle circle, double x, double y) { Circle c = new Circle(); c.center = new CADPoint(circle.Center.X + x, circle.Center.Y + y); c.radius = circle.Radius; return(c); }
public void rysuj_troj(DxfDocument dxf, Iglica[] iglice) { int punkty_x, punkty_y; punkty_x = Convert.ToInt16(tb_dlugosc.Text) * Convert.ToInt16(1 / 0.01); punkty_y = Convert.ToInt16(tb_szerokosc.Text) * Convert.ToInt16(1 / 0.01); double[] x = new double[punkty_x + 1]; double[] y = new double[punkty_y + 1]; double[,] siatka = new double[punkty_x + 1, punkty_y + 1]; if (Vertices.Count > 2) { //Do triangulation List <Triangulator.Geometry.Triangle> tris = Triangulator.Delauney.Triangulate(Vertices); // Draw the created triangles punkty_x = tris.Count(); foreach (Triangulator.Geometry.Triangle t in tris) { Vector3 pk_1 = new Vector3(); Vector3 pk_2 = new Vector3(); Vector3 pk_3 = new Vector3(); double epsilon = 0.01; // g.DrawLine(myPen, (float)Vertices[t.p1].X, (float)Vertices[t.p1].Y, (float)Vertices[t.p2].X, (float)Vertices[t.p2].Y); // g.DrawLine(myPen, (float)Vertices[t.p2].X, (float)Vertices[t.p2].Y, (float)Vertices[t.p3].X, (float)Vertices[t.p3].Y); // g.DrawLine(myPen, (float)Vertices[t.p1].X, (float)Vertices[t.p1].Y, (float)Vertices[t.p3].X, (float)Vertices[t.p3].Y); pk_1 = new Vector3((float)Vertices[t.p1].X, (float)Vertices[t.p1].Y, 0); pk_2 = new Vector3((float)Vertices[t.p2].X, (float)Vertices[t.p2].Y, 0); pk_3 = new Vector3((float)Vertices[t.p3].X, (float)Vertices[t.p3].Y, 0); for (int i = 0; i < listBox.Items.Count; i++) { if ((Math.Abs(Vertices[t.p1].X - iglice[i].X) < epsilon) & (Math.Abs(Vertices[t.p1].Y - iglice[i].Y) < epsilon)) { pk_1 = new Vector3((float)Vertices[t.p1].X, (float)Vertices[t.p1].Y, iglice[i].wysokosc); } if ((Math.Abs(Vertices[t.p2].X - iglice[i].X) < epsilon) & (Math.Abs(Vertices[t.p2].Y - iglice[i].Y) < epsilon)) { pk_2 = new Vector3((float)Vertices[t.p2].X, (float)Vertices[t.p2].Y, iglice[i].wysokosc); } if ((Math.Abs(Vertices[t.p3].X - iglice[i].X) < epsilon) & (Math.Abs(Vertices[t.p3].Y - iglice[i].Y) < epsilon)) { pk_3 = new Vector3((float)Vertices[t.p3].X, (float)Vertices[t.p3].Y, iglice[i].wysokosc); } } dPoint pk_4 = new dPoint(); dPoint pk_5 = new dPoint(); pk_5.x = pk_1.X; pk_5.y = pk_1.Y; pk_4 = pk_4.CircleCenter(pk_1, pk_2, pk_3); Vector3 pk_6 = new Vector3(); pk_6 = GetCen(pk_1, pk_2, pk_3); Vector2 pk_7 = new Vector2(pk_6.X, pk_6.Y); netDxf.Entities.Line ln_1 = new netDxf.Entities.Line(pk_1, pk_2); netDxf.Entities.Circle circle_1 = new netDxf.Entities.Circle(pk_6, Math.Sqrt(Math.Pow(pk_1.X - pk_6.X, 2) + Math.Pow(pk_1.Y - pk_6.Y, 2) + Math.Pow(pk_1.Z - pk_6.Z, 2))); // dxf.AddEntity(circle_1); //dxf.AddEntity(ln_1); ln_1 = new netDxf.Entities.Line(pk_2, pk_3); //dxf.AddEntity(ln_1); ln_1 = new netDxf.Entities.Line(pk_1, pk_3); //dxf.AddEntity(ln_1); wylicz_punkty_2(dxf, pk_1, pk_2, pk_3, pk_6, ref siatka, ref x, ref y); } Contour(dxf, siatka, x, y, kontury); } }
//Method to parse DXF line by line when LoadDXF fails public static DxfDocument LineByLineLoader(string filename) { vector_list.Clear(); DxfDocument dxfdata = new DxfDocument(); List<string> list_of_strings = new List<string>(); //reset logic function reset_logic(); entity_count =0; double intermediate =0.0d; //used for nullable exchange int int_intermediate =0; bool in_block = false; bool in_entities =false; int LineCount =0; string coder_string =""; string a_string =""; string layer_string =""; Vector2 start_point = new Vector2(0,0); Vector2 end_point = new Vector2(0,0); try { string line = null; bool found_file_end =false; System.IO.TextReader readFile = new StreamReader(filename); while (found_file_end==false) { line = readFile.ReadLine(); if (line != null) { list_of_strings.Add(line); } else { found_file_end=true; } } readFile.Close(); readFile = null; } catch(Exception e) { error_string=e.ToString(); return dxfdata; } for(int i=0;i<list_of_strings.Count; i+=2) //read strings in pairs - first is code - second is value { LineCount = LineCount+1; coder_string = list_of_strings[i].Trim(); try { a_string = list_of_strings[i+1].Trim(); } catch { a_string=""; } //check location in structure - only read from entities section if (coder_string =="0" && a_string=="BLOCK") { in_block=true; } if(coder_string =="2" && a_string=="ENTITIES") { in_entities=true; } if(coder_string =="0" && a_string=="ENDBLK") { in_block=false; } if(coder_string =="0" && a_string=="ENDSEC") { in_entities=false; } //read in layer info if(coder_string=="8" && in_block==false && in_entities==true && (ReadingLine==true || ReadingPolyline == true ||ReadingArc==true || ReadingCircle == true)) { layer_string = a_string; FoundNewLayer=true; //could populate a layer list here if needed } //read data if(coder_string=="10") { double.TryParse(a_string, out intermediate); X1=(double?)intermediate; } if (coder_string=="11") { double.TryParse(a_string, out intermediate); X2=(double?)intermediate; } if(coder_string=="20") { double.TryParse(a_string, out intermediate); Y1=(double?)intermediate; } if(coder_string=="21") { double.TryParse(a_string, out intermediate); Y2=(double?)intermediate; } if(coder_string=="40") { double.TryParse(a_string, out intermediate); radius=(double?)intermediate; } if(coder_string=="50") { double.TryParse(a_string, out intermediate); start_angle=(double?)intermediate; } if(coder_string=="51") { double.TryParse(a_string, out intermediate); end_angle=(double?)intermediate; } if(coder_string=="70") { if(ReadingPolyline==true) { if(a_string=="1") { polyline_closed=true; } else { polyline_closed=false; } } } if(coder_string=="90") { if(ReadingPolyline==true) { int.TryParse(a_string, out int_intermediate); PointCount = (int?)int_intermediate; } } //flag start of a line if(coder_string =="0" && a_string=="LINE" && in_block==false && in_entities==true) { if(ReadingLine==false) { reset_logic(); ReadingLine = true; } else { reset_logic(); } } //add line if data complete if(ReadingLine==true && X1!=null && Y1 !=null && X2 !=null && Y2 != null) { start_point = new Vector2((double)X1,(double)Y1); end_point = new Vector2((double)X2,(double)Y2); netDxf.Entities.Line aLine = new netDxf.Entities.Line(start_point,end_point); aLine.Layer = new netDxf.Tables.Layer(layer_string); dxfdata.AddEntity(aLine); reset_logic(); entity_count++; } //flag start of a LWPOLYLINE if(coder_string =="0" && a_string=="LWPOLYLINE" && in_block==false && in_entities==true) { if(ReadingPolyline == false) { reset_logic(); ReadingPolyline = true; } else { reset_logic(); } } //add point to polyline if(ReadingPolyline==true && X1 !=null && Y1!=null) { netDxf.Entities.LwPolylineVertex aVertex = new netDxf.Entities.LwPolylineVertex(new Vector2((double)X1,(double)Y1),0.0d); points.Add(aVertex); X1 = null; Y1 = null; } //add polyline if have enough points if(ReadingPolyline==true && points.Count==PointCount && PointCount !=null) { netDxf.Entities.LwPolyline aPolyline = new netDxf.Entities.LwPolyline(points,polyline_closed); aPolyline.Layer= new netDxf.Tables.Layer(layer_string); dxfdata.AddEntity(aPolyline); reset_logic(); entity_count++; } //flag star of a ARC if(coder_string =="0" && a_string=="ARC" && in_block == false) { if(ReadingArc==false) { reset_logic(); ReadingArc = true; } else { reset_logic(); } } //add arc if data complete if(ReadingArc==true && X1 != null && Y1 !=null && radius !=null && start_angle != null && end_angle !=null) { Vector2 center = new Vector2((double)X1,(double)Y1); netDxf.Entities.Arc aArc = new netDxf.Entities.Arc(center,(double)radius,(double)start_angle,(double)end_angle); aArc.Layer= new netDxf.Tables.Layer(layer_string); dxfdata.AddEntity(aArc); reset_logic(); entity_count++; } //flag star of a CIRCLE if (coder_string =="0" && a_string=="CIRCLE" && in_block ==false) { if (ReadingArc==false) { reset_logic(); ReadingCircle =true; } else { reset_logic(); } } //add circle if data complete if(ReadingCircle==true && X1 !=null && Y1 !=null && radius != null) { Vector2 center = new Vector2((double)X1,(double)Y1); netDxf.Entities.Circle aCircle = new netDxf.Entities.Circle(center,(double)radius); aCircle.Layer= new netDxf.Tables.Layer(layer_string); dxfdata.AddEntity(aCircle); reset_logic(); entity_count++; } } return dxfdata; }