1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
/*
* 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")
*/
/* Query language - geometry functions */
#include "obj_poly.h"
#include "data_it.h"
#define PCB dontuse
static int fnc_poly_num_islands(pcb_qry_exec_t *ectx, int argc, pcb_qry_val_t *argv, pcb_qry_val_t *res)
{
pcb_poly_t *poly;
long cnt = 0;
pcb_poly_it_t it;
rnd_polyarea_t *pa;
if ((argc != 1) || (argv[0].type != PCBQ_VT_OBJ))
return -1;
poly = (pcb_poly_t *)argv[0].data.obj;
if (poly->type != PCB_OBJ_POLY)
PCB_QRY_RET_INV(res);
if (poly->Clipped != NULL) {
if (PCB_FLAG_TEST(PCB_FLAG_FULLPOLY, poly))
for(pa = pcb_poly_island_first(poly, &it); pa != NULL; pa = pcb_poly_island_next(&it))
cnt++;
else
cnt = 1;
}
PCB_QRY_RET_INT(res, cnt);
}
/* pcb_intersect_obj_obj() wrapper that fails for layerobj-layerobj
check if they are in different groups */
RND_INLINE int isc_obj_obj(pcb_find_t *fctx, pcb_any_obj_t *o1, pcb_any_obj_t *o2)
{
/* in case of anylayer just skip, they don't have to be on the same layer group;
else if any object is a padstack, the low level isc function will handle it */
if (fctx->pstk_anylayer || (o1->type == PCB_OBJ_PSTK) || (o2->type == PCB_OBJ_PSTK))
return pcb_intersect_obj_obj(fctx, o1, o2);
/* one final fallback: non-layer-objects can't be compared on group level */
if ((o1->parent_type != PCB_PARENT_LAYER) || (o2->parent_type != PCB_PARENT_LAYER))
return pcb_intersect_obj_obj(fctx, o1, o2);
/* we are not anylayer; if the two objects are not on the same layer group,
it is impossible for them to intersect */
if ((o1->parent.layer != o2->parent.layer) && (pcb_layer_get_group_(o1->parent.layer) != pcb_layer_get_group_(o2->parent.layer)))
return rnd_false;
return pcb_intersect_obj_obj(fctx, o1, o2);
}
static int isc_subc_obj(pcb_qry_exec_t *ectx, pcb_find_t *fctx, pcb_subc_t *subc, pcb_any_obj_t *obj)
{
pcb_any_obj_t *so;
pcb_data_it_t it;
for(so = pcb_data_first(&it, subc->data, PCB_OBJ_CLASS_REAL); so != NULL; so = pcb_data_next(&it))
if (isc_obj_obj(fctx, obj, so))
return 1;
return 0;
}
static int isc_subc_subc(pcb_qry_exec_t *ectx, pcb_find_t *fctx, pcb_subc_t *subc1, pcb_subc_t *subc2)
{
pcb_any_obj_t *so;
pcb_data_it_t it;
for(so = pcb_data_first(&it, subc1->data, PCB_OBJ_CLASS_REAL); so != NULL; so = pcb_data_next(&it))
if (isc_subc_obj(ectx, fctx, subc2, so))
return 1;
return 0;
}
static int overlap_(pcb_qry_exec_t *ectx, pcb_find_t *fctx, int argc, pcb_qry_val_t *argv, pcb_qry_val_t *res)
{
if ((argc < 2) || (argv[0].type != PCBQ_VT_OBJ) || (argv[1].type != PCBQ_VT_OBJ))
return -1;
if (argc > 2) {
PCB_QRY_ARG_CONV_TO_COORD(fctx->bloat, &argv[2], return -1);
}
if (argc > 3)
return -1;
if ((argv[0].data.obj->type == PCB_OBJ_SUBC) && (argv[1].data.obj->type == PCB_OBJ_SUBC))
PCB_QRY_RET_INT(res, isc_subc_subc(ectx, fctx, (pcb_subc_t *)argv[0].data.obj, (pcb_subc_t *)argv[1].data.obj));
if (argv[0].data.obj->type == PCB_OBJ_SUBC)
PCB_QRY_RET_INT(res, isc_subc_obj(ectx, fctx, (pcb_subc_t *)argv[0].data.obj, argv[1].data.obj));
if (argv[1].data.obj->type == PCB_OBJ_SUBC)
PCB_QRY_RET_INT(res, isc_subc_obj(ectx, fctx, (pcb_subc_t *)argv[1].data.obj, argv[0].data.obj));
PCB_QRY_RET_INT(res, isc_obj_obj(fctx, argv[0].data.obj, argv[1].data.obj));
}
static int fnc_overlap(pcb_qry_exec_t *ectx, int argc, pcb_qry_val_t *argv, pcb_qry_val_t *res)
{
static pcb_find_t fctx = {0};
fctx.bloat = 0;
fctx.ignore_clearance = 1;
fctx.allow_noncopper_pstk = 1;
fctx.pstk_anylayer = 1;
return overlap_(ectx, &fctx, argc, argv, res);
}
static int fnc_intersect(pcb_qry_exec_t *ectx, int argc, pcb_qry_val_t *argv, pcb_qry_val_t *res)
{
static pcb_find_t fctx = {0};
fctx.ignore_clearance = 1;
fctx.allow_noncopper_pstk = 1;
return overlap_(ectx, &fctx, argc, argv, res);
}
|