Index: trunk/src/layer.c =================================================================== --- trunk/src/layer.c (revision 19102) +++ trunk/src/layer.c (revision 19103) @@ -38,6 +38,8 @@ #include "layer_ui.h" #include "layer_vis.h" #include "rtree.h" +#include "funchash.h" +#include "funchash_core.h" #include "obj_pstk_inlines.h" #include "list_common.h" @@ -467,6 +469,35 @@ return pcb_layer_rename_(&data->Layer[layer], pcb_strdup(color)); } +int pcb_layer_set_purpose__(pcb_layer_t *ly, char *purpose) +{ + free(ly->purpose); + if (purpose == NULL) { + ly->purpose = NULL; + ly->purpi = F_user; + } + else { + ly->purpose = purpose; + ly->purpi = pcb_funchash_get(purpose, NULL); + if (ly->purpi < 0) + ly->purpi = F_user; + } + return 0; +} + +int pcb_layer_set_purpose_(pcb_layer_t *ly, char *purpose) +{ + int ret = pcb_layer_set_purpose__(ly, purpose); + pcb_event(PCB_EVENT_LAYERS_CHANGED, NULL); + return ret; +} + +int pcb_layer_set_purpose(pcb_layer_t *ly, const char *purpose) +{ + return pcb_layer_set_purpose_(ly, pcb_strdup(purpose)); +} + + #undef APPEND static int is_last_top_copper_layer(pcb_board_t *pcb, int layer) Index: trunk/src/layer.h =================================================================== --- trunk/src/layer.h (revision 19102) +++ trunk/src/layer.h (revision 19103) @@ -115,6 +115,8 @@ const char *name; /* layer name */ pcb_layer_combining_t comb; /* how to combine this layer with other layers in the group */ + char *purpose; /* what a doc/mech layer is used for */ + int purpi; /* integer version of purpose from the funtion hash (cache) */ /* for bound layers these point to the board layer's*/ pcb_rtree_t *line_tree, *text_tree, *polygon_tree, *arc_tree; @@ -268,7 +270,12 @@ int pcb_layer_rename_(pcb_layer_t *Layer, char *Name); int pcb_layer_recolor_(pcb_layer_t *Layer, char *color); +/* Change the purpose field and recalc purpi (not undoable) */ +int pcb_layer_set_purpose__(pcb_layer_t *ly, char *purpose); /* no strdup, no event */ +int pcb_layer_set_purpose_(pcb_layer_t *ly, char *purpose); /* no strdup, send layer change event */ +int pcb_layer_set_purpose(pcb_layer_t *ly, const char *purpose); /* strdup, send event */ + /* index is 0..PCB_MAX_LAYER-1. If old_index is -1, a new layer is inserted at that index. If new_index is -1, the specified layer is deleted. Returns non-zero on error, zero if OK. */