Пример #1
0
        // Создание вершины из пар кодов
        public new static DxfVertex Create(List <DxfCodePair> pairs)
        {
            double bulge = 0;
            DxfDot dot   = null;

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

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

            return(new DxfVertex(dot, bulge));
        }
Пример #2
0
        // Определение угла поворота точки на окружности относительно центра
        private static double GetAngle(DxfDot center, Vector dot, double radius)
        {
            double angle = Math.Asin(Math.Abs(center.Y - dot.Y) / radius) * DxfHelper.RadToDeg;

            if (double.IsNaN(angle))
            {
                angle = Math.Acos(Math.Abs(center.X - dot.X) / radius) * DxfHelper.RadToDeg;
            }

            if (center.X <= dot.X && center.Y <= dot.Y)
            {
                return(angle);
            }
            else if (center.X >= dot.X && center.Y <= dot.Y)
            {
                return(180 - angle);
            }
            else if (center.X >= dot.X && center.Y >= dot.Y)
            {
                return(180 + angle);
            }
            else if (center.X <= dot.X && center.Y >= dot.Y)
            {
                angle = 360 - angle;
                angle = angle >= 360 ? angle - 360 : angle;
            }
            return(angle);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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);
        }
Пример #7
0
        // Создание координат 3D из пар кодов
        public static DxfDot Create(System.Collections.Generic.List <DxfCodePair> pairs)
        {
            DxfDot dot = new DxfDot();

            foreach (DxfCodePair pair in pairs)
            {
                switch (pair.Code)
                {
                case 10:
                    dot.X = pair.AsDouble;
                    break;

                case 20:
                    dot.Y = pair.AsDouble;
                    break;

                case 30:
                    dot.Z = pair.AsDouble;
                    break;
                }
            }
            return(dot);
        }
Пример #8
0
 public static DxfEndPoint EndPointFromDot(DxfDot dot)
 {
     return(new DxfEndPoint(dot.X, dot.Y, dot.Z));
 }
Пример #9
0
        public new static DxfVertex Zero => new DxfVertex(DxfDot.Zero);     // возвращает вершину с нулевыми координатами

        #endregion
        #region Конструктор класса

        internal DxfVertex(DxfDot point, double bulge = 0)
            : this(point.X, point.Y, point.Z, bulge)
        {
        }
Пример #10
0
 // Создание класса из пар кодов
 public new static LimMax Create(System.Collections.Generic.List <DxfCodePair> pairs) => new LimMax(DxfDot.Create(pairs).AsPoint);
Пример #11
0
 // Создание класса из пар кодов
 public new static ExtMin Create(System.Collections.Generic.List <DxfCodePair> pairs) => new ExtMin(DxfDot.Create(pairs));
Пример #12
0
 // Создание класса из пар кодов
 public new static InsBase Create(List <DxfCodePair> pairs) => new InsBase(DxfDot.Create(pairs));
Пример #13
0
        }                                               // имя секции

        #endregion
        #region Конструкторы

        public InsBase(DxfDot value)
            : base(value.X, value.Y, value.Z)
        {
        }
Пример #14
0
 private DxfPoint(DxfDot dot, DxfColors color = DxfColors.NotClosedLine)
 {
     Coordinates = dot;
     Color       = color;
 }
Пример #15
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);
        }
Пример #16
0
        }                                               // имя объекта в файле DXF

        #endregion
        #region Конструктор

        public ExtMax(DxfDot dot) :
            base(dot.X, dot.Y, dot.Z)
        {
        }
Пример #17
0
 // Создание класса из пар кодов
 public new static ExtMax Create(List <DxfCodePair> pairs) => new ExtMax(DxfDot.Create(pairs));
Пример #18
0
 // Перевод точки DxfDot в класс Windows.Point
 public static Point DotToPoint(DxfDot dot)
 {
     return(new Point(dot.X, dot.Y));
 }
Пример #19
0
        }                                               // имя в файле DXF

        #endregion
        #region Конструктор

        public ExtMin(DxfDot dot) :
            base(DxfHelper.NormalizeDouble(dot.X), DxfHelper.NormalizeDouble(dot.Y), DxfHelper.NormalizeDouble(dot.Z))
        {
        }