Issue #19: Finish integration of renderers to into command line interface

This commit is contained in:
Mario Hüttel 2019-06-19 20:47:19 +02:00
parent 5c994f892a
commit d107954859
4 changed files with 116 additions and 81 deletions

View File

@ -34,8 +34,8 @@
#include <gds-render/gds-utils/gds-parser.h>
#include <gds-render/layer/mapping-parser.h>
#include <gds-render/layer/layer-info.h>
#include <gds-render/output-renderers/cairo-output.h>
#include <gds-render/output-renderers/latex-output.h>
#include <gds-render/output-renderers/cairo-renderer.h>
#include <gds-render/output-renderers/latex-renderer.h>
#include <gds-render/output-renderers/external-renderer.h>
#include <gds-render/gds-utils/gds-tree-checker.h>
@ -55,12 +55,10 @@ static void delete_layer_info_with_name(struct layer_info *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, gboolean svg, char *svg_name, char *so_name, char *so_out_file)
void command_line_convert_gds(const char *gds_name, const char *cell_name, const char *output_file_name, const char *layer_file, const char *so_path,
enum command_line_renderer renderer, enum cmd_options options, double scale)
{
GList *libs = NULL;
FILE *tex_file;
int res;
GFile *file;
int i;
@ -75,10 +73,11 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
struct layer_info *linfo_temp;
struct gds_library *first_lib;
struct gds_cell *toplevel_cell = NULL, *temp_cell;
GdsOutputRenderer *output_renderer;
gboolean tex_layers = FALSE, tex_standalone = FALSE;
/* Check if parameters are valid */
if (!gds_name || (!pdf_name && pdf) || (!tex_name && tex) || !layer_file || !cell_name) {
if (!gds_name || !cell_name || !output_file_name || !layer_file) {
printf("Probably missing argument. Check --help option\n");
return;
}
@ -165,30 +164,43 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
* Deal with it.
*/
/* Render outputs */
if (pdf == TRUE || svg == TRUE) {
cairo_render_cell_to_vector_file(toplevel_cell, layer_info_list, (pdf == TRUE ? pdf_name : NULL),
(svg == TRUE ? svg_name : NULL), scale);
/* Render */
if (options & CMD_OPT_LATEX_LAYERS)
tex_layers = TRUE;
if (options & CMD_OPT_LATEX_STANDALONE)
tex_standalone = TRUE;
switch (renderer) {
case CMD_CAIRO_SVG:
output_renderer = GDS_RENDER_OUTPUT_RENDERER(cairo_renderer_new_svg());
break;
case CMD_LATEX:
output_renderer = GDS_RENDER_OUTPUT_RENDERER(latex_renderer_new_with_options(tex_layers, tex_standalone));
break;
case CMD_CAIRO_PDF:
output_renderer = GDS_RENDER_OUTPUT_RENDERER(cairo_renderer_new_pdf());
break;
case CMD_EXTERNAL:
output_renderer = GDS_RENDER_OUTPUT_RENDERER(external_renderer_new_with_so(so_path));
break;
case CMD_NONE:
/* Do nothing */
output_renderer = NULL;
break;
default:
output_renderer = NULL;
fprintf(stderr, "Invalid renderer supplied");
break;
}
if (tex == TRUE) {
tex_file = fopen(tex_name, "w");
if (!tex_file)
goto ret_clear_layer_list;
latex_render_cell_to_code(toplevel_cell, layer_info_list, tex_file, scale, pdf_layers, pdf_standalone);
fclose(tex_file);
if (output_renderer) {
gds_output_renderer_render_output(output_renderer, toplevel_cell, layer_info_list, output_file_name, scale);
g_object_unref(output_renderer);
}
if (so_name && so_out_file) {
if (strlen(so_name) == 0 || strlen(so_out_file) == 0)
goto ret_clear_layer_list;
/* Render output using external renderer */
printf("Invoking external renderer!\n");
external_renderer_render_cell(toplevel_cell, layer_info_list, so_out_file, so_name);
printf("External renderer finished!\n");
}
/* Render end */
ret_clear_layer_list:
g_list_free_full(layer_info_list, (GDestroyNotify)delete_layer_info_with_name);

View File

@ -33,28 +33,32 @@
#include <glib.h>
enum command_line_renderer {
CMD_NONE = 0,
CMD_EXTERNAL,
CMD_CAIRO_SVG,
CMD_CAIRO_PDF,
CMD_LATEX,
};
enum cmd_options {
CMD_OPT_NONE = 0U,
CMD_OPT_LATEX_STANDALONE = (1U<<0),
CMD_OPT_LATEX_LAYERS = (1U<<1),
};
/**
* @brief Convert GDS according to supplied parameters
* @param gds_name GDS File path
* @param pdf_name Cairo-PDF path
* @param tex_name TeX/TikZ path
* @param pdf Render Cairo
* @param tex Render LaTeX
* @param layer_file Layer mapping file
* @param cell_name Cell name to render
* @param scale Scale image down by this value
* @param pdf_layers TikZ creates OCG layers
* @param pdf_standalone LaTeX document is standalone7
* @param svg Render to SVG file
* @param so_name Path to shared object of custom renderer
* @param so_out_file Output file path for custom renderer
* @param svg_name SVG file name
*
* @note This function is pretty damn retarded (Lots of parameters). Will be reworked when generating GObjects for renderers.
* @brief render output file according to command line parameters
* @param gds_name Name of GDS file
* @param cell_name Name of cell to render
* @param output_file_name Output file name
* @param so_file Shared object file to search external rendering function
* @param renderer Type of output renderer
* @param options Additional options for output renderer
* @param scale Scale value
*/
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, gboolean svg, char *svg_name, char *so_name, char *so_out_file);
void command_line_convert_gds(const char *gds_name, const char *cell_name, const char *output_file_name, const char *layer_file,
const char *so_file, enum command_line_renderer renderer, enum cmd_options options, double scale);
#endif /* _COMMAND_LINE_H_ */

76
main.c
View File

@ -241,29 +241,25 @@ int main(int argc, char **argv)
GOptionContext *context;
gchar *gds_name;
gchar *basename;
gchar *pdfname = NULL, *texname = NULL, *mappingname = NULL, *cellname = NULL, *svgname = NULL;
gboolean tikz = FALSE, pdf = FALSE, pdf_layers = FALSE, pdf_standalone = FALSE, svg = FALSE;
gboolean version = FALSE;
gchar *output_path = NULL, *mappingname = NULL, *cellname = NULL;
gchar *renderer_arg = NULL;
gboolean version = FALSE, pdf_standalone = FALSE, pdf_layers = FALSE;
gchar *custom_library_path = NULL;
gchar *custom_library_file_name = NULL;
int scale = 1000;
int app_status = 0;
enum command_line_renderer renderer = CMD_NONE;
enum cmd_options opt = CMD_OPT_NONE;
GOptionEntry entries[] = {
{"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Print version", NULL},
{"tikz", 't', 0, G_OPTION_ARG_NONE, &tikz, "Output TikZ code", NULL },
{"pdf", 'p', 0, G_OPTION_ARG_NONE, &pdf, "Output PDF document", NULL },
//{"svg", 'S', 0, G_OPTION_ARG_NONE, &svg, "Output SVG image", NULL },
{"renderer", 'r', 0, G_OPTION_ARG_STRING, &renderer_arg, "Renderer to use", "pdf|svg|tikz|ext"},
{"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" },
//{"svg-output", 0, 0, G_OPTION_ARG_FILENAME, &svgname, "Optional path for PDF file", "PATH"},
{"output-file", 'o', 0, G_OPTION_ARG_FILENAME, &output_path, "Output file path", "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 PDF Layers (OCG)", NULL },
{"custom-render-lib", 'P', 0, G_OPTION_ARG_FILENAME, &custom_library_path, "Path to a custom shared object, that implements the " EXTERNAL_LIBRARY_FUNCTION " function", "PATH"},
{"external-lib-output", 'e', 0, G_OPTION_ARG_FILENAME, &custom_library_file_name, "Output path for external render library", "PATH"},
{NULL}
};
@ -287,9 +283,6 @@ int main(int argc, char **argv)
scale = 1;
}
/* No format selected */
if (!(tikz || pdf || svg))
tikz = TRUE;
/* Get gds name */
gds_name = argv[1];
@ -302,29 +295,50 @@ int main(int argc, char **argv)
/* 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 (!strcmp(renderer_arg, "pdf")) {
renderer = CMD_CAIRO_PDF;
if (!output_path)
output_path = g_strdup_printf("./%s.pdf", basename);
}
else if (!strcmp(renderer_arg, "svg")) {
renderer = CMD_NONE; // To buggy atm CMD_CAIRO_SVG;
if (!output_path)
output_path = g_strdup_printf("./%s.svg", basename);
} else if (!strcmp(renderer_arg, "tikz")) {
renderer = CMD_LATEX;
if (pdf_layers)
opt |= CMD_OPT_LATEX_LAYERS;
if (pdf_standalone)
opt |= CMD_OPT_LATEX_STANDALONE;
if (!output_path)
output_path = g_strdup_printf("./%s.tex", basename);
} else if (!strcmp(renderer_arg, "ext")) {
renderer = CMD_EXTERNAL;
} else {
fprintf(stderr, "No valid renderer specified\n");
}
if (!pdfname)
pdfname = g_strdup_printf("./%s.pdf", basename);
if (!svgname)
svgname = g_strdup_printf("./%s.svg", basename);
command_line_convert_gds(gds_name, pdfname, texname, pdf, tikz,
mappingname, cellname, (double)scale,
pdf_layers, pdf_standalone, svg, svgname,
custom_library_path, custom_library_file_name);
/* Clean up */
g_free(pdfname);
g_free(texname);
g_free(svgname);
if (basename)
g_free(basename);
if (!output_path || strlen(output_path) == 0) {
app_status = -2;
goto ret_free_renderer;
}
command_line_convert_gds(gds_name, cellname, output_path, mappingname, custom_library_path, renderer, opt, scale);
/* Clean up */
app_status = 0;
ret_free_renderer:
if (output_path)
g_free(output_path);
if (renderer_arg)
g_free(renderer_arg);
if (mappingname)
g_free(mappingname);
if (cellname)
g_free(cellname);
app_status = 0;
} else {
app_status = start_gui(argc, argv);
}

View File

@ -86,8 +86,11 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
}
/* Execute */
if (so_render_func)
if (so_render_func) {
g_message("Calling external renderer.");
ret = so_render_func(toplevel_cell, layer_info_list, output_file, scale);
g_message("External renderer finished.");
}
ret_close_so_handle:
dlclose(so_handle);
@ -139,8 +142,10 @@ static void external_renderer_set_property(GObject *obj, guint property_id, cons
}
}
static void external_renderer_dispose(ExternalRenderer *self)
static void external_renderer_dispose(GObject *self_obj)
{
ExternalRenderer *self = GDS_RENDER_EXTERNAL_RENDERER(self_obj);
if (self->shared_object_path) {
g_free(self->shared_object_path);
self->shared_object_path = NULL;
@ -157,7 +162,7 @@ static void external_renderer_class_init(ExternalRendererClass *klass)
GObjectClass *oclass;
inherited_parent_class = GDS_RENDER_OUTPUT_RENDERER_CLASS(klass);
oclass = G_OBJECT_CLASS(oclass);
oclass = G_OBJECT_CLASS(klass);
/* Override virtual function */
inherited_parent_class->render_output = external_renderer_render_output;