#include "InitCreateImageXYZDialog.h"
#include "ui_InitCreateImageXYZDialog.h"
#include <QFileDialog>
#include <QMessageBox>
#include "ImageNetOperator.h"

InitCreateImageXYZDialog::InitCreateImageXYZDialog(QWidget *parent)
	: QDialog(parent), ui(new Ui::InitCreateImageXYZDialogClass)
{
	ui->setupUi(this);
	connect(ui->pushButtonEchoGPSDataSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoGPSDataSelect_clicked()));
	connect(ui->pushButtonImageXYZSelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageXYZSelect_clicked()));
	connect(ui->pushButtonImageLLSelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageLLSelect_clicked()));
	connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted()));
	connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected()));
}

InitCreateImageXYZDialog::~InitCreateImageXYZDialog()
{}

void InitCreateImageXYZDialog::onpushButtonImageLLSelect_clicked()
{
	QString fileNamePath = QFileDialog::getSaveFileName(
		this,                           // 父窗口
		tr(u8"保存经纬度成像网格"),               // 标题
		QString(),                      // 默认路径
		tr(u8"ENVI Bin(*.bin);;ENVI Data(*.dat);;ENVI Data(*.data);;tiff影像(*.tif);;tiff影像(*.tiff)")  // 文件过滤器
	);
	// 如果用户选择了文件
	if (!fileNamePath.isEmpty()) {
		QString message = "选择的文件有：\n";
		this->ui->lineEditImageLLPath->setText(fileNamePath);
	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}

}

void InitCreateImageXYZDialog::onpushButtonImageXYZSelect_clicked()
{
	QString fileNamePath = QFileDialog::getSaveFileName(
		this,                           // 父窗口
		tr(u8"保存XYZ成像网格"),               // 标题
		QString(),                      // 默认路径
		tr(u8"ENVI Bin(*.bin);;ENVI Data(*.dat);;ENVI Data(*.data);;tiff影像(*.tif);;tiff影像(*.tiff)")  // 文件过滤器
	);
	// 如果用户选择了文件
	if (!fileNamePath.isEmpty()) {
		QString message = "选择的文件有：\n";
		this->ui->lineEditImageXYZPath->setText(fileNamePath);
	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}
}

void InitCreateImageXYZDialog::onpushButtonEchoGPSDataSelect_clicked()
{

	QString  fileNames = QFileDialog::getOpenFileName(
		this,                           // 父窗口
		tr(u8"选择回波GPS坐标点文件"),               // 标题
		QString(),                      // 默认路径
		tr(u8"GPS坐标点文件(*.gpspos.data);;All Files(*.*)")  // 文件过滤器
	);
	// 如果用户选择了文件
	if (!fileNames.isEmpty()) {
		QString message = "选择的文件有：\n";
		this->ui->lineEditEchoGPSDataPath->setText(fileNames);
	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}
}

void InitCreateImageXYZDialog::onbuttonBox_accepted()
{
	double NearRange = this->ui->doubleSpinBoxNearRange->value();
	double RangeResolution = this->ui->doubleSpinBoxRangeResolution->value();
	int64_t RangeNum = this->ui->spinBoxRangeNum->value();
	QString imageLLPath = this->ui->lineEditImageLLPath->text().trimmed();
	QString imageXYZPath = this->ui->lineEditImageXYZPath->text().trimmed();
	QString echoGPSDataPath = this->ui->lineEditEchoGPSDataPath->text().trimmed();

	InitCreateImageXYZProcess(imageLLPath, imageXYZPath, echoGPSDataPath, NearRange, RangeResolution, RangeNum);
	if (imageLLPath.isEmpty() || imageXYZPath.isEmpty() || echoGPSDataPath.isEmpty()) {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
		return;
	}
	QMessageBox::information(this, tr(u8"提示"), tr(u8"完成"));

}

void InitCreateImageXYZDialog::onbuttonBox_rejected()
{
	this->close();
}
