layer element created, dialog for multiple files added

This commit is contained in:
Mario Hüttel 2018-05-15 16:57:08 +02:00
parent 1539348cc6
commit aea3b490ca
5 changed files with 73 additions and 9 deletions

View File

@ -9,7 +9,7 @@ link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS})
configure_file(glade/main.glade glade/main.glade COPYONLY)
project(gds-render)
add_executable(${PROJECT_NAME} "main.c" "gdsparse.c")
add_executable(${PROJECT_NAME} "main.c" "gdsparse.c" "layer-element.c")
target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} m)

View File

@ -60,7 +60,7 @@
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkBox" id="button-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>

20
layer-element.c Normal file
View File

@ -0,0 +1,20 @@
#include "layer-element.h"
G_DEFINE_TYPE (LayerElement, layer_element, GTK_TYPE_BOX)
static void layer_element_class_init(LayerElementClass *klass)
{
return;
}
static void layer_element_init(LayerElement *self)
{
self->button = gtk_button_new();
gtk_box_pack_start(GTK_BOX(self), self->button, TRUE, TRUE, 0);
gtk_widget_show(self->button);
}
GtkWidget *layer_element_new(void)
{
return GTK_WIDGET(g_object_new(layer_element_get_type(), NULL));
}

26
layer-element.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef __LAYER_ELEMENT_H__
#define __LAYER_ELEMENT_H__
#include <gtk/gtk.h>
// #include <gdk/gdk.h>
#define LAYER_ELEMENT(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, layer_element_get_type(), LayerElement)
#define LAYER_ELEMENT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, layer_element_get_type(), LayerElementClass)
#define IS_LAYE_RELEMENT(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, layer_element_get_type())
typedef struct _LayerElement {
/* Inheritance */
GtkBox hbox;
/* Custom Elements */
GtkWidget *button;
} LayerElement;
typedef struct _LayerElementClass {
GtkBoxClass parent_class;
} LayerElementClass;
GType layer_element_get_type(void);
GtkWidget *layer_element_new(void);
#endif /* __LAYER_ELEMENT_H__ */

32
main.c
View File

@ -20,6 +20,8 @@
#include <stdio.h>
#include "gdsparse.h"
#include <gtk/gtk.h>
#include "layer-element.h"
enum cell_store_columns {
LIBRARY,
@ -29,9 +31,9 @@ enum cell_store_columns {
struct open_button_data {
GtkWindow *main_window;
GList **list_ptr;
GtkTreeStore *cell_store;
GtkWindow *main_window;
GList **list_ptr;
GtkTreeStore *cell_store;
};
@ -58,6 +60,7 @@ void on_load_gds(gpointer button, gpointer user)
GtkTreeStore *store = ptr->cell_store;
GtkWidget *open_dialog;
GtkFileChooser *file_chooser;
GtkWidget *msg_dialog;
GtkFileFilter *filter;
GtkStyleContext *button_style;
gint dialog_result;
@ -80,11 +83,24 @@ void on_load_gds(gpointer button, gpointer user)
/* Get File name */
filename = gtk_file_chooser_get_filename(file_chooser);
/* Clear Display */
gtk_tree_store_clear(store);
/* Delete parsed GDS data */
clear_lib_list(ptr->list_ptr);
if (*ptr->list_ptr) {
/* Libraries present */
msg_dialog =
gtk_message_dialog_new(ptr->main_window, GTK_DIALOG_USE_HEADER_BAR,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
"There's already data present? Delete old data?");
dialog_result = gtk_dialog_run(GTK_DIALOG(msg_dialog));
gtk_widget_destroy(msg_dialog);
} else
dialog_result = GTK_RESPONSE_YES;
/* Clear Display Will be completely refreshed in any case */
gtk_tree_store_clear(store);
if (dialog_result == GTK_RESPONSE_YES) {
/* Delete parsed GDS data */
clear_lib_list(ptr->list_ptr);
}
/* Parse new GDSII file */
gds_result = parse_gds_from_file(filename, ptr->list_ptr);
@ -145,6 +161,7 @@ int main(int argc, char **argv)
GList *gds_libs = NULL;
GtkTreeView *cell_tree;
GtkTreeStore *cell_store;
struct open_button_data open_data;
gtk_init(&argc, &argv);
@ -165,6 +182,7 @@ int main(int argc, char **argv)
"clicked", G_CALLBACK(on_load_gds), (gpointer)&open_data);
gtk_main();
return 0;