DimRegen.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/Draw/Dimension/Dimension.js");
  20. /**
  21. * \class DimRegen
  22. * \brief Regenerates dimensions to use automatic text position.
  23. * \ingroup ecma_modify
  24. */
  25. function DimRegen(guiAction) {
  26. Dimension.call(this, guiAction);
  27. }
  28. DimRegen.prototype = new Dimension();
  29. DimRegen.prototype.beginEvent = function() {
  30. Dimension.prototype.beginEvent.call(this);
  31. var di = this.getDocumentInterface();
  32. var document = this.getDocument();
  33. // find all selected entities:
  34. var ids = document.querySelectedEntities();
  35. var counter = 0;
  36. var op = new RModifyObjectsOperation();
  37. op.setText(this.getToolTitle());
  38. // reset all text positions of all selected dimension entities:
  39. for (i=0; i<ids.length; i++) {
  40. var id = ids[i];
  41. var entity = document.queryEntity(id);
  42. if (isDimensionEntity(entity) && entity.hasCustomTextPosition()) {
  43. entity.setCustomTextPosition(false);
  44. entity.getData().update();
  45. entity.getData().getShapes();
  46. op.addObject(entity, false);
  47. counter++;
  48. }
  49. }
  50. di.applyOperation(op);
  51. var msg;
  52. if (counter==0) {
  53. msg = qsTr("No dimension entities with custom label positions selected.");
  54. }
  55. else {
  56. msg = qsTr("Label position of %n dimension(s) was reset.", "", counter);
  57. }
  58. EAction.handleUserMessage(msg);
  59. this.terminate();
  60. };