1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-22 18:44:59 +02:00

Finished deletion. Assorted bug fixes.

- columns can now be deleted/undeleted
- reset active row if deleting that row
- grammar now accepts an empty file
- when a non-canvas entry becomes editable, we set the focus to it
- when adding the first reference to a frame, make it active
- when deleting the active reference to a frame, set the pointer to NULL
- measurements didn't have a drag_new action, causing trying to create them to
  crash fped
- offset field of measurements was incorrectly labeled "width"
- fixed operator precedence in gridify. Someone needs more sleep :-(



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5398 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2009-08-07 00:48:06 +00:00
parent 766efce919
commit 605bd52dc9
9 changed files with 125 additions and 44 deletions

7
TODO
View File

@ -1,6 +1,5 @@
Missing features: Missing features:
- populate input area (still needed: mm/mil, rezoom) - populate input area (still needed: mm/mil, rezoom)
- add table/var/loop editor (missing: add col/row, add/del var/table/loop)
- add default unit (combine with grid unit selection ?) - add default unit (combine with grid unit selection ?)
- consider adding auto/mm/mil selection for each dimension - consider adding auto/mm/mil selection for each dimension
- add measurements (partly done. still needed: find out how to define - add measurements (partly done. still needed: find out how to define
@ -8,6 +7,10 @@ Missing features:
- add KiCad output - add KiCad output
- add postscript output - add postscript output
- add option to include/omit helper vecs and frames (display and postscript) - add option to include/omit helper vecs and frames (display and postscript)
- reorder frames (can use text editor)
- reorder rows in a table (can use text editor)
- reorder columns in a table
- reorder variables in a frame (can use text editor)
Error detection: Error detection:
- eliminate duplicate instances - eliminate duplicate instances
@ -16,10 +19,12 @@ Style:
- make column of entry field greedily consume all unallocated space - make column of entry field greedily consume all unallocated space
- status area looks awful - status area looks awful
- add button with GTK_STOCK_UNDELETE for "undelete" to menu bar - add button with GTK_STOCK_UNDELETE for "undelete" to menu bar
- edit names/values/etc. in place if possible
Bugs: Bugs:
- default silk width has no business being hard-coded in obj.c - default silk width has no business being hard-coded in obj.c
- undelete only works if not much has changed since the deletion - undelete only works if not much has changed since the deletion
- re-center while dragging confuses the save-under mechanism
Code cleanup: Code cleanup:
- merge edit_unique with edit_name - merge edit_unique with edit_name

View File

@ -52,7 +52,7 @@ static struct deletion {
struct row *ref; struct row *ref;
struct row *prev; struct row *prev;
} row; } row;
struct { struct column {
struct var *var; struct var *var;
struct value *values; struct value *values;
struct table *table; struct table *table;
@ -187,7 +187,8 @@ static void destroy_obj(struct obj *obj)
{ {
switch (obj->type) { switch (obj->type) {
case ot_frame: case ot_frame:
/* nothing */ if (obj->u.frame.ref->active_ref == obj)
obj->u.frame.ref->active_ref = NULL;
break; break;
case ot_pad: case ot_pad:
free(obj->u.pad.name); free(obj->u.pad.name);
@ -288,7 +289,62 @@ static void undelete_row(struct row *row, struct row *prev)
void delete_column(struct table *table, int n) void delete_column(struct table *table, int n)
{ {
struct deletion *del;
struct column *col;
struct var **var;
struct row *row;
struct value **next, **value;
int i;
groups++; groups++;
del = new_deletion(dt_column);
col = &del->u.col;
col->table = table;
col->n = n;
var = &table->vars;
for (i = 0; i != n; i++)
var = &(*var)->next;
col->var = *var;
*var = (*var)->next;
next = &col->values;
for (row = table->rows; row; row = row->next) {
value = &row->values;
for (i = 0; i != n; i++)
value = &(*value)->next;
*next = *value;
*value = (*value)->next;
next = &(*next)->next;
}
*next = NULL;
}
static void undelete_column(const struct column *col)
{
struct var **var;
struct row *row;
struct value **anchor, *value, *next;
int i;
var = &col->table->vars;
for (i = 0; i != col->n; i++)
var = &(*var)->next;
col->var->next = *var;
*var = col->var;
value = col->values;
for (row = col->table->rows; row; row = row->next) {
anchor = &row->values;
for (i = 0; i != col->n; i++)
anchor = &(*anchor)->next;
next = value->next;
value->next = *anchor;
*anchor = value;
value = next;
}
} }
@ -471,6 +527,9 @@ static int undelete_one(void)
case dt_row: case dt_row:
undelete_row(del->u.row.ref, del->u.row.prev); undelete_row(del->u.row.ref, del->u.row.prev);
break; break;
case dt_column:
undelete_column(&del->u.col);
break;
default: default:
abort(); abort();
} }

20
fpd.y
View File

@ -162,19 +162,13 @@ static struct obj *new_obj(enum obj_type type)
%% %%
all: all:
START_FPD fpd START_FPD
| START_EXPR expr
{
expr_result = $2;
}
;
fpd:
{ {
root_frame = zalloc_type(struct frame); root_frame = zalloc_type(struct frame);
set_frame(root_frame); set_frame(root_frame);
} }
frame_defs part_name frame_items
fpd
{ {
root_frame->prev = last_frame; root_frame->prev = last_frame;
if (last_frame) if (last_frame)
@ -182,6 +176,14 @@ fpd:
else else
frames = root_frame; frames = root_frame;
} }
| START_EXPR expr
{
expr_result = $2;
}
;
fpd:
| frame_defs part_name frame_items
; ;
part_name: part_name:

5
fped.c
View File

@ -13,6 +13,7 @@
#include "cpp.h" #include "cpp.h"
#include "util.h"
#include "error.h" #include "error.h"
#include "obj.h" #include "obj.h"
#include "inst.h" #include "inst.h"
@ -46,6 +47,10 @@ int main(int argc, char **argv)
argc--; argc--;
argv++; argv++;
} }
if (!part_name)
part_name = stralloc("_");
reporter = report_to_stderr; reporter = report_to_stderr;
if (!instantiate()) if (!instantiate())
return 1; return 1;

14
gui.c
View File

@ -329,8 +329,11 @@ static void popup_add_row_by_value(void)
static void popup_del_row(void) static void popup_del_row(void)
{ {
struct value *value = popup_data; struct value *value = popup_data;
struct table *table = value->row->table;
delete_row(value->row); delete_row(value->row);
if (table->active_row == value->row)
table->active_row = table->rows;
change_world(); change_world();
} }
@ -341,7 +344,8 @@ static void popup_del_column_by_value(void)
const struct value *walk; const struct value *walk;
int n = 0; int n = 0;
for (walk = value->row->values; walk != value; walk = walk->next); for (walk = value->row->values; walk != value; walk = walk->next)
n++;
delete_column(value->row->table, n); delete_column(value->row->table, n);
change_world(); change_world();
} }
@ -530,7 +534,7 @@ static void edit_var(struct var *var)
label_in_box_bg(var->widget, COLOR_VAR_EDITING); label_in_box_bg(var->widget, COLOR_VAR_EDITING);
status_set_type_entry("name ="); status_set_type_entry("name =");
status_set_name("%s", var->name); status_set_name("%s", var->name);
edit_unique(&var->name, validate_var_name, var); edit_unique(&var->name, validate_var_name, var, 1);
} }
@ -551,7 +555,7 @@ static void edit_value(struct value *value)
{ {
inst_select_outside(value, unselect_value); inst_select_outside(value, unselect_value);
label_in_box_bg(value->widget, COLOR_EXPR_EDITING); label_in_box_bg(value->widget, COLOR_EXPR_EDITING);
edit_expr(&value->expr); edit_expr(&value->expr, 1);
} }
@ -954,7 +958,7 @@ static gboolean part_name_edit_event(GtkWidget *widget, GdkEventButton *event,
label_in_box_bg(widget, COLOR_PART_NAME_EDITING); label_in_box_bg(widget, COLOR_PART_NAME_EDITING);
status_set_type_entry("part ="); status_set_type_entry("part =");
status_set_name("%s", part_name); status_set_name("%s", part_name);
edit_name(&part_name, validate_part_name, NULL); edit_name(&part_name, validate_part_name, NULL, 1);
break; break;
} }
return TRUE; return TRUE;
@ -1015,7 +1019,7 @@ static void edit_frame(struct frame *frame)
label_in_box_bg(frame->label, COLOR_FRAME_EDITING); label_in_box_bg(frame->label, COLOR_FRAME_EDITING);
status_set_type_entry("name ="); status_set_type_entry("name =");
status_set_name("%s", frame->name); status_set_name("%s", frame->name);
edit_unique(&frame->name, validate_frame_name, frame); edit_unique(&frame->name, validate_frame_name, frame, 1);
} }

