Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

155 lignes
4.3KB

  1. var editor = {};
  2. var pi2 = Math.PI / 2;
  3. editor.selection = undefined;
  4. editor.mouseOver = undefined;
  5. editor.orientations = [
  6. new THREE.Euler(pi2, 0, 0),
  7. new THREE.Euler(0, 0, 0),
  8. new THREE.Euler(pi2, 0, pi2),
  9. ];
  10. editor.onFreeMove = function() {
  11. var found = editor.findNodeOnRay(mouse.ray);
  12. if (editor.mouseOver !== found) {
  13. editor.mouseOver = found;
  14. if (found) {
  15. gui.nodeMessage("Node " + found + " (VOP:" + abj.node[found].vop + ")");
  16. } else {
  17. gui.hideNodeMessage();
  18. }
  19. }
  20. };
  21. editor.focus = function(node) {
  22. editor.grid.position.copy(abj.node[node].position);
  23. gui.controls.target.copy(abj.node[node].position);
  24. gui.hideNodeMessage();
  25. editor.selection = node;
  26. gui.serverMessage("Selected node " + node + ".");
  27. node_name.innerHTML = "Node " + node;
  28. node_data.className = "visible";
  29. node_vop.innerHTML = "VOP: " + abj.node[node].vop;
  30. };
  31. editor.addQubitAtPoint = function(point) {
  32. if (point === null) {
  33. return;
  34. }
  35. point.round();
  36. // Check for clashes
  37. for (var node in abj.node) {
  38. var delta = new THREE.Vector3();
  39. delta.subVectors(abj.node[node].position, point);
  40. if (delta.length()<0.1){ return; }
  41. }
  42. // TODO: This SUCKS
  43. var new_node = point.x + "." + point.y + "." + point.z;
  44. abj.add_node(new_node, { position: point, vop:0 });
  45. editor.focus(new_node);
  46. graph.update();
  47. gui.serverMessage("Created node " + new_node +".");
  48. };
  49. editor.onClick = function() {
  50. var found = editor.findNodeOnRay(mouse.ray);
  51. if (found) {
  52. editor.focus(found);
  53. } else {
  54. var intersection = mouse.ray.intersectPlane(editor.plane);
  55. if (intersection !== null) {
  56. editor.addQubitAtPoint(intersection);
  57. }
  58. }
  59. };
  60. editor.onShiftClick = function() {
  61. var found = editor.findNodeOnRay(mouse.ray);
  62. if (found === undefined){ return; }
  63. if (editor.selection === undefined){ return; }
  64. if (found === editor.selection){ return; }
  65. abj.act_cz(found, editor.selection);
  66. editor.focus(found);
  67. gui.serverMessage("Acted CZ between " + found + " & " + editor.selection + ".");
  68. graph.update();
  69. };
  70. editor.onCtrlClick = function() {
  71. var found = editor.findNodeOnRay(mouse.ray);
  72. if (found === undefined){ return; }
  73. if (editor.selection === undefined){ return; }
  74. editor.focus(found);
  75. abj.act_hadamard(found);
  76. gui.serverMessage("Acted H on node " + found + ".");
  77. graph.update();
  78. };
  79. editor.prepare = function() {
  80. mouse.onFreeMove = editor.onFreeMove;
  81. mouse.onClick = editor.onClick;
  82. mouse.onShiftClick = editor.onShiftClick;
  83. mouse.onCtrlClick = editor.onCtrlClick;
  84. document.addEventListener("keydown", editor.onKey, false);
  85. editor.makeGrid();
  86. };
  87. editor.onKey = function(evt) {
  88. if (evt.keyCode === 32) {
  89. editor.setOrientation((editor.orientation + 1) % 3);
  90. }
  91. if (evt.keyCode === 46 || evt.keyCode === 68) {
  92. editor.deleteNode();
  93. }
  94. };
  95. editor.setOrientation = function(orientation) {
  96. editor.orientation = orientation;
  97. var rotation = editor.orientations[orientation];
  98. var normal = new THREE.Vector3(0, 1, 0);
  99. normal.applyEuler(rotation);
  100. editor.grid.rotation.copy(rotation);
  101. editor.plane = new THREE.Plane();
  102. editor.plane.setFromNormalAndCoplanarPoint(normal, editor.grid.position);
  103. gui.render();
  104. };
  105. editor.makeGrid = function() {
  106. editor.grid = new THREE.GridHelper(10, 1);
  107. editor.grid.setColors(0xbbbbbb, 0xeeeeee);
  108. editor.setOrientation(0);
  109. gui.scene.add(editor.grid);
  110. };
  111. editor.update = function() {};
  112. // Gets a reference to the node nearest to the mouse cursor
  113. editor.findNodeOnRay = function(ray) {
  114. for (var n in abj.node) {
  115. if (ray.distanceSqToPoint(abj.node[n].position) < 0.012) {
  116. return n;
  117. }
  118. }
  119. return undefined;
  120. };
  121. editor.deleteNode = function() {
  122. if (editor.selection === undefined){ return; }
  123. abj.del_node(editor.selection);
  124. graph.update();
  125. gui.serverMessage("Deleted node " + editor.selection + ".");
  126. editor.selection = undefined;
  127. node_data.className = "hidden";
  128. };
  129. editor.localComplementation = function() {
  130. if (editor.selection === undefined){ return; }
  131. abj.local_complementation(editor.selection);
  132. graph.update();
  133. gui.serverMessage("Inverted neighbourhood of " + editor.selection + ".");
  134. };