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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/*
* COPYRIGHT
*
* pcb-rnd, interactive printed circuit board design
* Copyright (C) 2017, 2018 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")
*/
#include "config.h"
#include "board.h"
#include "data.h"
#include "conf_core.h"
#include "event.h"
#include "layer.h"
#include "layer_ui.h"
#include "layer_grp.h"
#include "pcb-printf.h"
#include "hid_cfg.h"
#include "hid.h"
#include "layer_menu.h"
typedef struct {
const char *anch;
int view;
} ly_ctx_t;
static void layer_install_menu1(void *ctx_, pcb_hid_cfg_t *cfg, lht_node_t *node, char *path)
{
ly_ctx_t *ctx = ctx_;
int plen = strlen(path);
int len_avail = 125;
char *end = path + plen;
pcb_menu_prop_t props;
char act[256], chk[256];
int idx, max_ml, sect;
pcb_layergrp_id_t gid;
const pcb_menu_layers_t *ml;
memset(&props, 0, sizeof(props));
props.action = act;
props.update_on = "";
props.cookie = ctx->anch;
pcb_hid_cfg_del_anchor_menus(node, ctx->anch);
/* prepare for appending the strings at the end of the path, "under" the anchor */
*end = '/';
end++;
/* ui layers; have to go reverse to keep order because this will insert items */
if ((ctx->view) && (vtp0_len(&pcb_uilayers) > 0)) {
for(idx = vtp0_len(&pcb_uilayers)-1; idx >= 0; idx--) {
pcb_layer_t *ly = pcb_uilayers.array[idx];
if ((ly == NULL) || (ly->name == NULL))
continue;
props.checked = chk;
sprintf(act, "ToggleView(ui:%d)", idx);
sprintf(chk, "ChkView(ui:%d)", idx);
pcb_snprintf(end, len_avail, " %s", ly->name);
pcb_gui->create_menu(path, &props);
}
props.checked = NULL;
pcb_snprintf(end, len_avail, "[UI]");
pcb_gui->create_menu(path, &props);
}
/* menu-only virtual layers; have to go reverse to keep order because this will insert items */
for(ml = pcb_menu_layers, max_ml = 0; ml->name != NULL; ml++) max_ml++;
for(idx = max_ml-1; idx >= 0; idx--) {
ml = &pcb_menu_layers[idx];
props.checked = chk;
if (ctx->view) {
sprintf(act, "ToggleView(%s)", ml->abbrev);
sprintf(chk, "ChkView(%s)", ml->abbrev);
}
else {
if (ml->sel_offs == 0) /* do not list layers that can not be selected */
continue;
sprintf(act, "SelectLayer(%s)", ml->abbrev);
sprintf(chk, "ChkLayer(%s)", ml->abbrev);
}
pcb_snprintf(end, len_avail, " %s", ml->name);
pcb_gui->create_menu(path, &props);
}
props.checked = NULL;
pcb_snprintf(end, len_avail, "[virtual]");
pcb_gui->create_menu(path, &props);
/* have to go reverse to keep order because this will insert items */
for(sect = 0; sect < 2; sect++) {
pcb_snprintf(end, len_avail, "-");
props.foreground = NULL;
props.background = NULL;
props.checked = NULL;
*act = '\0';
*chk = '\0';
pcb_gui->create_menu(path, &props);
for(gid = pcb_max_group(PCB)-1; gid >= 0; gid--) {
pcb_layergrp_t *g = &PCB->LayerGroups.grp[gid];
int n;
if (g->ltype & PCB_LYT_SUBSTRATE)
continue;
if (!!sect != !!(PCB_LAYER_IN_STACK(g->ltype)))
continue;
for(n = g->len-1; n >= 0; n--) {
pcb_layer_id_t lid = g->lid[n];
pcb_layer_t *l = pcb_get_layer(PCB->Data, lid);
pcb_layer_type_t lyt = pcb_layer_flags_(l);
props.background = &l->meta.real.color;
props.foreground = &conf_core.appearance.color.background;
props.checked = chk;
if (ctx->view) {
sprintf(act, "ToggleView(%ld)", lid+1);
sprintf(chk, "ChkView(%ld)", lid+1);
}
else {
sprintf(act, "SelectLayer(%ld)", lid+1);
sprintf(chk, "ChkLayer(%ld)", lid+1);
}
pcb_snprintf(end, len_avail, " %s", l->name);
pcb_gui->create_menu(path, &props);
}
props.foreground = NULL;
props.background = NULL;
props.checked = NULL;
pcb_snprintf(end, len_avail, "[%s]", g->name);
pcb_gui->create_menu(path, &props);
}
}
/* restore the path */
end--;
*end = '\0';
}
static void layer_install_menu(void)
{
ly_ctx_t ctx;
ctx.view = 1;
ctx.anch = "@layerview";
pcb_hid_cfg_map_anchor_menus(ctx.anch, layer_install_menu1, &ctx);
ctx.view = 0;
ctx.anch = "@layerpick";
pcb_hid_cfg_map_anchor_menus(ctx.anch, layer_install_menu1, &ctx);
}
void pcb_layer_menu_update_ev(void *user_data, int argc, pcb_event_arg_t argv[])
{
layer_install_menu();
if ((pcb_gui != NULL) && (pcb_gui->update_menu_checkbox != NULL))
pcb_gui->update_menu_checkbox(NULL);
}
void pcb_layer_menu_vis_update_ev(void *user_data, int argc, pcb_event_arg_t argv[])
{
if ((pcb_gui != NULL) && (pcb_gui->update_menu_checkbox != NULL))
pcb_gui->update_menu_checkbox(NULL);
}
|