EditFromReference.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/Block/Block.js");
  20. /**
  21. * \class EditFromReference
  22. * \brief Edits the block that is referenced by the block reference
  23. * the user clicks.
  24. * \ingroup ecma_block
  25. */
  26. function EditFromReference(guiAction) {
  27. Block.call(this, guiAction);
  28. this.entity = undefined;
  29. }
  30. EditFromReference.prototype = new Block();
  31. EditFromReference.State = {
  32. ChoosingEntity : 0
  33. };
  34. EditFromReference.prototype.beginEvent = function() {
  35. Block.prototype.beginEvent.call(this);
  36. this.setState(EditFromReference.State.ChoosingEntity);
  37. };
  38. EditFromReference.prototype.setState = function(state) {
  39. Block.prototype.setState.call(this, state);
  40. this.getDocumentInterface().setClickMode(RAction.PickEntity);
  41. this.setCrosshairCursor();
  42. var appWin = RMainWindowQt.getMainWindow();
  43. switch (this.state) {
  44. case EditFromReference.State.ChoosingEntity:
  45. var tr = qsTr("Choose block reference");
  46. this.setLeftMouseTip(tr);
  47. this.setCommandPrompt(tr);
  48. break;
  49. }
  50. this.setRightMouseTip(EAction.trCancel);
  51. };
  52. EditFromReference.prototype.escapeEvent = function() {
  53. switch (this.state) {
  54. case EditFromReference.State.ChoosingEntity:
  55. EAction.prototype.escapeEvent.call(this);
  56. break;
  57. }
  58. };
  59. EditFromReference.prototype.pickEntity = function(event, preview) {
  60. var di = this.getDocumentInterface();
  61. var doc = this.getDocument();
  62. var entityId = this.getEntityId(event, preview);
  63. var entity = doc.queryEntity(entityId);
  64. if (isNull(entity)) {
  65. return;
  66. }
  67. switch (this.state) {
  68. case EditFromReference.State.ChoosingEntity:
  69. if (isBlockReferenceEntity(entity)) {
  70. this.entity = entity;
  71. }
  72. else {
  73. if (!preview) {
  74. EAction.warnNotBlockReference();
  75. }
  76. break;
  77. }
  78. if (preview) {
  79. this.updatePreview();
  80. }
  81. else {
  82. var blockName = entity.getReferencedBlockName();
  83. //di.setCurrentBlock(blockName);
  84. this.editBlock(blockName);
  85. this.terminate();
  86. }
  87. break;
  88. }
  89. };
  90. EditFromReference.prototype.getHighlightedEntities = function() {
  91. var ret = [];
  92. if (isEntity(this.entity)) {
  93. ret.push(this.entity.getId());
  94. }
  95. return ret;
  96. };