-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQuickCombine.py
More file actions
176 lines (154 loc) · 6.97 KB
/
Copy pathQuickCombine.py
File metadata and controls
176 lines (154 loc) · 6.97 KB
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
import xml.etree.ElementTree as ET
from UniversalClasses import State
from UniversalClasses import AffinityRule
from UniversalClasses import TransitionRule
from UniversalClasses import System, AffinityRule, TransitionRule
def main(currentSystem, file):
# Retrieve currentSystem's lists
# currentSystem's Affinity Rules
current_VerticalAffinityRules = currentSystem.returnVerticalAffinityList()
current_HorizontalAffinityRules = currentSystem.returnHorizontalAffinityList()
# currentSystem's Transition Rules
current_VerticalTransitionRules = currentSystem.returnVerticalTransitionList()
current_HorizontalTransitionRules = currentSystem.returnHorizontalTransitionList()
# currentSystem's States
current_SeedStateSet = currentSystem.returnSeedStates()
current_InitialStateSet = currentSystem.returnInitialStates()
current_CompleteStateSet = currentSystem.returnStates() # All states in the system
# Does the new state in secondSystem already exist in currentSystem?
state_duplicated = False
# Does the new rule in secondSystem alread exist in currentSystem?
rule_duplicated = False
tree = ET.parse(file)
treeroot = tree.getroot()
# Attach secondSystem's All States to currentSystem
for state_tag in treeroot.findall('AllStates/State'):
label = state_tag.get("Label")
# If the label is the pot (X), don't append a "$".
if(label != "X"):
label = label + "$"
color = state_tag.get("Color")
for state in current_CompleteStateSet:
if(state.returnLabel() == label):
state_duplicated = True
break
if(not state_duplicated):
tempState = State(label, color)
current_CompleteStateSet.append(tempState)
state_duplicated = False
# Attach secondSystem's Initial States
for state_tag in treeroot.findall("InitialStates/State"):
label = state_tag.get("Label")
# If the label is the pot (X), don't append a "$".
if(label != "X"):
label = label + "$"
color = state_tag.get("Color")
for state in current_InitialStateSet:
if(state.returnLabel() == label):
state_duplicated = True
break
if(not state_duplicated):
tempState = State(label, color)
current_InitialStateSet.append(tempState)
state_duplicated = False
# Seed States
for state_tag in treeroot.findall("SeedStates/State"):
label = state_tag.get("Label")
# If the label is the pot (X), don't append a "$".
if(label != "X"):
label = label + "$"
color = state_tag.get("Color")
for state in current_SeedStateSet:
if(state.returnLabel() == label):
state_duplicated = True
break
if(not state_duplicated):
tempState = State(label, color)
current_SeedStateSet.append(tempState)
state_duplicated = False
# Vertical Transitions
for rule_tag in treeroot.findall("VerticalTransitions/Rule"):
label1 = rule_tag.get("Label1")
label2 = rule_tag.get("Label2")
label1Final = rule_tag.get("Label1Final")
label2Final = rule_tag.get("Label2Final")
# If the label is the pot (X), don't append a "$".
if(label1 != "X"):
label1 = label1 + "$"
if(label2 != "X"):
label2 = label2 + "$"
if(label1Final != "X"):
label1Final = label1Final + "$"
if(label2Final != "X"):
label2Final = label2Final + "$"
# Attach secondSystem's Vertical Transitions if they don't already exist in currentSystem
for rule in current_VerticalTransitionRules:
if(rule.returnLabel1() == label1 and rule.returnLabel2() == label2 and rule.returnLabel1Final() == label1Final and rule.returnLabel2Final() == label2Final):
rule_duplicated = True
break
if(not rule_duplicated):
tempRule = TransitionRule(
label1, label2, label1Final, label2Final, "v")
current_VerticalTransitionRules.append(tempRule)
rule_duplicated = False
# Horizontal Transitions
for rule_tag in treeroot.findall("HorizontalTransitions/Rule"):
label1 = rule_tag.get("Label1")
label2 = rule_tag.get("Label2")
label1Final = rule_tag.get("Label1Final")
label2Final = rule_tag.get("Label2Final")
# If the label is the pot (X), don't append a "$".
if(label1 != "X"):
label1 = label1 + "$"
if(label2 != "X"):
label2 = label2 + "$"
if(label1Final != "X"):
label1Final = label1Final + "$"
if(label2Final != "X"):
label2Final = label2Final + "$"
# Attach secondSystem's Horizontal Transitions if they don't already exist in currentSystem
for rule in current_HorizontalTransitionRules:
if(rule.returnLabel1() == label1 and rule.returnLabel2() == label2 and rule.returnLabel1Final() == label1Final and rule.returnLabel2Final() == label2Final):
rule_duplicated = True
break
if(not rule_duplicated):
tempRule = TransitionRule(
label1, label2, label1Final, label2Final, "v")
current_HorizontalTransitionRules.append(tempRule)
rule_duplicated = False
# Vertical Affinities
for rule_tag in treeroot.findall("VerticalAffinities/Rule"):
label1 = rule_tag.get("Label1")
label2 = rule_tag.get("Label2")
strength = rule_tag.get("Strength")
if(label1 != "X"):
label1 = label1 + "$"
if(label2 != "X"):
label2 = label2 + "$"
# Attach secondSystem's Vertical Affinities if they don't already exist in currentSystem
for rule in current_VerticalAffinityRules:
if(rule.returnLabel1() == label1 and rule.returnLabel2() == label2):
rule_duplicated = True
break
if(not rule_duplicated):
tempRule = AffinityRule(label1, label2, "h", strength)
current_VerticalAffinityRules.append(tempRule)
rule_duplicated = False
# Horizontal Affinities
for rule_tag in treeroot.findall("HorizontalAffinities/Rule"):
label1 = rule_tag.get("Label1")
label2 = rule_tag.get("Label2")
strength = rule_tag.get("Strength")
if(label1 != "X"):
label1 = label1 + "$"
if(label2 != "X"):
label2 = label2 + "$"
# Attach secondSystem's Vertical Affinities if they don't already exist in currentSystem
for rule in current_HorizontalAffinityRules:
if(rule.returnLabel1() == label1 and rule.returnLabel2() == label2):
rule_duplicated = True
break
if(not rule_duplicated):
tempRule = AffinityRule(label1, label2, "h", strength)
current_HorizontalAffinityRules.append(tempRule)
rule_duplicated = False