PlotPanelObject.js 11.5 KB
/**
 * Project      : AMDA-NG
 * Name         : PlotPanelObject.js
 * @class   amdaPlotObj.PlotPanelObject
 * @extends Ext.data.Model
 * @brief   Plot Panel Business Object Definition 
 * @author  Benjamin Renard
 * @version $Id: PlotPanelObject.js benjamin $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :13/08/2015: BRE  - file creation
 */
 
 		
Ext.define('amdaPlotObj.PlotPanelObject', {
	extend: 'Ext.data.Model',
	
	lastParamId : 0,
	
	requires: [
	           'amdaPlotObj.PlotObjectConfig',
	           'amdaPlotObj.PlotAxisObject',
	           'amdaPlotObj.PlotParamObject'
	],
	
	fields : [
	          {name: 'id', type: 'string'},
	          {name: 'panel-background-color', type: 'string'},
              {name: 'panel-title-text', type: 'string'},
              {name: 'panel-title-color', type: 'string'},
              {name: 'panel-title-position', type: 'string'},
              {name: 'panel-title-alignment', type: 'string'},
              {name: 'panel-title-font-activated', type: 'boolean'},
              {name: 'panel-title-font-name', type: 'string'},
              {name: 'panel-title-font-size', type: 'int'},
              {name: 'panel-title-font-bold', type: 'boolean'},
              {name: 'panel-title-font-italic', type: 'boolean'},
              {name: 'panel-plot-type', type: 'string'},
              {name: 'panel-font-activated', type: 'boolean'},
              {name: 'panel-font-name', type: 'string'},
              {name: 'panel-font-size', type: 'int'},
              {name: 'panel-font-bold', type: 'boolean'},
              {name: 'panel-font-italic', type: 'boolean'},
              //Only used with layout Manual
              {name: 'panel-bounds-x', type: 'float'},
              {name: 'panel-bounds-y', type: 'float'},
              {name: 'panel-bounds-width', type: 'float'},
              {name: 'panel-bounds-height', type: 'float'},
              {name: 'panel-margin-left', type: 'float', useNull:true},
              {name: 'panel-margin-right', type: 'float', useNull:true},
              //Only used with layout Vertical
              {name: 'panel-prefered-width', type: 'float', useNull:true},
              {name: 'panel-prefered-height', type: 'float', useNull:true},
              //Only used for xyPlot
              {name: 'panel-scatter-isotropic', type: 'boolean'},
              //Only used for statusPlot and timePlot
              {name: 'panel-status-position', type: 'string'},
              {name: 'panel-status-colormap', type: 'int'},
              //Only used for tickPlot and timePlot
              {name: 'panel-tick-format', type: 'int'},
              //Only used for epochPlot
              {name: 'panel-epoch-centertimeid', type: 'string'}
    ],
    
    associations : [
              {
            	  type : 'hasMany', 
            	  model : 'amdaPlotObj.PlotAxisObject',
            	  name  : 'axes'
              },
              {
            	  type : 'hasMany', 
            	  model : 'amdaPlotObj.PlotParamObject',
            	  name  : 'params'
              },
              {
            	  type  : 'belongsTo',
                  model : 'amdaPlotObj.PlotTabObject'
              }
    ],
    
    initAxes : function()
    {
    	this.axes().removeAll();
    	switch (this.get('panel-plot-type'))
    	{
    	case 'timePlot' :
    		//Time axis
    		var recs = this.axes().add({id : 'time'});
        	recs[0].setDefaultValues('time');
        	//Y Left Axis
        	recs = this.axes().add({id : 'y-left'});
        	recs[0].setDefaultValues('y-left');
        	//Y Right Axis
        	recs = this.axes().add({id : 'y-right'});
        	recs[0].setDefaultValues('y-right');
        	//Color Axis
        	recs = this.axes().add({id : 'color'});
        	recs[0].setDefaultValues('color');
    		break;
    	case 'xyPlot' :
    	case 'instantPlot' :
    		//X Axis
    		var recs = this.axes().add({id : 'x'});
        	recs[0].setDefaultValues('x');
        	//Y Left Axis
        	recs = this.axes().add({id : 'y-left'});
        	recs[0].setDefaultValues('y-left');
        	//Y Right Axis
        	recs = this.axes().add({id : 'y-right'});
        	recs[0].setDefaultValues('y-right');
        	//Color Axis
        	recs = this.axes().add({id : 'color'});
        	recs[0].setDefaultValues('color');
    		break;
    	case 'epochPlot' :
    		//Epoch Axis
    		var recs = this.axes().add({id : 'epoch'});
        	recs[0].setDefaultValues('epoch');
        	//Y Left Axis
        	recs = this.axes().add({id : 'y-left'});
        	recs[0].setDefaultValues('y-left');
        	//Y Right Axis
        	recs = this.axes().add({id : 'y-right'});
        	recs[0].setDefaultValues('y-right');
        	//Color Axis
        	recs = this.axes().add({id : 'color'});
        	recs[0].setDefaultValues('color');
    		break;
    	case 'statusPlot' :
    	case 'tickPlot' :
    		//Time axis
    		var recs = this.axes().add({id : 'time'});
        	recs[0].setDefaultValues('time');
    		break;
    	}
    },
    
    createNewParam: function() {
    	var recs = this.params().add({id : this.get('id')+'-param-'+this.lastParamId});
    	++this.lastParamId;
    	var availableDrawingObjects = recs[0].getAvailableDrawingObjectByPlotType(this.get('panel-plot-type'));
    	recs[0].updateDrawingType(availableDrawingObjects[0].key, true);
		return recs[0];
    },
    
    removeParamById: function(paramId) {
    	//Retrieve param record
    	var paramRecord = this.params().getById(paramId);
    	if (paramRecord == null)
    		return false;
    	this.params().remove(paramRecord);
    	return true;
    },
    
    updatePlotType: function(plotType, forceUpdate) {
    	forceUpdate = (typeof forceUpdate !== 'undefined') ? forceUpdate : false;
    	
    	if (!forceUpdate && (plotType == this.get('panel-plot-type')))
    		return;
    	
    	this.set('panel-plot-type', plotType);
    	this.params().each(function (param, index) {
    		var availableDrawingObjects = param.getAvailableDrawingObjectByPlotType(plotType);
    		var compatibleDrawingType = false;
    		Ext.each(availableDrawingObjects, function (item, index) {
    			if (param.get('param-drawing-type') == item.key)
    			{
    				compatibleDrawingType = true;
    			}
    		});
    		if (!compatibleDrawingType)
    		{
    			param.updateDrawingType(availableDrawingObjects[0].key, forceUpdate);
    		}
    	});
    	this.initAxes();
    },
    
    setDefaultValues: function()
    {
    	this.set('panel-background-color', amdaPlotObj.PlotObjectConfig.defaultValues.panel.backgroundColor);
    	this.set('panel-title-text', '');
    	this.set('panel-title-color', amdaPlotObj.PlotObjectConfig.defaultValues.panel.title.color);
    	this.set('panel-title-position', amdaPlotObj.PlotObjectConfig.defaultValues.panel.title.position);
    	this.set('panel-title-alignment', amdaPlotObj.PlotObjectConfig.defaultValues.panel.title.alignment);
    	
    	this.set('panel-title-font-activated', false);
    	this.set('panel-title-font-name', amdaPlotObj.PlotObjectConfig.defaultValues.panel.font.name);
    	this.set('panel-title-font-size', amdaPlotObj.PlotObjectConfig.defaultValues.panel.font.size);
    	this.set('panel-title-font-bold', false);
    	this.set('panel-title-font-italic', false);
    	
    	this.set('panel-font-activated', false);
    	this.set('panel-font-name', amdaPlotObj.PlotObjectConfig.defaultValues.panel.font.name);
    	this.set('panel-font-size', amdaPlotObj.PlotObjectConfig.defaultValues.panel.font.size);
    	this.set('panel-font-bold', false);
    	this.set('panel-font-italic', false);
    	
    	this.set('panel-bounds-x', 0);
    	this.set('panel-bounds-y', 0);
    	this.set('panel-bounds-width', 1);
    	this.set('panel-bounds-height', 1);
    	
    	this.set('panel-margin-left', null);
    	this.set('panel-margin-right', null);
    	
    	this.set('panel-prefered-width', null);
    	this.set('panel-prefered-height', null);
    	
    	this.set('panel-scatter-isotropic', false);
    	
    	this.set('panel-status-position', amdaPlotObj.PlotObjectConfig.defaultValues.panel.status.position);
    	this.set('panel-status-colormap', amdaPlotObj.PlotObjectConfig.defaultValues.panel.status.colorMap);
    	
    	this.set('panel-tick-format', "");
    	
    	this.set('panel-epoch-centertimeid', "");
    	
    	this.updatePlotType(amdaPlotObj.PlotObjectConfig.defaultValues.panel.plotType);
    },
    
    getJsonValues : function() 
    {
    	var panelValues  = new Object();
    	
    	panelValues['panel-background-color'] = this.get('panel-background-color');
    	panelValues['panel-title-text'] = this.get('panel-title-text');
    	panelValues['panel-title-color'] = this.get('panel-title-color');
    	panelValues['panel-title-position'] = this.get('panel-title-position');
    	panelValues['panel-title-alignment'] = this.get('panel-title-alignment');
    	panelValues['panel-title-font-activated'] = this.get('panel-title-font-activated');
    	panelValues['panel-title-font-name'] = this.get('panel-title-font-name');
    	panelValues['panel-title-font-size'] = this.get('panel-title-font-size');
    	panelValues['panel-title-font-bold'] = this.get('panel-title-font-bold');
    	panelValues['panel-title-font-italic'] = this.get('panel-title-font-italic');
    	panelValues['panel-plot-type'] = this.get('panel-plot-type');
    	panelValues['panel-font-activated'] = this.get('panel-font-activated');
    	panelValues['panel-font-name'] = this.get('panel-font-name');
    	panelValues['panel-font-size'] = this.get('panel-font-size');
    	panelValues['panel-font-bold'] = this.get('panel-font-bold');
    	panelValues['panel-font-italic'] = this.get('panel-font-italic');
    	
    	panelValues['panel-bounds-x']      = this.get('panel-bounds-x');
    	panelValues['panel-bounds-y']      = this.get('panel-bounds-y');
    	panelValues['panel-bounds-width']  = this.get('panel-bounds-width');
    	panelValues['panel-bounds-height'] = this.get('panel-bounds-height');
    	
    	panelValues['panel-margin-left'] = this.get('panel-margin-left') ? this.get('panel-margin-left') : -1;
    	panelValues['panel-margin-right'] = this.get('panel-margin-right') ? this.get('panel-margin-right') : -1;
    	
    	panelValues['panel-prefered-width'] = this.get('panel-prefered-width') ? this.get('panel-prefered-width') : -1;
    	panelValues['panel-prefered-height'] = this.get('panel-prefered-height') ? this.get('panel-prefered-height') : -1;
    	
    	if (this.get('panel-plot-type') == 'xyPlot')
    		panelValues['panel-scatter-isotropic'] = this.get('panel-scatter-isotropic');
    	
    	if ((this.get('panel-plot-type') == 'statusPlot') || (this.get('panel-plot-type') == 'timePlot'))
    	{
    		panelValues['panel-status-position'] = this.get('panel-status-position');
    		panelValues['panel-status-colormap'] = this.get('panel-status-colormap');
    	}
    	
    	if ((this.get('panel-plot-type') == 'tickPlot') || (this.get('panel-plot-type') == 'timePlot'))
    	{
    		panelValues['panel-tick-format'] = this.get('panel-tick-format');
    	}
    	
    	if (this.get('panel-plot-type') == 'epochPlot')
    		panelValues['panel-epoch-centertimeid'] = this.get('panel-epoch-centertimeid');
    	
    	panelValues['axes'] = [];
    	
    	this.axes().each(function (axe, index) {
    		panelValues['axes'][index] = axe.getJsonValues();
    	});
    	
    	panelValues['params'] = [];
    	
    	this.params().each(function (param, index) {
    		panelValues['params'][index] = param.getJsonValues();
    	});
    	
    	return panelValues;
    }
});