Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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();
            }
        }
Exemple #4
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();
            }
        }