Blame view

js/app/controllers/PlotModule.js 9.6 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
/** 
 * Project   : AMDA-NG
 * Name      : PlotModule.js
 * @class    amdaDesktop.PlotModule
 * @extends  amdaDesktop.InteractiveModule
18d4a11e   Benjamin Renard   Save and load plo...
6
7
8
 * @brief    New Plot Module controller definition 
 * @author   Benjamin Renard
 * $Id: PlotModule.js benjamin $
16035364   Benjamin Renard   First commit
9
10
11
 */

Ext.define('amdaDesktop.PlotModule', {
18d4a11e   Benjamin Renard   Save and load plo...
12
13
14
15
	extend: 'amdaDesktop.InteractiveModule',
	
	requires: [
	           'amdaUI.PlotUI',
6f513d3f   Benjamin Renard   WIP
16
17
	           'amdaPlotObj.MultiplotRequestObject',
	           'amdaModel.MultiplotNode',
c9071a43   Benjamin Renard   Add instant plot ...
18
	           'amdaUI.PlotTabResultUI',
4efeb459   Benjamin Renard   First version for...
19
20
	           'amdaPlotComp.PlotPreviewUI',
		   'amdaUI.MultiPlotUI'
18d4a11e   Benjamin Renard   Save and load plo...
21
22
23
	],
	
	contentId : 'plotUI',
16035364   Benjamin Renard   First commit
24
    linkedNode : null,
16035364   Benjamin Renard   First commit
25
    
16035364   Benjamin Renard   First commit
26
    /**
18d4a11e   Benjamin Renard   Save and load plo...
27
28
29
     * @cfg {String} data models
     * @required
     */
6f513d3f   Benjamin Renard   WIP
30
    nodeDataModel : 'amdaModel.MultiplotNode',
16035364   Benjamin Renard   First commit
31
32
33
34
35
    
    /**
     * @cfg {String} window definitions
     * @required
     */
d341347d   Elena.Budnik   Plot Mgr ameliora...
36
37
    width: 650, 
    height: 670,
18d4a11e   Benjamin Renard   Save and load plo...
38
39
    uiType : 'newPanelPlot',
    helpTitle : 'Help on Plot Module',
6cf1dca2   Elena.Budnik   help file
40
41
    helpFile : 'plotHelp',
     
18d4a11e   Benjamin Renard   Save and load plo...
42
    plotResultWindowsManager : new Ext.AbstractManager(),
4efeb459   Benjamin Renard   First version for...
43
44
45
 
    multiPlotWin: null,
   
5c744625   Benjamin Renard   Synchronize reque...
46
47
48
49
50
51
    computeResultWindowSize : function(panelResult) {
        var size = panelResult.getImageSize();
        size.width  += 30;
        size.height += 95;
        return size;
    },
c9071a43   Benjamin Renard   Add instant plot ...
52
	
5c744625   Benjamin Renard   Synchronize reque...
53
54
55
56
57
58
    computePreviewWindowSize : function(previewContent) {
        var size = previewContent.getImageSize();
        size.width  += 30;
        size.height += 65;
        return size;
    },
18d4a11e   Benjamin Renard   Save and load plo...
59
    
87658ba0   Benjamin Renard   TT Navigation in ...
60
    updateInteractiveSession : function(session, newplot) {
5c744625   Benjamin Renard   Synchronize reque...
61
        var me = this;
2cfa3a1a   Benjamin Renard   Give the possibil...
62

5c744625   Benjamin Renard   Synchronize reque...
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

        Ext.each(session.result, function (tabResult, index) {
            if (logExecTime && tabResult.exectime) {
                console.log("CMD EXEC TIME FOR "+tabResult.plot+" = "+tabResult.exectime+"ms");
            }

            if (tabResult.preview) {
                var plotPreviewConfig = {
                    folder   : session.folder,
                    plotFile : tabResult.plot,
                    context  : tabResult.context,
                    interactiveId    : tabResult.id		
                };
                me.updatePreview(plotPreviewConfig);
                return;
            }

            var winResultId = tabResult.id+"-win";
18d4a11e   Benjamin Renard   Save and load plo...
81
    		
5c744625   Benjamin Renard   Synchronize reque...
82
            var winResult = me.getWindowResult(winResultId);
18d4a11e   Benjamin Renard   Save and load plo...
83
    		
5c744625   Benjamin Renard   Synchronize reque...
84
85
86
87
88
89
90
91
92
            var plotTabConfig = {
                folder   : session.folder,
                plotFile : tabResult.plot,
                context  : tabResult.context,
                interactiveId : tabResult.id,
                isInterval: tabResult.isInterval,
                ttName : tabResult.ttName,
                ttIndex : tabResult.ttIndex,
                ttNbIntervals : tabResult.ttNbIntervals,
27a055f4   Benjamin Renard   Multiplot (#8314)
93
94
                ttFileIndex : tabResult.ttFileIndex,
                multiplot: tabResult.multiplot
5c744625   Benjamin Renard   Synchronize reque...
95
            };
18d4a11e   Benjamin Renard   Save and load plo...
96
    		
5c744625   Benjamin Renard   Synchronize reque...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
            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 : tabResult.title,
                    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);
27a055f4   Benjamin Renard   Multiplot (#8314)
120
121
                        },
                        afterrender: function(win,opt) {
55b10506   Benjamin Renard   Update correctly ...
122
                            win.getPanelResult().updateConfig(tabResult.title, tabResult.multiplot);
5c744625   Benjamin Renard   Synchronize reque...
123
124
125
126
                        }
                    },
                    getPanelResult: function() {
                        return panelResult;
27a055f4   Benjamin Renard   Multiplot (#8314)
127
128
129
                    },
                    updateTitle: function(multiplot) {
                        win.setTitle(tabResult.title + (multiplot ? ' - Synchronized to multiplot' : ''));
5c744625   Benjamin Renard   Synchronize reque...
130
131
132
133
134
135
136
                    }
                });
                win.show();
                me.plotResultWindowsManager.register(win);
            }
            else {
                //update result
55b10506   Benjamin Renard   Update correctly ...
137
                winResult.getPanelResult().updateConfig(tabResult.title, tabResult.multiplot);
5c744625   Benjamin Renard   Synchronize reque...
138
                winResult.getPanelResult().updatePlotImage(plotTabConfig, newplot);
bb30f90e   Hacene SI HADJ MOHAND   9010 ok
139
140
141
                //update window size => not done see https://projects.irap.omp.eu/issues/9010
                //var size = me.computeResultWindowSize(winResult.getPanelResult());
                //winResult.setSize(size.width, size.height);
5c744625   Benjamin Renard   Synchronize reque...
142
143
144
                winResult.toFront();
            }
        });
