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.

editor.js 4.5KB

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