Duplicate.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/Edit/Edit.js");
  20. /**
  21. * \class Duplicate
  22. * \brief Copies the current selection to the clipboard.
  23. * The reference point is the center of the current selection.
  24. * \ingroup ecma_edit
  25. */
  26. function Duplicate(guiAction) {
  27. Edit.call(this, guiAction);
  28. }
  29. Duplicate.prototype = new Edit();
  30. Duplicate.prototype.beginEvent = function() {
  31. Edit.prototype.beginEvent.call(this);
  32. var doc = this.getDocument();
  33. var di = this.getDocumentInterface();
  34. var ids = doc.querySelectedEntities();
  35. // var op = new RAddObjectsOperation();
  36. // op.setText(this.getToolTitle());
  37. // var ids = doc.querySelectedEntities();
  38. // for (var i = 0; i < ids.length; ++i) {
  39. // var id = ids[i];
  40. // var e = doc.queryEntity(id);
  41. // op.addObject(e, false, true);
  42. // }
  43. // di.applyOperation(op);
  44. // copy to a local clipboard:
  45. var ms = new RMemoryStorage();
  46. var si = createSpatialIndex();
  47. var tmpDoc = new RDocument(ms, si);
  48. var tmpDi = new RDocumentInterface(tmpDoc);
  49. tmpDi.setNotifyListeners(false);
  50. var op = new RCopyOperation(new RVector(0,0), doc);
  51. op.setText(this.getToolTitle());
  52. tmpDi.applyOperation(op);
  53. op = new RPasteOperation(tmpDoc);
  54. op.setText(this.getToolTitle());
  55. op.setOffset(new RVector(0,0));
  56. op.setScale(1.0);
  57. op.setRotation(0.0);
  58. op.setFlipHorizontal(false);
  59. op.setFlipVertical(false);
  60. op.setToCurrentLayer(false);
  61. op.setOverwriteLayers(false);
  62. op.setOverwriteBlocks(false);
  63. // make sure duplicates are selected:
  64. tmpDi.selectAll();
  65. op.setKeepSelection(true);
  66. di.applyOperation(op);
  67. destr(tmpDi);
  68. // deselect originals, duplicates stay selected:
  69. di.deselectEntities(ids);
  70. EAction.handleUserMessage(qsTr("%n entity/ies duplicated", "", ids.length));
  71. this.terminate();
  72. };