Exemplo n.º 1
0
        private static void CreateBound(DxfArc arc)
        {
            double angle     = (arc.StartAngle < arc.EndAngel ? arc.EndAngel - arc.StartAngle : 360 - (arc.StartAngle - arc.EndAngel));
            int    precision = (int)angle;

            if (precision < 3)
            {
                precision = 3;
            }

            double[] ordX = new double[precision];
            double[] ordY = new double[precision];
            double   step = Math.Abs(angle / (precision - 1));

            for (int i = 0; i < precision; i++)
            {
                ordX[i] = arc.Radius * Math.Cos((arc.StartAngle + step * i) * DxfHelper.DegToRad) + arc.Center.X;
                ordY[i] = arc.Radius * Math.Sin((arc.StartAngle + step * i) * DxfHelper.DegToRad) + arc.Center.Y;
            }
            Array.Sort(ordX);
            Array.Sort(ordY);

            Rect rct = new Rect(ordX[0], ordY[0], ordX[ordX.Length - 1] - ordX[0], ordY[ordY.Length - 1] - ordY[0]);

            arc.Bound = rct;
        }
Exemplo n.º 2
0
        private static void CreateBound(DxfArc arc)
        {
            double angle     = (arc.StartAngle < arc.EndAngel ? arc.EndAngel - arc.StartAngle : 360 - (arc.StartAngle - arc.EndAngel));
            int    precision = (int)angle;

            if
            double[] ordX = new double[precision];
Exemplo n.º 3
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
        // Создать объект Arc из двух вершин, в первой из который устанолен коэффициет искривления
        public static DxfArc Create(DxfVertex vertex1, DxfVertex vertex2, DxfColors color = DxfColors.MainOutline)
        {
            if (vertex1.Bulge == 0)
            {
                throw new ArgumentNullException(Properties.Resource.BulgeNotFound);
            }

            DxfArc arc = new DxfArc();

            arc.Color = color;      // цвет линии

            // Наити полный угол дуги
            double angleOfArc = 0;

            if (Math.Abs(vertex1.Bulge) == 1)
            {
                angleOfArc = 180;
            }
            else
            {
                angleOfArc = Math.Abs(Math.Atan(vertex1.Bulge) * DxfHelper.RadToDeg) * 4;
            }

            // Найти хорду и ее длинну, определить начало и конец дуги,
            // т.к. в файлах DXF направление дуги всегда по часовой стрелке,
            // если коэффициент искривления вершины имеет отрицательное значение,
            // то поменять точки местами
            Vector startPoint = vertex1.Bulge > 0 ? new Vector(vertex1.X, vertex1.Y) : new Vector(vertex2.X, vertex2.Y);    // точка начала дуги
            Vector endPoint   = vertex1.Bulge > 0 ? new Vector(vertex2.X, vertex2.Y) : new Vector(vertex1.X, vertex1.Y);    // точка конца дуги
            Vector chord      = endPoint - startPoint;                                                                      // хорда

            // Радиус дуги
            // если угол дуги равен 180 градусов, то радиус равен половине длинны хорды
            if (angleOfArc == 180)
            {
                arc.Radius = chord.Length / 2;
            }
            else
            {
                arc.Radius = Math.Abs((chord.Length / Math.Sin(angleOfArc / 2 * DxfHelper.DegToRad)) / 2);
            }

            // найти центр хорды
            Vector centerChord = startPoint + chord / 2;

            if (angleOfArc == 180)
            {
                arc.Center = new DxfDot(centerChord.X, centerChord.Y);
            }
            else
            {
                // найти расстояние от центра дуги до середины хорды
                double length = Math.Sqrt(arc.Radius * arc.Radius - Math.Pow(chord.Length * .5, 2));
                // единичный вектор, перпендикулярный хорде
                Vector perp = angleOfArc > 180 ? DxfHelper.RotateVector(chord, 270) : DxfHelper.RotateVector(chord, 90);
                perp.Normalize();
                // умножить перпендикуляр на расстояние до центра дуги
                Vector size = perp * length;
                // найти центр дуги
                Vector centerArc = centerChord + size;
                arc.Center = new DxfDot(centerArc.X, centerArc.Y);
            }

            // найти начальный и конечный углы дуги
            arc.StartAngle = GetAngle(arc.Center, startPoint, arc.Radius);
            arc.EndAngel   = arc.StartAngle + angleOfArc;
            arc.EndAngel   = arc.EndAngel >= 360 ? arc.EndAngel - 360 : arc.EndAngel;

            CreateBound(arc);

            return(arc);
        }
Exemplo n.º 6
0
        public void ReadArcAndCirle(StreamReader Reader, List <IDxfComponent> DxfList)
        {
            string temp;
            double x1 = 0; double y1 = 0; double z1 = 0;
            double x2 = 0; double y2 = 0; double z2 = 0;
            double startAngle = 0;
            double stopAngle  = 0;
            double radius     = 0;

            for (int i = 0; i < 7; i++)
            {
                temp = (string)Reader.ReadLine();
                temp = temp.Trim();
                switch (temp)
                {
                case "10":
                    temp = (string)Reader.ReadLine();
                    temp = temp.Trim();
                    x1   = Convert.ToDouble(temp.Replace(".", ","));
                    break;

                case "20":
                    temp = (string)Reader.ReadLine();
                    temp = temp.Trim();
                    y1   = Convert.ToDouble(temp.Replace(".", ","));
                    break;

                case "30":
                    temp = (string)Reader.ReadLine();
                    temp = temp.Trim();
                    z1   = Convert.ToDouble(temp.Replace(".", ","));
                    break;


                case "40":
                    temp   = (string)Reader.ReadLine();
                    temp   = temp.Trim();
                    radius = Convert.ToDouble(temp.Replace(".", ","));
                    break;

                case "210":
                    temp = (string)Reader.ReadLine();
                    temp = temp.Trim();
                    x2   = Convert.ToDouble(temp.Replace(".", ","));
                    break;

                case "220":
                    temp = (string)Reader.ReadLine();
                    temp = temp.Trim();
                    y2   = Convert.ToDouble(temp.Replace(".", ","));
                    break;

                case "230":
                    temp = (string)Reader.ReadLine();
                    temp = temp.Trim();
                    z2   = Convert.ToDouble(temp.Replace(".", ","));
                    break;
                }
            }

            string line1;
            string line2;

            line1 = (string)Reader.ReadLine();
            line2 = (string)Reader.ReadLine();

            if (line1 == "100" && line2 == "AcDbArc")
            {
                for (int i = 0; i < 2; i++)
                {
                    temp = (string)Reader.ReadLine();
                    temp = temp.Trim();
                    switch (temp)
                    {
                    case "50":
                        temp       = (string)Reader.ReadLine();
                        temp       = temp.Trim();
                        startAngle = Convert.ToDouble(temp.Replace(".", ","));
                        break;

                    case "51":
                        temp      = (string)Reader.ReadLine();
                        temp      = temp.Trim();
                        stopAngle = Convert.ToDouble(temp.Replace(".", ","));
                        break;
                    }
                }

                DxfArc Arc = new DxfArc();
                Arc.startPoint.xval = x1;
                Arc.startPoint.yval = y1;
                Arc.startPoint.zval = z1;
                Arc.startAngle      = startAngle;
                Arc.radius          = radius;
                Arc.endPoint.xval   = x2;
                Arc.endPoint.yval   = y2;
                Arc.endPoint.zval   = z2;
                Arc.stopAngle       = stopAngle;
                DxfList.Add(Arc);
            }


            else
            {
                DxfCircle Circle = new DxfCircle();
                Circle.startPoint.xval = x1;
                Circle.startPoint.yval = y1;
                Circle.startPoint.zval = z1;

                Circle.endPoint.xval = x2;
                Circle.endPoint.yval = y2;
                Circle.endPoint.zval = z2;
                Circle.radius        = radius;
                DxfList.Add(Circle);
            }
        }