2009-08-03 19:12:47 +03:00
|
|
|
/*
|
|
|
|
* inst.h - Instance structures
|
|
|
|
*
|
|
|
|
* Written 2009 by Werner Almesberger
|
|
|
|
* Copyright 2009 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 INST_H
|
|
|
|
#define INST_H
|
|
|
|
|
2009-09-13 12:58:30 +03:00
|
|
|
#include <stdint.h>
|
2009-08-03 19:12:47 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "coord.h"
|
|
|
|
#include "obj.h"
|
2009-08-07 16:37:51 +03:00
|
|
|
#include "meas.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
enum mode {
|
|
|
|
mode_inactive, /* on inactive frame */
|
|
|
|
mode_active, /* on active frame */
|
|
|
|
mode_selected, /* item is selected */
|
2009-08-04 15:06:04 +03:00
|
|
|
mode_hover, /* hovering over item's contact area */
|
2009-08-03 19:12:47 +03:00
|
|
|
mode_n /* number of modes */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bbox {
|
|
|
|
struct coord min;
|
|
|
|
struct coord max;
|
|
|
|
};
|
|
|
|
|
2009-08-11 00:02:26 +03:00
|
|
|
|
|
|
|
enum inst_prio {
|
|
|
|
ip_frame, /* frames have their own selection */
|
2009-09-13 14:11:03 +03:00
|
|
|
ip_pad_copper, /* pads also accept clicks inside; pads with copper */
|
|
|
|
ip_pad_special, /* pads with only solder paste or mask, on top */
|
2009-08-11 00:02:26 +03:00
|
|
|
ip_circ, /* circles don't overlap easily */
|
2009-10-19 18:00:30 +03:00
|
|
|
ip_arc, /* arcs are like circles, just shorter */
|
2009-08-11 00:02:26 +03:00
|
|
|
ip_rect, /* rectangles have plenty of sides */
|
|
|
|
ip_meas, /* mesurements are like lines but set a bit apart */
|
|
|
|
ip_line, /* lines are easly overlapped by other things */
|
|
|
|
ip_vec, /* vectors only have the end point */
|
|
|
|
ip_n, /* number of priorities */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
struct inst;
|
|
|
|
|
2009-08-11 00:02:26 +03:00
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
struct inst_ops {
|
|
|
|
void (*debug)(struct inst *self);
|
|
|
|
void (*save)(FILE *file, struct inst *self);
|
|
|
|
void (*draw)(struct inst *self);
|
|
|
|
struct pix_buf *(*hover)(struct inst *self);
|
|
|
|
unit_type (*distance)(struct inst *self, struct coord pos,
|
|
|
|
unit_type scale);
|
|
|
|
void (*select)(struct inst *self);
|
|
|
|
int (*anchors)(struct inst *self, struct vec ***anchors);
|
|
|
|
void (*begin_drag_move)(struct inst *from, int i);
|
|
|
|
struct inst *(*find_point)(struct inst *self, struct coord pos);
|
|
|
|
struct pix_buf *(*draw_move)(struct inst *inst,
|
|
|
|
struct coord pos, int i);
|
|
|
|
void (*end_drag_move)(void);
|
|
|
|
/* arcs and measurements need this special override */
|
|
|
|
void (*do_move_to)(struct inst *inst, struct inst *to, int i);
|
|
|
|
};
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
struct inst {
|
|
|
|
const struct inst_ops *ops;
|
|
|
|
struct coord base;
|
|
|
|
struct bbox bbox;
|
2009-08-12 13:45:52 +03:00
|
|
|
struct vec *vec; /* NULL if not vector */
|
|
|
|
struct obj *obj; /* NULL if not object */
|
2009-08-03 19:12:47 +03:00
|
|
|
struct inst *outer; /* frame containing this item */
|
|
|
|
int active;
|
|
|
|
union {
|
2009-08-27 12:01:24 +03:00
|
|
|
struct {
|
|
|
|
int highlighted; /* for measurements */
|
|
|
|
struct coord end;
|
|
|
|
} vec;
|
2009-08-03 19:12:47 +03:00
|
|
|
struct {
|
2009-08-22 15:27:47 +03:00
|
|
|
struct frame *ref;
|
2009-08-04 21:03:06 +03:00
|
|
|
int active;
|
2009-08-03 19:12:47 +03:00
|
|
|
} frame;
|
|
|
|
const char *name;
|
|
|
|
struct {
|
|
|
|
unit_type width;
|
2009-08-27 12:01:24 +03:00
|
|
|
struct coord end;
|
2009-08-03 19:12:47 +03:00
|
|
|
} rect;
|
2009-08-05 00:45:33 +03:00
|
|
|
struct {
|
2009-08-21 11:34:17 +03:00
|
|
|
char *name;
|
2009-08-05 00:45:33 +03:00
|
|
|
struct coord other;
|
2009-09-13 12:58:30 +03:00
|
|
|
layer_type layers; /* bit-set of layers */
|
2009-08-05 00:45:33 +03:00
|
|
|
} pad;
|
2009-08-03 19:12:47 +03:00
|
|
|
struct {
|
|
|
|
unit_type r;
|
|
|
|
double a1, a2;
|
|
|
|
unit_type width;
|
|
|
|
} arc;
|
|
|
|
struct {
|
|
|
|
struct coord end;
|
|
|
|
double offset;
|
|
|
|
} meas;
|
|
|
|
} u;
|
|
|
|
struct inst *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-17 23:42:51 +03:00
|
|
|
struct pkg {
|
|
|
|
const char *name; /* NULL if global package */
|
|
|
|
struct inst *insts[ip_n];
|
|
|
|
struct inst **next_inst[ip_n];
|
|
|
|
struct sample **samples;
|
2009-08-18 23:52:09 +03:00
|
|
|
int n_samples;
|
2009-08-17 23:42:51 +03:00
|
|
|
struct pkg *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
extern struct inst *selected_inst;
|
2009-08-17 23:42:51 +03:00
|
|
|
extern struct pkg *pkgs; /* list of packages */
|
|
|
|
extern struct pkg *active_pkg; /* package selected in GUI */
|
|
|
|
extern struct pkg *curr_pkg; /* package currently being instantiated */
|
2009-08-04 00:52:21 +03:00
|
|
|
extern struct bbox active_frame_bbox;
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2009-08-17 23:42:51 +03:00
|
|
|
/*
|
|
|
|
* frame being instantiated - we need to export this one for meas.c, so that
|
|
|
|
* measurement scan update the root frame's bounding box.
|
|
|
|
*/
|
2009-09-13 14:11:03 +03:00
|
|
|
extern struct inst *curr_frame;
|
2009-08-17 23:42:51 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @@@ Note that we over-generalize a bit here: the only item that ever ends up
|
|
|
|
* in the global package is currently the root frame. However, we may later
|
|
|
|
* allow other items shared by all packages be there as well.
|
|
|
|
*/
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2009-08-19 01:03:51 +03:00
|
|
|
#define FOR_INST_PRIOS_UP(prio) \
|
2009-08-11 00:02:26 +03:00
|
|
|
for (prio = 0; prio != ip_n; prio++)
|
|
|
|
|
2009-08-19 01:03:51 +03:00
|
|
|
#define FOR_INST_PRIOS_DOWN(prio) \
|
2009-08-11 00:02:26 +03:00
|
|
|
for (prio = ip_n-1; prio != (enum inst_prio) -1; prio--)
|
|
|
|
|
2009-08-22 11:58:26 +03:00
|
|
|
#define FOR_PKG_INSTS(pkg, prio, inst) \
|
|
|
|
for (inst = (pkg)->insts[prio]; inst; inst = inst->next)
|
|
|
|
|
2009-08-19 01:03:51 +03:00
|
|
|
#define FOR_ALL_INSTS(i, prio, inst) \
|
|
|
|
for (i = 0; i != 2; i++) \
|
2009-08-22 11:58:26 +03:00
|
|
|
FOR_PKG_INSTS(i ? active_pkg : pkgs, prio, inst)
|
2009-08-11 00:02:26 +03:00
|
|
|
|
|
|
|
|
2009-08-22 22:00:55 +03:00
|
|
|
int bright(const struct inst *inst);
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
void inst_select_outside(void *item, void (*deselect)(void *item));
|
2009-08-08 17:11:26 +03:00
|
|
|
int inst_select(struct coord pos);
|
2009-08-03 19:12:47 +03:00
|
|
|
void inst_deselect(void);
|
|
|
|
|
2009-08-13 13:57:39 +03:00
|
|
|
void inst_select_vec(struct vec *vec);
|
|
|
|
void inst_select_obj(struct obj *obj);
|
2009-08-12 14:26:59 +03:00
|
|
|
|
2009-08-08 17:11:26 +03:00
|
|
|
struct inst *inst_find_point(struct coord pos);
|
2009-08-10 16:51:51 +03:00
|
|
|
int inst_find_point_selected(struct coord pos, struct inst **res);
|
2009-08-04 15:06:04 +03:00
|
|
|
struct coord inst_get_point(const struct inst *inst);
|
2009-08-04 21:03:06 +03:00
|
|
|
int inst_anchors(struct inst *inst, struct vec ***anchors);
|
|
|
|
struct vec *inst_get_vec(const struct inst *inst);
|
2009-08-04 15:06:04 +03:00
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
int inst_vec(struct vec *vec, struct coord base);
|
|
|
|
int inst_line(struct obj *obj, struct coord a, struct coord b, unit_type width);
|
|
|
|
int inst_rect(struct obj *obj, struct coord a, struct coord b, unit_type width);
|
|
|
|
int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b);
|
|
|
|
int inst_arc(struct obj *obj, struct coord center, struct coord start,
|
|
|
|
struct coord stop, unit_type width);
|
2009-08-21 21:20:37 +03:00
|
|
|
int inst_meas(struct obj *obj, struct coord from, struct coord to);
|
|
|
|
void inst_meas_hint(struct obj *obj, unit_type offset);
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
void inst_begin_active(int active);
|
|
|
|
void inst_end_active(void);
|
|
|
|
|
2009-08-22 15:27:47 +03:00
|
|
|
void inst_begin_frame(struct obj *obj, struct frame *frame,
|
2009-08-05 03:32:38 +03:00
|
|
|
struct coord base, int active, int is_active_frame);
|
2009-08-03 19:12:47 +03:00
|
|
|
void inst_end_frame(const struct frame *frame);
|
|
|
|
|
2009-08-17 23:42:51 +03:00
|
|
|
void inst_select_pkg(const char *name);
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
struct bbox inst_get_bbox(void);
|
|
|
|
|
|
|
|
void inst_start(void);
|
|
|
|
void inst_commit(void);
|
|
|
|
void inst_revert(void);
|
|
|
|
|
2009-08-08 17:11:26 +03:00
|
|
|
void inst_draw(void);
|
|
|
|
void inst_highlight_vecs(int (*pick)(struct inst *inst, void *user),
|
|
|
|
void *user);
|
2009-08-08 21:50:17 +03:00
|
|
|
struct inst *inst_find_vec(struct coord pos,
|
|
|
|
int (*pick)(struct inst *inst, void *user), void *user);
|
|
|
|
struct inst *insts_ip_vec(void);
|
|
|
|
|
2009-08-08 17:11:26 +03:00
|
|
|
struct pix_buf *inst_draw_move(struct inst *inst, struct coord pos, int i);
|
2009-08-10 16:51:51 +03:00
|
|
|
int inst_do_move_to(struct inst *inst, struct inst *to, int i);
|
2009-08-08 17:11:26 +03:00
|
|
|
struct pix_buf *inst_hover(struct inst *inst);
|
2009-08-09 04:51:20 +03:00
|
|
|
void inst_begin_drag_move(struct inst *inst, int i);
|
2009-08-05 21:43:00 +03:00
|
|
|
void inst_delete(struct inst *inst);
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
#endif /* !INST_H */
|