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
This commit is contained in:
Mario Hüttel 2019-03-14 21:30:37 +01:00
parent b0c25a4bcf
commit 6b03695824
13 changed files with 99 additions and 82 deletions

View File

@ -20,7 +20,7 @@ aux_source_directory("gds-parser" PARSER_SOURCES)
aux_source_directory("latex-output" LATEX_SOURCES) aux_source_directory("latex-output" LATEX_SOURCES)
aux_source_directory("cairo-output" CAIRO_SOURCES) aux_source_directory("cairo-output" CAIRO_SOURCES)
aux_source_directory("trigonometric" TRIG_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 "main.c" "mapping-parser.c" "command-line.c" "main-window.c" "external-renderer.c")
set(SOURCE set(SOURCE

View File

@ -24,7 +24,7 @@
#ifndef __CAIRO_OUTPUT_H__ #ifndef __CAIRO_OUTPUT_H__
#define __CAIRO_OUTPUT_H__ #define __CAIRO_OUTPUT_H__
#include "../layer-selector/layer-selector.h" #include "../layer/layer-info.h"
#include "../gds-parser/gds-types.h" #include "../gds-parser/gds-types.h"
/** @addtogroup Cairo-Renderer /** @addtogroup Cairo-Renderer

View File

@ -32,6 +32,7 @@
#include "command-line.h" #include "command-line.h"
#include "gds-parser/gds-parser.h" #include "gds-parser/gds-parser.h"
#include "mapping-parser.h" #include "mapping-parser.h"
#include "layer/layer-info.h"
#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"

View File

@ -34,7 +34,7 @@
#include "../gds-parser/gds-types.h" #include "../gds-parser/gds-types.h"
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <stdio.h>
#include "../mapping-parser.h" #include "../layer/layer-info.h"
#define LATEX_LINE_BUFFER_KB (10) /**< @brief Buffer for LaTeX Code line in KiB */ #define LATEX_LINE_BUFFER_KB (10) /**< @brief Buffer for LaTeX Code line in KiB */

9
layer/layer-info.c Normal file
View File

@ -0,0 +1,9 @@
#include "layer-info.h"
void delete_layer_info_struct(struct layer_info *info)
{
if (info)
free(info);
}

26
layer/layer-info.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef _LAYER_INFO_H_
#define _LAYER_INFO_H_
#include <gtk/gtk.h>
/**
* @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_

View File

@ -29,8 +29,10 @@
*/ */
#include "layer-selector.h" #include "layer-selector.h"
#include "layer-info.h"
#include "../gds-parser/gds-parser.h" #include "../gds-parser/gds-parser.h"
#include "../widgets/layer-element.h" #include "../widgets/layer-element.h"
#include "../mapping-parser.h"
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -40,12 +42,6 @@ static GtkWidget *global_load_button;
static GtkWidget *global_save_button; static GtkWidget *global_save_button;
static GtkListBox *global_list_box; static GtkListBox *global_list_box;
void delete_layer_info_struct(struct layer_info *info)
{
if (info)
free(info);
}
/** /**
* @brief export_rendered_layer_info * @brief export_rendered_layer_info
* @return new list with all info elements needed to render cells * @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); 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 * @brief Save layer mapping of whole list box into file

View File

@ -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 * @brief get the layer information present in the listbox of the selector
* @return List with layer_info elements * @return List with layer_info elements
*/ */
GList *export_rendered_layer_info(); GList *export_rendered_layer_info(void);
/**
* @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);
/** /**
* @brief Force sorting of the layer selector in a specified way * @brief Force sorting of the layer selector in a specified way

View File

@ -31,8 +31,8 @@
#include <stdio.h> #include <stdio.h>
#include "gds-parser/gds-parser.h" #include "gds-parser/gds-parser.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "layer-selector/layer-selector.h" #include "layer/layer-selector.h"
#include "layer-selector/layer-selector-dnd.h" #include "layer/layer-selector-dnd.h"
#include "tree-renderer/tree-store.h" #include "tree-renderer/tree-store.h"
#include "latex-output/latex-output.h" #include "latex-output/latex-output.h"
#include "widgets/conv-settings-dialog.h" #include "widgets/conv-settings-dialog.h"

View File

@ -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);
}
/** @} */ /** @} */

View File

@ -32,19 +32,7 @@
*/ */
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "widgets/layer-element.h"
/**
* @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 Load a line from \p stream and parse try to parse it as layer information * @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); 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__ */ #endif /* __MAPPING_PARSER_H__ */