示例#1
0
        // Создание линии из пар кодов
        public static DxfLine Create(List <DxfCodePair> pairs, bool ignoreLineType)
        {
            DxfLine line = new DxfLine();

            for (int i = 0; i < pairs.Count; i++)
            {
                switch (pairs[i].Code)
                {
                case 62:
                    line.Color = DxfColor.Create(pairs[i], ignoreLineType);
                    break;

                case 10:
                    if (pairs[i + 2].Code == 30)
                    {
                        line.StartPoint = DxfDot.Create(pairs.GetRange(i, 3));
                        i += 2;
                    }
                    else
                    {
                        line.StartPoint = DxfDot.Create(pairs.GetRange(i, 2));
                        i++;
                    }
                    break;

                case 11:
                    if ((i + 2) < pairs.Count && pairs[i + 2].Code == 31)
                    {
                        line.EndPoint = DxfEndPoint.Create(pairs.GetRange(i, 3));
                        i            += 2;
                    }
                    else
                    {
                        line.EndPoint = DxfEndPoint.Create(pairs.GetRange(i, 2));
                        i++;
                    }
                    break;
                }
            }

            if (line.Color == 0 && ignoreLineType)
            {
                line.Color = DxfColors.MainOutline;
            }
            else if (line.Color == 0 || line.Color == DxfColors.NoColor)
            {
                return(null);
            }

            CreateRect(line);

            return(line);
        }
示例#2
0
        // Создание класса из пар кодов
        public static DxfArc Create(List <DxfCodePair> pairs, bool ignoreLineType)
        {
            DxfArc arc = new DxfArc();

            for (int i = 0; i < pairs.Count; i++)
            {
                switch (pairs[i].Code)
                {
                case 62:
                    arc.Color = DxfColor.Create(pairs[i], ignoreLineType);
                    break;

                case 10:
                    if (pairs[i + 2].Code == 30)
                    {
                        arc.Center = DxfDot.Create(pairs.GetRange(i, 3));
                        i         += 2;
                    }
                    else
                    {
                        arc.Center = DxfDot.Create(pairs.GetRange(i, 2));
                        i++;
                    }
                    break;

                case 40:
                    arc.Radius = pairs[i].AsDouble;
                    break;

                case 50:
                    arc.StartAngle = pairs[i].AsDouble;
                    break;

                case 51:
                    arc.EndAngel = pairs[i].AsDouble;
                    break;
                }
            }

            if (arc.Color == 0 && ignoreLineType)
            {
                arc.Color = DxfColors.MainOutline;
            }
            else if (arc.Color == 0 || arc.Color == DxfColors.NoColor)
            {
                return(null);
            }

            CreateBound(arc);

            return(arc);
        }
示例#3
0
        // Создание класса из пар кодов
        public static DxfCircle Create(List <DxfCodePair> pairs, bool ignoreLineType)
        {
            DxfCircle circle = new DxfCircle();

            for (int i = 0; i < pairs.Count; i++)
            {
                switch (pairs[i].Code)
                {
                case 62:
                    circle.Color = DxfColor.Create(pairs[i], ignoreLineType);
                    break;

                case 10:
                    if (pairs[i + 2].Code == 30)
                    {
                        circle.Center = DxfDot.Create(pairs.GetRange(i, 3));
                        i            += 2;
                    }
                    else
                    {
                        circle.Center = DxfDot.Create(pairs.GetRange(i, 2));
                        i++;
                    }
                    break;

                case 40:
                    circle.Radius = pairs[i].AsDouble;
                    break;
                }
            }

            if (circle.Color == 0 && ignoreLineType)
            {
                circle.Color = DxfColors.MainOutline;
            }
            else if (circle.Color == 0 || circle.Color == DxfColors.NoColor)
            {
                return(null);
            }

            Rect rt = new Rect(circle.Center.X - circle.Radius, circle.Center.Y - circle.Radius,
                               circle.Radius * 2, circle.Radius * 2);

            circle.Bound = rt;

            return(circle);
        }
示例#4
0
        // Создание класса из пар кодов
        public static DxfArc Create(List <DxfCodePair> pairs, bool ignoreLineType)
        {
            DxfArc arc = new DxfArc();

            arc.Color = DxfColor.Create(pairs.Find(p => p.Code == 62), ignoreLineType);
            if (arc.Color == DxfColors.NoColor)
            {
                return(null);
            }
            arc.Center     = new DxfDot(pairs.Find(x => x.Code == 10).AsDouble, pairs.Find(y => y.Code == 20).AsDouble);
            arc.Radius     = pairs.Find(p => p.Code == 40).AsDouble;
            arc.StartAngle = pairs.Find(p => p.Code == 50).AsDouble;
            arc.EndAngel   = pairs.Find(p => p.Code == 51).AsDouble;

            CreateBound(arc);

            return(arc);
        }
