PlotSpectroForm.js 10.2 KB
/**
 * Project   : AMDA-NG
 * Name      : PlotSpectroForm.js
 * @class   amdaPlotComp.PlotSpectroForm
 * @extends amdaPlotComp.PlotStandardForm
 * @brief   Form to define specifics spectro options
 * @author  Benjamin Renard
 * @version $Id: PlotSpectroForm.js benjamin $
 */

Ext.define('amdaPlotComp.PlotSpectroForm', {
	extend: 'amdaPlotComp.PlotStandardForm',

	requires: [
		'amdaUI.ParamArgumentsUI'
	],
	setObject: function (object) {
		this.data = object.data;
		this.object = object.get('param-drawing-object');

		this.loadRecord(this.object);
	},

	getValuesRangeItems: function () {
		return [
			this.addStandardFloat2('spectro-value-min', 'Min value', -Number.MAX_VALUE, Number.MAX_VALUE, true),
			this.addStandardFloat2('spectro-value-max', 'Max value', -Number.MAX_VALUE, Number.MAX_VALUE, true)
		];
	},
	getFilteringItems: function () {
		return [
			this.addStandardCombo('filtering-level', 'Level', amdaPlotObj.PlotObjectConfig.availableFilteringLevel)
		];
	},

	/**
	 * Populate the comboBoxValue by the set of channel data related to the selected dimension
	 * @param {*} ref  the reference of the current instance of this class
	 * @param {*} index dimension's index
	 * @param {*} comboBoxV  the comboBoxValue
	 * @returns 
	 */
	populateComboBoxValue: (ref, index, comboBoxV) => {
		if (ref.data[amdaPlotObj.PlotObjectConfig.bgSubstraction.tableName][index].variable)
			return;

		const channelsData = ref.data[amdaPlotObj.PlotObjectConfig.bgSubstraction.tableName][index]
		[amdaPlotObj.PlotObjectConfig.bgSubstraction.tableChannels];

		const keyTemp = amdaPlotObj.PlotObjectConfig.fieldComboBox.key;
		const valueTemp = amdaPlotObj.PlotObjectConfig.fieldComboBox.value;

		const newDataForStore = [];
		//Loop through the channels
		for (channelIndex in channelsData) {
			const channelData = channelsData[channelIndex];
			let item = {};
			item[keyTemp] = channelIndex;
			item[valueTemp] = channelIndex + " : [" + channelData.min + " , " + channelData.max + "]";
			newDataForStore.push(item);
		}

		//Update the label of the field
		comboBoxV.setFieldLabel(ref.data[amdaPlotObj.PlotObjectConfig.bgSubstraction.tableName][index]["name"]
			+ " (" + ref.data[amdaPlotObj.PlotObjectConfig.bgSubstraction.tableName][index]["units"] + ") ");

		comboBoxV.store.loadData(newDataForStore);
	},

	/**
	 * Populate the comboBoxDim by the set of dimensions related to the selected parameter
	 * @param {*} ref the reference of the current instance of this class
	 * @param {*} comboBoxDim the comboBoxDim reference
	 */
	populateComboBoxDim: (ref, comboBoxDim) => {
		const keyTemp = amdaPlotObj.PlotObjectConfig.fieldComboBox.key;
		const valueTemp = amdaPlotObj.PlotObjectConfig.fieldComboBox.value;

		const newDataForStore = [];
		for (indexTable in ref.data[amdaPlotObj.PlotObjectConfig.bgSubstraction.tableName]) {
			const table = ref.data[amdaPlotObj.PlotObjectConfig.bgSubstraction.tableName][indexTable];
			let item = {};
			item[keyTemp] = indexTable;
			item[valueTemp] = table[amdaPlotObj.PlotObjectConfig.bgSubstraction.tableRelatedDim];
			newDataForStore.push(item);
		}

		//Set the new store
		comboBoxDim.store.loadData(newDataForStore);
	},

	/**
	 * Add a textInput which holds Background Substraction value when fixedvalue is selected
	 * @param {*} ref the reference of the current instance of this class
	 * @returns addStandardFloat2
	 */
	addComboBoxBackgroundSubFixedValue: (ref) => {
		return ref.addStandardFloat2(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.textinputkey,
			amdaPlotObj.PlotObjectConfig.bgSubstraction.value.textinputlabel, 0
			, Number.MAX_VALUE, true, true, (name, newValue, oldValue) => {
				if (oldValue !== newValue) {
					if (!newValue) {
						ref.object.set(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.key,
							amdaPlotObj.PlotObjectConfig.bgSubstraction.value.dimNullValue);
						return;
					}
					ref.object.set(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.key,
						newValue);
				}
			});
	},

	/**
	 * Reset ComboBoxDim and textInput
	 * 
	 * @param {*} ref the reference of the current instance of this class
	 */
	resetDependentComponents: (ref) => {
		const comboBoxDim = ref.getForm().findField(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.dimkey);
		ref.populateComboBoxDim(ref, comboBoxDim);
		comboBoxDim.setVisible(false);
		comboBoxDim.setValue(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.dimNullValue);

		const textInputV = ref.getForm().findField(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.textinputkey);
		textInputV.setVisible(false);
		textInputV.setValue(null);
	},

	/**
	 * Add a comboBox which holds Background Substraction type : bychannel, fixedvalue
	 * @param {*} ref the reference of the current instance of this class
	 * @returns StandardCombo
	 */
	addComboBoxBackgroundSubType: (ref) => {
		const data = [];
		for (value in amdaPlotObj.PlotObjectConfig.bgSubstraction.type.values) {
			const keyTemp = amdaPlotObj.PlotObjectConfig.fieldComboBox.key;
			const valueTemp = amdaPlotObj.PlotObjectConfig.fieldComboBox.value;
			let item = {};
			item[keyTemp] = value;
			item[valueTemp] = amdaPlotObj.PlotObjectConfig.bgSubstraction.type.values[value];
			data.push(item);
		}

		const comboBoxType = ref.addStandardCombo(amdaPlotObj.PlotObjectConfig.bgSubstraction.type.key,
			amdaPlotObj.PlotObjectConfig.bgSubstraction.type.label, data,
			(name, newKey, oldKey) => {
				if (newKey !== oldKey) {
					const newValue = amdaPlotObj.PlotObjectConfig.bgSubstraction.type.values[newKey];
					if (newKey === null || newValue === undefined) {
						ref.resetDependentComponents(ref);
						return;
					}

					//ComboBoxDim
					const comboBoxDim = ref.getForm().findField(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.dimkey);
					//Fixed value input
					const textInputV = ref.getForm().findField(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.textinputkey);

					//By channel
					if (newValue === amdaPlotObj.PlotObjectConfig.bgSubstraction.type.values.bychannel) {
						const nbDims = ref.data[amdaPlotObj.PlotObjectConfig.bgSubstraction.tableName].length;
						//Show comboBoxDim
						comboBoxDim.select(comboBoxDim.store.getAt(0));
						if (nbDims > 1)
							comboBoxDim.setVisible(true);

						//Hide comboBoxDim
						else
							comboBoxDim.setVisible(false);

						//Hide text input
						textInputV.setValue(null);
						textInputV.setVisible(false);
					}
					//By fixed value
					else if (newValue === amdaPlotObj.PlotObjectConfig.bgSubstraction.type.values.fixedvalue) {
						//Hide comboBoxDim
						comboBoxDim.setVisible(false);
						comboBoxDim.setValue(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.dimNullValue);
						//Show text input
						textInputV.setValue(null);
						textInputV.setVisible(true);
					}
					//Another value
					else {
						console.warn("Unkown key : ", newKey);
					}
				}
			});

		return comboBoxType;
	},

	/**
	 * Add a comboBox which holds Background Substraction value
	 * @param {*} ref the reference of the current instance of this class
	 * @returns StandardCombo
	 */
	addComboBoxBackgroundSubValue: (ref) => {
		const comboBoxValue = ref.addStandardCombo(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.key,
			"", [],
			(name, newKey, oldKey) => {
				if (newKey !== oldKey) {
					ref.object.set(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.key,
						newKey);
				}
			});

		return comboBoxValue;
	},

	/**
	 * Add a comboBox which holds Background Substraction dimension
	 * @param {*} ref the reference of the current instance of this class
	 * @returns StandardCombo
	 */
	addComboBoxBackgroundSubDim: (ref) => {
		const comboBoxDim = ref.addStandardCombo(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.dimkey,
			amdaPlotObj.PlotObjectConfig.bgSubstraction.value.dimlabel, [],
			(name, newKey, oldKey) => {
				const comboBoxV = ref.getForm().findField(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.key);

				if (newKey === amdaPlotObj.PlotObjectConfig.bgSubstraction.value.dimNullValue) {
					comboBoxV.setValue(-1);
					comboBoxV.setVisible(false);
					return;
				}

				if (newKey !== null && newKey !== undefined) {
					comboBoxV.setVisible(true);
					ref.populateComboBoxValue(ref, newKey, comboBoxV);
					comboBoxV.select(comboBoxV.store.getAt(0));
				}

				ref.object.set(amdaPlotObj.PlotObjectConfig.bgSubstraction.value.dimkey,
					newKey);

			});

		return comboBoxDim;
	},

	/**
	 * Add Background Substraction items
	 * @returns StandardFieldSet
	 */
	getBackgroundSubItems: function () {
		return [
			this.addComboBoxBackgroundSubType(this),
			this.addComboBoxBackgroundSubDim(this),
			this.addComboBoxBackgroundSubValue(this),
			this.addComboBoxBackgroundSubFixedValue(this)
		];
	},

	getFormItems: function () {
		const ref = this;
		const field = this.addStandardFieldSet(amdaPlotObj.PlotObjectConfig.bgSubstraction.name,
			amdaPlotObj.PlotObjectConfig.bgSubstraction.name, this.getBackgroundSubItems(),
			function (name, newKey, oldKey) {
				if (newKey !== oldKey) {
					const comboBoxType = ref.getForm().findField(amdaPlotObj.PlotObjectConfig.bgSubstraction.type.key);
					comboBoxType.setValue(null);
				}
			});

		return [
			this.addStandardCombo('spectro-resolution', 'Points per plot', amdaPlotObj.PlotObjectConfig.availableResolutions, function (name, value, oldValue) {
				ref.object.set('spectro-resolution', value);
			}),
			this.addStandardCombo('spectro-yaxis', 'Y axis', amdaPlotObj.PlotObjectConfig.availableYAxes, function (name, value, oldValue) {
				ref.object.set('spectro-yaxis', value);
				ref.crtTree.refresh();
			}),
			myDesktopApp.addAmdaInfo('MinMaxThreshold', 'vertical-align:bottom'),
			this.addStandardFieldSet('Min/Max thresholds', '', this.getValuesRangeItems()),
			this.addStandardCheck('spectro-log0-as-min', 'Show 0 values as Min Values in log scale', function (name, value, oldValue) {
				ref.object.set('spectro-log0-as-min', value);
			}),
			this.addStandardCombo('spectro-normalization', 'Normalization', amdaPlotObj.PlotObjectConfig.availableSpectroNormalization, function (name, value, oldValue) {
				if (ref.object.get('spectro-normalization') != value) {
					ref.object.set('spectro-normalization', value);
				}
			}),
			this.addStandardFieldSet('Spike Filtering ( ! Experimental ! )', 'filtering-activated', this.getFilteringItems()),
			field
		];
	}
});