#46: First draft for file open handle. Still buggy when multiple windows are opened

This commit is contained in:
Mario Hüttel 2023-01-24 19:44:12 +01:00
parent 14b1e8e22f
commit ce50fb708a
3 changed files with 97 additions and 66 deletions

View File

@ -274,25 +274,13 @@ const struct gds_cell_statistics cc = {
*/
static void on_load_gds(gpointer button, gpointer user)
{
GList *cell;
GtkTreeIter libiter;
GtkTreeIter celliter;
GList *lib;
struct gds_library *gds_lib;
struct gds_cell *gds_c;
(void)button;
GdsRenderGui *self;
GtkWidget *open_dialog;
GtkFileChooser *file_chooser;
GtkFileFilter *filter;
GtkStyleContext *button_style;
gint dialog_result;
int gds_result;
char *filename;
unsigned int cell_error_level;
const struct gds_library_parsing_opts gds_parsing_options = {
.simplified_polygons = 1,
};
self = RENDERER_GUI(user);
if (!self)
@ -319,59 +307,9 @@ static void on_load_gds(gpointer button, gpointer user)
/* Get File name */
filename = gtk_file_chooser_get_filename(file_chooser);
gtk_tree_store_clear(self->cell_tree_store);
clear_lib_list(&self->gds_libraries);
gds_render_gui_open_gds(self, filename);
/* Parse new GDSII file */
gds_result = parse_gds_from_file(filename, &self->gds_libraries, &gds_parsing_options);
/* Delete file name afterwards */
g_free(filename);
if (gds_result)
goto end_destroy;
/* remove suggested action from Open button */
button_style = gtk_widget_get_style_context(GTK_WIDGET(button));
gtk_style_context_remove_class(button_style, "suggested-action");
for (lib = self->gds_libraries; lib != NULL; lib = lib->next) {
gds_lib = (struct gds_library *)lib->data;
/* Create top level iter */
gtk_tree_store_append(self->cell_tree_store, &libiter, NULL);
gtk_tree_store_set(self->cell_tree_store, &libiter,
CELL_SEL_LIBRARY, gds_lib,
-1);
/* Check this library. This might take a while */
(void)gds_tree_check_cell_references(gds_lib);
(void)gds_tree_check_reference_loops(gds_lib);
for (cell = gds_lib->cells; cell != NULL; cell = cell->next) {
gds_c = (struct gds_cell *)cell->data;
gtk_tree_store_append(self->cell_tree_store, &celliter, &libiter);
/* Get the checking results for this cell */
cell_error_level = 0;
if (gds_c->checks.unresolved_child_count)
cell_error_level |= LIB_CELL_RENDERER_ERROR_WARN;
/* Check if it is completely b0rken */
if (gds_c->checks.affected_by_reference_loop)
cell_error_level |= LIB_CELL_RENDERER_ERROR_ERR;
/* Add cell to tree store model */
gtk_tree_store_set(self->cell_tree_store, &celliter,
CELL_SEL_CELL, gds_c,
CELL_SEL_CELL_ERROR_STATE, cell_error_level,
CELL_SEL_LIBRARY, gds_c->parent_library,
CELL_SEL_STAT, &gds_c->stats,
-1);
} /* for cells */
} /* for libraries */
/* Create Layers in Layer Box */
layer_selector_generate_layer_widgets(self->layer_selector, self->gds_libraries);
end_destroy:
/* Destroy dialog and filter */
@ -758,6 +696,76 @@ GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui)
return gui->main_window;
}
void gds_render_gui_open_gds(GdsRenderGui *self, const char *path)
{
GList *cell;
GtkTreeIter libiter;
GtkTreeIter celliter;
GList *lib;
struct gds_library *gds_lib;
struct gds_cell *gds_c;
GtkStyleContext *button_style;
int gds_result;
unsigned int cell_error_level;
const struct gds_library_parsing_opts gds_parsing_options = {
.simplified_polygons = 1,
};
gtk_tree_store_clear(self->cell_tree_store);
clear_lib_list(&self->gds_libraries);
/* Parse new GDSII file */
gds_result = parse_gds_from_file(path, &self->gds_libraries, &gds_parsing_options);
/* Delete file name afterwards */
if (gds_result)
return;
/* remove suggested action from Open button */
button_style = gtk_widget_get_style_context(self->open_button);
gtk_style_context_remove_class(button_style, "suggested-action");
for (lib = self->gds_libraries; lib != NULL; lib = lib->next) {
gds_lib = (struct gds_library *)lib->data;
/* Create top level iter */
gtk_tree_store_append(self->cell_tree_store, &libiter, NULL);
gtk_tree_store_set(self->cell_tree_store, &libiter,
CELL_SEL_LIBRARY, gds_lib,
-1);
/* Check this library. This might take a while */
(void)gds_tree_check_cell_references(gds_lib);
(void)gds_tree_check_reference_loops(gds_lib);
for (cell = gds_lib->cells; cell != NULL; cell = cell->next) {
gds_c = (struct gds_cell *)cell->data;
gtk_tree_store_append(self->cell_tree_store, &celliter, &libiter);
/* Get the checking results for this cell */
cell_error_level = 0;
if (gds_c->checks.unresolved_child_count)
cell_error_level |= LIB_CELL_RENDERER_ERROR_WARN;
/* Check if it is completely b0rken */
if (gds_c->checks.affected_by_reference_loop)
cell_error_level |= LIB_CELL_RENDERER_ERROR_ERR;
/* Add cell to tree store model */
gtk_tree_store_set(self->cell_tree_store, &celliter,
CELL_SEL_CELL, gds_c,
CELL_SEL_CELL_ERROR_STATE, cell_error_level,
CELL_SEL_LIBRARY, gds_c->parent_library,
CELL_SEL_STAT, &gds_c->stats,
-1);
} /* for cells */
} /* for libraries */
/* Create Layers in Layer Box */
layer_selector_generate_layer_widgets(self->layer_selector, self->gds_libraries);
}
static void gds_render_gui_init(GdsRenderGui *self)
{
GtkBuilder *main_builder;

View File

@ -54,6 +54,13 @@ GdsRenderGui *gds_render_gui_new();
*/
GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui);
/**
* @brief gds_render_gui_open_gds Open a GDS file. Emulates the manual load via GUI open button
* @param self GUI instance
* @param path file path
*/
void gds_render_gui_open_gds(GdsRenderGui *self, const char *path);
G_END_DECLS
/** @} */

