Compare commits

...

9 Commits

11 changed files with 100 additions and 28 deletions

View File

@ -35,6 +35,7 @@
#include "cairo-output/cairo-output.h" #include "cairo-output/cairo-output.h"
#include "latex-output/latex-output.h" #include "latex-output/latex-output.h"
#include "external-renderer.h" #include "external-renderer.h"
#include "gds-parser/gds-tree-checker.h"
/** /**
* @brief Delete layer_info and free nem element. * @brief Delete layer_info and free nem element.
@ -69,8 +70,10 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
GList *layer_info_list = NULL; GList *layer_info_list = NULL;
GList *cell_list; GList *cell_list;
struct layer_info *linfo_temp; struct layer_info *linfo_temp;
struct gds_library *first_lib;
struct gds_cell *toplevel_cell = NULL, *temp_cell; struct gds_cell *toplevel_cell = NULL, *temp_cell;
/* Check if parameters are valid */ /* Check if parameters are valid */
if (!gds_name || (!pdf_name && pdf) || (!tex_name && tex) || !layer_file || !cell_name) { if (!gds_name || (!pdf_name && pdf) || (!tex_name && tex) || !layer_file || !cell_name) {
printf("Probably missing argument. Check --help option\n"); printf("Probably missing argument. Check --help option\n");
@ -81,14 +84,14 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
clear_lib_list(&libs); clear_lib_list(&libs);
res = parse_gds_from_file(gds_name, &libs); res = parse_gds_from_file(gds_name, &libs);
if (res) if (res)
return; goto ret_destroy_library_list;
file = g_file_new_for_path(layer_file); file = g_file_new_for_path(layer_file);
stream = g_file_read(file, NULL, NULL); stream = g_file_read(file, NULL, NULL);
if (!stream) { if (!stream) {
printf("Layer mapping not readable!\n"); printf("Layer mapping not readable!\n");
goto destroy_file; goto ret_destroy_file;
} }
dstream = g_data_input_stream_new(G_INPUT_STREAM(stream)); dstream = g_data_input_stream_new(G_INPUT_STREAM(stream));
i = 0; i = 0;
@ -100,7 +103,7 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
linfo_temp = (struct layer_info *)malloc(sizeof(struct layer_info)); linfo_temp = (struct layer_info *)malloc(sizeof(struct layer_info));
if (!linfo_temp) { if (!linfo_temp) {
printf("Out of memory\n"); printf("Out of memory\n");
goto ret_clear_list; goto ret_clear_layer_list;
} }
linfo_temp->color.alpha = layer_color.alpha; linfo_temp->color.alpha = layer_color.alpha;
linfo_temp->color.red = layer_color.red; linfo_temp->color.red = layer_color.red;
@ -116,9 +119,15 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
/* find_cell in first library. */ /* find_cell in first library. */
if (!libs) if (!libs)
goto ret_clear_list; goto ret_clear_layer_list;
for (cell_list = ((struct gds_library *)libs->data)->cells; cell_list != NULL; cell_list = g_list_next(cell_list)) { first_lib = (struct gds_library *)libs->data;
if (!first_lib) {
fprintf(stderr, "No library in library list. This should not happen.\n");
goto ret_clear_layer_list;
}
for (cell_list = first_lib->cells; cell_list != NULL; cell_list = g_list_next(cell_list)) {
temp_cell = (struct gds_cell *)cell_list->data; temp_cell = (struct gds_cell *)cell_list->data;
if (!strcmp(temp_cell->name, cell_name)) { if (!strcmp(temp_cell->name, cell_name)) {
toplevel_cell = temp_cell; toplevel_cell = temp_cell;
@ -128,9 +137,31 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
if (!toplevel_cell) { if (!toplevel_cell) {
printf("Couldn't find cell in first library!\n"); printf("Couldn't find cell in first library!\n");
goto ret_clear_list; goto ret_clear_layer_list;
} }
/* Check if cell passes vital checks */
res = gds_tree_check_reference_loops(toplevel_cell->parent_library);
if (res < 0) {
fprintf(stderr, "Checking library %s failed.\n", first_lib->name);
goto ret_clear_layer_list;
} else if (res > 0) {
fprintf(stderr, "%d reference loops found.\n", res);
/* do further checking if the specified cell and/or its subcells are affected */
if (toplevel_cell->checks.affected_by_reference_loop == 1) {
fprintf(stderr, "Cell is affected by reference loop. Abort!\n");
goto ret_clear_layer_list;
}
}
if (toplevel_cell->checks.affected_by_reference_loop == GDS_CELL_CHECK_NOT_RUN)
fprintf(stderr, "Cell was not checked. This should not happen. Please report this issue. Will continue either way.\n");
/* Note: unresolved references are not an abort condition.
* Deal with it.
*/
/* Render outputs */ /* Render outputs */
if (pdf == TRUE || svg == TRUE) { if (pdf == TRUE || svg == TRUE) {
cairo_render_cell_to_vector_file(toplevel_cell, layer_info_list, (pdf == TRUE ? pdf_name : NULL), cairo_render_cell_to_vector_file(toplevel_cell, layer_info_list, (pdf == TRUE ? pdf_name : NULL),
@ -140,14 +171,14 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
if (tex == TRUE) { if (tex == TRUE) {
tex_file = fopen(tex_name, "w"); tex_file = fopen(tex_name, "w");
if (!tex_file) if (!tex_file)
goto ret_clear_list; goto ret_clear_layer_list;
latex_render_cell_to_code(toplevel_cell, layer_info_list, tex_file, scale, pdf_layers, pdf_standalone); latex_render_cell_to_code(toplevel_cell, layer_info_list, tex_file, scale, pdf_layers, pdf_standalone);
fclose(tex_file); fclose(tex_file);
} }
if (so_name && so_out_file) { if (so_name && so_out_file) {
if (strlen(so_name) == 0 || strlen(so_out_file) == 0) if (strlen(so_name) == 0 || strlen(so_out_file) == 0)
goto ret_clear_list; goto ret_clear_layer_list;
/* Render output using external renderer */ /* Render output using external renderer */
printf("Invoking external renderer!\n"); printf("Invoking external renderer!\n");
@ -155,15 +186,16 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
printf("External renderer finished!\n"); printf("External renderer finished!\n");
} }
ret_clear_list: ret_clear_layer_list:
g_list_free_full(layer_info_list, (GDestroyNotify)delete_layer_info_with_name); g_list_free_full(layer_info_list, (GDestroyNotify)delete_layer_info_with_name);
g_object_unref(dstream); g_object_unref(dstream);
g_object_unref(stream); g_object_unref(stream);
destroy_file: ret_destroy_file:
g_object_unref(file); g_object_unref(file);
/* Delete all allocated libraries */
ret_destroy_library_list:
clear_lib_list(&libs);
} }
/** @} */ /** @} */

View File

@ -4,5 +4,5 @@
* @defgroup trigonometric Trigonometric Helper Functions * @defgroup trigonometric Trigonometric Helper Functions
* *
* The trigonometric helper function are used to calculate bounding boxes * The trigonometric helper function are used to calculate bounding boxes
* @warning Code is incomplete. Please double check the functionality! * @warning Code is incomplete. Please double check for functionality!
*/ */

View File

@ -6,7 +6,7 @@ To use the application on the command line check 'gds-render --help'.
Application Options: Application Options:
- -t, --tikz Output TikZ code - -t, --tikz Output TikZ code
- -p, --pdf Output PDF document - -p, --pdf Output PDF document
- -s, --scale=<SCALE> Divide output coordinates by <SCALE> - -s, --scale=SCALE Divide output coordinates by SCALE
- -o, --tex-output=PATH Optional path for TeX file - -o, --tex-output=PATH Optional path for TeX file
- -O, --pdf-output=PATH Optional path for PDF file - -O, --pdf-output=PATH Optional path for PDF file
- -m, --mapping=PATH Path for Layer Mapping File - -m, --mapping=PATH Path for Layer Mapping File

View File

@ -36,7 +36,8 @@
/** /**
* @brief function name expected to be found in external library. * @brief function name expected to be found in external library.
* @detail The function has to be defined as follows: *
* The function has to be defined as follows:
* @code * @code
* int function_name(gds_cell *toplevel, GList *layer_info_list, char *output_file_name) * int function_name(gds_cell *toplevel, GList *layer_info_list, char *output_file_name)
* @endcode * @endcode

View File

@ -894,6 +894,7 @@ int parse_gds_from_file(const char *filename, GList **library_list)
*/ */
static void delete_cell_inst_element(struct gds_cell_instance *cell_inst) static void delete_cell_inst_element(struct gds_cell_instance *cell_inst)
{ {
if (cell_inst)
free(cell_inst); free(cell_inst);
} }
@ -903,6 +904,7 @@ static void delete_cell_inst_element(struct gds_cell_instance *cell_inst)
*/ */
static void delete_vertex(struct gds_point *vertex) static void delete_vertex(struct gds_point *vertex)
{ {
if (vertex)
free(vertex); free(vertex);
} }
@ -912,6 +914,9 @@ static void delete_vertex(struct gds_point *vertex)
*/ */
static void delete_graphics_obj(struct gds_graphics *gfx) static void delete_graphics_obj(struct gds_graphics *gfx)
{ {
if (!gfx)
return;
g_list_free_full(gfx->vertices, (GDestroyNotify)delete_vertex); g_list_free_full(gfx->vertices, (GDestroyNotify)delete_vertex);
free(gfx); free(gfx);
} }
@ -922,6 +927,9 @@ static void delete_graphics_obj(struct gds_graphics *gfx)
*/ */
static void delete_cell_element(struct gds_cell *cell) static void delete_cell_element(struct gds_cell *cell)
{ {
if (!cell)
return;
g_list_free_full(cell->child_cells, (GDestroyNotify)delete_cell_inst_element); g_list_free_full(cell->child_cells, (GDestroyNotify)delete_cell_inst_element);
g_list_free_full(cell->graphic_objs, (GDestroyNotify)delete_graphics_obj); g_list_free_full(cell->graphic_objs, (GDestroyNotify)delete_graphics_obj);
free(cell); free(cell);
@ -933,6 +941,9 @@ static void delete_cell_element(struct gds_cell *cell)
*/ */
static void delete_library_element(struct gds_library *lib) static void delete_library_element(struct gds_library *lib)
{ {
if (!lib)
return;
g_list_free(lib->cell_names); g_list_free(lib->cell_names);
g_list_free_full(lib->cells, (GDestroyNotify)delete_cell_element); g_list_free_full(lib->cells, (GDestroyNotify)delete_cell_element);
free(lib); free(lib);
@ -940,8 +951,12 @@ static void delete_library_element(struct gds_library *lib)
int clear_lib_list(GList **library_list) int clear_lib_list(GList **library_list)
{ {
if (!library_list)
return 0;
if (*library_list == NULL) if (*library_list == NULL)
return 0; return 0;
g_list_free_full(*library_list, (GDestroyNotify)delete_library_element); g_list_free_full(*library_list, (GDestroyNotify)delete_library_element);
*library_list = NULL; *library_list = NULL;
return 0; return 0;

View File

@ -65,7 +65,7 @@ int gds_tree_check_cell_references(struct gds_library *lib)
instance_iter = g_list_next(instance_iter)) { instance_iter = g_list_next(instance_iter)) {
cell_inst = (struct gds_cell_instance *)instance_iter->data; cell_inst = (struct gds_cell_instance *)instance_iter->data;
/* Check if broken. This should also not happen */ /* Check if broken. This should not happen */
if (!cell_inst) { if (!cell_inst) {
fprintf(stderr, "Broken cell list item found in cell %s. Will continue.\n", fprintf(stderr, "Broken cell list item found in cell %s. Will continue.\n",
cell->name); cell->name);
@ -83,6 +83,29 @@ int gds_tree_check_cell_references(struct gds_library *lib)
return total_unresolved_count; return total_unresolved_count;
} }
/**
* @brief This function sets the marker element in the check structure of each cell to zero.
* @param lib Library to work with
* @return 0 if successful; negative if a fault (null pointer, ...) occured.
*/
static int gds_tree_check_clear_cell_check_marker(struct gds_library *lib)
{
GList *cell_iter;
struct gds_cell *cell;
if (!lib)
return -1;
for (cell_iter = lib->cells; cell_iter != NULL; cell_iter = g_list_next(cell_iter)) {
cell = (struct gds_cell *)cell_iter->data;
if (!cell)
return -2;
cell->checks._internal.marker = 0;
}
}
int gds_tree_check_reference_loops(struct gds_library *lib) int gds_tree_check_reference_loops(struct gds_library *lib)
{ {
return 0; return 0;

2
main.c
View File

@ -133,7 +133,7 @@ int main(int argc, char **argv)
{"tex-layers", 'l', 0, G_OPTION_ARG_NONE, &pdf_layers, "Create PDF Layers (OCG)", 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"}, {"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"}, {"external-lib-output", 'e', 0, G_OPTION_ARG_FILENAME, &custom_library_file_name, "Output path for external render library", "PATH"},
{ NULL } {NULL}
}; };
context = g_option_context_new(" FILE - Convert GDS file <FILE> to graphic"); context = g_option_context_new(" FILE - Convert GDS file <FILE> to graphic");

View File

@ -40,7 +40,7 @@ enum cell_store_columns {
CELL_SEL_CELL_ERROR_STATE, /**< Used for cell color and selectability */ CELL_SEL_CELL_ERROR_STATE, /**< Used for cell color and selectability */
CELL_SEL_MODDATE, CELL_SEL_MODDATE,
CELL_SEL_ACCESSDATE, CELL_SEL_ACCESSDATE,
CELL_SEL_COLUMN_COUNT /**< Not a column. Used to determine count of coumns **/ CELL_SEL_COLUMN_COUNT /**< @brief Not a column. Used to determine count of columns */
}; };
struct tree_stores { struct tree_stores {

View File

@ -180,10 +180,11 @@ void bounding_box_update_point(union bounding_box *destination, conv_generic_to_
} }
/** /**
* @brief bounding_box_apply_transform * @brief Apply transformations onto bounding box.
* @param scale scaling factor * @param scale Scaling factor
* @param rotation roation of bounding box around the origin in degrees (counterclockwise) * @param rotation_deg Roation of bounding box around the origin in degrees (counterclockwise)
* @param box bounding box the operations should be applied to * @param flip_at_x Flip the boundig box on the x axis before rotating.
* @param box Bounding box the operations should be applied to.
*/ */
void bounding_box_apply_transform(double scale, double rotation_deg, bool flip_at_x, union bounding_box *box) void bounding_box_apply_transform(double scale, double rotation_deg, bool flip_at_x, union bounding_box *box)
{ {

View File

@ -38,9 +38,9 @@ static void convert_gds_point_to_2d_vector(struct gds_point *pt, struct vector_2
} }
/** /**
* @brief update_box_with_gfx * @brief Update the given bounding box with the bounding box of a graphics element.
* @param box * @param box box to update
* @param gfx_list * @param gfx Graphics element
*/ */
static void update_box_with_gfx(union bounding_box *box, struct gds_graphics *gfx) static void update_box_with_gfx(union bounding_box *box, struct gds_graphics *gfx)
{ {

View File

@ -18,7 +18,7 @@
*/ */
/** /**
* @file conv-settings-dilaog.c * @file conv-settings-dialog.c
* @brief Implementation of the setting dialog * @brief Implementation of the setting dialog
* @author Mario Hüttel <mario.huettel@gmx.net> * @author Mario Hüttel <mario.huettel@gmx.net>
*/ */