ToggleLayerVisibility.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/Layer/Layer.js");
  20. /**
  21. * \class ToggleLayerVisibility
  22. * \ingroup ecma_layer
  23. * \brief Toggle layer visibility.
  24. */
  25. function ToggleLayerVisibility(guiAction) {
  26. Layer.call(this, guiAction);
  27. }
  28. ToggleLayerVisibility.prototype = new Layer();
  29. ToggleLayerVisibility.prototype.beginEvent = function() {
  30. Layer.prototype.beginEvent.call(this);
  31. var layers = this.getSelectedLayers();
  32. var showFrozen = Layer.getShowFrozen();
  33. var freezeLayer = Layer.getFreezeLayer();
  34. var op = new RModifyObjectsOperation();
  35. for (var i=0; i<layers.length; i++) {
  36. var layer = layers[i];
  37. // separate column for frozen is shown:
  38. // always toggle off:
  39. if (showFrozen) {
  40. layer.setOff(!layer.isOff());
  41. op.addObject(layer);
  42. }
  43. else {
  44. // freeze layers:
  45. if (freezeLayer) {
  46. if (!layer.isFrozen() && !layer.isOff()) {
  47. layer.setFrozen(true);
  48. op.addObject(layer);
  49. }
  50. else {
  51. layer.setFrozen(false);
  52. layer.setOff(false);
  53. op.addObject(layer);
  54. }
  55. }
  56. // never freeze layers:
  57. else {
  58. layer.setFrozen(false);
  59. layer.setOff(!layer.isOff());
  60. op.addObject(layer);
  61. }
  62. }
  63. }
  64. if (!op.isEmpty()) {
  65. var di = this.getDocumentInterface();
  66. di.applyOperation(op);
  67. }
  68. else {
  69. destr(op);
  70. }
  71. this.terminate();
  72. };
  73. ToggleLayerVisibility.prototype.getSelectedLayers = function() {
  74. return [ this.getCurrentLayer() ];
  75. };