View File

@ -110,10 +110,12 @@ static void entry_color(GtkWidget *widget, const char *color)
static void setup_edit(GtkWidget *widget, const char *s, static void setup_edit(GtkWidget *widget, const char *s,
struct edit_ops *ops, void *ctx) struct edit_ops *ops, void *ctx, int focus)
{ {
gtk_entry_set_text(GTK_ENTRY(widget), s); gtk_entry_set_text(GTK_ENTRY(widget), s);
entry_color(widget, COLOR_EDIT_ASIS); entry_color(widget, COLOR_EDIT_ASIS);
if (focus)
gtk_widget_grab_focus(GTK_WIDGET(widget));
gtk_widget_show(widget); gtk_widget_show(widget);
gtk_object_set_data(GTK_OBJECT(widget), "edit-ops", ops); gtk_object_set_data(GTK_OBJECT(widget), "edit-ops", ops);
gtk_object_set_data(GTK_OBJECT(widget), "edit-ctx", ctx); gtk_object_set_data(GTK_OBJECT(widget), "edit-ctx", ctx);
@ -165,14 +167,14 @@ static struct edit_ops edit_ops_unique = {
void edit_unique(const char **s, int (*validate)(const char *s, void *ctx), void edit_unique(const char **s, int (*validate)(const char *s, void *ctx),
void *ctx) void *ctx, int focus)
{ {
static struct edit_unique_ctx unique_ctx; static struct edit_unique_ctx unique_ctx;
unique_ctx.s = s; unique_ctx.s = s;
unique_ctx.validate = validate; unique_ctx.validate = validate;
unique_ctx.ctx = ctx; unique_ctx.ctx = ctx;
setup_edit(status_entry, *s, &edit_ops_unique, &unique_ctx); setup_edit(status_entry, *s, &edit_ops_unique, &unique_ctx, focus);
} }
@ -221,7 +223,7 @@ static struct edit_ops edit_ops_null_unique = {
void edit_unique_null(const char **s, void edit_unique_null(const char **s,
int (*validate)(const char *s, void *ctx), void *ctx) int (*validate)(const char *s, void *ctx), void *ctx, int focus)
{ {
static struct edit_unique_ctx unique_ctx; static struct edit_unique_ctx unique_ctx;
@ -229,7 +231,7 @@ void edit_unique_null(const char **s,
unique_ctx.validate = validate; unique_ctx.validate = validate;
unique_ctx.ctx = ctx; unique_ctx.ctx = ctx;
setup_edit(status_entry, *s ? *s : "", setup_edit(status_entry, *s ? *s : "",
&edit_ops_null_unique, &unique_ctx); &edit_ops_null_unique, &unique_ctx, focus);
} }
@ -277,14 +279,15 @@ static struct edit_ops edit_ops_name = {
}; };
void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx) void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx,
int focus)
{ {
static struct edit_name_ctx name_ctx; static struct edit_name_ctx name_ctx;
name_ctx.s = s; name_ctx.s = s;
name_ctx.validate = validate; name_ctx.validate = validate;
name_ctx.ctx = ctx; name_ctx.ctx = ctx;
setup_edit(status_entry, *s, &edit_ops_name, &name_ctx); setup_edit(status_entry, *s, &edit_ops_name, &name_ctx, focus);
} }
@ -335,31 +338,31 @@ static struct edit_ops edit_ops_expr = {
}; };
static void edit_any_expr(GtkWidget *widget, struct expr **expr) static void edit_any_expr(GtkWidget *widget, struct expr **expr, int focus)
{ {
char *s; char *s;
s = unparse(*expr); s = unparse(*expr);
setup_edit(widget, s, &edit_ops_expr, expr); setup_edit(widget, s, &edit_ops_expr, expr, focus);
free(s); free(s);
} }
void edit_expr(struct expr **expr) void edit_expr(struct expr **expr, int focus)
{ {
edit_any_expr(status_entry, expr); edit_any_expr(status_entry, expr, focus);
} }
void edit_x(struct expr **expr) void edit_x(struct expr **expr)
{ {
edit_any_expr(status_entry_x, expr); edit_any_expr(status_entry_x, expr, 0);
} }
void edit_y(struct expr **expr) void edit_y(struct expr **expr)
{ {
edit_any_expr(status_entry_y, expr); edit_any_expr(status_entry_y, expr, 0);
} }

View File

@ -21,11 +21,12 @@
void edit_unique(const char **s, int (*validate)(const char *s, void *ctx), void edit_unique(const char **s, int (*validate)(const char *s, void *ctx),
void *ctx); void *ctx, int focus);
void edit_unique_null(const char **s, int (*validate)(const char *s, void *ctx), void edit_unique_null(const char **s, int (*validate)(const char *s, void *ctx),
void *ctx); void *ctx, int focus);
void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx); void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx,
void edit_expr(struct expr **expr); int focus);
void edit_expr(struct expr **expr, int focus);
void edit_x(struct expr **expr); void edit_x(struct expr **expr);
void edit_y(struct expr **expr); void edit_y(struct expr **expr);
void edit_nothing(void); void edit_nothing(void);

