Compare commits

..

No commits in common. "942df1d971651f26007f0cd97517b24727664975" and "a5d794461a6ee1ca6a34860490baadfb47b14aee" have entirely different histories.

8 changed files with 85 additions and 380 deletions

View File

@ -18,7 +18,7 @@ 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) aux_source_directory("cairo-output" CAIRO_SOURCES)
set(SOURCE "main.c" "layer-selector.c" "mapping-parser.c" "command-line.c" "main-window.c") set(SOURCE "main.c" "layer-selector.c" "main-window.c")
set(SOURCE set(SOURCE
${SOURCE} ${SOURCE}

View File

@ -1,137 +0,0 @@
/*
* 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 <stdio.h>
#include "command-line.h"
#include "gds-parser/gds-parser.h"
#include "mapping-parser.h"
#include "cairo-output/cairo-output.h"
#include "latex-output/latex-output.h"
static void delete_layer_info_with_name(struct layer_info *info)
{
if (info) {
if (info->name)
g_free(info->name);
free(info);
}
}
void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gboolean pdf, gboolean tex,
char *layer_file, char *cell_name, double scale, gboolean pdf_layers, gboolean pdf_standalone)
{
GList *libs = NULL;
FILE *tex_file;
int res;
GFile *file;
int i;
GFileInputStream *stream;
GDataInputStream *dstream;
gboolean layer_export;
GdkRGBA layer_color;
int layer;
char *layer_name;
GList *layer_info_list = NULL;
GList *cell_list;
struct layer_info *linfo_temp;
struct gds_cell *toplevel_cell = NULL, *temp_cell;
/* Check if parameters are valid */
if (!gds_name || ! pdf_name || !tex_name || !layer_file || !cell_name) {
printf("Probably missing argument. Check --help option\n");
return;
}
/* Load GDS */
clear_lib_list(&libs);
res = parse_gds_from_file(gds_name, &libs);
if (res)
return;
file = g_file_new_for_path(layer_file);
stream = g_file_read(file, NULL, NULL);
if (!stream) {
printf("Layer mapping not readable!\n");
goto destroy_file;
}
dstream = g_data_input_stream_new(G_INPUT_STREAM(stream));
i = 0;
do {
res = load_csv_line(dstream, &layer_export, &layer_name, &layer, &layer_color);
if (res == 0) {
if (!layer_export)
continue;
linfo_temp = (struct layer_info *)malloc(sizeof(struct layer_info));
if (!linfo_temp) {
printf("Out of memory\n");
goto ret_clear_list;
}
linfo_temp->color.alpha = layer_color.alpha;
linfo_temp->color.red = layer_color.red;
linfo_temp->color.green = layer_color.green;
linfo_temp->color.blue = layer_color.blue;
linfo_temp->name = layer_name;
linfo_temp->stacked_position = i++;
linfo_temp->layer = layer;
layer_info_list = g_list_append(layer_info_list, (gpointer)linfo_temp);
}
} while(res >= 0);
/* find_cell in first library. */
if (!libs)
goto ret_clear_list;
for (cell_list = ((struct gds_library *)libs->data)->cells; cell_list != NULL; cell_list = g_list_next(cell_list)) {
temp_cell = (struct gds_cell *)cell_list->data;
if (!strcmp(temp_cell->name, cell_name)) {
toplevel_cell = temp_cell;
break;
}
}
if (!toplevel_cell) {
printf("Couldn't find cell in first library!\n");
goto ret_clear_list;
}
/* Render outputs */
if (pdf == TRUE) {
cairo_render_cell_to_pdf(toplevel_cell, layer_info_list, pdf_name, scale);
}
if (tex == TRUE) {
tex_file = fopen(tex_name, "w");
if (!tex_file)
goto ret_clear_list;
latex_render_cell_to_code(toplevel_cell, layer_info_list, tex_file, scale, pdf_layers, pdf_standalone);
fclose(tex_file);
}
ret_clear_list:
g_list_free_full(layer_info_list, (GDestroyNotify)delete_layer_info_with_name);
g_object_unref(dstream);
g_object_unref(stream);
destroy_file:
g_object_unref(file);
}

View File

@ -1,27 +0,0 @@
/*
* 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 _COMMAND_LINE_H_
#define _COMMAND_LINE_H_
#include <glib.h>
void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gboolean pdf, gboolean tex,
char *layer_file, char *cell_name, double scale, gboolean pdf_layers, gboolean pdf_standalone);
#endif /* _COMMAND_LINE_H_ */

View File

@ -170,6 +170,79 @@ void generate_layer_widgets(GtkListBox *listbox, GList *libs)
gtk_widget_set_sensitive(global_save_button, TRUE); gtk_widget_set_sensitive(global_save_button, TRUE);
} }
/**
* @brief load_csv_line
* @param file
* @param export
* @param name
* @param layer
* @param color
* @param opacity
* @return 0 if succesfull, 1 if line was malformatted or parameters are broken, -1 if file end
*/
static int load_csv_line(GDataInputStream *stream, gboolean *export, char **name, int *layer, GdkRGBA *color)
{
int ret;
gsize len;
gchar *line;
GRegex *regex;
GMatchInfo *mi;
char *match;
if ((!export) || (!name) || (!layer) || (!color)) {
ret = 1;
goto ret_direct;
}
regex = g_regex_new("^(?<layer>[0-9]+),(?<r>[0-9\\.]+),(?<g>[0-9\\.]+),(?<b>[0-9\\.]+),(?<a>[0-9\\.]+),(?<export>[01]),(?<name>.*)$", 0, 0, NULL);
line = g_data_input_stream_read_line(stream, &len, NULL, NULL);
if (!line) {
ret = -1;
goto destroy_regex;
}
/* Match line in CSV */
g_regex_match(regex, line, 0, &mi);
if (g_match_info_matches(mi)) {
/* Line is valid */
match = g_match_info_fetch_named(mi, "layer");
*layer = (int)g_ascii_strtoll(match, NULL, 10);
g_free(match);
match = g_match_info_fetch_named(mi, "r");
color->red = g_ascii_strtod(match, NULL);
g_free(match);
match = g_match_info_fetch_named(mi, "g");
color->green = g_ascii_strtod(match, NULL);
g_free(match);
match = g_match_info_fetch_named(mi, "b");
color->blue = g_ascii_strtod(match, NULL);
g_free(match);
match = g_match_info_fetch_named(mi, "a");
color->alpha = g_ascii_strtod(match, NULL);
g_free(match);
match = g_match_info_fetch_named(mi, "export");
*export = ((!strcmp(match, "1")) ? TRUE : FALSE);
g_free(match);
match = g_match_info_fetch_named(mi, "name");
*name = match;
ret = 0;
} else {
/* Line is malformatted */
printf("Could not recognize line in CSV as valid entry: %s\n", line);
ret = 1;
}
g_match_info_free(mi);
g_free(line);
destroy_regex:
g_regex_unref(regex);
ret_direct:
return ret;
}
static LayerElement *find_layer_element_in_list(GList *el_list, int layer) static LayerElement *find_layer_element_in_list(GList *el_list, int layer)
{ {
LayerElement *ret = NULL; LayerElement *ret = NULL;

View File

@ -22,7 +22,14 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib.h> #include <glib.h>
#include "mapping-parser.h"
struct layer_info
{
int layer;
char *name;
int stacked_position; ///< Lower is bottom, higher is top
GdkRGBA color;
};
void generate_layer_widgets(GtkListBox *listbox, GList *libs); void generate_layer_widgets(GtkListBox *listbox, GList *libs);
void setup_load_mapping_callback(GtkWidget *button, GtkWindow *main_window); void setup_load_mapping_callback(GtkWidget *button, GtkWindow *main_window);

87
main.c
View File

@ -19,9 +19,7 @@
#include <stdio.h> #include <stdio.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib.h>
#include "main-window.h" #include "main-window.h"
#include "command-line.h"
struct application_data { struct application_data {
GtkApplication *app; GtkApplication *app;
@ -46,7 +44,7 @@ static void app_about(GSimpleAction *action, GVariant *parameter, gpointer user_
gtk_window_set_transient_for(GTK_WINDOW(dialog), appdata->main_window); gtk_window_set_transient_for(GTK_WINDOW(dialog), appdata->main_window);
gtk_dialog_run(dialog); gtk_dialog_run(dialog);
gtk_widget_destroy(GTK_WIDGET(dialog)); gtk_widget_destroy(dialog);
g_object_unref(builder); g_object_unref(builder);
} }
@ -66,12 +64,11 @@ static void gapp_activate(GApplication *app, gpointer user_data)
gtk_widget_show(GTK_WIDGET(main_window)); gtk_widget_show(GTK_WIDGET(main_window));
} }
static int start_gui(int argc, char **argv) int main(int argc, char **argv)
{ {
GtkApplication *gapp; GtkApplication *gapp;
int app_status; int app_status;
static struct application_data appdata; struct application_data appdata;
GMenu *menu; GMenu *menu;
GMenu *m_quit; GMenu *m_quit;
GMenu *m_about; GMenu *m_about;
@ -101,83 +98,5 @@ static int start_gui(int argc, char **argv)
app_status = g_application_run (G_APPLICATION(gapp), argc, argv); app_status = g_application_run (G_APPLICATION(gapp), argc, argv);
g_object_unref (gapp); g_object_unref (gapp);
return app_status;
}
int main(int argc, char **argv)
{
GError *error = NULL;
GOptionContext *context;
gchar *gds_name;
gchar *basename;
gchar *pdfname = NULL, *texname = NULL, *mappingname = NULL, *cellname = NULL;
gboolean tikz = FALSE, pdf = FALSE, pdf_layers = FALSE, pdf_standalone = FALSE;
int scale = 1000;
int app_status;
GOptionEntry entries[] =
{
{ "tikz", 't', 0, G_OPTION_ARG_NONE, &tikz, "Output TikZ code", NULL },
{ "pdf", 'p', 0, G_OPTION_ARG_NONE, &pdf, "Output PDF document", NULL },
{ "scale", 's', 0, G_OPTION_ARG_INT, &scale, "Divide output coordinates by <SCALE>", "<SCALE>" },
{ "tex-output", 'o', 0, G_OPTION_ARG_FILENAME, &texname, "Optional path for TeX file", "PATH" },
{ "pdf-output", 'O', 0, G_OPTION_ARG_FILENAME, &pdfname, "Optional path for PDF file", "PATH" },
{ "mapping", 'm', 0, G_OPTION_ARG_FILENAME, &mappingname, "Path for Layer Mapping File", "PATH" },
{ "cell", 'c', 0, G_OPTION_ARG_STRING, &cellname, "Cell to render", "NAME" },
{ "tex-standalone", 'a', 0, G_OPTION_ARG_NONE, &pdf_standalone, "Create standalone PDF", NULL },
{ "tex-layers", 'l', 0, G_OPTION_ARG_NONE, &pdf_layers, "Create standalone PDF", NULL },
{ NULL }
};
context = g_option_context_new(" FILE - Convert GDS file <FILE> to graphic");
g_option_context_add_main_entries(context, entries, NULL);
g_option_context_add_group(context, gtk_get_option_group(TRUE));
if (!g_option_context_parse (context, &argc, &argv, &error))
{
g_print ("Option parsing failed: %s\n", error->message);
exit (1);
}
if (argc >= 2) {
if (scale < 1) {
printf("Scale < 1 not allowed. Setting to 1\n");
scale = 1;
}
/* No format selected */
if (!(tikz || pdf)) {
tikz = TRUE;
}
/* Get gds name */
gds_name = argv[1];
/* Check if PDF/TeX names are supplied. if not generate */
basename = g_path_get_basename(gds_name);
if (!texname) {
texname = g_strdup_printf("./%s.tex", basename);
}
if (!pdfname) {
pdfname = g_strdup_printf("./%s.pdf", basename);
}
command_line_convert_gds(gds_name, pdfname, texname, pdf, tikz, mappingname, cellname,
(double)scale, pdf_layers, pdf_standalone);
/* Clean up */
g_free(pdfname);
g_free(texname);
if (mappingname)
g_free(mappingname);
if (cellname)
g_free(cellname);
app_status = 0;
} else {
app_status = start_gui(argc, argv);
}
return app_status; return app_status;
} }

View File

@ -1,95 +0,0 @@
/*
*
* 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 "mapping-parser.h"
/**
* @brief load_csv_line
* @param file
* @param export
* @param name
* @param layer
* @param color
* @param opacity
* @return 0 if succesfull, 1 if line was malformatted or parameters are broken, -1 if file end
*/
int load_csv_line(GDataInputStream *stream, gboolean *export, char **name, int *layer, GdkRGBA *color)
{
int ret;
gsize len;
gchar *line;
GRegex *regex;
GMatchInfo *mi;
char *match;
if ((!export) || (!name) || (!layer) || (!color)) {
ret = 1;
goto ret_direct;
}
regex = g_regex_new("^(?<layer>[0-9]+),(?<r>[0-9\\.]+),(?<g>[0-9\\.]+),(?<b>[0-9\\.]+),(?<a>[0-9\\.]+),(?<export>[01]),(?<name>.*)$", 0, 0, NULL);
line = g_data_input_stream_read_line(stream, &len, NULL, NULL);
if (!line) {
ret = -1;
goto destroy_regex;
}
/* Match line in CSV */
g_regex_match(regex, line, 0, &mi);
if (g_match_info_matches(mi)) {
/* Line is valid */
match = g_match_info_fetch_named(mi, "layer");
*layer = (int)g_ascii_strtoll(match, NULL, 10);
g_free(match);
match = g_match_info_fetch_named(mi, "r");
color->red = g_ascii_strtod(match, NULL);
g_free(match);
match = g_match_info_fetch_named(mi, "g");
color->green = g_ascii_strtod(match, NULL);
g_free(match);
match = g_match_info_fetch_named(mi, "b");
color->blue = g_ascii_strtod(match, NULL);
g_free(match);
match = g_match_info_fetch_named(mi, "a");
color->alpha = g_ascii_strtod(match, NULL);
g_free(match);
match = g_match_info_fetch_named(mi, "export");
*export = ((!strcmp(match, "1")) ? TRUE : FALSE);
g_free(match);
match = g_match_info_fetch_named(mi, "name");
*name = match;
ret = 0;
} else {
/* Line is malformatted */
printf("Could not recognize line in CSV as valid entry: %s\n", line);
ret = 1;
}
g_match_info_free(mi);
g_free(line);
destroy_regex:
g_regex_unref(regex);
ret_direct:
return ret;
}

View File

@ -1,35 +0,0 @@
/*
* 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 __MAPPING_PARSER_H__
#define __MAPPING_PARSER_H__
#include <gtk/gtk.h>
struct layer_info
{
int layer;
char *name;
int stacked_position; ///< Lower is bottom, higher is top
GdkRGBA color;
};
int load_csv_line(GDataInputStream *stream, gboolean *export, char **name, int *layer, GdkRGBA *color);
#endif /* __MAPPING_PARSER_H__ */