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

@@ -38,139 +38,172 @@ using namespace App;
EXTENSION_PROPERTY_SOURCE(App::OriginGroupExtension, App::GeoFeatureGroupExtension)
OriginGroupExtension::OriginGroupExtension () {
OriginGroupExtension::OriginGroupExtension()
{
initExtensionType(OriginGroupExtension::getExtensionClassTypeId());
EXTENSION_ADD_PROPERTY_TYPE ( Origin, (nullptr), 0, App::Prop_Hidden, "Origin linked to the group" );
EXTENSION_ADD_PROPERTY_TYPE(Origin,
(nullptr),
0,
App::Prop_Hidden,
"Origin linked to the group");
Origin.setScope(LinkScope::Child);
}
OriginGroupExtension::~OriginGroupExtension () = default;
OriginGroupExtension::~OriginGroupExtension() = default;
App::Origin *OriginGroupExtension::getOrigin () const {
App::DocumentObject *originObj = Origin.getValue ();
App::Origin* OriginGroupExtension::getOrigin() const
{
App::DocumentObject* originObj = Origin.getValue();
if ( !originObj ) {
if (!originObj) {
std::stringstream err;
err << "Can't find Origin for \"" << getExtendedObject()->getFullName () << "\"";
throw Base::RuntimeError ( err.str().c_str () );
} else if (! originObj->isDerivedFrom ( App::Origin::getClassTypeId() ) ) {
err << "Can't find Origin for \"" << getExtendedObject()->getFullName() << "\"";
throw Base::RuntimeError(err.str().c_str());
}
else if (!originObj->isDerivedFrom(App::Origin::getClassTypeId())) {
std::stringstream err;
err << "Bad object \"" << originObj->getFullName () << "\"(" << originObj->getTypeId().getName()
<< ") linked to the Origin of \"" << getExtendedObject()->getFullName () << "\"";
throw Base::RuntimeError ( err.str().c_str () );
} else {
return static_cast<App::Origin *> ( originObj );
err << "Bad object \"" << originObj->getFullName() << "\"("
<< originObj->getTypeId().getName() << ") linked to the Origin of \""
<< getExtendedObject()->getFullName() << "\"";
throw Base::RuntimeError(err.str().c_str());
}
else {
return static_cast<App::Origin*>(originObj);
}
}
bool OriginGroupExtension::extensionGetSubObject(DocumentObject *&ret, const char *subname,
PyObject **pyObj, Base::Matrix4D *mat, bool transform, int depth) const
bool OriginGroupExtension::extensionGetSubObject(DocumentObject*& ret,
const char* subname,
PyObject** pyObj,
Base::Matrix4D* mat,
bool transform,
int depth) const
{
App::DocumentObject *originObj = Origin.getValue ();
const char *dot;
if(originObj && originObj->isAttachedToDocument() &&
subname && (dot=strchr(subname,'.')))
{
App::DocumentObject* originObj = Origin.getValue();
const char* dot;
if (originObj && originObj->isAttachedToDocument() && subname && (dot = strchr(subname, '.'))) {
bool found;
if(subname[0] == '$')
found = std::string(subname+1,dot)==originObj->Label.getValue();
else
found = std::string(subname,dot)==originObj->getNameInDocument();
if(found) {
if(mat && transform)
if (subname[0] == '$') {
found = std::string(subname + 1, dot) == originObj->Label.getValue();
}
else {
found = std::string(subname, dot) == originObj->getNameInDocument();
}
if (found) {
if (mat && transform) {
*mat *= const_cast<OriginGroupExtension*>(this)->placement().getValue().toMatrix();
ret = originObj->getSubObject(dot+1,pyObj,mat,true,depth+1);
}
ret = originObj->getSubObject(dot + 1, pyObj, mat, true, depth + 1);
return true;
}
}
return GeoFeatureGroupExtension::extensionGetSubObject(ret,subname,pyObj,mat,transform,depth);
return GeoFeatureGroupExtension::extensionGetSubObject(ret,
subname,
pyObj,
mat,
transform,
depth);
}
App::DocumentObject *OriginGroupExtension::getGroupOfObject (const DocumentObject* obj) {
App::DocumentObject* OriginGroupExtension::getGroupOfObject(const DocumentObject* obj)
{
if(!obj)
if (!obj) {
return nullptr;
}
bool isOriginFeature = obj->isDerivedFrom(App::OriginFeature::getClassTypeId());
auto list = obj->getInList();
for (auto o : list) {
if(o->hasExtension(App::OriginGroupExtension::getExtensionClassTypeId()))
if (o->hasExtension(App::OriginGroupExtension::getExtensionClassTypeId())) {
return o;
}
else if (isOriginFeature && o->isDerivedFrom(App::Origin::getClassTypeId())) {
auto result = getGroupOfObject(o);
if(result)
if (result) {
return result;
}
}
}
return nullptr;
}
short OriginGroupExtension::extensionMustExecute() {
if (Origin.isTouched ()) {
short OriginGroupExtension::extensionMustExecute()
{
if (Origin.isTouched()) {
return 1;
} else {
}
else {
return GeoFeatureGroupExtension::extensionMustExecute();
}
}
App::DocumentObjectExecReturn *OriginGroupExtension::extensionExecute() {
try { // try to find all base axis and planes in the origin
getOrigin ();
} catch (const Base::Exception &ex) {
//getExtendedObject()->setError ();
return new App::DocumentObjectExecReturn ( ex.what () );
App::DocumentObjectExecReturn* OriginGroupExtension::extensionExecute()
{
try { // try to find all base axis and planes in the origin
getOrigin();
}
catch (const Base::Exception& ex) {
// getExtendedObject()->setError ();
return new App::DocumentObjectExecReturn(ex.what());
}
return GeoFeatureGroupExtension::extensionExecute ();
return GeoFeatureGroupExtension::extensionExecute();
}
App::DocumentObject *OriginGroupExtension::getLocalizedOrigin(App::Document *doc) {
App::DocumentObject *originObject = doc->addObject ( "App::Origin", "Origin" );
App::DocumentObject* OriginGroupExtension::getLocalizedOrigin(App::Document* doc)
{
App::DocumentObject* originObject = doc->addObject("App::Origin", "Origin");
QByteArray byteArray = tr("Origin").toUtf8();
originObject->Label.setValue(byteArray.constData());
return originObject;
}
void OriginGroupExtension::onExtendedSetupObject () {
App::Document *doc = getExtendedObject()->getDocument ();
void OriginGroupExtension::onExtendedSetupObject()
{
App::Document* doc = getExtendedObject()->getDocument();
App::DocumentObject *originObj = getLocalizedOrigin(doc);
App::DocumentObject* originObj = getLocalizedOrigin(doc);
assert ( originObj && originObj->isDerivedFrom ( App::Origin::getClassTypeId () ) );
Origin.setValue (originObj);
assert(originObj && originObj->isDerivedFrom(App::Origin::getClassTypeId()));
Origin.setValue(originObj);
GeoFeatureGroupExtension::onExtendedSetupObject ();
GeoFeatureGroupExtension::onExtendedSetupObject();
}
void OriginGroupExtension::onExtendedUnsetupObject () {
App::DocumentObject *origin = Origin.getValue ();
if (origin && !origin->isRemoving ()) {
origin->getDocument ()->removeObject (origin->getNameInDocument());
void OriginGroupExtension::onExtendedUnsetupObject()
{
App::DocumentObject* origin = Origin.getValue();
if (origin && !origin->isRemoving()) {
origin->getDocument()->removeObject(origin->getNameInDocument());
}
GeoFeatureGroupExtension::onExtendedUnsetupObject ();
GeoFeatureGroupExtension::onExtendedUnsetupObject();
}
void OriginGroupExtension::extensionOnChanged(const Property* p) {
if(p == &Origin) {
App::DocumentObject *owner = getExtendedObject();
App::DocumentObject *origin = Origin.getValue();
void OriginGroupExtension::extensionOnChanged(const Property* p)
{
if (p == &Origin) {
App::DocumentObject* owner = getExtendedObject();
App::DocumentObject* origin = Origin.getValue();
// Document::Importing indicates the object is being imported (i.e.
// copied). So check the Origin ownership here to prevent copy without
// dependency
if (origin && owner && owner->getDocument()
&& owner->getDocument()->testStatus(Document::Importing)) {
&& owner->getDocument()->testStatus(Document::Importing)) {
for (auto o : origin->getInList()) {
if(o != owner && o->hasExtension(App::OriginGroupExtension::getExtensionClassTypeId())) {
App::Document *document = owner->getDocument();
// Temporarily reset 'Restoring' status to allow document to auto label new objects
Base::ObjectStatusLocker<Document::Status, Document> guard(
Document::Restoring, document, false);
if (o != owner
&& o->hasExtension(App::OriginGroupExtension::getExtensionClassTypeId())) {
App::Document* document = owner->getDocument();
// Temporarily reset 'Restoring' status to allow document to auto label new
// objects
Base::ObjectStatusLocker<Document::Status, Document> guard(Document::Restoring,
document,
false);
Origin.setValue(getLocalizedOrigin(document));
FC_WARN("Reset origin in " << owner->getFullName());
return;
@@ -183,83 +216,99 @@ void OriginGroupExtension::extensionOnChanged(const Property* p) {
void OriginGroupExtension::relinkToOrigin(App::DocumentObject* obj)
{
//we get all links and replace the origin objects if needed (subnames need not to change, they
//would stay the same)
std::vector< App::DocumentObject* > result;
// we get all links and replace the origin objects if needed (subnames need not to change, they
// would stay the same)
std::vector<App::DocumentObject*> result;
std::vector<App::Property*> list;
obj->getPropertyList(list);
for(App::Property* prop : list) {
if(prop->isDerivedFrom<App::PropertyLink>()) {
for (App::Property* prop : list) {
if (prop->isDerivedFrom<App::PropertyLink>()) {
auto p = static_cast<App::PropertyLink*>(prop);
if(!p->getValue() || !p->getValue()->isDerivedFrom(App::OriginFeature::getClassTypeId()))
if (!p->getValue()
|| !p->getValue()->isDerivedFrom(App::OriginFeature::getClassTypeId())) {
continue;
}
p->setValue(getOrigin()->getOriginFeature(static_cast<OriginFeature*>(p->getValue())->Role.getValue()));
p->setValue(getOrigin()->getOriginFeature(
static_cast<OriginFeature*>(p->getValue())->Role.getValue()));
}
else if(prop->isDerivedFrom<App::PropertyLinkList>()) {
else if (prop->isDerivedFrom<App::PropertyLinkList>()) {
auto p = static_cast<App::PropertyLinkList*>(prop);
auto vec = p->getValues();
std::vector<App::DocumentObject*> result;
bool changed = false;
for(App::DocumentObject* o : vec) {
if(!o || !o->isDerivedFrom(App::OriginFeature::getClassTypeId()))
for (App::DocumentObject* o : vec) {
if (!o || !o->isDerivedFrom(App::OriginFeature::getClassTypeId())) {
result.push_back(o);
}
else {
result.push_back(getOrigin()->getOriginFeature(static_cast<OriginFeature*>(o)->Role.getValue()));
result.push_back(getOrigin()->getOriginFeature(
static_cast<OriginFeature*>(o)->Role.getValue()));
changed = true;
}
}
if(changed)
if (changed) {
static_cast<App::PropertyLinkList*>(prop)->setValues(result);
}
}
else if(prop->isDerivedFrom<App::PropertyLinkSub>()) {
else if (prop->isDerivedFrom<App::PropertyLinkSub>()) {
auto p = static_cast<App::PropertyLinkSub*>(prop);
if(!p->getValue() || !p->getValue()->isDerivedFrom(App::OriginFeature::getClassTypeId()))
if (!p->getValue()
|| !p->getValue()->isDerivedFrom(App::OriginFeature::getClassTypeId())) {
continue;
}
std::vector<std::string> subValues = p->getSubValues();
p->setValue(getOrigin()->getOriginFeature(static_cast<OriginFeature*>(p->getValue())->Role.getValue()), subValues);
p->setValue(getOrigin()->getOriginFeature(
static_cast<OriginFeature*>(p->getValue())->Role.getValue()),
subValues);
}
else if(prop->isDerivedFrom<App::PropertyLinkSubList>()) {
else if (prop->isDerivedFrom<App::PropertyLinkSubList>()) {
auto p = static_cast<App::PropertyLinkSubList*>(prop);
auto vec = p->getSubListValues();
bool changed = false;
for(auto &v : vec) {
if(v.first && v.first->isDerivedFrom(App::OriginFeature::getClassTypeId())) {
v.first = getOrigin()->getOriginFeature(static_cast<OriginFeature*>(v.first)->Role.getValue());
for (auto& v : vec) {
if (v.first && v.first->isDerivedFrom(App::OriginFeature::getClassTypeId())) {
v.first = getOrigin()->getOriginFeature(
static_cast<OriginFeature*>(v.first)->Role.getValue());
changed = true;
}
}
if(changed)
if (changed) {
p->setSubListValues(vec);
}
}
}
}
std::vector< DocumentObject* > OriginGroupExtension::addObjects(std::vector<DocumentObject*> objs) {
std::vector<DocumentObject*> OriginGroupExtension::addObjects(std::vector<DocumentObject*> objs)
{
for(auto obj : objs)
for (auto obj : objs) {
relinkToOrigin(obj);
}
return App::GeoFeatureGroupExtension::addObjects(objs);
}
bool OriginGroupExtension::hasObject(const DocumentObject* obj, bool recursive) const {
bool OriginGroupExtension::hasObject(const DocumentObject* obj, bool recursive) const
{
if(Origin.getValue() && (obj == getOrigin() || getOrigin()->hasObject(obj)))
if (Origin.getValue() && (obj == getOrigin() || getOrigin()->hasObject(obj))) {
return true;
}
return App::GroupExtension::hasObject(obj, recursive);
}
// Python feature ---------------------------------------------------------
namespace App {
namespace App
{
EXTENSION_PROPERTY_SOURCE_TEMPLATE(App::OriginGroupExtensionPython, App::OriginGroupExtension)
// explicit template instantiation
template class AppExport ExtensionPythonT<GroupExtensionPythonT<OriginGroupExtension>>;
}
} // namespace App