Index: trunk/src/crosshair.c =================================================================== --- trunk/src/crosshair.c (revision 29342) +++ trunk/src/crosshair.c (revision 29343) @@ -43,7 +43,6 @@ #include #include #include -#include #include "vtonpoint.h" #include "find.h" #include "undo.h" @@ -1037,36 +1036,6 @@ PCB->hidlib.grid = save_grid; } -static void pcb_crosshair_tool_logics(pcb_hidlib_t *hidlib, void *user_data, int argc, pcb_event_arg_t argv[]) -{ - int *ok = argv[1].d.p; - int id = argv[2].d.i; - pcb_board_t *pcb = (pcb_board_t *)hidlib; - if (pcb->RatDraw && !pcb_tool_get(id)->allow_when_drawing_ratlines) { - pcb_message(PCB_MSG_WARNING, "That tool can not be used on the rat layer!\n"); - *ok = 0; - } -} - -static void crosshair_chg_mode(conf_native_t *cfg, int arr_idx) -{ - pcb_tool_chg_mode(&PCB->hidlib); -} - -static void pcb_crosshair_mode_init(void) -{ - static conf_hid_callbacks_t cbs_mode; - static conf_hid_id_t tool_conf_id; - conf_native_t *n_mode = pcb_conf_get_field("editor/mode"); - tool_conf_id = pcb_conf_hid_reg(crosshair_cookie, NULL); - - if (n_mode != NULL) { - memset(&cbs_mode, 0, sizeof(conf_hid_callbacks_t)); - cbs_mode.val_change_post = crosshair_chg_mode; - pcb_conf_hid_set_cb(n_mode, tool_conf_id, &cbs_mode); - } -} - /* allocate GC only when the GUI is already up and running */ static void pcb_crosshair_gui_init(pcb_hidlib_t *hidlib, void *user_data, int argc, pcb_event_arg_t argv[]) { @@ -1098,8 +1067,6 @@ pcb_crosshair.tool_arc = pcb_crosshair.tool_poly = pcb_crosshair.tool_poly_hole = -1; pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_crosshair_gui_init, NULL, crosshair_cookie); - pcb_event_bind(PCB_EVENT_TOOL_SELECT_PRE, pcb_crosshair_tool_logics, NULL, crosshair_cookie); - pcb_crosshair_mode_init(); } @@ -1110,7 +1077,6 @@ if (pcb_render != NULL) pcb_hid_destroy_gc(pcb_crosshair.GC); pcb_event_unbind_allcookie(crosshair_cookie); - pcb_conf_hid_unreg(crosshair_cookie); } void pcb_crosshair_set_local_ref(pcb_coord_t X, pcb_coord_t Y, pcb_bool Showing) Index: trunk/src/main.c =================================================================== --- trunk/src/main.c (revision 29342) +++ trunk/src/main.c (revision 29343) @@ -74,6 +74,7 @@ #include "actions_pcb.h" #include #include +#include "tool_logic.h" const char *pcbhl_menu_file_paths[4]; const char *pcbhl_menu_name_fmt = "pcb-menu-%s.lht"; @@ -286,6 +287,7 @@ gui_support_plugins(0); pcb_render = pcb_gui = NULL; pcb_crosshair_uninit(); + pcb_tool_logic_uninit(); pcb_hidlib_uninit(); /* plugin unload */ if (PCB != NULL) { @@ -386,9 +388,9 @@ /* optionally: handle extra arguments, not processed by the hidlib, here */ n += pcbhl_main_args_add(&ga, argv[n], argv[n+1]); } - pcb_tool_init(); /* init before the plugins so that the static tools have the lowest index */ + pcb_tool_init(); + pcb_tool_logic_init(); - pcb_hidlib_init2(pup_buildins, NULL); pcb_actions_init_pcb_only(); Index: trunk/src/tool_logic.c =================================================================== --- trunk/src/tool_logic.c (revision 29342) +++ trunk/src/tool_logic.c (revision 29343) @@ -31,6 +31,7 @@ #include #include #include +#include #include "board.h" #include "conf_core.h" @@ -40,6 +41,52 @@ #include "tool_logic.h" +/*** Generic part, all rnd apps should do something like this ***/ + +static char tool_logic_cookie[] = "tool_logic"; + +static void tool_logics_chg_tool(pcb_hidlib_t *hidlib, void *user_data, int argc, pcb_event_arg_t argv[]) +{ + int *ok = argv[1].d.p; + int id = argv[2].d.i; + pcb_board_t *pcb = (pcb_board_t *)hidlib; + if (pcb->RatDraw && !pcb_tool_get(id)->allow_when_drawing_ratlines) { + pcb_message(PCB_MSG_WARNING, "That tool can not be used on the rat layer!\n"); + *ok = 0; + } +} + +static void tool_logic_chg_mode(conf_native_t *cfg, int arr_idx) +{ + pcb_tool_chg_mode(&PCB->hidlib); +} + + +void pcb_tool_logic_init(void) +{ + static conf_hid_callbacks_t cbs_mode; + static conf_hid_id_t tool_conf_id; + conf_native_t *n_mode = pcb_conf_get_field("editor/mode"); + tool_conf_id = pcb_conf_hid_reg(tool_logic_cookie, NULL); + + if (n_mode != NULL) { + memset(&cbs_mode, 0, sizeof(conf_hid_callbacks_t)); + cbs_mode.val_change_post = tool_logic_chg_mode; + pcb_conf_hid_set_cb(n_mode, tool_conf_id, &cbs_mode); + } + + pcb_event_bind(PCB_EVENT_TOOL_SELECT_PRE, tool_logic_chg_mode, NULL, tool_logic_cookie); +} + +void pcb_tool_logic_uninit(void) +{ + pcb_event_unbind_allcookie(tool_logic_cookie); + pcb_conf_hid_unreg(tool_logic_cookie); +} + +/*** pcb-rnd-specific parts ***/ + + pcb_bool pcb_tool_is_saved = pcb_false; static void get_grid_lock_coordinates(int type, void *ptr1, void *ptr2, void *ptr3, pcb_coord_t * x, pcb_coord_t * y) Index: trunk/src/tool_logic.h =================================================================== --- trunk/src/tool_logic.h (revision 29342) +++ trunk/src/tool_logic.h (revision 29343) @@ -27,6 +27,9 @@ #ifndef PCB_TOOL_LOGIC_H #define PCB_TOOL_LOGIC_H +void pcb_tool_logic_init(void); +void pcb_tool_logic_uninit(void); + void pcb_tool_attach_for_copy(pcb_hidlib_t *hl, pcb_coord_t PlaceX, pcb_coord_t PlaceY, pcb_bool do_rubberband); void pcb_tool_notify_block(void); /* create first or second corner of a marked block (when clicked) */ @@ -41,6 +44,4 @@ void pcb_release_mode(pcb_hidlib_t *hidlib); -/**** Low level, for internal use ****/ - #endif