Ejemplo n.º 1
0
        //protected static void cArcToDoubles(CircleArcGeometry cgeom, ref Stack<double> VertStack)
        protected static void cArcToDoubles(CircleArcGeometry cgeom, ref NFContour cont, Rectangle b, bool ccw)
        {
            double sx = cgeom.StartX;
            double sy = cgeom.StartY;

            double ex = cgeom.EndX;
            double ey = cgeom.EndY;

            /*double R = cgeom.Radius;
             * double L = 0.5 * Math.Sqrt((ex - sx) * (ex - sx) + (ey - sy) * (ey - sy));
             * double bulge = 0;
             * if (L > 0)
             * {
             *  bulge = (R - Math.Sqrt(R * R - L * L)) / L​;
             * }*/

            double[] angs  = getArcAngle(cgeom, ccw);
            double   bulge = Math.Tan(angs[0] / 4);

            if (ccw)
            {
                bulge = -bulge;
            }
            if (ccw)
            {
                cont.AddPoint(new NFPoint(sx - b.Left, b.Top - sy, bulge));
                cont.AddPoint(new NFPoint(ex - b.Left, b.Top - ey, bulge));
            }
            else
            {
                cont.AddPoint(new NFPoint(ex - b.Left, b.Top - ey, bulge));
                cont.AddPoint(new NFPoint(sx - b.Left, b.Top - sy, bulge));
            }
        }
Ejemplo n.º 2
0
        public void AddContour(NFContour Contour)
        {
            int L = Contours.GetLength(0) + 1;

            Array.Resize <NFContour>(ref Contours, L);
            Contours[L - 1] = Contour;
        }
Ejemplo n.º 3
0
        protected static void cArcToDoubles(CircleArcGeometry cgeom, ref NFContour cont, Rectangle b, bool ccw)
        {
            double sx = cgeom.StartX;
            double sy = cgeom.StartY;

            double ex = cgeom.EndX;
            double ey = cgeom.EndY;

            var    angs  = GetArcAngle(cgeom);
            double bulge = Math.Tan(angs.Item1 / 4);

            if (ccw)
            {
                bulge = -bulge;
                cont.AddPoint(new NFPoint(sx - b.Left, b.Top - sy, bulge));
                cont.AddPoint(new NFPoint(ex - b.Left, b.Top - ey, bulge));
            }
            else
            {
                cont.AddPoint(new NFPoint(ex - b.Left, b.Top - ey, bulge));
                cont.AddPoint(new NFPoint(sx - b.Left, b.Top - sy, bulge));
            }
        }
Ejemplo n.º 4
0
 public void AddContour(NFContour contour)
 {
     Contours.Add(contour);
 }
Ejemplo 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);
        }
Ejemplo n.º 6
0
 public void SetContour(int id, NFContour contour)
 {
     Contours[id] = contour;
 }
Ejemplo 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();
                }
            }
        }
Ejemplo 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);
        }