Skip to content

Commit

Permalink
Merge pull request FreeCAD#15501 from bgbsww/bgbsww-toponamingSaveRes…
Browse files Browse the repository at this point in the history
…tore4

Toponaming: Transfer in getLinksTo
  • Loading branch information
chennes authored Jul 22, 2024
2 parents 4beef5e + 97473a8 commit 3fa339e
Show file tree
Hide file tree
Showing 13 changed files with 536 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/App/GeoFeatureGroupExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ bool GeoFeatureGroupExtension::extensionGetSubObject(DocumentObject *&ret, const
*mat *= const_cast<GeoFeatureGroupExtension*>(this)->placement().getValue().toMatrix();
}else if((dot=strchr(subname,'.'))) {
if(subname[0]!='$')
ret = Group.find(std::string(subname,dot));
ret = Group.findUsingMap(std::string(subname,dot));
else{
std::string name = std::string(subname+1,dot);
for(auto child : Group.getValues()) {
Expand Down
2 changes: 1 addition & 1 deletion src/App/GroupExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ bool GroupExtension::extensionGetSubObject(DocumentObject *&ret, const char *sub
if(!dot)
return false;
if(subname[0]!='$')
ret = Group.find(std::string(subname,dot));
ret = Group.findUsingMap(std::string(subname,dot));
else{
std::string name = std::string(subname+1,dot);
for(auto child : Group.getValues()) {
Expand Down
2 changes: 1 addition & 1 deletion src/App/Link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ int LinkBaseExtension::getElementIndex(const char *subname, const char **psubnam
// Try search by element objects' name
std::string name(subname,dot);
if(_ChildCache.getSize()) {
auto obj=_ChildCache.find(name,&idx);
auto obj=_ChildCache.findUsingMap(name,&idx);
if(obj) {
auto group = obj->getExtensionByType<GroupExtension>(true,false);
if(group) {
Expand Down
46 changes: 46 additions & 0 deletions src/App/PropertyExpressionEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/DocumentObserver.h>
#include <Base/Reader.h>
#include <Base/Tools.h>
#include <Base/Writer.h>
Expand Down Expand Up @@ -1079,3 +1080,48 @@ void PropertyExpressionEngine::onRelabeledDocument(const App::Document &doc)
e.second.expression->visit(v);
}
}

void PropertyExpressionEngine::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();

for (auto& [expressionId, expressionInfo] : expressions) {
const auto& deps = expressionInfo.expression->getDeps(option);
auto it = deps.find(obj);
if (it == deps.end()) {
continue;
}
auto [docObj, map] = *it;
for (auto& [key, paths] : map) {
if (!subname) {
identifiers.push_back(expressionId);
break;
}
bool found = false;
for (const auto& path : paths) {
if (path.getSubObjectName() == subname) {
identifiers.push_back(expressionId);
found = true;
break;
}
App::SubObjectT sobjT(obj, path.getSubObjectName().c_str());
if (sobjT.getSubObject() == sobj && sobjT.getOldElementName() == subElement) {
identifiers.push_back(expressionId);
found = true;
break;
}
}
if (found) {
break;
}
}
}
}
5 changes: 5 additions & 0 deletions src/App/PropertyExpressionEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ class AppExport PropertyExpressionEngine : public App::PropertyExpressionContain
void afterRestore() override;
void onContainerRestored() override;

void getLinksTo(std::vector<App::ObjectIdentifier> &identifiers,
App::DocumentObject *obj,
const char *subname=nullptr,
bool all=false) const override;

/* Python interface */
PyObject *getPyObject() override;
void setPyObject(PyObject *) override;
Expand Down
Loading

0 comments on commit 3fa339e

Please sign in to comment.