Adaptagrams
io.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libdialect - A library for computing DiAlEcT layouts:
5  * D = Decompose/Distribute
6  * A = Arrange
7  * E = Expand/Emend
8  * T = Transform
9  *
10  * Copyright (C) 2018 Monash University
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  * See the file LICENSE.LGPL distributed with the library.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * Author(s): Steve Kieffer <http://skieffer.info>
23 */
24 
25 #ifndef DIALECT_IO_H
26 #define DIALECT_IO_H
27 
28 #include <istream>
29 #include <string>
30 #include <memory>
31 #include <iostream>
32 #include <cstdio>
33 
34 namespace dialect {
35 
36 class Graph;
37 
38 /*
39  * Support for TGLF: Trivial Graph Layout Format.
40  *
41  * TGLF looks like this:
42  *
43  * cx0 cy0 w0 h0
44  * cx1 cy1 w1 h1
45  * ...
46  * xn yn wn hn
47  * #
48  * i0 i1
49  * i2 i3 a b c d
50  * i4 i5 a' b'
51  * i6 i7
52  * ...
53  * #
54  * j0 j1 D R G
55  * j2 j3 D' R' G'
56  * ...
57  *
58  * and is of the form:
59  *
60  * NODES
61  * #
62  * LINKS
63  * #
64  * SEPCOS
65  *
66  * where
67  *
68  * NODES defines one node per line, giving the x and y coordinates of the
69  * centre of the node, followed by its width and height. All values are floats.
70  *
71  * LINKS defines one link (or "edge" or "connector") per line. A line begins
72  * with two zero-based indices referring to the nodes in the order defined
73  * in NODES. This is followed by zero or more pairs of floats giving
74  * the coordinates of route points. The centres of the source and target
75  * nodes are implicit route points, and should not be listed.
76  *
77  * SEPCOS defines one separation constraint per line. As with the LINKS,
78  * a line begins with two zero-based indices referring to the nodes in the
79  * order defined in NODES. This is followed by a DIRECTION D in [NSEWUDLRXY],
80  * (North, South, East, West, Up, Down, Left, Right, x-dimension, y-dimension)
81  * a RELATION R in [EM] (Exact, Minimal), and a GAP, which is a float.
82  *
83  * Note: For the DIRECTION, X is a synonym for R, and Y a synonym for D.
84  *
85  * The NODES section must be nonempty, but either or both of the LINKS
86  * and SEPCOS sections may be empty or omitted.
87  *
88 */
89 
95 std::shared_ptr<Graph> buildGraphFromTglf(std::istream &in);
96 
102 std::shared_ptr<Graph> buildGraphFromTglf(std::string &s);
103 
109 std::shared_ptr<Graph> buildGraphFromTglfFile(const std::string &filepath);
110 
115 void writeStringToFile(const std::string &s, const std::string &filepath);
116 
117 } // namespace dialect
118 
119 #endif // DIALECT_IO_H
std::shared_ptr< Graph > buildGraphFromTglf(std::istream &in)
Build a Graph object from TGLF.
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
std::shared_ptr< Graph > buildGraphFromTglfFile(const std::string &filepath)
Build a Graph object from a file containing TGLF.
void writeStringToFile(const std::string &s, const std::string &filepath)
Write a string to a file.
Definition: io.cpp:152