Block.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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_block Block Tools
  21. // * \ingroup ecma_scripts
  22. // *
  23. // * \brief This module contains ECMAScript implementations of
  24. // * block related tools.
  25. // */
  26. // include("scripts/EAction.js");
  27. // include("scripts/Widgets/BlockList/BlockList.js");
  28. // /**
  29. // * \class Block
  30. // * \ingroup ecma_block
  31. // * \brief Base class for block tools.
  32. // */
  33. // function Block(guiAction) {
  34. // EAction.call(this, guiAction);
  35. // }
  36. // Block.prototype = new EAction();
  37. // Block.includeBasePath = includeBasePath;
  38. // Block.prototype.beginEvent = function() {
  39. // EAction.prototype.beginEvent.call(this);
  40. // if (!isNull(this.getGuiAction()) && this.getGuiAction().objectName==="BlockToolsPanelAction") {
  41. // EAction.showCadToolBarPanel("BlockToolsPanel");
  42. // this.terminate();
  43. // }
  44. // };
  45. // Block.getMenu = function() {
  46. // var menu = EAction.getMenu(Block.getTitle(), "BlockMenu");
  47. // menu.setProperty("scriptFile", Block.includeBasePath + "/Block.js");
  48. // return menu;
  49. // };
  50. // Block.getToolBar = function() {
  51. // var tb = EAction.getToolBar(Block.getTitle(), "BlockToolBar");
  52. // tb.visible = false;
  53. // return tb;
  54. // };
  55. // Block.getCadToolBarPanel = function() {
  56. // var mtb = EAction.getMainCadToolBarPanel();
  57. // var actionName = "BlockToolsPanelAction";
  58. // if (!isNull(mtb) && mtb.findChild(actionName)==undefined) {
  59. // var action = new RGuiAction(qsTr("Block Tools"), mtb);
  60. // action.setScriptFile(Block.includeBasePath + "/Block.js");
  61. // action.objectName = actionName;
  62. // action.setRequiresDocument(true);
  63. // action.setIcon(Block.includeBasePath + "/Block.svg");
  64. // //action.setStatusTip(qsTr("Show block tools"));
  65. // action.setDefaultShortcut(new QKeySequence("w,b"));
  66. // action.setNoState();
  67. // action.setDefaultCommands(["blockmenu"]);
  68. // action.setGroupSortOrder(60);
  69. // action.setSortOrder(100);
  70. // action.setWidgetNames(["!MainToolsPanel"]);
  71. // }
  72. // var tb = EAction.getCadToolBarPanel(
  73. // Block.getTitle(),
  74. // "BlockToolsPanel",
  75. // true
  76. // );
  77. // return tb;
  78. // };
  79. // Block.getToolMatrixPanel = function() {
  80. // RSettings.setValue("Block/VisibleInMatrixPanel", false, false);
  81. // return EAction.getToolMatrixPanel(Block.getTitle(), "BlockMatrixPanel", 8000);
  82. // };
  83. // Block.getTitle = function() {
  84. // return qsTr("&Block");
  85. // };
  86. // Block.prototype.getTitle = function() {
  87. // return Block.getTitle();
  88. // };
  89. // Block.init = function() {
  90. // Block.getMenu();
  91. // Block.getToolBar();
  92. // Block.getCadToolBarPanel();
  93. // Block.getToolMatrixPanel();
  94. // };
  95. // /**
  96. // * \return The ID of the block that is currently highlighted (selected) in
  97. // * the block list. This is usually not that block that is currently being edited.
  98. // */
  99. // Block.getActiveBlockId = function() {
  100. // var blockList = EAction.getMainWindow().findChild("BlockList");
  101. // if (isNull(blockList)) {
  102. // return RObject.INVALID_ID;
  103. // }
  104. // var list = blockList.selectedItems();
  105. // if (list.length === 0) {
  106. // return RObject.INVALID_ID;
  107. // }
  108. // var item = list[0];
  109. // if (isNull(item)) {
  110. // return RObject.INVALID_ID;
  111. // }
  112. // var document = EAction.getDocument();
  113. // if (isNull(document)) {
  114. // return RObject.INVALID_ID;
  115. // }
  116. // var blockId = document.getBlockId(item.data(BlockList.colName, Qt.UserRole));
  117. // return blockId;
  118. // };
  119. // Block.showHide = function(show, action, blockId) {
  120. // var op = new RModifyObjectsOperation();
  121. // op.setText(action.getToolTitle());
  122. // var blocks = action.getDocument().queryAllBlocks();
  123. // for (var b = 0; b < blocks.length; ++b) {
  124. // var block = action.getDocument().queryBlock(blocks[b]);
  125. // if (blocks[b] !== blockId) {
  126. // block.setFrozen(!show);
  127. // } else {
  128. // block.setFrozen(false);
  129. // }
  130. // op.addObject(block);
  131. // }
  132. // var di = action.getDocumentInterface();
  133. // di.applyOperation(op);
  134. // di.clearPreview();
  135. // di.repaintViews();
  136. // };
  137. // /**
  138. // * Makes the given block the one that is being edited. This method
  139. // * stores / restores the zoom and zoom offset per block.
  140. // */
  141. // Block.prototype.editBlock = function(blockName) {
  142. // var di = this.getDocumentInterface();
  143. // //var doc = this.getDocument();
  144. // //var views = this.getGraphicsViews();
  145. // Block.editBlock(di, blockName);
  146. // };
  147. // Block.editBlock = function(di, blockName) {
  148. // var doc = di.getDocument();
  149. // var views = EAction.getGraphicsViews(di);
  150. // var i, view, blockZoom;
  151. // if (doc.isEditingWorkingSet()) {
  152. // EAction.handleUserWarning(qsTr("Cannot edit block while editing a block in-place"));
  153. // return;
  154. // }
  155. // // store offset and zoom factor of all views in a map blockId -> [factor, offset vector]:
  156. // var blockId = doc.getCurrentBlockId();
  157. // for (i=0; i<views.length; i++) {
  158. // view = views[i];
  159. // if (!isFunction(view.property)) {
  160. // continue;
  161. // }
  162. // blockZoom = view.property("blockZoom");
  163. // if (isNull(blockZoom)) {
  164. // blockZoom = new Object();
  165. // }
  166. // blockZoom[blockId] = [view.getFactor(), view.getOffset()];
  167. // view.setProperty("blockZoom", blockZoom);
  168. // //print("stored zoom for block: ", blockId, ", view: ", i, ", factor: ", view.getFactor());
  169. // }
  170. // // change current block that is being edited:
  171. // di.setCurrentBlock(blockName);
  172. // // restore offset and zoom factor for all views:
  173. // blockId = doc.getCurrentBlockId();
  174. // for (i=0; i<views.length; i++) {
  175. // view = views[i];
  176. // if (!isFunction(view.property)) {
  177. // continue;
  178. // }
  179. // blockZoom = view.property("blockZoom");
  180. // if (isNull(blockZoom)) {
  181. // view.autoZoom(-1, true);
  182. // continue;
  183. // }
  184. // if (isNull(blockZoom[blockId]) || blockZoom[blockId].length!==2) {
  185. // view.autoZoom(-1, true);
  186. // }
  187. // else {
  188. // view.setFactor(blockZoom[blockId][0]);
  189. // view.setOffset(blockZoom[blockId][1]);
  190. // //print("restored zoom for block: ", blockId, ", view: ", i, ", factor: ", view.getFactor());
  191. // }
  192. // }
  193. // };