DivideFloorScene.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * :*$@@%$*: ;: ;; ;;
  5. * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
  6. * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
  7. * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
  8. * =@* %! @ $= % %@= =%@! %=
  9. * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
  10. * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
  11. * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
  12. * $@* ;@@@%=!: *@*
  13. * =@$ ;;;!=%@@@@=! =@!
  14. * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
  15. * ;%@@$=$@@%* *@@@$=%@@%;
  16. * ::;:: ::;:: All rights reserved.
  17. *
  18. * ********************************************************************************************************************
  19. */
  20. import { FloorScene } from "./FloorScene";
  21. import { SPoint, SRect } from "@saga-web/draw/lib";
  22. import { SceneMarkItem } from "./items/SceneMarkItem";
  23. import { ZoneItem } from "./items/ZoneItem";
  24. import { Zone } from "./types/Zone";
  25. import { SMouseEvent } from "@saga-web/base/lib";
  26. import { SGraphyItem } from "@saga-web/graphy/lib";
  27. import { HighlightItem } from "./items/HighlightItem";
  28. import { SMathUtil } from "./utils/SMathUtil";
  29. import { MinDis } from "./types/MinDis";
  30. import { PointToLine } from "./types/PointToLine";
  31. /**
  32. * 划分业务空间
  33. *
  34. * @author 郝建龙
  35. */
  36. export class DivideFloorScene extends FloorScene {
  37. /** 是否开启用户标记 */
  38. _isMarking: boolean = false;
  39. get isMarking(): boolean {
  40. return this._isMarking;
  41. } // Get isMarking
  42. set isMarking(v: boolean) {
  43. if (this._isMarking === v) {
  44. return;
  45. }
  46. this._isMarking = v;
  47. } // Set isMarking
  48. /** 蒙版item */
  49. sceneMark: SGraphyItem | null = null;
  50. /** 业务空间list */
  51. zoneList: ZoneItem[] = [];
  52. /** 业务空间是否可选 */
  53. _isZoneSelectable: boolean = true;
  54. get isZoneSelectable(): boolean {
  55. return this._isZoneSelectable;
  56. } // Get isZoneSelectable
  57. set isZoneSelectable(v: boolean) {
  58. if (this._isZoneSelectable === v) {
  59. return;
  60. }
  61. this._isZoneSelectable = v;
  62. this.zoneList.map((t: ZoneItem) => {
  63. t.selectable = this._isZoneSelectable;
  64. return t;
  65. });
  66. } // Set isZoneSelectable
  67. /** 高亮item */
  68. hightLight: HighlightItem = new HighlightItem(null, new SPoint(), 0);
  69. /** 吸附距离 */
  70. private _absorbLen: number = 1;
  71. get absorbLen(): number {
  72. return this._absorbLen;
  73. } // Get absorbLen
  74. set absorbLen(v: number) {
  75. this._absorbLen = v;
  76. } // Set absorbLen
  77. /**
  78. * 构造函数
  79. *
  80. * @param data
  81. */
  82. constructor() {
  83. super();
  84. this.addItem(this.hightLight);
  85. } // Constructor
  86. /**
  87. * 添加轮廓线
  88. *
  89. * @param data
  90. */
  91. addSceneMark(data: SPoint[]): void {
  92. if (data.length) {
  93. let sceneMark = new SceneMarkItem(null, data);
  94. this.addItem(sceneMark);
  95. this.sceneMark = sceneMark;
  96. }
  97. } // Function addSceneMark
  98. /**
  99. * 清除蒙版
  100. *
  101. */
  102. clearSceneMark(): void {
  103. if (this.sceneMark) {
  104. this.grabItem = null;
  105. this.removeItem(this.sceneMark);
  106. this.sceneMark = null;
  107. this.isMarking = false;
  108. }
  109. } // Function clearSceneMark()
  110. /**
  111. * 鼠标按下事件
  112. *
  113. * @param event 保存事件参数
  114. * @return boolean
  115. */
  116. onMouseDown(event: SMouseEvent): boolean {
  117. if (this.isMarking && event.buttons == 1) {
  118. if (this.sceneMark) {
  119. this.sceneMark.onMouseDown(event);
  120. } else {
  121. let point = new SPoint(event.x, event.y);
  122. let sceneMark = new SceneMarkItem(null, point);
  123. this.addItem(sceneMark);
  124. this.sceneMark = sceneMark;
  125. this.grabItem = sceneMark;
  126. }
  127. } else {
  128. super.onMouseDown(event);
  129. }
  130. return false;
  131. } // Function onMouseDown()
  132. /**
  133. * 鼠标抬起事件
  134. *
  135. * @param event 保存事件参数
  136. * @return boolean
  137. */
  138. onMouseUp(event: SMouseEvent): boolean {
  139. return false;
  140. } // Function onMouseUp()
  141. /***
  142. * 键盘按下事件
  143. *
  144. * @param event 保存事件参数
  145. */
  146. onKeyUp(event: KeyboardEvent): void {
  147. if (this.isMarking) {
  148. if (this.grabItem) {
  149. this.grabItem.onKeyUp(event);
  150. }
  151. } else {
  152. super.onKeyUp(event);
  153. }
  154. } // Function onKeyUp()
  155. /***
  156. * 注册鼠标点击事件
  157. *
  158. * @param _this 接收者
  159. * @param fn 处理函数
  160. */
  161. click(_this: any, fn: Function): void {
  162. this.spaceList.map(t => {
  163. t.connect("click", _this, fn);
  164. });
  165. this.zoneList.map(t => {
  166. t.connect("click", _this, fn);
  167. });
  168. } // Function click()
  169. /**
  170. * 添加业务空间到scene 中
  171. *
  172. * @param zone 业务空间list
  173. */
  174. addZoneList(zone: Zone[]): void {
  175. zone.map(t => {
  176. this.addZone(t);
  177. });
  178. } // Function addZoneList
  179. /**
  180. * 添加业务空间到scene 中
  181. *
  182. * @param zone 业务空间
  183. */
  184. addZone(zone: Zone): void {
  185. let item = new ZoneItem(null, zone);
  186. item.zOrder = 3;
  187. item.selectable = this.isZoneSelectable;
  188. this.zoneList.push(item);
  189. this.addItem(item);
  190. } // Function addZone
  191. /**
  192. * 清空选中的空间
  193. *
  194. */
  195. clearSpaceSelection(): void {
  196. this.spaceList.map(t => {
  197. t.selected = false;
  198. return t;
  199. });
  200. } // Function clearSpaceSelection
  201. /**
  202. * 清空选中的业务空间
  203. *
  204. */
  205. clearZoneSelection(): void {
  206. this.zoneList.map(t => {
  207. t.selected = false;
  208. return t;
  209. });
  210. } // Function clearZoneSelection
  211. /**
  212. * 切换业务空间
  213. *
  214. */
  215. changeSelectZone(zoneitem: ZoneItem): void {
  216. this.zoneList.map(zone => {
  217. zone.selected = false;
  218. zone.unselectFlag = true;
  219. return zone;
  220. });
  221. zoneitem.visible = false;
  222. } // Function changeSelectZone
  223. /**
  224. * 吸附空间
  225. *
  226. * @param 鼠标事件对象
  227. */
  228. onMouseMove(event: SMouseEvent): boolean {
  229. this.hightLight.visible = false;
  230. this.absorbSpace(event);
  231. return false;
  232. } // Function onMouseMove
  233. /**
  234. * 吸附空间
  235. *
  236. * @param 鼠标事件对象
  237. */
  238. absorbSpace(event: SMouseEvent): void {
  239. let P = this.absorbPoint(event);
  240. if (P.Point) {
  241. this.hightLight.distance = P.MinDis;
  242. this.hightLight.point = new SPoint(P.Point.X, -P.Point.Y);
  243. this.hightLight.visible = true;
  244. } else {
  245. let L = this.absorbLine(event);
  246. if (L.Line) {
  247. this.hightLight.distance = L.MinDis;
  248. this.hightLight.line = L.Line;
  249. this.hightLight.visible = true;
  250. }
  251. }
  252. } // Function absorbSpace
  253. /**
  254. * 点是否在吸附区域内
  255. *
  256. * @param p 要判断的点
  257. * @param minX 空间区域
  258. * @param minY 空间区域
  259. * @param maxX 空间区域
  260. * @param maxY 空间区域
  261. */
  262. isPointInAbsorbArea(
  263. p: SPoint,
  264. minX: number,
  265. maxX: number,
  266. minY: number,
  267. maxY: number
  268. ): boolean {
  269. let rect = new SRect(
  270. minX - 1000,
  271. minY - 1000,
  272. maxX - minX + 200,
  273. maxY - minY + 2000
  274. );
  275. return rect.contains(p.x, p.y);
  276. } // Function isPointInAbsorbArea
  277. /**
  278. * 吸附点
  279. *
  280. * @param 鼠标事件对象
  281. * @return 吸附的点
  282. */
  283. absorbPoint(event: SMouseEvent): MinDis {
  284. let minPointDis = Number.MAX_SAFE_INTEGER;
  285. let Point;
  286. this.spaceList.map(space => {
  287. if (
  288. this.isPointInAbsorbArea(
  289. new SPoint(event.x, event.y),
  290. space.minX,
  291. space.maxX,
  292. space.minY,
  293. space.maxY
  294. )
  295. ) {
  296. space.data.OutLine.map(item => {
  297. let minDis = SMathUtil.getMinDisPoint(
  298. new SPoint(event.x, event.y),
  299. item
  300. );
  301. if (
  302. minDis &&
  303. minDis.MinDis < 2500 &&
  304. minDis.MinDis < minPointDis
  305. ) {
  306. minPointDis = minDis.MinDis;
  307. Point = minDis.Point;
  308. }
  309. });
  310. }
  311. });
  312. let minPoint = {
  313. MinDis: minPointDis,
  314. Point: Point
  315. };
  316. return minPoint;
  317. } // Function absorbPoint
  318. /**
  319. * 吸附点
  320. *
  321. * @param 鼠标事件对象
  322. * @return 吸附的线
  323. */
  324. absorbLine(event: SMouseEvent): PointToLine {
  325. let minPointDis = Number.MAX_SAFE_INTEGER;
  326. let Point, Line;
  327. this.spaceList.map(space => {
  328. if (
  329. this.isPointInAbsorbArea(
  330. new SPoint(event.x, event.y),
  331. space.minX,
  332. space.maxX,
  333. space.minY,
  334. space.maxY
  335. )
  336. ) {
  337. space.data.OutLine.map(item => {
  338. let minDisLine = SMathUtil.getMinDisLine(
  339. new SPoint(event.x, event.y),
  340. item
  341. );
  342. if (
  343. minDisLine &&
  344. minDisLine.MinDis < 2500 &&
  345. minDisLine.MinDis < minPointDis
  346. ) {
  347. minPointDis = minDisLine.MinDis;
  348. Point = minDisLine.Point;
  349. Line = minDisLine.Line;
  350. }
  351. });
  352. }
  353. });
  354. let minPointLine = {
  355. MinDis: minPointDis,
  356. Point: Point,
  357. Line: Line
  358. };
  359. return minPointLine;
  360. } // Function absorbLine
  361. } // Class DivideFloorScene