Completely restructudred code

* Subfolders for different modules
* LaTeX output module started
* Convert button sensitivity impemented
This commit is contained in:
Mario Hüttel 2018-05-22 16:17:14 +02:00
parent 9a6aee1410
commit 29f66951d1
11 changed files with 114 additions and 154 deletions

View File

@ -7,20 +7,24 @@ project(gds-render)
add_subdirectory(glade)
include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} "layer-widget")
include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS})
link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS})
add_definitions(${GLIB2_CFLAGS_OTHER})
aux_source_directory("layer-widget" SUB_SOURCES)
aux_source_directory("layer-widget" LAYER_SOURCES)
aux_source_directory("tree-renderer" RENDERER_SOURCES)
set(SOURCE "main.c" "gdsparse.c" "layer-selector.c")
aux_source_directory("gds-parser" PARSER_SOURCES)
aux_source_directory("latex-output" LATEX_SOURCES)
set(SOURCE "main.c" "layer-selector.c")
set(SOURCE
${SOURCE}
${SUB_SOURCES}
${LAYER_SOURCES}
${RENDERER_SOURCES}
${PARSER_SOURCES}
${LATEX_SOURCES}
)

View File

@ -27,7 +27,7 @@
*/
#include "gdsparse.h"
#include "gds-parser.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

View File

@ -1,59 +0,0 @@
#ifndef __GDS_TYPES_H__
#define __GDS_TYPES_H__
#include <stdint.h>
#define CELL_NAME_MAX (100)
enum graphics_type {GRAPHIC_PATH = 0, GRAPHIC_POLYGON = 1};
struct gds_time_field {
uint16_t year;
uint16_t month;
uint16_t day;
uint16_t hour;
uint16_t minute;
uint16_t second;
};
struct gds_point {
int x;
int y;
};
struct gds_graphics {
enum graphics_type type;
GList *vertices;
unsigned int path_width;
int width_absolute;
int16_t layer;
uint16_t datatype;
};
struct gds_cell_instance {
char ref_name[CELL_NAME_MAX];
struct gds_cell *cell_ref;
struct gds_point origin;
int flipped;
double angle;
double magnification;
};
struct gds_cell {
char name[CELL_NAME_MAX];
struct gds_time_field mod_time;
struct gds_time_field access_time;
GList *child_cells;
GList *graphic_objs;
};
struct gds_library {
char name[CELL_NAME_MAX];
struct gds_time_field mod_time;
struct gds_time_field access_time;
double unit_to_meters;
GList *cells;
GList *cell_names;
};
#endif /* __GDS_TYPES_H__ */

View File

@ -3,6 +3,7 @@
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="main-window">
<property name="height_request">250</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="delete-event" handler="on_window_close" swapped="no"/>
@ -57,6 +58,24 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="convert-button">
<property name="label">gtk-convert</property>
<property name="name">button-convert</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
<child>
@ -64,15 +83,23 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTreeView" id="cell-tree">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="cell-tree">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
@ -81,6 +108,7 @@
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
@ -102,43 +130,6 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="button-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton" id="convert-button">
<property name="label">gtk-convert</property>
<property name="name">button-convert</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>

View File

@ -17,13 +17,9 @@
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GDSPARSE_H__
#define __GDSPARSE_H__
#include "latex-output.h"
#include <glib.h>
#include "gds-types.h"
void render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file)
{
int parse_gds_from_file(const char *filename, GList **library_array);
int clear_lib_list(GList **library_list);
#endif /* __GDSPARSE_H__ */
}

View File

