Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        // 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);
        }
Exemplo n.º 5
0
        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();
            }
        }
Exemplo n.º 6
0
        public static Transform GetRotation(this NFP nfp)
        {
            //Transformation matrix from translation and rotation
            Transform rotation = Transform.Rotation(Rhino.RhinoMath.ToRadians(nfp.rotation), new Point3d(nfp.Points[0].x, nfp.Points[0].y, 0));

            return(rotation);
        }
Exemplo n.º 7
0
        public static void simplifyDPStep(NFP points, int first, int last, double?sqTolerance, NFP simplified)
        {
            var maxSqDist = sqTolerance;
            var index     = -1;
            var marked    = false;

            for (var i = first + 1; i < last; i++)
            {
                var sqDist = getSqSegDist(points[i], points[first], points[last]);

                if (sqDist > maxSqDist)
                {
                    index     = i;
                    maxSqDist = sqDist;
                }
            }


            if (maxSqDist > sqTolerance || marked)
            {
                if (index - first > 1)
                {
                    simplifyDPStep(points, first, index, sqTolerance, simplified);
                }
                simplified.push(points[index]);
                if (last - index > 1)
                {
                    simplifyDPStep(points, index, last, sqTolerance, simplified);
                }
            }
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        private void button8_Click(object sender, EventArgs e)
        {
            List <PolygonHelper> phhs = new List <PolygonHelper>();

            //if (!checkBox1.Checked)
            {
                if (dataModel.SelectedItems.Length < 2)
                {
                    dataModel.ParentForm.StatusMessage("there are no 2 polygon selected", StatusMessageType.Warning); return;
                }

                foreach (var item in dataModel.SelectedItems)
                {
                    phhs.Add(item as PolygonHelper);
                }
            }
            //  else
            {
                //   phhs.Add((comboBox2.SelectedItem as ComboBoxItem).Tag as PolygonHelper);
                //   phhs.Add((comboBox3.SelectedItem as ComboBoxItem).Tag as PolygonHelper);
            }

            var ar1 = phhs.ToArray();


            NFP p  = new NFP();
            NFP p2 = new NFP();


            var    jType          = (JoinType)comboBox1.SelectedIndex;
            double offset         = double.Parse(textBox2.Text.Replace(",", "."), CultureInfo.InvariantCulture);
            double miterLimit     = double.Parse(textBox3.Text.Replace(",", "."), CultureInfo.InvariantCulture);
            double curveTolerance = double.Parse(textBox4.Text.Replace(",", "."), CultureInfo.InvariantCulture);

            p.Points  = ar1[0].Polygon.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
            p2.Points = ar1[1].Polygon.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
            var           offs = ClipperHelper.intersection(p, p2, offset, jType, curveTolerance: curveTolerance, miterLimit: miterLimit);
            PolygonHelper ph   = new PolygonHelper();


            if (offs.Any())
            {
                ph.Polygon.Points = offs.First().Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
            }

            foreach (var item in offs.Skip(1))
            {
                var nfp2 = new NFP();

                nfp2.Points = item.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
                ph.Polygon.Childrens.Add(nfp2);
            }


            dataModel.AddItem(ph);
        }
Exemplo n.º 10
0
        public static Transform GetTransform(this NFP nfp)
        {
            //Transformation matrix from translation and rotation
            Transform translate = Transform.Translation(new Vector3d(nfp.x, nfp.y, 0));
            Transform rotation  = Transform.Rotation(Rhino.RhinoMath.ToRadians(nfp.rotation), new Point3d(nfp.Points[0].x, nfp.Points[0].y, 0));

            translate *= rotation;

            return(translate);
        }
Exemplo n.º 11
0
        public NFP[] GetPairOfSelectedNfps()
        {
            List <PolygonHelper> phhs = new List <PolygonHelper>();

            //if (!checkBox1.Checked)
            {
                if (SelectedItems.Length < 2)
                {
                    ParentForm.StatusMessage("there are no 2 polygon selected", StatusMessageType.Warning); return(null);
                }

                foreach (var item in SelectedItems)
                {
                    phhs.Add(item as PolygonHelper);
                }
            }
            //  else
            {
                //   phhs.Add((comboBox2.SelectedItem as ComboBoxItem).Tag as PolygonHelper);
                //  phhs.Add((comboBox3.SelectedItem as ComboBoxItem).Tag as PolygonHelper);
            }

            var ar1 = phhs.ToArray();


            NFP p  = new NFP();
            NFP p2 = new NFP();


            p.Points = ar1[0].Polygon.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
            foreach (var item in ar1[0].Polygon.Childrens)
            {
                if (p.Childrens == null)
                {
                    p.Childrens = new List <NFP>();
                }
                p.Childrens.Add(new NFP()
                {
                    Points = item.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray()
                });
            }
            p2.Points = ar1[1].Polygon.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
            foreach (var item in ar1[1].Polygon.Childrens)
            {
                if (p2.Childrens == null)
                {
                    p2.Childrens = new List <NFP>();
                }
                p2.Childrens.Add(new NFP()
                {
                    Points = item.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray()
                });
            }
            return(new[] { p, p2 });
        }
Exemplo n.º 12
0
        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();
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        // 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);
        }
