Index: fields.sphash =================================================================== --- fields.sphash (revision 33103) +++ fields.sphash (revision 33104) @@ -13,6 +13,7 @@ thickness clearance layer +layergroup width height name Index: query_access.c =================================================================== --- query_access.c (revision 33103) +++ query_access.c (revision 33104) @@ -424,11 +424,66 @@ PCB_QRY_RET_INV(res); } +static int field_layergrp(pcb_qry_exec_t *ec, pcb_any_obj_t *obj, pcb_qry_node_t *fld, pcb_qry_val_t *res) +{ + pcb_layergrp_t *g = (pcb_layergrp_t *)obj; + query_fields_keys_t fh1; + + fld2hash_req(fh1, fld, 0); + + /* in some cases .type will do the wrong thing at the caller; the escape is .layer.type; drop the redundant .layer */ + if (fh1 == query_fields_layergroup) { + fld = fld->next; + fld2hash_req(fh1, fld, 0); + } + + if (fh1 == query_fields_a) { + const char *s2; + fld2str_req(s2, fld, 1); + PCB_QRY_RET_STR(res, pcb_attribute_get(&g->Attributes, s2)); + } + + if (fld->next != NULL) + PCB_QRY_RET_INV(res); + + switch(fh1) { + case query_fields_IID: PCB_QRY_RET_INT(res, pcb_obj_iid((pcb_any_obj_t *)g)); + case query_fields_name: PCB_QRY_RET_STR(res, g->name); + case query_fields_visible: PCB_QRY_RET_INT(res, g - ec->pcb->LayerGroups.grp); + case query_fields_position: PCB_QRY_RET_INT(res, g->ltype & PCB_LYT_ANYWHERE); + case query_fields_type: PCB_QRY_RET_INT(res, g->ltype & PCB_LYT_ANYTHING); + case query_fields_purpose: PCB_QRY_RET_STR(res, g->purpose); + default:; + } + + PCB_QRY_RET_INV(res); +} + static int field_layer_from_ptr(pcb_qry_exec_t *ec, pcb_layer_t *l, pcb_qry_node_t *fld, pcb_qry_val_t *res) { return field_layer(ec, (pcb_any_obj_t *)l, fld, res); } +static int field_layergrp_from_ptr(pcb_qry_exec_t *ec, pcb_layergrp_t *l, pcb_qry_node_t *fld, pcb_qry_val_t *res) +{ + return field_layergrp(ec, (pcb_any_obj_t *)l, fld, res); +} + +static int field_layergrp_from_layer_ptr(pcb_qry_exec_t *ec, pcb_layer_t *l, pcb_qry_node_t *fld, pcb_qry_val_t *res) +{ + pcb_layergrp_t *grp; + + l = pcb_layer_get_real(l); + if (l == NULL) + PCB_QRY_RET_INV(res); + + grp = pcb_get_layergrp(ec->pcb, l->meta.real.grp); + if (grp == NULL) + PCB_QRY_RET_INV(res); + + return field_layergrp(ec, (pcb_any_obj_t *)grp, fld, res); +} + /* process from .layer */ static int layer_of_obj(pcb_qry_exec_t *ec, pcb_qry_node_t *fld, pcb_qry_val_t *res, pcb_layer_type_t mask) { @@ -450,6 +505,27 @@ return field_layer_from_ptr(ec, PCB->Data->Layer+id, fld, res); } +/* process from .layergroup */ +static int layergrp_of_obj(pcb_qry_exec_t *ec, pcb_qry_node_t *fld, pcb_qry_val_t *res, pcb_layer_type_t mask) +{ + rnd_layergrp_id_t id; + const char *s1; + + if (pcb_layergrp_list(PCB, mask, &id, 1) != 1) + PCB_QRY_RET_INV(res); + + fld2str_req(s1, fld, 0); + + if (s1 == NULL) { + res->source = NULL; + res->type = PCBQ_VT_OBJ; + res->data.obj = (pcb_any_obj_t *)&(PCB->LayerGroups.grp[id]); + return 0; + } + + return field_layergrp_from_ptr(ec, PCB->LayerGroups.grp+id, fld, res); +} + static double pcb_line_len2(pcb_line_t *l) { double x = l->Point1.X - l->Point2.X; @@ -476,6 +552,12 @@ else PCB_QRY_RET_INV(res); } + else if (fh1 == query_fields_layergroup) { + if (obj->parent_type == PCB_PARENT_LAYER) + return field_layergrp_from_layer_ptr(ec, obj->parent.layer, fld->next, res); + else + PCB_QRY_RET_INV(res); + } NETNAME_FIELDS(ec); @@ -547,6 +629,12 @@ else PCB_QRY_RET_INV(res); } + else if (fh1 == query_fields_layergroup) { + if (obj->parent_type == PCB_PARENT_LAYER) + return field_layergrp_from_layer_ptr(ec, obj->parent.layer, fld->next, res); + else + PCB_QRY_RET_INV(res); + } NETNAME_FIELDS(ec); @@ -603,6 +691,12 @@ else PCB_QRY_RET_INV(res); } + else if (fh1 == query_fields_layergroup) { + if (obj->parent_type == PCB_PARENT_LAYER) + return field_layergrp_from_layer_ptr(ec, obj->parent.layer, fld->next, res); + else + PCB_QRY_RET_INV(res); + } if (fld->next != NULL) PCB_QRY_RET_INV(res); @@ -638,6 +732,12 @@ else PCB_QRY_RET_INV(res); } + else if (fh1 == query_fields_layergroup) { + if (obj->parent_type == PCB_PARENT_LAYER) + return field_layergrp_from_layer_ptr(ec, obj->parent.layer, fld->next, res); + else + PCB_QRY_RET_INV(res); + } NETNAME_FIELDS(ec); @@ -680,6 +780,12 @@ else PCB_QRY_RET_INV(res); } + else if (fh1 == query_fields_layergroup) { + if (obj->parent_type == PCB_PARENT_LAYER) + return field_layergrp_from_layer_ptr(ec, obj->parent.layer, fld->next, res); + else + PCB_QRY_RET_INV(res); + } NETNAME_FIELDS(ec); @@ -819,6 +925,9 @@ if (fh1 == query_fields_layer) return layer_of_obj(ec, fld->next, res, PCB_LYT_SILK | (PCB_FLAG_TEST(PCB_FLAG_ONSOLDER, p) ? PCB_LYT_BOTTOM : PCB_LYT_TOP)); + if (fh1 == query_fields_layergroup) + return layergrp_of_obj(ec, fld->next, res, PCB_LYT_SILK | (PCB_FLAG_TEST(PCB_FLAG_ONSOLDER, p) ? PCB_LYT_BOTTOM : PCB_LYT_TOP)); + if (fld->next != NULL) PCB_QRY_RET_INV(res); @@ -914,8 +1023,7 @@ case PCB_OBJ_NET: return field_net(ec, obj, fld, res); case PCB_OBJ_LAYER: return field_layer(ec, obj, fld, res); -TODO("layer TODO") - case PCB_OBJ_LAYERGRP: + case PCB_OBJ_LAYERGRP: return field_layergrp(ec, obj, fld, res); default:; }