EditScence.ts 52 KB

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