settings dialog fully implemented

This commit is contained in:
Mario Hüttel 2018-07-19 17:49:33 +02:00
parent 4c04ce3614
commit d9f0f3cdd5
7 changed files with 135 additions and 17 deletions

View File

@ -17,6 +17,7 @@ aux_source_directory("widgets" LAYER_SOURCES)
aux_source_directory("tree-renderer" RENDERER_SOURCES) aux_source_directory("tree-renderer" RENDERER_SOURCES)
aux_source_directory("gds-parser" PARSER_SOURCES) aux_source_directory("gds-parser" PARSER_SOURCES)
aux_source_directory("latex-output" LATEX_SOURCES) aux_source_directory("latex-output" LATEX_SOURCES)
aux_source_directory("cairo-output" CAIRO_SOURCES)
set(SOURCE "main.c" "layer-selector.c") set(SOURCE "main.c" "layer-selector.c")
@ -26,6 +27,7 @@ set(SOURCE
${RENDERER_SOURCES} ${RENDERER_SOURCES}
${PARSER_SOURCES} ${PARSER_SOURCES}
${LATEX_SOURCES} ${LATEX_SOURCES}
${CAIRO_SOURCES}
) )
add_compile_options(-Wall) add_compile_options(-Wall)

View File

@ -0,0 +1,33 @@
/*
* GDSII-Converter
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "cairo-output.h"
#include <math.h>
#include <cairo.h>
#include <cairo-pdf.h>
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");
}

View File

@ -0,0 +1,28 @@
/*
* GDSII-Converter
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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__ */

View File

@ -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; GString *working_line;

View File

@ -27,6 +27,6 @@
#define LATEX_LINE_BUFFER_KB (10) #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__ */ #endif /* __LATEX_OUTPUT_H__ */

59
main.c
View File

@ -24,6 +24,7 @@
#include "tree-renderer/tree-store.h" #include "tree-renderer/tree-store.h"
#include "latex-output/latex-output.h" #include "latex-output/latex-output.h"
#include "widgets/conv-settings-dialog.h" #include "widgets/conv-settings-dialog.h"
#include "cairo-output/cairo-output.h"
struct open_button_data { struct open_button_data {
GtkWindow *main_window; GtkWindow *main_window;
@ -161,22 +162,23 @@ end_destroy:
static void on_convert_clicked(gpointer button, gpointer user) 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; struct convert_button_data *data = (struct convert_button_data *)user;
GtkTreeSelection *selection; GtkTreeSelection *selection;
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel *model; GtkTreeModel *model;
GList *layer_list; GList *layer_list;
struct gds_cell *cell_to_render; struct gds_cell *cell_to_render;
FILE *tex_file; FILE *output_file;
GtkWidget *dialog; GtkWidget *dialog;
RendererSettingsDialog *settings; RendererSettingsDialog *settings;
GtkFileFilter *filter;
gint res; gint res;
char *file_name; 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 */ /* Get selected cell */
selection = gtk_tree_view_get_selection(data->tree_view); selection = gtk_tree_view_get_selection(data->tree_view);
if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE) 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 */ /* Get layers that are rendered */
layer_list = export_rendered_layer_info(); 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 */ /* 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); "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)); res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) { if (res == GTK_RESPONSE_ACCEPT) {
file_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 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); 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 { } else {
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
} }
ret_layer_destroy:
g_list_free_full(layer_list, (GDestroyNotify)delete_layer_info_struct); g_list_free_full(layer_list, (GDestroyNotify)delete_layer_info_struct);
} }

View File

@ -22,7 +22,8 @@
struct _RendererSettingsDialog { struct _RendererSettingsDialog {
GtkDialog parent; GtkDialog parent;
/* Private loot */ /* Private loot */
GtkWidget *radio_latex; // Only Latex-radio. Other one is implicit GtkWidget *radio_latex;
GtkWidget *radio_cairo;
GtkWidget *scale; GtkWidget *scale;
}; };
@ -48,9 +49,12 @@ static void renderer_settings_dialog_init(RendererSettingsDialog *self)
builder = gtk_builder_new_from_resource("/dialog.glade"); builder = gtk_builder_new_from_resource("/dialog.glade");
box = GTK_WIDGET(gtk_builder_get_object(builder, "dialog-box")); box = GTK_WIDGET(gtk_builder_get_object(builder, "dialog-box"));
self->radio_latex = GTK_WIDGET(gtk_builder_get_object(builder, "latex-radio")); 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")); 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_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_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), box);
gtk_window_set_title(GTK_WINDOW(self), "Renderer Settings");
g_object_unref(builder); g_object_unref(builder);
} }
@ -65,11 +69,25 @@ RendererSettingsDialog *renderer_settings_dialog_new(GtkWindow *parent)
return res; 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; return;
settings->scale = gtk_range_get_value(GTK_RANGE(dialog->scale)); 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); 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;
}
}