From e6157eecd8eb400a7be25537d4a89d822fc8e0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 20 Oct 2015 11:09:29 +0200 Subject: [PATCH] nglib-python restructuring --- ng/CMakeLists.txt | 12 ++++++------ ng/netgenpy.cpp | 24 +++++++++++++----------- ng/ngpkg.cpp | 1 + nglib/CMakeLists.txt | 3 +++ py_tutorials/opengl.py | 9 +++------ py_tutorials/opengl_window.py | 2 +- python/__init__.py | 3 +++ python/csg.py | 17 ++++------------- python/geom2d.py | 15 ++------------- python/meshing.py | 8 +------- 10 files changed, 37 insertions(+), 57 deletions(-) diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 90327d34..5d331db0 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -13,15 +13,15 @@ if(USE_GUI) endif(USE_GUI) if(USE_PYTHON) - add_library(pynglib SHARED netgenpy.cpp) - target_link_libraries( pynglib nglib ) + add_library(ngpy SHARED netgenpy.cpp) + target_link_libraries( ngpy nglib ) if(APPLE) - set_target_properties( pynglib PROPERTIES SUFFIX ".so") + set_target_properties( ngpy PROPERTIES SUFFIX ".so") elseif(WIN32) - set_target_properties( pynglib PROPERTIES SUFFIX ".pyd") + set_target_properties( ngpy PROPERTIES SUFFIX ".pyd") endif() - set_target_properties( pynglib PROPERTIES OUTPUT_NAME "nglib") - install(TARGETS pynglib ${ng_install_dir}) +# set_target_properties( ngpy PROPERTIES OUTPUT_NAME "nglib") + install(TARGETS ngpy ${ng_install_dir}) endif(USE_PYTHON) install(FILES diff --git a/ng/netgenpy.cpp b/ng/netgenpy.cpp index d627af57..1179a7ed 100644 --- a/ng/netgenpy.cpp +++ b/ng/netgenpy.cpp @@ -1,18 +1,22 @@ -#ifdef WIN32 - // a wrapper to load netgen-dll into python - #include #include -void __declspec(dllimport) ExportNetgenMeshing(); -void __declspec(dllimport) ExportMeshVis(); -void __declspec(dllimport) ExportCSG(); -void __declspec(dllimport) ExportCSGVis(); -void __declspec(dllimport) ExportGeom2d(); +#ifdef WIN32 +#define DLL_HEADER __declspec(dllimport) +#else +#define DLL_HEADER +#endif -BOOST_PYTHON_MODULE(nglib) + +void DLL_HEADER ExportNetgenMeshing(); +void DLL_HEADER ExportMeshVis(); +void DLL_HEADER ExportCSG(); +void DLL_HEADER ExportCSGVis(); +void DLL_HEADER ExportGeom2d(); + +BOOST_PYTHON_MODULE(libngpy) { ExportCSG(); ExportCSGVis(); @@ -21,5 +25,3 @@ BOOST_PYTHON_MODULE(nglib) ExportGeom2d(); } - -#endif diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index 1cb85aa0..f90bd176 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -1959,6 +1959,7 @@ namespace netgen int w = Togl_Width (togl); int h = Togl_Height (togl); + cout << "togl h x w = " << h << " x " << w << endl; glViewport(0, 0, w, h); diff --git a/nglib/CMakeLists.txt b/nglib/CMakeLists.txt index 63eb3f15..3f3890e7 100644 --- a/nglib/CMakeLists.txt +++ b/nglib/CMakeLists.txt @@ -20,6 +20,9 @@ if(WIN32) endif(WIN32) add_library(nglib SHARED nglib.cpp ${nglib_objects}) +if(NOT WIN32) + target_link_libraries( nglib mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) +endif(NOT WIN32) target_link_libraries( nglib ${LIBPTHREAD} ${OCC_LIBRARIES} ${LIBTOGL} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ) diff --git a/py_tutorials/opengl.py b/py_tutorials/opengl.py index 3ba7293d..bdd3aefa 100644 --- a/py_tutorials/opengl.py +++ b/py_tutorials/opengl.py @@ -35,13 +35,10 @@ win_geom = Window( name=b"ngs", drawfunc=mydraw, mousefunc=mymouse) ########################################### # press ctrl+c to break loop -try: - while(True): - for i in range(10000): - glutMainLoopEvent() +while(True): + for i in range(10000): + glutMainLoopEvent() print('press ctrl+c to create second window!') -except: - pass ########################################### # create second window (transformation matrices are shared) diff --git a/py_tutorials/opengl_window.py b/py_tutorials/opengl_window.py index e336a9ac..9e243f1a 100644 --- a/py_tutorials/opengl_window.py +++ b/py_tutorials/opengl_window.py @@ -15,7 +15,7 @@ class Window(): self.drawfunc() def __init__( self, name=b"Window", width=500, height=500, drawfunc=None, mousefunc=None ): - glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS) +# glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH) glutInitWindowSize(width, height) # set window size glutInitWindowPosition(0, 0) # set window position diff --git a/python/__init__.py b/python/__init__.py index 0319b9f8..ee8a9845 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -6,6 +6,9 @@ if __platform.startswith('linux') or __platform.startswith('darwin'): if __platform.startswith('win'): path.append(environ['NETGENDIR']) + +from libngpy import * + from . import csg from . import meshing diff --git a/python/csg.py b/python/csg.py index 9e2159e2..16d10cf7 100644 --- a/python/csg.py +++ b/python/csg.py @@ -1,16 +1,7 @@ -from netgen import __platform -if __platform.startswith('linux') or __platform.startswith('darwin'): - # Linux or Mac OS X - from libcsg.csg import * - import libcsgvis.csgvis as csgvis - from libcsgvis.csgvis import MouseMove - from libmesh.meshing import * -if __platform.startswith('win'): - # Windows - from nglib.csg import * - import nglib.csgvis as csgvis - from nglib.csgvis import MouseMove - from nglib.meshing import * +from libngpy.csg import * +import libngpy.csgvis as csgvis +from libngpy.csgvis import MouseMove +from libngpy.meshing import * CSGeometry.VS = csgvis.VS diff --git a/python/geom2d.py b/python/geom2d.py index 34148e93..842d2532 100644 --- a/python/geom2d.py +++ b/python/geom2d.py @@ -1,16 +1,5 @@ -from netgen import __platform -if __platform.startswith('linux') or __platform.startswith('darwin'): - # Linux or Mac OS X - from libgeom2d.geom2d import * -# import libcsgvis.csgvis as csgvis -# from libcsgvis.csgvis import MouseMove - from libmesh.meshing import * -if __platform.startswith('win'): - # Windows - from nglib.geom2d import * -# import nglib.csgvis as csgvis -# from nglib.csgvis import MouseMove - from nglib.meshing import * +from libngpy.geom2d import * +from libngpy.meshing import * diff --git a/python/meshing.py b/python/meshing.py index 5388017b..0e3aca83 100644 --- a/python/meshing.py +++ b/python/meshing.py @@ -1,7 +1 @@ -from netgen import __platform -if __platform.startswith('linux') or __platform.startswith('darwin'): - # Linux or Mac OS X - from libmesh.meshing import * -if __platform.startswith('win'): - # Windows - from nglib.meshing import * +from libngpy.meshing import *