Blame mono/Diagram/Diagram.cs

777717
/*
777717
    ......... 2015 Ivan Mahonin
777717
777717
    This program is free software: you can redistribute it and/or modify
777717
    it under the terms of the GNU General Public License as published by
777717
    the Free Software Foundation, either version 3 of the License, or
777717
    (at your option) any later version.
777717
777717
    This program is distributed in the hope that it will be useful,
777717
    but WITHOUT ANY WARRANTY; without even the implied warranty of
777717
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
777717
    GNU General Public License for more details.
777717
777717
    You should have received a copy of the GNU General Public License
777717
    along with this program.  If not, see <http: licenses="" www.gnu.org="">.</http:>
777717
*/
777717
777717
using System;
8cb222
using System.Collections.Generic;
8cb222
using System.Drawing;
8cb222
8cb222
namespace Diagram {
8cb222
    public class Block {
8cb222
        public string id = "";
8cb222
        public string caption = "";
8cb222
        public string text = "";
8cb222
        public Color color = Color.Black;
8cb222
    }
8cb222
8cb222
    public class Link {
8cb222
        public string id = "";
8cb222
        public string srcId = "";
8cb222
        public string dstId = "";
8cb222
    }
8cb222
8cb222
    public class Diagram {
8cb222
        public readonly Dictionary<string, block=""> blocks = new Dictionary<string, block="">();</string,></string,>
8cb222
        public readonly Dictionary<string, link=""> links = new Dictionary<string, link="">();</string,></string,>
8cb222
8cb222
        public Diagram addBlock(Block block) {
8cb222
            blocks.Add(block.id, block);
8cb222
            return this;
8cb222
        }
8cb222
8cb222
        public Diagram addBlock(string id, string caption, string text, Color color, string[] links = null) {
8cb222
            addBlock(new Block() { id = id, caption = caption, text = text, color = color });
8cb222
            if (links != null)
8cb222
                foreach(string link in links)
8cb222
                    addLink(id, link);
8cb222
            return this;
8cb222
        }
8cb222
8cb222
        public Diagram addBlock(string id, string caption, string text, string[] links = null) {
8cb222
            addBlock(id, caption, text, Color.Black, links);
8cb222
            return this;
8cb222
        }
8cb222
8cb222
        public Diagram addLink(Link link, string srcId = "", string dstId = "") {
8cb222
            if (srcId != "")
8cb222
                link.srcId = srcId;
8cb222
            if (dstId != "")
8cb222
                link.dstId = dstId;
8cb222
            if (link.id == "")
8cb222
                link.id = link.srcId + link.dstId;
8cb222
            links.Add(link.id, link);
8cb222
            return this;
8cb222
        }
8cb222
8cb222
        public Diagram addLink(Link link) {
8cb222
            if (link.id == "")
8cb222
                link.id = link.srcId + link.dstId;
8cb222
            links.Add(link.id, link);
8cb222
            return this;
8cb222
        }
8cb222
8cb222
        public Diagram addLink(string srcId, string dstId) {
8cb222
            addLink(new Link(), srcId, dstId);
8cb222
            return this;
8cb222
        }
8cb222
    }
8cb222
}
8cb222