Esempio n. 1
0
        public void AddItem(NFItem Item)
        {
            int L = Items.GetLength(0) + 1;

            Array.Resize <NFItem>(ref Items, L);
            Items[L - 1] = Item;
        }
Esempio n. 2
0
        public void initList()
        {
            listView1.Items.Clear();
            for (int i = 0; i < task.Count(); i++)
            {
                NFItem item = task.GetItem(i);

                ListViewItem l_item = new ListViewItem();
                l_item.Text       = item.Name;
                l_item.ImageIndex = 0;
                listView1.Items.Add(l_item);
            }
        }
Esempio n. 3
0
 public void SetItem(int id, NFItem item) => Items[id] = item;
Esempio n. 4
0
 public void AddItem(NFItem item) => Items.Add(item);
Esempio n. 5
0
        public static NFTask GetGeometry()
        {
            Msg("[Nesting Factory] Starting collect geometry...");

            ICollection <Area> EO       = Doc.GetAreas();
            IEnumerator <Area> GeomEnum = EO.GetEnumerator();

            GeomEnum.MoveNext();

            NFTask task = new NFTask();

            for (int area_num = 0; area_num < EO.Count; area_num++)
            {
                Area area = GeomEnum.Current;
                GeomEnum.MoveNext();
                Rectangle BoundBox = area.BoundRect;
                double    bound_x  = BoundBox.Left;
                double    bound_y  = BoundBox.Top;


                NFItem item = new NFItem(area.ObjectId.ToString());

                for (int num_contour = 0; num_contour < area.ContourCount; num_contour++)
                {
                    Contour   contour = area.GetContour(num_contour);
                    NFContour cont    = new NFContour();

                    for (int num_segment = 0; num_segment < contour.SegmentCount; num_segment++)
                    {
                        ContourSegment csegment = contour.GetSegment(num_segment);

                        switch (csegment.GeometryType)
                        {
                        case ObjectGeometryType.Line:
                            LineGeometry linegeom = csegment.Geometry as LineGeometry;
                            cont.AddPoint(new NFPoint(linegeom.X1 - bound_x, bound_y - linegeom.Y1, 0));
                            cont.AddPoint(new NFPoint(linegeom.X2 - bound_x, bound_y - linegeom.Y2, 0));
                            break;

                        /*case ObjectGeometryType.Polyline:
                         *
                         *  PolylineGeometry polygeom = csegment.Geometry as PolylineGeometry;
                         *  CircleArcGeometry[] cArcs = polygeom.GetCircleArcApproximation(2);
                         *
                         *  for (int i = 0; i < cArcs.GetLength(0); i++)
                         *  {
                         *      cArcToDoubles(cArcs[i], ref cont, BoundBox);
                         *  }
                         *  break;*/
                        case ObjectGeometryType.CircleArc:

                            CircleArcGeometry cgeom = csegment.Geometry as CircleArcGeometry;
                            cArcToDoubles(cgeom, ref cont, BoundBox, csegment.IsCounterclockwise);

                            break;

                        case ObjectGeometryType.Circle:
                            CircleGeometry cirgeom = csegment.Geometry as CircleGeometry;
                            cont.AddPoint(new NFPoint(cirgeom.CenterX + cirgeom.Radius - bound_x, bound_y - cirgeom.CenterY, 1));
                            cont.AddPoint(new NFPoint(cirgeom.CenterX - cirgeom.Radius - bound_x, bound_y - cirgeom.CenterY, 1));
                            break;

                        default:
                            PolylineGeometry polygeom = csegment.Geometry as PolylineGeometry;
                            int v_count = polygeom.Count;
                            for (int i = 0; i < v_count; i++)
                            {
                                if (v_count < 50 || i % (csegment.GeometryType == ObjectGeometryType.Ellipse ? 5 : 1) == 0 || i == v_count)
                                {
                                    cont.AddPoint(new NFPoint(polygeom.GetX(i) - bound_x, bound_y - polygeom.GetY(i), 0));
                                }
                            }
                            break;
                        }
                    }
                    item.AddContour(cont);
                }
                task.AddItem(item);
            }
            Msg("[Nesting Factory] Geometry collected");
            return(task);
        }
