diff --git a/include/gds-render/output-renderers/gds-output-renderer.h b/include/gds-render/output-renderers/gds-output-renderer.h new file mode 100644 index 0000000..ea5f8bc --- /dev/null +++ b/include/gds-render/output-renderers/gds-output-renderer.h @@ -0,0 +1,92 @@ +/* + * 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 gds-output-renderer.h + * @brief Header for output renderer base class + * @author Mario Hüttel + */ + +/** + * @addtogroup GdsOutputRenderer + * @{ + */ + +#ifndef _GDS_OUTPUT_RENDERER_H_ +#define _GDS_OUTPUT_RENDERER_H_ + +#include +#include +#include + +G_BEGIN_DECLS + +#define GDS_RENDER_TYPE_OUTPUT_RENDERER (gds_output_renderer_get_type()) + +G_DECLARE_DERIVABLE_TYPE(GdsOutputRenderer, gds_output_renderer, GDS_RENDER, OUTPUT_RENDERER, GObject); + +/** + * @brief Base output renderer class structure. + * @note This structure is only used for internal inheritance of GObjects. Do not use in code outside of these classes. + */ +struct _GdsOutputRendererClass { + GObjectClass parent_class; + + /** + * @brief Virtual render output function. Overwritten by final class implementation + */ + int (*render_output)(GdsOutputRenderer *renderer, + struct gds_cell *cell, + GList *layer_infos, + const char *output_file, + double scale); + gpointer padding[4]; +}; + +enum { + GDS_OUTPUT_RENDERER_GEN_ERR = -100, /**< @brief Error set by the _GdsOutputRendererClass::render_output virtual function, if renderer is invalid. */ + GDS_OUTPUT_RENDERER_PARAM_ERR = -200 /**< @brief Error set by the _GdsOutputRendererClass::render_output virtual function, if parameters are faulty. */ +}; + +/** + * @brief Create a new GdsOutputRenderer GObject. + * @return New object + */ +GdsOutputRenderer *gds_output_renderer_new(); + +/** + * @brief gds_output_renderer_render_output + * @param renderer Renderer object + * @param cell Cell to render + * @param layer_infos List of Layer information (@ref layer_info) + * @param output_file Output file name + * @param scale scale value. The output is scaled *down* by this value + * @return 0 if successful + */ +int gds_output_renderer_render_output(GdsOutputRenderer *renderer, + struct gds_cell *cell, + GList *layer_infos, + const char *output_file, + double scale); + +G_END_DECLS + +#endif /* _GDS_OUTPUT_RENDERER_H_ */ + +/** @} */ diff --git a/output-renderers/gds-output-renderer.c b/output-renderers/gds-output-renderer.c new file mode 100644 index 0000000..fb19f0c --- /dev/null +++ b/output-renderers/gds-output-renderer.c @@ -0,0 +1,98 @@ +/* + * GDSII-Converter + * Copyright (C) 2019 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 gds-output-renderer.c + * @brief Base GObject class for output renderers + * + * All output renderers are derived from this class + * + * @author Mario Hüttel + */ + +/** @addtogroup GdsOutputRenderer + * @{ + */ + +#include + +typedef struct { + gpointer padding[12]; +} GdsOutputRendererPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE(GdsOutputRenderer, gds_output_renderer, G_TYPE_OBJECT) + +static int gds_output_renderer_render_dummy(GdsOutputRenderer *renderer, + struct gds_cell *cell, + GList *layer_infos, + const char *output_file, + double scale) +{ + (void)renderer; + (void)cell; + (void)layer_infos; + (void)output_file; + (void)scale; + + g_warning("Output renderer does not define a render_output function!"); + return 0; +} + +static void gds_output_renderer_class_init(GdsOutputRendererClass *klass) +{ + klass->render_output = gds_output_renderer_render_dummy; +} + +void gds_output_renderer_init(GdsOutputRenderer *self) +{ + (void)self; + + return; +} + +GdsOutputRenderer *gds_output_renderer_new() +{ + return GDS_RENDER_OUTPUT_RENDERER(g_object_new(GDS_RENDER_TYPE_OUTPUT_RENDERER, NULL)); +} + +int gds_output_renderer_render_output(GdsOutputRenderer *renderer, struct gds_cell *cell, GList *layer_infos, const char *output_file, double scale) +{ + GdsOutputRendererClass *klass; + + if (GDS_RENDER_IS_OUTPUT_RENDERER(renderer) == FALSE) { + g_error("Output Renderer not valid."); + return GDS_OUTPUT_RENDERER_GEN_ERR; + } + + if (!cell || !layer_infos || !output_file) { + g_error("Output renderer called with insufficient parameters."); + return GDS_OUTPUT_RENDERER_PARAM_ERR; + } + + klass = GDS_RENDER_OUTPUT_RENDERER_GET_CLASS(renderer); + if (klass->render_output == NULL) { + g_critical("Output Renderer: Rendering function broken. This is a bug."); + return GDS_OUTPUT_RENDERER_GEN_ERR; + } + + return klass->render_output(renderer, cell, layer_infos, output_file, scale); +} + + +/** @} */