SelectRectangle.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/Select/Select.js");
  20. /**
  21. * \class SelectRectangle
  22. * \ingroup ecma_select
  23. * \brief Selects all entities inside a user specified rectangle.
  24. */
  25. function SelectRectangle(guiAction) {
  26. Select.call(this, guiAction);
  27. this.point1 = undefined;
  28. this.point2 = undefined;
  29. this.setUiOptions("SelectRectangle.ui");
  30. }
  31. SelectRectangle.prototype = new Select();
  32. SelectRectangle.State = {
  33. SettingPoint1 : 0,
  34. SettingPoint2 : 1
  35. };
  36. SelectRectangle.prototype.selectEntities = function() {
  37. var di = EAction.getDocumentInterface();
  38. var doc = EAction.getDocument();
  39. var box = new RBox(this.point1, this.point2);
  40. var matchingEntities;
  41. if (this.crossSelection) {
  42. matchingEntities = doc.queryIntersectedEntitiesXY(box);
  43. }
  44. else {
  45. matchingEntities = doc.queryContainedEntitiesXY(box);
  46. }
  47. this.selectWithMode(matchingEntities);
  48. };
  49. SelectRectangle.prototype.beginEvent = function() {
  50. Select.prototype.beginEvent.call(this);
  51. this.setState(SelectRectangle.State.SettingPoint1);
  52. };
  53. SelectRectangle.prototype.setState = function(state) {
  54. Select.prototype.setState.call(this, state);
  55. this.getDocumentInterface().setClickMode(RAction.PickCoordinate);
  56. this.setCrosshairCursor();
  57. var tr;
  58. var appWin = RMainWindowQt.getMainWindow();
  59. switch (this.state) {
  60. case SelectRectangle.State.SettingPoint1:
  61. tr = qsTr("First corner");
  62. this.setLeftMouseTip(tr);
  63. this.setCommandPrompt(tr);
  64. this.setRightMouseTip(EAction.trCancel);
  65. this.point1 = undefined;
  66. this.point2 = undefined;
  67. break;
  68. case SelectRectangle.State.SettingPoint2:
  69. tr = qsTr("Second corner");
  70. this.setLeftMouseTip(tr);
  71. this.setCommandPrompt(tr);
  72. this.setRightMouseTip(EAction.trDone);
  73. break;
  74. }
  75. EAction.showSnapTools();
  76. };
  77. SelectRectangle.prototype.escapeEvent = function() {
  78. switch (this.state) {
  79. case SelectRectangle.State.SettingPoint1:
  80. EAction.prototype.escapeEvent.call(this);
  81. break;
  82. case SelectRectangle.State.SettingPoint2:
  83. EAction.prototype.escapeEvent.call(this);
  84. break;
  85. }
  86. };
  87. SelectRectangle.prototype.coordinateEvent = function(event) {
  88. switch (this.state) {
  89. case SelectRectangle.State.SettingPoint1:
  90. this.point1 = event.getModelPosition();
  91. this.setState(SelectRectangle.State.SettingPoint2);
  92. break;
  93. case SelectRectangle.State.SettingPoint2:
  94. this.point2 = event.getModelPosition();
  95. this.selectEntities();
  96. this.getDocumentInterface().clearPreview();
  97. this.getDocumentInterface().repaintViews();
  98. this.setState(SelectRectangle.State.SettingPoint1);
  99. break;
  100. }
  101. };
  102. SelectRectangle.prototype.coordinateEventPreview = function(event) {
  103. switch (this.state) {
  104. case SelectRectangle.State.SettingPoint2:
  105. this.point2 = event.getModelPosition();
  106. this.preview();
  107. break;
  108. default:
  109. break;
  110. }
  111. };
  112. SelectRectangle.prototype.preview = function() {
  113. if (this.state != SelectRectangle.State.SettingPoint2) {
  114. return;
  115. }
  116. Select.previewSelectionBox(
  117. this.getDocumentInterface(),
  118. new RBox(this.point1, this.point2),
  119. this.crossSelection
  120. );
  121. /*
  122. var points = new Array(
  123. this.point1,
  124. new RVector(this.point1.x, this.point2.y),
  125. this.point2,
  126. new RVector(this.point2.x, this.point1.y),
  127. this.point1
  128. );
  129. this.previewSelectionPolygon(points);
  130. */
  131. };