ShapeRectanglePP.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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("../Shape.js");
  20. include("../../DrawBasedOnRectanglePP.js");
  21. include("scripts/Draw/Hatch/Hatch.js");
  22. /**
  23. * \class ShapeRectanglePP
  24. * \brief Rectangle from two corner points.
  25. * \ingroup ecma_draw_shape
  26. */
  27. function ShapeRectanglePP(guiAction) {
  28. DrawBasedOnRectanglePP.call(this, guiAction);
  29. this.createPolyline = false;
  30. this.fill = false;
  31. this.roundCorners = false;
  32. this.radius = 1.0;
  33. this.setUiOptions(["../Shape.ui", "ShapeRectanglePP.ui"]);
  34. }
  35. ShapeRectanglePP.prototype = new DrawBasedOnRectanglePP();
  36. ShapeRectanglePP.prototype.beginEvent = function() {
  37. DrawBasedOnRectanglePP.prototype.beginEvent.call(this);
  38. };
  39. ShapeRectanglePP.prototype.getOperation = function(preview) {
  40. var doc = this.getDocument();
  41. var corners = this.getCorners();
  42. var op = new RAddObjectsOperation();
  43. op.setText(this.getToolTitle());
  44. var shapes = this.getShapes(corners);
  45. for (var i=0; i<shapes.length; ++i) {
  46. var e = shapeToEntity(this.getDocument(), shapes[i]);
  47. if (isNull(e)) {
  48. continue;
  49. }
  50. op.addObject(e);
  51. }
  52. Shape.complementOperation(this, doc, op, shapes);
  53. return op;
  54. };
  55. ShapeRectanglePP.prototype.getShapes = function(corners) {
  56. return Shape.getShapes(this, corners);
  57. };
  58. ShapeRectanglePP.prototype.slotCreatePolylineChanged = function(checked) {
  59. Shape.slotCreatePolylineChanged(this, checked);
  60. };
  61. ShapeRectanglePP.prototype.slotFillChanged = function(checked) {
  62. Shape.slotFillChanged(this, checked);
  63. };
  64. ShapeRectanglePP.prototype.slotRoundCornersChanged = function(checked) {
  65. Shape.slotRoundCornersChanged(this, checked);
  66. };
  67. ShapeRectanglePP.prototype.slotRadiusChanged = function(v) {
  68. Shape.slotRadiusChanged(this, v);
  69. };
  70. ShapeRectanglePP.prototype.slotRotateChanged = function(v) {
  71. this.rotate = v;
  72. this.updatePreview(true);
  73. };
  74. ShapeRectanglePP.prototype.slotRotationChanged = function(value) {
  75. if (isNumber(value)) {
  76. this.rotation = value;
  77. }
  78. else {
  79. this.rotation = 0.0;
  80. }
  81. this.updatePreview(true);
  82. };
  83. ShapeRectanglePP.prototype.initUiOptions = function(resume, optionsToolBar) {
  84. DrawBasedOnRectanglePP.prototype.initUiOptions.call(this, resume, optionsToolBar);
  85. var w;
  86. this.createPolyline = RSettings.getBoolValue(this.settingsGroup + "/CreatePolyline", false);
  87. this.fill = RSettings.getBoolValue(this.settingsGroup + "/Fill", false);
  88. this.roundCorners = RSettings.getBoolValue(this.settingsGroup + "/RoundCorners", false);
  89. this.radius = RSettings.getDoubleValue(this.settingsGroup + "/Radius", 1.0);
  90. w = optionsToolBar.findChild("CreatePolyline");
  91. if (!isNull(w)) {
  92. w.checked = this.createPolyline;
  93. }
  94. w = optionsToolBar.findChild("Fill");
  95. if (!isNull(w)) {
  96. w.checked = this.fill;
  97. }
  98. w = optionsToolBar.findChild("RoundCorners");
  99. if (!isNull(w)) {
  100. w.checked = this.roundCorners;
  101. }
  102. w = optionsToolBar.findChild("Radius");
  103. if (!isNull(w)) {
  104. w.setValue(this.radius);
  105. }
  106. };
  107. ShapeRectanglePP.prototype.hideUiOptions = function(saveToSettings) {
  108. DrawBasedOnRectanglePP.prototype.hideUiOptions.call(this, saveToSettings);
  109. RSettings.setValue(this.settingsGroup + "/CreatePolyline", this.createPolyline);
  110. RSettings.setValue(this.settingsGroup + "/Fill", this.fill);
  111. RSettings.setValue(this.settingsGroup + "/RoundCorners", this.roundCorners);
  112. RSettings.setValue(this.settingsGroup + "/Radius", this.radius);
  113. };