SPlanScene.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*
  2. * *********************************************************************************************************************
  3. *
  4. * !!
  5. * .F88X
  6. * X8888Y
  7. * .}888888N;
  8. * i888888N; .:! .I$WI:
  9. * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
  10. * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
  11. * +888888N; .8888888Y "&&8Y.}8,
  12. * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
  13. * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
  14. * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
  15. * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
  16. * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
  17. * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
  18. * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
  19. * .:R888888I
  20. * .&888888I Copyright (c) 2009-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * ****/
  25. import { SBaseEditScene, SBasePipe, SBaseEquipment } from "@persagy-web/big-edit";
  26. import { SGraphEdit, SGraphPropertyCommand } from "@persagy-web/edit";
  27. import { SMouseEvent } from "@persagy-web/base/lib";
  28. import { SGraphSelectContainer, SLineStyle } from "@persagy-web/graph";
  29. import { SItemStatus } from "@persagy-web/big/lib/enums/SItemStatus";
  30. import { rgbaNum } from "@persagy-web/big-edit/lib/until";
  31. // 引入命令
  32. import { SGraphAddCommand } from "@persagy-web/edit/lib/commands/SGraphAddCommand";
  33. import { SColor, SFont, SArrowStyleType } from "@persagy-web/draw/lib";
  34. import { SPlanParser } from "./";
  35. /**
  36. * 平面图场景类
  37. *
  38. * @author 张宇 <taohuzy@163.com>
  39. */
  40. export class SPlanScene extends SBaseEditScene {
  41. /** 图例数据 */
  42. legendObj: any = null;
  43. constructor() {
  44. super();
  45. // 选择绑定选额item事件
  46. this.selectContainer.connect("listChange", this, this.listChange);
  47. }
  48. /**
  49. * 选中返回的选中 item 回调方法
  50. *
  51. * @param event 鼠标事件参数
  52. */
  53. listChange(list: any): void {
  54. const itemList: any = [];
  55. list.itemList.forEach((item: any) => {
  56. if (item instanceof SGraphEdit && !(item instanceof SGraphSelectContainer)) {
  57. itemList.push(item);
  58. }
  59. });
  60. this.emitChoice(itemList);
  61. }
  62. /**
  63. * 选中返回的选中 item 回调方法(用于场景的外部调用)
  64. *
  65. * @param list 选中的 item 数组
  66. */
  67. emitChoice(list: any) {}
  68. /**
  69. * 鼠标左键按下
  70. *
  71. * @param event 鼠标事件参数
  72. */
  73. onMouseDown(event: SMouseEvent): any {
  74. this.vueOnMouseDown(event); //外部调用
  75. if (this.grabItem) {
  76. if (this.grabItem instanceof SBasePipe) {
  77. this.setTipeEndanchor(event);
  78. return true;
  79. }
  80. return this.grabItem.onMouseDown(event);
  81. }
  82. if (this.editCmd == "EditBaseLine") {
  83. this.addPolyLineArrow(event);
  84. this.clearCmdStatus();
  85. } else if (this.editCmd == "EditBasePolyLine") {
  86. this.addPolyLine(event);
  87. this.clearCmdStatus();
  88. } else if (this.editCmd == "EditBasetext") {
  89. this.addTextItem(event);
  90. this.clearCmdStatus();
  91. } else if (this.editCmd == "BaseExplain") {
  92. this.addExplainItem(event);
  93. this.clearCmdStatus();
  94. } else if (this.editCmd == "EditBaseImage") {
  95. this.addImageItem(event);
  96. this.clearCmdStatus();
  97. } else if (this.editCmd == "EditBasePolygon") {
  98. this.addPolygonItem(event);
  99. this.clearCmdStatus();
  100. } else if (this.editCmd == "EditBaseRect") {
  101. this.addRectItem(event);
  102. this.clearCmdStatus();
  103. } else if (this.editCmd == "EditBaseTriangle") {
  104. this.addTriangleItem(event);
  105. this.clearCmdStatus();
  106. } else if (this.editCmd == "EditBaseCircle") {
  107. this.addCircleItem(event);
  108. this.clearCmdStatus();
  109. } else if (this.editCmd == "EditBaseArrows") {
  110. this.addPolygonArrow(event);
  111. this.clearCmdStatus();
  112. } else if (this.editCmd == "wantou" || this.editCmd == "santong" || this.editCmd == "sitong") {
  113. this.addPipeUninTool(event, this.editCmd);
  114. this.clearCmdStatus();
  115. } else if (this.editCmd == "EditBasePipe") {
  116. this.addBasePipe(event, this.legendObj);
  117. this.clearCmdStatus();
  118. } else if (this.editCmd == "") {
  119. super.onMouseDown(event);
  120. }
  121. }
  122. /**
  123. * 鼠标右键事件
  124. *
  125. * @param event 鼠标事件参数
  126. * @returns 是否点击右键
  127. */
  128. onContextMenu(event: SMouseEvent): boolean {
  129. if (!super.onContextMenu(event)) {
  130. this.getItem(null, [event]);
  131. }
  132. return true;
  133. }
  134. /**
  135. * 修改 item 样式,数据等方法
  136. *
  137. * @param styletype string 修改样式类型
  138. * @param changeStyle 更改样式数据
  139. * @param itemList ? SGraphEdit[] 如果不传入默认使用选择器中选中得item
  140. */
  141. updateStyle(styletype: string, changestyle: any, itemList?: SGraphEdit[]): void {
  142. // 如果未传入需要修改样式的item,默认取选择器中的item
  143. let List = null;
  144. if (itemList && itemList.length) {
  145. List = itemList;
  146. } else {
  147. List = this.selectContainer.itemList;
  148. }
  149. let styleValue: any;
  150. if (styletype == "strokeColor" || styletype == "backgroundColor" || styletype == "fillColor") {
  151. const colorlist = rgbaNum(changestyle);
  152. styleValue = new SColor(Number(colorlist[0]), Number(colorlist[1]), Number(colorlist[2]), colorlist[3] * 255);
  153. } else if (styletype == "lineStyle") {
  154. styleValue = SLineStyle[changestyle];
  155. } else if (styletype == "begin" || styletype == "end") {
  156. styleValue = SArrowStyleType[changestyle];
  157. } else if (styletype == "font") {
  158. styleValue = new SFont("sans-serif", changestyle);
  159. } else {
  160. styleValue = changestyle;
  161. }
  162. List.forEach((item: SGraphEdit, index: number) => {
  163. if (item instanceof SGraphSelectContainer) {
  164. return;
  165. }
  166. const oldMsg = item[styletype];
  167. const newMsg = styleValue;
  168. this.undoStack.push(new SGraphPropertyCommand(this, item, styletype, oldMsg, newMsg));
  169. item[styletype] = styleValue;
  170. });
  171. }
  172. /**
  173. * 修改指定设备得信息点
  174. *
  175. * @param obj Object 信息点
  176. */
  177. changeEquipMsgPoint(obj: any): void {
  178. const List = this.selectContainer.itemList.length ? this.selectContainer.itemList[0] : null;
  179. if (List && List instanceof SBaseEquipment) {
  180. List.setMsgPoint(obj);
  181. }
  182. }
  183. /**
  184. * item 创建完成后回调
  185. *
  186. * @param event 鼠标事件参数
  187. */
  188. finishCreated(item: SGraphEdit): void {
  189. this.grabItem = null;
  190. item.status = SItemStatus.Normal;
  191. this.undoStack.push(new SGraphAddCommand(this, item));
  192. this.selectContainer.clear();
  193. this.selectContainer.toggleItem(item);
  194. }
  195. /**
  196. * 修改 cmdstatus 函数;常在在业务中调用
  197. */
  198. clearCmdStatus() {
  199. //do something
  200. }
  201. /**
  202. * 获取item (常用与场景外的调用F)
  203. * @param event SMouseEvent 鼠标事件
  204. * @param item SGraphEdit|null 返回item
  205. *
  206. */
  207. getItem(item: SGraphEdit | null, event: SMouseEvent[]): void {
  208. // do something
  209. }
  210. /**
  211. * 获取item (常用与场景外的调用F)
  212. * @param event SMouseEvent 鼠标事件
  213. * @param item SGraphEdit|null 返回item
  214. *
  215. */
  216. vueOnMouseDown(event: SMouseEvent) {
  217. // do something
  218. }
  219. /**
  220. * 设置 item 状态
  221. */
  222. setItemStatus() {
  223. const List = this.selectContainer.itemList[0];
  224. if (List && List instanceof SGraphEdit) {
  225. if (List.status == SItemStatus.Normal) {
  226. List.status = SItemStatus.Edit;
  227. this.grabItem = List;
  228. } else {
  229. List.status = SItemStatus.Normal;
  230. this.grabItem = null;
  231. }
  232. }
  233. }
  234. /**
  235. * 获取item (常用与场景外的调用F)
  236. *
  237. * @params isAll 是否为全部item数据
  238. * @return obj 返回保存的数据接口
  239. */
  240. save(isAll: boolean = true) {
  241. if (!this.view) return;
  242. const Marktype: string[] = [
  243. "BasePolygon",
  244. "BaseLine",
  245. "BaseText",
  246. "BaseExplain",
  247. "BaseImage",
  248. "BaseCircle",
  249. "BaseArrow",
  250. "BaseTriangle",
  251. "BaseRect",
  252. "BaseArrowPolygon",
  253. ];
  254. const NodeType: string[] = ["BaseEquipment"];
  255. const RelationType: string[] = ["BasePipe"];
  256. const markers: any = []; /**图例节点 */ // 与工程信息无关的标识对象(增加文本注释,图上的图片说明)
  257. const nodes: any = []; /**图例节点 */ // 与工程信息无关的标识对象(增加文本注释,图上的图片说明)
  258. const relations: any = []; /**图例节点 */ // 与工程信息无关的标识对象(增加文本注释,图上的图片说明)
  259. let nodeList;
  260. if (isAll) {
  261. nodeList = this.root.children;
  262. } else {
  263. nodeList = this.selectContainer.itemList;
  264. }
  265. nodeList.forEach((item) => {
  266. if (item instanceof SGraphEdit && !(item instanceof SGraphSelectContainer)) {
  267. // 添加节点数据
  268. if (item.data && Marktype.includes(item.data.properties.type)) {
  269. markers.push(item.toData());
  270. }
  271. if (item.legendData && NodeType.includes(item.legendData.properties.type)) {
  272. nodes.push(item.toData());
  273. }
  274. if (item.relationData && RelationType.includes(item.relationData.properties.type)) {
  275. relations.push(item.toData());
  276. }
  277. }
  278. });
  279. return {
  280. markers,
  281. nodes,
  282. relations,
  283. };
  284. }
  285. /**
  286. * 粘贴
  287. */
  288. paste(): void {
  289. const copyList = JSON.parse(JSON.stringify(this.copyString));
  290. const parserData = new SPlanParser();
  291. const graphItemList: SGraphEdit[] = [];
  292. parserData.parseData(copyList);
  293. parserData.markers.forEach((item: SGraphEdit) => {
  294. item.selectable = true;
  295. item.moveable = true;
  296. if (this.view) {
  297. item.pos.x += 10 / this.view.scale;
  298. item.pos.y += 10 / this.view.scale;
  299. }
  300. this.addItem(item);
  301. graphItemList.push(item);
  302. });
  303. this.addListCommand(graphItemList);
  304. this.view ? this.view.update() : "";
  305. }
  306. }