Added 'to' sequence diagram generator for plantuml and json
This commit is contained in:
@@ -543,6 +543,7 @@ struct sequence_diagram : public diagram {
|
||||
|
||||
option<std::vector<source_location>> start_from{"start_from"};
|
||||
option<std::vector<std::vector<source_location>>> from_to{"from_to"};
|
||||
option<std::vector<source_location>> to{"to"};
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -196,6 +196,7 @@ types:
|
||||
participants_order: !optional [string]
|
||||
start_from: !optional [source_location_t]
|
||||
from_to: !optional [[source_location_t]]
|
||||
to: !optional [source_location_t]
|
||||
package_diagram_t:
|
||||
type: !variant [package]
|
||||
#
|
||||
|
||||
@@ -575,6 +575,7 @@ template <> struct convert<sequence_diagram> {
|
||||
|
||||
get_option(node, rhs.start_from);
|
||||
get_option(node, rhs.from_to);
|
||||
get_option(node, rhs.to);
|
||||
get_option(node, rhs.combine_free_functions_into_file_participants);
|
||||
get_option(node, rhs.generate_return_types);
|
||||
get_option(node, rhs.generate_condition_statements);
|
||||
|
||||
@@ -349,6 +349,7 @@ YAML::Emitter &operator<<(YAML::Emitter &out, const sequence_diagram &c)
|
||||
out << YAML::Key << "type" << YAML::Value << c.type();
|
||||
out << c.start_from;
|
||||
out << c.from_to;
|
||||
out << c.to;
|
||||
out << dynamic_cast<const inheritable_diagram_options &>(c);
|
||||
out << YAML::EndMap;
|
||||
return out;
|
||||
|
||||
@@ -617,8 +617,8 @@ void generator::generate_diagram(nlohmann::json &parent) const
|
||||
const auto &from_location = ft.front();
|
||||
const auto &to_location = ft.back();
|
||||
|
||||
auto [from_activity_id, to_activity_id] =
|
||||
model().get_from_to_activity_ids(from_location, to_location);
|
||||
auto from_activity_id = model().get_from_activity_id(from_location);
|
||||
auto to_activity_id = model().get_to_activity_id(to_location);
|
||||
|
||||
if (from_activity_id == 0 || to_activity_id == 0)
|
||||
continue;
|
||||
@@ -655,6 +655,42 @@ void generator::generate_diagram(nlohmann::json &parent) const
|
||||
json_["sequences"].push_back(std::move(sequence));
|
||||
}
|
||||
|
||||
for (const auto &to_location : config().to()) {
|
||||
auto to_activity_id = model().get_to_activity_id(to_location);
|
||||
|
||||
if (to_activity_id == 0)
|
||||
continue;
|
||||
|
||||
auto message_chains_unique =
|
||||
model().get_all_from_to_message_chains(0, to_activity_id);
|
||||
|
||||
nlohmann::json sequence;
|
||||
sequence["to"]["location"] = to_location.location;
|
||||
sequence["to"]["id"] = to_activity_id;
|
||||
|
||||
block_statements_stack_.push_back(std::ref(sequence));
|
||||
|
||||
sequence["message_chains"] = nlohmann::json::array();
|
||||
|
||||
for (const auto &mc : message_chains_unique) {
|
||||
nlohmann::json message_chain;
|
||||
|
||||
block_statements_stack_.push_back(std::ref(message_chain));
|
||||
|
||||
for (const auto &m : mc) {
|
||||
generate_call(m, current_block_statement());
|
||||
}
|
||||
|
||||
block_statements_stack_.pop_back();
|
||||
|
||||
sequence["message_chains"].push_back(std::move(message_chain));
|
||||
}
|
||||
|
||||
block_statements_stack_.pop_back();
|
||||
|
||||
json_["sequences"].push_back(std::move(sequence));
|
||||
}
|
||||
|
||||
for (const auto &sf : config().start_from()) {
|
||||
if (sf.location_type == location_t::function) {
|
||||
common::model::diagram_element::id_t start_from{0};
|
||||
|
||||
@@ -416,8 +416,8 @@ void generator::generate_diagram(std::ostream &ostr) const
|
||||
const auto &from_location = ft.front();
|
||||
const auto &to_location = ft.back();
|
||||
|
||||
auto [from_activity_id, to_activity_id] =
|
||||
model().get_from_to_activity_ids(from_location, to_location);
|
||||
auto from_activity_id = model().get_from_activity_id(from_location);
|
||||
auto to_activity_id = model().get_to_activity_id(to_location);
|
||||
|
||||
if (from_activity_id == 0 || to_activity_id == 0)
|
||||
continue;
|
||||
@@ -451,6 +451,43 @@ void generator::generate_diagram(std::ostream &ostr) const
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &to_location : config().to()) {
|
||||
auto to_activity_id = model().get_to_activity_id(to_location);
|
||||
|
||||
if (to_activity_id == 0)
|
||||
continue;
|
||||
|
||||
auto message_chains_unique =
|
||||
model().get_all_from_to_message_chains(0, to_activity_id);
|
||||
|
||||
bool first_separator_skipped{false};
|
||||
for (const auto &mc : message_chains_unique) {
|
||||
if (!first_separator_skipped)
|
||||
first_separator_skipped = true;
|
||||
else
|
||||
ostr << "====\n";
|
||||
|
||||
const auto from_activity_id = mc.front().from();
|
||||
|
||||
const auto &from =
|
||||
model().get_participant<model::function>(from_activity_id);
|
||||
|
||||
if (from.value().type_name() == "method" ||
|
||||
config().combine_free_functions_into_file_participants()) {
|
||||
generate_participant(ostr, from_activity_id);
|
||||
ostr << "[->"
|
||||
<< " " << generate_alias(from.value()) << " : "
|
||||
<< from.value().message_name(
|
||||
select_method_arguments_render_mode())
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
for (const auto &m : mc) {
|
||||
generate_call(m, ostr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &sf : config().start_from()) {
|
||||
if (sf.location_type == location_t::function) {
|
||||
common::model::diagram_element::id_t start_from{0};
|
||||
|
||||
@@ -209,31 +209,11 @@ std::vector<std::string> diagram::list_start_from_values() const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::pair<common::model::diagram_element::id_t,
|
||||
common::model::diagram_element::id_t>
|
||||
diagram::get_from_to_activity_ids(const config::source_location &from_location,
|
||||
common::model::diagram_element::id_t diagram::get_to_activity_id(
|
||||
const config::source_location &to_location) const
|
||||
{
|
||||
common::model::diagram_element::id_t from_activity{0};
|
||||
common::model::diagram_element::id_t to_activity{0};
|
||||
|
||||
for (const auto &[k, v] : sequences()) {
|
||||
const auto &caller = *participants().at(v.from());
|
||||
std::string vfrom = caller.full_name(false);
|
||||
if (vfrom == from_location.location) {
|
||||
LOG_DBG("Found sequence diagram start point '{}': {}", vfrom, k);
|
||||
from_activity = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (from_activity == 0) {
|
||||
LOG_WARN("Failed to find 'from' participant {} for start_from "
|
||||
"condition",
|
||||
from_location.location);
|
||||
return {from_activity, to_activity};
|
||||
}
|
||||
|
||||
for (const auto &[k, v] : sequences()) {
|
||||
for (const auto &m : v.messages()) {
|
||||
if (m.type() != common::model::message_t::kCall)
|
||||
@@ -250,13 +230,36 @@ diagram::get_from_to_activity_ids(const config::source_location &from_location,
|
||||
}
|
||||
|
||||
if (to_activity == 0) {
|
||||
LOG_WARN("Failed to find 'to' participant {} for from_to "
|
||||
LOG_WARN("Failed to find 'to' participant {} for to "
|
||||
"condition",
|
||||
to_location.location);
|
||||
return {from_activity, to_activity};
|
||||
}
|
||||
|
||||
return {from_activity, to_activity};
|
||||
return to_activity;
|
||||
}
|
||||
|
||||
common::model::diagram_element::id_t diagram::get_from_activity_id(
|
||||
const config::source_location &from_location) const
|
||||
{
|
||||
common::model::diagram_element::id_t from_activity{0};
|
||||
|
||||
for (const auto &[k, v] : sequences()) {
|
||||
const auto &caller = *participants().at(v.from());
|
||||
std::string vfrom = caller.full_name(false);
|
||||
if (vfrom == from_location.location) {
|
||||
LOG_DBG("Found sequence diagram start point '{}': {}", vfrom, k);
|
||||
from_activity = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (from_activity == 0) {
|
||||
LOG_WARN("Failed to find 'from' participant {} for from "
|
||||
"condition",
|
||||
from_location.location);
|
||||
}
|
||||
|
||||
return from_activity;
|
||||
}
|
||||
|
||||
std::unordered_set<message_chain_t> diagram::get_all_from_to_message_chains(
|
||||
@@ -362,7 +365,8 @@ std::unordered_set<message_chain_t> diagram::get_all_from_to_message_chains(
|
||||
std::copy_if(message_chains.begin(), message_chains.end(),
|
||||
std::inserter(message_chains_unique, message_chains_unique.begin()),
|
||||
[from_activity](const message_chain_t &mc) {
|
||||
return !mc.empty() && (mc.front().from() == from_activity);
|
||||
return !mc.empty() &&
|
||||
(from_activity == 0 || (mc.front().from() == from_activity));
|
||||
});
|
||||
|
||||
return message_chains_unique;
|
||||
|
||||
@@ -241,6 +241,9 @@ public:
|
||||
/**
|
||||
* @brief Generate a list of message chains matching a from_to constraint
|
||||
*
|
||||
* If 'from_activity' is 0, this method will return all message chains
|
||||
* ending in 'to_activity'.
|
||||
*
|
||||
* @param from_activity Source activity for from_to message chain
|
||||
* @param to_activity Target activity for from_to message chain
|
||||
* @return List of message chains
|
||||
@@ -250,16 +253,22 @@ public:
|
||||
common::model::diagram_element::id_t to_activity) const;
|
||||
|
||||
/**
|
||||
* @brief Get ids of from and to activities in from_to constraint
|
||||
* @brief Get id of a 'to' activity
|
||||
*
|
||||
* @param from_activity Source activity for from_to message chain
|
||||
* @param to_activity Target activity for from_to message chain
|
||||
* @return Pair of activity ids (0 if not found)
|
||||
* @param to_location Target activity
|
||||
* @return Activity id
|
||||
*/
|
||||
std::pair<common::model::diagram_element::id_t,
|
||||
common::model::diagram_element::id_t>
|
||||
get_from_to_activity_ids(const config::source_location &from_activity,
|
||||
const config::source_location &to_activity) const;
|
||||
common::model::diagram_element::id_t get_to_activity_id(
|
||||
const config::source_location &to_location) const;
|
||||
|
||||
/**
|
||||
* @brief Get id of a 'from' activity
|
||||
*
|
||||
* @param from_location Source activity
|
||||
* @return Activity id
|
||||
*/
|
||||
common::model::diagram_element::id_t get_from_activity_id(
|
||||
const config::source_location &from_location) const;
|
||||
|
||||
/**
|
||||
* @brief Once the diagram is complete, run any final processing.
|
||||
|
||||
Reference in New Issue
Block a user