SelectLayerByEntity.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 SelectLayerByEntity
  22. * \ingroup ecma_select
  23. * \brief Select all entities on the same layer.
  24. */
  25. function SelectLayerByEntity(guiAction) {
  26. Select.call(this, guiAction);
  27. this.setUiOptions("SelectLayerByEntity.ui");
  28. }
  29. SelectLayerByEntity.prototype = new Select();
  30. SelectLayerByEntity.State = {
  31. ChoosingEntity : 0
  32. };
  33. SelectLayerByEntity.prototype.selectEntities = function(entityId) {
  34. var entity = this.doc.queryEntity(entityId);
  35. if (isNull(entity)) {
  36. return;
  37. }
  38. var layerId = entity.getLayerId();
  39. // select all entities on the same layer:
  40. this.matchingEntities = this.doc.queryLayerEntities(layerId);
  41. };
  42. SelectLayerByEntity.prototype.beginEvent = function() {
  43. Select.prototype.beginEvent.call(this);
  44. this.doc = this.getDocument();
  45. this.di = this.getDocumentInterface();
  46. this.setState(SelectLayerByEntity.State.ChoosingEntity);
  47. };
  48. SelectLayerByEntity.prototype.setState = function(state) {
  49. Select.prototype.setState.call(this, state);
  50. this.setCrosshairCursor();
  51. this.getDocumentInterface().setClickMode(RAction.PickEntity);
  52. var appWin = RMainWindowQt.getMainWindow();
  53. var tr = qsTr("Choose entity on layer");
  54. this.setLeftMouseTip(tr);
  55. this.setCommandPrompt(tr);
  56. this.setRightMouseTip(EAction.trCancel);
  57. };
  58. SelectLayerByEntity.prototype.entityPickEvent = function(event) {
  59. this.matchingEntities = [];
  60. this.selectEntities(this.getEntityId(event, false));
  61. this.selectWithMode(this.matchingEntities);
  62. };
  63. SelectLayerByEntity.prototype.entityPickEventPreview = function(event) {
  64. this.di.highlightEntity(this.getEntityId(event, true));
  65. };