예제 #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);
            }
예제 #2
0
            public override bool ProcessLine(byte[] line)
            {
                double X1, Y1, X2, Y2, width;
                int    net;
                Layers layer;
                bool   InComponent = false;
                Int16  component   = 0;

                base.ProcessLine();
                net = B2UInt16(line, 3 + 5);
                if (net == 0x0000FFFF)
                {
                    net = 0;
                }
                else
                {
                    net++;
                }
                component   = B2Int16(line, 7 + 5);
                InComponent = (component != -1);
                X1          = Math.Round(ToMM(line, 13 + 5) - originX, Precision);
                Y1          = Math.Round(ToMM(line, 17 + 5) - originY, Precision);
                X2          = Math.Round(ToMM(line, 21 + 5) - originX, Precision);
                Y2          = Math.Round(ToMM(line, 25 + 5) - originY, Precision);

                CheckMinMax(X1 + originX, Y1 + originY);
                CheckMinMax(X2 + originX, Y2 + originY);
                width = Math.Round(ToMM(line, 29 + 5), Precision);

                layer = (Layers)line[5];
                string Layer           = Brd.GetLayer(layer);
                int    ComponentNumber = 0;

                if (InComponent)
                {
                    // belongs to a component definition
                    ComponentNumber = component;
                }
                // check for and reject very short tracks
                if (Length(X1, Y1, X2, Y2) <= 0.001)
                {
                    OutputError($"Zero length track rejected at X1={X1} Y1={-Y1} X2={X2} y2={-Y2} ");
                    return(true);
                }
                if (!InComponent)
                {
                    if (net == 0)
                    {
                        if (!Brd.OnInnerLayer(layer))
                        {
                            if ((Layer != "Edge.Cuts") || !Brd.CheckExistingLine(X1, -Y1, X2, -Y2))
                            {
                                List <string> Layers = Brd.GetLayers(Layer);
                                foreach (var L in Layers)
                                {
                                    Line Line = new Line(X1, Y1, X2, Y2, L, width, net);
                                    LinesL.Add(Line);
                                }
                            }
                        }
                    }
                    else
                    {
                        Line Line = new Line(X1, Y1, X2, Y2, Brd.GetLayer(layer), width, net);
                        LinesL.Add(Line);
                        //tracks.Append($"  (segment (start {X1} {-Y1}) (end {X2} {-Y2}) (width {width}) (layer {Layer}) (net {net}))\n");
                        //track_count++;
                    }
                }
                else
                {
                    Line Line = new Line(X1, Y1, X2, Y2, Brd.GetLayer(layer), width);
                    ModulesL[ComponentNumber].Lines.Add(Line);
                }
                return(true);
            }