mxPidMisc.js 11 KB

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