SelectIntersectedEntities.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 SelectIntersectedEntities
  22. * \ingroup ecma_select
  23. * \brief Select entities intersected with line.
  24. */
  25. function SelectIntersectedEntities(guiAction, select) {
  26. Select.call(this, guiAction);
  27. if (select == undefined) {
  28. select = true;
  29. }
  30. this.State = {
  31. SettingPoint1 : 0,
  32. SettingPoint2 : 1
  33. };
  34. this.point1 = undefined;
  35. this.point2 = undefined;
  36. this.select = select;
  37. this.setUiOptions("SelectIntersectedEntities.ui");
  38. }
  39. SelectIntersectedEntities.prototype = new Select();
  40. SelectIntersectedEntities.prototype.selectEntities = function() {
  41. var match;
  42. var line = new RLine(this.point1, this.point2);
  43. var matchingEntities = [];
  44. // limit search to bounding box of line:
  45. var box = line.getBoundingBox();
  46. var entities = EAction.getDocument().queryIntersectedEntitiesXY(box);
  47. for (var e = 0; e < entities.length; ++e) {
  48. var entity = EAction.getDocument().queryEntity(entities[e]);
  49. match = false;
  50. // check if the entity intersects with any of the polygon edges:
  51. match = false;
  52. if (entity.intersectsWith(line)) {
  53. match = true;
  54. }
  55. if (match) {
  56. matchingEntities.push(entities[e]);
  57. }
  58. }
  59. this.selectWithMode(matchingEntities);
  60. };
  61. SelectIntersectedEntities.prototype.beginEvent = function() {
  62. Select.prototype.beginEvent.call(this);
  63. this.setState(this.State.SettingPoint1);
  64. };
  65. SelectIntersectedEntities.prototype.setState = function(state) {
  66. Select.prototype.setState.call(this, state);
  67. this.getDocumentInterface().setClickMode(RAction.PickCoordinate);
  68. this.setCrosshairCursor();
  69. var tr;
  70. var appWin = RMainWindowQt.getMainWindow();
  71. switch (this.state) {
  72. case this.State.SettingPoint1:
  73. tr = qsTr("First point");
  74. this.setLeftMouseTip(tr);
  75. this.setCommandPrompt(tr);
  76. this.setRightMouseTip(EAction.trCancel);
  77. break;
  78. case this.State.SettingPoint2:
  79. tr = qsTr("Second point");
  80. this.setLeftMouseTip(tr);
  81. this.setCommandPrompt(tr);
  82. this.setRightMouseTip(EAction.trCancel);
  83. break;
  84. }
  85. EAction.showSnapTools();
  86. };
  87. SelectIntersectedEntities.prototype.escapeEvent = function() {
  88. switch (this.state) {
  89. case this.State.SettingPoint1:
  90. EAction.prototype.escapeEvent.call(this);
  91. break;
  92. case this.State.SettingPoint2:
  93. this.setState(this.State.SettingPoint1);
  94. break;
  95. }
  96. };
  97. SelectIntersectedEntities.prototype.coordinateEvent = function(event) {
  98. var di = this.getDocumentInterface();
  99. switch (this.state) {
  100. case this.State.SettingPoint1:
  101. this.point1 = event.getModelPosition();
  102. di.setRelativeZero(this.point1);
  103. this.setState(this.State.SettingPoint2);
  104. break;
  105. case this.State.SettingPoint2:
  106. this.point2 = event.getModelPosition();
  107. this.selectEntities();
  108. di.setRelativeZero(this.point2);
  109. this.point1 = this.point2;
  110. this.setState(this.State.SettingPoint1);
  111. break;
  112. }
  113. };
  114. SelectIntersectedEntities.prototype.coordinateEventPreview = function(event) {
  115. switch (this.state) {
  116. case this.State.SettingPoint2:
  117. this.point2 = event.getModelPosition();
  118. this.getDocumentInterface().addAuxShapeToPreview(
  119. new RLine(this.point1, this.point2));
  120. break;
  121. default:
  122. break;
  123. }
  124. };