From d9f0f3cdd54fff4b4ba65f5be2cb418ff6250076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 19 Jul 2018 17:49:33 +0200 Subject: [PATCH] settings dialog fully implemented --- CMakeLists.txt | 2 ++ cairo-output/cairo-output.c | 33 +++++++++++++++++++ cairo-output/cairo-output.h | 28 ++++++++++++++++ latex-output/latex-output.c | 2 +- latex-output/latex-output.h | 2 +- main.c | 59 +++++++++++++++++++++++++++------- widgets/conv-settings-dialog.c | 26 ++++++++++++--- 7 files changed, 135 insertions(+), 17 deletions(-) create mode 100644 cairo-output/cairo-output.c create mode 100644 cairo-output/cairo-output.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 940026f..a487249 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ aux_source_directory("widgets" LAYER_SOURCES) aux_source_directory("tree-renderer" RENDERER_SOURCES) aux_source_directory("gds-parser" PARSER_SOURCES) aux_source_directory("latex-output" LATEX_SOURCES) +aux_source_directory("cairo-output" CAIRO_SOURCES) set(SOURCE "main.c" "layer-selector.c") @@ -26,6 +27,7 @@ set(SOURCE ${RENDERER_SOURCES} ${PARSER_SOURCES} ${LATEX_SOURCES} + ${CAIRO_SOURCES} ) add_compile_options(-Wall) diff --git a/cairo-output/cairo-output.c b/cairo-output/cairo-output.c new file mode 100644 index 0000000..b07e9a6 --- /dev/null +++ b/cairo-output/cairo-output.c @@ -0,0 +1,33 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * This file is part of GDSII-Converter. + * + * GDSII-Converter is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter 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 GDSII-Converter. If not, see . + */ + +#include "cairo-output.h" +#include +#include +#include + +void cairo_render_cell_to_pdf(struct gds_cell *cell, GList *layer_infos, char *pdf_file) +{ + cairo_surface_t *surface; + cairo_t *cr; + + + + printf("cairo export not yet implemented!\n"); +} diff --git a/cairo-output/cairo-output.h b/cairo-output/cairo-output.h new file mode 100644 index 0000000..d6e00b2 --- /dev/null +++ b/cairo-output/cairo-output.h @@ -0,0 +1,28 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * This file is part of GDSII-Converter. + * + * GDSII-Converter is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter 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 GDSII-Converter. If not, see . + */ + +#ifndef __CAIRO_OUTPUT_H__ +#define __CAIRO_OUTPUT_H__ + +#include "../layer-selector.h" +#include "../gds-parser/gds-types.h" + +void cairo_render_cell_to_pdf(struct gds_cell *cell, GList *layer_infos, char *pdf_file); + +#endif /* __CAIRO_OUTPUT_H__ */ diff --git a/latex-output/latex-output.c b/latex-output/latex-output.c index 75a5d68..74cc486 100644 --- a/latex-output/latex-output.c +++ b/latex-output/latex-output.c @@ -188,7 +188,7 @@ static void render_cell(struct gds_cell *cell, GList *layer_infos, FILE *tex_fil } -void render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file) +void latex_render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file) { GString *working_line; diff --git a/latex-output/latex-output.h b/latex-output/latex-output.h index 5d79ed9..037f141 100644 --- a/latex-output/latex-output.h +++ b/latex-output/latex-output.h @@ -27,6 +27,6 @@ #define LATEX_LINE_BUFFER_KB (10) -void render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file); +void latex_render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file); #endif /* __LATEX_OUTPUT_H__ */ diff --git a/main.c b/main.c index 69b9d62..ae88294 100644 --- a/main.c +++ b/main.c @@ -24,6 +24,7 @@ #include "tree-renderer/tree-store.h" #include "latex-output/latex-output.h" #include "widgets/conv-settings-dialog.h" +#include "cairo-output/cairo-output.h" struct open_button_data { GtkWindow *main_window; @@ -161,22 +162,23 @@ end_destroy: static void on_convert_clicked(gpointer button, gpointer user) { + static struct render_settings sett = { + .scale = 1000.0f, + .renderer = RENDERER_LATEX_TIKZ, + }; struct convert_button_data *data = (struct convert_button_data *)user; GtkTreeSelection *selection; GtkTreeIter iter; GtkTreeModel *model; GList *layer_list; struct gds_cell *cell_to_render; - FILE *tex_file; + FILE *output_file; GtkWidget *dialog; RendererSettingsDialog *settings; + GtkFileFilter *filter; gint res; char *file_name; - settings = renderer_settings_dialog_new(GTK_WINDOW(data->main_window)); - gtk_dialog_run(GTK_DIALOG(settings)); - gtk_widget_destroy(GTK_WIDGET(settings)); - /* Get selected cell */ selection = gtk_tree_view_get_selection(data->tree_view); if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE) @@ -190,21 +192,56 @@ static void on_convert_clicked(gpointer button, gpointer user) /* Get layers that are rendered */ layer_list = export_rendered_layer_info(); + settings = renderer_settings_dialog_new(GTK_WINDOW(data->main_window)); + renderer_settings_dialog_set_settings(settings, &sett); + res = gtk_dialog_run(GTK_DIALOG(settings)); + if (res == GTK_RESPONSE_OK) { + renderer_settings_dialog_get_settings(settings, &sett); + gtk_widget_destroy(GTK_WIDGET(settings)); + } else { + gtk_widget_destroy(GTK_WIDGET(settings)); + goto ret_layer_destroy; + } + + + /* save file dialog */ - dialog = gtk_file_chooser_dialog_new("Save TeX File", GTK_WINDOW(data->main_window), GTK_FILE_CHOOSER_ACTION_SAVE, + dialog = gtk_file_chooser_dialog_new((sett.renderer == RENDERER_LATEX_TIKZ + ? "Save LaTeX File" : "Save PDF"), + GTK_WINDOW(data->main_window), GTK_FILE_CHOOSER_ACTION_SAVE, "Cancel", GTK_RESPONSE_CANCEL, "Save", GTK_RESPONSE_ACCEPT, NULL); + /* Set file filter according to settings */ + filter = gtk_file_filter_new(); + if (sett.renderer == RENDERER_LATEX_TIKZ) { + gtk_file_filter_add_pattern(filter, "*.tex"); + gtk_file_filter_set_name(filter, "LaTeX-Files"); + } else { + gtk_file_filter_add_pattern(filter, "*.pdf"); + gtk_file_filter_set_name(filter, "PDF-Files"); + } + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); + res = gtk_dialog_run(GTK_DIALOG(dialog)); if (res == GTK_RESPONSE_ACCEPT) { file_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - tex_file = fopen(file_name, "w"); - g_free(file_name); gtk_widget_destroy(dialog); - render_cell_to_code(cell_to_render, layer_list, tex_file); - fclose(tex_file); + + switch (sett.renderer) { + case RENDERER_LATEX_TIKZ: + output_file = fopen(file_name, "w"); + latex_render_cell_to_code(cell_to_render, layer_list, output_file); + fclose(output_file); + break; + case RENDERER_CAIROGRAPHICS: + cairo_render_cell_to_pdf(cell_to_render, layer_list, file_name); + break; + } + g_free(file_name); + } else { gtk_widget_destroy(dialog); } - +ret_layer_destroy: g_list_free_full(layer_list, (GDestroyNotify)delete_layer_info_struct); } diff --git a/widgets/conv-settings-dialog.c b/widgets/conv-settings-dialog.c index 7ce267f..475cc6c 100644 --- a/widgets/conv-settings-dialog.c +++ b/widgets/conv-settings-dialog.c @@ -22,7 +22,8 @@ struct _RendererSettingsDialog { GtkDialog parent; /* Private loot */ - GtkWidget *radio_latex; // Only Latex-radio. Other one is implicit + GtkWidget *radio_latex; + GtkWidget *radio_cairo; GtkWidget *scale; }; @@ -48,9 +49,12 @@ static void renderer_settings_dialog_init(RendererSettingsDialog *self) builder = gtk_builder_new_from_resource("/dialog.glade"); box = GTK_WIDGET(gtk_builder_get_object(builder, "dialog-box")); self->radio_latex = GTK_WIDGET(gtk_builder_get_object(builder, "latex-radio")); + self->radio_cairo = GTK_WIDGET(gtk_builder_get_object(builder, "cairo-radio")); self->scale = GTK_WIDGET(gtk_builder_get_object(builder, "dialog-scale")); gtk_dialog_add_buttons(dialog, "Cancel", GTK_RESPONSE_CANCEL, "OK", GTK_RESPONSE_OK, NULL); gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), box); + gtk_window_set_title(GTK_WINDOW(self), "Renderer Settings"); + g_object_unref(builder); } @@ -65,11 +69,25 @@ RendererSettingsDialog *renderer_settings_dialog_new(GtkWindow *parent) return res; } -void renderer_settings_dialog_set_settings(RendererSettingsDialog *dialog, struct render_settings *settings) +void renderer_settings_dialog_get_settings(RendererSettingsDialog *dialog, struct render_settings *settings) { - if (!settings) + if (!settings || !dialog) return; settings->scale = gtk_range_get_value(GTK_RANGE(dialog->scale)); settings->renderer = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->radio_latex)) == TRUE ? RENDERER_LATEX_TIKZ : RENDERER_CAIROGRAPHICS); } -void renderer_settings_dialog_get_settings(RendererSettingsDialog *dialog, struct render_settings *settings); +void renderer_settings_dialog_set_settings(RendererSettingsDialog *dialog, struct render_settings *settings) +{ + if (!settings || !dialog) + return; + gtk_range_set_value(GTK_RANGE(dialog->scale), settings->scale); + + switch (settings->renderer) { + case RENDERER_LATEX_TIKZ: + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->radio_latex), TRUE); + break; + case RENDERER_CAIROGRAPHICS: + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->radio_cairo), TRUE); + break; + } +}