Esempio n. 6
0
        private void listView1_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems != null && listView1.SelectedItems.Count > 0)
            {
                string areaName = listView1.SelectedItems[0].Text;
                num  = listView1.SelectedItems[0].Index;
                Item = task.GetItem(num);

                //Отрисовка превьюшки детали
                Document Doc = TFlex.Application.ActiveDocument;
                select = Doc.GetObjectByName(areaName) as Area;
                TFlex.Drawing.Rectangle bound = select.BoundRect;
                double Scale = 159 / Math.Max(bound.Width, bound.Height);

                Bitmap   img   = new Bitmap(160, 160);
                Graphics graph = Graphics.FromImage(img);
                Pen      pen   = new Pen(Brushes.White);
                graph.DrawRectangle(pen, new Rectangle(0, 0, 159, 159));
                pen       = new Pen(Brushes.Black);
                pen.Width = 1;
                for (int cc = 0; cc < select.ContourCount; cc++)
                {
                    Contour cont = select.GetContour(cc);
                    for (int sc = 0; sc < cont.SegmentCount; sc++)
                    {
                        ContourSegment segm = cont.GetSegment(sc);
                        switch (segm.GeometryType)
                        {
                        case ObjectGeometryType.Line:
                            LineGeometry line = segm.Geometry as LineGeometry;
                            graph.DrawLine(pen, (float)((line.X1 - bound.Left) * Scale), (float)((bound.Top - line.Y1) * Scale), (float)((line.X2 - bound.Left) * Scale), (float)((bound.Top - line.Y2) * Scale));
                            break;

                        case ObjectGeometryType.Circle:
                            CircleGeometry circle = segm.Geometry as CircleGeometry;
                            double         radius = (circle.Radius * Scale);
                            int            xc     = (int)((circle.CenterX - bound.Left) * Scale);
                            int            yc     = (int)((bound.Top - circle.CenterY) * Scale);

                            graph.DrawEllipse(pen, new Rectangle((int)(xc - radius), (int)(yc - radius), (int)radius * 2, (int)radius * 2));
                            break;

                        case ObjectGeometryType.CircleArc:
                            CircleArcGeometry cgeom = segm.Geometry as CircleArcGeometry;
                            int xc1 = (int)((cgeom.CenterX - bound.Left) * Scale);
                            int yc1 = (int)((bound.Top - cgeom.CenterY) * Scale);
                            radius = (cgeom.Radius * Scale);
                            double[] angles = NFGetGeom.getArcAngle(cgeom, segm.IsCounterclockwise);
                            double   ang    = angles[0] * 180 / Math.PI;
                            double   ang1   = angles[1] * 180 / Math.PI - 90;
                            graph.DrawArc(pen, (float)(xc1 - radius), (float)(yc1 - radius), (float)(radius * 2), (float)(radius * 2), (float)ang1, (float)ang);
                            break;

                        default:

                            PolylineGeometry geom = segm.Geometry as PolylineGeometry;

                            if (geom != null)
                            {
                                for (int i = 1; i < geom.Count; i++)
                                {
                                    int x1 = (int)((geom.GetX(i) - bound.Left) * Scale);
                                    int y1 = (int)((bound.Top - geom.GetY(i)) * Scale);
                                    int x2 = (int)((geom.GetX(i - 1) - bound.Left) * Scale);
                                    int y2 = (int)((bound.Top - geom.GetY(i - 1)) * Scale);
                                    graph.DrawLine(pen, (float)x1, (float)y1, (float)x2, (float)y2);
                                }
                            }
                            break;
                        }
                    }
                }

                pictureBox1.Image = img;

                //Задание параметров форме

                label10.Text = "Размер квадрата детали = " + (int)(159 / Scale);
                label9.Text  = "Количество контуров: " + select.ContourCount;

                selectComboNum(ref comboBox2, Item.Rotation);

                selectComboNum(ref comboBox1, Item.Reflection);
                selectComboNum(ref comboBox1, Item.Reflection);

                textBox4.Text = Item.Count.ToString();
            }
        }
