App: Apply clang format (part 1)

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

View File

@@ -21,7 +21,6 @@
***************************************************************************/
#ifndef APP_FEATUREPYTHON_H
#define APP_FEATUREPYTHON_H
@@ -38,10 +37,11 @@ class Property;
class AppExport FeaturePythonImp
{
public:
enum ValueT {
NotImplemented = 0, // not handled
Accepted = 1, // handled and accepted
Rejected = 2 // handled and rejected
enum ValueT
{
NotImplemented = 0, // not handled
Accepted = 1, // handled and accepted
Rejected = 2 // handled and rejected
};
explicit FeaturePythonImp(App::DocumentObject*);
@@ -50,93 +50,95 @@ public:
bool execute();
bool mustExecute() const;
void onBeforeChange(const Property* prop);
bool onBeforeChangeLabel(std::string &newLabel);
bool onBeforeChangeLabel(std::string& newLabel);
void onChanged(const Property* prop);
void onDocumentRestored();
void unsetupObject();
std::string getViewProviderName();
PyObject *getPyObject();
PyObject* getPyObject();
bool getSubObject(App::DocumentObject *&ret, const char *subname, PyObject **pyObj,
Base::Matrix4D *mat, bool transform, int depth) const;
bool getSubObject(App::DocumentObject*& ret,
const char* subname,
PyObject** pyObj,
Base::Matrix4D* mat,
bool transform,
int depth) const;
bool getSubObjects(std::vector<std::string> &ret, int reason) const;
bool getSubObjects(std::vector<std::string>& ret, int reason) const;
bool getLinkedObject(App::DocumentObject *&ret, bool recurse,
Base::Matrix4D *mat, bool transform, int depth) const;
bool getLinkedObject(App::DocumentObject*& ret,
bool recurse,
Base::Matrix4D* mat,
bool transform,
int depth) const;
ValueT canLinkProperties() const;
ValueT allowDuplicateLabel() const;
ValueT redirectSubName(std::ostringstream &ss,
App::DocumentObject *topParent,
App::DocumentObject *child) const;
ValueT redirectSubName(std::ostringstream& ss,
App::DocumentObject* topParent,
App::DocumentObject* child) const;
int canLoadPartial() const;
/// return true to activate tree view group object handling
ValueT hasChildElement() const;
/// Get sub-element visibility
int isElementVisible(const char *) const;
int isElementVisible(const char*) const;
/// Set sub-element visibility
int setElementVisible(const char *, bool);
int setElementVisible(const char*, bool);
bool editProperty(const char *propName);
bool editProperty(const char* propName);
private:
App::DocumentObject* object;
bool has__object__{false};
bool has__object__ {false};
#define FC_PY_FEATURE_PYTHON \
FC_PY_ELEMENT(execute)\
FC_PY_ELEMENT(mustExecute)\
FC_PY_ELEMENT(onBeforeChange)\
FC_PY_ELEMENT(onBeforeChangeLabel)\
FC_PY_ELEMENT(onChanged)\
FC_PY_ELEMENT(onDocumentRestored)\
FC_PY_ELEMENT(unsetupObject)\
FC_PY_ELEMENT(getViewProviderName)\
FC_PY_ELEMENT(getSubObject)\
FC_PY_ELEMENT(getSubObjects)\
FC_PY_ELEMENT(getLinkedObject)\
FC_PY_ELEMENT(canLinkProperties)\
FC_PY_ELEMENT(allowDuplicateLabel)\
FC_PY_ELEMENT(redirectSubName)\
FC_PY_ELEMENT(canLoadPartial)\
FC_PY_ELEMENT(hasChildElement)\
FC_PY_ELEMENT(isElementVisible)\
FC_PY_ELEMENT(setElementVisible)\
FC_PY_ELEMENT(editProperty)\
#define FC_PY_FEATURE_PYTHON \
FC_PY_ELEMENT(execute) \
FC_PY_ELEMENT(mustExecute) \
FC_PY_ELEMENT(onBeforeChange) \
FC_PY_ELEMENT(onBeforeChangeLabel) \
FC_PY_ELEMENT(onChanged) \
FC_PY_ELEMENT(onDocumentRestored) \
FC_PY_ELEMENT(unsetupObject) \
FC_PY_ELEMENT(getViewProviderName) \
FC_PY_ELEMENT(getSubObject) \
FC_PY_ELEMENT(getSubObjects) \
FC_PY_ELEMENT(getLinkedObject) \
FC_PY_ELEMENT(canLinkProperties) \
FC_PY_ELEMENT(allowDuplicateLabel) \
FC_PY_ELEMENT(redirectSubName) \
FC_PY_ELEMENT(canLoadPartial) \
FC_PY_ELEMENT(hasChildElement) \
FC_PY_ELEMENT(isElementVisible) \
FC_PY_ELEMENT(setElementVisible) \
FC_PY_ELEMENT(editProperty)
#define FC_PY_ELEMENT_DEFINE(_name) \
Py::Object py_##_name;
#define FC_PY_ELEMENT_DEFINE(_name) Py::Object py_##_name;
#define FC_PY_ELEMENT_INIT(_name) \
FC_PY_GetCallable(pyobj,#_name,py_##_name);\
if(!py_##_name.isNone()) {\
PyObject *pyRecursive = PyObject_GetAttrString(pyobj, \
"__allow_recursive_" #_name);\
if(!pyRecursive) {\
PyErr_Clear();\
_Flags.set(FlagAllowRecursive_##_name, false);\
}else{\
_Flags.set(FlagAllowRecursive_##_name, PyObject_IsTrue(pyRecursive));\
Py_DECREF(pyRecursive);\
}\
#define FC_PY_ELEMENT_INIT(_name) \
FC_PY_GetCallable(pyobj, #_name, py_##_name); \
if (!py_##_name.isNone()) { \
PyObject* pyRecursive = PyObject_GetAttrString(pyobj, "__allow_recursive_" #_name); \
if (!pyRecursive) { \
PyErr_Clear(); \
_Flags.set(FlagAllowRecursive_##_name, false); \
} \
else { \
_Flags.set(FlagAllowRecursive_##_name, PyObject_IsTrue(pyRecursive)); \
Py_DECREF(pyRecursive); \
} \
}
#define FC_PY_ELEMENT_FLAG(_name) \
FlagCalling_##_name,\
FlagAllowRecursive_##_name,
#define FC_PY_ELEMENT_FLAG(_name) FlagCalling_##_name, FlagAllowRecursive_##_name,
#define _FC_PY_CALL_CHECK(_name,_ret) \
if((!_Flags.test(FlagAllowRecursive_##_name) \
&& _Flags.test(FlagCalling_##_name)) \
|| py_##_name.isNone()) \
{\
_ret;\
}\
#define _FC_PY_CALL_CHECK(_name, _ret) \
if ((!_Flags.test(FlagAllowRecursive_##_name) && _Flags.test(FlagCalling_##_name)) \
|| py_##_name.isNone()) { \
_ret; \
} \
Base::BitsetLocker<Flags> guard(_Flags, FlagCalling_##_name);
#undef FC_PY_ELEMENT
@@ -147,16 +149,16 @@ private:
#undef FC_PY_ELEMENT
#define FC_PY_ELEMENT(_name) FC_PY_ELEMENT_FLAG(_name)
enum Flag {
FC_PY_FEATURE_PYTHON
FlagMax,
enum Flag
{
FC_PY_FEATURE_PYTHON FlagMax,
};
using Flags = std::bitset<FlagMax>;
mutable Flags _Flags;
public:
void init(PyObject *pyobj);
void init(PyObject* pyobj);
};
/**
@@ -164,185 +166,226 @@ public:
* derived class as Python feature -- simply by subclassing.
* @author Werner Mayer
*/
template <class FeatureT>
class FeaturePythonT : public FeatureT
template<class FeatureT>
class FeaturePythonT: public FeatureT
{
PROPERTY_HEADER_WITH_OVERRIDE(App::FeaturePythonT<FeatureT>);
public:
FeaturePythonT() {
ADD_PROPERTY(Proxy,(Py::Object()));
FeaturePythonT()
{
ADD_PROPERTY(Proxy, (Py::Object()));
// cannot move this to the initializer list to avoid warning
imp = new FeaturePythonImp(this);
}
~FeaturePythonT() override {
~FeaturePythonT() override
{
delete imp;
}
/** @name methods override DocumentObject */
//@{
short mustExecute() const override {
if (this->isTouched())
short mustExecute() const override
{
if (this->isTouched()) {
return 1;
}
auto ret = FeatureT::mustExecute();
if(ret) return ret;
return imp->mustExecute()?1:0;
if (ret) {
return ret;
}
return imp->mustExecute() ? 1 : 0;
}
/// recalculate the Feature
DocumentObjectExecReturn *execute() override {
DocumentObjectExecReturn* execute() override
{
try {
bool handled = imp->execute();
if (!handled)
if (!handled) {
return FeatureT::execute();
}
}
catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
return DocumentObject::StdReturn;
}
const char* getViewProviderNameOverride() const override {
const char* getViewProviderNameOverride() const override
{
viewProviderName = imp->getViewProviderName();
if(!viewProviderName.empty())
if (!viewProviderName.empty()) {
return viewProviderName.c_str();
}
return FeatureT::getViewProviderNameOverride();
}
/// returns the type name of the ViewProvider
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return FeatureT::getViewProviderName();
}
App::DocumentObject *getSubObject(const char *subname, PyObject **pyObj,
Base::Matrix4D *mat, bool transform, int depth) const override
App::DocumentObject* getSubObject(const char* subname,
PyObject** pyObj,
Base::Matrix4D* mat,
bool transform,
int depth) const override
{
App::DocumentObject *ret = nullptr;
if(imp->getSubObject(ret,subname,pyObj,mat,transform,depth))
App::DocumentObject* ret = nullptr;
if (imp->getSubObject(ret, subname, pyObj, mat, transform, depth)) {
return ret;
return FeatureT::getSubObject(subname,pyObj,mat,transform,depth);
}
return FeatureT::getSubObject(subname, pyObj, mat, transform, depth);
}
std::vector<std::string> getSubObjects(int reason=0) const override {
std::vector<std::string> getSubObjects(int reason = 0) const override
{
std::vector<std::string> ret;
if(imp->getSubObjects(ret,reason))
if (imp->getSubObjects(ret, reason)) {
return ret;
}
return FeatureT::getSubObjects(reason);
}
App::DocumentObject *getLinkedObject(bool recurse,
Base::Matrix4D *mat, bool transform, int depth) const override
App::DocumentObject*
getLinkedObject(bool recurse, Base::Matrix4D* mat, bool transform, int depth) const override
{
App::DocumentObject *ret = nullptr;
if(imp->getLinkedObject(ret,recurse,mat,transform,depth))
App::DocumentObject* ret = nullptr;
if (imp->getLinkedObject(ret, recurse, mat, transform, depth)) {
return ret;
return FeatureT::getLinkedObject(recurse,mat,transform,depth);
}
return FeatureT::getLinkedObject(recurse, mat, transform, depth);
}
/// return true to activate tree view group object handling
bool hasChildElement() const override {
bool hasChildElement() const override
{
switch (imp->hasChildElement()) {
case FeaturePythonImp::Accepted:
return true;
case FeaturePythonImp::Rejected:
return false;
default:
return FeatureT::hasChildElement();
case FeaturePythonImp::Accepted:
return true;
case FeaturePythonImp::Rejected:
return false;
default:
return FeatureT::hasChildElement();
}
}
/// Get sub-element visibility
int isElementVisible(const char *element) const override {
int isElementVisible(const char* element) const override
{
int ret = imp->isElementVisible(element);
if(ret == -2)
if (ret == -2) {
return FeatureT::isElementVisible(element);
}
return ret;
}
/// Set sub-element visibility
int setElementVisible(const char *element, bool visible) override {
int ret = imp->setElementVisible(element,visible);
if(ret == -2)
return FeatureT::setElementVisible(element,visible);
int setElementVisible(const char* element, bool visible) override
{
int ret = imp->setElementVisible(element, visible);
if (ret == -2) {
return FeatureT::setElementVisible(element, visible);
}
return ret;
}
bool canLinkProperties() const override {
switch (imp->canLinkProperties()) {
case FeaturePythonImp::Accepted:
return true;
case FeaturePythonImp::Rejected:
return false;
default:
return FeatureT::canLinkProperties();
}
}
bool allowDuplicateLabel() const override {
switch (imp->allowDuplicateLabel()) {
case FeaturePythonImp::Accepted:
return true;
case FeaturePythonImp::Rejected:
return false;
default:
return FeatureT::allowDuplicateLabel();
}
}
bool redirectSubName(std::ostringstream &ss,
App::DocumentObject *topParent, App::DocumentObject *child) const override
bool canLinkProperties() const override
{
switch (imp->redirectSubName(ss,topParent,child)) {
case FeaturePythonImp::Accepted:
return true;
case FeaturePythonImp::Rejected:
return false;
default:
return FeatureT::redirectSubName(ss, topParent, child);
switch (imp->canLinkProperties()) {
case FeaturePythonImp::Accepted:
return true;
case FeaturePythonImp::Rejected:
return false;
default:
return FeatureT::canLinkProperties();
}
}
int canLoadPartial() const override {
bool allowDuplicateLabel() const override
{
switch (imp->allowDuplicateLabel()) {
case FeaturePythonImp::Accepted:
return true;
case FeaturePythonImp::Rejected:
return false;
default:
return FeatureT::allowDuplicateLabel();
}
}
bool redirectSubName(std::ostringstream& ss,
App::DocumentObject* topParent,
App::DocumentObject* child) const override
{
switch (imp->redirectSubName(ss, topParent, child)) {
case FeaturePythonImp::Accepted:
return true;
case FeaturePythonImp::Rejected:
return false;
default:
return FeatureT::redirectSubName(ss, topParent, child);
}
}
int canLoadPartial() const override
{
int ret = imp->canLoadPartial();
if(ret>=0)
if (ret >= 0) {
return ret;
}
return FeatureT::canLoadPartial();
}
void editProperty(const char *propName) override {
if (!imp->editProperty(propName))
void editProperty(const char* propName) override
{
if (!imp->editProperty(propName)) {
FeatureT::editProperty(propName);
}
}
PyObject *getPyObject() override {
PyObject* getPyObject() override
{
if (FeatureT::PythonObject.is(Py::_None())) {
// ref counter is set to 1
FeatureT::PythonObject = Py::Object(imp->getPyObject(),true);
FeatureT::PythonObject = Py::Object(imp->getPyObject(), true);
}
return Py::new_reference_to(FeatureT::PythonObject);
}
void setPyObject(PyObject *obj) override {
if (obj)
void setPyObject(PyObject* obj) override
{
if (obj) {
FeatureT::PythonObject = obj;
else
}
else {
FeatureT::PythonObject = Py::None();
}
}
protected:
void onBeforeChange(const Property* prop) override {
void onBeforeChange(const Property* prop) override
{
FeatureT::onBeforeChange(prop);
imp->onBeforeChange(prop);
}
void onBeforeChangeLabel(std::string &newLabel) override{
if(!imp->onBeforeChangeLabel(newLabel))
void onBeforeChangeLabel(std::string& newLabel) override
{
if (!imp->onBeforeChangeLabel(newLabel)) {
FeatureT::onBeforeChangeLabel(newLabel);
}
}
void onChanged(const Property* prop) override {
if(prop == &Proxy)
void onChanged(const Property* prop) override
{
if (prop == &Proxy) {
imp->init(Proxy.getValue().ptr());
}
imp->onChanged(prop);
FeatureT::onChanged(prop);
}
void onDocumentRestored() override {
void onDocumentRestored() override
{
imp->onDocumentRestored();
FeatureT::onDocumentRestored();
}
void unsetupObject() override {
void unsetupObject() override
{
imp->unsetupObject();
FeatureT::unsetupObject();
}
@@ -350,8 +393,8 @@ protected:
public:
FeaturePythonT(const FeaturePythonT&) = delete;
FeaturePythonT(FeaturePythonT&&) = delete;
FeaturePythonT& operator= (const FeaturePythonT&) = delete;
FeaturePythonT& operator= (FeaturePythonT&&) = delete;
FeaturePythonT& operator=(const FeaturePythonT&) = delete;
FeaturePythonT& operator=(FeaturePythonT&&) = delete;
private:
FeaturePythonImp* imp;
@@ -360,9 +403,9 @@ private:
};
// Special Feature-Python classes
using FeaturePython = FeaturePythonT<DocumentObject>;
using GeometryPython = FeaturePythonT<GeoFeature >;
using FeaturePython = FeaturePythonT<DocumentObject>;
using GeometryPython = FeaturePythonT<GeoFeature>;
} //namespace App
} // namespace App
#endif // APP_FEATUREPYTHON_H
#endif // APP_FEATUREPYTHON_H