Select.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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_select Selection Tools
  21. // * \ingroup ecma_scripts
  22. // *
  23. // * \brief This module contains ECMAScript implementations of advanced
  24. // * selection tools.
  25. // */
  26. // include("scripts/EAction.js");
  27. // /**
  28. // * \class Select
  29. // * \brief Base class for all advanced selection tools.
  30. // * \ingroup ecma_select
  31. // */
  32. // function Select(guiAction) {
  33. // EAction.call(this, guiAction);
  34. // this.selectionMode = Select.Mode.Replace;
  35. // this.crossSelection = false;
  36. // }
  37. // Select.prototype = new EAction();
  38. // Select.includeBasePath = includeBasePath;
  39. // Select.Mode = {
  40. // Replace: 0,
  41. // Add: 1,
  42. // Remove: 2,
  43. // Intersect: 3
  44. // };
  45. // Select.prototype.beginEvent = function() {
  46. // EAction.prototype.beginEvent.call(this);
  47. // if (!isNull(this.getGuiAction()) && this.getGuiAction().objectName==="SelectToolsPanelAction") {
  48. // EAction.showCadToolBarPanel("SelectToolsPanel");
  49. // this.terminate();
  50. // }
  51. // };
  52. // /**
  53. // * Adds the given box as a selection box to the preview.
  54. // * \param di RDocumentInterface
  55. // * \param box RBox
  56. // * \param crossSelection boolean true for cross selection
  57. // */
  58. // Select.previewSelectionBox = function(di, box, crossSelection) {
  59. // var points = new Array(
  60. // box.c1,
  61. // new RVector(box.c1.x, box.c2.y),
  62. // box.c2,
  63. // new RVector(box.c2.x, box.c1.y),
  64. // box.c1
  65. // );
  66. // Select.previewSelectionPolygon(di, points, crossSelection);
  67. // };
  68. // /**
  69. // * Adds a selection polygon with the given points to the preview.
  70. // * \param points Array of RVector objects
  71. // */
  72. // Select.previewSelectionPolygon = function(di, points, crossSelection) {
  73. // var polygon = new RPolyline(points, true);
  74. // var color = RSettings.getColor("GraphicsViewColors/SelectionBoxColor", new RColor(128,0,0,255));
  75. // var lw = RLineweight.Weight000;
  76. // var c;
  77. // if (crossSelection) {
  78. // c = RSettings.getColor("GraphicsViewColors/SelectionBoxBackgroundCrossColor", new RColor(0,0,255,30));
  79. // } else {
  80. // c = RSettings.getColor("GraphicsViewColors/SelectionBoxBackgroundColor", new RColor(0,255,0,30));
  81. // }
  82. // // TODO c.getQColor() doesn't work
  83. // var bgColor = new QColor(c.red(), c.green(), c.blue(), c.alpha());
  84. // var brush = new QBrush(bgColor, Qt.SolidPattern);
  85. // if (crossSelection) {
  86. // var dashes = new Array(10, 5);
  87. // di.addShapeToPreview(polygon, color, brush,
  88. // lw, Qt.CustomDashLine.valueOf(), dashes);
  89. // } else {
  90. // // TODO "Qt.SolidLine" doesn't convert to number
  91. // di.addShapeToPreview(polygon, color, brush,
  92. // lw, Qt.SolidLine.valueOf());
  93. // }
  94. // };
  95. // /**
  96. // * Called when the user toggles the cross selection option available in
  97. // * some selection options toolbars.
  98. // */
  99. // Select.prototype.slotCrossSelectionChanged = function(checked) {
  100. // this.crossSelection = checked;
  101. // this.getDocumentInterface().clearPreview();
  102. // this.getDocumentInterface().repaintViews();
  103. // this.preview();
  104. // };
  105. // /**
  106. // * Called when the current selection mode changed to 'replace'.
  107. // */
  108. // Select.prototype.slotModeReplaceChanged = function(checked) {
  109. // if (checked) {
  110. // this.selectionMode = Select.Mode.Replace;
  111. // }
  112. // };
  113. // /**
  114. // * Called when the current selection mode changed to 'add'.
  115. // */
  116. // Select.prototype.slotModeAddChanged = function(checked) {
  117. // if (checked) {
  118. // this.selectionMode = Select.Mode.Add;
  119. // }
  120. // };
  121. // /**
  122. // * Called when the current selection mode changed to 'remove'.
  123. // */
  124. // Select.prototype.slotModeRemoveChanged = function(checked) {
  125. // if (checked) {
  126. // this.selectionMode = Select.Mode.Remove;
  127. // }
  128. // };
  129. // /**
  130. // * Called when the current selection mode changed to 'intersect'.
  131. // */
  132. // Select.prototype.slotModeIntersectChanged = function(checked) {
  133. // if (checked) {
  134. // this.selectionMode = Select.Mode.Intersect;
  135. // }
  136. // };
  137. // /**
  138. // * Change selection based on given matching entities and current
  139. // * selection mode.
  140. // */
  141. // Select.prototype.selectWithMode = function(entityIds) {
  142. // var di = this.getDocumentInterface();
  143. // Select.selectWithMode(entityIds, di, this.selectionMode);
  144. // };
  145. // Select.selectWithMode = function(entityIds, di, selectionMode) {
  146. // switch (selectionMode) {
  147. // case Select.Mode.Replace:
  148. // di.selectEntities(entityIds, false);
  149. // break;
  150. // case Select.Mode.Add:
  151. // di.selectEntities(entityIds, true);
  152. // break;
  153. // case Select.Mode.Remove:
  154. // di.deselectEntities(entityIds);
  155. // break;
  156. // case Select.Mode.Intersect:
  157. // var doc = di.getDocument();
  158. // var allEntityIds = doc.queryAllEntities();
  159. // var entityIdsToSelect = [];
  160. // var entityIdsToDeselect = [];
  161. // for (var e = 0; e < allEntityIds.length; ++e) {
  162. // var entityId = allEntityIds[e];
  163. // var entity = EAction.getDocument().queryEntity(entityId);
  164. // var match = entityIds.contains(entityId);
  165. // var previouslySelected = entity.isSelected();
  166. // var select = match && previouslySelected;
  167. // if (select && !previouslySelected) {
  168. // entityIdsToSelect.push(entityId);
  169. // }
  170. // if (!select && previouslySelected) {
  171. // entityIdsToDeselect.push(entityId);
  172. // }
  173. // }
  174. // if (entityIdsToSelect.length!==0) {
  175. // di.selectEntities(entityIdsToSelect);
  176. // }
  177. // if (entityIdsToDeselect.length!==0) {
  178. // di.deselectEntities(entityIdsToDeselect);
  179. // }
  180. // break;
  181. // }
  182. // };
  183. // Select.getMenu = function() {
  184. // var menu = EAction.getMenu(Select.getTitle(), "SelectMenu");
  185. // menu.setProperty("scriptFile", Select.includeBasePath + "/Select.js");
  186. // return menu;
  187. // };
  188. // Select.getToolBar = function() {
  189. // var tb = EAction.getToolBar(Select.getTitle(), "SelectToolBar");
  190. // tb.visible = false;
  191. // return tb;
  192. // };
  193. // Select.getCadToolBarPanel = function() {
  194. // var mtb = EAction.getMainCadToolBarPanel();
  195. // var actionName = "SelectToolsPanelAction";
  196. // if (!isNull(mtb) && isNull(mtb.findChild(actionName))) {
  197. // var action = new RGuiAction(qsTr("Selection Tools"), mtb);
  198. // action.setScriptFile(Select.includeBasePath + "/Select.js");
  199. // action.objectName = actionName;
  200. // action.setRequiresDocument(true);
  201. // action.setIcon(Select.includeBasePath + "/Select.svg");
  202. // //action.setStatusTip(qsTr("Show selection tools"));
  203. // action.setDefaultShortcut(new QKeySequence("w,s"));
  204. // action.setNoState();
  205. // action.setDefaultCommands(["selectionmenu"]);
  206. // action.setGroupSortOrder(40);
  207. // action.setSortOrder(400);
  208. // action.setWidgetNames(["MainToolsPanel"]);
  209. // }
  210. // var tb = EAction.getCadToolBarPanel(qsTr("Selection Tools Panel"), "SelectToolsPanel", true);
  211. // return tb;
  212. // };
  213. // Select.getToolMatrixPanel = function() {
  214. // return EAction.getToolMatrixPanel(Select.getTitle(), "SelectMatrixPanel", 4000);
  215. // };
  216. // Select.getTitle = function() {
  217. // return qsTr("&Select");
  218. // };
  219. // Select.prototype.getTitle = function() {
  220. // return Select.getTitle();
  221. // };
  222. // Select.init = function() {
  223. // Select.getMenu();
  224. // Select.getToolBar();
  225. // Select.getCadToolBarPanel();
  226. // Select.getToolMatrixPanel();
  227. // };