Commit 51b7c77c7f884a88b58f7adde4e69105e4723b3e

Authored by Benjamin Renard
1 parent bd59dd0b

Add templated parameters support

generic_data/ParamTemplate/ParamTemplateList.xml 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +<?xml version="1.0"?>
  2 +
  3 +<paramTemplateList>
  4 + <paramTemplate paramId='bmorsch_mso' fileName='bmorsch_mso_##sampling##_##orbit##'>
  5 + <arguments>
  6 + <argument key='sampling' name='Sampling Time' type='float' default='60'/>
  7 + <argument key='orbit' name='Spacecraft Orbit' type='list' default='mex_xyz'>
  8 + <item key='mex_xyz' name='MEX'/>
  9 + <item key='mav_xyz_mso' name='MAVEN'/>
  10 + <item key='xyz_mgs_mso' name='MGS'/>
  11 + </argument>
  12 + </arguments>
  13 + </paramTemplate>
  14 + <paramTemplate paramId='bmorsch_tot' fileName='bmorsch_tot_##sampling##_##orbit##'>
  15 + <arguments>
  16 + <argument key='sampling' name='Sampling Time' type='float' default='60'/>
  17 + <argument key='orbit' name='Spacecraft Orbit' type='list' default='mex_xyz'>
  18 + <item key='mex_xyz' name='MEX'/>
  19 + <item key='mav_xyz_mso' name='MAVEN'/>
  20 + <item key='xyz_mgs_mso' name='MGS'/>
  21 + </argument>
  22 + </arguments>
  23 + </paramTemplate>
  24 +</paramTemplateList>
0 25 \ No newline at end of file
... ...
generic_data/ParamTemplate/bmorsch_mso_##sampling##_##orbit##.xml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<param xml:id="bmorsch_mso_##sampling##_##orbit##">
  3 + <get>
  4 + <amdaParam name='##orbit##'/>
  5 + </get>
  6 + <process description="bmorsch_mso(##sampling##, ##orbit##)">#morschhauser_bfield(#sampling_classic($##orbit##;##sampling##;5))</process>
  7 + <output/>
  8 +</param>
... ...
generic_data/ParamTemplate/bmorsch_tot_##sampling##_##orbit##.xml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<param xml:id="bmorsch_tot_##sampling##_##orbit##">
  3 + <get>
  4 + <amdaParam name='##orbit##'/>
  5 + </get>
  6 + <process description="bmorsch_tot(##sampling##,##orbit##)">#morschhauser_bmag(#sampling_classic($##orbit##;##sampling##;5))</process>
  7 + <output/>
  8 +</param>