Esempio n. 7
0
        public void SaveToItems(string filePath)       //Функция для отладки в CatUI
        {
            //string filePath = "F:/items/";
            string taskfile = "TASKNAME\tNFTest\nTIMELIMIT:\t3600000\nTASKTYPE:\tSheet\n";

            taskfile += String.Format("WIDTH:\t{0}\nLENGTH:\t{1}\n", this.ListY, this.ListX);
            taskfile += "SHEETQUANT:\t1\n";
            taskfile += String.Format("ITEM2DOMAINDIST:\t{0}\n", this.p2l);
            taskfile += String.Format("ITEM2ITEMDIST:\t{0}\n", this.p2p);



            for (int item_id = 0; item_id < this.Count(); item_id++)
            {
                NFItem Item     = Items[item_id];
                int    CC       = Item.ContourCount();
                string fileData = "ITEMNAME:\t" + Item.Name + "\n";

                int    rot     = (Item.Rotation == 0 ? this.DefaultRotation : Item.Rotation - 1);
                string rotstep = "";
                switch (rot)
                {
                case 0:
                    rotstep = "NO";
                    break;

                case 1:
                    rotstep = "PI";
                    break;

                case 2:
                    rotstep = "PI/2";
                    break;

                case 3:
                    rotstep = "FREE";
                    break;
                }
                int refl  = (Item.Reflection == 0 ? this.DefaultReflection : Item.Reflection - 1);
                int count = (Item.Count == 0 ? this.DefaultItemCount : Item.Count);

                taskfile += String.Format("ITEMFILE:\t{0}.item\n", ".\\" + item_id);
                taskfile += String.Format("ITEMQUANT:\t{0}\n", count);
                taskfile += String.Format("ROTATE:\t{0}\n", (rot > 1 ? 1 : rot));
                taskfile += String.Format("ROTSTEP:\t{0}\n", rotstep);
                taskfile += String.Format("REFLECT:\t{0}\n", refl);


                for (int contour_id = 0; contour_id < CC; contour_id++)
                {
                    NFContour contour = Item.GetContour(contour_id);
                    int       VC      = contour.VertexCount();
                    fileData += "VERTQUANT:\t" + VC + "\n";

                    for (int v_id = 0; v_id < VC; v_id++)
                    {
                        NFPoint Point = contour.GetPoint(v_id);
                        fileData += "VERTEX:\t" + Point.x + "\t" + Point.y + "\t" + Point.b + "\n";
                    }
                }
                using (StreamWriter sw = File.CreateText(filePath + item_id + ".item"))
                {
                    fileData = fileData.Replace(",", ".");
                    sw.WriteLine(fileData);
                    sw.Close();
                }

                using (StreamWriter sw = File.CreateText(filePath + "NFTest.task"))
                {
                    sw.WriteLine(taskfile);
                    sw.Close();
                }
            }
        }
Esempio n. 8
0
        public static NFTask GetGeometry()
        {
            Msg("[Nesting Factory] Starting collect geometry...");

            ICollection <Area> Areas = Doc.GetAreas();

            NFTask task = new NFTask();

            foreach (var area in Areas)
            {
                Rectangle BoundBox = area.BoundRect;
                double    boundX   = BoundBox.Left;
                double    boundY   = BoundBox.Top;


                NFItem item = new NFItem(area.ObjectId.ToString());

                for (int num_contour = 0; num_contour < area.ContourCount; num_contour++)
                {
                    Contour   contour = area.GetContour(num_contour);
                    NFContour cont    = new NFContour();

                    foreach (var csegment in contour)
                    {
                        switch (csegment.GeometryType)
                        {
                        case ObjectGeometryType.Line:
                            LineGeometry linegeom = csegment.Geometry as LineGeometry;
                            cont.AddPoint(new NFPoint(linegeom.X1 - boundX, boundY - linegeom.Y1, 0));
                            cont.AddPoint(new NFPoint(linegeom.X2 - boundX, boundY - linegeom.Y2, 0));
                            break;

                        case ObjectGeometryType.CircleArc:
                            CircleArcGeometry cgeom = csegment.Geometry as CircleArcGeometry;
                            cArcToDoubles(cgeom, ref cont, BoundBox, csegment.IsCounterclockwise);
                            break;

                        case ObjectGeometryType.Circle:
                            CircleGeometry cirgeom = csegment.Geometry as CircleGeometry;
                            cont.AddPoint(new NFPoint(cirgeom.CenterX + cirgeom.Radius - boundX, boundY - cirgeom.CenterY, 1));
                            cont.AddPoint(new NFPoint(cirgeom.CenterX - cirgeom.Radius - boundX, boundY - cirgeom.CenterY, 1));
                            break;

                        default:
                            PolylineGeometry polygeom = csegment.Geometry as PolylineGeometry;
                            int v_count = polygeom.Count;
                            for (int i = 0; i < v_count; i++)
                            {
                                if (v_count < 50 || i % (csegment.GeometryType == ObjectGeometryType.Ellipse ? 5 : 1) == 0 || i == v_count)
                                {
                                    cont.AddPoint(new NFPoint(polygeom.GetX(i) - boundX, boundY - polygeom.GetY(i), 0));
                                }
                            }
                            break;
                        }
                    }
                    item.AddContour(cont);
                }
                task.AddItem(item);
            }
            Msg("[Nesting Factory] Geometry collected");
            return(task);
        }
