IsometricGridTop.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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("../IsometricView.js");
  20. /**
  21. * Helper class to update grid button status when focus changes
  22. * (e.g. other view is activated).
  23. */
  24. function ProjectionFocusListener(action, proj) {
  25. RViewFocusListenerAdapter.call(this);
  26. this.guiAction = action;
  27. this.proj = proj;
  28. }
  29. ProjectionFocusListener.prototype = new RViewFocusListenerAdapter();
  30. ProjectionFocusListener.prototype.updateFocus = function(view) {
  31. if (isNull(view)) {
  32. this.guiAction.setChecked(false);
  33. return;
  34. }
  35. // isometric grid switched off:
  36. if (isNull(this.proj)) {
  37. this.guiAction.setChecked(!IsometricGridTop.isGridIsometric(view));
  38. }
  39. // isometric grid projection set:
  40. else {
  41. this.guiAction.setChecked(
  42. IsometricGridTop.isGridIsometric(view) &&
  43. IsometricGridTop.getProjection(view)===this.proj
  44. );
  45. }
  46. };
  47. /**
  48. * \class IsometricGridTop
  49. * \brief Switches isometric grid to top view.
  50. * \ingroup ecma_view
  51. */
  52. function IsometricGridTop(guiAction) {
  53. IsometricView.call(this, guiAction);
  54. this.proj = RS.IsoTop;
  55. }
  56. IsometricGridTop.prototype = new IsometricView();
  57. IsometricGridTop.prototype.beginEvent = function() {
  58. IsometricView.prototype.beginEvent.call(this);
  59. var view = this.getDocumentInterface().getLastKnownViewWithFocus();
  60. if (isNull(view)) {
  61. this.terminate();
  62. return;
  63. }
  64. if (isNull(this.proj)) {
  65. IsometricGridTop.setIsometricGrid(view, false);
  66. }
  67. else {
  68. IsometricGridTop.setIsometricGrid(view, true);
  69. IsometricGridTop.setProjection(view, this.proj);
  70. }
  71. view.getGrid().update(true);
  72. view.regenerate();
  73. this.terminate();
  74. };
  75. IsometricGridTop.prototype.finishEvent = function() {
  76. IsometricView.prototype.finishEvent.call(this);
  77. var view = this.getDocumentInterface().getLastKnownViewWithFocus();
  78. if (isNull(view)) {
  79. return;
  80. }
  81. var guiAction = this.getGuiAction();
  82. if (isNull(guiAction)) {
  83. return;
  84. }
  85. if (isNull(this.proj)) {
  86. guiAction.setChecked(!IsometricGridTop.isGridIsometric(view));
  87. }
  88. else {
  89. guiAction.setChecked(IsometricGridTop.getProjection(view)===this.proj);
  90. }
  91. };
  92. IsometricGridTop.isGridIsometric = function(view) {
  93. var grid = IsometricView.getGrid(view);
  94. if (isNull(grid)) {
  95. return false;
  96. }
  97. return grid.isIsometric();
  98. };
  99. IsometricGridTop.setIsometricGrid = function(view, status) {
  100. var grid = IsometricView.getGrid(view);
  101. if (isNull(grid)) {
  102. return;
  103. }
  104. return grid.setIsometric(status);
  105. };
  106. IsometricGridTop.getProjection = function(view) {
  107. var grid = IsometricView.getGrid(view);
  108. if (isNull(grid)) {
  109. return RS.IsoTop;
  110. }
  111. return grid.getProjection();
  112. };
  113. IsometricGridTop.setProjection = function(view, p) {
  114. var grid = IsometricView.getGrid(view);
  115. if (isNull(grid)) {
  116. return;
  117. }
  118. return grid.setProjection(p);
  119. };
  120. IsometricGridTop.init = function(basePath) {
  121. var action = new RGuiAction(qsTr("&Top Projection"), RMainWindowQt.getMainWindow());
  122. action.setScriptFile(basePath + "/IsometricGridTop.js");
  123. action.setRequiresDocument(true);
  124. action.setIcon(basePath + "/IsometricGridTop.svg");
  125. action.setDefaultShortcut(new QKeySequence("j,t"));
  126. action.setDefaultCommands(["isometricgridtop", "jt"]);
  127. action.setGroup("isometricProjection");
  128. action.setNoState(true);
  129. action.setGroupSortOrder(3500);
  130. action.setSortOrder(100);
  131. action.setWidgetNames(["ViewMenu", "IsometricViewToolBar", "ViewToolsPanel", "ViewMatrixPanel"]);
  132. var appWin = EAction.getMainWindow();
  133. var fl = new ProjectionFocusListener(action, RS.IsoTop);
  134. appWin.addViewFocusListener(fl);
  135. };