Example #1
0
        public static Module Parse(SNodeBase Node)
        {
            Module      result   = null;
            SExpression RootNode = Node as SExpression;

            if ((RootNode != null) && (RootNode.Name == "module"))
            {
                int index = 0;

                result      = new Module();
                result.Name = (RootNode.Items[index++] as SNodeAtom).Value;

                while (index < RootNode.Items.Count)
                {
                    SExpression sexpr = RootNode.Items[index] as SExpression;

                    switch (sexpr.Name)
                    {
                    case "layer":
                        result.layer = Layer.ParseLayer(RootNode.Items[index]);
                        break;

                    case "tedit":
                        result.tedit = sexpr.GetUintHex();
                        break;

                    case "tstamp":
                        result.tstamp = sexpr.GetUintHex();
                        break;

                    case "descr":
                        result.description = sexpr.GetString();
                        break;

                    case "tags":
                        result.tags = sexpr.GetString();
                        break;

                    case "path":
                        result.path = sexpr.GetString();
                        break;

                    case "at":
                        result.position = Position.Parse(sexpr);
                        break;

                    case "attr":
                        result.attr = sexpr.GetString();
                        break;

                    case "fp_text":
                        switch ((sexpr.Items[0] as SNodeAtom).Value)
                        {
                        case "reference":
                            result.Reference = fp_text.Parse(RootNode.Items[index]);
                            break;

                        case "value":
                            result.Value = fp_text.Parse(RootNode.Items[index]);
                            break;

                        default:
                            //todo usertext
                            if (result.UserText == null)
                            {
                                result.UserText = new List <fp_text>();
                            }
                            result.UserText.Add(fp_text.Parse(RootNode.Items[index]));
                            break;
                        }
                        break;

                    case "fp_line":
                    case "fp_arc":
                    case "fp_circle":
                    case "fp_polygon":
                    case "fp_poly":
                    {
                        fp_shape shape = null;
                        switch (sexpr.Name)
                        {
                        case "fp_line":
                            shape = fp_line.Parse(RootNode.Items[index]);
                            break;

                        case "fp_arc":
                            shape = fp_arc.Parse(sexpr);
                            break;

                        case "fp_circle":
                            shape = fp_circle.Parse(sexpr);
                            break;

                        case "fp_polygon":
                        case "fp_poly":
                            shape = fp_polygon.Parse(sexpr);
                            break;
                        }

                        if (shape != null)
                        {
                            if (result.Borders == null)
                            {
                                result.Borders = new List <fp_shape>();
                            }
                            result.Borders.Add(shape);
                        }
                    }
                    break;

                    case "pad":
                        pad pad = pad.Parse(RootNode.Items[index]);
                        if (pad != null)
                        {
                            if (result.Pads == null)
                            {
                                result.Pads = new List <pad>();
                            }
                            result.Pads.Add(pad);
                        }
                        break;

                    case "model":
                        if (result.CadModels == null)
                        {
                            result.CadModels = new List <model>();
                        }
                        result.CadModels.Add(model.Parse(sexpr));
                        break;
                    }
                    index++;
                }
            }

            return(result);
        }
Example #2
0
        public static pad Parse(SNodeBase node)
        {
            pad result = new pad();

            if ((node is SExpression) && ((node as SExpression).Name == "pad"))
            {
                SExpression expr = node as SExpression;

                int index = 0;

                result.number = (expr.Items[index++] as SNodeAtom).Value;
                result.type   = (expr.Items[index++] as SNodeAtom).Value;
                result.shape  = (expr.Items[index++] as SNodeAtom).Value;

                //
                while (index < expr.Items.Count)
                {
                    SExpression sub = expr.Items[index] as SExpression;

                    switch (sub.Name)
                    {
                    case "at":
                        result.position = Position.Parse(sub);
                        break;

                    case "size":
                        result.size = sub.GetSizeF();
                        break;

                    case "drill":
                        result.drill = Drill.Parse(sub);
                        break;

                    case "layers":
                        result._layers.ParseLayers(sub);
                        break;

                    case "net":
                        result.net = Net.Parse(sub);
                        break;

                    case "die_length":
                        result.die_length = sub.GetFloat();
                        break;

                    case "solder_mask_margin":
                        result.solder_mask_margin = sub.GetFloat();
                        break;

                    case "clearance":
                        result.clearance = sub.GetFloat();
                        break;

                    case "solder_paste_margin":
                        result.solder_paste_margin = sub.GetFloat();
                        break;

                    case "solder_paste_ratio":
                        result.solder_paste_ratio = sub.GetInt();
                        break;

                    case "zone_connect":
                        result.zone_connect = sub.GetInt();
                        break;

                    case "thermal_width":
                        result.thermal_width = sub.GetFloat();
                        break;

                    case "thermal_gap":
                        result.thermal_gap = sub.GetFloat();
                        break;
                    }
                    index++;
                }

                return(result);
            }
            else
            {
                return(null);  // error
            }
        }