From 05f4a074fb6ef48e11b3f509db67bc4b0389b0e7 Mon Sep 17 00:00:00 2001 From: Alexey Fedoseev Date: Mon, 22 Apr 2024 21:50:47 +0300 Subject: [PATCH] add new states by the doc interface --- cyberiadamlpp.cpp | 14 ++++++++++++++ cyberiadamlpp.h | 10 +++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cyberiadamlpp.cpp b/cyberiadamlpp.cpp index da58c82..f8f4be6 100644 --- a/cyberiadamlpp.cpp +++ b/cyberiadamlpp.cpp @@ -1188,6 +1188,20 @@ StateMachine* Document::new_state_machine(const ID& _id, const String& sm_name, return sm; } +State* Document::new_state(ElementCollection* _parent, const String& state_name, const Rect& r, const Color& _color) +{ + State* state = new State(_parent, generate_vertex_id(_parent), state_name, r, _color); + _parent->add_element(state); + return state; +} + +State* Document::new_state(ElementCollection* _parent, const ID& state_id, const String& state_name, const Rect& r, const Color& _color) +{ + State* state = new State(_parent, state_id, state_name, r, _color); + _parent->add_element(state); + return state; +} + void Document::check_cyberiada_error(int res, const String& msg) const { switch (res) { diff --git a/cyberiadamlpp.h b/cyberiadamlpp.h index 9b758e4..1f8882d 100644 --- a/cyberiadamlpp.h +++ b/cyberiadamlpp.h @@ -537,9 +537,13 @@ namespace Cyberiada { Document(); void reset(); - StateMachine* new_state_machine(const String& sm_nam, const Rect& r = Rect()); + StateMachine* new_state_machine(const String& sm_name, const Rect& r = Rect()); StateMachine* new_state_machine(const ID& id, const String& sm_name, const Rect& r = Rect()); - + State* new_state(ElementCollection* parent, const String& state_name, + const Rect& r = Rect(), const Color& color = Color()); + State* new_state(ElementCollection* parent, const ID& id, const String& state_name, + const Rect& r = Rect(), const Color& color = Color()); + void load(const String& path, DocumentFormat f = formatDetect); void save(const String& path, DocumentFormat f = formatCyberiada10) const; @@ -557,7 +561,7 @@ namespace Cyberiada { void check_cyberiada_error(int res, const String& msg = "") const; void update_metainfo_element(); ID generate_sm_id() const; - ID generate_vertex_id(const Element* element) const; + ID generate_vertex_id(const Element* parent) const; ID generate_transition_id(const String& source_id, const String& target_id) const; void import_nodes_recursively(ElementCollection* collection, CyberiadaNode* nodes); void import_edges(ElementCollection* collection, CyberiadaEdge* edges);