InfoPosition.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/Information/Information.js");
  20. /**
  21. * \class InfoPosition
  22. * \ingroup ecma_information
  23. * \brief Query point position.
  24. */
  25. function InfoPosition(guiAction) {
  26. Information.call(this, guiAction);
  27. this.pos = undefined;
  28. this.lastPos = undefined;
  29. this.setUiOptions("../Information.ui");
  30. }
  31. InfoPosition.prototype = new Information();
  32. InfoPosition.State = {
  33. SettingPoint : 0
  34. };
  35. InfoPosition.prototype.beginEvent = function() {
  36. Information.prototype.beginEvent.call(this);
  37. this.setState(InfoPosition.State.SettingPoint);
  38. };
  39. InfoPosition.prototype.setState = function(state) {
  40. Information.prototype.setState.call(this, state);
  41. var di = this.getDocumentInterface();
  42. di.setClickMode(RAction.PickCoordinate);
  43. this.setCrosshairCursor();
  44. var appWin = RMainWindowQt.getMainWindow();
  45. switch (this.state) {
  46. case InfoPosition.State.SettingPoint:
  47. var tsPoint = qsTr("Point");
  48. this.setCommandPrompt(tsPoint);
  49. this.setLeftMouseTip(tsPoint);
  50. this.setRightMouseTip(EAction.trCancel);
  51. break;
  52. }
  53. EAction.showSnapTools();
  54. };
  55. InfoPosition.prototype.escapeEvent = function() {
  56. switch (this.state) {
  57. case InfoPosition.State.SettingPoint:
  58. EAction.prototype.escapeEvent.call(this);
  59. break;
  60. }
  61. };
  62. InfoPosition.prototype.getDisplayedLabel = function(p, prec) {
  63. if (isNull(prec)) {
  64. prec = 4;
  65. }
  66. return coordinateToString(p, prec, false, false, this.getDocument());
  67. };
  68. InfoPosition.prototype.pickCoordinate = function(event, preview) {
  69. var appWin = EAction.getMainWindow();
  70. var di = this.getDocumentInterface();
  71. switch (this.state) {
  72. case InfoPosition.State.SettingPoint:
  73. this.pos = event.getModelPosition();
  74. if (!preview) {
  75. this.lastPos = this.pos;
  76. }
  77. var op = this.getOperation(preview);
  78. if (!preview) {
  79. appWin.handleUserInfo(this.getDisplayedLabel(this.pos, 8));
  80. if (!isNull(op)) {
  81. if (this.addToDrawing) {
  82. di.applyOperation(op);
  83. }
  84. else {
  85. destr(op);
  86. }
  87. }
  88. }
  89. else {
  90. di.previewOperation(op);
  91. }
  92. break;
  93. }
  94. };
  95. InfoPosition.prototype.getOperation = function(preview) {
  96. if (isNull(this.pos)) {
  97. return undefined;
  98. }
  99. var op = new RAddObjectsOperation();
  100. op.setText(this.getToolTitle());
  101. var di = this.getDocumentInterface();
  102. var view = di.getLastKnownViewWithFocus();
  103. view = getRGraphicsView(view);
  104. view.clearTextLabels();
  105. this.addShape(op, new RPoint(this.pos), preview);
  106. var label = this.getDisplayedLabel(this.pos);
  107. this.addTextLabel(op, view, this.pos, label, preview);
  108. if (preview && !this.addToDrawing && !isNull(this.lastPos)) {
  109. label = this.getDisplayedLabel(this.lastPos);
  110. this.addTextLabel(op, view, this.lastPos, label, preview);
  111. this.addShape(op, new RPoint(this.lastPos), preview);
  112. }
  113. return op;
  114. };