Make renderer settings dialog settings unique for each window

This commit is contained in:
Mario Hüttel 2019-03-22 21:59:27 +01:00
parent 5537c076a8
commit ff3f692f2c

View File

@ -57,6 +57,7 @@ struct _GdsRenderGui {
LayerSelector *layer_selector; LayerSelector *layer_selector;
GtkTreeView *cell_tree_view; GtkTreeView *cell_tree_view;
GList *gds_libraries; GList *gds_libraries;
struct render_settings render_dialog_settings;
}; };
G_DEFINE_TYPE(GdsRenderGui, gds_render_gui, G_TYPE_OBJECT) G_DEFINE_TYPE(GdsRenderGui, gds_render_gui, G_TYPE_OBJECT)
@ -245,10 +246,6 @@ end_destroy:
static void on_convert_clicked(gpointer button, gpointer user) static void on_convert_clicked(gpointer button, gpointer user)
{ {
(void)button; (void)button;
static struct render_settings sett = {
.scale = 1000.0,
.renderer = RENDERER_LATEX_TIKZ,
};
GdsRenderGui *self; GdsRenderGui *self;
GtkTreeSelection *selection; GtkTreeSelection *selection;
GtkTreeIter iter; GtkTreeIter iter;
@ -263,12 +260,15 @@ static void on_convert_clicked(gpointer button, gpointer user)
char *file_name; char *file_name;
union bounding_box cell_box; union bounding_box cell_box;
unsigned int height, width; unsigned int height, width;
struct render_settings *sett;
self = RENDERER_GUI(user); self = RENDERER_GUI(user);
if (!self) if (!self)
return; return;
sett = &self->render_dialog_settings;
/* Get selected cell */ /* Get selected cell */
selection = gtk_tree_view_get_selection(self->cell_tree_view); selection = gtk_tree_view_get_selection(self->cell_tree_view);
if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE) if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE)
@ -295,14 +295,14 @@ static void on_convert_clicked(gpointer button, gpointer user)
/* Show settings dialog */ /* Show settings dialog */
settings = renderer_settings_dialog_new(GTK_WINDOW(self->main_window)); settings = renderer_settings_dialog_new(GTK_WINDOW(self->main_window));
renderer_settings_dialog_set_settings(settings, &sett); renderer_settings_dialog_set_settings(settings, sett);
renderer_settings_dialog_set_database_unit_scale(settings, cell_to_render->parent_library->unit_in_meters); renderer_settings_dialog_set_database_unit_scale(settings, cell_to_render->parent_library->unit_in_meters);
renderer_settings_dialog_set_cell_height(settings, height); renderer_settings_dialog_set_cell_height(settings, height);
renderer_settings_dialog_set_cell_width(settings, width); renderer_settings_dialog_set_cell_width(settings, width);
res = gtk_dialog_run(GTK_DIALOG(settings)); res = gtk_dialog_run(GTK_DIALOG(settings));
if (res == GTK_RESPONSE_OK) { if (res == GTK_RESPONSE_OK) {
renderer_settings_dialog_get_settings(settings, &sett); renderer_settings_dialog_get_settings(settings, sett);
gtk_widget_destroy(GTK_WIDGET(settings)); gtk_widget_destroy(GTK_WIDGET(settings));
} else { } else {
gtk_widget_destroy(GTK_WIDGET(settings)); gtk_widget_destroy(GTK_WIDGET(settings));
@ -310,13 +310,13 @@ static void on_convert_clicked(gpointer button, gpointer user)
} }
/* save file dialog */ /* save file dialog */
dialog = gtk_file_chooser_dialog_new((sett.renderer == RENDERER_LATEX_TIKZ dialog = gtk_file_chooser_dialog_new((sett->renderer == RENDERER_LATEX_TIKZ
? "Save LaTeX File" : "Save PDF"), ? "Save LaTeX File" : "Save PDF"),
GTK_WINDOW(self->main_window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_WINDOW(self->main_window), GTK_FILE_CHOOSER_ACTION_SAVE,
"Cancel", GTK_RESPONSE_CANCEL, "Save", GTK_RESPONSE_ACCEPT, NULL); "Cancel", GTK_RESPONSE_CANCEL, "Save", GTK_RESPONSE_ACCEPT, NULL);
/* Set file filter according to settings */ /* Set file filter according to settings */
filter = gtk_file_filter_new(); filter = gtk_file_filter_new();
switch (sett.renderer) { switch (sett->renderer) {
case RENDERER_LATEX_TIKZ: case RENDERER_LATEX_TIKZ:
gtk_file_filter_add_pattern(filter, "*.tex"); gtk_file_filter_add_pattern(filter, "*.tex");
gtk_file_filter_set_name(filter, "LaTeX-Files"); gtk_file_filter_set_name(filter, "LaTeX-Files");
@ -340,23 +340,23 @@ static void on_convert_clicked(gpointer button, gpointer user)
file_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); file_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
switch (sett.renderer) { switch (sett->renderer) {
case RENDERER_LATEX_TIKZ: case RENDERER_LATEX_TIKZ:
output_file = fopen(file_name, "w"); output_file = fopen(file_name, "w");
latex_render_cell_to_code(cell_to_render, layer_list, output_file, sett.scale, latex_render_cell_to_code(cell_to_render, layer_list, output_file, sett->scale,
sett.tex_pdf_layers, sett.tex_standalone); sett->tex_pdf_layers, sett->tex_standalone);
fclose(output_file); fclose(output_file);
break; break;
case RENDERER_CAIROGRAPHICS_SVG: case RENDERER_CAIROGRAPHICS_SVG:
case RENDERER_CAIROGRAPHICS_PDF: case RENDERER_CAIROGRAPHICS_PDF:
cairo_render_cell_to_vector_file(cell_to_render, layer_list, cairo_render_cell_to_vector_file(cell_to_render, layer_list,
(sett.renderer == RENDERER_CAIROGRAPHICS_PDF (sett->renderer == RENDERER_CAIROGRAPHICS_PDF
? file_name ? file_name
: NULL), : NULL),
(sett.renderer == RENDERER_CAIROGRAPHICS_SVG (sett->renderer == RENDERER_CAIROGRAPHICS_SVG
? file_name ? file_name
: NULL), : NULL),
sett.scale); sett->scale);
break; break;
} }
g_free(file_name); g_free(file_name);
@ -534,6 +534,13 @@ static void gds_render_gui_init(GdsRenderGui *self)
g_object_unref(main_builder); g_object_unref(main_builder);
/* Set default conversion/rendering settings */
self->render_dialog_settings.scale = 1000;
self->render_dialog_settings.renderer = RENDERER_LATEX_TIKZ;
self->render_dialog_settings.tex_pdf_layers = FALSE;
self->render_dialog_settings.tex_standalone = FALSE;
/* Reference all objects referenced by this object */ /* Reference all objects referenced by this object */
g_object_ref(self->main_window); g_object_ref(self->main_window);
g_object_ref(self->cell_tree_view); g_object_ref(self->cell_tree_view);