mainScene.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { SRect, SSize, SPoint } from "@sybotan-web/base";
  2. import { SGraphyPolygonItem } from './newItems/SGraphyPolygonItem.js'
  3. import { SGraphyScene, SMouseEvent } from "@sybotan-web/graphy";
  4. import { SPen, SPainter, SColor } from "@sybotan-web/draw";
  5. import { dataItemPath, dataItem, dataSpaceItem, dataInterface, PolygonItemInterface } from './dataType.js' //传入参数的参数接口类型
  6. /**
  7. * @name mainScene
  8. * @time 2019-07.07;
  9. * 添加所有item的场景到scene中
  10. */
  11. export default class mainScene extends SGraphyScene {
  12. data: dataInterface;
  13. private _isShowSpace: boolean = true; // 是否显示空间;
  14. private _isShowWallList: boolean = true; //是否展示墙体;
  15. private _isShowEquipmentList: boolean = true; //是否展示设备;
  16. private _isShowVrtualWallList: boolean = true; //是否展示虚拟墙
  17. // 设置是否显示空间
  18. get isShowSpace(): boolean {
  19. return this._isShowSpace
  20. }
  21. set isShowSpace(b: boolean) {
  22. this._isShowSpace = b
  23. }
  24. // 设置是否显示墙
  25. get isShowWallList(): boolean {
  26. return this._isShowWallList
  27. }
  28. set isShowWallList(b: boolean) {
  29. this._isShowWallList = b
  30. }
  31. // 设置是否显示设备
  32. get isShowEquipmentList(): boolean {
  33. return this._isShowEquipmentList
  34. }
  35. set isShowEquipmentList(b: boolean) {
  36. this._isShowEquipmentList = b
  37. }
  38. // 设置是否显示虚拟墙
  39. get isShowVrtualWallList(): boolean {
  40. return this._isShowVrtualWallList
  41. }
  42. set isShowVrtualWallList(b: boolean) {
  43. this._isShowVrtualWallList = b
  44. }
  45. /**
  46. * @param data 绘制空间地图得所有参数
  47. */
  48. constructor(data: dataInterface) {
  49. super()
  50. this.data = data;
  51. this.addAllItemList(data);
  52. }
  53. // 以下是绘制方法
  54. /**
  55. * 增添所有绘制item(地图);
  56. */
  57. addAllItemList(data: dataInterface) {
  58. let space: dataSpaceItem[] = data.SpaceList;
  59. this.addSpaceList(space) //绘制空间
  60. }
  61. /**
  62. * 添加所有空间到scene 中
  63. * @param space 空间list
  64. */
  65. addSpaceList(space: dataSpaceItem[]): void {
  66. if (space && space.length) {
  67. for (let i = 0; i < space.length; i++) {
  68. if (space[i].Paths[1] && space[i].Paths[1].length >= 2) {
  69. this.addItem(this.constructeItem(
  70. {
  71. parent: null,
  72. space: space[i]
  73. }));
  74. }
  75. }
  76. for (let i = 0; i < space.length; i++) {
  77. if (space[i].Paths[0] && space[i].Paths[0].length >= 2 && !space[i].Paths[1]) {
  78. this.addItem(this.constructeItem(
  79. {
  80. parent: null,
  81. space: space[i]
  82. }));
  83. }
  84. }
  85. }
  86. }
  87. // 绘制墙体
  88. addWallList(): void {
  89. }
  90. // 绘制设备
  91. addEquipmentList() {
  92. }
  93. // 绘制柱体
  94. addColumnListList(): void {
  95. }
  96. // 绘制虚拟墙
  97. addVrtualWallList(): void {
  98. }
  99. /**
  100. * 产生item实例
  101. */
  102. constructeItem(PolygonItemInterfaceData: PolygonItemInterface): SGraphyPolygonItem {
  103. return new SGraphyPolygonItem(PolygonItemInterfaceData)
  104. }
  105. // 鼠标交互类事件
  106. // 点击
  107. click(_this: any, fn: any): void {
  108. this.root.children.forEach(item => {
  109. item.connect("click", _this, fn);
  110. });
  111. }
  112. // 双击
  113. dbclick(_this: any, fn: any): void {
  114. this.root.children.forEach(item => {
  115. item.connect("doubleClick", _this, fn);
  116. });
  117. }
  118. // 按下
  119. mouseDown(_this: any, fn: any) {
  120. this.root.children.forEach(item => {
  121. item.connect("mouseDown", _this, fn);
  122. });
  123. }
  124. //移动
  125. mouseMove(_this: any, fn: any) {
  126. this.root.children.forEach(item => {
  127. item.connect("mouseMove", _this, fn);
  128. });
  129. }
  130. // 点解结束
  131. mouseUp(_this: any, fn: any) {
  132. this.root.children.forEach(item => {
  133. item.connect("mouseUp", _this, fn);
  134. });
  135. }
  136. }