editScence.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { SMouseEvent, SUndoStack } from "@saga-web/base";
  2. import { SGraphScene,SGraphyItem } from '@saga-web/graph/lib';
  3. import { SPoint } from '@saga-web/draw/lib';
  4. import { SFloorParser, SImageItem, STextItem, SLineItem, SPolylineItem } from "@saga-web/big";
  5. import { SGraphItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate, SGraphAddCommand } from "@saga-web/graph/lib";
  6. import { SPolygonItem } from "./SPolygonItem";
  7. /**
  8. * 在线绘图
  9. *
  10. * @author 韩耀龙
  11. */
  12. export class EditScence extends SGraphScene {
  13. undoStack = new SUndoStack();
  14. /** 命令 1 绘制直线 */
  15. private cmd = 0;
  16. /** 获取当前状态 */
  17. get getCmd(): number {
  18. return this.cmd;
  19. }
  20. /** 编辑当前状态 */
  21. set setCmd(cmd: number) {
  22. if (cmd == 0) {
  23. this.grabItem = null;
  24. this.focusItem = null;
  25. }
  26. this.cmd = cmd;
  27. if(this.focusItem){
  28. // 取消操作
  29. this.focusItem.cancelOperate();
  30. this.focusItem = null;
  31. }
  32. };
  33. /** 当前选中焦点Item */
  34. focusItem:SGraphyItem:null = null;
  35. constructor() {
  36. super();
  37. // 选择绑定选额item事件
  38. this.selectContainer.connect('listChange', this, this.listChange)
  39. }
  40. /**
  41. * 监听选择item数据
  42. *
  43. */
  44. listChange() {
  45. console.log(arguments)
  46. }
  47. /**
  48. * 增加线段item
  49. */
  50. addLine(event: SMouseEvent): boolean {
  51. const item = new SLineItem(null, new SPoint(event.x, event.y));
  52. this.addItem(item);
  53. this.grabItem = item;
  54. this.undoStack.push(new SGraphAddCommand(this, item));
  55. // item.connect("onMove", this, this.onItemMove.bind(this));
  56. return true
  57. }
  58. /**
  59. * 增加多边形item
  60. */
  61. addPolygonItem(event: SMouseEvent): void {
  62. //创建item
  63. const Polylines = new SPolygonItem(null);
  64. //设置状态
  65. Polylines.setStatus = 3;
  66. const point = new SPoint(event.x, event.y)
  67. Polylines.setPointList = [point];
  68. this.addItem(Polylines);
  69. this.grabItem = Polylines;
  70. this.focusItem = Polylines
  71. }
  72. /**
  73. * 增加textItem
  74. */
  75. addImgItem() {
  76. }
  77. /**
  78. * 增加管道
  79. */
  80. addTextItem(event: SMouseEvent): void {
  81. const item = new STextItem(null, '请在右侧属性栏输入文字!');
  82. item.moveTo(event.x, event.y);
  83. this.addItem(item);
  84. this.grabItem == null
  85. this.cmd = 0;
  86. }
  87. /**
  88. * 增加图标
  89. */
  90. addIconItem(): void {
  91. }
  92. /**
  93. * 更改item对应属性
  94. */
  95. editItemStatus(): void {
  96. }
  97. /**
  98. * 删除指定item
  99. */
  100. deleiteItemStatus(): void {
  101. }
  102. /**
  103. * 对齐指定item
  104. */
  105. alignItem(type, itemList): void {
  106. }
  107. /**
  108. * 提取item
  109. */
  110. extractItem(): void {
  111. }
  112. /**
  113. * 锁住item
  114. */
  115. lockItem(): void {
  116. }
  117. /**
  118. * 执行取消操作
  119. */
  120. redo(): void {
  121. this.undoStack.undo();
  122. }
  123. /**
  124. * 执行重做操作执行
  125. */
  126. undo(): void {
  127. this.undoStack.redo();
  128. }
  129. ////////////////////////
  130. // 以下为鼠标键盘操作事件
  131. onMouseDown(event: SMouseEvent): any {
  132. if (this.grabItem) {
  133. return this.grabItem.onMouseDown(event);
  134. }
  135. switch (this.cmd) {
  136. case 1:
  137. this.addLine(event);
  138. break;
  139. case 2:
  140. this.addTextItem(event);
  141. break;
  142. case 3:
  143. this.addPolygonItem(event);
  144. break;
  145. default:
  146. return super.onMouseDown(event);
  147. }
  148. }
  149. /**
  150. * 键盘事件
  151. *
  152. * @param event 事件参数
  153. * @return boolean
  154. */
  155. onKeyDown(event: KeyboardEvent): any {
  156. if (this.grabItem) {
  157. this.grabItem.onKeyDown(event);
  158. }
  159. if (event.key == "Enter") {
  160. this.cmd = 0
  161. }
  162. return false
  163. }
  164. }