Polyline.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_draw_polyline Polyline Drawing Tools
  21. * \ingroup ecma_draw
  22. *
  23. * \brief This module contains ECMAScript implementations of various polyline
  24. * drawing and modification tools.
  25. */
  26. include("scripts/Draw/Draw.js");
  27. /**
  28. * \class Polyline
  29. * \brief Base class for all polyline drawing tools.
  30. * \ingroup ecma_draw_polyline
  31. */
  32. function Polyline(guiAction) {
  33. Draw.call(this, guiAction);
  34. }
  35. Polyline.prototype = new Draw();
  36. Polyline.includeBasePath = includeBasePath;
  37. Polyline.prototype.beginEvent = function() {
  38. Draw.prototype.beginEvent.call(this);
  39. if (!isNull(this.getGuiAction()) && this.getGuiAction().objectName==="PolylineToolsPanelAction") {
  40. EAction.showCadToolBarPanel("PolylineToolsPanel");
  41. this.terminate();
  42. }
  43. };
  44. Polyline.getMenu = function() {
  45. // var menu = EAction.getSubMenu(
  46. // Draw.getMenu(),
  47. // 20, 700,
  48. // Polyline.getTitle(),
  49. // "DrawPolylineMenu",
  50. // Polyline.includeBasePath + "/Polyline.svg"
  51. // );
  52. // menu.setProperty("scriptFile", Polyline.includeBasePath + "/Polyline.js");
  53. // return menu;
  54. };
  55. Polyline.getToolBar = function() {
  56. var tb = EAction.getToolBar(Polyline.getTitle(), "PolylineToolBar", Qt.TopToolBarArea, Draw.getContextMenuCategory());
  57. //tb.orientation = Qt.Vertical;
  58. tb.visible = false;
  59. return tb;
  60. };
  61. Polyline.getCadToolBarPanel = function() {
  62. var mtb = Draw.getCadToolBarPanel();
  63. var actionName = "PolylineToolsPanelAction";
  64. if (!isNull(mtb) && mtb.findChild(actionName)==undefined) {
  65. var action = new RGuiAction(qsTr("Polyline Tools"), mtb);
  66. action.setScriptFile(Polyline.includeBasePath + "/Polyline.js");
  67. action.objectName = actionName;
  68. action.setRequiresDocument(true);
  69. action.setIcon(Polyline.includeBasePath + "/Polyline.svg");
  70. //action.setStatusTip(qsTr("Show polyline tools"));
  71. action.setDefaultShortcut(new QKeySequence("w,o"));
  72. action.setNoState();
  73. action.setDefaultCommands(["polylinemenu"]);
  74. action.setGroupSortOrder(20);
  75. action.setSortOrder(700);
  76. action.setWidgetNames(["MainToolsPanel"]);
  77. }
  78. var tb = EAction.getCadToolBarPanel(
  79. Polyline.getTitle(),
  80. "PolylineToolsPanel",
  81. true
  82. );
  83. return tb;
  84. };
  85. Polyline.getToolMatrixPanel = function() {
  86. return EAction.getToolMatrixPanel(Polyline.getTitle(), "PolylineMatrixPanel", 700);
  87. };
  88. Polyline.getTitle = function() {
  89. return qsTr("&Polyline");
  90. };
  91. Polyline.prototype.getTitle = function() {
  92. return Polyline.getTitle();
  93. };
  94. Polyline.init = function() {
  95. Polyline.getMenu();
  96. Polyline.getToolBar();
  97. Polyline.getCadToolBarPanel();
  98. Polyline.getToolMatrixPanel();
  99. };
  100. Polyline.prototype.getClosestSegment = function(pos) {
  101. if (isNull(this.polylineEntity)) {
  102. return undefined;
  103. }
  104. var i = this.polylineEntity.getClosestSegment(pos);
  105. if (i<0) {
  106. return undefined;
  107. }
  108. var seg = this.polylineEntity.getSegmentAt(i);
  109. if (isNull(seg)) {
  110. return undefined;
  111. }
  112. this.previousNode = seg.getStartPoint();
  113. this.nextNode = seg.getEndPoint();
  114. return i;
  115. };