Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 29400) +++ trunk/scconfig/Rev.h (revision 29401) @@ -1 +1 @@ -static const int myrev = 29389; +static const int myrev = 29401; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 29400) +++ trunk/scconfig/Rev.tab (revision 29401) @@ -1,4 +1,4 @@ -29389 configure move generic actions from core to librnd +29401 configure move generic actions from core to librnd 29385 configure remove build system special casing: generated lists for action registration 29375 configure librnd separation: stroke plugin API conversion from stub to event 29340 configure librnd separation: tool code Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 29400) +++ trunk/src/Makefile.in (revision 29401) @@ -81,6 +81,7 @@ $(LIBRND)/core/file_loaded.o $(LIBRND)/core/funchash.o $(LIBRND)/core/grid.o + $(LIBRND)/core/gui_act.o $(LIBRND)/core/heap.o $(LIBRND)/core/hid.o $(LIBRND)/core/hid_attrib.o @@ -582,6 +583,7 @@ # rndlib: corner case: some headers are not derived from the objects sub /local/pcb/HDRS_HIDLIB {$(LIBRND)/core/hid_dlg.h } {} sub /local/pcb/HDRS_HIDLIB {$(LIBRND)/core/conf_act.h } {} +sub /local/pcb/HDRS_HIDLIB {$(LIBRND)/core/gui_act.h } {} append /local/pcb/HDRS_HIDLIB {$(LIBRND)/config.h $(LIBRND)/core/global_typedefs.h $(LIBRND)/core/globalconst.h $(LIBRND)/core/math_helper.h $(LIBRND)/core/buildin.hidlib.h $(LIBRND)/core/hid_inlines.h $(LIBRND)/core/rotate.h $(LIBRND)/core/fptr_cast.h $(LIBRND)/core/safe_fs_dir.h $(LIBRND)/core/compat_inc.h $(LIBRND)/poly/rtree2_compat.h $(LIBRND)/core/color_cache.h } gsub /local/pcb/HDRS_3RDLIB {../src_3rd/liblihata/dom_[^ ]*.h } {} gsub /local/pcb/HDRS_3RDLIB {../src_3rd/liblihata/tree_[^ ]*.h } {} Index: trunk/src/crosshair.c =================================================================== --- trunk/src/crosshair.c (revision 29400) +++ trunk/src/crosshair.c (revision 29401) @@ -911,10 +911,10 @@ if (ans != PCB_OBJ_VOID) { pcb_pstk_t *ps = (pcb_pstk_t *) ptr2; check_snap_object(&snap_data, ps->x, ps->y, pcb_true, (pcb_any_obj_t *)ps); - pcb_crosshair.snapped_pstk = ps; + hidlib->tool_snapped_obj_bbox = &ps->BoundingBox; } else - pcb_crosshair.snapped_pstk = NULL; + hidlib->tool_snapped_obj_bbox = NULL; /*** arc ***/ ans = PCB_OBJ_VOID; Index: trunk/src/crosshair.h =================================================================== --- trunk/src/crosshair.h (revision 29400) +++ trunk/src/crosshair.h (revision 29401) @@ -68,7 +68,6 @@ pcb_route_t Route; /* Calculated line route in LINE or MOVE(LINE) mode */ vtop_t onpoint_objs; vtop_t old_onpoint_objs; - pcb_pstk_t *snapped_pstk; pcb_any_obj_t *extobj_edit; /* refers to the editobject (of an extobj) being edited */ /* list of object IDs that could have been dragged so that they can be cycled */ Index: trunk/src/gui_act.c =================================================================== --- trunk/src/gui_act.c (revision 29400) +++ trunk/src/gui_act.c (revision 29401) @@ -555,68 +555,6 @@ /* --------------------------------------------------------------------------- */ -static const char pcb_acts_CreateMenu[] = "CreateMenu(path)\nCreateMenu(path, action, tooltip, cookie)"; -static const char pcb_acth_CreateMenu[] = "Creates a new menu, popup (only path specified) or submenu (at least path and action are specified)"; -static fgw_error_t pcb_act_CreateMenu(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - if (pcb_gui == NULL) { - pcb_message(PCB_MSG_ERROR, "Error: can't create menu, there's no GUI hid loaded\n"); - PCB_ACT_IRES(-1); - return 0; - } - - PCB_ACT_CONVARG(1, FGW_STR, CreateMenu, ;); - PCB_ACT_MAY_CONVARG(2, FGW_STR, CreateMenu, ;); - PCB_ACT_MAY_CONVARG(3, FGW_STR, CreateMenu, ;); - PCB_ACT_MAY_CONVARG(4, FGW_STR, CreateMenu, ;); - - if (argc > 1) { - pcb_menu_prop_t props; - - memset(&props, 0, sizeof(props)); - props.action = (argc > 2) ? argv[2].val.str : NULL; - props.tip = (argc > 3) ? argv[3].val.str : NULL; - props.cookie = (argc > 4) ? argv[4].val.str : NULL; - - pcb_gui->create_menu(pcb_gui, argv[1].val.str, &props); - - PCB_ACT_IRES(0); - return 0; - } - - PCB_ACT_FAIL(CreateMenu); -} - -/* --------------------------------------------------------------------------- */ - -static const char pcb_acts_RemoveMenu[] = "RemoveMenu(path|cookie)"; -static const char pcb_acth_RemoveMenu[] = "Recursively removes a new menu, popup (only path specified) or submenu. "; -static fgw_error_t pcb_act_RemoveMenu(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - if (pcb_gui == NULL) { - pcb_message(PCB_MSG_ERROR, "can't remove menu, there's no GUI hid loaded\n"); - PCB_ACT_IRES(-1); - return 0; - } - - if (pcb_gui->remove_menu == NULL) { - pcb_message(PCB_MSG_ERROR, "can't remove menu, the GUI doesn't support it\n"); - PCB_ACT_IRES(-1); - return 0; - } - - PCB_ACT_CONVARG(1, FGW_STR, RemoveMenu, ;); - if (pcb_gui->remove_menu(pcb_gui, argv[1].val.str) != 0) { - pcb_message(PCB_MSG_ERROR, "failed to remove some of the menu items\n"); - PCB_ACT_IRES(-1); - } - else - PCB_ACT_IRES(0); - return 0; -} - -/* --------------------------------------------------------------------------- */ - static const char pcb_acts_SetSame[] = "SetSame()"; static const char pcb_acth_SetSame[] = "Sets current layer and sizes to match indicated item."; /* DOC: setsame.html */ @@ -684,135 +622,6 @@ return 0; } - -/* This action is provided for CLI convenience */ -static const char pcb_acts_FullScreen[] = "FullScreen(on|off|toggle)\n"; -static const char pcb_acth_FullScreen[] = "Hide widgets to get edit area full screen"; - -static fgw_error_t pcb_act_FullScreen(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - int id = -2; - PCB_ACT_MAY_CONVARG(1, FGW_KEYWORD, FullScreen, id = fgw_keyword(&argv[1])); - - PCB_ACT_IRES(0); - switch(id) { - case -2: - case F_Toggle: - pcb_conf_setf(CFR_DESIGN, "editor/fullscreen", -1, "%d", !pcbhl_conf.editor.fullscreen, POL_OVERWRITE); - break; - case F_On: - pcb_conf_set(CFR_DESIGN, "editor/fullscreen", -1, "1", POL_OVERWRITE); - break; - case F_Off: - pcb_conf_set(CFR_DESIGN, "editor/fullscreen", -1, "0", POL_OVERWRITE); - break; - default: - PCB_ACT_FAIL(FullScreen); - } - return 0; -} - -static const char pcb_acts_Cursor[] = "Cursor(Type,DeltaUp,DeltaRight,Units)"; -static const char pcb_acth_Cursor[] = "Move the cursor."; -/* DOC: cursor.html */ -static fgw_error_t pcb_act_Cursor(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - pcb_unit_list_t extra_units_x = { - {"grid", 0, 0}, - {"view", 0, PCB_UNIT_PERCENT}, - {"board", 0, PCB_UNIT_PERCENT}, - {"", 0, 0} - }; - pcb_unit_list_t extra_units_y = { - {"grid", 0, 0}, - {"view", 0, PCB_UNIT_PERCENT}, - {"board", 0, PCB_UNIT_PERCENT}, - {"", 0, 0} - }; - int op, pan_warp = HID_SC_DO_NOTHING; - double dx, dy; - pcb_coord_t view_width, view_height; - const char *a1, *a2, *a3; - pcb_box_t vbx; - - extra_units_x[0].scale = PCB_ACT_HIDLIB->grid; - extra_units_x[2].scale = PCB_ACT_HIDLIB->size_x; - - extra_units_y[0].scale = PCB_ACT_HIDLIB->grid; - extra_units_y[2].scale = PCB_ACT_HIDLIB->size_y; - - pcb_gui->view_get(pcb_gui, &vbx); - view_width = vbx.X2 - vbx.X1; - view_height = vbx.Y2 - vbx.Y1; - - extra_units_x[1].scale = view_width; - extra_units_y[1].scale = view_height; - - PCB_ACT_CONVARG(1, FGW_KEYWORD, Cursor, op = fgw_keyword(&argv[1])); - PCB_ACT_CONVARG(2, FGW_STR, Cursor, a1 = argv[2].val.str); - PCB_ACT_CONVARG(3, FGW_STR, Cursor, a2 = argv[3].val.str); - PCB_ACT_CONVARG(4, FGW_STR, Cursor, a3 = argv[4].val.str); - - if (op == F_Pan) - pan_warp = HID_SC_PAN_VIEWPORT; - else if (op == F_Warp) - pan_warp = HID_SC_WARP_POINTER; - else - PCB_ACT_FAIL(Cursor); - - if (pcb_strcasecmp(a3, "grid") == 0) { - char *end; - dx = strtod(a1, &end) * pcbhl_conf.editor.grid; - dy = strtod(a2, &end) * pcbhl_conf.editor.grid; - } - else { - dx = pcb_get_value_ex(a1, a3, NULL, extra_units_x, "", NULL); - dy = pcb_get_value_ex(a2, a3, NULL, extra_units_y, "", NULL); - } - - if (pcbhl_conf.editor.view.flip_x) - dx = -dx; - if (!pcbhl_conf.editor.view.flip_y) - dy = -dy; - - /* Allow leaving snapped pin/pad/padstack */ - if (pcb_crosshair.snapped_pstk) { - pcb_pstk_t *ps = pcb_crosshair.snapped_pstk; - pcb_coord_t radius = ((ps->BoundingBox.X2 - ps->BoundingBox.X1) + (ps->BoundingBox.Y2 - ps->BoundingBox.Y1))/6; - if (dx < 0) - dx -= radius; - else if (dx > 0) - dx += radius; - if (dy < 0) - dy -= radius; - else if (dy > 0) - dy += radius; - } - - pcb_hidcore_crosshair_move_to(PCB_ACT_HIDLIB, pcb_crosshair.X + dx, pcb_crosshair.Y + dy, 1); - pcb_gui->set_crosshair(pcb_gui, pcb_crosshair.X, pcb_crosshair.Y, pan_warp); - - PCB_ACT_IRES(0); - return 0; -} - -static const char pcb_acts_MoveCursorTo[] = "MoveCursorTo(x,y)"; -static const char pcb_acth_MoveCursorTo[] = "Move the cursor to absolute coords, pan the view as needed."; -static fgw_error_t pcb_act_MoveCursorTo(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - pcb_coord_t x, y; - - PCB_ACT_CONVARG(1, FGW_COORD, Cursor, x = fgw_coord(&argv[1])); - PCB_ACT_CONVARG(2, FGW_COORD, Cursor, y = fgw_coord(&argv[2])); - - pcb_hidcore_crosshair_move_to(PCB_ACT_HIDLIB, x, y, 0); - pcb_gui->set_crosshair(pcb_gui, pcb_crosshair.X, pcb_crosshair.Y, HID_SC_PAN_VIEWPORT); - - PCB_ACT_IRES(0); - return 0; -} - - #define istrue(s) ((*(s) == '1') || (*(s) == 'y') || (*(s) == 'Y') || (*(s) == 't') || (*(s) == 'T')) static const char pcb_acts_EditLayer[] = "Editlayer([@layer], [name=text|auto=[0|1]|sub=[0|1])]\nEditlayer([@layer], attrib, key=value)"; @@ -1455,42 +1264,6 @@ return 0; } -static const char pcb_acts_grid[] = - "grid(set, [name:]size[@offs][!unit])\n" - "grid(+|up)\n" "grid(-|down)\n" "grid(#N)\n" "grid(idx, N)\n"; -static const char pcb_acth_grid[] = "Set the grid."; -static fgw_error_t pcb_act_grid(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - const char *op, *a; - - PCB_ACT_CONVARG(1, FGW_STR, grid, op = argv[1].val.str); - PCB_ACT_IRES(0); - - if (strcmp(op, "set") == 0) { - pcb_grid_t dst; - PCB_ACT_CONVARG(2, FGW_STR, grid, a = argv[2].val.str); - if (!pcb_grid_parse(&dst, a)) - PCB_ACT_FAIL(grid); - pcb_grid_set(PCB_ACT_HIDLIB, &dst); - pcb_grid_free(&dst); - } - else if ((strcmp(op, "up") == 0) || (strcmp(op, "+") == 0)) - pcb_grid_list_step(PCB_ACT_HIDLIB, +1); - else if ((strcmp(op, "down") == 0) || (strcmp(op, "-") == 0)) - pcb_grid_list_step(PCB_ACT_HIDLIB, -1); - else if (strcmp(op, "idx") == 0) { - PCB_ACT_CONVARG(2, FGW_STR, grid, a = argv[2].val.str); - pcb_grid_list_jump(PCB_ACT_HIDLIB, atoi(a)); - } - else if (op[0] == '#') { - pcb_grid_list_jump(PCB_ACT_HIDLIB, atoi(op+1)); - } - else - PCB_ACT_FAIL(grid); - - return 0; -} - const char pcb_acts_chkrst[] = "ChkRst(route_style_id)\n"; const char pcb_acth_chkrst[] = "Return 1 if route_style_id matches pen."; /* DOC: chkrst.html */ @@ -1509,19 +1282,6 @@ return 0; } -static const char pcb_acts_GetXY[] = "GetXY()"; -static const char pcb_acth_GetXY[] = "Get a coordinate."; -/* DOC: getxy.html */ -static fgw_error_t pcb_act_GetXY(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - pcb_coord_t x, y; - const char *msg = "Click to enter a coordinate."; - PCB_ACT_MAY_CONVARG(1, FGW_STR, GetXY, msg = argv[1].val.str); - PCB_ACT_IRES(0); - pcb_hid_get_coords(msg, &x, &y, 0); - return 0; -} - static const char pcb_acts_boardflip[] = "BoardFlip([sides])"; static const char pcb_acth_boardflip[] = "Mirror the board over the x axis, optionally mirroring sides as well."; /* DOC: boardflip.html */ @@ -1590,71 +1350,26 @@ return 0; } -static const char pcb_acts_Benchmark[] = "Benchmark()"; -static const char pcb_acth_Benchmark[] = "Benchmark the GUI speed."; -/* DOC: benchmark.html */ -static fgw_error_t pcb_act_Benchmark(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - double fps = 0; - if ((pcb_gui != NULL) && (pcb_gui->benchmark != NULL)) { - fps = pcb_gui->benchmark(pcb_gui); - pcb_message(PCB_MSG_INFO, "%f redraws per second\n", fps); - } - else - pcb_message(PCB_MSG_ERROR, "benchmark is not available in the current HID\n"); - - PCB_ACT_DRES(fps); - return 0; -} - -static const char pcb_acts_Help[] = "Help()"; -static const char pcb_acth_Help[] = "On-line action help"; -static fgw_error_t pcb_act_Help(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - pcb_print_actions(); - PCB_ACT_IRES(0); - return 0; -} - -static const char pcb_acts_Redraw[] = "Redraw()"; -static const char pcb_acth_Redraw[] = "Redraw the entire screen"; -static fgw_error_t pcb_act_Redraw(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - pcb_gui->invalidate_all(pcb_gui); - PCB_ACT_IRES(0); - return 0; -} - static pcb_action_t gui_action_list[] = { {"Display", pcb_act_Display, pcb_acth_Display, pcb_acts_Display}, {"CycleDrag", pcb_act_CycleDrag, pcb_acth_CycleDrag, pcb_acts_CycleDrag}, - {"FullScreen", pcb_act_FullScreen, pcb_acth_FullScreen, pcb_acts_FullScreen}, {"MarkCrosshair", pcb_act_MarkCrosshair, pcb_acth_MarkCrosshair, pcb_acts_MarkCrosshair}, {"SetSame", pcb_act_SetSame, pcb_acth_SetSame, pcb_acts_SetSame}, {"RouteStyle", pcb_act_RouteStyle, pcb_acth_RouteStyle, pcb_acts_RouteStyle}, - {"CreateMenu", pcb_act_CreateMenu, pcb_acth_CreateMenu, pcb_acts_CreateMenu}, - {"RemoveMenu", pcb_act_RemoveMenu, pcb_acth_RemoveMenu, pcb_acts_RemoveMenu}, {"SelectLayer", pcb_act_SelectLayer, pcb_acth_selectlayer, pcb_acts_selectlayer}, {"ChkLayer", pcb_act_ChkLayer, pcb_acth_chklayer, pcb_acts_chklayer}, {"ToggleView", pcb_act_ToggleView, pcb_acth_toggleview, pcb_acts_toggleview}, {"ChkView", pcb_act_ChkView, pcb_acth_chkview, pcb_acts_chkview}, - {"Cursor", pcb_act_Cursor, pcb_acth_Cursor, pcb_acts_Cursor}, - {"MoveCursorTo", pcb_act_MoveCursorTo, pcb_acth_MoveCursorTo, pcb_acts_MoveCursorTo}, {"EditLayer", pcb_act_EditLayer, pcb_acth_EditLayer, pcb_acts_EditLayer}, {"EditGroup", pcb_act_EditGroup, pcb_acth_EditGroup, pcb_acts_EditGroup}, {"DelGroup", pcb_act_DelGroup, pcb_acth_DelGroup, pcb_acts_DelGroup}, {"DupGroup", pcb_act_DupGroup, pcb_acth_DupGroup, pcb_acts_DupGroup}, {"NewGroup", pcb_act_NewGroup, pcb_acth_NewGroup, pcb_acts_NewGroup}, - {"Grid", pcb_act_grid, pcb_acth_grid, pcb_acts_grid}, {"SetUnits", pcb_act_SetUnits, pcb_acth_setunits, pcb_acts_setunits}, {"ChkRst", pcb_act_ChkRst, pcb_acth_chkrst, pcb_acts_chkrst}, - {"GetXY", pcb_act_GetXY, pcb_acth_GetXY, pcb_acts_GetXY}, {"BoardFlip", pcb_act_boardflip, pcb_acth_boardflip, pcb_acts_boardflip}, - {"ClipInhibit", pcb_act_ClipInhibit, pcb_acth_ClipInhibit, pcb_acts_ClipInhibit}, - {"Benchmark", pcb_act_Benchmark, pcb_acth_Benchmark, pcb_acts_Benchmark}, - {"Help", pcb_act_Help, pcb_acth_Help, pcb_acts_Help}, - {"Redraw", pcb_act_Redraw, pcb_acth_Redraw, pcb_acts_Redraw} + {"ClipInhibit", pcb_act_ClipInhibit, pcb_acth_ClipInhibit, pcb_acts_ClipInhibit} }; void pcb_gui_act_init2(void) Index: trunk/src/librnd/core/gui_act.c =================================================================== --- trunk/src/librnd/core/gui_act.c (nonexistent) +++ trunk/src/librnd/core/gui_act.c (revision 29401) @@ -0,0 +1,337 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * (this file is based on PCB, interactive printed circuit board design) + * Copyright (C) 1994,1995,1996 Thomas Nau + * Copyright (C) 1997, 1998, 1999, 2000, 2001 Harry Eaton + * Copyright (C) 2019,2020 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") + * + * + * Old contact info: + * Harry Eaton, 6697 Buttonhole Ct, Columbia, MD 21044, USA + * haceaton@aplcomm.jhuapl.edu + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char pcb_acts_CreateMenu[] = "CreateMenu(path)\nCreateMenu(path, action, tooltip, cookie)"; +static const char pcb_acth_CreateMenu[] = "Creates a new menu, popup (only path specified) or submenu (at least path and action are specified)"; +static fgw_error_t pcb_act_CreateMenu(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + if (pcb_gui == NULL) { + pcb_message(PCB_MSG_ERROR, "Error: can't create menu, there's no GUI hid loaded\n"); + PCB_ACT_IRES(-1); + return 0; + } + + PCB_ACT_CONVARG(1, FGW_STR, CreateMenu, ;); + PCB_ACT_MAY_CONVARG(2, FGW_STR, CreateMenu, ;); + PCB_ACT_MAY_CONVARG(3, FGW_STR, CreateMenu, ;); + PCB_ACT_MAY_CONVARG(4, FGW_STR, CreateMenu, ;); + + if (argc > 1) { + pcb_menu_prop_t props; + + memset(&props, 0, sizeof(props)); + props.action = (argc > 2) ? argv[2].val.str : NULL; + props.tip = (argc > 3) ? argv[3].val.str : NULL; + props.cookie = (argc > 4) ? argv[4].val.str : NULL; + + pcb_gui->create_menu(pcb_gui, argv[1].val.str, &props); + + PCB_ACT_IRES(0); + return 0; + } + + PCB_ACT_FAIL(CreateMenu); +} + +/* --------------------------------------------------------------------------- */ + +static const char pcb_acts_RemoveMenu[] = "RemoveMenu(path|cookie)"; +static const char pcb_acth_RemoveMenu[] = "Recursively removes a new menu, popup (only path specified) or submenu. "; +static fgw_error_t pcb_act_RemoveMenu(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + if (pcb_gui == NULL) { + pcb_message(PCB_MSG_ERROR, "can't remove menu, there's no GUI hid loaded\n"); + PCB_ACT_IRES(-1); + return 0; + } + + if (pcb_gui->remove_menu == NULL) { + pcb_message(PCB_MSG_ERROR, "can't remove menu, the GUI doesn't support it\n"); + PCB_ACT_IRES(-1); + return 0; + } + + PCB_ACT_CONVARG(1, FGW_STR, RemoveMenu, ;); + if (pcb_gui->remove_menu(pcb_gui, argv[1].val.str) != 0) { + pcb_message(PCB_MSG_ERROR, "failed to remove some of the menu items\n"); + PCB_ACT_IRES(-1); + } + else + PCB_ACT_IRES(0); + return 0; +} + +/* This action is provided for CLI convenience */ +static const char pcb_acts_FullScreen[] = "FullScreen(on|off|toggle)\n"; +static const char pcb_acth_FullScreen[] = "Hide widgets to get edit area full screen"; + +static fgw_error_t pcb_act_FullScreen(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + const char *cmd = NULL; + PCB_ACT_MAY_CONVARG(1, FGW_STR, FullScreen, cmd = argv[1].val.str); + + if ((cmd == NULL) || (pcb_strcasecmp(cmd, "Toggle") == 0)) + pcb_conf_setf(CFR_DESIGN, "editor/fullscreen", -1, "%d", !pcbhl_conf.editor.fullscreen, POL_OVERWRITE); + else if (pcb_strcasecmp(cmd, "On") == 0) + pcb_conf_set(CFR_DESIGN, "editor/fullscreen", -1, "1", POL_OVERWRITE); + else if (pcb_strcasecmp(cmd, "Off") == 0) + pcb_conf_set(CFR_DESIGN, "editor/fullscreen", -1, "0", POL_OVERWRITE); + else + PCB_ACT_FAIL(FullScreen); + + return 0; +} + +static const char pcb_acts_Cursor[] = "Cursor(Type,DeltaUp,DeltaRight,Units)"; +static const char pcb_acth_Cursor[] = "Move the cursor."; +/* DOC: cursor.html */ +static fgw_error_t pcb_act_Cursor(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + pcb_hidlib_t *hidlib = PCB_ACT_HIDLIB; + pcb_unit_list_t extra_units_x = { + {"grid", 0, 0}, + {"view", 0, PCB_UNIT_PERCENT}, + {"board", 0, PCB_UNIT_PERCENT}, + {"", 0, 0} + }; + pcb_unit_list_t extra_units_y = { + {"grid", 0, 0}, + {"view", 0, PCB_UNIT_PERCENT}, + {"board", 0, PCB_UNIT_PERCENT}, + {"", 0, 0} + }; + int pan_warp = HID_SC_DO_NOTHING; + double dx, dy; + pcb_coord_t view_width, view_height; + const char *a1, *a2, *a3, *op; + pcb_box_t vbx; + + extra_units_x[0].scale = PCB_ACT_HIDLIB->grid; + extra_units_x[2].scale = PCB_ACT_HIDLIB->size_x; + + extra_units_y[0].scale = PCB_ACT_HIDLIB->grid; + extra_units_y[2].scale = PCB_ACT_HIDLIB->size_y; + + pcb_gui->view_get(pcb_gui, &vbx); + view_width = vbx.X2 - vbx.X1; + view_height = vbx.Y2 - vbx.Y1; + + extra_units_x[1].scale = view_width; + extra_units_y[1].scale = view_height; + + PCB_ACT_CONVARG(1, FGW_STR, Cursor, op = argv[1].val.str); + PCB_ACT_CONVARG(2, FGW_STR, Cursor, a1 = argv[2].val.str); + PCB_ACT_CONVARG(3, FGW_STR, Cursor, a2 = argv[3].val.str); + PCB_ACT_CONVARG(4, FGW_STR, Cursor, a3 = argv[4].val.str); + + switch(*op) { + case 'p': case 'P': /* Pan */ + pan_warp = HID_SC_PAN_VIEWPORT; + break; + case 'w': case 'W': /* Warp */ + pan_warp = HID_SC_WARP_POINTER; + break; + default: + PCB_ACT_FAIL(Cursor); + } + + if (pcb_strcasecmp(a3, "grid") == 0) { + char *end; + dx = strtod(a1, &end) * pcbhl_conf.editor.grid; + dy = strtod(a2, &end) * pcbhl_conf.editor.grid; + } + else { + dx = pcb_get_value_ex(a1, a3, NULL, extra_units_x, "", NULL); + dy = pcb_get_value_ex(a2, a3, NULL, extra_units_y, "", NULL); + } + + if (pcbhl_conf.editor.view.flip_x) + dx = -dx; + if (!pcbhl_conf.editor.view.flip_y) + dy = -dy; + + /* Allow leaving snapped pin/pad/padstack */ + if (hidlib->tool_snapped_obj_bbox) { + pcb_box_t *bbx = hidlib->tool_snapped_obj_bbox; + pcb_coord_t radius = ((bbx->X2 - bbx->X1) + (bbx->Y2 - bbx->Y1))/6; + if (dx < 0) + dx -= radius; + else if (dx > 0) + dx += radius; + if (dy < 0) + dy -= radius; + else if (dy > 0) + dy += radius; + } + + pcb_hidcore_crosshair_move_to(hidlib, hidlib->ch_x + dx, hidlib->ch_y + dy, 1); + pcb_gui->set_crosshair(pcb_gui, hidlib->ch_x, hidlib->ch_y, pan_warp); + + PCB_ACT_IRES(0); + return 0; +} + +static const char pcb_acts_MoveCursorTo[] = "MoveCursorTo(x,y)"; +static const char pcb_acth_MoveCursorTo[] = "Move the cursor to absolute coords, pan the view as needed."; +static fgw_error_t pcb_act_MoveCursorTo(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + pcb_hidlib_t *hidlib = PCB_ACT_HIDLIB; + pcb_coord_t x, y; + + PCB_ACT_CONVARG(1, FGW_COORD, Cursor, x = fgw_coord(&argv[1])); + PCB_ACT_CONVARG(2, FGW_COORD, Cursor, y = fgw_coord(&argv[2])); + + pcb_hidcore_crosshair_move_to(PCB_ACT_HIDLIB, x, y, 0); + pcb_gui->set_crosshair(pcb_gui, hidlib->ch_x, hidlib->ch_y, HID_SC_PAN_VIEWPORT); + + PCB_ACT_IRES(0); + return 0; +} + + +static const char pcb_acts_grid[] = + "grid(set, [name:]size[@offs][!unit])\n" + "grid(+|up)\n" "grid(-|down)\n" "grid(#N)\n" "grid(idx, N)\n"; +static const char pcb_acth_grid[] = "Set the grid."; +static fgw_error_t pcb_act_grid(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + const char *op, *a; + + PCB_ACT_CONVARG(1, FGW_STR, grid, op = argv[1].val.str); + PCB_ACT_IRES(0); + + if (strcmp(op, "set") == 0) { + pcb_grid_t dst; + PCB_ACT_CONVARG(2, FGW_STR, grid, a = argv[2].val.str); + if (!pcb_grid_parse(&dst, a)) + PCB_ACT_FAIL(grid); + pcb_grid_set(PCB_ACT_HIDLIB, &dst); + pcb_grid_free(&dst); + } + else if ((strcmp(op, "up") == 0) || (strcmp(op, "+") == 0)) + pcb_grid_list_step(PCB_ACT_HIDLIB, +1); + else if ((strcmp(op, "down") == 0) || (strcmp(op, "-") == 0)) + pcb_grid_list_step(PCB_ACT_HIDLIB, -1); + else if (strcmp(op, "idx") == 0) { + PCB_ACT_CONVARG(2, FGW_STR, grid, a = argv[2].val.str); + pcb_grid_list_jump(PCB_ACT_HIDLIB, atoi(a)); + } + else if (op[0] == '#') { + pcb_grid_list_jump(PCB_ACT_HIDLIB, atoi(op+1)); + } + else + PCB_ACT_FAIL(grid); + + return 0; +} + +static const char pcb_acts_GetXY[] = "GetXY()"; +static const char pcb_acth_GetXY[] = "Get a coordinate."; +/* DOC: getxy.html */ +static fgw_error_t pcb_act_GetXY(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + pcb_coord_t x, y; + const char *msg = "Click to enter a coordinate."; + PCB_ACT_MAY_CONVARG(1, FGW_STR, GetXY, msg = argv[1].val.str); + PCB_ACT_IRES(0); + pcb_hid_get_coords(msg, &x, &y, 0); + return 0; +} + +static const char pcb_acts_Benchmark[] = "Benchmark()"; +static const char pcb_acth_Benchmark[] = "Benchmark the GUI speed."; +/* DOC: benchmark.html */ +static fgw_error_t pcb_act_Benchmark(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + double fps = 0; + + if ((pcb_gui != NULL) && (pcb_gui->benchmark != NULL)) { + fps = pcb_gui->benchmark(pcb_gui); + pcb_message(PCB_MSG_INFO, "%f redraws per second\n", fps); + } + else + pcb_message(PCB_MSG_ERROR, "benchmark is not available in the current HID\n"); + + PCB_ACT_DRES(fps); + return 0; +} + +static const char pcb_acts_Help[] = "Help()"; +static const char pcb_acth_Help[] = "On-line action help"; +static fgw_error_t pcb_act_Help(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + pcb_print_actions(); + PCB_ACT_IRES(0); + return 0; +} + +static const char pcb_acts_Redraw[] = "Redraw()"; +static const char pcb_acth_Redraw[] = "Redraw the entire screen"; +static fgw_error_t pcb_act_Redraw(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + pcb_gui->invalidate_all(pcb_gui); + PCB_ACT_IRES(0); + return 0; +} + +static pcb_action_t rnd_gui_action_list[] = { + {"FullScreen", pcb_act_FullScreen, pcb_acth_FullScreen, pcb_acts_FullScreen}, + {"CreateMenu", pcb_act_CreateMenu, pcb_acth_CreateMenu, pcb_acts_CreateMenu}, + {"RemoveMenu", pcb_act_RemoveMenu, pcb_acth_RemoveMenu, pcb_acts_RemoveMenu}, + {"Cursor", pcb_act_Cursor, pcb_acth_Cursor, pcb_acts_Cursor}, + {"MoveCursorTo", pcb_act_MoveCursorTo, pcb_acth_MoveCursorTo, pcb_acts_MoveCursorTo}, + {"Grid", pcb_act_grid, pcb_acth_grid, pcb_acts_grid}, + {"GetXY", pcb_act_GetXY, pcb_acth_GetXY, pcb_acts_GetXY}, + {"Benchmark", pcb_act_Benchmark, pcb_acth_Benchmark, pcb_acts_Benchmark}, + {"Help", pcb_act_Help, pcb_acth_Help, pcb_acts_Help}, + {"Redraw", pcb_act_Redraw, pcb_acth_Redraw, pcb_acts_Redraw} +}; + +void rnd_gui_act_init2(void) +{ + PCB_REGISTER_ACTIONS(rnd_gui_action_list, NULL); +} Index: trunk/src/librnd/core/hid_init.c =================================================================== --- trunk/src/librnd/core/hid_init.c (revision 29400) +++ trunk/src/librnd/core/hid_init.c (revision 29401) @@ -322,7 +322,9 @@ extern void pcb_hid_nogui_init2(void); extern void rnd_conf_act_init2(void); extern void rnd_tool_act_init2(void); +extern void rnd_gui_act_init2(void); + void pcb_hidlib_init2(const pup_buildin_t *buildins, const pup_buildin_t *local_buildins) { pcb_actions_init(); @@ -370,6 +372,7 @@ pcb_hid_nogui_init2(); rnd_conf_act_init2(); rnd_tool_act_init2(); + rnd_gui_act_init2(); } Index: trunk/src/librnd/core/hidlib.h =================================================================== --- trunk/src/librnd/core/hidlib.h (revision 29400) +++ trunk/src/librnd/core/hidlib.h (revision 29401) @@ -47,6 +47,7 @@ unsigned int tool_hit; /* optional: type of a hit object of PCB_MOVE_TYPES; 0 if there was no PCB_MOVE_TYPES object under the crosshair */ unsigned int tool_click:1; /* optional: true if clicked somewhere with the arrow tool */ pcb_mark_t tool_grabbed; /* point where a drag&drop operation started */ + pcb_box_t *tool_snapped_obj_bbox; /* internal */ int *batch_ask_ovr; /* if not NULL, override local ask-overwrite state - useful when manu operations that need to write files are ran in batch, e.g. in a cam job */