PlotParamObject.js 7.4 KB
/**
 * 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.PlotOrbitSerieObject',
	           'amdaPlotObj.PlotSpectroObject',
	           'amdaPlotObj.PlotStatusBarObject',
	           'amdaPlotObj.PlotTickBarObject',
	           'amdaPlotObj.PlotInstantSerieObject',
	           'amdaPlotObj.PlotInstantSpectroObject'
	],
	
	fields : [
	          {name: 'id', type: 'int'},
	          {name: 'param-id', type: 'string'},
	          {name: 'param-type', type: 'int'},
	          {name: 'param-dim-1', type: 'string'},
	          {name: 'param-dim-2', 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);
        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 info = '';
		
		var paramIndexes = '';
		switch (this.get('param-type')) {
  	  		case 0:
  	  			//scalar - nothing to do
  	  			break;
  	  		case 1:
  	  			//Tab1D
  	  			if ((this.get('param-dim-1') != '') && (this.get('param-dim-1') != '*'))
  	  				paramIndexes = '('+this.get('param-dim-1')+')';
  	  			else if ((this.get('param-dim-2') != '') && (this.get('param-dim-2') != '*'))
  	  				paramIndexes = '('+this.get('param-dim-2')+')';
  	  			break;
  	  		case 2:
  	  			//Tab2D
  	  			var dim1 = this.get('param-dim-1') != '' ? this.get('param-dim-1') : "*";
  	  			var dim2 = this.get('param-dim-2') != '' ? this.get('param-dim-2') : "*";
  	  			if ((dim1 != '*') || (dim2 != '*'))
  	  				paramIndexes = '('+dim1+','+dim2+')';
  	  	}
		
		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 = this.get('param-id')+paramIndexes+', '+projection;
			}
			else
				info = this.get('param-id')+paramIndexes+' = f('+this.get('param-drawing-object').get('serie-xaxis-param')+', t)';
			break;
		case 'instantPlot' :
			info = this.get('param-id')+paramIndexes;
			break;
		default :
			info = this.get('param-id')+paramIndexes+' = 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  = new Object();
    	
    	paramValues['id'] = this.get('id');
    	
    	paramValues['param-id'] = this.get('param-id');
    	paramValues['param-type'] = this.get('param-type');
    	paramValues['param-dim-1'] = this.get('param-dim-1');
    	paramValues['param-dim-2'] = this.get('param-dim-2');
    	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;
    }
});