... ...
js/app/models/PlotObjects/PlotParamObject.js
... ... @@ -35,7 +35,8 @@ Ext.define(&#39;amdaPlotObj.PlotParamObject&#39;, {
35 35 {name: 'param-dim-1', type: 'string'},
36 36 {name: 'param-dim-2', type: 'string'},
37 37 {name: 'param-drawing-type', type: 'string'},
38   - {name: 'param-drawing-object', type: 'auto'}
  38 + {name: 'param-drawing-object', type: 'auto'},
  39 + {name: 'param-template-args', type: 'auto'}
39 40 ],
40 41  
41 42 associations : [
... ... @@ -173,22 +174,30 @@ Ext.define(&#39;amdaPlotObj.PlotParamObject&#39;, {
173 174 paramIndexes = '('+dim1+','+dim2+')';
174 175 }
175 176  
  177 + var template_args = "";
  178 + if (this.get('param-template-args')) {
  179 + Ext.Object.each(this.get('param-template-args'), function (argKey, argValue) {
  180 + template_args += "_";
  181 + template_args += argValue;
  182 + });
  183 + }
  184 +
176 185 switch (plotType)
177 186 {
178 187 case 'xyPlot' :
179 188 if (this.get('param-drawing-type') == 'orbit-serie')
180 189 {
181 190 var projection = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaPlotObj.PlotObjectConfig.availableOrbitSerieProjections, this.get('param-drawing-object').get('serie-projection'));
182   - info = this.get('param-id')+paramIndexes+', '+projection;
  191 + info = this.get('param-id')+template_args+paramIndexes+', '+projection;
183 192 }
184 193 else
185   - info = this.get('param-id')+paramIndexes+' = f('+this.get('param-drawing-object').get('serie-xaxis-param')+', t)';
  194 + info = this.get('param-id')+template_args+paramIndexes+' = f('+this.get('param-drawing-object').get('serie-xaxis-param')+', t)';
186 195 break;
187 196 case 'instantPlot' :
188   - info = this.get('param-id')+paramIndexes;
  197 + info = this.get('param-id')+template_args+paramIndexes;
189 198 break;
190 199 default :
191   - info = this.get('param-id')+paramIndexes+' = f(t)';
  200 + info = this.get('param-id')+template_args+paramIndexes+' = f(t)';
192 201 }
193 202  
194 203 info += ', '+type;
... ... @@ -233,6 +242,13 @@ Ext.define(&#39;amdaPlotObj.PlotParamObject&#39;, {
233 242 if (this.get('param-drawing-object') != null)
234 243 paramValues['param-drawing-object'] = this.get('param-drawing-object').getJsonValues();
235 244  
  245 + if (this.get('param-template-args') != null) {
  246 + paramValues['param-template-args'] = new Object();
  247 + Ext.Object.each(this.get('param-template-args'), function (argKey, argValue) {
  248 + paramValues['param-template-args'][argKey] = argValue;
  249 + });
  250 + }
  251 +
236 252 return paramValues;
237 253 }
238 254 });
239 255 \ No newline at end of file
... ...
js/app/views/ParamArgumentsUI.js
... ... @@ -13,6 +13,8 @@ Ext.define(&#39;amdaUI.ParamArgumentsUI&#39;, {
13 13 extend: 'Ext.container.Container',
14 14 alias: 'widget.paramArguments',
15 15  
  16 + regexp_istemplate: /^template_(.*)/,
  17 +
16 18 onChange: null,
17 19  
18 20 // -1 -> unknown, 0 -> scalar, 1 -> Tab1D, 2 -> Tab2D
... ... @@ -51,10 +53,24 @@ Ext.define(&#39;amdaUI.ParamArgumentsUI&#39;, {
51 53 else
52 54 {
53 55 //Rebuild arguments selection
54   - me.rebuildArguments(result.data, uiScope);
55   - //Set current values
56   - if (crtArgsValues)
57   - me.setValues(crtArgsValues);
  56 + me.rebuildArguments(result, uiScope);
  57 +
  58 + //Set values
  59 + var argsValues = crtArgsValues;
  60 + if (!argsValues)
  61 + argsValues = {};
  62 + if (result.template && result.template.arguments) {
  63 + if (!argsValues['template_args'])
  64 + argsValues['template_args'] = {};
  65 + //Add default template args definition if needed
  66 + Ext.Object.each(result.template.arguments, function (argKey, argDef) {
  67 + if (!argsValues['template_args'][argKey])
  68 + argsValues['template_args'][argKey] = argDef['default'];
  69 + }, me);
  70 + }
  71 + me.setValues(argsValues);
  72 +
  73 + //Set default values
58 74 if (onReady)
59 75 onReady(uiScope);
60 76 }
... ... @@ -69,7 +85,12 @@ Ext.define(&#39;amdaUI.ParamArgumentsUI&#39;, {
69 85  
70 86 setValues: function(values) {
71 87 this.items.each(function (item) {
72   - if (values[item.getId()])
  88 + if (this.regexp_istemplate.test(item.getId())) {
  89 + var arg_key = this.regexp_istemplate.exec(item.getId())[1];
  90 + if (values['template_args'] && values['template_args'][arg_key])
  91 + item.setValue(values['template_args'][arg_key]);
  92 + }
  93 + else if (values[item.getId()])
73 94 item.setValue(values[item.getId()]);
74 95 }, this);
75 96 },
... ... @@ -77,8 +98,17 @@ Ext.define(&#39;amdaUI.ParamArgumentsUI&#39;, {
77 98 getValues: function() {
78 99 var values = {type : this.paramType};
79 100 this.items.each(function(item) {
80   - values[item.getId()] = item.getValue();
81   - });
  101 + if (item.getId() == 'no-arg')
  102 + return;
  103 + if (this.regexp_istemplate.test(item.getId())) {
  104 + var arg_key = this.regexp_istemplate.exec(item.getId())[1];
  105 + if (!values['template_args'])
  106 + values['template_args'] = {};
  107 + values['template_args'][arg_key] = item.getValue();
  108 + }
  109 + else
  110 + values[item.getId()] = item.getValue();
  111 + }, this);
82 112  
83 113 return values;
84 114 },
... ... @@ -92,26 +122,30 @@ Ext.define(&#39;amdaUI.ParamArgumentsUI&#39;, {
92 122 resetArguments: function(noArgsMsg) {
93 123 this.removeAll();
94 124 if (!noArgsMsg)
95   - this.add(new Ext.form.Label({text: 'No arguments for this parameter'}));
  125 + this.add(new Ext.form.Label({text: 'No argument for this parameter', id: 'no-arg'}));
96 126 },
97 127  
98   - rebuildArguments: function(data, uiScope) {
  128 + rebuildArguments: function(result, uiScope) {
99 129 this.resetArguments(true);
100 130  
101 131 this.paramType = -1;
102   - if (data && data.dimensions) {
  132 + if (result.data && result.data.dimensions) {
103 133 this.paramType = 0;
104   - if (data.dimensions.dim_1 && (parseInt(data.dimensions.dim_1) > 1)) {
105   - this.buildDimIndexSelection("dim_1", data, uiScope);
  134 + if (result.data.dimensions.dim_1 && (parseInt(result.data.dimensions.dim_1) > 1)) {
  135 + this.buildDimIndexSelection("dim_1", result.data, uiScope);
106 136 ++this.paramType;
107 137 }
108   - if (data.dimensions.dim_2 && (parseInt(data.dimensions.dim_2) > 1)) {
109   - this.buildDimIndexSelection("dim_2", data, uiScope);
  138 + if (result.data.dimensions.dim_2 && (parseInt(result.data.dimensions.dim_2) > 1)) {
  139 + this.buildDimIndexSelection("dim_2", result.data, uiScope);
110 140 ++this.paramType;
111 141 }
112 142 }
113 143  
114   - if (this.paramType <= 0)
  144 + var isTemplate = (result.template && result.template.arguments);
  145 + if (isTemplate)
  146 + this.buildTemplateArguments(result.template.arguments, uiScope);
  147 +
  148 + if ((this.paramType <= 0) && !isTemplate)
115 149 //Add no args message
116 150 this.resetArguments(false);
117 151 },
... ... @@ -174,7 +208,7 @@ Ext.define(&#39;amdaUI.ParamArgumentsUI&#39;, {
174 208 listeners: {
175 209 change: function(field, newValue, oldValue, eOpts) {
176 210 if (this.onChange != null)
177   - this.onChange(uiScope, relatedDim, newValue, oldValue);
  211 + this.onChange(uiScope, relatedDim, newValue, oldValue, false);
178 212 },
179 213 scope: this
180 214 }
... ... @@ -184,5 +218,65 @@ Ext.define(&#39;amdaUI.ParamArgumentsUI&#39;, {
184 218 this.add(indexesCombo);
185 219  
186 220 return indexesCombo;
  221 + },
  222 +
  223 + buildTemplateArguments: function(arguments, uiScope) {
  224 + var me = this;
  225 + Ext.Object.each(arguments, function (key, argument) {
  226 + switch (argument.type) {
  227 + case 'float' :
  228 + var argumentField = Ext.create('Ext.form.NumberField', {
  229 + id: 'template_' + key,
  230 + fieldLabel: argument.name,
  231 + decimalPrecision : 3,
  232 + allowBlank : false,
  233 + value: parseFloat(argument.default),
  234 + listeners: {
  235 + change: function(field, newValue, oldValue, eOpts) {
  236 + if (me.onChange != null)
  237 + me.onChange(uiScope, key, newValue, oldValue, true);
  238 + },
  239 + scope: me
  240 + }
  241 + });
  242 +
  243 + me.add(argumentField);
  244 + break;
  245 + case 'list' :
  246 + var items = [];
  247 + Ext.Object.each(argument.items, function (itemKey, itemName) {
  248 + items.push({'key' : itemKey, 'value' : itemName});
  249 + });
  250 +
  251 + var itemsStore = Ext.create('Ext.data.Store', {
  252 + fields: ['key', 'value'],
  253 + data : items
  254 + });
  255 +
  256 + var itemsCombo = Ext.create('Ext.form.ComboBox', {
  257 + fieldLabel: argument.name,
  258 + store: itemsStore,
  259 + queryMode: 'local',
  260 + displayField: 'value',
  261 + valueField: 'key',
  262 + value: argument.default,
  263 + editable: false,
  264 + id: 'template_' + key,
  265 + listeners: {
  266 + change: function(field, newValue, oldValue, eOpts) {
  267 + if (me.onChange != null)
  268 + me.onChange(uiScope, key, newValue, oldValue, true);
  269 + },
  270 + scope: me
  271 + }
  272 +
  273 + });
  274 +
  275 + me.add(itemsCombo);
  276 + break;
  277 + default:
  278 + console.log('Template argument type not yet implemented: '+argument.type);
  279 + }
  280 + });
187 281 }
188 282 });
189 283 \ No newline at end of file
... ...
js/app/views/PlotComponents/PlotParamForm.js
... ... @@ -103,17 +103,29 @@ Ext.define(&#39;amdaPlotComp.PlotParamForm&#39;, {
103 103 drawingOptionsForm.setObject(this.object);
104 104  
105 105 if (this.paramArgs && paramId)
106   - this.paramArgs.editParameter(paramId, {'dim_1' : this.object.get('param-dim-1'), 'dim_2' : this.object.get('param-dim-2')}, this, function (uiScope) {
  106 + this.paramArgs.editParameter(paramId, {'dim_1' : this.object.get('param-dim-1'), 'dim_2' : this.object.get('param-dim-2'), 'template_args' : this.object.get('param-template-args')}, this, function (uiScope) {
107 107 uiScope.object.set('param-type', uiScope.paramArgs.paramType);
  108 + var crtValues = uiScope.paramArgs.getValues();
  109 + if (crtValues && crtValues['template_args'])
  110 + uiScope.object.set('param-template-args', crtValues['template_args']);
108 111 uiScope.crtTree.refresh();
109 112 });
110 113 },
111 114  
112   - onChangeParamArgs: function(uiScope, args_key, newValue, oldValue) {
113   - if (args_key == 'dim_1')
114   - uiScope.object.set('param-dim-1', newValue);
115   - else if (args_key == 'dim_2')
116   - uiScope.object.set('param-dim-2', newValue);
  115 + onChangeParamArgs: function(uiScope, args_key, newValue, oldValue, isTemplateArg) {
  116 + if (!isTemplateArg) {
  117 + if (args_key == 'dim_1')
  118 + uiScope.object.set('param-dim-1', newValue);
  119 + else if (args_key == 'dim_2')
  120 + uiScope.object.set('param-dim-2', newValue);
  121 + }
  122 + else {
  123 + var templateArgs = uiScope.object.get('param-template-args');
  124 + if (!templateArgs)
  125 + templateArgs = {};
  126 + templateArgs[args_key] = newValue;
  127 + uiScope.object.set('param-template-args', templateArgs);
  128 + }
117 129 uiScope.crtTree.refresh();
118 130 },
119 131  
... ...