diff --git a/gds-render-gui.c b/gds-render-gui.c index 7802013..2193066 100644 --- a/gds-render-gui.c +++ b/gds-render-gui.c @@ -691,19 +691,13 @@ static void on_select_all_layers_clicked(GtkWidget *button, gpointer user_data) layer_selector_select_all_layers(gui->layer_selector, TRUE); } -static void auto_naming_clicked(GtkWidget *button, gpointer user_data) +static gboolean auto_naming_ask_for_override(GdsRenderGui *gui) { - GdsRenderGui *gui; GtkDialog *dialog; - gboolean overwrite; - int dialog_result; - (void)button; + gint dialog_result; + gboolean overwrite = FALSE; - gui = RENDERER_GUI(user_data); - - /* Don't do anything if the selector is empty. */ - if (!layer_selector_contains_elements(gui->layer_selector)) - return; + g_return_val_if_fail(RENDERER_IS_GUI(gui), FALSE); /* Ask for overwrite */ dialog = GTK_DIALOG(gtk_message_dialog_new(gui->main_window, GTK_DIALOG_USE_HEADER_BAR, GTK_MESSAGE_QUESTION, @@ -720,6 +714,25 @@ static void auto_naming_clicked(GtkWidget *button, gpointer user_data) } gtk_widget_destroy(GTK_WIDGET(dialog)); + return overwrite; +} + +static void auto_naming_clicked(GtkWidget *button, gpointer user_data) +{ + GdsRenderGui *gui; + gboolean overwrite = FALSE; + (void)button; + + gui = RENDERER_GUI(user_data); + + /* Don't do anything if the selector is empty. */ + if (!layer_selector_contains_elements(gui->layer_selector)) + return; + + /* Ask, if names shall be overwritten, if they are not empty */ + if (layer_selector_num_of_named_elements(gui->layer_selector) > 0) + overwrite = auto_naming_ask_for_override(gui); + layer_selector_auto_name_layers(gui->layer_selector, overwrite); } diff --git a/include/gds-render/layer/layer-selector.h b/include/gds-render/layer/layer-selector.h index a3d7535..d4a6871 100644 --- a/include/gds-render/layer/layer-selector.h +++ b/include/gds-render/layer/layer-selector.h @@ -130,6 +130,13 @@ void layer_selector_auto_name_layers(LayerSelector *layer_selector, gboolean ove */ gboolean layer_selector_contains_elements(LayerSelector *layer_selector); +/** + * @brief Get number of layer elements that are named + * @param[in] layer_selector Layer selector + * @return Number of layers with a name != NULL or != "" + */ +size_t layer_selector_num_of_named_elements(LayerSelector *layer_selector); + G_END_DECLS #endif /* __LAYER_SELECTOR_H__ */ diff --git a/include/gds-render/output-renderers/cairo-renderer.h b/include/gds-render/output-renderers/cairo-renderer.h index cceb692..78cec69 100644 --- a/include/gds-render/output-renderers/cairo-renderer.h +++ b/include/gds-render/output-renderers/cairo-renderer.h @@ -38,7 +38,7 @@ G_DECLARE_FINAL_TYPE(CairoRenderer, cairo_renderer, GDS_RENDER, CAIRO_RENDERER, #define GDS_RENDER_TYPE_CAIRO_RENDERER (cairo_renderer_get_type()) -#define MAX_LAYERS (300) /**< \brief Maximum layer count the output renderer can process. Typically GDS only specifies up to 255 layers.*/ +#define MAX_LAYERS (5000) /**< \brief Maximum layer count the output renderer can process. Typically GDS only specifies up to 255 layers.*/ /** * @brief Create new CairoRenderer for SVG output diff --git a/layer/layer-selector.c b/layer/layer-selector.c index 4111731..0872c9c 100644 --- a/layer/layer-selector.c +++ b/layer/layer-selector.c @@ -822,12 +822,10 @@ void layer_selector_auto_color_layers(LayerSelector *layer_selector, ColorPalett unsigned int color_count; GdkRGBA color; - if (GDS_RENDER_IS_COLOR_PALETTE(palette) == FALSE || LAYER_IS_SELECTOR(layer_selector) == FALSE) - return; - if (global_alpha <= 0) - return; - if (GTK_IS_LIST_BOX(layer_selector->list_box) == FALSE) - return; + g_return_if_fail(GDS_RENDER_IS_COLOR_PALETTE(palette)); + g_return_if_fail(LAYER_IS_SELECTOR(layer_selector)); + g_return_if_fail(global_alpha > 0); + g_return_if_fail(GTK_IS_LIST_BOX(layer_selector->list_box)); le_list = gtk_container_get_children(GTK_CONTAINER(layer_selector->list_box)); @@ -898,4 +896,31 @@ gboolean layer_selector_contains_elements(LayerSelector *layer_selector) return (layer_element_list ? TRUE : FALSE); } +size_t layer_selector_num_of_named_elements(LayerSelector *layer_selector) +{ + GList *le_list; + GList *le_list_ptr; + LayerElement *le; + const char *layer_name; + size_t count = 0U; + + g_return_val_if_fail(LAYER_IS_SELECTOR(layer_selector), 0U); + + le_list = gtk_container_get_children(GTK_CONTAINER(layer_selector->list_box)); + + for (le_list_ptr = le_list; le_list_ptr != NULL; le_list_ptr = g_list_next(le_list_ptr)) { + le = LAYER_ELEMENT(le_list_ptr->data); + if (!le) + continue; + layer_name = layer_element_get_name(le); + + if (layer_name && *layer_name) { + /* Layer name is not empty. Count it */ + count++; + } + } + + return count; +} + /** @} */