-
Notifications
You must be signed in to change notification settings - Fork 1
/
gateSwitch.js
196 lines (185 loc) · 7.02 KB
/
gateSwitch.js
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
/* ________________________________________________________________________________
* |Components for switching the gate type in a DFT. |
* |________________________________________________________________________________|
*/
/* JQuerry onClick functions
*
* Prepare the visable gui elements for the switching and call the switchElement function.
*/
$('#gateSwitch-vot, #gateSwitch-gate, #gateSwitch-pdep').on('click', function() {
switched = true;
if (switchElem.data('type') == 'vot') {
$('#dialog-vot').dialog('close');
} else if (switchElem.data('type') == 'pdep') {
$('#dialog-pdep').dialog('close');
} else {
$('#dialog-gate').dialog('close');
}
$('#dialog-switch').dialog({
width: 250,
height: 250,
modal: true,
resizable: false,
dialogClass: 'no-close',
classes: {
'ui-dialog': 'highlight'
},
buttons: [{
id: 'switchConfirmButton',
text: 'Change',
click: function() {
$(this).dialog('close');
var type = $('#switch-type').val();
if (type == 'vot') {
$('#gateSwitch-vot').addClass('nonVis');
$('#gateSwitch-vot').removeClass('vis');
var sub = 'Change to ' + $('#switch-type').val().toUpperCase();
$('#dialog-vot').dialog({
width: 300,
modal: true,
title: sub,
resizable: false,
dialogClass: 'no-close',
classes: {
'ui-dialog': 'highlight'
},
buttons: [{
id: 'switchConfirmButton-vot',
text: 'Confirm',
click: function() {
if (validationCheck($('#switch-type').val())) {
switchElement(type);
switched = false;
}
}
},
{
text: 'Cancel',
click: function() {
$(this).dialog('close');
}
}
],
close: function() {
invalidNameReset();
}
});
} else if (type == 'pdep') {
$('#gateSwitch-pdep').addClass('nonVis');
$('#gateSwitch-pdep').removeClass('vis');
var sub = 'Change to ' + $('#switch-type').val().toUpperCase();
$('#dialog-pdep').dialog({
width: 300,
modal: true,
title: sub,
resizable: false,
dialogClass: 'no-close',
classes: {
'ui-dialog': 'highlight'
},
buttons: [{
id: 'switchConfirmButton-pdep',
text: 'Confirm',
click: function() {
if (validationCheck($('#switch-type').val())) {
switchElement(type);
switched = false;
}
}
},
{
text: 'Cancel',
click: function() {
$(this).dialog('close');
}
}
],
close: function() {
invalidNameReset();
}
});
} else {
$('#gateSwitch-gate').addClass('nonVis');
$('#gateSwitch-gate').removeClass('vis');
var sub = 'Change to ' + $('#switch-type').val().toUpperCase();
$('#dialog-gate').dialog({
width: 300,
modal: true,
title: sub,
resizable: false,
dialogClass: 'no-close',
classes: {
'ui-dialog': 'highlight'
},
buttons: [{
id: 'switchConfirmButton-gate',
text: 'Confirm',
click: function() {
switchElement(type);
switched = false;
}
},
{
text: 'Cancel',
click: function() {
$(this).dialog('close');
}
}
],
close: function() {
invalidNameReset();
}
});
}
}
},
{
text: 'Cancel',
click: function() {
$(this).dialog('close');
}
}],
close: function() {
$(this).dialog('close');
}
});
});
/* void switchElement(type)
* @param type - the new type of the gate
*
*
* Save all edges, delete old gate, create new gate and restore the edges.
*/
function switchElement(type) {
var id = switchElem.data('id');
// Save connected edges.
var incomers = switchElem.incomers().edges();
var outGoing = switchElem.outgoers().edges();
// Get parent if parent exist
var parent = switchElem.parent();
removeNode(cy.getElementById(id));
var storedCurrentId = currentId;
currentId = switchElem.id() - 1;
if (type == 'vot') {
addVot(switchElem.position('x'), switchElem.position('y'), parent);
} else if (type == 'pdep') {
addPDEP(switchElem.position('x'), switchElem.position('y'), parent);
} else {
addGate(switchElem.position('x'), switchElem.position('y'), type, parent);
}
currentId = storedCurrentId;
// Restore edges
outGoing.forEach(function(edge) {
var sourceId = edge.data('source');
var targetId = edge.data('target');
addEdge(edge, cy.getElementById(sourceId), cy.getElementById(targetId));
cy.add(edge);
});
incomers.forEach(function(edge) {
var sourceId = edge.data('source');
var targetId = edge.data('target');
addEdge(edge, cy.getElementById(sourceId), cy.getElementById(targetId));
cy.add(edge);
});
switchElem = {};
}