From fd3f995dc601023687f66baf842bb0577baaf162 Mon Sep 17 00:00:00 2001 From: Alexey Fedoseev Date: Wed, 24 Apr 2024 18:25:46 +0300 Subject: [PATCH] add new comments doc interface --- cyberiadamlpp.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++-- cyberiadamlpp.h | 22 ++++++++++++++-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/cyberiadamlpp.cpp b/cyberiadamlpp.cpp index a285cb2..d28306a 100644 --- a/cyberiadamlpp.cpp +++ b/cyberiadamlpp.cpp @@ -429,7 +429,7 @@ CyberiadaNode* Comment::to_node() const return node; } -CyberiadaEdge* Comment::subjects_to_edge() const +CyberiadaEdge* Comment::subjects_to_edges() const { CyberiadaEdge* result = NULL; if (has_subjects()) { @@ -1356,6 +1356,66 @@ Transition* Document::new_transition(StateMachine* sm, const ID& _id, Element* s return t; } +Comment* Document::new_comment(ElementCollection* _parent, const String& body, const Rect& r, const Color& c, const String& markup) +{ + check_parent_element(_parent); + + Comment* comm = new Comment(_parent, generate_vertex_id(_parent), body, true, markup, r, c); + _parent->add_element(comm); + return comm; +} + +Comment* Document::new_comment(ElementCollection* _parent, const String& _name, const String& body, const Rect& r, const Color& c, + const String& markup) +{ + check_parent_element(_parent); + + Comment* comm = new Comment(_parent, generate_vertex_id(_parent), body, _name, true, markup, r, c); + _parent->add_element(comm); + return comm; +} + +Comment* Document::new_comment(ElementCollection* _parent, const ID& _id, const String& _name, const String& body, + const Rect& r, const Color& c, const String& markup) +{ + check_parent_element(_parent); + check_id_uniqueness(_id); + + Comment* comm = new Comment(_parent, _id, body, _name, true, markup, r, c); + _parent->add_element(comm); + return comm; +} + +Comment* Document::new_formal_comment(ElementCollection* _parent, const String& body, const Rect& r, const Color& c, const String& markup) +{ + check_parent_element(_parent); + + Comment* comm = new Comment(_parent, generate_vertex_id(_parent), body, false, markup, r, c); + _parent->add_element(comm); + return comm; +} + +Comment* Document::new_formal_comment(ElementCollection* _parent, const String& _name, const String& body, const Rect& r, const Color& c, + const String& markup) +{ + check_parent_element(_parent); + + Comment* comm = new Comment(_parent, generate_vertex_id(_parent), body, _name, false, markup, r, c); + _parent->add_element(comm); + return comm; +} + +Comment* Document::new_formal_comment(ElementCollection* _parent, const ID& _id, const String& _name, const String& body, + const Rect& r, const Color& c, const String& markup) +{ + check_parent_element(_parent); + check_id_uniqueness(_id); + + Comment* comm = new Comment(_parent, _id, body, _name, true, markup, r, c); + _parent->add_element(comm); + return comm; +} + void Document::check_cyberiada_error(int res, const String& msg) const { switch (res) { @@ -1770,7 +1830,7 @@ void Document::export_edges(CyberiadaEdge** edges, const StateMachine* sm) const std::list comments = sm->get_comments(); for (std::list::const_iterator j = comments.begin(); j != comments.end(); j++) { const Comment* c = *j; - edge = c->subjects_to_edge(); + edge = c->subjects_to_edges(); if (*edges) { CyberiadaEdge* e = *edges; while (e->next) e = e->next; diff --git a/cyberiadamlpp.h b/cyberiadamlpp.h index 7b8aa9b..054d68e 100644 --- a/cyberiadamlpp.h +++ b/cyberiadamlpp.h @@ -219,7 +219,7 @@ namespace Cyberiada { const String& get_markup() const { return markup; } virtual CyberiadaNode* to_node() const; - virtual CyberiadaEdge* subjects_to_edge() const; + virtual CyberiadaEdge* subjects_to_edges() const; protected: virtual std::ostream& dump(std::ostream& os) const; @@ -566,7 +566,25 @@ namespace Cyberiada { const Action& action, const Polyline& pl = Polyline(), const Point& sp = Point(), const Point& tp = Point(), const Point& label = Point(), const Color& color = Color()); - + Comment* new_comment(ElementCollection* parent, const String& body, + const Rect& rect = Rect(), const Color& color = Color(), + const String& markup = String()); + Comment* new_comment(ElementCollection* parent, const String& name, const String& body, + const Rect& rect = Rect(), const Color& color = Color(), + const String& markup = String()); + Comment* new_comment(ElementCollection* parent, const ID& id, const String& name, const String& body, + const Rect& rect = Rect(), const Color& color = Color(), + const String& markup = String()); + Comment* new_formal_comment(ElementCollection* parent, const String& body, + const Rect& rect = Rect(), const Color& color = Color(), + const String& markup = String()); + Comment* new_formal_comment(ElementCollection* parent, const String& name, const String& body, + const Rect& rect = Rect(), const Color& color = Color(), + const String& markup = String()); + Comment* new_formal_comment(ElementCollection* parent, const ID& id, const String& name, const String& body, + const Rect& rect = Rect(), const Color& color = Color(), + const String& markup = String()); + void load(const String& path, DocumentFormat f = formatDetect); void save(const String& path, DocumentFormat f = formatCyberiada10) const;