#include "QtWidgetsClass_FarSourceSetting.h"

QtWidgetsClass_FarSourceSetting::QtWidgetsClass_FarSourceSetting(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);
}

QtWidgetsClass_FarSourceSetting::~QtWidgetsClass_FarSourceSetting()
{}

size_t QtWidgetsClass_FarSourceSetting::getThetaPoints()
{
	return this->ui.lineEdit_thetaPoints->text().toInt();
}

size_t QtWidgetsClass_FarSourceSetting::getPhiPoints()
{
	return this->ui.lineEdit_phiPoints->text().toInt();
}

QString QtWidgetsClass_FarSourceSetting::getFFEPath()
{
	return this->ui.lineEdit_filepath->text().trimmed();
}

void QtWidgetsClass_FarSourceSetting::on_pushButton_Cancel_clicked()
{
	this->close();
}
void QtWidgetsClass_FarSourceSetting::on_pushButton_select_clicked()
{
	QString fileName = getOpenFilePath(this, u8"Open File",  u8"FFE Files (*.ffe)");
	if (!fileName.isEmpty()) {
		this->ui.lineEdit_filepath->setText(fileName);
		// 打开文件
		FEKOBase::FEKOFarFieldFileClass* farfieldfile = new FEKOBase::FEKOFarFieldFileClass();
		farfieldfile->parseFarFieldFile(fileName);
		if (farfieldfile->dataBlockList.count() == 0) {
			QMessageBox::warning(nullptr, u8"警告", u8"ffe文件解析失败，请检查文件格式是否正确！");
		}
		this->ui.lineEdit_thetaPoints->setText(QString::number( farfieldfile->dataBlockList[0].thetaSamples));
		this->ui.lineEdit_phiPoints->setText(QString::number(farfieldfile->dataBlockList[0].phiSamples));
	}
}
void QtWidgetsClass_FarSourceSetting::on_pushButton_OK_clicked() {
	emit this->setResultSelected(this->getThetaPoints(), this->getPhiPoints(), this->getFFEPath());
	this->close();
}