PlotModule.js 5.33 KB
/** 
 * Project   : AMDA-NG
 * Name      : PlotModule.js
 * @class    amdaDesktop.PlotModule
 * @extends  amdaDesktop.InteractiveModule
 * @brief    New Plot Module controller definition 
 * @author   Benjamin Renard
 * $Id: PlotModule.js benjamin $
 */

Ext.define('amdaDesktop.PlotModule', {
	extend: 'amdaDesktop.InteractiveModule',
	
	requires: [
	           'amdaUI.PlotUI',
	           'amdaPlotObj.PlotRequestObject',
	           'amdaModel.PlotNode',
	           'amdaUI.PlotTabResultUI',
	           'amdaPlotComp.PlotPreviewUI'
	],
	
	contentId : 'plotUI',
    linkedNode : null,
    
    /**
     * @cfg {String} data models
     * @required
     */
    nodeDataModel : 'amdaModel.PlotNode',
    
    /**
     * @cfg {String} window definitions
     * @required
     */
    width: 600, 
    height: 620,
    uiType : 'newPanelPlot',
    helpTitle : 'Help on Plot Module',
    
    plotResultWindowsManager : new Ext.AbstractManager(),
    
    computeResultWindowSize : function(panelResult)
	{
	    var size = panelResult.getImageSize();
	    size.width  += 30;
	    size.height += 95;
	    
	    return size;
	},
	
	computePreviewWindowSize : function(previewContent)
	{
	    var size = previewContent.getImageSize();
	    size.width  += 30;
	    size.height += 65;
	    
	    return size;
	},
    
    updateInteractiveSession : function(session, newplot) {
    	var me = this;
    	
    	
    	
    	Ext.each(session.result, function (tabResult, index) {
    		if (tabResult.preview)
        	{
    			var plotPreviewConfig = {
    					folder   : session.folder,
    					plotFile : tabResult.plot,
    					context  : tabResult.context,
    					tabId    : tabResult.id		
    			};
    			me.updatePreview(plotPreviewConfig);
        		return;
        	}
    		
    		var winResultId = tabResult.id+"-win";
    		
    		var winResult = me.getWindowResult(winResultId);
    		
    		var plotTabConfig = {
					folder   : session.folder,
					plotFile : tabResult.plot,
					context  : tabResult.context,
					tabId    : tabResult.id,
					multiplot : tabResult.multiplot,
					superposeMode : tabResult.superposeMode,
					isInterval: tabResult.isInterval,
					ttName : tabResult.ttName,
					ttIndex : tabResult.ttIndex,
					ttNbIntervals : tabResult.ttNbIntervals,
					ttFileIndex : tabResult.ttFileIndex
			};
    		
    		if (winResult == null) {
    			
    			var x = 50 + tabResult.index * 50;
    		    var y = 100 + tabResult.index * 20;
    			
    			//create new result win
    			var panelResult = new amdaUI.PlotTabResultUI(plotTabConfig);
    		
    			var size = me.computeResultWindowSize(panelResult);
    		
    			var win = myDesktopApp.getDesktop().createWindow({
    				id    : tabResult.id+"-win",
    				title : 'Plot '+(tabResult.index+1),
    				width : size.width,
    				height: size.height,
    				x : x,
    				y : y,
    				layout: 'fit',
    				items : [ 
    				         panelResult 
    				],
    				listeners: {
    					scope: me,				  
    					beforeclose: function(win,opt) {
    						me.plotResultWindowsManager.unregister(win);
    					}
    				},
    				getPanelResult: function() {
    					return panelResult;
    				}
    			});
    			win.show();
    			me.plotResultWindowsManager.register(win);
    		}
    		else
    		{
    			//update result
    			winResult.getPanelResult().updatePlotImage(plotTabConfig, newplot);
    			//update window size
    			var size = me.computeResultWindowSize(winResult.getPanelResult());
    			winResult.setSize(size.width, size.height);
    			
    			winResult.toFront();
    		}
    	});
    },
    
    closeInteractiveSession : function() {
    	var me = this;
    	this.plotResultWindowsManager.each(function (key, value, length) {
    		value.close();
    	});
    },
    
    updatePreview : function(plotPreviewConfig) {
    	var winPreviewId = "plot-preview-win";
		
		var winPreview = this.getWindowResult(winPreviewId);
		
		if (winPreview == null) {
			//create new preview win
			var previewContent = new amdaPlotComp.PlotPreviewUI(plotPreviewConfig);
		
			var size = this.computePreviewWindowSize(previewContent);
			
			var win = myDesktopApp.getDesktop().createWindow({
				id    : winPreviewId,
				title : 'Plot Preview',
				width : size.width,
				height: size.height,
				layout: 'fit',
				items : [ 
				         previewContent 
				],
				listeners: {
					scope: this,				  
					beforeclose: function(win,opt) {
						this.plotResultWindowsManager.unregister(win);
					}
				},
				getPreviewContent: function() {
					return previewContent;
				}
			});
			win.show();
			this.plotResultWindowsManager.register(win);
		}
		else
		{
			//update result
			winPreview.getPreviewContent().updatePlotImage(plotPreviewConfig);
			//update window size
			var size = this.computePreviewWindowSize(winPreview.getPreviewContent());
			winPreview.setSize(size.width, size.height);
			winPreview.toFront();
		}
    },
    
    getInteractiveMultiPlotState : function() {
    	var state = {};
    	this.plotResultWindowsManager.each(function (key, value, length) {
    		if (value.getPanelResult)
    			state[value.getPanelResult().tabId] = value.getPanelResult().getInteractiveMultiPlotState();
    	});
    	return state;
    },
    
    getWindowResult: function(winResultId){
	    if (!this.plotResultWindowsManager.get(winResultId)) return null;
	    return this.plotResultWindowsManager.get(winResultId);	    
	}
});