EllipseRR.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/Draw/Ellipse/Ellipse.js");
  20. include("../../DrawBasedOnRectangleSize.js");
  21. include("scripts/ShapeAlgorithms.js");
  22. /**
  23. * \class EllipseRR
  24. * \brief Ellipse from position and radii.
  25. * \ingroup ecma_draw_ellipse
  26. */
  27. function EllipseRR(guiAction) {
  28. DrawBasedOnRectangleSize.call(this, guiAction);
  29. this.dialogUiFile = "EllipseRRDialog.ui";
  30. this.setUiOptions("EllipseRR.ui");
  31. }
  32. EllipseRR.prototype = new DrawBasedOnRectangleSize();
  33. EllipseRR.prototype.getShapes = function(corners) {
  34. var lines = [];
  35. for (var i=0; i<corners.length; ++i) {
  36. lines.push(new RLine(corners[i], corners[(i+1)%corners.length]));
  37. }
  38. var ellipse = ShapeAlgorithms.createEllipseInscribedFromLines(lines[0], lines[1], lines[2], lines[3]);
  39. ellipse = Ellipse.postProcess(ellipse);
  40. return [ ellipse ];
  41. };
  42. EllipseRR.prototype.getAuxPreview = function() {
  43. if (isNull(this.corners) || this.corners.length===0) {
  44. return undefined;
  45. }
  46. var ret = [];
  47. for (var i=0; i<this.corners.length; ++i) {
  48. ret.push(new RLine(this.corners[i], this.corners[(i+1)%this.corners.length]));
  49. }
  50. return ret;
  51. };
  52. EllipseRR.prototype.slotXRadiusChanged = function(value) {
  53. this.width = value * 2;
  54. this.updateOkButton();
  55. this.updatePreview(true);
  56. };
  57. EllipseRR.prototype.slotYRadiusChanged = function(value) {
  58. this.height = value * 2;
  59. this.updateOkButton();
  60. this.updatePreview(true);
  61. };