EditScence.ts 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  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, Transparency, SPolygonItem, SRectSelectItem } 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. import { TimeSelect } from 'element-ui';
  25. import { STopologyParser } from '@/lib/parsers/STopologyParser';
  26. import { SCustomLegendItem } from '@/lib/items/SCustomLegendItem';
  27. /**
  28. * 在线绘图
  29. *
  30. * @author 韩耀龙
  31. */
  32. export class EditScence extends SGraphScene {
  33. undoStack = new SUndoStack();
  34. /** 判断是否为苹果电脑 */
  35. public isMac = /macintosh|mac os x/i.test(navigator.userAgent);
  36. /** 命令 1 绘制直线 */
  37. private cmd = 'choice';
  38. /** 获取当前状态 */
  39. get getCmd(): string {
  40. return this.cmd;
  41. }
  42. /** 编辑当前状态 */
  43. set setCmd(cmd: string) {
  44. if (cmd == 'choice') {
  45. this.grabItem = null;
  46. }
  47. this.cmd = cmd;
  48. if (this.focusItem) {
  49. // 取消操作
  50. this.focusItem.cancelOperate();
  51. this.focusItem = null;
  52. // this.selectContainer.clear()
  53. }
  54. if (this.view) {
  55. this.view.update();
  56. }
  57. };
  58. /** 绘制区域时 是否为点选 */
  59. isSelecting: boolean = true;
  60. /** 是否开启吸附 */
  61. isAbsorbing: boolean = false;
  62. /** 吸附展示item */
  63. highLight: HighlightItem | null = null;
  64. // /** 矩形选择区域 */
  65. // rectSelectItem: SRectSelectItem | null = null;
  66. // /** 框选 */
  67. // isRectSelection: number = 0;
  68. /** 当前选中焦点Item */
  69. focusItem: SGraphItem | null = null;
  70. /** 当前选中焦点ItemList */
  71. focusItemList: SGraphItem[] | null = null;
  72. /**图例节点 */
  73. Nodes: any = []; // 图例节点,所有与工程信息化相关的图例(图标类型与区域)
  74. /**图例节点 */ // 与工程信息无关的标识对象(增加文本注释,图上的图片说明)
  75. Markers: any = [];
  76. /** 管线对象 */
  77. Relations: any = [];
  78. _isEditStatus: Boolean = true; // 是否可编辑
  79. set isEditStatus(bol: Boolean): void {
  80. this._isEditStatus = bol;
  81. }
  82. get isEditStatus(): Boolean {
  83. return this._isEditStatus
  84. }
  85. //复制粘贴
  86. copyString = {
  87. Nodes: [],
  88. Markers: [],
  89. Relations: []
  90. };
  91. constructor() {
  92. super();
  93. // // 选择绑定选额item事件
  94. this.selectContainer.connect("listChange", this, this.listChange);
  95. ItemColor.spaceColor = new SColor("#f0f0f0")
  96. ItemColor.wallColor = new SColor("#d4d4d4")
  97. ItemColor.columnColor = new SColor("#d4d4d4")
  98. ItemColor.virtualWallColor = new SColor("#d4d4d4")
  99. ItemColor.selectColor = new SColor("#f0f0f0")
  100. ItemColor.spaceBorderColor = new SColor("#d4d4d4");
  101. console.log('isMac',this.isMac)
  102. }
  103. /** 绘制图例样式 */
  104. _legend: any | null = null;
  105. get getlegend(): any {
  106. return this._legend;
  107. };
  108. set setlegend(obj: any) {
  109. this._legend = obj;
  110. }
  111. /** fid=>item映射,由解析器存入 */
  112. fidToItem = {}
  113. /**
  114. * 监听变化
  115. * @param obj 变化后的对象
  116. */
  117. listChange(obj: any) {
  118. let itemType: string = 'equipment';
  119. this.focusItemList = obj.itemList;
  120. if (obj.itemList[0] instanceof STextMarkerItem) {
  121. itemType = 'baseText'
  122. } else if (obj.itemList[0] instanceof SImageMarkerItem) {
  123. itemType = 'baseImage'
  124. } else if (obj.itemList[0] instanceof SLineMarkerItem) {
  125. itemType = 'baseLine'
  126. } else if (obj.itemList[0] instanceof SZoneLegendItem) {
  127. itemType = 'Zone'
  128. } else if (obj.itemList[0] instanceof SFHFQZoneLegendItem) {
  129. itemType = 'Zone'
  130. } else if (obj.itemList[0] instanceof SSCPZZoneLegendItem) {
  131. itemType = 'Zone'
  132. } else if (obj.itemList[0] instanceof SCustomLegendItem) {
  133. itemType = 'Zone'
  134. } else if (obj.itemList[0] instanceof SImageLegendItem) {
  135. itemType = 'Image'
  136. } else if (obj.itemList[0] instanceof TipelineItem) {
  137. itemType = 'Line'
  138. } else if (obj.itemList[0] instanceof SSpaceItem) { // 点选
  139. this.clickToAddArea(obj.itemList[0]);
  140. return
  141. } else {
  142. itemType = ''
  143. };
  144. if (obj.itemList.length == 1) {
  145. // 获取聚焦item
  146. this.focusItem = obj.itemList[0]
  147. } else {
  148. this.focusItem = null
  149. }
  150. let msg = {
  151. itemList: obj.itemList,
  152. itemType,
  153. }
  154. this.emitChange(msg)
  155. }
  156. emitChange(msg: any) {
  157. }
  158. /**
  159. * 增加线段item
  160. */
  161. addLine(event: SMouseEvent): boolean {
  162. const clickItem = this.clickIsItem(event);
  163. if (clickItem) {
  164. let centerPoint = clickItem.boundingRect().center();
  165. const p = clickItem.mapToScene(centerPoint.x, centerPoint.y);
  166. event.x = p.x;
  167. event.y = p.y;
  168. }
  169. const data = {
  170. /** ID */
  171. ID: uuid(),
  172. /** 名称 */
  173. Name: '直线',
  174. /** 图标(Image),线类型(Line) */
  175. Type: "Line",
  176. /** 位置 */
  177. Pos: { X: 0, Y: 0 },
  178. /** 由应用自己定义 */
  179. Properties: {
  180. IconUrl: require("../../assets/images/t-line-hover.png"),
  181. Line: [{ X: event.x, Y: event.y }],
  182. LineWidth: 1,
  183. StrokeColor: "#bdc3c8"
  184. }
  185. }
  186. const item = new SLineMarkerItem(null, data);
  187. item.status = SItemStatus.Create;
  188. item.selectable = true;
  189. this.addItem(item);
  190. // this.Markers.push(item);
  191. item.connect("finishCreated", this, this.finishCreated);
  192. this.grabItem = item;
  193. this.focusItem = item;
  194. // 起始item点
  195. item.startItem = clickItem;
  196. if (clickItem) {
  197. clickItem.connect('onMove', item, item.changePos);
  198. }
  199. return true
  200. }
  201. /**
  202. * 增加折线item
  203. */
  204. addPolylineItem(event: SMouseEvent): boolean {
  205. const point = new SPoint(event.x, event.y)
  206. const item = new TipelineItem(null, [point]);
  207. //设置状态
  208. item.selectable = true;
  209. item.status = SItemStatus.Create;
  210. this.addItem(item);
  211. item.connect("finishCreated", this, this.finishCreated);
  212. this.grabItem = item;
  213. this.focusItem = item;
  214. return true
  215. }
  216. /**
  217. * 增加管道 lenged
  218. */
  219. addTipelineItem(event: SMouseEvent): boolean {
  220. const anc = this.clickIsAnchor(event);
  221. if (anc) {
  222. const p = anc.mapToScene(0, 0)
  223. anc.isConnected = true;
  224. event.x = p.x;
  225. event.y = p.y;
  226. }
  227. const LegendData: Relation = {
  228. ID: uuid(),
  229. Name: this._legend.Name,
  230. GraphElementId: this._legend.Id,
  231. PointList: [{ X: event.x, Y: event.y }],
  232. LineType: "Line",
  233. Properties: {
  234. IconUrl: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  235. LineDash: this._legend.LineDash,
  236. LineWidth: this._legend.LineWidth,
  237. Color: this._legend.Color,
  238. },
  239. }
  240. const item = new TipelineItem(null, LegendData);
  241. //设置状态
  242. item.selectable = true;
  243. item.status = SItemStatus.Create;
  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. return true
  257. }
  258. /**
  259. * 增加多边形item lenged
  260. */
  261. addPolygonItem(event: SMouseEvent): void {
  262. const SubType = this._legend.SubType ? this._legend.SubType : '';
  263. const LegendData: Legend = {
  264. ID: uuid(),
  265. Name: this._legend.Name,
  266. GraphElementType: this._legend.Type,
  267. Num: 1,
  268. GraphElementId: this._legend.Id,
  269. AttachObjectIds: [],
  270. Type: "Zone",
  271. Pos: { X: event.x, Y: event.y },
  272. OutLine: [{ X: event.x, Y: event.y }],
  273. SubType: SubType,
  274. Properties: {
  275. IconUrl: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  276. StrokeColor: this._legend.Color,
  277. FillColor: this._legend.FillColor,
  278. LineDash: this._legend.LineDash,
  279. LineWidth: this._legend.LineWidth,
  280. font: 14,
  281. color: "#1F2429",
  282. TextPos: { X: 0, Y: 0 },
  283. InfoTypeId: this._legend.InfoTypeId.length ? this._legend.InfoTypeId : [],
  284. InfoSystemId: this._legend.InfoSystemId ? this._legend.InfoSystemId : '',
  285. InfoLocal: this._legend.InfoLocal.length ? this._legend.InfoLocal : []
  286. },
  287. }
  288. let Polylines = null;
  289. if (SubType == "SCPZ") {
  290. Polylines = new SSCPZZoneLegendItem(null, LegendData);
  291. } else if (SubType == "FHFQ") {
  292. Polylines = new SFHFQZoneLegendItem(null, LegendData);
  293. } else if (SubType == "CUSTOM") {
  294. Polylines = new SCustomLegendItem(null, LegendData);
  295. } else {
  296. Polylines = new SZoneLegendItem(null, LegendData);
  297. }
  298. Polylines.selectable = true;
  299. //设置状态
  300. Polylines.status = SItemStatus.Create;
  301. // Polylines.moveable = true;
  302. this.addItem(Polylines);
  303. Polylines.connect("finishCreated", this, this.finishCreated);
  304. this.grabItem = Polylines;
  305. this.focusItem = Polylines;
  306. }
  307. /**
  308. * 点选创建区域
  309. */
  310. clickToAddArea(item: SSpaceItem): void {
  311. if (this.cmd != 'Zone') {
  312. return
  313. }
  314. if (this.isSelecting && this._legend) {
  315. //@ts-ignore
  316. item.isExtracted = true
  317. const SubType = this._legend.SubType ? this._legend.SubType : '';
  318. const LegendData: Legend = {
  319. ID: uuid(),
  320. Name: this._legend.Name,
  321. GraphElementType: this._legend.Type,
  322. Num: 1,
  323. GraphElementId: this._legend.Id,
  324. AttachObjectIds: [],
  325. Type: "Zone",
  326. Pos: { X: item.x, Y: item.y },
  327. OutLine: item.pointArr[0],
  328. SubType: SubType,
  329. Properties: {
  330. IconUrl: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  331. StrokeColor: this._legend.Color,
  332. FillColor: this._legend.FillColor,
  333. LineDash: this._legend.LineDash,
  334. LineWidth: this._legend.LineWidth,
  335. font: 14,
  336. color: "#1F2429",
  337. FID: item.data.SourceId,
  338. TextPos: { X: item.data.Location.Points[0].X, Y: -item.data.Location.Points[0].Y },
  339. InfoTypeId: this._legend.InfoTypeId.length ? this._legend.InfoTypeId : [],
  340. InfoSystemId: this._legend.InfoSystemId ? this._legend.InfoSystemId : '',
  341. InfoLocal: this._legend.InfoLocal.length ? this._legend.InfoLocal : []
  342. },
  343. }
  344. let Polylines = null;
  345. if (SubType == "SCPZ") {
  346. Polylines = new SSCPZZoneLegendItem(null, LegendData);
  347. } else if (SubType == "FHFQ") {
  348. Polylines = new SFHFQZoneLegendItem(null, LegendData);
  349. } else {
  350. Polylines = new SZoneLegendItem(null, LegendData);
  351. }
  352. Polylines.selectable = true;
  353. //设置状态
  354. Polylines.status = SItemStatus.Normal;
  355. this.addItem(Polylines);
  356. // this.Nodes.push(Polylines);
  357. this.finishCreated(Polylines)
  358. this.focusItem = Polylines;
  359. this.scenceUpdate(this);
  360. }
  361. }
  362. /**
  363. * 增加图片Item mark
  364. */
  365. addImgItem(event: SMouseEvent) {
  366. const data = {
  367. /** ID */
  368. ID: uuid(),
  369. /** 名称 */
  370. Name: '图片',
  371. Num: 1,
  372. /** 图标(Image),线类型(Line) */
  373. Type: "Image",
  374. /** 位置 */
  375. Pos: { X: event.x, Y: event.y },
  376. /** 由应用自己定义 */
  377. Properties: {
  378. IconUrl: require(`../../assets/images/t-img-hover.png`),
  379. StrokeColor: "#c0ccda",
  380. Url: '',
  381. }
  382. }
  383. const item = new SImageMarkerItem(null, data);
  384. item.selectable = true;
  385. item.moveable = true;
  386. this.addItem(item);
  387. this.Markers.push(item);
  388. this.grabItem == null;
  389. this.focusItem = item;
  390. this.finishCreated(item);
  391. this.scenceUpdate(this);
  392. }
  393. /**
  394. * 增加文字item
  395. */
  396. addTextItem(event: SMouseEvent): void {
  397. const data = {
  398. /** ID */
  399. ID: uuid(),
  400. /** 名称 */
  401. Name: '文本',
  402. /** 图标 */
  403. Type: "Text",
  404. /** 位置 */
  405. Pos: { X: event.x, Y: event.y },
  406. /** 由应用自己定义 */
  407. Properties: {
  408. IconUrl: require(`../../assets/images/t-text-hover.png`),
  409. Text: '请在右侧属性栏输入文字!',
  410. Color: "#646c73",
  411. Font: 14,
  412. BackgroundColor: "#f7f9facc"
  413. }
  414. }
  415. const item = new STextMarkerItem(null, data);
  416. item.moveTo(event.x, event.y);
  417. item.selectable = true;
  418. item.moveable = true;
  419. this.addItem(item);
  420. this.Markers.push(item);
  421. this.grabItem = null;
  422. this.focusItem = item;
  423. this.cmd = 'choice';
  424. this.finishCreated(item);
  425. this.scenceUpdate(this);
  426. }
  427. /**
  428. * 增加图标lenged图标
  429. */
  430. addIconItem(event: SMouseEvent): void {
  431. //获取信息工程化相关参数
  432. const LegendData: Legend = {
  433. ID: uuid(),
  434. Name: "",
  435. GraphElementType: this._legend.Type,
  436. Num: 1,
  437. GraphElementId: this._legend.Id,
  438. AttachObjectIds: [],
  439. Pos: { X: event.x, Y: event.y },
  440. Scale: { X: 1, Y: 1, Z: 1 }, // 缩放
  441. Rolate: { X: 0, Y: 0, Z: 0 },
  442. Size: { Width: 0, Height: 0 }, // 大小
  443. Type: this._legend.Type,
  444. Properties: {
  445. IconUrl: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  446. Url: '/serve/topology-wanda/Picture/query/' + this._legend.Url,
  447. Num: 1, // 此num与信息工程化得num无关
  448. Size: {
  449. Width: this._legend.Size?this._legend.Size.Width?this._legend.Size.Width:32:32, //icon 的宽
  450. Height: this._legend.Size?this._legend.Size.Height?this._legend.Size.Height:32:32, //icon 的高
  451. },
  452. font: 16, //font
  453. color: "#1F2429", //字体颜色
  454. FrameColor: this._legend.FrameColor,
  455. GraphCategoryId: this._legend.GraphCategoryId,
  456. InfoSystemId: this._legend.InfoSystemId ? this._legend.InfoSystemId : '',
  457. InfoTypeId: this._legend.InfoTypeId.length ? this._legend.InfoTypeId : [],// 铺位可视化Typeid(用于编辑工程信息化时默认问题)
  458. InfoLocal: this._legend.InfoLocal.length ? this._legend.InfoLocal : []
  459. },
  460. }
  461. const cmd = this.cmd;
  462. const item = new SImageLegendItem(null, LegendData);
  463. this.cmd = 'choice';
  464. item.selectable = true;
  465. item.moveable = true;
  466. this.addItem(item);
  467. this.Nodes.push(item);
  468. this.grabItem = null;
  469. this.focusItem = item;
  470. this.finishCreated(item);
  471. this.scenceUpdate(this);
  472. if (event.ctrlKey) {
  473. this.cmd = cmd;
  474. }
  475. }
  476. /**
  477. * 更改item对应属性
  478. */
  479. editItemStatus(): void {
  480. }
  481. /**
  482. * 更改文本对应属性
  483. * @param str string 文字内容
  484. */
  485. updatedText(str: string): void {
  486. if (this.focusItem) {
  487. const oldMsg = this.focusItem.text;
  488. const newMsg = str;
  489. this.focusItem.text = str;
  490. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "text", oldMsg, newMsg));
  491. this.scenceUpdate(this);
  492. }
  493. }
  494. /**
  495. * 更改文本fontSize属性
  496. * @param size number 文字大小
  497. */
  498. updatedFontSize(size: number): void {
  499. if (this.focusItem) {
  500. let old = new SFont(this.focusItem.font);
  501. let font = new SFont(this.focusItem.font);
  502. font.size = size;
  503. this.focusItem.font = font;
  504. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "font", old, font));
  505. }
  506. }
  507. /**
  508. * 更改线宽属性
  509. * @param lineWidth number 线宽大小
  510. */
  511. updatedLineWidth(lineWidth: number): void {
  512. if (this.focusItem) {
  513. const oldMsg = this.focusItem.lineWidth;
  514. const newMsg = lineWidth;
  515. this.focusItem.lineWidth = lineWidth;
  516. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "lineWidth", oldMsg, newMsg));
  517. }
  518. }
  519. /**
  520. * 更改文本颜色属性
  521. * @param str string 颜色
  522. */
  523. updatedFontColor(color: string): void {
  524. if (this.focusItem) {
  525. const oldMsg = this.focusItem.color;
  526. const newMsg = new SColor(color);
  527. this.focusItem.color = newMsg;
  528. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "color", oldMsg, newMsg));
  529. }
  530. }
  531. /**
  532. * 更改border颜色
  533. * @param color string 颜色
  534. */
  535. updatedBorderColor(color: string): void {
  536. if (this.focusItem) {
  537. const oldMsg = this.focusItem.strokeColor;
  538. const newMsg = new SColor(color);
  539. this.focusItem.strokeColor = newMsg;
  540. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "strokeColor", oldMsg, newMsg));
  541. }
  542. }
  543. /**
  544. * 更改item宽
  545. * @param width number 颜色
  546. */
  547. updatedWidth(width: number): void {
  548. if (this.focusItem) {
  549. let oldMsg = null;
  550. const newMsg = width;
  551. if (this.focusItem.data && this.focusItem.data.GraphElementType && this.focusItem.data.GraphElementType == "Image") {
  552. oldMsg = this.focusItem.sWidth
  553. this.focusItem.sWidth = width;
  554. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "sWidth", oldMsg, newMsg));
  555. } else {
  556. oldMsg = this.focusItem.width
  557. this.focusItem.width = width;
  558. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "width", oldMsg, newMsg));
  559. }
  560. }
  561. }
  562. /**
  563. * 更改item高
  564. * @param height number 颜色
  565. */
  566. updatedHeight(height: number): void {
  567. if (this.focusItem) {
  568. let oldMsg = null;
  569. const newMsg = height;
  570. if (this.focusItem.data && this.focusItem.data.GraphElementType && this.focusItem.data.GraphElementType == "Image") {
  571. oldMsg = this.focusItem.sHeight;
  572. this.focusItem.sHeight = height;
  573. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "sHeight", oldMsg, newMsg));
  574. } else {
  575. oldMsg = this.focusItem.height;
  576. this.focusItem.height = height;
  577. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "height", oldMsg, newMsg));
  578. }
  579. }
  580. }
  581. /**
  582. * 更改item坐标
  583. * @param x number x x坐标
  584. * @param y number y y坐标
  585. */
  586. updatedPosition(x: number, y: number): void {
  587. if (this.focusItem) {
  588. let p = this.focusItem.mapFromScene(x, y)
  589. // newx - oldx = newleft - oldleft
  590. // 要求的值(新的x坐标) - 旧的x坐标 = 新的左边界(用户输入的值) - 旧的左边界
  591. this.focusItem.x = (p.x - this.focusItem.boundingRect().left) * this.focusItem.inverseScale + this.focusItem.x;
  592. this.focusItem.y = (p.y - this.focusItem.boundingRect().top) * this.focusItem.inverseScale + this.focusItem.y;
  593. if (this.focusItem instanceof SPolylineItem || this.focusItem instanceof SPolygonItem || this.focusItem instanceof SLineItem) {
  594. this.focusItem.moveToOrigin(this.focusItem.x, this.focusItem.y)
  595. }
  596. }
  597. }
  598. /**
  599. * 更改item 背景色坐标
  600. * @param color string 颜色color
  601. */
  602. updatedbackColor(color: string): void {
  603. if (this.focusItem) {
  604. const newMsg = new SColor(color);
  605. const oldMsg = this.focusItem.backgroundColor;
  606. this.focusItem.backgroundColor = new SColor(color);
  607. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "backgroundColor", oldMsg, newMsg));
  608. }
  609. }
  610. /**
  611. * 更改item Url
  612. * @param url string 图片key
  613. */
  614. upadataImageUrl(url: string): void {
  615. if (this.focusItem) {
  616. const newMsg = '/serve/topology-wanda/Picture/query/' + url;
  617. const oldMsg = this.focusItem.url;
  618. this.focusItem.url = newMsg;
  619. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "url", oldMsg, newMsg));
  620. }
  621. }
  622. /**
  623. * 更改item border
  624. * @param val string border类型
  625. */
  626. upadataBorder(val: string): void {
  627. if (this.focusItem) {
  628. let borderStyle = null;
  629. if (val == 'dashed') {
  630. borderStyle = SLineStyle.Dashed;
  631. } else if (val == 'dotted') {
  632. borderStyle = SLineStyle.Dotted;
  633. } else if (val == 'solid') {
  634. borderStyle = SLineStyle.Solid;
  635. }
  636. const newMsg = borderStyle;
  637. const oldMsg = this.focusItem.lineStyle;
  638. this.focusItem.lineStyle = borderStyle;
  639. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "lineStyle", oldMsg, newMsg));
  640. }
  641. }
  642. /**
  643. * 更改item 名称
  644. * @param val string border类型
  645. */
  646. upadataLengedName(val: string): void {
  647. if (this.focusItem && this.focusItem.data) {
  648. const newMsg = val;
  649. const oldMsg = this.focusItem.text;
  650. this.focusItem.text = val;
  651. this.focusItem.name = val;
  652. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "text", oldMsg, newMsg));
  653. this.scenceUpdate(this);
  654. }
  655. }
  656. /**
  657. * 更改item Num数量
  658. * @param num number item数量 (只对icon设备类)
  659. */
  660. upadatImageNum(num: number): void {
  661. if (this.focusItem && this.focusItem.num) {
  662. const newMsg = num;
  663. const oldMsg = this.focusItem.num;
  664. this.focusItem.num = num;
  665. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "num", oldMsg, newMsg));
  666. }
  667. }
  668. /**
  669. * 更改item Num数量
  670. * @param num number item数量 (只对icon设备类)
  671. */
  672. upadatfillColor(fillColor: string): void {
  673. if (this.focusItem && this.focusItem.fillColor) {
  674. let fillColorT;
  675. if (fillColor.length == 7) {
  676. fillColorT = fillColor + Transparency[15];
  677. if (this.focusItem instanceof SSCPZZoneLegendItem || this.focusItem instanceof SFHFQZoneLegendItem) {
  678. const sc = new SColor(this.focusItem.fillColor);
  679. const alp = ((sc.alpha/255)*100).toFixed()
  680. fillColorT = fillColor + Transparency[alp];
  681. // fillColorT = fillColor + Transparency[80];
  682. }
  683. } else {
  684. fillColorT = fillColor;
  685. }
  686. const newMsg = new SColor(fillColorT);
  687. const oldMsg = this.focusItem.fillColor;
  688. this.focusItem.fillColor = new SColor(fillColorT);
  689. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "fillColor", oldMsg, newMsg));
  690. }
  691. }
  692. /**
  693. * 更改图例说
  694. * @param num number
  695. */
  696. upadatitemExplain(ItemExplain: string): void {
  697. if (this.focusItem) {
  698. this.focusItem.data.Properties.ItemExplain = ItemExplain;
  699. }
  700. }
  701. /**
  702. * 更新工程信息化的相关数据
  703. * @param AttachObjectIds Array
  704. */
  705. upadatAttachObjectIds(AttachObjectIds: [], flag: boolean): void {
  706. if (this.focusItem) {
  707. this.focusItem.data.AttachObjectIds = AttachObjectIds;
  708. // 重新选中focusitem
  709. const item = this.focusItem;
  710. this.selectContainer.clear();
  711. this.selectContainer.toggleItem(item);
  712. if (
  713. item instanceof SImageLegendItem ||
  714. item instanceof SZoneLegendItem ||
  715. item instanceof SSCPZZoneLegendItem ||
  716. item instanceof SFHFQZoneLegendItem
  717. ) {
  718. let arr = item.data.AttachObjectIds;
  719. if (arr && arr.length && arr[arr.length - 1].name && flag) {
  720. let name = item.name;
  721. if (name) {
  722. item.name = name + `\n${arr[arr.length - 1].name}`;
  723. item.text = name + `\n${arr[arr.length - 1].name}`;
  724. } else {
  725. item.name = arr[arr.length - 1].name;
  726. item.text = arr[arr.length - 1].name;
  727. }
  728. }
  729. // 绑定工程信息化数据后设置状态
  730. if (item.data.AttachObjectIds && item.data.AttachObjectIds.length) {
  731. item.isActive = true;
  732. } else {
  733. item.isActive = false;
  734. }
  735. }
  736. }
  737. }
  738. /**
  739. * 自定义多边形修改背景色
  740. */
  741. updateCustomBgColor(val: string):void{
  742. if (this.focusItem) {
  743. const newMsg = new SColor(val);
  744. const oldMsg = this.focusItem.fillColor;
  745. this.focusItem.fillColor = new SColor(val)
  746. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "fillColor", oldMsg, newMsg));
  747. }
  748. }
  749. /**
  750. * 自定义多边形修改边框色
  751. */
  752. updateCustomBdColor(val: string):void{
  753. if (this.focusItem) {
  754. const newMsg = new SColor(val);
  755. const oldMsg = this.focusItem.strokeColor;
  756. this.focusItem.strokeColor = new SColor(val)
  757. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "strokeColor", oldMsg, newMsg));
  758. }
  759. }
  760. /**
  761. * 删除指定item
  762. */
  763. deleiteItem(): void {
  764. if (this.focusItem) {
  765. if ((this.focusItem instanceof SZoneLegendItem ||
  766. this.focusItem instanceof SSCPZZoneLegendItem ||
  767. this.focusItem instanceof SFHFQZoneLegendItem ||
  768. this.focusItem instanceof TipelineItem) &&
  769. this.focusItem.curIndex != -1
  770. ) {
  771. this.focusItem.deletePoint(this.focusItem.curIndex);
  772. } else {
  773. this.undoStack.push(new SGraphDeleteCommand(this, this.focusItem));
  774. this.removeItem(this.focusItem);
  775. let a = -1
  776. this.Nodes.forEach((item: any, index: number) => {
  777. if (item.id == this.focusItem.id) {
  778. a = index
  779. }
  780. });
  781. if (a > -1) {
  782. this.Nodes.splice(a, 1);
  783. }
  784. let b = -1;
  785. this.Markers.forEach((item: any, index: number) => {
  786. if (item.id == this.focusItem.id) {
  787. b = index
  788. }
  789. });
  790. if (b > -1) {
  791. this.Markers.splice(b, 1);
  792. }
  793. let c = -1;
  794. this.Relations.forEach((item: any, index: number) => {
  795. if (item.id == this.focusItem.id) {
  796. c = index
  797. }
  798. });
  799. if (c > -1) {
  800. this.Relations.splice(c, 1);
  801. }
  802. this.grabItem = null;
  803. this.focusItem = null;
  804. if (this.view) {
  805. this.view.update();
  806. }
  807. this.scenceUpdate(this);
  808. }
  809. } else {
  810. //批量删除
  811. if (!this.focusItemList) {
  812. return
  813. }
  814. this.undoStack.push(new SGraphDeleteListCommand(this, this.focusItemList))
  815. this.focusItemList.forEach((focusItem) => {
  816. this.removeItem(focusItem);
  817. let a = -1
  818. this.Nodes.forEach((item: any, index: number) => {
  819. if (item.id == focusItem.id) {
  820. a = index
  821. }
  822. });
  823. if (a > -1) {
  824. this.Nodes.splice(a, 1);
  825. }
  826. let b = -1;
  827. this.Markers.forEach((item: any, index: number) => {
  828. if (item.id == focusItem.id) {
  829. b = index
  830. }
  831. });
  832. if (b > -1) {
  833. this.Markers.splice(b, 1);
  834. }
  835. let c = -1;
  836. this.Relations.forEach((item: any, index: number) => {
  837. if (item.id == focusItem.id) {
  838. c = index
  839. }
  840. });
  841. if (c > -1) {
  842. this.Relations.splice(c, 1);
  843. }
  844. });
  845. this.focusItemList = [];
  846. this.grabItem = null;
  847. this.focusItem = null;
  848. if (this.view) {
  849. this.view.update();
  850. }
  851. this.scenceUpdate(this);
  852. }
  853. }
  854. scenceUpdate(scence: any) {
  855. }
  856. /**
  857. * 对齐指定item
  858. * @param v
  859. */
  860. changeAlignItem(v: any): void {
  861. this.selectContainer.layout(v);
  862. }
  863. /**
  864. * 图层排序
  865. * @param v
  866. */
  867. changeOrderItem(v: any): void {
  868. this.selectContainer.setOrder(v);
  869. }
  870. /**
  871. * 提取item
  872. */
  873. extractItem(): void {
  874. console.log(this)
  875. }
  876. /**
  877. * 保存数据
  878. */
  879. saveMsgItem(): any {
  880. const Nodes: any = [];
  881. const Markers: any = [];
  882. const Relations: any = [];
  883. this.Nodes.forEach(e => {
  884. Nodes.push(e.toData())
  885. });
  886. this.Markers.forEach(e => {
  887. Markers.push(e.toData())
  888. });
  889. this.Relations.forEach(e => {
  890. Relations.push(e.toData())
  891. });
  892. let element = {
  893. Nodes, Markers, Relations
  894. }
  895. return element
  896. }
  897. /**
  898. * 执行取消操作
  899. */
  900. redo(): void {
  901. if (this.grabItem && this.grabItem.redo) {
  902. this.grabItem.redo()
  903. } else {
  904. this.undoStack.redo();
  905. this.scenceUpdate(this);
  906. }
  907. }
  908. /**
  909. * 执行重做操作执行
  910. */
  911. undo(): void {
  912. if (this.grabItem && this.grabItem.undo) {
  913. this.grabItem.undo()
  914. } else {
  915. this.undoStack.undo();
  916. this.scenceUpdate(this);
  917. }
  918. }
  919. /**
  920. * 完成事件创建的回调函数
  921. */
  922. finishCreated(item: any) {
  923. // let arrList = []
  924. if (this.cmd == 'baseLine') {
  925. // arrList = this.Markers;
  926. // 对数组遍历防止相同得id注入
  927. let canPush = true; //是否可注入
  928. this.Markers.forEach((arrItem: any) => {
  929. if (arrItem.id == item.id) {
  930. canPush = false
  931. }
  932. })
  933. if (canPush) {
  934. this.Markers.push(item);
  935. this.undoStack.push(new SGraphAddCommand(this, item));
  936. }
  937. }
  938. this.cmd = 'choice';
  939. this.selectContainer.clear()
  940. this.selectContainer.toggleItem(item)
  941. setTimeout(() => {
  942. this.focusItem = item;
  943. });
  944. if (item instanceof SZoneLegendItem || item instanceof SFHFQZoneLegendItem || item instanceof SSCPZZoneLegendItem || item instanceof SCustomLegendItem) {
  945. let canPush = true; //是否可注入
  946. this.Nodes.forEach((arrItem: any) => {
  947. if (arrItem.id == item.id) {
  948. canPush = false
  949. }
  950. })
  951. if (canPush) {
  952. this.Nodes.push(item); //完成后,方可扔到Node节点
  953. this.undoStack.push(new SGraphAddCommand(this, item));
  954. }
  955. }
  956. // 管道完成后方可保存
  957. if (item instanceof TipelineItem) {
  958. let canPush = true; //是否可注入
  959. this.Relations.forEach((arrItem: any) => {
  960. if (arrItem.id == item.id) {
  961. canPush = false
  962. }
  963. })
  964. if (canPush) {
  965. this.Relations.push(item);
  966. this.undoStack.push(new SGraphAddCommand(this, item));
  967. }
  968. }
  969. this.scenceUpdate(this);
  970. }
  971. ////////////////////////
  972. // 以下为鼠标键盘操作事件
  973. onMouseDown(event: SMouseEvent): any {
  974. if (!this.isEditStatus) {
  975. return true
  976. }
  977. // 判断是否开启吸附,并且有吸附的点
  978. if (
  979. this.isAbsorbing &&
  980. this.highLight &&
  981. this.highLight.visible
  982. ) {
  983. event.x = this.highLight.point.x;
  984. event.y = this.highLight.point.y;
  985. }
  986. if (this.grabItem) {
  987. if (this.grabItem instanceof TipelineItem) {
  988. this.setTipeEndanchor(event)
  989. return true;
  990. } else if (this.grabItem instanceof SLineMarkerItem && this.grabItem.status == SItemStatus.Create) {
  991. this.setLineItem(event)
  992. return true;
  993. }
  994. return this.grabItem.onMouseDown(event);
  995. }
  996. switch (this.cmd) {
  997. // case 'choice':
  998. // if (!super.onMouseDown(event)){
  999. // this.addRectSelect(event);
  1000. // }
  1001. // break
  1002. case 'baseLine':
  1003. this.addLine(event);
  1004. break;
  1005. case 'baseText':
  1006. this.addTextItem(event);
  1007. break;
  1008. case 'baseImage':
  1009. this.addImgItem(event)
  1010. break;
  1011. case 'Zone':
  1012. if (!this.isSelecting) {
  1013. this.addPolygonItem(event);
  1014. } else {
  1015. // 点选创建区域
  1016. return super.onMouseDown(event)
  1017. }
  1018. break;
  1019. case 'Image':
  1020. this.addIconItem(event);
  1021. break;
  1022. case 'Line':
  1023. this.addTipelineItem(event);
  1024. break;
  1025. default:
  1026. return super.onMouseDown(event);
  1027. }
  1028. }
  1029. onMouseMove(event: SMouseEvent): boolean {
  1030. if (!this.isEditStatus) {
  1031. return true
  1032. }
  1033. if (this.isAbsorbing) {
  1034. if (!this.highLight) {
  1035. this.highLight = new HighlightItem(null);
  1036. this.addItem(this.highLight);
  1037. }
  1038. this.highLight.visible = false;
  1039. this.absorbSpace(event);
  1040. }
  1041. if (this.grabItem){
  1042. if (this.grabItem instanceof TipelineItem) {
  1043. const anc = this.clickIsAnchor(event);
  1044. if (anc) {
  1045. const p = anc.mapToScene(0, 0)
  1046. event.x = p.x;
  1047. event.y = p.y;
  1048. return this.grabItem.onMouseMove(event);
  1049. }
  1050. } else if (this.grabItem instanceof SRectSelectItem) {
  1051. return this.grabItem.onMouseMove(event);
  1052. }
  1053. }
  1054. return super.onMouseMove(event)
  1055. }
  1056. onMouseUp(event: SMouseEvent): boolean {
  1057. if (!this.isEditStatus) {
  1058. return true
  1059. }
  1060. if (this.grabItem) {
  1061. if (this.grabItem instanceof SLineMarkerItem && this.grabItem.status == SItemStatus.Edit) {
  1062. this.setLineItem(event)
  1063. return true;
  1064. } else if (this.grabItem instanceof TipelineItem) {
  1065. this.updateTipeAnc(event);
  1066. return true;
  1067. } else if (this.grabItem instanceof SRectSelectItem) {
  1068. this.groupSelect();
  1069. this.removeItem(this.grabItem);
  1070. this.grabItem = null;
  1071. if (this.view) {
  1072. this.view.update()
  1073. }
  1074. return true;
  1075. }
  1076. return this.grabItem.onMouseUp(event);
  1077. }
  1078. return super.onMouseUp(event)
  1079. }
  1080. /**
  1081. * 键盘事件
  1082. *
  1083. * @param event 事件参数
  1084. * @return boolean
  1085. */
  1086. onKeyDown(event: KeyboardEvent): any {
  1087. if (!this.isEditStatus) {
  1088. return true
  1089. }
  1090. if (this.grabItem) {
  1091. this.grabItem.onKeyDown(event);
  1092. if (event.code == "Escape") {
  1093. const item = this.grabItem;
  1094. this.grabItem = null
  1095. this.removeItem(item);
  1096. if (this.view) {
  1097. this.view.update()
  1098. }
  1099. this.setCmd = 'choice'
  1100. }
  1101. }
  1102. // 删除键功能
  1103. if (event.code == 'Delete') {
  1104. this.deleiteItem()
  1105. }
  1106. // 删除键功能--兼容苹果mac
  1107. if (event.code == 'Backspace' && this.isMac){
  1108. this.deleiteItem()
  1109. }
  1110. // 复制粘贴
  1111. if (event.ctrlKey && !event.repeat) {
  1112. if (event.code == 'KeyC') {
  1113. console.log('ctrl c')
  1114. this.copy()
  1115. } else if (event.code == 'KeyV') {
  1116. console.log('ctrl v')
  1117. this.paste()
  1118. }
  1119. }
  1120. return false
  1121. }
  1122. /**
  1123. * 复制
  1124. *
  1125. */
  1126. copy(){
  1127. if (this.selectContainer.itemList.length) {
  1128. this.copyString = {
  1129. Nodes: [],
  1130. Markers: [],
  1131. Relations: []
  1132. };
  1133. this.selectContainer.itemList.forEach(t => {
  1134. const type = this.itemToType(t);
  1135. if (type) {
  1136. const data = JSON.parse(JSON.stringify(t.toData()))
  1137. data.ID = ''
  1138. if (data.Type == 'Image') {
  1139. data.AnchorList = []
  1140. }
  1141. this.copyString[type].push(data)
  1142. }
  1143. })
  1144. // 生成复制字符串
  1145. console.log(this.copyString)
  1146. return
  1147. // 获取input dom
  1148. const input = document.createElement('input');
  1149. input.setAttribute('id', 'COPYINPUT')
  1150. input.value = JSON.stringify(this.copyString)
  1151. document.body.appendChild(input);
  1152. input.select()
  1153. document.execCommand('copy');
  1154. input.style.display='none';
  1155. console.log(input.value, Date.now());
  1156. document.body.removeChild(input)
  1157. }
  1158. }
  1159. /**
  1160. * 粘贴
  1161. *
  1162. */
  1163. paste(){
  1164. const parserData = new STopologyParser(null);
  1165. // 需要深拷贝
  1166. parserData.parseData(JSON.parse(JSON.stringify(this.copyString)))
  1167. // 不需要复制区域
  1168. // parserData.zoneLegendList.forEach(t => {
  1169. // if (t instanceof SCustomLegendItem) {
  1170. // if (this.view) {
  1171. // t.pos.x += 10 / this.view.scale
  1172. // t.pos.y += 10 / this.view.scale
  1173. // }
  1174. // this.addItem(t)
  1175. // this.Nodes.push(t);
  1176. // graphItemList.push(t)
  1177. // }
  1178. // // 加到node
  1179. // // 加命令
  1180. // })
  1181. const graphItemList = [];
  1182. parserData.imageLegendList.forEach(t => {
  1183. if (this.view) {
  1184. t.pos.x += 10 / this.view.scale
  1185. t.pos.y += 10 / this.view.scale
  1186. }
  1187. t.moveable = true;
  1188. this.addItem(t)
  1189. this.Nodes.push(t);
  1190. graphItemList.push(t)
  1191. })
  1192. parserData.imageMarkerList.forEach(t => {
  1193. if (this.view) {
  1194. t.pos.x += 10 / this.view.scale
  1195. t.pos.y += 10 / this.view.scale
  1196. }
  1197. t.moveable = true;
  1198. this.addItem(t)
  1199. this.Markers.push(t);
  1200. graphItemList.push(t)
  1201. })
  1202. parserData.lineMarkerList.forEach(t => {
  1203. if (this.view) {
  1204. t.pos.x += 10 / this.view.scale
  1205. t.pos.y += 10 / this.view.scale
  1206. }
  1207. t.moveable = true;
  1208. this.addItem(t)
  1209. this.Markers.push(t);
  1210. graphItemList.push(t)
  1211. })
  1212. parserData.textMarkerList.forEach(t => {
  1213. if (this.view) {
  1214. t.pos.x += 10 / this.view.scale
  1215. t.pos.y += 10 / this.view.scale
  1216. }
  1217. t.moveable = true;
  1218. this.addItem(t)
  1219. this.Markers.push(t);
  1220. graphItemList.push(t)
  1221. })
  1222. parserData.relationList.forEach(t => {
  1223. if (this.view) {
  1224. t.pos.x += 10 / this.view.scale
  1225. t.pos.y += 10 / this.view.scale
  1226. t.moveToOrigin(t.pos.x, t.pos.y)
  1227. }
  1228. t.moveable = true;
  1229. this.addItem(t)
  1230. this.Relations.push(t);
  1231. graphItemList.push(t)
  1232. })
  1233. this.scenceUpdate(this);
  1234. if (graphItemList.length) {
  1235. this.AddListCommand(graphItemList)
  1236. }
  1237. }
  1238. /**
  1239. * 跨页面粘贴
  1240. *
  1241. */
  1242. crossPagePaste(crossPageString: string){
  1243. try {
  1244. console.log(crossPageString);
  1245. const pageObj = JSON.parse(crossPageString)
  1246. const parserData = new STopologyParser(null);
  1247. // 需要深拷贝
  1248. parserData.parseData(JSON.parse(JSON.stringify(pageObj)))
  1249. // 不需要复制区域
  1250. // parserData.zoneLegendList.forEach(t => {
  1251. // if (t instanceof SCustomLegendItem) {
  1252. // if (this.view) {
  1253. // t.pos.x += 10 / this.view.scale
  1254. // t.pos.y += 10 / this.view.scale
  1255. // }
  1256. // this.addItem(t)
  1257. // this.Nodes.push(t);
  1258. // graphItemList.push(t)
  1259. // }
  1260. // // 加到node
  1261. // // 加命令
  1262. // })
  1263. const graphItemList = [];
  1264. parserData.imageLegendList.forEach(t => {
  1265. if (this.view) {
  1266. t.pos.x += 10 / this.view.scale
  1267. t.pos.y += 10 / this.view.scale
  1268. }
  1269. t.moveable = true;
  1270. this.addItem(t)
  1271. this.Nodes.push(t);
  1272. graphItemList.push(t)
  1273. })
  1274. parserData.imageMarkerList.forEach(t => {
  1275. if (this.view) {
  1276. t.pos.x += 10 / this.view.scale
  1277. t.pos.y += 10 / this.view.scale
  1278. }
  1279. t.moveable = true;
  1280. this.addItem(t)
  1281. this.Markers.push(t);
  1282. graphItemList.push(t)
  1283. })
  1284. parserData.lineMarkerList.forEach(t => {
  1285. if (this.view) {
  1286. t.pos.x += 10 / this.view.scale
  1287. t.pos.y += 10 / this.view.scale
  1288. }
  1289. t.moveable = true;
  1290. this.addItem(t)
  1291. this.Markers.push(t);
  1292. graphItemList.push(t)
  1293. })
  1294. parserData.textMarkerList.forEach(t => {
  1295. if (this.view) {
  1296. t.pos.x += 10 / this.view.scale
  1297. t.pos.y += 10 / this.view.scale
  1298. }
  1299. t.moveable = true;
  1300. this.addItem(t)
  1301. this.Markers.push(t);
  1302. graphItemList.push(t)
  1303. })
  1304. parserData.relationList.forEach(t => {
  1305. if (this.view) {
  1306. t.pos.x += 10 / this.view.scale
  1307. t.pos.y += 10 / this.view.scale
  1308. t.moveToOrigin(t.pos.x, t.pos.y)
  1309. }
  1310. t.moveable = true;
  1311. this.addItem(t)
  1312. this.Relations.push(t);
  1313. graphItemList.push(t)
  1314. })
  1315. this.scenceUpdate(this);
  1316. if (graphItemList.length) {
  1317. this.AddListCommand(graphItemList)
  1318. }
  1319. } catch (e) {
  1320. console.log(e);
  1321. }
  1322. }
  1323. /** 类型转换 */
  1324. itemToType(obj:SGraphItem):String{
  1325. if (obj instanceof STextMarkerItem) {
  1326. return 'Markers'
  1327. } else if (obj instanceof SImageMarkerItem) {
  1328. return 'Markers'
  1329. } else if (obj instanceof SLineMarkerItem) {
  1330. return 'Markers'
  1331. } else if (obj instanceof SZoneLegendItem) {
  1332. return 'Nodes'
  1333. } else if (obj instanceof SFHFQZoneLegendItem) {
  1334. return 'Nodes'
  1335. } else if (obj instanceof SSCPZZoneLegendItem) {
  1336. return 'Nodes'
  1337. } else if (obj instanceof SImageLegendItem) {
  1338. return 'Nodes'
  1339. } else if (obj instanceof TipelineItem) {
  1340. return 'Relations'
  1341. }
  1342. return '';
  1343. }
  1344. /**
  1345. * 鼠标双击事件
  1346. *
  1347. * @param event 事件参数
  1348. * @return boolean
  1349. */
  1350. onDoubleClick(event: SMouseEvent): boolean {
  1351. if (!this.isEditStatus) {
  1352. return true
  1353. } else {
  1354. return super.onDoubleClick(event);
  1355. }
  1356. } // Function onDoubleClick()
  1357. /**
  1358. * 设置管线结束锚点
  1359. *
  1360. */
  1361. setTipeEndanchor(event: SMouseEvent): void {
  1362. if (this.grabItem instanceof TipelineItem) {
  1363. const anc = this.clickIsAnchor(event);
  1364. if (anc) {
  1365. const p = anc.mapToScene(0, 0)
  1366. anc.isConnected = true;
  1367. event.x = p.x;
  1368. event.y = p.y;
  1369. if (this.grabItem.status == SItemStatus.Create) {
  1370. if (this.grabItem.pointList.length) {
  1371. this.grabItem.endAnchor = anc;
  1372. anc.parent ?.connect('changePos', this.grabItem, this.grabItem.changePos)
  1373. }
  1374. this.grabItem.anchor2ID = anc.id
  1375. this.grabItem.node2Id = anc.parent.id
  1376. this.grabItem.onMouseDown(event)
  1377. this.grabItem.status = SItemStatus.Normal;
  1378. this.finishCreated(this.grabItem)
  1379. return
  1380. }
  1381. }
  1382. this.grabItem.onMouseDown(event)
  1383. }
  1384. }
  1385. /**
  1386. * 管线item修改锚点
  1387. *
  1388. */
  1389. updateTipeAnc(event: SMouseEvent): void {
  1390. if (this.grabItem instanceof TipelineItem) {
  1391. const anc = this.clickIsAnchor(event);
  1392. if (anc) {
  1393. const p = anc.mapToScene(0, 0)
  1394. event.x = p.x;
  1395. event.y = p.y;
  1396. if (this.grabItem.status == SItemStatus.Edit) {
  1397. if (this.grabItem.curIndex == 0) {
  1398. if (this.grabItem.startAnchor) {
  1399. this.grabItem.startAnchor.isConnected = false
  1400. this.grabItem.startAnchor.parent.disconnect('changePos', this.grabItem);
  1401. }
  1402. anc.isConnected = true;
  1403. this.grabItem.startAnchor = anc;
  1404. this.grabItem.anchor1ID = anc.id
  1405. this.grabItem.node1Id = anc.parent.id
  1406. anc.parent.connect('changePos', this.grabItem, this.grabItem.changePos)
  1407. }
  1408. if (this.grabItem.curIndex == this.grabItem.pointList.length - 1) {
  1409. if (this.grabItem.endAnchor) {
  1410. this.grabItem.endAnchor.isConnected = false
  1411. this.grabItem.endAnchor.parent.disconnect('changePos', this.grabItem);
  1412. }
  1413. anc.isConnected = true;
  1414. this.grabItem.endAnchor = anc;
  1415. this.grabItem.anchor2ID = anc.id
  1416. this.grabItem.node2Id = anc.parent.id
  1417. anc.parent.connect('changePos', this.grabItem, this.grabItem.changePos)
  1418. }
  1419. }
  1420. this.grabItem.onMouseUp(event)
  1421. return
  1422. } else {
  1423. if (this.grabItem.status == SItemStatus.Edit) {
  1424. if (this.grabItem.curIndex == 0) {
  1425. if (this.grabItem.startAnchor) {
  1426. this.grabItem.startAnchor.isConnected = false
  1427. this.grabItem.startAnchor.parent.disconnect('changePos', this.grabItem);
  1428. this.grabItem.startAnchor = null;
  1429. this.grabItem.anchor1ID = ''
  1430. this.grabItem.node1Id = ''
  1431. }
  1432. }
  1433. if (this.grabItem.curIndex == this.grabItem.pointList.length - 1) {
  1434. if (this.grabItem.endAnchor) {
  1435. this.grabItem.endAnchor.isConnected = false
  1436. this.grabItem.endAnchor.parent.disconnect('changePos', this.grabItem);
  1437. this.grabItem.endAnchor = null;
  1438. this.grabItem.anchor2ID = ''
  1439. this.grabItem.node2Id = ''
  1440. }
  1441. }
  1442. }
  1443. this.grabItem.onMouseUp(event)
  1444. return
  1445. }
  1446. }
  1447. }
  1448. /**
  1449. * 设置直线结束Item
  1450. *
  1451. */
  1452. setLineItem(event: SMouseEvent): void {
  1453. if (this.grabItem instanceof SLineMarkerItem) {
  1454. const item = this.clickIsItem(event);
  1455. // 鼠标点是否在某个item内
  1456. if (item) {
  1457. let scenePoint = item.boundingRect().center();
  1458. const p = item.mapToScene(scenePoint.x, scenePoint.y);
  1459. event.x = p.x;
  1460. event.y = p.y;
  1461. if (this.grabItem.status == SItemStatus.Create) {
  1462. // 点击在item内、创建状态且端点列表不为空时将直线结束端点和item绑定
  1463. if (this.grabItem.line.length) {
  1464. if (this.grabItem.startItem ?.id == item.id) {
  1465. this.grabItem.endItem = null;
  1466. } else {
  1467. this.grabItem.endItem = item;
  1468. this.grabItem.line[1] = new SPoint(event.x, event.y);
  1469. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1470. }
  1471. }
  1472. this.grabItem.onMouseDown(event);
  1473. return
  1474. } else if (this.grabItem.status == SItemStatus.Edit) {
  1475. // 点击在item内、编辑状态且点击的为结束端点时
  1476. if (this.grabItem.curIndex == 1) {
  1477. // 直线关联的起始item是直线结束端点所在的item时,不吸附在点击item中心并将直线关联的结束item置为null
  1478. if (this.grabItem.startItem ?.id == item.id) {
  1479. this.grabItem.endItem = null;
  1480. } else {// 反正吸附,关联
  1481. this.grabItem.endItem = item;
  1482. this.grabItem.line[1] = new SPoint(event.x, event.y);
  1483. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1484. }
  1485. } else if (this.grabItem.curIndex == 0) {
  1486. if (this.grabItem.endItem ?.id == item.id) {
  1487. this.grabItem.startItem = null;
  1488. } else {
  1489. this.grabItem.startItem = item;
  1490. this.grabItem.line[0] = new SPoint(event.x, event.y);
  1491. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1492. }
  1493. }
  1494. }
  1495. } else {
  1496. // 如果不在item内且点击的是直线的某个端点,将端点的关联item置为null
  1497. if (this.grabItem.line.length && this.grabItem.curIndex != -1) {
  1498. if (this.grabItem.curIndex == 1) {
  1499. this.grabItem.endItem = null;
  1500. } else if (this.grabItem.curIndex == 0) {
  1501. this.grabItem.startItem = null;
  1502. }
  1503. } else {
  1504. this.grabItem.onMouseDown(event);
  1505. return
  1506. }
  1507. }
  1508. // if (this.grabItem.status == SItemStatus.Create) {
  1509. // // 鼠标点是否在某个item内
  1510. // if (item) {
  1511. // let scenePoint = item.boundingRect().center();
  1512. // const p = item.mapToScene(scenePoint.x, scenePoint.y);
  1513. // event.x = p.x;
  1514. // event.y = p.y;
  1515. // if (this.grabItem.line.length && this.grabItem.curIndex == -1) {
  1516. // this.grabItem.endItem = item;
  1517. // this.grabItem.line[1] = new SPoint(event.x, event.y);
  1518. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1519. // }
  1520. // this.grabItem.onMouseDown(event);
  1521. // return
  1522. // } else {
  1523. // if (this.grabItem.line.length && this.grabItem.curIndex != -1) {
  1524. // if (this.grabItem.curIndex == 1) {
  1525. // this.grabItem.endItem = null;
  1526. // } else if (this.grabItem.curIndex == 0) {
  1527. // this.grabItem.startItem = null;
  1528. // }
  1529. // }
  1530. // }
  1531. // } else if (this.grabItem.status == SItemStatus.Edit) {
  1532. // if (this.grabItem.curIndex == 1) {
  1533. // this.grabItem.endItem = item;
  1534. // this.grabItem.line[1] = new SPoint(event.x, event.y);
  1535. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1536. // } else if (this.grabItem.curIndex == 0) {
  1537. // this.grabItem.startItem = item;
  1538. // this.grabItem.line[0] = new SPoint(event.x, event.y);
  1539. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1540. // }
  1541. // }
  1542. this.grabItem.onMouseUp(event);
  1543. }
  1544. }
  1545. /**
  1546. * 划线时点击位置是否是锚点
  1547. *
  1548. * @param event 事件
  1549. * @param len 限制距离
  1550. * @return 点击的锚点
  1551. * */
  1552. clickIsAnchor(event: SMouseEvent): SAnchorItem | null {
  1553. let minAnchor = null;
  1554. let len: number = -1;
  1555. this.Nodes.forEach(image => {
  1556. // image.showAnchor = false;
  1557. if (image.anchorList && image.anchorList.length) {
  1558. if(image.img && image.img instanceof SImageItem) {
  1559. let scenePoint = image.img.mapFromScene(event.x, event.y);
  1560. if (image.img.contains(scenePoint.x, scenePoint.y)) {
  1561. let anchor = image.anchorList[0]
  1562. let anchorPoint = anchor.mapToScene(0, 0);
  1563. let dis = SMathUtil.pointDistance(
  1564. event.x,
  1565. event.y,
  1566. anchorPoint.x,
  1567. anchorPoint.y
  1568. );
  1569. console.log(dis)
  1570. if (len < 0) {
  1571. minAnchor = anchor;
  1572. len = dis;
  1573. }
  1574. if (dis < len) {
  1575. minAnchor = anchor;
  1576. len = dis;
  1577. }
  1578. }
  1579. // let scenePoint = image.mapFromScene(event.x, event.y);
  1580. // if (image.contains(scenePoint.x, scenePoint.y)) {
  1581. // image.anchorList.forEach(anchor => {
  1582. // let anchorPoint = anchor.mapToScene(0, 0);
  1583. // let dis = SMathUtil.pointDistance(
  1584. // event.x,
  1585. // event.y,
  1586. // anchorPoint.x,
  1587. // anchorPoint.y
  1588. // );
  1589. // if (len < 0) {
  1590. // len = anchor.sceneDis;
  1591. // }
  1592. // if (dis < len) {
  1593. // minAnchor = anchor;
  1594. // len = dis;
  1595. // }
  1596. // })
  1597. }
  1598. }
  1599. })
  1600. console.log('-----------------------')
  1601. console.log(minAnchor)
  1602. console.log('-----------------------')
  1603. // if (minAnchor&&minAnchor.parent) {
  1604. // minAnchor.parent.showAnchor = true
  1605. // }
  1606. return minAnchor;
  1607. }
  1608. /**
  1609. * 划线时点击位置是在文本,图片,,区域内
  1610. *
  1611. * @param event 事件
  1612. * @return 点击的item
  1613. * */
  1614. clickIsItem(event: SMouseEvent): SGraphItem | null {
  1615. let minIten = null;
  1616. let len: number = -1;
  1617. let itemList = this.Nodes.concat(this.Markers);
  1618. itemList.forEach(item => {
  1619. if (
  1620. item instanceof STextMarkerItem ||
  1621. item instanceof SImageMarkerItem ||
  1622. item instanceof SZoneLegendItem ||
  1623. item instanceof SFHFQZoneLegendItem ||
  1624. item instanceof SSCPZZoneLegendItem
  1625. ) {
  1626. let scenePoint = item.mapFromScene(event.x, event.y);
  1627. if (item.contains(scenePoint.x, scenePoint.y)) {
  1628. let dis = SMathUtil.pointDistance(
  1629. scenePoint.x,
  1630. scenePoint.y,
  1631. item.boundingRect().center().x,
  1632. item.boundingRect().center().y
  1633. );
  1634. if (len < 0) {
  1635. minIten = item;
  1636. len = dis;
  1637. }
  1638. if (dis < len) {
  1639. minIten = item;
  1640. len = dis;
  1641. }
  1642. }
  1643. }
  1644. })
  1645. console.log('-----------------------')
  1646. console.log(minIten)
  1647. console.log('-----------------------')
  1648. return minIten;
  1649. }
  1650. /**
  1651. * 点是否在吸附区域内
  1652. *
  1653. * @param p 要判断的点
  1654. * @param minX 空间区域
  1655. * @param minY 空间区域
  1656. * @param maxX 空间区域
  1657. * @param maxY 空间区域
  1658. */
  1659. static isPointInAbsorbArea(
  1660. p: SPoint,
  1661. minX: number,
  1662. maxX: number,
  1663. minY: number,
  1664. maxY: number
  1665. ): boolean {
  1666. let rect = new SRect(
  1667. minX - 1000,
  1668. minY - 1000,
  1669. maxX - minX + 2000,
  1670. maxY - minY + 2000
  1671. );
  1672. return rect.contains(p.x, p.y);
  1673. } // Function isPointInAbsorbArea()
  1674. /**
  1675. * 吸附空间
  1676. *
  1677. * @param event 鼠标事件对象
  1678. * @return boolean 是否找到吸附的对象
  1679. */
  1680. absorbSpace(event: SMouseEvent): boolean {
  1681. if (!this.highLight) {
  1682. return false;
  1683. }
  1684. let absorbLen = 1000;
  1685. if (this.view) {
  1686. absorbLen = 10 / this.view.scale;
  1687. }
  1688. let P = this.absorbSpacePoint(event, absorbLen);
  1689. if (P.Point) {
  1690. this.highLight.distance = P.MinDis;
  1691. this.highLight.point = new SPoint(P.Point.X, -P.Point.Y);
  1692. this.highLight.visible = true;
  1693. return true;
  1694. } else {
  1695. let L = this.absorbSpaceLine(event, absorbLen);
  1696. if (L.Line && L.Point) {
  1697. this.highLight.distance = L.MinDis;
  1698. this.highLight.point = L.Point;
  1699. this.highLight.line = L.Line;
  1700. this.highLight.visible = true;
  1701. return true;
  1702. }
  1703. return false;
  1704. }
  1705. } // Function absorbSpace()
  1706. /**
  1707. * 吸附空间点
  1708. *
  1709. * @param event 鼠标事件对象
  1710. * @param absorbLen 吸附距离
  1711. * @return MinDis 吸附的点
  1712. */
  1713. absorbSpacePoint(event: SMouseEvent, absorbLen: number): MinDis {
  1714. let minPointDis = Number.MAX_SAFE_INTEGER;
  1715. let Point;
  1716. this.spaceList.map((space): void => {
  1717. if (
  1718. EditScence.isPointInAbsorbArea(
  1719. new SPoint(event.x, event.y),
  1720. space.minX,
  1721. space.maxX,
  1722. space.minY,
  1723. space.maxY
  1724. )
  1725. ) {
  1726. space.data.OutLine.forEach((item): void => {
  1727. let minDis = SMathUtil.getMinDisPoint(
  1728. new SPoint(event.x, event.y),
  1729. item
  1730. );
  1731. if (
  1732. minDis &&
  1733. minDis.MinDis < absorbLen &&
  1734. minDis.MinDis < minPointDis
  1735. ) {
  1736. minPointDis = minDis.MinDis;
  1737. Point = minDis.Point;
  1738. }
  1739. });
  1740. }
  1741. });
  1742. return {
  1743. MinDis: minPointDis,
  1744. Point: Point
  1745. };
  1746. } // Function absorbSpacePoint()
  1747. /**
  1748. * 吸附空间线
  1749. *
  1750. * @param event 鼠标事件对象
  1751. * @param absorbLen 吸附距离
  1752. * @return PointToLine 吸附的线
  1753. */
  1754. absorbSpaceLine(event: SMouseEvent, absorbLen: number): PointToLine {
  1755. let minPointDis = Number.MAX_SAFE_INTEGER;
  1756. let Point, Line;
  1757. this.spaceList.forEach((space): void => {
  1758. if (
  1759. EditScence.isPointInAbsorbArea(
  1760. new SPoint(event.x, event.y),
  1761. space.minX,
  1762. space.maxX,
  1763. space.minY,
  1764. space.maxY
  1765. )
  1766. ) {
  1767. space.data.OutLine.forEach((item): void => {
  1768. let minDisLine = SMathUtil.getMinDisLine(
  1769. new SPoint(event.x, event.y),
  1770. item
  1771. );
  1772. if (
  1773. minDisLine &&
  1774. minDisLine.MinDis < absorbLen &&
  1775. minDisLine.MinDis < minPointDis
  1776. ) {
  1777. minPointDis = minDisLine.MinDis;
  1778. Point = minDisLine.Point;
  1779. Line = minDisLine.Line;
  1780. }
  1781. });
  1782. }
  1783. });
  1784. return {
  1785. MinDis: minPointDis,
  1786. Point: Point,
  1787. Line: Line
  1788. };
  1789. } // Function absorbSpaceLine()
  1790. /**
  1791. * 添加多个item命令
  1792. * @param focusItemList 鼠标事件对象
  1793. */
  1794. AddListCommand(focusItemList: any[]): void {
  1795. this.undoStack.push(new SGraphAddListCommand(this, focusItemList));
  1796. }
  1797. /**
  1798. * 选中状态方法
  1799. * @param item 鼠标事件对象
  1800. */
  1801. toggleItem(item: SGraphItem): void {
  1802. this.selectContainer.clear()
  1803. this.selectContainer.toggleItem(item)
  1804. }
  1805. /**
  1806. * 图标旋转更新角度
  1807. *
  1808. * @param ang 旋转角度
  1809. */
  1810. updateItemAng(ang: number) :void{
  1811. if (this.focusItem) {
  1812. if (this.focusItem instanceof SImageLegendItem) {
  1813. const oldMsg = this.focusItem.img.rotate;
  1814. const newMsg = ang;
  1815. this.focusItem.img.rotate = ang;
  1816. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem.img, "rotate", oldMsg, newMsg));
  1817. this.scenceUpdate(this);
  1818. }
  1819. }
  1820. }
  1821. /**
  1822. * 框选
  1823. */
  1824. addRectSelect(event: SMouseEvent) {
  1825. let point = new SPoint(event.x, event.y);
  1826. let rect = new SRectSelectItem(null, point);
  1827. this.addItem(rect);
  1828. this.grabItem = rect;
  1829. }
  1830. /**
  1831. * 计算框选交集
  1832. */
  1833. groupSelect(){
  1834. this.selectContainer.clear()
  1835. if (this.grabItem instanceof SRectSelectItem) {
  1836. const rect = this.grabItem.boundingRect();
  1837. this.arrToSelect(this.Nodes, rect)
  1838. this.arrToSelect(this.Markers, rect)
  1839. this.arrToSelect(this.Relations, rect)
  1840. }
  1841. }
  1842. /**
  1843. * 选中item:框选
  1844. */
  1845. private arrToSelect(arr: SGraphItem[], rect:SRect){
  1846. if(Array.isArray(arr) && arr.length) {
  1847. arr.forEach(t => {
  1848. if (t.parent) {
  1849. let temp = t.boundingRect();
  1850. let lefttop = t.mapToScene(temp.left, temp.top)
  1851. let rightbottom = t.mapToScene(temp.right, temp.bottom)
  1852. let r = new SRect(lefttop, rightbottom)
  1853. if (rect.isIn(r)){
  1854. this.selectContainer.toggleItem(t)
  1855. }
  1856. }
  1857. })
  1858. }
  1859. }
  1860. }