Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 21219) +++ trunk/scconfig/Rev.h (revision 21220) @@ -1 +1 @@ -static const int myrev = 21183; +static const int myrev = 21220; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 21219) +++ trunk/scconfig/Rev.tab (revision 21220) @@ -1,4 +1,4 @@ -21183 configure new drc infra and GUI +21220 configure new drc infra and GUI 21098 configure old pinout dialog removal 20317 configure new core color infra 20260 configure plugin frame for ttf import Index: trunk/src/drc.h =================================================================== --- trunk/src/drc.h (revision 21219) +++ trunk/src/drc.h (nonexistent) @@ -1,85 +0,0 @@ -/* - * COPYRIGHT - * - * pcb-rnd, interactive printed circuit board design - * (this file is based on PCB, interactive printed circuit board design) - * Copyright (C) 1994,1995,1996, 2004 Thomas Nau - * 15 Oct 2008 Ineiev: add different crosshair shapes - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Contact: - * Project page: http://repo.hu/projects/pcb-rnd - * lead developer: http://repo.hu/projects/pcb-rnd/contact.html - * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") - * - */ -#ifndef PCB_DRC_H -#define PCB_DRC_H - -#include -#include "unit.h" -#include "idpath.h" -#include "box.h" - -typedef struct drc_violation_s pcb_drc_violation_t; -struct drc_violation_s { - unsigned long int uid; /* ID unique for each violation within the drc subsystem (for GUI identification of violations) */ - - char *type; - char *title; - char *explanation; - - unsigned have_coord:1; - pcb_coord_t x, y; /* center of error, for the indication */ - pcb_box_t bbox; /* bounding box of all error objects (in both groups) */ - - unsigned have_measured:1; - pcb_coord_t measured_value; - pcb_coord_t required_value; - - pcb_idpath_list_t objs[2]; /* two groups of offending objects */ - - gdl_elem_t link; /* always part of a list */ -}; - -/* List of drc violations */ -#define TDL(x) pcb_drc_list_ ## x -#define TDL_LIST_T pcb_drc_list_t -#define TDL_ITEM_T pcb_drc_violation_t -#define TDL_FIELD link -#define TDL_SIZE_T size_t -#define TDL_FUNC - -#define pcb_drc_list_foreach(list, iterator, loop_elem) \ - gdl_foreach_((&((list)->lst)), (iterator), (loop_elem)) - -#include -#include - -void pcb_drc_free(pcb_drc_violation_t *item); - -void pcb_drc_list_free_fields(pcb_drc_list_t *lst); -void pcb_drc_list_free(pcb_drc_list_t *lst); - -int pcb_drc_all(pcb_drc_list_t *lst); - -/* Slow, linear search for an UID in a list; returns NULL if not found */ -pcb_drc_violation_t *pcb_drc_by_uid(const pcb_drc_list_t *lst, unsigned long int uid); - -/* Zoom the drawing area to the drc error */ -void pcb_drc_goto(pcb_drc_violation_t *item); - -#endif Index: trunk/src/drc_list.c =================================================================== --- trunk/src/drc_list.c (revision 21219) +++ trunk/src/drc_list.c (nonexistent) @@ -1,89 +0,0 @@ -/* - * - * COPYRIGHT - * - * pcb-rnd, interactive printed circuit board design - * Copyright (C) 2018 Tibor 'Igor2' Palinkas - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Contact: - * Project page: http://repo.hu/projects/pcb-rnd - * lead developer: http://repo.hu/projects/pcb-rnd/contact.html - * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") - * - */ -#include "config.h" - -#define TDL_DONT_UNDEF -#include "drc.h" -#include -#undef TDL_DONT_UNDEF -#include - - -#include "actions.h" - - -void pcb_drc_free(pcb_drc_violation_t *item) -{ - pcb_drc_list_remove(item); - pcb_idpath_list_clear(&item->objs[0]); - pcb_idpath_list_clear(&item->objs[1]); - free(item->title); - free(item->explanation); - free(item); -} - -void pcb_drc_list_free_fields(pcb_drc_list_t *lst) -{ - for(;;) { - pcb_drc_violation_t *item = pcb_drc_list_first(lst); - if (item == NULL) - break; - pcb_drc_free(item); - } -} - -void pcb_drc_list_free(pcb_drc_list_t *lst) -{ - pcb_drc_list_free_fields(lst); - free(lst); -} - -pcb_drc_violation_t *pcb_drc_by_uid(const pcb_drc_list_t *lst, unsigned long int uid) -{ - pcb_drc_violation_t *v; - - for(v = pcb_drc_list_first((pcb_drc_list_t *)lst); v != NULL; v = pcb_drc_list_next(v)) - if (v->uid == uid) - return v; - - return NULL; -} - -void pcb_drc_goto(pcb_drc_violation_t *item) -{ - if (item->have_coord) { - fgw_arg_t res, argv[5]; - - argv[1].type = FGW_COORD; fgw_coord(&argv[1]) = item->bbox.X1; - argv[2].type = FGW_COORD; fgw_coord(&argv[2]) = item->bbox.Y1; - argv[3].type = FGW_COORD; fgw_coord(&argv[3]) = item->bbox.X2; - argv[4].type = FGW_COORD; fgw_coord(&argv[4]) = item->bbox.Y2; - pcb_actionv_bin("zoom", &res, 5, argv); - } -} - Index: trunk/src/Makefile.dep =================================================================== --- trunk/src/Makefile.dep (revision 21219) +++ trunk/src/Makefile.dep (revision 21220) @@ -443,7 +443,7 @@ paths.h ../src_plugins/dialogs/dlg_lib_pstk.c vtpadstack.h hid_inlines.h \ obj_text_draw.h draw.h obj_pstk_draw.h undo_old.h select.h \ ../src_plugins/dialogs/dlg_undo.c ../src_3rd/libuundo/uundo.h undo.h \ - undo_old.h ../src_plugins/dialogs/dlg_drc.h \ + undo_old.h ../src_plugins/dialogs/dlg_view.h \ ../src_plugins/dialogs/act_dad.h dolists.h ../src_plugins/dialogs/dlg_drc.o: ../src_plugins/dialogs/dlg_drc.c \ ../config.h ../src_3rd/genht/htsp.h ../src_3rd/genht/ht.h \ @@ -460,7 +460,7 @@ ../src_3rd/genvector/genvector_undef.h layer_grp.h \ ../src_3rd/libfungw/fungw.h ../src_3rd/genht/htpp.h conf_core.h conf.h \ pcb-printf.h ../src_3rd/liblihata/lihata.h ../src_3rd/genvector/vtp0.h \ - list_conf.h drc.h idpath.h draw.h hid_inlines.h hid_dad.h compat_misc.h \ + list_conf.h view.h idpath.h draw.h hid_inlines.h hid_dad.h compat_misc.h \ hid_attrib.h hid_dad_tree.h hid_dad.h ../src_plugins/distalign/distalign.o: \ ../src_plugins/distalign/distalign.c board.h ../config.h \ @@ -6130,7 +6130,7 @@ funchash_core.h funchash.h funchash_core_list.h obj_pstk_draw.h \ obj_line_draw.h obj_arc_draw.h obj_rat_draw.h obj_poly_draw.h \ obj_text_draw.h obj_subc_parent.h draw_composite.c draw_ly_spec.c -drc_list.o: drc_list.c ../config.h drc.h ../src_3rd/genlist/gendlist.h \ +drc_list.o: drc_list.c ../config.h view.h ../src_3rd/genlist/gendlist.h \ unit.h idpath.h ../src_3rd/genlist/gentdlist_impl.h \ ../src_3rd/genlist/gendlist.h ../src_3rd/genlist/gentdlist_undef.h \ obj_common.h flag.h globalconst.h attrib.h global_typedefs.h pcb_bool.h \ @@ -6224,7 +6224,7 @@ ../src_3rd/libuundo/uundo.h undo_old.h plug_io.h actions.h compat_misc.h \ event.h layer_vis.h obj_text_draw.h obj_subc_parent.h find_geo.c macro.h \ obj_arc_ui.h obj_pstk_inlines.h board.h rats_patch.h thermal.h \ - find_lookup.c compat_nls.h find_intconn.c find_drc.c drc.h idpath.h \ + find_lookup.c compat_nls.h find_intconn.c find_drc.c view.h idpath.h \ data_it.h obj_arc_draw.h obj_rat_draw.h obj_line_draw.h obj_poly_draw.h \ obj_pstk_draw.h find_misc.c change.h find_clear.c find_debug.c \ find_print.c find_any_isect.c Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 21219) +++ trunk/src/Makefile.in (revision 21220) @@ -71,7 +71,6 @@ crosshair.o data.o draw.o - drc_list.o error.o event.o font.o @@ -187,6 +186,7 @@ undo_act.o undo_old.o unit.o + view.o vtlibrary.o vtc0.o vtonpoint.o Index: trunk/src/find_drc.c =================================================================== --- trunk/src/find_drc.c (revision 21219) +++ trunk/src/find_drc.c (revision 21220) @@ -28,7 +28,7 @@ * */ -#include "drc.h" +#include "view.h" #include "compat_nls.h" #include "data_it.h" Index: trunk/src/view.c =================================================================== --- trunk/src/view.c (nonexistent) +++ trunk/src/view.c (revision 21220) @@ -0,0 +1,89 @@ +/* + * + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2018 Tibor 'Igor2' Palinkas + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + * + */ +#include "config.h" + +#define TDL_DONT_UNDEF +#include "view.h" +#include +#undef TDL_DONT_UNDEF +#include + + +#include "actions.h" + + +void pcb_drc_free(pcb_drc_violation_t *item) +{ + pcb_drc_list_remove(item); + pcb_idpath_list_clear(&item->objs[0]); + pcb_idpath_list_clear(&item->objs[1]); + free(item->title); + free(item->explanation); + free(item); +} + +void pcb_drc_list_free_fields(pcb_drc_list_t *lst) +{ + for(;;) { + pcb_drc_violation_t *item = pcb_drc_list_first(lst); + if (item == NULL) + break; + pcb_drc_free(item); + } +} + +void pcb_drc_list_free(pcb_drc_list_t *lst) +{ + pcb_drc_list_free_fields(lst); + free(lst); +} + +pcb_drc_violation_t *pcb_drc_by_uid(const pcb_drc_list_t *lst, unsigned long int uid) +{ + pcb_drc_violation_t *v; + + for(v = pcb_drc_list_first((pcb_drc_list_t *)lst); v != NULL; v = pcb_drc_list_next(v)) + if (v->uid == uid) + return v; + + return NULL; +} + +void pcb_drc_goto(pcb_drc_violation_t *item) +{ + if (item->have_coord) { + fgw_arg_t res, argv[5]; + + argv[1].type = FGW_COORD; fgw_coord(&argv[1]) = item->bbox.X1; + argv[2].type = FGW_COORD; fgw_coord(&argv[2]) = item->bbox.Y1; + argv[3].type = FGW_COORD; fgw_coord(&argv[3]) = item->bbox.X2; + argv[4].type = FGW_COORD; fgw_coord(&argv[4]) = item->bbox.Y2; + pcb_actionv_bin("zoom", &res, 5, argv); + } +} + Index: trunk/src/view.h =================================================================== --- trunk/src/view.h (nonexistent) +++ trunk/src/view.h (revision 21220) @@ -0,0 +1,85 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * (this file is based on PCB, interactive printed circuit board design) + * Copyright (C) 1994,1995,1996, 2004 Thomas Nau + * 15 Oct 2008 Ineiev: add different crosshair shapes + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + * + */ +#ifndef PCB_DRC_H +#define PCB_DRC_H + +#include +#include "unit.h" +#include "idpath.h" +#include "box.h" + +typedef struct drc_violation_s pcb_drc_violation_t; +struct drc_violation_s { + unsigned long int uid; /* ID unique for each violation within the drc subsystem (for GUI identification of violations) */ + + char *type; + char *title; + char *explanation; + + unsigned have_coord:1; + pcb_coord_t x, y; /* center of error, for the indication */ + pcb_box_t bbox; /* bounding box of all error objects (in both groups) */ + + unsigned have_measured:1; + pcb_coord_t measured_value; + pcb_coord_t required_value; + + pcb_idpath_list_t objs[2]; /* two groups of offending objects */ + + gdl_elem_t link; /* always part of a list */ +}; + +/* List of drc violations */ +#define TDL(x) pcb_drc_list_ ## x +#define TDL_LIST_T pcb_drc_list_t +#define TDL_ITEM_T pcb_drc_violation_t +#define TDL_FIELD link +#define TDL_SIZE_T size_t +#define TDL_FUNC + +#define pcb_drc_list_foreach(list, iterator, loop_elem) \ + gdl_foreach_((&((list)->lst)), (iterator), (loop_elem)) + +#include +#include + +void pcb_drc_free(pcb_drc_violation_t *item); + +void pcb_drc_list_free_fields(pcb_drc_list_t *lst); +void pcb_drc_list_free(pcb_drc_list_t *lst); + +int pcb_drc_all(pcb_drc_list_t *lst); + +/* Slow, linear search for an UID in a list; returns NULL if not found */ +pcb_drc_violation_t *pcb_drc_by_uid(const pcb_drc_list_t *lst, unsigned long int uid); + +/* Zoom the drawing area to the drc error */ +void pcb_drc_goto(pcb_drc_violation_t *item); + +#endif Index: trunk/src_plugins/dialogs/dlg_drc.c =================================================================== --- trunk/src_plugins/dialogs/dlg_drc.c (revision 21219) +++ trunk/src_plugins/dialogs/dlg_drc.c (nonexistent) @@ -1,336 +0,0 @@ -/* - * COPYRIGHT - * - * pcb-rnd, interactive printed circuit board design - * Copyright (C) 2018 Tibor 'Igor2' Palinkas - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact: - * Project page: http://repo.hu/projects/pcb-rnd - * lead developer: http://repo.hu/projects/pcb-rnd/contact.html - * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") - */ - -#include "config.h" - -#include -#include -#include - -#include "actions.h" -#include "board.h" -#include "conf_core.h" -#include "drc.h" -#include "draw.h" -#include "event.h" -#include "hid_inlines.h" -#include "hid_dad.h" -#include "hid_dad_tree.h" - -static const const char *drc_cookie = "dlg_drc"; - -typedef struct { - PCB_DAD_DECL_NOINIT(dlg) - pcb_board_t *pcb; - pcb_drc_list_t drc; - int alloced, active; - - unsigned long int selected; - - int wlist, wcount, wprev, wexplanation, wmeasure; -} drc_ctx_t; - -drc_ctx_t drc_ctx; - -static void drc_close_cb(void *caller_data, pcb_hid_attr_ev_t ev) -{ - drc_ctx_t *ctx = caller_data; - - - PCB_DAD_FREE(ctx->dlg); - if (ctx->alloced) - free(ctx); -} - -void drc2dlg(drc_ctx_t *ctx) -{ - char tmp[32]; - pcb_drc_violation_t *v; - pcb_hid_attribute_t *attr; - pcb_hid_tree_t *tree; - pcb_hid_row_t *r; - char *cell[3], *cursor_path = NULL; - - sprintf(tmp, "%d", pcb_drc_list_length(&ctx->drc)); - PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wcount, str_value, tmp); - - attr = &ctx->dlg[ctx->wlist]; - tree = (pcb_hid_tree_t *)attr->enumerations; - - /* remember cursor */ - r = pcb_dad_tree_get_selected(attr); - if (r != NULL) - cursor_path = pcb_strdup(r->cell[0]); - - /* remove existing items */ - for(r = gdl_first(&tree->rows); r != NULL; r = gdl_first(&tree->rows)) - pcb_dad_tree_remove(attr, r); - - /* add all items */ - cell[2] = NULL; - for(v = pcb_drc_list_first(&ctx->drc); v != NULL; v = pcb_drc_list_next(v)) { - pcb_hid_row_t *r, *rt; - rt = htsp_get(&tree->paths, v->type); - if (rt == NULL) { - cell[0] = pcb_strdup(v->type); - cell[1] = pcb_strdup(""); - rt = pcb_dad_tree_append(attr, NULL, cell); - rt->user_data2.lng = 0; - } - - cell[0] = pcb_strdup_printf("%lu", v->uid); - cell[1] = pcb_strdup(v->title); - r = pcb_dad_tree_append_under(attr, rt, cell); - r->user_data2.lng = v->uid; - } - - /* restore cursor */ - if (cursor_path != NULL) { - pcb_hid_attr_val_t hv; - hv.str_value = cursor_path; - pcb_gui->attr_dlg_set_value(ctx->dlg_hid_ctx, ctx->wlist, &hv); - free(cursor_path); - } -} - -static char *re_wrap(char *inp, int len) -{ - int cnt; - char *s, *lastspc = NULL; - for(s = inp, cnt = 0; *s != '\0'; s++,cnt++) { - if (*s == '\n') - *s = ' '; - if ((cnt >= len) && (lastspc != NULL)) { - cnt = 0; - *lastspc = '\n'; - lastspc = NULL; - } - else if (isspace(*s)) - lastspc = s; - } - return inp; -} - -static void drc_select(pcb_hid_attribute_t *attrib, void *hid_ctx, pcb_hid_row_t *row) -{ - pcb_hid_tree_t *tree = (pcb_hid_tree_t *)attrib->enumerations; - drc_ctx_t *ctx = tree->user_ctx; - pcb_drc_violation_t *v = NULL; - - if (row != NULL) { - ctx->selected = row->user_data2.lng; - v = pcb_drc_by_uid(&ctx->drc, ctx->selected); - if (v != NULL) { - pcb_drc_goto(v); - PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wexplanation, str_value, re_wrap(pcb_strdup(v->explanation), 32)); - if (v->have_measured) - PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wmeasure, str_value, pcb_strdup_printf("%m+required: %$ms\nmeasured: %$ms\n", conf_core.editor.grid_unit->allow, v->required_value, v->measured_value)); - else - PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wmeasure, str_value, pcb_strdup_printf("%m+required: %$ms\n", conf_core.editor.grid_unit->allow, v->required_value)); - } - } - - if (v == NULL) { - ctx->selected = 0; - PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wexplanation, str_value, pcb_strdup("")); - PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wmeasure, str_value, pcb_strdup("")); - } - - pcb_dad_preview_zoomto(&ctx->dlg[ctx->wprev], &v->bbox); -} - -static vtp0_t drc_color_save; - -static void drc_expose_cb(pcb_hid_attribute_t *attrib, pcb_hid_preview_t *prv, pcb_hid_gc_t gc, const pcb_hid_expose_ctx_t *e) -{ - drc_ctx_t *ctx = prv->user_ctx; - pcb_xform_t xform; - int old_termlab, g; - static const char *offend_color[] = {"#ff0000", "#0000ff"}; - pcb_drc_violation_t *v = pcb_drc_by_uid(&ctx->drc, ctx->selected); - size_t n; - void **p; - - if (v == NULL) - return; - - /* NOTE: zoom box was already set on select */ - - /* save offending object colors */ - vtp0_truncate(&drc_color_save, 0); - for(g = 0; g < 2; g++) { - pcb_idpath_t *i; - for(i = pcb_idpath_list_first(&v->objs[g]); i != NULL; /*i = pcb_idpath_list_next(i)*/i=0) { - pcb_any_obj_t *obj = pcb_idpath2obj(ctx->pcb->Data, i); - if ((obj != NULL) && (obj->type & PCB_OBJ_CLASS_REAL)) { - vtp0_append(&drc_color_save, obj); - if (obj->override_color != NULL) { - char *save = pcb_strdup(obj->override_color); - vtp0_append(&drc_color_save, save); - } - else - vtp0_append(&drc_color_save, NULL); - strcpy(obj->override_color, offend_color[g]); - } - } - } - - /* draw the board */ - old_termlab = pcb_draw_force_termlab; - pcb_draw_force_termlab = 1; - memset(&xform, 0, sizeof(xform)); - xform.layer_faded = 1; - pcb_hid_expose_all(pcb_gui, e, &xform); - pcb_draw_force_termlab = old_termlab; - - /* restore object color */ - for(n = 0, p = drc_color_save.array; n < drc_color_save.used; n+=2,p+=2) { - pcb_any_obj_t *obj = p[0]; - char *s = p[1]; - if (s != NULL) { - strcpy(obj->override_color, s); - free(s); - } - else - *obj->override_color = '\0'; - } - vtp0_truncate(&drc_color_save, 0); -} - - -static pcb_bool drc_mouse_cb(pcb_hid_attribute_t *attrib, pcb_hid_preview_t *prv, pcb_hid_mouse_ev_t kind, pcb_coord_t x, pcb_coord_t y) -{ - return pcb_false; /* don't redraw */ -} - - -static void drc_preview_update_cb(void *user_data, int argc, pcb_event_arg_t argv[]) -{ - drc_ctx_t *ctx = user_data; - pcb_hid_attr_val_t hv; - - if ((ctx == NULL) || (!ctx->active) || (ctx->selected == 0)) - return; - - hv.str_value = NULL; - pcb_gui->attr_dlg_set_value(ctx->dlg_hid_ctx, ctx->wprev, &hv); -} - - -static void pcb_dlg_drc(drc_ctx_t *ctx, const char *title) -{ - const char *hdr[] = { "ID", "title", NULL }; - - - PCB_DAD_BEGIN_VBOX(ctx->dlg); - PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); - - PCB_DAD_BEGIN_HPANE(ctx->dlg); - PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); - - /* left */ - PCB_DAD_BEGIN_VBOX(ctx->dlg); - PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); - - PCB_DAD_BEGIN_HBOX(ctx->dlg); - PCB_DAD_LABEL(ctx->dlg, "Number of violations:"); - PCB_DAD_LABEL(ctx->dlg, "n/a"); - ctx->wcount = PCB_DAD_CURRENT(ctx->dlg); - PCB_DAD_END(ctx->dlg); - - PCB_DAD_TREE(ctx->dlg, 2, 1, hdr); - PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_SCROLL | PCB_HATF_EXPFILL); - PCB_DAD_TREE_SET_CB(ctx->dlg, selected_cb, drc_select); - PCB_DAD_TREE_SET_CB(ctx->dlg, ctx, ctx); - ctx->wlist = PCB_DAD_CURRENT(ctx->dlg); - - PCB_DAD_BEGIN_HBOX(ctx->dlg); - PCB_DAD_BUTTON(ctx->dlg, "Copy"); - PCB_DAD_BUTTON(ctx->dlg, "Cut"); - PCB_DAD_BUTTON(ctx->dlg, "Del"); - PCB_DAD_END(ctx->dlg); - - PCB_DAD_BEGIN_HBOX(ctx->dlg); - PCB_DAD_BUTTON(ctx->dlg, "Paste before"); - PCB_DAD_BUTTON(ctx->dlg, "Paste after"); - PCB_DAD_END(ctx->dlg); - PCB_DAD_END(ctx->dlg); - - /* right */ - PCB_DAD_BEGIN_VBOX(ctx->dlg); - PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); - PCB_DAD_PREVIEW(ctx->dlg, drc_expose_cb, drc_mouse_cb, NULL, NULL, ctx); - ctx->wprev = PCB_DAD_CURRENT(ctx->dlg); - PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); - PCB_DAD_LABEL(ctx->dlg, "(explanation)"); - ctx->wexplanation = PCB_DAD_CURRENT(ctx->dlg); - PCB_DAD_LABEL(ctx->dlg, "(measure)"); - ctx->wmeasure = PCB_DAD_CURRENT(ctx->dlg); - PCB_DAD_END(ctx->dlg); - PCB_DAD_END(ctx->dlg); - - PCB_DAD_BEGIN_HBOX(ctx->dlg); - PCB_DAD_BUTTON(ctx->dlg, "Refresh"); - PCB_DAD_BEGIN_HBOX(ctx->dlg); - PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); - PCB_DAD_END(ctx->dlg); - PCB_DAD_BUTTON(ctx->dlg, "Close"); - PCB_DAD_END(ctx->dlg); - PCB_DAD_END(ctx->dlg); - - PCB_DAD_NEW(ctx->dlg, title, "", ctx, pcb_false, drc_close_cb); - - ctx->active = 1; -} - - -static drc_ctx_t drc_gui_ctx = {0}; -const char pcb_acts_DRC[] = "DRC()\n"; -const char pcb_acth_DRC[] = "Execute drc checks"; -fgw_error_t pcb_act_DRC(fgw_arg_t *ores, int oargc, fgw_arg_t *oargv) -{ - - if (!drc_gui_ctx.active) { - drc_gui_ctx.pcb = PCB; - pcb_dlg_drc(&drc_gui_ctx, "DRC violations"); - } - - pcb_drc_all(&drc_gui_ctx.drc); - drc2dlg(&drc_gui_ctx); - - return 0; -} - -void pcb_drc_dlg_uninit(void) -{ - pcb_event_unbind_allcookie(drc_cookie); - vtp0_uninit(&drc_color_save); -} - -void pcb_drc_dlg_init(void) -{ - pcb_event_bind(PCB_EVENT_USER_INPUT_POST, drc_preview_update_cb, &drc_gui_ctx, drc_cookie); -} Index: trunk/src_plugins/dialogs/dlg_drc.h =================================================================== --- trunk/src_plugins/dialogs/dlg_drc.h (revision 21219) +++ trunk/src_plugins/dialogs/dlg_drc.h (nonexistent) @@ -1,7 +0,0 @@ -extern const char pcb_acts_DRC[]; -extern const char pcb_acth_DRC[]; -fgw_error_t pcb_act_DRC(fgw_arg_t *ores, int oargc, fgw_arg_t *oargv); - -void pcb_drc_dlg_uninit(void); -void pcb_drc_dlg_init(void); - Index: trunk/src_plugins/dialogs/Plug.tmpasm =================================================================== --- trunk/src_plugins/dialogs/Plug.tmpasm (revision 21219) +++ trunk/src_plugins/dialogs/Plug.tmpasm (revision 21220) @@ -2,7 +2,7 @@ put /local/pcb/mod/OBJS [@ $(PLUGDIR)/dialogs/dialogs.o $(PLUGDIR)/dialogs/act_dad.o - $(PLUGDIR)/dialogs/dlg_drc.o + $(PLUGDIR)/dialogs/dlg_view.o @] switch /local/pcb/dialogs/controls Index: trunk/src_plugins/dialogs/dialogs.c =================================================================== --- trunk/src_plugins/dialogs/dialogs.c (revision 21219) +++ trunk/src_plugins/dialogs/dialogs.c (revision 21220) @@ -48,7 +48,7 @@ #include "dlg_lib_pstk.c" #include "dlg_undo.c" -#include "dlg_drc.h" +#include "dlg_view.h" #include "act_dad.h" pcb_action_t dialogs_action_list[] = { Index: trunk/src_plugins/dialogs/dlg_view.c =================================================================== --- trunk/src_plugins/dialogs/dlg_view.c (nonexistent) +++ trunk/src_plugins/dialogs/dlg_view.c (revision 21220) @@ -0,0 +1,336 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2018 Tibor 'Igor2' Palinkas + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + +#include "config.h" + +#include +#include +#include + +#include "actions.h" +#include "board.h" +#include "conf_core.h" +#include "view.h" +#include "draw.h" +#include "event.h" +#include "hid_inlines.h" +#include "hid_dad.h" +#include "hid_dad_tree.h" + +static const const char *drc_cookie = "dlg_drc"; + +typedef struct { + PCB_DAD_DECL_NOINIT(dlg) + pcb_board_t *pcb; + pcb_drc_list_t drc; + int alloced, active; + + unsigned long int selected; + + int wlist, wcount, wprev, wexplanation, wmeasure; +} drc_ctx_t; + +drc_ctx_t drc_ctx; + +static void drc_close_cb(void *caller_data, pcb_hid_attr_ev_t ev) +{ + drc_ctx_t *ctx = caller_data; + + + PCB_DAD_FREE(ctx->dlg); + if (ctx->alloced) + free(ctx); +} + +void drc2dlg(drc_ctx_t *ctx) +{ + char tmp[32]; + pcb_drc_violation_t *v; + pcb_hid_attribute_t *attr; + pcb_hid_tree_t *tree; + pcb_hid_row_t *r; + char *cell[3], *cursor_path = NULL; + + sprintf(tmp, "%d", pcb_drc_list_length(&ctx->drc)); + PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wcount, str_value, tmp); + + attr = &ctx->dlg[ctx->wlist]; + tree = (pcb_hid_tree_t *)attr->enumerations; + + /* remember cursor */ + r = pcb_dad_tree_get_selected(attr); + if (r != NULL) + cursor_path = pcb_strdup(r->cell[0]); + + /* remove existing items */ + for(r = gdl_first(&tree->rows); r != NULL; r = gdl_first(&tree->rows)) + pcb_dad_tree_remove(attr, r); + + /* add all items */ + cell[2] = NULL; + for(v = pcb_drc_list_first(&ctx->drc); v != NULL; v = pcb_drc_list_next(v)) { + pcb_hid_row_t *r, *rt; + rt = htsp_get(&tree->paths, v->type); + if (rt == NULL) { + cell[0] = pcb_strdup(v->type); + cell[1] = pcb_strdup(""); + rt = pcb_dad_tree_append(attr, NULL, cell); + rt->user_data2.lng = 0; + } + + cell[0] = pcb_strdup_printf("%lu", v->uid); + cell[1] = pcb_strdup(v->title); + r = pcb_dad_tree_append_under(attr, rt, cell); + r->user_data2.lng = v->uid; + } + + /* restore cursor */ + if (cursor_path != NULL) { + pcb_hid_attr_val_t hv; + hv.str_value = cursor_path; + pcb_gui->attr_dlg_set_value(ctx->dlg_hid_ctx, ctx->wlist, &hv); + free(cursor_path); + } +} + +static char *re_wrap(char *inp, int len) +{ + int cnt; + char *s, *lastspc = NULL; + for(s = inp, cnt = 0; *s != '\0'; s++,cnt++) { + if (*s == '\n') + *s = ' '; + if ((cnt >= len) && (lastspc != NULL)) { + cnt = 0; + *lastspc = '\n'; + lastspc = NULL; + } + else if (isspace(*s)) + lastspc = s; + } + return inp; +} + +static void drc_select(pcb_hid_attribute_t *attrib, void *hid_ctx, pcb_hid_row_t *row) +{ + pcb_hid_tree_t *tree = (pcb_hid_tree_t *)attrib->enumerations; + drc_ctx_t *ctx = tree->user_ctx; + pcb_drc_violation_t *v = NULL; + + if (row != NULL) { + ctx->selected = row->user_data2.lng; + v = pcb_drc_by_uid(&ctx->drc, ctx->selected); + if (v != NULL) { + pcb_drc_goto(v); + PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wexplanation, str_value, re_wrap(pcb_strdup(v->explanation), 32)); + if (v->have_measured) + PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wmeasure, str_value, pcb_strdup_printf("%m+required: %$ms\nmeasured: %$ms\n", conf_core.editor.grid_unit->allow, v->required_value, v->measured_value)); + else + PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wmeasure, str_value, pcb_strdup_printf("%m+required: %$ms\n", conf_core.editor.grid_unit->allow, v->required_value)); + } + } + + if (v == NULL) { + ctx->selected = 0; + PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wexplanation, str_value, pcb_strdup("")); + PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->wmeasure, str_value, pcb_strdup("")); + } + + pcb_dad_preview_zoomto(&ctx->dlg[ctx->wprev], &v->bbox); +} + +static vtp0_t drc_color_save; + +static void drc_expose_cb(pcb_hid_attribute_t *attrib, pcb_hid_preview_t *prv, pcb_hid_gc_t gc, const pcb_hid_expose_ctx_t *e) +{ + drc_ctx_t *ctx = prv->user_ctx; + pcb_xform_t xform; + int old_termlab, g; + static const char *offend_color[] = {"#ff0000", "#0000ff"}; + pcb_drc_violation_t *v = pcb_drc_by_uid(&ctx->drc, ctx->selected); + size_t n; + void **p; + + if (v == NULL) + return; + + /* NOTE: zoom box was already set on select */ + + /* save offending object colors */ + vtp0_truncate(&drc_color_save, 0); + for(g = 0; g < 2; g++) { + pcb_idpath_t *i; + for(i = pcb_idpath_list_first(&v->objs[g]); i != NULL; /*i = pcb_idpath_list_next(i)*/i=0) { + pcb_any_obj_t *obj = pcb_idpath2obj(ctx->pcb->Data, i); + if ((obj != NULL) && (obj->type & PCB_OBJ_CLASS_REAL)) { + vtp0_append(&drc_color_save, obj); + if (obj->override_color != NULL) { + char *save = pcb_strdup(obj->override_color); + vtp0_append(&drc_color_save, save); + } + else + vtp0_append(&drc_color_save, NULL); + strcpy(obj->override_color, offend_color[g]); + } + } + } + + /* draw the board */ + old_termlab = pcb_draw_force_termlab; + pcb_draw_force_termlab = 1; + memset(&xform, 0, sizeof(xform)); + xform.layer_faded = 1; + pcb_hid_expose_all(pcb_gui, e, &xform); + pcb_draw_force_termlab = old_termlab; + + /* restore object color */ + for(n = 0, p = drc_color_save.array; n < drc_color_save.used; n+=2,p+=2) { + pcb_any_obj_t *obj = p[0]; + char *s = p[1]; + if (s != NULL) { + strcpy(obj->override_color, s); + free(s); + } + else + *obj->override_color = '\0'; + } + vtp0_truncate(&drc_color_save, 0); +} + + +static pcb_bool drc_mouse_cb(pcb_hid_attribute_t *attrib, pcb_hid_preview_t *prv, pcb_hid_mouse_ev_t kind, pcb_coord_t x, pcb_coord_t y) +{ + return pcb_false; /* don't redraw */ +} + + +static void drc_preview_update_cb(void *user_data, int argc, pcb_event_arg_t argv[]) +{ + drc_ctx_t *ctx = user_data; + pcb_hid_attr_val_t hv; + + if ((ctx == NULL) || (!ctx->active) || (ctx->selected == 0)) + return; + + hv.str_value = NULL; + pcb_gui->attr_dlg_set_value(ctx->dlg_hid_ctx, ctx->wprev, &hv); +} + + +static void pcb_dlg_drc(drc_ctx_t *ctx, const char *title) +{ + const char *hdr[] = { "ID", "title", NULL }; + + + PCB_DAD_BEGIN_VBOX(ctx->dlg); + PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); + + PCB_DAD_BEGIN_HPANE(ctx->dlg); + PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); + + /* left */ + PCB_DAD_BEGIN_VBOX(ctx->dlg); + PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); + + PCB_DAD_BEGIN_HBOX(ctx->dlg); + PCB_DAD_LABEL(ctx->dlg, "Number of violations:"); + PCB_DAD_LABEL(ctx->dlg, "n/a"); + ctx->wcount = PCB_DAD_CURRENT(ctx->dlg); + PCB_DAD_END(ctx->dlg); + + PCB_DAD_TREE(ctx->dlg, 2, 1, hdr); + PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_SCROLL | PCB_HATF_EXPFILL); + PCB_DAD_TREE_SET_CB(ctx->dlg, selected_cb, drc_select); + PCB_DAD_TREE_SET_CB(ctx->dlg, ctx, ctx); + ctx->wlist = PCB_DAD_CURRENT(ctx->dlg); + + PCB_DAD_BEGIN_HBOX(ctx->dlg); + PCB_DAD_BUTTON(ctx->dlg, "Copy"); + PCB_DAD_BUTTON(ctx->dlg, "Cut"); + PCB_DAD_BUTTON(ctx->dlg, "Del"); + PCB_DAD_END(ctx->dlg); + + PCB_DAD_BEGIN_HBOX(ctx->dlg); + PCB_DAD_BUTTON(ctx->dlg, "Paste before"); + PCB_DAD_BUTTON(ctx->dlg, "Paste after"); + PCB_DAD_END(ctx->dlg); + PCB_DAD_END(ctx->dlg); + + /* right */ + PCB_DAD_BEGIN_VBOX(ctx->dlg); + PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); + PCB_DAD_PREVIEW(ctx->dlg, drc_expose_cb, drc_mouse_cb, NULL, NULL, ctx); + ctx->wprev = PCB_DAD_CURRENT(ctx->dlg); + PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); + PCB_DAD_LABEL(ctx->dlg, "(explanation)"); + ctx->wexplanation = PCB_DAD_CURRENT(ctx->dlg); + PCB_DAD_LABEL(ctx->dlg, "(measure)"); + ctx->wmeasure = PCB_DAD_CURRENT(ctx->dlg); + PCB_DAD_END(ctx->dlg); + PCB_DAD_END(ctx->dlg); + + PCB_DAD_BEGIN_HBOX(ctx->dlg); + PCB_DAD_BUTTON(ctx->dlg, "Refresh"); + PCB_DAD_BEGIN_HBOX(ctx->dlg); + PCB_DAD_COMPFLAG(ctx->dlg, PCB_HATF_EXPFILL); + PCB_DAD_END(ctx->dlg); + PCB_DAD_BUTTON(ctx->dlg, "Close"); + PCB_DAD_END(ctx->dlg); + PCB_DAD_END(ctx->dlg); + + PCB_DAD_NEW(ctx->dlg, title, "", ctx, pcb_false, drc_close_cb); + + ctx->active = 1; +} + + +static drc_ctx_t drc_gui_ctx = {0}; +const char pcb_acts_DRC[] = "DRC()\n"; +const char pcb_acth_DRC[] = "Execute drc checks"; +fgw_error_t pcb_act_DRC(fgw_arg_t *ores, int oargc, fgw_arg_t *oargv) +{ + + if (!drc_gui_ctx.active) { + drc_gui_ctx.pcb = PCB; + pcb_dlg_drc(&drc_gui_ctx, "DRC violations"); + } + + pcb_drc_all(&drc_gui_ctx.drc); + drc2dlg(&drc_gui_ctx); + + return 0; +} + +void pcb_drc_dlg_uninit(void) +{ + pcb_event_unbind_allcookie(drc_cookie); + vtp0_uninit(&drc_color_save); +} + +void pcb_drc_dlg_init(void) +{ + pcb_event_bind(PCB_EVENT_USER_INPUT_POST, drc_preview_update_cb, &drc_gui_ctx, drc_cookie); +} Index: trunk/src_plugins/dialogs/dlg_view.h =================================================================== --- trunk/src_plugins/dialogs/dlg_view.h (nonexistent) +++ trunk/src_plugins/dialogs/dlg_view.h (revision 21220) @@ -0,0 +1,7 @@ +extern const char pcb_acts_DRC[]; +extern const char pcb_acth_DRC[]; +fgw_error_t pcb_act_DRC(fgw_arg_t *ores, int oargc, fgw_arg_t *oargv); + +void pcb_drc_dlg_uninit(void); +void pcb_drc_dlg_init(void); +