Exemplo n.º 15
0
        private void button1_Click(object sender, EventArgs e)
        {
            NFP p = new NFP();

            if (!(dataModel.SelectedItem is PolygonHelper ph2))
            {
                return;
            }

            p.Points = ph2.Polygon.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
            var    jType          = (JoinType)comboBox1.SelectedIndex;
            double offset         = double.Parse(textBox2.Text.Replace(",", "."), CultureInfo.InvariantCulture);
            double miterLimit     = double.Parse(textBox3.Text.Replace(",", "."), CultureInfo.InvariantCulture);
            double curveTolerance = double.Parse(textBox4.Text.Replace(",", "."), CultureInfo.InvariantCulture);
            var    offs           = ClipperHelper.offset(p, offset, jType, curveTolerance: curveTolerance, miterLimit: miterLimit);
            //if (offs.Count() > 1) throw new NotImplementedException();
            PolygonHelper ph = new PolygonHelper();

            foreach (var item in ph2.Polygon.Childrens)
            {
                var offs2 = ClipperHelper.offset(item, -offset, jType, curveTolerance: curveTolerance, miterLimit: miterLimit);
                var nfp1  = new NFP();
                if (offs2.Any())
                {
                    //if (offs2.Count() > 1) throw new NotImplementedException();
                    foreach (var zitem in offs2)
                    {
                        nfp1.Points = zitem.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
                        ph.Polygon.Childrens.Add(nfp1);
                    }
                }
            }

            if (offs.Any())
            {
                ph.Polygon.Points = offs.First().Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
            }

            foreach (var item in offs.Skip(1))
            {
                var nfp2 = new NFP();

                nfp2.Points = item.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
                ph.Polygon.Childrens.Add(nfp2);
            }

            ph.OffsetX  = ph2.OffsetX;
            ph.OffsetY  = ph2.OffsetY;
            ph.Rotation = ph2.Rotation;
            dataModel.AddItem(ph);
        }
Exemplo n.º 16
0
        // both algorithms combined for awesome performance
        public static NFP simplify(NFP points, double?tolerance, bool highestQuality)
        {
            if (points.Length <= 2)
            {
                return(points);
            }

            var sqTolerance = (tolerance != null) ? (tolerance * tolerance) : 1;

            points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
            points = simplifyDouglasPeucker(points, sqTolerance);

            return(points);
        }
Exemplo n.º 17
0
        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));
        }
Exemplo n.º 18
0
        GraphicsPath getGraphicsPath(NFP nfp)
        {
            GraphicsPath gp = new GraphicsPath();

            gp.AddPolygon(nfp.Points.Select(z => Transform(z.x, z.y)).ToArray());
            if (nfp.children != null)
            {
                foreach (var item in nfp.children)
                {
                    gp.AddPolygon(item.Points.Select(z => Transform(z.x, z.y)).ToArray());
                }
            }
            return(gp);
        }
Exemplo n.º 19
0
        public GraphicsPath Draw(NFP nfp, Pen pen = null, Brush brush = null)
        {
            var gp = getGraphicsPath(nfp);

            if (brush != null)
            {
                gr.FillPath(brush, gp);
            }
            if (pen != null)
            {
                gr.DrawPath(pen, gp);
            }
            return(gp);
        }
Exemplo n.º 20
0
        //--------------------->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);
            }
        }
Exemplo n.º 21
0
        private void button12_Click(object sender, EventArgs e)
        {
            var res = dataModel.GetPairOfSelectedNfps();

            if (res == null)
            {
                return;
            }
            NFP offs = null;

            offs = ClipperHelper.MinkowskiSum(res[0], res[1], checkBox2.Checked, checkBox3.Checked);
            if (offs != null)
            {
                PolygonHelper ph = new PolygonHelper();
                //ph.Polygon.Points = offs.Points.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
                ph.Polygon = DeepNest.clone2(offs);

                dataModel.AddItem(ph);
            }
        }
Exemplo n.º 22
0
        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);
                }
            }
        }
Exemplo n.º 23
0
        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();
        }
Exemplo n.º 24
0
        public static Polyline ToPolyline(this NFP nfp)
        {
            Polyline polyline = new Polyline();


            foreach (SvgPoint p in nfp.Points)
            {
                polyline.Add(p.x, p.y, 0);
            }

            polyline.Add(polyline[0]);

            //Transformation
            Transform translate = Transform.Translation(new Vector3d(nfp.x, nfp.y, 0));
            Transform rotation  = Transform.Rotation(Rhino.RhinoMath.ToRadians(nfp.rotation), new Point3d(nfp.Points[0].x, nfp.Points[0].y, 0));

            translate *= rotation;

            polyline.Transform(translate);

            return(polyline);
        }
