-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
131 lines (95 loc) · 3.68 KB
/
helper.py
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
import sys
import os
from uppaalpy import nta as u
""" BEGIN GENERAL HELPER FUNCTIONS """
def blockPrint():
"""Disable printing to console
"""
sys.stdout = open(os.devnull, 'w')
def enablePrint():
"""Restore printing to console
"""
sys.stdout = sys.__stdout__
def forcePrint(text):
"""Print a string to console, although it is currently blocked
:param str text: text to be printed to console
"""
enablePrint()
print(text)
blockPrint()
""" END GENERAL HELPER FUNCTIONS """
""" BEGIN POSITIONAL HELPER FUNCTIONS """
def middle_nail_pos(src, tar):
if hasattr(src, "pos") & hasattr(tar, "pos"):
return int((src.pos[0] + tar.pos[0]) / 2), int((src.pos[1] + tar.pos[1]) / 2)
else:
return 1
# same as nail position
def guard_label_pos(src, tar):
"""Determines the position for the guard label of a transition
:param u.Location src: source location
:param u.Location tar: target location
:return: position tuple
:rtype: tuple of int
"""
return (src.pos[0] + tar.pos[0]) / 2, (src.pos[1] + tar.pos[1]) / 2
def asgn_label_pos(src, tar):
"""Determines the position for the assignment label of a transition
:param u.Location src: source location
:param u.Location tar: target location
:return: position tuple
:rtype: tuple of int
"""
return [(src.pos[0] + tar.pos[0]) / 2 + 5, (src.pos[1] + tar.pos[1]) / 2]
def sync_label_pos(src, tar):
"""Determines the position for the synchronisation label of a transition
:param u.Location src: source location
:param u.Location tar: target location
:return: position tuple
:rtype: tuple of int
"""
return [(src.pos[0] + tar.pos[0]) / 2 + 10, (src.pos[1] + tar.pos[1]) / 2]
def comment_label_pos(src, tar):
"""Determines the position for the comment label of a transition
:param u.Location src: source location
:param u.Location tar: target location
:return: position tuple
:rtype: tuple of int
"""
return [(src.pos[0] + tar.pos[0]) / 2 + 10, (src.pos[1] + tar.pos[1]) / 2 + 5]
def name_loc_pos(loc_x, loc_y):
"""Determines the position for the name of a location
:param int loc_x: x coordinate of the location
:param int loc_y: y coordinate of the location
:return: position tuple
:rtype: tuple of int
"""
return [loc_x + 7, loc_y + 7]
def inv_loc_pos(loc_x, loc_y):
"""Determines the position for the invariant of a location
:param int loc_x: x coordinate of the location
:param int loc_y: y coordinate of the location
:return: position tuple
:rtype: tuple of int
"""
return [loc_x + 7, loc_y + 20]
def repos_loc(loc, x_pos, y_pos):
"""Repositions a location and its Labels to a new position
:param u.Location loc: location to be repositioned
:param int x_pos: new x coordinate
:param int y_pos: new y coordinate
:return: repositioned location
:rtype: u.Location
"""
# print("repositioning " + loc.name.name)
loc.pos = [x_pos, y_pos]
loc.name.pos = name_loc_pos(x_pos, y_pos)
loc.invariant.pos = inv_loc_pos(x_pos, y_pos)
return loc
# TODO: Future work on edge positioning in SUT template
def arrange_sut_edges(sut):
all_edges = sut.get_trans_by_source(sut.graph.initial_location)
num_edges = len(all_edges)
for i in range(num_edges):
all_edges[i].nails = NotImplemented
# we need nail position function depending on number of edges -> circle around sut