Point.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_point Point Drawing Tools
  21. * \ingroup ecma_draw
  22. *
  23. * \brief This module contains ECMAScript implementations of various point drawing tools.
  24. */
  25. include("scripts/Draw/Draw.js");
  26. /**
  27. * \class Point
  28. * \brief Base class for all point drawing tools.
  29. * \ingroup ecma_draw_point
  30. */
  31. function Point(guiAction) {
  32. Draw.call(this, guiAction);
  33. }
  34. Point.prototype = new Draw();
  35. Point.includeBasePath = includeBasePath;
  36. Point.prototype.beginEvent = function() {
  37. Draw.prototype.beginEvent.call(this);
  38. if (!isNull(this.getGuiAction()) && this.getGuiAction().objectName==="PointToolsPanelAction") {
  39. EAction.showCadToolBarPanel("PointToolsPanel");
  40. this.terminate();
  41. }
  42. };
  43. Point.getMenu = function() {
  44. // var menu = EAction.getSubMenu(
  45. // Draw.getMenu(),
  46. // 20, 100,
  47. // Point.getTitle(),
  48. // "DrawPointMenu",
  49. // Point.includeBasePath + "/Point.svg"
  50. // );
  51. // menu.setProperty("scriptFile", Point.includeBasePath + "/Point.js");
  52. // return menu;
  53. };
  54. Point.getToolBar = function() {
  55. var tb = EAction.getToolBar(Point.getTitle(), "PointToolBar", Qt.TopToolBarArea, Draw.getContextMenuCategory());
  56. tb.visible = false;
  57. return tb;
  58. };
  59. Point.getCadToolBarPanel = function() {
  60. var mtb = Draw.getCadToolBarPanel();
  61. var actionName = "PointToolsPanelAction";
  62. if (!isNull(mtb) && mtb.findChild(actionName)==undefined) {
  63. var action = new RGuiAction(qsTr("Point Tools"), mtb);
  64. action.setScriptFile(Point.includeBasePath + "/Point.js");
  65. action.objectName = actionName;
  66. action.setRequiresDocument(true);
  67. action.setIcon(Point.includeBasePath + "/Point.svg");
  68. //action.setStatusTip(qsTr("Show point tools"));
  69. action.setDefaultShortcut(new QKeySequence("w,p"));
  70. action.setNoState();
  71. action.setDefaultCommands(["pointmenu"]);
  72. action.setGroupSortOrder(20);
  73. action.setSortOrder(100);
  74. action.setWidgetNames(["MainToolsPanel"]);
  75. }
  76. var tb = EAction.getCadToolBarPanel(
  77. Point.getTitle(),
  78. "PointToolsPanel",
  79. true
  80. );
  81. return tb;
  82. };
  83. Point.getToolMatrixPanel = function() {
  84. return EAction.getToolMatrixPanel(Point.getTitle(), "PointMatrixPanel", 100);
  85. };
  86. Point.getTitle = function() {
  87. return qsTr("&Point");
  88. };
  89. Point.prototype.getTitle = function() {
  90. return Point.getTitle();
  91. };
  92. Point.addPointsOnLine = function(doc, op, startPoint, endPoint, numberOfPoints) {
  93. var point = new RPointEntity(doc, new RPointData(startPoint));
  94. op.addObject(point);
  95. var dv = startPoint.operator_subtract(endPoint).operator_divide(numberOfPoints - 1);
  96. var v = startPoint;
  97. for ( var i = 1; i < numberOfPoints - 1; ++i) {
  98. point = new RPointEntity(doc, new RPointData(v.operator_subtract(dv.operator_multiply(i))));
  99. op.addObject(point);
  100. }
  101. point = new RPointEntity(doc, new RPointData(endPoint));
  102. op.addObject(point);
  103. };
  104. Point.init = function() {
  105. Point.getMenu();
  106. Point.getToolBar();
  107. Point.getCadToolBarPanel();
  108. Point.getToolMatrixPanel();
  109. };