2016-07-22 06:04:42 +03:00
|
|
|
/*
|
|
|
|
* sch.h - Parse Eeschema .sch file
|
|
|
|
*
|
|
|
|
* Written 2016 by Werner Almesberger
|
|
|
|
* Copyright 2016 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-07-22 05:54:32 +03:00
|
|
|
#ifndef SCH_H
|
|
|
|
#define SCH_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2016-07-31 03:33:36 +03:00
|
|
|
#include "dwg.h"
|
2016-07-27 02:34:12 +03:00
|
|
|
#include "text.h"
|
2016-07-24 04:52:15 +03:00
|
|
|
#include "lib.h"
|
|
|
|
|
2016-07-22 05:54:32 +03:00
|
|
|
|
|
|
|
enum sch_state {
|
|
|
|
sch_basic, /* basic state */
|
|
|
|
sch_descr, /* prelude and description */
|
|
|
|
sch_comp, /* component */
|
|
|
|
sch_sheet, /* sub-sheet */
|
|
|
|
sch_text, /* text or label */
|
|
|
|
sch_wire, /* wire */
|
|
|
|
};
|
|
|
|
|
2016-07-31 07:48:31 +03:00
|
|
|
struct sch_obj {
|
|
|
|
enum sch_obj_type {
|
|
|
|
sch_obj_wire,
|
|
|
|
sch_obj_junction,
|
|
|
|
sch_obj_noconn,
|
|
|
|
sch_obj_text,
|
|
|
|
sch_obj_comp,
|
|
|
|
sch_obj_sheet,
|
|
|
|
} type;
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct sch_wire {
|
|
|
|
void (*fn)(int sx, int sy, int ex, int ey);
|
|
|
|
int ex, ey;
|
|
|
|
} wire;
|
|
|
|
struct sch_text {
|
|
|
|
void (*fn)(int x, int y, const char *s,
|
|
|
|
int dir, int dim, enum dwg_shape shape);
|
|
|
|
const char *s;
|
|
|
|
int dir; /* orientation */
|
|
|
|
int dim; /* dimension */
|
|
|
|
enum dwg_shape shape;
|
|
|
|
} text;
|
|
|
|
struct sch_comp {
|
|
|
|
const struct comp *comp; /* current component */
|
|
|
|
unsigned unit; /* unit of current component */
|
|
|
|
struct comp_field {
|
|
|
|
struct text txt;
|
|
|
|
struct comp_field *next;
|
|
|
|
} *fields;
|
|
|
|
int m[6];
|
|
|
|
} comp;
|
|
|
|
struct sch_sheet {
|
|
|
|
unsigned h, w;
|
|
|
|
const char *sheet;
|
|
|
|
unsigned sheet_dim;
|
|
|
|
const char *file;
|
|
|
|
unsigned file_dim;
|
|
|
|
bool rotated;
|
|
|
|
|
|
|
|
struct sheet_field {
|
|
|
|
char *s;
|
|
|
|
int x, y;
|
|
|
|
unsigned dim;
|
|
|
|
enum dwg_shape shape;
|
|
|
|
unsigned side;
|
|
|
|
struct sheet_field *next;
|
|
|
|
} *fields;
|
|
|
|
} sheet;
|
|
|
|
} u;
|
|
|
|
|
|
|
|
struct sch_obj *next;
|
|
|
|
};
|
|
|
|
|
2016-08-01 02:10:45 +03:00
|
|
|
struct sheet {
|
|
|
|
struct sch_obj *objs;
|
|
|
|
struct sheet *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sch_file {
|
|
|
|
const char *name;
|
|
|
|
int lineno;
|
|
|
|
struct sch_file *parent;
|
|
|
|
};
|
|
|
|
|
2016-07-22 05:54:32 +03:00
|
|
|
struct sch_ctx {
|
|
|
|
enum sch_state state;
|
2016-07-30 02:48:06 +03:00
|
|
|
|
2016-08-01 02:25:06 +03:00
|
|
|
bool recurse;
|
|
|
|
|
2016-07-31 07:48:31 +03:00
|
|
|
struct sch_obj obj;
|
2016-08-01 02:10:45 +03:00
|
|
|
struct sch_obj **next_obj;
|
|
|
|
|
|
|
|
struct sheet *sheets;
|
|
|
|
struct sheet **next_sheet;
|
2016-07-30 02:48:06 +03:00
|
|
|
|
2016-08-01 17:47:39 +03:00
|
|
|
const struct lib *lib;
|
|
|
|
|
2016-08-01 02:10:45 +03:00
|
|
|
struct sch_file *file;
|
2016-07-22 05:54:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-27 02:34:12 +03:00
|
|
|
void decode_alignment(struct text *txt, char hor, char vert);
|
|
|
|
|
2016-08-01 02:10:45 +03:00
|
|
|
void sch_render(const struct sheet *sheet);
|
2016-08-01 19:04:52 +03:00
|
|
|
void sch_parse(struct sch_ctx *ctx, const char *file, const struct lib *lib);
|
2016-08-01 02:25:06 +03:00
|
|
|
void sch_init(struct sch_ctx *ctx, bool recurse);
|
2016-07-22 05:54:32 +03:00
|
|
|
|
|
|
|
#endif /* !SCH_H */
|