PlotParamObject.js 7.93 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.PlotSauvaudObject',
	           'amdaPlotObj.PlotStatusBarObject',
	           'amdaPlotObj.PlotTickBarObject',
	           'amdaPlotObj.PlotInstantSerieObject',
	           'amdaPlotObj.PlotInstantSpectroObject',
                               'amdaPlotObj.PlotIntervalsObject'
	],
	
	fields : [
                  {name: 'param-type', type: 'string', defaultValue: 'param'}, //Available types: param, ttcat
                  {name: 'param-ttcat-name', 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(drawingType, data)
    {
    	//Create drawing object in relation with the drawing type
    	switch (drawingType)
    	{
    	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);
	case 'intervals' :
		return new amdaPlotObj.PlotIntervalsObject(data);
                	case 'sauvaud' :
		return new amdaPlotObj.PlotSauvaudObject(data);
    	default :
    		return null;
    	}
    },
    
    changeDrawingType: function(drawingType, drawData)
    {
    	if (drawingType == this.get('param-drawing-type'))
    		return;
    	
    	this.set('param-drawing-type', drawingType);
    	
    	this.set('param-drawing-object', this.createDrawingObjectByType(drawingType));
    	
    	//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 && (drawingType == drawData.type))
    			this.get('param-drawing-object').loadFromData(drawData);
    	}
    },
    
    getAvailableDrawingObjectByPlotType: function(plotType) {
        switch (this.get('param-type'))
        {
        case 'param' :
    	    switch (plotType)
    	    {
    	    case 'timePlot'  :
    	    case 'epochPlot' :
    		return [
    		        {'key' : 'serie', 'value' : 'Serie'},
    		        {'key' : 'spectro', 'value' : 'Spectro'},
                                                // {'key' : 'sauvaud', 'value' : 'Sauvaud'}, - #8528 - Hide Sauvaud plot - Not fully tested
    		        {'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'}
    		];
    	    }
            break;
        case 'ttcat':
            switch (plotType)
            {
            case 'timePlot':
                return [
			{'key' : 'intervals', 'value' : 'Intervals'},
                        {'key' : 'serie', 'value' : 'Serie'},
                        {'key' : 'status-bar', 'value' : 'Status Bar'}
                ];
            case 'statusPlot':
                return [
                        {'key' : 'status-bar', 'value' : 'Status Bar'}
                ];
            }
            break;
        }
    	return [];
    },
    
    setDefaultValues: function(drawingType)
    {
    	this.changeDrawingType(drawingType);
    },

    getShortInfo : function(plotType)
    {
    	var availableDrawingObjects = this.getAvailableDrawingObjectByPlotType(plotType);
		var typeName = amdaPlotObj.PlotObjectConfig.getValueByKey(availableDrawingObjects, this.get('param-drawing-type'));
		
		var fullName = '';
		if (this.get('param-type') == 'ttcat') {
			fullName = this.get('param-ttcat-name');
		}
		else {
			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 += ', '+typeName;
		
		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;
                        	case 'sauvaud' :
			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-type'] = this.get('param-type');
	paramValues['param-ttcat-name'] = this.get('param-ttcat-name');
    	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;
    }
});