Added diagram context filter
This commit is contained in:
@@ -125,6 +125,9 @@ subclass_filter::subclass_filter(filter_t type, std::vector<std::string> roots)
|
||||
std::optional<bool> subclass_filter::match(
|
||||
const diagram &d, const element &e) const
|
||||
{
|
||||
if (d.type() != diagram_t::kClass)
|
||||
return {};
|
||||
|
||||
if (roots_.empty())
|
||||
return {};
|
||||
|
||||
@@ -200,8 +203,11 @@ context_filter::context_filter(filter_t type, std::vector<std::string> context)
|
||||
}
|
||||
|
||||
std::optional<bool> context_filter::match(
|
||||
const diagram &d, const element &r) const
|
||||
const diagram &d, const element &e) const
|
||||
{
|
||||
if (d.type() != diagram_t::kClass)
|
||||
return {};
|
||||
|
||||
if (!d.complete())
|
||||
return {};
|
||||
|
||||
@@ -209,7 +215,49 @@ std::optional<bool> context_filter::match(
|
||||
return {};
|
||||
|
||||
return std::any_of(context_.begin(), context_.end(),
|
||||
[&r](const auto &rel) { return std::optional<bool>{}; });
|
||||
[&e, &d](const auto &context_root_name) {
|
||||
const auto &context_root =
|
||||
static_cast<const class_diagram::model::diagram &>(d).get_class(
|
||||
context_root_name);
|
||||
|
||||
if (context_root.has_value()) {
|
||||
// This is a direct match to the context root
|
||||
if (context_root.value().full_name(false) == e.full_name(false))
|
||||
return true;
|
||||
|
||||
// Return a positive match if the element e is in a direct
|
||||
// relationship with any of the context_root's
|
||||
for (const relationship &rel :
|
||||
context_root.value().relationships()) {
|
||||
if (rel.destination() == e.full_name(false))
|
||||
return true;
|
||||
}
|
||||
for (const relationship &rel : e.relationships()) {
|
||||
if (rel.destination() ==
|
||||
context_root.value().full_name(false))
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return a positive match if the context_root is a parent
|
||||
// of the element
|
||||
for (const class_diagram::model::class_parent &p :
|
||||
context_root.value().parents()) {
|
||||
if (p.name() == e.full_name(false))
|
||||
return true;
|
||||
}
|
||||
if (dynamic_cast<const class_diagram::model::class_ *>(&e) !=
|
||||
nullptr) {
|
||||
for (const class_diagram::model::class_parent &p :
|
||||
static_cast<const class_diagram::model::class_ &>(e)
|
||||
.parents()) {
|
||||
if (p.name() == context_root.value().full_name(false))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
diagram_filter::diagram_filter(
|
||||
|
||||
Reference in New Issue
Block a user