Esempio n. 9
0
        private void listView1_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                string areaName = listView1.SelectedItems[0].Text;
                SelectedIndex = listView1.SelectedItems[0].Index;
                SelectedItem  = task.Items[SelectedIndex];

                //Отрисовка превьюшки детали
                Document Doc = TFlex.Application.ActiveDocument;
                SelectedArea = Doc.GetObjectByName(areaName) as Area;
                TFlex.Drawing.Rectangle bound = SelectedArea.BoundRect;
                double Scale = 159 / Math.Max(bound.Width, bound.Height);

                Bitmap   img   = new Bitmap(160, 160);
                Graphics graph = Graphics.FromImage(img);
                Pen      pen   = new Pen(Brushes.White);
                graph.DrawRectangle(pen, new Rectangle(0, 0, 159, 159));
                pen       = new Pen(Brushes.Black);
                pen.Width = 1;
                for (int cc = 0; cc < SelectedArea.ContourCount; cc++)
                {
                    Contour cont = SelectedArea.GetContour(cc);
                    foreach (var segm in cont)
                    {
                        switch (segm.GeometryType)
                        {
                        case ObjectGeometryType.Line:
                            LineGeometry line = segm.Geometry as LineGeometry;
                            if (line != null)
                            {
                                graph.DrawLine(pen, (float)((line.X1 - bound.Left) * Scale), (float)((bound.Top - line.Y1) * Scale), (float)((line.X2 - bound.Left) * Scale), (float)((bound.Top - line.Y2) * Scale));
                            }
                            break;

                        case ObjectGeometryType.Circle:
                            CircleGeometry circle = segm.Geometry as CircleGeometry;
                            if (circle == null)
                            {
                                break;
                            }
                            double radius = (circle.Radius * Scale);
                            int    xc     = (int)((circle.CenterX - bound.Left) * Scale);
                            int    yc     = (int)((bound.Top - circle.CenterY) * Scale);

                            graph.DrawEllipse(pen, new Rectangle((int)(xc - radius), (int)(yc - radius), (int)radius * 2, (int)radius * 2));
                            break;

                        case ObjectGeometryType.CircleArc:
                            CircleArcGeometry cgeom = segm.Geometry as CircleArcGeometry;
                            if (cgeom == null)
                            {
                                break;
                            }
                            int xc1 = (int)((cgeom.CenterX - bound.Left) * Scale);
                            int yc1 = (int)((bound.Top - cgeom.CenterY) * Scale);
                            radius = (cgeom.Radius * Scale);
                            var    angles = NFUtils.GetArcAngle(cgeom);
                            double ang    = angles.Item1 * 180 / Math.PI;
                            double ang1   = angles.Item2 * 180 / Math.PI - 90;
                            graph.DrawArc(pen, (float)(xc1 - radius), (float)(yc1 - radius), (float)(radius * 2), (float)(radius * 2), (float)ang1, (float)ang);
                            break;

                        default:

                            PolylineGeometry geom = segm.Geometry as PolylineGeometry;

                            if (geom == null)
                            {
                                break;
                            }
                            for (int i = 1; i < geom.Count; i++)
                            {
                                int x1 = (int)((geom.GetX(i) - bound.Left) * Scale);
                                int y1 = (int)((bound.Top - geom.GetY(i)) * Scale);
                                int x2 = (int)((geom.GetX(i - 1) - bound.Left) * Scale);
                                int y2 = (int)((bound.Top - geom.GetY(i - 1)) * Scale);
                                graph.DrawLine(pen, (float)x1, (float)y1, (float)x2, (float)y2);
                            }
                            break;
                        }
                    }
                }

                pictureBox1.Image = img;

                //Задание параметров форме

                label10.Text = $"Размеры детали = {(int) bound.Width} x {(int) bound.Height}";
                label9.Text  = $"Количество контуров: {SelectedArea.ContourCount}";

                selectComboNum(ref comboBox2, SelectedItem.Rotation);

                selectComboNum(ref comboBox1, SelectedItem.Reflection);
                selectComboNum(ref comboBox1, SelectedItem.Reflection);

                textBox4.Text = SelectedItem.Count.ToString();
            }
        }