1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-22 18:28:59 +02:00

eeshow/: change file name handling from positional to be extension-driven

This also enables versioning for page layouts.
We no longer need the option -P.
This commit is contained in:
Werner Almesberger 2016-08-22 20:47:06 -03:00
parent e6a4224d81
commit 1b250bd467
7 changed files with 74 additions and 67 deletions

View File

@ -131,7 +131,7 @@ neo900.pdf: $(NAME) sch2pdf neo900-template.fig
$(NEO900_HW)/neo900.sch
pdf: $(NAME)
./eeshow -r -P $(NEO900_HW)/neo900pageframe_A3.kicad_wks \
./eeshow -r $(NEO900_HW)/neo900pageframe_A3.kicad_wks \
neo900.lib kicad-libs/components/powered.lib \
$(NEO900_HW)/neo900.sch -- pdf -o neo900.pdf

View File

@ -52,9 +52,11 @@ struct gui_hist {
struct gui_sheet *sheets; /* NULL if failed */
unsigned age; /* 0-based; uncommitted or HEAD = 0 */
struct pl_ctx *pl; /* NULL if none or failed */
/* caching support */
void **oids; /* file object IDs */
int libs_open;
unsigned libs_open;
struct sch_ctx sch_ctx;
struct lib lib; /* combined library */
bool identical; /* identical with previous entry */
@ -68,8 +70,6 @@ struct gui_ctx {
float scale; /* pixels = eeschema * scale */
int x, y; /* center, in eeschema coordinates */
struct pl_ctx *pl; // @@@
struct gui_hist *hist; /* revision history; NULL if none */
struct hist *vcs_hist; /* underlying VCS data; NULL if none */

View File

@ -30,6 +30,7 @@
#include "misc/util.h"
#include "misc/diag.h"
#include "file/git-hist.h"
#include "kicad/ext.h"
#include "kicad/pl.h"
#include "kicad/lib.h"
#include "kicad/sch.h"
@ -212,12 +213,13 @@ static struct gui_sheet *get_sheets(struct gui_ctx *ctx, struct gui_hist *hist,
*/
static const struct sheet *parse_files(struct gui_hist *hist,
int n_args, char **args, bool recurse, struct gui_hist *prev)
const struct file_names *fn, bool recurse, struct gui_hist *prev)
{
char *rev = NULL;
struct file sch_file;
struct file lib_files[n_args - 1];
int libs_open, i;
struct file lib_files[fn->n_libs];
struct file pl_file;
unsigned libs_open, i;
bool libs_cached = 0;
bool ok;
@ -225,7 +227,7 @@ static const struct sheet *parse_files(struct gui_hist *hist,
rev = vcs_git_get_rev(hist->vcs_hist);
sch_init(&hist->sch_ctx, recurse);
ok = file_open_revision(&sch_file, rev, args[n_args - 1], NULL);
ok = file_open_revision(&sch_file, rev, fn->sch, NULL);
if (rev)
free(rev);
@ -235,11 +237,22 @@ static const struct sheet *parse_files(struct gui_hist *hist,
}
lib_init(&hist->lib);
for (libs_open = 0; libs_open != n_args - 1; libs_open++)
if (!file_open(lib_files + libs_open, args[libs_open],
for (libs_open = 0; libs_open != fn->n_libs; libs_open++)
if (!file_open(lib_files + libs_open, fn->libs[libs_open],
&sch_file))
goto fail;
if (fn->pl) {
if (!file_open(&pl_file, fn->pl, &sch_file))
goto fail;
hist->pl = pl_parse(&pl_file);
file_close(&pl_file);
/*
* We treat failing to parse the page layout as a "minor"
* failure and don't reject the revision just because of it.
*/
}
if (hist->vcs_hist) {
hist->oids = alloc_type_n(void *, libs_open);
hist->libs_open = libs_open;
@ -293,8 +306,7 @@ fail:
struct add_hist_ctx {
struct gui_ctx *ctx;
int n_args;
char **args;
const struct file_names *fn;
bool recurse;
unsigned limit;
};
@ -324,7 +336,8 @@ static void add_hist(void *user, struct hist *h)
hist->vcs_hist = h;
hist->libs_open = 0;
hist->identical = 0;
sch = parse_files(hist, ahc->n_args, ahc->args, ahc->recurse, prev);
hist->pl = NULL;
sch = parse_files(hist, ahc->fn, ahc->recurse, prev);
hist->sheets = sch ? get_sheets(ctx, hist, sch) : NULL;
hist->age = age;
@ -336,13 +349,12 @@ static void add_hist(void *user, struct hist *h)
}
static void get_revisions(struct gui_ctx *ctx,
int n_args, char **args, bool recurse, int limit)
static void get_revisions(struct gui_ctx *ctx, const struct file_names *fn,
bool recurse, int limit)
{
struct add_hist_ctx add_hist_ctx = {
.ctx = ctx,
.n_args = n_args,
.args = args,
.fn = fn,
.recurse = recurse,
.limit = limit ? limit < 0 ? -limit : limit : -1,
};
@ -383,14 +395,12 @@ static void get_history(struct gui_ctx *ctx, const char *sch_name, int limit)
/* ----- Initialization ---------------------------------------------------- */
int gui(unsigned n_args, char **args, bool recurse, int limit,
struct pl_ctx *pl)
int gui(const struct file_names *fn, bool recurse, int limit)
{
GtkWidget *window;
char *title;
struct gui_ctx ctx = {
.scale = 1 / 16.0,
.pl = pl, // @@@
.hist = NULL,
.vcs_hist = NULL,
.showing_history= 0,
@ -422,11 +432,11 @@ int gui(unsigned n_args, char **args, bool recurse, int limit,
gtk_widget_show_all(window);
get_history(&ctx, args[n_args - 1], limit);
get_history(&ctx, fn->sch, limit);
if (ctx.hist_size)
setup_progress_bar(&ctx, window);
get_revisions(&ctx, n_args, args, recurse, limit);
get_revisions(&ctx, fn, recurse, limit);
for (ctx.new_hist = ctx.hist; ctx.new_hist && !ctx.new_hist->sheets;
ctx.new_hist = ctx.new_hist->next);
if (!ctx.new_hist)

View File

@ -15,12 +15,9 @@
#include <stdbool.h>
/*
* Note: this isn't (argc, argv) ! args stars right with the first file name
* and there is no NULL at the end.
*/
#include "kicad/ext.h"
int gui(unsigned n_args, char **args, bool recurse, int limit,
struct pl_ctx *pl);
int gui(const struct file_names *fn, bool recurse, int limit);
#endif /* !GUI_GUI_H */

View File

@ -231,8 +231,8 @@ void render_sheet(struct gui_sheet *sheet)
char *argv[] = { "gui", NULL };
gfx_init(&cro_canvas_ops, 1, argv);
if (sheet->ctx && sheet->ctx->pl) /* @@@ no pl_render for delta */
pl_render(sheet->ctx->pl, sheet->hist->sch_ctx.sheets,
if (sheet->hist && sheet->hist->pl) /* @@@ no pl_render for delta */
pl_render(sheet->hist->pl, sheet->hist->sch_ctx.sheets,
sheet->sch);
sch_render(sheet->sch);
cro_canvas_end(gfx_ctx,

View File

@ -1,5 +1,5 @@
/*
* main.c - Convert Eeschema schematics to FIG
* main.c - Visualize and convert Eeschema schematics
*
* Written 2016 by Werner Almesberger
* Copyright 2016 by Werner Almesberger
@ -26,6 +26,7 @@
#include "gfx/diff.h"
#include "gfx/gfx.h"
#include "file/file.h"
#include "kicad/ext.h"
#include "kicad/sexpr.h"
#include "kicad/pl.h"
#include "kicad/lib.h"
@ -60,12 +61,12 @@ static void sexpr(void)
exit(1);
}
void usage(const char *name)
{
fprintf(stderr,
"usage: %s [gtk_flags] [-r] [-N n] [[rev:]file.lib ...] [rev:]file.sch\n"
" %s [-r] [-v ...] [[rev:]file.lib ...] [rev:]file.sch\n"
"usage: %s [gtk_flags] [-r] [-N n] kicad_file ...\n"
" %s [-r] [-v ...] kicad_file ...\n"
" %*s[-- driver_spec]\n"
" %s [-v ...] -C [rev:]file\n"
" %s [-v ...] -H path_into_repo\n"
@ -73,7 +74,10 @@ void usage(const char *name)
" %s -V\n"
" %s gdb ...\n"
"\n"
" rev git revision\n"
" kicad_file [rev:]file.ext\n"
" ext .lib, .sch, or .kicad_wks\n"
" rev git revision\n"
"\n"
" -r recurse into sub-sheets\n"
" -v increase verbosity of diagnostic output\n"
" -C 'cat' the file to standard output\n"
@ -121,12 +125,13 @@ int main(int argc, char **argv)
const char *cat = NULL;
const char *history = NULL;
const char *fmt = NULL;
const char *page_layout = NULL;
struct pl_ctx *pl = NULL;
int limit = 0;
char c;
int arg, dashdash;
int dashdash;
unsigned i;
bool have_dashdash = 0;
struct file_names file_names;
int gfx_argc;
char **gfx_argv;
const struct gfx_ops **ops = ops_list;
@ -153,7 +158,7 @@ int main(int argc, char **argv)
if (!have_dashdash)
gtk_init(&argc, &argv);
while ((c = getopt(dashdash, argv, "P:rvC:F:H:N:SV")) != EOF)
while ((c = getopt(dashdash, argv, "rvC:F:H:N:SV")) != EOF)
switch (c) {
case 'r':
recurse = 1;
@ -173,9 +178,6 @@ int main(int argc, char **argv)
case 'N':
limit = atoi(optarg);
break;
case 'P':
page_layout = optarg;
break;
case 'S':
sexpr();
return 0;
@ -215,10 +217,31 @@ int main(int argc, char **argv)
return 0;
}
if (page_layout) {
if (dashdash - optind < 1)
usage(*argv);
classify_files(&file_names, argv + optind, dashdash - optind);
if (!file_names.sch)
fatal("top sheet name required");
if (!have_dashdash) {
optind = 0; /* reset getopt */
return gui(&file_names, recurse, limit);
}
sch_init(&sch_ctx, recurse);
if (!file_open(&sch_file, file_names.sch, NULL))
return 1;
lib_init(&lib);
for (i = 0; i != file_names.n_libs; i++)
if (!lib_parse(&lib, file_names.libs[i], &sch_file))
return 1;
if (file_names.pl) {
struct file file;
if (!file_open(&file, page_layout, NULL))
if (!file_open(&file, file_names.pl, &sch_file))
return 1;
pl = pl_parse(&file);
file_close(&file);
@ -226,29 +249,6 @@ int main(int argc, char **argv)
return 1;
}
if (dashdash - optind < 1)
usage(*argv);
if (!have_dashdash) {
unsigned n = argc - optind;
char **args;
args = alloc_type_n(char *, n);
memcpy(args, argv + optind, sizeof(const char *) * n);
optind = 0; /* reset getopt */
return gui(n, args, recurse, limit, pl);
}
sch_init(&sch_ctx, recurse);
if (!file_open(&sch_file, argv[dashdash - 1], NULL))
return 1;
lib_init(&lib);
for (arg = optind; arg != dashdash - 1; arg++)
if (!lib_parse(&lib, argv[arg], &sch_file))
return 1;
if (dashdash == argc) {
gfx_argc = 1;
gfx_argv = alloc_type_n(char *, 2);

View File

@ -1,5 +1,5 @@
/*
* main.h - Convert Eeschema schematics to FIG
* main.h - Visualize and convert Eeschema schematics
*
* Written 2016 by Werner Almesberger
* Copyright 2016 by Werner Almesberger