logplus/ModuleConsole/src/LogModuleParamers.cpp

1060 lines
41 KiB
C++
Raw Normal View History

2026-01-16 17:18:41 +08:00
#pragma warning( push ,0)
#include <QDateTime>
#include <QTextEdit>
#include <QCompleter>
#include "completertextedit.h"
#include <QAction>
#include <QMenu>
#include <QToolBar>
#include <QMenuBar>
// #include "WorkflowSceneManager.h"
#include <QDockWidget>
#include <QDialog>
#include <QHBoxLayout>
#include <QSplitter>
#include <QObject>
#include <QApplication>
#include <QDebug>
#include <QFileDialog>
#include <QSettings>
#include <QPushButton>
// #include "QtWellSceneManager.h"
#include "LogModuleConsole.h"
#include "LogModuleParamers.h"
#include "GeometryUtils.h"
#include "WorkflowWidget.h"
#include "WorkflowSceneManager.h"
#include "BaseObject.h"
// #include "PaiObject.h"
#include "ObjectID.h"
#include <QTextCodec>
// #include "ObjProject.h"
// #include "ModuleGraphicsItem.h"
// #include "PaiModuleTree.h"
#include "Module.h"
#include "PELibraryModule.h"
#include "ModuleManager.h"
#include "SaveHelper.h"
#include "WellLogWorkflowRunner.h"
#include "VecViewCommand.h"
#include "OSGFramework.h"
// #include "ObjectEvent.h"
// #include "VecWindowCommand.h"
// #include "VecSceneManager.h"
// #include "VecDisplayObjectCommand.h"
#include "ModuleInformation.h"
#include "GeometryUtils.h"
#include "ParameterEditorModel.h"
#include "ModuleTreeDlg.h"
#include "PaiPushButton.h"
// #include "ConsoleOutputWidget.h"
#include "PaiWorkflowTemplateTree.h"
// #include "ObjWelllogINP.h"
// #include "DataTree.h"
#pragma warning( pop )
// void OSGFRAMEWORK_EXPORT AppendConsole(pai::log::Priority priority,const QString &output);
using namespace pai::graphics2d;
using namespace pai;
using namespace pai::workflow;
using namespace pai::gui;
using namespace pai::module;
using namespace pai::graphics;
BEGIN_OSGGRAPHICS_NAMESPACE;
//关闭事件
void CModuleParamers::closeEvent(QCloseEvent *event)
{
}
//构造函数
CModuleParamers::CModuleParamers(CModuleConsole*pModuleConsole,QWidget *parent):QMainWindow(parent)
{
m_ModuleToolBarView=NULL;
// m_pEdtParamCard=NULL;
m_TabWidget_Module=NULL;
m_TablWiget_Para=NULL;
// m_pBtnParamAllSelect=NULL;
// m_pBtnParamAllClear=NULL;
// m_pBtnParamSettingOK=NULL;
m_pParamSettingList=NULL;
// m_pTemplateTree=NULL;
// m_pCurrentModuleInfo=NULL;
m_pDialogLayout=NULL;
m_pModuleConsole=pModuleConsole;
m_CurrentSLFFileName = "";
OpenOrClose();
}
CModuleParamers::~CModuleParamers()
{
/*
if(m_pDockWidget) {
m_pDockWidget->setParent(NULL);
delete m_pDockWidget;
m_pDockWidget=NULL;
}
*/
}
// 初始化
void CModuleParamers::InitCardParamSettings(pai::workflow::CModuleInformation * amoduleInfo)
{
//TODO处理汉化问题
// ParameterEditorModel* pEditorModel = dynamic_cast< ParameterEditorModel * > (m_pParameterEditor->model());
// pEditorModel->m_currentindex=QModelIndex();
// if(pEditorModel) pEditorModel->clear();
m_pParamSettingList->clear();
m_pCurrentModuleInfo=amoduleInfo;
if(!amoduleInfo) return;
PELibraryModule* amodule=dynamic_cast<PELibraryModule*>(amoduleInfo->GetModule());
if(!amodule) return;
//初始化基础信息
amodule->InitModule(m_pParameterEditor);
//初始化文本窗口
QString str=amodule->LoadINPParamCardFromSLF(NULL,NULL);
str.replace(" "," ");
str.replace("",",");
str.replace(", ",",");
str.replace(",",", ");
if(GetEdtParamCard()) GetEdtParamCard()->clear();
if(GetEdtParamCard()) {
GetEdtParamCard()->setText(str);
}
str.replace(" "," ");
str.replace("",",");
str.replace(", ",",");
QStringList lines;
str.replace("\r\n","\n");
lines=str.split("\n");
lines.removeAll("\n");
lines.removeAll("");
if(!lines.size()||(lines.size()==1&&lines[0]=="END")) {
str=amodule->CreateParamCardFromConfig();
str.replace(" "," ");
str.replace("",",");
str.replace(", ",",");
str.replace(",",", ");
if(GetEdtParamCard()) {
GetEdtParamCard()->setText(str);
}
str.replace(" "," ");
str.replace("",",");
str.replace(", ",",");
str.replace("\r\n","\n");
lines=str.split("\n");
}
QTextCodec *codec = QTextCodec::codecForName("UTF8");
QTextDocument *pdoc=GetEdtParamCard()->document();
if(pdoc)pdoc->setModified(false);
QStringList paramnames=amodule->GetParamNames();
QStringList paramcnnames=amodule->GetParamCNNames();
for(int i=0;i<paramnames.size();i++)
{
paramnames[i]=paramnames[i].trimmed();
}
for(int i=0;i<paramcnnames.size();i++)
{
paramcnnames[i]=paramcnnames[i].trimmed();
}
QCompleter *oldcompleter=GetEdtParamCard()->GetCompleter();
QCompleter *completer = new QCompleter(paramnames, GetEdtParamCard());
GetEdtParamCard()->setCompleter(completer);
if(oldcompleter) {
QWidget *pp=dynamic_cast<QWidget *>(oldcompleter->parent());
if(pp) {
}
oldcompleter->setParent(NULL);
delete oldcompleter;
}
QStringList paramGroups;
if(amodule->Conc)paramGroups=amodule->GetNames(amodule->Conc->ValType,';',false);
for(int i=0;i<paramGroups.size();i++) {
paramGroups[i]=paramGroups[i].trimmed();
}
if(paramGroups.size()==1&&paramGroups[0]=="") paramGroups.clear();
QStringList Groups;
QStringList paramGroupstemp=paramGroups;
bool cflag=0;
while(paramGroupstemp.size()) {
QString cs=paramGroupstemp[0];
cs=cs.trimmed();
if(cs!="")cflag=true;
Groups.append(cs);
paramGroupstemp.removeAll(paramGroupstemp[0]);
}
if(!cflag) Groups.clear();
QString fun=QString::fromStdString(amodule->GetMetaData()->GetID());
int i=fun.indexOf("_");
if(i>-1) fun=fun.mid(i+1);
QString paramSettingFileName=QCoreApplication::applicationDirPath() + QDir::separator() +"app"+QDir::separator()
+fun+".config";
QStringList paramSetting;
QFile file( paramSettingFileName );
if (file.exists()&& file.open( QIODevice::ReadOnly ) ) {
QTextStream stream( &file );
QString amoduleConfig;
int n = 1;
while ( !stream.atEnd() ) {
amoduleConfig = stream.readLine(); // 不包括“\n”的一行文本
amoduleConfig=amoduleConfig.trimmed();
if(amoduleConfig=="") continue;
while(amoduleConfig.indexOf("\r\n")>-1) amoduleConfig.replace("\r\n","\n");
paramSetting += amoduleConfig;
}
file.close();
}
int GroupCount=Groups.size();
if(GroupCount) {
for(int j=0;j<GroupCount;j++) {
QString aa=Groups[j];
int paramGroupscount=paramGroups.size();
QTreeWidgetItem *itemf = new QTreeWidgetItem(m_pParamSettingList);
itemf->setText(0,aa);
for(int i=0;i<paramnames.size();i++){
if(paramGroupscount>i) {
QString bb=paramGroups[i];
if(aa!=bb) continue;
}
QTreeWidgetItem *item = new QTreeWidgetItem;
if(paramcnnames.size()>i){
QString s=paramcnnames.at(i);
item->setText(1,s);
}
else if(paramnames.size()>i)item->setText(0,paramnames.at(i) );
if(paramnames.size()>i) {
if(paramSetting.indexOf(paramnames.at(i))>=0)
item->setData(0, Qt::CheckStateRole, Qt::Checked );
else
item->setData(0, Qt::CheckStateRole, Qt::Unchecked );
}
itemf->addChild(item );
}
}
}
amodule->SetCardParamColor(GetEdtParamCard());
//初始化可视化窗口
amodule->LoadParamFromLines(lines);
m_pParameterEditor->slotBackModule(amoduleInfo);
amodule->SetEdit(GetEdtParamCard());
m_TabWidget_Module->setCurrentIndex(1);
// m_TabWidget_Module->currentChanged(1);
// m_TabWidget_Module->currentWidget();
}
// CVecWindowDocument* CModuleParamers::GetWindowDocument()
// {
// CVecWindow *pWindow=CVecWindowCommand::GetCurrentWindow();
// if(!pWindow) return NULL;
// CVecWindowDocument*pDoc=dynamic_cast<CVecWindowDocument*>(pWindow->GetWindowDocument());
// return pDoc;
// }
// QVector<CObjWellTrack*> CModuleParamers::GetWellTracks()
// {
// QVector<CObjWellTrack*> wells;
// CVecWindowDocument*pDoc=GetWindowDocument();
// CQtWellSceneManager*m_pWellSceneManager = dynamic_cast<CQtWellSceneManager*>(pDoc->GetVecWindow()->GetSceneManager());
// if(!m_pWellSceneManager) return wells;
// wells =m_pWellSceneManager->GetWellSectionGeomtry().GetAllWellTrack(true);
// return wells;
// }
void CModuleParamers::OpenOrClose()
{
// CModuleConsole*pCon=dynamic_cast<CModuleConsole*>(m_pModuleConsole);
// if(!pCon) return;
// if(!m_TabWidget_Module) CreatParamControlWidget();
// if(!m_TabWidget_Module) {
// AfxMessageBox("无法创建参数编辑文件!");
// return;
// }
// if(!pCon->GetWorkflowWidget()) return;
// WorkflowSceneManager *pWorkflowScene=dynamic_cast<WorkflowSceneManager *>(pCon->GetWorkflowWidget()->GetScene());
// if(!pWorkflowScene) return;
// pCon->GetWorkflowControl()->SetActiveTemplate(m_pTemplateTree);
// pWorkflowScene->SetParameterEditor(m_pParameterEditor);
// CWellLogWorkflowDataModel* pwellWorkflowDataModel=dynamic_cast<CWellLogWorkflowDataModel*>(pCon->GetWorkflowWidget()->GetWorkflow());
// if(!pwellWorkflowDataModel) return;
// int nModuleCount = pwellWorkflowDataModel->GetModuleCount();
// // bool v=!m_pDockWidget->isVisible();
// // m_pDockWidget->setVisible(v);
}
void LoadPEModules()
{
//模块定义配置文件加载
QString PeModulePath=QCoreApplication::applicationDirPath() + QDir::separator() + "app"+QDir::separator();
QString moduleConfigFileName = PeModulePath+"ModuleConfig.txt";
//配置信息全部加载到内存列表
QStringList modulesConfig;
QFile file( moduleConfigFileName );
if ( file.open( QIODevice::ReadOnly ) ) {
QTextStream stream( &file );
QString amoduleConfig;
int n = 1;
while ( !stream.atEnd() ) {
amoduleConfig = stream.readLine(); // 不包括“\n”的一行文本
//printf( "%3d: %s\n", n++, line.latin1() );
if(amoduleConfig.trimmed()!="")
modulesConfig += amoduleConfig;
}
file.close();
}
//开始分析加载模块
QString errormsg="";
for (int j = 0; j < modulesConfig.size(); ++j)
{
QStringList amoduleConfig=modulesConfig[j].split(" ");
if(amoduleConfig.size()<6)//文本的格式是:常规处理 岩石力学与井眼稳定性分析 shpor.dll shpor shpor.inp 2
{
errormsg=errormsg+"试加载算法模块配置信息出错,请检查ModuleConfig.txt如下配置信息请去除多余的空格请确保6或7栏配置[PELibraryModule]:"+modulesConfig[j]+"\n";
continue;
}
QString strDllPath="";
if(amoduleConfig.size()==6)
strDllPath =PeModulePath+ amoduleConfig[2];
if(amoduleConfig.size()>=7){
//定义了子分类
if(amoduleConfig[2].indexOf(".DLL",0,Qt::CaseInsensitive)>-1) {
strDllPath =PeModulePath+ amoduleConfig[2];
}
else strDllPath =PeModulePath+ amoduleConfig[3];
}
//加载插件
{
QFileInfo afile(strDllPath);
if(afile.exists()) {
PELibraryModule * aPeModule=new PELibraryModule();
//目前modulemananger底层采用另外std::map,默认排序,通过加序号,来实现按这个序号的排序
std::string sortnumber=QString::number(10000+j).toStdString();
//一个dll文件中有多个方法通过dll名+入口函数名的方式来区分
aPeModule->GetMetaData()->SetCategory(amoduleConfig[0].toStdString());
if(amoduleConfig.size()==6)
{
aPeModule->GetMetaData()->SetID(sortnumber+afile.completeBaseName().toStdString()+"_"+amoduleConfig[3].toStdString());
aPeModule->GetMetaData()->SetName(amoduleConfig[1].toStdString());
aPeModule->strDLLFun=amoduleConfig[3];
aPeModule->paramCardNameInSlf=amoduleConfig[4];
aPeModule->runBrunch=amoduleConfig[5].toInt();
}
if(amoduleConfig.size()>=7)
{
if(amoduleConfig[2].indexOf(".DLL",0,Qt::CaseInsensitive)>-1) {
aPeModule->GetMetaData()->SetID(sortnumber+afile.completeBaseName().toStdString()+"_"+amoduleConfig[3].toStdString());
aPeModule->GetMetaData()->SetName(amoduleConfig[1].toStdString());
aPeModule->strDLLFun=amoduleConfig[3];
aPeModule->paramCardNameInSlf=amoduleConfig[4];
aPeModule->runBrunch=amoduleConfig[5].toInt();
aPeModule->strPlot=amoduleConfig[6];
}
else {
aPeModule->GetMetaData()->SetSubCategory(amoduleConfig[1].toStdString());
aPeModule->GetMetaData()->SetID(sortnumber+afile.completeBaseName().toStdString()+"_"+amoduleConfig[4].toStdString());
aPeModule->GetMetaData()->SetName(amoduleConfig[2].toStdString());
if(amoduleConfig.size()>7 )aPeModule->strPlot=amoduleConfig[7];
aPeModule->strDLLFun=amoduleConfig[4];
aPeModule->paramCardNameInSlf=amoduleConfig[5];
aPeModule->runBrunch=amoduleConfig[6].toInt();
}
}
aPeModule->SetLibraryfilename(strDllPath);
GetModuleManager()->AddModule(aPeModule->GetLibraryfilename().toStdString(),aPeModule,NULL);
}
}
}//for
// if(errormsg!="")
// AppendConsole(pai::log::PAI_ERROR,errormsg);
//delete aPeModule;
}
CParameterEditor * CModuleParamers::CreatParamControlWidget()
{
CModuleConsole *pModuleConsole=m_pModuleConsole;
if(!pModuleConsole) return NULL;
CModuleManager*pMM=GetModuleManager();
std::vector<pai::module::CModule*> vecModules;
pMM->ListAllModules(vecModules);
if(!vecModules.size())
{
LoadPEModules();
}
///////////////////////////////////////////////////
m_TabWidget_Module = new QTabWidget();
///处理模块
QSplitter * m_pSplitter=new QSplitter(Qt::Orientation::Vertical);
m_ModuleToolBarView = new CPaiModuleToolBarView(NULL);
m_pSplitter->addWidget(m_ModuleToolBarView);
m_PWorkflowWidget = new WorkflowWidget(pModuleConsole->m_pWorkflowDataModel);
WorkflowSceneManager *pWorkflowScene = new WorkflowSceneManager(0,0,800,750,m_PWorkflowWidget);
// m_PWorkflowWidget->SetScene(pWorkflowScene);
// m_pSplitter->addWidget(m_PWorkflowWidget);
///组合模块
// m_pTemplateTree = new pai::CPaiWorkflowTemplateTree(QUuid());
///参数编辑模块
m_TablWiget_Para = new QTabWidget();
m_TabWidget_Module->addTab(m_pSplitter,QIcon(::GetImagePath() + "icon/workflow.png"),QObject::tr("方法模块"));
// m_TabWidget_Module->addTab(m_pTemplateTree,QIcon(::GetImagePath()+"icon/SaveAsTemplate.png"),QObject::tr("定制方法"));
m_TabWidget_Module->addTab(m_TablWiget_Para,QIcon(::GetImagePath()+"icon/SaveAsTemplate.png"),QObject::tr("计算处理"));
//参数卡页面初始化
/////
m_pParameterEditor = new CParameterEditor(NULL);
if(m_pParameterEditor != NULL)
{
ParameterEditorModel* pEditorModel = dynamic_cast< ParameterEditorModel * > (m_pParameterEditor->model());
// if(pModuleConsole->GetWorkflowWidget()&&pEditorModel != NULL && pModuleConsole->GetWorkflowWidget()->GetWorkflow())
// {
// pEditorModel->SetCurrentWorkflowID(QUuid(pModuleConsole->GetWorkflowWidget()->GetWorkflow()->GetID()));
// pEditorModel->m_SelectedCompositeMethod=pModuleConsole->GetSelectedCompositeMethod();
// }
QWidget * pWidget = new QWidget();
pWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
PaiPushButton * m_pbtnRun2;
m_pbtnRun2= new PaiPushButton(QIcon(::GetImagePath() +"icon/run.png"),"处理");
m_pbtnRun= new PaiPushButton(QIcon(::GetImagePath() +"icon/run.png"),"处理当前段");
m_pbtnRun->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
//先初始化widget 并设置好布局
QVBoxLayout*pVBoxLayout = new QVBoxLayout();
pVBoxLayout->setSpacing(0);
pVBoxLayout->setAlignment(Qt::AlignTop);
QToolBar * ptoolbar = new QToolBar();
ptoolbar->addWidget(m_pbtnRun2);
ptoolbar->addWidget(m_pbtnRun);
pVBoxLayout->addWidget(m_pParameterEditor);
//基于父widget创建
m_pDialogLayout = new QScrollArea();
m_pDialogLayout->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pDialogLayout->setWidgetResizable(true);//在widget要显示的内容超出范围时能够改变widget
m_pDialogLayout->setMinimumHeight(0);
pVBoxLayout->addWidget(m_pDialogLayout);
pVBoxLayout->addWidget(ptoolbar);
pWidget->setLayout(pVBoxLayout);
m_TablWiget_Para->addTab(pWidget,QIcon( ::GetImagePath() + "icon/Zone.png" ),QObject::tr("可视参数"));
connect(m_pbtnRun2,SIGNAL(clicked()),this,SLOT(slotRun()));
connect(m_pbtnRun,SIGNAL(clicked()),this,SLOT(slotRunCurrentZone()));
}
m_pEdtParamCard = new CompleterTextEdit();
connect(m_pEdtParamCard,SIGNAL(cursorPositionChanged()),
this,SLOT(onCurrentLineHighLight()));
connect(m_pEdtParamCard,SIGNAL(selectionChanged()),this,SLOT(onLineHighLight()));
if(m_pEdtParamCard){
QFont ft(QString::fromLocal8Bit("宋体"),16);
m_pEdtParamCard->setFont(ft);
QTextOption textOp=m_pEdtParamCard->document()->defaultTextOption();
textOp.setWrapMode(QTextOption::WordWrap);
m_pEdtParamCard->document()->setDefaultTextOption(textOp);
m_pParameterEditor->SetEdit(m_pEdtParamCard);
PaiPushButton * m_pOKButton1;
PaiPushButton * m_pOKButton;
PaiPushButton * m_pbtnLoadParameterCard;
PaiPushButton * m_pbtnSaveParameterCard;
PaiPushButton * m_pbtnRun1;
QWidget * pWidget = new QWidget();
m_pOKButton1 = new PaiPushButton(QIcon(::GetImagePath() +"icon/ParamZone.png"),"参数统计");
m_pOKButton = new PaiPushButton(QIcon(::GetImagePath() +"icon/ParamZone.png"),"可视化");
m_pbtnLoadParameterCard= new PaiPushButton(QIcon(::GetImagePath() +"icon/Open.png"),"读取");
m_pbtnSaveParameterCard= new PaiPushButton(QIcon(::GetImagePath() +"icon/SaveAs.png"),"另存");
m_pbtnRun1= new PaiPushButton(QIcon(::GetImagePath() +"icon/run.png"),"处理");
QVBoxLayout * pVBoxLayout = new QVBoxLayout();
QToolBar * ptoolbar = new QToolBar();
ptoolbar->addWidget(m_pbtnRun1);
ptoolbar->addWidget(m_pOKButton1);
ptoolbar->addWidget(m_pOKButton);
ptoolbar->addWidget(m_pbtnLoadParameterCard);
ptoolbar->addWidget(m_pbtnSaveParameterCard);
pVBoxLayout->addWidget(m_pEdtParamCard);
pVBoxLayout->addWidget(ptoolbar);
pWidget->setLayout(pVBoxLayout);
m_TablWiget_Para->addTab(pWidget,QIcon( ::GetImagePath() + "icon/ParameterCard.png" ),QObject::tr("文本参数"));
connect( m_pOKButton1,SIGNAL(clicked()),this,SLOT(slotOnSTPAR()));
connect( m_pOKButton,SIGNAL(clicked()),this,SLOT(slotOnSetParameterOK()));
connect(m_pbtnLoadParameterCard,SIGNAL(clicked()),this,SLOT(slotLoadParameterCard()));
connect(m_pbtnSaveParameterCard,SIGNAL(clicked()),this,SLOT(slotSaveParameterCard()));
connect(m_pbtnRun1,SIGNAL(clicked()),this,SLOT(slotRunCard()));
}
//常见参数配置
m_pParamSettingList=new QTreeWidget();
if(m_pParamSettingList) {
QStringList ss;
ss<</*QString::fromLocal8Bit*/("参数")<</*QString::fromLocal8Bit*/("含义");
2026-01-16 17:18:41 +08:00
m_pParamSettingList->setHeaderLabels(ss);
QVBoxLayout * psVBoxLayout = new QVBoxLayout();
psVBoxLayout->addWidget(m_pParamSettingList);
m_pBtnParamSettingOK= new PaiPushButton(QIcon(::GetImagePath() +"icon/ParamZone.png"),"保存");
m_pBtnParamAllSelect= new PaiPushButton(QIcon(::GetImagePath() +"icon/select.png"),"全部选中");
m_pBtnParamAllClear= new PaiPushButton(QIcon(::GetImagePath() +"icon/clear.png"),"全部清除");
QToolBar * pstoolbar = new QToolBar();
psVBoxLayout->addWidget(pstoolbar);
pstoolbar->addWidget(m_pBtnParamSettingOK);
pstoolbar->addWidget(m_pBtnParamAllSelect);
pstoolbar->addWidget(m_pBtnParamAllClear);
QWidget * psWidget = new QWidget();
psWidget->setLayout(psVBoxLayout);
m_TablWiget_Para->addTab(psWidget,QIcon( ::GetImagePath() + "icon/ParameterCard.png" ),QObject::tr("文本参数配置"));
connect( m_pBtnParamSettingOK,SIGNAL(clicked()),this,SLOT(slotOnSetingParameterOK()));
connect( m_pBtnParamAllSelect,SIGNAL(clicked()),this,SLOT(slotOnSelectParameterOK()));
connect( m_pBtnParamAllClear,SIGNAL(clicked()),this,SLOT(slotOnClearParameterOK()));
}
setCentralWidget(m_TabWidget_Module);
// connect(&ModuleGraphicsItem::m_EventAgent, SIGNAL(ClickSelectedItem(pai::workflow::CModuleInformation*)),
// m_ModuleToolBarView->GetModuleTree(), SLOT(slotSelectModule(pai::workflow::CModuleInformation*)));
connect(m_ModuleToolBarView->GetModuleTree(),SIGNAL(DeliverModule(const QString&)),pWorkflowScene,SLOT(slotAddModule(const QString&)),Qt::UniqueConnection);
// disconnect(pWorkflowScene, SIGNAL(signalOpenModuleParam(pai::workflow::CModuleInformation*)),
// m_pParameterEditor, SLOT(slotForceOpen(pai::workflow::CModuleInformation*)));
// connect(pWorkflowScene, SIGNAL(signalOpenModuleParam(pai::workflow::CModuleInformation*)),
// m_pParameterEditor, SLOT(slotForceOpen(pai::workflow::CModuleInformation*)));
// connect(m_pParameterEditor->model(),
// SIGNAL(signalErrorInfoChanged(pai::workflow::CModuleInformation *,bool ,const pai::module::CModuleCheckResult, ValidateEventSource)),
// pWorkflowScene,
// SLOT(slotOnModuleParameterError(pai::workflow::CModuleInformation*,bool ,const pai::module::CModuleCheckResult, ValidateEventSource)));
// connect(pWorkflowScene, SIGNAL(doubleClickModule(pai::workflow::CModuleInformation* ,bool)), m_pParameterEditor,
// SLOT(slotOpen(pai::workflow::CModuleInformation*, bool)));
// connect(pWorkflowScene, SIGNAL(doubleClickModule(pai::workflow::CModuleInformation*, bool)), pModuleConsole->GetWorkflowControl(),
// SLOT( slotActivateParameterEditor(pai::workflow::CModuleInformation*, bool)));
// connect(m_pTemplateTree,SIGNAL(itemDoubleClicked(pai::objectmodel::PaiObject*)),pWorkflowScene,SLOT(slotApplyTemplate(pai::objectmodel::PaiObject*)));
// if(pModuleConsole->GetSelectedModuleClassId()!="")
// {
// m_ModuleToolBarView->GetModuleTree()->MonkeyClickedModule(pModuleConsole->GetSelectedModuleClassId());
// }
// else if(pModuleConsole->GetSelectedCompositeMethod()!="")//说明使用了组合方法
// {
// //第一步让模板树的方法到操作区
// // m_pTemplateTree->MonkeyClickedModule(pModuleConsole->GetSelectedCompositeMethod());
// }
//第二步,让方法依次双击,从而初始化参数区
// int nModuleCount = pModuleConsole->m_pWorkflowDataModel->GetModuleCount();
// if(nModuleCount>1){
// ParameterEditorModel* pEditorModel = dynamic_cast< ParameterEditorModel * > (m_pParameterEditor->model());
// pEditorModel->m_CompositeMethod=true;
// }
// for(int i = 0; i < nModuleCount; ++i)
// {
// pai::workflow::CModuleInformation* pModule =pModuleConsole->m_pWorkflowDataModel->GetModule(i);
// if( pModule)
// {
// PELibraryModule *pPE=dynamic_cast<PELibraryModule *>(pModule->GetModule());
// if(pPE) {
// pPE->SetEdit(m_pEdtParamCard);
// }
// m_pParameterEditor->slotForceOpen(pModule);
// }
// }
// connect(this, SIGNAL(signalOpenParameterEditor(pai::workflow::CModuleInformation* ,bool)), m_pParameterEditor,
// SLOT(slotOpen(pai::workflow::CModuleInformation*, bool)));
HideModuleTree();
//pDockWidget->hide();
return m_pParameterEditor;
}
void CModuleParamers::slotRunCard()
{
// CModuleConsole *pModuleConsole=m_pModuleConsole;
// if(!pModuleConsole) return;
// PaiWorkflowDataModel* pWorkflowDatamdel = pModuleConsole->GetWorkflowWidget()->GetWorkflow();
// int nModuleCount = pWorkflowDatamdel->GetModuleCount();
// for(int i = 0; i < nModuleCount; ++i)
// {
// pai::workflow::CModuleInformation* pModule = pWorkflowDatamdel->GetModule(i);
// if(pModule)
// {
// PELibraryModule *pPE=dynamic_cast<PELibraryModule *>(pModule->GetModule());
// if(pPE) pPE->isEditCard=true;
// }
// }
// OnSetParameterToSlf();
// slotRun();
// for(int i = 0; i < nModuleCount; ++i)
// {
// pai::workflow::CModuleInformation* pModule = pWorkflowDatamdel->GetModule(i);
// if(pModule)
// {
// PELibraryModule *pPE=dynamic_cast<PELibraryModule *>(pModule->GetModule());
// if(pPE) pPE->isEditCard=false;
// }
// }
}
void CModuleParamers::onLineHighLight()
{
/*
QTextCursor cursor = m_pEdtParamCard->textCursor();
cursor.clearSelection();
QString editText = m_pEdtParamCard->toPlainText();
editText = editText.toLower();
int pos=cursor.position();
int nextpos=pos+1;
QString searchText =",";
//searchText.toLower();
while (pos>-1)
{
int startIdx = pos;//editText.indexOf(searchText);
int endIdx = startIdx+1;// + searchText.size();
cursor.setPosition(startIdx, QTextCursor::MoveAnchor);
cursor.setPosition(endIdx, QTextCursor::KeepAnchor);
QString text1=cursor.selectedText();
if(text1!=",") pos--;
else break;
}
while (nextpos<editText.size())
{
int startIdx = nextpos;//editText.indexOf(searchText);
int endIdx = startIdx+1;// + searchText.size();
cursor.setPosition(startIdx, QTextCursor::MoveAnchor);
cursor.setPosition(endIdx, QTextCursor::KeepAnchor);
QString text1=cursor.selectedText();
if(text1!=",") nextpos++;
else break;
}
cursor.clearSelection();
cursor.selectionEnd();
cursor.setPosition(pos, QTextCursor::MoveAnchor);
cursor.setPosition(nextpos, QTextCursor::KeepAnchor);
QString text1=cursor.selectedText();
QTextCharFormat format;
// QColor lineColor = QColor(Qt::gray).lighter(140);
format.setBackground(Qt::red);
format.setForeground(Qt::blue);
cursor.mergeCharFormat(format);
m_pEdtParamCard->setTextCursor(cursor);
int a=1;
*/
}
QColor setInsertTextColor(QTextEdit *m_pEdtParamCard,QString search_text,const QColor &color)
{
QTextDocument *document =m_pEdtParamCard->document();
bool found = false;
QTextCursor highlight_cursor(document);
QTextCursor cursor(document);
//开始
cursor.beginEditBlock();
QTextCharFormat color_format(highlight_cursor.charFormat());
QColor oldcolor;
color_format.setForeground(color);
while (!highlight_cursor.isNull() && !highlight_cursor.atEnd()) {
//查找指定的文本,匹配整个单词
highlight_cursor = document->find(search_text, highlight_cursor);//, QTextDocument::FindBackward);
if (!highlight_cursor.isNull()) {
if(!found)
found = true;
oldcolor=highlight_cursor.charFormat().foreground().color();
highlight_cursor.mergeCharFormat(color_format);
}
}
cursor.endEditBlock();
return oldcolor;
}
void CModuleParamers::onCurrentLineHighLight()
{
static QString ntext1;
static QColor oldcolor;
QTextEdit *edit = (QTextEdit *)m_pEdtParamCard;
QTextCursor cursor = edit->textCursor();
QTextCursor cursor1 = edit->textCursor();
QList<QTextEdit::ExtraSelection> extraSelection;
QTextEdit::ExtraSelection selection;
QString editText = edit->toPlainText();
if(ntext1.size()) setInsertTextColor(m_pEdtParamCard,ntext1,oldcolor);
int pos=cursor.position();
int nextpos=pos+1;
QChar ch=0x2029;
while (pos>-1)
{
int startIdx = pos;//editText.indexOf(searchText);
int endIdx = startIdx+1;// + searchText.size();
cursor.setPosition(startIdx, QTextCursor::MoveAnchor);
cursor.setPosition(endIdx, QTextCursor::KeepAnchor);
QString text1=cursor.selectedText();
if(text1.size()&&text1.at(0)==0x2029) break;
if(text1!=","&&text1!="\r"&&text1!="\n") pos--;
else {
pos++;
break;
}
}
while (nextpos<editText.size())
{
int startIdx = nextpos;//editText.indexOf(searchText);
int endIdx = startIdx+1;// + searchText.size();
cursor.setPosition(startIdx, QTextCursor::MoveAnchor);
cursor.setPosition(endIdx, QTextCursor::KeepAnchor);
QString text1=cursor.selectedText();
if(text1.size()&&text1.at(0)==0x2029) break;
if(text1!="="&&text1!=","&&text1!="\r"&&text1!="\n") nextpos++;
else break;
}
cursor.clearSelection();
cursor.setPosition(pos, QTextCursor::MoveAnchor);
cursor.setPosition(nextpos, QTextCursor::KeepAnchor);
QString ntext=editText.mid(pos,nextpos-pos);
if(ntext.size()||ntext.indexOf('=')>0) {
int pos=ntext.indexOf('=');
if(pos>0) ntext=ntext.left(pos);
ntext=ntext.trimmed();
oldcolor=cursor.charFormat().foreground().color();
setInsertTextColor(m_pEdtParamCard,ntext,QColor(Qt::red));
}
QColor lineColor = QColor(Qt::gray).lighter(140);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection,true);
selection.cursor =cursor1;
selection.cursor.clearSelection();
//将刚设置的 selection追加到链表当中
extraSelection.append(selection);
edit->setExtraSelections(extraSelection);
ntext1=ntext;
}
void CModuleParamers::slotRunCurrentZone()
{
CModuleConsole*pWorkflowConsole=m_pModuleConsole;
if(!pWorkflowConsole) return;
SetWorkflowConsole(pWorkflowConsole);
float sdep=-99999,edep=-99999;
pWorkflowConsole->g_mModuleParamers->GetCurrentZone(sdep,edep);
if(sdep==-99999) {
// AfxMessageBox("请先选中层段!\n(点击层内任意字段均可)");
QMessageBox::information(NULL,"","请先选中层段!\n(点击层内任意字段均可)");
return;
}
// pWorkflowConsole->RunWorkFlow(sdep,edep);
QString Zone = "";
pai::workflow::CModuleInformation * pModuleInfo = m_pCurrentModuleInfo;
pai::module::CModule* pModule = pModuleInfo->GetModule();
PELibraryModule * pWelllogModule = dynamic_cast<PELibraryModule*>(pModule);
std::string strName = pModuleInfo->GetName();
double dep1=-99999,dep2=-99999;
char *Zone1=NULL;
if(!Zone.isEmpty()) Zone1=(char*)Zone.toStdString().c_str();
int i=(int)pWelllogModule->Run(sdep,edep,Zone1);
}
bool CModuleParamers::GetCurrentZone(float &sdep,float &edep)
{
return m_pParameterEditor->GetCurrentZone(sdep,edep);
}
void CModuleParamers::slotRun()
{
// CModuleConsole*pWorkflowConsole=m_pModuleConsole;
// if(!pWorkflowConsole) return;
// SetWorkflowConsole(pWorkflowConsole);
// pWorkflowConsole->g_mModuleParamers->m_pParameterEditor->FinishInputData();
// pWorkflowConsole->RunWorkFlow();
// PELibraryModule * pWelllogModule = NULL;
// CWellLogWorkflowDataModel * pWorkflowDataModel =dynamic_cast<CWellLogWorkflowDataModel*>( ::GetWorkflowConsole()->GetWorkflowWidget()->GetWorkflow() );
// if (pWorkflowDataModel)
// {
// pWelllogModule = dynamic_cast<PELibraryModule*>(pWorkflowDataModel->m_pModule);
// }
QString Zone = "";
pai::workflow::CModuleInformation * pModuleInfo = m_pCurrentModuleInfo;
pai::module::CModule* pModule = pModuleInfo->GetModule();
PELibraryModule * pWelllogModule = dynamic_cast<PELibraryModule*>(pModule);
std::string strName = pModuleInfo->GetName();
double dep1=-99999,dep2=-99999;
char *Zone1=NULL;
if(!Zone.isEmpty()) Zone1=(char*)Zone.toStdString().c_str();
int i=(int)pWelllogModule->Run(dep1,dep2,Zone1);
}
// void CModuleParamers::slotOpenParameterEditor(pai::workflow::CModuleInformation* pInfo, bool IsModuleReadOnly)
// {
// CModuleConsole *pModuleConsole=m_pModuleConsole;
// if(!pModuleConsole) return;
// PaiWorkflowDataModel* pWorkflowDatamdel = pModuleConsole->GetWorkflowWidget()->GetWorkflow();
// int nModuleCount = pWorkflowDatamdel->GetModuleCount();
// for(int i = 0; i < nModuleCount; ++i)
// {
// pai::workflow::CModuleInformation* pModule = pWorkflowDatamdel->GetModule(i);
// if(pInfo == pModule)
// {
// emit signalOpenParameterEditor(pInfo,IsModuleReadOnly);
// }
// }
// }
void CModuleParamers::HideModuleTree()
{
if(m_TabWidget_Module)m_TabWidget_Module->setVisible(true);
}
void CModuleParamers::HideParameterEditor()
{
m_TablWiget_Para->setVisible(false);
}
void CModuleParamers::slotOnSTPAR()
{
OnSetParameterOK(true);
}
void CModuleParamers::slotOnSetParameterOK()
{
OnSetParameterOK();
}
void CModuleParamers::OnSetParameterToSlf()
{
// AppendConsole(pai::log::PAI_INFO,"开始解析参数卡...");
// QString str = m_pEdtParamCard->toPlainText();
// str.replace(" "," ");
// str.replace("",",");
// str.replace(", ",",");
// QTextDocument *pdoc=m_pEdtParamCard->document();
// if(pdoc)pdoc->setModified(false);
// QString time_str=QString::fromStdString(GenTimeStamp());
// QString runPath = QCoreApplication::applicationFilePath();
// CModuleConsole *pModuleConsole=m_pModuleConsole;
// if(!pModuleConsole) return;
// CWellLogWorkflowDataModel* currentworkflow=dynamic_cast<CWellLogWorkflowDataModel*>(pModuleConsole->GetWorkflowWidget()->GetWorkflow());
// if(!currentworkflow) return;
// str.replace("\r\n","\r");
// str.replace("\r","\r\n");
// QStringList lines;
// if(str.indexOf("\r\n")>-1) {
// lines=str.split("\r\n");
// }
// else lines=str.split("\n");
// CModule* pModule=NULL;
// if(m_pCurrentModuleInfo) pModule=m_pCurrentModuleInfo->GetModule();
// WorkflowSceneManager* pscenmgr=(WorkflowSceneManager*)(pModuleConsole->GetWorkflowWidget()->GetScene());
// //非组合模块运行,只处理当前模块
// QVector<CObjWellTrack*> wellts=GetWellTracks();
// foreach(CObjWellTrack*pWellt,wellts)
// {
// CObjWelllogRound *pWell=pWellt->GetWelllogRound();
// if(!pWell) return;
// int modulecount=currentworkflow->GetModuleCount();
// for(int index=0;index<modulecount;index++)
// {
// CModule* pCurrentModule=currentworkflow->GetModule(index)->GetModule();
// if(!pModule) pModule=pCurrentModule;
// if(pCurrentModule){
// QString fileName=((PELibraryModule*)pCurrentModule)->GetINPCardName();
// if(((PELibraryModule*)pCurrentModule)->GetParamCardfilename()=="")
// ((PELibraryModule*)pCurrentModule)->SetParamCardfilename(fileName);
// ((PELibraryModule*)pCurrentModule)->SetSlfFileName(pWell->GetSlfFileName());
// CObjWellLogINP::SaveParamStrToSlfFile(str,((PELibraryModule*)pCurrentModule)->GetParamCardfilename(),pWell->GetSlfFileName());
// //
// }
// }
// }
}
void CModuleParamers::OnSetParameterOK(int stpar)
{
// AppendConsole(pai::log::PAI_INFO,"开始解析参数卡...");
// QString str = m_pEdtParamCard->toPlainText();
// str.replace(" "," ");
// str.replace("",",");
// str.replace(", ",",");
// QTextDocument *pdoc=m_pEdtParamCard->document();
// if(pdoc)pdoc->setModified(false);
// QString time_str=QString::fromStdString(GenTimeStamp());
// QString runPath = QCoreApplication::applicationFilePath();
// CModuleConsole *pModuleConsole=m_pModuleConsole;
// if(!pModuleConsole) return;
// CWellLogWorkflowDataModel* currentworkflow=dynamic_cast<CWellLogWorkflowDataModel*>(pModuleConsole->GetWorkflowWidget()->GetWorkflow());
// if(!currentworkflow) return;
// str.replace("\r\n","\r");
// str.replace("\r","\r\n");
// QStringList lines;
// if(str.indexOf("\r\n")>-1) {
// lines=str.split("\r\n");
// }
// else lines=str.split("\n");
// CModule* pModule=NULL;
// if(m_pCurrentModuleInfo) pModule=m_pCurrentModuleInfo->GetModule();
// WorkflowSceneManager* pscenmgr=(WorkflowSceneManager*)(pModuleConsole->GetWorkflowWidget()->GetScene());
// //非组合模块运行,只处理当前模块
// QVector<CObjWellTrack*> wellts=GetWellTracks();
// foreach(CObjWellTrack*pWellt,wellts)
// {
// CObjWelllogRound *pWell=pWellt->GetWelllogRound();
// if(!pWell) return;
// int modulecount=currentworkflow->GetModuleCount();
// for(int index=0;index<modulecount;index++)
// {
// CModule* pCurrentModule=currentworkflow->GetModule(index)->GetModule();
// if(!pModule) pModule=pCurrentModule;
// if(pCurrentModule){
// QString fileName=((PELibraryModule*)pCurrentModule)->GetINPCardName();
// if(((PELibraryModule*)pCurrentModule)->GetParamCardfilename()=="")
// ((PELibraryModule*)pCurrentModule)->SetParamCardfilename(fileName);
// ((PELibraryModule*)pCurrentModule)->SetSlfFileName(pWell->GetSlfFileName());
// CObjWellLogINP::SaveParamStrToSlfFile(str,((PELibraryModule*)pCurrentModule)->GetParamCardfilename(),pWell->GetSlfFileName());
// //
// }
// }
// }
// if(pModule) {
// ParameterEditorModel* pEditorModel = dynamic_cast< ParameterEditorModel * > (m_pParameterEditor->model());
// if(pEditorModel) {
// pEditorModel->m_currentindex=QModelIndex();
// pEditorModel->clear();
// }
// ((PELibraryModule*)pModule)->InitModule(m_pParameterEditor);
// if (((PELibraryModule*)pModule)->LoadParamFromLines(lines)){
// if(stpar)((PELibraryModule*)pModule)->GetPARAM_TAB();
// AppendConsole(pai::log::PAI_INFO,"参数卡解析完成,界面同步中...");
// }
// else
// AppendConsole(pai::log::PAI_INFO,"参数卡解析失败请检查模块json文件是否有Zones字段及参数格式...");
// m_pParameterEditor->slotBackModule(m_pCurrentModuleInfo);
// }
// AppendConsole(pai::log::PAI_INFO,"参数卡解析完成,界面同步完成");
}
QString CModuleParamers::GetCurrentSLFFileName()
{
return m_CurrentSLFFileName;
// CModuleConsole *pModuleConsole=m_pModuleConsole;
// if(!pModuleConsole) return "";
// CWellLogWorkflowDataModel* pwellWorkflowDataModel=dynamic_cast<CWellLogWorkflowDataModel*>(pModuleConsole->GetWorkflowWidget()->GetWorkflow());
// CBaseObject* subtree=CPaiObjectHelper::GetSubtree(::GetProject(),pwellWorkflowDataModel->GetCurrentWellRoundPath());
// if(subtree)
// {
// if(subtree->GetPaiObject()->GetTypeID()==GetClassID_WellLogRound()){
// CObjWelllogRound* currentwr=(CObjWelllogRound*)(subtree->GetPaiObject());
// return currentwr->GetSlfFileName();
// }
// }
return "";
}
void CModuleParamers::slotLoadParameterCard()
{
QString fileName = QFileDialog::getOpenFileName(this, ("打开参数卡"), NULL, ("参数卡文件(*.inp)"));
if(fileName=="") return;
QFile file( fileName );
if ( file.open( QIODevice::ReadOnly ) ) {
m_pEdtParamCard->clear();
QTextStream stream( &file );
QString oneline;
int n = 1;
while ( !stream.atEnd() ) {
oneline = stream.readLine(); // 不包括“\n”的一行文本
//printf( "%3d: %s\n", n++, line.latin1() );
m_pEdtParamCard->append(oneline);
}
file.close();
if(m_pCurrentModuleInfo) {
PELibraryModule *pPe=dynamic_cast<PELibraryModule*>(m_pCurrentModuleInfo->GetModule());
if(pPe) {
pPe->SetCardParamColor(GetEdtParamCard());
}
}
}
else QMessageBox::about(NULL, "提示", "打开参数卡错误!");
}
void CModuleParamers::slotOnSelectParameterOK()
{
if(!m_pParamSettingList) return;
int count1=m_pParamSettingList->topLevelItemCount();
for(int i=0;i<count1;i++)
{
QTreeWidgetItem *item=m_pParamSettingList->topLevelItem(i);
for(int j=0;j<item->childCount();j++) {
QTreeWidgetItem *item1=item->child(j);
item1->setData(0,Qt::CheckStateRole,Qt::Checked);
}
}
}
void CModuleParamers::slotOnClearParameterOK()
{
if(!m_pParamSettingList) return;
int count1=m_pParamSettingList->topLevelItemCount();
for(int i=0;i<count1;i++)
{
QTreeWidgetItem *item=m_pParamSettingList->topLevelItem(i);
for(int j=0;j<item->childCount();j++) {
QTreeWidgetItem *item1=item->child(j);
item1->setData(0,Qt::CheckStateRole,Qt::Unchecked);
}
}
}
void CModuleParamers::slotOnSetingParameterOK()
{
if(!m_pParamSettingList) return;
if(!m_pCurrentModuleInfo) return;
PELibraryModule* amodule=dynamic_cast<PELibraryModule*>(m_pCurrentModuleInfo->GetModule());
if(amodule)
{
QString fun=QString::fromStdString(amodule->GetMetaData()->GetID());
int i=fun.indexOf("_");
if(i>-1) fun=fun.mid(i+1);
QString paramSettingFileName=QCoreApplication::applicationDirPath() + QDir::separator() +"app"+QDir::separator()
+fun+".config";
QFile paramSettingFile(paramSettingFileName);
if (paramSettingFile.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream out(&paramSettingFile);
int count1=m_pParamSettingList->topLevelItemCount();
for(int i=0;i<count1;i++)
{
QTreeWidgetItem *item=m_pParamSettingList->topLevelItem(i);
for(int j=0;j<item->childCount();j++) {
QTreeWidgetItem *item1=item->child(j);
int vv=item1->data(0,Qt::CheckStateRole).toInt();
if(item1->data(0,Qt::CheckStateRole)==Qt::Checked) {
out<<item1->text(0)<<"\r\n";
}
}
}
}
paramSettingFile.close();
}
InitCardParamSettings(m_pCurrentModuleInfo);
}
void CModuleParamers::slotSaveParameterCard()
{
QString fileName = QFileDialog::getSaveFileName(this, ("保存参数卡"), NULL, ("参数卡文件(*.inp)"));
if(fileName=="") return;
QString str = m_pEdtParamCard->toPlainText();
str.replace(" "," ");
str.replace("",",");
str.replace(", ",",");
QFile file(fileName);
if(!file.open(QIODevice::WriteOnly | QIODevice::Text|QIODevice::Append))
{
QMessageBox::warning(NULL,QObject::tr("提示"),QObject::tr("打不开文件,无法进行写入操作!") ,QMessageBox::Yes);
}
QTextStream in(&file);
in<<str<<"\n";
file.close();
QMessageBox::about(NULL, "提示", "参数卡保存成功");
}
END_OSGGRAPHICS_NAMESPACE