EditScence.ts 60 KB

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