Пример #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));
            }
        }
Пример #2
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));
            }
        }
Пример #3
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);
        }
Пример #4
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);
        }