Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 9358) +++ trunk/scconfig/Rev.h (revision 9359) @@ -1 +1 @@ -static const int myrev = 9254; +static const int myrev = 9359; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 9358) +++ trunk/scconfig/Rev.tab (revision 9359) @@ -1,3 +1,4 @@ +9359 configure drc infrastructure in libcschem 9254 configure new plugin: funcmap 9211 configure lib: per-plugin-per-project storage 9079 configure rubber band wire move Index: trunk/src/libcschem/Makefile.dep =================================================================== --- trunk/src/libcschem/Makefile.dep (revision 9358) +++ trunk/src/libcschem/Makefile.dep (revision 9359) @@ -163,6 +163,12 @@ ../libcschem/cnc_text_dyn.h ../libcschem/cnc_text.h cnc_grp.h \ non_graphical.h project.h ../libcschem/engine.h plug_library.h csch_printf.o: csch_printf.c config.h csch_printf.h +drc.o: drc.c config.h actions_csch.h drc.h ../libcschem/concrete.h \ + ../libcschem/common_types.h ../libcschem/config.h ../libcschem/rtree.h \ + ../libcschem/attrib.h ../libcschem/oidpath.h ../libcschem/vtoid.h \ + ../../src_3rd/libuundo/uundo.h ../../src_3rd/libminuid/libminuid.h \ + ../../src_3rd/gengeo2d/typecfg_long_double.h ../../src_3rd/opc89.h \ + ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h event.h engine.o: engine.c config.h actions_csch.h project.h \ ../libcschem/common_types.h ../libcschem/config.h \ ../libcschem/concrete.h ../libcschem/rtree.h ../libcschem/attrib.h \ @@ -210,7 +216,7 @@ ../../src_3rd/gengeo2d/typecfg_long_double.h ../../src_3rd/opc89.h \ ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h \ ../libcschem/engine.h plug_library.h integrity.h concrete.h undo.h \ - actions_csch.h + actions_csch.h drc.h non_graphical.o: non_graphical.c config.h concrete.h \ ../libcschem/common_types.h ../libcschem/config.h ../libcschem/rtree.h \ ../libcschem/attrib.h ../libcschem/oidpath.h ../libcschem/vtoid.h \ Index: trunk/src/libcschem/Makefile.in =================================================================== --- trunk/src/libcschem/Makefile.in (revision 9358) +++ trunk/src/libcschem/Makefile.in (revision 9359) @@ -13,6 +13,7 @@ actions_csch.o attrib.o concrete.o + drc.o cnc_any_obj.o cnc_arc.o cnc_bitmap.o Index: trunk/src/libcschem/drc.c =================================================================== --- trunk/src/libcschem/drc.c (nonexistent) +++ trunk/src/libcschem/drc.c (revision 9359) @@ -0,0 +1,114 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - libcschem: design rule checker + * Copyright (C) 2023 Tibor 'Igor2' Palinkas + * + * (Supported by NLnet NGI0 Entrust Fund in 2023) + * + * 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/sch-rnd + * contact lead developer: http://www.repo.hu/projects/sch-rnd/contact.html + * mailing list: http://www.repo.hu/projects/sch-rnd/contact.html + */ + +#include "config.h" + +#include +#include + +#include "actions_csch.h" +#include "drc.h" +#include "event.h" + +static const char drc_cookie[] = "libcschem/drc"; + +csch_drc_violation_t *csch_drc_violation_alloc(void) +{ + csch_drc_violation_t *v = calloc(sizeof(csch_drc_violation_t), 1); + return v; +} + +csch_drc_violation_t *csch_drc_violation_alloc_append(csch_drc_t *ctx) +{ + csch_drc_violation_t *v = csch_drc_violation_alloc(); + vtp0_append(&ctx->violations, v); + return v; +} + + +void csch_drc_violation_free(csch_drc_violation_t *v) +{ + free(v->title); + free(v->desc); + free(v); +} + +void csch_drc_uninit(csch_drc_t *ctx) +{ + long n; + + ctx->ran = 0; + for(n = 0; n < ctx->violations.used; n++) + csch_drc_violation_free(ctx->violations.array[n]); + vtp0_uninit(&ctx->violations); +} + + +long csch_drc_project(csch_drc_t *ctx, csch_sheet_t *sheet) +{ + ctx->ran = 0; + vtp0_init(&ctx->violations); + + rnd_event(&sheet->hidlib, CSCH_EVENT_DRC_RUN, "p", ctx); + if (ctx->ran == 0) + rnd_message(RND_MSG_ERROR, "No DRC tests ran. Is any DRC capable plugin compiled? Are they disabled? Are all rules disabled?\n"); + + return ctx->violations.used; +} + + + +static const char csch_acts_DRC[] = "DRC([list|print|log|dump])"; +static const char csch_acth_DRC[] = "Invoke the DRC check. Results are presented as the argument requests."; +static fgw_error_t csch_act_DRC(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + csch_sheet_t *sheet = CSCH_ACT_SHEET; + csch_drc_t ctx; + const char *dlg_type = "list"; + + RND_ACT_MAY_CONVARG(1, FGW_STR, DRC, dlg_type = argv[1].val.str); + + csch_drc_project(&ctx, sheet); + + return 0; +} + +static rnd_action_t csch_drc_act_list[] = { + {"DRC", csch_act_DRC, csch_acth_DRC, csch_acts_DRC} +}; + +void csch_drc_act_init(void) +{ + RND_REGISTER_ACTIONS(csch_drc_act_list, drc_cookie); +} + +void csch_drc_act_uninit(void) +{ + rnd_remove_actions_by_cookie(drc_cookie); +} + Index: trunk/src/libcschem/event.c =================================================================== --- trunk/src/libcschem/event.c (revision 9358) +++ trunk/src/libcschem/event.c (revision 9359) @@ -28,7 +28,7 @@ #include #include "event.h" -static const char *csch_evnames[CSCH_EVENT_last] = { +static const char *csch_evnames[] = { "cschev_layervis_changed", "cschev_undo_post", "cschev_sheet_edit", @@ -44,13 +44,10 @@ "cschev_prj_stance_changed", "cschev_library_changed", "cschev_selection_changed", + "cschev_drc_run", "cschev_buffer_copy_custom", - "cschev_buffer_paste_custom", - - "cschev_drc_run", - - NULL + "cschev_buffer_paste_custom" }; void csch_event_init_app(void) Index: trunk/src/libcschem/event.h =================================================================== --- trunk/src/libcschem/event.h (revision 9358) +++ trunk/src/libcschem/event.h (revision 9359) @@ -50,12 +50,12 @@ CSCH_EVENT_LIBRARY_CHANGED, /* [d] called after a new entry is added to the library so that any open library window can be updated on the GUI; no args (sheet can be retrieved from hidlib) */ CSCH_EVENT_SELECTION_CHANGED, /* [d] called after object selection changed (sleected/unselected objects) */ + CSCH_EVENT_DRC_RUN, /* [d] called from core to run all configured DRCs (implemented in plugins). Args: (csch_drc_t *ctx). Each DRC plugin shall increase ctx->ran if it did any check */ + /* generated by the app, not libcschem */ CSCH_EVENT_BUFFER_COPY_CUSTOM, /* [d] called before an object is duplicated from sheet to buffer; args: (csch_chdr_t **obj, csch_sheet_t *buffer); *obj is the current object, initially the source object on the sheet; destination buffer the second arg */ CSCH_EVENT_BUFFER_PASTE_CUSTOM, /* [d] called before an object is duplicated from buffer to sheet; args: (csch_chdr_t **obj); *obj is the current object, initially the source object in the buffer; destination sheet is in the hidlib arg */ - CSCH_EVENT_DRC_RUN, /* [d] called from core to run all configured DRCs (implemented in plugins). Args: (int *) that each DRC plugin shall increase if it did any check */ - CSCH_EVENT_last /* not a real event */ }; Index: trunk/src/libcschem/libcschem.c =================================================================== --- trunk/src/libcschem/libcschem.c (revision 9358) +++ trunk/src/libcschem/libcschem.c (revision 9359) @@ -40,6 +40,7 @@ #include "integrity.h" #include "undo.h" #include "actions_csch.h" +#include "drc.h" const int *csch_cfg_multiport_net_merge = NULL; minuid_session_t csch_minuid; @@ -60,6 +61,7 @@ csch_project_uninit(); csch_project_act_uninit(); csch_integrity_act_uninit(); + csch_drc_act_uninit(); csch_undo_act_uninit(); csch_plug_library_uninit(); } @@ -69,6 +71,7 @@ csch_actions_init(&rnd_fgw); /* custom fgw types */ csch_project_act_init(); csch_integrity_act_init(); + csch_drc_act_init(); csch_undo_act_init(); csch_project_init(); return 0;