mxElectrical.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /**
  2. * $Id: mxElectrical.js,v 1.0 2016/10/25 17:05:39 mate Exp $
  3. * Copyright (c) 2006-2016, JGraph Ltd
  4. */
  5. //**********************************************************************************************************************************************************
  6. //Test Point
  7. //**********************************************************************************************************************************************************
  8. /**
  9. * Extends mxShape.
  10. */
  11. function mxShapeElectricalTestPoint(bounds, fill, stroke, strokewidth)
  12. {
  13. mxShape.call(this);
  14. this.bounds = bounds;
  15. this.fill = fill;
  16. this.stroke = stroke;
  17. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  18. };
  19. /**
  20. * Extends mxShape.
  21. */
  22. mxUtils.extend(mxShapeElectricalTestPoint, mxShape);
  23. mxShapeElectricalTestPoint.prototype.cst = {
  24. SHAPE_TEST_POINT : 'mxgraph.electrical.transmission.testPoint'
  25. };
  26. /**
  27. * Function: paintVertexShape
  28. *
  29. * Paints the vertex shape.
  30. */
  31. mxShapeElectricalTestPoint.prototype.paintVertexShape = function(c, x, y, w, h)
  32. {
  33. c.translate(x, y);
  34. var strokeColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, '#000000');
  35. var size = Math.min(w, h);
  36. c.setFillColor(strokeColor);
  37. c.begin();
  38. c.ellipse(w * 0.5 - size / 2, 0, size, size);
  39. c.fillAndStroke();
  40. if (h > w)
  41. {
  42. c.begin();
  43. c.moveTo(w * 0.5, size);
  44. c.lineTo(w * 0.5, h);
  45. c.stroke();
  46. }
  47. };
  48. mxCellRenderer.prototype.defaultShapes[mxShapeElectricalTestPoint.prototype.cst.SHAPE_TEST_POINT] = mxShapeElectricalTestPoint;
  49. mxShapeElectricalTestPoint.prototype.constraints = [
  50. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  51. new mxConnectionConstraint(new mxPoint(0.5, 1), true)
  52. ];
  53. //**********************************************************************************************************************************************************
  54. //Straight Bus
  55. //**********************************************************************************************************************************************************
  56. /**
  57. * Extends mxShape.
  58. */
  59. function mxShapeElectricalStraightBus(bounds, fill, stroke, strokewidth)
  60. {
  61. mxShape.call(this);
  62. this.bounds = bounds;
  63. this.fill = fill;
  64. this.stroke = stroke;
  65. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  66. };
  67. /**
  68. * Extends mxShape.
  69. */
  70. mxUtils.extend(mxShapeElectricalStraightBus, mxShape);
  71. mxShapeElectricalStraightBus.prototype.cst = {
  72. SHAPE_STRAIGHT_BUS : 'mxgraph.electrical.transmission.straightBus'
  73. };
  74. /**
  75. * Function: paintVertexShape
  76. *
  77. * Paints the vertex shape.
  78. */
  79. mxShapeElectricalStraightBus.prototype.paintVertexShape = function(c, x, y, w, h)
  80. {
  81. c.translate(x, y);
  82. var size = Math.min(w, h);
  83. var x1 = w * 0.2;
  84. var y1 = 0;
  85. if (w > h)
  86. {
  87. y1 = h * 0.5;
  88. }
  89. else
  90. {
  91. y1 = w / 2;
  92. }
  93. c.begin();
  94. c.moveTo(w - x1, 0);
  95. c.lineTo(w - x1, h - y1);
  96. c.lineTo(w, h - y1);
  97. c.lineTo(w * 0.5, h);
  98. c.lineTo(0, h - y1);
  99. c.lineTo(x1, h - y1);
  100. c.lineTo(x1, 0);
  101. c.fillAndStroke();
  102. };
  103. mxCellRenderer.prototype.defaultShapes[mxShapeElectricalStraightBus.prototype.cst.SHAPE_STRAIGHT_BUS] = mxShapeElectricalStraightBus;
  104. mxShapeElectricalStraightBus.prototype.constraints = [
  105. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  106. new mxConnectionConstraint(new mxPoint(0.5, 1), true)
  107. ];
  108. //**********************************************************************************************************************************************************
  109. //Two-Line Bus Elbow
  110. //**********************************************************************************************************************************************************
  111. /**
  112. * Extends mxShape.
  113. */
  114. function mxShapeElectricalTwoLineBusElbow(bounds, fill, stroke, strokewidth)
  115. {
  116. mxShape.call(this);
  117. this.bounds = bounds;
  118. this.fill = fill;
  119. this.stroke = stroke;
  120. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  121. this.notch = 0;
  122. };
  123. /**
  124. * Extends mxShape.
  125. */
  126. mxUtils.extend(mxShapeElectricalTwoLineBusElbow, mxShape);
  127. mxShapeElectricalTwoLineBusElbow.prototype.cst = {
  128. SHAPE_TWO_LINE_BUS_ELBOW : 'mxgraph.electrical.transmission.twoLineBusElbow'
  129. };
  130. /**
  131. * Function: paintVertexShape
  132. *
  133. * Paints the vertex shape.
  134. */
  135. mxShapeElectricalTwoLineBusElbow.prototype.paintVertexShape = function(c, x, y, w, h)
  136. {
  137. var notch = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'notch', this.notch))));
  138. c.translate(x, y);
  139. c.begin();
  140. c.moveTo(0, h);
  141. c.lineTo(w, h);
  142. c.lineTo(w, 0);
  143. c.stroke();
  144. var wn = Math.min(w, notch);
  145. var hn = Math.min(h, notch);
  146. c.begin();
  147. c.moveTo(0, h - hn);
  148. c.lineTo(w - wn, h - hn);
  149. c.lineTo(w - wn, 0);
  150. c.stroke();
  151. };
  152. mxCellRenderer.prototype.defaultShapes[mxShapeElectricalTwoLineBusElbow.prototype.cst.SHAPE_TWO_LINE_BUS_ELBOW] = mxShapeElectricalTwoLineBusElbow;
  153. mxShapeElectricalTwoLineBusElbow.prototype.constraints = null;
  154. Graph.handleFactory[mxShapeElectricalTwoLineBusElbow.prototype.cst.SHAPE_TWO_LINE_BUS_ELBOW] = function(state)
  155. {
  156. var handles = [Graph.createHandle(state, ['notch'], function(bounds)
  157. {
  158. var notch = Math.max(Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'notch', this.notch))), 0);
  159. return new mxPoint(bounds.x + bounds.width / 4, bounds.y + bounds.height - notch);
  160. }, function(bounds, pt)
  161. {
  162. this.state.style['notch'] = Math.round(0.2 * Math.max(0, bounds.width - pt.y + bounds.y)) / 0.2;
  163. })];
  164. return handles;
  165. }
  166. //**********************************************************************************************************************************************************
  167. //Three-Line Bus Elbow
  168. //**********************************************************************************************************************************************************
  169. /**
  170. * Extends mxShape.
  171. */
  172. function mxShapeElectricalThreeLineBusElbow(bounds, fill, stroke, strokewidth)
  173. {
  174. mxShape.call(this);
  175. this.bounds = bounds;
  176. this.fill = fill;
  177. this.stroke = stroke;
  178. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  179. this.notch = 0;
  180. };
  181. /**
  182. * Extends mxShape.
  183. */
  184. mxUtils.extend(mxShapeElectricalThreeLineBusElbow, mxShape);
  185. mxShapeElectricalThreeLineBusElbow.prototype.cst = {
  186. SHAPE_THREE_LINE_BUS_ELBOW : 'mxgraph.electrical.transmission.threeLineBusElbow'
  187. };
  188. /**
  189. * Function: paintVertexShape
  190. *
  191. * Paints the vertex shape.
  192. */
  193. mxShapeElectricalThreeLineBusElbow.prototype.paintVertexShape = function(c, x, y, w, h)
  194. {
  195. var notch = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'notch', this.notch))));
  196. c.translate(x, y);
  197. c.begin();
  198. c.moveTo(0, h);
  199. c.lineTo(w, h);
  200. c.lineTo(w, 0);
  201. c.stroke();
  202. var wn = Math.min(w, notch);
  203. var hn = Math.min(h, notch);
  204. c.begin();
  205. c.moveTo(0, h - hn);
  206. c.lineTo(w - wn, h - hn);
  207. c.lineTo(w - wn, 0);
  208. c.stroke();
  209. c.begin();
  210. c.moveTo(0, h - hn / 2);
  211. c.lineTo(w - wn / 2, h - hn / 2);
  212. c.lineTo(w - wn / 2, 0);
  213. c.stroke();
  214. };
  215. mxCellRenderer.prototype.defaultShapes[mxShapeElectricalThreeLineBusElbow.prototype.cst.SHAPE_THREE_LINE_BUS_ELBOW] = mxShapeElectricalThreeLineBusElbow;
  216. mxShapeElectricalThreeLineBusElbow.prototype.constraints = null;
  217. Graph.handleFactory[mxShapeElectricalThreeLineBusElbow.prototype.cst.SHAPE_THREE_LINE_BUS_ELBOW] = function(state)
  218. {
  219. var handles = [Graph.createHandle(state, ['notch'], function(bounds)
  220. {
  221. var notch = Math.max(Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'notch', this.notch))), 0);
  222. return new mxPoint(bounds.x + bounds.width / 4, bounds.y + bounds.height - notch);
  223. }, function(bounds, pt)
  224. {
  225. this.state.style['notch'] = Math.round(0.2 * Math.max(0, bounds.width - pt.y + bounds.y)) / 0.2;
  226. })];
  227. return handles;
  228. }
  229. //**********************************************************************************************************************************************************
  230. //Four-Line Bus Elbow
  231. //**********************************************************************************************************************************************************
  232. /**
  233. * Extends mxShape.
  234. */
  235. function mxShapeElectricalFourLineBusElbow(bounds, fill, stroke, strokewidth)
  236. {
  237. mxShape.call(this);
  238. this.bounds = bounds;
  239. this.fill = fill;
  240. this.stroke = stroke;
  241. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  242. this.notch = 0;
  243. };
  244. /**
  245. * Extends mxShape.
  246. */
  247. mxUtils.extend(mxShapeElectricalFourLineBusElbow, mxShape);
  248. mxShapeElectricalFourLineBusElbow.prototype.cst = {
  249. SHAPE_FOUR_LINE_BUS_ELBOW : 'mxgraph.electrical.transmission.fourLineBusElbow'
  250. };
  251. /**
  252. * Function: paintVertexShape
  253. *
  254. * Paints the vertex shape.
  255. */
  256. mxShapeElectricalFourLineBusElbow.prototype.paintVertexShape = function(c, x, y, w, h)
  257. {
  258. var notch = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'notch', this.notch))));
  259. c.translate(x, y);
  260. c.begin();
  261. c.moveTo(0, h);
  262. c.lineTo(w, h);
  263. c.lineTo(w, 0);
  264. c.stroke();
  265. var wn = Math.min(w, notch);
  266. var hn = Math.min(h, notch);
  267. c.begin();
  268. c.moveTo(0, h - hn);
  269. c.lineTo(w - wn, h - hn);
  270. c.lineTo(w - wn, 0);
  271. c.stroke();
  272. c.begin();
  273. c.moveTo(0, h - hn / 3);
  274. c.lineTo(w - wn / 3, h - hn / 3);
  275. c.lineTo(w - wn / 3, 0);
  276. c.stroke();
  277. c.begin();
  278. c.moveTo(0, h - hn * 2 / 3);
  279. c.lineTo(w - wn * 2 / 3, h - hn * 2 / 3);
  280. c.lineTo(w - wn * 2 / 3, 0);
  281. c.stroke();
  282. };
  283. mxCellRenderer.prototype.defaultShapes[mxShapeElectricalFourLineBusElbow.prototype.cst.SHAPE_FOUR_LINE_BUS_ELBOW] = mxShapeElectricalFourLineBusElbow;
  284. mxShapeElectricalFourLineBusElbow.prototype.constraints = null;
  285. Graph.handleFactory[mxShapeElectricalFourLineBusElbow.prototype.cst.SHAPE_FOUR_LINE_BUS_ELBOW] = function(state)
  286. {
  287. var handles = [Graph.createHandle(state, ['notch'], function(bounds)
  288. {
  289. var notch = Math.max(Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'notch', this.notch))), 0);
  290. return new mxPoint(bounds.x + bounds.width / 4, bounds.y + bounds.height - notch);
  291. }, function(bounds, pt)
  292. {
  293. this.state.style['notch'] = Math.round(0.2 * Math.max(0, bounds.width - pt.y + bounds.y)) / 0.2;
  294. })];
  295. return handles;
  296. }
  297. //**********************************************************************************************************************************************************
  298. //Four-Line Bus Elbow
  299. //**********************************************************************************************************************************************************
  300. /**
  301. * Extends mxShape.
  302. */
  303. function mxShapeElectricalEightLineBusElbow(bounds, fill, stroke, strokewidth)
  304. {
  305. mxShape.call(this);
  306. this.bounds = bounds;
  307. this.fill = fill;
  308. this.stroke = stroke;
  309. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  310. this.notch = 0;
  311. };
  312. /**
  313. * Extends mxShape.
  314. */
  315. mxUtils.extend(mxShapeElectricalEightLineBusElbow, mxShape);
  316. mxShapeElectricalEightLineBusElbow.prototype.cst = {
  317. SHAPE_EIGHT_LINE_BUS_ELBOW : 'mxgraph.electrical.transmission.eightLineBusElbow'
  318. };
  319. /**
  320. * Function: paintVertexShape
  321. *
  322. * Paints the vertex shape.
  323. */
  324. mxShapeElectricalEightLineBusElbow.prototype.paintVertexShape = function(c, x, y, w, h)
  325. {
  326. var notch = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'notch', this.notch))));
  327. c.translate(x, y);
  328. c.begin();
  329. c.moveTo(0, h);
  330. c.lineTo(w, h);
  331. c.lineTo(w, 0);
  332. c.stroke();
  333. var wn = Math.min(w, notch);
  334. var hn = Math.min(h, notch);
  335. c.begin();
  336. c.moveTo(0, h - hn);
  337. c.lineTo(w - wn, h - hn);
  338. c.lineTo(w - wn, 0);
  339. c.stroke();
  340. c.begin();
  341. c.moveTo(0, h - hn / 7);
  342. c.lineTo(w - wn / 7, h - hn / 7);
  343. c.lineTo(w - wn / 7, 0);
  344. c.stroke();
  345. c.begin();
  346. c.moveTo(0, h - hn * 2 / 7);
  347. c.lineTo(w - wn * 2 / 7, h - hn * 2 / 7);
  348. c.lineTo(w - wn * 2 / 7, 0);
  349. c.stroke();
  350. c.begin();
  351. c.moveTo(0, h - hn * 3 / 7);
  352. c.lineTo(w - wn * 3 / 7, h - hn * 3 / 7);
  353. c.lineTo(w - wn * 3 / 7, 0);
  354. c.stroke();
  355. c.begin();
  356. c.moveTo(0, h - hn * 4 / 7);
  357. c.lineTo(w - wn * 4 / 7, h - hn * 4 / 7);
  358. c.lineTo(w - wn * 4 / 7, 0);
  359. c.stroke();
  360. c.begin();
  361. c.moveTo(0, h - hn * 5 / 7);
  362. c.lineTo(w - wn * 5 / 7, h - hn * 5 / 7);
  363. c.lineTo(w - wn * 5 / 7, 0);
  364. c.stroke();
  365. c.begin();
  366. c.moveTo(0, h - hn * 6 / 7);
  367. c.lineTo(w - wn * 6 / 7, h - hn * 6 / 7);
  368. c.lineTo(w - wn * 6 / 7, 0);
  369. c.stroke();
  370. };
  371. mxCellRenderer.prototype.defaultShapes[mxShapeElectricalEightLineBusElbow.prototype.cst.SHAPE_EIGHT_LINE_BUS_ELBOW] = mxShapeElectricalEightLineBusElbow;
  372. mxShapeElectricalEightLineBusElbow.prototype.constraints = null;
  373. Graph.handleFactory[mxShapeElectricalEightLineBusElbow.prototype.cst.SHAPE_EIGHT_LINE_BUS_ELBOW] = function(state)
  374. {
  375. var handles = [Graph.createHandle(state, ['notch'], function(bounds)
  376. {
  377. var notch = Math.max(Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'notch', this.notch))), 0);
  378. return new mxPoint(bounds.x + bounds.width / 4, bounds.y + bounds.height - notch);
  379. }, function(bounds, pt)
  380. {
  381. this.state.style['notch'] = Math.round(0.2 * Math.max(0, bounds.width - pt.y + bounds.y)) / 0.2;
  382. })];
  383. return handles;
  384. }