Ellipse.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_ellipse Ellipse Drawing Tools
  21. * \ingroup ecma_draw
  22. *
  23. * \brief This module contains ECMAScript implementations of various ellipse drawing tools.
  24. */
  25. include("scripts/Draw/Draw.js");
  26. /**
  27. * \class Ellipse
  28. * \brief Base class for all ellipse drawing tools.
  29. * \ingroup ecma_draw_ellipse
  30. */
  31. function Ellipse(guiAction) {
  32. Draw.call(this, guiAction);
  33. }
  34. Ellipse.prototype = new Draw();
  35. Ellipse.includeBasePath = includeBasePath;
  36. /**
  37. * Ellipse shape post processing.
  38. * \return ellipseShape or, if configured polyline.
  39. */
  40. Ellipse.postProcess = function(ellipseShape) {
  41. if (RSettings.getBoolValue("Ellipse/CreatePolyline", false)!==true) {
  42. return ellipseShape;
  43. }
  44. var ellipseSegments = RSettings.getIntValue("Explode/EllipseSegments", 32);
  45. return ellipseShape.approximateWithArcs(ellipseSegments);
  46. };
  47. Ellipse.prototype.beginEvent = function() {
  48. Draw.prototype.beginEvent.call(this);
  49. if (!isNull(this.getGuiAction()) && this.getGuiAction().objectName==="EllipseToolsPanelAction") {
  50. EAction.showCadToolBarPanel("EllipseToolsPanel");
  51. this.terminate();
  52. }
  53. };
  54. Ellipse.getMenu = function() {
  55. // var menu = EAction.getSubMenu(
  56. // Draw.getMenu(),
  57. // 20, 500,
  58. // Ellipse.getTitle(),
  59. // "DrawEllipseMenu",
  60. // Ellipse.includeBasePath + "/Ellipse.svg"
  61. // );
  62. // menu.setProperty("scriptFile", Ellipse.includeBasePath + "/Ellipse.js");
  63. // return menu;
  64. };
  65. Ellipse.getToolBar = function() {
  66. var tb = EAction.getToolBar(Ellipse.getTitle(), "EllipseToolBar", Qt.TopToolBarArea, Draw.getContextMenuCategory());
  67. tb.visible = false;
  68. return tb;
  69. };
  70. Ellipse.getCadToolBarPanel = function() {
  71. var mtb = Draw.getCadToolBarPanel();
  72. var actionName = "EllipseToolsPanelAction";
  73. if (!isNull(mtb) && mtb.findChild(actionName)==undefined) {
  74. var action = new RGuiAction(qsTr("Ellipse Tools"), mtb);
  75. action.setScriptFile(Ellipse.includeBasePath + "/Ellipse.js");
  76. action.objectName = actionName;
  77. action.setRequiresDocument(true);
  78. action.setIcon(Ellipse.includeBasePath + "/Ellipse.svg");
  79. //action.setStatusTip(qsTr("Show ellipse tools"));
  80. action.setDefaultShortcut(new QKeySequence("w,e"));
  81. action.setNoState();
  82. action.setDefaultCommands(["ellipsemenu"]);
  83. action.setGroupSortOrder(20);
  84. action.setSortOrder(500);
  85. action.setWidgetNames(["MainToolsPanel"]);
  86. }
  87. var tb = EAction.getCadToolBarPanel(Ellipse.getTitle(), "EllipseToolsPanel", true);
  88. return tb;
  89. };
  90. Ellipse.getToolMatrixPanel = function() {
  91. return EAction.getToolMatrixPanel(Ellipse.getTitle(), "EllipseMatrixPanel", 500);
  92. };
  93. Ellipse.getTitle = function() {
  94. return qsTr("&Ellipse");
  95. };
  96. Ellipse.prototype.getTitle = function() {
  97. return Ellipse.getTitle();
  98. };
  99. Ellipse.init = function() {
  100. Ellipse.getMenu();
  101. Ellipse.getToolBar();
  102. Ellipse.getCadToolBarPanel();
  103. Ellipse.getToolMatrixPanel();
  104. };