Toponaming: Transfer in getLinksTo

This commit is contained in:
Zheng, Lei
2024-07-18 09:51:42 -04:00
committed by bgbsww
parent 0bddc51805
commit c9232b141a
8 changed files with 228 additions and 13 deletions

View File

@@ -31,6 +31,7 @@
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/DocumentObserver.h>
#include <App/Expression.h>
#include <App/ExpressionParser.h>
#include <App/ExpressionVisitors.h>
@@ -2267,3 +2268,50 @@ bool PropertySheet::hasSpan() const
{
return !mergedCells.empty();
}
void PropertySheet::getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
App::DocumentObject* obj,
const char* subname,
bool all) const
{
Expression::DepOption option =
all ? Expression::DepOption::DepAll : Expression::DepOption::DepNormal;
App::SubObjectT objT(obj, subname);
auto sobj = objT.getSubObject();
auto subElement = objT.getOldElementName();
auto owner = Base::freecad_dynamic_cast<App::DocumentObject>(getContainer());
for (const auto& v : data) {
if (auto expr = v.second->getExpression()) {
const auto& deps = expr->getDeps(option);
auto it = deps.find(obj);
if (it == deps.end()) {
continue;
}
for (auto& dep : it->second) {
if (!subname) {
identifiers.emplace_back(owner, v.first.toString().c_str());
break;
}
bool found = false;
for (const auto& path : dep.second) {
if (path.getSubObjectName() == subname) {
identifiers.emplace_back(owner, v.first.toString().c_str());
found = true;
break;
}
App::SubObjectT sobjT(obj, path.getSubObjectName().c_str());
if (sobjT.getSubObject() == sobj && sobjT.getOldElementName() == subElement) {
identifiers.emplace_back(owner, v.first.toString().c_str());
found = true;
break;
}
}
if (found) {
break;
}
}
}
}
}