예제 #1
0
파일: gr_line.cs 프로젝트: cjsatuforc/eakit
        //  (gr_line (start 77.47 39.37) (end 77.47 62.23) (angle 90) (layer Dwgs.User) (width 0.14986))
        public static gr_line Parse(SExpression root_node)
        {
            gr_line result = new gr_line();

            foreach (SExpression node in root_node.Items)
            {
                if (node.Name == "start")
                {
                    float x = float.Parse((node.Items[0] as SNodeAtom).Value);
                    float y = float.Parse((node.Items[1] as SNodeAtom).Value);

                    result.start = new PointF(x, y);
                }
                else if (node.Name == "end")
                {
                    float x = float.Parse((node.Items[0] as SNodeAtom).Value);
                    float y = float.Parse((node.Items[1] as SNodeAtom).Value);

                    result.end = new PointF(x, y);
                }
                else if (node.Name == "layer")
                {
                    result.layer = (node.Items[0] as SNodeAtom).Value;
                }
                else if (node.Name == "width")
                {
                    result.width = (node.Items[0] as SNodeAtom).AsFloat;
                }
            }
            return(result);
        }
예제 #2
0
        public void Render(Canvas canvas)
        {
            canvas.color_background = Color.Black;

            // units in mm?
            canvas.Min          = new PointF(0, 0);
            canvas.Max          = new PointF(297, 210);
            canvas.grid_spacing = 10;

            canvas.Ydir = 1; // +ve Y is down the page

            canvas.Initialise();

            foreach (graphic_base node in this.Drawings)
            {
                if (node is gr_line)
                {
                    gr_line gr_line = node as gr_line;

                    Point sp1 = canvas.ToScreen(gr_line.start);
                    Point sp2 = canvas.ToScreen(gr_line.end);

                    Pen pen = new Pen(GetColorFromLayer(gr_line.layer));
                    canvas.g.DrawLine(pen, sp1, sp2);
                }
                else if (node is gr_text)
                {
                    gr_text text = node as gr_text;

                    Point sp1  = canvas.ToScreen(text.Position.At);
                    Font  font = new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel);

                    canvas.g.DrawString(text.Value, font, Brushes.White, sp1);
                }
            }
        }
예제 #3
0
        public bool LoadFromFile(string filename)
        {
            bool result = false;

            RootNode.LoadFromFile(filename);

            UnParsed = new List <SExpression>();

            if (RootNode.Name == "kicad_pcb")
            {
                SNodeBase pcb_node = RootNode;

                SExpression pcb_items = (pcb_node as SExpression);

                foreach (SExpression node in pcb_items.Items)
                {
                    string name = node.Name;

                    if (name == "gr_line")
                    {
                        //
                        gr_line g = gr_line.Parse(node);
                        if (Drawings == null)
                        {
                            Drawings = new List <graphic_base>();
                        }
                        Drawings.Add(g);
                    }
                    else if (name == "gr_text")
                    {
                        //
                        gr_text g = gr_text.Parse(node);
                        if (Drawings == null)
                        {
                            Drawings = new List <graphic_base>();
                        }
                        Drawings.Add(g);
                    }
                    else if (name == "gr_arc")
                    {
                        gr_arc g = gr_arc.Parse(node);
                        if (Drawings == null)
                        {
                            Drawings = new List <graphic_base>();
                        }
                        Drawings.Add(g);
                    }
                    else if (name == "gr_circle")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "module")
                    {
                        Module module = Module.Parse(node);
                        if (Modules == null)
                        {
                            Modules = new List <Module>();
                        }
                        Modules.Add(module);
                    }
                    else if (name == "version")
                    {
                        FileVersion = node.GetString();
                    }
                    else if (name == "host")
                    {
                        Host_Name    = (node.Items[0] as SNodeAtom).Value;
                        Host_Version = (node.Items[1] as SNodeAtom).Value;
                    }
                    else if (name == "general")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "page")
                    {
                        Page = node.GetString();
                    }
                    else if (name == "title_block")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "layers")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "setup")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "net")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "net_class")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "dimension")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "segment")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "via")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else if (name == "zone")
                    {
                        Trace("LoadPcb: todo: {0}", name);
                    }
                    else
                    {
                        Trace("LoadPcb: unrecognised: {0}", name);
                    }
                }
            }

            return(result);
        }