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