SelectContour.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 SelectContour
  22. * \ingroup ecma_select
  23. * \brief Select connected entities.
  24. */
  25. function SelectContour(guiAction) {
  26. Select.call(this, guiAction);
  27. this.tolerance = 0.0;
  28. this.sameLayer = false;
  29. this.setUiOptions("SelectContour.ui");
  30. }
  31. SelectContour.prototype = new Select();
  32. SelectContour.State = {
  33. ChoosingEntity : 0
  34. };
  35. SelectContour.prototype.beginEvent = function() {
  36. Select.prototype.beginEvent.call(this);
  37. this.setState(SelectContour.State.ChoosingEntity);
  38. };
  39. SelectContour.prototype.setState = function(state) {
  40. var di = this.getDocumentInterface();
  41. di.setClickMode(RAction.PickEntity);
  42. this.setCrosshairCursor();
  43. var appWin = RMainWindowQt.getMainWindow();
  44. var tr = qsTr("Choose entity of contour");
  45. this.setLeftMouseTip(tr);
  46. this.setCommandPrompt(tr);
  47. this.setRightMouseTip(EAction.trCancel);
  48. };
  49. SelectContour.prototype.entityPickEvent = function(event) {
  50. this.selectEntities(this.getEntityId(event, false));
  51. };
  52. SelectContour.prototype.selectEntities = function(entityId) {
  53. var doc = this.getDocument();
  54. var layerId = RObject.INVALID_ID;
  55. if (this.sameLayer) {
  56. var e = doc.queryEntityDirect(entityId);
  57. if (!isNull(e)) {
  58. layerId = e.getLayerId();
  59. }
  60. }
  61. var matchingEntities = SelectContour.getConnectedEntities(doc, entityId, this.tolerance, layerId);
  62. this.selectWithMode(matchingEntities);
  63. };
  64. SelectContour.prototype.entityPickEventPreview = function(event) {
  65. var di = this.getDocumentInterface();
  66. var id = this.getEntityId(event, true);
  67. di.highlightEntity(id);
  68. };
  69. SelectContour.prototype.slotToleranceChanged = function(value) {
  70. this.tolerance = value;
  71. };
  72. SelectContour.prototype.slotSameLayerChanged = function(value) {
  73. this.sameLayer = value;
  74. };
  75. /**
  76. * \return Array of entity IDs of entities which are directly or indirectly
  77. * connected to the given entity, including the given entityId.
  78. */
  79. SelectContour.getConnectedEntities = function(doc, entityId, tolerance, layerId) {
  80. if (isNull(layerId)) {
  81. layerId = RObject.INVALID_ID;
  82. }
  83. return doc.queryConnectedEntities(entityId, tolerance, layerId);
  84. };