EditScence.ts 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  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. StrokeColor: "#c0ccda",
  361. Url: '',
  362. }
  363. }
  364. const item = new SImageMarkerItem(null, data);
  365. item.zOrder = ItemOrder.imageOrder;
  366. item.selectable = true;
  367. item.moveable = true;
  368. this.addItem(item);
  369. this.Markers.push(item);
  370. this.grabItem == null;
  371. this.focusItem = item;
  372. this.finishCreated(item);
  373. this.scenceUpdate(this);
  374. }
  375. /**
  376. * 增加文字item
  377. */
  378. addTextItem(event: SMouseEvent): void {
  379. const data = {
  380. /** ID */
  381. ID: uuid(),
  382. /** 名称 */
  383. Name: '文本',
  384. /** 图标 */
  385. Type: "Text",
  386. /** 位置 */
  387. Pos: { X: event.x, Y: event.y },
  388. /** 由应用自己定义 */
  389. Properties: {
  390. IconUrl: require(`../../assets/images/t-text-hover.png`),
  391. Text: '请在右侧属性栏输入文字!',
  392. Color: '',
  393. Font: 12,
  394. BackgroundColor: '#f7f9fa'
  395. }
  396. }
  397. const item = new STextMarkerItem(null, data);
  398. item.moveTo(event.x, event.y);
  399. item.selectable = true;
  400. item.moveable = true;
  401. item.zOrder = ItemOrder.textOrder;
  402. this.addItem(item);
  403. this.Markers.push(item);
  404. this.grabItem = item;
  405. this.focusItem = item;
  406. this.cmd = 'choice';
  407. this.finishCreated(item);
  408. this.scenceUpdate(this);
  409. }
  410. /**
  411. * 增加图标lenged图标
  412. */
  413. addIconItem(event: SMouseEvent): void {
  414. //获取信息工程化相关参数
  415. const InfoSystemId = this._legend.InfoSystemId ? this._legend.InfoSystemId : '';
  416. const LegendData: Legend = {
  417. ID: uuid(),
  418. Name: this._legend.Name,
  419. GraphElementType: this._legend.Type,
  420. Num: 1,
  421. GraphElementId: this._legend.Id,
  422. AttachObjectIds: [],
  423. Pos: { X: event.x, Y: event.y },
  424. Scale: { X: 1, Y: 1, Z: 1 }, // 缩放
  425. Rolate: { X: 0, Y: 0, Z: 0 },
  426. Size: { Width: 0, Height: 0 }, // 大小
  427. Type: this._legend.Type,
  428. Properties: {
  429. IconUrl: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  430. Url: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  431. Num: 1, // 此num与信息工程化得num无关
  432. sWidth: 32, //icon 的宽
  433. sHeight: 32, //icon 的高
  434. font: 12, //font
  435. color: '', //字体颜色
  436. GraphCategoryId: this._legend.GraphCategoryId,
  437. InfoSystemId: InfoSystemId //信息工程话分类ID分类
  438. },
  439. }
  440. const item = new SImageLegendItem(null, LegendData);
  441. this.cmd = 'choice';
  442. item.selectable = true;
  443. item.moveable = true;
  444. item.zOrder = ItemOrder.markOrder;
  445. this.addItem(item);
  446. this.Nodes.push(item);
  447. this.grabItem = item;
  448. this.focusItem = item;
  449. this.finishCreated(item);
  450. this.scenceUpdate(this);
  451. }
  452. /**
  453. * 更改item对应属性
  454. */
  455. editItemStatus(): void {
  456. }
  457. /**
  458. * 更改文本对应属性
  459. * @param str string 文字内容
  460. */
  461. updatedText(str: string): void {
  462. if (this.focusItem) {
  463. const oldMsg = this.focusItem.text;
  464. const newMsg = str;
  465. this.focusItem.text = str;
  466. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "text", oldMsg, newMsg));
  467. this.scenceUpdate(this);
  468. }
  469. }
  470. /**
  471. * 更改文本fontSize属性
  472. * @param size number 文字大小
  473. */
  474. updatedFontSize(size: number): void {
  475. if (this.focusItem) {
  476. let old = new SFont(this.focusItem.font);
  477. let font = new SFont(this.focusItem.font);
  478. font.size = size;
  479. this.focusItem.font = font;
  480. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "font", old, font));
  481. }
  482. }
  483. /**
  484. * 更改线宽属性
  485. * @param lineWidth number 线宽大小
  486. */
  487. updatedLineWidth(lineWidth: number): void {
  488. if (this.focusItem) {
  489. const oldMsg = this.focusItem.lineWidth;
  490. const newMsg = lineWidth;
  491. this.focusItem.lineWidth = lineWidth;
  492. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "lineWidth", oldMsg, newMsg));
  493. }
  494. }
  495. /**
  496. * 更改文本颜色属性
  497. * @param str string 颜色
  498. */
  499. updatedFontColor(color: string): void {
  500. if (this.focusItem) {
  501. const oldMsg = this.focusItem.color;
  502. const newMsg = new SColor(color);
  503. this.focusItem.color = newMsg;
  504. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "color", oldMsg, newMsg));
  505. }
  506. }
  507. /**
  508. * 更改border颜色
  509. * @param color string 颜色
  510. */
  511. updatedBorderColor(color: string): void {
  512. if (this.focusItem) {
  513. const oldMsg = this.focusItem.strokeColor;
  514. const newMsg = new SColor(color);
  515. this.focusItem.strokeColor = newMsg;
  516. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "strokeColor", oldMsg, newMsg));
  517. }
  518. }
  519. /**
  520. * 更改item宽
  521. * @param width number 颜色
  522. */
  523. updatedWidth(width: number): void {
  524. if (this.focusItem) {
  525. let oldMsg = null;
  526. const newMsg = width;
  527. if (this.focusItem.data && this.focusItem.data.GraphElementType && this.focusItem.data.GraphElementType == "Image") {
  528. oldMsg = this.focusItem.sWidth
  529. this.focusItem.sWidth = width;
  530. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "sWidth", oldMsg, newMsg));
  531. } else {
  532. oldMsg = this.focusItem.width
  533. this.focusItem.width = width;
  534. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "width", oldMsg, newMsg));
  535. }
  536. }
  537. }
  538. /**
  539. * 更改item高
  540. * @param height number 颜色
  541. */
  542. updatedHeight(height: number): void {
  543. if (this.focusItem) {
  544. let oldMsg = null;
  545. const newMsg = height;
  546. if (this.focusItem.data && this.focusItem.data.GraphElementType && this.focusItem.data.GraphElementType == "Image") {
  547. oldMsg = this.focusItem.sHeight;
  548. this.focusItem.sHeight = height;
  549. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "sHeight", oldMsg, newMsg));
  550. } else {
  551. oldMsg = this.focusItem.height;
  552. this.focusItem.height = height;
  553. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "height", oldMsg, newMsg));
  554. }
  555. }
  556. }
  557. /**
  558. * 更改item坐标
  559. * @param x number x x坐标
  560. * @param y number y y坐标
  561. */
  562. updatedPosition(x: number, y: number): void {
  563. if (this.focusItem) {
  564. let p = this.focusItem.mapFromScene(x, y)
  565. // newx - oldx = newleft - oldleft
  566. // 要求的值(新的x坐标) - 旧的x坐标 = 新的左边界(用户输入的值) - 旧的左边界
  567. this.focusItem.x = p.x - this.focusItem.boundingRect().left + this.focusItem.x;
  568. this.focusItem.y = p.y - this.focusItem.boundingRect().top + this.focusItem.y;
  569. }
  570. }
  571. /**
  572. * 更改item 背景色坐标
  573. * @param color string 颜色color
  574. */
  575. updatedbackColor(color: string): void {
  576. if (this.focusItem) {
  577. const newMsg = new SColor(color);
  578. const oldMsg = this.focusItem.backgroundColor;
  579. this.focusItem.backgroundColor = new SColor(color);
  580. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "backgroundColor", oldMsg, newMsg));
  581. }
  582. }
  583. /**
  584. * 更改item Url
  585. * @param url string 图片key
  586. */
  587. upadataImageUrl(url: string): void {
  588. if (this.focusItem) {
  589. const newMsg = '/serve/topology-wanda/Picture/query/' + url;
  590. const oldMsg = this.focusItem.url;
  591. this.focusItem.url = newMsg;
  592. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "url", oldMsg, newMsg));
  593. }
  594. }
  595. /**
  596. * 更改item border
  597. * @param val string border类型
  598. */
  599. upadataBorder(val: string): void {
  600. if (this.focusItem) {
  601. let borderStyle = null;
  602. if (val == 'dashed') {
  603. borderStyle = SLineStyle.Dashed;
  604. } else if (val == 'dotted') {
  605. borderStyle = SLineStyle.Dotted;
  606. } else if (val == 'solid') {
  607. borderStyle = SLineStyle.Solid;
  608. }
  609. const newMsg = borderStyle;
  610. const oldMsg = this.focusItem.lineStyle;
  611. this.focusItem.lineStyle = borderStyle;
  612. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "lineStyle", oldMsg, newMsg));
  613. }
  614. }
  615. /**
  616. * 更改item 名称
  617. * @param val string border类型
  618. */
  619. upadataLengedName(val: string): void {
  620. if (this.focusItem && this.focusItem.data) {
  621. const newMsg = val;
  622. const oldMsg = this.focusItem.text;
  623. this.focusItem.text = val;
  624. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "text", oldMsg, newMsg));
  625. this.scenceUpdate(this);
  626. }
  627. }
  628. /**
  629. * 更改item Num数量
  630. * @param num number item数量 (只对icon设备类)
  631. */
  632. upadatImageNum(num: number): void {
  633. if (this.focusItem && this.focusItem.num) {
  634. const newMsg = num;
  635. const oldMsg = this.focusItem.num;
  636. this.focusItem.num = num;
  637. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "num", oldMsg, newMsg));
  638. }
  639. }
  640. /**
  641. * 更改item Num数量
  642. * @param num number item数量 (只对icon设备类)
  643. */
  644. upadatfillColor(fillColor: string): void {
  645. if (this.focusItem && this.focusItem.fillColor) {
  646. const newMsg = new SColor(fillColor);
  647. const oldMsg = this.focusItem.fillColor;
  648. this.focusItem.fillColor = new SColor(fillColor);
  649. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "num", oldMsg, newMsg));
  650. }
  651. }
  652. /**
  653. * 更改图例说
  654. * @param num number
  655. */
  656. upadatitemExplain(ItemExplain: string): void {
  657. if (this.focusItem) {
  658. this.focusItem.data.Properties.ItemExplain = ItemExplain;
  659. }
  660. }
  661. /**
  662. * 更新工程信息化的相关数据
  663. * @param AttachObjectIds Array
  664. */
  665. upadatAttachObjectIds(AttachObjectIds: []): void {
  666. if (this.focusItem) {
  667. this.focusItem.data.AttachObjectIds = AttachObjectIds;
  668. // 重新选中focusitem
  669. const item = this.focusItem;
  670. this.selectContainer.clear();
  671. this.selectContainer.toggleItem(item)
  672. }
  673. }
  674. /**
  675. * 删除指定item
  676. */
  677. deleiteItem(): void {
  678. if (this.focusItem) {
  679. if ((this.focusItem instanceof SZoneLegendItem ||
  680. this.focusItem instanceof SSCPZZoneLegendItem ||
  681. this.focusItem instanceof SFHFQZoneLegendItem ||
  682. this.focusItem instanceof TipelineItem) &&
  683. this.focusItem.curIndex != -1
  684. ) {
  685. this.focusItem.deletePoint(this.focusItem.curIndex);
  686. } else {
  687. this.undoStack.push(new SGraphDeleteCommand(this, this.focusItem));
  688. this.removeItem(this.focusItem);
  689. let a = -1
  690. this.Nodes.forEach((item: any, index: number) => {
  691. if (item.id == this.focusItem.id) {
  692. a = index
  693. }
  694. });
  695. if (a > -1) {
  696. this.Nodes.splice(a, 1);
  697. }
  698. let b = -1;
  699. this.Markers.forEach((item: any, index: number) => {
  700. if (item.id == this.focusItem.id) {
  701. b = index
  702. }
  703. });
  704. if (b > -1) {
  705. this.Markers.splice(b, 1);
  706. }
  707. let c = -1;
  708. this.Relations.forEach((item: any, index: number) => {
  709. if (item.id == this.focusItem.id) {
  710. c = index
  711. }
  712. });
  713. if (c > -1) {
  714. this.Relations.splice(c, 1);
  715. }
  716. this.focusItem = null;
  717. if (this.view) {
  718. this.view.update();
  719. }
  720. this.scenceUpdate(this);
  721. }
  722. } else {
  723. //批量删除
  724. if (!this.focusItemList) {
  725. return
  726. }
  727. this.undoStack.push(new SGraphDeleteListCommand(this, this.focusItemList))
  728. this.focusItemList.forEach((focusItem) => {
  729. this.removeItem(focusItem);
  730. let a = -1
  731. this.Nodes.forEach((item: any, index: number) => {
  732. if (item.id == focusItem.id) {
  733. a = index
  734. }
  735. });
  736. if (a > -1) {
  737. this.Nodes.splice(a, 1);
  738. }
  739. let b = -1;
  740. this.Markers.forEach((item: any, index: number) => {
  741. if (item.id == focusItem.id) {
  742. b = index
  743. }
  744. });
  745. if (b > -1) {
  746. this.Markers.splice(b, 1);
  747. }
  748. let c = -1;
  749. this.Relations.forEach((item: any, index: number) => {
  750. if (item.id == focusItem.id) {
  751. c = index
  752. }
  753. });
  754. if (c > -1) {
  755. this.Relations.splice(c, 1);
  756. }
  757. });
  758. this.focusItemList = [];
  759. if (this.view) {
  760. this.view.update();
  761. }
  762. this.scenceUpdate(this);
  763. }
  764. }
  765. scenceUpdate(scence: any) {
  766. }
  767. /**
  768. * 对齐指定item
  769. * @param v
  770. */
  771. changeAlignItem(v: any): void {
  772. this.selectContainer.layout(v);
  773. }
  774. /**
  775. * 提取item
  776. */
  777. extractItem(): void {
  778. console.log(this)
  779. }
  780. /**
  781. * 保存数据
  782. */
  783. saveMsgItem(): any {
  784. const Nodes: any = [];
  785. const Markers: any = [];
  786. const Relations: any = [];
  787. this.Nodes.forEach(e => {
  788. Nodes.push(e.toData())
  789. });
  790. this.Markers.forEach(e => {
  791. Markers.push(e.toData())
  792. });
  793. this.Relations.forEach(e => {
  794. Relations.push(e.toData())
  795. });
  796. let element = {
  797. Nodes, Markers, Relations
  798. }
  799. return element
  800. }
  801. /**
  802. * 执行取消操作
  803. */
  804. redo(): void {
  805. if (this.grabItem && this.grabItem.redo) {
  806. this.grabItem.redo()
  807. } else {
  808. this.undoStack.redo();
  809. }
  810. }
  811. /**
  812. * 执行重做操作执行
  813. */
  814. undo(): void {
  815. if (this.grabItem && this.grabItem.undo) {
  816. this.grabItem.undo()
  817. } else {
  818. this.undoStack.undo();
  819. }
  820. }
  821. /**
  822. * 完成事件创建的回调函数
  823. */
  824. finishCreated(item: any) {
  825. let arrList = []
  826. if (this.cmd == 'baseLine') {
  827. arrList = this.Markers
  828. }
  829. this.cmd = 'choice';
  830. this.selectContainer.clear()
  831. this.selectContainer.toggleItem(item)
  832. setTimeout(() => {
  833. this.focusItem = item;
  834. })
  835. this.undoStack.push(new SGraphAddCommand(this, item, arrList));
  836. }
  837. ////////////////////////
  838. // 以下为鼠标键盘操作事件
  839. onMouseDown(event: SMouseEvent): any {
  840. if (!this.isEditStatus) {
  841. return true
  842. }
  843. // 判断是否开启吸附,并且有吸附的点
  844. if (
  845. this.isAbsorbing &&
  846. this.highLight &&
  847. this.highLight.visible
  848. ) {
  849. event.x = this.highLight.point.x;
  850. event.y = this.highLight.point.y;
  851. }
  852. if (this.grabItem) {
  853. if (this.grabItem instanceof TipelineItem) {
  854. this.setTipeEndanchor(event)
  855. return true;
  856. } else if (this.grabItem instanceof SLineMarkerItem && this.grabItem.status == SItemStatus.Create) {
  857. this.setLineItem(event)
  858. return true;
  859. }
  860. return this.grabItem.onMouseDown(event);
  861. }
  862. switch (this.cmd) {
  863. case 'baseLine':
  864. this.addLine(event);
  865. break;
  866. case 'baseText':
  867. this.addTextItem(event);
  868. break;
  869. case 'baseImage':
  870. this.addImgItem(event)
  871. break;
  872. case 'Zone':
  873. if (!this.isSelecting) {
  874. this.addPolygonItem(event);
  875. } else {
  876. // 点选创建区域
  877. return super.onMouseDown(event)
  878. }
  879. break;
  880. case 'Image':
  881. this.addIconItem(event);
  882. break;
  883. case 'Line':
  884. this.addTipelineItem(event);
  885. break;
  886. default:
  887. return super.onMouseDown(event);
  888. }
  889. }
  890. onMouseMove(event: SMouseEvent): boolean {
  891. if (!this.isEditStatus) {
  892. return true
  893. }
  894. if (this.isAbsorbing) {
  895. if (!this.highLight) {
  896. this.highLight = new HighlightItem(null);
  897. this.addItem(this.highLight);
  898. }
  899. this.highLight.visible = false;
  900. this.absorbSpace(event);
  901. }
  902. return super.onMouseMove(event)
  903. }
  904. onMouseUp(event: SMouseEvent): boolean {
  905. if (!this.isEditStatus) {
  906. return true
  907. }
  908. if (this.grabItem) {
  909. if (this.grabItem instanceof SLineMarkerItem && this.grabItem.status == SItemStatus.Edit) {
  910. this.setLineItem(event)
  911. return true;
  912. } else if (this.grabItem instanceof TipelineItem) {
  913. this.updateTipeAnc(event);
  914. return true;
  915. }
  916. return this.grabItem.onMouseUp(event);
  917. }
  918. return super.onMouseUp(event)
  919. }
  920. /**
  921. * 键盘事件
  922. *
  923. * @param event 事件参数
  924. * @return boolean
  925. */
  926. onKeyDown(event: KeyboardEvent): any {
  927. if (!this.isEditStatus) {
  928. return true
  929. }
  930. if (this.grabItem) {
  931. this.grabItem.onKeyDown(event);
  932. if (event.code == "Escape") {
  933. const item = this.grabItem;
  934. this.grabItem = null
  935. this.removeItem(item);
  936. if (this.view) {
  937. this.view.update()
  938. }
  939. this.setCmd = 'choice'
  940. }
  941. }
  942. // 删除键功能
  943. if (event.code == 'Delete') {
  944. this.deleiteItem()
  945. }
  946. return false
  947. }
  948. /**
  949. * 鼠标双击事件
  950. *
  951. * @param event 事件参数
  952. * @return boolean
  953. */
  954. onDoubleClick(event: SMouseEvent): boolean {
  955. if (!this.isEditStatus) {
  956. return true
  957. } else {
  958. return super.onDoubleClick(event);
  959. }
  960. } // Function onDoubleClick()
  961. /**
  962. * 设置管线结束锚点
  963. *
  964. */
  965. setTipeEndanchor(event: SMouseEvent): void {
  966. if (this.grabItem instanceof TipelineItem) {
  967. const anc = this.clickIsAnchor(event);
  968. if (anc) {
  969. const p = anc.mapToScene(0, 0)
  970. anc.isConnected = true;
  971. event.x = p.x;
  972. event.y = p.y;
  973. if (this.grabItem.status == SItemStatus.Create) {
  974. if (this.grabItem.pointList.length) {
  975. this.grabItem.endAnchor = anc;
  976. anc.parent ?.connect('changePos', this.grabItem, this.grabItem.changePos)
  977. }
  978. this.grabItem.anchor2ID = anc.id
  979. this.grabItem.node2Id = anc.parent.id
  980. this.grabItem.onMouseDown(event)
  981. this.grabItem.status = SItemStatus.Normal;
  982. this.finishCreated(this.grabItem)
  983. return
  984. }
  985. }
  986. this.grabItem.onMouseDown(event)
  987. }
  988. }
  989. /**
  990. * 管线item修改锚点
  991. *
  992. */
  993. updateTipeAnc(event: SMouseEvent): void {
  994. if (this.grabItem instanceof TipelineItem) {
  995. const anc = this.clickIsAnchor(event);
  996. if (anc) {
  997. const p = anc.mapToScene(0, 0)
  998. event.x = p.x;
  999. event.y = p.y;
  1000. if (this.grabItem.status == SItemStatus.Edit) {
  1001. if (this.grabItem.curIndex == 0) {
  1002. if (this.grabItem.startAnchor) {
  1003. this.grabItem.startAnchor.isConnected = false
  1004. this.grabItem.startAnchor.parent.disconnect('changePos', this.grabItem);
  1005. }
  1006. anc.isConnected = true;
  1007. this.grabItem.startAnchor = anc;
  1008. this.grabItem.anchor1ID = anc.id
  1009. this.grabItem.node1Id = anc.parent.id
  1010. anc.parent.connect('changePos', this.grabItem, this.grabItem.changePos)
  1011. }
  1012. if (this.grabItem.curIndex == this.grabItem.pointList.length - 1) {
  1013. if (this.grabItem.endAnchor) {
  1014. this.grabItem.endAnchor.isConnected = false
  1015. this.grabItem.endAnchor.parent.disconnect('changePos', this.grabItem);
  1016. }
  1017. anc.isConnected = true;
  1018. this.grabItem.endAnchor = anc;
  1019. this.grabItem.anchor2ID = anc.id
  1020. this.grabItem.node2Id = anc.parent.id
  1021. anc.parent.connect('changePos', this.grabItem, this.grabItem.changePos)
  1022. }
  1023. }
  1024. this.grabItem.onMouseUp(event)
  1025. return
  1026. } else {
  1027. if (this.grabItem.status == SItemStatus.Edit) {
  1028. if (this.grabItem.curIndex == 0) {
  1029. if (this.grabItem.startAnchor) {
  1030. this.grabItem.startAnchor.isConnected = false
  1031. this.grabItem.startAnchor.parent.disconnect('changePos', this.grabItem);
  1032. this.grabItem.startAnchor = null;
  1033. this.grabItem.anchor1ID = ''
  1034. this.grabItem.node1Id = ''
  1035. }
  1036. }
  1037. if (this.grabItem.curIndex == this.grabItem.pointList.length - 1) {
  1038. if (this.grabItem.endAnchor) {
  1039. this.grabItem.endAnchor.isConnected = false
  1040. this.grabItem.endAnchor.parent.disconnect('changePos', this.grabItem);
  1041. this.grabItem.endAnchor = null;
  1042. this.grabItem.anchor2ID = ''
  1043. this.grabItem.node2Id = ''
  1044. }
  1045. }
  1046. }
  1047. this.grabItem.onMouseUp(event)
  1048. return
  1049. }
  1050. }
  1051. }
  1052. /**
  1053. * 设置直线结束Item
  1054. *
  1055. */
  1056. setLineItem(event: SMouseEvent): void {
  1057. if (this.grabItem instanceof SLineMarkerItem) {
  1058. const item = this.clickIsItem(event);
  1059. // 鼠标点是否在某个item内
  1060. if (item) {
  1061. let scenePoint = item.boundingRect().center();
  1062. const p = item.mapToScene(scenePoint.x, scenePoint.y);
  1063. event.x = p.x;
  1064. event.y = p.y;
  1065. if (this.grabItem.status == SItemStatus.Create) {
  1066. // 点击在item内、创建状态且端点列表不为空时将直线结束端点和item绑定
  1067. if (this.grabItem.line.length) {
  1068. if (this.grabItem.startItem ?.id == item.id) {
  1069. this.grabItem.endItem = null;
  1070. } else {
  1071. this.grabItem.endItem = item;
  1072. this.grabItem.line[1] = new SPoint(event.x, event.y);
  1073. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1074. }
  1075. }
  1076. this.grabItem.onMouseDown(event);
  1077. return
  1078. } else if (this.grabItem.status == SItemStatus.Edit) {
  1079. // 点击在item内、编辑状态且点击的为结束端点时
  1080. if (this.grabItem.curIndex == 1) {
  1081. // 直线关联的起始item是直线结束端点所在的item时,不吸附在点击item中心并将直线关联的结束item置为null
  1082. if (this.grabItem.startItem ?.id == item.id) {
  1083. this.grabItem.endItem = null;
  1084. } else {// 反正吸附,关联
  1085. this.grabItem.endItem = item;
  1086. this.grabItem.line[1] = new SPoint(event.x, event.y);
  1087. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1088. }
  1089. } else if (this.grabItem.curIndex == 0) {
  1090. if (this.grabItem.endItem ?.id == item.id) {
  1091. this.grabItem.startItem = null;
  1092. } else {
  1093. this.grabItem.startItem = item;
  1094. this.grabItem.line[0] = new SPoint(event.x, event.y);
  1095. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1096. }
  1097. }
  1098. }
  1099. } else {
  1100. // 如果不在item内且点击的是直线的某个端点,将端点的关联item置为null
  1101. if (this.grabItem.line.length && this.grabItem.curIndex != -1) {
  1102. if (this.grabItem.curIndex == 1) {
  1103. this.grabItem.endItem = null;
  1104. } else if (this.grabItem.curIndex == 0) {
  1105. this.grabItem.startItem = null;
  1106. }
  1107. } else {
  1108. this.grabItem.onMouseDown(event);
  1109. return
  1110. }
  1111. }
  1112. // if (this.grabItem.status == SItemStatus.Create) {
  1113. // // 鼠标点是否在某个item内
  1114. // if (item) {
  1115. // let scenePoint = item.boundingRect().center();
  1116. // const p = item.mapToScene(scenePoint.x, scenePoint.y);
  1117. // event.x = p.x;
  1118. // event.y = p.y;
  1119. // if (this.grabItem.line.length && this.grabItem.curIndex == -1) {
  1120. // this.grabItem.endItem = item;
  1121. // this.grabItem.line[1] = new SPoint(event.x, event.y);
  1122. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1123. // }
  1124. // this.grabItem.onMouseDown(event);
  1125. // return
  1126. // } else {
  1127. // if (this.grabItem.line.length && this.grabItem.curIndex != -1) {
  1128. // if (this.grabItem.curIndex == 1) {
  1129. // this.grabItem.endItem = null;
  1130. // } else if (this.grabItem.curIndex == 0) {
  1131. // this.grabItem.startItem = null;
  1132. // }
  1133. // }
  1134. // }
  1135. // } else if (this.grabItem.status == SItemStatus.Edit) {
  1136. // if (this.grabItem.curIndex == 1) {
  1137. // this.grabItem.endItem = item;
  1138. // this.grabItem.line[1] = new SPoint(event.x, event.y);
  1139. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1140. // } else if (this.grabItem.curIndex == 0) {
  1141. // this.grabItem.startItem = item;
  1142. // this.grabItem.line[0] = new SPoint(event.x, event.y);
  1143. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1144. // }
  1145. // }
  1146. this.grabItem.onMouseUp(event);
  1147. }
  1148. }
  1149. /**
  1150. * 划线时点击位置是否是锚点
  1151. *
  1152. * @param event 事件
  1153. * @param len 限制距离
  1154. * @return 点击的锚点
  1155. * */
  1156. clickIsAnchor(event: SMouseEvent): SAnchorItem | null {
  1157. let minAnchor = null;
  1158. let len: number = -1;
  1159. this.Nodes.forEach(image => {
  1160. if (image.anchorList && image.anchorList.length) {
  1161. image.anchorList.forEach(anchor => {
  1162. let anchorPoint = anchor.mapToScene(0, 0);
  1163. let dis = SMathUtil.pointDistance(
  1164. event.x,
  1165. event.y,
  1166. anchorPoint.x,
  1167. anchorPoint.y
  1168. );
  1169. if (len < 0) {
  1170. len = anchor.sceneDis;
  1171. }
  1172. if (dis < len) {
  1173. minAnchor = anchor;
  1174. len = dis;
  1175. }
  1176. })
  1177. }
  1178. })
  1179. console.log('-----------------------')
  1180. console.log(minAnchor)
  1181. console.log('-----------------------')
  1182. return minAnchor;
  1183. }
  1184. /**
  1185. * 划线时点击位置是在文本,图片,,区域内
  1186. *
  1187. * @param event 事件
  1188. * @return 点击的item
  1189. * */
  1190. clickIsItem(event: SMouseEvent): SGraphItem | null {
  1191. let minIten = null;
  1192. let len: number = -1;
  1193. let itemList = this.Nodes.concat(this.Markers);
  1194. itemList.forEach(item => {
  1195. if (
  1196. item instanceof STextMarkerItem ||
  1197. item instanceof SImageMarkerItem ||
  1198. item instanceof SZoneLegendItem ||
  1199. item instanceof SFHFQZoneLegendItem ||
  1200. item instanceof SSCPZZoneLegendItem
  1201. ) {
  1202. let scenePoint = item.mapFromScene(event.x, event.y);
  1203. if (item.contains(scenePoint.x, scenePoint.y)) {
  1204. let dis = SMathUtil.pointDistance(
  1205. scenePoint.x,
  1206. scenePoint.y,
  1207. item.boundingRect().center().x,
  1208. item.boundingRect().center().y
  1209. );
  1210. if (len < 0) {
  1211. minIten = item;
  1212. len = dis;
  1213. }
  1214. if (dis < len) {
  1215. minIten = item;
  1216. len = dis;
  1217. }
  1218. }
  1219. }
  1220. })
  1221. console.log('-----------------------')
  1222. console.log(minIten)
  1223. console.log('-----------------------')
  1224. return minIten;
  1225. }
  1226. /**
  1227. * 点是否在吸附区域内
  1228. *
  1229. * @param p 要判断的点
  1230. * @param minX 空间区域
  1231. * @param minY 空间区域
  1232. * @param maxX 空间区域
  1233. * @param maxY 空间区域
  1234. */
  1235. static isPointInAbsorbArea(
  1236. p: SPoint,
  1237. minX: number,
  1238. maxX: number,
  1239. minY: number,
  1240. maxY: number
  1241. ): boolean {
  1242. let rect = new SRect(
  1243. minX - 1000,
  1244. minY - 1000,
  1245. maxX - minX + 2000,
  1246. maxY - minY + 2000
  1247. );
  1248. return rect.contains(p.x, p.y);
  1249. } // Function isPointInAbsorbArea()
  1250. /**
  1251. * 吸附空间
  1252. *
  1253. * @param event 鼠标事件对象
  1254. * @return boolean 是否找到吸附的对象
  1255. */
  1256. absorbSpace(event: SMouseEvent): boolean {
  1257. if (!this.highLight) {
  1258. return false;
  1259. }
  1260. let absorbLen = 1000;
  1261. if (this.view) {
  1262. absorbLen = 10 / this.view.scale;
  1263. }
  1264. let P = this.absorbSpacePoint(event, absorbLen);
  1265. if (P.Point) {
  1266. this.highLight.distance = P.MinDis;
  1267. this.highLight.point = new SPoint(P.Point.X, -P.Point.Y);
  1268. this.highLight.visible = true;
  1269. return true;
  1270. } else {
  1271. let L = this.absorbSpaceLine(event, absorbLen);
  1272. if (L.Line && L.Point) {
  1273. this.highLight.distance = L.MinDis;
  1274. this.highLight.point = L.Point;
  1275. this.highLight.line = L.Line;
  1276. this.highLight.visible = true;
  1277. return true;
  1278. }
  1279. return false;
  1280. }
  1281. } // Function absorbSpace()
  1282. /**
  1283. * 吸附空间点
  1284. *
  1285. * @param event 鼠标事件对象
  1286. * @param absorbLen 吸附距离
  1287. * @return MinDis 吸附的点
  1288. */
  1289. absorbSpacePoint(event: SMouseEvent, absorbLen: number): MinDis {
  1290. let minPointDis = Number.MAX_SAFE_INTEGER;
  1291. let Point;
  1292. this.spaceList.map((space): void => {
  1293. if (
  1294. EditScence.isPointInAbsorbArea(
  1295. new SPoint(event.x, event.y),
  1296. space.minX,
  1297. space.maxX,
  1298. space.minY,
  1299. space.maxY
  1300. )
  1301. ) {
  1302. space.data.OutLine.forEach((item): void => {
  1303. let minDis = SMathUtil.getMinDisPoint(
  1304. new SPoint(event.x, event.y),
  1305. item
  1306. );
  1307. if (
  1308. minDis &&
  1309. minDis.MinDis < absorbLen &&
  1310. minDis.MinDis < minPointDis
  1311. ) {
  1312. minPointDis = minDis.MinDis;
  1313. Point = minDis.Point;
  1314. }
  1315. });
  1316. }
  1317. });
  1318. return {
  1319. MinDis: minPointDis,
  1320. Point: Point
  1321. };
  1322. } // Function absorbSpacePoint()
  1323. /**
  1324. * 吸附空间线
  1325. *
  1326. * @param event 鼠标事件对象
  1327. * @param absorbLen 吸附距离
  1328. * @return PointToLine 吸附的线
  1329. */
  1330. absorbSpaceLine(event: SMouseEvent, absorbLen: number): PointToLine {
  1331. let minPointDis = Number.MAX_SAFE_INTEGER;
  1332. let Point, Line;
  1333. this.spaceList.forEach((space): void => {
  1334. if (
  1335. EditScence.isPointInAbsorbArea(
  1336. new SPoint(event.x, event.y),
  1337. space.minX,
  1338. space.maxX,
  1339. space.minY,
  1340. space.maxY
  1341. )
  1342. ) {
  1343. space.data.OutLine.forEach((item): void => {
  1344. let minDisLine = SMathUtil.getMinDisLine(
  1345. new SPoint(event.x, event.y),
  1346. item
  1347. );
  1348. if (
  1349. minDisLine &&
  1350. minDisLine.MinDis < absorbLen &&
  1351. minDisLine.MinDis < minPointDis
  1352. ) {
  1353. minPointDis = minDisLine.MinDis;
  1354. Point = minDisLine.Point;
  1355. Line = minDisLine.Line;
  1356. }
  1357. });
  1358. }
  1359. });
  1360. return {
  1361. MinDis: minPointDis,
  1362. Point: Point,
  1363. Line: Line
  1364. };
  1365. } // Function absorbSpaceLine()
  1366. /**
  1367. * 添加多个item命令
  1368. * @param focusItemList 鼠标事件对象
  1369. */
  1370. AddListCommand(focusItemList: any[]): void {
  1371. this.undoStack.push(new SGraphAddListCommand(this, focusItemList));
  1372. }
  1373. /**
  1374. * 选中状态方法
  1375. * @param item 鼠标事件对象
  1376. */
  1377. toggleItem(item: SGraphItem): void {
  1378. this.selectContainer.clear()
  1379. this.selectContainer.toggleItem(item)
  1380. }
  1381. }