You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWATI/Src/nmNum/nmSubWnd/nmSubWndGrid.cpp

214 lines
6.5 KiB
C++

#include "zxLogInstance.h"
#include "ZxBaHelper.h"
#include "ZxResolutionHelper.h"
#include "zxSysUtils.h"
#include "ZxPtyDock.h"
#include "iDockBaseWx.h"
#include "ZxMainWindow.h"
#include "ZxSubAxisX.h"
#include "ZxSubAxisY.h"
#include "ZxPlot.h"
#include "ZxObjCurve.h"
#include "ZxSubTitle.h"
#include "tCurvePlotScene.h"
#include "tCurvePlotView.h"
#include "ZxTableView.h"
#include "ZxTableModel.h"
#include "mModuleDefines.h"
#include "ZxDataWell.h"
#include "ZxDataProject.h"
#include "ZxRstJobWnd.h"
#ifdef QT_DEBUG
#include "ZxDataGaugeP.h"
#endif
#ifdef QT_DEBUG
#include "nmXmlHelper.h"
#endif
#include "nmSubWndGrid.h"
#include "nmDataDemo.h"
#include "nmDataLogFile.h"
#include "nmDataGeoWell.h"
#include "nmDataGeoOutline.h"
#include "nmDataGeo.h"
#include "nmGuiPlot.h"
#include "nmWxGridVTKContainerWidget.h"
#include "nmWxGridDlg.h"
#include <QVector>
#include <QProcess>
nmSubWndGrid::nmSubWndGrid(QWidget *parent, QString sExt) :
iSubWndBaseAF(parent, sExt)
{
m_sMdiWndType = s_MdiType_DataNum;
m_pAnalyzeData = nmDataDemo::getInstance();
setWindowTitle(tr("nmSubWndGrid"));
}
nmSubWndGrid::~nmSubWndGrid()
{
#ifdef QT_DEBUG
#endif
}
void nmSubWndGrid::configWnd()
{
iSubWndBaseAF::configWnd();
if(NULL != m_pMainWindow) {
disconnect(this, SIGNAL(sigAppendDock2Main(iDockBaseWx*, Qt::DockWidgetArea)), \
m_pMainWindow, SLOT(slotAppendDock2Main(iDockBaseWx*, Qt::DockWidgetArea)));
connect(this, SIGNAL(sigAppendDock2Main(iDockBaseWx*, Qt::DockWidgetArea)), \
m_pMainWindow, SLOT(slotAppendDock2Main(iDockBaseWx*, Qt::DockWidgetArea)));
}
initUI();
}
void nmSubWndGrid::initUI()
{
// 主布局:定义
initUiMain();
// 外围布局DockWx
{
// initUiDockWxs();
// initUiDockPtys();
}
#ifdef QT_DEBUG
// 示例如何加载xml文件
if(_nmXmlHelper->loadXmlDefines()) {
foreach(nmXmlData* pData, *(_nmXmlHelper->getVecNmXmlDataPtrs())) {
Q_ASSERT(NULL != pData);
zxLogRunD(QString("%1: %2").arg(pData->m_sName).arg(pData->m_sAlias));
}
}
#endif
}
QWidget* nmSubWndGrid::initUiMainWx()
{
// TODO拿到网格设置参数
// 类型:三角形、四边形和六边形
// 拿到多边形的边界和井的数据
nmGuiPlot* pPlot = (nmGuiPlot*)m_pAnalyzeData->getWxPlot();
QVector<QPointF> outlineInformation = pPlot->getOutlinePoints();
nmDataLogFile::getInstance()->writeLog("==== outline start ====");
for(int i = 0; i < outlineInformation.count(); i++) {
QPointF p = outlineInformation[i];
nmDataLogFile::getInstance()->writeLog(QString("%1 %2").arg(p.x()).arg(p.y()));
}
nmDataLogFile::getInstance()->writeLog("==== outline end ====");
QVector<QVector<double >> wellList = pPlot->getWellsInformation();
nmDataLogFile::getInstance()->writeLog("==== " + QString::number(outlineInformation.count()) + " ====");
nmDataLogFile::getInstance()->writeLog("==== " + QString::number(wellList.count()) + " ====");
// 根据边界和井的信息生成geo文件先生成一个文件到tmp中
this->genGeo(outlineInformation, wellList);
// 调用gmsh生成3维vtk网格文件
this->genGrid();
// 调用gmsh生成2维vtk网格文件
this->genGrid(false);
// 生成井信息的文件
this->genWellFile(wellList);
// 渲染
QString sDir = ZxBaseUtil::getDirOf(s_Dir_Temp, "Nm/PreProcessing");
QString sFile = sDir + "oil.vtk";
nmWxGridVTKContainerWidget* vtkWidget = new nmWxGridVTKContainerWidget(NULL, sFile);
return vtkWidget;
}
bool nmSubWndGrid::runCmdBy(QString sName, QString sID)
{
if(sID.toInt() == 5401) {
return true;
}
return false;
}
void nmSubWndGrid::genGeo(QVector<QPointF> outlinePoints, QVector<QVector<double >> vWellsInfo)
{
// 井数据结构
QVector<CircleWell> circles;
for(int i = 0; i < vWellsInfo.count(); i++) {
QVector<double> vWellInfo = vWellsInfo[i];
QPointF center(vWellInfo[0], vWellInfo[1]);
double radius = vWellInfo[2];
int wellGridNum = 13;
circles.append(CircleWell(center, radius, wellGridNum));
}
// 面网格设置
double gridSize = 0.5;
nmDataGeo geo(outlinePoints, circles, gridSize);
QString sDir = ZxBaseUtil::getDirOf(s_Dir_Temp, "Nm/PreProcessing");
QString sFile = sDir + "oil.geo";
geo.generate3DFile(sFile);
geo.generate2DFile(sDir + "oil-2d.geo");
geo.generateWells(sDir + "oil-2d-wells.txt");
}
void nmSubWndGrid::genGrid(bool is3D)
{
QProcess process;
QString sDir = ZxBaseUtil::getDirOf(s_Dir_Temp, "Nm/PreProcessing");
QString currentDir = QDir::currentPath();
nmDataLogFile::getInstance()->writeLog(currentDir);
// 设置工作目录
QDir::setCurrent(sDir);
// 要执行的命令和参数
// gmsh.exe -2 oil.geo -o oil.vtk
// gmsh.exe -2 oil-2d.geo -o oil-2d.vtk
QString geoName = "oil.geo";
if(!is3D) {
geoName = "oil-2d.geo";
}
process.start("gmsh.exe", QStringList() << "-2" << geoName << "-o" << QString(geoName).replace("geo", "vtk") << " -saveall");
// 等待命令启动
if(!process.waitForStarted()) {
nmDataLogFile::getInstance()->writeLog("Command failed to start.");
return ;
}
// 等待命令执行结束
if(!process.waitForFinished()) {
nmDataLogFile::getInstance()->writeLog("Command failed to finish.");
return;
}
// 读取命令的输出
QByteArray output = process.readAllStandardOutput();
nmDataLogFile::getInstance()->writeLog("Gen grid command output: " + output);
qDebug() << "Gen grid command output: " + output;
// 设置恢复
QDir::setCurrent(currentDir);
}
void nmSubWndGrid::setAnalyzeData(nmDataDemo *newAnalyzeData)
{
m_pAnalyzeData = newAnalyzeData;
}
void nmSubWndGrid::genWellFile(QVector<QVector<double >> vWellsInfo)
{
// 面网格设置
double gridNum = 12;
QString sDir = ZxBaseUtil::getDirOf(s_Dir_Temp, "Nm/PreProcessing");
QString sFile = sDir + "oil-2d-wells.txt";
QFile file(sFile);
//检查
if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning("Cannot open file for writing: %s", qPrintable(file.errorString()));
return;
}
QTextStream out(&file);
out << vWellsInfo.size() << "\n";
for(int i = 0; i < vWellsInfo.size(); i++) {
QVector<double> wellInfo = vWellsInfo[i];
out << wellInfo[0] << " " << wellInfo[1] << " " << wellInfo[2] << " " << gridNum << "\n";
}
file.close();
}