VESPERS2DScanConfiguration::VESPERS2DScanConfiguration(QObject *parent)
	: AMStepScanConfiguration(parent), VESPERSScanConfiguration()
{
	setName("2D Map");
	setUserScanName("2D Map");
	dbObject_->setParent(this);
	setIncomingChoice(VESPERS::Imini);
	setFluorescenceDetector(VESPERS::SingleElement);
	setMotor(VESPERS::Motors(VESPERS::H | VESPERS::V));
	setCCDDetector(VESPERS::NoCCD);
	setCCDFileName("");
	setExportAsAscii(true);
	setExportSpectraSources(true);
	setExportSpectraInRows(true);
	setCloseFastShutter(true);
	setReturnToOriginalPosition(false);

	AMScanAxisRegion *region = new AMScanAxisRegion;
	AMScanAxis *axis = new AMScanAxis(AMScanAxis::StepAxis, region);
	appendScanAxis(axis);
	region = new AMScanAxisRegion;
	axis = new AMScanAxis(AMScanAxis::StepAxis, region);
	appendScanAxis(axis);

	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionTimeChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(dbObject_, SIGNAL(ccdDetectorChanged(int)), this, SLOT(computeTotalTime()));
}
SXRMB2DMapScanConfiguration::SXRMB2DMapScanConfiguration(QObject *parent)
	: AMStepScanConfiguration(parent), SXRMBScanConfiguration()
{
	timeOffset_ = 0.8;

	setName("2D Map");
	setUserScanName("2D Map");
	setEnergy(3000.0);

	exportAsAscii_ = false;

	AMScanAxisRegion *region = new AMScanAxisRegion;
	AMScanAxis *axis = new AMScanAxis(AMScanAxis::StepAxis, region);
	appendScanAxis(axis);
	region = new AMScanAxisRegion;
	axis = new AMScanAxis(AMScanAxis::StepAxis, region);
	appendScanAxis(axis);

	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionTimeChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime()));
}
VESPERSSpatialLineScanConfiguration::VESPERSSpatialLineScanConfiguration(QObject *parent)
	: AMStepScanConfiguration(parent), VESPERSScanConfiguration()
{
	setName("Line Scan");
	setUserScanName("Line Scan");
	dbObject_->setParent(this);
	setIncomingChoice(VESPERS::Imini);
	setFluorescenceDetector(VESPERS::SingleElement);
	setMotor(VESPERS::H);
	setCCDDetector(VESPERS::NoCCD);
	setCCDFileName("");
	setExportSpectraSources(true);
	setExportSpectraInRows(true);
	setOtherPosition(-123456789.0);
	setCloseFastShutter(true);
	setReturnToOriginalPosition(false);

	AMScanAxisRegion *region = new AMScanAxisRegion;
	AMScanAxis *axis = new AMScanAxis(AMScanAxis::StepAxis, region);
	appendScanAxis(axis);

	connect(this, SIGNAL(startChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(stepChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(endChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(timeChanged(double)), this, SLOT(computeTotalTime()));
	connect(dbObject_, SIGNAL(ccdDetectorChanged(int)), this, SLOT(computeTotalTime()));
}
VESPERSEXAFSScanConfiguration::VESPERSEXAFSScanConfiguration(QObject *parent)
	: AMEXAFSScanConfiguration(parent), VESPERSScanConfiguration()
{
	regions_->setSensibleRange(-30, 40);
	exafsRegions()->setDefaultEdgeEnergy(0); // Everything for XAS related scans on VESPERS is done using relative energy to the edge on a PV level.
	exafsRegions()->setEnergyControl(VESPERSBeamline::vespers()->energyRelative());
	exafsRegions()->setTimeControl(VESPERSBeamline::vespers()->masterDwellTime());
	exafsRegions()->setKControl(VESPERSBeamline::vespers()->kControl());
	exafsRegions()->setDefaultIsRelative(true);
	regions_->setDefaultUnits(" eV");
	regions_->setDefaultTimeUnits(" s");
	setName("XAS Scan");
	setUserScanName("XAS Scan");
	dbObject_->setParent(this);
	setFluorescenceDetector(VESPERS::NoXRF);
	setTransmissionChoice(VESPERS::Ipost);
	setIncomingChoice(VESPERS::Imini);
	edge_ = "";
	energy_ = 0.0;
	useFixedTime_ = false;
	numberOfScans_ = 1;

	goToPosition_ = false;
	position_ = qMakePair(0.0, 0.0);
	setExportSpectraSources(true);
	connect(regions_, SIGNAL(regionsChanged()), this, SLOT(computeTotalTime()));
	connect(regions_, SIGNAL(regionsChanged()), this, SLOT(onEXAFSRegionsChanged()));
	connect(VESPERSBeamline::vespers()->variableIntegrationTime(), SIGNAL(a0Changed(double)), this, SLOT(computeTotalTime()));
	connect(VESPERSBeamline::vespers()->variableIntegrationTime(), SIGNAL(a1Changed(double)), this, SLOT(computeTotalTime()));
	connect(VESPERSBeamline::vespers()->variableIntegrationTime(), SIGNAL(a2Changed(double)), this, SLOT(computeTotalTime()));
}
void REIXSXASScanConfigurationView::setupConnections()
{
	// Make connections: from widgets to scan configuration.
	connect(applyGratingBox_, SIGNAL(clicked(bool)), config_, SLOT(setApplyMonoGrating(bool)));
	connect(applyMirrorBox_, SIGNAL(clicked(bool)), config_, SLOT(setApplyMonoMirror(bool)));
	connect(applySlitWidthBox_, SIGNAL(clicked(bool)), config_, SLOT(setApplySlitWidth(bool)));
	connect(applyPolarizationBox_, SIGNAL(clicked(bool)), config_, SLOT(setApplyPolarization(bool)));
	connect(namedAutomaticallyBox_, SIGNAL(clicked(bool)), config_, SLOT(setNamedAutomatically(bool)));

	connect(gratingBox_, SIGNAL(currentIndexChanged(int)), config_, SLOT(setMonoGrating(int)));
	connect(mirrorBox_, SIGNAL(currentIndexChanged(int)), config_, SLOT(setMonoMirror(int)));
	connect(slitWidthBox_, SIGNAL(valueChanged(double)), config_, SLOT(setSlitWidth(double)));
	connect(polarizationBox_, SIGNAL(currentIndexChanged(int)), config_, SLOT(setPolarization(int)));
	connect(polarizationAngleBox_, SIGNAL(valueChanged(double)), config_, SLOT(setPolarizationAngle(double)));
	connect(nameEdit_, SIGNAL(textEdited(QString)), config_, SLOT(setUserScanName(QString)));
	connect(sampleSelector_, SIGNAL(currentSampleChanged(int)), config_, SLOT(setSampleId(int)));
	connect(namedAutomaticallyBox_, SIGNAL(clicked(bool)), config_, SLOT(setNamedAutomatically(bool)));

	// Make connections: from widgets to enable/disable other widgets
	connect(applyGratingBox_, SIGNAL(clicked(bool)), gratingBox_, SLOT(setEnabled(bool)));
	connect(applyMirrorBox_, SIGNAL(clicked(bool)), mirrorBox_, SLOT(setEnabled(bool)));
	connect(applySlitWidthBox_, SIGNAL(clicked(bool)), slitWidthBox_, SLOT(setEnabled(bool)));
	connect(applyPolarizationBox_, SIGNAL(clicked(bool)), polarizationBox_, SLOT(setEnabled(bool)));
	connect(applyPolarizationBox_, SIGNAL(clicked(bool)), this, SLOT(reviewPolarizationAngleBoxEnabled()));
	connect(polarizationBox_, SIGNAL(activated(int)), this, SLOT(reviewPolarizationAngleBoxEnabled()));
	connect(namedAutomaticallyBox_, SIGNAL(clicked(bool)), nameEdit_, SLOT(setDisabled(bool)));
	connect(namedAutomaticallyBox_, SIGNAL(clicked(bool)), sampleSelector_, SLOT(setDisabled(bool)));

	connect(config_, SIGNAL(totalTimeChanged(double)), this, SLOT(onEstimatedTimeChanged()));
	connect(config_, SIGNAL(scanAxisAdded(AMScanAxis*)), this, SLOT(onEstimatedTimeChanged()));
	connect(config_, SIGNAL(scanAxisRemoved(AMScanAxis*)), this, SLOT(onEstimatedTimeChanged()));
	connect(config_, SIGNAL(modifiedChanged(bool)), this, SLOT(onEstimatedTimeChanged()));
	connect(config_, SIGNAL(configurationChanged()), this, SLOT(onEstimatedTimeChanged()));
}
SGMXASScanConfiguration::SGMXASScanConfiguration(QObject *parent)
	: AMGenericContinuousScanConfiguration(parent)
{
	setName("SGM XAS");
	setUserScanName("SGM XAS");
	setAutomaticDirectionAssessment(true);
	setDirection(Increase);

	setControl(0, SGMBeamline::sgm()->energyControlSet()->energy()->toInfo());
	scanAxes_.at(0)->regionAt(0)->setRegionStep(1);
}
AMEXAFSScanConfiguration::AMEXAFSScanConfiguration(const AMEXAFSScanConfiguration &original, bool setup)
	: AMXASScanConfiguration(original, false)
{
	if (setup){

		qDebug() << "Using AMEXAFSScanConfiguration copy constructor";
		setUserScanName(original.userScanName());
		regions_ = new AMEXAFSRegionsList(this);
		connect(regions_, SIGNAL(regionsChanged()), this, SLOT(onRegionsChanged()));
		connect(regions_, SIGNAL(regionsChanged()), this, SIGNAL(configurationChanged()));
	}
}
VESPERSTimeScanConfiguration::VESPERSTimeScanConfiguration(const VESPERSTimeScanConfiguration &original)
	: AMTimedRegionScanConfiguration(original), VESPERSScanConfiguration(original)
{
	setName(original.name());
	setUserScanName(original.name());
	dbObject_->setParent(this);
	setExportSpectraSources(original.exportSpectraSources());
	computeTotalTime();

	connect(this, SIGNAL(timeChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(timePerAcquisitionChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(iterationsChanged(int)), this, SLOT(computeTotalTime()));
	connect(dbObject_, SIGNAL(ccdDetectorChanged(int)), this, SLOT(computeTotalTime()));
}
SXRMB2DMapScanConfiguration::SXRMB2DMapScanConfiguration(const SXRMB2DMapScanConfiguration &original)
	: AMStepScanConfiguration(original), SXRMBScanConfiguration(original)
{
	setName(original.name());
	setUserScanName(original.userScanName());

	exportAsAscii_ = original.exportAsAscii();

	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionTimeChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime()));
}
VESPERSSpatialLineScanConfiguration::VESPERSSpatialLineScanConfiguration(const VESPERSSpatialLineScanConfiguration &original)
	: AMStepScanConfiguration(original), VESPERSScanConfiguration(original)
{
	setName(original.name());
	setUserScanName(original.name());
	dbObject_->setParent(this);
	setOtherPosition(original.otherPosition());
	setExportSpectraSources(original.exportSpectraSources());
	setCloseFastShutter(original.closeFastShutter());
	setReturnToOriginalPosition(original.returnToOriginalPosition());
	computeTotalTime();

	connect(this, SIGNAL(startChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(stepChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(endChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(timeChanged(double)), this, SLOT(computeTotalTime()));
	connect(dbObject_, SIGNAL(ccdDetectorChanged(int)), this, SLOT(computeTotalTime()));
}
VESPERS2DScanConfiguration::VESPERS2DScanConfiguration(const VESPERS2DScanConfiguration &original)
	: AMStepScanConfiguration(original), VESPERSScanConfiguration(original)
{
	setName(original.name());
	setUserScanName(original.name());
	dbObject_->setParent(this);
	setExportAsAscii(original.exportAsAscii());
	setExportSpectraSources(original.exportSpectraSources());
	setExportSpectraInRows(original.exportSpectraInRows());
	setCloseFastShutter(original.closeFastShutter());
	setReturnToOriginalPosition(original.returnToOriginalPosition());
	computeTotalTime();
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionTimeChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime()));
	connect(dbObject_, SIGNAL(ccdDetectorChanged(int)), this, SLOT(computeTotalTime()));
}
VESPERSEXAFSScanConfiguration::VESPERSEXAFSScanConfiguration(const VESPERSEXAFSScanConfiguration &original)
	: AMEXAFSScanConfiguration(original), VESPERSScanConfiguration(original)
{
	regions_->setSensibleStart(original.regions()->sensibleStart());
	regions_->setSensibleEnd(original.regions()->sensibleEnd());
	exafsRegions()->setDefaultEdgeEnergy(original.exafsRegions()->defaultEdgeEnergy());
	exafsRegions()->setEnergyControl(VESPERSBeamline::vespers()->energyRelative());
	exafsRegions()->setTimeControl(VESPERSBeamline::vespers()->masterDwellTime());
	exafsRegions()->setKControl(VESPERSBeamline::vespers()->kControl());
	regions_->setDefaultUnits(original.regions()->defaultUnits());
	regions_->setDefaultTimeUnits(original.regions()->defaultTimeUnits());
	exafsRegions()->setDefaultIsRelative(original.exafsRegions()->defaultIsRelative());

	for (int i = 0; i < original.regionCount(); i++){

		// Because I store the values in energy space, I need to ask for them explicitly with no converstion.  Otherwise, the k-space values will be converted twice.
		regions_->addRegion(i, original.regionStartByType(i, AMEXAFSRegion::Energy), original.regionDelta(i), original.regionEndByType(i, AMEXAFSRegion::Energy), original.regionTime(i));
		exafsRegions()->setType(i, original.regionType(i));
		exafsRegions()->setEdgeEnergy(i, original.regionEdgeEnergy(i));
	}

	setName(original.name());
	setUserScanName(original.userScanName());
	dbObject_->setParent(this);
	edge_ = original.edge();
	energy_ = original.energy();
	useFixedTime_ = original.useFixedTime();
	numberOfScans_ = original.numberOfScans();

	goToPosition_ = original.goToPosition();
	position_ = original.position();
	setExportSpectraSources(original.exportSpectraSources());
	computeTotalTime();
	connect(regions_, SIGNAL(regionsChanged()), this, SLOT(computeTotalTime()));
	connect(regions_, SIGNAL(regionsChanged()), this, SLOT(onEXAFSRegionsChanged()));
	connect(VESPERSBeamline::vespers()->variableIntegrationTime(), SIGNAL(a0Changed(double)), this, SLOT(computeTotalTime()));
	connect(VESPERSBeamline::vespers()->variableIntegrationTime(), SIGNAL(a1Changed(double)), this, SLOT(computeTotalTime()));
	connect(VESPERSBeamline::vespers()->variableIntegrationTime(), SIGNAL(a2Changed(double)), this, SLOT(computeTotalTime()));
}
VESPERSTimeScanConfiguration::VESPERSTimeScanConfiguration(QObject *parent)
	: AMTimedRegionScanConfiguration(parent), VESPERSScanConfiguration()
{
	setName("Timed Scan");
	setUserScanName("Timed Scan");
	dbObject_->setParent(this);
	setIncomingChoice(VESPERS::Imini);
	setFluorescenceDetector(VESPERS::SingleElement);
	setCCDDetector(VESPERS::NoCCD);
	setCCDFileName("");
	setExportSpectraSources(true);
	setExportSpectraInRows(true);
	setTime(1);
	setTimePerAcquisition(10);
	setIterations(1);
	computeTotalTime();

	connect(this, SIGNAL(timeChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(timePerAcquisitionChanged(double)), this, SLOT(computeTotalTime()));
	connect(this, SIGNAL(iterationsChanged(int)), this, SLOT(computeTotalTime()));
	connect(dbObject_, SIGNAL(ccdDetectorChanged(int)), this, SLOT(computeTotalTime()));
}
REIXSRIXSScanConfigurationView::REIXSRIXSScanConfigurationView(REIXSXESScanConfiguration* config, QWidget *parent) :
	AMScanConfigurationView(parent)
{
	if(config) {
		configuration_ = config;
		ownsConfiguration_ = false;
	}
	else {
		configuration_ = new REIXSXESScanConfiguration(this);
		ownsConfiguration_ = true;
	}

	chooseScanDialog_ = 0;
	/*
	image_ = new MPlotSeriesBasic();
	image_->setColorMap(*colorMap_);
	*/

	currentScan_ = 0;

	queueView_ = new AMActionRunnerQueueView3(AMActionRunner3::workflow());

	detectorOptions = new QGroupBox("Initial Setup");
	stopScanOptions = new QGroupBox("Stop scan when...");
	nameOptions = new QGroupBox("Scan meta-data");
	XASEnergySelect = new QGroupBox("Select Scan Energy");

	energyBox_ = new QDoubleSpinBox();
	energyBox_->setDecimals(2);
	energyBox_->setEnabled(true);
	energyBox_->setRange(92,2000);
	energyBox_->setValue(configuration_->energy());
	energyBox_->setSingleStep(0.1);

	energyBoxLabel_ = new QLabel("RIXS Excitation Energy:");

	slitWidthBox_= new QDoubleSpinBox();
	slitWidthBox_->setRange(5,500);
	slitWidthBox_->setValue(configuration_->slitWidth());
	slitWidthBox_->setSingleStep(5);
	slitWidthBox_->setDecimals(0);
	slitWidthBox_->setEnabled(configuration_->applySlitWidth());
	applySlitWidthBox_ = new QCheckBox("Slit Width");
	applySlitWidthBox_->setChecked(configuration_->applySlitWidth());


	polarizationBox_ = new QComboBox();
	polarizationBox_->addItem("Circular Left");
	polarizationBox_->addItem("Circular Right");
	polarizationBox_->addItem("Linear Horizontal");
	polarizationBox_->addItem("Linear Vertical +");
	polarizationBox_->addItem("Linear Vertical -");
	polarizationBox_->addItem("Linear Inclined");
	polarizationBox_->setCurrentIndex(configuration_->polarization());
	polarizationBox_->setEnabled(configuration_->applyPolarization());
	applyPolarizationBox_ = new QCheckBox("Polarization");
	applyPolarizationBox_->setChecked(configuration_->applyPolarization());


	polarizationAngleBox_ = new QDoubleSpinBox();
	polarizationAngleBox_->setDecimals(0);
	polarizationAngleBox_->setRange(-180,180);
	polarizationAngleBox_->setEnabled((configuration_->applyPolarization() && (configuration_->polarization() == 5)));
	polarizationAngleBox_->setValue(configuration_->polarizationAngle());
	polarizationAngleBox_->setSingleStep(10);

	polarizationAngleLabel_ = new QLabel();
	polarizationAngleLabel_->setText("      Angle");

	doNotClearExistingCountsOption_ = new QCheckBox("Do not clear previous detector data");

	maximumTotalCounts_ = new QDoubleSpinBox();
	maximumTimeEdit_ = new QTimeEdit();

	numberEdit_ = new QSpinBox();
	numberEdit_->setRange(0, 10000);
	numberEdit_->setEnabled(false);
	nameEdit_ = new QLineEdit();
	sampleSelector_ = new AMSamplePre2013Editor(AMDatabase::database("user"));
	autoNamingCheckBox_ = new QCheckBox("from last sample move");

	maximumTotalCounts_->setDecimals(0);
	maximumTotalCounts_->setRange(10, 1000000000);
	maximumTimeEdit_->setDisplayFormat("hh:mm:ss");

	XASScanName_ = new QLabel("Select XAS Scan...");

	/*
	addEnergy_ =  new QPushButton();
	addEnergy_->setText("Add Energy");
	QIcon down;
	down.addFile(QString::fromUtf8(":/22x22/go-down-dark.png"), QSize(), QIcon::Normal, QIcon::Off);
	addEnergy_->setIcon(down);
	queueScan_ = new QPushButton();
	queueScan_->setText("Add This Energy");
	*/

	loadXASData_ = new QPushButton();
	loadXASData_->setText("Load XAS Scan");


	// Add scan view (plots)
	scanView_ = new AMScanView();
	scanView_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	scanView_->changeViewMode(AMScanView::Tabs);

	// share the scan set model with the AMScanView
	scanSetModel_ = scanView_->model();

	/*
	plot_ = new MPlot();
	plotWidget_ = new MPlotWidget();
	plotWidget_->setPlot(plot_);

	plot_->plotArea()->setBrush(QBrush(QColor(Qt::white)));
	plot_->axisRight()->setTicks(0);
	plot_->axisBottom()->setTicks(4);
	plot_->axisLeft()->showGrid(false);
	plot_->axisBottom()->showAxisName(false);
	plot_->axisLeft()->showAxisName(false);
	plot_->axisScaleBottom()->setPadding(0);
	plot_->axisScaleLeft()->setPadding(0);
	image_ = 0;
	*/

	QGridLayout* RIXSView = new QGridLayout();


	QGridLayout* initialSetupLayout = new QGridLayout();
	initialSetupLayout->addWidget(applySlitWidthBox_,1,0);
	initialSetupLayout->addWidget(slitWidthBox_,1,1);
	initialSetupLayout->addWidget(applyPolarizationBox_,2,0);
	initialSetupLayout->addWidget(polarizationBox_,2,1);
	initialSetupLayout->addWidget(polarizationAngleLabel_,3,0);
	initialSetupLayout->addWidget(polarizationAngleBox_,3,1);
	initialSetupLayout->addWidget(doNotClearExistingCountsOption_,4,0,1,2,0);
	detectorOptions->setLayout(initialSetupLayout);

	QFormLayout* stopScanWhenLayout = new QFormLayout();
	stopScanWhenLayout->addRow("Total Counts Reaches", maximumTotalCounts_);
	stopScanWhenLayout->addRow("After this much time", maximumTimeEdit_);
	stopScanOptions->setLayout(stopScanWhenLayout);

	QFormLayout* scanMetaDataLayout = new QFormLayout();
	scanMetaDataLayout->addRow("Scan base name", nameEdit_);
	/*
	scanMetaDataLayout->addRow("Number", numberEdit_);
	*/
	scanMetaDataLayout->addRow("Sample", sampleSelector_);
	scanMetaDataLayout->addRow("Set automatically", autoNamingCheckBox_);
	nameOptions->setLayout(scanMetaDataLayout);

	QGridLayout* XASScanViewLayout = new QGridLayout();
	XASScanViewLayout->addWidget(scanView_,0,0,1,5);
	XASScanViewLayout->addWidget(energyBoxLabel_,1,0);
	XASScanViewLayout->addWidget(energyBox_,1,1);
	/*
	XASScanViewLayout->addWidget(queueScan_,1,2);
	*/
	XASScanViewLayout->addWidget(loadXASData_,1,4);
	XASEnergySelect->setLayout(XASScanViewLayout);

	RIXSView->addWidget(detectorOptions, 0,0);
	RIXSView->addWidget(stopScanOptions,1,0);
	RIXSView->addWidget(nameOptions,2,0);
	RIXSView->addWidget(XASEnergySelect,0,1,3,1);
	RIXSView->addWidget(queueView_, 3,0,1,2);

	QVBoxLayout* outerVLayout = new QVBoxLayout();
	outerVLayout->setContentsMargins(0,0,0,0);
	outerVLayout->setSpacing(0);
	outerVLayout->addWidget(new AMTopFrame("Setup RIXS Scans", QIcon(":/utilities-system-monitor.png")));
	outerVLayout->addLayout(RIXSView);

	setLayout(outerVLayout);

	currentCalibrationId_ = -1;

	maximumTotalCounts_->setValue(configuration_->maximumTotalCounts());
	maximumTimeEdit_->setTime(QTime().addSecs(int(configuration_->maximumDurationSeconds())));
	doNotClearExistingCountsOption_->setChecked(configuration_->doNotClearExistingCounts());
	nameEdit_->setText(configuration_->userScanName());
	numberEdit_->setValue(configuration_->scanNumber());
	sampleSelector_->setCurrentSampleFromId(configuration_->sampleId());
	autoNamingCheckBox_->setChecked(configuration_->namedAutomatically());
	onAutoNamingCheckboxClicked(configuration_->namedAutomatically());

	configuration_->setApplyEnergy(true);

	connect(loadXASData_, SIGNAL(clicked()), this, SLOT(onloadXASDataClicked()));
	/*
	connect(queueScan_, SIGNAL(clicked()), this, SLOT(onQueueScanClicked()));
	*/
	connect(applySlitWidthBox_, SIGNAL(toggled(bool)),slitWidthBox_,SLOT(setEnabled(bool)));
	connect(applySlitWidthBox_, SIGNAL(clicked(bool)), configuration_, SLOT(setApplySlitWidth(bool)));
	connect(slitWidthBox_, SIGNAL(valueChanged(double)), configuration_, SLOT(setSlitWidth(double)));

	connect(energyBox_, SIGNAL(valueChanged(double)), configuration_, SLOT(setEnergy(double)));

	connect(applyPolarizationBox_, SIGNAL(clicked(bool)), configuration_, SLOT(setApplyPolarization(bool)));
	connect(polarizationBox_, SIGNAL(currentIndexChanged(int)), configuration_, SLOT(setPolarization(int)));
	connect(polarizationAngleBox_, SIGNAL(valueChanged(double)), configuration_, SLOT(setPolarizationAngle(double)));
	connect(applyPolarizationBox_, SIGNAL(clicked(bool)), polarizationBox_, SLOT(setEnabled(bool)));
	connect(applyPolarizationBox_, SIGNAL(clicked(bool)), this, SLOT(reviewPolarizationAngleBoxEnabled()));
	connect(polarizationBox_, SIGNAL(activated(int)), this, SLOT(reviewPolarizationAngleBoxEnabled()));



	connect(doNotClearExistingCountsOption_, SIGNAL(toggled(bool)), configuration_, SLOT(setDoNotClearExistingCounts(bool)));

	connect(maximumTotalCounts_, SIGNAL(valueChanged(double)), configuration_, SLOT(setMaximumTotalCounts(double)));
	connect(maximumTimeEdit_, SIGNAL(timeChanged(QTime)), this, SLOT(onMaximumTimeEditChanged(QTime)));

	connect(autoNamingCheckBox_, SIGNAL(clicked(bool)), this, SLOT(onAutoNamingCheckboxClicked(bool)));

	connect(nameEdit_, SIGNAL(textEdited(QString)), configuration_, SLOT(setUserScanName(QString)));
	connect(numberEdit_, SIGNAL(valueChanged(int)), configuration_, SLOT(setScanNumber(int)));
	connect(sampleSelector_, SIGNAL(currentSampleChanged(int)), configuration_, SLOT(setSampleId(int)));
	connect(autoNamingCheckBox_, SIGNAL(clicked(bool)), configuration_, SLOT(setNamedAutomatically(bool)));

	connect(scanView_, SIGNAL(dataPositionChanged(QPointF)), this, SLOT(onDataPositionToolChanged(QPointF)));
	connect(energyBox_, SIGNAL(valueChanged(double)), this, SLOT(onEnergySpinBoxChanged(double)));
}