DrawBoundingBox.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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("scripts/EAction.js");
  20. /**
  21. * This action draws a bounding box around each selected entity.
  22. */
  23. function DrawBoundingBox(guiAction) {
  24. EAction.call(this, guiAction);
  25. // bounding box offset:
  26. this.offset = 0.0;
  27. }
  28. DrawBoundingBox.prototype = new EAction();
  29. /**
  30. * Draws the bounding box(es) of the selected entities and terminates.
  31. */
  32. DrawBoundingBox.prototype.beginEvent = function() {
  33. EAction.prototype.beginEvent.call(this);
  34. var di = this.getDocumentInterface();
  35. var document = this.getDocument();
  36. // find all selected entities:
  37. var ids = document.querySelectedEntities();
  38. var i, k;
  39. var op = new RAddObjectsOperation();
  40. // add four lines for each bounding box of each entity:
  41. for (i=0; i<ids.length; i++) {
  42. var id = ids[i];
  43. var entity = document.queryEntity(id);
  44. var boundingBox = entity.getBoundingBox();
  45. var lineShapes = boundingBox.getLines2d();
  46. for (k=0; k<lineShapes.length; k++) {
  47. var lineEntity = shapeToEntity(document, lineShapes[k]);
  48. op.addObject(lineEntity, false);
  49. }
  50. }
  51. di.applyOperation(op);
  52. this.terminate();
  53. };
  54. /**
  55. * Adds a menu for this action.
  56. */
  57. DrawBoundingBox.init = function(basePath) {
  58. var action = new RGuiAction(qsTr("Draw &Bounding Box"), RMainWindowQt.getMainWindow());
  59. action.setRequiresDocument(true);
  60. action.setScriptFile(basePath + "/DrawBoundingBox.js");
  61. action.setGroupSortOrder(54500);
  62. action.setSortOrder(100);
  63. action.setWidgetNames(["MiscDrawMenu"]);
  64. };