Modify.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. /**
  20. * \defgroup ecma_modify Modification Tools
  21. * \ingroup ecma_scripts
  22. *
  23. * \brief This module contains ECMAScript implementations of various
  24. * modification tools.
  25. */
  26. include("scripts/EAction.js");
  27. /**
  28. * \class Modify
  29. * \brief Base class for all modification tools.
  30. * \ingroup ecma_modify
  31. */
  32. function Modify(guiAction) {
  33. EAction.call(this, guiAction);
  34. this.autoRefresh = true;
  35. this.copies = 0;
  36. }
  37. Modify.prototype = new EAction();
  38. Modify.includeBasePath = includeBasePath;
  39. Modify.prototype.beginEvent = function() {
  40. EAction.prototype.beginEvent.call(this);
  41. if (!isNull(this.getGuiAction()) && this.getGuiAction().objectName==="ModifyToolsPanelAction") {
  42. EAction.showCadToolBarPanel("ModifyToolsPanel");
  43. this.terminate();
  44. }
  45. };
  46. Modify.prototype.deleteSelectedEntities = function(msgEntitiesDeleted, msgNothingDeleted) {
  47. var di = EAction.getDocumentInterface();
  48. var doc = di.getDocument();
  49. var ids = doc.querySelectedEntities();
  50. var op = new RDeleteSelectionOperation();
  51. var trans = di.applyOperation(op);
  52. var count = ids.length;
  53. var appWin = EAction.getMainWindow();
  54. if (count === 0) {
  55. appWin.handleUserMessage(msgNothingDeleted);
  56. } else {
  57. appWin.handleUserMessage(msgEntitiesDeleted + ": " + count);
  58. }
  59. return count;
  60. };
  61. Modify.prototype.slotRefresh = function() {
  62. var di = EAction.getDocumentInterface();
  63. di.deselectAll();
  64. this.refresh();
  65. };
  66. Modify.prototype.slotClose = function() {
  67. this.terminate();
  68. };
  69. Modify.prototype.slotAutoRefreshChanged = function(checked) {
  70. this.autoRefresh = checked;
  71. };
  72. Modify.getMenu = function() {
  73. // var menu = EAction.getMenu(Modify.getTitle(), "ModifyMenu");
  74. // menu.setProperty("scriptFile", Modify.includeBasePath + "/Modify.js");
  75. // return menu;
  76. };
  77. Modify.getToolBar = function() {
  78. var tb = EAction.getToolBar(Modify.getTitle(), "ModifyToolBar");
  79. tb.visible = false;
  80. return tb;
  81. };
  82. Modify.getCadToolBarPanel = function() {
  83. var mtb = EAction.getMainCadToolBarPanel();
  84. var actionName = "ModifyToolsPanelAction";
  85. if (!isNull(mtb) && mtb.findChild(actionName)==undefined) {
  86. var action = new RGuiAction(qsTr("Modification Tools"), mtb);
  87. action.setScriptFile(Modify.includeBasePath + "/Modify.js");
  88. action.objectName = actionName;
  89. action.setRequiresDocument(true);
  90. action.setIcon(Modify.includeBasePath + "/Modify.svg");
  91. //action.setStatusTip(qsTr("Show modification tools"));
  92. action.setDefaultShortcut(new QKeySequence("w,m"));
  93. action.setNoState();
  94. action.setDefaultCommands(["modifymenu"]);
  95. action.setGroupSortOrder(40);
  96. action.setSortOrder(100);
  97. action.setWidgetNames(["MainToolsPanel"]);
  98. }
  99. var tb = EAction.getCadToolBarPanel(
  100. Modify.getTitle(),
  101. "ModifyToolsPanel",
  102. true
  103. );
  104. return tb;
  105. };
  106. Modify.getToolMatrixPanel = function() {
  107. return EAction.getToolMatrixPanel(Modify.getTitle(), "ModifyMatrixPanel", 3000);
  108. };
  109. Modify.getTitle = function() {
  110. return qsTr("&Modify");
  111. };
  112. Modify.prototype.getTitle = function() {
  113. return Modify.getTitle();
  114. };
  115. Modify.init = function() {
  116. Modify.getMenu();
  117. Modify.getToolBar();
  118. Modify.getCadToolBarPanel();
  119. Modify.getToolMatrixPanel();
  120. };