18d4a11e   Benjamin Renard   Save and load plo...
145
146
147
    },
    
    closeInteractiveSession : function() {
5c744625   Benjamin Renard   Synchronize reque...
148
149
150
151
        var me = this;
        this.plotResultWindowsManager.each(function (key, value, length) {
            value.close();
        });
4efeb459   Benjamin Renard   First version for...
152
153
154
	if (this.multiPlotWin) {
		this.multiPlotWin.close();
	}
18d4a11e   Benjamin Renard   Save and load plo...
155
    },
5c744625   Benjamin Renard   Synchronize reque...
156

c9071a43   Benjamin Renard   Add instant plot ...
157
    updatePreview : function(plotPreviewConfig) {
5c744625   Benjamin Renard   Synchronize reque...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
        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();
        }
c9071a43   Benjamin Renard   Add instant plot ...
198
199
    },
    
18d4a11e   Benjamin Renard   Save and load plo...
200
201
202
    getWindowResult: function(winResultId){
	    if (!this.plotResultWindowsManager.get(winResultId)) return null;
	    return this.plotResultWindowsManager.get(winResultId);	    
57e15214   Benjamin Renard   Fix addParameter ...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
    },

    addParameter : function(paramNode) {
        var me = this;
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow(this.id);
        if (win) {
            me.getUiContent().addParameter(paramNode, false);
            win.show();
        }
        else {
            this.createWindow(function () {
                me.getUiContent().addParameter(paramNode, true);
            });
        }
2048f5bc   Benjamin Renard   Fix save & edit plot
218
219
220
221
222
223
224
225
    },

    editPlot : function(plotNode) {
        var me = this;
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow(this.id);
        if (win) {
            // Plot UI is opened => add plot in a new tab
55fa3bbc   Benjamin Renard   Reset plot reques...
226
            me.linkedNode.get('object').plots().add(plotNode);
2048f5bc   Benjamin Renard   Fix save & edit plot
227
228
229
230
231
232
233
234
235
236
237
238
            me.getUiContent().editPlot(plotNode);
            win.show();
        }
        else {
            // Plot UI is closed
            this.createWindow(null, function() {
                //This is the onAfterCreateObject callback
                //Add plot node to the multiplot object
                me.linkedNode.get('object').plots().removeAll();
                me.linkedNode.get('object').plots().add(plotNode);
            });
        }
84d442b4   Benjamin Renard   Synchronize plot ...
239
240
    },

