public LineSegment(netDxf.Entities.Line dxfLine) { this.Origin = (Point)dxfLine.StartPoint; this.EndPt = (Point)dxfLine.EndPoint; this.BoundingBox = new BoundingBox(this.Origin); this.BoundingBox.expandByPoint(this.EndPt); }
private void DrawDXF2() { // canvas1.Children.Clear(); /*this.Content = DXF2WPF.GetMainGrid("sample2.dxf");*/ //this.Content = myDXF.GetMainGrid("sample2.dxf",true,false); netDxf.Entities.Line ligneTmp = new netDxf.Entities.Line(); ligneTmp.StartPoint = new Vector3(0, 0, 0); ligneTmp.EndPoint = new Vector3(100, 100, 0); /*ligneTmp.Thickness=20; * ligneTmp.Lineweight = (Lineweight)15; * ligneTmp.Color = new AciColor(8);*/ myDXF.DxfDoc = new DxfDocument(); myDXF.DxfDoc.AddEntity(ligneTmp); Grid mainGrid = new Grid(); Canvas newMainCanvas = new Canvas(); DXF2WPF.GetCanvas(myDXF.DxfDoc, myDXF.mainCanvas); myDXF.mainCanvas.Background = new SolidColorBrush(Colors.Blue); mainGrid.Children.Add(myDXF.mainCanvas); this.Content = mainGrid; //this.Content = myDXF.GetMainGrid("panther.dxf"); /*CanvasCreator.GetCanvas(DxfDoc,canvas1); * DrawUtils.DrawOrigin(canvas1);*/ }
public MarkGeometryLine(netDxf.Entities.Line line) : base() { StartPoint = new MarkGeometryPoint(line.StartPoint); EndPoint = new MarkGeometryPoint(line.EndPoint); ReferencePoint = (MarkGeometryPoint)StartPoint.Clone(); Update(); }
Entity ReadLine(netDxf.Entities.Line line, double x, double y) { Line l = new Line(); l.startPoint = new CADPoint(line.StartPoint.X + x, line.StartPoint.Y + y); l.endPoint = new CADPoint(line.EndPoint.X + x, line.EndPoint.Y + y); return(l); }
public List <netDxf.Entities.EntityObject> ToDXFEntities() { List <netDxf.Entities.EntityObject> entityList = new List <netDxf.Entities.EntityObject>(); //橫線 for (int i = 0; i < this.Dim1Length; i++) { List <netDxf.Entities.SplineVertex> controlPoints = new List <netDxf.Entities.SplineVertex>(); for (int j = 0; j < this.Dim2Length; j++) { controlPoints.Add( new netDxf.Entities.SplineVertex( this.Points[i, j].X, this.Points[i, j].Y, this.Points[i, j].Z )); } netDxf.Entities.Spline spline = new netDxf.Entities.Spline(controlPoints); spline.Color = new netDxf.AciColor(this.Color); entityList.Add(spline); } //縱線 for (int j = 0; j < this.Dim2Length; j++) { List <netDxf.Entities.SplineVertex> controlPoints = new List <netDxf.Entities.SplineVertex>(); for (int i = 0; i < this.Dim1Length; i++) { controlPoints.Add( new netDxf.Entities.SplineVertex( this.Points[i, j].X, this.Points[i, j].Y, this.Points[i, j].Z )); } netDxf.Entities.Spline spline = new netDxf.Entities.Spline(controlPoints); spline.Color = new netDxf.AciColor(this.Color); entityList.Add(spline); } //法向線 for (int i = 0; i < this.Dim1Length; i++) { for (int j = 0; j < this.Dim2Length; j++) { netDxf.Entities.Line line = new netDxf.Entities.Line( new netDxf.Vector3(this.Points[i, j].ToArray()), new netDxf.Vector3((this.Points[i, j] + this.Normals[i, j] * 0.5).ToArray())); line.Color = netDxf.AciColor.Red; entityList.Add(line); } } return(entityList); }
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); } }
public void Contour(DxfDocument dxf, double[,] d, double[] x, double[] y, double[] z) { double x1 = 0.0; double x2 = 0.0; double y1 = 0.0; double y2 = 0.0; var h = new double[5]; var sh = new int[5]; var xh = new double[5]; var yh = new double[5]; int ilb = d.GetLowerBound(0); int iub = d.GetUpperBound(0); int jlb = d.GetLowerBound(1); int jub = d.GetUpperBound(1); int nc = z.Length; // The indexing of im and jm should be noted as it has to start from zero // unlike the fortran counter part int[] im = { 0, 1, 1, 0 }; int[] jm = { 0, 0, 1, 1 }; // Note that castab is arranged differently from the FORTRAN code because // Fortran and C/C++ arrays are transposed of each other, in this case // it is more tricky as castab is in 3 dimension int[,,] castab = { { { 0, 0, 8 }, { 0, 2, 5 }, { 7, 6, 9 } }, { { 0, 3, 4 }, { 1, 3, 1 }, { 4, 3, 0 } }, { { 9, 6, 7 }, { 5, 2, 0 }, { 8, 0, 0 } } }; Func <int, int, double> xsect = (p1, p2) => (h[p2] * xh[p1] - h[p1] * xh[p2]) / (h[p2] - h[p1]); Func <int, int, double> ysect = (p1, p2) => (h[p2] * yh[p1] - h[p1] * yh[p2]) / (h[p2] - h[p1]); for (int j = jub - 1; j >= jlb; j--) { int i; for (i = ilb; i <= iub - 1; i++) { double temp1 = Math.Min(d[i, j], d[i, j + 1]); double temp2 = Math.Min(d[i + 1, j], d[i + 1, j + 1]); double dmin = Math.Min(temp1, temp2); temp1 = Math.Max(d[i, j], d[i, j + 1]); temp2 = Math.Max(d[i + 1, j], d[i + 1, j + 1]); double dmax = Math.Max(temp1, temp2); if (dmax >= z[0] && dmin <= z[nc - 1]) { short k; for (k = 0; k < nc; k++) { if (z[k] >= dmin && z[k] <= dmax) { int m; for (m = 4; m >= 0; m--) { if (m > 0) { // The indexing of im and jm should be noted as it has to // start from zero h[m] = d[i + im[m - 1], j + jm[m - 1]] - z[k]; xh[m] = x[i + im[m - 1]]; yh[m] = y[j + jm[m - 1]]; } else { h[0] = 0.25 * (h[1] + h[2] + h[3] + h[4]); xh[0] = 0.5 * (x[i] + x[i + 1]); yh[0] = 0.5 * (y[j] + y[j + 1]); } if (h[m] > 0.0) { sh[m] = 1; } else if (h[m] < 0.0) { sh[m] = -1; } else { sh[m] = 0; } } // Note: at this stage the relative heights of the corners and the // centre are in the h array, and the corresponding coordinates are // in the xh and yh arrays. The centre of the box is indexed by 0 // and the 4 corners by 1 to 4 as shown below. // Each triangle is then indexed by the parameter m, and the 3 // vertices of each triangle are indexed by parameters m1,m2,and // m3. // It is assumed that the centre of the box is always vertex 2 // though this isimportant only when all 3 vertices lie exactly on // the same contour level, in which case only the side of the box // is drawn. // vertex 4 +-------------------+ vertex 3 // | \ / | // | \ m-3 / | // | \ / | // | \ / | // | m=2 X m=2 | the centre is vertex 0 // | / \ | // | / \ | // | / m=1 \ | // | / \ | // vertex 1 +-------------------+ vertex 2 // Scan each triangle in the box for (m = 1; m <= 4; m++) { int m1 = m; int m2 = 0; int m3; if (m != 4) { m3 = m + 1; } else { m3 = 1; } int caseValue = castab[sh[m1] + 1, sh[m2] + 1, sh[m3] + 1]; if (caseValue != 0) { switch (caseValue) { case 1: // Line between vertices 1 and 2 x1 = xh[m1]; y1 = yh[m1]; x2 = xh[m2]; y2 = yh[m2]; break; case 2: // Line between vertices 2 and 3 x1 = xh[m2]; y1 = yh[m2]; x2 = xh[m3]; y2 = yh[m3]; break; case 3: // Line between vertices 3 and 1 x1 = xh[m3]; y1 = yh[m3]; x2 = xh[m1]; y2 = yh[m1]; break; case 4: // Line between vertex 1 and side 2-3 x1 = xh[m1]; y1 = yh[m1]; x2 = xsect(m2, m3); y2 = ysect(m2, m3); break; case 5: // Line between vertex 2 and side 3-1 x1 = xh[m2]; y1 = yh[m2]; x2 = xsect(m3, m1); y2 = ysect(m3, m1); break; case 6: // Line between vertex 3 and side 1-2 x1 = xh[m3]; y1 = yh[m3]; x2 = xsect(m1, m2); y2 = ysect(m1, m2); break; case 7: // Line between sides 1-2 and 2-3 x1 = xsect(m1, m2); y1 = ysect(m1, m2); x2 = xsect(m2, m3); y2 = ysect(m2, m3); break; case 8: // Line between sides 2-3 and 3-1 x1 = xsect(m2, m3); y1 = ysect(m2, m3); x2 = xsect(m3, m1); y2 = ysect(m3, m1); break; case 9: // Line between sides 3-1 and 1-2 x1 = xsect(m3, m1); y1 = ysect(m3, m1); x2 = xsect(m1, m2); y2 = ysect(m1, m2); break; default: break; } Vector3 pk_1 = new Vector3(x1, y1, 0); Vector3 pk_2 = new Vector3(x2, y2, 0); netDxf.Entities.Line ln_1 = new netDxf.Entities.Line(pk_1, pk_2); string nazwa_warsty = z[k].ToString(); int index0; if (nazwa_warsty.IndexOf(",") != -1) { index0 = nazwa_warsty.IndexOf(","); nazwa_warsty = nazwa_warsty.Substring(0, index0) + "_" + nazwa_warsty.Substring(index0 + 1, nazwa_warsty.Length - index0 - 1); } netDxf.Tables.Layer warstwa = new netDxf.Tables.Layer("h-" + nazwa_warsty + "m"); dxf.Layers.Add(warstwa); ln_1.Layer = warstwa; dxf.AddEntity(ln_1); } } } } } } } }
//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; }
public List<netDxf.Entities.EntityObject> ToDXFEntities() { List<netDxf.Entities.EntityObject> entityList = new List<netDxf.Entities.EntityObject>(); //橫線 for (int i = 0; i < this.Dim1Length; i++) { List<netDxf.Entities.SplineVertex> controlPoints = new List<netDxf.Entities.SplineVertex>(); for (int j = 0; j < this.Dim2Length; j++) controlPoints.Add( new netDxf.Entities.SplineVertex( this.Points[i, j].X, this.Points[i, j].Y, this.Points[i, j].Z )); netDxf.Entities.Spline spline = new netDxf.Entities.Spline(controlPoints); spline.Color = new netDxf.AciColor(this.Color); entityList.Add(spline); } //縱線 for (int j = 0; j < this.Dim2Length; j++) { List<netDxf.Entities.SplineVertex> controlPoints = new List<netDxf.Entities.SplineVertex>(); for (int i = 0; i < this.Dim1Length; i++) controlPoints.Add( new netDxf.Entities.SplineVertex( this.Points[i, j].X, this.Points[i, j].Y, this.Points[i, j].Z )); netDxf.Entities.Spline spline = new netDxf.Entities.Spline(controlPoints); spline.Color = new netDxf.AciColor(this.Color); entityList.Add(spline); } //法向線 for (int i = 0; i < this.Dim1Length; i++) { for (int j = 0; j < this.Dim2Length; j++) { netDxf.Entities.Line line = new netDxf.Entities.Line( new netDxf.Vector3(this.Points[i, j].ToArray()), new netDxf.Vector3((this.Points[i, j] + this.Normals[i, j]*0.5).ToArray())); line.Color = netDxf.AciColor.Red; entityList.Add(line); } } return entityList; }