View File

@ -168,8 +168,8 @@ static struct coord gridify(struct coord base, struct coord pos)
struct coord new; struct coord new;
unit_type unit = mm_to_units(0.1); unit_type unit = mm_to_units(0.1);
new.x = pos.x-(pos.x-base.x % unit); new.x = pos.x-((pos.x-base.x) % unit);
new.y = pos.y-(pos.y-base.y % unit); new.y = pos.y-((pos.y-base.y) % unit);
if (new.x != base.x || new.y != base.y) if (new.x != base.x || new.y != base.y)
return new; return new;
if (fabs(pos.x-base.x) > fabs(pos.y-base.y)) if (fabs(pos.x-base.x) > fabs(pos.y-base.y))
@ -494,7 +494,7 @@ static int end_new_meas(struct draw_ctx *ctx,
static struct tool_ops meas_ops = { static struct tool_ops meas_ops = {
.drag_new = NULL, .drag_new = drag_new_line,
.end_new = end_new_meas, .end_new = end_new_meas,
}; };
@ -588,6 +588,8 @@ static int end_new_frame(struct draw_ctx *ctx,
obj = new_obj(ot_frame, from); obj = new_obj(ot_frame, from);
obj->u.frame.ref = locked_frame; obj->u.frame.ref = locked_frame;
obj->u.frame.lineno = 0; obj->u.frame.lineno = 0;
if (!locked_frame->active_ref)
locked_frame->active_ref = obj;
locked_frame = NULL; locked_frame = NULL;
tool_frame_update(); tool_frame_update();
return 1; return 1;

14
inst.c
View File

@ -353,7 +353,7 @@ static void vec_op_select(struct inst *self)
status_set_type_entry("ref ="); status_set_type_entry("ref =");
status_set_name("%s", self->vec->name ? self->vec->name : ""); status_set_name("%s", self->vec->name ? self->vec->name : "");
rect_status(self->base, self->u.rect.end, -1); rect_status(self->base, self->u.rect.end, -1);
edit_unique_null(&self->vec->name, validate_vec_name, self->vec); edit_unique_null(&self->vec->name, validate_vec_name, self->vec, 0);
edit_x(&self->vec->x); edit_x(&self->vec->x);
edit_y(&self->vec->y); edit_y(&self->vec->y);
} }
@ -404,7 +404,7 @@ static void line_op_debug(struct inst *self)
static void line_op_select(struct inst *self) static void line_op_select(struct inst *self)
{ {
rect_status(self->bbox.min, self->bbox.max, self->u.rect.width); rect_status(self->bbox.min, self->bbox.max, self->u.rect.width);
edit_expr(&self->obj->u.line.width); edit_expr(&self->obj->u.line.width, 0);
} }
@ -457,7 +457,7 @@ static void rect_op_debug(struct inst *self)
static void rect_op_select(struct inst *self) static void rect_op_select(struct inst *self)
{ {
rect_status(self->bbox.min, self->bbox.max, self->u.rect.width); rect_status(self->bbox.min, self->bbox.max, self->u.rect.width);
edit_expr(&self->obj->u.rect.width); edit_expr(&self->obj->u.rect.width, 0);
} }
@ -514,7 +514,7 @@ static void pad_op_select(struct inst *self)
status_set_type_entry("label ="); status_set_type_entry("label =");
status_set_name("%s", self->u.pad.name); status_set_name("%s", self->u.pad.name);
rect_status(self->base, self->u.pad.other, -1); rect_status(self->base, self->u.pad.other, -1);
edit_name(&self->obj->u.pad.name, validate_pad_name, NULL); edit_name(&self->obj->u.pad.name, validate_pad_name, NULL, 0);
} }
@ -572,7 +572,7 @@ static void arc_op_select(struct inst *self)
status_set_r("r = %5.2f mm", units_to_mm(self->u.arc.r)); status_set_r("r = %5.2f mm", units_to_mm(self->u.arc.r));
status_set_type_entry("width ="); status_set_type_entry("width =");
status_set_name("%5.2f mm", units_to_mm(self->u.arc.width)); status_set_name("%5.2f mm", units_to_mm(self->u.arc.width));
edit_expr(&self->obj->u.arc.width); edit_expr(&self->obj->u.arc.width, 0);
} }
@ -638,9 +638,9 @@ static void meas_op_debug(struct inst *self)
static void meas_op_select(struct inst *self) static void meas_op_select(struct inst *self)
{ {
rect_status(self->bbox.min, self->bbox.max, -1); rect_status(self->bbox.min, self->bbox.max, -1);
status_set_type_entry("width ="); status_set_type_entry("offset =");
status_set_name("%5.2f mm", units_to_mm(self->u.meas.offset)); status_set_name("%5.2f mm", units_to_mm(self->u.meas.offset));
edit_expr(&self->obj->u.meas.offset); edit_expr(&self->obj->u.meas.offset, 0);
} }