-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphpainter.cpp
129 lines (116 loc) · 2.51 KB
/
graphpainter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "graphpainter.h"
graphpainter::graphpainter(const char * addr)
{
strcpy(exeaddr, addr);
}
bool graphpainter::newpainter(const char * filename, const GraphType gtype,const LayoutType ltype)
{
fout.open(filename, ios::out);
mode = 0;
if (fout.good())
{
strcpy(this->filename, filename);
switch (gtype)
{
case Graph:
fout << "%Graph%" << endl; break;
case BT:
fout << "%BT%" << endl; break;
case DiGraph:
fout << "%DiGraph%" << endl; break;
}
switch (ltype)
{
case none:
fout << "%none layout%" << endl; break;
case bt:
fout << "%bst layout%" << endl; break;
case graphviz:
fout << "%graphviz layout%" << endl; break;
case joel:
fout << "%joel layout%" << endl; break;
case joel2:
fout << "%joel2 layout%" << endl; break;
}
return true;
}
return false;
}
void graphpainter::close()
{
fout.close();
}
void graphpainter::setgraph(const char * attr, const char * value)
{
if (mode != 0)
throw logic_error("Set Graph Just After New Painter.");
fout << '#' << attr << '#' << endl << value << endl;
}
void graphpainter::setfigure(const char * attr, const char * value)
{
if (mode != 1)
{
mode = 1;
fout << "%figure%" << endl;
}
fout << '#' << attr << '#' << endl << value << endl;
}
void graphpainter::setlayout(const char * attr, const char * value)
{
if (mode != 2)
{
mode = 2;
fout << "%layout%" << endl;
}
fout << '#' << attr << '#' << endl << value << endl;
}
void graphpainter::setdraw(const char * attr, const char * value)
{
if (mode != 3)
{
mode = 3;
fout << "%draw%" << endl;
}
fout << '#' << attr << '#' << endl << value << endl;
}
void graphpainter::setnode(const char * nodeid, const char * label)
{
if (mode != 4)
{
mode = 4;
fout << "%node%" << endl;
}
if (label != "")
fout << nodeid << ':' << label << endl;
else
fout << nodeid << endl;
}
void graphpainter::setbtnode(char bind,const char * nodeid, const char * label)
{
if (mode != 4)
{
mode = 4;
fout << "%node%" << endl;
}
fout << bind << " ";
if (label != "")
fout << nodeid << ':' << label << endl;
else
fout << nodeid << endl;
}
void graphpainter::setedge(const char * uid, const char * vid)
{
if (mode != 5)
{
mode = 5;
fout << "%edge%" << endl;
}
fout << uid << "," << vid << endl;
}
void graphpainter::draw(const char * tip)
{
stringstream str;
cout << tip;
str << exeaddr << " " << filename;
system(str.str().c_str());
}