PlotParamObject.js 6.14 KB
/**
 * Project      : AMDA-NG
 * Name         : PlotParamObject.js
 * @class   amdaPlotObj.PlotParamObject
 * @extends amdaModel.RequestParamObject
 * @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: 'amdaModel.RequestParamObject',
	
	requires: [
	           'amdaPlotObj.PlotObjectConfig',
	           'amdaPlotObj.PlotSerieObject',
			   'amdaPlotObj.PlotOrbitSerieObject',
	           'amdaPlotObj.PlotSpectroObject',
	           'amdaPlotObj.PlotStatusBarObject',
	           'amdaPlotObj.PlotTickBarObject',
	           'amdaPlotObj.PlotInstantSerieObject',
	           'amdaPlotObj.PlotInstantSpectroObject'
	],
	
	fields : [
	          {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);
        if ((arguments.length > 0) && arguments[0])
        {
        	if (arguments[0]['param-drawing-object'])
        		me.loadDrawingObject(arguments[0]['param-drawing-object']);
        }
        this.dirty = false;
    },
    
    loadDrawingObject: function(drawing)
    {
    	var drawingObject = this.get('param-drawing-object');
    	if (drawingObject == null)
    		return;
    	this.set('param-drawing-object', this.createDrawingObjectByType(this.get('param-drawing-type'), drawing));
    	drawingObject.dirty = false;
    },
    
    createDrawingObjectByType : function(type, data)
    {
    	//Create drawing object in relation with the type
    	switch (type)
    	{
    	case 'serie' :
    		return new amdaPlotObj.PlotSerieObject(data);
		case 'orbit-serie' :
			return new amdaPlotObj.PlotOrbitSerieObject(data);
    	case 'spectro' :
    		return new amdaPlotObj.PlotSpectroObject(data);
    	case 'status-bar' :
    		return new amdaPlotObj.PlotStatusBarObject(data);
    	case 'tick-bar' :
    		return new amdaPlotObj.PlotTickBarObject(data);
    	case 'iserie' :
    		return new amdaPlotObj.PlotInstantSerieObject(data);
    	case 'ispectro' :
    		return new amdaPlotObj.PlotInstantSpectroObject(data);
    	default :
    		return null;
    	}
    },
    
    changeDrawingType: function(type, drawData)
    {
    	if (type == this.get('param-drawing-type'))
    		return;
    	
    	this.set('param-drawing-type', type);
    	
    	this.set('param-drawing-object', this.createDrawingObjectByType(type));
    	
    	//Set drawing object to default status
    	if (this.get('param-drawing-object') != null)
    	{
    		this.get('param-drawing-object').setDefaultValues();
    		if (this.get('param-drawing-object').loadFromData && drawData)
    			this.get('param-drawing-object').loadFromData(drawData);
    	}
    },
    
    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.changeDrawingType(type);
    },
    
    getShortInfo : function(plotType)
    {
    	var availableDrawingObjects = this.getAvailableDrawingObjectByPlotType(plotType);
		var type = amdaPlotObj.PlotObjectConfig.getValueByKey(availableDrawingObjects, this.get('param-drawing-type'));
		
		var fullName = this.getParamFullName();
		
		var info = '';
		
		switch (plotType)
		{
		case 'xyPlot' :
			if (this.get('param-drawing-type') == 'orbit-serie')
			{
				var projection = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaPlotObj.PlotObjectConfig.availableOrbitSerieProjections, this.get('param-drawing-object').get('serie-projection'));
				info = fullName+', '+projection;
			}
			else
				info = fullName+' = f('+this.get('param-drawing-object').get('serie-xaxis-param')+', t)';
			break;
		case 'instantPlot' :
			info = fullName;
			break;
		default :
			info = fullName+' = 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;
    },
    
    isDirty : function()
    {
    	if (this.dirty)
    		return true;
    	if (this.get('param-drawing-object') != null)
    		return this.get('param-drawing-object').dirty;
    	
    	return false;
    },
    
    getJsonValues : function() 
    {
    	var paramValues  = this.callParent(arguments);
    	
    	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;
    }
});