interactivemie.h 8.31 KB
#ifndef INTERACTIVEMIE_H
#define INTERACTIVEMIE_H

#include <QtGui/QMainWindow>
#include <QDragEnterEvent>
#include <qfiledialog.h>
#include <qinputdialog.h>
#include "ui_interactivemie.h"
#include "globals.h"

class InteractiveMie : public QMainWindow
{
	Q_OBJECT

public:
	InteractiveMie(QWidget *parent = 0, Qt::WFlags flags = 0);
	~InteractiveMie();
	bool updating;

	void refreshUI()
	{
		updating = true;

		ui.spinNuMin->setValue(nuMin);
		ui.spinNuMax->setValue(nuMax);
		ui.spinAMin->setValue(aMin);
		ui.spinAMax->setValue(aMax);
		ui.spinRadius->setValue(radius);
		ui.spinBaseIR->setValue(baseIR);
		ui.spinScaleK->setValue(cA);
		ui.spinObjNAi->setValue(oNAi);
		ui.spinObjNAo->setValue(oNAo);
		ui.spinCondNAi->setValue(cNAi);
		ui.spinCondNAo->setValue(cNAo);
		ui.spinError->setValue(minMSE);
		ui.spinMaxIter->setValue(maxFitIter);
		ui.spinI0Scale->setValue(scaleI0);

		//display spectra values
		ui.chkDisplaySimSpec->setChecked(dispSimSpec);
		ui.chkDisplayRefSpec->setChecked(dispRefSpec);
		ui.chkDisplaySimK->setChecked(dispSimK);
		ui.chkDisplayMatK->setChecked(dispMatK);
		ui.chkDisplaySimN->setChecked(dispSimN);
		ui.chkDisplayMatN->setChecked(dispMatN);
		ui.spinDispScaleK->setValue(dispScaleK);
		ui.spinDispScaleN->setValue(dispScaleN);

		//material selection combo box
		ui.cmbMaterial->clear();
		for(unsigned int i=0; i<MaterialList.size(); i++)
			ui.cmbMaterial->addItem(MaterialList[i].name.c_str(), i);
		ui.cmbMaterial->setCurrentIndex(currentMaterial);

		updating = false;

	}

	void dragEnterEvent(QDragEnterEvent *event)
	{
		cout<<"This is a test."<<endl;
		QStringList s = event->mimeData()->formats();
		if (event->mimeData()->hasFormat("application/x-qt-windows-mime;value=\"FileName\"") ||
			event->mimeData()->hasFormat("text/plain"))
		{
			event->acceptProposedAction();
			
		}
	}