示例#5
0
        // Создание точки из пар кодов
        public static DxfPoint Create(List <DxfCodePair> pairs, bool ignoreLineType)
        {
            DxfPoint point = new DxfPoint();

            for (int i = 0; i < pairs.Count; i++)
            {
                switch (pairs[i].Code)
                {
                case 62:
                    point.Color = DxfColor.Create(pairs[i], ignoreLineType);
                    break;

                case 10:
                    if ((i + 2) < pairs.Count && pairs[i + 2].Code == 30)
                    {
                        point.Coordinates = DxfDot.Create(pairs.GetRange(i, 3));
                        i += 2;
                    }
                    else
                    {
                        point.Coordinates = DxfDot.Create(pairs.GetRange(i, 2));
                        i++;
                    }
                    break;
                }
            }

            if (point.Color == 0 && !ignoreLineType)
            {
                point.Color = DxfColors.MainOutline;
            }
            if (point.Color == 0 || point.Color == DxfColors.NoColor)
            {
                return(null);
            }

            Rect rt = new Rect(point.Coordinates.X, point.Coordinates.Y, 1, 1);

            point.Bound = rt;
            return(point);
        }
示例#6
0
        // Метод создания эллипса из пар кодов
        public static DxfEllipse Create(List <DxfCodePair> pairs, bool ignoreLineType)
        {
            DxfEllipse ellipse = new DxfEllipse();

            for (int i = 0; i < pairs.Count; i++)
            {
                switch (pairs[i].Code)
                {
                case 62:
                    ellipse.Color = DxfColor.Create(pairs[i], ignoreLineType);
                    break;

                case 10:
                    if (pairs[i + 2].Code == 30)
                    {
                        ellipse.Center = DxfDot.Create(pairs.GetRange(i, 3));
                        i += 2;
                    }
                    else
                    {
                        ellipse.Center = DxfDot.Create(pairs.GetRange(i, 2));
                        i++;
                    }
                    break;

                case 11:
                    if (pairs[i + 2].Code == 31)
                    {
                        ellipse.MajorAxis = DxfMajorAxis.Create(pairs.GetRange(i, 3));
                        i += 2;
                    }
                    else
                    {
                        ellipse.MajorAxis = DxfMajorAxis.Create(pairs.GetRange(i, 2));
                        i++;
                    }
                    break;

                case 40:
                    ellipse.Ratio = pairs[i].AsDouble;
                    break;

                case 41:
                    ellipse.StartParam = pairs[i].AsDouble;
                    break;

                case 42:
                    ellipse.EndParam = pairs[i].AsDouble;
                    break;
                }
            }

            if (ellipse.Color == 0 && ignoreLineType)
            {
                ellipse.Color = DxfColors.MainOutline;
            }
            else if (ellipse.Color == 0 || ellipse.Color == DxfColors.NoColor)
            {
                return(null);
            }

            Vector majorVector = new Vector(ellipse.MajorAxis.X, ellipse.MajorAxis.Y);

            ellipse.majorRadius = majorVector.Length;
            ellipse.minorRadius = ellipse.majorRadius * ellipse.Ratio;
            ellipse.rotateAngle = Vector.AngleBetween(new Vector(1, 0), majorVector);
            ellipse.center      = new Vector(ellipse.Center.X, ellipse.Center.Y);

            int    precision = (int)(Math.Abs(ellipse.EndParam - ellipse.StartParam) * DxfHelper.RadToDeg);
            double step      = Math.Abs(ellipse.EndParam - ellipse.StartParam) / (precision - 1);

            double[] ordX = new double[precision];
            double[] ordY = new double[precision];

            for (int i = 0; i < precision; i++)
            {
                double angle = ellipse.StartParam + step * i;

                Vector vector = ellipse.GetVector(angle, 1, ellipse.rotateAngle);

                ordX[i] = vector.X;
                ordY[i] = vector.Y;
            }
            Array.Sort(ordX);
            Array.Sort(ordY);
            Rect rt = new Rect(ordX[0], ordY[0], ordX[ordX.Length - 1] - ordX[0], ordY[ordY.Length - 1] - ordY[0]);

            ellipse.Bound = rt;
            return(ellipse);
        }