20
main.c
View File

@ -40,6 +40,8 @@
struct application_data {
GtkApplication *app;
GList *gui_list;
gint num_files_to_open;
GFile **files;
};
/**
@ -158,6 +160,7 @@ static void gapp_activate(GApplication *app, gpointer user_data)
{
GtkWindow *main_window;
GdsRenderGui *gui;
char *open_file_path;
struct application_data * const appdata = (struct application_data *)user_data;
gui = gds_render_gui_new();
@ -166,7 +169,12 @@ static void gapp_activate(GApplication *app, gpointer user_data)
g_signal_connect(gui, "window-closed", G_CALLBACK(gui_window_closed_callback), &appdata->gui_list);
main_window = gds_render_gui_get_main_window(gui);
if (appdata->num_files_to_open >= 1) {
/* Open first file. Multiple files are not supported and ignored */
open_file_path = g_file_get_path(appdata->files[0]);
gds_render_gui_open_gds(gui, open_file_path);
g_free(open_file_path);
}
gtk_application_add_window(GTK_APPLICATION(app), main_window);
gtk_widget_show(GTK_WIDGET(main_window));
}
@ -178,6 +186,12 @@ static void gapp_activate(GApplication *app, gpointer user_data)
*/
static void gapp_activate_open(GApplication *app, GFile** files, gint n_files, const gchar* hint, gpointer user_data)
{
(void)hint;
struct application_data *appdata = (struct application_data *)user_data;
appdata->files = files;
appdata->num_files_to_open = n_files;
gapp_activate(app, user_data);
}
@ -198,7 +212,9 @@ static int start_gui(int argc, char **argv)
GString *application_domain;
int app_status;
static struct application_data appdata = {
.gui_list = NULL
.gui_list = NULL,
.num_files_to_open = 0,
.files = NULL,
};
GMenu *menu;
GMenu *m_quit;