EditScence.ts 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. import { SMouseEvent, SUndoStack } from "@saga-web/base";
  2. import { SGraphScene, SGraphLayoutType, SAnchorItem } from '@saga-web/graph/lib';
  3. import { SFloorParser, SLineItem, SPolylineItem, SItemStatus, ItemOrder, STooltipItem, ItemColor } from "@saga-web/big";
  4. import { SGraphItem, SLineStyle, SGraphPropertyCommand, SImageItem, STextItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate, SGraphAddCommand } from "@saga-web/graph/lib";
  5. import {SGraphAddListCommand} from "./SGraphAddListCommand"
  6. import {SGraphDeleteCommand} from "./SGraphDeleteCommand"
  7. import {SGraphDeleteListCommand} from "./SGraphDeleteListCommand"
  8. import { SZoneLegendItem } from "@/lib/items/SZoneLegendItem";
  9. import { SSCPZZoneLegendItem } from "@/lib/items/SSCPZZoneLegendItem";
  10. import { SFHFQZoneLegendItem } from "@/lib/items/SFHFQZoneLegendItem";
  11. import { SImageLegendItem } from "@/lib/items/SImageLegendItem";
  12. import { TipelineItem } from "@/lib/items/TipelineItem";
  13. import { SImageMarkerItem } from "@/lib/items/SImageMarkerItem"
  14. import { SPoint, SFont, SColor, SRect } from '@saga-web/draw/lib';
  15. import { Legend } from '@/lib/types/Legend';
  16. import { Relation } from '@/lib/types/Relation';
  17. import { uuid } from "@/components/mapClass/until";
  18. import { STextMarkerItem } from '@/lib/items/STextMarkerItem';
  19. import { SLineMarkerItem } from '@/lib/items/SLineMarkerItem';
  20. import { SSpaceItem } from '@saga-web/big/lib/items/floor/SSpaceItem';
  21. import { SMathUtil } from '@saga-web/big/lib/utils/SMathUtil';
  22. import { MinDis } from '@saga-web/big/lib/types/MinDis';
  23. import { HighlightItem } from '@/lib/items/HighlightItem';
  24. /**
  25. * 在线绘图
  26. *
  27. * @author 韩耀龙
  28. */
  29. export class EditScence extends SGraphScene {
  30. undoStack = new SUndoStack();
  31. /** 命令 1 绘制直线 */
  32. private cmd = 'choice';
  33. /** 获取当前状态 */
  34. get getCmd(): string {
  35. return this.cmd;
  36. }
  37. /** 编辑当前状态 */
  38. set setCmd(cmd: string) {
  39. if (cmd == 'choice') {
  40. this.grabItem = null;
  41. }
  42. this.cmd = cmd;
  43. if (this.focusItem) {
  44. // 取消操作
  45. this.focusItem.cancelOperate();
  46. this.focusItem = null;
  47. // this.selectContainer.clear()
  48. }
  49. if (this.view) {
  50. this.view.update();
  51. }
  52. };
  53. /** 绘制区域时 是否为点选 */
  54. isSelecting: boolean = false;
  55. /** 是否开启吸附 */
  56. isAbsorbing: boolean = false;
  57. /** 吸附展示item */
  58. highLight: HighlightItem | null = null;
  59. /** 当前选中焦点Item */
  60. focusItem: SGraphItem | null = null;
  61. /** 当前选中焦点ItemList */
  62. focusItemList: SGraphItem[] | null = null;
  63. /**图例节点 */
  64. Nodes: any = []; // 图例节点,所有与工程信息化相关的图例(图标类型与区域)
  65. /**图例节点 */ // 与工程信息无关的标识对象(增加文本注释,图上的图片说明)
  66. Markers: any = [];
  67. /** 管线对象 */
  68. Relations: any = [];
  69. _isEditStatus: Boolean = true; // 是否可编辑
  70. set isEditStatus(bol: Boolean): void {
  71. this._isEditStatus = bol;
  72. }
  73. get isEditStatus(): Boolean {
  74. return this._isEditStatus
  75. }
  76. constructor() {
  77. super();
  78. // // 选择绑定选额item事件
  79. this.selectContainer.connect("listChange", this, this.listChange);
  80. ItemColor.spaceColor = new SColor("#A4ABB22B")
  81. ItemColor.wallColor = new SColor("#A7AEB3FF")
  82. ItemColor.columnColor = new SColor("#A7AEB3FF")
  83. ItemColor.virtualWallColor = new SColor("#A7AEB3FF")
  84. ItemColor.selectColor = new SColor("#84A0BB2B")
  85. ItemColor.spaceBorderColor = new SColor("#A7AEB3FF")
  86. }
  87. /** 绘制图例样式 */
  88. _legend: any | null = null;
  89. get getlegend(): any {
  90. return this._legend;
  91. };
  92. set setlegend(obj: any) {
  93. this._legend = obj;
  94. }
  95. /** fid=>item映射,由解析器存入 */
  96. fidToItem = {}
  97. /**
  98. * 监听变化
  99. * @param obj 变化后的对象
  100. */
  101. listChange(obj: any) {
  102. let itemType: string = 'equipment';
  103. this.focusItemList = obj.itemList;
  104. if (obj.itemList[0] instanceof STextMarkerItem) {
  105. itemType = 'baseText'
  106. } else if (obj.itemList[0] instanceof SImageMarkerItem) {
  107. itemType = 'baseImage'
  108. } else if (obj.itemList[0] instanceof SLineMarkerItem) {
  109. itemType = 'baseLine'
  110. } else if (obj.itemList[0] instanceof SZoneLegendItem) {
  111. itemType = 'Zone'
  112. } else if (obj.itemList[0] instanceof SFHFQZoneLegendItem) {
  113. itemType = 'Zone'
  114. } else if (obj.itemList[0] instanceof SSCPZZoneLegendItem) {
  115. itemType = 'Zone'
  116. } else if (obj.itemList[0] instanceof SImageLegendItem) {
  117. itemType = 'Image'
  118. } else if (obj.itemList[0] instanceof TipelineItem) {
  119. itemType = 'Line'
  120. } else if (obj.itemList[0] instanceof SSpaceItem) { // 点选
  121. this.clickToAddArea(obj.itemList[0]);
  122. return
  123. } else {
  124. itemType = ''
  125. };
  126. if (obj.itemList.length == 1) {
  127. // 获取聚焦item
  128. this.focusItem = obj.itemList[0]
  129. } else {
  130. this.focusItem = null
  131. }
  132. let msg = {
  133. itemList: obj.itemList,
  134. itemType,
  135. }
  136. this.emitChange(msg)
  137. }
  138. emitChange(msg: any) {
  139. }
  140. /**
  141. * 增加线段item
  142. */
  143. addLine(event: SMouseEvent): boolean {
  144. const clickItem = this.clickIsItem(event);
  145. if (clickItem) {
  146. let centerPoint = clickItem.boundingRect().center();
  147. const p = clickItem.mapToScene(centerPoint.x, centerPoint.y);
  148. event.x = p.x;
  149. event.y = p.y;
  150. }
  151. const data = {
  152. /** ID */
  153. ID: uuid(),
  154. /** 名称 */
  155. Name: '直线',
  156. /** 图标(Image),线类型(Line) */
  157. Type: "Line",
  158. /** 位置 */
  159. Pos: { X: 0, Y: 0 },
  160. /** 由应用自己定义 */
  161. Properties: {
  162. IconUrl: require("../../assets/images/t-line-hover.png"),
  163. Line: [{ X: event.x, Y: event.y }],
  164. LineWidth: 2
  165. }
  166. }
  167. const item = new SLineMarkerItem(null, data);
  168. item.status = SItemStatus.Create;
  169. item.zOrder = ItemOrder.lineOrder;
  170. item.selectable = true;
  171. this.addItem(item);
  172. this.Markers.push(item);
  173. item.connect("finishCreated", this, this.finishCreated);
  174. this.grabItem = item;
  175. this.focusItem = item;
  176. // 起始item点
  177. item.startItem = clickItem;
  178. if (clickItem) {
  179. clickItem.connect('onMove', item, item.changePos);
  180. }
  181. this.scenceUpdate(this);
  182. return true
  183. }
  184. /**
  185. * 增加折线item
  186. */
  187. addPolylineItem(event: SMouseEvent): boolean {
  188. const point = new SPoint(event.x, event.y)
  189. const item = new TipelineItem(null, [point]);
  190. //设置状态
  191. item.selectable = true;
  192. item.status = SItemStatus.Create;
  193. item.zOrder = ItemOrder.polylineOrder
  194. this.addItem(item);
  195. item.connect("finishCreated", this, this.finishCreated);
  196. this.grabItem = item;
  197. this.focusItem = item;
  198. return true
  199. }
  200. /**
  201. * 增加管道 lenged
  202. */
  203. addTipelineItem(event: SMouseEvent): boolean {
  204. const anc = this.clickIsAnchor(event);
  205. if (anc) {
  206. const p = anc.mapToScene(0, 0)
  207. anc.isConnected = true;
  208. event.x = p.x;
  209. event.y = p.y;
  210. }
  211. const LegendData: Relation = {
  212. ID: uuid(),
  213. Name: this._legend.Name,
  214. GraphElementId: this._legend.Id,
  215. PointList: [{ X: event.x, Y: event.y }],
  216. LineType: "Line",
  217. Properties: {
  218. IconUrl: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  219. LineDash: this._legend.LineDash,
  220. LineWidth: this._legend.LineWidth,
  221. Color: this._legend.Color,
  222. },
  223. }
  224. const item = new TipelineItem(null, LegendData);
  225. //设置状态
  226. item.selectable = true;
  227. item.status = SItemStatus.Create;
  228. item.zOrder = ItemOrder.polylineOrder
  229. this.addItem(item);
  230. this.Relations.push(item);
  231. item.connect("finishCreated", this, this.finishCreated);
  232. this.grabItem = item;
  233. this.focusItem = item;
  234. // 起始锚点
  235. item.startAnchor = anc;
  236. if (anc) {
  237. anc.parent ?.connect('changePos', item, item.changePos)
  238. item.anchor1ID = anc.id;
  239. item.node1Id = anc.parent.id;
  240. }
  241. this.scenceUpdate(this);
  242. return true
  243. }
  244. /**
  245. * 增加多边形item lenged
  246. */
  247. addPolygonItem(event: SMouseEvent): void {
  248. const SubType = this._legend.SubType ? this._legend.SubType : '';
  249. const LegendData: Legend = {
  250. ID: uuid(),
  251. Name: this._legend.Name,
  252. GraphElementType: this._legend.Type,
  253. Num: 1,
  254. GraphElementId: this._legend.Id,
  255. AttachObjectIds: [],
  256. Type: "Zone",
  257. Pos: { X: event.x, Y: event.y },
  258. OutLine: [{ X: event.x, Y: event.y }],
  259. SubType: SubType,
  260. Properties: {
  261. IconUrl: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  262. StrokeColor: this._legend.Color,
  263. FillColor: this._legend.FillColor,
  264. LineDash: this._legend.LineDash,
  265. LineWidth: this._legend.LineWidth,
  266. font: 0,
  267. color: '',
  268. TextPos: { X: 0, Y: 0 }
  269. },
  270. }
  271. let Polylines = null;
  272. if (SubType == "SCPZ") {
  273. Polylines = new SSCPZZoneLegendItem(null, LegendData);
  274. } else if (SubType == "FHFQ") {
  275. Polylines = new SFHFQZoneLegendItem(null, LegendData);
  276. } else {
  277. Polylines = new SZoneLegendItem(null, LegendData);
  278. }
  279. Polylines.selectable = true;
  280. //设置状态
  281. Polylines.status = SItemStatus.Create;
  282. Polylines.zOrder = ItemOrder.polygonOrder;
  283. // Polylines.moveable = true;
  284. this.addItem(Polylines);
  285. this.Nodes.push(Polylines);
  286. Polylines.connect("finishCreated", this, this.finishCreated);
  287. this.grabItem = Polylines;
  288. this.focusItem = Polylines;
  289. this.scenceUpdate(this);
  290. }
  291. /**
  292. * 点选创建区域
  293. */
  294. clickToAddArea(item: SSpaceItem): void {
  295. if (this.cmd != 'Zone') {
  296. return
  297. }
  298. if (this.isSelecting && this._legend) {
  299. //@ts-ignore
  300. item.isExtracted = true
  301. const SubType = this._legend.SubType ? this._legend.SubType : '';
  302. const LegendData: Legend = {
  303. ID: uuid(),
  304. Name: this._legend.Name,
  305. GraphElementType: this._legend.Type,
  306. Num: 1,
  307. GraphElementId: this._legend.Id,
  308. AttachObjectIds: [],
  309. Type: "Zone",
  310. Pos: { X: item.x, Y: item.y },
  311. OutLine: item.pointArr[0],
  312. SubType: SubType,
  313. Properties: {
  314. IconUrl: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  315. StrokeColor: this._legend.Color,
  316. FillColor: this._legend.FillColor,
  317. LineDash: this._legend.LineDash,
  318. LineWidth: this._legend.LineWidth,
  319. font: 12,
  320. color: '',
  321. FID: item.data.SourceId,
  322. TextPos: { X: item.data.Location.Points[0].X, Y: -item.data.Location.Points[0].Y }
  323. },
  324. }
  325. let Polylines = null;
  326. if (SubType == "SCPZ") {
  327. Polylines = new SSCPZZoneLegendItem(null, LegendData);
  328. } else if (SubType == "FHFQ") {
  329. Polylines = new SFHFQZoneLegendItem(null, LegendData);
  330. } else {
  331. Polylines = new SZoneLegendItem(null, LegendData);
  332. }
  333. Polylines.selectable = true;
  334. //设置状态
  335. Polylines.status = SItemStatus.Normal;
  336. this.addItem(Polylines);
  337. this.Nodes.push(Polylines);
  338. this.finishCreated(Polylines)
  339. this.focusItem = Polylines;
  340. this.scenceUpdate(this);
  341. }
  342. }
  343. /**
  344. * 增加图片Item mark
  345. */
  346. addImgItem(event: SMouseEvent) {
  347. const data = {
  348. /** ID */
  349. ID: uuid(),
  350. /** 名称 */
  351. Name: '图片',
  352. Num: 1,
  353. /** 图标(Image),线类型(Line) */
  354. Type: "Image",
  355. /** 位置 */
  356. Pos: { X: event.x, Y: event.y },
  357. /** 由应用自己定义 */
  358. Properties: {
  359. IconUrl: require(`../../assets/images/t-img-hover.png`),
  360. Url: '',
  361. }
  362. }
  363. const item = new SImageMarkerItem(null, data);
  364. item.zOrder = ItemOrder.imageOrder;
  365. item.selectable = true;
  366. item.moveable = true;
  367. this.addItem(item);
  368. this.Markers.push(item);
  369. this.grabItem == null;
  370. this.focusItem = item;
  371. this.finishCreated(item);
  372. this.scenceUpdate(this);
  373. }
  374. /**
  375. * 增加文字item
  376. */
  377. addTextItem(event: SMouseEvent): void {
  378. const data = {
  379. /** ID */
  380. ID: uuid(),
  381. /** 名称 */
  382. Name: '文本',
  383. /** 图标 */
  384. Type: "Text",
  385. /** 位置 */
  386. Pos: { X: event.x, Y: event.y },
  387. /** 由应用自己定义 */
  388. Properties: {
  389. IconUrl: require(`../../assets/images/t-text-hover.png`),
  390. Text: '请在右侧属性栏输入文字!',
  391. Color: '',
  392. Font: 12,
  393. BackgroundColor: '#f7f9fa'
  394. }
  395. }
  396. const item = new STextMarkerItem(null, data);
  397. item.moveTo(event.x, event.y);
  398. item.selectable = true;
  399. item.moveable = true;
  400. item.zOrder = ItemOrder.textOrder;
  401. this.addItem(item);
  402. this.Markers.push(item);
  403. this.grabItem = item;
  404. this.focusItem = item;
  405. this.cmd = 'choice';
  406. this.finishCreated(item);
  407. this.scenceUpdate(this);
  408. }
  409. /**
  410. * 增加图标lenged图标
  411. */
  412. addIconItem(event: SMouseEvent): void {
  413. //获取信息工程化相关参数
  414. const InfoSystemId = this._legend.InfoSystemId ? this._legend.InfoSystemId : '';
  415. const LegendData: Legend = {
  416. ID: uuid(),
  417. Name: this._legend.Name,
  418. GraphElementType: this._legend.Type,
  419. Num: 1,
  420. GraphElementId: this._legend.Id,
  421. AttachObjectIds: [],
  422. Pos: { X: event.x, Y: event.y },
  423. Scale: { X: 1, Y: 1, Z: 1 }, // 缩放
  424. Rolate: { X: 0, Y: 0, Z: 0 },
  425. Size: { Width: 0, Height: 0 }, // 大小
  426. Type: this._legend.Type,
  427. Properties: {
  428. IconUrl: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  429. Url: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  430. Num: 1, // 此num与信息工程化得num无关
  431. sWidth: 24, //icon 的宽
  432. sHeight: 24, //icon 的高
  433. font: 12, //font
  434. color: '', //字体颜色
  435. GraphCategoryId: this._legend.GraphCategoryId,
  436. InfoSystemId: InfoSystemId //信息工程话分类ID分类
  437. },
  438. }
  439. const item = new SImageLegendItem(null, LegendData);
  440. this.cmd = 'choice';
  441. item.selectable = true;
  442. item.moveable = true;
  443. item.zOrder = ItemOrder.markOrder;
  444. this.addItem(item);
  445. this.Nodes.push(item);
  446. this.grabItem = item;
  447. this.focusItem = item;
  448. this.finishCreated(item);
  449. this.scenceUpdate(this);
  450. }
  451. /**
  452. * 更改item对应属性
  453. */
  454. editItemStatus(): void {
  455. }
  456. /**
  457. * 更改文本对应属性
  458. * @param str string 文字内容
  459. */
  460. updatedText(str: string): void {
  461. if (this.focusItem) {
  462. const oldMsg = this.focusItem.text;
  463. const newMsg = str;
  464. this.focusItem.text = str;
  465. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "text", oldMsg, newMsg));
  466. this.scenceUpdate(this);
  467. }
  468. }
  469. /**
  470. * 更改文本fontSize属性
  471. * @param size number 文字大小
  472. */
  473. updatedFontSize(size: number): void {
  474. if (this.focusItem) {
  475. let old = new SFont(this.focusItem.font);
  476. let font = new SFont(this.focusItem.font);
  477. font.size = size;
  478. this.focusItem.font = font;
  479. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "font", old, font));
  480. }
  481. }
  482. /**
  483. * 更改线宽属性
  484. * @param lineWidth number 线宽大小
  485. */
  486. updatedLineWidth(lineWidth: number): void {
  487. if (this.focusItem) {
  488. const oldMsg = this.focusItem.lineWidth;
  489. const newMsg = lineWidth;
  490. this.focusItem.lineWidth = lineWidth;
  491. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "lineWidth", oldMsg, newMsg));
  492. }
  493. }
  494. /**
  495. * 更改文本颜色属性
  496. * @param str string 颜色
  497. */
  498. updatedFontColor(color: string): void {
  499. if (this.focusItem) {
  500. const oldMsg = this.focusItem.color;
  501. const newMsg = new SColor(color);
  502. this.focusItem.color = newMsg;
  503. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "color", oldMsg, newMsg));
  504. }
  505. }
  506. /**
  507. * 更改border颜色
  508. * @param color string 颜色
  509. */
  510. updatedBorderColor(color: string): void {
  511. if (this.focusItem) {
  512. const oldMsg = this.focusItem.strokeColor;
  513. const newMsg = new SColor(color);
  514. this.focusItem.strokeColor = newMsg;
  515. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "strokeColor", oldMsg, newMsg));
  516. }
  517. }
  518. /**
  519. * 更改item宽
  520. * @param width number 颜色
  521. */
  522. updatedWidth(width: number): void {
  523. if (this.focusItem) {
  524. let oldMsg = null;
  525. const newMsg = width;
  526. if (this.focusItem.data && this.focusItem.data.GraphElementType && this.focusItem.data.GraphElementType == "Image") {
  527. oldMsg = this.focusItem.sWidth
  528. this.focusItem.sWidth = width;
  529. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "sWidth", oldMsg, newMsg));
  530. } else {
  531. oldMsg = this.focusItem.width
  532. this.focusItem.width = width;
  533. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "width", oldMsg, newMsg));
  534. }
  535. }
  536. }
  537. /**
  538. * 更改item高
  539. * @param height number 颜色
  540. */
  541. updatedHeight(height: number): void {
  542. if (this.focusItem) {
  543. let oldMsg = null;
  544. const newMsg = height;
  545. if (this.focusItem.data && this.focusItem.data.GraphElementType && this.focusItem.data.GraphElementType == "Image") {
  546. oldMsg = this.focusItem.sHeight;
  547. this.focusItem.sHeight = height;
  548. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "sHeight", oldMsg, newMsg));
  549. } else {
  550. oldMsg = this.focusItem.height;
  551. this.focusItem.height = height;
  552. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "height", oldMsg, newMsg));
  553. }
  554. }
  555. }
  556. /**
  557. * 更改item坐标
  558. * @param x number x x坐标
  559. * @param y number y y坐标
  560. */
  561. updatedPosition(x: number, y: number): void {
  562. if (this.focusItem) {
  563. let p = this.focusItem.mapFromScene(x, y)
  564. // newx - oldx = newleft - oldleft
  565. // 要求的值(新的x坐标) - 旧的x坐标 = 新的左边界(用户输入的值) - 旧的左边界
  566. this.focusItem.x = p.x - this.focusItem.boundingRect().left + this.focusItem.x;
  567. this.focusItem.y = p.y - this.focusItem.boundingRect().top + this.focusItem.y;
  568. }
  569. }
  570. /**
  571. * 更改item 背景色坐标
  572. * @param color string 颜色color
  573. */
  574. updatedbackColor(color: string): void {
  575. if (this.focusItem) {
  576. const newMsg = new SColor(color);
  577. const oldMsg = this.focusItem.backgroundColor;
  578. this.focusItem.backgroundColor = new SColor(color);
  579. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "backgroundColor", oldMsg, newMsg));
  580. }
  581. }
  582. /**
  583. * 更改item Url
  584. * @param url string 图片key
  585. */
  586. upadataImageUrl(url: string): void {
  587. if (this.focusItem) {
  588. const newMsg = '/serve/topology-wanda/Picture/query/' + url;
  589. const oldMsg = this.focusItem.url;
  590. this.focusItem.url = newMsg;
  591. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "url", oldMsg, newMsg));
  592. }
  593. }
  594. /**
  595. * 更改item border
  596. * @param val string border类型
  597. */
  598. upadataBorder(val: string): void {
  599. if (this.focusItem) {
  600. let borderStyle = null;
  601. if (val == 'dashed') {
  602. borderStyle = SLineStyle.Dashed;
  603. } else if (val == 'dotted') {
  604. borderStyle = SLineStyle.Dotted;
  605. } else if (val == 'solid') {
  606. borderStyle = SLineStyle.Solid;
  607. }
  608. const newMsg = borderStyle;
  609. const oldMsg = this.focusItem.lineStyle;
  610. this.focusItem.lineStyle = borderStyle;
  611. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "lineStyle", oldMsg, newMsg));
  612. }
  613. }
  614. /**
  615. * 更改item 名称
  616. * @param val string border类型
  617. */
  618. upadataLengedName(val: string): void {
  619. if (this.focusItem && this.focusItem.data) {
  620. const newMsg = val;
  621. const oldMsg = this.focusItem.text;
  622. this.focusItem.text = val;
  623. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "text", oldMsg, newMsg));
  624. this.scenceUpdate(this);
  625. }
  626. }
  627. /**
  628. * 更改item Num数量
  629. * @param num number item数量 (只对icon设备类)
  630. */
  631. upadatImageNum(num: number): void {
  632. if (this.focusItem && this.focusItem.num) {
  633. const newMsg = num;
  634. const oldMsg = this.focusItem.num;
  635. this.focusItem.num = num;
  636. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "num", oldMsg, newMsg));
  637. }
  638. }
  639. /**
  640. * 更改item Num数量
  641. * @param num number item数量 (只对icon设备类)
  642. */
  643. upadatfillColor(fillColor: string): void {
  644. if (this.focusItem && this.focusItem.fillColor) {
  645. const newMsg = new SColor(fillColor);
  646. const oldMsg = this.focusItem.fillColor;
  647. this.focusItem.fillColor = new SColor(fillColor);
  648. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "num", oldMsg, newMsg));
  649. }
  650. }
  651. /**
  652. * 更改图例说
  653. * @param num number
  654. */
  655. upadatitemExplain(ItemExplain: string): void {
  656. if (this.focusItem) {
  657. this.focusItem.data.Properties.ItemExplain = ItemExplain;
  658. }
  659. }
  660. /**
  661. * 更新工程信息化的相关数据
  662. * @param AttachObjectIds Array
  663. */
  664. upadatAttachObjectIds(AttachObjectIds: []): void {
  665. if (this.focusItem) {
  666. this.focusItem.data.AttachObjectIds = AttachObjectIds;
  667. // 重新选中focusitem
  668. const item = this.focusItem;
  669. this.selectContainer.clear();
  670. this.selectContainer.toggleItem(item)
  671. }
  672. }
  673. /**
  674. * 删除指定item
  675. */
  676. deleiteItem(): void {
  677. if (this.focusItem) {
  678. if ((this.focusItem instanceof SZoneLegendItem ||
  679. this.focusItem instanceof SSCPZZoneLegendItem ||
  680. this.focusItem instanceof SFHFQZoneLegendItem ||
  681. this.focusItem instanceof TipelineItem) &&
  682. this.focusItem.curIndex != -1
  683. ) {
  684. this.focusItem.deletePoint(this.focusItem.curIndex);
  685. } else {
  686. this.undoStack.push(new SGraphDeleteCommand(this, this.focusItem));
  687. this.removeItem(this.focusItem);
  688. let a = -1
  689. this.Nodes.forEach((item: any, index: number) => {
  690. if (item.id == this.focusItem.id) {
  691. a = index
  692. }
  693. });
  694. if (a > -1) {
  695. this.Nodes.splice(a, 1);
  696. }
  697. let b = -1;
  698. this.Markers.forEach((item: any, index: number) => {
  699. if (item.id == this.focusItem.id) {
  700. b = index
  701. }
  702. });
  703. if (b > -1) {
  704. this.Markers.splice(b, 1);
  705. }
  706. let c = -1;
  707. this.Relations.forEach((item: any, index: number) => {
  708. if (item.id == this.focusItem.id) {
  709. c = index
  710. }
  711. });
  712. if (c > -1) {
  713. this.Relations.splice(c, 1);
  714. }
  715. this.focusItem = null;
  716. if (this.view) {
  717. this.view.update();
  718. }
  719. this.scenceUpdate(this);
  720. }
  721. } else {
  722. //批量删除
  723. if (!this.focusItemList) {
  724. return
  725. }
  726. this.undoStack.push(new SGraphDeleteListCommand(this,this.focusItemList))
  727. this.focusItemList.forEach((focusItem) => {
  728. this.removeItem(focusItem);
  729. let a = -1
  730. this.Nodes.forEach((item: any, index: number) => {
  731. if (item.id == focusItem.id) {
  732. a = index
  733. }
  734. });
  735. if (a > -1) {
  736. this.Nodes.splice(a, 1);
  737. }
  738. let b = -1;
  739. this.Markers.forEach((item: any, index: number) => {
  740. if (item.id == focusItem.id) {
  741. b = index
  742. }
  743. });
  744. if (b > -1) {
  745. this.Markers.splice(b, 1);
  746. }
  747. let c = -1;
  748. this.Relations.forEach((item: any, index: number) => {
  749. if (item.id == focusItem.id) {
  750. c = index
  751. }
  752. });
  753. if (c > -1) {
  754. this.Relations.splice(c, 1);
  755. }
  756. });
  757. this.focusItemList = [];
  758. if (this.view) {
  759. this.view.update();
  760. }
  761. this.scenceUpdate(this);
  762. }
  763. }
  764. scenceUpdate(scence: any) {
  765. }
  766. /**
  767. * 对齐指定item
  768. * @param v
  769. */
  770. changeAlignItem(v: any): void {
  771. this.selectContainer.layout(v);
  772. }
  773. /**
  774. * 提取item
  775. */
  776. extractItem(): void {
  777. console.log(this)
  778. }
  779. /**
  780. * 保存数据
  781. */
  782. saveMsgItem(): any {
  783. const Nodes: any = [];
  784. const Markers: any = [];
  785. const Relations: any = [];
  786. this.Nodes.forEach(e => {
  787. Nodes.push(e.toData())
  788. });
  789. this.Markers.forEach(e => {
  790. Markers.push(e.toData())
  791. });
  792. this.Relations.forEach(e => {
  793. Relations.push(e.toData())
  794. });
  795. let element = {
  796. Nodes, Markers, Relations
  797. }
  798. return element
  799. }
  800. /**
  801. * 执行取消操作
  802. */
  803. redo(): void {
  804. if (this.grabItem && this.grabItem.redo) {
  805. this.grabItem.redo()
  806. } else {
  807. this.undoStack.redo();
  808. }
  809. }
  810. /**
  811. * 执行重做操作执行
  812. */
  813. undo(): void {
  814. if (this.grabItem && this.grabItem.undo) {
  815. this.grabItem.undo()
  816. } else {
  817. this.undoStack.undo();
  818. }
  819. }
  820. /**
  821. * 完成事件创建的回调函数
  822. */
  823. finishCreated(item: any) {
  824. let arrList = []
  825. if(this.cmd == 'baseLine'){
  826. arrList = this.Markers
  827. }
  828. this.cmd = 'choice';
  829. this.selectContainer.clear()
  830. this.selectContainer.toggleItem(item)
  831. setTimeout(() => {
  832. this.focusItem = item;
  833. })
  834. this.undoStack.push(new SGraphAddCommand(this, item,arrList));
  835. }
  836. ////////////////////////
  837. // 以下为鼠标键盘操作事件
  838. onMouseDown(event: SMouseEvent): any {
  839. if (!this.isEditStatus) {
  840. return super.onMouseDown(event);
  841. }
  842. // 判断是否开启吸附,并且有吸附的点
  843. if (
  844. this.isAbsorbing &&
  845. this.highLight &&
  846. this.highLight.visible
  847. ) {
  848. event.x = this.highLight.point.x;
  849. event.y = this.highLight.point.y;
  850. }
  851. if (this.grabItem) {
  852. if (this.grabItem instanceof TipelineItem) {
  853. this.setTipeEndanchor(event)
  854. return true;
  855. } else if (this.grabItem instanceof SLineMarkerItem && this.grabItem.status == SItemStatus.Create) {
  856. this.setLineItem(event)
  857. return true;
  858. }
  859. return this.grabItem.onMouseDown(event);
  860. }
  861. switch (this.cmd) {
  862. case 'baseLine':
  863. this.addLine(event);
  864. break;
  865. case 'baseText':
  866. this.addTextItem(event);
  867. break;
  868. case 'baseImage':
  869. this.addImgItem(event)
  870. break;
  871. case 'Zone':
  872. if (!this.isSelecting) {
  873. this.addPolygonItem(event);
  874. } else {
  875. // 点选创建区域
  876. return super.onMouseDown(event)
  877. }
  878. break;
  879. case 'Image':
  880. this.addIconItem(event);
  881. break;
  882. case 'Line':
  883. this.addTipelineItem(event);
  884. break;
  885. default:
  886. return super.onMouseDown(event);
  887. }
  888. }
  889. onMouseMove(event: SMouseEvent): boolean {
  890. if (!this.isEditStatus) {
  891. return super.onMouseMove(event);
  892. }
  893. if (this.isAbsorbing) {
  894. if (!this.highLight) {
  895. this.highLight = new HighlightItem(null);
  896. this.addItem(this.highLight);
  897. }
  898. this.highLight.visible = false;
  899. this.absorbSpace(event);
  900. }
  901. return super.onMouseMove(event)
  902. }
  903. onMouseUp(event: SMouseEvent): boolean {
  904. if (this.grabItem) {
  905. if (this.grabItem instanceof SLineMarkerItem && this.grabItem.status == SItemStatus.Edit) {
  906. this.setLineItem(event)
  907. return true;
  908. } else if (this.grabItem instanceof TipelineItem){
  909. this.updateTipeAnc(event);
  910. return true;
  911. }
  912. return this.grabItem.onMouseUp(event);
  913. }
  914. return super.onMouseUp(event)
  915. }
  916. /**
  917. * 键盘事件
  918. *
  919. * @param event 事件参数
  920. * @return boolean
  921. */
  922. onKeyDown(event: KeyboardEvent): any {
  923. if (!this.isEditStatus) {
  924. return super.onKeyDown(event);
  925. }
  926. if (this.grabItem) {
  927. this.grabItem.onKeyDown(event);
  928. if (event.code == "Escape") {
  929. const item = this.grabItem;
  930. this.grabItem = null
  931. this.removeItem(item);
  932. if (this.view) {
  933. this.view.update()
  934. }
  935. this.setCmd = 'choice'
  936. }
  937. }
  938. // if (event.key == "Enter") {
  939. // this.cmd = 0
  940. // }
  941. return false
  942. }
  943. /**
  944. * 鼠标双击事件
  945. *
  946. * @param event 事件参数
  947. * @return boolean
  948. */
  949. onDoubleClick(event: SMouseEvent): boolean {
  950. if (!this.isEditStatus) {
  951. return true
  952. } else {
  953. return super.onDoubleClick(event);
  954. }
  955. } // Function onDoubleClick()
  956. /**
  957. * 设置管线结束锚点
  958. *
  959. */
  960. setTipeEndanchor(event: SMouseEvent): void {
  961. if (this.grabItem instanceof TipelineItem) {
  962. const anc = this.clickIsAnchor(event);
  963. if (anc) {
  964. const p = anc.mapToScene(0, 0)
  965. anc.isConnected = true;
  966. event.x = p.x;
  967. event.y = p.y;
  968. if (this.grabItem.status == SItemStatus.Create) {
  969. if (this.grabItem.pointList.length) {
  970. this.grabItem.endAnchor = anc;
  971. anc.parent ?.connect('changePos', this.grabItem, this.grabItem.changePos)
  972. }
  973. this.grabItem.anchor2ID = anc.id
  974. this.grabItem.node2Id = anc.parent.id
  975. this.grabItem.onMouseDown(event)
  976. this.grabItem.status = SItemStatus.Normal;
  977. this.finishCreated(this.grabItem)
  978. return
  979. }
  980. }
  981. this.grabItem.onMouseDown(event)
  982. }
  983. }
  984. /**
  985. * 管线item修改锚点
  986. *
  987. */
  988. updateTipeAnc(event: SMouseEvent): void {
  989. if (this.grabItem instanceof TipelineItem){
  990. const anc = this.clickIsAnchor(event);
  991. if (anc) {
  992. const p = anc.mapToScene(0, 0)
  993. event.x = p.x;
  994. event.y = p.y;
  995. if (this.grabItem.status == SItemStatus.Edit) {
  996. if (this.grabItem.curIndex == 0) {
  997. if (this.grabItem.startAnchor){
  998. this.grabItem.startAnchor.isConnected = false
  999. this.grabItem.startAnchor.parent.disconnect('changePos',this.grabItem);
  1000. }
  1001. anc.isConnected = true;
  1002. this.grabItem.startAnchor = anc;
  1003. this.grabItem.anchor1ID = anc.id
  1004. this.grabItem.node1Id = anc.parent.id
  1005. anc.parent.connect('changePos', this.grabItem, this.grabItem.changePos)
  1006. }
  1007. if (this.grabItem.curIndex == this.grabItem.pointList.length-1) {
  1008. if (this.grabItem.endAnchor){
  1009. this.grabItem.endAnchor.isConnected = false
  1010. this.grabItem.endAnchor.parent.disconnect('changePos',this.grabItem);
  1011. }
  1012. anc.isConnected = true;
  1013. this.grabItem.endAnchor = anc;
  1014. this.grabItem.anchor2ID = anc.id
  1015. this.grabItem.node2Id = anc.parent.id
  1016. anc.parent.connect('changePos', this.grabItem, this.grabItem.changePos)
  1017. }
  1018. }
  1019. this.grabItem.onMouseUp(event)
  1020. return
  1021. } else {
  1022. if (this.grabItem.status == SItemStatus.Edit) {
  1023. if (this.grabItem.curIndex == 0) {
  1024. if (this.grabItem.startAnchor){
  1025. this.grabItem.startAnchor.isConnected = false
  1026. this.grabItem.startAnchor.parent.disconnect('changePos',this.grabItem);
  1027. this.grabItem.startAnchor = null;
  1028. this.grabItem.anchor1ID = ''
  1029. this.grabItem.node1Id = ''
  1030. }
  1031. }
  1032. if (this.grabItem.curIndex == this.grabItem.pointList.length-1) {
  1033. if (this.grabItem.endAnchor){
  1034. this.grabItem.endAnchor.isConnected = false
  1035. this.grabItem.endAnchor.parent.disconnect('changePos',this.grabItem);
  1036. this.grabItem.endAnchor = null;
  1037. this.grabItem.anchor2ID = ''
  1038. this.grabItem.node2Id = ''
  1039. }
  1040. }
  1041. }
  1042. this.grabItem.onMouseUp(event)
  1043. return
  1044. }
  1045. }
  1046. }
  1047. /**
  1048. * 设置直线结束Item
  1049. *
  1050. */
  1051. setLineItem(event: SMouseEvent): void {
  1052. if (this.grabItem instanceof SLineMarkerItem) {
  1053. const item = this.clickIsItem(event);
  1054. // 鼠标点是否在某个item内
  1055. if (item) {
  1056. let scenePoint = item.boundingRect().center();
  1057. const p = item.mapToScene(scenePoint.x, scenePoint.y);
  1058. event.x = p.x;
  1059. event.y = p.y;
  1060. if (this.grabItem.status == SItemStatus.Create) {
  1061. // 点击在item内、创建状态且端点列表不为空时将直线结束端点和item绑定
  1062. if (this.grabItem.line.length) {
  1063. if (this.grabItem.startItem ?.id == item.id) {
  1064. this.grabItem.endItem = null;
  1065. } else {
  1066. this.grabItem.endItem = item;
  1067. this.grabItem.line[1] = new SPoint(event.x, event.y);
  1068. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1069. }
  1070. }
  1071. this.grabItem.onMouseDown(event);
  1072. return
  1073. } else if (this.grabItem.status == SItemStatus.Edit) {
  1074. // 点击在item内、编辑状态且点击的为结束端点时
  1075. if (this.grabItem.curIndex == 1) {
  1076. // 直线关联的起始item是直线结束端点所在的item时,不吸附在点击item中心并将直线关联的结束item置为null
  1077. if (this.grabItem.startItem ?.id == item.id) {
  1078. this.grabItem.endItem = null;
  1079. } else {// 反正吸附,关联
  1080. this.grabItem.endItem = item;
  1081. this.grabItem.line[1] = new SPoint(event.x, event.y);
  1082. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1083. }
  1084. } else if (this.grabItem.curIndex == 0) {
  1085. if (this.grabItem.endItem ?.id == item.id) {
  1086. this.grabItem.startItem = null;
  1087. } else {
  1088. this.grabItem.startItem = item;
  1089. this.grabItem.line[0] = new SPoint(event.x, event.y);
  1090. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1091. }
  1092. }
  1093. }
  1094. } else {
  1095. // 如果不在item内且点击的是直线的某个端点,将端点的关联item置为null
  1096. if (this.grabItem.line.length && this.grabItem.curIndex != -1) {
  1097. if (this.grabItem.curIndex == 1) {
  1098. this.grabItem.endItem = null;
  1099. } else if (this.grabItem.curIndex == 0) {
  1100. this.grabItem.startItem = null;
  1101. }
  1102. } else {
  1103. this.grabItem.onMouseDown(event);
  1104. return
  1105. }
  1106. }
  1107. // if (this.grabItem.status == SItemStatus.Create) {
  1108. // // 鼠标点是否在某个item内
  1109. // if (item) {
  1110. // let scenePoint = item.boundingRect().center();
  1111. // const p = item.mapToScene(scenePoint.x, scenePoint.y);
  1112. // event.x = p.x;
  1113. // event.y = p.y;
  1114. // if (this.grabItem.line.length && this.grabItem.curIndex == -1) {
  1115. // this.grabItem.endItem = item;
  1116. // this.grabItem.line[1] = new SPoint(event.x, event.y);
  1117. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1118. // }
  1119. // this.grabItem.onMouseDown(event);
  1120. // return
  1121. // } else {
  1122. // if (this.grabItem.line.length && this.grabItem.curIndex != -1) {
  1123. // if (this.grabItem.curIndex == 1) {
  1124. // this.grabItem.endItem = null;
  1125. // } else if (this.grabItem.curIndex == 0) {
  1126. // this.grabItem.startItem = null;
  1127. // }
  1128. // }
  1129. // }
  1130. // } else if (this.grabItem.status == SItemStatus.Edit) {
  1131. // if (this.grabItem.curIndex == 1) {
  1132. // this.grabItem.endItem = item;
  1133. // this.grabItem.line[1] = new SPoint(event.x, event.y);
  1134. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1135. // } else if (this.grabItem.curIndex == 0) {
  1136. // this.grabItem.startItem = item;
  1137. // this.grabItem.line[0] = new SPoint(event.x, event.y);
  1138. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1139. // }
  1140. // }
  1141. this.grabItem.onMouseUp(event);
  1142. }
  1143. }
  1144. /**
  1145. * 划线时点击位置是否是锚点
  1146. *
  1147. * @param event 事件
  1148. * @param len 限制距离
  1149. * @return 点击的锚点
  1150. * */
  1151. clickIsAnchor(event: SMouseEvent): SAnchorItem | null {
  1152. let minAnchor = null;
  1153. let len: number = -1;
  1154. this.Nodes.forEach(image => {
  1155. if (image.anchorList && image.anchorList.length) {
  1156. image.anchorList.forEach(anchor => {
  1157. let anchorPoint = anchor.mapToScene(0, 0);
  1158. let dis = SMathUtil.pointDistance(
  1159. event.x,
  1160. event.y,
  1161. anchorPoint.x,
  1162. anchorPoint.y
  1163. );
  1164. if (len < 0) {
  1165. len = anchor.sceneDis;
  1166. }
  1167. if (dis < len) {
  1168. minAnchor = anchor;
  1169. len = dis;
  1170. }
  1171. })
  1172. }
  1173. })
  1174. console.log('-----------------------')
  1175. console.log(minAnchor)
  1176. console.log('-----------------------')
  1177. return minAnchor;
  1178. }
  1179. /**
  1180. * 划线时点击位置是在文本,图片,,区域内
  1181. *
  1182. * @param event 事件
  1183. * @return 点击的item
  1184. * */
  1185. clickIsItem(event: SMouseEvent): SGraphItem | null {
  1186. let minIten = null;
  1187. let len: number = -1;
  1188. let itemList = this.Nodes.concat(this.Markers);
  1189. itemList.forEach(item => {
  1190. if (
  1191. item instanceof STextMarkerItem ||
  1192. item instanceof SImageMarkerItem ||
  1193. item instanceof SZoneLegendItem ||
  1194. item instanceof SFHFQZoneLegendItem ||
  1195. item instanceof SSCPZZoneLegendItem
  1196. ) {
  1197. let scenePoint = item.mapFromScene(event.x, event.y);
  1198. if (item.contains(scenePoint.x, scenePoint.y)) {
  1199. let dis = SMathUtil.pointDistance(
  1200. scenePoint.x,
  1201. scenePoint.y,
  1202. item.boundingRect().center().x,
  1203. item.boundingRect().center().y
  1204. );
  1205. if (len < 0) {
  1206. minIten = item;
  1207. len = dis;
  1208. }
  1209. if (dis < len) {
  1210. minIten = item;
  1211. len = dis;
  1212. }
  1213. }
  1214. }
  1215. })
  1216. console.log('-----------------------')
  1217. console.log(minIten)
  1218. console.log('-----------------------')
  1219. return minIten;
  1220. }
  1221. /**
  1222. * 点是否在吸附区域内
  1223. *
  1224. * @param p 要判断的点
  1225. * @param minX 空间区域
  1226. * @param minY 空间区域
  1227. * @param maxX 空间区域
  1228. * @param maxY 空间区域
  1229. */
  1230. static isPointInAbsorbArea(
  1231. p: SPoint,
  1232. minX: number,
  1233. maxX: number,
  1234. minY: number,
  1235. maxY: number
  1236. ): boolean {
  1237. let rect = new SRect(
  1238. minX - 1000,
  1239. minY - 1000,
  1240. maxX - minX + 2000,
  1241. maxY - minY + 2000
  1242. );
  1243. return rect.contains(p.x, p.y);
  1244. } // Function isPointInAbsorbArea()
  1245. /**
  1246. * 吸附空间
  1247. *
  1248. * @param event 鼠标事件对象
  1249. * @return boolean 是否找到吸附的对象
  1250. */
  1251. absorbSpace(event: SMouseEvent): boolean {
  1252. if (!this.highLight) {
  1253. return false;
  1254. }
  1255. let absorbLen = 1000;
  1256. if (this.view) {
  1257. absorbLen = 10 / this.view.scale;
  1258. }
  1259. let P = this.absorbSpacePoint(event, absorbLen);
  1260. if (P.Point) {
  1261. this.highLight.distance = P.MinDis;
  1262. this.highLight.point = new SPoint(P.Point.X, -P.Point.Y);
  1263. this.highLight.visible = true;
  1264. return true;
  1265. } else {
  1266. let L = this.absorbSpaceLine(event, absorbLen);
  1267. if (L.Line && L.Point) {
  1268. this.highLight.distance = L.MinDis;
  1269. this.highLight.point = L.Point;
  1270. this.highLight.line = L.Line;
  1271. this.highLight.visible = true;
  1272. return true;
  1273. }
  1274. return false;
  1275. }
  1276. } // Function absorbSpace()
  1277. /**
  1278. * 吸附空间点
  1279. *
  1280. * @param event 鼠标事件对象
  1281. * @param absorbLen 吸附距离
  1282. * @return MinDis 吸附的点
  1283. */
  1284. absorbSpacePoint(event: SMouseEvent, absorbLen: number): MinDis {
  1285. let minPointDis = Number.MAX_SAFE_INTEGER;
  1286. let Point;
  1287. this.spaceList.map((space): void => {
  1288. if (
  1289. EditScence.isPointInAbsorbArea(
  1290. new SPoint(event.x, event.y),
  1291. space.minX,
  1292. space.maxX,
  1293. space.minY,
  1294. space.maxY
  1295. )
  1296. ) {
  1297. space.data.OutLine.forEach((item): void => {
  1298. let minDis = SMathUtil.getMinDisPoint(
  1299. new SPoint(event.x, event.y),
  1300. item
  1301. );
  1302. if (
  1303. minDis &&
  1304. minDis.MinDis < absorbLen &&
  1305. minDis.MinDis < minPointDis
  1306. ) {
  1307. minPointDis = minDis.MinDis;
  1308. Point = minDis.Point;
  1309. }
  1310. });
  1311. }
  1312. });
  1313. return {
  1314. MinDis: minPointDis,
  1315. Point: Point
  1316. };
  1317. } // Function absorbSpacePoint()
  1318. /**
  1319. * 吸附空间线
  1320. *
  1321. * @param event 鼠标事件对象
  1322. * @param absorbLen 吸附距离
  1323. * @return PointToLine 吸附的线
  1324. */
  1325. absorbSpaceLine(event: SMouseEvent, absorbLen: number): PointToLine {
  1326. let minPointDis = Number.MAX_SAFE_INTEGER;
  1327. let Point, Line;
  1328. this.spaceList.forEach((space): void => {
  1329. if (
  1330. EditScence.isPointInAbsorbArea(
  1331. new SPoint(event.x, event.y),
  1332. space.minX,
  1333. space.maxX,
  1334. space.minY,
  1335. space.maxY
  1336. )
  1337. ) {
  1338. space.data.OutLine.forEach((item): void => {
  1339. let minDisLine = SMathUtil.getMinDisLine(
  1340. new SPoint(event.x, event.y),
  1341. item
  1342. );
  1343. if (
  1344. minDisLine &&
  1345. minDisLine.MinDis < absorbLen &&
  1346. minDisLine.MinDis < minPointDis
  1347. ) {
  1348. minPointDis = minDisLine.MinDis;
  1349. Point = minDisLine.Point;
  1350. Line = minDisLine.Line;
  1351. }
  1352. });
  1353. }
  1354. });
  1355. return {
  1356. MinDis: minPointDis,
  1357. Point: Point,
  1358. Line: Line
  1359. };
  1360. } // Function absorbSpaceLine()
  1361. /**
  1362. * 添加多个item命令
  1363. * @param focusItemList 鼠标事件对象
  1364. */
  1365. AddListCommand (focusItemList:any[]):void{
  1366. this.undoStack.push(new SGraphAddListCommand(this,focusItemList));
  1367. }
  1368. }