Core: Add getPlacementOf replacing previous getGlobalPlacement logic. (#26059)
* Core: Add getPlacementOf replacing previous getGlobalPlacement logic. * Update src/App/DocumentObject.cpp Co-authored-by: Kacper Donat <kadet1090@gmail.com> * Update DocumentObject.cpp * Fix error when called from python with targetObj == None --------- Co-authored-by: Kacper Donat <kadet1090@gmail.com>
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/MatrixPy.h>
|
||||
#include <Base/PlacementPy.h>
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
|
||||
#include "DocumentObject.h"
|
||||
@@ -1003,3 +1004,32 @@ void DocumentObjectPy::setNoTouch(Py::Boolean value)
|
||||
{
|
||||
getDocumentObjectPtr()->setStatus(ObjectStatus::NoTouch, value.isTrue());
|
||||
}
|
||||
|
||||
PyObject* DocumentObjectPy::getPlacementOf(PyObject* args)
|
||||
{
|
||||
char* subname;
|
||||
PyObject* target = Py_None; // Initialize to None
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|O", &subname, &target)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
App::DocumentObject* targetObj = nullptr;
|
||||
|
||||
// Check if a target was provided and is not None
|
||||
if (target && target != Py_None) {
|
||||
// Now perform the type check manually
|
||||
if (!PyObject_TypeCheck(target, &DocumentObjectPy::Type)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Target argument must be a DocumentObject or None");
|
||||
return nullptr;
|
||||
}
|
||||
targetObj = static_cast<DocumentObjectPy*>(target)->getDocumentObjectPtr();
|
||||
}
|
||||
|
||||
PY_TRY
|
||||
{
|
||||
Base::Placement p = getDocumentObjectPtr()->getPlacementOf(subname, targetObj);
|
||||
return new Base::PlacementPy(new Base::Placement(p));
|
||||
}
|
||||
PY_CATCH
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user