2016-08-02 17:00:08 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SCH_H
|
|
|
|
#define SCH_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "dwg.h"
|
|
|
|
#include "text.h"
|
2016-08-18 03:07:13 +03:00
|
|
|
#include "file/file.h"
|
2016-08-02 17:00:08 +03:00
|
|
|
#include "lib.h"
|
|
|
|
|
|
|
|
|
|
|
|
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-08-06 02:41:35 +03:00
|
|
|
sch_eof, /* skipping anything after $EndSCHEMATC */
|
2016-08-02 17:00:08 +03:00
|
|
|
};
|
|
|
|
|
2016-08-03 17:53:03 +03:00
|
|
|
struct sheet;
|
|
|
|
|
2016-08-02 17:00:08 +03:00
|
|
|
struct sch_obj {
|
|
|
|
enum sch_obj_type {
|
|
|
|
sch_obj_wire,
|
|
|
|
sch_obj_junction,
|
|
|
|
sch_obj_noconn,
|
|
|
|
sch_obj_text,
|
2016-08-11 02:49:01 +03:00
|
|
|
sch_obj_glabel,
|
2016-08-02 17:00:08 +03:00
|
|
|
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,
|
2016-08-11 03:50:07 +03:00
|
|
|
int dir, int dim, enum dwg_shape shape,
|
|
|
|
struct dwg_bbox *bbox);
|
2016-08-02 17:00:08 +03:00
|
|
|
const char *s;
|
|
|
|
int dir; /* orientation */
|
|
|
|
int dim; /* dimension */
|
|
|
|
enum dwg_shape shape;
|
2016-08-11 03:50:07 +03:00
|
|
|
struct dwg_bbox bbox; /* set when rendering; glabel */
|
2016-08-02 17:00:08 +03:00
|
|
|
} text;
|
|
|
|
struct sch_comp {
|
|
|
|
const struct comp *comp; /* current component */
|
|
|
|
unsigned unit; /* unit of current component */
|
2016-08-16 07:47:07 +03:00
|
|
|
unsigned convert;/* "De Morgan" selection */
|
2016-08-02 17:00:08 +03:00
|
|
|
struct comp_field {
|
|
|
|
struct text txt;
|
|
|
|
struct comp_field *next;
|
|
|
|
} *fields;
|
|
|
|
int m[6];
|
|
|
|
} comp;
|
|
|
|
struct sch_sheet {
|
|
|
|
unsigned h, w;
|
2016-08-03 17:46:24 +03:00
|
|
|
const char *name;
|
|
|
|
unsigned name_dim;
|
2016-08-02 17:00:08 +03:00
|
|
|
const char *file;
|
|
|
|
unsigned file_dim;
|
|
|
|
bool rotated;
|
2016-08-16 10:07:42 +03:00
|
|
|
bool error; /* if set, sheet == NULL */
|
2016-08-06 02:25:58 +03:00
|
|
|
const struct sheet *sheet;
|
|
|
|
/* pointer to sub-sheet; NULL if absent */
|
2016-08-02 17:00:08 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sheet {
|
2016-08-06 02:25:58 +03:00
|
|
|
const char *title; /* malloced, unless delta */
|
2016-08-02 17:00:08 +03:00
|
|
|
struct sch_obj *objs;
|
2016-08-02 23:12:33 +03:00
|
|
|
struct sch_obj **next_obj;
|
2016-08-02 17:00:08 +03:00
|
|
|
struct sheet *next;
|
2016-08-10 22:33:40 +03:00
|
|
|
|
2016-08-11 00:57:04 +03:00
|
|
|
bool has_children; /* aka sub-sheets */
|
|
|
|
|
|
|
|
/* caching */
|
|
|
|
void *oid;
|
2016-08-02 17:00:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sch_ctx {
|
|
|
|
enum sch_state state;
|
|
|
|
|
|
|
|
bool recurse;
|
|
|
|
|
|
|
|
struct sch_obj obj;
|
|
|
|
|
2016-08-02 23:12:33 +03:00
|
|
|
struct sheet *curr_sheet;
|
2016-08-02 17:00:08 +03:00
|
|
|
struct sheet *sheets;
|
|
|
|
struct sheet **next_sheet;
|
|
|
|
|
2016-08-11 00:57:04 +03:00
|
|
|
/* for caching */
|
|
|
|
const struct sch_ctx *prev;
|
|
|
|
|
2016-08-02 17:00:08 +03:00
|
|
|
const struct lib *lib;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void decode_alignment(struct text *txt, char hor, char vert);
|
|
|
|
|
|
|
|
void sch_render(const struct sheet *sheet);
|
2016-08-11 00:57:04 +03:00
|
|
|
bool sch_parse(struct sch_ctx *ctx, struct file *file, const struct lib *lib,
|
|
|
|
const struct sch_ctx *prev);
|
2016-08-02 17:00:08 +03:00
|
|
|
void sch_init(struct sch_ctx *ctx, bool recurse);
|
2016-08-06 02:25:58 +03:00
|
|
|
void sch_free(struct sch_ctx *ctx);
|
2016-08-02 17:00:08 +03:00
|
|
|
|
|
|
|
#endif /* !SCH_H */
|