Exemple #1
0
void AMScanDatabaseImportController::copySamples()
{
	if(state_ != Importing) return;
	emit progressDescription("Copying Samples...");
	emit stepProgress(-1);
	int totalSteps = s2dSampleIds_.count();
	int currentStep = 0;

	QMutableMapIterator<int, int> i(s2dSampleIds_);
	while (i.hasNext()) {
		if(state_ != Importing) return;
		i.next();
		emit stepProgress(int(100.0*(++currentStep)/totalSteps));
		// key is id; value is id in destination database, or -1 if not there yet. (if not there, need to insert)
		int sourceId = i.key(), destinationId = i.value();
		if(destinationId<1) {
			AMSample s;
			s.loadFromDb(sourceDb_, sourceId);
			if(s.storeToDb(destinationDb_))
				i.setValue(s.id());
			else
				AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -2, "Could not import the sample '" % sourceSamples_.value(sourceId) % "' into the database."));
		}
		qApp->sendPostedEvents();
		qApp->processEvents();
	}
}
QString AMSamplePlateMoveActionInfo::samplePositionName() const{
	if(samplePlateId() == -1)
		return "No Plate Selected";

	if(samplePositionIndex() < 0)
		return "No Sample Selected";

	AMSamplePlate samplePlate;
	if(!samplePlate.loadFromDb(AMDatabase::database("user"), samplePlateId_))
		return "Plate Error";

	if(samplePositionIndex() > samplePlate.count())
		return "Sample Index Error";

	AMSample actualSample;
	if(!actualSample.loadFromDb(AMDatabase::database("user"), samplePlate.at(samplePositionIndex()).sampleId()))
		return "Sample Error";

	return actualSample.name();
}
REIXSSampleMoveActionEditor::REIXSSampleMoveActionEditor(REIXSSampleMoveActionInfo *info, QWidget *parent) : QFrame(parent) {

	info_ = info;

	// Create GUI:
	fromSample_ = new QRadioButton("Sample on Plate");
	fromPositions_ = new QRadioButton("Defined Position");

	QVBoxLayout* vl = new QVBoxLayout();
	vl->addWidget(fromSample_);
	vl->addWidget(fromPositions_);
	vl->setContentsMargins(0,0,0,0);

	QHBoxLayout* hl = new QHBoxLayout();

	sample_ = new QComboBox();

	x_ = new QDoubleSpinBox();
	x_->setRange(-100, 100);
	x_->setDecimals(2);

	y_ = new QDoubleSpinBox();
	y_->setRange(-100, 100);
	y_->setDecimals(2);

	z_ = new QDoubleSpinBox();
	z_->setRange(-1000, 1000);
	z_->setDecimals(2);

	theta_ = new QDoubleSpinBox();
	theta_->setRange(-360, 360);
	theta_->setDecimals(2);

	hl->addLayout(vl);
	hl->addStretch(0);
	hl->addWidget(sample_);
	hl->addStretch(0);
	hl->addWidget(new QLabel("X:"));
	hl->addWidget(x_);
	hl->addWidget(new QLabel("Y:"));
	hl->addWidget(y_);
	hl->addWidget(new QLabel("Z:"));
	hl->addWidget(z_);
	hl->addWidget(new QLabel("Theta:"));
	hl->addWidget(theta_);


	setLayout(hl);

	// Initialize GUI:

	// Fill the sample choices based on the beamline's _current_ sample plate. This is a dubious choice, and couples this widget to the beamline class.
	AMSamplePlate* samplePlate = REIXSBeamline::bl()->samplePlate();
	for(int i=0, cc=samplePlate->count(); i<cc; ++i) {
		int sampleId = samplePlate->at(i).sampleId();
		AMSample s; s.loadFromDb(AMDatabase::database("user"), sampleId);
		sample_->addItem(s.name(), sampleId);
	}
	if(samplePlate->id() == info_->samplePlateId() && info_->samplePlateId() > 0) {	// If the beamline's current sample plate id matches the samplePlateId() of our action, set the currently-selected sample to match.
		sample_->setCurrentIndex(info_->sampleIndex());
	}

	// Mode 1: move to sample plate / sample:
	if(info_->samplePlateId() > 0) {
		fromSample_->setChecked(true);

		sample_->setEnabled(true);
		x_->setEnabled(false);
		y_->setEnabled(false);
		z_->setEnabled(false);
		theta_->setEnabled(false);
	}
	// Mode 2: move to fixed position:
	else {
		fromPositions_->setChecked(true);
		sample_->setEnabled(false);
		x_->setEnabled(true);
		y_->setEnabled(true);
		z_->setEnabled(true);
		theta_->setEnabled(true);

		x_->setValue(info_->x());
		y_->setValue(info_->y());
		z_->setValue(info_->z());
		theta_->setValue(info_->theta());
	}

	// make connections:
	connect(sample_, SIGNAL(activated(int)), this, SLOT(onSampleActivated(int)));
	connect(fromSample_, SIGNAL(toggled(bool)), this, SLOT(onFromSampleToggled(bool)));

	// connect editing finished for all spin boxes...
	connect(x_, SIGNAL(editingFinished()), this, SLOT(onSpinBoxEditingFinished()));
	connect(y_, SIGNAL(editingFinished()), this, SLOT(onSpinBoxEditingFinished()));
	connect(z_, SIGNAL(editingFinished()), this, SLOT(onSpinBoxEditingFinished()));
	connect(theta_, SIGNAL(editingFinished()), this, SLOT(onSpinBoxEditingFinished()));
}