SnapXManual.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * Copyright (c) 2013 by Robert S. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("scripts/EAction.js");
  20. /**
  21. * \class SnapXManual
  22. * \ingroup ecma_snap
  23. * \brief Lock X position.
  24. */
  25. function SnapXManual(guiAction) {
  26. EAction.call(this, guiAction);
  27. this.State = {
  28. PickingPoint1 : 0,
  29. PickingPoint2 : 1
  30. };
  31. this.state = this.State.PickingPoint1;
  32. this.setCommandPrompt("Specify point for X coordinate");
  33. this.point1 = undefined;
  34. this.point2 = undefined;
  35. };
  36. SnapXManual.prototype = new EAction();
  37. SnapXManual.prototype.beginEvent = function() {
  38. EAction.prototype.beginEvent.call(this);
  39. this.di = this.getDocumentInterface();
  40. this.di.setClickMode(RAction.PickCoordinate);
  41. this.base = this.getOverrideBase();
  42. if (isNull(this.base)) {
  43. qWarning("No base action to override");
  44. this.terminate();
  45. return;
  46. }
  47. if (this.base.getClickMode() !== RAction.PickCoordinate) {
  48. qWarning("No coordinate requested at this point");
  49. this.terminate();
  50. }
  51. };
  52. SnapXManual.prototype.coordinateEvent = function(event) {
  53. if (this.state === this.State.PickingPoint1) {
  54. this.point1 = event.getModelPosition();
  55. this.state = this.State.PickingPoint2;
  56. this.setCommandPrompt("Specify point for Y coordinate");
  57. }
  58. else {
  59. this.point2 = event.getModelPosition();
  60. var p = new RVector(this.point1.x, this.point2.y);
  61. if (!isNull(this.base)) {
  62. this.base.coordinateEvent(
  63. new RCoordinateEvent(
  64. p,
  65. event.getGraphicsScene(),
  66. event.getGraphicsView()
  67. )
  68. );
  69. }
  70. this.terminate();
  71. }
  72. };
  73. SnapXManual.prototype.coordinateEventPreview = function(event) {
  74. if (this.state === this.State.PickingPoint2) {
  75. this.point2 = event.getModelPosition();
  76. var p = new RVector(this.point1.x, this.point2.y);
  77. if (!isNull(this.base)) {
  78. this.base.coordinateEventPreview(
  79. new RCoordinateEvent(
  80. p,
  81. event.getGraphicsScene(),
  82. event.getGraphicsView()
  83. )
  84. );
  85. var point = new RVector(this.point1.x, this.point2.y);
  86. var line = new RLine(this.point1, point);
  87. this.di.addAuxShapeToPreview(line);
  88. this.di.setCursorPosition(p);
  89. }
  90. }
  91. };