Point1P.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/Point/Point.js");
  20. /**
  21. * \class Point1P
  22. * \brief Point from position.
  23. * \ingroup ecma_draw_point
  24. */
  25. function Point1P(guiAction) {
  26. Point.call(this, guiAction);
  27. this.point = undefined;
  28. }
  29. Point1P.State = {
  30. SettingPosition : 0
  31. };
  32. Point1P.prototype = new Point();
  33. Point1P.prototype.beginEvent = function() {
  34. Point.prototype.beginEvent.call(this);
  35. this.setState(Point1P.State.SettingPosition);
  36. };
  37. Point1P.prototype.setState = function(state) {
  38. Point.prototype.setState.call(this, state);
  39. this.setCrosshairCursor();
  40. this.getDocumentInterface().setClickMode(RAction.PickCoordinate);
  41. var appWin = RMainWindowQt.getMainWindow();
  42. var trPos = qsTr("Position");
  43. this.setCommandPrompt(trPos);
  44. this.setLeftMouseTip(trPos);
  45. this.setRightMouseTip(EAction.trCancel);
  46. EAction.showSnapTools();
  47. };
  48. Point1P.prototype.pickCoordinate = function(event, preview) {
  49. var di = this.getDocumentInterface();
  50. this.point = event.getModelPosition();
  51. if (preview) {
  52. this.updatePreview();
  53. }
  54. else {
  55. di.setRelativeZero(this.point);
  56. this.applyOperation();
  57. }
  58. };
  59. Point1P.prototype.getOperation = function(preview) {
  60. if (!isVector(this.point)) {
  61. return undefined;
  62. }
  63. var op = new RAddObjectsOperation();
  64. op.setText(this.getToolTitle());
  65. var e = new RPointEntity(
  66. this.getDocument(),
  67. new RPointData(this.point)
  68. );
  69. op.addObject(e);
  70. return op;
  71. };