Index: trunk/src_plugins/act_draw/act_draw.c =================================================================== --- trunk/src_plugins/act_draw/act_draw.c (revision 31721) +++ trunk/src_plugins/act_draw/act_draw.c (revision 31722) @@ -63,6 +63,7 @@ } while(0) #include "act_pstk_proto.c" +#include "act_polybool.c" static const char pcb_acts_LineNew[] = "LineNew([noundo,] data, layer, X1, Y1, X2, Y2, Thickness, Clearance, Flags)"; static const char pcb_acth_LineNew[] = "Create a pcb line segment on a layer. For now data must be \"pcb\". Returns the idpath of the new object or 0 on error."; @@ -470,7 +471,8 @@ {"PolyNewEnd", pcb_act_PolyNewEnd, pcb_acth_PolyNewEnd, pcb_acts_PolyNewEnd}, {"PstkProtoTmp", pcb_act_PstkProtoTmp, pcb_acth_PstkProtoTmp, pcb_acts_PstkProtoTmp}, {"PstkProtoEdit", pcb_act_PstkProtoEdit, pcb_acth_PstkProtoEdit, pcb_acts_PstkProtoEdit}, - {"LayerObjDup", pcb_act_LayerObjDup, pcb_acth_LayerObjDup, pcb_acts_LayerObjDup} + {"LayerObjDup", pcb_act_LayerObjDup, pcb_acth_LayerObjDup, pcb_acts_LayerObjDup}, + {"PolyBool", pcb_act_PolyBool, pcb_acth_PolyBool, pcb_acts_PolyBool} }; static const char *act_draw_cookie = "act_draw"; Index: trunk/src_plugins/act_draw/act_polybool.c =================================================================== --- trunk/src_plugins/act_draw/act_polybool.c (nonexistent) +++ trunk/src_plugins/act_draw/act_polybool.c (revision 31722) @@ -0,0 +1,94 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 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 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") + */ + +/* included from act_draw.c */ + +#include "obj_pstk_inlines.h" + +static void pick_obj(vtp0_t *objs) +{ + rnd_coord_t x, y; + const char *msg = objs->used == 0 ? ask_first : ask_subseq; + for(;;) { + rnd_hid_get_coords(msg, &x, &y, 1); + rnd_trace("xy: %$mm %$mm\n", x, y); + } +} + +static const char pcb_acts_PolyBool[] = "PstkProto([noundo,] unite|isect|sub|xor, [poly1, poly2, [poly...]])\n"; +static const char pcb_acth_PolyBool[] = "Perform polygon boolean operation on the clipped polygons referred. A poly is either and idpath, selected, found or object (for the object under the cursor). When not specified, two object polygons are used."; +static fgw_error_t pcb_act_PolyBool(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + char *cmd; + int cmdi, n; + vtp0_t objs; + rnd_bool_op_t bop; + const char *ask_first, *ask_subseq; + DRAWOPTARG; + + + RND_ACT_CONVARG(1+ao, FGW_STR, PolyBool, cmd = argv[1+ao].val.str); + + cmdi = act_draw_keywords_sphash(cmd); + switch(cmdi) { + case act_draw_keywords_unite: bop = RND_PBO_UNITE; ask_first = ask_subseq = "click on polygon to unite"; break; + case act_draw_keywords_isect: bop = RND_PBO_ISECT; ask_first = ask_subseq = "click on polygon to contribute in intersection"; break; + case act_draw_keywords_sub: bop = RND_PBO_SUB; ask_first = "click on polygon to subtract other polygons from"; ask_subseq = "click on polygon to subtract from the first"; break; + case act_draw_keywords_xor: bop = RND_PBO_XOR; ask_first = ask_subseq = "click on polygon to xor"; break; + default: + RND_ACT_FAIL(PolyBool); + } + + RND_ACT_IRES(-1); + vtp0_init(&objs); + for(n = 2+ao; n < argc; n++) { + if ((argv[n].type & FGW_STR) == FGW_STR) { + if (strcmp(argv[n].val.str, "object") == 0) { + pick_obj(&objs); + } + else { + rnd_message(RND_MSG_ERROR, "Invalid polygon specification string: '%s'\n", argv[n].val.str); + goto error; + } + } + else { + pcb_idpath_t *idp; + RND_ACT_MAY_CONVARG(n, FGW_IDPATH, PolyBool, idp = fgw_idpath(&argv[n])); + if ((idp == NULL) || !fgw_ptr_in_domain(&rnd_fgw, &argv[n], RND_PTR_DOMAIN_IDPATH)) { + rnd_message(RND_MSG_ERROR, "Invalid polygon specification idpath in arg %d\n", n); + goto error; + } + } + } + + while(objs.used < 2) + pick_obj(&objs); + + error:; + vtp0_uninit(&objs); + return 0; +} + Index: trunk/src_plugins/act_draw/keywords.sphash =================================================================== --- trunk/src_plugins/act_draw/keywords.sphash (revision 31721) +++ trunk/src_plugins/act_draw/keywords.sphash (revision 31722) @@ -7,3 +7,7 @@ remove hdia shape:line +unite +isect +sub +xor