예제 #1
0
        public static ComponentNetlist Parse(SExpression root_node)
        {
            ComponentNetlist result = new ComponentNetlist();

            foreach (SNodeBase item in root_node.Items)
            {
                if (item is SExpression)
                {
                    SExpression node = item as SExpression;
                    switch (node.Name)
                    {
                    case "ref":
                        result.Reference = node.GetValue();
                        break;

                    case "value":
                        result.Value = node.GetValue();
                        break;

                    case "footprint":
                        result.Footprint = node.GetValue();
                        break;

                    case "tstamp":
                        result.Timestamp = node.GetValue();
                        break;

                    case "libsource":
                        result.Symbol = PartSpecifier.Parse(node);
                        break;

                    case "sheetpath":
                        break;

                    case "fields":
                    {
                        result.Fields = new List <Field>();
                        foreach (SExpression sub in node.Items)
                        {
                            Field field = new Field();

                            SExpression name = (sub.Items[0] as SExpression);
                            field.Name  = (name.Items[0] as SNodeAtom).Value;
                            field.Value = (sub.Items[1] as SNodeAtom).Value;

                            result.Fields.Add(field);
                        }
                    }
                    break;
                    }
                }
                else if (item is SNodeList)
                {
                    SNodeList node = item as SNodeList;

                    result.Fields = new List <Field>();
                    foreach (SExpression sub in node.Items)
                    {
                        Field field = new Field();

                        SExpression name = (sub.Items[0] as SExpression);
                        field.Name  = (name.Items[0] as SNodeAtom).Value;
                        field.Value = (sub.Items[1] as SNodeAtom).Value;

                        result.Fields.Add(field);
                    }
                }
            }

            return(result);
        }
예제 #2
0
        public bool LoadFromFile(String Filename)
        {
            bool result = false;

            RootNode = new SExpression();
            RootNode.LoadFromFile(Filename);

            if (RootNode.Name == "export")
            {
                foreach (SNodeBase node in RootNode.Items)
                {
                    if (node is SExpression)
                    {
                        SExpression sexp = node as SExpression;
                        switch (sexp.Name)
                        {
                        case "version":
                            Version = sexp.GetValue();
                            break;

                        case "design":
                            break;

                        case "components":
                        {
                            foreach (SExpression sub_node in sexp.Items)
                            {
                                if (sub_node.Name == "comp")
                                {
                                    ComponentNetlist comp = ComponentNetlist.Parse(sub_node);
                                    if (Components == null)
                                    {
                                        Components = new List <ComponentBase>();
                                    }
                                    Components.Add(comp);
                                }
                            }
                        }
                        break;

                        case "libparts":
                            break;

                        case "libraries":
                        {
                            foreach (SExpression sub_node in sexp.Items)
                            {
                                if (sub_node.Name == "library")
                                {
                                    LibrarySpec lib = LibrarySpec.Parse(sub_node);
                                    if (Libraries == null)
                                    {
                                        Libraries = new List <LibrarySpec>();
                                    }
                                    Libraries.Add(lib);
                                }
                            }
                        }
                        break;

                        case "nets":
                            break;
                        }
                    }
                }
            }

            return(result);
        }