EditScence.ts 52 KB

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