#include "WBCLFZSystemModule.h"
#include <QApplication>
#include <QDateTime> //添加QDateTime头文件
#include <QMovie>
#include <QPixmap>
#include <QSplashScreen>
#include <QTextCodec>
#include <vtkOutputWindow.h>
#include "PointCloudProcess/pclvisualizer.h"
#include "modelProcess/ModelProcess.h"
#include "TableProcess/TableMainWindow.h"
#include "SqliteDBProcess/src/Application.h"
#include "SqliteDBProcess/src/sqlite.h"
#include "SqliteDBProcess/src/SqliteDBMainWindow.h"
#include "EchoShowProcess/FEKOResultImport.h"
#include "QConsoleWidget.h"
#include "QConsoleCommandAction.h"
//#include "EchoShowProcess/FEKOResultProcessExportWindow.h"


WBCLFZSystemModule::WBCLFZSystemModule(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
}

WBCLFZSystemModule::~WBCLFZSystemModule()
{

}
void WBCLFZSystemModule::on_pushButton_PointCloud_clicked() {
	startPointProcess();
}


void WBCLFZSystemModule::on_pushButton_TableProcesss_clicked()
{
	//TableMainWindow* w = new TableMainWindow();
	//w->show();
	// Show main window
	SqliteDBMainWindow* w = new SqliteDBMainWindow(this);
	w->show();
}

void WBCLFZSystemModule::on_pushButton_ModelProcess_clicked()
{
	BandingModelPrcessAndQConsoleWidgetClass* bandingobj = new BandingModelPrcessAndQConsoleWidgetClass();
	bandingobj->createModelProcess();
	bandingobj->createQConsoleWidget();
	bandingobj->bandingModelProcessAndQConsoleWidget();
	bandingobj->getModelProcess()->show();
}

void WBCLFZSystemModule::on_pushButton_EchoProcess_clicked()
{
	//qDebug() << u8"启动FEKO->csv 文件 \n";
	//QString  xmlfilepath = getOpenFilePath(this, QString::fromUtf8(u8"保存FEKO结果导入任务xml"), ".", QString::fromUtf8(u8"xml文件 (*.xml)"));
	//qDebug() << u8"选择 xmlfile 文件路径：\t " + xmlfilepath + u8"\n";
	//FEKOResultImportTaskNode* fekoresulttask = new FEKOResultImportTaskNode();
	//fekoresulttask->loadXmlFile(xmlfilepath);
	//fekoresulttask->ExcuteTask();

	//// 参数
	//FEKOResultProcessExportWindow* fekoResultProcessswindws=new FEKOResultProcessExportWindow();
	//fekoResultProcessswindws->show();


	FEKOImageSettingTaskNodeClass* test=new FEKOImageSettingTaskNodeClass();
	test->ExcuteTask();
}

void startPointProcess()
{
	QPixmap pixmap("logo1.png");  // 读取图片
	QSplashScreen splash(pixmap); //

	//读取ini文件中上一次关闭软件时候的窗口位置和大小：
	qDebug() << qApp->applicationDirPath() << endl;
	QString wstrFilePath = qApp->applicationDirPath() + "/setting.ini";
	QSettings* settings = new QSettings(
		wstrFilePath, QSettings::IniFormat); //用QSetting获取ini文件中的数据
	int x = settings->value("WindowGeometry/x").toInt();
	int y = settings->value("WindowGeometry/y").toInt();
	int width = settings->value("WindowGeometry/width").toInt();
	int height = settings->value("WindowGeometry/height").toInt();
	qDebug() << "Position is right:" << x << " " << y << " " << width << " "
		<< height;
	QDesktopWidget* desktopWidget = QApplication::desktop();
	QRect clientRect = desktopWidget->availableGeometry();
	QRect targRect0 = QRect(clientRect.width() / 4,
		clientRect.height() / 4,
		clientRect.width() / 2,
		clientRect.height() / 2);
	QRect targRect = QRect(x, y, width, height);
	if (
		width == 0 || height == 0 || x < 0 || x > clientRect.width() || y < 0 ||
		y >	  clientRect.height()) //如果上一次关闭软件的时候，窗口位置不正常，则本次显示在显示器的正中央
	{
		targRect = targRect0;
		qDebug() << "Position is not right:" << x << " " << y << " " << width << " " << height;
	}

	PCLVisualizer* w = new PCLVisualizer();
	w->setGeometry(targRect); //设置主窗口的大小
	w->show();

	splash.finish(w); //在主体对象初始化完成后结束启动动画
}

void startTableProcess()
{

}

void startModelProcess()
{

}

void startEchoProcess()
{

}
