From 6b0369582424ae0dbff5724adf6c0fe0d7770233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 14 Mar 2019 21:30:37 +0100 Subject: [PATCH] Restructured Code * Move layer info struct and associated functions to dedicated c/h files. * Rename layer selector folder more generic "layer" Besides from restructuring nothing changes --- CMakeLists.txt | 2 +- cairo-output/cairo-output.h | 2 +- command-line.c | 1 + latex-output/latex-output.h | 2 +- layer/layer-info.c | 9 +++ layer/layer-info.h | 26 +++++++++ .../layer-selector-dnd.c | 0 .../layer-selector-dnd.h | 0 {layer-selector => layer}/layer-selector.c | 58 +------------------ {layer-selector => layer}/layer-selector.h | 9 +-- main-window.c | 4 +- mapping-parser.c | 46 +++++++++++++++ mapping-parser.h | 22 +++---- 13 files changed, 99 insertions(+), 82 deletions(-) create mode 100644 layer/layer-info.c create mode 100644 layer/layer-info.h rename {layer-selector => layer}/layer-selector-dnd.c (100%) rename {layer-selector => layer}/layer-selector-dnd.h (100%) rename {layer-selector => layer}/layer-selector.c (88%) rename {layer-selector => layer}/layer-selector.h (90%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8dceae..5a69d99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ aux_source_directory("gds-parser" PARSER_SOURCES) aux_source_directory("latex-output" LATEX_SOURCES) aux_source_directory("cairo-output" CAIRO_SOURCES) aux_source_directory("trigonometric" TRIG_SOURCES) -aux_source_directory("layer-selector" LAYER_SELECTOR_SOURCES) +aux_source_directory("layer" LAYER_SELECTOR_SOURCES) set(SOURCE "main.c" "mapping-parser.c" "command-line.c" "main-window.c" "external-renderer.c") set(SOURCE diff --git a/cairo-output/cairo-output.h b/cairo-output/cairo-output.h index cd2e8bd..3afccbe 100644 --- a/cairo-output/cairo-output.h +++ b/cairo-output/cairo-output.h @@ -24,7 +24,7 @@ #ifndef __CAIRO_OUTPUT_H__ #define __CAIRO_OUTPUT_H__ -#include "../layer-selector/layer-selector.h" +#include "../layer/layer-info.h" #include "../gds-parser/gds-types.h" /** @addtogroup Cairo-Renderer diff --git a/command-line.c b/command-line.c index 0dc302f..ee7e8ec 100644 --- a/command-line.c +++ b/command-line.c @@ -32,6 +32,7 @@ #include "command-line.h" #include "gds-parser/gds-parser.h" #include "mapping-parser.h" +#include "layer/layer-info.h" #include "cairo-output/cairo-output.h" #include "latex-output/latex-output.h" #include "external-renderer.h" diff --git a/latex-output/latex-output.h b/latex-output/latex-output.h index 334c3da..2329171 100644 --- a/latex-output/latex-output.h +++ b/latex-output/latex-output.h @@ -34,7 +34,7 @@ #include "../gds-parser/gds-types.h" #include #include -#include "../mapping-parser.h" +#include "../layer/layer-info.h" #define LATEX_LINE_BUFFER_KB (10) /**< @brief Buffer for LaTeX Code line in KiB */ diff --git a/layer/layer-info.c b/layer/layer-info.c new file mode 100644 index 0000000..368bc90 --- /dev/null +++ b/layer/layer-info.c @@ -0,0 +1,9 @@ + + +#include "layer-info.h" + +void delete_layer_info_struct(struct layer_info *info) +{ + if (info) + free(info); +} diff --git a/layer/layer-info.h b/layer/layer-info.h new file mode 100644 index 0000000..f56040a --- /dev/null +++ b/layer/layer-info.h @@ -0,0 +1,26 @@ +#ifndef _LAYER_INFO_H_ +#define _LAYER_INFO_H_ + +#include + +/** + * @brief Layer information. + * + * This structs contains information on how to render a layer + */ +struct layer_info +{ + int layer; /**< @brief Layer number */ + char *name; /**< @brief Layer name */ + int stacked_position; ///< @brief Position of layer in output @warning This parameter is not used by any renderer so far @note Lower is bottom, higher is top + GdkRGBA color; /**< @brief RGBA color used to render this layer */ +}; + +/** + * @brief Delete a layer_info struct + * @param info Struct to be deleted. + * @note The layer_info::name Element has to be freed manually + */ +void delete_layer_info_struct(struct layer_info *info); + +#endif // _LAYERINFO_H_ diff --git a/layer-selector/layer-selector-dnd.c b/layer/layer-selector-dnd.c similarity index 100% rename from layer-selector/layer-selector-dnd.c rename to layer/layer-selector-dnd.c diff --git a/layer-selector/layer-selector-dnd.h b/layer/layer-selector-dnd.h similarity index 100% rename from layer-selector/layer-selector-dnd.h rename to layer/layer-selector-dnd.h diff --git a/layer-selector/layer-selector.c b/layer/layer-selector.c similarity index 88% rename from layer-selector/layer-selector.c rename to layer/layer-selector.c index 31f8e56..4a25b90 100644 --- a/layer-selector/layer-selector.c +++ b/layer/layer-selector.c @@ -29,8 +29,10 @@ */ #include "layer-selector.h" +#include "layer-info.h" #include "../gds-parser/gds-parser.h" #include "../widgets/layer-element.h" +#include "../mapping-parser.h" #include #include #include @@ -40,12 +42,6 @@ static GtkWidget *global_load_button; static GtkWidget *global_save_button; static GtkListBox *global_list_box; -void delete_layer_info_struct(struct layer_info *info) -{ - if (info) - free(info); -} - /** * @brief export_rendered_layer_info * @return new list with all info elements needed to render cells @@ -320,57 +316,7 @@ static void load_mapping_clicked(GtkWidget *button, gpointer user_data) gtk_widget_destroy(dialog); } -/** - * @brief Create Line for LayerMapping file with supplied information - * @param layer_element information - * @param line_buffer buffer to write to - * @param max_len Maximum length that cna be used in \p line_buffer - */ -static void create_csv_line(LayerElement *layer_element, char *line_buffer, size_t max_len) -{ - int i; - GString *string; - gboolean export; - const gchar *name; - int layer; - GdkRGBA color; - string = g_string_new_len(NULL, max_len-1); - - /* Extract values */ - export = layer_element_get_export(layer_element); - name = (const gchar*)layer_element_get_name(layer_element); - layer = layer_element_get_layer(layer_element); - layer_element_get_color(layer_element, &color); - - /* print values to line */ - g_string_printf(string, "%d:%lf:%lf:%lf:%lf:%d:%s\n", - layer, color.red, color.green, - color.blue, color.alpha, (export == TRUE ? 1 : 0), name); - /* Fix broken locale settings */ - for (i = 0; string->str[i]; i++) { - if (string->str[i] == ',') - string->str[i] = '.'; - } - - for (i = 0; string->str[i]; i++) { - if (string->str[i] == ':') - string->str[i] = ','; - } - - if (string->len > (max_len-1)) { - printf("Layer Definition too long. Please shorten Layer Name!!\n"); - line_buffer[0] = 0x0; - return; - } - - /* copy max_len bytes of string */ - strncpy(line_buffer, (char *)string->str, max_len-1); - line_buffer[max_len-1] = 0; - - /* Completely remove string */ - g_string_free(string, TRUE); -} /** * @brief Save layer mapping of whole list box into file diff --git a/layer-selector/layer-selector.h b/layer/layer-selector.h similarity index 90% rename from layer-selector/layer-selector.h rename to layer/layer-selector.h index 5324186..968e441 100644 --- a/layer-selector/layer-selector.h +++ b/layer/layer-selector.h @@ -61,14 +61,7 @@ void setup_save_mapping_callback(GtkWidget *button, GtkWindow *main_window); * @brief get the layer information present in the listbox of the selector * @return List with layer_info elements */ -GList *export_rendered_layer_info(); - -/** - * @brief Delete a layer_info struct - * @param info Struct to be deleted. - * @note The layer_info::name Element has to be freed manually - */ -void delete_layer_info_struct(struct layer_info *info); +GList *export_rendered_layer_info(void); /** * @brief Force sorting of the layer selector in a specified way diff --git a/main-window.c b/main-window.c index 7632e0f..1291609 100644 --- a/main-window.c +++ b/main-window.c @@ -31,8 +31,8 @@ #include #include "gds-parser/gds-parser.h" #include -#include "layer-selector/layer-selector.h" -#include "layer-selector/layer-selector-dnd.h" +#include "layer/layer-selector.h" +#include "layer/layer-selector-dnd.h" #include "tree-renderer/tree-store.h" #include "latex-output/latex-output.h" #include "widgets/conv-settings-dialog.h" diff --git a/mapping-parser.c b/mapping-parser.c index 9c03d80..861b776 100644 --- a/mapping-parser.c +++ b/mapping-parser.c @@ -94,5 +94,51 @@ ret_direct: } +void create_csv_line(LayerElement *layer_element, char *line_buffer, size_t max_len) +{ + int i; + GString *string; + gboolean export; + const gchar *name; + int layer; + GdkRGBA color; + + string = g_string_new_len(NULL, max_len-1); + + /* Extract values */ + export = layer_element_get_export(layer_element); + name = (const gchar*)layer_element_get_name(layer_element); + layer = layer_element_get_layer(layer_element); + layer_element_get_color(layer_element, &color); + + /* print values to line */ + g_string_printf(string, "%d:%lf:%lf:%lf:%lf:%d:%s\n", + layer, color.red, color.green, + color.blue, color.alpha, (export == TRUE ? 1 : 0), name); + /* Fix broken locale settings */ + for (i = 0; string->str[i]; i++) { + if (string->str[i] == ',') + string->str[i] = '.'; + } + + for (i = 0; string->str[i]; i++) { + if (string->str[i] == ':') + string->str[i] = ','; + } + + if (string->len > (max_len-1)) { + printf("Layer Definition too long. Please shorten Layer Name!!\n"); + line_buffer[0] = 0x0; + return; + } + + /* copy max_len bytes of string */ + strncpy(line_buffer, (char *)string->str, max_len-1); + line_buffer[max_len-1] = 0; + + /* Completely remove string */ + g_string_free(string, TRUE); +} + /** @} */ diff --git a/mapping-parser.h b/mapping-parser.h index c573744..4fe92dc 100644 --- a/mapping-parser.h +++ b/mapping-parser.h @@ -32,19 +32,7 @@ */ #include - -/** - * @brief Layer information. - * - * This structs contains information on how to render a layer - */ -struct layer_info -{ - int layer; /**< @brief Layer number */ - char *name; /**< @brief Layer name */ - int stacked_position; ///< @brief Position of layer in output @warning This parameter is not used by any renderer so far @note Lower is bottom, higher is top - GdkRGBA color; /**< @brief RGBA color used to render this layer */ -}; +#include "widgets/layer-element.h" /** * @brief Load a line from \p stream and parse try to parse it as layer information @@ -57,6 +45,14 @@ struct layer_info */ int load_csv_line(GDataInputStream *stream, gboolean *export, char **name, int *layer, GdkRGBA *color); +/** + * @brief Create Line for LayerMapping file with supplied information + * @param layer_element information + * @param line_buffer buffer to write to + * @param max_len Maximum length that cna be used in \p line_buffer + */ +void create_csv_line(LayerElement *layer_element, char *line_buffer, size_t max_len); + /** @} */ #endif /* __MAPPING_PARSER_H__ */