Blame view

js/app/models/PlotObjects/PlotCurveObject.js 5.28 KB
dbb7bcbe   Benjamin Renard   Add curves defint...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * Project      : AMDA-NG
 * Name         : PlotCurveObject.js
 * @class   amdaPlotObj.PlotCurveObject
 * @extends Ext.data.Model
 * @brief   Plot Curve Business Object Definition 
 * @author  Benjamin Renard
 * @version $Id: PlotCurveObject.js benjamin $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :03/09/2015: BRE  - file creation
 */

Ext.define('amdaPlotObj.PlotCurveObject', {
	extend: 'Ext.data.Model',
	idProperty: 'id',
	
	requires: [
	           'amdaPlotObj.PlotCurveDef',
	           'amdaPlotObj.PlotCurveParamObject'
	],
	
	fields : [
fd5552a4   Benjamin Renard   Info for plot ele...
25
	          {name: 'id', type: 'int'},
dbb7bcbe   Benjamin Renard   Add curves defint...
26
	          {name: 'curve-name', type: 'string'},
fd5552a4   Benjamin Renard   Info for plot ele...
27
	          {name: 'curve-serie-id', type: 'int', useNull:true},
dbb7bcbe   Benjamin Renard   Add curves defint...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	          {name: 'curve-line-style', type: 'string'},
	          {name: 'curve-line-width', type: 'float'},
	          {name: 'curve-line-color', type: 'string'}
	],
	
	associations : [
	                {
	              	  type : 'hasMany', 
	              	  model : 'amdaPlotObj.PlotCurveParamObject',
	              	  name  : 'params'
	                }
    ],
	
	constructor: function(){
		var me = this;
        me.callParent(arguments);
        if ((arguments.length > 0) && arguments[0])
        {
        	if (arguments[0].params)
        		me.loadParams(arguments[0].params);
        }
        else
        {
        	//new object, set default fields values
        	me.setDefaultValues();
        }
a971060f   Benjamin Renard   Fix some bugs
54
        this.dirty = false;
dbb7bcbe   Benjamin Renard   Add curves defint...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    },
    
    getCurvesDefStore: function(onCurvesDefGet)
    {
    	var curvesDefStore = Ext.data.StoreManager.lookup('curvesDefStore');

		if (!curvesDefStore)
		{
			curvesDefStore = Ext.create('Ext.data.Store', {
				model: 'amdaPlotObj.PlotCurveDef',
				storeId: 'curvesDefStore'
			});
			
			curvesDefStore.load({
				scope: this,
				callback: function(records, operation, success) {
					if (onCurvesDefGet != null)
						onCurvesDefGet(curvesDefStore);
				}
			});
		}
		else
		{
ced82260   Benjamin Renard   Get initial plot ...
78
79
80
81
82
83
84
85
86
			if (curvesDefStore.isLoading()) {
				var me = this;
				var task = new Ext.util.DelayedTask(function(){
					me.getCurvesDefStore(onCurvesDefGet);
				});
				task.delay(100);
				return;
			}
			
dbb7bcbe   Benjamin Renard   Add curves defint...
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
			if (onCurvesDefGet != null)
				onCurvesDefGet(curvesDefStore);
		}
    },
    
    setCurveName: function(curveName, onReady)
    {
    	this.set('curve-name', curveName);
    	
    	var me = this;
    	this.getCurvesDefStore(function (curvesDefStore) {
    		me.params().removeAll();
    		curvesDefStore.each(function(curveDef) {
    			if (curveDef.get('id') == curveName)
    			{
    				curveDef.params().each(function (paramDef) {
    					me.params().add({
    						'curve-param-name' : paramDef.get('name'),
    						'curve-param-internal' : paramDef.get('internal'),
    						'curve-param-value' : paramDef.get('defaultValue')});
    				});
    			}
    		});
    		if (onReady != null)
    			onReady(me);
    	});    	
    },
    
    loadParams: function(params)
    {
       this.params().loadData(params);
    },
ced82260   Benjamin Renard   Get initial plot ...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    
    loadFromData: function(curveData,serieId)
    {
    	var me = this;
    	if (curveData['curve-name']) {
    		this.setCurveName(curveData['curve-name'], function(curveObject) {
    			if (curveData['curve-line-style'])
    				me.set('curve-line-style', curveData['curve-line-style']);
    			if (curveData['curve-line-width'])
    				me.set('curve-line-width', curveData['curve-line-width']);
    			if (curveData['curve-line-color'])
    				me.set('curve-line-color', curveData['curve-line-color']);
    			
    			me.set('curve-serie-id', serieId);
    			
    			if (curveData["curve-attributes"])
    	    		Ext.Object.each(curveData["curve-attributes"], function(key, value) {
    	    			me.params().each(function (param) {
    	    				if (param.get('curve-param-name') == value['curve-param-name'])
    	    					param.set('curve-param-value', value['curve-param-value'])
    	    			});
    	    		}, me);
    		});
    	}
    },
dbb7bcbe   Benjamin Renard   Add curves defint...
144
145
146
147
	
	setDefaultValues: function()
    {
    	this.set('curve-name', '');
fd5552a4   Benjamin Renard   Info for plot ele...
148
    	this.set('curve-serie-id', null);
dbb7bcbe   Benjamin Renard   Add curves defint...
149
150
151
152
    	this.set('curve-line-style', amdaPlotObj.PlotObjectConfig.defaultValues.curves.line.style);
    	this.set('curve-line-width', amdaPlotObj.PlotObjectConfig.defaultValues.curves.line.width);
    	this.set('curve-line-color', amdaPlotObj.PlotObjectConfig.defaultValues.curves.line.color);
    },
fd5552a4   Benjamin Renard   Info for plot ele...
153
    
a971060f   Benjamin Renard   Fix some bugs
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    isDirty : function()
    {
    	if (this.dirty)
    		return true;
    	
    	var d = false;
    	this.params().each(function (param, index) {
    		if (param.dirty)
    			d = true;
    	});
    	
    	return d;
    },
    
dbb7bcbe   Benjamin Renard   Add curves defint...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    getJsonValues : function() 
    {
    	var curveValues  = new Object();
    	
    	curveValues['id'] = this.get('id');
    	
    	curveValues['curve-name'] = this.get('curve-name');
    	curveValues['curve-serie-id'] = this.get('curve-serie-id');
    	curveValues['curve-line-style'] = this.get('curve-line-style');
    	curveValues['curve-line-width'] = this.get('curve-line-width');
    	curveValues['curve-line-color'] = this.get('curve-line-color');
    		
    	curveValues['params'] = [];
    	
    	this.params().each(function (param, index) {
    		curveValues['params'][index] = param.getJsonValues();
    	});
    	
    	return curveValues;
    }
});