5c744625   Benjamin Renard   Synchronize reque...
241
    syncAfterRename: function(renamedNode) {
84d442b4   Benjamin Renard   Synchronize plot ...
242
243
244
245
246
        var me = this;
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow(this.id);
        if (win) {
            me.getUiContent().updateTabs();
5c744625   Benjamin Renard   Synchronize reque...
247
            me.getUiContent().updateRequestName(renamedNode);
84d442b4   Benjamin Renard   Synchronize plot ...
248
        }
4efeb459   Benjamin Renard   First version for...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    },

    showMultiplotWin: function() {
	var me = this;
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow(this.id);

        if (!win) {
            return;
        }

	if (!this.multiPlotWin) {
		var multiPlotPanel = Ext.create('amdaUI.MultiPlotUI',
			{
                            plotWin: me.getUiContent()
			}
		);
		this.multiPlotWin = myDesktopApp.getDesktop().createWindow({
			id    : "multiplot-win",
			title : "Multi Plot Manager",
			width : 320,
			height: 320,
			minHeight: 300,
			minWidth: 320,
			layout: 'fit',
			items : [
				multiPlotPanel
			],
                        listeners: {
                            beforeclose: function(win,opt) {
                                me.multiPlotWin = null;
d4a8d462   Benjamin Renard   Improve MultiPlot...
280
                                me.getUiContent().enableSinglePlot(true);
27a055f4   Benjamin Renard   Multiplot (#8314)
281
				me.plotResultWindowsManager.each(function (key, value, length) {
55b10506   Benjamin Renard   Update correctly ...
282
					value.getPanelResult().updateConfig(value.getPanelResult().plotName, false);
27a055f4   Benjamin Renard   Multiplot (#8314)
283
				});
4efeb459   Benjamin Renard   First version for...
284
285
286
287
288
                            }
                        }
		});
	}

d4a8d462   Benjamin Renard   Improve MultiPlot...
289
        this.getUiContent().enableSinglePlot(false);
4efeb459   Benjamin Renard   First version for...
290
291
292
293
294
295
296
297
	this.multiPlotWin.show();

    },

    refreshMultiPlot: function() {
        if (this.multiPlotWin) {
            this.multiPlotWin.items.items[0].refreshMultiPlot();
        }
d4a8d462   Benjamin Renard   Improve MultiPlot...
298
        this.getUiContent().enableSinglePlot(!this.isMultiPlot());
4efeb459   Benjamin Renard   First version for...
299
300
301
302
    },

    isMultiPlot : function() {
        return this.multiPlotWin && !this.multiPlotWin.isHidden();
ebbb3638   Benjamin Renard   Edit plot tab on ...
303
    }
2cfa3a1a   Benjamin Renard   Give the possibil...
304
});