SPlanEquipment.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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) 2016-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import { SGraphItem, SAnchorItem } from "@persagy-web/graph/lib";
  27. import { SPoint, SPainter, SColor } from "@persagy-web/draw";
  28. import { Example } from "../index";
  29. import { SBaseIconTextEdit, SBaseTextEdit } from "@persagy-web/edit";
  30. import { svgTobase64, uuid } from "@persagy-web/big-edit/lib/until";
  31. /**
  32. * 编辑基础设备类
  33. *
  34. * @author 张宇 <taohuzy@163.com>
  35. */
  36. export class SPlanEquipment extends SBaseIconTextEdit {
  37. /** 设备图例 */
  38. private _legendData: Example | null = null;
  39. set legendData(val) {
  40. this._legendData = val;
  41. this.initData();
  42. } // set legendData()
  43. get legendData(): Example | null {
  44. return this._legendData;
  45. } // get legendData()
  46. // 文件服务器key值
  47. defaultUrl: string = "";
  48. /** 图例url */
  49. private _url: string = "";
  50. set url(val) {
  51. this._url = val;
  52. this.initUrl();
  53. } // set url()
  54. get url(): string {
  55. return this._url;
  56. } // get url()
  57. /** 与BIM坐标关系连线的颜色 */
  58. _lineColor: SColor = new SColor("#F54E45ff");
  59. get lineColor(): SColor {
  60. return this._lineColor;
  61. }
  62. set lineColor(v: SColor) {
  63. this._lineColor = v;
  64. this.update();
  65. }
  66. /** 是否显示与BIM坐标的关系 */
  67. _showLine: boolean = false;
  68. get showLine(): boolean {
  69. return this._showLine;
  70. }
  71. set showLine(v: boolean) {
  72. if (v === this._showLine) {
  73. return;
  74. }
  75. this._showLine = v;
  76. this.update();
  77. }
  78. /** 公式 */
  79. private _formula: any[] = [];
  80. // private _formula: string = "";
  81. set formula(val) {
  82. this._formula = val;
  83. try {
  84. // const textList = JSON.parse(this._formula);
  85. if (this.scene) {
  86. this.textItemList.forEach((textItem) => {
  87. this.scene?.removeItem(textItem);
  88. });
  89. }
  90. if (this._formula.length) {
  91. // if (textList.length) {
  92. const textItemList: any[] = [];
  93. this._formula.forEach((item: any, index: number) => {
  94. // textList.forEach((item: any, index: number) => {
  95. let obj = new SBaseTextEdit(this, null);
  96. obj.propertyData = { ...item };
  97. obj.text = item.name;
  98. if (item.pos) {
  99. obj.moveTo(item.pos.x, item.pos.y);
  100. } else {
  101. obj.moveTo(this.img.width * 0.5, this.font.size * (index - 0.125 - 0.5 * this._formula.length));
  102. }
  103. // TODO: obj.moveTo(this.img.width * 0.5, -(this.font.size * 1.25 * 0.5) + (index * this.font.size) - (textList.length - 1) * 0.5 * this.font.size);
  104. // obj.moveTo(this.img.width * 0.5, this.font.size * (index - 0.125 - 0.5 * textList.length));
  105. obj.connect("onMove", this, this.textMove.bind(this));
  106. obj.font = this.font;
  107. obj.color = this.color;
  108. obj.isTransform = false;
  109. obj.showSelect = false;
  110. textItemList.push(obj);
  111. });
  112. this.textItemList = textItemList;
  113. } else {
  114. this.textItemList = [];
  115. }
  116. this.update();
  117. } catch (error) {
  118. console.error("公式数据错误", error);
  119. }
  120. } // set formula()
  121. // get formula(): string {
  122. get formula(): any[] {
  123. return this._formula;
  124. } // get formula()
  125. // 设备附加数据
  126. anotherMsg: string = "";
  127. /**
  128. * 构造函数
  129. *
  130. * @param parent 指向父对象
  131. * @param data 数据
  132. */
  133. constructor(parent: SGraphItem | null, data: Example) {
  134. super(parent);
  135. this.zOrder = 9700;
  136. this.isTransform = false;
  137. this.sWidth = 32;
  138. this.sHeight = 32;
  139. this.img.showSelect = false;
  140. this.moveable = true;
  141. this.selectable = true;
  142. this.legendData = data;
  143. } // Constructor
  144. /**
  145. * 设置 legendData 时对 item 做设置
  146. */
  147. initData() {
  148. if (!this.legendData) return;
  149. if (this.legendData.size) {
  150. this.sWidth = this.legendData.size.width;
  151. this.sHeight = this.legendData.size.height;
  152. }
  153. this.img.connect("onMove", this, this.changeAnchorPoint.bind(this));
  154. if (this.legendData.anchorList && this.legendData.anchorList.length) {
  155. this.anchorList = this.legendData.anchorList.map((t) => {
  156. let item = new SAnchorItem(this);
  157. if (t.anchorId) {
  158. item.id = t.anchorId;
  159. }
  160. item.moveTo(t.pos.x, t.pos.y);
  161. return item;
  162. });
  163. } else {
  164. const anchorPoint = [{ x: this.img.x, y: this.img.y, anchorId: uuid() }];
  165. this.anchorList = anchorPoint.map((t) => {
  166. let item = new SAnchorItem(this);
  167. if (t.anchorId) {
  168. item.id = t.anchorId;
  169. }
  170. item.moveTo(t.x, t.y);
  171. return item;
  172. });
  173. }
  174. this.id = this.legendData.id ? this.legendData.id : "";
  175. this.showAnchor = false;
  176. this.anotherMsg = this.legendData?.properties?.anotherMsg ? this.legendData.properties.anotherMsg : "";
  177. if (this.legendData.pos?.x && this.legendData.pos?.y) {
  178. this.x = this.legendData.pos.x;
  179. this.y = this.legendData.pos.y;
  180. }
  181. }
  182. initUrl() {
  183. svgTobase64(this.url)
  184. .then((res) => {
  185. this.img.url = res ? res : "";
  186. })
  187. .catch((res) => {
  188. this.img.url = res;
  189. });
  190. }
  191. /**
  192. * 文本位置移动回调函数
  193. * @param textItem 移动的文本元素
  194. * @param pointList 移动前后位置坐标信息
  195. */
  196. textMove(textItem: SBaseTextEdit, pointList: SPoint[]) {
  197. this.moveText();
  198. }
  199. moveText() {}
  200. /**
  201. * 返回对象储存的相关数据
  202. *
  203. * @return 对象储存的相关数据
  204. */
  205. toData(): any {
  206. if (this.legendData) {
  207. // 位置
  208. const objExtInfo = {
  209. attachObjectIds: [this.id],
  210. pos: this.pos,
  211. properties: {
  212. id: this.id,
  213. anotherMsg: this.anotherMsg,
  214. },
  215. };
  216. return objExtInfo;
  217. }
  218. return new Object();
  219. }
  220. /**
  221. * Item 绘制操作
  222. *
  223. * @param painter 绘制对象
  224. */
  225. onDraw(painter: SPainter): void {
  226. if (this.showLine && this.legendData?.bimLocation && this.legendData?.locationJson) {
  227. const bimX = (this.legendData.locationJson.x - this.x) / this.inverseScale;
  228. const bimY = (-this.legendData.locationJson.y - this.y) / this.inverseScale;
  229. const bimColor = new SColor(this.lineColor);
  230. bimColor.alpha = 51;
  231. painter.pen.color = this.lineColor;
  232. painter.pen.lineWidth = 1
  233. painter.drawLine(0, 0, bimX, bimY);
  234. painter.pen.color = SColor.Transparent;
  235. painter.brush.color = bimColor;
  236. painter.drawCircle(bimX, bimY, 5);
  237. painter.brush.color = this.lineColor;
  238. painter.drawCircle(bimX, bimY, 2);
  239. }
  240. super.onDraw(painter);
  241. } // Function onDraw()
  242. }