public static Dimension Parse(SExpression root_node) { Dimension result; if ((root_node is SExpression) && ((root_node as SExpression).Name == "dimension")) { result = new Dimension(); int index = 0; // while (index < root_node.Items.Count) { SNodeBase node = root_node.Items[index]; SExpression sub = node as SExpression; switch (sub.Name) { case "at": //todo: get all the things break; } index++; } return(result); } else { return(null); // error } }
public static General Parse(SNodeBase node) { General result = new General(); if ((node is SExpression) && ((node as SExpression).Name == "fp_text")) { SExpression expr = node as SExpression; result.links = (expr.Items[0] as SNodeAtom).AsInt; result.no_connects = (expr.Items[1] as SNodeAtom).AsInt; result.area = (expr.Items[2] as SExpression).GetRectF(); result.thickness = (expr.Items[3] as SNodeAtom).AsFloat; result.drawings = (expr.Items[4] as SNodeAtom).AsInt; result.tracks = (expr.Items[5] as SNodeAtom).AsInt; result.zones = (expr.Items[6] as SNodeAtom).AsInt; result.modules = (expr.Items[7] as SNodeAtom).AsInt; result.nets = (expr.Items[8] as SNodeAtom).AsInt; return(result); } else { return(null); // error } }
public static DimensionFeature Parse(SExpression root_node) { DimensionFeature result; if ((root_node is SExpression) && (feature_names.Find(x => x == (root_node as SExpression).Name) != null)) { result = new DimensionFeature(); int index = 0; result.Name = (root_node as SExpression).Name; // while (index < root_node.Items.Count) { SNodeBase node = root_node.Items[index]; SExpression sub = node as SExpression; switch (sub.Name) { case "pts": //TODO: get points break; } index++; } return(result); } else { return(null); // error } }
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 } }
public static Via Parse(SExpression root_node) { Via result; if ((root_node is SExpression) && ((root_node as SExpression).Name == "via")) { result = new Via(); int index = 0; // while (index < root_node.Items.Count) { SNodeBase node = root_node.Items[index]; SExpression sub = node as SExpression; switch (sub.Name) { case "at": { float x = float.Parse((sub.Items[0] as SNodeAtom).Value); float y = float.Parse((sub.Items[1] as SNodeAtom).Value); result.at = new PointF(x, y); } break; case "size": result.size = sub.GetFloat(); break; case "drill": result.drill = sub.GetFloat(); break; case "layers": result.topmost_layer = sub.GetString(0); result.topmost_layer = sub.GetString(1); break; case "net": result.net = sub.GetInt(); break; case "tstamp": result.tstamp = sub.GetUintHex(); break; } index++; } return(result); } else { return(null); // error } }
// e.g (layers F.Cu F.Paste F.Mask) public void ParseLayers(SNodeBase node) { Layers.Clear(); if ((node is SExpression) && ((node as SExpression).Name == "layers")) { SExpression expr = node as SExpression; foreach (SNodeAtom atom in expr.Items) { AddLayer(atom.Value); } } }
public static fp_text Parse(SNodeBase node) { fp_text result = new fp_text(); if ((node is SExpression) && ((node as SExpression).Name == "fp_text")) { SExpression expr = node as SExpression; result.Type = (expr.Items[0] as SNodeAtom).Value; result.Value = (expr.Items[1] as SNodeAtom).Value; int index = 2; while (index < expr.Items.Count) { if (expr.Items[index] is SExpression) { SExpression sub = expr.Items[index] as SExpression; if (sub.Name == "at") { result.position = Position.Parse(sub); } else if (sub.Name == "effects") { result.effects = TextEffects.Parse(sub); } else if (sub.Name == "layer") { result.layer = Layer.ParseLayer(sub); } } else { SNodeAtom atom = expr.Items[index] as SNodeAtom; if (atom.Value == "hide") { result.visible = false; } } index++; } return(result); } else { return(null); // error } }
public static LibEntry Parse(SExpression root_node) { LibEntry result = null; if (root_node.Name == "lib") { result = new LibEntry(); int index = 0; // while (index < root_node.Items.Count) { SNodeBase node = root_node.Items[index]; SExpression sub = node as SExpression; switch (sub.Name) { case "name": result.Name = sub.GetString(); break; case "type": result.Type = sub.GetString(); break; case "uri": result.Uri = sub.GetString(); break; case "options": result.Options = sub.GetString(); break; case "descr": result.Description = sub.GetString(); break; } index++; } return(result); } else { return(null); // error } }
public static fp_line Parse(SNodeBase node) { fp_line result = new fp_line(); if ((node is SExpression) && ((node as SExpression).Name == "fp_line")) { SExpression expr = node as SExpression; result.start = (expr.Items[0] as SExpression).GetPointF(); result.end = (expr.Items[1] as SExpression).GetPointF(); result.layer = Layer.ParseLayer(expr.Items[2]); result.width = (expr.Items[3] as SExpression).GetFloat(); return(result); } else { return(null); // error } }
public static Net Parse(SNodeBase node) { Net result; if ((node is SExpression) && ((node as SExpression).Name == "net")) { result = new Net(); SExpression expr = node as SExpression; int index = 0; result.Number = (expr.Items[index++] as SNodeAtom).AsInt; result.Name = (expr.Items[index++] as SNodeAtom).Value; return(result); } else { return(null); // error } }
// parsing // parse single layer // e.g (layer F.SilkS) public static string ParseLayer(SNodeBase node) { if ((node is SExpression) && ((node as SExpression).Name == "layer")) { SExpression expr = node as SExpression; string result = ""; foreach (SNodeAtom atom in expr.Items) { if (result != "") { result += "|"; } result += atom.Value; } return(result); } else { return(""); // error } }
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); }
public static Zone Parse(SExpression root_node) { Zone result; if ((root_node is SExpression) && ((root_node as SExpression).Name == "zone")) { result = new Zone(); int index = 0; // while (index < root_node.Items.Count) { SNodeBase node = root_node.Items[index]; SExpression sub = node as SExpression; switch (sub.Name) { case "net": result.net = sub.GetInt(); break; case "net_name": result.net_name = sub.GetString(); break; case "layer": result.layer = sub.GetString(); break; case "tstamp": result.tstamp = sub.GetUintHex(); break; case "hatch": { switch (sub.GetString()) { case "none": result.outline_style = ZoneOutlineStyle.none; break; case "edge": result.outline_style = ZoneOutlineStyle.edge; break; case "full": result.outline_style = ZoneOutlineStyle.full; break; } result.hatch_pitch = sub.GetFloat(1); } break; case "connect_pads": //todo break; case "min_thickness": result.min_thickness = sub.GetFloat(); break; case "fill": //todo break; case "polygon": //todo break; } index++; } return(result); } else { return(null); // error } }
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); }
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 } }
// public static TextEffects Parse(SNodeBase node) { if ((node is SExpression) && ((node as SExpression).Name == "effects")) { SExpression expr = node as SExpression; TextEffects result = new TextEffects(); int index = 0; while (index < expr.Items.Count) { SExpression sexpr = expr.Items[index] as SExpression; // justify: horiz_align, mirror switch (sexpr.Name) { case "font": result.font = FontAttributes.Parse(expr.Items[0] as SExpression); break; case "justify": foreach (SNodeBase s2 in sexpr.Items) { if (s2 is SNodeAtom) { SNodeAtom atom = s2 as SNodeAtom; switch (atom.Value) { case "mirror": result.mirror = true; break; case "left": result.horiz_align = TextJustify.left; break; case "right": result.horiz_align = TextJustify.right; break; case "top": result.vert_align = VerticalAlign.top; break; case "bottom": result.vert_align = VerticalAlign.bottom; break; } } } break; } index++; } return(result); } else { return(null); // error } }