diff --git a/pybind11/MooseVec.cpp b/pybind11/MooseVec.cpp index 4bb013cfc3..8ca21684ea 100644 --- a/pybind11/MooseVec.cpp +++ b/pybind11/MooseVec.cpp @@ -34,6 +34,10 @@ MooseVec::MooseVec(const ObjId& oid) : oid_(oid), path_(oid.path()) { } +MooseVec::MooseVec(const Id& id) : oid_(ObjId(id)), path_(id.path()) +{ +} + const string MooseVec::dtype() const { return oid_.element()->cinfo()->name(); diff --git a/pybind11/MooseVec.h b/pybind11/MooseVec.h index befc425630..ff3a536b8f 100644 --- a/pybind11/MooseVec.h +++ b/pybind11/MooseVec.h @@ -10,11 +10,14 @@ #ifndef MOOSE_VEC_H #define MOOSE_VEC_H -class MooseVec { +class MooseVec +{ public: MooseVec(const string& path, unsigned int n, const string& dtype); + MooseVec(const Id& id); + MooseVec(const ObjId& oid); const ObjId& obj() const; diff --git a/pybind11/helper.cpp b/pybind11/helper.cpp index a5f63e965d..bed2371476 100644 --- a/pybind11/helper.cpp +++ b/pybind11/helper.cpp @@ -22,6 +22,8 @@ #include "../external/pybind11/include/pybind11/pybind11.h" #include "../external/pybind11/include/pybind11/stl.h" +namespace py = pybind11; + // See // https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#binding-stl-containers // #include "../external/pybind11/include/pybind11/stl_bind.h" @@ -44,8 +46,6 @@ using namespace std; -namespace py = pybind11; - using namespace std; Id initShell(void) @@ -138,14 +138,12 @@ ObjId createIdFromPath(string path, string type, unsigned int numData) return nId; } - bool mooseExists(const string& p) { string path = moose::normalizePath(p); return Id(path) != Id() || path == "/" || path == "/root"; } - ObjId loadModelInternal(const string& fname, const string& modelpath, const string& solverclass = "") { @@ -215,7 +213,6 @@ void mooseMoveObjId(const ObjId& a, const ObjId& b) getShellPtr()->doMove(a.id, b); } - void mooseSetClock(const unsigned int clockId, double dt) { getShellPtr()->doSetClock(clockId, dt); @@ -243,10 +240,9 @@ py::object mooseGetCwe() return py::cast(mooseGetCweId()); } - void mooseSetCwe(const py::object& arg) { - if(py::isinstance(arg)) + if (py::isinstance(arg)) return getShellPtr()->setCwe(ObjId(arg.cast())); return getShellPtr()->setCwe(arg.cast()); } @@ -319,13 +315,14 @@ void mooseStop() getShellPtr()->doStop(); } -ObjId mooseCopy(const py::object& elem, ObjId newParent, string newName, - unsigned int n = 1, bool toGlobal = false, - bool copyExtMsgs = false) +// Id is synonym with Id in previous binding. +MooseVec mooseCopy(const py::object& elem, ObjId newParent, string newName, + unsigned int n = 1, bool toGlobal = false, + bool copyExtMsgs = false) { Id orig = py::cast(elem); - return ObjId(getShellPtr()->doCopy(orig, newParent, newName, n, toGlobal, - copyExtMsgs)); + return MooseVec(getShellPtr()->doCopy(orig, newParent, newName, n, toGlobal, + copyExtMsgs)); } /** diff --git a/pybind11/helper.h b/pybind11/helper.h index f3ffef3e96..f79df006a3 100644 --- a/pybind11/helper.h +++ b/pybind11/helper.h @@ -19,6 +19,8 @@ #include "../shell/Shell.h" +#include "MooseVec.h" + namespace py = pybind11; using namespace std; @@ -134,7 +136,7 @@ inline bool mooseDeleteStr(const string& path) ObjId mooseCreate(const string type, const string& path, unsigned int numdata = 1); -ObjId mooseCopy(const py::object& orig, ObjId newParent, string newName, +MooseVec mooseCopy(const py::object& orig, ObjId newParent, string newName, unsigned int n, bool toGlobal, bool copyExtMsgs); diff --git a/pybind11/pymoose.cpp b/pybind11/pymoose.cpp index 74ebcfaa92..da6a4b94ab 100644 --- a/pybind11/pymoose.cpp +++ b/pybind11/pymoose.cpp @@ -178,6 +178,8 @@ PYBIND11_MODULE(_moose, m) .def("__getitem__", &__Finfo__::getItem) .def("__setitem__", &__Finfo__::setItem); + // A thin wrapper around Id from ../basecode/Id.h . Usually this is shows + // at moose.vec. py::class_(m, "_Id") .def(py::init<>()) .def(py::init())