Skip to content

Commit 702505a

Browse files
Upgrades the create tool - can now set the alphabet, including to symbol type. Fixes an issue introduced in The Refactor where tool selection did not collectly set node dragability.
1 parent 89779ae commit 702505a

File tree

3 files changed

+86
-22
lines changed

3 files changed

+86
-22
lines changed

FSM/Source/create.html

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,36 @@
1414
data-links='[]'
1515
data-question='{"type":"none", "alphabet":["a", "b", "ε"], "alphabetType":"char"}'
1616
data-options='{"constrainRename":true}'
17-
data-iconaddress = 'http://homepages.inf.ed.ac.uk/s1020995/img/Icons/'>
18-
<div class="menu">
19-
<a href='index.html' class='pure-button'>Home</a>
20-
<a href="about.html" class='pure-button'>About</a>
21-
<a href="help.html" class='pure-button'>Help</a>
22-
</div>
23-
<div class="createtools">
24-
<label for="traceform">Input</label>
25-
<input type="text" class="qform" ,="" id="traceform" value="aab">
26-
<button id="traceform-button" class="pure-button" type="submit">Test</button>
27-
</div>
28-
<svg id="main-svg" width="960" height="500" class="active">
29-
<defs>
30-
<marker id="end-arrow" viewBox="0 -10 20 20" refX="7" markerWidth="5" markerHeight="5" orient="auto"><path d="M0,-10L20,0L0,10" fill="#000"></path></marker>
31-
<marker id="highlight-arrow" viewBox="0 -10 20 20" refX="7" markerWidth="5" markerHeight="5" orient="auto"><path d="M0,-10L20,0L0,10" fill="green"></path></marker>
32-
</defs>
33-
</svg>
17+
data-iconaddress = 'http://homepages.inf.ed.ac.uk/s1020995/stable/img/Icons/'>
18+
<div class="maindiv" style="width:85%">
19+
<div class="menu">
20+
<a href='index.html' class='pure-button'>Home</a>
21+
<a href="about.html" class='pure-button'>About</a>
22+
<a href="help.html" class='pure-button'>Help</a>
23+
</div>
24+
<div class="createtools pure-form-aligned" style="margin-top:10px;">
25+
<fieldset style="border-style:none;">
26+
<div class="pure-control-group">
27+
<label for="setalphabet">Alphabet</label>
28+
<input type="text" class ="qform" id="setalphabet" value='["a", "b"]'>
29+
<button id="setalphabet-button" class="pure-button" type="submit" style="margin-left:5px;" >Set</button>
30+
<p id="alphabeterror" style="display:inline; margin-left:10px"></p>
31+
</div>
32+
33+
<div class="pure-control-group">
34+
<label for="traceform">Input</label>
35+
<input type="text" class="qform" id="traceform" value="aab">
36+
<button id="traceform-button" class="pure-button" type="submit" style="margin-left:5px;">Test</button>
37+
</div>
38+
</fieldset>
39+
</div>
40+
<svg id="main-svg" width="960" height="500" class="active">
41+
<defs>
42+
<marker id="end-arrow" viewBox="0 -10 20 20" refX="7" markerWidth="5" markerHeight="5" orient="auto"><path d="M0,-10L20,0L0,10" fill="#000"></path></marker>
43+
<marker id="highlight-arrow" viewBox="0 -10 20 20" refX="7" markerWidth="5" markerHeight="5" orient="auto"><path d="M0,-10L20,0L0,10" fill="green"></path></marker>
44+
</defs>
45+
</svg>
46+
</div>
3447
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.js"></script>
3548
<script src="fsm.js"></script>
3649
<script type="text/javascript" src="create.js"></script>

FSM/Source/create.js

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
create = {
1+
var create = {
22
setup: function() {
33
// Setup the creation environment.
44
create.registerTraceButtonListener();
5+
create.registerAlphabetButtonListener();
56
},
67
registerTraceButtonListener:function(){
78
d3.select("#traceform-button")
@@ -10,8 +11,58 @@ create = {
1011
display.showTrace(input);
1112
console.log(input);
1213
});
14+
},
15+
registerAlphabetButtonListener:function(){
16+
d3.select("#setalphabet-button")
17+
.on("click", function(){
18+
var alphabet = document.querySelector("#setalphabet").value;
19+
create.setalphabet(alphabet);
20+
console.log(alphabet);
21+
});
22+
},
23+
setalphabet: function(string){
24+
try{
25+
var alphabet = JSON.parse(string);
26+
document.querySelector("#alphabeterror").innerHTML = "";
27+
if(alphabet.constructor !== Array){
28+
throw new Error("alphabet must be an array.");
29+
}
30+
if (alphabet.indexOf("ε") == -1){
31+
alphabet.push("ε");
32+
}
33+
var alphabetType = "char";
34+
for (i = 0; i < alphabet.length; i++){
35+
if(alphabet[i].length > 1){
36+
alphabetType = "symbol";
37+
}
38+
}
39+
model.question.alphabetType = alphabetType;
40+
model.question.alphabet = alphabet;
41+
var purgeAlphabet = function(link){
42+
var newAlphabet = alphabet;
43+
link.input = link.input.filter(function(symbol){
44+
return newAlphabet.indexOf(symbol) != -1;
45+
});
46+
};
47+
for(var i = 0; i < model.links.length; i++){
48+
purgeAlphabet(model.links[i]);
49+
display.updateLinkLabel(model.links[i].id);
50+
}
51+
setTimeout(restart, 250);
52+
// Reinstate draggable nodes if they are allowed by the current tool:
53+
if(global.toolsWithDragAllowed.indexOf(model.toolMode) != -1){
54+
// Need to wait, otherwise this doesn't work
55+
window.setTimeout(function(){
56+
global.circle.call(global.force.drag);
57+
}, 300);
58+
}
59+
}
60+
catch(e){
61+
document.querySelector("#alphabeterror").innerHTML = 'Parse error - enter alphabet in form ["a", "b"]';
62+
}
63+
1364
}
14-
}
65+
};
1566

1667
// Start create mode here
17-
create.setup()
68+
create.setup();

FSM/Source/fsm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,7 @@ var eventHandler = {
25532553
controller.renameSubmit();
25542554

25552555
// Reinstate drag-to-move if previous mode did not allow it.
2556-
if(global.toolsWithDragAllowed.indexOf(model.toolMode) != -1){
2556+
if(global.toolsWithDragAllowed.indexOf(model.toolMode) == -1){
25572557
global.circle.call(global.force.drag);
25582558
}
25592559
// If current mode is the same as the new mode, deselect it:
@@ -2566,7 +2566,7 @@ var eventHandler = {
25662566
.attr("fill", "url(#Gradient1)");
25672567
}
25682568
// disable node dragging if needed by new mode:
2569-
if (newMode == "linetool" || newMode == "texttool" || newMode == "acceptingtool" || newMode == "deletetool" || newMode == "nodetool"){
2569+
if (global.toolsWithDragAllowed.indexOf(newMode) == -1){
25702570
global.circle
25712571
.on("mousedown.drag", null)
25722572
.on("touchstart.drag", null);

0 commit comments

Comments
 (0)