correct state actions initialization, add new transitions to the doc interface
This commit is contained in:
@@ -225,8 +225,8 @@ CyberiadaPolyline* Cyberiada::c_polyline(const Polyline& polyline)
|
|||||||
// Action
|
// Action
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
Action::Action(ActionType _type, const Guard& _guard, const Behavior& _behavior):
|
Action::Action(ActionType _type, const Behavior& _behavior):
|
||||||
type(_type), guard(_guard), behavior(_behavior)
|
type(_type), behavior(_behavior)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -940,6 +940,12 @@ void State::remove_element(const ID& _id)
|
|||||||
|
|
||||||
void State::add_action(const Action& a)
|
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);
|
actions.push_back(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1306,6 +1312,33 @@ ChoicePseudostate* Document::new_choice(ElementCollection* _parent, const ID& _i
|
|||||||
return choice;
|
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
|
void Document::check_cyberiada_error(int res, const String& msg) const
|
||||||
{
|
{
|
||||||
switch (res) {
|
switch (res) {
|
||||||
@@ -1388,7 +1421,11 @@ void Document::import_nodes_recursively(ElementCollection* collection, Cyberiada
|
|||||||
} else {
|
} else {
|
||||||
throw CybMLException("Unsupported action type " + std::to_string(a->type));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -389,9 +389,11 @@ namespace Cyberiada {
|
|||||||
|
|
||||||
class Action {
|
class Action {
|
||||||
public:
|
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());
|
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; }
|
ActionType get_type() const { return type; }
|
||||||
bool has_trigger() const { return !trigger.empty(); }
|
bool has_trigger() const { return !trigger.empty(); }
|
||||||
const Event& get_trigger() const { return trigger; }
|
const Event& get_trigger() const { return trigger; }
|
||||||
@@ -556,6 +558,14 @@ namespace Cyberiada {
|
|||||||
const Rect& r = Rect(), const Color& color = Color());
|
const Rect& r = Rect(), const Color& color = Color());
|
||||||
ChoicePseudostate* new_choice(ElementCollection* parent, const ID& id, const Name& name,
|
ChoicePseudostate* new_choice(ElementCollection* parent, const ID& id, const Name& name,
|
||||||
const Rect& r = Rect(), const Color& color = Color());
|
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 load(const String& path, DocumentFormat f = formatDetect);
|
||||||
void save(const String& path, DocumentFormat f = formatCyberiada10) const;
|
void save(const String& path, DocumentFormat f = formatCyberiada10) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user