private void button17_Click(object sender, EventArgs e) { var ww = r.Next(400) + 10; var hh = r.Next(400) + 5; QntDialog q = new QntDialog(); int src = 0; if (polygons.Any()) { src = polygons.Max(z => z.source.Value) + 1; } if (q.ShowDialog() == DialogResult.OK) { for (int i = 0; i < q.Qnt; i++) { var xx = r.Next(2000) + 100; var yy = r.Next(2000); NFP pl = new NFP(); pl.source = src; polygons.Add(pl); pl.Points = new SvgPoint[] { }; pl.x = xx; pl.y = yy; pl.AddPoint(new SvgPoint(0, 0)); pl.AddPoint(new SvgPoint(0 + ww, 0)); pl.AddPoint(new SvgPoint(0 + ww, 0 + hh)); pl.AddPoint(new SvgPoint(0, 0 + hh)); } UpdateList(); } }
// rest of the code doesn't care about point format // basic distance-based simplification public static NFP simplifyRadialDist(NFP points, double?sqTolerance) { var prevPoint = points[0]; var newPoints = new NFP(); newPoints.AddPoint(prevPoint); SvgPoint point = null; int i = 1; for (var len = points.Length; i < len; i++) { point = points[i]; if (point.marked || getSqDist(point, prevPoint) > sqTolerance) { newPoints.AddPoint(point); prevPoint = point; } } if (prevPoint != point) { newPoints.AddPoint(point); } return(newPoints); }
private void button13_Click(object sender, EventArgs e) { var cnt = GetCountFromDialog(); Random r = new Random(); for (int i = 0; i < cnt; i++) { var xx = r.Next(2000) + 100; var yy = r.Next(2000); var ww = r.Next(60) + 10; var hh = r.Next(60) + 5; NFP pl = new NFP(); int src = 0; if (polygons.Any()) { src = polygons.Max(z => z.source.Value) + 1; } polygons.Add(pl); pl.source = src; pl.x = xx; pl.y = yy; pl.Points = new SvgPoint[] { }; pl.AddPoint(new SvgPoint(0, 0)); pl.AddPoint(new SvgPoint(ww, 0)); pl.AddPoint(new SvgPoint(ww, hh)); pl.AddPoint(new SvgPoint(0, hh)); } UpdateList(); }
private void button16_Click(object sender, EventArgs e) { Random r = new Random(); for (int i = 0; i < 10; i++) { var xx = r.Next(2000) + 100; var yy = r.Next(2000); var ww = r.Next(400) + 10; var hh = r.Next(400) + 5; NFP pl = new NFP(); int src = 0; if (polygons.Any()) { src = polygons.Max(z => z.source.Value) + 1; } pl.source = src; polygons.Add(pl); pl.Points = new SvgPoint[] { }; pl.AddPoint(new SvgPoint(xx, yy)); pl.AddPoint(new SvgPoint(xx + ww, yy)); pl.AddPoint(new SvgPoint(xx + ww, yy + hh)); pl.AddPoint(new SvgPoint(xx, yy + hh)); } UpdateList(); }
private void button2_Click(object sender, EventArgs e) { Random r = new Random(); var xx = r.Next(2000) + 100; var yy = r.Next(2000); var ww = 20; var hh = 20; NFP pl = new NFP(); int src = 0; if (polygons.Any()) { src = polygons.Max(z => z.source.Value) + 1; } polygons.Add(pl); pl.source = src; pl.x = xx; pl.y = yy; pl.Points = new SvgPoint[] { }; pl.AddPoint(new SvgPoint(0, 0)); pl.AddPoint(new SvgPoint(ww, 0)); pl.AddPoint(new SvgPoint(ww, hh)); pl.AddPoint(new SvgPoint(0, hh)); UpdateList(); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // var cnt = GetCountFromDialog(); Random r = new Random(); for (int i = 0; i < 5; i++) { var xx = r.Next(2000) + 100; var yy = r.Next(2000); var ww = r.Next(60) + 10; var hh = r.Next(60) + 5; NFP pl = new NFP(); int src = 0; if (polygons.Any()) { src = polygons.Max(z => z.source.Value) + 1; } polygons.Add(pl); pl.source = src; pl.x = xx; pl.y = yy; pl.Points = new SvgPoint[] { }; pl.AddPoint(new SvgPoint(0, 0)); pl.AddPoint(new SvgPoint(ww, 0)); pl.AddPoint(new SvgPoint(ww, hh)); pl.AddPoint(new SvgPoint(0, hh)); } // UpdateList(); List <Sheet> sh = new List <Sheet>(); var srcAA = context.GetNextSheetSource(); sh.Add(NewSheet(3000, 2000)); foreach (var item in sh) { item.source = srcAA; context.Sheets.Add(item); } if (sheets.Count == 0 || polygons.Count == 0) { MessageBox.Show("There are no sheets or parts", MessageBoxButtons.OK); return(Result.Success);; } stop = false; // progressBar1.Value = 0; // tabControl1.SelectedTab = tabPage4; context.ReorderSheets(); RunDeepnest(); return(Result.Success); }
private void button8_Click(object sender, EventArgs e) { var xx = r.Next(2000) + 100; var yy = r.Next(2000); var ww = r.Next(250) + 150; var hh = r.Next(250) + 120; NFP pl = new NFP(); int src = 0; if (polygons.Any()) { src = polygons.Max(z => z.source.Value) + 1; } polygons.Add(pl); pl.source = src; pl.Points = new SvgPoint[] { }; pl.AddPoint(new SvgPoint(0, 0)); pl.AddPoint(new SvgPoint(0 + ww, 0)); pl.AddPoint(new SvgPoint(0 + ww, 0 + hh)); pl.AddPoint(new SvgPoint(0, 0 + hh)); pl.x = xx; pl.y = yy; pl.children = new List <NFP>(); int gap = 10; int szx = ww / 4; int szy = hh / 3; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { var hole = new NFP(); pl.children.Add(hole); hole.Points = new SvgPoint[] { }; int hx = (i * ww / 4) + gap * (i + 1); int hy = (j * hh / 3) + gap * (j + 1); hole.AddPoint(new SvgPoint(hx + szx, hy + szy)); hole.AddPoint(new SvgPoint(hx, hy + szy)); hole.AddPoint(new SvgPoint(hx, hy)); hole.AddPoint(new SvgPoint(hx + szx, hy)); hole.x = xx; hole.y = yy; } } UpdateList(); }
public void AddRectanglePart(int src, int ww = 50, int hh = 80) { int xx = 0; int yy = 0; NFP pl = new NFP(); polygons.Add(pl); pl.source = src; pl.Points = new SvgPoint[] { }; pl.AddPoint(new SvgPoint(xx, yy)); pl.AddPoint(new SvgPoint(xx + ww, yy)); pl.AddPoint(new SvgPoint(xx + ww, yy + hh)); pl.AddPoint(new SvgPoint(xx, yy + hh)); }
private void button14_Click(object sender, EventArgs e) { Random r = new Random(); for (int i = 0; i < 10; i++) { var xx = r.Next(2000) + 100; var yy = r.Next(2000); var rad = r.Next(60) + 10; NFP pl = new NFP(); int src = 0; if (polygons.Any()) { src = polygons.Max(z => z.source.Value) + 1; } pl.source = src; polygons.Add(pl); pl.x = xx; pl.y = yy; pl.Points = new SvgPoint[] { }; for (int ang = 0; ang < 360; ang += 15) { var xx1 = (float)(rad * Math.Cos(ang * Math.PI / 180.0f)); var yy1 = (float)(rad * Math.Sin(ang * Math.PI / 180.0f)); pl.AddPoint(new SvgPoint(xx1, yy1)); } } UpdateList(); }
private void button6_Click(object sender, EventArgs e) { var cnt = GetCountFromDialog(); Random r = new Random(); for (int i = 0; i < cnt; i++) { var xx = r.Next(2000) + 100; var yy = r.Next(2000); var ww = r.Next(250) + 150; var hh = r.Next(250) + 120; NFP pl = new NFP(); int src = 0; if (polygons.Any()) { src = polygons.Max(z => z.source.Value) + 1; } polygons.Add(pl); pl.source = src; pl.Points = new SvgPoint[] { }; pl.AddPoint(new SvgPoint(0, 0)); pl.AddPoint(new SvgPoint(0 + ww, 0)); pl.AddPoint(new SvgPoint(0 + ww, 0 + hh)); pl.AddPoint(new SvgPoint(0, 0 + hh)); pl.x = xx; pl.y = yy; var hole = new NFP(); pl.children = new List <NFP>(); pl.children.Add(hole); hole.Points = new SvgPoint[] { }; int gap = 10; hole.AddPoint(new SvgPoint(0 + gap, 0 + gap)); hole.AddPoint(new SvgPoint(0 + ww - gap, 0 + gap)); hole.AddPoint(new SvgPoint(0 + ww - gap, 0 + hh - gap)); hole.AddPoint(new SvgPoint(0 + gap, 0 + hh - gap)); hole.x = xx; hole.y = yy; } UpdateList(); }
// simplification using Ramer-Douglas-Peucker algorithm public static NFP simplifyDouglasPeucker(NFP points, double?sqTolerance) { var last = points.Length - 1; var simplified = new NFP(); simplified.AddPoint(points[0]); simplifyDPStep(points, 0, last, sqTolerance, simplified); simplified.push(points[last]); return(simplified); }
//--------------------->Second function points here public void ImportFromRawDetail(RawDetail raw, int src) { NFP po = new NFP(); po.Name = raw.Name;//take name po.Points = new SvgPoint[] { }; //if (raw.Outers.Any()) { var tt = raw.Outers.Union(raw.Holes).OrderByDescending(z => z.Len).First(); foreach (var item in tt.Points) { po.AddPoint(new SvgPoint(item.X, item.Y)); } po.source = src; polygons.Add(po); } }
public void AddPolygon(Polyline polyline, int id) { if (polyline.IsValid) { if (polyline.Count > 2) { NFP pl = new NFP(); pl.source = id; pl.Points = new SvgPoint[] { }; int last = (polyline.IsClosed) ? 1 : 0; for (int i = 0; i < polyline.Count - last; i++) { pl.AddPoint(new SvgPoint(polyline[i].X, polyline[i].Y)); } polygons.Add(pl); } } }
private void button5_Click(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { var xx = r.Next(2000) + 100; var yy = r.Next(2000); var rad = r.Next(60) + 10; int rad2 = rad - 8; NFP pl = new NFP(); int src = 0; if (polygons.Any()) { src = polygons.Max(z => z.source.Value) + 1; } pl.source = src; polygons.Add(pl); pl.Points = new SvgPoint[] { }; NFP hole = new NFP(); for (int ang = 0; ang < 360; ang += 15) { var xx1 = (float)(rad * Math.Cos(ang * Math.PI / 180.0f)); var yy1 = (float)(rad * Math.Sin(ang * Math.PI / 180.0f)); pl.AddPoint(new SvgPoint(xx1, yy1)); var xx2 = (float)(rad2 * Math.Cos(ang * Math.PI / 180.0f)); var yy2 = (float)(rad2 * Math.Sin(ang * Math.PI / 180.0f)); hole.AddPoint(new SvgPoint(xx2, yy2)); } pl.children = new List <NFP>(); pl.children.Add(hole); pl.x = xx; pl.y = yy; } UpdateList(); }