TranslateRotate.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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("../Translate/Translate.js");
  20. /**
  21. * \class TranslateRotate
  22. * \brief Translates and rotates selected entities. Supports multiple copies.
  23. * \ingroup ecma_modify
  24. */
  25. function TranslateRotate(guiAction) {
  26. Translate.call(this, guiAction);
  27. this.angle = 0.0;
  28. this.setUiOptions("TranslateRotate.ui");
  29. }
  30. TranslateRotate.prototype = new Translate();
  31. TranslateRotate.includeBasePath = includeBasePath;
  32. /**
  33. * Shows the translation rotation dialog.
  34. *
  35. * \return True if the dialog was accepted, false if it was canceled.
  36. */
  37. TranslateRotate.prototype.showDialog = function() {
  38. var dialog = WidgetFactory.createDialog(TranslateRotate.includeBasePath, "TranslateRotateDialog.ui");
  39. WidgetFactory.restoreState(dialog);
  40. var widgets = getWidgets(dialog);
  41. // initialize dialog angle to angle used in tool options toolbar:
  42. widgets["Angle"].setValue(this.angle);
  43. if (!dialog.exec()) {
  44. destr(dialog);
  45. EAction.activateMainWindow();
  46. return false;
  47. }
  48. if (widgets["DeleteOriginal"].checked===true) {
  49. this.copies = 0;
  50. }
  51. else if (widgets["KeepOriginal"].checked===true) {
  52. this.copies = 1;
  53. }
  54. else {
  55. this.copies = widgets["NumberOfCopies"].getValue();
  56. }
  57. this.angle = widgets["Angle"].getValue();
  58. this.useCurrentAttributes = (widgets["UseCurrentAttributes"].checked===true);
  59. WidgetFactory.saveState(dialog);
  60. destr(dialog);
  61. EAction.activateMainWindow();
  62. return true;
  63. };
  64. TranslateRotate.prototype.getOperation = function(preview, selectResult) {
  65. // skip implementation from class Translate and use
  66. // Transform implementation instead:
  67. return Transform.prototype.getOperation.call(this, preview, selectResult);
  68. };
  69. /**
  70. * Callback function for Transform.getOperation.
  71. */
  72. TranslateRotate.prototype.transform = function(entity, k, op, preview, flags) {
  73. entity.rotate(this.angle * k, this.referencePoint);
  74. var delta = this.targetPoint.operator_subtract(this.referencePoint);
  75. entity.move(delta.operator_multiply(k));
  76. op.addObject(entity, flags);
  77. };
  78. TranslateRotate.prototype.slotAngleChanged = function(value) {
  79. this.angle = value;
  80. };