Compare commits

...

2 Commits

Author SHA1 Message Date
15ff68ea74 Fix invalid conversion 2018-12-22 19:13:33 +01:00
6bb05890b9 Add database unit parsing 2018-12-22 19:11:09 +01:00
3 changed files with 27 additions and 6 deletions

View File

@ -48,6 +48,12 @@
#include <math.h> #include <math.h>
#include <cairo.h> #include <cairo.h>
/**
* @brief Default units assumed for library.
* @note This value is usually overwritten with the value defined in the library.
*/
#define GDS_DEFAULT_UNITS (10E-9)
#define GDS_ERROR(fmt, ...) printf("[PARSE_ERROR] " fmt "\n", ##__VA_ARGS__) /**< @brief Print GDS error*/ #define GDS_ERROR(fmt, ...) printf("[PARSE_ERROR] " fmt "\n", ##__VA_ARGS__) /**< @brief Print GDS error*/
#define GDS_WARN(fmt, ...) printf("[PARSE_WARNING] " fmt "\n", ##__VA_ARGS__) /**< @brief Print GDS warning */ #define GDS_WARN(fmt, ...) printf("[PARSE_WARNING] " fmt "\n", ##__VA_ARGS__) /**< @brief Print GDS warning */
@ -221,7 +227,7 @@ static GList *append_library(GList *curr_list, struct gds_library **library_ptr)
if (lib) { if (lib) {
lib->cells = NULL; lib->cells = NULL;
lib->name[0] = 0; lib->name[0] = 0;
lib->unit_to_meters = 1; // Default. Will be overwritten lib->unit_in_meters = GDS_DEFAULT_UNITS; // Default. Will be overwritten
lib->cell_names = NULL; lib->cell_names = NULL;
} else } else
return NULL; return NULL;
@ -383,7 +389,7 @@ static int name_cell(struct gds_cell *cell, unsigned int bytes,
return -1; return -1;
} }
data[bytes] = 0; // Append '0' data[bytes] = 0; // Append '0'
len = strlen(data); len = (int)strlen(data);
if (len > CELL_NAME_MAX-1) { if (len > CELL_NAME_MAX-1) {
GDS_ERROR("Cell name '%s' too long: %d\n", data, len); GDS_ERROR("Cell name '%s' too long: %d\n", data, len);
return -1; return -1;
@ -710,6 +716,8 @@ int parse_gds_from_file(const char *filename, GList **library_list)
break; break;
case PATHTYPE: case PATHTYPE:
break; break;
case UNITS:
break;
default: default:
//GDS_WARN("Record: %04x, len: %u", (unsigned int)rec_type, (unsigned int)rec_data_length); //GDS_WARN("Record: %04x, len: %u", (unsigned int)rec_type, (unsigned int)rec_data_length);
break; break;
@ -731,7 +739,6 @@ int parse_gds_from_file(const char *filename, GList **library_list)
switch (rec_type) { switch (rec_type) {
case HEADER: case HEADER:
case UNITS:
case ENDLIB: case ENDLIB:
case ENDSTR: case ENDSTR:
case BOUNDARY: case BOUNDARY:
@ -742,6 +749,20 @@ int parse_gds_from_file(const char *filename, GList **library_list)
case INVALID: case INVALID:
break; break;
case UNITS:
if (!current_lib) {
GDS_WARN("Units defined outside of library!\n");
break;
}
if (rec_data_length != 16) {
GDS_WARN("Unit define incomplete. Will assume database unit of %E meters\n", current_lib->unit_in_meters);
break;
}
current_lib->unit_in_meters = gds_convert_double(&workbuff[8]);
GDS_INF("Length of database unit: %E meters\n", current_lib->unit_in_meters);
break;
case BGNLIB: case BGNLIB:
/* Parse date record */ /* Parse date record */
gds_parse_date(workbuff, read, &current_lib->mod_time, &current_lib->access_time); gds_parse_date(workbuff, read, &current_lib->mod_time, &current_lib->access_time);

View File

@ -113,7 +113,7 @@ struct gds_library {
char name[CELL_NAME_MAX]; char name[CELL_NAME_MAX];
struct gds_time_field mod_time; struct gds_time_field mod_time;
struct gds_time_field access_time; struct gds_time_field access_time;
double unit_to_meters; /**< @warning not yet implemented */ double unit_in_meters; /**< Length of a database unit in meters */
GList *cells; /**< List of #gds_cell that contains all cells in this library*/ GList *cells; /**< List of #gds_cell that contains all cells in this library*/
GList *cell_names /**< List of strings that contains all cell names */; GList *cell_names /**< List of strings that contains all cell names */;
}; };

View File

@ -202,7 +202,7 @@ end_destroy:
static void on_convert_clicked(gpointer button, gpointer user) static void on_convert_clicked(gpointer button, gpointer user)
{ {
static struct render_settings sett = { static struct render_settings sett = {
.scale = 1000.0f, .scale = 1000.0,
.renderer = RENDERER_LATEX_TIKZ, .renderer = RENDERER_LATEX_TIKZ,
}; };
struct convert_button_data *data = (struct convert_button_data *)user; struct convert_button_data *data = (struct convert_button_data *)user;