Compare commits

..

No commits in common. "46-open-file-in-gui" and "master" have entirely different histories.

3 changed files with 68 additions and 111 deletions

View File

@ -274,13 +274,25 @@ const struct gds_cell_statistics cc = {
*/ */
static void on_load_gds(gpointer button, gpointer user) static void on_load_gds(gpointer button, gpointer user)
{ {
(void)button; GList *cell;
GtkTreeIter libiter;
GtkTreeIter celliter;
GList *lib;
struct gds_library *gds_lib;
struct gds_cell *gds_c;
GdsRenderGui *self; GdsRenderGui *self;
GtkWidget *open_dialog; GtkWidget *open_dialog;
GtkFileChooser *file_chooser; GtkFileChooser *file_chooser;
GtkFileFilter *filter; GtkFileFilter *filter;
GtkStyleContext *button_style;
gint dialog_result; gint dialog_result;
int gds_result;
char *filename; char *filename;
unsigned int cell_error_level;
const struct gds_library_parsing_opts gds_parsing_options = {
.simplified_polygons = 1,
};
self = RENDERER_GUI(user); self = RENDERER_GUI(user);
if (!self) if (!self)
@ -307,9 +319,59 @@ static void on_load_gds(gpointer button, gpointer user)
/* Get File name */ /* Get File name */
filename = gtk_file_chooser_get_filename(file_chooser); filename = gtk_file_chooser_get_filename(file_chooser);
gds_render_gui_open_gds(self, filename); gtk_tree_store_clear(self->cell_tree_store);
clear_lib_list(&self->gds_libraries);
/* Parse new GDSII file */
gds_result = parse_gds_from_file(filename, &self->gds_libraries, &gds_parsing_options);
/* Delete file name afterwards */
g_free(filename); 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: end_destroy:
/* Destroy dialog and filter */ /* Destroy dialog and filter */
@ -696,76 +758,6 @@ GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui)
return gui->main_window; 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) static void gds_render_gui_init(GdsRenderGui *self)
{ {
GtkBuilder *main_builder; GtkBuilder *main_builder;

View File

@ -54,13 +54,6 @@ GdsRenderGui *gds_render_gui_new();
*/ */
GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui); 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 G_END_DECLS
/** @} */ /** @} */

36
main.c
View File

@ -40,8 +40,6 @@
struct application_data { struct application_data {
GtkApplication *app; GtkApplication *app;
GList *gui_list; GList *gui_list;
gint num_files_to_open;
GFile **files;
}; };
/** /**
@ -160,7 +158,6 @@ static void gapp_activate(GApplication *app, gpointer user_data)
{ {
GtkWindow *main_window; GtkWindow *main_window;
GdsRenderGui *gui; GdsRenderGui *gui;
char *open_file_path;
struct application_data * const appdata = (struct application_data *)user_data; struct application_data * const appdata = (struct application_data *)user_data;
gui = gds_render_gui_new(); gui = gds_render_gui_new();
@ -169,32 +166,11 @@ static void gapp_activate(GApplication *app, gpointer user_data)
g_signal_connect(gui, "window-closed", G_CALLBACK(gui_window_closed_callback), &appdata->gui_list); g_signal_connect(gui, "window-closed", G_CALLBACK(gui_window_closed_callback), &appdata->gui_list);
main_window = gds_render_gui_get_main_window(gui); 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_application_add_window(GTK_APPLICATION(app), main_window);
gtk_widget_show(GTK_WIDGET(main_window)); gtk_widget_show(GTK_WIDGET(main_window));
} }
/**
* @brief Activation of GUI when opening a file from commandline
* @param app he GApplication reference
* @param user_data Used to store the individual GUI instances.
*/
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);
}
/** /**
* @brief Start the graphical interface. * @brief Start the graphical interface.
* *
@ -212,9 +188,7 @@ static int start_gui(int argc, char **argv)
GString *application_domain; GString *application_domain;
int app_status; int app_status;
static struct application_data appdata = { static struct application_data appdata = {
.gui_list = NULL, .gui_list = NULL
.num_files_to_open = 0,
.files = NULL,
}; };
GMenu *menu; GMenu *menu;
GMenu *m_quit; GMenu *m_quit;
@ -227,11 +201,10 @@ static int start_gui(int argc, char **argv)
application_domain = g_string_new(NULL); application_domain = g_string_new(NULL);
g_string_printf(application_domain, "de.shimatta.gds_render_%s", _app_git_commit); g_string_printf(application_domain, "de.shimatta.gds_render_%s", _app_git_commit);
gapp = gtk_application_new(application_domain->str, G_APPLICATION_HANDLES_OPEN); gapp = gtk_application_new(application_domain->str, G_APPLICATION_FLAGS_NONE);
g_string_free(application_domain, TRUE); g_string_free(application_domain, TRUE);
g_application_register(G_APPLICATION(gapp), NULL, NULL); g_application_register(G_APPLICATION(gapp), NULL, NULL);
g_signal_connect(gapp, "open", G_CALLBACK(gapp_activate_open), &appdata);
g_signal_connect(gapp, "activate", G_CALLBACK(gapp_activate), &appdata); g_signal_connect(gapp, "activate", G_CALLBACK(gapp_activate), &appdata);
if (g_application_get_is_remote(G_APPLICATION(gapp)) == TRUE) { if (g_application_get_is_remote(G_APPLICATION(gapp)) == TRUE) {
@ -338,8 +311,7 @@ int main(int argc, char **argv)
goto ret_status; goto ret_status;
} }
/* A minimum of a file name and a cell or analyze command are needed to use CLI */ if (argc >= 2) {
if (argc >= 2 && (analyze || cellname || output_paths)) {
if (scale < 1) { if (scale < 1) {
printf(_("Scale < 1 not allowed. Setting to 1\n")); printf(_("Scale < 1 not allowed. Setting to 1\n"));
scale = 1; scale = 1;