Root/
| 1 | /* |
| 2 | * kicad/sch.h - Parse Eeschema .sch file |
| 3 | * |
| 4 | * Written 2016 by Werner Almesberger |
| 5 | * Copyright 2016 by Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #ifndef KICAD_SCH_H |
| 15 | #define KICAD_SCH_H |
| 16 | |
| 17 | #include <stdbool.h> |
| 18 | |
| 19 | #include "kicad/dwg.h" |
| 20 | #include "gfx/text.h" |
| 21 | #include "file/file.h" |
| 22 | #include "kicad/lib.h" |
| 23 | |
| 24 | |
| 25 | enum sch_state { |
| 26 | sch_basic, /* basic state */ |
| 27 | sch_descr, /* prelude and description */ |
| 28 | sch_comp, /* component */ |
| 29 | sch_sheet, /* sub-sheet */ |
| 30 | sch_text, /* text or label */ |
| 31 | sch_wire, /* wire */ |
| 32 | sch_eof, /* skipping anything after $EndSCHEMATC */ |
| 33 | }; |
| 34 | |
| 35 | struct sheet; |
| 36 | |
| 37 | struct sch_obj { |
| 38 | enum sch_obj_type { |
| 39 | sch_obj_wire, |
| 40 | sch_obj_junction, |
| 41 | sch_obj_noconn, |
| 42 | sch_obj_text, |
| 43 | sch_obj_glabel, |
| 44 | sch_obj_comp, |
| 45 | sch_obj_sheet, |
| 46 | } type; |
| 47 | |
| 48 | int x, y; |
| 49 | |
| 50 | union { |
| 51 | struct sch_wire { |
| 52 | void (*fn)(int sx, int sy, int ex, int ey); |
| 53 | int ex, ey; |
| 54 | } wire; |
| 55 | struct sch_text { |
| 56 | void (*fn)(int x, int y, const char *s, |
| 57 | int dir, int dim, enum dwg_shape shape, |
| 58 | struct dwg_bbox *bbox); |
| 59 | const char *s; |
| 60 | int dir; /* orientation */ |
| 61 | int dim; /* dimension */ |
| 62 | enum dwg_shape shape; |
| 63 | struct dwg_bbox bbox; /* set when rendering; glabel */ |
| 64 | } text; |
| 65 | struct sch_comp { |
| 66 | const struct comp *comp; /* current component */ |
| 67 | unsigned unit; /* unit of current component */ |
| 68 | unsigned convert;/* "De Morgan" selection */ |
| 69 | struct comp_field { |
| 70 | struct text txt; |
| 71 | struct comp_field *next; |
| 72 | } *fields; |
| 73 | int m[6]; |
| 74 | } comp; |
| 75 | struct sch_sheet { |
| 76 | unsigned h, w; |
| 77 | const char *name; |
| 78 | unsigned name_dim; |
| 79 | const char *file; |
| 80 | unsigned file_dim; |
| 81 | bool rotated; |
| 82 | bool error; /* if set, sheet == NULL */ |
| 83 | const struct sheet *sheet; |
| 84 | /* pointer to sub-sheet; NULL if absent */ |
| 85 | |
| 86 | struct sheet_field { |
| 87 | char *s; |
| 88 | int x, y; |
| 89 | unsigned dim; |
| 90 | enum dwg_shape shape; |
| 91 | unsigned side; |
| 92 | struct sheet_field *next; |
| 93 | } *fields; |
| 94 | } sheet; |
| 95 | } u; |
| 96 | |
| 97 | struct sch_obj *next; |
| 98 | }; |
| 99 | |
| 100 | struct sheet { |
| 101 | const char *title; /* malloced, unless delta */ |
| 102 | struct sch_obj *objs; |
| 103 | struct sch_obj **next_obj; |
| 104 | struct sheet *next; |
| 105 | |
| 106 | int w, h; |
| 107 | |
| 108 | bool has_children; /* aka sub-sheets */ |
| 109 | |
| 110 | /* caching */ |
| 111 | void *oid; |
| 112 | }; |
| 113 | |
| 114 | struct sch_ctx { |
| 115 | enum sch_state state; |
| 116 | |
| 117 | bool recurse; |
| 118 | |
| 119 | struct sch_obj obj; |
| 120 | |
| 121 | struct sheet *curr_sheet; |
| 122 | struct sheet *sheets; |
| 123 | struct sheet **next_sheet; |
| 124 | |
| 125 | /* for caching */ |
| 126 | const struct sch_ctx *prev; |
| 127 | |
| 128 | const struct lib *lib; |
| 129 | }; |
| 130 | |
| 131 | |
| 132 | void decode_alignment(struct text *txt, char hor, char vert); |
| 133 | |
| 134 | void sch_render(const struct sheet *sheet); |
| 135 | bool sch_parse(struct sch_ctx *ctx, struct file *file, const struct lib *lib, |
| 136 | const struct sch_ctx *prev); |
| 137 | void sch_init(struct sch_ctx *ctx, bool recurse); |
| 138 | void sch_free(struct sch_ctx *ctx); |
| 139 | |
| 140 | #endif /* !KICAD_SCH_H */ |
| 141 |
Branches:
master
