mxPidMisc.js 11 KB

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