diff --git a/static/index.html b/static/index.html index e941749..20313e4 100644 --- a/static/index.html +++ b/static/index.html @@ -20,25 +20,25 @@ - - + + -
-

Node (5,2)

+ diff --git a/static/main.css b/static/main.css index cd03e3a..5907e13 100644 --- a/static/main.css +++ b/static/main.css @@ -27,7 +27,7 @@ html, body { margin: 0; padding: 0; overflow: hidden; font-size: 10pt; font-fam } -#pallette { +#node_data { background-color: black; color:white; padding: 10px; diff --git a/static/scripts/anders_briegel.js b/static/scripts/anders_briegel.js index fcb4c79..282a1f6 100644 --- a/static/scripts/anders_briegel.js +++ b/static/scripts/anders_briegel.js @@ -13,6 +13,13 @@ abj.add_nodes = function(nodes) { nodes.forEach(add_node); }; +abj.del_node = function(node) { + for (var i in abj.adj[node]) { + abj.del_edge(node, i); + } + delete abj.node[node]; +}; + abj.add_edge = function(a, b) { abj.adj[a][b] = {}; abj.adj[b][a] = {}; @@ -34,10 +41,10 @@ abj.has_edge = function(a, b) { }; abj.toggle_edge = function(a, b) { - if (has_edge(a, b)) { - del_edge(a, b); + if (abj.has_edge(a, b)) { + abj.del_edge(a, b); } else { - add_edge(a, b); + abj.add_edge(a, b); } }; @@ -76,7 +83,7 @@ abj.act_local_rotation = function(node, operation) { }; abj.act_hadamard = function(node) { - act_local_rotation(node, 10); + abj.act_local_rotation(node, 10); }; abj.is_sole_member = function(node, group) { @@ -84,21 +91,21 @@ abj.is_sole_member = function(node, group) { }; abj.act_cz = function(a, b) { - if (is_sole_member(abj.adj[a], b)) { + if (abj.is_sole_member(abj.adj[a], b)) { remove_vop(a, b); } - if (is_sole_member(abj.adj[b], a)) { + if (abj.is_sole_member(abj.adj[b], a)) { remove_vop(b, a); } - if (is_sole_member(abj.adj[a], b)) { + if (abj.is_sole_member(abj.adj[a], b)) { remove_vop(a, b); } - var edge = has_edge(a, b); + var edge = abj.has_edge(a, b); var new_state = tables.cz_table[edge ? 1 : 0][abj.node[a].vop][abj.node[b].vop]; abj.node[a].vop = new_state[1]; abj.node[b].vop = new_state[2]; if (new_state[0] != edge) { - toggle_edge(a, b); + abj.toggle_edge(a, b); } }; diff --git a/static/scripts/editor.js b/static/scripts/editor.js index 8fe5695..4ac7469 100644 --- a/static/scripts/editor.js +++ b/static/scripts/editor.js @@ -2,6 +2,7 @@ var editor = {}; var pi2 = Math.PI / 2; editor.selection = undefined; +editor.mouseOver = undefined; editor.orientations = [ new THREE.Euler(pi2, 0, 0), @@ -12,11 +13,10 @@ editor.orientations = [ editor.onFreeMove = function() { var found = editor.findNodeOnRay(mouse.ray); - if (editor.selection !== found) { - editor.selection = found; + if (editor.mouseOver !== found) { + editor.mouseOver = found; if (found) { - gui.nodeMessage("Node " + found + " (VOP:" + abj.node[found].vop + ")" + - "
" + "Click to edit neighbourhood"); + gui.nodeMessage("Node " + found + " (VOP:" + abj.node[found].vop + ")"); } else { gui.hideNodeMessage(); } @@ -29,6 +29,9 @@ editor.focus = function(node) { gui.hideNodeMessage(); editor.selection = node; gui.serverMessage("Selected node " + node + "."); + node_name.innerHTML = "Node " + node; + node_data.className = "visible"; + node_vop.innerHTML = "VOP: " + abj.node[node].vop; }; editor.addQubitAtPoint = function(point) { @@ -44,11 +47,12 @@ editor.addQubitAtPoint = function(point) { if (delta.length()<0.1){ return; } } - abj.add_node(abj.order(), { position: point }); - editor.grid.position.copy(point); - gui.controls.target.copy(point); + // TODO: This SUCKS + var new_node = Math.random()*100000|0; + abj.add_node(new_node, { position: point, vop:0 }); + editor.focus(new_node); graph.update(); - gui.serverMessage("Created node."); + gui.serverMessage("Created node " + new_node +"."); }; editor.onClick = function() { @@ -63,16 +67,44 @@ editor.onClick = function() { } }; +editor.onShiftClick = function() { + var found = editor.findNodeOnRay(mouse.ray); + if (found === undefined){ return; } + if (editor.selection === undefined){ return; } + if (found === editor.selection){ return; } + abj.act_cz(found, editor.selection); + editor.focus(found); + gui.serverMessage("Acted CZ between " + found + " & " + editor.selection + "."); + graph.update(); +}; + +editor.onCtrlClick = function() { + var found = editor.findNodeOnRay(mouse.ray); + if (found === undefined){ return; } + if (editor.selection === undefined){ return; } + editor.focus(found); + abj.act_hadamard(found); + gui.serverMessage("Acted H on node " + found + "."); + graph.update(); +}; + + editor.prepare = function() { mouse.onFreeMove = editor.onFreeMove; mouse.onClick = editor.onClick; + mouse.onShiftClick = editor.onShiftClick; + mouse.onCtrlClick = editor.onCtrlClick; document.addEventListener("keydown", editor.onKey, false); editor.makeGrid(); }; editor.onKey = function(evt) { - if (evt.keyCode !== 32) {return;} - editor.setOrientation((editor.orientation + 1) % 3); + if (evt.keyCode === 32) { + editor.setOrientation((editor.orientation + 1) % 3); + } + if (evt.keyCode === 46 || evt.keyCode === 68) { + editor.deleteNode(); + } }; editor.setOrientation = function(orientation) { @@ -104,3 +136,12 @@ editor.findNodeOnRay = function(ray) { } return undefined; }; + +editor.deleteNode = function() { + if (editor.selection === undefined){ return; } + abj.del_node(editor.selection); + graph.update(); + gui.serverMessage("Deleted node " + editor.selection + "."); + editor.selection = undefined; + node_data.className = "hidden"; +}; diff --git a/static/scripts/graph.js b/static/scripts/graph.js index 64ee658..2133ee7 100644 --- a/static/scripts/graph.js +++ b/static/scripts/graph.js @@ -1,5 +1,5 @@ var graph = {}; -graph.colors = ["lightblue", "green", "yellow", "red", "pink", "orange", "purple"]; +graph.colors = ["red", "green", "yellow", "green", "pink", "orange", "purple"]; graph.prepare = function() { materials.prepare(); diff --git a/static/scripts/main.js b/static/scripts/main.js index 263480d..0074b37 100644 --- a/static/scripts/main.js +++ b/static/scripts/main.js @@ -15,6 +15,6 @@ window.onload = function() { gui.prepare(); mouse.prepare(); editor.prepare(); - bootstrap(); + //bootstrap(); gui.loop(); }; diff --git a/static/scripts/websocket.js b/static/scripts/websocket.js index 52b799a..d2a08a0 100644 --- a/static/scripts/websocket.js +++ b/static/scripts/websocket.js @@ -20,6 +20,6 @@ websocket.connect = function(update) { }; ws.onclose = function(evt) { - gui.serverMessage("Connection to server lost. Reconnect.", true); + gui.serverMessage("No connection to server. Reconnect.", true); }; };