mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-12 00:59:16 +05:00
workplane draft
This commit is contained in:
parent
4629bccd72
commit
3e8664b40e
@ -4,6 +4,7 @@
|
|||||||
#include <../general/ngpython.hpp>
|
#include <../general/ngpython.hpp>
|
||||||
#include <core/python_ngcore.hpp>
|
#include <core/python_ngcore.hpp>
|
||||||
#include "../meshing/python_mesh.hpp"
|
#include "../meshing/python_mesh.hpp"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <meshing.hpp>
|
#include <meshing.hpp>
|
||||||
#include <occgeom.hpp>
|
#include <occgeom.hpp>
|
||||||
@ -24,9 +25,11 @@
|
|||||||
#include <TDF_Attribute.hxx>
|
#include <TDF_Attribute.hxx>
|
||||||
#include <Standard_GUID.hxx>
|
#include <Standard_GUID.hxx>
|
||||||
#include <Geom_TrimmedCurve.hxx>
|
#include <Geom_TrimmedCurve.hxx>
|
||||||
|
#include <Geom_Plane.hxx>
|
||||||
#include <GC_MakeSegment.hxx>
|
#include <GC_MakeSegment.hxx>
|
||||||
#include <GC_MakeCircle.hxx>
|
#include <GC_MakeCircle.hxx>
|
||||||
#include <GC_MakeArcOfCircle.hxx>
|
#include <GC_MakeArcOfCircle.hxx>
|
||||||
|
#include <GC_MakePlane.hxx>
|
||||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||||
#include <BRepBuilderAPI_MakeWire.hxx>
|
#include <BRepBuilderAPI_MakeWire.hxx>
|
||||||
#include <BRepBuilderAPI_Transform.hxx>
|
#include <BRepBuilderAPI_Transform.hxx>
|
||||||
@ -88,18 +91,137 @@ extern py::object CastShape(const TopoDS_Shape & s);
|
|||||||
DLL_HEADER void ExportNgOCCBasic(py::module &m);
|
DLL_HEADER void ExportNgOCCBasic(py::module &m);
|
||||||
DLL_HEADER void ExportNgOCCShapes(py::module &m);
|
DLL_HEADER void ExportNgOCCShapes(py::module &m);
|
||||||
|
|
||||||
|
|
||||||
|
class WorkPlane : public enable_shared_from_this<WorkPlane>
|
||||||
|
{
|
||||||
|
gp_Ax3 axis;
|
||||||
|
gp_Ax2d localpos;
|
||||||
|
gp_Pnt2d startpnt;
|
||||||
|
Handle(Geom_Surface) surf;
|
||||||
|
// Geom_Plane surf;
|
||||||
|
|
||||||
|
BRepBuilderAPI_MakeWire wire_builder;
|
||||||
|
std::vector<TopoDS_Wire> wires;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
WorkPlane (const gp_Ax3 & _axis, const gp_Ax2d _localpos = gp_Ax2d())
|
||||||
|
: axis(_axis), localpos(_localpos) // , surf(_axis)
|
||||||
|
{
|
||||||
|
// surf = GC_MakePlane (gp_Ax1(axis.Location(), axis.Direction()));
|
||||||
|
surf = new Geom_Plane(axis);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto MoveTo (double h, double v)
|
||||||
|
{
|
||||||
|
startpnt = gp_Pnt2d(h,v);
|
||||||
|
localpos.SetLocation(startpnt);
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Direction (double h, double v)
|
||||||
|
{
|
||||||
|
localpos.SetDirection(gp_Dir2d(h,v));
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto LineTo (double h, double v)
|
||||||
|
{
|
||||||
|
gp_Pnt2d old2d = localpos.Location();
|
||||||
|
gp_Pnt oldp = axis.Location() . Translated(old2d.X() * axis.XDirection() + old2d.Y() * axis.YDirection());
|
||||||
|
|
||||||
|
// localpos.Translate (gp_Vec2d(h,v));
|
||||||
|
localpos.SetLocation (gp_Pnt2d(h,v));
|
||||||
|
gp_Pnt2d new2d = localpos.Location();
|
||||||
|
gp_Pnt newp = axis.Location() . Translated(new2d.X() * axis.XDirection() + new2d.Y() * axis.YDirection());
|
||||||
|
|
||||||
|
cout << "lineto, newp = " << occ2ng(newp) << endl;
|
||||||
|
gp_Pnt pfromsurf;
|
||||||
|
surf->D0(new2d.X(), new2d.Y(), pfromsurf);
|
||||||
|
cout << "p from plane = " << occ2ng(pfromsurf) << endl;
|
||||||
|
|
||||||
|
|
||||||
|
Handle(Geom_TrimmedCurve) curve = GC_MakeSegment(oldp, newp);
|
||||||
|
auto edge = BRepBuilderAPI_MakeEdge(curve).Edge();
|
||||||
|
wire_builder.Add(edge);
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Line(double h, double v)
|
||||||
|
{
|
||||||
|
gp_Pnt2d oldp = localpos.Location();
|
||||||
|
oldp.Translate(gp_Vec2d(h,v));
|
||||||
|
return LineTo (oldp.X(), oldp.Y());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Line(double len)
|
||||||
|
{
|
||||||
|
gp_Dir2d dir = localpos.Direction();
|
||||||
|
cout << "dir = " << dir.X() << ", " << dir.Y() << endl;
|
||||||
|
gp_Pnt2d oldp = localpos.Location();
|
||||||
|
oldp.Translate(len*dir);
|
||||||
|
return LineTo (oldp.X(), oldp.Y());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Rotate (double angle)
|
||||||
|
{
|
||||||
|
localpos.Rotate(localpos.Location(), angle*M_PI/180);
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Close ()
|
||||||
|
{
|
||||||
|
LineTo (startpnt.X(), startpnt.Y());
|
||||||
|
wires.push_back (wire_builder.Wire());
|
||||||
|
wire_builder = BRepBuilderAPI_MakeWire();
|
||||||
|
}
|
||||||
|
|
||||||
|
TopoDS_Wire Last()
|
||||||
|
{
|
||||||
|
return wires.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
TopoDS_Face Face()
|
||||||
|
{
|
||||||
|
// crashes ????
|
||||||
|
BRepBuilderAPI_MakeFace builder(surf, 1e-8);
|
||||||
|
for (auto w : wires)
|
||||||
|
builder.Add(w);
|
||||||
|
return builder.Face();
|
||||||
|
|
||||||
|
// only one wire, for now:
|
||||||
|
// return BRepBuilderAPI_MakeFace(wires.back()).Face();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
DLL_HEADER void ExportNgOCC(py::module &m)
|
DLL_HEADER void ExportNgOCC(py::module &m)
|
||||||
{
|
{
|
||||||
m.attr("occ_version") = OCC_VERSION_COMPLETE;
|
m.attr("occ_version") = OCC_VERSION_COMPLETE;
|
||||||
|
|
||||||
ExportNgOCCBasic(m);
|
ExportNgOCCBasic(m);
|
||||||
ExportNgOCCShapes(m);
|
ExportNgOCCShapes(m);
|
||||||
|
|
||||||
|
py::class_<WorkPlane, shared_ptr<WorkPlane>> (m, "WorkPlane")
|
||||||
|
.def(py::init<gp_Ax3, gp_Ax2d>(), py::arg("axis"), py::arg("pos")=gp_Ax2d())
|
||||||
|
.def("MoveTo", &WorkPlane::MoveTo)
|
||||||
|
.def("Direction", &WorkPlane::Direction)
|
||||||
|
.def("LineTo", &WorkPlane::LineTo)
|
||||||
|
.def("Rotate", &WorkPlane::Rotate)
|
||||||
|
.def("Line", [](WorkPlane&wp,double l) { return wp.Line(l); })
|
||||||
|
.def("Line", [](WorkPlane&wp,double h,double v) { return wp.Line(h,v); })
|
||||||
|
.def("Close", &WorkPlane::Close)
|
||||||
|
.def("Last", &WorkPlane::Last)
|
||||||
|
.def("Face", &WorkPlane::Face)
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// not working, since occ - exceptions don't derive from std::exception
|
// not working, since occ - exceptions don't derive from std::exception
|
||||||
// py::register_exception<Standard_Failure>(m, "OCC-Exception");
|
// py::register_exception<Standard_Failure>(m, "OCC-Exception");
|
||||||
|
|
||||||
py::class_<OCCGeometry, shared_ptr<OCCGeometry>, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string")
|
py::class_<OCCGeometry, shared_ptr<OCCGeometry>, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string")
|
||||||
.def(py::init<>())
|
|
||||||
/*
|
/*
|
||||||
.def(py::init<const TopoDS_Shape&>(), py::arg("shape"),
|
.def(py::init<const TopoDS_Shape&>(), py::arg("shape"),
|
||||||
"Create Netgen OCCGeometry from existing TopoDS_Shape")
|
"Create Netgen OCCGeometry from existing TopoDS_Shape")
|
||||||
|
@ -142,7 +142,7 @@ DLL_HEADER void ExportNgOCCBasic(py::module &m)
|
|||||||
py::class_<gp_Ax3>(m, "gp_Ax3")
|
py::class_<gp_Ax3>(m, "gp_Ax3")
|
||||||
.def(py::init([](gp_Pnt p, gp_Dir N, gp_Dir Vx) {
|
.def(py::init([](gp_Pnt p, gp_Dir N, gp_Dir Vx) {
|
||||||
return gp_Ax3(p,N, Vx);
|
return gp_Ax3(p,N, Vx);
|
||||||
}), py::arg("p"), py::arg("n"), py::arg("x"))
|
}), py::arg("p")=gp_Pnt(0,0,0), py::arg("n")=gp_Vec(0,0,1), py::arg("h")=gp_Vec(1,0,0))
|
||||||
.def(py::init<gp_Ax2>())
|
.def(py::init<gp_Ax2>())
|
||||||
.def_property("p", [](gp_Ax3 & ax) { return ax.Location(); }, [](gp_Ax3&ax, gp_Pnt p) { ax.SetLocation(p); })
|
.def_property("p", [](gp_Ax3 & ax) { return ax.Location(); }, [](gp_Ax3&ax, gp_Pnt p) { ax.SetLocation(p); })
|
||||||
;
|
;
|
||||||
@ -189,7 +189,7 @@ DLL_HEADER void ExportNgOCCBasic(py::module &m)
|
|||||||
py::class_<gp_Ax2d>(m, "gp_Ax2d")
|
py::class_<gp_Ax2d>(m, "gp_Ax2d")
|
||||||
.def(py::init([](gp_Pnt2d p, gp_Dir2d d) {
|
.def(py::init([](gp_Pnt2d p, gp_Dir2d d) {
|
||||||
return gp_Ax2d(p,d);
|
return gp_Ax2d(p,d);
|
||||||
}))
|
}), py::arg("p")=gp_Pnt2d(0,0), py::arg("d")=gp_Dir2d(1,0))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user