mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
ModuleScope
This commit is contained in:
parent
4bef2d7617
commit
17fe06468d
@ -106,19 +106,7 @@ namespace netgen
|
|||||||
|
|
||||||
void ExportCSG()
|
void ExportCSG()
|
||||||
{
|
{
|
||||||
|
ModuleScope module("csg");
|
||||||
std::string nested_name = "csg";
|
|
||||||
if( bp::scope() )
|
|
||||||
nested_name = bp::extract<std::string>(bp::scope().attr("__name__") + ".csg");
|
|
||||||
|
|
||||||
bp::object module(bp::handle<>(bp::borrowed(PyImport_AddModule(nested_name.c_str()))));
|
|
||||||
|
|
||||||
cout << "exporting csg " << nested_name << endl;
|
|
||||||
bp::object parent = bp::scope() ? bp::scope() : bp::import("__main__");
|
|
||||||
parent.attr("csg") = module ;
|
|
||||||
|
|
||||||
bp::scope local_scope(module);
|
|
||||||
|
|
||||||
|
|
||||||
bp::class_<Point<2>> ("Point2d", bp::init<double,double>())
|
bp::class_<Point<2>> ("Point2d", bp::init<double,double>())
|
||||||
.def(bp::self+Vec<2>())
|
.def(bp::self+Vec<2>())
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifdef NG_PYTHON
|
#ifdef NG_PYTHON
|
||||||
|
|
||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
|
#include <../general/ngpython.hpp>
|
||||||
|
|
||||||
#include <meshing.hpp>
|
#include <meshing.hpp>
|
||||||
#include <geometry2d.hpp>
|
#include <geometry2d.hpp>
|
||||||
|
|
||||||
@ -8,49 +10,9 @@ using namespace netgen;
|
|||||||
namespace bp = boost::python;
|
namespace bp = boost::python;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
// Lambda to function pointer conversion
|
|
||||||
template <typename Function>
|
|
||||||
struct function_traits
|
|
||||||
: public function_traits<decltype(&Function::operator())> {};
|
|
||||||
|
|
||||||
template <typename ClassType, typename ReturnType, typename... Args>
|
|
||||||
struct function_traits<ReturnType(ClassType::*)(Args...) const> {
|
|
||||||
typedef ReturnType (*pointer)(Args...);
|
|
||||||
typedef ReturnType return_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Function>
|
|
||||||
typename function_traits<Function>::pointer
|
|
||||||
FunctionPointer (const Function& lambda) {
|
|
||||||
return static_cast<typename function_traits<Function>::pointer>(lambda);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline string ToString (const T& t)
|
|
||||||
{
|
|
||||||
stringstream ss;
|
|
||||||
ss << t;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ExportGeom2d()
|
void ExportGeom2d()
|
||||||
{
|
{
|
||||||
|
ModuleScope module("geom2d");
|
||||||
std::string nested_name = "geom2d";
|
|
||||||
if( bp::scope() )
|
|
||||||
nested_name = bp::extract<std::string>(bp::scope().attr("__name__") + ".geom2d");
|
|
||||||
|
|
||||||
bp::object module(bp::handle<>(bp::borrowed(PyImport_AddModule(nested_name.c_str()))));
|
|
||||||
|
|
||||||
cout << "exporting geom2d " << nested_name << endl;
|
|
||||||
bp::object parent = bp::scope() ? bp::scope() : bp::import("__main__");
|
|
||||||
parent.attr("geom2d") = module ;
|
|
||||||
|
|
||||||
bp::scope local_scope(module);
|
|
||||||
|
|
||||||
bp::class_<SplineGeometry2d, boost::noncopyable>("SplineGeometry")
|
bp::class_<SplineGeometry2d, boost::noncopyable>("SplineGeometry")
|
||||||
.def("Load",&SplineGeometry2d::Load)
|
.def("Load",&SplineGeometry2d::Load)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
#include <boost/python/slice.hpp>
|
#include <boost/python/slice.hpp>
|
||||||
|
#include <../general/ngpython.hpp>
|
||||||
|
|
||||||
#include <mystdlib.h>
|
#include <mystdlib.h>
|
||||||
#include "meshing.hpp"
|
#include "meshing.hpp"
|
||||||
@ -11,35 +12,6 @@ using namespace netgen;
|
|||||||
namespace bp = boost::python;
|
namespace bp = boost::python;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
// Lambda to function pointer conversion
|
|
||||||
template <typename Function>
|
|
||||||
struct function_traits
|
|
||||||
: public function_traits<decltype(&Function::operator())> {};
|
|
||||||
|
|
||||||
template <typename ClassType, typename ReturnType, typename... Args>
|
|
||||||
struct function_traits<ReturnType(ClassType::*)(Args...) const> {
|
|
||||||
typedef ReturnType (*pointer)(Args...);
|
|
||||||
typedef ReturnType return_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Function>
|
|
||||||
typename function_traits<Function>::pointer
|
|
||||||
FunctionPointer (const Function& lambda) {
|
|
||||||
return static_cast<typename function_traits<Function>::pointer>(lambda);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline string ToString (const T& t)
|
|
||||||
{
|
|
||||||
stringstream ss;
|
|
||||||
ss << t;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T, int BASE = 0, typename TIND = int>
|
template <typename T, int BASE = 0, typename TIND = int>
|
||||||
void ExportArray ()
|
void ExportArray ()
|
||||||
{
|
{
|
||||||
@ -67,17 +39,7 @@ void ExportArray ()
|
|||||||
void ExportNetgenMeshing()
|
void ExportNetgenMeshing()
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string nested_name = "meshing";
|
ModuleScope module("meshing");
|
||||||
if( bp::scope() )
|
|
||||||
nested_name = bp::extract<std::string>(bp::scope().attr("__name__") + ".meshing");
|
|
||||||
|
|
||||||
bp::object module(bp::handle<>(bp::borrowed(PyImport_AddModule(nested_name.c_str()))));
|
|
||||||
|
|
||||||
cout << "exporting meshing " << nested_name << endl;
|
|
||||||
bp::object parent = bp::scope() ? bp::scope() : bp::import("__main__");
|
|
||||||
parent.attr("meshing") = module ;
|
|
||||||
|
|
||||||
bp::scope local_scope(module);
|
|
||||||
|
|
||||||
bp::class_<PointIndex>("PointId", bp::init<int>())
|
bp::class_<PointIndex>("PointId", bp::init<int>())
|
||||||
.def("__repr__", &ToString<PointIndex>)
|
.def("__repr__", &ToString<PointIndex>)
|
||||||
|
Loading…
Reference in New Issue
Block a user