Compare commits

...

6 Commits

5 changed files with 95 additions and 2 deletions

View File

@ -586,6 +586,34 @@ static void on_select_all_layers_clicked(GtkWidget *button, gpointer user_data)
layer_selector_select_all_layers(gui->layer_selector, TRUE); layer_selector_select_all_layers(gui->layer_selector, TRUE);
} }
static void auto_naming_clicked(GtkWidget *button, gpointer user_data)
{
GdsRenderGui *gui;
GtkDialog *dialog;
gboolean overwrite;
int dialog_result;
(void)button;
gui = RENDERER_GUI(user_data);
/* Ask for overwrite */
dialog = GTK_DIALOG(gtk_message_dialog_new(gui->main_window, GTK_DIALOG_USE_HEADER_BAR, GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO, "Overwrite existing layer names?"));
dialog_result = gtk_dialog_run(dialog);
switch (dialog_result) {
case GTK_RESPONSE_YES:
overwrite = TRUE;
break;
case GTK_RESPONSE_NO: /* Expected fallthrough */
default:
overwrite = FALSE;
break;
}
gtk_widget_destroy(GTK_WIDGET(dialog));
layer_selector_auto_name_layers(gui->layer_selector, overwrite);
}
GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui) GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui)
{ {
return gui->main_window; return gui->main_window;
@ -601,6 +629,7 @@ static void gds_render_gui_init(GdsRenderGui *self)
GtkWidget *sort_down_button; GtkWidget *sort_down_button;
GtkWidget *activity_bar_box; GtkWidget *activity_bar_box;
GtkWidget *auto_color_button; GtkWidget *auto_color_button;
GtkWidget *auto_naming_button;
main_builder = gtk_builder_new_from_resource("/gui/main.glade"); main_builder = gtk_builder_new_from_resource("/gui/main.glade");
@ -672,6 +701,10 @@ static void gds_render_gui_init(GdsRenderGui *self)
self->select_all_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-select-all")); self->select_all_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-select-all"));
g_signal_connect(self->select_all_button, "clicked", G_CALLBACK(on_select_all_layers_clicked), self); g_signal_connect(self->select_all_button, "clicked", G_CALLBACK(on_select_all_layers_clicked), self);
/* Setup auto naming button */
auto_naming_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-auto-name"));
g_signal_connect(auto_naming_button, "clicked", G_CALLBACK(auto_naming_clicked), self);
g_object_unref(main_builder); g_object_unref(main_builder);
/* Setup default button sensibility data */ /* Setup default button sensibility data */

View File

@ -103,10 +103,21 @@ void layer_selector_select_all_layers(LayerSelector *layer_selector, gboolean se
* @brief Apply colors from palette to all layers. Aditionally set alpha * @brief Apply colors from palette to all layers. Aditionally set alpha
* @param layer_selector LayerSelector object * @param layer_selector LayerSelector object
* @param palette Color palette to use * @param palette Color palette to use
* @param global_alpha Additional alpha value that is applied to all layers * @param global_alpha Additional alpha value that is applied to all layers. Must be > 0
*/ */
void layer_selector_auto_color_layers(LayerSelector *layer_selector, ColorPalette *palette, double global_alpha); void layer_selector_auto_color_layers(LayerSelector *layer_selector, ColorPalette *palette, double global_alpha);
/**
* @brief Auto name all layers in the layer selector.
*
* This functions sets the name of the layer equal to its number.
* The \p overwrite parameter specifies if already set layer names are overwritten.
*
* @param layer_selector LayerSelector
* @param overwrite Overwrite existing layer names
*/
void layer_selector_auto_name_layers(LayerSelector *layer_selector, gboolean overwrite);
G_END_DECLS G_END_DECLS
#endif /* __LAYER_SELECTOR_H__ */ #endif /* __LAYER_SELECTOR_H__ */

View File

@ -857,4 +857,34 @@ ret_free_le_list:
g_list_free(le_list); g_list_free(le_list);
} }
void layer_selector_auto_name_layers(LayerSelector *layer_selector, gboolean overwrite)
{
GList *le_list;
GList *le_list_ptr;
LayerElement *le;
const char *old_layer_name;
GString *new_layer_name;
g_return_if_fail(LAYER_IS_SELECTOR(layer_selector));
new_layer_name = g_string_new_len(NULL, 10);
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;
old_layer_name = layer_element_get_name(le);
/* Check if layer name is empty or may be overwritten */
if (!old_layer_name || *old_layer_name == '\0' || overwrite) {
g_string_printf(new_layer_name, "Layer %d", layer_element_get_layer(le));
layer_element_set_name(le, new_layer_name->str);
}
}
g_string_free(new_layer_name, TRUE);
g_list_free(le_list);
}
/** @} */ /** @} */

2
main.c
View File

@ -92,7 +92,7 @@ static void app_about(GSimpleAction *action, GVariant *parameter, gpointer user_
GString *comment_text; GString *comment_text;
comment_text = g_string_new("gds-render is a tool fo rendering GDS2 layout files into vector graphics."); comment_text = g_string_new("gds-render is a tool fo rendering GDS2 layout files into vector graphics.");
g_string_append_printf(comment_text, "\n\n Full git commit: %s", _app_git_commit); g_string_append_printf(comment_text, "\n\nFull git commit: %s", _app_git_commit);
builder = gtk_builder_new_from_resource("/gui/about.glade"); builder = gtk_builder_new_from_resource("/gui/about.glade");
dialog = GTK_DIALOG(gtk_builder_get_object(builder, "about-dialog")); dialog = GTK_DIALOG(gtk_builder_get_object(builder, "about-dialog"));

View File

@ -2,6 +2,11 @@
<!-- Generated with glade 3.22.1 --> <!-- Generated with glade 3.22.1 -->
<interface> <interface>
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkImage" id="auto-name-img">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-edit</property>
</object>
<object class="GtkImage" id="color-img"> <object class="GtkImage" id="color-img">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -234,6 +239,20 @@
<property name="position">3</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkButton" id="button-auto-name">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">auto-name-img</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>