#include "QLonLatInterpAtiFromDEM.h"
#include "ui_QLonLatInterpAtiFromDEM.h"
#include "BaseConstVariable.h"
#include "BaseTool.h"
#include "RasterToolBase.h"
#include "LogInfoCls.h"
#include <QMessageBox>
#include <QFileDialog>
#include "ImageNetOperator.h"

QLonLatInterpAtiFromDEM::QLonLatInterpAtiFromDEM(QWidget *parent)
	: QDialog(parent)
	,ui(new Ui::QLonLatInterpAtiFromDEMClass)
{
	ui->setupUi(this);

	connect(ui->pushButtonLonLatRasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonLonLatRasterSelect_clicked()));
	connect(ui->pushButtonDEMRasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonDEMRasterSelect_clicked()));
	connect(ui->pushButtonLLARasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonLLARasterSelect_clicked()));
	connect(ui->pushButtonXYZRasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonXYZRasterSelect_clicked()));
	connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted()));
	connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected()));


}

QLonLatInterpAtiFromDEM::~QLonLatInterpAtiFromDEM()
{

}

void QLonLatInterpAtiFromDEM::onpushButtonLonLatRasterSelect_clicked()
{

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

}

void QLonLatInterpAtiFromDEM::onpushButtonDEMRasterSelect_clicked()
{
	QString  fileNames = QFileDialog::getOpenFileName(
		this,                            // 父窗口
		tr(u8"选择DEM数据文件"),               // 标题
		QString(),                       // 默认路径
		tr(ENVI_FILE_FORMAT_FILTER)  // 文件过滤器
	);
	// 如果用户选择了文件
	if (!fileNames.isEmpty()) {
		QString message = "选择的文件有：\n";
		this->ui->lineEditDEMRasterPath->setText(fileNames);
	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}
}

void QLonLatInterpAtiFromDEM::onpushButtonLLARasterSelect_clicked()
{
	QString  fileNames = QFileDialog::getSaveFileName(
		this,                            // 父窗口
		tr(u8"选择保存采样后数据文件"),               // 标题
		QString(),                       // 默认路径
		tr(ENVI_FILE_FORMAT_FILTER)  // 文件过滤器
	);
	// 如果用户选择了文件
	if (!fileNames.isEmpty()) {
		QString message = "选择的文件有：\n";
		this->ui->lineEditLLARasterPath->setText(fileNames);
	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}
}

void QLonLatInterpAtiFromDEM::onpushButtonXYZRasterSelect_clicked()
{
	QString  fileNames = QFileDialog::getSaveFileName(
		this,                            // 父窗口
		tr(u8"选择采样后转换数据文件"),               // 标题
		QString(),                       // 默认路径
		tr(ENVI_FILE_FORMAT_FILTER)  // 文件过滤器
	);
	// 如果用户选择了文件
	if (!fileNames.isEmpty()) {
		QString message = "选择的文件有：\n";
		this->ui->lineEditXYZRasterPath->setText(fileNames);
	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}
}

void QLonLatInterpAtiFromDEM::onbuttonBox_accepted()
{
	QString llrasterpath = ui->lineEditLonLatRasterPath->text();
	QString demrasterpath = ui->lineEditDEMRasterPath->text();
	QString llarasterpath = ui->lineEditLLARasterPath->text();
	QString xyzrasterpath = ui->lineEditXYZRasterPath->text();

	qDebug() << "从DEM采样高程中。。。。";
	InterpLookTableRfromDEM(llrasterpath, demrasterpath, llarasterpath);
	qDebug() << "经纬度转换为XYZ中。。。。";
	RangeLooktableLLA_2_RangeLooktableXYZ(llarasterpath, xyzrasterpath);
	QMessageBox::information(this, tr(u8"提示"), tr(u8"完成"));
}

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

