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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
/*
* COPYRIGHT
*
* pcb-rnd, interactive printed circuit board design
* Copyright (C) 2017, 2018, 2020, 2021 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 <genvector/gds_char.h>
#include "board.h"
#include "data.h"
#include "conf_core.h"
#include <librnd/core/rnd_conf.h>
#include <librnd/core/event.h>
#include "layer.h"
#include "layer_ui.h"
#include "layer_grp.h"
#include <librnd/core/rnd_printf.h>
#include <librnd/core/hid_cfg.h>
#include <librnd/hid/hid.h>
#include <librnd/hid/hid_menu.h>
#include "layer_menu.h"
static const char *menu_cookie = "lib_hid_pcbui layer menus";
static void layer_install_menu1(const char *anch, int view)
{
int plen = strlen(anch);
rnd_menu_prop_t props;
char act[256], chk[256];
char *sep;
int idx, max_ml, sect, sepo;
rnd_layergrp_id_t gid;
const pcb_menu_layers_t *ml;
gds_t path = {0};
memset(&props, 0, sizeof(props));
props.action = act;
props.update_on = "";
props.cookie = menu_cookie;
/* prepare for appending the strings at the end of the path, "under" the anchor */
gds_append_str(&path, anch);
gds_append(&path, '/');
plen++;
/* ui layers; have to go reverse to keep order because this will insert items */
if ((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);
gds_truncate(&path, plen);
gds_append_str(&path, " ");
sepo = path.used;
gds_append_str(&path, ly->name);
for(sep = path.array + sepo - 1; *sep != '\0'; sep++) /* do not allow '/' in layer name, that would kill the menu system */
if (*sep == '/')
*sep = '|';
rnd_hid_menu_create(path.array, &props);
}
props.checked = NULL;
gds_truncate(&path, plen);
gds_append_str(&path, "[UI]");
rnd_hid_menu_create(path.array, &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 (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);
}
gds_truncate(&path, plen);
gds_append_str(&path, " ");
sepo = path.used;
gds_append_str(&path, ml->name);
for(sep = path.array + sepo - 1; *sep !='\0'; sep++) /* do not allow '/' in layer name, that would kill the menu system */
if (*sep == '/')
*sep = '|';
rnd_hid_menu_create(path.array, &props);
}
props.checked = NULL;
gds_truncate(&path, plen);
gds_append_str(&path, "[virtual]");
rnd_hid_menu_create(path.array, &props);
/* have to go reverse to keep order because this will insert items */
for(sect = 0; sect < 2; sect++) {
gds_truncate(&path, plen);
gds_append(&path, '-');
props.foreground = NULL;
props.background = NULL;
props.checked = NULL;
*act = '\0';
*chk = '\0';
rnd_hid_menu_create(path.array, &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--) {
rnd_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 = &rnd_conf.appearance.color.background;
props.checked = chk;
if (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);
}
gds_truncate(&path, plen);
gds_append_str(&path, " ");
sepo = path.used;
gds_append_str(&path, l->name);
for(sep = path.array + sepo - 1; *sep != '\0'; sep++) /* do not allow '/' in layer name, that would kill the menu system */
if (*sep == '/')
*sep = '|';
rnd_hid_menu_create(path.array, &props);
}
props.foreground = NULL;
props.background = NULL;
props.checked = NULL;
gds_truncate(&path, plen);
gds_append(&path, '[');
sepo = path.used;
gds_append_str(&path, g->name);
gds_append(&path, ']');
for(sep = path.array + sepo - 1; *sep != '\0'; sep++) /* do not allow '/' in layer name, that would kill the menu system */
if (*sep == '/')
*sep = '|';
rnd_hid_menu_create(path.array, &props);
}
}
gds_uninit(&path);
}
static void custom_layer_attr_key(pcb_layer_t *l, rnd_layer_id_t lid, const char *attrname, const char *menu_prefix, const char *action_prefix, rnd_menu_prop_t *keyprops, gds_t *path, int plen)
{
char *sep, *key = pcb_attribute_get(&l->Attributes, attrname);
int sepo;
if (key != NULL) {
keyprops->accel = key;
gds_truncate(path, plen);
sepo = path->used+1;
rnd_append_printf(path, "%s %ld:%s", menu_prefix, lid+1, l->name);
sprintf((char *)keyprops->action, "%s(%ld)", action_prefix, lid+1);
for(sep = path->array + sepo - 1; *sep != '\0'; sep++) /* do not allow '/' in layer name, that would kill the menu system */
if (*sep == '/')
*sep = '|';
rnd_hid_menu_create(path->array, keyprops);
}
}
static void layer_install_menu_key(const char *anch, int view)
{
int plen = strlen(anch);
char act[256];
rnd_layer_id_t lid;
pcb_layer_t *l;
rnd_menu_prop_t keyprops;
gds_t path = {0};
/* prepare for appending the strings at the end of the path, "under" the anchor */
gds_append_str(&path, anch);
gds_append(&path, '/');
plen++;
memset(&keyprops, 0, sizeof(keyprops));
keyprops.action = act;
keyprops.update_on = "";
keyprops.cookie = menu_cookie;
for(lid = 0, l = PCB->Data->Layer; lid < PCB->Data->LayerN; lid++,l++) {
custom_layer_attr_key(l, lid, "pcb-rnd::key::select", "select", "SelectLayer", &keyprops, &path, plen);
custom_layer_attr_key(l, lid, "pcb-rnd::key::vis", "vis", "ToggleView", &keyprops, &path, plen);
}
gds_uninit(&path);
}
static int need_layer_menu_update = 0, need_layer_key_update = 0;
void pcb_layer_menu_batch_timer_ev(rnd_design_t *hidlib, void *user_data, int argc, rnd_event_arg_t argv[])
{
int keys_done = 0;
if (pcb_layergrp_is_inhibited())
return;
if (need_layer_menu_update) {
/*rnd_trace("layer menu update.\n");*/
rnd_hid_menu_unload(rnd_gui, menu_cookie);
layer_install_menu1("/anchored/@layerview", 1);
layer_install_menu1("/anchored/@layerpick", 0);
layer_install_menu_key("/anchored/@layerkeys", 0);
need_layer_menu_update = 0;
keys_done = 1;
}
if (need_layer_key_update) {
/*rnd_trace("layer key update timer!\n");*/
if (!keys_done)
layer_install_menu_key("/anchored/@layerkeys", 0);
need_layer_key_update = 0;
}
}
static void layer_install_menu(rnd_design_t *hidlib)
{
need_layer_menu_update = 1;
rnd_hid_gui_batch_timer(hidlib);
}
void pcb_layer_menu_update_ev(rnd_design_t *hidlib, void *user_data, int argc, rnd_event_arg_t argv[])
{
layer_install_menu(hidlib);
if ((rnd_gui != NULL) && (rnd_gui->update_menu_checkbox != NULL))
rnd_gui->update_menu_checkbox(rnd_gui, NULL);
}
void pcb_layer_menu_vis_update_ev(rnd_design_t *hidlib, void *user_data, int argc, rnd_event_arg_t argv[])
{
if ((rnd_gui != NULL) && (rnd_gui->update_menu_checkbox != NULL))
rnd_gui->update_menu_checkbox(rnd_gui, NULL);
}
void pcb_layer_menu_key_update_ev(rnd_design_t *hidlib, void *user_data, int argc, rnd_event_arg_t argv[])
{
need_layer_key_update = 1;
rnd_hid_gui_batch_timer(hidlib);
}
|