@ -18,7 +18,8 @@
*/
#include "layer-selector.h"
#include "gdsparse.h"
#include "gds-parser/gds-parser.h"
#include "layer-widget/layer-element.h"
#include <glib.h>
#include <string.h>
#include <stdio.h>
@ -27,33 +28,42 @@ static GList *layer_widgets = NULL;
static GtkWidget *load_button;
static GtkWidget *save_button;
static void layer_list_remove_element(struct layer_info *inf)
{
if (inf)
free(inf);
}
void get_layer_info(GList **info_list, GtkListBox *box)
{
GList *local_list = NULL;
/* Clear info Glist */
if (*info_list != NULL) {
g_list_free_full(*info_list, (GDestroyNotify)layer_list_remove_element);
*info_list = NULL;
}
*info_list = local_list;
}
static void delete_layer_widget(GtkWidget *widget)
{
gtk_widget_destroy(widget);
}
/**
* @brief export_rendered_layer_info
* @return new list with all info elements needed to render cells
*/
GList *export_rendered_layer_info()
{
GList *info_list = NULL;
LayerElement *le;
struct layer_info *linfo;
GList *widget_list;
/* Iterate through widgets and add layers that shall be exported */
for (widget_list = layer_widgets; widget_list != NULL; widget_list = widget_list->next) {
le = LAYER_ELEMENT(widget_list->data);
if (layer_element_get_export(le) == TRUE) {
/* Allocate new info and fill with info */
linfo = (struct layer_info *)malloc(sizeof(struct layer_info));
layer_element_get_color(le, &linfo->color);
linfo->layer = layer_element_get_layer(le);
/* Append to list */
info_list = g_list_append(info_list, (gpointer)linfo);
}
}
return info_list;
}
void clear_list_box_widgets(GtkListBox *box)
{
GList *list;

View File

@ -22,21 +22,16 @@
#include <gtk/gtk.h>
#include <glib.h>
#include <layer-element.h>
struct layer_info {
int id;
/* This contains both: opacity and Color */
GdkRGBA color;
struct layer_info
{
int layer;
GdkRGBA color;
};
void generate_layer_widgets(GtkListBox *listbox, GList *libs);
void clear_list_box_widgets();
void setup_load_mapping_callback(GtkWidget *button, GtkWindow *main_window);
void setup_save_mapping_callback(GtkWidget *button, GtkWindow *main_window);
void get_layer_info(GList **info_list, GtkListBox *box);
GList *export_rendered_layer_info();
#endif /* __LAYER_SELECTOR_H__ */

View File

@ -21,7 +21,6 @@
G_DEFINE_TYPE(LayerElement, layer_element, GTK_TYPE_BOX)
static void layer_element_dispose(GObject *obj)
{
/* destroy parent container. This destroys all widgets inside */

36
main.c
View File

@ -18,12 +18,12 @@
*/
#include <stdio.h>
#include "gdsparse.h"
#include "gds-parser/gds-parser.h"
#include <gtk/gtk.h>
#include <layer-element.h>
#include "layer-widget/layer-element.h"
#include "layer-selector.h"
#include "tree-renderer/lib-cell-renderer.h"
#include "tree-renderer/tree-store.h"
#include "latex-output/latex-output.h"
struct open_button_data {
GtkWindow *main_window;
@ -32,6 +32,11 @@ struct open_button_data {
GtkListBox *layer_box;
};
struct convert_button_data {
GList *layer_info;
GtkTreeView *tree_view;
};
gboolean on_window_close(gpointer window, gpointer user)
{
gtk_widget_destroy(GTK_WIDGET(window));
@ -156,9 +161,24 @@ end_destroy:
static void on_convert_clicked(gpointer button, gpointer user)
{
struct convert_button_data *data = (struct convert_button_data *)user;
printf("convert\n");
}
/* This function activates/deactivates the convert button depending on whether
* a cell is selected for conversion or not */
static void cell_selection_changed(GtkTreeSelection *sel, GtkWidget *convert_button)
{
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);
} else {
gtk_widget_set_sensitive(convert_button, FALSE);
}
}
int main(int argc, char **argv)
{
@ -166,7 +186,8 @@ int main(int argc, char **argv)
GList *gds_libs = NULL;
GtkTreeView *cell_tree;
GtkTreeStore *cell_store;
GtkWidget *widget_generic;
GtkWidget *conv_button;
GtkWidget *layer;
GtkWidget *listbox;
@ -191,8 +212,8 @@ int main(int argc, char **argv)
/* Connect Convert button */
widget_generic = GTK_WIDGET(gtk_builder_get_object(main_builder, "convert-button"));
g_signal_connect(widget_generic, "clicked", G_CALLBACK(on_convert_clicked), layer);
conv_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "convert-button"));
g_signal_connect(conv_button, "clicked", G_CALLBACK(on_convert_clicked), layer);
listbox = GTK_WIDGET(gtk_builder_get_object(main_builder, "layer-list"));
open_data.layer_box = GTK_LIST_BOX(listbox);
@ -203,6 +224,9 @@ int main(int argc, char **argv)
setup_save_mapping_callback(GTK_WIDGET(gtk_builder_get_object(main_builder, "button-save-mapping")),
open_data.main_window);
/* 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);
gtk_main();

View File

@ -18,7 +18,7 @@
*/
#include "lib-cell-renderer.h"
#include "../gds-types.h"
#include "../gds-parser/gds-types.h"
G_DEFINE_TYPE(LibCellRenderer, lib_cell_renderer, GTK_TYPE_CELL_RENDERER_TEXT)

View File

@ -1,6 +1,6 @@
#include "tree-store.h"
#include "lib-cell-renderer.h"
#include "../gds-types.h"
#include "../gds-parser/gds-types.h"
static gboolean tree_sel_func(GtkTreeSelection *selection,
GtkTreeModel *model,