Compare commits
8 Commits
587b79dc31
...
5357aff1b8
Author | SHA1 | Date | |
---|---|---|---|
5357aff1b8 | |||
64508104bc | |||
60f54e2240 | |||
19b26a3c26 | |||
28734a797a | |||
31d9d26aa4 | |||
45f0d90a87 | |||
33deba8ca4 |
@ -21,7 +21,7 @@ aux_source_directory("latex-output" LATEX_SOURCES)
|
||||
aux_source_directory("cairo-output" CAIRO_SOURCES)
|
||||
aux_source_directory("trigonometric" TRIG_SOURCES)
|
||||
aux_source_directory("layer" LAYER_SELECTOR_SOURCES)
|
||||
set(SOURCE "main.c" "mapping-parser.c" "command-line.c" "main-window.c" "external-renderer.c")
|
||||
set(SOURCE "main.c" "mapping-parser.c" "command-line.c" "gds-render-gui.c" "external-renderer.c")
|
||||
|
||||
set(SOURCE
|
||||
${SOURCE}
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file main-window.c
|
||||
* @file gds-render-gui.c
|
||||
* @brief Handling of GUI
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
@ -27,12 +27,11 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "main-window.h"
|
||||
#include "gds-render-gui.h"
|
||||
#include <stdio.h>
|
||||
#include "gds-parser/gds-parser.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include "layer/layer-selector.h"
|
||||
#include "layer/layer-selector-dnd.h"
|
||||
#include "tree-renderer/tree-store.h"
|
||||
#include "latex-output/latex-output.h"
|
||||
#include "widgets/conv-settings-dialog.h"
|
||||
@ -41,25 +40,22 @@
|
||||
#include "version/version.h"
|
||||
#include "tree-renderer/lib-cell-renderer.h"
|
||||
#include "gds-parser/gds-tree-checker.h"
|
||||
/**
|
||||
* @brief User data supplied to callback function of the open button
|
||||
*/
|
||||
struct open_button_data {
|
||||
|
||||
struct _GdsRenderGui {
|
||||
/* Parent GObject */
|
||||
GObject parent;
|
||||
|
||||
/* Custom fields */
|
||||
GtkWindow *main_window;
|
||||
GList **list_ptr;
|
||||
GtkTreeStore *cell_store;
|
||||
GtkSearchEntry *search_entry;
|
||||
GtkWidget *convert_button;
|
||||
GtkTreeStore *cell_tree_store;
|
||||
GtkWidget *cell_search_entry;
|
||||
LayerSelector *layer_selector;
|
||||
GtkTreeView *cell_tree_view;
|
||||
GList *gds_libraries;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief User data supplied to callback function of the convert button
|
||||
*/
|
||||
struct convert_button_data {
|
||||
GtkTreeView *tree_view;
|
||||
GtkWindow *main_window;
|
||||
LayerSelector *layer_selector;
|
||||
};
|
||||
G_DEFINE_TYPE(GdsRenderGui, gds_render_gui, G_TYPE_OBJECT)
|
||||
|
||||
/**
|
||||
* @brief Window close event of main window
|
||||
@ -71,11 +67,17 @@ struct convert_button_data {
|
||||
*/
|
||||
static gboolean on_window_close(gpointer window, GdkEvent *event, gpointer user)
|
||||
{
|
||||
/* Destroy all objects helb by this module, that are not part of the GUI itself */
|
||||
g_object_unref(LAYER_SELECTOR(user));
|
||||
GdsRenderGui *self;
|
||||
|
||||
/* Close Window. Leads to termination of the program */
|
||||
self = RENDERER_GUI(user);
|
||||
/* Don't close window in case of error */
|
||||
if (!self)
|
||||
return TRUE;
|
||||
|
||||
/* Close Window. Leads to termination of the program/the current instance */
|
||||
g_clear_object(&self->main_window);
|
||||
gtk_widget_destroy(GTK_WIDGET(window));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -111,8 +113,7 @@ static void on_load_gds(gpointer button, gpointer user)
|
||||
GList *lib;
|
||||
struct gds_library *gds_lib;
|
||||
struct gds_cell *gds_c;
|
||||
struct open_button_data *ptr = (struct open_button_data *)user;
|
||||
GtkTreeStore *store = ptr->cell_store;
|
||||
GdsRenderGui *self;
|
||||
GtkWidget *open_dialog;
|
||||
GtkFileChooser *file_chooser;
|
||||
GtkFileFilter *filter;
|
||||
@ -124,7 +125,11 @@ static void on_load_gds(gpointer button, gpointer user)
|
||||
GString *acc_date;
|
||||
unsigned int cell_error_level;
|
||||
|
||||
open_dialog = gtk_file_chooser_dialog_new("Open GDSII File", ptr->main_window,
|
||||
self = RENDERER_GUI(user);
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
open_dialog = gtk_file_chooser_dialog_new("Open GDSII File", self->main_window,
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
"Cancel", GTK_RESPONSE_CANCEL,
|
||||
"Open GDSII", GTK_RESPONSE_ACCEPT,
|
||||
@ -143,11 +148,11 @@ static void on_load_gds(gpointer button, gpointer user)
|
||||
/* Get File name */
|
||||
filename = gtk_file_chooser_get_filename(file_chooser);
|
||||
|
||||
gtk_tree_store_clear(store);
|
||||
clear_lib_list(ptr->list_ptr);
|
||||
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, ptr->list_ptr);
|
||||
gds_result = parse_gds_from_file(filename, &self->gds_libraries);
|
||||
|
||||
/* Delete file name afterwards */
|
||||
g_free(filename);
|
||||
@ -158,16 +163,16 @@ static void on_load_gds(gpointer button, gpointer user)
|
||||
button_style = gtk_widget_get_style_context(GTK_WIDGET(button));
|
||||
gtk_style_context_remove_class(button_style, "suggested-action");
|
||||
|
||||
for (lib = *(ptr->list_ptr); lib != NULL; lib = lib->next) {
|
||||
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(store, &libiter, NULL);
|
||||
gtk_tree_store_append(self->cell_tree_store, &libiter, NULL);
|
||||
|
||||
/* Convert dates to String */
|
||||
mod_date = generate_string_from_date(&gds_lib->mod_time);
|
||||
acc_date = generate_string_from_date(&gds_lib->access_time);
|
||||
|
||||
gtk_tree_store_set(store, &libiter,
|
||||
gtk_tree_store_set(self->cell_tree_store, &libiter,
|
||||
CELL_SEL_LIBRARY, gds_lib,
|
||||
CELL_SEL_MODDATE, mod_date->str,
|
||||
CELL_SEL_ACCESSDATE, acc_date->str,
|
||||
@ -184,7 +189,7 @@ static void on_load_gds(gpointer button, gpointer user)
|
||||
|
||||
for (cell = gds_lib->cells; cell != NULL; cell = cell->next) {
|
||||
gds_c = (struct gds_cell *)cell->data;
|
||||
gtk_tree_store_append(store, &celliter, &libiter);
|
||||
gtk_tree_store_append(self->cell_tree_store, &celliter, &libiter);
|
||||
|
||||
/* Convert dates to String */
|
||||
mod_date = generate_string_from_date(&gds_c->mod_time);
|
||||
@ -200,7 +205,7 @@ static void on_load_gds(gpointer button, gpointer user)
|
||||
cell_error_level |= LIB_CELL_RENDERER_ERROR_ERR;
|
||||
|
||||
/* Add cell to tree store model */
|
||||
gtk_tree_store_set(store, &celliter,
|
||||
gtk_tree_store_set(self->cell_tree_store, &celliter,
|
||||
CELL_SEL_CELL, gds_c,
|
||||
CELL_SEL_MODDATE, mod_date->str,
|
||||
CELL_SEL_ACCESSDATE, acc_date->str,
|
||||
@ -215,7 +220,7 @@ static void on_load_gds(gpointer button, gpointer user)
|
||||
}
|
||||
|
||||
/* Create Layers in Layer Box */
|
||||
layer_selector_generate_layer_widgets(ptr->layer_selector, *(ptr->list_ptr));
|
||||
layer_selector_generate_layer_widgets(self->layer_selector, self->gds_libraries);
|
||||
}
|
||||
|
||||
end_destroy:
|
||||
@ -235,7 +240,7 @@ static void on_convert_clicked(gpointer button, gpointer user)
|
||||
.scale = 1000.0,
|
||||
.renderer = RENDERER_LATEX_TIKZ,
|
||||
};
|
||||
struct convert_button_data *data = (struct convert_button_data *)user;
|
||||
GdsRenderGui *self;
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
@ -250,11 +255,13 @@ static void on_convert_clicked(gpointer button, gpointer user)
|
||||
union bounding_box cell_box;
|
||||
unsigned int height, width;
|
||||
|
||||
if (!data)
|
||||
self = RENDERER_GUI(user);
|
||||
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
/* Get selected cell */
|
||||
selection = gtk_tree_view_get_selection(data->tree_view);
|
||||
selection = gtk_tree_view_get_selection(self->cell_tree_view);
|
||||
if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE)
|
||||
return;
|
||||
|
||||
@ -264,7 +271,7 @@ static void on_convert_clicked(gpointer button, gpointer user)
|
||||
return;
|
||||
|
||||
/* Get layers that are rendered */
|
||||
layer_list = layer_selector_export_rendered_layer_info(data->layer_selector);
|
||||
layer_list = layer_selector_export_rendered_layer_info(self->layer_selector);
|
||||
|
||||
/* Calculate cell size in DB units */
|
||||
bounding_box_prepare_empty(&cell_box);
|
||||
@ -278,7 +285,7 @@ static void on_convert_clicked(gpointer button, gpointer user)
|
||||
width = (unsigned int)(cell_box.vectors.upper_right.x - cell_box.vectors.lower_left.x);
|
||||
|
||||
/* Show settings dialog */
|
||||
settings = renderer_settings_dialog_new(GTK_WINDOW(data->main_window));
|
||||
settings = renderer_settings_dialog_new(GTK_WINDOW(self->main_window));
|
||||
renderer_settings_dialog_set_settings(settings, &sett);
|
||||
renderer_settings_dialog_set_database_unit_scale(settings, cell_to_render->parent_library->unit_in_meters);
|
||||
renderer_settings_dialog_set_cell_height(settings, height);
|
||||
@ -296,7 +303,7 @@ static void on_convert_clicked(gpointer button, gpointer user)
|
||||
/* save file dialog */
|
||||
dialog = gtk_file_chooser_dialog_new((sett.renderer == RENDERER_LATEX_TIKZ
|
||||
? "Save LaTeX File" : "Save PDF"),
|
||||
GTK_WINDOW(data->main_window), GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_WINDOW(self->main_window), GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
"Cancel", GTK_RESPONSE_CANCEL, "Save", GTK_RESPONSE_ACCEPT, NULL);
|
||||
/* Set file filter according to settings */
|
||||
filter = gtk_file_filter_new();
|
||||
@ -374,55 +381,83 @@ static void cell_tree_view_activated(gpointer tree_view, GtkTreePath *path,
|
||||
* This function activates/deactivates the convert button depending on whether
|
||||
* a cell is selected for conversion or not
|
||||
* @param sel
|
||||
* @param convert_button
|
||||
* @param self
|
||||
*/
|
||||
static void cell_selection_changed(GtkTreeSelection *sel, GtkWidget *convert_button)
|
||||
static void cell_selection_changed(GtkTreeSelection *sel, GdsRenderGui *self)
|
||||
{
|
||||
GtkTreeModel *model = NULL;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (gtk_tree_selection_get_selected(sel, &model, &iter)) {
|
||||
/* Node selected. Show button */
|
||||
gtk_widget_set_sensitive(convert_button, TRUE);
|
||||
gtk_widget_set_sensitive(self->convert_button, TRUE);
|
||||
} else {
|
||||
gtk_widget_set_sensitive(convert_button, FALSE);
|
||||
gtk_widget_set_sensitive(self->convert_button, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static void sort_up_callback(GtkWidget *widget, gpointer user)
|
||||
{
|
||||
(void)widget;
|
||||
LayerSelector *sel;
|
||||
GdsRenderGui *self;
|
||||
|
||||
sel = LAYER_SELECTOR(user);
|
||||
if (!sel)
|
||||
self = RENDERER_GUI(user);
|
||||
if (!self)
|
||||
return;
|
||||
layer_selector_force_sort(sel, LAYER_SELECTOR_SORT_UP);
|
||||
layer_selector_force_sort(self->layer_selector, LAYER_SELECTOR_SORT_UP);
|
||||
}
|
||||
|
||||
static void sort_down_callback(GtkWidget *widget, gpointer user)
|
||||
{
|
||||
(void)widget;
|
||||
LayerSelector *sel;
|
||||
GdsRenderGui *self;
|
||||
|
||||
sel = LAYER_SELECTOR(user);
|
||||
if (!sel)
|
||||
self = RENDERER_GUI(user);
|
||||
if (!self)
|
||||
return;
|
||||
layer_selector_force_sort(sel, LAYER_SELECTOR_SORT_DOWN);
|
||||
layer_selector_force_sort(self->layer_selector, LAYER_SELECTOR_SORT_DOWN);
|
||||
}
|
||||
|
||||
GtkWindow *create_main_window()
|
||||
static void gds_render_gui_dispose(GObject *gobject)
|
||||
{
|
||||
GdsRenderGui *self;
|
||||
|
||||
self = RENDERER_GUI(gobject);
|
||||
|
||||
g_clear_object(&self->cell_tree_view);
|
||||
g_clear_object(&self->convert_button);
|
||||
g_clear_object(&self->layer_selector);
|
||||
g_clear_object(&self->cell_tree_store);
|
||||
g_clear_object(&self->cell_search_entry);
|
||||
|
||||
|
||||
if (self->main_window) {
|
||||
g_signal_handlers_destroy(self->main_window);
|
||||
gtk_widget_destroy(GTK_WIDGET(self->main_window));
|
||||
self->main_window = NULL;
|
||||
}
|
||||
|
||||
/* Chain up */
|
||||
G_OBJECT_CLASS(gds_render_gui_parent_class)->dispose(gobject);
|
||||
}
|
||||
|
||||
static void gds_render_gui_class_init(GdsRenderGuiClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
gobject_class->dispose = gds_render_gui_dispose;
|
||||
}
|
||||
|
||||
GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui)
|
||||
{
|
||||
return gui->main_window;
|
||||
}
|
||||
|
||||
static void gds_render_gui_init(GdsRenderGui *self)
|
||||
{
|
||||
GtkBuilder *main_builder;
|
||||
GtkTreeView *cell_tree;
|
||||
GtkWidget *listbox;
|
||||
GtkWidget *conv_button;
|
||||
GtkWidget *search_entry;
|
||||
GtkHeaderBar *header_bar;
|
||||
LayerSelector *layer_selector;
|
||||
static GList *gds_libs;
|
||||
static struct open_button_data open_data;
|
||||
static struct convert_button_data conv_data;
|
||||
struct tree_stores *cell_selector_stores;
|
||||
GtkWidget *sort_up_button;
|
||||
GtkWidget *sort_down_button;
|
||||
@ -430,34 +465,29 @@ GtkWindow *create_main_window()
|
||||
main_builder = gtk_builder_new_from_resource("/main.glade");
|
||||
gtk_builder_connect_signals(main_builder, NULL);
|
||||
|
||||
cell_tree = GTK_TREE_VIEW(gtk_builder_get_object(main_builder, "cell-tree"));
|
||||
search_entry = GTK_WIDGET(gtk_builder_get_object(main_builder, "cell-search"));
|
||||
open_data.search_entry = GTK_SEARCH_ENTRY(search_entry);
|
||||
cell_selector_stores = setup_cell_selector(cell_tree, GTK_ENTRY(search_entry));
|
||||
self->cell_tree_view = GTK_TREE_VIEW(gtk_builder_get_object(main_builder, "cell-tree"));
|
||||
self->cell_search_entry = GTK_WIDGET(gtk_builder_get_object(main_builder, "cell-search"));
|
||||
|
||||
open_data.cell_store = cell_selector_stores->base_store;
|
||||
open_data.list_ptr = &gds_libs;
|
||||
open_data.main_window = GTK_WINDOW(gtk_builder_get_object(main_builder, "main-window"));
|
||||
cell_selector_stores = setup_cell_selector(self->cell_tree_view, GTK_ENTRY(self->cell_search_entry));
|
||||
|
||||
self->cell_tree_store = cell_selector_stores->base_store;
|
||||
|
||||
self->main_window = GTK_WINDOW(gtk_builder_get_object(main_builder, "main-window"));
|
||||
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-gds")),
|
||||
"clicked", G_CALLBACK(on_load_gds), (gpointer)&open_data);
|
||||
"clicked", G_CALLBACK(on_load_gds), (gpointer)self);
|
||||
|
||||
/* Connect Convert button */
|
||||
conv_data.tree_view = cell_tree;
|
||||
conv_data.main_window = open_data.main_window;
|
||||
|
||||
conv_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "convert-button"));
|
||||
g_signal_connect(conv_button, "clicked", G_CALLBACK(on_convert_clicked), &conv_data);
|
||||
self->convert_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "convert-button"));
|
||||
g_signal_connect(self->convert_button, "clicked", G_CALLBACK(on_convert_clicked), (gpointer)self);
|
||||
|
||||
listbox = GTK_WIDGET(gtk_builder_get_object(main_builder, "layer-list"));
|
||||
/* Create layer selector */
|
||||
layer_selector = layer_selector_new(GTK_LIST_BOX(listbox));
|
||||
conv_data.layer_selector = layer_selector;
|
||||
open_data.layer_selector = layer_selector;
|
||||
self->layer_selector = layer_selector_new(GTK_LIST_BOX(listbox));
|
||||
|
||||
|
||||
/* Callback for selection change of cell selector */
|
||||
g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(cell_tree)), "changed",
|
||||
G_CALLBACK(cell_selection_changed), conv_button);
|
||||
g_signal_connect(cell_tree, "row-activated", G_CALLBACK(cell_tree_view_activated), &conv_data);
|
||||
g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(self->cell_tree_view)), "changed",
|
||||
G_CALLBACK(cell_selection_changed), self);
|
||||
g_signal_connect(self->cell_tree_view, "row-activated", G_CALLBACK(cell_tree_view_activated), self);
|
||||
|
||||
/* Set version in main window subtitle */
|
||||
header_bar = GTK_HEADER_BAR(gtk_builder_get_object(main_builder, "header-bar"));
|
||||
@ -467,25 +497,34 @@ GtkWindow *create_main_window()
|
||||
sort_up_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-up-sort"));
|
||||
sort_down_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-down-sort"));
|
||||
|
||||
g_signal_connect(sort_up_button, "clicked", G_CALLBACK(sort_up_callback), layer_selector);
|
||||
g_signal_connect(sort_down_button, "clicked", G_CALLBACK(sort_down_callback), layer_selector);
|
||||
|
||||
g_signal_connect(sort_up_button, "clicked", G_CALLBACK(sort_up_callback), self);
|
||||
g_signal_connect(sort_down_button, "clicked", G_CALLBACK(sort_down_callback), self);
|
||||
|
||||
/* Set buttons for loading and saving */
|
||||
layer_selector_set_load_mapping_button(layer_selector,
|
||||
layer_selector_set_load_mapping_button(self->layer_selector,
|
||||
GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-mapping")),
|
||||
conv_data.main_window);
|
||||
layer_selector_set_save_mapping_button(layer_selector, GTK_WIDGET(gtk_builder_get_object(main_builder, "button-save-mapping")),
|
||||
conv_data.main_window);
|
||||
|
||||
self->main_window);
|
||||
layer_selector_set_save_mapping_button(self->layer_selector, GTK_WIDGET(gtk_builder_get_object(main_builder, "button-save-mapping")),
|
||||
self->main_window);
|
||||
|
||||
/* Connect delete-event */
|
||||
g_signal_connect(GTK_WIDGET(open_data.main_window), "delete-event",
|
||||
G_CALLBACK(on_window_close), layer_selector);
|
||||
g_signal_connect(GTK_WIDGET(self->main_window), "delete-event",
|
||||
G_CALLBACK(on_window_close), self);
|
||||
|
||||
g_object_unref(main_builder);
|
||||
|
||||
return conv_data.main_window;
|
||||
/* Reference all objects referenced by this object */
|
||||
g_object_ref(self->main_window);
|
||||
g_object_ref(self->cell_tree_view);
|
||||
g_object_ref(self->convert_button);
|
||||
g_object_ref(self->layer_selector);
|
||||
g_object_ref(self->cell_tree_store);
|
||||
g_object_ref(self->cell_search_entry);
|
||||
}
|
||||
|
||||
GdsRenderGui *gds_render_gui_new()
|
||||
{
|
||||
return RENDERER_GUI(g_object_new(RENDERER_TYPE_GUI, NULL));
|
||||
}
|
||||
|
||||
/** @} */
|
@ -18,13 +18,13 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file main-window.h
|
||||
* @brief Header for main-window
|
||||
* @file gds-render-gui.h
|
||||
* @brief Header for GdsRenderGui Object
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
#ifndef _MAIN_WINDOW_H_
|
||||
#define _MAIN_WINDOW_H_
|
||||
#ifndef _GDS_RENDER_GUI_
|
||||
#define _GDS_RENDER_GUI_
|
||||
|
||||
/**
|
||||
* @addtogroup MainApplication
|
||||
@ -33,14 +33,29 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE(GdsRenderGui, gds_render_gui, RENDERER, GUI, GObject);
|
||||
|
||||
#define RENDERER_TYPE_GUI (gds_render_gui_get_type())
|
||||
|
||||
/**
|
||||
* @brief Create main window
|
||||
*
|
||||
* This function creates the main window and sets the necessary callback routines.
|
||||
* @brief Create new GdsRenderGui Object
|
||||
* @return
|
||||
*/
|
||||
GtkWindow *create_main_window();
|
||||
GdsRenderGui *gds_render_gui_new();
|
||||
|
||||
/**
|
||||
* @brief Get main window
|
||||
*
|
||||
* This function returns the main window of the GUI, which can later be displayed.
|
||||
* All handling of hte GUI is taken care of inside the GdsRenderGui Object
|
||||
* @return
|
||||
*/
|
||||
GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* _MAIN_WINDOW_H_ */
|
||||
#endif /* _GDS_RENDER_GUI_ */
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* GDSII-Converter
|
||||
* Copyright (C) 2019 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 layer-selector-dnd.h
|
||||
* @brief Header for drag and drop of layer selector
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
#ifndef _LAYER_SELECTOR_DND_H_
|
||||
#define _LAYER_SELECTOR_DND_H_
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#endif /* _LAYER_SELECTOR_DND_H_ */
|
@ -29,7 +29,6 @@
|
||||
*/
|
||||
|
||||
#include "layer-selector.h"
|
||||
#include "layer-selector-dnd.h"
|
||||
#include "layer-info.h"
|
||||
#include "../gds-parser/gds-parser.h"
|
||||
#include "../widgets/layer-element.h"
|
||||
@ -49,6 +48,8 @@ struct _LayerSelector {
|
||||
GtkWindow *save_parent_window;
|
||||
GtkListBox *list_box;
|
||||
|
||||
GtkTargetEntry dnd_target;
|
||||
|
||||
gpointer dummy[4];
|
||||
};
|
||||
|
||||
@ -56,9 +57,62 @@ G_DEFINE_TYPE(LayerSelector, layer_selector, G_TYPE_OBJECT)
|
||||
|
||||
|
||||
/* Drag and drop code */
|
||||
static GtkTargetEntry entries[] = {
|
||||
{ "GTK_LIST_BOX_ROW", GTK_TARGET_SAME_APP, 0 }
|
||||
};
|
||||
|
||||
static void sel_layer_element_drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
|
||||
{
|
||||
GtkWidget *row;
|
||||
GtkAllocation alloc;
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
int x, y;
|
||||
(void)data;
|
||||
|
||||
row = gtk_widget_get_ancestor(widget, GTK_TYPE_LIST_BOX_ROW);
|
||||
gtk_widget_get_allocation(row, &alloc);
|
||||
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, alloc.width, alloc.height);
|
||||
cr = cairo_create(surface);
|
||||
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context(row), "drag-icon");
|
||||
gtk_widget_draw (row, cr);
|
||||
gtk_style_context_remove_class(gtk_widget_get_style_context(row), "drag-icon");
|
||||
|
||||
gtk_widget_translate_coordinates (widget, row, 0, 0, &x, &y);
|
||||
cairo_surface_set_device_offset (surface, -x, -y);
|
||||
gtk_drag_set_icon_surface (context, surface);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
g_object_set_data(G_OBJECT(gtk_widget_get_parent(row)), "drag-row", row);
|
||||
gtk_style_context_add_class(gtk_widget_get_style_context(row), "drag-row");
|
||||
}
|
||||
|
||||
static void sel_layer_element_drag_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
|
||||
{
|
||||
GtkWidget *row;
|
||||
(void)context;
|
||||
(void)data;
|
||||
|
||||
row = gtk_widget_get_ancestor(widget, GTK_TYPE_LIST_BOX_ROW);
|
||||
g_object_set_data(G_OBJECT(gtk_widget_get_parent(row)), "drag-row", NULL);
|
||||
gtk_style_context_remove_class(gtk_widget_get_style_context(row), "drag-row");
|
||||
gtk_style_context_remove_class(gtk_widget_get_style_context(row), "drag-hover");
|
||||
}
|
||||
|
||||
static void sel_layer_element_drag_data_get(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data,
|
||||
guint info, guint time, gpointer data)
|
||||
{
|
||||
(void)context;
|
||||
(void)info;
|
||||
(void)time;
|
||||
(void)data;
|
||||
GdkAtom atom;
|
||||
|
||||
atom = gdk_atom_intern_static_string("GTK_LIST_BOX_ROW");
|
||||
|
||||
gtk_selection_data_set(selection_data, atom,
|
||||
32, (const guchar *)&widget, sizeof(gpointer));
|
||||
}
|
||||
|
||||
static GtkListBoxRow *layer_selector_get_last_row (GtkListBox *list)
|
||||
{
|
||||
@ -250,6 +304,11 @@ static void layer_selector_dispose(GObject *self)
|
||||
g_clear_object(&sel->associated_load_button);
|
||||
g_clear_object(&sel->associated_save_button);
|
||||
|
||||
if (sel->dnd_target.target) {
|
||||
g_free(sel->dnd_target.target);
|
||||
sel->dnd_target.target = NULL;
|
||||
}
|
||||
|
||||
/* Chain up to parent's dispose function */
|
||||
G_OBJECT_CLASS(layer_selector_parent_class)->dispose(self);
|
||||
}
|
||||
@ -270,23 +329,26 @@ static void layer_selector_class_init(LayerSelectorClass *klass)
|
||||
g_object_unref(provider);
|
||||
}
|
||||
|
||||
static void layer_selector_setup_dnd(GtkListBox *box)
|
||||
static void layer_selector_setup_dnd(LayerSelector *self)
|
||||
{
|
||||
gtk_drag_dest_set(GTK_WIDGET(box), GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, entries, 1, GDK_ACTION_MOVE);
|
||||
g_signal_connect(box, "drag-data-received", G_CALLBACK(layer_selector_drag_data_received), NULL);
|
||||
g_signal_connect(box, "drag-motion", G_CALLBACK(layer_selector_drag_motion), NULL);
|
||||
g_signal_connect(box, "drag-leave", G_CALLBACK(layer_selector_drag_leave), NULL);
|
||||
gtk_drag_dest_set(GTK_WIDGET(self->list_box), GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, &self->dnd_target, 1, GDK_ACTION_MOVE);
|
||||
g_signal_connect(self->list_box, "drag-data-received", G_CALLBACK(layer_selector_drag_data_received), NULL);
|
||||
g_signal_connect(self->list_box, "drag-motion", G_CALLBACK(layer_selector_drag_motion), NULL);
|
||||
g_signal_connect(self->list_box, "drag-leave", G_CALLBACK(layer_selector_drag_leave), NULL);
|
||||
}
|
||||
|
||||
/* Drag and drop end */
|
||||
|
||||
static void layer_selector_init(LayerSelector *self)
|
||||
{
|
||||
/* Setup drag and drop for associated list box */
|
||||
self->load_parent_window = NULL;
|
||||
self->save_parent_window = NULL;
|
||||
self->associated_load_button = NULL;
|
||||
self->associated_save_button = NULL;
|
||||
|
||||
self->dnd_target.target = g_strdup_printf("LAYER_SELECTOR_DND_%p", self);
|
||||
self->dnd_target.info = 0;
|
||||
self->dnd_target.flags = GTK_TARGET_SAME_APP;
|
||||
}
|
||||
|
||||
LayerSelector *layer_selector_new(GtkListBox *list_box)
|
||||
@ -298,7 +360,7 @@ LayerSelector *layer_selector_new(GtkListBox *list_box)
|
||||
|
||||
selector = LAYER_SELECTOR(g_object_new(TYPE_LAYER_SELECTOR, NULL));
|
||||
selector->list_box = list_box;
|
||||
layer_selector_setup_dnd(list_box);
|
||||
layer_selector_setup_dnd(selector);
|
||||
g_object_ref(G_OBJECT(list_box));
|
||||
|
||||
return selector;
|
||||
@ -385,6 +447,14 @@ static gboolean layer_selector_check_if_layer_widget_exists(LayerSelector *self,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void sel_layer_element_setup_dnd_callbacks(LayerSelector *self, LayerElement *element)
|
||||
{
|
||||
layer_element_set_dnd_callbacks(element, &self->dnd_target, 1,
|
||||
sel_layer_element_drag_begin,
|
||||
sel_layer_element_drag_data_get,
|
||||
sel_layer_element_drag_end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Analyze \p cell and append used layers to list box
|
||||
* @param listbox listbox to add layer
|
||||
@ -402,6 +472,7 @@ static void layer_selector_analyze_cell_layers(LayerSelector *self, struct gds_c
|
||||
layer = (int)gfx->layer;
|
||||
if (layer_selector_check_if_layer_widget_exists(self, layer) == FALSE) {
|
||||
le = layer_element_new();
|
||||
sel_layer_element_setup_dnd_callbacks(self, LAYER_ELEMENT(le));
|
||||
layer_element_set_layer(LAYER_ELEMENT(le), layer);
|
||||
gtk_list_box_insert(self->list_box, le, -1);
|
||||
gtk_widget_show(le);
|
||||
@ -678,7 +749,7 @@ void layer_selector_force_sort(LayerSelector *selector, enum layer_selector_sort
|
||||
if (!box)
|
||||
return;
|
||||
|
||||
/* Set dorting function, sort, and disable sorting function */
|
||||
/* Set sorting function, sort, and disable sorting function */
|
||||
gtk_list_box_set_sort_func(box, layer_selector_sort_func, (gpointer)&sort_function, NULL);
|
||||
gtk_list_box_invalidate_sort(box);
|
||||
gtk_list_box_set_sort_func(box, NULL, NULL, NULL);
|
||||
|
48
main.c
48
main.c
@ -20,23 +20,32 @@
|
||||
#include <stdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib.h>
|
||||
#include "main-window.h"
|
||||
#include "gds-render-gui.h"
|
||||
#include "command-line.h"
|
||||
#include "external-renderer.h"
|
||||
#include "version/version.h"
|
||||
|
||||
struct application_data {
|
||||
GtkApplication *app;
|
||||
GtkWindow *main_window;
|
||||
GList *gui_list;
|
||||
};
|
||||
|
||||
static void app_quit(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
||||
{
|
||||
const struct application_data * const appdata = (const struct application_data *)user_data;
|
||||
struct application_data * const appdata = (struct application_data *)user_data;
|
||||
(void)action;
|
||||
(void)parameter;
|
||||
GList *list_iter;
|
||||
GdsRenderGui *gui;
|
||||
|
||||
gtk_widget_destroy(GTK_WIDGET(appdata->main_window));
|
||||
/* Dispose all GUIs */
|
||||
for (list_iter = appdata->gui_list; list_iter != NULL; list_iter = g_list_next(list_iter)) {
|
||||
gui = RENDERER_GUI(list_iter->data);
|
||||
g_object_unref(gui);
|
||||
}
|
||||
|
||||
g_list_free(appdata->gui_list);
|
||||
appdata->gui_list = NULL;
|
||||
}
|
||||
|
||||
static void app_about(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
||||
@ -49,7 +58,7 @@ static void app_about(GSimpleAction *action, GVariant *parameter, gpointer user_
|
||||
|
||||
builder = gtk_builder_new_from_resource("/about.glade");
|
||||
dialog = GTK_DIALOG(gtk_builder_get_object(builder, "about-dialog"));
|
||||
gtk_window_set_transient_for(GTK_WINDOW(dialog), appdata->main_window);
|
||||
gtk_window_set_transient_for(GTK_WINDOW(dialog), NULL);
|
||||
gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), _app_version_string);
|
||||
gtk_dialog_run(dialog);
|
||||
|
||||
@ -65,10 +74,15 @@ const static GActionEntry app_actions[] = {
|
||||
static void gapp_activate(GApplication *app, gpointer user_data)
|
||||
{
|
||||
GtkWindow *main_window;
|
||||
GdsRenderGui *gui;
|
||||
|
||||
struct application_data * const appdata = (struct application_data *)user_data;
|
||||
|
||||
main_window = create_main_window();
|
||||
appdata->main_window = main_window;
|
||||
gui = gds_render_gui_new();
|
||||
appdata->gui_list = g_list_append(appdata->gui_list, gui);
|
||||
|
||||
main_window = gds_render_gui_get_main_window(gui);
|
||||
|
||||
gtk_application_add_window(GTK_APPLICATION(app), main_window);
|
||||
gtk_widget_show(GTK_WIDGET(main_window));
|
||||
}
|
||||
@ -78,15 +92,23 @@ static int start_gui(int argc, char **argv)
|
||||
|
||||
GtkApplication *gapp;
|
||||
int app_status;
|
||||
static struct application_data appdata;
|
||||
static struct application_data appdata = {.gui_list = NULL};
|
||||
GMenu *menu;
|
||||
GMenu *m_quit;
|
||||
GMenu *m_about;
|
||||
GList *list_iter;
|
||||
GdsRenderGui *gui;
|
||||
|
||||
gapp = gtk_application_new("de.shimatta.gds-render", G_APPLICATION_NON_UNIQUE);
|
||||
gapp = gtk_application_new("de.shimatta.gds-render", G_APPLICATION_FLAGS_NONE);
|
||||
g_application_register(G_APPLICATION(gapp), NULL, NULL);
|
||||
g_signal_connect(gapp, "activate", G_CALLBACK(gapp_activate), &appdata);
|
||||
|
||||
if (g_application_get_is_remote(G_APPLICATION(gapp)) == TRUE) {
|
||||
g_application_activate(G_APPLICATION(gapp));
|
||||
printf("There is already an open instance. Will open second window in said instance.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
menu = g_menu_new();
|
||||
m_quit = g_menu_new();
|
||||
m_about = g_menu_new();
|
||||
@ -105,6 +127,14 @@ static int start_gui(int argc, char **argv)
|
||||
app_status = g_application_run(G_APPLICATION(gapp), argc, argv);
|
||||
g_object_unref(gapp);
|
||||
|
||||
/* Destroy gui_list */
|
||||
for (list_iter = appdata.gui_list; list_iter != NULL; list_iter = g_list_next(list_iter)) {
|
||||
gui = RENDERER_GUI(list_iter->data);
|
||||
g_object_unref(gui);
|
||||
}
|
||||
|
||||
g_list_free(appdata.gui_list);
|
||||
|
||||
return app_status;
|
||||
}
|
||||
|
||||
|
@ -57,65 +57,6 @@ static void layer_element_class_init(LayerElementClass *klass)
|
||||
oclass->constructed = layer_element_constructed;
|
||||
}
|
||||
|
||||
static GtkTargetEntry entries[] = {
|
||||
{ "GTK_LIST_BOX_ROW", GTK_TARGET_SAME_APP, 0 }
|
||||
};
|
||||
|
||||
static void layer_element_drag_begin(GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
gpointer data)
|
||||
{
|
||||
GtkWidget *row;
|
||||
GtkAllocation alloc;
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
int x, y;
|
||||
(void)data;
|
||||
|
||||
row = gtk_widget_get_ancestor(widget, GTK_TYPE_LIST_BOX_ROW);
|
||||
gtk_widget_get_allocation(row, &alloc);
|
||||
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, alloc.width, alloc.height);
|
||||
cr = cairo_create(surface);
|
||||
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context(row), "drag-icon");
|
||||
gtk_widget_draw (row, cr);
|
||||
gtk_style_context_remove_class(gtk_widget_get_style_context(row), "drag-icon");
|
||||
|
||||
gtk_widget_translate_coordinates (widget, row, 0, 0, &x, &y);
|
||||
cairo_surface_set_device_offset (surface, -x, -y);
|
||||
gtk_drag_set_icon_surface (context, surface);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
g_object_set_data(G_OBJECT(gtk_widget_get_parent(row)), "drag-row", row);
|
||||
gtk_style_context_add_class(gtk_widget_get_style_context(row), "drag-row");
|
||||
}
|
||||
|
||||
static void layer_element_drag_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
|
||||
{
|
||||
GtkWidget *row;
|
||||
(void)context;
|
||||
(void)data;
|
||||
|
||||
row = gtk_widget_get_ancestor(widget, GTK_TYPE_LIST_BOX_ROW);
|
||||
g_object_set_data(G_OBJECT(gtk_widget_get_parent(row)), "drag-row", NULL);
|
||||
gtk_style_context_remove_class(gtk_widget_get_style_context(row), "drag-row");
|
||||
gtk_style_context_remove_class(gtk_widget_get_style_context(row), "drag-hover");
|
||||
}
|
||||
|
||||
static void layer_element_drag_data_get(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data,
|
||||
guint info, guint time, gpointer data)
|
||||
{
|
||||
(void)context;
|
||||
(void)info;
|
||||
(void)time;
|
||||
(void)data;
|
||||
|
||||
gtk_selection_data_set(selection_data, gdk_atom_intern_static_string("GTK_LIST_BOX_ROW"),
|
||||
32, (const guchar *)&widget, sizeof(gpointer));
|
||||
}
|
||||
|
||||
static void layer_element_init(LayerElement *self)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
@ -131,13 +72,6 @@ static void layer_element_init(LayerElement *self)
|
||||
self->priv.name = GTK_ENTRY(gtk_builder_get_object(builder, "entry"));
|
||||
self->priv.event_handle = GTK_EVENT_BOX(gtk_builder_get_object(builder, "event-box"));
|
||||
|
||||
/* Setup drag and drop */
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context(GTK_WIDGET(self)), "row");
|
||||
gtk_drag_source_set(GTK_WIDGET(self->priv.event_handle), GDK_BUTTON1_MASK, entries, 1, GDK_ACTION_MOVE);
|
||||
g_signal_connect(self->priv.event_handle, "drag-begin", G_CALLBACK(layer_element_drag_begin), NULL);
|
||||
g_signal_connect(self->priv.event_handle, "drag-data-get", G_CALLBACK(layer_element_drag_data_get), NULL);
|
||||
g_signal_connect(self->priv.event_handle, "drag-end", G_CALLBACK(layer_element_drag_end), NULL);
|
||||
|
||||
g_object_unref(builder);
|
||||
}
|
||||
|
||||
@ -194,4 +128,19 @@ void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba)
|
||||
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(elem->priv.color), rgba);
|
||||
}
|
||||
|
||||
void layer_element_set_dnd_callbacks(LayerElement *elem, GtkTargetEntry *entries, int entry_count,
|
||||
void (*drag_begin)(GtkWidget *, GdkDragContext *, gpointer),
|
||||
void (*drag_data_get)(GtkWidget *, GdkDragContext *,
|
||||
GtkSelectionData *, guint , guint, gpointer),
|
||||
void (*drag_end)(GtkWidget *, GdkDragContext *, gpointer))
|
||||
{
|
||||
/* Setup drag and drop */
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context(GTK_WIDGET(elem)), "row");
|
||||
gtk_drag_source_set(GTK_WIDGET(elem->priv.event_handle), GDK_BUTTON1_MASK, entries, entry_count, GDK_ACTION_MOVE);
|
||||
g_signal_connect(elem->priv.event_handle, "drag-begin", G_CALLBACK(drag_begin), NULL);
|
||||
g_signal_connect(elem->priv.event_handle, "drag-data-get", G_CALLBACK(drag_data_get), NULL);
|
||||
g_signal_connect(elem->priv.event_handle, "drag-end", G_CALLBACK(drag_end), NULL);
|
||||
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -118,6 +118,18 @@ void layer_element_get_color(LayerElement *elem, GdkRGBA *rgba);
|
||||
*/
|
||||
void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba);
|
||||
|
||||
/**
|
||||
* @brief layer_element_set_dnd_callbacks
|
||||
* @param elem
|
||||
* @param entries
|
||||
* @param entry_count
|
||||
*/
|
||||
void layer_element_set_dnd_callbacks(LayerElement *elem, GtkTargetEntry *entries, int entry_count,
|
||||
void (*drag_begin)(GtkWidget *, GdkDragContext *, gpointer),
|
||||
void (*drag_data_get)(GtkWidget *, GdkDragContext *,
|
||||
GtkSelectionData *, guint , guint, gpointer),
|
||||
void (*drag_end)(GtkWidget *, GdkDragContext *, gpointer));
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __LAYER_ELEMENT_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user