EditScence.ts 72 KB

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