Compare commits
17 Commits
v1.2.2
...
71b500e030
Author | SHA1 | Date | |
---|---|---|---|
71b500e030 | |||
d69d4f3f7e | |||
a60fe6543e | |||
dc32499ad7 | |||
322439145e | |||
231248e404 | |||
88d912f59d | |||
f454ca7e71 | |||
045b9dce30 | |||
112a5ac74c | |||
6b5101ecec | |||
583e5581c0 | |||
519d2296ad | |||
02720ec37b | |||
cf2947d2d5 | |||
c7ceef7d66 | |||
ebce4a2669 |
@@ -40,7 +40,7 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"${CMAKE_CURRENT_BINARY_DIR}/translations/output\")
|
||||
message("${BoldMagenta}${CMAKE_CURRENT_BINARY_DIR}/translations/output used as data dir${ColorReset}")
|
||||
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
message("Global locale directory used. Make sure files in /usr/share/locale are available")
|
||||
message("${BoldCyan}Global locale directory used. Make sure files in /usr/share/locale are available${ColorReset}")
|
||||
add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"/usr/share\")
|
||||
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
||||
|
@@ -146,6 +146,7 @@ int command_line_convert_gds(const char *gds_name,
|
||||
double scale)
|
||||
{
|
||||
int ret = -1;
|
||||
int render_ret;
|
||||
GList *libs = NULL;
|
||||
int res;
|
||||
GList *renderer_list = NULL;
|
||||
@@ -163,7 +164,14 @@ int command_line_convert_gds(const char *gds_name,
|
||||
|
||||
/* Load layer_settings */
|
||||
layer_sett = layer_settings_new();
|
||||
layer_settings_load_from_csv(layer_sett, layer_file);
|
||||
if (!layer_sett)
|
||||
goto return_value;
|
||||
|
||||
ret = layer_settings_load_from_csv(layer_sett, layer_file);
|
||||
if (ret) {
|
||||
fprintf(stderr, _("Loading layer mapping file failed.\n"));
|
||||
goto ret_destroy_layer_mapping;
|
||||
}
|
||||
|
||||
/* Create renderers */
|
||||
if (create_renderers(renderers, output_file_names, tex_layers, tex_standalone,
|
||||
@@ -221,7 +229,9 @@ int command_line_convert_gds(const char *gds_name,
|
||||
/* Execute all rendererer instances */
|
||||
for (list_iter = renderer_list; list_iter; list_iter = list_iter->next) {
|
||||
current_renderer = GDS_RENDER_OUTPUT_RENDERER(list_iter->data);
|
||||
gds_output_renderer_render_output(current_renderer, toplevel_cell, scale);
|
||||
render_ret = gds_output_renderer_render_output(current_renderer, toplevel_cell, scale);
|
||||
if (render_ret)
|
||||
fprintf(stderr, "Rendering failed with error code: %d\n", render_ret);
|
||||
}
|
||||
|
||||
ret_destroy_library_list:
|
||||
@@ -231,6 +241,7 @@ ret_clear_renderers:
|
||||
g_object_unref(list_iter->data);
|
||||
ret_destroy_layer_mapping:
|
||||
g_object_unref(layer_sett);
|
||||
return_value:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -22,5 +22,6 @@
|
||||
* @ref EXTERNAL_LIBRARY_RENDER_FUNCTION | int EXTERNAL_LIBRARY_RENDER_FUNCTION(struct gds_cell *toplevel, GList *layer_info_list, const char *output_file_name, double scale) | Render cell to output file
|
||||
* @ref EXTERNAL_LIBRARY_INIT_FUNCTION | int EXTERNAL_LIBRARY_INIT_FUNCTION(const char *option_string, const char *version_string) | Init function. Executed before rendering. This is given the command line parameters specified for the external renderer and the version string of the currently running gds-render program.
|
||||
* @ref EXTERNAL_LIBRARY_FORK_REQUEST | int EXTERNAL_LIBRARY_FORK_REQUEST; | The pure presence of this integer results in the execution inside a subprocess of hte whole shared object's code
|
||||
* @ref EXTERNAL_LIBRARY_FINALIZE_FUNCTION | int EXTERNAL_LIBRARY_FINALIZE_FUNCTION(void) | Called after rendering
|
||||
*
|
||||
*/
|
||||
|
@@ -32,6 +32,15 @@
|
||||
*/
|
||||
#define EXTERNAL_LIBRARY_INIT_FUNCTION exported_init
|
||||
|
||||
/**
|
||||
* @brief Function name expected to be found in external library for finalizing.
|
||||
*
|
||||
* @code
|
||||
* int EXTERNAL_LIBRARY_FINALIZE_FUNCTION(void);
|
||||
* @endcode
|
||||
*/
|
||||
#define EXTERNAL_LIBRARY_FINALIZE_FUNCTION exported_finalize
|
||||
|
||||
/**
|
||||
* @brief Global integer specified by an external renderer to signal, that the init and render functions shall be executed in a subprocess
|
||||
*
|
||||
|
@@ -66,6 +66,7 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
|
||||
{
|
||||
int (*so_render_func)(struct gds_cell *, GList *, const char *, double) = NULL;
|
||||
int (*so_init_func)(const char *, const char *) = NULL;
|
||||
int (*so_finalize_func)(void) = NULL;
|
||||
void *so_handle = NULL;
|
||||
char *error_msg;
|
||||
int forking_req;
|
||||
@@ -93,7 +94,7 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
|
||||
so_render_func = (int (*)(struct gds_cell *, GList *, const char *, double))
|
||||
dlsym(so_handle, xstr(EXTERNAL_LIBRARY_RENDER_FUNCTION));
|
||||
error_msg = dlerror();
|
||||
if (error_msg != NULL) {
|
||||
if (error_msg) {
|
||||
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
|
||||
goto ret_close_so_handle;
|
||||
}
|
||||
@@ -101,11 +102,19 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
|
||||
/* Load the init function */
|
||||
so_init_func = (int (*)(const char *, const char *))dlsym(so_handle, xstr(EXTERNAL_LIBRARY_INIT_FUNCTION));
|
||||
error_msg = dlerror();
|
||||
if (error_msg != NULL) {
|
||||
if (error_msg) {
|
||||
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
|
||||
goto ret_close_so_handle;
|
||||
}
|
||||
|
||||
/* Load the finalize function */
|
||||
so_finalize_func = (int (*)(void))dlsym(so_handle, xstr(EXTERNAL_LIBRARY_FINALIZE_FUNCTION));
|
||||
error_msg = dlerror();
|
||||
if (error_msg) {
|
||||
fprintf(stderr, "Finalize function not found in library:\n%s\n", error_msg);
|
||||
goto ret_close_so_handle;
|
||||
}
|
||||
|
||||
/* Check if forking is requested */
|
||||
if (dlsym(so_handle, xstr(EXTERNAL_LIBRARY_FORK_REQUEST)))
|
||||
forking_req = 1;
|
||||
@@ -127,6 +136,9 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
|
||||
if (!ret)
|
||||
ret = so_render_func(toplevel_cell, layer_info_list, output_file, scale);
|
||||
|
||||
/* Finalize the external renderer */
|
||||
ret |= so_finalize_func();
|
||||
|
||||
/* If we are in a separate process, terminate here */
|
||||
if (forking_req)
|
||||
exit(ret);
|
||||
|
@@ -1,2 +1,4 @@
|
||||
add_subdirectory(plugin-example)
|
||||
add_custom_target(plugins DEPENDS pluginexample)
|
||||
add_subdirectory(python-renderer)
|
||||
|
||||
add_custom_target(plugins DEPENDS pluginexample pythonrenderer)
|
||||
|
@@ -1,12 +1,11 @@
|
||||
project(pluginexample)
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_search_module(PYTHON REQUIRED python3)
|
||||
|
||||
aux_source_directory(src SOURCES)
|
||||
|
||||
include_directories(${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
link_libraries(${PYTHON_LDFLAGS} version)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
link_libraries(version)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED EXCLUDE_FROM_ALL ${SOURCES})
|
||||
add_dependencies(${PROJECT_NAME} version)
|
||||
|
@@ -25,7 +25,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include <gds-render/gds-utils/gds-types.h>
|
||||
@@ -46,4 +45,9 @@ int FUNC_DECL(EXTERNAL_LIBRARY_INIT_FUNCTION)(const char *params, const char *ve
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FUNC_DECL(EXTERNAL_LIBRARY_FINALIZE_FUNCTION)(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
16
plugins/python-renderer/CMakeLists.txt
Normal file
16
plugins/python-renderer/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
project(pythonrenderer)
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
find_package(PythonLibs)
|
||||
|
||||
aux_source_directory(src SOURCES)
|
||||
|
||||
include_directories(${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
link_libraries(${PYTHON_LIBRARIES} version)
|
||||
|
||||
message("Python version found: ${PYTHONLIBS_VERSION_STRING}")
|
||||
message(${PYTHON_LIBRARIES})
|
||||
message(${PYTHON_INCLUDE_DIRS})
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED EXCLUDE_FROM_ALL ${SOURCES})
|
||||
add_dependencies(${PROJECT_NAME} version)
|
||||
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* GDSII-Converter Python Plugin
|
||||
* 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 gds-render-module.h
|
||||
* @brief Header file for the gds-render python module implementation
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
#ifndef __GDS_RENDER_MODULE_H__
|
||||
#define __GDS_RENDER_MODULE_H__
|
||||
|
||||
/**
|
||||
* @addtogroup python-renderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* __GDS_RENDER_MODULE_H__ */
|
26
plugins/python-renderer/src/gds-render-module.c
Normal file
26
plugins/python-renderer/src/gds-render-module.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* GDSII-Converter Python Plugin
|
||||
* 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 gds-render-module.c
|
||||
* @brief Gds-render python module implementation
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
#include <python-renderer/gds-render-module.h>
|
137
plugins/python-renderer/src/plugin-main.c
Normal file
137
plugins/python-renderer/src/plugin-main.c
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* GDSII-Converter Python Plugin
|
||||
* 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 python-renderer/plugin-main.c
|
||||
* @author Mario
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup python-plugin Python Plugin for External Renderer
|
||||
* @ingroup plugins
|
||||
* This is a plugin for calling an external python script as renderer
|
||||
* @addtogroup python-plugin
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include <unistd.h>
|
||||
#include <Python.h>
|
||||
|
||||
#include <gds-render/gds-utils/gds-types.h>
|
||||
#include <gds-render/output-renderers/external-renderer-interfaces.h>
|
||||
|
||||
#include <python-renderer/gds-render-module.h>
|
||||
|
||||
/**
|
||||
* @brief Global variable for loaded module. This is not very nice.
|
||||
* @warning This has to be changed, if this api wants to be re-entrant.
|
||||
*/
|
||||
static PyObject *p_module = NULL;
|
||||
|
||||
int FUNC_DECL(EXTERNAL_LIBRARY_RENDER_FUNCTION)(struct gds_cell *toplevel, GList *layer_info_list, const char *output_file_name, double scale)
|
||||
{
|
||||
int ret = 0;
|
||||
PyObject *p_render_func;
|
||||
PyObject *p_return_value;
|
||||
|
||||
if (!toplevel)
|
||||
return -1000;
|
||||
if (!p_module)
|
||||
return -2000;
|
||||
|
||||
printf("Rendering %s\n", toplevel->name);
|
||||
|
||||
p_render_func = PyObject_GetAttrString(p_module, "test_func");
|
||||
if (!p_render_func && !PyCallable_Check(p_render_func)) {
|
||||
if (PyErr_Occurred())
|
||||
PyErr_Print();
|
||||
else
|
||||
fprintf(stderr, "Function not found in python module\n");
|
||||
|
||||
ret = -1;
|
||||
goto return_value;
|
||||
}
|
||||
|
||||
p_return_value = PyObject_CallObject(p_render_func, NULL);
|
||||
if (p_return_value) {
|
||||
printf("Result of call: %ld\n", PyLong_AsLong(p_return_value));
|
||||
Py_DECREF(p_return_value);
|
||||
}
|
||||
|
||||
Py_XDECREF(p_render_func);
|
||||
|
||||
return_value:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FUNC_DECL(EXTERNAL_LIBRARY_INIT_FUNCTION)(const char *params, const char *version)
|
||||
{
|
||||
int ret = 0;
|
||||
PyObject *p_name;
|
||||
PyObject *p_sys_path;
|
||||
PyObject *p_cwd_string;
|
||||
char cwd[256];
|
||||
|
||||
if (!params || !version)
|
||||
return -1000;
|
||||
|
||||
printf("Init with params: %s\ngds-render version: %s\n", params, version);
|
||||
Py_Initialize();
|
||||
|
||||
if (!getcwd(cwd, sizeof(cwd))) {
|
||||
fprintf(stderr, "Error getting current working directory. Maybe the path is too long?\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
p_sys_path = PySys_GetObject("path");
|
||||
p_cwd_string = PyUnicode_FromString(cwd);
|
||||
PyList_Append(p_sys_path, p_cwd_string);
|
||||
Py_DECREF(p_cwd_string);
|
||||
|
||||
p_name = PyUnicode_DecodeFSDefault(params);
|
||||
p_module = PyImport_Import(p_name);
|
||||
Py_DECREF(p_name);
|
||||
|
||||
if (!p_module) {
|
||||
PyErr_Print();
|
||||
fprintf(stderr, "Failed to load %s\n", params);
|
||||
ret = -1;
|
||||
goto return_value;
|
||||
}
|
||||
|
||||
return_value:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FUNC_DECL(EXTERNAL_LIBRARY_FINALIZE_FUNCTION)(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
printf("Finalizing\n");
|
||||
|
||||
if (p_module)
|
||||
Py_DECREF(p_module);
|
||||
|
||||
ret = Py_FinalizeEx();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** @} */
|
Reference in New Issue
Block a user