2018-05-10 01:43:14 +02:00
/*
2018-05-15 22:54:10 +02:00
* GDSII - Converter
2018-05-10 01:43:14 +02:00
* Copyright ( C ) 2018 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
2018-05-16 16:29:34 +02:00
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation .
2018-05-10 01:43:14 +02:00
*
2018-05-15 22:54:10 +02:00
* GDSII - Converter is distributed in the hope that it will be useful ,
2018-05-10 01:43:14 +02:00
* 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/>.
*/
2018-05-07 13:27:50 +02:00
# include <stdio.h>
2018-05-08 15:00:37 +02:00
# include <gtk/gtk.h>
2018-07-23 17:00:37 +02:00
# include <glib.h>
2018-07-23 13:10:34 +02:00
# include "main-window.h"
2018-07-23 17:00:37 +02:00
# include "command-line.h"
2018-12-15 00:05:34 +01:00
# include "external-renderer.h"
2019-03-11 10:36:02 +01:00
# include "version/version.h"
2018-05-08 16:50:30 +02:00
2018-07-23 15:10:40 +02:00
struct application_data {
2019-03-13 22:54:52 +01:00
GtkApplication * app ;
GtkWindow * main_window ;
2018-07-23 15:10:40 +02:00
} ;
static void app_quit ( GSimpleAction * action , GVariant * parameter , gpointer user_data )
{
2019-03-07 20:14:44 +01:00
const struct application_data * const appdata = ( const struct application_data * ) user_data ;
2018-12-15 00:03:40 +01:00
( void ) action ;
( void ) parameter ;
2018-12-11 00:06:27 +01:00
2018-07-23 15:10:40 +02:00
gtk_widget_destroy ( GTK_WIDGET ( appdata - > main_window ) ) ;
}
static void app_about ( GSimpleAction * action , GVariant * parameter , gpointer user_data )
{
GtkBuilder * builder ;
GtkDialog * dialog ;
2019-03-07 20:14:44 +01:00
const struct application_data * const appdata = ( const struct application_data * ) user_data ;
2018-12-15 00:03:40 +01:00
( void ) action ;
( void ) parameter ;
2018-07-23 15:10:40 +02:00
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_dialog_run ( dialog ) ;
2018-07-23 17:00:37 +02:00
gtk_widget_destroy ( GTK_WIDGET ( dialog ) ) ;
2018-07-23 15:10:40 +02:00
g_object_unref ( builder ) ;
}
2018-09-22 23:32:22 +02:00
const static GActionEntry app_actions [ ] = {
2019-03-14 19:10:06 +01:00
{ " quit " , app_quit , NULL , NULL , NULL , { 0 } } ,
{ " about " , app_about , NULL , NULL , NULL , { 0 } }
2018-07-23 15:10:40 +02:00
} ;
2018-05-08 15:00:37 +02:00
2018-07-23 13:10:34 +02:00
static void gapp_activate ( GApplication * app , gpointer user_data )
2018-05-08 15:00:37 +02:00
{
2018-07-23 13:10:34 +02:00
GtkWindow * main_window ;
2019-03-07 20:14:44 +01:00
struct application_data * const appdata = ( struct application_data * ) user_data ;
2018-05-22 16:17:14 +02:00
2019-03-14 19:02:17 +01:00
main_window = create_main_window ( ) ;
appdata - > main_window = main_window ;
gtk_application_add_window ( GTK_APPLICATION ( app ) , main_window ) ;
gtk_widget_show ( GTK_WIDGET ( main_window ) ) ;
2018-05-22 16:17:14 +02:00
}
2018-05-08 16:02:44 +02:00
2018-07-23 17:00:37 +02:00
static int start_gui ( int argc , char * * argv )
2018-05-08 15:00:37 +02:00
{
2018-07-23 17:00:37 +02:00
2018-07-23 13:10:34 +02:00
GtkApplication * gapp ;
int app_status ;
2018-07-23 17:00:37 +02:00
static struct application_data appdata ;
2018-07-23 15:10:40 +02:00
GMenu * menu ;
GMenu * m_quit ;
GMenu * m_about ;
2018-05-15 16:57:08 +02:00
2019-03-14 19:02:17 +01:00
gapp = gtk_application_new ( " de.shimatta.gds-render " , G_APPLICATION_NON_UNIQUE ) ;
2018-07-23 15:10:40 +02:00
g_application_register ( G_APPLICATION ( gapp ) , NULL , NULL ) ;
2018-12-11 00:06:27 +01:00
g_signal_connect ( gapp , " activate " , G_CALLBACK ( gapp_activate ) , & appdata ) ;
2018-07-23 15:10:40 +02:00
menu = g_menu_new ( ) ;
m_quit = g_menu_new ( ) ;
m_about = g_menu_new ( ) ;
g_menu_append ( m_quit , " Quit " , " app.quit " ) ;
g_menu_append ( m_about , " About " , " app.about " ) ;
g_menu_append_section ( menu , NULL , G_MENU_MODEL ( m_about ) ) ;
g_menu_append_section ( menu , NULL , G_MENU_MODEL ( m_quit ) ) ;
2018-12-11 00:06:27 +01:00
g_action_map_add_action_entries ( G_ACTION_MAP ( gapp ) , app_actions ,
G_N_ELEMENTS ( app_actions ) , & appdata ) ;
2018-07-23 15:10:40 +02:00
gtk_application_set_app_menu ( GTK_APPLICATION ( gapp ) , G_MENU_MODEL ( menu ) ) ;
g_object_unref ( m_quit ) ;
g_object_unref ( m_about ) ;
g_object_unref ( menu ) ;
2018-05-17 21:46:14 +02:00
2018-12-11 00:06:27 +01:00
app_status = g_application_run ( G_APPLICATION ( gapp ) , argc , argv ) ;
g_object_unref ( gapp ) ;
2018-05-07 13:27:50 +02:00
2018-07-23 17:00:37 +02:00
return app_status ;
}
2019-03-11 10:36:02 +01:00
static void print_version ( )
{
printf ( " This is gds-render, version: %s \n \n For a list of supported commands execute with --help option. \n " ,
2019-03-13 22:54:52 +01:00
_app_version_string ) ;
2019-03-11 10:36:02 +01:00
}
2018-07-23 17:00:37 +02:00
int main ( int argc , char * * argv )
{
GError * error = NULL ;
GOptionContext * context ;
2018-07-23 21:12:25 +02:00
gchar * gds_name ;
gchar * basename ;
2018-07-30 12:35:30 +02:00
gchar * pdfname = NULL , * texname = NULL , * mappingname = NULL , * cellname = NULL , * svgname = NULL ;
gboolean tikz = FALSE , pdf = FALSE , pdf_layers = FALSE , pdf_standalone = FALSE , svg = FALSE ;
2019-03-11 10:36:02 +01:00
gboolean version = FALSE ;
2018-12-15 00:05:34 +01:00
gchar * custom_library_path = NULL ;
gchar * custom_library_file_name = NULL ;
2018-07-23 17:00:37 +02:00
int scale = 1000 ;
2019-03-11 10:36:02 +01:00
int app_status = 0 ;
2018-07-23 17:00:37 +02:00
2018-12-11 00:06:27 +01:00
GOptionEntry entries [ ] = {
2019-03-13 22:54:52 +01:00
{ " version " , ' v ' , 0 , G_OPTION_ARG_NONE , & version , " Print version " , NULL } ,
{ " tikz " , ' t ' , 0 , G_OPTION_ARG_NONE , & tikz , " Output TikZ code " , NULL } ,
{ " pdf " , ' p ' , 0 , G_OPTION_ARG_NONE , & pdf , " Output PDF document " , NULL } ,
//{"svg", 'S', 0, G_OPTION_ARG_NONE, &svg, "Output SVG image", NULL },
{ " scale " , ' s ' , 0 , G_OPTION_ARG_INT , & scale , " Divide output coordinates by <SCALE> " , " <SCALE> " } ,
{ " tex-output " , ' o ' , 0 , G_OPTION_ARG_FILENAME , & texname , " Optional path for TeX file " , " PATH " } ,
{ " pdf-output " , ' O ' , 0 , G_OPTION_ARG_FILENAME , & pdfname , " Optional path for PDF file " , " PATH " } ,
//{"svg-output", 0, 0, G_OPTION_ARG_FILENAME, &svgname, "Optional path for PDF file", "PATH"},
{ " mapping " , ' m ' , 0 , G_OPTION_ARG_FILENAME , & mappingname , " Path for Layer Mapping File " , " PATH " } ,
{ " cell " , ' c ' , 0 , G_OPTION_ARG_STRING , & cellname , " Cell to render " , " NAME " } ,
{ " tex-standalone " , ' a ' , 0 , G_OPTION_ARG_NONE , & pdf_standalone , " Create standalone PDF " , NULL } ,
{ " tex-layers " , ' l ' , 0 , G_OPTION_ARG_NONE , & pdf_layers , " Create PDF Layers (OCG) " , NULL } ,
{ " custom-render-lib " , ' P ' , 0 , G_OPTION_ARG_FILENAME , & custom_library_path , " Path to a custom shared object, that implements the " EXTERNAL_LIBRARY_FUNCTION " function " , " PATH " } ,
{ " external-lib-output " , ' e ' , 0 , G_OPTION_ARG_FILENAME , & custom_library_file_name , " Output path for external render library " , " PATH " } ,
{ NULL }
2018-07-23 17:00:37 +02:00
} ;
context = g_option_context_new ( " FILE - Convert GDS file <FILE> to graphic " ) ;
g_option_context_add_main_entries ( context , entries , NULL ) ;
g_option_context_add_group ( context , gtk_get_option_group ( TRUE ) ) ;
2018-12-11 00:06:27 +01:00
if ( ! g_option_context_parse ( context , & argc , & argv , & error ) ) {
g_print ( " Option parsing failed: %s \n " , error - > message ) ;
exit ( 1 ) ;
}
2018-07-23 17:00:37 +02:00
2019-03-11 10:36:02 +01:00
if ( version ) {
print_version ( ) ;
2019-03-13 22:54:52 +01:00
goto ret_status ;
2019-03-11 10:36:02 +01:00
}
2018-07-23 17:00:37 +02:00
if ( argc > = 2 ) {
2018-07-23 21:12:25 +02:00
if ( scale < 1 ) {
printf ( " Scale < 1 not allowed. Setting to 1 \n " ) ;
scale = 1 ;
}
/* No format selected */
2018-12-11 00:06:27 +01:00
if ( ! ( tikz | | pdf | | svg ) )
2018-07-23 21:12:25 +02:00
tikz = TRUE ;
/* Get gds name */
gds_name = argv [ 1 ] ;
/* Check if PDF/TeX names are supplied. if not generate */
basename = g_path_get_basename ( gds_name ) ;
2018-12-11 00:06:27 +01:00
if ( ! texname )
2018-07-23 21:12:25 +02:00
texname = g_strdup_printf ( " ./%s.tex " , basename ) ;
2018-12-11 00:06:27 +01:00
if ( ! pdfname )
2018-07-23 21:12:25 +02:00
pdfname = g_strdup_printf ( " ./%s.pdf " , basename ) ;
2018-12-11 00:06:27 +01:00
if ( ! pdfname )
2018-07-30 12:35:30 +02:00
pdfname = g_strdup_printf ( " ./%s.svg " , basename ) ;
2018-12-11 00:06:27 +01:00
command_line_convert_gds ( gds_name , pdfname , texname , pdf , tikz ,
2019-03-13 22:54:52 +01:00
mappingname , cellname , ( double ) scale ,
pdf_layers , pdf_standalone , svg , svgname ,
custom_library_path , custom_library_file_name ) ;
2018-07-23 21:12:25 +02:00
/* Clean up */
g_free ( pdfname ) ;
g_free ( texname ) ;
2018-07-30 12:35:30 +02:00
g_free ( svgname ) ;
g_free ( basename ) ;
2018-07-23 21:12:25 +02:00
if ( mappingname )
g_free ( mappingname ) ;
if ( cellname )
g_free ( cellname ) ;
2018-07-23 20:17:18 +02:00
app_status = 0 ;
2018-07-23 17:00:37 +02:00
} else {
app_status = start_gui ( argc , argv ) ;
}
2019-03-11 10:36:02 +01:00
ret_status :
2018-07-23 13:10:34 +02:00
return app_status ;
2018-05-07 13:27:50 +02:00
}