ExDumpPolyline.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. include("../IOExamples.js");
  20. /**
  21. * \ingroup ecma_misc_examples_ioexamples
  22. * \class ExDumpPolyline
  23. * This action dumps all selected polylines as plain text into the
  24. * command line history.
  25. */
  26. function ExDumpPolyline(guiAction) {
  27. IOExamples.call(this, guiAction);
  28. }
  29. ExDumpPolyline.prototype = new IOExamples();
  30. ExDumpPolyline.prototype.beginEvent = function() {
  31. IOExamples.prototype.beginEvent.call(this);
  32. var di = this.getDocumentInterface();
  33. var document = this.getDocument();
  34. var ids = document.querySelectedEntities();
  35. for (var i=0; i<ids.length; i++) {
  36. var id = ids[i];
  37. var entity = document.queryEntity(id);
  38. if (isPolylineEntity(entity)) {
  39. var ori = entity.getOrientation(true);
  40. if (ori===RS.CW) {
  41. EAction.handleUserMessage(qsTr("Clockwise polyline:"));
  42. }
  43. else if (ori===RS.CCW) {
  44. EAction.handleUserMessage(qsTr("Counterclockwise polyline:"));
  45. }
  46. var n = entity.countVertices();
  47. for (var k=0; k<n; k++) {
  48. var v = entity.getVertexAt(k);
  49. EAction.handleUserMessage("%1,%2,".arg(v.x).arg(v.y));
  50. }
  51. }
  52. }
  53. this.terminate();
  54. };
  55. ExDumpPolyline.init = function(basePath) {
  56. var action = new RGuiAction(qsTr("&Output Polyline Vertices"), RMainWindowQt.getMainWindow());
  57. action.setRequiresDocument(true);
  58. action.setScriptFile(basePath + "/ExDumpPolyline.js");
  59. action.setGroupSortOrder(71100);
  60. action.setSortOrder(100);
  61. action.setWidgetNames(["IOExamplesMenu"]);
  62. };