-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.go
93 lines (77 loc) · 1.94 KB
/
graph.go
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
package main
import (
"fmt"
"goldutil/qmap"
"io"
"strings"
)
func GraphQMap(qm qmap.QMap, w io.Writer) {
fmt.Fprintln(w, "digraph TB {")
fmt.Fprintln(w, " overlap = false;")
for _, v := range qm.RawEntities() {
name := v.Name()
class := v.Class()
if class == "multi_manager" {
graphMultiManager(v, w)
continue
}
target, ok := v.GetProperty(qmap.KTarget)
if ok && target != "" {
if class == "trigger_relay" {
graphTriggerRelayTarget(v, target, w)
} else {
fmt.Fprintf(w, " %s -> %s;\n", name, target)
}
}
triggerTarget, ok := v.GetProperty(qmap.KTriggerTarget)
if ok && triggerTarget != "" {
condition, ok := v.GetProperty(qmap.KTriggerCondition)
if !ok {
condition = "0"
}
fmt.Fprintf(w, " %s -> %s [label=\"cond:%s\"];\n", name, triggerTarget, condition)
}
killTarget, ok := v.GetProperty(qmap.KKillTarget)
if ok && killTarget != "" {
fmt.Fprintf(w, " %s -> %s [label=\"kill\"];\n", name, killTarget)
}
master, ok := v.GetProperty(qmap.KMaster)
if ok && master != "" {
fmt.Fprintf(w, " %s -> %s [label=\"master\"];\n", name, master)
}
}
fmt.Fprintln(w, "}")
}
var mmIgnored = map[string]struct{}{
qmap.KName: {},
qmap.KAngles: {},
qmap.KClass: {},
qmap.KOrigin: {},
qmap.KFlags: {},
}
func graphMultiManager(mm qmap.Entity, w io.Writer) {
for target := range mm.PropertyMap() {
if _, ok := mmIgnored[target]; ok {
continue
}
if strings.HasPrefix(target, "_tb_") {
continue
}
fmt.Fprintf(w, " %s -> %s;\n", mm.Name(), target)
}
}
func graphTriggerRelayTarget(relay qmap.Entity, target string, w io.Writer) {
name := relay.Name()
state, ok := relay.GetProperty("triggerstate")
if !ok {
state = "0"
}
switch state {
case "1":
fmt.Fprintf(w, " %s -> %s [label=\"on\"];\n", name, target)
case "2":
fmt.Fprintf(w, " %s -> %s [label=\"toggle\"];\n", name, target)
default:
fmt.Fprintf(w, " %s -> %s [label=\"off\"];\n", name, target)
}
}