fix DocumentObject::isInInListRecursive and DocumentObject::isInOutListRecursive
This commit is contained in:
@@ -297,7 +297,9 @@ std::vector<App::DocumentObject*> DocumentObject::getInList(void) const
|
||||
#endif // if USE_OLD_DAG
|
||||
|
||||
|
||||
void _getInListRecursive(std::set<DocumentObject*>& objSet, const DocumentObject* obj, const DocumentObject* checkObj, int depth)
|
||||
void _getInListRecursive(std::set<DocumentObject*>& objSet,
|
||||
const DocumentObject* obj,
|
||||
const DocumentObject* checkObj, int depth)
|
||||
{
|
||||
for (const auto objIt : obj->getInList()) {
|
||||
// if the check object is in the recursive inList we have a cycle!
|
||||
@@ -326,7 +328,9 @@ std::vector<App::DocumentObject*> DocumentObject::getInListRecursive(void) const
|
||||
return array;
|
||||
}
|
||||
|
||||
void _getOutListRecursive(std::set<DocumentObject*>& objSet, const DocumentObject* obj, const DocumentObject* checkObj, int depth)
|
||||
void _getOutListRecursive(std::set<DocumentObject*>& objSet,
|
||||
const DocumentObject* obj,
|
||||
const DocumentObject* checkObj, int depth)
|
||||
{
|
||||
for (const auto objIt : obj->getOutList()) {
|
||||
// if the check object is in the recursive inList we have a cycle!
|
||||
@@ -355,6 +359,81 @@ std::vector<App::DocumentObject*> DocumentObject::getOutListRecursive(void) cons
|
||||
return array;
|
||||
}
|
||||
|
||||
// helper for isInInListRecursive()
|
||||
bool _isInInListRecursive(const DocumentObject* act,
|
||||
const DocumentObject* checkObj, int depth)
|
||||
{
|
||||
#ifndef USE_OLD_DAG
|
||||
for (auto obj : act->getInList()) {
|
||||
if (obj == checkObj)
|
||||
return true;
|
||||
// if we reach the depth limit we have a cycle!
|
||||
if (depth <= 0) {
|
||||
throw Base::RuntimeError("DocumentObject::isInInListRecursive(): cyclic dependency detected!");
|
||||
}
|
||||
|
||||
if (_isInInListRecursive(obj, checkObj, depth - 1))
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
(void)act;
|
||||
(void)checkObj;
|
||||
(void)depth;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DocumentObject::isInInListRecursive(DocumentObject *linkTo) const
|
||||
{
|
||||
int maxDepth = getDocument()->countObjects() + 2;
|
||||
return _isInInListRecursive(this, linkTo, maxDepth);
|
||||
}
|
||||
|
||||
bool DocumentObject::isInInList(DocumentObject *linkTo) const
|
||||
{
|
||||
#ifndef USE_OLD_DAG
|
||||
if (std::find(_inList.begin(), _inList.end(), linkTo) != _inList.end())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
#else
|
||||
(void)linkTo;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// helper for isInOutListRecursive()
|
||||
bool _isInOutListRecursive(const DocumentObject* act,
|
||||
const DocumentObject* checkObj, int depth)
|
||||
{
|
||||
#ifndef USE_OLD_DAG
|
||||
for (auto obj : act->getOutList()) {
|
||||
if (obj == checkObj)
|
||||
return true;
|
||||
// if we reach the depth limit we have a cycle!
|
||||
if (depth <= 0) {
|
||||
throw Base::RuntimeError("DocumentObject::isInOutListRecursive(): cyclic dependency detected!");
|
||||
}
|
||||
|
||||
if (_isInOutListRecursive(obj, checkObj, depth - 1))
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
(void)act;
|
||||
(void)checkObj;
|
||||
(void)depth;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DocumentObject::isInOutListRecursive(DocumentObject *linkTo) const
|
||||
{
|
||||
int maxDepth = getDocument()->countObjects() + 2;
|
||||
return _isInOutListRecursive(this, linkTo, maxDepth);
|
||||
}
|
||||
|
||||
std::vector<std::list<App::DocumentObject*> >
|
||||
DocumentObject::getPathsByOutList(App::DocumentObject* to) const
|
||||
{
|
||||
@@ -400,84 +479,6 @@ bool DocumentObject::testIfLinkDAGCompatible(PropertyLinkSub &linkTo) const
|
||||
return this->testIfLinkDAGCompatible(linkTo_in_vector);
|
||||
}
|
||||
|
||||
bool DocumentObject::_isInInListRecursive(const DocumentObject* /*act*/,
|
||||
const DocumentObject* test,
|
||||
const DocumentObject* checkObj, int depth) const
|
||||
{
|
||||
#ifndef USE_OLD_DAG
|
||||
if (std::find(_inList.begin(), _inList.end(), test) != _inList.end())
|
||||
return true;
|
||||
|
||||
for (auto obj : _inList) {
|
||||
// if the check object is in the recursive inList we have a cycle!
|
||||
if (obj == checkObj || depth <= 0) {
|
||||
throw Base::RuntimeError("DocumentObject::isInInListRecursive(): cyclic dependency detected!");
|
||||
}
|
||||
|
||||
if (_isInInListRecursive(obj, test, checkObj, depth - 1))
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
(void)test;
|
||||
(void)checkObj;
|
||||
(void)depth;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DocumentObject::isInInListRecursive(DocumentObject *linkTo) const
|
||||
{
|
||||
return _isInInListRecursive(this, linkTo, this, getDocument()->countObjects());
|
||||
}
|
||||
|
||||
bool DocumentObject::isInInList(DocumentObject *linkTo) const
|
||||
{
|
||||
#ifndef USE_OLD_DAG
|
||||
if (std::find(_inList.begin(), _inList.end(), linkTo) != _inList.end())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
#else
|
||||
(void)linkTo;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool DocumentObject::_isInOutListRecursive(const DocumentObject* act,
|
||||
const DocumentObject* test,
|
||||
const DocumentObject* checkObj, int depth) const
|
||||
{
|
||||
#ifndef USE_OLD_DAG
|
||||
std::vector <DocumentObject*> outList = act->getOutList();
|
||||
|
||||
if (std::find(outList.begin(), outList.end(), test) != outList.end())
|
||||
return true;
|
||||
|
||||
for (auto obj : outList) {
|
||||
// if the check object is in the recursive inList we have a cycle!
|
||||
if (obj == checkObj || depth <= 0) {
|
||||
throw Base::RuntimeError("DocumentObject::isInOutListRecursive(): cyclic dependency detected!");
|
||||
}
|
||||
|
||||
if (_isInOutListRecursive(obj, test, checkObj, depth - 1))
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
(void)act;
|
||||
(void)test;
|
||||
(void)checkObj;
|
||||
(void)depth;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DocumentObject::isInOutListRecursive(DocumentObject *linkTo) const
|
||||
{
|
||||
return _isInOutListRecursive(this, linkTo, this, getDocument()->countObjects());
|
||||
}
|
||||
|
||||
void DocumentObject::onLostLinkToObject(DocumentObject*)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user