EditScence.ts 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938
  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. let nameArr = name.split("\n");
  722. if (nameArr[nameArr.length - 1] != arr[arr.length - 1].name)
  723. if (name) {
  724. item.name = name + `\n${arr[arr.length - 1].name}`;
  725. item.text = name + `\n${arr[arr.length - 1].name}`;
  726. } else {
  727. item.name = arr[arr.length - 1].name;
  728. item.text = arr[arr.length - 1].name;
  729. }
  730. }
  731. // 绑定工程信息化数据后设置状态
  732. if (item.data.AttachObjectIds && item.data.AttachObjectIds.length) {
  733. item.isActive = true;
  734. } else {
  735. item.isActive = false;
  736. }
  737. }
  738. }
  739. }
  740. /**
  741. * 自定义多边形修改背景色
  742. */
  743. updateCustomBgColor(val: string):void{
  744. if (this.focusItem) {
  745. const newMsg = new SColor(val);
  746. const oldMsg = this.focusItem.fillColor;
  747. this.focusItem.fillColor = new SColor(val)
  748. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "fillColor", oldMsg, newMsg));
  749. }
  750. }
  751. /**
  752. * 自定义多边形修改边框色
  753. */
  754. updateCustomBdColor(val: string):void{
  755. if (this.focusItem) {
  756. const newMsg = new SColor(val);
  757. const oldMsg = this.focusItem.strokeColor;
  758. this.focusItem.strokeColor = new SColor(val)
  759. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "strokeColor", oldMsg, newMsg));
  760. }
  761. }
  762. /**
  763. * 删除指定item
  764. */
  765. deleiteItem(): void {
  766. if (this.focusItem) {
  767. if ((this.focusItem instanceof SZoneLegendItem ||
  768. this.focusItem instanceof SSCPZZoneLegendItem ||
  769. this.focusItem instanceof SFHFQZoneLegendItem ||
  770. this.focusItem instanceof TipelineItem) &&
  771. this.focusItem.curIndex != -1
  772. ) {
  773. this.focusItem.deletePoint(this.focusItem.curIndex);
  774. } else {
  775. this.undoStack.push(new SGraphDeleteCommand(this, this.focusItem));
  776. this.removeItem(this.focusItem);
  777. let a = -1
  778. this.Nodes.forEach((item: any, index: number) => {
  779. if (item.id == this.focusItem.id) {
  780. a = index
  781. }
  782. });
  783. if (a > -1) {
  784. this.Nodes.splice(a, 1);
  785. }
  786. let b = -1;
  787. this.Markers.forEach((item: any, index: number) => {
  788. if (item.id == this.focusItem.id) {
  789. b = index
  790. }
  791. });
  792. if (b > -1) {
  793. this.Markers.splice(b, 1);
  794. }
  795. let c = -1;
  796. this.Relations.forEach((item: any, index: number) => {
  797. if (item.id == this.focusItem.id) {
  798. c = index
  799. }
  800. });
  801. if (c > -1) {
  802. this.Relations.splice(c, 1);
  803. }
  804. this.grabItem = null;
  805. this.focusItem = null;
  806. if (this.view) {
  807. this.view.update();
  808. }
  809. this.scenceUpdate(this);
  810. }
  811. } else {
  812. //批量删除
  813. if (!this.focusItemList) {
  814. return
  815. }
  816. this.undoStack.push(new SGraphDeleteListCommand(this, this.focusItemList))
  817. this.focusItemList.forEach((focusItem) => {
  818. this.removeItem(focusItem);
  819. let a = -1
  820. this.Nodes.forEach((item: any, index: number) => {
  821. if (item.id == focusItem.id) {
  822. a = index
  823. }
  824. });
  825. if (a > -1) {
  826. this.Nodes.splice(a, 1);
  827. }
  828. let b = -1;
  829. this.Markers.forEach((item: any, index: number) => {
  830. if (item.id == focusItem.id) {
  831. b = index
  832. }
  833. });
  834. if (b > -1) {
  835. this.Markers.splice(b, 1);
  836. }
  837. let c = -1;
  838. this.Relations.forEach((item: any, index: number) => {
  839. if (item.id == focusItem.id) {
  840. c = index
  841. }
  842. });
  843. if (c > -1) {
  844. this.Relations.splice(c, 1);
  845. }
  846. });
  847. this.focusItemList = [];
  848. this.grabItem = null;
  849. this.focusItem = null;
  850. if (this.view) {
  851. this.view.update();
  852. }
  853. this.scenceUpdate(this);
  854. }
  855. }
  856. scenceUpdate(scence: any) {
  857. }
  858. /**
  859. * 对齐指定item
  860. * @param v
  861. */
  862. changeAlignItem(v: any): void {
  863. this.selectContainer.layout(v);
  864. }
  865. /**
  866. * 图层排序
  867. * @param v
  868. */
  869. changeOrderItem(v: any): void {
  870. this.selectContainer.setOrder(v);
  871. }
  872. /**
  873. * 提取item
  874. */
  875. extractItem(): void {
  876. console.log(this)
  877. }
  878. /**
  879. * 保存数据
  880. */
  881. saveMsgItem(): any {
  882. const Nodes: any = [];
  883. const Markers: any = [];
  884. const Relations: any = [];
  885. this.Nodes.forEach(e => {
  886. Nodes.push(e.toData())
  887. });
  888. this.Markers.forEach(e => {
  889. Markers.push(e.toData())
  890. });
  891. this.Relations.forEach(e => {
  892. Relations.push(e.toData())
  893. });
  894. let element = {
  895. Nodes, Markers, Relations
  896. }
  897. return element
  898. }
  899. /**
  900. * 执行取消操作
  901. */
  902. redo(): void {
  903. if (this.grabItem && this.grabItem.redo) {
  904. this.grabItem.redo()
  905. } else {
  906. this.undoStack.redo();
  907. this.scenceUpdate(this);
  908. }
  909. }
  910. /**
  911. * 执行重做操作执行
  912. */
  913. undo(): void {
  914. if (this.grabItem && this.grabItem.undo) {
  915. this.grabItem.undo()
  916. } else {
  917. this.undoStack.undo();
  918. this.scenceUpdate(this);
  919. }
  920. }
  921. /**
  922. * 完成事件创建的回调函数
  923. */
  924. finishCreated(item: any) {
  925. // let arrList = []
  926. if (this.cmd == 'baseLine') {
  927. // arrList = this.Markers;
  928. // 对数组遍历防止相同得id注入
  929. let canPush = true; //是否可注入
  930. this.Markers.forEach((arrItem: any) => {
  931. if (arrItem.id == item.id) {
  932. canPush = false
  933. }
  934. })
  935. if (canPush) {
  936. this.Markers.push(item);
  937. this.undoStack.push(new SGraphAddCommand(this, item));
  938. }
  939. }
  940. this.cmd = 'choice';
  941. this.selectContainer.clear()
  942. this.selectContainer.toggleItem(item)
  943. setTimeout(() => {
  944. this.focusItem = item;
  945. });
  946. if (item instanceof SZoneLegendItem || item instanceof SFHFQZoneLegendItem || item instanceof SSCPZZoneLegendItem || item instanceof SCustomLegendItem) {
  947. let canPush = true; //是否可注入
  948. this.Nodes.forEach((arrItem: any) => {
  949. if (arrItem.id == item.id) {
  950. canPush = false
  951. }
  952. })
  953. if (canPush) {
  954. this.Nodes.push(item); //完成后,方可扔到Node节点
  955. this.undoStack.push(new SGraphAddCommand(this, item));
  956. }
  957. }
  958. // 管道完成后方可保存
  959. if (item instanceof TipelineItem) {
  960. let canPush = true; //是否可注入
  961. this.Relations.forEach((arrItem: any) => {
  962. if (arrItem.id == item.id) {
  963. canPush = false
  964. }
  965. })
  966. if (canPush) {
  967. this.Relations.push(item);
  968. this.undoStack.push(new SGraphAddCommand(this, item));
  969. }
  970. }
  971. this.scenceUpdate(this);
  972. }
  973. ////////////////////////
  974. // 以下为鼠标键盘操作事件
  975. onMouseDown(event: SMouseEvent): any {
  976. if (!this.isEditStatus) {
  977. return true
  978. }
  979. // 判断是否开启吸附,并且有吸附的点
  980. if (
  981. this.isAbsorbing &&
  982. this.highLight &&
  983. this.highLight.visible
  984. ) {
  985. event.x = this.highLight.point.x;
  986. event.y = this.highLight.point.y;
  987. }
  988. if (this.grabItem) {
  989. if (this.grabItem instanceof TipelineItem) {
  990. this.setTipeEndanchor(event)
  991. return true;
  992. } else if (this.grabItem instanceof SLineMarkerItem && this.grabItem.status == SItemStatus.Create) {
  993. this.setLineItem(event)
  994. return true;
  995. }
  996. return this.grabItem.onMouseDown(event);
  997. }
  998. switch (this.cmd) {
  999. // case 'choice':
  1000. // if (!super.onMouseDown(event)){
  1001. // this.addRectSelect(event);
  1002. // }
  1003. // break
  1004. case 'baseLine':
  1005. this.addLine(event);
  1006. break;
  1007. case 'baseText':
  1008. this.addTextItem(event);
  1009. break;
  1010. case 'baseImage':
  1011. this.addImgItem(event)
  1012. break;
  1013. case 'Zone':
  1014. if (!this.isSelecting) {
  1015. this.addPolygonItem(event);
  1016. } else {
  1017. // 点选创建区域
  1018. return super.onMouseDown(event)
  1019. }
  1020. break;
  1021. case 'Image':
  1022. this.addIconItem(event);
  1023. break;
  1024. case 'Line':
  1025. this.addTipelineItem(event);
  1026. break;
  1027. default:
  1028. return super.onMouseDown(event);
  1029. }
  1030. }
  1031. onMouseMove(event: SMouseEvent): boolean {
  1032. if (!this.isEditStatus) {
  1033. return true
  1034. }
  1035. if (this.isAbsorbing) {
  1036. if (!this.highLight) {
  1037. this.highLight = new HighlightItem(null);
  1038. this.addItem(this.highLight);
  1039. }
  1040. this.highLight.visible = false;
  1041. this.absorbSpace(event);
  1042. }
  1043. if (this.grabItem){
  1044. if (this.grabItem instanceof TipelineItem) {
  1045. const anc = this.clickIsAnchor(event);
  1046. if (anc) {
  1047. const p = anc.mapToScene(0, 0)
  1048. event.x = p.x;
  1049. event.y = p.y;
  1050. return this.grabItem.onMouseMove(event);
  1051. }
  1052. } else if (this.grabItem instanceof SRectSelectItem) {
  1053. return this.grabItem.onMouseMove(event);
  1054. }
  1055. }
  1056. return super.onMouseMove(event)
  1057. }
  1058. onMouseUp(event: SMouseEvent): boolean {
  1059. if (!this.isEditStatus) {
  1060. return true
  1061. }
  1062. if (this.grabItem) {
  1063. if (this.grabItem instanceof SLineMarkerItem && this.grabItem.status == SItemStatus.Edit) {
  1064. this.setLineItem(event)
  1065. return true;
  1066. } else if (this.grabItem instanceof TipelineItem) {
  1067. this.updateTipeAnc(event);
  1068. return true;
  1069. } else if (this.grabItem instanceof SRectSelectItem) {
  1070. this.groupSelect();
  1071. this.removeItem(this.grabItem);
  1072. this.grabItem = null;
  1073. if (this.view) {
  1074. this.view.update()
  1075. }
  1076. return true;
  1077. }
  1078. return this.grabItem.onMouseUp(event);
  1079. }
  1080. return super.onMouseUp(event)
  1081. }
  1082. /**
  1083. * 键盘事件
  1084. *
  1085. * @param event 事件参数
  1086. * @return boolean
  1087. */
  1088. onKeyDown(event: KeyboardEvent): any {
  1089. if (!this.isEditStatus) {
  1090. return true
  1091. }
  1092. if (this.grabItem) {
  1093. this.grabItem.onKeyDown(event);
  1094. if (event.code == "Escape") {
  1095. const item = this.grabItem;
  1096. this.grabItem = null
  1097. this.removeItem(item);
  1098. if (this.view) {
  1099. this.view.update()
  1100. }
  1101. this.setCmd = 'choice'
  1102. }
  1103. }
  1104. // 删除键功能
  1105. if (event.code == 'Delete') {
  1106. this.deleiteItem()
  1107. }
  1108. // 删除键功能--兼容苹果mac
  1109. if (event.code == 'Backspace' && this.isMac){
  1110. this.deleiteItem()
  1111. }
  1112. // 复制粘贴
  1113. if (event.ctrlKey && !event.repeat) {
  1114. if (event.code == 'KeyC') {
  1115. console.log('ctrl c')
  1116. this.copy()
  1117. } else if (event.code == 'KeyV') {
  1118. console.log('ctrl v')
  1119. this.paste()
  1120. }
  1121. }
  1122. return false
  1123. }
  1124. /**
  1125. * 复制
  1126. *
  1127. */
  1128. copy(){
  1129. if (this.selectContainer.itemList.length) {
  1130. this.copyString = {
  1131. Nodes: [],
  1132. Markers: [],
  1133. Relations: []
  1134. };
  1135. this.selectContainer.itemList.forEach(t => {
  1136. const type = this.itemToType(t);
  1137. if (type) {
  1138. const data = JSON.parse(JSON.stringify(t.toData()))
  1139. data.ID = ''
  1140. if (data.Type == 'Image') {
  1141. data.AnchorList = []
  1142. }
  1143. this.copyString[type].push(data)
  1144. }
  1145. })
  1146. // 生成复制字符串
  1147. console.log(this.copyString)
  1148. return
  1149. // 获取input dom
  1150. const input = document.createElement('input');
  1151. input.setAttribute('id', 'COPYINPUT')
  1152. input.value = JSON.stringify(this.copyString)
  1153. document.body.appendChild(input);
  1154. input.select()
  1155. document.execCommand('copy');
  1156. input.style.display='none';
  1157. console.log(input.value, Date.now());
  1158. document.body.removeChild(input)
  1159. }
  1160. }
  1161. /**
  1162. * 粘贴
  1163. *
  1164. */
  1165. paste(){
  1166. const parserData = new STopologyParser(null);
  1167. // 需要深拷贝
  1168. parserData.parseData(JSON.parse(JSON.stringify(this.copyString)))
  1169. // 不需要复制区域
  1170. // parserData.zoneLegendList.forEach(t => {
  1171. // if (t instanceof SCustomLegendItem) {
  1172. // if (this.view) {
  1173. // t.pos.x += 10 / this.view.scale
  1174. // t.pos.y += 10 / this.view.scale
  1175. // }
  1176. // this.addItem(t)
  1177. // this.Nodes.push(t);
  1178. // graphItemList.push(t)
  1179. // }
  1180. // // 加到node
  1181. // // 加命令
  1182. // })
  1183. const graphItemList = [];
  1184. parserData.imageLegendList.forEach(t => {
  1185. if (this.view) {
  1186. t.pos.x += 10 / this.view.scale
  1187. t.pos.y += 10 / this.view.scale
  1188. }
  1189. t.moveable = true;
  1190. this.addItem(t)
  1191. this.Nodes.push(t);
  1192. graphItemList.push(t)
  1193. })
  1194. parserData.imageMarkerList.forEach(t => {
  1195. if (this.view) {
  1196. t.pos.x += 10 / this.view.scale
  1197. t.pos.y += 10 / this.view.scale
  1198. }
  1199. t.moveable = true;
  1200. this.addItem(t)
  1201. this.Markers.push(t);
  1202. graphItemList.push(t)
  1203. })
  1204. parserData.lineMarkerList.forEach(t => {
  1205. if (this.view) {
  1206. t.pos.x += 10 / this.view.scale
  1207. t.pos.y += 10 / this.view.scale
  1208. }
  1209. t.moveable = true;
  1210. this.addItem(t)
  1211. this.Markers.push(t);
  1212. graphItemList.push(t)
  1213. })
  1214. parserData.textMarkerList.forEach(t => {
  1215. if (this.view) {
  1216. t.pos.x += 10 / this.view.scale
  1217. t.pos.y += 10 / this.view.scale
  1218. }
  1219. t.moveable = true;
  1220. this.addItem(t)
  1221. this.Markers.push(t);
  1222. graphItemList.push(t)
  1223. })
  1224. parserData.relationList.forEach(t => {
  1225. if (this.view) {
  1226. t.pos.x += 10 / this.view.scale
  1227. t.pos.y += 10 / this.view.scale
  1228. t.moveToOrigin(t.pos.x, t.pos.y)
  1229. }
  1230. t.moveable = true;
  1231. this.addItem(t)
  1232. this.Relations.push(t);
  1233. graphItemList.push(t)
  1234. })
  1235. this.scenceUpdate(this);
  1236. if (graphItemList.length) {
  1237. this.AddListCommand(graphItemList)
  1238. }
  1239. }
  1240. /**
  1241. * 跨页面粘贴
  1242. *
  1243. */
  1244. crossPagePaste(crossPageString: string){
  1245. try {
  1246. console.log(crossPageString);
  1247. const pageObj = JSON.parse(crossPageString)
  1248. const parserData = new STopologyParser(null);
  1249. // 需要深拷贝
  1250. parserData.parseData(JSON.parse(JSON.stringify(pageObj)))
  1251. // 不需要复制区域
  1252. // parserData.zoneLegendList.forEach(t => {
  1253. // if (t instanceof SCustomLegendItem) {
  1254. // if (this.view) {
  1255. // t.pos.x += 10 / this.view.scale
  1256. // t.pos.y += 10 / this.view.scale
  1257. // }
  1258. // this.addItem(t)
  1259. // this.Nodes.push(t);
  1260. // graphItemList.push(t)
  1261. // }
  1262. // // 加到node
  1263. // // 加命令
  1264. // })
  1265. const graphItemList = [];
  1266. parserData.imageLegendList.forEach(t => {
  1267. if (this.view) {
  1268. t.pos.x += 10 / this.view.scale
  1269. t.pos.y += 10 / this.view.scale
  1270. }
  1271. t.moveable = true;
  1272. this.addItem(t)
  1273. this.Nodes.push(t);
  1274. graphItemList.push(t)
  1275. })
  1276. parserData.imageMarkerList.forEach(t => {
  1277. if (this.view) {
  1278. t.pos.x += 10 / this.view.scale
  1279. t.pos.y += 10 / this.view.scale
  1280. }
  1281. t.moveable = true;
  1282. this.addItem(t)
  1283. this.Markers.push(t);
  1284. graphItemList.push(t)
  1285. })
  1286. parserData.lineMarkerList.forEach(t => {
  1287. if (this.view) {
  1288. t.pos.x += 10 / this.view.scale
  1289. t.pos.y += 10 / this.view.scale
  1290. }
  1291. t.moveable = true;
  1292. this.addItem(t)
  1293. this.Markers.push(t);
  1294. graphItemList.push(t)
  1295. })
  1296. parserData.textMarkerList.forEach(t => {
  1297. if (this.view) {
  1298. t.pos.x += 10 / this.view.scale
  1299. t.pos.y += 10 / this.view.scale
  1300. }
  1301. t.moveable = true;
  1302. this.addItem(t)
  1303. this.Markers.push(t);
  1304. graphItemList.push(t)
  1305. })
  1306. parserData.relationList.forEach(t => {
  1307. if (this.view) {
  1308. t.pos.x += 10 / this.view.scale
  1309. t.pos.y += 10 / this.view.scale
  1310. t.moveToOrigin(t.pos.x, t.pos.y)
  1311. }
  1312. t.moveable = true;
  1313. this.addItem(t)
  1314. this.Relations.push(t);
  1315. graphItemList.push(t)
  1316. })
  1317. this.scenceUpdate(this);
  1318. if (graphItemList.length) {
  1319. this.AddListCommand(graphItemList)
  1320. }
  1321. } catch (e) {
  1322. console.log(e);
  1323. }
  1324. }
  1325. /** 类型转换 */
  1326. itemToType(obj:SGraphItem):String{
  1327. if (obj instanceof STextMarkerItem) {
  1328. return 'Markers'
  1329. } else if (obj instanceof SImageMarkerItem) {
  1330. return 'Markers'
  1331. } else if (obj instanceof SLineMarkerItem) {
  1332. return 'Markers'
  1333. } else if (obj instanceof SZoneLegendItem) {
  1334. return 'Nodes'
  1335. } else if (obj instanceof SFHFQZoneLegendItem) {
  1336. return 'Nodes'
  1337. } else if (obj instanceof SSCPZZoneLegendItem) {
  1338. return 'Nodes'
  1339. } else if (obj instanceof SImageLegendItem) {
  1340. return 'Nodes'
  1341. } else if (obj instanceof TipelineItem) {
  1342. return 'Relations'
  1343. }
  1344. return '';
  1345. }
  1346. /**
  1347. * 鼠标双击事件
  1348. *
  1349. * @param event 事件参数
  1350. * @return boolean
  1351. */
  1352. onDoubleClick(event: SMouseEvent): boolean {
  1353. if (!this.isEditStatus) {
  1354. return true
  1355. } else {
  1356. return super.onDoubleClick(event);
  1357. }
  1358. } // Function onDoubleClick()
  1359. /**
  1360. * 设置管线结束锚点
  1361. *
  1362. */
  1363. setTipeEndanchor(event: SMouseEvent): void {
  1364. if (this.grabItem instanceof TipelineItem) {
  1365. const anc = this.clickIsAnchor(event);
  1366. if (anc) {
  1367. const p = anc.mapToScene(0, 0)
  1368. anc.isConnected = true;
  1369. event.x = p.x;
  1370. event.y = p.y;
  1371. if (this.grabItem.status == SItemStatus.Create) {
  1372. if (this.grabItem.pointList.length) {
  1373. this.grabItem.endAnchor = anc;
  1374. anc.parent ?.connect('changePos', this.grabItem, this.grabItem.changePos)
  1375. }
  1376. this.grabItem.anchor2ID = anc.id
  1377. this.grabItem.node2Id = anc.parent.id
  1378. this.grabItem.onMouseDown(event)
  1379. this.grabItem.status = SItemStatus.Normal;
  1380. this.finishCreated(this.grabItem)
  1381. return
  1382. }
  1383. }
  1384. this.grabItem.onMouseDown(event)
  1385. }
  1386. }
  1387. /**
  1388. * 管线item修改锚点
  1389. *
  1390. */
  1391. updateTipeAnc(event: SMouseEvent): void {
  1392. if (this.grabItem instanceof TipelineItem) {
  1393. const anc = this.clickIsAnchor(event);
  1394. if (anc) {
  1395. const p = anc.mapToScene(0, 0)
  1396. event.x = p.x;
  1397. event.y = p.y;
  1398. if (this.grabItem.status == SItemStatus.Edit) {
  1399. if (this.grabItem.curIndex == 0) {
  1400. if (this.grabItem.startAnchor) {
  1401. this.grabItem.startAnchor.isConnected = false
  1402. this.grabItem.startAnchor.parent.disconnect('changePos', this.grabItem);
  1403. }
  1404. anc.isConnected = true;
  1405. this.grabItem.startAnchor = anc;
  1406. this.grabItem.anchor1ID = anc.id
  1407. this.grabItem.node1Id = anc.parent.id
  1408. anc.parent.connect('changePos', this.grabItem, this.grabItem.changePos)
  1409. }
  1410. if (this.grabItem.curIndex == this.grabItem.pointList.length - 1) {
  1411. if (this.grabItem.endAnchor) {
  1412. this.grabItem.endAnchor.isConnected = false
  1413. this.grabItem.endAnchor.parent.disconnect('changePos', this.grabItem);
  1414. }
  1415. anc.isConnected = true;
  1416. this.grabItem.endAnchor = anc;
  1417. this.grabItem.anchor2ID = anc.id
  1418. this.grabItem.node2Id = anc.parent.id
  1419. anc.parent.connect('changePos', this.grabItem, this.grabItem.changePos)
  1420. }
  1421. }
  1422. this.grabItem.onMouseUp(event)
  1423. return
  1424. } else {
  1425. if (this.grabItem.status == SItemStatus.Edit) {
  1426. if (this.grabItem.curIndex == 0) {
  1427. if (this.grabItem.startAnchor) {
  1428. this.grabItem.startAnchor.isConnected = false
  1429. this.grabItem.startAnchor.parent.disconnect('changePos', this.grabItem);
  1430. this.grabItem.startAnchor = null;
  1431. this.grabItem.anchor1ID = ''
  1432. this.grabItem.node1Id = ''
  1433. }
  1434. }
  1435. if (this.grabItem.curIndex == this.grabItem.pointList.length - 1) {
  1436. if (this.grabItem.endAnchor) {
  1437. this.grabItem.endAnchor.isConnected = false
  1438. this.grabItem.endAnchor.parent.disconnect('changePos', this.grabItem);
  1439. this.grabItem.endAnchor = null;
  1440. this.grabItem.anchor2ID = ''
  1441. this.grabItem.node2Id = ''
  1442. }
  1443. }
  1444. }
  1445. this.grabItem.onMouseUp(event)
  1446. return
  1447. }
  1448. }
  1449. }
  1450. /**
  1451. * 设置直线结束Item
  1452. *
  1453. */
  1454. setLineItem(event: SMouseEvent): void {
  1455. if (this.grabItem instanceof SLineMarkerItem) {
  1456. const item = this.clickIsItem(event);
  1457. // 鼠标点是否在某个item内
  1458. if (item) {
  1459. let scenePoint = item.boundingRect().center();
  1460. const p = item.mapToScene(scenePoint.x, scenePoint.y);
  1461. event.x = p.x;
  1462. event.y = p.y;
  1463. if (this.grabItem.status == SItemStatus.Create) {
  1464. // 点击在item内、创建状态且端点列表不为空时将直线结束端点和item绑定
  1465. if (this.grabItem.line.length) {
  1466. if (this.grabItem.startItem ?.id == item.id) {
  1467. this.grabItem.endItem = null;
  1468. } else {
  1469. this.grabItem.endItem = item;
  1470. this.grabItem.line[1] = new SPoint(event.x, event.y);
  1471. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1472. }
  1473. }
  1474. this.grabItem.onMouseDown(event);
  1475. return
  1476. } else if (this.grabItem.status == SItemStatus.Edit) {
  1477. // 点击在item内、编辑状态且点击的为结束端点时
  1478. if (this.grabItem.curIndex == 1) {
  1479. // 直线关联的起始item是直线结束端点所在的item时,不吸附在点击item中心并将直线关联的结束item置为null
  1480. if (this.grabItem.startItem ?.id == item.id) {
  1481. this.grabItem.endItem = null;
  1482. } else {// 反正吸附,关联
  1483. this.grabItem.endItem = item;
  1484. this.grabItem.line[1] = new SPoint(event.x, event.y);
  1485. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1486. }
  1487. } else if (this.grabItem.curIndex == 0) {
  1488. if (this.grabItem.endItem ?.id == item.id) {
  1489. this.grabItem.startItem = null;
  1490. } else {
  1491. this.grabItem.startItem = item;
  1492. this.grabItem.line[0] = new SPoint(event.x, event.y);
  1493. item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1494. }
  1495. }
  1496. }
  1497. } else {
  1498. // 如果不在item内且点击的是直线的某个端点,将端点的关联item置为null
  1499. if (this.grabItem.line.length && this.grabItem.curIndex != -1) {
  1500. if (this.grabItem.curIndex == 1) {
  1501. this.grabItem.endItem = null;
  1502. } else if (this.grabItem.curIndex == 0) {
  1503. this.grabItem.startItem = null;
  1504. }
  1505. } else {
  1506. this.grabItem.onMouseDown(event);
  1507. return
  1508. }
  1509. }
  1510. // if (this.grabItem.status == SItemStatus.Create) {
  1511. // // 鼠标点是否在某个item内
  1512. // if (item) {
  1513. // let scenePoint = item.boundingRect().center();
  1514. // const p = item.mapToScene(scenePoint.x, scenePoint.y);
  1515. // event.x = p.x;
  1516. // event.y = p.y;
  1517. // if (this.grabItem.line.length && this.grabItem.curIndex == -1) {
  1518. // this.grabItem.endItem = item;
  1519. // this.grabItem.line[1] = new SPoint(event.x, event.y);
  1520. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1521. // }
  1522. // this.grabItem.onMouseDown(event);
  1523. // return
  1524. // } else {
  1525. // if (this.grabItem.line.length && this.grabItem.curIndex != -1) {
  1526. // if (this.grabItem.curIndex == 1) {
  1527. // this.grabItem.endItem = null;
  1528. // } else if (this.grabItem.curIndex == 0) {
  1529. // this.grabItem.startItem = null;
  1530. // }
  1531. // }
  1532. // }
  1533. // } else if (this.grabItem.status == SItemStatus.Edit) {
  1534. // if (this.grabItem.curIndex == 1) {
  1535. // this.grabItem.endItem = item;
  1536. // this.grabItem.line[1] = new SPoint(event.x, event.y);
  1537. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1538. // } else if (this.grabItem.curIndex == 0) {
  1539. // this.grabItem.startItem = item;
  1540. // this.grabItem.line[0] = new SPoint(event.x, event.y);
  1541. // item.connect('onMove', this.grabItem, this.grabItem.changePos);
  1542. // }
  1543. // }
  1544. this.grabItem.onMouseUp(event);
  1545. }
  1546. }
  1547. /**
  1548. * 划线时点击位置是否是锚点
  1549. *
  1550. * @param event 事件
  1551. * @param len 限制距离
  1552. * @return 点击的锚点
  1553. * */
  1554. clickIsAnchor(event: SMouseEvent): SAnchorItem | null {
  1555. let minAnchor = null;
  1556. let len: number = -1;
  1557. this.Nodes.forEach(image => {
  1558. // image.showAnchor = false;
  1559. if (image.anchorList && image.anchorList.length) {
  1560. if(image.img && image.img instanceof SImageItem) {
  1561. let scenePoint = image.img.mapFromScene(event.x, event.y);
  1562. if (image.img.contains(scenePoint.x, scenePoint.y)) {
  1563. let anchor = image.anchorList[0]
  1564. let anchorPoint = anchor.mapToScene(0, 0);
  1565. let dis = SMathUtil.pointDistance(
  1566. event.x,
  1567. event.y,
  1568. anchorPoint.x,
  1569. anchorPoint.y
  1570. );
  1571. console.log(dis)
  1572. if (len < 0) {
  1573. minAnchor = anchor;
  1574. len = dis;
  1575. }
  1576. if (dis < len) {
  1577. minAnchor = anchor;
  1578. len = dis;
  1579. }
  1580. }
  1581. // let scenePoint = image.mapFromScene(event.x, event.y);
  1582. // if (image.contains(scenePoint.x, scenePoint.y)) {
  1583. // image.anchorList.forEach(anchor => {
  1584. // let anchorPoint = anchor.mapToScene(0, 0);
  1585. // let dis = SMathUtil.pointDistance(
  1586. // event.x,
  1587. // event.y,
  1588. // anchorPoint.x,
  1589. // anchorPoint.y
  1590. // );
  1591. // if (len < 0) {
  1592. // len = anchor.sceneDis;
  1593. // }
  1594. // if (dis < len) {
  1595. // minAnchor = anchor;
  1596. // len = dis;
  1597. // }
  1598. // })
  1599. }
  1600. }
  1601. })
  1602. console.log('-----------------------')
  1603. console.log(minAnchor)
  1604. console.log('-----------------------')
  1605. // if (minAnchor&&minAnchor.parent) {
  1606. // minAnchor.parent.showAnchor = true
  1607. // }
  1608. return minAnchor;
  1609. }
  1610. /**
  1611. * 划线时点击位置是在文本,图片,,区域内
  1612. *
  1613. * @param event 事件
  1614. * @return 点击的item
  1615. * */
  1616. clickIsItem(event: SMouseEvent): SGraphItem | null {
  1617. let minIten = null;
  1618. let len: number = -1;
  1619. let itemList = this.Nodes.concat(this.Markers);
  1620. itemList.forEach(item => {
  1621. if (
  1622. item instanceof STextMarkerItem ||
  1623. item instanceof SImageMarkerItem ||
  1624. item instanceof SZoneLegendItem ||
  1625. item instanceof SFHFQZoneLegendItem ||
  1626. item instanceof SSCPZZoneLegendItem
  1627. ) {
  1628. let scenePoint = item.mapFromScene(event.x, event.y);
  1629. if (item.contains(scenePoint.x, scenePoint.y)) {
  1630. let dis = SMathUtil.pointDistance(
  1631. scenePoint.x,
  1632. scenePoint.y,
  1633. item.boundingRect().center().x,
  1634. item.boundingRect().center().y
  1635. );
  1636. if (len < 0) {
  1637. minIten = item;
  1638. len = dis;
  1639. }
  1640. if (dis < len) {
  1641. minIten = item;
  1642. len = dis;
  1643. }
  1644. }
  1645. }
  1646. })
  1647. console.log('-----------------------')
  1648. console.log(minIten)
  1649. console.log('-----------------------')
  1650. return minIten;
  1651. }
  1652. /**
  1653. * 点是否在吸附区域内
  1654. *
  1655. * @param p 要判断的点
  1656. * @param minX 空间区域
  1657. * @param minY 空间区域
  1658. * @param maxX 空间区域
  1659. * @param maxY 空间区域
  1660. */
  1661. static isPointInAbsorbArea(
  1662. p: SPoint,
  1663. minX: number,
  1664. maxX: number,
  1665. minY: number,
  1666. maxY: number
  1667. ): boolean {
  1668. let rect = new SRect(
  1669. minX - 1000,
  1670. minY - 1000,
  1671. maxX - minX + 2000,
  1672. maxY - minY + 2000
  1673. );
  1674. return rect.contains(p.x, p.y);
  1675. } // Function isPointInAbsorbArea()
  1676. /**
  1677. * 吸附空间
  1678. *
  1679. * @param event 鼠标事件对象
  1680. * @return boolean 是否找到吸附的对象
  1681. */
  1682. absorbSpace(event: SMouseEvent): boolean {
  1683. if (!this.highLight) {
  1684. return false;
  1685. }
  1686. let absorbLen = 1000;
  1687. if (this.view) {
  1688. absorbLen = 10 / this.view.scale;
  1689. }
  1690. let P = this.absorbSpacePoint(event, absorbLen);
  1691. if (P.Point) {
  1692. this.highLight.distance = P.MinDis;
  1693. this.highLight.point = new SPoint(P.Point.X, -P.Point.Y);
  1694. this.highLight.visible = true;
  1695. return true;
  1696. } else {
  1697. let L = this.absorbSpaceLine(event, absorbLen);
  1698. if (L.Line && L.Point) {
  1699. this.highLight.distance = L.MinDis;
  1700. this.highLight.point = L.Point;
  1701. this.highLight.line = L.Line;
  1702. this.highLight.visible = true;
  1703. return true;
  1704. }
  1705. return false;
  1706. }
  1707. } // Function absorbSpace()
  1708. /**
  1709. * 吸附空间点
  1710. *
  1711. * @param event 鼠标事件对象
  1712. * @param absorbLen 吸附距离
  1713. * @return MinDis 吸附的点
  1714. */
  1715. absorbSpacePoint(event: SMouseEvent, absorbLen: number): MinDis {
  1716. let minPointDis = Number.MAX_SAFE_INTEGER;
  1717. let Point;
  1718. this.spaceList.map((space): void => {
  1719. if (
  1720. EditScence.isPointInAbsorbArea(
  1721. new SPoint(event.x, event.y),
  1722. space.minX,
  1723. space.maxX,
  1724. space.minY,
  1725. space.maxY
  1726. )
  1727. ) {
  1728. space.data.OutLine.forEach((item): void => {
  1729. let minDis = SMathUtil.getMinDisPoint(
  1730. new SPoint(event.x, event.y),
  1731. item
  1732. );
  1733. if (
  1734. minDis &&
  1735. minDis.MinDis < absorbLen &&
  1736. minDis.MinDis < minPointDis
  1737. ) {
  1738. minPointDis = minDis.MinDis;
  1739. Point = minDis.Point;
  1740. }
  1741. });
  1742. }
  1743. });
  1744. return {
  1745. MinDis: minPointDis,
  1746. Point: Point
  1747. };
  1748. } // Function absorbSpacePoint()
  1749. /**
  1750. * 吸附空间线
  1751. *
  1752. * @param event 鼠标事件对象
  1753. * @param absorbLen 吸附距离
  1754. * @return PointToLine 吸附的线
  1755. */
  1756. absorbSpaceLine(event: SMouseEvent, absorbLen: number): PointToLine {
  1757. let minPointDis = Number.MAX_SAFE_INTEGER;
  1758. let Point, Line;
  1759. this.spaceList.forEach((space): void => {
  1760. if (
  1761. EditScence.isPointInAbsorbArea(
  1762. new SPoint(event.x, event.y),
  1763. space.minX,
  1764. space.maxX,
  1765. space.minY,
  1766. space.maxY
  1767. )
  1768. ) {
  1769. space.data.OutLine.forEach((item): void => {
  1770. let minDisLine = SMathUtil.getMinDisLine(
  1771. new SPoint(event.x, event.y),
  1772. item
  1773. );
  1774. if (
  1775. minDisLine &&
  1776. minDisLine.MinDis < absorbLen &&
  1777. minDisLine.MinDis < minPointDis
  1778. ) {
  1779. minPointDis = minDisLine.MinDis;
  1780. Point = minDisLine.Point;
  1781. Line = minDisLine.Line;
  1782. }
  1783. });
  1784. }
  1785. });
  1786. return {
  1787. MinDis: minPointDis,
  1788. Point: Point,
  1789. Line: Line
  1790. };
  1791. } // Function absorbSpaceLine()
  1792. /**
  1793. * 添加多个item命令
  1794. * @param focusItemList 鼠标事件对象
  1795. */
  1796. AddListCommand(focusItemList: any[]): void {
  1797. this.undoStack.push(new SGraphAddListCommand(this, focusItemList));
  1798. }
  1799. /**
  1800. * 选中状态方法
  1801. * @param item 鼠标事件对象
  1802. */
  1803. toggleItem(item: SGraphItem): void {
  1804. this.selectContainer.clear()
  1805. this.selectContainer.toggleItem(item)
  1806. }
  1807. /**
  1808. * 图标旋转更新角度
  1809. *
  1810. * @param ang 旋转角度
  1811. */
  1812. updateItemAng(ang: number) :void{
  1813. if (this.focusItem) {
  1814. if (this.focusItem instanceof SImageLegendItem) {
  1815. const oldMsg = this.focusItem.img.rotate;
  1816. const newMsg = ang;
  1817. this.focusItem.img.rotate = ang;
  1818. this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem.img, "rotate", oldMsg, newMsg));
  1819. this.scenceUpdate(this);
  1820. }
  1821. }
  1822. }
  1823. /**
  1824. * 框选
  1825. */
  1826. addRectSelect(event: SMouseEvent) {
  1827. let point = new SPoint(event.x, event.y);
  1828. let rect = new SRectSelectItem(null, point);
  1829. this.addItem(rect);
  1830. this.grabItem = rect;
  1831. }
  1832. /**
  1833. * 计算框选交集
  1834. */
  1835. groupSelect(){
  1836. this.selectContainer.clear()
  1837. if (this.grabItem instanceof SRectSelectItem) {
  1838. const rect = this.grabItem.boundingRect();
  1839. this.arrToSelect(this.Nodes, rect)
  1840. this.arrToSelect(this.Markers, rect)
  1841. this.arrToSelect(this.Relations, rect)
  1842. }
  1843. }
  1844. /**
  1845. * 选中item:框选
  1846. */
  1847. private arrToSelect(arr: SGraphItem[], rect:SRect){
  1848. if(Array.isArray(arr) && arr.length) {
  1849. arr.forEach(t => {
  1850. if (t.parent) {
  1851. let temp = t.boundingRect();
  1852. let lefttop = t.mapToScene(temp.left, temp.top)
  1853. let rightbottom = t.mapToScene(temp.right, temp.bottom)
  1854. let r = new SRect(lefttop, rightbottom)
  1855. if (rect.isIn(r)){
  1856. this.selectContainer.toggleItem(t)
  1857. }
  1858. }
  1859. })
  1860. }
  1861. }
  1862. }