0003279: Error 'invalid DAG' after deleting sketch using expressions

This commit is contained in:
wmayer
2018-01-31 00:27:38 +01:00
parent 9d838dd8d2
commit 004206aa0b
3 changed files with 51 additions and 0 deletions

View File

@@ -2867,6 +2867,9 @@ void Document::_removeObject(DocumentObject* pcObject)
void Document::breakDependency(DocumentObject* pcObject, bool clear)
{
// Nullify all dependent objects
std::vector<DocumentObject *> docObjs;
pcObject->ExpressionEngine.getDocumentObjectDeps(docObjs);
for (std::map<std::string,DocumentObject*>::iterator it = d->objectMap.begin(); it != d->objectMap.end(); ++it) {
std::map<std::string,App::Property*> Map;
it->second->getPropertyMap(Map);
@@ -2929,6 +2932,14 @@ void Document::breakDependency(DocumentObject* pcObject, bool clear)
}
}
}
if (std::find(docObjs.begin(), docObjs.end(), it->second) != docObjs.end()) {
std::vector<App::ObjectIdentifier> paths;
pcObject->ExpressionEngine.getPathsToDocumentObject(it->second, paths);
for (std::vector<App::ObjectIdentifier>::iterator jt = paths.begin(); jt != paths.end(); ++jt) {
pcObject->ExpressionEngine.setValue(*jt, nullptr);
}
}
}
}

View File

@@ -680,6 +680,44 @@ void PropertyExpressionEngine::getDocumentObjectDeps(std::vector<DocumentObject
}
}
/**
* @brief Find paths to document object.
* @param obj Document object
* @param paths Object identifier
*/
void PropertyExpressionEngine::getPathsToDocumentObject(DocumentObject* obj,
std::vector<App::ObjectIdentifier> & paths) const
{
DocumentObject * owner = freecad_dynamic_cast<DocumentObject>(getContainer());
if (owner == 0)
return;
ExpressionMap::const_iterator i = expressions.begin();
while (i != expressions.end()) {
std::set<ObjectIdentifier> deps;
i->second.expression->getDeps(deps);
std::set<ObjectIdentifier>::const_iterator j = deps.begin();
while (j != deps.end()) {
const ObjectIdentifier & p = *j;
DocumentObject* docObj = p.getDocumentObject();
if (docObj == obj && docObj != owner) {
paths.push_back(i->first);
break;
}
++j;
}
++i;
}
}
/**
* @brief Determine whether any dependencies of any of the registered expressions have been touched.
* @return True if at least on dependency has been touched.

View File

@@ -101,6 +101,8 @@ public:
void getDocumentObjectDeps(std::vector<DocumentObject*> & docObjs) const;
void getPathsToDocumentObject(DocumentObject*, std::vector<App::ObjectIdentifier> & paths) const;
bool depsAreTouched() const;
boost::unordered_map<const App::ObjectIdentifier, const ExpressionInfo> getExpressions() const;