All: Reformat according to new standard
This commit is contained in:
committed by
Kacper Donat
parent
eafd18dac0
commit
25c3ba7338
@@ -20,7 +20,7 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
# include <sstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Base/Matrix.h>
|
||||
@@ -55,60 +55,71 @@ std::string DocumentPy::representation() const
|
||||
}
|
||||
|
||||
|
||||
PyObject* DocumentPy::show(PyObject *args)
|
||||
PyObject* DocumentPy::show(PyObject* args)
|
||||
{
|
||||
char *psFeatStr;
|
||||
if (!PyArg_ParseTuple(args, "s;Name of the Feature to show have to be given!", &psFeatStr))
|
||||
char* psFeatStr;
|
||||
if (!PyArg_ParseTuple(args, "s;Name of the Feature to show have to be given!", &psFeatStr)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
getDocumentPtr()->setShow(psFeatStr);
|
||||
Py_Return;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::hide(PyObject *args)
|
||||
PyObject* DocumentPy::hide(PyObject* args)
|
||||
{
|
||||
char *psFeatStr;
|
||||
if (!PyArg_ParseTuple(args, "s;Name of the Feature to hide have to be given!", &psFeatStr))
|
||||
char* psFeatStr;
|
||||
if (!PyArg_ParseTuple(args, "s;Name of the Feature to hide have to be given!", &psFeatStr)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
getDocumentPtr()->setHide(psFeatStr);
|
||||
Py_Return;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::setPos(PyObject *args)
|
||||
PyObject* DocumentPy::setPos(PyObject* args)
|
||||
{
|
||||
char *psFeatStr;
|
||||
char* psFeatStr;
|
||||
Base::Matrix4D mat;
|
||||
PyObject *pcMatObj;
|
||||
if (!PyArg_ParseTuple(args, "sO!;Name of the Feature and the transformation matrix have to be given!",
|
||||
&psFeatStr, &(Base::MatrixPy::Type), &pcMatObj))
|
||||
PyObject* pcMatObj;
|
||||
if (!PyArg_ParseTuple(
|
||||
args,
|
||||
"sO!;Name of the Feature and the transformation matrix have to be given!",
|
||||
&psFeatStr,
|
||||
&(Base::MatrixPy::Type),
|
||||
&pcMatObj
|
||||
)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mat = static_cast<Base::MatrixPy*>(pcMatObj)->value();
|
||||
|
||||
PY_TRY {
|
||||
getDocumentPtr()->setPos(psFeatStr,mat);
|
||||
PY_TRY
|
||||
{
|
||||
getDocumentPtr()->setPos(psFeatStr, mat);
|
||||
Py_Return;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::setEdit(PyObject *args)
|
||||
PyObject* DocumentPy::setEdit(PyObject* args)
|
||||
{
|
||||
char *psFeatStr;
|
||||
char* psFeatStr;
|
||||
int mod = 0;
|
||||
char *subname = nullptr;
|
||||
ViewProvider *vp = nullptr;
|
||||
App::DocumentObject *obj = nullptr;
|
||||
char* subname = nullptr;
|
||||
ViewProvider* vp = nullptr;
|
||||
App::DocumentObject* obj = nullptr;
|
||||
|
||||
// by name
|
||||
if (PyArg_ParseTuple(args, "s|is", &psFeatStr,&mod,&subname)) {
|
||||
if (PyArg_ParseTuple(args, "s|is", &psFeatStr, &mod, &subname)) {
|
||||
obj = getDocumentPtr()->getDocument()->getObject(psFeatStr);
|
||||
if (!obj) {
|
||||
PyErr_Format(Base::PyExc_FC_GeneralError, "No such object found in document: '%s'", psFeatStr);
|
||||
@@ -117,112 +128,115 @@ PyObject* DocumentPy::setEdit(PyObject *args)
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
PyObject *pyObj;
|
||||
if (!PyArg_ParseTuple(args, "O|is", &pyObj,&mod,&subname))
|
||||
PyObject* pyObj;
|
||||
if (!PyArg_ParseTuple(args, "O|is", &pyObj, &mod, &subname)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (PyObject_TypeCheck(pyObj,&App::DocumentObjectPy::Type)) {
|
||||
if (PyObject_TypeCheck(pyObj, &App::DocumentObjectPy::Type)) {
|
||||
obj = static_cast<App::DocumentObjectPy*>(pyObj)->getDocumentObjectPtr();
|
||||
}
|
||||
else if (PyObject_TypeCheck(pyObj,&ViewProviderPy::Type)) {
|
||||
else if (PyObject_TypeCheck(pyObj, &ViewProviderPy::Type)) {
|
||||
vp = static_cast<ViewProviderPy*>(pyObj)->getViewProviderPtr();
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError,"Expect the first argument to be string, DocumentObject or ViewObject");
|
||||
PyErr_SetString(
|
||||
PyExc_TypeError,
|
||||
"Expect the first argument to be string, DocumentObject or ViewObject"
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!vp) {
|
||||
if (!obj || !obj->isAttachedToDocument() || !(vp=Application::Instance->getViewProvider(obj))) {
|
||||
PyErr_SetString(PyExc_ValueError,"Invalid document object");
|
||||
if (!obj || !obj->isAttachedToDocument()
|
||||
|| !(vp = Application::Instance->getViewProvider(obj))) {
|
||||
PyErr_SetString(PyExc_ValueError, "Invalid document object");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool ok = getDocumentPtr()->setEdit(vp,mod,subname);
|
||||
bool ok = getDocumentPtr()->setEdit(vp, mod, subname);
|
||||
|
||||
return PyBool_FromLong(ok ? 1 : 0);
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::getInEdit(PyObject *args)
|
||||
PyObject* DocumentPy::getInEdit(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ViewProvider* vp = getDocumentPtr()->getInEdit();
|
||||
if (vp)
|
||||
if (vp) {
|
||||
return vp->getPyObject();
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::resetEdit(PyObject *args)
|
||||
PyObject* DocumentPy::resetEdit(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
getDocumentPtr()->resetEdit();
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::addAnnotation(PyObject *args)
|
||||
PyObject* DocumentPy::addAnnotation(PyObject* args)
|
||||
{
|
||||
char *psAnnoName,*psFileName,*psModName = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "ss|s;Name of the Annotation and a file name have to be given!",
|
||||
&psAnnoName,&psFileName,&psModName))
|
||||
char *psAnnoName, *psFileName, *psModName = nullptr;
|
||||
if (!PyArg_ParseTuple(
|
||||
args,
|
||||
"ss|s;Name of the Annotation and a file name have to be given!",
|
||||
&psAnnoName,
|
||||
&psFileName,
|
||||
&psModName
|
||||
)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
auto pcExt = new ViewProviderExtern();
|
||||
|
||||
pcExt->setModeByFile(psModName ? psModName : "Main", psFileName);
|
||||
pcExt->adjustDocumentName(getDocumentPtr()->getDocument()->getName());
|
||||
getDocumentPtr()->setAnnotationViewProvider(psAnnoName,pcExt);
|
||||
getDocumentPtr()->setAnnotationViewProvider(psAnnoName, pcExt);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::update(PyObject *args)
|
||||
PyObject* DocumentPy::update(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
getDocumentPtr()->onUpdate();
|
||||
Py_Return;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::getObject(PyObject *args)
|
||||
PyObject* DocumentPy::getObject(PyObject* args)
|
||||
{
|
||||
char *sName;
|
||||
if (!PyArg_ParseTuple(args, "s", &sName))
|
||||
char* sName;
|
||||
if (!PyArg_ParseTuple(args, "s", &sName)) {
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
ViewProvider *pcView = getDocumentPtr()->getViewProviderByName(sName);
|
||||
if (pcView)
|
||||
return pcView->getPyObject();
|
||||
else
|
||||
Py_Return;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::activeObject(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
App::DocumentObject *pcFtr = getDocumentPtr()->getDocument()->getActiveObject();
|
||||
if (pcFtr) {
|
||||
ViewProvider *pcView = getDocumentPtr()->getViewProvider(pcFtr);
|
||||
PY_TRY
|
||||
{
|
||||
ViewProvider* pcView = getDocumentPtr()->getViewProviderByName(sName);
|
||||
if (pcView) {
|
||||
return pcView->getPyObject();
|
||||
}
|
||||
else {
|
||||
@@ -232,14 +246,36 @@ PyObject* DocumentPy::activeObject(PyObject *args)
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::activeView(PyObject *args)
|
||||
PyObject* DocumentPy::activeObject(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
Gui::MDIView *pcView = getDocumentPtr()->getActiveView();
|
||||
if (pcView){
|
||||
PY_TRY
|
||||
{
|
||||
App::DocumentObject* pcFtr = getDocumentPtr()->getDocument()->getActiveObject();
|
||||
if (pcFtr) {
|
||||
ViewProvider* pcView = getDocumentPtr()->getViewProvider(pcFtr);
|
||||
return pcView->getPyObject();
|
||||
}
|
||||
else {
|
||||
Py_Return;
|
||||
}
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::activeView(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY
|
||||
{
|
||||
Gui::MDIView* pcView = getDocumentPtr()->getActiveView();
|
||||
if (pcView) {
|
||||
// already incremented in getPyObject().
|
||||
return pcView->getPyObject();
|
||||
}
|
||||
@@ -250,11 +286,12 @@ PyObject* DocumentPy::activeView(PyObject *args)
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::createView(PyObject *args)
|
||||
PyObject* DocumentPy::createView(PyObject* args)
|
||||
{
|
||||
char* sType;
|
||||
if (!PyArg_ParseTuple(args, "s", &sType))
|
||||
if (!PyArg_ParseTuple(args, "s", &sType)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Base::Type type = Base::Type::fromName(sType);
|
||||
if (type.isBad()) {
|
||||
@@ -262,22 +299,25 @@ PyObject* DocumentPy::createView(PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
Gui::MDIView* pcView = getDocumentPtr()->createView(type);
|
||||
if (pcView) {
|
||||
return pcView->getPyObject();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Py_Return;
|
||||
}
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::mdiViewsOfType(PyObject *args) const
|
||||
PyObject* DocumentPy::mdiViewsOfType(PyObject* args) const
|
||||
{
|
||||
char* sType;
|
||||
if (!PyArg_ParseTuple(args, "s", &sType))
|
||||
if (!PyArg_ParseTuple(args, "s", &sType)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Base::Type type = Base::Type::fromName(sType);
|
||||
if (type.isBad()) {
|
||||
@@ -285,60 +325,70 @@ PyObject* DocumentPy::mdiViewsOfType(PyObject *args) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
std::list<Gui::MDIView*> views = getDocumentPtr()->getMDIViewsOfType(type);
|
||||
Py::List list;
|
||||
for (auto it : views)
|
||||
for (auto it : views) {
|
||||
list.append(Py::asObject(it->getPyObject()));
|
||||
}
|
||||
return Py::new_reference_to(list);
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::save(PyObject *args)
|
||||
PyObject* DocumentPy::save(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
bool ok = getDocumentPtr()->save();
|
||||
return Py::new_reference_to(Py::Boolean(ok));
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::saveAs(PyObject *args)
|
||||
PyObject* DocumentPy::saveAs(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
bool ok = getDocumentPtr()->saveAs();
|
||||
return Py::new_reference_to(Py::Boolean(ok));
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::sendMsgToViews(PyObject *args)
|
||||
PyObject* DocumentPy::sendMsgToViews(PyObject* args)
|
||||
{
|
||||
char* msg;
|
||||
if (!PyArg_ParseTuple(args, "s", &msg))
|
||||
if (!PyArg_ParseTuple(args, "s", &msg)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
getDocumentPtr()->sendMsgToViews(msg);
|
||||
Py_Return;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::mergeProject(PyObject *args)
|
||||
PyObject* DocumentPy::mergeProject(PyObject* args)
|
||||
{
|
||||
char* filename;
|
||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
||||
if (!PyArg_ParseTuple(args, "s", &filename)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
Base::FileInfo fi(filename);
|
||||
Base::ifstream str(fi, std::ios::in | std::ios::binary);
|
||||
App::Document* doc = getDocumentPtr()->getDocument();
|
||||
@@ -350,13 +400,14 @@ PyObject* DocumentPy::mergeProject(PyObject *args)
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::toggleTreeItem(PyObject *args)
|
||||
PyObject* DocumentPy::toggleTreeItem(PyObject* args)
|
||||
{
|
||||
PyObject *object;
|
||||
const char *subname = nullptr;
|
||||
PyObject* object;
|
||||
const char* subname = nullptr;
|
||||
int mod = 0;
|
||||
if (!PyArg_ParseTuple(args,"O!|is",&(App::DocumentObjectPy::Type), &object,&mod,&subname))
|
||||
if (!PyArg_ParseTuple(args, "O!|is", &(App::DocumentObjectPy::Type), &object, &mod, &subname)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
App::DocumentObject* Object = static_cast<App::DocumentObjectPy*>(object)->getDocumentObjectPtr();
|
||||
App::DocumentObject* parent = nullptr;
|
||||
@@ -372,9 +423,11 @@ PyObject* DocumentPy::toggleTreeItem(PyObject *args)
|
||||
}
|
||||
|
||||
// get the gui document of the Assembly Item
|
||||
//ActiveAppDoc = Item->getDocument();
|
||||
//ActiveGuiDoc = Gui::Application::Instance->getDocument(getDocumentPtr());
|
||||
auto ActiveVp = dynamic_cast<Gui::ViewProviderDocumentObject*>(getDocumentPtr()->getViewProvider(Object));
|
||||
// ActiveAppDoc = Item->getDocument();
|
||||
// ActiveGuiDoc = Gui::Application::Instance->getDocument(getDocumentPtr());
|
||||
auto ActiveVp = dynamic_cast<Gui::ViewProviderDocumentObject*>(
|
||||
getDocumentPtr()->getViewProvider(Object)
|
||||
);
|
||||
switch (mod) {
|
||||
case 0:
|
||||
getDocumentPtr()->signalExpandObject(*ActiveVp, TreeItemMode::ToggleItem, parent, subname);
|
||||
@@ -396,23 +449,26 @@ PyObject* DocumentPy::toggleTreeItem(PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::scrollToTreeItem(PyObject *args)
|
||||
PyObject* DocumentPy::scrollToTreeItem(PyObject* args)
|
||||
{
|
||||
PyObject *view;
|
||||
if (!PyArg_ParseTuple(args,"O!",&(Gui::ViewProviderDocumentObjectPy::Type), &view))
|
||||
PyObject* view;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(Gui::ViewProviderDocumentObjectPy::Type), &view)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Gui::ViewProviderDocumentObject* vp = static_cast<ViewProviderDocumentObjectPy*>
|
||||
(view)->getViewProviderDocumentObjectPtr();
|
||||
Gui::ViewProviderDocumentObject* vp
|
||||
= static_cast<ViewProviderDocumentObjectPy*>(view)->getViewProviderDocumentObjectPtr();
|
||||
getDocumentPtr()->signalScrollToObject(*vp);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::toggleInSceneGraph(PyObject *args) {
|
||||
PyObject *view;
|
||||
if (!PyArg_ParseTuple(args,"O!",&(Gui::ViewProviderPy::Type), &view))
|
||||
PyObject* DocumentPy::toggleInSceneGraph(PyObject* args)
|
||||
{
|
||||
PyObject* view;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(Gui::ViewProviderPy::Type), &view)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Gui::ViewProvider* vp = static_cast<ViewProviderPy*>(view)->getViewProviderPtr();
|
||||
getDocumentPtr()->toggleInSceneGraph(vp);
|
||||
@@ -422,9 +478,9 @@ PyObject* DocumentPy::toggleInSceneGraph(PyObject *args) {
|
||||
|
||||
Py::Object DocumentPy::getActiveObject() const
|
||||
{
|
||||
App::DocumentObject *object = getDocumentPtr()->getDocument()->getActiveObject();
|
||||
App::DocumentObject* object = getDocumentPtr()->getDocument()->getActiveObject();
|
||||
if (object) {
|
||||
ViewProvider *viewObj = getDocumentPtr()->getViewProvider(object);
|
||||
ViewProvider* viewObj = getDocumentPtr()->getViewProvider(object);
|
||||
return Py::Object(viewObj->getPyObject(), true);
|
||||
}
|
||||
else {
|
||||
@@ -439,7 +495,7 @@ void DocumentPy::setActiveObject(Py::Object /*arg*/)
|
||||
|
||||
Py::Object DocumentPy::getActiveView() const
|
||||
{
|
||||
Gui::MDIView *view = getDocumentPtr()->getActiveView();
|
||||
Gui::MDIView* view = getDocumentPtr()->getActiveView();
|
||||
if (view) {
|
||||
// already incremented in getPyObject().
|
||||
return Py::Object(view->getPyObject(), true);
|
||||
@@ -456,7 +512,7 @@ void DocumentPy::setActiveView(Py::Object /*arg*/)
|
||||
|
||||
Py::Object DocumentPy::getDocument() const
|
||||
{
|
||||
App::Document *doc = getDocumentPtr()->getDocument();
|
||||
App::Document* doc = getDocumentPtr()->getDocument();
|
||||
if (doc) {
|
||||
// already incremented in getPyObject().
|
||||
return Py::Object(doc->getPyObject(), true);
|
||||
@@ -468,47 +524,56 @@ Py::Object DocumentPy::getDocument() const
|
||||
|
||||
Py::Object DocumentPy::getEditingTransform() const
|
||||
{
|
||||
return Py::asObject(new Base::MatrixPy(new Base::Matrix4D(
|
||||
getDocumentPtr()->getEditingTransform())));
|
||||
return Py::asObject(
|
||||
new Base::MatrixPy(new Base::Matrix4D(getDocumentPtr()->getEditingTransform()))
|
||||
);
|
||||
}
|
||||
|
||||
void DocumentPy::setEditingTransform(Py::Object arg)
|
||||
{
|
||||
if (!PyObject_TypeCheck(arg.ptr(),&Base::MatrixPy::Type))
|
||||
if (!PyObject_TypeCheck(arg.ptr(), &Base::MatrixPy::Type)) {
|
||||
throw Py::TypeError("Expecting type of matrix");
|
||||
}
|
||||
|
||||
getDocumentPtr()->setEditingTransform(
|
||||
*static_cast<Base::MatrixPy*>(arg.ptr())->getMatrixPtr());
|
||||
getDocumentPtr()->setEditingTransform(*static_cast<Base::MatrixPy*>(arg.ptr())->getMatrixPtr());
|
||||
}
|
||||
|
||||
Py::Object DocumentPy::getInEditInfo() const {
|
||||
ViewProviderDocumentObject *vp = nullptr;
|
||||
std::string subname,subelement;
|
||||
Py::Object DocumentPy::getInEditInfo() const
|
||||
{
|
||||
ViewProviderDocumentObject* vp = nullptr;
|
||||
std::string subname, subelement;
|
||||
int mode = 0;
|
||||
getDocumentPtr()->getInEdit(&vp,&subname,&mode,&subelement);
|
||||
if (!vp || !vp->getObject() || !vp->getObject()->isAttachedToDocument())
|
||||
getDocumentPtr()->getInEdit(&vp, &subname, &mode, &subelement);
|
||||
if (!vp || !vp->getObject() || !vp->getObject()->isAttachedToDocument()) {
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
return Py::TupleN(Py::Object(vp->getObject()->getPyObject(),true),
|
||||
Py::String(subname),Py::String(subelement),Py::Long(mode));
|
||||
return Py::TupleN(
|
||||
Py::Object(vp->getObject()->getPyObject(), true),
|
||||
Py::String(subname),
|
||||
Py::String(subelement),
|
||||
Py::Long(mode)
|
||||
);
|
||||
}
|
||||
|
||||
void DocumentPy::setInEditInfo(Py::Object arg)
|
||||
{
|
||||
PyObject *pyobj;
|
||||
const char *subname;
|
||||
if (!PyArg_ParseTuple(arg.ptr(), "O!s", &Gui::ViewProviderDocumentObjectPy::Type,
|
||||
&pyobj, &subname))
|
||||
PyObject* pyobj;
|
||||
const char* subname;
|
||||
if (!PyArg_ParseTuple(arg.ptr(), "O!s", &Gui::ViewProviderDocumentObjectPy::Type, &pyobj, &subname)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
getDocumentPtr()->setInEdit(static_cast<ViewProviderDocumentObjectPy*>(
|
||||
pyobj)->getViewProviderDocumentObjectPtr(),subname);
|
||||
getDocumentPtr()->setInEdit(
|
||||
static_cast<ViewProviderDocumentObjectPy*>(pyobj)->getViewProviderDocumentObjectPtr(),
|
||||
subname
|
||||
);
|
||||
}
|
||||
|
||||
Py::Long DocumentPy::getEditMode() const
|
||||
{
|
||||
int mode = -1;
|
||||
getDocumentPtr()->getInEdit(nullptr,nullptr,&mode);
|
||||
getDocumentPtr()->getInEdit(nullptr, nullptr, &mode);
|
||||
|
||||
return Py::Long(mode);
|
||||
}
|
||||
@@ -534,7 +599,8 @@ Py::List DocumentPy::getTreeRootObjects() const
|
||||
Py::List res;
|
||||
|
||||
for (auto obj : objs) {
|
||||
//Note: Here we must force the Py::Object to own this Python object as getPyObject() increments the counter
|
||||
// Note: Here we must force the Py::Object to own this Python object as getPyObject()
|
||||
// increments the counter
|
||||
res.append(Py::Object(obj->getPyObject(), true));
|
||||
}
|
||||
|
||||
@@ -542,7 +608,7 @@ Py::List DocumentPy::getTreeRootObjects() const
|
||||
}
|
||||
|
||||
|
||||
PyObject *DocumentPy::getCustomAttributes(const char* attr) const
|
||||
PyObject* DocumentPy::getCustomAttributes(const char* attr) const
|
||||
{
|
||||
// Note: Here we want to return only a document object if its
|
||||
// name matches 'attr'. However, it is possible to have an object
|
||||
@@ -550,13 +616,15 @@ PyObject *DocumentPy::getCustomAttributes(const char* attr) const
|
||||
// wise it wouldn't be possible to address this attribute any more.
|
||||
// The object must then be addressed by the getObject() method directly.
|
||||
if (!this->ob_type->tp_dict) {
|
||||
if (PyType_Ready(this->ob_type) < 0)
|
||||
if (PyType_Ready(this->ob_type) < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* item = PyDict_GetItemString(this->ob_type->tp_dict, attr);
|
||||
if (item)
|
||||
if (item) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// search for an object with this name
|
||||
ViewProvider* obj = getDocumentPtr()->getViewProviderByName(attr);
|
||||
@@ -564,7 +632,7 @@ PyObject *DocumentPy::getCustomAttributes(const char* attr) const
|
||||
return (obj ? obj->getPyObject() : nullptr);
|
||||
}
|
||||
|
||||
int DocumentPy::setCustomAttributes(const char* attr, PyObject *)
|
||||
int DocumentPy::setCustomAttributes(const char* attr, PyObject*)
|
||||
{
|
||||
// Note: Here we want to return only a document object if its
|
||||
// name matches 'attr'. However, it is possible to have an object
|
||||
@@ -572,19 +640,20 @@ int DocumentPy::setCustomAttributes(const char* attr, PyObject *)
|
||||
// wise it wouldn't be possible to address this attribute any more.
|
||||
// The object must then be addressed by the getObject() method directly.
|
||||
if (!this->ob_type->tp_dict) {
|
||||
if (PyType_Ready(this->ob_type) < 0)
|
||||
if (PyType_Ready(this->ob_type) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* item = PyDict_GetItemString(this->ob_type->tp_dict, attr);
|
||||
if (item)
|
||||
if (item) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ViewProvider* obj = getDocumentPtr()->getViewProviderByName(attr);
|
||||
if (obj) {
|
||||
std::stringstream str;
|
||||
str << "'Document' object attribute '" << attr
|
||||
<< "' must not be set this way" << std::ends;
|
||||
str << "'Document' object attribute '" << attr << "' must not be set this way" << std::ends;
|
||||
throw Py::AttributeError(str.str());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user