示例#1
0
        private Symbol FindSymbol(Part part, string gateId)
        {
            Library lib = schematic.Drawing.Schematic.Libraries.Library.Find(x => x.Name == part.Library);

            Deviceset devset = lib.Devicesets.Deviceset.Find(x => x.Name == part.Deviceset);

            Gate   gate   = devset.Gates.Gate.Find(x => x.Name == gateId);
            Symbol symbol = lib.Symbols.Symbol.Find(x => x.Name == gate.Symbol);

            return(symbol);
        }
示例#2
0
        private int GetUnitNumber(Part part, string gate_name)
        {
            Library   lib    = schematic.Drawing.Schematic.Libraries.Library.Find(x => x.Name == part.Library);
            Deviceset devset = lib.Devicesets.Deviceset.Find(x => x.Name == part.Deviceset);

            int unit = 1;

            foreach (Gate gate in devset.Gates.Gate)
            {
                if (gate.Name == gate_name)
                {
                    return(unit);
                }
                else
                {
                    unit++;
                }
            }
            return(0);
        }
示例#3
0
        private void GetSymbol(Library lib, Deviceset devset, k.Symbol.Symbol k_sym)
        {
            bool   is_multi_part         = false;
            bool   interchangeable_units = false;
            string symbol_name           = devset.Gates.Gate[0].Symbol;

            if (devset.Gates.Gate.Count == 1)
            {
                is_multi_part = false;
            }
            else
            {
                is_multi_part         = true;
                interchangeable_units = true;
                foreach (Gate gate in devset.Gates.Gate)
                {
                    if (symbol_name != gate.Symbol)
                    {
                        interchangeable_units = false;
                        break;
                    }
                }

                k_sym.NumUnits = devset.Gates.Gate.Count;
                if (interchangeable_units)
                {
                    k_sym.Locked = false;
                }
                else
                {
                    k_sym.Locked = true;
                }
            }

            int gate_index = 0;

            k_sym.ShowPinName   = true;
            k_sym.ShowPinNumber = true;

            foreach (Gate gate in devset.Gates.Gate)
            {
                Symbol sym = lib.Symbols.Symbol.Find(x => x.Name == gate.Symbol);
                if (sym == null)
                {
                    Trace("error: symbol not found: " + gate.Symbol);
                    return;
                }

                if ((lib.Name != null) && lib.Name.StartsWith("supply"))
                {
                    k_sym.PowerSymbol             = true;
                    k_sym.Reference               = "#PWR";
                    k_sym.fReference.Text.Value   = "#PWR";
                    k_sym.fReference.Text.Visible = false;
                }

                int unit = 0;
                //int convert = 1;

                if (is_multi_part && !interchangeable_units)
                {
                    unit = gate_index + 1;
                }

                if ((gate_index == 0) || (is_multi_part && !interchangeable_units))
                {
                    // graphic lines, arcs
                    foreach (Wire wire in sym.Wire)
                    {
                        float curve = (float)StringUtils.StringToDouble(wire.Curve);

                        if (curve == 0)
                        {
                            k_sym.Drawings.Add(new k.Symbol.sym_polygon(unit, Common.StrToInch(wire.Width), k.Symbol.FillTypes.None,
                                                                        new List <PointF>()
                            {
                                Common.StrToPointInch(wire.X1, wire.Y1), Common.StrToPointInch(wire.X2, wire.Y2)
                            }));
                        }
                        else
                        {
                            PointF start = Common.StrToPointInch(wire.X1, wire.Y1);
                            PointF end = Common.StrToPointInch(wire.X2, wire.Y2);
                            float  arc_start, arc_end, radius;
                            PointF center = Common.kicad_arc_center(start, end, -curve, out radius, out arc_start, out arc_end);

                            k_sym.Drawings.Add(new k.Symbol.sym_arc(unit, Common.StrToInch(wire.Width),
                                                                    center, radius, arc_start, arc_end,
                                                                    start, end));
                        }
                    }

                    // graphic : circles
                    foreach (Circle circle in sym.Circle)
                    {
                        float width = 1;
                        if (!string.IsNullOrEmpty(circle.Width))
                        {
                            width = Math.Max(Common.StrToInch(circle.Width), 1);
                        }

                        k_sym.Drawings.Add(new k.Symbol.sym_circle(unit, width, k.Symbol.FillTypes.None,
                                                                   Common.StrToPointInch(circle.X, circle.Y),
                                                                   Common.StrToInch(circle.Radius)));
                    }

                    // graphic : rectangles
                    foreach (EagleImport.Rectangle rect in sym.Rectangle)
                    {
                        k_sym.Drawings.Add(new k.Symbol.sym_rectangle(unit, 1f, k.Symbol.FillTypes.PenColor, Common.StrToPointInch(rect.X1, rect.Y1), Common.StrToPointInch(rect.X2, rect.Y2)));
                    }

                    // graphic : texts
                    // check for name, value
                    foreach (Text text in sym.Text)
                    {
                        k.Symbol.sym_text k_text = new k.Symbol.sym_text(unit, text.mText, 0, Common.StrToPointInch(text.X, text.Y), Common.StrToInch(text.Size),
                                                                         false, false, false, k.Symbol.SymbolField.HorizAlign_Left, k.Symbol.SymbolField.VertAlign_Bottom);

                        //ExtRotation extRot = ExtRotation.Parse(text.Rot);
                        k_text.Text.xAngle = Common.GetAngle(text.Rot);

                        k_text.Text.Pos.Rotation = Common.xGetAngleFlip(text.Rot, out k_text.Text.xMirror);

                        SizeF textSize = strokeFont.GetTextSize(text.mText, new Kicad_utils.TextEffects(k_text.Text.FontSize));

                        string t = text.mText.ToUpperInvariant();
                        if (t.Contains(">NAME") || t.Contains(">PART") ||
                            t.Contains(">VALUE"))
                        {
                            k.Symbol.SymbolField sym_text;
                            if (t.Contains(">VALUE"))
                            {
                                sym_text = k_sym.fValue;
                            }
                            else
                            {
                                sym_text = k_sym.fReference;
                            }

                            sym_text.Text.Pos      = k_text.Text.Pos;
                            sym_text.Text.FontSize = k_text.Text.FontSize;
                            if ((k_text.Text.Pos.Rotation == 0) || (k_text.Text.Pos.Rotation == 180))
                            {
                                sym_text.Text.Pos.Rotation = 0;
                            }
                            else
                            {
                                sym_text.Text.Pos.Rotation = 90;
                            }
                        }
                        else
                        {
                            // unless Spin is set?
                            if (k_text.Text.Pos.Rotation == 180)
                            {
                                k_text.Text.Pos.At.X    -= textSize.Width;
                                k_text.Text.Pos.At.Y    -= textSize.Height;
                                k_text.Text.Pos.Rotation = 0;
                            }

                            //
                            k_sym.Drawings.Add(k_text);
                        }
                    }
                }


                // Pins
                foreach (Pin pin in sym.Pin)
                {
                    k.Symbol.sym_pin k_pin = new k.Symbol.sym_pin(unit, Common.ConvertName(pin.Name), "~", Common.StrToPointInch(pin.X, pin.Y),
                                                                  250,
                                                                  "L",
                                                                  50f, 50f, "P", "", true);
                    switch (pin.Rot)
                    {
                    case "R0": k_pin.Orientation = "R"; break;

                    case "R90": k_pin.Orientation = "U"; break;

                    case "R180": k_pin.Orientation = "L"; break;

                    case "R270": k_pin.Orientation = "D"; break;

                    default:
                        k_pin.Orientation = "R"; break;
                    }
                    switch (pin.Length)
                    {
                    case PinLength.point: k_pin.Length = 0; break;

                    case PinLength.@short: k_pin.Length = 100; break;

                    case PinLength.middle: k_pin.Length = 200; break;

                    case PinLength.@long: k_pin.Length = 300; break;

                    default:
                        k_pin.Length = 300; break;
                    }

                    switch (pin.Visible)
                    {
                    case PinVisible.off:
                        k_pin.SizeName = 0;
                        k_pin.SizeNum  = 0;
                        break;

                    case PinVisible.pad:
                        k_pin.SizeName = 0;
                        break;

                    case PinVisible.pin:
                        k_pin.SizeNum = 0;
                        break;

                    case PinVisible.both:
                        break;
                    }

                    switch (pin.Direction)
                    {
                    case PinDirection.nc: k_pin.Type = "N"; break;

                    case PinDirection.@in: k_pin.Type = "I"; break;

                    case PinDirection.@out: k_pin.Type = "O"; break;

                    case PinDirection.io: k_pin.Type = "B"; break;

                    case PinDirection.oc: k_pin.Type = "C"; break;

                    case PinDirection.hiz: k_pin.Type = "T"; break;

                    case PinDirection.pas: k_pin.Type = "P"; break;

                    case PinDirection.pwr: k_pin.Type = "W"; break;

                    case PinDirection.sup: k_pin.Type = "w"; break;

                    default:
                        k_pin.Type = "B";
                        break;
                    }

                    if (k_sym.PowerSymbol)
                    {
                        k_pin.Type      = k.Symbol.sym_pin.dir_power_in;
                        k_pin.PinNumber = "~";
                        k_pin.Visible   = false;
                        // todo add line...

                        if (k_pin.Length != 0)
                        {
                            PointF p1 = k_pin.Pos;
                            PointF p2 = new PointF(k_pin.Pos.X + k_pin.Length, k_pin.Pos.Y);

                            p2 = PointFExt.Rotate(p2, k_pin.Pos, Common.GetAngle(pin.Rot));

                            k_sym.Drawings.Add(new k.Symbol.sym_polygon(unit, 6,
                                                                        k.Symbol.FillTypes.None,
                                                                        new List <PointF>()
                            {
                                p1, p2
                            }));
                        }
                    }

                    switch (pin.Function)
                    {
                    case PinFunction.none: k_pin.Shape = ""; break;

                    case PinFunction.dot: k_pin.Shape = "I"; break;

                    case PinFunction.clk: k_pin.Shape = "C"; break;

                    case PinFunction.dotclk: k_pin.Shape = "CI"; break;
                    }

                    //
                    k_sym.Drawings.Add(k_pin);
                }

                gate_index++;
            } // foreach gate
        }