/
imp.go
324 lines (294 loc) · 7.55 KB
/
imp.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
package gra1
// (c) Christian Maurer v. 130402 - license see murus.go
import (
// "murus/ker"
. "murus/obj"
"murus/str"
"murus/kbd"
"murus/col"; "murus/scr"; "murus/errh"
// "murus/pseq"
// "murus/img"
"murus/gra"
"murus/gra1/node"; "murus/gra1/edge"
)
const (
pack = "gra1"
suffix = "gra"
)
var (
Graph *gra.Imp
initialisiert bool
Ecke, Ecke1, tempEcke, tempEcke1 *node.Imp
Kante, tempKante *edge.Imp
help []string
)
func Init (e, d bool, n uint, s string) {
//
if initialisiert {
Graph.Terminate ()
} else {
scr.Switch (scr.WVGApp)
initialisiert = true
}
Ecke = node.New (n)
Ecke1 = node.New (n)
tempEcke = node.New (n)
tempEcke1 = node.New (n)
Kante = edge.New ()
tempKante = edge.New ()
Graph = gra.New (d, Ecke, Kante)
edge.WithValues = e
Dateiname:= ""
str.RemAllSpaces (&s)
if str.Empty (s) {
Dateiname = "temp"
} else {
Dateiname = s
}
// sel.DateinameEditieren (Dateiname)
Graph.Name (Dateiname + "." + "gra")
}
func SetColours (n, a col.Colour) {
//
tempEcke.SetColours (n, a)
tempKante.SetColours (n, a)
}
func ausgewaehlt (Ecke *node.Imp) bool {
//
loop: for {
c, _:= kbd.Command ()
switch c { case kbd.Here:
if Graph.ExPred (node.UnderMouse) {
Ecke = Graph.Get ().(*node.Imp)
return true
}
case kbd.Esc:
break loop
}
}
return false
}
func NodesSelected () bool {
//
scr.MouseCursor (true)
g:= false
for {
errh.Hint ("Start auswählen")
if ausgewaehlt (Ecke) { // Ecke aktuell
Graph.Position (true) // Ecke postaktuell
Write()
errh.Hint ("Ziel auswählen")
if ausgewaehlt (Ecke1) { // Ecke1 aktuell
errh.DelHint()
if Graph.Positioned () {
errh.Error ("Fehler: Start und Ziel sind gleich !", 0)
} else {
g = true
break
}
}
} else {
break
}
}
Write()
errh.DelHint()
scr.MouseCursor (false)
return g
}
func NodeSelected () bool {
//
scr.MouseCursor (true)
errh.Hint ("Ecke auswählen")
g:= false
if ausgewaehlt (Ecke) { // Ecke aktuell
Graph.Position (true) // Ecke postaktuell
g = true
Write()
}
errh.DelHint()
scr.MouseCursor (false)
return g
}
func write (n Any, a bool) {
//
n.(*node.Imp).WriteCond (a)
}
func write3 (e, n, n1 Any, a bool) {
//
e.(*edge.Imp).WriteCond (n.(*node.Imp), n1.(*node.Imp), Graph.Directed(), a)
}
func Write () {
//
scr.Buf (true)
Graph.Trav3Cond (write3)
Graph.TravCond (write)
scr.Buf (false)
}
func wr (vis, inv bool) {
//
g:= Graph.Directed ()
tempEcke = Graph.Get ().(*node.Imp) // tempEcke aktuell
tempEcke.Write (vis, inv)
Graph.Position (true) // tempEcke auch postaktuell
k:= Graph.NumLocal ()
if k > 0 {
for i:= uint(0); i < k; i++ {
Graph.Step (i, true)
n, n1, e:= Graph.Get3 () // tempEcke aktuell
tempEcke, tempEcke1, tempKante = n.(*node.Imp), n1.(*node.Imp), e.(*edge.Imp)
tempKante.Write (tempEcke, tempEcke1, g, vis, inv)
Graph.Step (i, false)
}
}
if ! g { return }
Graph.InvAct ()
k = Graph.NumLocal ()
if k > 0 {
for i:= uint(0); i < k - 1; i++ {
Graph.Step (i, true)
n, n1, e:= Graph.Get3 () // tempEcke aktuell
tempEcke, tempEcke1, tempKante = n.(*node.Imp), n1.(*node.Imp), e.(*edge.Imp)
tempKante.Write (tempEcke, tempEcke1, true, vis, inv) // !
Graph.Step (i, false)
}
}
Graph.InvAct ()
}
func Edit () {
//
Write ()
errh.Hint ("Graph editieren: Hilfe per F1, fertig: Abbruchtaste (Esc)")
scr.MouseCursor (true)
loop: for {
K, i:= kbd.Command ()
// errh.DelHint()
switch K { case kbd.Esc:
break loop
case kbd.Help:
errh.WriteHelp (help)
case kbd.Here: // neue Ecke oder Namen vorhandener Ecke ändern:
if Graph.ExPred (node.UnderMouse) {
if i > 0 {
Ecke = Graph.Get ().(*node.Imp) // aktuell: Ecke
Ecke.Edit ()
Graph.Put (Ecke)
}
} else {
Ecke.Clr ()
Ecke.Locate ()
Ecke.Write (true, true)
Ecke.Edit ()
Graph.Ins (Ecke)
}
case kbd.Del: // Ecke entfernen
if Graph.ExPred (node.UnderMouse) {
wr (false, false)
Graph.Del ()
}
case kbd.There: // Ecke verschieben
switch i { case 0:
if Graph.ExPred (node.UnderMouse) {
wr (false, false)
wr (false, true)
loop1: for {
geschoben:= false
kk, _:= kbd.Command ()
switch kk { case kbd.Push:
geschoben = true
wr (false, true)
Ecke = Graph.Get ().(*node.Imp)
Ecke.Locate ()
Graph.Put (Ecke)
wr (false, true)
case kbd.Thither:
wr (false, true)
if geschoben {
Graph.Put (Ecke)
}
wr (true, false)
break loop1
}
}
}
default: // Ecke entfernen
if Graph.ExPred (node.UnderMouse) {
wr (false, false)
Graph.Del ()
}
}
case kbd.This: // Ecken verbinden / Kante entfernen:
x0, y0:= scr.MousePosGr ()
x, y:= x0, y0
if Graph.ExPred (node.UnderMouse) {
Ecke = Graph.Get ().(*node.Imp) // Ecke aktuell
Graph.Position (true) // Ecke auch postaktuell
loop2: for {
kk, _:= kbd.Command()
switch kk {
case kbd.Move:
scr.LineInv (x0, y0, x, y)
x, y = scr.MousePosGr ()
scr.LineInv (x0, y0, x, y)
case kbd.Thus:
scr.LineInv (x0, y0, x, y)
if Graph.ExPred (node.UnderMouse) {
Ecke1 = Graph.Get ().(*node.Imp) // Ecke1 aktuell
g:= Graph.Directed ()
if g {
Kante.Write (Ecke, Ecke1, g, false, false)
}
Kante.Edit (Ecke, Ecke1, g)
Graph.Edge1 (Kante)
if Kante.Val () == 0 {
Kante.Write (Ecke, Ecke1, g, false, false)
Graph.Del1 ()
}
}
break loop2
}
}
}
case kbd.PrintScr:
// img.Write (".tmp.Graph", 0, 0, scr.NX(), scr.NY())
// img.Print()
}
}
errh.DelHint()
}
func Done () bool {
//
return Graph.NumAct() == Graph.Num ()
/* >>>>> falsch ^^^^^^^^^; richtig wäre: Anzahl der
Ecken der Zusammenhangskomponente, in der die aktuelle Ecke liegt */
}
func Terminate () {
//
if initialisiert {
Graph.Terminate ()
}
}
func Set (d gra.Demo) {
//
Graph.Install (write, write3)
Graph.Set (d)
}
func init () {
//
h:= [...]string { " neue Ecke: linke Maustaste ",
" Ecke verschieben: rechte Maustaste ",
" Ecken verbinden: mittlere Maustaste ",
" ",
"Eckennamen ändern: Vorwahl- und linke Maustaste ",
" Ecke löschen: Vorwahl- und rechte Maustaste",
" Graph ausdrucken: Drucktaste ",
" ",
"(Vorwahltaste = Umschalt-, Strg- oder Alt-Taste)",
" ",
" Done: Abbruchtaste (Esc) " }
help = make ([]string, len (h))
for i, l:= range (h) { str.Set (&help[i], l) }
// scr.Fullscreen ()
// scr.Switch (scr.WVGApp)
// ker.InstallTerm (Terminate) // goes not :-(
}