App: Apply clang format (part 1)

This commit is contained in:
wmayer
2024-11-15 17:43:49 +01:00
committed by wwmayer
parent ee18317e08
commit 4e82a0af48
124 changed files with 6733 additions and 4886 deletions

View File

@@ -76,7 +76,7 @@ Py::Object DocumentObjectPy::getDocument() const
}
}
PyObject* DocumentObjectPy::isAttachedToDocument(PyObject *args)
PyObject* DocumentObjectPy::isAttachedToDocument(PyObject* args)
{
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
@@ -87,27 +87,52 @@ PyObject* DocumentObjectPy::isAttachedToDocument(PyObject *args)
return Py::new_reference_to(Py::Boolean(ok));
}
PyObject* DocumentObjectPy::addProperty(PyObject *args, PyObject *kwd)
PyObject* DocumentObjectPy::addProperty(PyObject* args, PyObject* kwd)
{
char *sType,*sName=nullptr,*sGroup=nullptr,*sDoc=nullptr;
short attr=0;
char *sType, *sName = nullptr, *sGroup = nullptr, *sDoc = nullptr;
short attr = 0;
std::string sDocStr;
PyObject *ro = Py_False, *hd = Py_False;
PyObject* enumVals = nullptr;
const std::array<const char *, 9> kwlist {"type","name","group","doc","attr","read_only","hidden","enum_vals",nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(
args, kwd, "ss|sethO!O!O", kwlist, &sType, &sName, &sGroup, "utf-8",
&sDoc, &attr, &PyBool_Type, &ro, &PyBool_Type, &hd, &enumVals))
const std::array<const char*, 9> kwlist {"type",
"name",
"group",
"doc",
"attr",
"read_only",
"hidden",
"enum_vals",
nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args,
kwd,
"ss|sethO!O!O",
kwlist,
&sType,
&sName,
&sGroup,
"utf-8",
&sDoc,
&attr,
&PyBool_Type,
&ro,
&PyBool_Type,
&hd,
&enumVals)) {
return nullptr;
}
if (sDoc) {
sDocStr = sDoc;
PyMem_Free(sDoc);
}
Property *prop = getDocumentObjectPtr()->
addDynamicProperty(sType,sName,sGroup,sDocStr.c_str(),attr,
Base::asBoolean(ro), Base::asBoolean(hd));
Property* prop = getDocumentObjectPtr()->addDynamicProperty(sType,
sName,
sGroup,
sDocStr.c_str(),
attr,
Base::asBoolean(ro),
Base::asBoolean(hd));
// enum support
auto* propEnum = dynamic_cast<App::PropertyEnumeration*>(prop);
@@ -118,26 +143,28 @@ PyObject* DocumentObjectPy::addProperty(PyObject *args, PyObject *kwd)
return Py::new_reference_to(this);
}
PyObject* DocumentObjectPy::removeProperty(PyObject *args)
PyObject* DocumentObjectPy::removeProperty(PyObject* args)
{
char *sName;
if (!PyArg_ParseTuple(args, "s", &sName))
char* sName;
if (!PyArg_ParseTuple(args, "s", &sName)) {
return nullptr;
}
bool ok = getDocumentObjectPtr()->removeDynamicProperty(sName);
return Py_BuildValue("O", (ok ? Py_True : Py_False));
}
PyObject* DocumentObjectPy::supportedProperties(PyObject *args)
PyObject* DocumentObjectPy::supportedProperties(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
std::vector<Base::Type> ary;
Base::Type::getAllDerivedFrom(App::Property::getClassTypeId(), ary);
Py::List res;
for (auto & it : ary) {
Base::BaseClass *data = static_cast<Base::BaseClass*>(it.createInstance());
for (auto& it : ary) {
Base::BaseClass* data = static_cast<Base::BaseClass*>(it.createInstance());
if (data) {
delete data;
res.append(Py::String(it.getName()));
@@ -146,19 +173,21 @@ PyObject* DocumentObjectPy::supportedProperties(PyObject *args)
return Py::new_reference_to(res);
}
PyObject* DocumentObjectPy::touch(PyObject * args)
PyObject* DocumentObjectPy::touch(PyObject* args)
{
char *propName = nullptr;
if (!PyArg_ParseTuple(args, "|s",&propName))
char* propName = nullptr;
if (!PyArg_ParseTuple(args, "|s", &propName)) {
return nullptr;
if(propName) {
if(!propName[0]) {
}
if (propName) {
if (!propName[0]) {
getDocumentObjectPtr()->touch(true);
Py_Return;
}
auto prop = getDocumentObjectPtr()->getPropertyByName(propName);
if(!prop)
if (!prop) {
throw Py::RuntimeError("Property not found");
}
prop->touch();
Py_Return;
}
@@ -167,18 +196,20 @@ PyObject* DocumentObjectPy::touch(PyObject * args)
Py_Return;
}
PyObject* DocumentObjectPy::purgeTouched(PyObject * args)
PyObject* DocumentObjectPy::purgeTouched(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
getDocumentObjectPtr()->purgeTouched();
Py_Return;
}
PyObject* DocumentObjectPy::enforceRecompute(PyObject * args)
PyObject* DocumentObjectPy::enforceRecompute(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
getDocumentObjectPtr()->enforceRecompute();
Py_Return;
}
@@ -207,13 +238,13 @@ Py::List DocumentObjectPy::getState() const
uptodate = false;
list.append(Py::String("Restore"));
}
if (object->testStatus(App::Expand)){
if (object->testStatus(App::Expand)) {
list.append(Py::String("Expanded"));
}
if (object->testStatus(App::PartialObject)){
if (object->testStatus(App::PartialObject)) {
list.append(Py::String("Partial"));
}
if (object->testStatus(App::ObjImporting)){
if (object->testStatus(App::ObjImporting)) {
list.append(Py::String("Importing"));
}
if (uptodate) {
@@ -225,7 +256,7 @@ Py::List DocumentObjectPy::getState() const
Py::Object DocumentObjectPy::getViewObject() const
{
try {
PyObject *dict = PySys_GetObject("modules");
PyObject* dict = PySys_GetObject("modules");
if (!dict) {
return Py::None();
}
@@ -237,12 +268,13 @@ Py::Object DocumentObjectPy::getViewObject() const
}
// double-check that the module doesn't have a null pointer
Py::Module module(PyImport_ImportModule("FreeCADGui"),true);
Py::Module module(PyImport_ImportModule("FreeCADGui"), true);
if (module.isNull() || !module.hasAttr("getDocument")) {
// in v0.14+, the GUI module can be loaded in console mode (but doesn't have all its document methods)
// in v0.14+, the GUI module can be loaded in console mode (but doesn't have all its
// document methods)
return Py::None();
}
if(!getDocumentObjectPtr()->getDocument()) {
if (!getDocumentObjectPtr()->getDocument()) {
throw Py::RuntimeError("Object has no document");
}
const char* internalName = getDocumentObjectPtr()->getNameInDocument();
@@ -266,7 +298,7 @@ Py::Object DocumentObjectPy::getViewObject() const
return Py::None();
}
// FreeCADGui is loaded, so there must be wrong something else
throw; // re-throw
throw; // re-throw
}
}
@@ -275,8 +307,9 @@ Py::List DocumentObjectPy::getInList() const
Py::List ret;
std::vector<DocumentObject*> list = getDocumentObjectPtr()->getInList();
for (auto It : list)
for (auto It : list) {
ret.append(Py::Object(It->getPyObject(), true));
}
return ret;
}
@@ -287,8 +320,9 @@ Py::List DocumentObjectPy::getInListRecursive() const
try {
std::vector<DocumentObject*> list = getDocumentObjectPtr()->getInListRecursive();
for (auto It : list)
for (auto It : list) {
ret.append(Py::Object(It->getPyObject(), true));
}
}
catch (const Base::Exception& e) {
throw Py::IndexError(e.what());
@@ -301,8 +335,9 @@ Py::List DocumentObjectPy::getOutList() const
Py::List ret;
std::vector<DocumentObject*> list = getDocumentObjectPtr()->getOutList();
for (auto It : list)
for (auto It : list) {
ret.append(Py::Object(It->getPyObject(), true));
}
return ret;
}
@@ -314,8 +349,9 @@ Py::List DocumentObjectPy::getOutListRecursive() const
std::vector<DocumentObject*> list = getDocumentObjectPtr()->getOutListRecursive();
// create the python list for the output
for (auto It : list)
for (auto It : list) {
ret.append(Py::Object(It->getPyObject(), true));
}
}
catch (const Base::Exception& e) {
throw Py::IndexError(e.what());
@@ -324,14 +360,15 @@ Py::List DocumentObjectPy::getOutListRecursive() const
return ret;
}
PyObject* DocumentObjectPy::setExpression(PyObject * args)
PyObject* DocumentObjectPy::setExpression(PyObject* args)
{
char * path = nullptr;
PyObject * expr;
char * comment = nullptr;
char* path = nullptr;
PyObject* expr;
char* comment = nullptr;
if (!PyArg_ParseTuple(args, "sO|s", &path, &expr, &comment))
if (!PyArg_ParseTuple(args, "sO|s", &path, &expr, &comment)) {
return nullptr;
}
App::ObjectIdentifier p(ObjectIdentifier::parse(getDocumentObjectPtr(), path));
@@ -340,10 +377,11 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args)
Py_Return;
}
else if (PyUnicode_Check(expr)) {
const char * exprStr = PyUnicode_AsUTF8(expr);
const char* exprStr = PyUnicode_AsUTF8(expr);
std::shared_ptr<Expression> shared_expr(Expression::parse(getDocumentObjectPtr(), exprStr));
if (shared_expr && comment)
if (shared_expr && comment) {
shared_expr->comment = comment;
}
getDocumentObjectPtr()->setExpression(p, shared_expr);
Py_Return;
@@ -352,22 +390,24 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args)
throw Py::TypeError("String or None expected.");
}
PyObject* DocumentObjectPy::clearExpression(PyObject * args)
PyObject* DocumentObjectPy::clearExpression(PyObject* args)
{
char * path = nullptr;
if (!PyArg_ParseTuple(args, "s", &path))
char* path = nullptr;
if (!PyArg_ParseTuple(args, "s", &path)) {
return nullptr;
}
App::ObjectIdentifier p(ObjectIdentifier::parse(getDocumentObjectPtr(), path));
getDocumentObjectPtr()->clearExpression(p);
Py_Return;
}
PyObject* DocumentObjectPy::evalExpression(PyObject *self, PyObject * args)
PyObject* DocumentObjectPy::evalExpression(PyObject* self, PyObject* args)
{
const char *expr;
if (!PyArg_ParseTuple(args, "s", &expr))
const char* expr;
if (!PyArg_ParseTuple(args, "s", &expr)) {
return nullptr;
}
// HINT:
// The standard behaviour of Python for class methods is to always pass the class
@@ -385,19 +425,23 @@ PyObject* DocumentObjectPy::evalExpression(PyObject *self, PyObject * args)
obj = static_cast<DocumentObjectPy*>(self)->getDocumentObjectPtr();
}
PY_TRY {
PY_TRY
{
std::shared_ptr<Expression> shared_expr(Expression::parse(obj, expr));
if (shared_expr)
if (shared_expr) {
return Py::new_reference_to(shared_expr->getPyValue());
}
Py_Return;
} PY_CATCH
}
PY_CATCH
}
PyObject* DocumentObjectPy::recompute(PyObject *args)
PyObject* DocumentObjectPy::recompute(PyObject* args)
{
PyObject *recursive = Py_False;
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &recursive))
PyObject* recursive = Py_False;
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &recursive)) {
return nullptr;
}
try {
bool ok = getDocumentObjectPtr()->recomputeFeature(Base::asBoolean(recursive));
@@ -408,10 +452,11 @@ PyObject* DocumentObjectPy::recompute(PyObject *args)
}
}
PyObject* DocumentObjectPy::isValid(PyObject *args)
PyObject* DocumentObjectPy::isValid(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
try {
bool ok = getDocumentObjectPtr()->isValid();
@@ -422,10 +467,11 @@ PyObject* DocumentObjectPy::isValid(PyObject *args)
}
}
PyObject* DocumentObjectPy::getStatusString(PyObject *args)
PyObject* DocumentObjectPy::getStatusString(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
try {
Py::String text(getDocumentObjectPtr()->getStatusString());
@@ -436,9 +482,10 @@ PyObject* DocumentObjectPy::getStatusString(PyObject *args)
}
}
PyObject* DocumentObjectPy::getSubObject(PyObject *args, PyObject *keywds)
PyObject* DocumentObjectPy::getSubObject(PyObject* args, PyObject* keywds)
{
enum class ReturnType {
enum class ReturnType
{
PyObject = 0,
DocObject = 1,
DocAndPyObject = 2,
@@ -448,19 +495,33 @@ PyObject* DocumentObjectPy::getSubObject(PyObject *args, PyObject *keywds)
LinkAndMatrix = 6
};
PyObject *obj;
PyObject* obj;
short retType = 0;
PyObject *pyMat = nullptr;
PyObject *doTransform = Py_True;
PyObject* pyMat = nullptr;
PyObject* doTransform = Py_True;
short depth = 0;
static const std::array<const char *, 6> kwlist {"subname", "retType", "matrix", "transform", "depth", nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args, keywds, "O|hO!O!h", kwlist, &obj, &retType, &Base::MatrixPy::Type,
&pyMat, &PyBool_Type, &doTransform, &depth)) {
static const std::array<const char*, 6> kwlist {"subname",
"retType",
"matrix",
"transform",
"depth",
nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args,
keywds,
"O|hO!O!h",
kwlist,
&obj,
&retType,
&Base::MatrixPy::Type,
&pyMat,
&PyBool_Type,
&doTransform,
&depth)) {
return nullptr;
}
if (retType < 0 || static_cast<size_t> (retType) > kwlist.size()) {
if (retType < 0 || static_cast<size_t>(retType) > kwlist.size()) {
PyErr_SetString(PyExc_ValueError, "invalid retType, can only be integer 0~6");
return nullptr;
}
@@ -493,12 +554,15 @@ PyObject* DocumentObjectPy::getSubObject(PyObject *args, PyObject *keywds)
bool transform = Base::asBoolean(doTransform);
struct SubInfo {
App::DocumentObject *sobj{nullptr};
struct SubInfo
{
App::DocumentObject* sobj {nullptr};
Py::Object obj;
Py::Object pyObj;
Base::Matrix4D mat;
explicit SubInfo(const Base::Matrix4D &mat) : mat(mat){}
explicit SubInfo(const Base::Matrix4D& mat)
: mat(mat)
{}
};
Base::Matrix4D mat;
@@ -506,50 +570,66 @@ PyObject* DocumentObjectPy::getSubObject(PyObject *args, PyObject *keywds)
mat = *static_cast<Base::MatrixPy*>(pyMat)->getMatrixPtr();
}
PY_TRY {
PY_TRY
{
std::vector<SubInfo> ret;
for(const auto &sub : subs) {
for (const auto& sub : subs) {
ret.emplace_back(mat);
auto &info = ret.back();
PyObject *pyObj = nullptr;
auto& info = ret.back();
PyObject* pyObj = nullptr;
info.sobj = getDocumentObjectPtr()->getSubObject(sub.c_str(),
retEnum != ReturnType::PyObject &&
retEnum != ReturnType::DocAndPyObject ? nullptr : &pyObj,
&info.mat, transform, depth);
if (pyObj)
info.sobj = getDocumentObjectPtr()->getSubObject(
sub.c_str(),
retEnum != ReturnType::PyObject && retEnum != ReturnType::DocAndPyObject ? nullptr
: &pyObj,
&info.mat,
transform,
depth);
if (pyObj) {
info.pyObj = Py::asObject(pyObj);
if (info.sobj)
}
if (info.sobj) {
info.obj = Py::asObject(info.sobj->getPyObject());
}
}
if (ret.empty())
if (ret.empty()) {
Py_Return;
}
auto getReturnValue = [retEnum, pyMat](SubInfo& ret) -> Py::Object {
if (retEnum == ReturnType::PyObject)
if (retEnum == ReturnType::PyObject) {
return ret.pyObj;
else if (retEnum == ReturnType::DocObject && !pyMat)
}
else if (retEnum == ReturnType::DocObject && !pyMat) {
return ret.obj;
else if (!ret.sobj)
}
else if (!ret.sobj) {
return Py::None();
else if (retEnum == ReturnType::Placement)
}
else if (retEnum == ReturnType::Placement) {
return Py::Placement(Base::Placement(ret.mat));
else if (retEnum == ReturnType::Matrix)
}
else if (retEnum == ReturnType::Matrix) {
return Py::Matrix(ret.mat);
else if (retEnum == ReturnType::LinkAndPlacement || retEnum == ReturnType::LinkAndMatrix) {
}
else if (retEnum == ReturnType::LinkAndPlacement
|| retEnum == ReturnType::LinkAndMatrix) {
ret.sobj->getLinkedObject(true, &ret.mat, false);
if (retEnum == ReturnType::LinkAndPlacement)
if (retEnum == ReturnType::LinkAndPlacement) {
return Py::Placement(Base::Placement(ret.mat));
else
}
else {
return Py::Matrix(ret.mat);
}
}
else {
Py::Tuple rret(retEnum == ReturnType::DocObject ? 2 : 3);
rret.setItem(0, ret.obj);
rret.setItem(1, Py::asObject(new Base::MatrixPy(ret.mat)));
if (retEnum != ReturnType::DocObject)
if (retEnum != ReturnType::DocObject) {
rret.setItem(2, ret.pyObj);
}
return rret;
}
};
@@ -559,7 +639,7 @@ PyObject* DocumentObjectPy::getSubObject(PyObject *args, PyObject *keywds)
}
Py::Tuple tuple(ret.size());
for(size_t i=0; i<ret.size(); ++i) {
for (size_t i = 0; i < ret.size(); ++i) {
tuple.setItem(i, getReturnValue(ret[i]));
}
return Py::new_reference_to(tuple);
@@ -567,62 +647,90 @@ PyObject* DocumentObjectPy::getSubObject(PyObject *args, PyObject *keywds)
PY_CATCH
}
PyObject* DocumentObjectPy::getSubObjectList(PyObject *args) {
const char *subname;
if (!PyArg_ParseTuple(args, "s", &subname))
return nullptr;
Py::List res;
PY_TRY {
for(auto o : getDocumentObjectPtr()->getSubObjectList(subname))
res.append(Py::asObject(o->getPyObject()));
return Py::new_reference_to(res);
}PY_CATCH
}
PyObject* DocumentObjectPy::getSubObjects(PyObject *args) {
int reason = 0;
if (!PyArg_ParseTuple(args, "|i", &reason))
return nullptr;
PY_TRY {
auto names = getDocumentObjectPtr()->getSubObjects(reason);
Py::Tuple pyObjs(names.size());
for(size_t i=0;i<names.size();++i)
pyObjs.setItem(i,Py::String(names[i]));
return Py::new_reference_to(pyObjs);
}PY_CATCH;
}
PyObject* DocumentObjectPy::getLinkedObject(PyObject *args, PyObject *keywds)
PyObject* DocumentObjectPy::getSubObjectList(PyObject* args)
{
PyObject *recursive = Py_True;
PyObject *pyMat = Py_None;
PyObject *transform = Py_True;
short depth = 0;
static const std::array<const char *, 5> kwlist {"recursive","matrix","transform","depth", nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args, keywds, "|O!OO!h", kwlist,
&PyBool_Type, &recursive, &pyMat, &PyBool_Type, &transform, &depth)) {
const char* subname;
if (!PyArg_ParseTuple(args, "s", &subname)) {
return nullptr;
}
Py::List res;
PY_TRY
{
for (auto o : getDocumentObjectPtr()->getSubObjectList(subname)) {
res.append(Py::asObject(o->getPyObject()));
}
return Py::new_reference_to(res);
}
PY_CATCH
}
PyObject* DocumentObjectPy::getSubObjects(PyObject* args)
{
int reason = 0;
if (!PyArg_ParseTuple(args, "|i", &reason)) {
return nullptr;
}
PY_TRY {
Base::PyTypeCheck(&pyMat, &Base::MatrixPy::Type, "expect argument 'matrix' to be of type Base.Matrix");
PY_TRY
{
auto names = getDocumentObjectPtr()->getSubObjects(reason);
Py::Tuple pyObjs(names.size());
for (size_t i = 0; i < names.size(); ++i) {
pyObjs.setItem(i, Py::String(names[i]));
}
return Py::new_reference_to(pyObjs);
}
PY_CATCH;
}
PyObject* DocumentObjectPy::getLinkedObject(PyObject* args, PyObject* keywds)
{
PyObject* recursive = Py_True;
PyObject* pyMat = Py_None;
PyObject* transform = Py_True;
short depth = 0;
static const std::array<const char*, 5> kwlist {"recursive",
"matrix",
"transform",
"depth",
nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args,
keywds,
"|O!OO!h",
kwlist,
&PyBool_Type,
&recursive,
&pyMat,
&PyBool_Type,
&transform,
&depth)) {
return nullptr;
}
PY_TRY
{
Base::PyTypeCheck(&pyMat,
&Base::MatrixPy::Type,
"expect argument 'matrix' to be of type Base.Matrix");
Base::Matrix4D _mat;
Base::Matrix4D *mat = nullptr;
Base::Matrix4D* mat = nullptr;
if (pyMat) {
_mat = *static_cast<Base::MatrixPy*>(pyMat)->getMatrixPtr();
mat = &_mat;
}
auto linked = getDocumentObjectPtr()->getLinkedObject(
Base::asBoolean(recursive), mat, Base::asBoolean(transform), depth);
if (!linked)
auto linked = getDocumentObjectPtr()->getLinkedObject(Base::asBoolean(recursive),
mat,
Base::asBoolean(transform),
depth);
if (!linked) {
linked = getDocumentObjectPtr();
auto pyObj = Py::Object(linked->getPyObject(),true);
}
auto pyObj = Py::Object(linked->getPyObject(), true);
if (mat) {
Py::Tuple ret(2);
ret.setItem(0,pyObj);
ret.setItem(1,Py::asObject(new Base::MatrixPy(*mat)));
ret.setItem(0, pyObj);
ret.setItem(1, Py::asObject(new Base::MatrixPy(*mat)));
return Py::new_reference_to(ret);
}
@@ -631,44 +739,56 @@ PyObject* DocumentObjectPy::getLinkedObject(PyObject *args, PyObject *keywds)
PY_CATCH;
}
PyObject* DocumentObjectPy::isElementVisible(PyObject *args)
PyObject* DocumentObjectPy::isElementVisible(PyObject* args)
{
char *element = nullptr;
if (!PyArg_ParseTuple(args, "s", &element))
char* element = nullptr;
if (!PyArg_ParseTuple(args, "s", &element)) {
return nullptr;
PY_TRY {
}
PY_TRY
{
return Py_BuildValue("h", getDocumentObjectPtr()->isElementVisible(element));
} PY_CATCH;
}
PY_CATCH;
}
PyObject* DocumentObjectPy::setElementVisible(PyObject *args)
PyObject* DocumentObjectPy::setElementVisible(PyObject* args)
{
char *element = nullptr;
PyObject *visible = Py_True;
if (!PyArg_ParseTuple(args, "s|O!", &element, &PyBool_Type, &visible))
char* element = nullptr;
PyObject* visible = Py_True;
if (!PyArg_ParseTuple(args, "s|O!", &element, &PyBool_Type, &visible)) {
return nullptr;
PY_TRY {
return Py_BuildValue("h", getDocumentObjectPtr()->setElementVisible(element, Base::asBoolean(visible)));
} PY_CATCH;
}
PY_TRY
{
return Py_BuildValue(
"h",
getDocumentObjectPtr()->setElementVisible(element, Base::asBoolean(visible)));
}
PY_CATCH;
}
PyObject* DocumentObjectPy::hasChildElement(PyObject *args)
PyObject* DocumentObjectPy::hasChildElement(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
PY_TRY {
return Py_BuildValue("O", getDocumentObjectPtr()->hasChildElement()?Py_True:Py_False);
} PY_CATCH;
}
PY_TRY
{
return Py_BuildValue("O", getDocumentObjectPtr()->hasChildElement() ? Py_True : Py_False);
}
PY_CATCH;
}
PyObject* DocumentObjectPy::getParentGroup(PyObject *args)
PyObject* DocumentObjectPy::getParentGroup(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
try {
auto grp = GroupExtension::getGroupOfObject(getDocumentObjectPtr());
if(!grp) {
if (!grp) {
Py_INCREF(Py_None);
return Py_None;
}
@@ -679,14 +799,15 @@ PyObject* DocumentObjectPy::getParentGroup(PyObject *args)
}
}
PyObject* DocumentObjectPy::getParentGeoFeatureGroup(PyObject *args)
PyObject* DocumentObjectPy::getParentGeoFeatureGroup(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
try {
auto grp = GeoFeatureGroupExtension::getGroupOfObject(getDocumentObjectPtr());
if(!grp) {
if (!grp) {
Py_INCREF(Py_None);
return Py_None;
}
@@ -697,14 +818,15 @@ PyObject* DocumentObjectPy::getParentGeoFeatureGroup(PyObject *args)
}
}
PyObject* DocumentObjectPy::getParent(PyObject *args)
PyObject* DocumentObjectPy::getParent(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
try {
auto grp = getDocumentObjectPtr()->getFirstParent();
if(!grp) {
if (!grp) {
Py_INCREF(Py_None);
return Py_None;
}
@@ -725,15 +847,15 @@ Py::Boolean DocumentObjectPy::getMustExecute() const
}
}
PyObject* DocumentObjectPy::getPathsByOutList(PyObject *args)
PyObject* DocumentObjectPy::getPathsByOutList(PyObject* args)
{
PyObject* o;
if (!PyArg_ParseTuple(args, "O!", &DocumentObjectPy::Type, &o))
if (!PyArg_ParseTuple(args, "O!", &DocumentObjectPy::Type, &o)) {
return nullptr;
}
try {
DocumentObject* target = static_cast<DocumentObjectPy*>
(o)->getDocumentObjectPtr();
DocumentObject* target = static_cast<DocumentObjectPy*>(o)->getDocumentObjectPtr();
auto array = getDocumentObjectPtr()->getPathsByOutList(target);
Py::List list;
for (const auto& it : array) {
@@ -766,100 +888,120 @@ PyObject* DocumentObjectPy::getElementMapVersion(PyObject* args)
Py::String(getDocumentObjectPtr()->getElementMapVersion(prop, Base::asBoolean(restored))));
}
PyObject *DocumentObjectPy::getCustomAttributes(const char* ) const
PyObject* DocumentObjectPy::getCustomAttributes(const char*) const
{
return nullptr;
return nullptr;
}
//remove
int DocumentObjectPy::setCustomAttributes(const char* , PyObject *)
// remove
int DocumentObjectPy::setCustomAttributes(const char*, PyObject*)
{
return 0;
}
Py::Int DocumentObjectPy::getID() const {
Py::Int DocumentObjectPy::getID() const
{
return Py::Int(getDocumentObjectPtr()->getID());
}
Py::Boolean DocumentObjectPy::getRemoving() const {
Py::Boolean DocumentObjectPy::getRemoving() const
{
return {getDocumentObjectPtr()->testStatus(ObjectStatus::Remove)};
}
PyObject *DocumentObjectPy::resolve(PyObject *args)
PyObject* DocumentObjectPy::resolve(PyObject* args)
{
const char *subname;
if (!PyArg_ParseTuple(args, "s",&subname))
const char* subname;
if (!PyArg_ParseTuple(args, "s", &subname)) {
return nullptr;
}
PY_TRY {
PY_TRY
{
std::string elementName;
const char *subElement = nullptr;
App::DocumentObject *parent = nullptr;
auto obj = getDocumentObjectPtr()->resolve(subname,&parent,&elementName,&subElement);
const char* subElement = nullptr;
App::DocumentObject* parent = nullptr;
auto obj = getDocumentObjectPtr()->resolve(subname, &parent, &elementName, &subElement);
Py::Tuple ret(4);
ret.setItem(0,obj?Py::Object(obj->getPyObject(),true):Py::None());
ret.setItem(1,parent?Py::Object(parent->getPyObject(),true):Py::None());
ret.setItem(2,Py::String(elementName.c_str()));
ret.setItem(3,Py::String(subElement?subElement:""));
ret.setItem(0, obj ? Py::Object(obj->getPyObject(), true) : Py::None());
ret.setItem(1, parent ? Py::Object(parent->getPyObject(), true) : Py::None());
ret.setItem(2, Py::String(elementName.c_str()));
ret.setItem(3, Py::String(subElement ? subElement : ""));
return Py::new_reference_to(ret);
} PY_CATCH;
}
PY_CATCH;
Py_Return;
}
PyObject *DocumentObjectPy::resolveSubElement(PyObject *args)
PyObject* DocumentObjectPy::resolveSubElement(PyObject* args)
{
const char *subname;
PyObject *append = Py_False;
const char* subname;
PyObject* append = Py_False;
int type = 0;
if (!PyArg_ParseTuple(args, "s|O!i",&subname,&PyBool_Type,&append,&type))
if (!PyArg_ParseTuple(args, "s|O!i", &subname, &PyBool_Type, &append, &type)) {
return nullptr;
}
PY_TRY {
PY_TRY
{
ElementNamePair elementName;
auto obj = GeoFeature::resolveElement(getDocumentObjectPtr(), subname,elementName,
Base::asBoolean(append), static_cast<GeoFeature::ElementNameType>(type));
auto obj = GeoFeature::resolveElement(getDocumentObjectPtr(),
subname,
elementName,
Base::asBoolean(append),
static_cast<GeoFeature::ElementNameType>(type));
Py::Tuple ret(3);
ret.setItem(0,obj?Py::Object(obj->getPyObject(),true):Py::None());
ret.setItem(1,Py::String(elementName.newName));
ret.setItem(2,Py::String(elementName.oldName));
ret.setItem(0, obj ? Py::Object(obj->getPyObject(), true) : Py::None());
ret.setItem(1, Py::String(elementName.newName));
ret.setItem(2, Py::String(elementName.oldName));
return Py::new_reference_to(ret);
} PY_CATCH;
}
PY_CATCH;
Py_Return;
}
Py::List DocumentObjectPy::getParents() const {
Py::List DocumentObjectPy::getParents() const
{
Py::List ret;
for(auto &v : getDocumentObjectPtr()->getParents())
ret.append(Py::TupleN(Py::Object(v.first->getPyObject(),true),Py::String(v.second)));
for (auto& v : getDocumentObjectPtr()->getParents()) {
ret.append(Py::TupleN(Py::Object(v.first->getPyObject(), true), Py::String(v.second)));
}
return ret;
}
PyObject *DocumentObjectPy::adjustRelativeLinks(PyObject *args) {
PyObject *pyobj;
PyObject *recursive = Py_True;
if (!PyArg_ParseTuple(args, "O!|O",&DocumentObjectPy::Type,&pyobj,&recursive))
PyObject* DocumentObjectPy::adjustRelativeLinks(PyObject* args)
{
PyObject* pyobj;
PyObject* recursive = Py_True;
if (!PyArg_ParseTuple(args, "O!|O", &DocumentObjectPy::Type, &pyobj, &recursive)) {
return nullptr;
PY_TRY {
}
PY_TRY
{
auto obj = static_cast<DocumentObjectPy*>(pyobj)->getDocumentObjectPtr();
auto inList = obj->getInListEx(true);
inList.insert(obj);
std::set<App::DocumentObject *> visited;
return Py::new_reference_to(Py::Boolean(
getDocumentObjectPtr()->adjustRelativeLinks(inList,
Base::asBoolean(recursive) ? &visited : nullptr)));
}PY_CATCH
std::set<App::DocumentObject*> visited;
return Py::new_reference_to(Py::Boolean(getDocumentObjectPtr()->adjustRelativeLinks(
inList,
Base::asBoolean(recursive) ? &visited : nullptr)));
}
PY_CATCH
}
Py::String DocumentObjectPy::getOldLabel() const {
Py::String DocumentObjectPy::getOldLabel() const
{
return {getDocumentObjectPtr()->getOldLabel()};
}
Py::Boolean DocumentObjectPy::getNoTouch() const {
Py::Boolean DocumentObjectPy::getNoTouch() const
{
return {getDocumentObjectPtr()->testStatus(ObjectStatus::NoTouch)};
}
void DocumentObjectPy::setNoTouch(Py::Boolean value) {
getDocumentObjectPtr()->setStatus(ObjectStatus::NoTouch,value.isTrue());
void DocumentObjectPy::setNoTouch(Py::Boolean value)
{
getDocumentObjectPtr()->setStatus(ObjectStatus::NoTouch, value.isTrue());
}