From 83e7bfe9978f750659e53863f4b53c2b70350795 Mon Sep 17 00:00:00 2001 From: Alexey Fedoseev Date: Tue, 23 Apr 2024 13:51:53 +0300 Subject: [PATCH] correct state actions initialization, add new transitions to the doc interface --- cyberiadamlpp.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- cyberiadamlpp.h | 12 +++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/cyberiadamlpp.cpp b/cyberiadamlpp.cpp index 09b126f..fae9d31 100644 --- a/cyberiadamlpp.cpp +++ b/cyberiadamlpp.cpp @@ -225,8 +225,8 @@ CyberiadaPolyline* Cyberiada::c_polyline(const Polyline& polyline) // Action // ----------------------------------------------------------------------------- -Action::Action(ActionType _type, const Guard& _guard, const Behavior& _behavior): - type(_type), guard(_guard), behavior(_behavior) +Action::Action(ActionType _type, const Behavior& _behavior): + type(_type), behavior(_behavior) { } @@ -940,6 +940,12 @@ void State::remove_element(const ID& _id) void State::add_action(const Action& a) { + if (a.is_empty_transition()) { + throw ParametersException("Empty transition action is not allowed"); + } + if (a.get_type() != actionTransition && a.has_guard()) { + throw ParametersException("Guards are not allowed for entry/exit activities"); + } actions.push_back(a); } @@ -1306,6 +1312,33 @@ ChoicePseudostate* Document::new_choice(ElementCollection* _parent, const ID& _i return choice; } +Transition* Document::new_transition(ElementCollection* _parent, Element* source, Element* target, + const Action& action, const Polyline& pl, + const Point& sp, const Point& tp, + const Point& label, const Color& c) +{ + check_parent_element(_parent); + + Transition* t = new Transition(_parent, generate_vertex_id(_parent), source, target, + action, pl, sp, tp, label, c); + _parent->add_element(t); + return t; +} + +Transition* Document::new_transition(ElementCollection* _parent, const ID& _id, Element* source, Element* target, + const Action& action, const Polyline& pl, + const Point& sp, const Point& tp, + const Point& label, const Color& c) +{ + check_parent_element(_parent); + check_id_uniqueness(_id); + + Transition* t = new Transition(_parent, _id, source, target, + action, pl, sp, tp, label, c); + _parent->add_element(t); + return t; +} + void Document::check_cyberiada_error(int res, const String& msg) const { switch (res) { @@ -1388,7 +1421,11 @@ void Document::import_nodes_recursively(ElementCollection* collection, Cyberiada } else { throw CybMLException("Unsupported action type " + std::to_string(a->type)); } - state->add_action(Action(at, a->guard, a->behavior)); + if (a->guard && *(a->guard)) { + // guard is not empty + throw CybMLException("Guards are not allowed in entry/exit actions"); + } + state->add_action(Action(at, a->behavior)); } } diff --git a/cyberiadamlpp.h b/cyberiadamlpp.h index 7c268e1..96199d2 100644 --- a/cyberiadamlpp.h +++ b/cyberiadamlpp.h @@ -389,9 +389,11 @@ namespace Cyberiada { class Action { public: - Action(ActionType type, const Guard& guard = Guard(), const Behavior& behavior = Behavior()); + Action(ActionType type, const Behavior& behavior = Behavior()); Action(const Event& trigger = Event(), const Guard& guard = Guard(), const Behavior& behavior = Behavior()); + bool is_empty_transition() const { return (type == actionTransition && !has_trigger() && + !has_guard() && !has_behavior()); } ActionType get_type() const { return type; } bool has_trigger() const { return !trigger.empty(); } const Event& get_trigger() const { return trigger; } @@ -556,6 +558,14 @@ namespace Cyberiada { const Rect& r = Rect(), const Color& color = Color()); ChoicePseudostate* new_choice(ElementCollection* parent, const ID& id, const Name& name, const Rect& r = Rect(), const Color& color = Color()); + Transition* new_transition(ElementCollection* parent, Element* source, Element* target, + const Action& action, const Polyline& pl = Polyline(), + const Point& sp = Point(), const Point& tp = Point(), + const Point& label = Point(), const Color& color = Color()); + Transition* new_transition(ElementCollection* parent, const ID& id, Element* source, Element* target, + const Action& action, const Polyline& pl = Polyline(), + const Point& sp = Point(), const Point& tp = Point(), + const Point& label = Point(), const Color& color = Color()); void load(const String& path, DocumentFormat f = formatDetect); void save(const String& path, DocumentFormat f = formatCyberiada10) const;