KeyService.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import Constant from "../Constant";
  2. import { dataService } from "./DataService";
  3. import { stateService } from "./StateService";
  4. import { elementService } from "./ElementService";
  5. import { coordinate } from "../Coordinate";
  6. import VectorType from "../enum/VectorType";
  7. import SelectState from "../enum/SelectState.js";
  8. import LayerEvents from "../enum/LayerEvents.js";
  9. import { componentService } from "./ComponentService";
  10. import { symbolService } from "./SymbolService";
  11. import { furnitureService } from "./FurnitureService";
  12. import { tagService } from "./TagService";
  13. import { addRoad } from "../Controls/AddRoad";
  14. import UIEvents from "../enum/UIEvents.js";
  15. import { wallService } from "./WallService";
  16. import { moveRectangle } from "../Controls/MoveRectangle";
  17. export default class KeyService {
  18. constructor() {
  19. this.wallLineStyle = null;
  20. this.targetItem = null;
  21. }
  22. clearTargetItem() {
  23. this.targetItem = null;
  24. }
  25. copy(focusItem, mousePosition) {
  26. if (focusItem && focusItem.type) {
  27. this.targetItem = {
  28. vectorId: focusItem.vectorId,
  29. type: focusItem.type,
  30. };
  31. }
  32. this.paste(mousePosition);
  33. this.clearTargetItem();
  34. }
  35. //复制
  36. paste(mousePosition) {
  37. let flag = false;
  38. const position = coordinate.getXYFromScreen(mousePosition);
  39. // if (this.targetItem && componentService.isComponent(this.targetItem.type)) {
  40. // const component = dataService.getComponent(this.targetItem.vectorId)
  41. // const newComponent = componentService.createComponent(position, this.targetItem.type)
  42. // newComponent.angle = component.angle
  43. // newComponent.sideWidth = component.sideWidth
  44. // newComponent.sideThickness = component.sideThickness
  45. // stateService.setSelectItem(newComponent.vectorId, this.targetItem.type, SelectState.All)
  46. // stateService.setDraggingItem(stateService.selectItem)
  47. // stateService.setEventName(LayerEvents.MoveComponent)
  48. // flag = true
  49. // } else if (this.targetItem && this.targetItem.type == VectorType.Tag) {
  50. // let tag = dataService.getTag(this.targetItem.vectorId)
  51. // const newTag = tagService.createTag(position)
  52. // newTag.title = tag.title
  53. // newTag.des = tag.des
  54. // newTag.unit = tag.unit
  55. // newTag.adding = tag.adding
  56. // newTag.name = tag.name
  57. // stateService.setSelectItem(newTag.vectorId, this.targetItem.type, SelectState.All)
  58. // stateService.setDraggingItem(stateService.selectItem)
  59. // stateService.setEventName(LayerEvents.MoveTag)
  60. // flag = true
  61. // } else if (this.targetItem && furnitureService.isFurniture(this.targetItem.type)) {
  62. // const furniture = dataService.getFurniture(this.targetItem.vectorId)
  63. // const newFurniture = furnitureService.createFurniture(position, this.targetItem.type)
  64. // newFurniture.angle = furniture.angle
  65. // newFurniture.zoom = furniture.zoom
  66. // stateService.setSelectItem(newFurniture.vectorId, this.targetItem.type, SelectState.All)
  67. // stateService.setDraggingItem(stateService.selectItem)
  68. // stateService.setEventName(LayerEvents.MoveFurniture)
  69. // moveRectangle.clear()
  70. // flag = true
  71. // }
  72. if (this.targetItem && furnitureService.isFurniture(this.targetItem.type)) {
  73. const furniture = dataService.getFurniture(this.targetItem.vectorId);
  74. const newFurniture = furnitureService.createFurniture(
  75. position,
  76. this.targetItem.type
  77. );
  78. newFurniture.angle = furniture.angle;
  79. newFurniture.zoom = furniture.zoom;
  80. stateService.setSelectItem(
  81. newFurniture.vectorId,
  82. this.targetItem.type,
  83. SelectState.All
  84. );
  85. stateService.setDraggingItem(stateService.selectItem);
  86. stateService.setEventName(LayerEvents.MoveFurniture);
  87. moveRectangle.clear();
  88. flag = true;
  89. }
  90. stateService.clearFocusItem();
  91. return flag;
  92. }
  93. }
  94. const keyService = new KeyService();
  95. export { keyService };