Ejemplo n.º 1
0
            public override bool ProcessLine(byte[] line)
            {
                double StartAngle, EndAngle, Radius, Width;
                Layers Layer;
                double X1, Y1;
                Int16  Component;
                Int16  net;

                base.ProcessLine();
                ArcStruct a = ByteArrayToStructure <ArcStruct>(line);

                Layer = (Layers)a.Layer;
                net   = a.net;
                net++;
                Component  = a.Component;
                X1         = Math.Round((double)a.X1 * 25.4 / 10000000 - originX, Precision);
                Y1         = Math.Round((double)a.Y1 * 25.4 / 10000000 - originY, Precision);
                Radius     = Math.Round((double)a.Radius * 25.4 / 10000000, Precision);
                StartAngle = a.StartAngle;
                EndAngle   = a.EndAngle;
                Width      = (double)a.Width * 25.4 / 10000000;

                bool   InComponent = Component != -1;
                double Angle;

                if (EndAngle < StartAngle)
                {
                    EndAngle += 360;
                }

                Angle = (EndAngle - StartAngle);
                double X     = X1 + Radius * Math.Cos(StartAngle * Math.PI / 180);
                double Y     = Y1 + Radius * Math.Sin(StartAngle * Math.PI / 180);
                string layer = Brd.GetLayer(Layer);

                if (!InComponent)
                {
                    if (net > 0 && Brd.IsCopperLayer(Layer))
                    {
                        if (!Globals.PcbnewVersion)
                        {
                            // arcs with nets on copper layers allowed in 5.99
                            Arc Arc = new Arc(X1, Y1, StartAngle, EndAngle, Radius, Layer, Width, net);
                            ArcsL.Add(Arc);
                        }
                        else
                        {
                            //arcs.Append($"  (arc (start {Math.Round(X1, Precision)} {Math.Round(-Y1, Precision)}) (end {Math.Round(X, Precision)} {Math.Round(-Y, Precision)}) (angle {Math.Round(Angle, Precision)}) (layer {L}) (net {Net}) (width {Width}))\n");

                            // we have an arc/track on a copper layer and it has a net
                            // these aren't supported by KiCad yet so generate a curve out of track segments
                            // first normalise it so that the centre is at 0,0
                            // save the centre point
                            double XC = X1;
                            double YC = Y1;

                            X = X - XC;
                            Y = Y - YC;

                            double radius = Math.Sqrt(X * X + Y * Y);
                            // start angle in radians
                            double start_angle = Arc.Radians(StartAngle);
                            double end_angle   = Arc.Radians(EndAngle);
                            double X2          = Radius * Math.Cos(end_angle);
                            double Y2          = Radius * Math.Sin(end_angle);
                            X = Radius * Math.Cos(start_angle);
                            Y = Radius * Math.Sin(start_angle);

                            // generate arc segments at 5° increments
                            for (double angle = start_angle; angle < end_angle; angle += 2 * Math.PI / 72)
                            {
                                X1 = Radius * Math.Cos(angle);
                                Y1 = Radius * Math.Sin(angle);
                                Line Line = new Line(XC + X, YC + Y, XC + X1, YC + Y1, layer, Width, net);
                                LinesL.Add(Line);
                                X = X1;
                                Y = Y1;
                            }
                            // do last segment
                            if (X != X2 || Y != Y2)
                            {
                                Line Line = new Line(X + XC, Y + YC, X2 + XC, Y2 + YC, layer, Width, net);
                                LinesL.Add(Line);
                            }
                        }
                    }
                    else
                    {
                        // only add if not part of board outline
                        if ((layer != "Edge.Cuts") || !Brd.CheckExistingArc(X1, Y1, X, Y, Angle))
                        {
                            List <string> Layers = Brd.GetLayers(layer);
                            foreach (var L in Layers)
                            {
                                Arc Arc = new Arc(X1, Y1, StartAngle, EndAngle, Radius, Brd.GetAltiumLayer(L), Width);
                                ArcsL.Add(Arc);
                            }
                        }
                    }
                }
                else
                {
                    Arc Arc = new Arc(X1, Y1, StartAngle, EndAngle, Radius, Layer, Width);
                    ModulesL[Component].Arcs.Add(Arc);
                }
                return(true);
            }