EditHatch.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. /**
  20. * \ingroup ecma_modify
  21. *
  22. * \brief This module contains the ECMAScript implementation of the hatch
  23. * editing tool.
  24. */
  25. include("scripts/Modify/Modify.js");
  26. include("scripts/Draw/Hatch/HatchDialog.js");
  27. /**
  28. * \class EditHatch
  29. * \brief Edit hatch.
  30. * \ingroup ecma_modify
  31. */
  32. function EditHatch(guiAction) {
  33. Modify.call(this, guiAction);
  34. this.entity = undefined;
  35. }
  36. EditHatch.prototype = new Modify();
  37. EditHatch.State = {
  38. ChoosingEntity : 0
  39. };
  40. EditHatch.prototype.beginEvent = function() {
  41. Modify.prototype.beginEvent.call(this);
  42. this.setState(EditHatch.State.ChoosingEntity);
  43. };
  44. EditHatch.prototype.setState = function(state) {
  45. Modify.prototype.setState.call(this, state);
  46. this.getDocumentInterface().setClickMode(RAction.PickEntity);
  47. this.setCrosshairCursor();
  48. var appWin = RMainWindowQt.getMainWindow();
  49. switch (this.state) {
  50. case EditHatch.State.ChoosingEntity:
  51. var tr = qsTr("Choose hatch");
  52. this.setLeftMouseTip(tr);
  53. this.setCommandPrompt(tr);
  54. break;
  55. }
  56. this.setRightMouseTip(EAction.trCancel);
  57. };
  58. EditHatch.prototype.pickEntity = function(event, preview) {
  59. var doc = this.getDocument();
  60. var entityId = this.getEntityId(event, preview);
  61. var entity = doc.queryEntity(entityId);
  62. if (isNull(entity)) {
  63. this.entity = undefined;
  64. this.updatePreview();
  65. return;
  66. }
  67. switch (this.state) {
  68. case EditHatch.State.ChoosingEntity:
  69. if (isHatchEntity(entity)) {
  70. this.entity = entity;
  71. }
  72. if (preview) {
  73. this.updatePreview();
  74. }
  75. else {
  76. EditHatch.editHatch(entity);
  77. }
  78. break;
  79. }
  80. };
  81. EditHatch.prototype.getHighlightedEntities = function() {
  82. var ret = [];
  83. if (isEntity(this.entity)) {
  84. ret.push(this.entity.getId());
  85. }
  86. return ret;
  87. };
  88. /**
  89. * This static method may also be accessed by other tools to edit the
  90. * given hatch entity in a hatch dialog.
  91. */
  92. EditHatch.editHatch = function(entity) {
  93. if (!isHatchEntity(entity)) {
  94. return;
  95. }
  96. var dialog = new HatchDialog();
  97. var hatchData = dialog.show(entity.getData());
  98. if (isNull(hatchData)) {
  99. // dialog canceled:
  100. return;
  101. }
  102. var newEntity = entity.clone();
  103. newEntity.setData(hatchData);
  104. var op = new RModifyObjectOperation(newEntity);
  105. if (!isNull(op)) {
  106. var di = EAction.getDocumentInterface();
  107. di.applyOperation(op);
  108. di.selectEntity(entity.getId());
  109. }
  110. };