mxPidMisc.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /**
  2. * $Id: mxPidMisc.js,v 1.4 2013/11/22 10:46:56 mate Exp $
  3. * Copyright (c) 2006-2013, JGraph Ltd
  4. */
  5. //**********************************************************************************************************************************************************
  6. //Fan
  7. //**********************************************************************************************************************************************************
  8. /**
  9. * Extends mxShape.
  10. */
  11. function mxShapePidFan(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(mxShapePidFan, mxShape);
  23. mxShapePidFan.prototype.cst = {
  24. SHAPE_FAN : 'mxgraph.pid2misc.fan',
  25. FAN_TYPE : 'fanType',
  26. COMMON : 'common',
  27. AXIAL : 'axial',
  28. RADIAL : 'radial'
  29. };
  30. /**
  31. * Function: paintVertexShape
  32. *
  33. * Paints the vertex shape.
  34. */
  35. mxShapePidFan.prototype.paintVertexShape = function(c, x, y, w, h)
  36. {
  37. c.translate(x, y);
  38. this.background(c, x, y, w, h);
  39. c.setShadow(false);
  40. this.foreground(c, x, y, w, h);
  41. };
  42. mxShapePidFan.prototype.background = function(c, x, y, w, h)
  43. {
  44. c.ellipse(0, 0, w, h);
  45. c.fillAndStroke();
  46. };
  47. mxShapePidFan.prototype.foreground = function(c, x, y, w, h)
  48. {
  49. c.begin();
  50. c.moveTo(w * 0.3, h * 0.045);
  51. c.lineTo(w * 0.97, h * 0.33);
  52. c.moveTo(w * 0.3, h * 0.955);
  53. c.lineTo(w * 0.97, h * 0.67);
  54. c.moveTo(w * 0.4228, h * 0.3655);
  55. c.arcTo(w * 0.15, h * 0.03, 50, 0, 1, w * 0.5, h * 0.5);
  56. c.arcTo(w * 0,15, h * 0.03, 50, 0, 1, w * 0.3772, h * 0.4045);
  57. c.arcTo(w * 0.15, h * 0.03, 50, 0, 1, w * 0.3025, h * 0.271);
  58. c.arcTo(w * 0.15, h * 0.03, 50, 0, 1, w * 0.4228, h * 0.3655);
  59. c.close();
  60. c.moveTo(w * 0.377, h * 0.5973);
  61. c.arcTo(w * 0.15, h * 0.03, -50, 0, 1, w * 0.4966, h * 0.5019);
  62. c.arcTo(w * 0,15, h * 0.03, -50, 0, 1, w * 0.423, h * 0.636);
  63. c.arcTo(w * 0.15, h * 0.03, -50, 0, 1, w * 0.3034, h * 0.7314);
  64. c.arcTo(w * 0.15, h * 0.03, -50, 0, 1, w * 0.377, h * 0.5973);
  65. c.close();
  66. c.stroke();
  67. c.ellipse(w * 0.5, h * 0.47, w * 0.3, h * 0.06);
  68. c.stroke();
  69. var type = mxUtils.getValue(this.style, mxShapePidFan.prototype.cst.FAN_TYPE, 'common');
  70. if (type === mxShapePidFan.prototype.cst.AXIAL)
  71. {
  72. c.begin();
  73. c.moveTo(w * 0.1, h * 0.5);
  74. c.lineTo(w * 0.3, h * 0.5);
  75. c.stroke();
  76. }
  77. else if (type === mxShapePidFan.prototype.cst.RADIAL)
  78. {
  79. c.begin();
  80. c.moveTo(w * 0.2, h * 0.4);
  81. c.lineTo(w * 0.2, h * 0.6);
  82. c.stroke();
  83. }
  84. };
  85. mxCellRenderer.prototype.defaultShapes[mxShapePidFan.prototype.cst.SHAPE_FAN] = mxShapePidFan;
  86. //**********************************************************************************************************************************************************
  87. //Column
  88. //**********************************************************************************************************************************************************
  89. /**
  90. * Extends mxShape.
  91. */
  92. function mxShapePidColumn(bounds, fill, stroke, strokewidth)
  93. {
  94. mxShape.call(this);
  95. this.bounds = bounds;
  96. this.fill = fill;
  97. this.stroke = stroke;
  98. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  99. };
  100. /**
  101. * Extends mxShape.
  102. */
  103. mxUtils.extend(mxShapePidColumn, mxShape);
  104. mxShapePidColumn.prototype.cst = {
  105. SHAPE_COLUMN : 'mxgraph.pid2misc.column',
  106. COLUMN_TYPE : 'columnType',
  107. COMMON : 'common',
  108. FIXED : 'fixed',
  109. FLUIDIZED : 'fluid',
  110. BAFFLE : 'baffle',
  111. VALVE : 'valve',
  112. BUBBLE : 'bubble',
  113. NOZZLE : 'nozzle',
  114. TRAY : 'tray'
  115. };
  116. /**
  117. * Function: paintVertexShape
  118. *
  119. * Paints the vertex shape.
  120. */
  121. mxShapePidColumn.prototype.paintVertexShape = function(c, x, y, w, h)
  122. {
  123. c.translate(x, y);
  124. this.background(c, x, y, w, h);
  125. c.setShadow(false);
  126. this.foreground(c, x, y, w, h);
  127. };
  128. mxShapePidColumn.prototype.background = function(c, x, y, w, h)
  129. {
  130. h = Math.max(h, 30);
  131. c.begin();
  132. c.moveTo(0, 15);
  133. c.arcTo(w * 0.5, 15, 0, 0, 1, w, 15);
  134. c.lineTo(w, h - 15);
  135. c.arcTo(w * 0.5, 15, 0, 0, 1, 0, h - 15);
  136. c.close();
  137. c.fillAndStroke();
  138. };
  139. mxShapePidColumn.prototype.foreground = function(c, x, y, w, h)
  140. {
  141. var type = mxUtils.getValue(this.style, mxShapePidColumn.prototype.cst.COLUMN_TYPE, 'common');
  142. if (type === mxShapePidColumn.prototype.cst.FIXED)
  143. {
  144. var step = w * 1.2;
  145. var range = h - 50;
  146. var rem = range % step;
  147. var off = rem * 0.5 + 25;
  148. c.begin();
  149. for (var i = 0; i <= range - step; i += step)
  150. {
  151. c.moveTo(0, i + off + step * 0.1);
  152. c.lineTo(w, i + off + step * 0.1);
  153. c.moveTo(0, i + off + step * 0.9);
  154. c.lineTo(w, i + off + step * 0.9);
  155. c.moveTo(0, i + off + step * 0.1);
  156. c.lineTo(w, i + off + step * 0.9);
  157. c.moveTo(0, i + off + step * 0.9);
  158. c.lineTo(w, i + off + step * 0.1);
  159. }
  160. c.stroke();
  161. }
  162. else if (type === mxShapePidColumn.prototype.cst.TRAY)
  163. {
  164. var step = w * 0.2;
  165. var range = h - 50;
  166. var rem = range % step;
  167. var off = rem * 0.5 + 25;
  168. c.setDashed(true);
  169. c.begin();
  170. for (var i = 0; i <= range; i += step)
  171. {
  172. c.moveTo(0, i + off);
  173. c.lineTo(w, i + off);
  174. }
  175. c.stroke();
  176. }
  177. else if (type === mxShapePidColumn.prototype.cst.FLUIDIZED)
  178. {
  179. var stepY = w * 0.1;
  180. var stepX = w * 0.1;
  181. var range = h - 50;
  182. var rem = range % stepY;
  183. var off = 25;
  184. var dot = Math.min(w, h) * 0.02;
  185. var fillColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  186. var dashed = mxUtils.getValue(this.style, mxConstants.STYLE_DASHED, '0');
  187. var strokeColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, '#000000');
  188. var odd = 0;
  189. c.setFillColor(strokeColor);
  190. c.setDashed(true);
  191. c.begin();
  192. c.moveTo(0, 25);
  193. c.lineTo(w, 25);
  194. c.moveTo(0, h - 25);
  195. c.lineTo(w, h - 25);
  196. c.stroke();
  197. if (dashed === '0')
  198. {
  199. c.setDashed(false);
  200. }
  201. else
  202. {
  203. c.setDashed(true);
  204. }
  205. var counter = 0;
  206. for (var i = off + stepY * 0.5; i < range + off - dot; i += stepY)
  207. {
  208. var startJ = stepX;
  209. odd = counter % 2;
  210. if (odd === 0)
  211. {
  212. startJ = stepX * 0.5;
  213. }
  214. for (var j = startJ; j < w; j += stepX )
  215. {
  216. c.ellipse(j, i, dot, dot);
  217. c.fillAndStroke();
  218. }
  219. counter++;
  220. }
  221. }
  222. else if (type === mxShapePidColumn.prototype.cst.BAFFLE)
  223. {
  224. var stepY = w * 0.2;
  225. var range = h - 50 - stepY;
  226. var rem = range % stepY;
  227. var off = 25 + stepY * 0.5;
  228. var odd = 0;
  229. c.setDashed(true);
  230. c.begin();
  231. c.moveTo(0, 25);
  232. c.lineTo(w, 25);
  233. c.moveTo(0, h - 25);
  234. c.lineTo(w, h - 25);
  235. c.stroke();
  236. var counter = 0;
  237. c.begin();
  238. for (var i = off + stepY * 0.5; i < range + off; i += stepY)
  239. {
  240. odd = counter % 2;
  241. if (odd === 0)
  242. {
  243. c.moveTo(0, i);
  244. c.lineTo(w * 0.9, i);
  245. c.lineTo(w * 0.9, i - stepY * 0.3);
  246. }
  247. else
  248. {
  249. c.moveTo(w * 0.1, i - stepY * 0.5);
  250. c.lineTo(w * 0.1, i);
  251. c.lineTo(w, i);
  252. }
  253. counter++;
  254. }
  255. c.stroke();
  256. }
  257. else if (type === mxShapePidColumn.prototype.cst.VALVE || type === mxShapePidColumn.prototype.cst.BUBBLE)
  258. {
  259. var stepY = w * 0.2;
  260. var range = h - 50 - stepY;
  261. var rem = range % stepY;
  262. var off = 25 + stepY * 0.5;
  263. var dashed = mxUtils.getValue(this.style, mxConstants.STYLE_DASHED, '0');
  264. var odd = 0;
  265. c.setFillColor(strokeColor);
  266. c.setDashed(true);
  267. c.begin();
  268. c.moveTo(0, 25);
  269. c.lineTo(w, 25);
  270. c.moveTo(0, h - 25);
  271. c.lineTo(w, h - 25);
  272. c.stroke();
  273. if (dashed === '0')
  274. {
  275. c.setDashed(false);
  276. }
  277. else
  278. {
  279. c.setDashed(true);
  280. }
  281. c.begin();
  282. for (var i = off + stepY * 0.5; i < range + off; i += stepY)
  283. {
  284. c.moveTo(0, i);
  285. c.lineTo(w * 0.4, i);
  286. if (type === mxShapePidColumn.prototype.cst.VALVE)
  287. {
  288. c.moveTo(w * 0.4, i - stepY * 0.2);
  289. c.lineTo(w * 0.6, i - stepY * 0.2);
  290. }
  291. else if (type === mxShapePidColumn.prototype.cst.BUBBLE)
  292. {
  293. c.moveTo(w * 0.25, i - stepY * 0.2);
  294. c.arcTo(stepY * 3, stepY * 3, 0, 0, 1, w * 0.75, i - stepY * 0.2);
  295. }
  296. c.moveTo(w * 0.6, i);
  297. c.lineTo(w, i);
  298. }
  299. c.stroke();
  300. }
  301. else if (type === mxShapePidColumn.prototype.cst.NOZZLE)
  302. {
  303. var step = w * 1.2;
  304. var range = h - 50;
  305. var rem = range % step;
  306. var off = rem * 0.5 + 25;
  307. var dashed = mxUtils.getValue(this.style, mxConstants.STYLE_DASHED, 0);
  308. for (var i = 0; i <= range - step; i += step)
  309. {
  310. c.setDashed(true);
  311. c.begin();
  312. c.moveTo(0, i + off + step * 0.2);
  313. c.lineTo(w, i + off + step * 0.2);
  314. c.moveTo(0, i + off + step * 0.8);
  315. c.lineTo(w, i + off + step * 0.8);
  316. c.stroke();
  317. if (dashed === 0)
  318. {
  319. c.setDashed(false);
  320. }
  321. else
  322. {
  323. c.setDashed(true);
  324. }
  325. c.begin();
  326. c.moveTo(0, i + off + step * 0.2);
  327. c.lineTo(w, i + off + step * 0.8);
  328. c.moveTo(0, i + off + step * 0.8);
  329. c.lineTo(w, i + off + step * 0.2);
  330. if (i !== 0)
  331. {
  332. c.moveTo(0, i + off);
  333. c.lineTo(w * 0.5, i + off);
  334. c.moveTo(w * 0.5 - step * 0.08, i + off + step * 0.08);
  335. c.lineTo(w * 0.5, i + off);
  336. c.lineTo(w * 0.5 + step * 0.08, i + off + step * 0.08);
  337. c.moveTo(w * 0.5, i + off);
  338. c.lineTo(w * 0.5, i + off + step * 0.08);
  339. }
  340. c.stroke();
  341. }
  342. c.stroke();
  343. }
  344. };
  345. mxCellRenderer.prototype.defaultShapes[mxShapePidColumn.prototype.cst.SHAPE_COLUMN] = mxShapePidColumn;
  346. //**********************************************************************************************************************************************************
  347. //Conveyor
  348. //**********************************************************************************************************************************************************
  349. /**
  350. * Extends mxShape.
  351. */
  352. function mxShapePidConveyor(bounds, fill, stroke, strokewidth)
  353. {
  354. mxShape.call(this);
  355. this.bounds = bounds;
  356. this.fill = fill;
  357. this.stroke = stroke;
  358. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  359. };
  360. /**
  361. * Extends mxShape.
  362. */
  363. mxUtils.extend(mxShapePidConveyor, mxShape);
  364. mxShapePidConveyor.prototype.cst = {
  365. SHAPE_CONVEYOR : 'mxgraph.pid2misc.conveyor'
  366. };
  367. /**
  368. * Function: paintVertexShape
  369. *
  370. * Paints the vertex shape.
  371. */
  372. mxShapePidConveyor.prototype.paintVertexShape = function(c, x, y, w, h)
  373. {
  374. c.translate(x, y);
  375. this.background(c, x, y, w, h);
  376. c.setShadow(false);
  377. };
  378. mxShapePidConveyor.prototype.background = function(c, x, y, w, h)
  379. {
  380. var wheelSize = Math.min(h, w * 0.5);
  381. c.begin();
  382. c.moveTo(wheelSize * 0.5, 0);
  383. c.lineTo(w - wheelSize * 0.5, 0);
  384. c.stroke();
  385. c.ellipse(0, 0, wheelSize, wheelSize);
  386. c.fillAndStroke();
  387. c.ellipse(w - wheelSize, 0, wheelSize, wheelSize);
  388. c.fillAndStroke();
  389. c.begin();
  390. c.moveTo(wheelSize * 0.5, wheelSize);
  391. c.lineTo(w - wheelSize * 0.5, wheelSize);
  392. c.stroke();
  393. //holders
  394. var dist = w - wheelSize * 1.8;
  395. var startX = wheelSize * 0.9;
  396. var step = wheelSize * 0.7;
  397. for (var i = 0; i < dist; i = i + step)
  398. {
  399. c.rect(startX + i, 0, wheelSize * 0.2, wheelSize * 0.1);
  400. c.fillAndStroke();
  401. c.rect(startX + i, wheelSize * 0.9, wheelSize * 0.2, wheelSize * 0.1);
  402. c.fillAndStroke();
  403. }
  404. };
  405. mxCellRenderer.prototype.defaultShapes[mxShapePidConveyor.prototype.cst.SHAPE_CONVEYOR] = mxShapePidConveyor;