SnapCoordinatePolar.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. 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("../SnapCoordinate/SnapCoordinate.js");
  20. include("../../WidgetFactory.js");
  21. /**
  22. * RSnap implementation for polar coordinate snap.
  23. */
  24. function RSnapCoordinatePolar(guiAction) {
  25. RSnapCoordinate.call(this, guiAction);
  26. this.r = 0.0;
  27. this.a = 0.0;
  28. }
  29. RSnapCoordinatePolar.prototype = new RSnapCoordinate();
  30. RSnapCoordinatePolar.prototype.initAction = function(guiAction) {
  31. this.action = new EAction(guiAction);
  32. if (!isNull(this.action.setUiOptions)) {
  33. this.action.setUiOptions(SnapCoordinatePolar.includeBasePath + "/SnapCoordinatePolar.ui");
  34. }
  35. var snap = this;
  36. this.action.slotRChanged = function(value) {
  37. snap.r = value;
  38. snap.update();
  39. };
  40. this.action.slotAChanged = function(value) {
  41. snap.a = value;
  42. snap.update();
  43. };
  44. this.action.slotRelativeChanged = function(on) {
  45. snap.relative = on;
  46. snap.update();
  47. };
  48. this.action.slotSet = function() {
  49. var ce = snap.getCoordinateEvent();
  50. if (!isNull(ce)) {
  51. var di = EAction.getDocumentInterface();
  52. di.coordinateEvent(ce);
  53. }
  54. };
  55. };
  56. RSnapCoordinatePolar.prototype.getCoordinate = function() {
  57. var di = EAction.getDocumentInterface();
  58. var coordinate = RVector.createPolar(this.r, this.a);
  59. if (this.relative) {
  60. coordinate = coordinate.operator_add(di.getRelativeZero());
  61. }
  62. return coordinate;
  63. };
  64. /**
  65. * \class SnapCoordinatePolar
  66. * \ingroup ecma_snap
  67. * \brief Enter polar coordinate.
  68. */
  69. function SnapCoordinatePolar(guiAction) {
  70. Snap.call(this, guiAction);
  71. }
  72. SnapCoordinatePolar.prototype = new Snap();
  73. SnapCoordinatePolar.includeBasePath = includeBasePath;
  74. SnapCoordinatePolar.prototype.beginEvent = function() {
  75. Snap.prototype.beginEvent.call(this);
  76. var guiAction = RGuiAction.getByScriptFile("scripts/Snap/SnapCoordinatePolar/SnapCoordinatePolar.js");
  77. var s = new RSnapCoordinatePolar(guiAction);
  78. this.getDocumentInterface().setSnap(s);
  79. this.terminate();
  80. };