new transitions interface

This commit is contained in:
Alexey Fedoseev
2024-04-24 11:52:00 +03:00
parent 6611fda149
commit 6fda6817f4
2 changed files with 49 additions and 13 deletions

View File

@@ -682,7 +682,17 @@ void ElementCollection::add_element(Element* e)
{ {
CYB_ASSERT(e); CYB_ASSERT(e);
CYB_ASSERT(e->get_parent() == this); CYB_ASSERT(e->get_parent() == this);
if (e->get_type() == elementTransition) {
children.push_back(e); children.push_back(e);
} else {
ElementList::iterator i;
for (i = children.begin(); i != children.end(); i++) {
if ((*i)->get_type() == elementTransition) {
break;
}
}
children.insert(i, e);
}
} }
void ElementCollection::add_first_element(Element* e) void ElementCollection::add_first_element(Element* e)
@@ -1080,6 +1090,8 @@ CyberiadaEdge* Transition::to_edge() const
std::ostream& Transition::dump(std::ostream& os) const std::ostream& Transition::dump(std::ostream& os) const
{ {
Element::dump(os); Element::dump(os);
os << ", source: '" << source->get_id() << "'";
os << ", target: '" << target->get_id() << "'";
if (has_action()) { if (has_action()) {
os << ", action: {"; os << ", action: {";
os << action; os << action;
@@ -1312,30 +1324,35 @@ ChoicePseudostate* Document::new_choice(ElementCollection* _parent, const ID& _i
return choice; return choice;
} }
Transition* Document::new_transition(ElementCollection* _parent, Element* source, Element* target, Transition* Document::new_transition(StateMachine* sm, Element* source, Element* target,
const Action& action, const Polyline& pl, const Action& action, const Polyline& pl,
const Point& sp, const Point& tp, const Point& sp, const Point& tp,
const Point& label, const Color& c) const Point& label, const Color& c)
{ {
check_parent_element(_parent); check_parent_element(sm);
check_transition_element(source);
check_transition_element(target);
check_transition_action(action);
Transition* t = new Transition(_parent, generate_vertex_id(_parent), source, target, Transition* t = new Transition(sm, generate_transition_id(source->get_id(), target->get_id()),
action, pl, sp, tp, label, c); source, target, action, pl, sp, tp, label, c);
_parent->add_element(t); sm->add_element(t);
return t; return t;
} }
Transition* Document::new_transition(ElementCollection* _parent, const ID& _id, Element* source, Element* target, Transition* Document::new_transition(StateMachine* sm, const ID& _id, Element* source, Element* target,
const Action& action, const Polyline& pl, const Action& action, const Polyline& pl,
const Point& sp, const Point& tp, const Point& sp, const Point& tp,
const Point& label, const Color& c) const Point& label, const Color& c)
{ {
check_parent_element(_parent); check_parent_element(sm);
check_transition_element(source);
check_transition_element(target);
check_id_uniqueness(_id); check_id_uniqueness(_id);
check_transition_action(action);
Transition* t = new Transition(_parent, _id, source, target, Transition* t = new Transition(sm, _id, source, target, action, pl, sp, tp, label, c);
action, pl, sp, tp, label, c); sm->add_element(t);
_parent->add_element(t);
return t; return t;
} }
@@ -1375,6 +1392,23 @@ void Document::check_single_initial(const ElementCollection* _parent) const
} }
} }
void Document::check_transition_action(const Action& action) const
{
if (action.get_type() != actionTransition) {
throw ParametersException("Transitions cannot contain entry/exit activities");
}
}
void Document::check_transition_element(const Element* element) const
{
if (!element) {
throw ParametersException("Empty element");
}
if (element->get_type() == elementRoot || element->get_type() == elementSM) {
throw ParametersException("Bad element for transition");
}
}
void Document::import_nodes_recursively(ElementCollection* collection, CyberiadaNode* nodes) void Document::import_nodes_recursively(ElementCollection* collection, CyberiadaNode* nodes)
{ {
CYB_ASSERT(collection); CYB_ASSERT(collection);

View File

@@ -558,11 +558,11 @@ 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, Transition* new_transition(StateMachine* sm, Element* source, Element* target,
const Action& action, const Polyline& pl = Polyline(), const Action& action, const Polyline& pl = Polyline(),
const Point& sp = Point(), const Point& tp = Point(), const Point& sp = Point(), const Point& tp = Point(),
const Point& label = Point(), const Color& color = Color()); const Point& label = Point(), const Color& color = Color());
Transition* new_transition(ElementCollection* parent, const ID& id, Element* source, Element* target, Transition* new_transition(StateMachine* sm, const ID& id, Element* source, Element* target,
const Action& action, const Polyline& pl = Polyline(), const Action& action, const Polyline& pl = Polyline(),
const Point& sp = Point(), const Point& tp = Point(), const Point& sp = Point(), const Point& tp = Point(),
const Point& label = Point(), const Color& color = Color()); const Point& label = Point(), const Color& color = Color());
@@ -594,6 +594,8 @@ namespace Cyberiada {
void check_parent_element(const ElementCollection* parent) const; void check_parent_element(const ElementCollection* parent) const;
void check_id_uniqueness(const ID& id) const; void check_id_uniqueness(const ID& id) const;
void check_single_initial(const ElementCollection* parent) const; void check_single_initial(const ElementCollection* parent) const;
void check_transition_element(const Element* element) const;
void check_transition_action(const Action& action) const;
String format; String format;
DocumentMetainformation metainfo; DocumentMetainformation metainfo;