RestrictAngleLength.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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("scripts/Snap/Snap.js");
  20. /**
  21. * RSnapRestriction implementation. Extends RRestrictAngleLength
  22. * with an options toolbar which allows the user to enter the angle / length.
  23. */
  24. function RRestrictAngleLengthExtension(di) {
  25. RRestrictAngleLength.call(this, di);
  26. // create action to show options for the restriction and handle user interface events:
  27. this.action = new EAction(
  28. RGuiAction.getByScriptFile(RRestrictAngleLengthExtension.includeBasePath + "/RestrictAngleLength.js")
  29. );
  30. this.action.setUiOptions(RRestrictAngleLengthExtension.includeBasePath + "/RestrictAngleLength.ui");
  31. var restriction = this;
  32. this.action.slotRestrictAngleChanged = function(value) {
  33. restriction.setRestrictAngle(value);
  34. }
  35. this.action.slotAngleChanged = function(value) {
  36. restriction.setAngle(value);
  37. };
  38. this.action.slotBaseAngleChanged = function(value) {
  39. restriction.setBaseAngle(value);
  40. };
  41. this.action.slotRestrictLengthChanged = function(value) {
  42. restriction.setRestrictLength(value);
  43. }
  44. this.action.slotLengthChanged = function(value) {
  45. restriction.setLength(value);
  46. };
  47. this.action.slotBaseLengthChanged = function(value) {
  48. restriction.setBaseLength(value);
  49. };
  50. }
  51. RRestrictAngleLengthExtension.prototype = new RRestrictAngleLength();
  52. RRestrictAngleLengthExtension.includeBasePath = includeBasePath;
  53. RRestrictAngleLengthExtension.prototype.showUiOptions = function() {
  54. this.action.showUiOptions(false);
  55. };
  56. RRestrictAngleLengthExtension.prototype.hideUiOptions = function() {
  57. this.action.hideUiOptions();
  58. };
  59. /**
  60. * \class RestrictAngleLength
  61. * \ingroup ecma_snap
  62. * \brief Restriction of angle or distance.
  63. */
  64. function RestrictAngleLength(guiAction) {
  65. Snap.call(this, guiAction);
  66. }
  67. RestrictAngleLength.prototype = new Snap();
  68. RestrictAngleLength.prototype.beginEvent = function() {
  69. Snap.prototype.beginEvent.call(this);
  70. var di = this.getDocumentInterface();
  71. var sr = di.getSnapRestriction();
  72. if (!isNull(sr)) {
  73. if (isOfType(sr, RRestrictAngleLength)) {
  74. // already active: disable:
  75. di.setSnapRestriction(new RRestrictOff(di));
  76. var guiAction = RGuiAction.getByScriptFile("scripts/Snap/RestrictOff/RestrictOff.js");
  77. if (!isNull(guiAction)) {
  78. guiAction.slotTrigger();
  79. }
  80. this.terminate();
  81. return;
  82. }
  83. }
  84. // activate restriction:
  85. di.setSnapRestriction(new RRestrictAngleLengthExtension(di));
  86. this.terminate();
  87. };