Ejemplo n.º 1
0
        public static PcbSegment Parse(SExpression root_node)
        {
            PcbSegment result;

            if ((root_node is SExpression) && ((root_node as SExpression).Name == "segment"))
            {
                result = new PcbSegment();
                int index = 0;

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

                    switch (sub.Name)
                    {
                    case "start":
                    {
                        float x = float.Parse((sub.Items[0] as SNodeAtom).Value);
                        float y = float.Parse((sub.Items[1] as SNodeAtom).Value);
                        result.start = new PointF(x, y);
                    }
                    break;

                    case "end":
                    {
                        float x = float.Parse((sub.Items[0] as SNodeAtom).Value);
                        float y = float.Parse((sub.Items[1] as SNodeAtom).Value);
                        result.end = new PointF(x, y);
                    }
                    break;

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

                    case "layer":
                        result.layer = sub.GetString();
                        break;

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

                    case "tstamp":
                        result.tstamp = sub.GetUintHex();
                        break;
                    }
                    index++;
                }

                return(result);
            }
            else
            {
                return(null);  // error
            }
        }
Ejemplo n.º 2
0
        public void SaveToFile(string filename)
        {
            filename = Path.ChangeExtension(filename, "kicad_pcb");

            if (Drawings == null)
            {
                General.drawings = 0;
            }
            else
            {
                General.drawings = Drawings.Count;
            }

            if (Modules == null)
            {
                General.modules = 0;
            }
            else
            {
                General.modules = Modules.Count;
            }

            if (Nets == null)
            {
                General.nets = 0;
            }
            else
            {
                General.nets = Nets.Count;
            }

            //

            RootNode = new SExpression();
            List <SExpression> sex_list;
            List <SNodeBase>   node_list;

            RootNode.Name  = "kicad_pcb";
            RootNode.Items = new List <SNodeBase>();

            RootNode.Items.Add(new SExpression("version", new List <SNodeBase>()
            {
                new SNodeAtom(FileVersion)
            }));
            RootNode.Items.Add(new SExpression("host", new List <SNodeBase>()
            {
                new SNodeAtom(Host_Name), new SNodeAtom(Host_Version)
            }));
            RootNode.Items.Add(General.GetSExpression());

            node_list = new List <SNodeBase>();
            node_list.Add(new SNodeAtom(Page));
            if (PageMode != PageMode.landscape)
            {
                node_list.Add(new SNodeAtom(PageMode.ToString()));
            }
            RootNode.Items.Add(new SExpression("page", node_list));

            RootNode.Items.Add(PcbLayer.GetSExpression(Layers));
            RootNode.Items.Add(Setup.GetSExpression());

            sex_list = Net.GetSExpressionList(Nets);
            foreach (SExpression sex in sex_list)
            {
                RootNode.Items.Add(sex);
            }

            sex_list = NetClass.GetSExpressionList(NetClasses);
            foreach (SExpression sex in sex_list)
            {
                RootNode.Items.Add(sex);
            }

            if (Modules != null)
            {
                sex_list = Module.GetSExpressionList(Modules);
                foreach (SExpression sex in sex_list)
                {
                    RootNode.Items.Add(sex);
                }
            }

            if (Drawings != null)
            {
                sex_list = graphic_base.GetSExpressionList(Drawings);
                foreach (SExpression sex in sex_list)
                {
                    RootNode.Items.Add(sex);
                }
            }

            if (Segments != null)
            {
                sex_list = PcbSegment.GetSExpressionList(Segments);
                foreach (SExpression sex in sex_list)
                {
                    RootNode.Items.Add(sex);
                }
            }

            if (Zones != null)
            {
                sex_list = Zone.GetSExpressionList(Zones);
                foreach (SExpression sex in sex_list)
                {
                    RootNode.Items.Add(sex);
                }
            }

            if (Vias != null)
            {
                sex_list = Via.GetSExpressionList(Vias);
                foreach (SExpression sex in sex_list)
                {
                    RootNode.Items.Add(sex);
                }
            }

            if (Dimensions != null)
            {
                sex_list = Dimension.GetSExpressionList(Dimensions);
                foreach (SExpression sex in sex_list)
                {
                    RootNode.Items.Add(sex);
                }
            }

            //
            RootNode.WriteToFile(filename);
        }