Exemplo n.º 25
0
        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();
        }
Exemplo n.º 26
0
        // Bottom-Left algorithm
        double BottomLeft(ref List <Block> blocks, string sort = "none")
        {
            int    x = 0; int y = 0;
            bool   FindBL = true;
            double height = 0;

            if (sort != "none")
            {
                blocks = SortBlocks(blocks, sort);
            }

            PackedBlocks.Clear();

            foreach (Block block in blocks)
            {
                // Make NFPs of all PackedBlocks
                NFPs.Clear();
                foreach (Block packedblock in PackedBlocks)
                {
                    NFP nfp = new NFP
                    {
                        X = packedblock.Xg - block.W,
                        Y = packedblock.Yg - packedblock.H,
                        W = packedblock.W + block.W,
                        H = packedblock.H + block.H
                    };
                    NFPs.Add(nfp);
                }


                // Scan the Container to find the Bottom-Left Point
                for (y = (int)Y0; y > 0; y--)
                {
                    for (x = (int)X0; x < (int)(X0 + ContainerWidth - block.W); x++)
                    {
                        FindBL = true;
                        foreach (NFP nfp in NFPs)
                        {
                            // Scanning point (x, y) is in any NFP, or not?
                            if (x > nfp.X && x < nfp.X + nfp.W &&
                                y > nfp.Y && y < nfp.Y + nfp.H)
                            {
                                FindBL = false;
                                x      = (int)(nfp.X + nfp.W); // Skip to the right end of this NFP
                                break;
                            }
                        }
                        // if (x,y) is not in any NFPs, the point is BL.
                        if (FindBL)
                        {
                            break;
                        }
                    }
                    if (FindBL)
                    {
                        break;
                    }
                }

                block.Xg = (double)x;
                block.Yg = (double)y;

                if (Y0 - (block.Yg - block.H) > height)
                {
                    height = Y0 - (block.Yg - block.H);
                }

                PackedBlocks.Add(block);
            }

            return(height);
        }
Exemplo n.º 27
0
        public void DeepNestIterate()
        {
            List <NFP> lsheets = new List <NFP>();
            List <NFP> lpoly   = new List <NFP>();

            for (int i = 0; i < polygons.Count; i++)
            {
                polygons[i].id = i;
            }
            for (int i = 0; i < sheets.Count; i++)
            {
                sheets[i].id = i;
            }
            foreach (var item in polygons)
            {
                NFP clone = new NFP();
                clone.id     = item.id;
                clone.source = item.source;
                clone.Points = item.Points.Select(z => new SvgPoint(z.x, z.y)
                {
                    exact = z.exact
                }).ToArray();

                lpoly.Add(clone);
            }


            foreach (var item in sheets)
            {
                RectanglePolygonSheet clone = new RectanglePolygonSheet();
                clone.id     = item.id;
                clone.source = item.source;
                clone.Points = item.Points.Select(z => new SvgPoint(z.x, z.y)
                {
                    exact = z.exact
                }).ToArray();

                lsheets.Add(clone);
            }


            var grps = lpoly.GroupBy(z => z.source).ToArray();

            if (Background.UseParallel)
            {
                Parallel.ForEach(grps, (item) => {
                    SvgNest.offsetTree(item.First(), 1.0 * SvgNest.Config.spacing, SvgNest.Config);
                    foreach (var zitem in item)
                    {
                        zitem.Points = item.First().Points.ToArray();
                    }
                });
            }
            else
            {
                foreach (var item in grps)
                {
                    SvgNest.offsetTree(item.First(), 1.0 * SvgNest.Config.spacing, SvgNest.Config);
                    foreach (var zitem in item)
                    {
                        zitem.Points = item.First().Points.ToArray();
                    }
                }
            }
            foreach (var item in lsheets)
            {
                SvgNest.offsetTree(item, -1.0 * SvgNest.Config.spacing, SvgNest.Config, true);
            }



            List <NestItem> partsLocal = new List <NestItem>();
            var             p1         = lpoly.GroupBy(z => z.source).Select(z => new NestItem()
            {
                Polygon = z.First(),
                IsSheet = false,
                Quanity = z.Count()
            });

            var p2 = lsheets.GroupBy(z => z.source).Select(z => new NestItem()
            {
                Polygon = z.First(),
                IsSheet = true,
                Quanity = z.Count()
            });


            partsLocal.AddRange(p1);
            partsLocal.AddRange(p2);
            int srcc = 0;

            foreach (var item in partsLocal)
            {
                item.Polygon.source = srcc++;
            }


            nest.launchWorkers(partsLocal.ToArray());
            var plcpr = nest.nests.First();


            if (current == null || plcpr.fitness < current.fitness)
            {
                AssignPlacement(plcpr);
            }
        }