/** * Project  : AMDA-NG * Name : PlotParamObject.js * @class amdaPlotObj.PlotParamObject * @extends Ext.data.Model * @brief Plot Param Business Object Definition * @author Benjamin Renard * @version $Id: PlotParamObject.js benjamin $ ****************************************************************************** * FT Id : Date : Name - Description ****************************************************************************** * : :17/08/2015: BRE - file creation */ Ext.define('amdaPlotObj.PlotParamObject', { extend: 'Ext.data.Model', idProperty: 'id', requires: [ 'amdaPlotObj.PlotObjectConfig', 'amdaPlotObj.PlotSerieObject', 'amdaPlotObj.PlotSpectroObject', 'amdaPlotObj.PlotStatusBarObject', 'amdaPlotObj.PlotTickBarObject', 'amdaPlotObj.PlotInstantSerieObject', 'amdaPlotObj.PlotInstantSpectroObject' ], fields : [ {name: 'id', type: 'int'}, {name: 'param-id', type: 'string'}, {name: 'param-drawing-type', type: 'string'}, {name: 'param-drawing-object', type: 'auto'} ], associations : [ { type : 'belongsTo', model : 'amdaPlotObj.PlotPanelObject', getterName : 'Panel' } ], constructor: function(){ var me = this; me.callParent(arguments); me.updateDrawingType(this.get('param-drawing-type'), true); if ((arguments.length > 0) && arguments[0]) { if (arguments[0]['param-drawing-object']) me.loadDrawingObject(arguments[0]['param-drawing-object']); } }, loadDrawingObject: function(drawing) { var drawingObject = this.get('param-drawing-object'); if (drawingObject == null) return; Ext.Object.each(drawing, function(key,value) { drawingObject.set(key,value); }); }, updateDrawingType: function(type, forceUpdate) { forceUpdate = (typeof forceUpdate !== 'undefined') ? forceUpdate : false; if (!forceUpdate && (type == this.get('param-drawing-type'))) return; this.set('param-drawing-type', type); //Create drawing object in relation with the type switch (type) { case 'serie' : this.set('param-drawing-object', new amdaPlotObj.PlotSerieObject()); break; case 'spectro' : this.set('param-drawing-object', new amdaPlotObj.PlotSpectroObject()); break; case 'status-bar' : this.set('param-drawing-object', new amdaPlotObj.PlotStatusBarObject()); break; case 'tick-bar' : this.set('param-drawing-object', new amdaPlotObj.PlotTickBarObject()); break; case 'iserie' : this.set('param-drawing-object', new amdaPlotObj.PlotInstantSerieObject()); break; case 'ispectro' : this.set('param-drawing-object', new amdaPlotObj.PlotInstantSpectroObject()); break; default : this.set('param-drawing-object', null); } //Set drawing object to default status if (this.get('param-drawing-object') != null) this.get('param-drawing-object').setDefaultValues(); }, getAvailableDrawingObjectByPlotType: function(plotType) { switch (plotType) { case 'timePlot' : case 'epochPlot' : return [ {'key' : 'serie', 'value' : 'Serie'}, {'key' : 'spectro', 'value' : 'Spectro'}, {'key' : 'tick-bar', 'value' : 'Tick Bar'}, {'key' : 'status-bar', 'value' : 'Status Bar'} ]; case 'xyPlot' : return [ {'key' : 'serie', 'value' : 'Serie'}, {'key' : 'orbit-serie', 'value' : 'Orbit Serie'} ]; case 'instantPlot' : return [ {'key' : 'iserie', 'value' : 'Serie'}, {'key' : 'ispectro', 'value' : 'Spectro'} ]; case 'statusPlot' : return [ {'key' : 'status-bar', 'value' : 'Status Bar'} ]; case 'tickPlot' : return [ {'key' : 'tick-bar', 'value' : 'Tick Bar'} ]; } return []; }, setDefaultValues: function(type) { this.updateDrawingType(type, true); }, getShortInfo : function(plotType) { var availableDrawingObjects = this.getAvailableDrawingObjectByPlotType(plotType); var type = amdaPlotObj.PlotObjectConfig.getValueByKey(availableDrawingObjects, this.get('param-drawing-type')); var info = ''; switch (plotType) { case 'xyPlot' : info = this.get('param-id')+' = f('+this.get('param-drawing-object').get('serie-xaxis-param')+', t)'; break; case 'instantPlot' : info = this.get('param-id'); break; default : info = this.get('param-id')+' = f(t)'; } info += ', '+type; switch (this.get('param-drawing-type')) { case 'serie' : var yAxis = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaPlotObj.PlotObjectConfig.availableYAxes, this.get('param-drawing-object').get('serie-yaxis')); info += ', Y '+yAxis; break; case 'spectro' : var yAxis = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaPlotObj.PlotObjectConfig.availableYAxes, this.get('param-drawing-object').get('spectro-yaxis')); info += ', Y '+yAxis; break; } return info; }, getJsonValues : function() { var paramValues = new Object(); paramValues['id'] = this.get('id'); paramValues['param-id'] = this.get('param-id'); paramValues['param-drawing-type'] = this.get('param-drawing-type'); if (this.get('param-drawing-object') != null) paramValues['param-drawing-object'] = this.get('param-drawing-object').getJsonValues(); return paramValues; } });