From 199833d603de8372099eaeee81fad58f9341b4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 29 Dec 2018 01:13:33 +0100 Subject: [PATCH] Updated code for cell size calculation --- main-window.c | 5 ++ trigonometric/bounding-box.c | 5 ++ trigonometric/bounding-box.h | 1 + trigonometric/cell-trigonometrics.c | 104 ++++++++++++++++++++++++++++ trigonometric/cell-trigonometrics.h | 47 +++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 trigonometric/cell-trigonometrics.c create mode 100644 trigonometric/cell-trigonometrics.h diff --git a/main-window.c b/main-window.c index 564fa52..b67f733 100644 --- a/main-window.c +++ b/main-window.c @@ -36,6 +36,7 @@ #include "latex-output/latex-output.h" #include "widgets/conv-settings-dialog.h" #include "cairo-output/cairo-output.h" +#include "trigonometric/cell-trigonometrics.h" /** * @brief User data supplied to callback function of the open button @@ -217,6 +218,7 @@ static void on_convert_clicked(gpointer button, gpointer user) GtkFileFilter *filter; gint res; char *file_name; + union bounding_box *cell_box; /* Get selected cell */ selection = gtk_tree_view_get_selection(data->tree_view); @@ -231,6 +233,9 @@ static void on_convert_clicked(gpointer button, gpointer user) /* Get layers that are rendered */ layer_list = export_rendered_layer_info(); + /* Calculate cell size in DB units */ + + /* Show settings dialog */ settings = renderer_settings_dialog_new(GTK_WINDOW(data->main_window)); renderer_settings_dialog_set_settings(settings, &sett); res = gtk_dialog_run(GTK_DIALOG(settings)); diff --git a/trigonometric/bounding-box.c b/trigonometric/bounding-box.c index 648ac1b..db13baa 100644 --- a/trigonometric/bounding-box.c +++ b/trigonometric/bounding-box.c @@ -157,4 +157,9 @@ void bounding_box_update_point(union bounding_box *destination, conv_generic_to_ destination->vectors.upper_right.y = MAX(destination->vectors.upper_right.y, point.y); } +void bounding_box_apply_transform(double scale, double rotation, union bounding_box *box) +{ + +} + /** @} */ diff --git a/trigonometric/bounding-box.h b/trigonometric/bounding-box.h index aa9e1a1..e1f733d 100644 --- a/trigonometric/bounding-box.h +++ b/trigonometric/bounding-box.h @@ -48,6 +48,7 @@ void bounding_box_calculate_polygon(GList *vertices, conv_generic_to_vector_2d_t void bounding_box_update_box(union bounding_box *destination, union bounding_box *update); void bounding_box_prepare_empty(union bounding_box *box); void bounding_box_update_point(union bounding_box *destination, conv_generic_to_vector_2d_t conv_func, void *pt); +void bounding_box_apply_transform(double scale, double rotation, union bounding_box *box); #endif /* _BOUNDING_BOX_H_ */ diff --git a/trigonometric/cell-trigonometrics.c b/trigonometric/cell-trigonometrics.c new file mode 100644 index 0000000..5ca584d --- /dev/null +++ b/trigonometric/cell-trigonometrics.c @@ -0,0 +1,104 @@ +/* + * 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 . + */ + +/** + * @file cell-trigonometrics.c + * @brief Calculation of gds_cell trigonometrics + * @author Mario Hüttel + */ + +#include "cell-trigonometrics.h" + +/** + * @addtogroup trigonometric + * @{ + */ + +static void convert_gds_point_to_2d_vector(struct gds_point *pt, struct vector_2d *vector) +{ + vector->x = pt->x; + vector->y = pt->y; +} + +/** + * @brief update_box_with_gfx + * @param box + * @param gfx_list + */ +static void update_box_with_gfx(union bounding_box *box, struct gds_graphics *gfx) +{ + union bounding_box current_box; + + bounding_box_prepare_empty(¤t_box); + + switch (gfx->gfx_type) { + case GRAPHIC_BOX: + case GRAPHIC_POLYGON: + bounding_box_calculate_polygon(gfx->vertices, + (conv_generic_to_vector_2d_t)&convert_gds_point_to_2d_vector, + ¤t_box); + break; + case GRAPHIC_PATH: + /* + * This is not implemented correctly. + * Please be aware if paths are the oputpost elements of your cell. + * You might end up with a completely wrong calculated cell size. + */ + /* Okay.. You're right. It is not implemented at all. ;P */ + break; + default: + /* Unknown graphics object. */ + /* Print error? Nah.. */ + break; + } + + /* Update box with results */ + bounding_box_update_box(box, ¤t_box); +} + +void calculate_cell_bounding_box(union bounding_box *box, struct gds_cell *cell) +{ + GList *gfx_list; + struct gds_graphics *gfx; + GList *sub_cell_list; + struct gds_cell_instance *sub_cell; + union bounding_box temp_box; + + if (!box || !cell) + return; + + /* Update box with graphic elements */ + for (gfx_list = cell->graphic_objs; gfx_list != NULL; gfx_list = gfx_list->next) { + gfx = (struct gds_graphics *)gfx_list->data; + update_box_with_gfx(box, gfx); + } + + /* Update bounding box with boxes of subcells */ + for (sub_cell_list = cell->child_cells; sub_cell_list != NULL; sub_cell_list = sub_cell_list->next) { + sub_cell = (struct gds_cell_instance *)sub_cell_list->data; + bounding_box_prepare_empty(&temp_box); + /* Recursion Woohoo!! This dies if your GDS is faulty and contains a reference loop */ + calculate_cell_bounding_box(&temp_box, sub_cell->cell_ref); + + /* TODO: Apply transformations! */ + + } +} + +/** @} */ diff --git a/trigonometric/cell-trigonometrics.h b/trigonometric/cell-trigonometrics.h new file mode 100644 index 0000000..2a4ba5d --- /dev/null +++ b/trigonometric/cell-trigonometrics.h @@ -0,0 +1,47 @@ +/* + * 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 . + */ + +/** + * @file cell-trigonometrics.h + * @brief Calculation of gds_cell trigonometrics + * @author Mario Hüttel + */ + +/** + * @addtogroup trigonometric + * @{ + */ + +#ifndef _CELL_TRIGONOMETRICS_H_ +#define _CELL_TRIGONOMETRICS_H_ + +#include "bounding-box.h" +#include "../gds-parser/gds-types.h" + +/** + * @brief calculate_cell_bounding_box Calculate bounding box of gds cell + * @param box Resulting boundig box. Will be uüdated and not overwritten + * @param cell toplevel cell + * @warning Path handling not yet implemented correctly + */ +void calculate_cell_bounding_box(union bounding_box *box, struct gds_cell *cell); + +#endif /* _CELL_TRIGONOMETRICS_H_ */ + +/** @} */