2022-04-17 00:37:26 +02:00
|
|
|
/*
|
|
|
|
* GDSII-Converter
|
|
|
|
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file gds-statistics.c
|
|
|
|
* @brief Statistics of GDS files
|
|
|
|
* @author Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gds-render/gds-utils/gds-statistics.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup GDS-Utilities
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
#define MAX_RECURSION_DEPTH (1024)
|
|
|
|
|
|
|
|
static void calculate_vertex_gfx_count_cell(struct gds_cell *cell, unsigned int recursion_depth)
|
2022-04-17 00:37:26 +02:00
|
|
|
{
|
2022-04-17 18:37:32 +02:00
|
|
|
GList *cell_iter;
|
|
|
|
struct gds_cell_instance *cell_ref;
|
|
|
|
struct gds_cell *sub_cell;
|
2022-04-17 00:37:26 +02:00
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
g_return_if_fail(cell);
|
|
|
|
|
|
|
|
/* Check if cell has already been calculated */
|
|
|
|
if (cell->stats.total_gfx_count && cell->stats.total_vertex_count) {
|
|
|
|
/* Return. This cell and all of its subcells have been calculated */
|
2022-04-17 00:37:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
/* Update with own vertex / GFX count */
|
|
|
|
cell->stats.total_vertex_count = cell->stats.vertex_count;
|
|
|
|
cell->stats.total_gfx_count = cell->stats.gfx_count;
|
2022-04-17 00:37:26 +02:00
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
/* Do not analyze further, if maximum recursion depth is reached */
|
|
|
|
if (!recursion_depth)
|
2022-04-17 00:37:26 +02:00
|
|
|
return;
|
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
for (cell_iter = cell->child_cells; cell_iter; cell_iter = g_list_next(cell_iter)) {
|
|
|
|
/* Scan all subcells recursively, if there are any */
|
2022-04-17 00:37:26 +02:00
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
cell_ref = (struct gds_cell_instance *)cell_iter->data;
|
|
|
|
sub_cell = (struct gds_cell *)cell_ref->cell_ref;
|
2022-04-17 00:37:26 +02:00
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
calculate_vertex_gfx_count_cell(sub_cell, recursion_depth - 1);
|
2022-04-17 00:37:26 +02:00
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
/* Increment count */
|
|
|
|
cell->stats.total_vertex_count += sub_cell->stats.total_vertex_count;
|
|
|
|
cell->stats.total_gfx_count += sub_cell->stats.total_vertex_count;
|
2022-04-17 00:37:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
void gds_statistics_calc_cummulative_counts_in_lib(struct gds_library *lib)
|
2022-04-17 00:37:26 +02:00
|
|
|
{
|
2022-04-17 18:37:32 +02:00
|
|
|
GList *cell_iter;
|
|
|
|
struct gds_cell *cell;
|
2022-04-17 00:37:26 +02:00
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
g_return_if_fail(lib);
|
2022-04-17 00:37:26 +02:00
|
|
|
|
2022-04-17 18:37:32 +02:00
|
|
|
for (cell_iter = lib->cells; cell_iter; cell_iter = g_list_next(cell_iter)) {
|
|
|
|
cell = (struct gds_cell *)cell_iter->data;
|
|
|
|
calculate_vertex_gfx_count_cell(cell, MAX_RECURSION_DEPTH);
|
|
|
|
lib->stats.vertex_count += cell->stats.vertex_count;
|
|
|
|
lib->stats.cell_count++;
|
|
|
|
lib->stats.gfx_count += cell->stats.gfx_count;
|
|
|
|
lib->stats.reference_count += cell->stats.reference_count;
|
2022-04-17 00:37:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @} */
|