	void dropEvent(QDropEvent *event)
	{
		//cout<<"Challenge Accepted."<<endl;
		RefSpectrum.clear();
		RefSpectrum.push_back(SetReferenceSpectrum(event->mimeData()->text().toAscii().data()));
		UpdateDisplay();
	}

private:
	Ui::InteractiveMieClass ui;

public slots:
	//display parameters
	void on_spinNuMin_valueChanged(int i){
		nuMin = (float)i;
		UpdateDisplay();
	}
	void on_spinNuMax_valueChanged(int i){
		nuMax = (float)i;
		UpdateDisplay();
	}
	void on_spinAMin_valueChanged(double d){
		aMin = d;
		UpdateDisplay();
	}
	void on_spinAMax_valueChanged(double d){
		aMax = d;
		UpdateDisplay();
	}
	void on_chkDisplaySimSpec_clicked(bool b){
		dispSimSpec = b;
		UpdateDisplay();
	}
	void on_chkDisplayRefSpec_clicked(bool b){
		dispRefSpec = b;
		UpdateDisplay();
	}	
	void on_chkDisplaySimK_clicked(bool b){
		dispSimK = b;
		UpdateDisplay();
	}
	void on_chkDisplayMatK_clicked(bool b){
		dispMatK = b;
		UpdateDisplay();
	}
	void on_chkDisplaySimN_clicked(bool b){
		dispSimN = b;
		UpdateDisplay();
	}
	void on_chkDisplayMatN_clicked(bool b){
		dispMatN = b;
		UpdateDisplay();
	}
	void on_spinDispScaleK_valueChanged(double d){
		dispScaleK = d;
		UpdateDisplay();
	}
	void on_spinDispScaleN_valueChanged(double d){
		dispScaleN = d;
		UpdateDisplay();
	}
	void on_radDisplayAbsorbance_clicked(bool b){
		dispSimType = AbsorbanceSpecType;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_radDisplayIntensity_toggled(bool b){
		dispSimType = IntensitySpecType;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_chkNormalize_clicked(bool b){
		dispNormalize = b;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_spinNormFactor_valueChanged(double d){
		dispNormFactor = d;
		SimulateSpectrum();
		UpdateDisplay();
	}

	//material parameters
	void on_spinRadius_valueChanged(double d){
		radius = d;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_spinBaseIR_valueChanged(double d){
		baseIR = d;
		ChangeAbsorbance();
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_spinScaleK_valueChanged(double d){
		cA = d;
		ChangeAbsorbance();
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_chkApplyMaterial_clicked(bool b){
		applyMaterial = b;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_cmbMaterial_currentIndexChanged(int i){
		if(updating) return;

		currentMaterial = i;
		SetMaterial();
		SimulateSpectrum();
		UpdateDisplay();
		refreshUI();
	}

	//optical parameters
	void on_spinCondNAi_valueChanged(double d){
		cNAi = d;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_spinCondNAo_valueChanged(double d){
		cNAo = d;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_spinObjNAi_valueChanged(double d){
		oNAi = d;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_spinObjNAo_valueChanged(double d){
		oNAo = d;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_radTransmissionOptics_clicked(bool d){
		ui.spinCondNAi->setEnabled(true);
		ui.spinCondNAo->setEnabled(true);
		opticsMode = TransmissionOpticsType;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_radReflectionOptics_clicked(bool d){
		ui.spinCondNAi->setEnabled(false);
		ui.spinCondNAo->setEnabled(false);
		ui.radDisplayAbsorbance->setEnabled(false);
		ui.radDisplayIntensity->setChecked(true);
		opticsMode = ReflectionOpticsType;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_chkPointDetector_clicked(bool b){
		if(b)
		{
			pointDetector = true;
			ui.spinObjectiveSamples->setEnabled(false);
		}
		else
		{
			pointDetector = false;
			ui.spinObjectiveSamples->setEnabled(true);
		}

		SimulateSpectrum();
		UpdateDisplay();
	}

	void on_spinObjectiveSamples_valueChanged(int i){
		objectiveSamples = i;
		SimulateSpectrum();
		UpdateDisplay();
	}

	//Fitting
	void on_spinMaxIter_valueChanged(int i){
		maxFitIter = i;
	}
	void on_spinError_valueChanged(double d){
		minMSE = d;
	}
	void on_spinI0Scale_valueChanged(double d){
		scaleI0 = d;
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_spinRefSlope_valueChanged(double d){
		refSlope = d;
		UpdateDisplay();
	}

	//display settings

	//Buttons
	void on_btnFit_clicked(){
		FitDisplay();
		refreshUI();
	}
	void on_btnSave_clicked(){
		SaveState();
	}
	void on_btnReset_clicked(){
		SetDefaults();
		SimulateSpectrum();
		UpdateDisplay();
		refreshUI();
	}
	void on_btnResetK_clicked(){
		ChangeAbsorbance();
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_btnEstimateK_clicked(){
		EstimateMaterial();
		SimulateSpectrum();
		UpdateDisplay();
	}
	void on_btnDistortion_clicked(){
		//ComputeDistortion();
		MinimizeDistortion();
	}
	void on_btnTimings_clicked(){
		PD.PrintResults(cout);
	}

	//menu items
	void on_mnuLoadReference_triggered(){
		QString fileName = QFileDialog::getOpenFileName(this, tr("Open Reference Spectrum"));

		if(fileName != QString::null){
			RefSpectrum.clear();
			RefSpectrum.push_back(LoadSpectrum(fileName.toAscii().data()));
		}
		UpdateDisplay();
	}

	void on_mnuLoadMaterial_triggered(){

		//first load the imaginary part
		QString kFileName = QFileDialog::getOpenFileName(this, tr("Open Imaginary (k) Spectrum"));
		
		//exit if no file was selected
		if(kFileName == QString::null)
			return;

		QString nFileName = QFileDialog::getOpenFileName(this, tr("Open Imaginary (n) Spectrum"));

		//request the material name
		QString matName = QInputDialog::getText(this, tr("Material Name"), tr("Enter material name:"));

		//if a real part was given, load both
		if(nFileName != QString::null)
			LoadMaterial(kFileName.toAscii().data(), nFileName.toAscii().data(), matName.toAscii().data());
		else
			LoadMaterial(kFileName.toAscii().data(), matName.toAscii().data());

		//add the new material to the combo box
		refreshUI();
	}

	void on_mnuSaveSim_triggered(){
		//first load the imaginary part
		QString fileName = QFileDialog::getSaveFileName(this, tr("Save Simulated Spectrum"));
		SaveSimulation(fileName.toAscii().data());
	}

	void on_mnuSaveK_triggered(){
		//first load the imaginary part
		QString fileName = QFileDialog::getSaveFileName(this, tr("Save Imaginary Index of Refraction (k)"));
		SaveK(fileName.toAscii().data());
	}

	void on_mnuSaveN_triggered(){
		//first load the imaginary part
		QString fileName = QFileDialog::getSaveFileName(this, tr("Save Real Index of Refraction (n)"));
		SaveN(fileName.toAscii().data());
	}



};

#endif // INTERACTIVEMIE_H