添加后处理vtu、pvtu格式支持,优化cgns格式的读取以及其它问题优化
|
@ -149,7 +149,7 @@ PointerAlignment: Left
|
|||
# 允许重新排版注释
|
||||
ReflowComments: true
|
||||
# 允许排序#include
|
||||
SortIncludes: CaseInsensitive
|
||||
SortIncludes: Never
|
||||
# 在C风格类型转换后添加空格
|
||||
SpaceAfterCStyleCast: false
|
||||
# 在赋值运算符之前添加空格
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
.vscode
|
||||
.vs
|
||||
.idea
|
||||
/build
|
||||
/install
|
||||
/extlib
|
||||
|
|
|
@ -66,6 +66,7 @@ option(FASTCAE_ENABLE_OPENMP "使用OpenMP" OFF)
|
|||
option(FASTCAE_ENABLE_MPI "使用MPI" OFF)
|
||||
option(FASTCAE_DOXYGEN_DOC "生成Doxygen文档" OFF)
|
||||
option(FASTCAE_INSTALLATION_PACKAGE "生成${PROJECT_NAME}安装包" ON)
|
||||
option(FASTCAE_DEBUG_INFO "输出调试信息" ON)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# 指定编译选项
|
||||
|
@ -109,6 +110,13 @@ if(FASTCAE_ENABLE_MPI)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# 输出调试信息
|
||||
#-----------------------------------------------------------------------------
|
||||
if(FASTCAE_DEBUG_INFO)
|
||||
add_definitions(-DOUTPUT_DEBUG_INFO)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# 从系统查找Qt模块,开启Qt中间文件的自动生成
|
||||
#-----------------------------------------------------------------------------
|
||||
|
|
|
@ -10,6 +10,7 @@ Version:2.5.x
|
|||
- 加入OpenGL版本检测函数,当环境OPenGL版本低于3.3时,给出错误提示。
|
||||
- 新增自动打包功能,Windows需要NSIS 3.03+、Linux需要dpkg-deb或者rpmbuild(需要python3)。
|
||||
- 新增文档自动生成功能,需要安装Doxygen和Graphviz。
|
||||
- 增加vtu、pvtu格式的后处理文件支持
|
||||
|
||||
**功能优化**
|
||||
- 代码全部采用cmake进行管理,可任意选择vscode、Visual Studio、Clion、Qtcreator等支持cmake系统的IDE。
|
||||
|
@ -17,6 +18,9 @@ Version:2.5.x
|
|||
- 删除Qt浏览器组建及相关依赖(Qt安装不再需要QWebEngine组件)。
|
||||
- 优化Python调用,不再依赖系统配置,简化操作。
|
||||
- 从依赖库中移除未使用的VTK、OpenCASCADE模块。
|
||||
- 优化CGNS后处理文件解析,添加MIXED类型单元区域的解析。
|
||||
- 优化后处理属性面板场变量数据类型的显示方式。
|
||||
- 优化日志输出方式,便于错误定位
|
||||
|
||||
**功能修复**
|
||||
- 修复linux环境卸载插件时崩溃的问题
|
||||
|
|
33
README.md
|
@ -9,6 +9,39 @@
|
|||
- src: FastCAE源码
|
||||
- test: 包含单元测试代码(待整理)
|
||||
|
||||
## 构建编译
|
||||
|
||||
### FastCAE相关的cmake构建选项说明
|
||||
- `FASTCAE_AUTO_DOWNLOAD`:如果源码目录不存在extlib目录时是否会自动从gitee克隆依赖包。
|
||||
- `FASTCAE_DOXYGEN_DOC`:是否需要构建目标Doxygen(需要本地安装Doxygen软件)
|
||||
- `FASTCAE_ENABLE_DEV`:是否在构建完成时自动拷贝依赖文件到调试目录。(开启该选项会在每次编译完拷贝第三方依赖库文件到构建目录,会增加构建时间)
|
||||
- `FASTCAE_ENABLE_MPI`:是否开启MPI支持(目前无效)。
|
||||
- `FASTCAE_ENABLE_OPENMP`:是否开启OpenMP。
|
||||
- `FASTCAE_ENABLE_TEST`:是否构建单元测试模块(目前无效)。
|
||||
- `FASTCAE_INSTALLATION_PACKAGE`:是否构建安装包制作PACKAGE。
|
||||
|
||||
### cmake预定义目标说明:
|
||||
- ALL_BUILD:生成所有项目。
|
||||
- INSTALL:安装FastCAE到CMAKE_INSTALL_PREFIX定义的目录。
|
||||
- PACKAGE或者package: 在Visual Studio中该目标为大写,在其它构建系统中该目标为小写,用于将FastCAE打包成安装包(exe、deb、rpm)。
|
||||
- DOXYGEN: 生成FastCAE的Doxygen格式文档(html)。
|
||||
|
||||
### 编译视频教程
|
||||
|
||||
#### Windows
|
||||
|
||||
- <a href="https://www.bilibili.com/video/BV1U24y1R73n/" target="_blank">cmake 3.24.1 + Visual Studio Community 2017</a>
|
||||
- <a href="https://www.bilibili.com/video/BV1FX4y1y7T4/" target="_blank">QtCreator编译</a>
|
||||
|
||||
|
||||
#### Linux
|
||||
|
||||
- <a href="https://www.bilibili.com/video/BV1iW4y1Y79p/" target="_blank">cmake + GNU GCC + make</a>
|
||||
- <a href="https://www.bilibili.com/video/BV1xd4y1q7Cm/" target="_blank">借助vscode构建、编译、安装、打包</a>
|
||||
|
||||
### 编译说明
|
||||
|
||||
- windows环境下使用vscode时,编译工具链只能使用Visual Studio,目前不支持MinGW工具
|
||||
|
||||
### extlib目录结构
|
||||
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
#include "DebugLogger.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
#define filename(x) strrchr(x, '\\') ? strrchr(x, '\\') + 1 : x
|
||||
#else
|
||||
#define filename(x) strrchr(x, '/') ? strrchr(x, '/') + 1 : x
|
||||
#endif
|
||||
|
||||
namespace Common {
|
||||
void DebugLogger::info(const char* file, int line, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
output(file, line, format, 0, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DebugLogger::warning(const char* file, int line, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
output(file, line, format, 1, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DebugLogger::error(const char* file, int line, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
output(file, line, format, 2, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
char* DebugLogger::currentTime()
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm* timeS;
|
||||
char* buffer = new char[80];
|
||||
|
||||
time(&rawtime);
|
||||
|
||||
timeS = localtime(&rawtime);
|
||||
sprintf(buffer, "%d-%s%d-%s%d %s%d:%s%d:%s%d", timeS->tm_year + 1900,
|
||||
timeS->tm_mon < 10 ? "0" : "", timeS->tm_mon, timeS->tm_mday < 10 ? "0" : "",
|
||||
timeS->tm_mday, timeS->tm_hour < 10 ? "0" : "", timeS->tm_hour,
|
||||
timeS->tm_min < 10 ? "0" : "", timeS->tm_min, timeS->tm_sec < 10 ? "0" : "",
|
||||
timeS->tm_sec);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制台显示控制格式:ESC[{attr1};{attr2};…;{attrn}m
|
||||
* 显示方式:
|
||||
* 0(默认值)
|
||||
* 1(高亮显示,顺便加粗?不确定)
|
||||
* 2(暗淡)
|
||||
* 22(非粗体,不确定)
|
||||
* 4(下划线)
|
||||
* 5(闪烁,但是我没看出有什么效果。。)
|
||||
* 25(非闪烁)
|
||||
* 7(反显,我也没看出效果)
|
||||
* 27(非反显)
|
||||
* 8(隐藏)
|
||||
*
|
||||
* 字体颜色:
|
||||
* 30(黑色)
|
||||
* 31(红色)
|
||||
* 32(绿色)
|
||||
* 33(黄色)
|
||||
* 34(蓝色)
|
||||
* 35(品红)
|
||||
* 36(青色)
|
||||
* 37(白色)
|
||||
* 背景色:
|
||||
* 40(黑色)
|
||||
* 41(红色)
|
||||
* 42(绿色)
|
||||
* 43(黄色)
|
||||
* 44(蓝色)
|
||||
* 45(品红)
|
||||
* 46(青色)
|
||||
* 47(白色)
|
||||
*/
|
||||
void DebugLogger::output(const char* file, int line, const char* format, int level,
|
||||
va_list args)
|
||||
{
|
||||
char type[15] = "";
|
||||
switch(level) {
|
||||
case 1:
|
||||
printf("\033[33m"); // 红色
|
||||
strcpy(type, "WARNING");
|
||||
break;
|
||||
case 2:
|
||||
printf("\033[31m"); // 黄色
|
||||
strcpy(type, "ERROR");
|
||||
break;
|
||||
default:
|
||||
strcpy(type, "INFO");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("[%s][%s:%d][%s]: ", currentTime(), filename(file), line, type);
|
||||
|
||||
vprintf(format, args);
|
||||
printf("\033[0m");
|
||||
}
|
||||
} // namespace Common
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* @file DebugLogger.h
|
||||
* @brief 用于输出调试信息的类
|
||||
* @author FastCAE研发小组(fastcae@diso.cn)
|
||||
* @version 2.5.0
|
||||
* @date 2023-05-11 16:12
|
||||
* @copyright Copyright (c) Since 2020 青岛数智船海科技有限公司 All rights reserved.
|
||||
*
|
||||
* ============================================================================
|
||||
* Program: FastCAE
|
||||
*
|
||||
* Copyright (c) Since 2020 青岛数智船海科技有限公司 All rights reserved.
|
||||
* See License or http://www.fastcae.com/ for details.
|
||||
*
|
||||
* BSD 3-Clause License
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED.
|
||||
* ==================================================================================
|
||||
*/
|
||||
#ifndef DEBUGLOGGER_H
|
||||
#define DEBUGLOGGER_H
|
||||
|
||||
#include "CommonAPI.h"
|
||||
|
||||
#include <cstdarg>
|
||||
|
||||
namespace Common {
|
||||
class COMMONAPI DebugLogger {
|
||||
public:
|
||||
DebugLogger() = delete;
|
||||
~DebugLogger() = delete;
|
||||
|
||||
public:
|
||||
static void info(const char* file, int line, const char* format, ...);
|
||||
static void warning(const char* file, int line, const char* format, ...);
|
||||
static void error(const char* file, int line, const char* format, ...);
|
||||
|
||||
protected:
|
||||
static char* currentTime();
|
||||
static void output(const char* file, int line, const char* format, int level, va_list args);
|
||||
};
|
||||
} // namespace Common
|
||||
|
||||
// 用宏OUTPUT_DEBUG_INFO控制调试信息是否输出的开关
|
||||
#ifdef OUTPUT_DEBUG_INFO
|
||||
#define DebugInfo(FORMAT, ...) Common::DebugLogger::info(__FILE__, __LINE__, FORMAT, __VA_ARGS__)
|
||||
#define DebugWarn(FORMAT, ...) Common::DebugLogger::warning(__FILE__, __LINE__, FORMAT, __VA_ARGS__)
|
||||
#define DebugError(FORMAT, ...) Common::DebugLogger::error(__FILE__, __LINE__, FORMAT, __VA_ARGS__)
|
||||
#else
|
||||
#define DebugInfo(FORMAT, ...)
|
||||
#define DebugWarn(FORMAT, ...)
|
||||
#define DebugError(FORMAT, ...)
|
||||
#endif // OUTPUT_DEBUG_INFO
|
||||
|
||||
#endif
|
|
@ -31,7 +31,7 @@ set_property(DIRECTORY ${CMAKE_SOURCE_DIR}
|
|||
VS_STARTUP_PROJECT FastCAE
|
||||
)
|
||||
|
||||
list(APPEND _depend_library PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence MainWindow)
|
||||
list(APPEND _depend_library Common PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence MainWindow)
|
||||
if(_WIN_)
|
||||
#list(APPEND _depend_library XGenerateReport License)
|
||||
endif()
|
||||
|
|
|
@ -20,19 +20,21 @@
|
|||
* DISCLAIMED.
|
||||
* ==================================================================================
|
||||
*/
|
||||
#include "CommandLine.h"
|
||||
#include "FastCAEVersionMacros.h"
|
||||
#include "MainWindow/MainWindow.h"
|
||||
#include "XBeautyUI.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QOpenGLContext>
|
||||
#include <QMessageBox>
|
||||
#include "MainWindow/MainWindow.h"
|
||||
#include "XBeautyUI.h"
|
||||
#include "CommandLine.h"
|
||||
#include "FastCAEVersionMacros.h"
|
||||
#include <QOpenGLContext>
|
||||
#include <QProcess>
|
||||
// #include "ConfigOptions/ConfigDataReader.h"
|
||||
// #include "ConfigOptions/ConfigOptions.h"
|
||||
// #include "ConfigOptions/GlobalConfig.h"
|
||||
#include "Common/DebugLogger.h"
|
||||
#include "Settings/BusAPI.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -49,21 +51,22 @@ bool testOpenGL()
|
|||
bool supportOpenGLCore = false;
|
||||
QString currentOpenGLVersion = "";
|
||||
QOpenGLContext ctx;
|
||||
if (ctx.create())
|
||||
{
|
||||
if(ctx.create()) {
|
||||
auto version = ctx.format();
|
||||
if (version.majorVersion() > 3 || (version.majorVersion() == 3 && version.minorVersion() >= 3))
|
||||
{
|
||||
if(version.majorVersion() > 3
|
||||
|| (version.majorVersion() == 3 && version.minorVersion() >= 3)) {
|
||||
supportOpenGLCore = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentOpenGLVersion = QString("%1.%2").arg(version.majorVersion()).arg(version.minorVersion());
|
||||
} else {
|
||||
currentOpenGLVersion =
|
||||
QString("%1.%2").arg(version.majorVersion()).arg(version.minorVersion());
|
||||
}
|
||||
}
|
||||
if (!supportOpenGLCore)
|
||||
{
|
||||
QMessageBox::critical(nullptr, "OpenGL Error", "Startup failed: FastCAE requires OpenGL version greater than or equal to 3.3, but the current version is " + currentOpenGLVersion, QMessageBox::Ok);
|
||||
if(!supportOpenGLCore) {
|
||||
QMessageBox::critical(nullptr, "OpenGL Error",
|
||||
"Startup failed: FastCAE requires OpenGL version greater than or "
|
||||
"equal to 3.3, but the current version is "
|
||||
+ currentOpenGLVersion,
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
return supportOpenGLCore;
|
||||
}
|
||||
|
@ -86,15 +89,14 @@ int main(int argc, char *argv[])
|
|||
return 1;
|
||||
|
||||
QApplication app(argc, argv);
|
||||
if (!testOpenGL())
|
||||
{
|
||||
if(!testOpenGL()) {
|
||||
return 1;
|
||||
}
|
||||
// QString path = qApp->applicationDirPath();
|
||||
// ConfigOption::ConfigDataReader reader(path + "/../ConfigFiles/", ConfigOption::ConfigOption::getInstance());
|
||||
// reader.read();
|
||||
// QString qUseRibbon = ConfigOption::ConfigOption::getInstance()->getGlobalConfig()->getUseRibbon();
|
||||
// bool bUseRibbon = qUseRibbon == "yes" ? true : false;
|
||||
// ConfigOption::ConfigDataReader reader(path + "/../ConfigFiles/",
|
||||
// ConfigOption::ConfigOption::getInstance()); reader.read(); QString qUseRibbon =
|
||||
// ConfigOption::ConfigOption::getInstance()->getGlobalConfig()->getUseRibbon(); bool
|
||||
// bUseRibbon = qUseRibbon == "yes" ? true : false;
|
||||
|
||||
bool isRibbon = Setting::BusAPI::instance()->isUseRibbon();
|
||||
|
||||
|
@ -107,8 +109,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
//**************加载qss******************
|
||||
QFile qssFile(qssFileName);
|
||||
if (qssFile.exists())
|
||||
{
|
||||
if(qssFile.exists()) {
|
||||
qssFile.open(QIODevice::ReadOnly);
|
||||
QString style = qssFile.readAll();
|
||||
qApp->setStyleSheet(style);
|
||||
|
@ -147,8 +148,7 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
#endif
|
||||
|
||||
if (e == -1000)
|
||||
{
|
||||
if(e == -1000) {
|
||||
QProcess::startDetached(qApp->applicationFilePath(), QStringList());
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ add_library(MainWindow
|
|||
#-----------------------------------------------------------------------------
|
||||
target_compile_definitions(MainWindow PRIVATE "MAINWINDOW_API")
|
||||
|
||||
list(APPEND _depend_library PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostRenderData PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence Common)
|
||||
list(APPEND _depend_library Common PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostRenderData PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence Common)
|
||||
if(_WIN_)
|
||||
list(APPEND _depend_library XGenerateReport)
|
||||
endif()
|
||||
|
|
|
@ -1248,7 +1248,7 @@ namespace GUI {
|
|||
|
||||
FileDirectoryDialog dlg;
|
||||
QStringList filterTypes = { "VTK(*.vtk)", "CGNS(*.cgns)", "Plot3D(*.x)",
|
||||
"Tecplot(*.szplt)" };
|
||||
"Tecplot(*.szplt)","VTU(*.vtu)","PVTU(*.pvtu)" };
|
||||
dlg.iniFileFilterType(filterTypes);
|
||||
if(dlg.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
#include <QTranslator>
|
||||
|
||||
#include "Common/DebugLogger.h"
|
||||
namespace GUI {
|
||||
const static QStringList Lang_List = {
|
||||
":/translations/MainWindow_zh_CN", ":/translations/MainWidgets_zh_CN",
|
||||
|
@ -34,8 +34,11 @@ namespace GUI {
|
|||
_app->removeTranslator(tranlator);
|
||||
const QString lang = Lang_List.at(i);
|
||||
bool ok = tranlator->load(lang);
|
||||
qDebug() << lang;
|
||||
assert(ok);
|
||||
if(ok) {
|
||||
DebugInfo("Success to load lang file: %s\n", lang.toStdString().c_str());
|
||||
} else {
|
||||
DebugError("Failed to load lang file: %s\n", lang.toStdString().c_str());
|
||||
}
|
||||
_app->installTranslator(tranlator);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,36 @@
|
|||
#include "CGNSReaderAlgorithm.h"
|
||||
// #include <vtkCGNSReader.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkAppendFilter.h>
|
||||
#include <vtkMultiBlockDataSet.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
// #include <vtkDataSetMapper.h>
|
||||
#include <vtkDataSet.h>
|
||||
#include <vtkUnstructuredGrid.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <vtkCellData.h>
|
||||
#include <vtkDataArray.h>
|
||||
#include <vtkDataSet.h>
|
||||
#include <vtkDemandDrivenPipeline.h>
|
||||
#include <vtkDoubleArray.h>
|
||||
#include <vtkFieldData.h>
|
||||
#include <vtkInformation.h>
|
||||
#include <vtkDemandDrivenPipeline.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <vtkStreamingDemandDrivenPipeline.h>
|
||||
#include <vtkUnstructuredGrid.h>
|
||||
// #include <vtkCGNSFileSeriesReader.h>
|
||||
#include <vtkInformation.h>
|
||||
#include "FCGNSReader.h"
|
||||
#include <vtkInformationStringKey.h>
|
||||
|
||||
#include <cgns_io.h>
|
||||
#include <cgnslib.h>
|
||||
#include <QDebug>
|
||||
#include <vtkInformation.h>
|
||||
#include <vtkInformationStringKey.h>
|
||||
|
||||
#define MAXBLOCKNUM 2000
|
||||
|
||||
CGNSReaderAlgorithm::CGNSReaderAlgorithm()
|
||||
{
|
||||
this->FileName = NULL;
|
||||
// 设置输入端口的数量
|
||||
this->SetNumberOfInputPorts(0);
|
||||
// 设置输出端口的数量
|
||||
this->SetNumberOfOutputPorts(MAXBLOCKNUM + 1);
|
||||
|
||||
for(int i = 0; i < MAXBLOCKNUM; ++i)
|
||||
|
@ -39,38 +42,47 @@ CGNSReaderAlgorithm::~CGNSReaderAlgorithm()
|
|||
this->FileName = NULL;
|
||||
}
|
||||
|
||||
int CGNSReaderAlgorithm::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
|
||||
/**
|
||||
* 许多过滤器可以在不直接提供ProcessRequest()方法的情况下实现。
|
||||
* 标准过滤器超类提供了ProcessRequest()的默认实现,该实现通过将最常见的请求转换为对特定于请求的方法的调用来实现。
|
||||
*/
|
||||
int CGNSReaderAlgorithm::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
|
||||
vtkInformationVector* outputVector)
|
||||
{
|
||||
if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
|
||||
{
|
||||
return this->RequestInformation(request, inputVector,
|
||||
outputVector);
|
||||
// vtkDemandDrivenPipeline::REQUEST_INFORMATION()定义请求以确保输出信息是最新的
|
||||
if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) {
|
||||
return this->RequestInformation(request, inputVector, outputVector);
|
||||
}
|
||||
if (request->Has(
|
||||
vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
|
||||
{
|
||||
return this->RequestUpdateExtent(request, inputVector,
|
||||
outputVector);
|
||||
// vtkDemandDrivenPipeline::REQUEST_DATA()定义了向上游传播更新范围的请求。
|
||||
if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) {
|
||||
return this->RequestUpdateExtent(request, inputVector, outputVector);
|
||||
}
|
||||
if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
|
||||
{
|
||||
// vtkDemandDrivenPipeline::REQUEST_DATA()定义请求以确保输出数据是最新的
|
||||
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) {
|
||||
return this->RequestData(request, inputVector, outputVector);
|
||||
}
|
||||
return this->Superclass::ProcessRequest(request, inputVector,
|
||||
outputVector);
|
||||
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector)
|
||||
{
|
||||
if (!this->FileName)
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @param[in] vtkInformationVector**包含输入管道信息。数组的每个元素代表一个输入端口。
|
||||
* 是一个vtkInformationVector,对应输入端口上连接的输入管道信息对象。
|
||||
* @param[in]
|
||||
* outputVector是一个vtkInformationVector,包含滤器的每个输出端口提供一个输出管道信息对象。
|
||||
* @note
|
||||
* 用于输入和输出的每个管道信息对象都包含一个vtkDataObject,其存储键为vtkDataObobject::DATA_OBJECT()。
|
||||
* @since 2.5.0
|
||||
*/
|
||||
int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**,
|
||||
vtkInformationVector* outputVector)
|
||||
{
|
||||
if(!this->FileName) {
|
||||
vtkErrorMacro("A FileName must be specified.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
_blockList.clear();
|
||||
_blockNames.clear();
|
||||
|
||||
|
@ -97,12 +109,13 @@ int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vt
|
|||
vtkSmartPointer<vtkAppendFilter> appFilter = vtkSmartPointer<vtkAppendFilter>::New();
|
||||
appFilter->MergePointsOn();
|
||||
|
||||
if (mBlock == nullptr) return 0;
|
||||
if(mBlock == nullptr)
|
||||
return 0;
|
||||
getBlocks(mBlock);
|
||||
|
||||
for (int i =0;i< _blockList.size(); ++i)
|
||||
{
|
||||
if(!_visibleStates[i]) continue;
|
||||
for(int i = 0; i < _blockList.size(); ++i) {
|
||||
if(!_visibleStates[i])
|
||||
continue;
|
||||
auto dataset = _blockList.at(i);
|
||||
|
||||
fillPointArray(dataset);
|
||||
|
@ -110,7 +123,6 @@ int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vt
|
|||
appFilter->AddInputData(dataset);
|
||||
}
|
||||
|
||||
|
||||
appFilter->Update();
|
||||
|
||||
vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
|
||||
|
@ -118,9 +130,9 @@ int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vt
|
|||
output->GetPointData()->PassData(appFilter->GetOutput()->GetPointData());
|
||||
output->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());
|
||||
|
||||
for (int i =1;i<=_blockList.size();i++)
|
||||
{
|
||||
if (i > MAXBLOCKNUM) break;
|
||||
for(int i = 1; i <= _blockList.size(); i++) {
|
||||
if(i > MAXBLOCKNUM)
|
||||
break;
|
||||
auto data = _blockList.at(i - 1);
|
||||
vtkUnstructuredGrid* outData = vtkUnstructuredGrid::GetData(outputVector, i);
|
||||
vtkSmartPointer<vtkAppendFilter> appFilter = vtkSmartPointer<vtkAppendFilter>::New();
|
||||
|
@ -128,7 +140,8 @@ int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vt
|
|||
appFilter->Update();
|
||||
outData->CopyStructure(appFilter->GetOutput());
|
||||
outData->GetPointData()->PassData(appFilter->GetOutput()->GetPointData());
|
||||
outData->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());;
|
||||
outData->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());
|
||||
;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -137,40 +150,34 @@ bool CGNSReaderAlgorithm::useVTKCGNSReader()
|
|||
{
|
||||
int currentFileIndex = 0;
|
||||
int OK = cg_open(FileName, CG_MODE_READ, ¤tFileIndex);
|
||||
if (CG_OK != OK) return false;
|
||||
if(CG_OK != OK)
|
||||
return false;
|
||||
bool useVTK = false;
|
||||
int nBase = 0;
|
||||
OK = cg_nbases(currentFileIndex, &nBase);
|
||||
|
||||
for (int ibase = 1; ibase <= nBase; ++ibase)
|
||||
{
|
||||
for(int ibase = 1; ibase <= nBase; ++ibase) {
|
||||
int zone_node_number = 0;
|
||||
cg_nzones(currentFileIndex, ibase, &zone_node_number);
|
||||
|
||||
for (int izone = 1; izone <= zone_node_number; ++izone)
|
||||
{
|
||||
for(int izone = 1; izone <= zone_node_number; ++izone) {
|
||||
CGNS_ENUMT(ZoneType_t) zonetype;
|
||||
cg_zone_type(currentFileIndex, ibase, izone, &zonetype);
|
||||
if (zonetype == CGNS_ENUMV(Unstructured))
|
||||
{
|
||||
if(zonetype == CGNS_ENUMV(Unstructured)) {
|
||||
int nSection{ 0 };
|
||||
cg_nsections(currentFileIndex, ibase, izone, &nSection);
|
||||
for (int iSec = 1;iSec <= nSection; ++iSec)
|
||||
{
|
||||
for(int iSec = 1; iSec <= nSection; ++iSec) {
|
||||
char sectionName[33] = { 0 };
|
||||
cgsize_t istart = 0, iend = 0;
|
||||
int nbndry = 0, iparent_flag = 0;
|
||||
CGNS_ENUMT(ElementType_t) itype;
|
||||
OK = cg_section_read(currentFileIndex, ibase, izone, iSec, sectionName, &itype
|
||||
, &istart, &iend, &nbndry, &iparent_flag);
|
||||
if (itype >= 20)
|
||||
{
|
||||
OK = cg_section_read(currentFileIndex, ibase, izone, iSec, sectionName, &itype,
|
||||
&istart, &iend, &nbndry, &iparent_flag);
|
||||
if(itype >= 20) {
|
||||
cg_close(currentFileIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +192,6 @@ CGNSReaderAlgorithm* CGNSReaderAlgorithm::New()
|
|||
return reader;
|
||||
}
|
||||
|
||||
|
||||
void CGNSReaderAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
|
||||
{
|
||||
this->Superclass::PrintSelf(os, indent);
|
||||
|
@ -194,7 +200,8 @@ void CGNSReaderAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
|
|||
|
||||
void CGNSReaderAlgorithm::setVisible(int blockIndex, bool vis)
|
||||
{
|
||||
if (blockIndex >= MAXBLOCKNUM) return;
|
||||
if(blockIndex >= MAXBLOCKNUM)
|
||||
return;
|
||||
_visibleStates[blockIndex] = vis;
|
||||
// this->Modified();
|
||||
}
|
||||
|
@ -214,9 +221,17 @@ QStringList CGNSReaderAlgorithm::getBlockBCTypes()
|
|||
return _bcTypes;
|
||||
}
|
||||
|
||||
int CGNSReaderAlgorithm::FillOutputPortInformation(int port, vtkInformation* info)
|
||||
int CGNSReaderAlgorithm::FillInputPortInformation(int, vtkInformation*)
|
||||
{
|
||||
// 该算法没有输入端口
|
||||
// info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);
|
||||
// info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
|
||||
// info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CGNSReaderAlgorithm::FillOutputPortInformation(int, vtkInformation* info)
|
||||
{
|
||||
Q_UNUSED(port)
|
||||
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid");
|
||||
return 1;
|
||||
}
|
||||
|
@ -225,21 +240,18 @@ void CGNSReaderAlgorithm::getBlocks(vtkDataObject* blockData,const char* Name)
|
|||
{
|
||||
auto block = vtkMultiBlockDataSet::SafeDownCast(blockData);
|
||||
|
||||
if (block == nullptr)
|
||||
{
|
||||
if(block == nullptr) {
|
||||
auto dataset = vtkDataSet::SafeDownCast(blockData);
|
||||
if (dataset == nullptr) return;
|
||||
if(dataset == nullptr)
|
||||
return;
|
||||
dataset->Modified();
|
||||
QString totalName = QString::fromLocal8Bit(Name);
|
||||
QStringList NameBC = totalName.split("!|||!");
|
||||
|
||||
if (NameBC.size() == 2)
|
||||
{
|
||||
if(NameBC.size() == 2) {
|
||||
_blockNames.append(NameBC.at(0));
|
||||
_bcTypes.append(NameBC.at(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_blockNames.append(totalName);
|
||||
_bcTypes.append("None");
|
||||
}
|
||||
|
@ -253,8 +265,7 @@ void CGNSReaderAlgorithm::getBlocks(vtkDataObject* blockData,const char* Name)
|
|||
block->Modified();
|
||||
const int nBlock = block->GetNumberOfBlocks();
|
||||
|
||||
for (int i = 0; i < nBlock; i++)
|
||||
{
|
||||
for(int i = 0; i < nBlock; i++) {
|
||||
vtkDataObject* obj = block->GetBlock(i);
|
||||
const char* currentName = block->GetMetaData(i)->Get(vtkCompositeDataSet::NAME());
|
||||
getBlocks(obj, currentName);
|
||||
|
@ -263,44 +274,50 @@ void CGNSReaderAlgorithm::getBlocks(vtkDataObject* blockData,const char* Name)
|
|||
|
||||
void CGNSReaderAlgorithm::getPointArray(vtkDataSet* dataset)
|
||||
{
|
||||
if (dataset == nullptr) return;
|
||||
if(dataset == nullptr)
|
||||
return;
|
||||
|
||||
auto pointData = dataset->GetPointData();
|
||||
if (pointData == nullptr) return;
|
||||
if(pointData == nullptr)
|
||||
return;
|
||||
|
||||
const int nPointArray = pointData->GetNumberOfArrays();
|
||||
for (int i = 0; i < nPointArray; i++)
|
||||
{
|
||||
for(int i = 0; i < nPointArray; i++) {
|
||||
const char* aName = pointData->GetArrayName(i);
|
||||
auto dataArray = pointData->GetArray(aName);
|
||||
if (dataArray == nullptr) return; //continue;
|
||||
if(dataArray == nullptr)
|
||||
return; // continue;
|
||||
int aNum[2]{ 0 };
|
||||
aNum[0] = dataArray->GetNumberOfComponents();
|
||||
aNum[1] = dataArray->GetNumberOfTuples();
|
||||
|
||||
if (_pointDataArray.contains(aName)) continue;
|
||||
if(_pointDataArray.contains(aName))
|
||||
continue;
|
||||
_pointDataArray.insert(aName, aNum);
|
||||
}
|
||||
}
|
||||
|
||||
void CGNSReaderAlgorithm::getCellArray(vtkDataSet* dataset)
|
||||
{
|
||||
if (dataset == nullptr) return;
|
||||
if(dataset == nullptr)
|
||||
return;
|
||||
|
||||
auto cellData = dataset->GetCellData();
|
||||
if (cellData == nullptr) return;
|
||||
if(cellData == nullptr)
|
||||
return;
|
||||
|
||||
const int nCellArray = cellData->GetNumberOfArrays();
|
||||
for (int i = 0; i < nCellArray; i++)
|
||||
{
|
||||
for(int i = 0; i < nCellArray; i++) {
|
||||
const char* aName = cellData->GetArrayName(i);
|
||||
auto dataArray = cellData->GetArray(aName);
|
||||
if (dataArray == nullptr) return; //continue;
|
||||
if(dataArray == nullptr)
|
||||
return; // continue;
|
||||
int aNum[2]{ 0 };
|
||||
aNum[0] = dataArray->GetNumberOfComponents();
|
||||
aNum[1] = dataArray->GetNumberOfTuples();
|
||||
|
||||
if (_cellDataArray.contains(aName)) continue;
|
||||
if(_cellDataArray.contains(aName))
|
||||
continue;
|
||||
_cellDataArray.insert(aName, aNum);
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +346,6 @@ void CGNSReaderAlgorithm::fillPointArray(vtkDataSet* dataset)
|
|||
//
|
||||
// pointData->AddArray(dataArray);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
void CGNSReaderAlgorithm::fillCellArray(vtkDataSet* dataset)
|
||||
|
|
|
@ -3,24 +3,34 @@
|
|||
|
||||
#include "PostAlgorithmAPI.h"
|
||||
#include "PostRenderData/Macros.hxx"
|
||||
#include <vtkUnstructuredGridAlgorithm.h>
|
||||
#include <QString>
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <vtkUnstructuredGridAlgorithm.h>
|
||||
|
||||
ForwardDeclar(vtkInformation)
|
||||
ForwardDeclar(vtkDataSet)
|
||||
ForwardDeclar(vtkDataObject)
|
||||
ForwardDeclar(vtkDataArray)
|
||||
ForwardDeclar(vtkInformation);
|
||||
ForwardDeclar(vtkDataSet);
|
||||
ForwardDeclar(vtkDataObject);
|
||||
ForwardDeclar(vtkDataArray);
|
||||
|
||||
class POSTALGORITHMAPI CGNSReaderAlgorithm :public vtkUnstructuredGridAlgorithm
|
||||
{
|
||||
class POSTALGORITHMAPI CGNSReaderAlgorithm : public vtkUnstructuredGridAlgorithm {
|
||||
public:
|
||||
static CGNSReaderAlgorithm* New();
|
||||
vtkTypeMacro(CGNSReaderAlgorithm, vtkUnstructuredGridAlgorithm);
|
||||
void PrintSelf(ostream& os, vtkIndent indent);
|
||||
|
||||
/**
|
||||
* @brief 打印对象当前对象(包括超类)的信息
|
||||
*
|
||||
* @param[in] os 输出流
|
||||
* @param[in] indent 缩进
|
||||
*/
|
||||
void PrintSelf(ostream& os, vtkIndent indent) override;
|
||||
/** @name Set/Get宏
|
||||
* 相当于setter/getter,同vtkSetMacro(FileName, char*)/vtkGetMacro(FileName, char*)
|
||||
* @{
|
||||
*/
|
||||
vtkSetStringMacro(FileName);
|
||||
vtkGetStringMacro(FileName);
|
||||
/** @} */
|
||||
|
||||
void setVisible(int blockIndex, bool vis);
|
||||
|
||||
|
@ -30,7 +40,16 @@ public:
|
|||
|
||||
QStringList getBlockBCTypes();
|
||||
|
||||
int FillOutputPortInformation(int port, vtkInformation* info);
|
||||
/**
|
||||
* @brief 填充该算法的输入端口信息对象
|
||||
* @param[in] port 端口序号,从0开始
|
||||
*/
|
||||
int FillInputPortInformation(int port, vtkInformation* info) override;
|
||||
/**
|
||||
* @brief 填充该算法的输入端口信息对象
|
||||
* @param[in] port 端口序号,从0开始
|
||||
*/
|
||||
int FillOutputPortInformation(int port, vtkInformation* info) override;
|
||||
|
||||
/**
|
||||
* @brief 获取块数据
|
||||
|
@ -62,8 +81,22 @@ protected:
|
|||
CGNSReaderAlgorithm();
|
||||
~CGNSReaderAlgorithm();
|
||||
|
||||
int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector);
|
||||
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*);
|
||||
/**
|
||||
* @brief 当VTK管道更新时,过滤器可能会收到请求,要求它处理一些信息和/或数据。
|
||||
* 这些请求首先被发送到过滤器的执行对象,然后由该对象发送请求
|
||||
* 通过调用虚拟方法vtkAlgorithm::ProcessRequest()来实现算法。
|
||||
* 该方法给出了请求信息对象和一组输入输出管道信息要操作的对象。它负责尝试完成请求并报告成功或失败。
|
||||
* 每个算法对象必须按原样提供ProcessRequest()的实现算法执行的入口点.
|
||||
*
|
||||
* \param request
|
||||
* \param inputVector
|
||||
* \param outputVector
|
||||
* \return
|
||||
*/
|
||||
int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
|
||||
vtkInformationVector* outputVector) override;
|
||||
|
||||
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
|
||||
|
||||
bool useVTKCGNSReader();
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ add_library(PostAlgorithm
|
|||
target_compile_definitions(PostAlgorithm PRIVATE "POSTALGORITHM_API")
|
||||
#target_compile_definitions(PostAlgorithm PRIVATE "H5_BUILT_AS_DYNAMIC_LIB")
|
||||
|
||||
list(APPEND _depend_library Common)
|
||||
|
||||
list(APPEND _runtimes_libraries
|
||||
FASTCAE::CGNS FASTCAE::HDF5 FASTCAE::HDF5CPP FASTCAE::TECIO Qt5::Core VTK::CommonColor VTK::CommonComputationalGeometry VTK::CommonCore VTK::CommonDataModel VTK::CommonExecutionModel VTK::CommonMath VTK::CommonMisc VTK::CommonSystem VTK::CommonTransforms VTK::DICOMParser VTK::FiltersCore VTK::FiltersExtraction VTK::FiltersGeneral VTK::FiltersGeometry VTK::FiltersHybrid VTK::FiltersModeling VTK::FiltersParallel VTK::FiltersSources VTK::FiltersStatistics VTK::FiltersTexture VTK::IOCore VTK::IOGeometry VTK::IOImage VTK::IOLegacy VTK::IOParallel VTK::IOXML VTK::IOXMLParser VTK::ImagingCore VTK::ImagingFourier VTK::ImagingSources VTK::ParallelCore VTK::ParallelDIY VTK::RenderingCore VTK::doubleconversion VTK::expat VTK::jpeg VTK::jsoncpp VTK::lz4 VTK::lzma VTK::metaio VTK::png VTK::pugixml VTK::sys VTK::tiff VTK::zlib
|
||||
)
|
||||
|
@ -37,8 +39,14 @@ list(APPEND _runtimes_libraries
|
|||
#-----------------------------------------------------------------------------
|
||||
target_link_libraries(PostAlgorithm PRIVATE
|
||||
${_runtimes_libraries}
|
||||
${_depend_library}
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# 添加依赖关系
|
||||
#-----------------------------------------------------------------------------
|
||||
add_dependencies(PostAlgorithm ${_depend_library})
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# 添加运行时依赖关系
|
||||
#-----------------------------------------------------------------------------
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
#include "FCGNSGridReaderBase.h"
|
||||
#include <cgnstypes.h>
|
||||
|
||||
#include "Common/DebugLogger.h"
|
||||
|
||||
#include <cgns_io.h>
|
||||
#include <cgnslib.h>
|
||||
#include <QDebug>
|
||||
#include <vtkDataSet.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <cgnstypes.h>
|
||||
#include <vtkCellData.h>
|
||||
#include <vtkDataSet.h>
|
||||
#include <vtkDoubleArray.h>
|
||||
#include <vtkFloatArray.h>
|
||||
#include <vtkStructuredGrid.h>
|
||||
#include <vtkNew.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <vtkStructuredGrid.h>
|
||||
|
||||
FCGNSGridReaderBase::FCGNSGridReaderBase(vtkMultiBlockDataSet* root)
|
||||
: _root(root)
|
||||
|
@ -23,72 +25,78 @@ void FCGNSGridReaderBase::setInfo(int fileIndex, int baseIndex, int zoneIndex)
|
|||
_zoneIndex = zoneIndex;
|
||||
}
|
||||
|
||||
void FCGNSGridReaderBase::readCoordinate(int dim, int count, cgsize_t rangeMin[3], cgsize_t rangeMax[3])
|
||||
void FCGNSGridReaderBase::readCoordinate(int dim, int count, cgsize_t rangeMin[3],
|
||||
cgsize_t rangeMax[3])
|
||||
{
|
||||
_vertexList.clear();
|
||||
_vertexList.fill(VPoint(), count);
|
||||
|
||||
// 坐标名称(CoordinateX,CoordinateY,CoordinateZ,CoordinateR,CoordinateTheta,CoordinatePhi等)
|
||||
// 参考http://cgns.github.io/CGNS_docs_current/sids/dataname.html#dataname_grid
|
||||
char coordinate_name[33] = { 0 };
|
||||
CGNS_ENUMV(DataType_t)
|
||||
datatype;
|
||||
int OK = 0;
|
||||
for (int i = 1; i <= dim; ++i)
|
||||
{
|
||||
OK = cg_coord_info(_fileIndex, _baseIndex, _zoneIndex, i, &datatype, coordinate_name);
|
||||
if (CG_OK != OK)
|
||||
continue;
|
||||
// 坐标值的数据类型(RealSingle 或者 RealDouble)
|
||||
CGNS_ENUMV(DataType_t) datatype;
|
||||
int result = 0;
|
||||
for(int i = 1; i <= dim; ++i) {
|
||||
// 读取坐标信息,构建数据存储数组
|
||||
result = cg_coord_info(_fileIndex, _baseIndex, _zoneIndex, i, &datatype, coordinate_name);
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to get coordinate(index = %d) info\n", i);
|
||||
break;
|
||||
}
|
||||
void* xyz{ nullptr };
|
||||
if (datatype == CGNS_ENUMV(RealSingle))
|
||||
if(datatype == CGNS_ENUMV(RealSingle)) {
|
||||
xyz = new float[count];
|
||||
else if (datatype == CGNS_ENUMV(RealDouble))
|
||||
} else if(datatype == CGNS_ENUMV(RealDouble)) {
|
||||
xyz = new double[count];
|
||||
if (xyz == nullptr)
|
||||
continue;
|
||||
} else {
|
||||
DebugError("Invalid data type for coordinate: %s\n", coordinate_name);
|
||||
break;
|
||||
}
|
||||
|
||||
OK = cg_coord_read(_fileIndex, _baseIndex, _zoneIndex, coordinate_name, datatype, rangeMin, rangeMax, xyz);
|
||||
if (OK != 0)
|
||||
continue;
|
||||
// 读取坐标数据
|
||||
// 官方文档(datatype不需要区分RealSingle或者RealDouble,可以自动处理,但是由于数据量一般比较大,考虑
|
||||
// 节约内存,也可以做区分):The function cg_coord_read returns the coordinate array
|
||||
// coord_array, for the range prescribed by range_min and range_max. The array is returned
|
||||
// to the application in the data type requested in mem_datatype. This data type does not
|
||||
// need to be the same as the one in which the coordinates are stored in the file. A
|
||||
// coordinate array stored as double precision in the CGNS file can be returned to the
|
||||
// application as single precision, or vice versa. The functions cg_coord_general_read and
|
||||
// cg_coord_general_write allow for type conversion when both reading from and writing to
|
||||
// the file.
|
||||
result = cg_coord_read(_fileIndex, _baseIndex, _zoneIndex, coordinate_name, datatype,
|
||||
rangeMin, rangeMax, xyz);
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to read grid coordinate: %s\n", coordinate_name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp(coordinate_name, "CoordinateX"))
|
||||
{
|
||||
if (datatype == CGNS_ENUMV(RealDouble))
|
||||
{
|
||||
if(strcmp(coordinate_name, "CoordinateX") == 0) {
|
||||
if(datatype == CGNS_ENUMV(RealDouble)) {
|
||||
auto* c = static_cast<double*>(xyz);
|
||||
for(int ipt = 0; ipt < count; ++ipt)
|
||||
_vertexList[ipt].x = c[ipt];
|
||||
}
|
||||
else if (datatype == CGNS_ENUMV(RealSingle))
|
||||
{
|
||||
} else if(datatype == CGNS_ENUMV(RealSingle)) {
|
||||
auto* c = static_cast<float*>(xyz);
|
||||
for(int ipt = 0; ipt < count; ++ipt)
|
||||
_vertexList[ipt].x = c[ipt];
|
||||
}
|
||||
}
|
||||
else if (!strcmp(coordinate_name, "CoordinateY"))
|
||||
{
|
||||
if (datatype == CGNS_ENUMV(RealDouble))
|
||||
{
|
||||
} else if(strcmp(coordinate_name, "CoordinateY") == 0) {
|
||||
if(datatype == CGNS_ENUMV(RealDouble)) {
|
||||
auto* c = static_cast<double*>(xyz);
|
||||
for(int ipt = 0; ipt < count; ++ipt)
|
||||
_vertexList[ipt].y = c[ipt];
|
||||
}
|
||||
else if (datatype == CGNS_ENUMV(RealSingle))
|
||||
{
|
||||
} else if(datatype == CGNS_ENUMV(RealSingle)) {
|
||||
auto* c = static_cast<float*>(xyz);
|
||||
for(int ipt = 0; ipt < count; ++ipt)
|
||||
_vertexList[ipt].y = c[ipt];
|
||||
}
|
||||
}
|
||||
else if (!strcmp(coordinate_name, "CoordinateZ"))
|
||||
{
|
||||
if (datatype == CGNS_ENUMV(RealDouble))
|
||||
{
|
||||
} else if(dim == 3 && (strcmp(coordinate_name, "CoordinateZ") == 0)) {
|
||||
if(datatype == CGNS_ENUMV(RealDouble)) {
|
||||
auto* c = static_cast<double*>(xyz);
|
||||
for(int ipt = 0; ipt < count; ++ipt)
|
||||
_vertexList[ipt].z = c[ipt];
|
||||
}
|
||||
else if (datatype == CGNS_ENUMV(RealSingle))
|
||||
{
|
||||
} else if(datatype == CGNS_ENUMV(RealSingle)) {
|
||||
auto* c = static_cast<float*>(xyz);
|
||||
for(int ipt = 0; ipt < count; ++ipt)
|
||||
_vertexList[ipt].z = c[ipt];
|
||||
|
@ -97,30 +105,36 @@ void FCGNSGridReaderBase::readCoordinate(int dim, int count, cgsize_t rangeMin[3
|
|||
}
|
||||
|
||||
if(datatype == CGNS_ENUMV(RealSingle))
|
||||
delete (float *)xyz;
|
||||
delete[](float*)xyz;
|
||||
else if(datatype == CGNS_ENUMV(RealDouble))
|
||||
delete (double *)xyz;
|
||||
delete[](double*)xyz;
|
||||
}
|
||||
}
|
||||
|
||||
void FCGNSGridReaderBase::readFlowSolution(vtkDataSet* grid)
|
||||
{
|
||||
int OK = 0;
|
||||
int result = 0;
|
||||
int nsol = 0;
|
||||
OK = cg_nsols(_fileIndex, _baseIndex, _zoneIndex, &nsol);
|
||||
if (CG_OK != OK)
|
||||
result = cg_nsols(_fileIndex, _baseIndex, _zoneIndex, &nsol);
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to read number of flow solution\n");
|
||||
return;
|
||||
} else {
|
||||
DebugInfo("Number of flow solution is %d\n", nsol);
|
||||
}
|
||||
|
||||
_dataSet = grid;
|
||||
|
||||
for (int isol = 1; isol <= nsol; ++isol)
|
||||
{
|
||||
CGNS_ENUMT(GridLocation_t)
|
||||
varloc;
|
||||
for(int isol = 1; isol <= nsol; ++isol) {
|
||||
CGNS_ENUMT(GridLocation_t) varloc;
|
||||
char sol_name[33] = { 0 };
|
||||
OK = cg_sol_info(_fileIndex, _baseIndex, _zoneIndex, isol, sol_name, &varloc);
|
||||
if (CG_OK != OK)
|
||||
continue;
|
||||
qDebug() << sol_name << varloc;
|
||||
result = cg_sol_info(_fileIndex, _baseIndex, _zoneIndex, isol, sol_name, &varloc);
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to read info of flow solution\n");
|
||||
return;
|
||||
} else {
|
||||
DebugInfo("Flow solution: %s, var location: %d\n", sol_name, varloc);
|
||||
}
|
||||
|
||||
QList<QString> varNames;
|
||||
QList<void*> values;
|
||||
|
@ -137,32 +151,39 @@ void FCGNSGridReaderBase::readFlowSolution(vtkDataSet *grid)
|
|||
}
|
||||
|
||||
void FCGNSGridReaderBase::readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc,
|
||||
QList<QString> &varNames, QList<int> &valueType, QList<void *> &values)
|
||||
QList<QString>& varNames, QList<int>& valueType,
|
||||
QList<void*>& values)
|
||||
{
|
||||
qDebug() << loc;
|
||||
if(loc != CGNS_ENUMT(Vertex) && loc != CGNS_ENUMT(CellCenter))
|
||||
return;
|
||||
int OK = 0;
|
||||
int var_num = 0;
|
||||
OK = cg_nfields(_fileIndex, _baseIndex, _zoneIndex, solIndex, &var_num);
|
||||
if (CG_OK != OK)
|
||||
return;
|
||||
int valNum = 0;
|
||||
for (int iFiled = 1; iFiled <= var_num; ++iFiled)
|
||||
{
|
||||
CGNS_ENUMT(DataType_t)
|
||||
datatype;
|
||||
char var_name[33] = {0};
|
||||
OK = cg_field_info(_fileIndex, _baseIndex, _zoneIndex, solIndex, iFiled, &datatype, var_name);
|
||||
DebugError("Unsupported grid location: %d\n", loc);
|
||||
return;
|
||||
}
|
||||
int OK = 0;
|
||||
int nFields = 0;
|
||||
OK = cg_nfields(_fileIndex, _baseIndex, _zoneIndex, solIndex, &nFields);
|
||||
if(CG_OK != OK)
|
||||
continue;
|
||||
qDebug() << var_name << datatype;
|
||||
{
|
||||
DebugError("Failed to read number of fields\n");
|
||||
return;
|
||||
}
|
||||
int valNum = 0;
|
||||
for(int iField = 1; iField <= nFields; ++iField) {
|
||||
CGNS_ENUMT(DataType_t) datatype;
|
||||
char fieldName[33] = { 0 };
|
||||
OK = cg_field_info(_fileIndex, _baseIndex, _zoneIndex, solIndex, iField, &datatype,
|
||||
fieldName);
|
||||
if(CG_OK != OK) {
|
||||
DebugError("Failed to read info of field[%d]\n", iField);
|
||||
return;
|
||||
} else
|
||||
{
|
||||
DebugInfo("Begin to parse field: %s\n", fieldName);
|
||||
}
|
||||
|
||||
cgsize_t min[3] = { 1, 1, 1 }, max[3] = { 0 };
|
||||
if (!_isStructedGrid)
|
||||
{
|
||||
switch (loc)
|
||||
{
|
||||
if(!_isStructedGrid) {
|
||||
switch(loc) {
|
||||
case CGNS_ENUMT(Vertex):
|
||||
valNum = max[0] = max[1] = max[2] = _dataSet->GetNumberOfPoints();
|
||||
break;
|
||||
|
@ -172,14 +193,11 @@ void FCGNSGridReaderBase::readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
auto sG = vtkStructuredGrid::SafeDownCast(_dataSet);
|
||||
int dims[3];
|
||||
sG->GetDimensions(dims);
|
||||
switch (loc)
|
||||
{
|
||||
switch(loc) {
|
||||
case CGNS_ENUMT(Vertex):
|
||||
max[0] = dims[0];
|
||||
max[1] = dims[1];
|
||||
|
@ -204,36 +222,38 @@ void FCGNSGridReaderBase::readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t)
|
|||
else if(datatype == CGNS_ENUMT(RealDouble))
|
||||
valuesArr = new double[valNum];
|
||||
|
||||
OK = cg_field_read(_fileIndex, _baseIndex, _zoneIndex, solIndex, var_name, datatype, min, max, valuesArr);
|
||||
if (CG_OK != OK)
|
||||
continue;
|
||||
OK = cg_field_read(_fileIndex, _baseIndex, _zoneIndex, solIndex, fieldName, datatype, min,
|
||||
max, valuesArr);
|
||||
if(CG_OK != OK) {
|
||||
DebugError("Failed to read flow solution for %s\n", fieldName);
|
||||
return;
|
||||
}
|
||||
|
||||
varNames.append(var_name);
|
||||
values.append(valuesArr);
|
||||
varNames.append(fieldName);
|
||||
valueType.append(datatype);
|
||||
values.append(valuesArr);
|
||||
}
|
||||
}
|
||||
|
||||
void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
|
||||
QList<QString> varNames, QList<int> vType, QList<void *> valueList)
|
||||
void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc, QList<QString> varNames,
|
||||
QList<int> vType, QList<void*> valueList)
|
||||
{
|
||||
QHash<QString, QHash<QString, QString>> vectorName;
|
||||
QStringList scalarName;
|
||||
for (QString varName : varNames)
|
||||
{
|
||||
for(QString varName : varNames) {
|
||||
QString component, vecName;
|
||||
bool isV = isVectorComponent(varName, vecName, component);
|
||||
if (!isV)
|
||||
if(isV) {
|
||||
vectorName[vecName].insert(component.toLower(), varName);
|
||||
} else
|
||||
{
|
||||
scalarName.append(varName);
|
||||
continue;
|
||||
}
|
||||
vectorName[vecName].insert(component.toLower(), varName);
|
||||
|
||||
}
|
||||
QStringList vecKeys = vectorName.keys();
|
||||
QStringList unVkeys;
|
||||
for (QString vecKey : vecKeys)
|
||||
{
|
||||
for(QString vecKey : vecKeys) {
|
||||
QHash<QString, QString> vvs = vectorName.value(vecKey);
|
||||
if(vvs.size() == _dim)
|
||||
continue;
|
||||
|
@ -243,12 +263,10 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
|
|||
for(QString uk : unVkeys)
|
||||
vectorName.remove(uk);
|
||||
|
||||
if (CGNS_ENUMT(Vertex) == loc)
|
||||
{
|
||||
if(CGNS_ENUMT(Vertex) == loc) {
|
||||
int nc = _dataSet->GetNumberOfPoints();
|
||||
auto pointArray = _dataSet->GetPointData();
|
||||
for (QString sca : scalarName)
|
||||
{
|
||||
auto* pointArray = _dataSet->GetPointData();
|
||||
for(QString sca : scalarName) {
|
||||
int index = varNames.indexOf(sca);
|
||||
int type = vType.at(index);
|
||||
void* v = valueList.at(index);
|
||||
|
@ -256,8 +274,7 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
|
|||
pointArray->AddArray(array);
|
||||
}
|
||||
|
||||
for (QString vec : vectorName.keys())
|
||||
{
|
||||
for(QString vec : vectorName.keys()) {
|
||||
QHash<QString, QString> comps = vectorName.value(vec);
|
||||
QString comp = comps.value("x");
|
||||
int index = varNames.indexOf(comp);
|
||||
|
@ -273,8 +290,7 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
|
|||
index = varNames.indexOf(comp);
|
||||
void* z = nullptr;
|
||||
int ztype = 0;
|
||||
if (index >= 0)
|
||||
{
|
||||
if(index >= 0) {
|
||||
z = valueList.at(index);
|
||||
ztype = vType.at(index);
|
||||
}
|
||||
|
@ -282,13 +298,10 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
|
|||
auto array = generateVectorArray(vec, nc, xtype, x, ytype, y, ztype, z);
|
||||
pointArray->AddArray(array);
|
||||
}
|
||||
}
|
||||
else if (CGNS_ENUMT(CellCenter) == loc)
|
||||
{
|
||||
} else if(CGNS_ENUMT(CellCenter) == loc) {
|
||||
int nc = _dataSet->GetNumberOfCells();
|
||||
auto cellArray = _dataSet->GetCellData();
|
||||
for (QString sca : scalarName)
|
||||
{
|
||||
for(QString sca : scalarName) {
|
||||
int index = varNames.indexOf(sca);
|
||||
void* v = valueList.at(index);
|
||||
int type = vType.at(index);
|
||||
|
@ -296,8 +309,7 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
|
|||
cellArray->AddArray(array);
|
||||
}
|
||||
|
||||
for (QString vec : vectorName.keys())
|
||||
{
|
||||
for(QString vec : vectorName.keys()) {
|
||||
QHash<QString, QString> comps = vectorName.value(vec);
|
||||
QString comp = comps.value("x");
|
||||
int index = varNames.indexOf(comp);
|
||||
|
@ -313,8 +325,7 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
|
|||
index = varNames.indexOf(comp);
|
||||
void* z = nullptr;
|
||||
int ztype = 0;
|
||||
if (index >= 0)
|
||||
{
|
||||
if(index >= 0) {
|
||||
z = valueList.at(index);
|
||||
ztype = vType.at(index);
|
||||
}
|
||||
|
@ -330,8 +341,7 @@ bool FCGNSGridReaderBase::isVectorComponent(QString name, QString &vecName, QStr
|
|||
QRegExp pattern("\\s*x$|\\s*X$|\\s*y$|\\s*Y$|\\s*z$|\\s*Z$");
|
||||
bool is = false;
|
||||
is = name.contains(pattern);
|
||||
if (is)
|
||||
{
|
||||
if(is) {
|
||||
comp = name.right(1);
|
||||
vecName = name.remove(comp);
|
||||
if(vecName.isEmpty())
|
||||
|
@ -350,8 +360,7 @@ vtkDataArray *FCGNSGridReaderBase::generateScalarArray(QString varName, int num,
|
|||
{
|
||||
array = vtkFloatArray::New();
|
||||
valueFloat = static_cast<float*>(va);
|
||||
}
|
||||
else if (type == 4) // double
|
||||
} else if(type == 4) // double
|
||||
{
|
||||
array = vtkDoubleArray::New();
|
||||
valueDouble = static_cast<double*>(va);
|
||||
|
@ -359,10 +368,8 @@ vtkDataArray *FCGNSGridReaderBase::generateScalarArray(QString varName, int num,
|
|||
|
||||
double v = 0;
|
||||
array->SetName(varName.toLatin1().data());
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
for(int i = 0; i < num; ++i) {
|
||||
switch(type) {
|
||||
case 3:
|
||||
v = valueFloat[i];
|
||||
break;
|
||||
|
@ -377,12 +384,11 @@ vtkDataArray *FCGNSGridReaderBase::generateScalarArray(QString varName, int num,
|
|||
|
||||
double range[2];
|
||||
array->GetRange(range);
|
||||
qDebug() << varName << range[0] << range[1];
|
||||
return array;
|
||||
}
|
||||
|
||||
vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num,
|
||||
int xType, void *x, int yType, void *y, int zType, void *z)
|
||||
vtkDataArray* FCGNSGridReaderBase::generateVectorArray(QString varName, int num, int xType, void* x,
|
||||
int yType, void* y, int zType, void* z)
|
||||
{
|
||||
auto array = vtkDoubleArray::New();
|
||||
array->SetName(varName.toLatin1().data());
|
||||
|
@ -410,10 +416,8 @@ vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num,
|
|||
zDV = static_cast<double*>(z);
|
||||
|
||||
double vx = 0, vy = 0, vz = 0;
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
switch (xType)
|
||||
{
|
||||
for(int i = 0; i < num; ++i) {
|
||||
switch(xType) {
|
||||
case 3:
|
||||
vx = xFV[i];
|
||||
break;
|
||||
|
@ -424,8 +428,7 @@ vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num,
|
|||
break;
|
||||
}
|
||||
|
||||
switch (yType)
|
||||
{
|
||||
switch(yType) {
|
||||
case 3:
|
||||
vy = yFV[i];
|
||||
break;
|
||||
|
@ -436,8 +439,7 @@ vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num,
|
|||
break;
|
||||
}
|
||||
|
||||
switch (zType)
|
||||
{
|
||||
switch(zType) {
|
||||
case 3:
|
||||
vz = zFV[i];
|
||||
break;
|
||||
|
|
|
@ -1,58 +1,153 @@
|
|||
#ifndef _FCGNSGRIDREADER_H__
|
||||
#define _FCGNSGRIDREADER_H__
|
||||
|
||||
#include <QVector>
|
||||
#include <cgnstypes.h>
|
||||
#include <cgnslib.h>
|
||||
#include <cgnstypes.h>
|
||||
#include <QHash>
|
||||
#include <QVector>
|
||||
|
||||
class vtkMultiBlockDataSet;
|
||||
class vtkDataSet;
|
||||
class vtkDataArray;
|
||||
|
||||
struct VPoint
|
||||
{
|
||||
/**
|
||||
* @brief 用于存储点坐标的结构体
|
||||
* @since 2.5.0
|
||||
*/
|
||||
struct VPoint {
|
||||
double x{ 0 };
|
||||
double y{ 0 };
|
||||
double z{ 0 };
|
||||
};
|
||||
|
||||
class FCGNSGridReaderBase
|
||||
{
|
||||
class FCGNSGridReaderBase {
|
||||
public:
|
||||
/**
|
||||
* @brief 构造函数
|
||||
* @param[out] root 包含数据的vtkMultiBlockDataSet对象
|
||||
*/
|
||||
FCGNSGridReaderBase(vtkMultiBlockDataSet* root);
|
||||
virtual ~FCGNSGridReaderBase() = default;
|
||||
|
||||
/**
|
||||
* @brief 设置要读取zone的信息
|
||||
*
|
||||
* @param[in] fileIndex 文件索引
|
||||
* @param[in] baseIndex 单库base的索引
|
||||
* @param[in] zoneIndex 区域zone的索引
|
||||
*/
|
||||
void setInfo(int fileIndex, int baseIndex, int zoneIndex);
|
||||
|
||||
/**
|
||||
* @brief zone读取函数,由子类重写
|
||||
* @since 2.5.0
|
||||
*/
|
||||
virtual void read() = 0;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief 读取zone中的坐标信息
|
||||
* @param[in] dim 维数
|
||||
* @param[in] count 顶点数
|
||||
* @param[out] range_from 指定读取范围的最小索引,全部读取时为1
|
||||
* @param[out] range_to 指定读取范围的最大索引,全部读取时为顶点数
|
||||
* @since 2.5.0
|
||||
*/
|
||||
void readCoordinate(int dim, int count, cgsize_t range_from[3], cgsize_t range_to[3]);
|
||||
|
||||
/**
|
||||
* @brief 读取zone中的计算结果
|
||||
* @param[out] grid 要保存计算结果的vtkDataSet对象
|
||||
* @since 2.5.0
|
||||
*/
|
||||
void readFlowSolution(vtkDataSet* grid);
|
||||
|
||||
/**
|
||||
* @brief 读取场数据
|
||||
* @param[in] solIndex 计算结果索引
|
||||
* @param[in] loc 计算结果存储位置
|
||||
* @param[out] varNames 场变量名称数组
|
||||
* @param[out] valueType 场变量类型数组
|
||||
* @param[out] values 场变量数据数组
|
||||
* @since 2.5.0
|
||||
*/
|
||||
void readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc, QList<QString>& varNames,
|
||||
QList<int>& valueType, QList<void*>& values);
|
||||
|
||||
/**
|
||||
* @brief 添加场数据到vtk格式数据中
|
||||
* @param[in] loc 场变量位置
|
||||
* @param[in] varNames 场变量名称数组
|
||||
* @param[in] valueType 场变量类型数组
|
||||
* @param[in] values 场变量数据数组
|
||||
* @since 2.5.0
|
||||
*/
|
||||
void addValueToGrid(CGNS_ENUMT(GridLocation_t) loc, QList<QString> varNames,
|
||||
QList<int> valueType, QList<void*> values);
|
||||
|
||||
/**
|
||||
* @brief 判断场变量是否为矢量分量
|
||||
* @param[in] name 场变量名称
|
||||
* @param[out] vecName 场变量名称(不含分量x,y,z)
|
||||
* @param[out] comp 分量(x,y,z)
|
||||
* @note 该函数判断依据为变量名称的最后一个字母是否为x,y,z(不区分大小写)。
|
||||
* @since 2.5.0
|
||||
*/
|
||||
bool isVectorComponent(QString name, QString& vecName, QString& comp);
|
||||
|
||||
/**
|
||||
* @brief 生成标量场的vtkDataArray
|
||||
* @param[in] varName 场变量名称
|
||||
* @param[in] num 场变量值数组大小
|
||||
* @param[in] type 场变量数据类型
|
||||
* @param[in] va 场变量值数组
|
||||
* @since 2.5.0
|
||||
*/
|
||||
vtkDataArray* generateScalarArray(QString varName, int num, int type, void* va);
|
||||
|
||||
vtkDataArray* generateVectorArray(QString varName, int num,
|
||||
int xtype, void * x,int ytype, void* y, int ztype, void* z);
|
||||
/**
|
||||
* @brief 生成矢量场的vtkDataArray
|
||||
* @param[in] varName 场变量名称
|
||||
* @param[in] num 场变量值数组大小
|
||||
* @param[in] xtype 场变量数据x分量类型
|
||||
* @param[in] x 场变量值x分量数组
|
||||
* @param[in] ytype 场变量数据y分量类型
|
||||
* @param[in] y 场变量值y分量数组
|
||||
* @param[in] ztype 场变量数据z分量类型
|
||||
* @param[in] z 场变量值z分量数组
|
||||
* @since 2.5.0
|
||||
*/
|
||||
vtkDataArray* generateVectorArray(QString varName, int num, int xtype, void* x, int ytype,
|
||||
void* y, int ztype, void* z);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief 存储要返回的结果数据
|
||||
*/
|
||||
vtkMultiBlockDataSet* _root{};
|
||||
int _fileIndex{ -1 }, _baseIndex{ -1 }, _zoneIndex{ -1 };
|
||||
/**
|
||||
* @brief CGNS文件索引
|
||||
*/
|
||||
int _fileIndex{ -1 };
|
||||
/**
|
||||
* @brief base索引
|
||||
*/
|
||||
int _baseIndex{ -1 };
|
||||
/**
|
||||
* @brief zone索引
|
||||
*/
|
||||
int _zoneIndex{ -1 };
|
||||
/**
|
||||
* @brief 是否为结构化数据
|
||||
*/
|
||||
bool _isStructedGrid{ false };
|
||||
/**
|
||||
* @brief 数据维度
|
||||
*/
|
||||
int _dim{ 2 };
|
||||
vtkDataSet* _dataSet{};
|
||||
QString _zoneName;
|
||||
|
||||
/**
|
||||
* @brief 节点数组
|
||||
* @since 2.5.0
|
||||
*/
|
||||
QVector<VPoint> _vertexList{};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
#include "FCGNSReader.h"
|
||||
|
||||
#include "Common/DebugLogger.h"
|
||||
#include "FCGNSStructureZoneReader.h"
|
||||
#include "FCGNSUnStructureZoneReader.h"
|
||||
|
||||
#include <cgns_io.h>
|
||||
#include <cgnslib.h>
|
||||
#include <QFile>
|
||||
#include <vtkDemandDrivenPipeline.h>
|
||||
#include <vtkInformation.h>
|
||||
#include <vtkInformationVector.h>
|
||||
#include <vtkDemandDrivenPipeline.h>
|
||||
#include <vtkStreamingDemandDrivenPipeline.h>
|
||||
#include <vtkMultiBlockDataSet.h>
|
||||
#include <vtkSetGet.h>
|
||||
#include <QFile>
|
||||
#include <cgnslib.h>
|
||||
#include <cgns_io.h>
|
||||
#include "FCGNSUnStructureZoneReader.h"
|
||||
#include "FCGNSStructureZoneReader.h"
|
||||
#include <vtkStreamingDemandDrivenPipeline.h>
|
||||
|
||||
FCGNSReader* FCGNSReader::New()
|
||||
{
|
||||
|
@ -31,93 +34,90 @@ FCGNSReader::FCGNSReader()
|
|||
this->FileName = nullptr;
|
||||
}
|
||||
|
||||
FCGNSReader::~FCGNSReader()
|
||||
FCGNSReader::~FCGNSReader() {}
|
||||
|
||||
void FCGNSReader::readZone(int fileIndex, int baseIndex, int zoneIndex,
|
||||
vtkMultiBlockDataSet* output)
|
||||
{
|
||||
// 读取zonetype:Structured 或 Unstructured
|
||||
CGNS_ENUMT(ZoneType_t) zonetype;
|
||||
if(CG_OK != cg_zone_type(fileIndex, baseIndex, zoneIndex, &zonetype)){
|
||||
DebugError("Failed to read zone(index = %d) type\n", zoneIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
void FCGNSReader::readZone(int fileIndex, int baseIndex, int zoneIndex, vtkMultiBlockDataSet* output)
|
||||
{
|
||||
CGNS_ENUMT(ZoneType_t) zonetype;
|
||||
if (CG_OK != cg_zone_type(fileIndex, baseIndex, zoneIndex, &zonetype))
|
||||
return ;
|
||||
|
||||
if (zonetype == CGNS_ENUMV(Structured))
|
||||
{
|
||||
if(zonetype == CGNS_ENUMV(Structured)) {
|
||||
FCGNSStructeGridReader r(output);
|
||||
r.setInfo(fileIndex, baseIndex, zoneIndex);
|
||||
r.setReadBC(_readBC);
|
||||
r.read();
|
||||
}
|
||||
else if (zonetype == CGNS_ENUMV(Unstructured))
|
||||
{
|
||||
} else if(zonetype == CGNS_ENUMV(Unstructured)) {
|
||||
FCGNSUnStructeGridReader r(output);
|
||||
r.setInfo(fileIndex, baseIndex, zoneIndex);
|
||||
r.read();
|
||||
}
|
||||
}
|
||||
|
||||
int FCGNSReader::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
|
||||
int FCGNSReader::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
|
||||
vtkInformationVector* outputVector)
|
||||
{
|
||||
if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
|
||||
{
|
||||
return this->RequestInformation(request, inputVector,
|
||||
outputVector);
|
||||
if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) {
|
||||
return this->RequestInformation(request, inputVector, outputVector);
|
||||
}
|
||||
if (request->Has(
|
||||
vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
|
||||
{
|
||||
return this->RequestUpdateExtent(request, inputVector,
|
||||
outputVector);
|
||||
if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) {
|
||||
return this->RequestUpdateExtent(request, inputVector, outputVector);
|
||||
}
|
||||
if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
|
||||
{
|
||||
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) {
|
||||
return this->RequestData(request, inputVector, outputVector);
|
||||
}
|
||||
return this->Superclass::ProcessRequest(request, inputVector,
|
||||
outputVector);
|
||||
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
|
||||
}
|
||||
|
||||
int FCGNSReader::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector)
|
||||
int FCGNSReader::RequestData(vtkInformation*, vtkInformationVector**,
|
||||
vtkInformationVector* outputVector)
|
||||
{
|
||||
auto output = vtkMultiBlockDataSet::GetData(outputVector);
|
||||
|
||||
bool ok = canReadFile();
|
||||
if (!ok) return 0;
|
||||
if(!ok) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 打开文件
|
||||
int currentFileIndex = 0;
|
||||
if (cg_open(FileName, CG_MODE_READ, ¤tFileIndex))
|
||||
{
|
||||
if(CG_OK != cg_open(FileName, CG_MODE_READ, ¤tFileIndex)) {
|
||||
DebugError("Failed to open file %s\n", FileName);
|
||||
return 0;
|
||||
} else {
|
||||
DebugInfo("Success to open file %s\n", FileName);
|
||||
}
|
||||
|
||||
|
||||
// 获取CGNS数据库的单库(CGNSBase_t)的数量,一般为1
|
||||
int nBase = 0;
|
||||
if (cg_nbases(currentFileIndex, &nBase))
|
||||
{
|
||||
if(CG_OK != cg_nbases(currentFileIndex, &nBase)) {
|
||||
DebugError("Failed to get number of base\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int ibase = 1; ibase <= nBase; ++ibase)
|
||||
{
|
||||
// 遍历读取zone(base和zone节点的索引都是从1开始的)
|
||||
for(int ibase = 1; ibase <= nBase; ++ibase) {
|
||||
int zone_node_number = 0;
|
||||
if (cg_nzones(currentFileIndex, ibase, &zone_node_number))
|
||||
{
|
||||
if(CG_OK != cg_nzones(currentFileIndex, ibase, &zone_node_number)) {
|
||||
return false;
|
||||
}
|
||||
for (int izone = 1; izone <= zone_node_number; ++izone)
|
||||
{
|
||||
for(int izone = 1; izone <= zone_node_number; ++izone) {
|
||||
readZone(currentFileIndex, ibase, izone, output);
|
||||
}
|
||||
|
||||
}
|
||||
cgio_close_file(currentFileIndex);
|
||||
// 关闭文件
|
||||
cg_close(currentFileIndex);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool FCGNSReader::canReadFile()
|
||||
{
|
||||
int cgioFile;
|
||||
int ierr = 1;
|
||||
bool ierr = true;
|
||||
double rootNodeId;
|
||||
double childId;
|
||||
float FileVersion = 0.0;
|
||||
|
@ -126,100 +126,154 @@ bool FCGNSReader::canReadFile()
|
|||
char errmsg[CGIO_MAX_ERROR_LENGTH + 1];
|
||||
int ndim = 0;
|
||||
cgsize_t dimVals[12];
|
||||
int fileType = CG_FILE_NONE;
|
||||
int fileType = CGIO_FILE_NONE;
|
||||
char* fileTypeStr = new char[20];
|
||||
|
||||
if (cgio_open_file(FileName, CG_MODE_READ, CG_FILE_NONE, &cgioFile) != CG_OK)
|
||||
{
|
||||
// 检查文件文件名以确定它是否是有效的数据库
|
||||
auto result = cgio_check_file(FileName, &fileType);
|
||||
if(CGIO_ERR_NONE != result || CGIO_FILE_NONE == fileType) {
|
||||
DebugError("%s is a invalid database!\n", FileName);
|
||||
return false;
|
||||
} else {
|
||||
DebugInfo("Check database: %s?\tpass!\n", FileName);
|
||||
}
|
||||
|
||||
// 确定当前库是否支持fileType给出的数据库类型
|
||||
// 始终支持CGIO_FILE_ADF;如果库是用HDF5构建的,则支持CGIO_FILE_HDF5;在32位模式下构建时支持CGIO_FILE_ADF2。
|
||||
result = cgio_is_supported(fileType);
|
||||
switch(fileType) {
|
||||
case CGIO_FILE_ADF:
|
||||
strcpy(fileTypeStr, "CGIO_FILE_ADF");
|
||||
break;
|
||||
case CGIO_FILE_HDF5:
|
||||
strcpy(fileTypeStr, "CGIO_FILE_HDF5");
|
||||
break;
|
||||
case CGIO_FILE_ADF2:
|
||||
strcpy(fileTypeStr, "CGIO_FILE_ADF2");
|
||||
break;
|
||||
case CGIO_FILE_NONE:
|
||||
strcpy(fileTypeStr, "CGIO_FILE_NONE");
|
||||
break;
|
||||
default:
|
||||
fileTypeStr = "Unknown";
|
||||
break;
|
||||
}
|
||||
if(CGIO_ERR_FILE_TYPE == result) {
|
||||
DebugError("FileType: %s is not support!\n", fileTypeStr);
|
||||
return false;
|
||||
} else {
|
||||
DebugInfo("FileType: support by library?\tyes!\n");
|
||||
}
|
||||
|
||||
// 打开数据库,设置数据库标识cgioFile,用于后续操作
|
||||
if(cgio_open_file(FileName, CG_MODE_READ, fileType, &cgioFile) != CG_OK) {
|
||||
cgio_error_message(errmsg);
|
||||
vtkErrorMacro(<< "vtkCGNSReader::CanReadFile : " << errmsg);
|
||||
DebugError("Failed to open file %s, error: %s\n", FileName, errmsg);
|
||||
return 0;
|
||||
} else {
|
||||
DebugInfo("Success to open file %s, identifier = %d\n", FileName, cgioFile);
|
||||
}
|
||||
|
||||
cgio_get_root_id(cgioFile, &rootNodeId);
|
||||
cgio_get_file_type(cgioFile, &fileType);
|
||||
// 获取数据库中根节点的标识
|
||||
if(CG_OK != cgio_get_root_id(cgioFile, &rootNodeId)) {
|
||||
DebugError("Failed to get root node identifier of database(%d)\n", cgioFile);
|
||||
goto CloseDataBase;
|
||||
} else {
|
||||
DebugInfo("Success to get root node identifier of database(%d), identifier = %d\n",
|
||||
cgioFile, rootNodeId);
|
||||
}
|
||||
|
||||
if (cgio_get_node_id(cgioFile, rootNodeId, "CGNSLibraryVersion", &childId))
|
||||
{
|
||||
// 为什么还要获取一次fileType?
|
||||
// cgio_get_file_type(cgioFile, &fileType);
|
||||
|
||||
// 获取生成文件的CGNS动态库版本
|
||||
if(CG_OK != cgio_get_node_id(cgioFile, rootNodeId, "CGNSLibraryVersion", &childId)) {
|
||||
cgio_error_message(errmsg);
|
||||
vtkErrorMacro(<< "vtkCGNSReader::CanReadFile : " << errmsg);
|
||||
ierr = 0;
|
||||
goto CanReadError;
|
||||
DebugError("Failed to get CGNSLibraryVersion node, error: %s\n", errmsg);
|
||||
ierr = false;
|
||||
goto CloseDataBase;
|
||||
} else {
|
||||
DebugInfo("Success to get CGNSLibraryVersion node, identifier = %f\n", childId);
|
||||
}
|
||||
|
||||
if (cgio_get_data_type(cgioFile, childId, dataType))
|
||||
{
|
||||
vtkErrorMacro(<< "CGNS Version data type");
|
||||
ierr = 0;
|
||||
goto CanReadError;
|
||||
// 获取CGNSLibraryVersion节点的数据类型( "MT", "I4", "I8", "U4", "U8", "R4", "C1", "B1")
|
||||
// "MT" 不包含数据的空节点
|
||||
// "I4" 32位整数(4字节)
|
||||
// "I8" 64位整数(8字节)
|
||||
// "U4" 32位无符号整数(4字节)
|
||||
// "U8" 64位无符号整数(8字节)
|
||||
// "R4" 32位实数(4字节)
|
||||
// "R8" 64位实数(8字节)
|
||||
// "C1" 字符
|
||||
// "B1" 无符号字节
|
||||
if(CG_OK != cgio_get_data_type(cgioFile, childId, dataType)) {
|
||||
cgio_error_message(errmsg);
|
||||
DebugError("Failed to get CGNSLibraryVersion value type, error: %s\n", errmsg);
|
||||
ierr = false;
|
||||
goto CloseDataBase;
|
||||
} else {
|
||||
DebugInfo("Success to get CGNSLibraryVersion value type: %s\n", dataType);
|
||||
}
|
||||
|
||||
if (cgio_get_dimensions(cgioFile, childId, &ndim, dimVals))
|
||||
{
|
||||
vtkErrorMacro(<< "cgio_get_dimensions");
|
||||
ierr = 0;
|
||||
goto CanReadError;
|
||||
// 获取CGNSLibraryVersion节点的数据的维度
|
||||
if(CG_OK != cgio_get_dimensions(cgioFile, childId, &ndim, dimVals)) {
|
||||
cgio_error_message(errmsg);
|
||||
DebugError("Failed to get CGNSLibraryVersion value dimensions, error: %s\n", errmsg);
|
||||
ierr = false;
|
||||
goto CloseDataBase;
|
||||
} else {
|
||||
DebugInfo("Success to get CGNSLibraryVersion value dimensions, num of dimensions: %d\n",
|
||||
ndim);
|
||||
}
|
||||
|
||||
// check data type
|
||||
if (strcmp(dataType, "R4") != 0)
|
||||
{
|
||||
vtkErrorMacro(<< "Unexpected data type for CGNS-Library-Version=" << dataType);
|
||||
ierr = 0;
|
||||
goto CanReadError;
|
||||
// 检查CGNSLibraryVersion节点的数据类型(float,参考cg_version函数:http://cgns.github.io/CGNS_docs_current/midlevel/fileops.html)
|
||||
if(strcmp(dataType, "R4") != 0) {
|
||||
DebugError("Unexpected data type for CGNS library version: %s\n", dataType);
|
||||
ierr = false;
|
||||
goto CloseDataBase;
|
||||
}
|
||||
|
||||
// check data dim
|
||||
if ((ndim != 1) || (dimVals[0] != 1))
|
||||
{
|
||||
vtkDebugMacro(<< "Wrong data dimension for CGNS-Library-Version");
|
||||
ierr = 0;
|
||||
goto CanReadError;
|
||||
// 检查CGNSLibraryVersion节点的数据的维度
|
||||
if((ndim != 1) || (dimVals[0] != 1)) {
|
||||
DebugError("Invalid data dimension for CGNS library version\n");
|
||||
ierr = false;
|
||||
goto CloseDataBase;
|
||||
}
|
||||
|
||||
// read data
|
||||
if (cgio_read_all_data_type(cgioFile, childId, "R4", &FileVersion))
|
||||
{
|
||||
vtkErrorMacro(<< "read CGNS version number");
|
||||
ierr = 0;
|
||||
goto CanReadError;
|
||||
// 读取CGNSLibraryVersion节点的数据
|
||||
if(cgio_read_all_data_type(cgioFile, childId, "R4", &FileVersion)) {
|
||||
DebugError("An error occurred reading the CGNS library version\n");
|
||||
ierr = false;
|
||||
goto CloseDataBase;
|
||||
} else {
|
||||
DebugInfo("CGNS library version: %f\n", FileVersion);
|
||||
}
|
||||
|
||||
// Check that the library version is at least as recent as the one used
|
||||
// to create the file being read
|
||||
|
||||
// 检测生成CGNS文件的库版本号是否比当前版本FastCAE使用的CGNS库版本更新
|
||||
intFileVersion = static_cast<int>(FileVersion * 1000 + 0.5);
|
||||
|
||||
if (intFileVersion > CGNS_VERSION)
|
||||
{
|
||||
// This code allows reading version newer than the lib,
|
||||
// as long as the 1st digit of the versions are equal
|
||||
if ((intFileVersion / 1000) > (CGNS_VERSION / 1000))
|
||||
{
|
||||
vtkErrorMacro(<< "The file " << FileName
|
||||
<< " was written with a more recent version"
|
||||
"of the CGNS library. You must update your CGNS"
|
||||
"library before trying to read this file.");
|
||||
ierr = 0;
|
||||
if(intFileVersion > CGNS_VERSION) {
|
||||
// 主版本号一样的,可以读取
|
||||
if(floor(intFileVersion / 1000) > floor(CGNS_VERSION / 1000)) {
|
||||
DebugError("The file %s was written with a more newer version of the CGNS library\n",
|
||||
FileName);
|
||||
ierr = false;
|
||||
}
|
||||
// warn only if different in second digit
|
||||
if ((intFileVersion / 100) > (CGNS_VERSION / 100))
|
||||
{
|
||||
if((intFileVersion / 100) > (CGNS_VERSION / 100)) {
|
||||
vtkWarningMacro(<< "The file being read is more recent"
|
||||
"than the CGNS library used");
|
||||
}
|
||||
}
|
||||
if ((intFileVersion / 10) < 255)
|
||||
{
|
||||
if((intFileVersion / 10) < 255) {
|
||||
vtkWarningMacro(<< "The file being read was written with an old version"
|
||||
"of the CGNS library. Please update your file"
|
||||
"to a more recent version.");
|
||||
}
|
||||
vtkDebugMacro(<< "FileVersion=" << FileVersion << "\n");
|
||||
|
||||
CanReadError:
|
||||
CloseDataBase:
|
||||
cgio_close_file(cgioFile);
|
||||
return ierr ? true : false;
|
||||
|
||||
return ierr;
|
||||
}
|
||||
|
||||
void FCGNSReader::setReadBC(bool read)
|
||||
|
|
|
@ -3,21 +3,27 @@
|
|||
|
||||
#include <vtkMultiBlockDataSetAlgorithm.h>
|
||||
|
||||
class FCGNSReader : public vtkMultiBlockDataSetAlgorithm
|
||||
{
|
||||
class FCGNSReader : public vtkMultiBlockDataSetAlgorithm {
|
||||
public:
|
||||
static FCGNSReader* New();
|
||||
vtkTypeMacro(FCGNSReader, vtkMultiBlockDataSetAlgorithm);
|
||||
void PrintSelf(ostream& os, vtkIndent indent) override;
|
||||
|
||||
/**@name Getter和Setter宏
|
||||
* 相当于setter/getter,同vtkSetMacro(FileName, char*)/vtkGetMacro(FileName, char*)
|
||||
* @{
|
||||
*/
|
||||
vtkSetStringMacro(FileName);
|
||||
vtkGetStringMacro(FileName);
|
||||
//@}
|
||||
|
||||
int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
|
||||
vtkInformationVector* outputVector) override;
|
||||
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
|
||||
|
||||
|
||||
int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector);
|
||||
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*);
|
||||
|
||||
/**
|
||||
* @brief 检测指定文件是否可以被正常读取(包括文件格式、CGNS库版本号)
|
||||
*/
|
||||
bool canReadFile();
|
||||
|
||||
void setReadBC(bool read);
|
||||
|
@ -27,7 +33,14 @@ public:
|
|||
private:
|
||||
FCGNSReader();
|
||||
~FCGNSReader();
|
||||
|
||||
/**
|
||||
* @brief 读取CGNS文件的单个zone
|
||||
* @param[in] fileIndex 文件的索引号
|
||||
* @param[in] baseIndex base的索引号(从1开始)
|
||||
* @param[in] zoneIndex zone的索引号(从1开始)
|
||||
* @param[out] output
|
||||
* @since 2.5.0
|
||||
*/
|
||||
void readZone(int fileIndex, int baseIndex, int zoneIndex, vtkMultiBlockDataSet* output);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
#include "FCGNSStructureZoneReader.h"
|
||||
#include <vtkStructuredGrid.h>
|
||||
#include <vtkMultiBlockDataSet.h>
|
||||
#include <vtkInformation.h>
|
||||
#include <vtkDataSetWriter.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <QDebug>
|
||||
#include <cgnstypes.h>
|
||||
#include <cgnslib.h>
|
||||
#include <cgns_io.h>
|
||||
#include <vtkFloatArray.h>
|
||||
#include <vtkDoubleArray.h>
|
||||
#include <vtkInformationStringKey.h>
|
||||
#include <vtkNew.h>
|
||||
|
||||
#include "PostRenderData/Macros.hxx"
|
||||
|
||||
#include <cgns_io.h>
|
||||
#include <cgnslib.h>
|
||||
#include <cgnstypes.h>
|
||||
#include <vtkDataSetWriter.h>
|
||||
#include <vtkDoubleArray.h>
|
||||
#include <vtkFloatArray.h>
|
||||
#include <vtkInformation.h>
|
||||
#include <vtkInformationStringKey.h>
|
||||
#include <vtkMultiBlockDataSet.h>
|
||||
#include <vtkNew.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <vtkStructuredGrid.h>
|
||||
|
||||
FCGNSStructeGridReader::FCGNSStructeGridReader(vtkMultiBlockDataSet* root)
|
||||
: FCGNSGridReaderBase(root)
|
||||
|
@ -21,22 +21,22 @@ FCGNSStructeGridReader::FCGNSStructeGridReader(vtkMultiBlockDataSet* root)
|
|||
_isStructedGrid = true;
|
||||
}
|
||||
|
||||
|
||||
void FCGNSStructeGridReader::read()
|
||||
{
|
||||
char zone_name[33] = { 0 };
|
||||
cgsize_t zoneSize[3][3] = { 0 };
|
||||
int OK = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize[0]);
|
||||
if (CG_OK != OK) return;
|
||||
if(CG_OK != OK)
|
||||
return;
|
||||
_zoneName = QString(zone_name);
|
||||
|
||||
int dim{ 0 };
|
||||
OK = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim);
|
||||
if (CG_OK != OK) return;
|
||||
if(CG_OK != OK)
|
||||
return;
|
||||
|
||||
cgsize_t read_range[2][3] = { 0 };
|
||||
for (int ijk = 0; ijk < 3; ++ijk)
|
||||
{
|
||||
for(int ijk = 0; ijk < 3; ++ijk) {
|
||||
read_range[0][ijk] = 1;
|
||||
read_range[1][ijk] = zoneSize[0][ijk];
|
||||
}
|
||||
|
@ -62,7 +62,6 @@ void FCGNSStructeGridReader::read()
|
|||
this->readBC();
|
||||
|
||||
this->spllitSection(sGrid);
|
||||
|
||||
}
|
||||
|
||||
void FCGNSStructeGridReader::setReadBC(bool r)
|
||||
|
@ -79,9 +78,9 @@ void FCGNSStructeGridReader::readBC()
|
|||
{
|
||||
int nbc{ 0 };
|
||||
int OK = cg_nbocos(_fileIndex, _baseIndex, _zoneIndex, &nbc);
|
||||
if (CG_OK != OK) return;
|
||||
for (int ibc = 1; ibc <= nbc; ++ibc)
|
||||
{
|
||||
if(CG_OK != OK)
|
||||
return;
|
||||
for(int ibc = 1; ibc <= nbc; ++ibc) {
|
||||
CGNS_ENUMT(BCType_t) bctype;
|
||||
CGNS_ENUMT(PointSetType_t) ptype;
|
||||
// CGNS_ENUMT(GridLocation_t) location;
|
||||
|
@ -91,19 +90,21 @@ void FCGNSStructeGridReader::readBC()
|
|||
cgsize_t np = 0, is = 0;
|
||||
int ib = 0;
|
||||
|
||||
OK = cg_boco_info(_fileIndex,_baseIndex, _zoneIndex, ibc, bc_name, &bctype,
|
||||
&ptype, &np, nrmlindex, &is, &datatype, &ib);
|
||||
if (CG_OK != OK) continue;
|
||||
if(ptype != CGNS_ENUMV(PointRange)) continue;
|
||||
OK = cg_boco_info(_fileIndex, _baseIndex, _zoneIndex, ibc, bc_name, &bctype, &ptype, &np,
|
||||
nrmlindex, &is, &datatype, &ib);
|
||||
if(CG_OK != OK)
|
||||
continue;
|
||||
if(ptype != CGNS_ENUMV(PointRange))
|
||||
continue;
|
||||
|
||||
cgsize_t* pnpnts = new cgsize_t[6];
|
||||
OK = cg_boco_read(_fileIndex, _baseIndex, _zoneIndex, ibc, pnpnts, NULL);
|
||||
if(OK != CG_OK) continue;
|
||||
if(OK != CG_OK)
|
||||
continue;
|
||||
|
||||
BCInfo info(bc_name, pnpnts, bctype);
|
||||
_bcList.append(info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FCGNSStructeGridReader::spllitSection(vtkStructuredGrid* gird)
|
||||
|
@ -118,18 +119,13 @@ void FCGNSStructeGridReader::spllitSection(vtkStructuredGrid* gird)
|
|||
|
||||
void FCGNSStructeGridReader::extractBCs(vtkStructuredGrid* grid)
|
||||
{
|
||||
qDebug() << "BC in zone: " << _zoneName;
|
||||
int dim[3] = { 0 };
|
||||
grid->GetDimensions(dim);
|
||||
for (BCInfo bc: _bcList)
|
||||
{
|
||||
for(BCInfo bc : _bcList) {
|
||||
QList<int> ptIndexs;
|
||||
for (int k = bc.kMin; k <= bc.kMax; ++k)
|
||||
{
|
||||
for (int j = bc.jMin; j <= bc.jMax; ++j)
|
||||
{
|
||||
for (int i = bc.iMin; i <= bc.iMax; ++i)
|
||||
{
|
||||
for(int k = bc.kMin; k <= bc.kMax; ++k) {
|
||||
for(int j = bc.jMin; j <= bc.jMax; ++j) {
|
||||
for(int i = bc.iMin; i <= bc.iMax; ++i) {
|
||||
int index = dim[0] * dim[1] * k + dim[0] * j + i;
|
||||
ptIndexs.append(index);
|
||||
}
|
||||
|
@ -137,12 +133,10 @@ void FCGNSStructeGridReader::extractBCs(vtkStructuredGrid *grid)
|
|||
}
|
||||
extractBCGrid(grid, &bc, ptIndexs);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info, QList<int> & indexs)
|
||||
void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info,
|
||||
QList<int>& indexs)
|
||||
{
|
||||
vtkStructuredGrid* bcMesh = vtkStructuredGrid::New();
|
||||
const int iDim = info->iMax - info->iMin + 1;
|
||||
|
@ -151,12 +145,7 @@ void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info
|
|||
|
||||
bcMesh->SetDimensions(iDim, jDim, kDim);
|
||||
|
||||
qDebug() << indexs.size();
|
||||
qDebug() << iDim * jDim*kDim;
|
||||
|
||||
// vtkNew<vtkPoints> points;
|
||||
DecCreVTKSmartPtr(vtkPoints,points)
|
||||
for (int index : indexs)
|
||||
DecCreVTKSmartPtr(vtkPoints, points) for(int index : indexs)
|
||||
{
|
||||
double* coor = grid->GetPoint(index);
|
||||
points->InsertNextPoint(coor);
|
||||
|
@ -166,8 +155,7 @@ void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info
|
|||
vtkPointData* pointData = grid->GetPointData();
|
||||
const int nArray = pointData->GetNumberOfArrays();
|
||||
|
||||
for (int iArray = 0; iArray < nArray; ++iArray)
|
||||
{
|
||||
for(int iArray = 0; iArray < nArray; ++iArray) {
|
||||
const char* name = pointData->GetArrayName(iArray);
|
||||
vtkDataArray* array = pointData->GetArray(name);
|
||||
const int nComp = array->GetNumberOfComponents();
|
||||
|
@ -178,27 +166,24 @@ void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info
|
|||
copyArray = vtkDoubleArray::New();
|
||||
else if(array->IsA("vtkFloatArray"))
|
||||
copyArray = vtkFloatArray::New();
|
||||
if(copyArray == nullptr) continue;
|
||||
if(copyArray == nullptr)
|
||||
continue;
|
||||
copyArray->SetName(name);
|
||||
|
||||
copyArray->SetNumberOfComponents(nComp);
|
||||
for (int ic = 0; ic < nComp; ++ic)
|
||||
{
|
||||
for(int ic = 0; ic < nComp; ++ic) {
|
||||
const char* arrName = array->GetComponentName(ic);
|
||||
copyArray->SetComponentName(ic, arrName);
|
||||
}
|
||||
// copyArray->Resize(indexs.size());
|
||||
for (int in =0;in<indexs.size(); ++in)
|
||||
{
|
||||
for(int in = 0; in < indexs.size(); ++in) {
|
||||
int index = indexs.at(in);
|
||||
for (int ic = 0; ic < nComp; ++ic)
|
||||
{
|
||||
for(int ic = 0; ic < nComp; ++ic) {
|
||||
double v = array->GetComponent(index, ic);
|
||||
copyArray->InsertComponent(in, ic, v);
|
||||
}
|
||||
}
|
||||
bcMesh->GetPointData()->AddArray(copyArray);
|
||||
|
||||
}
|
||||
|
||||
int n = _root->GetNumberOfBlocks();
|
||||
|
@ -211,33 +196,22 @@ QString GetBCType(QString name, int bcType)
|
|||
{
|
||||
QString sBCType{ "None" };
|
||||
QString sName = name.toLower();
|
||||
if (bcType == 7)
|
||||
{
|
||||
if(bcType == 7) {
|
||||
sBCType = "Far";
|
||||
return sBCType;
|
||||
}
|
||||
else if (bcType >= 16 && bcType <= 17)
|
||||
{
|
||||
} else if(bcType >= 16 && bcType <= 17) {
|
||||
sBCType = "Sym";
|
||||
return sBCType;
|
||||
}
|
||||
else if (bcType >= 20 && bcType <= 24)
|
||||
{
|
||||
} else if(bcType >= 20 && bcType <= 24) {
|
||||
sBCType = "Wall";
|
||||
return sBCType;
|
||||
}
|
||||
else if(sName.contains("far"))
|
||||
{
|
||||
} else if(sName.contains("far")) {
|
||||
sBCType = "Far";
|
||||
return sBCType;
|
||||
}
|
||||
else if (sName.contains("sym"))
|
||||
{
|
||||
} else if(sName.contains("sym")) {
|
||||
sBCType = "Sym";
|
||||
return sBCType;
|
||||
}
|
||||
else if (sName.contains("wall"))
|
||||
{
|
||||
} else if(sName.contains("wall")) {
|
||||
sBCType = "Wall";
|
||||
return sBCType;
|
||||
}
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
#include "FCGNSUnStructureZoneReader.h"
|
||||
#include <vtkMultiBlockDataSet.h>
|
||||
#include <cgnstypes.h>
|
||||
|
||||
#include "Common/DebugLogger.h"
|
||||
#include "PostRenderData/Macros.hxx"
|
||||
|
||||
#include <cgns_io.h>
|
||||
#include <cgnslib.h>
|
||||
#include <cgnstypes.h>
|
||||
#include <QDebug>
|
||||
#include <vtkUnstructuredGrid.h>
|
||||
#include <vtkNew.h>
|
||||
#include <vtkPoints.h>
|
||||
#include <vtkCellType.h>
|
||||
#include <vtkDataSetWriter.h>
|
||||
#include <vtkSelectionNode.h>
|
||||
#include <vtkSelection.h>
|
||||
#include <vtkExtractSelection.h>
|
||||
#include <vtkIdTypeArray.h>
|
||||
#include <vtkMultiBlockDataSet.h>
|
||||
#include <vtkInformation.h>
|
||||
#include <vtkCellType.h>
|
||||
#include "PostRenderData/Macros.hxx"
|
||||
#include <vtkMultiBlockDataSet.h>
|
||||
#include <vtkNew.h>
|
||||
#include <vtkPoints.h>
|
||||
#include <vtkSelection.h>
|
||||
#include <vtkSelectionNode.h>
|
||||
#include <vtkUnstructuredGrid.h>
|
||||
|
||||
FCGNSUnStructeGridReader::FCGNSUnStructeGridReader(vtkMultiBlockDataSet* root)
|
||||
: FCGNSGridReaderBase(root)
|
||||
|
@ -25,188 +27,361 @@ FCGNSUnStructeGridReader::FCGNSUnStructeGridReader(vtkMultiBlockDataSet *root)
|
|||
|
||||
void FCGNSUnStructeGridReader::read()
|
||||
{
|
||||
char zone_name[33] = {0};
|
||||
cgsize_t zoneSize[3] = {0, 0, 0};
|
||||
int OK = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize);
|
||||
if (CG_OK != OK)
|
||||
if(_fileIndex < 0 || _baseIndex < 0 || _zoneIndex < 0) {
|
||||
DebugError("Invalid zone(file: %d, base: %d, zone: %d)\n", _fileIndex, _baseIndex,
|
||||
_zoneIndex);
|
||||
return;
|
||||
}
|
||||
DebugInfo("Start reading zone(file: %d, base: %d, zone: %d)...\n", _fileIndex, _baseIndex,
|
||||
_zoneIndex);
|
||||
// 读取zone信息
|
||||
char zone_name[33] = { 0 };
|
||||
// 在非结构化网格数据中zonesize的元素分别对应NVertex, NCell, NBoundVertex
|
||||
cgsize_t zoneSize[3] = { 0, 0, 0 };
|
||||
auto result = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize);
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to read zone(index = %d) information\n", _zoneIndex);
|
||||
return;
|
||||
} else {
|
||||
DebugInfo("NVertex = %d, NCell = %d, NBoundVertex = %d\n", zoneSize[0], zoneSize[1],
|
||||
zoneSize[2]);
|
||||
}
|
||||
|
||||
_zoneName = QString(zone_name);
|
||||
const int nVertex = zoneSize[0], nCell = zoneSize[1], nBoundary = zoneSize[2];
|
||||
|
||||
// 坐标数组的个数
|
||||
int dim{ 0 };
|
||||
OK = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim);
|
||||
if (CG_OK != OK)
|
||||
result = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim);
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to read number of coordinate arrays for zone %d\n", _zoneIndex);
|
||||
return;
|
||||
} else {
|
||||
DebugInfo("Number of coordinate arrays for zone %d is %d\n", _zoneIndex, dim);
|
||||
}
|
||||
|
||||
// vtkUnstructuredGrid* unsGrid = vtkUnstructuredGrid::New();
|
||||
|
||||
DecCreVTKSmartPtr(vtkUnstructuredGrid, unsGrid)
|
||||
// 需要读取全部数据,所以range=[1,nVertex]
|
||||
cgsize_t read_range[2][3] = { 0 };
|
||||
for (int ijk = 0; ijk < 3; ++ijk)
|
||||
{
|
||||
for(int ijk = 0; ijk < 3; ++ijk) {
|
||||
read_range[0][ijk] = 1;
|
||||
read_range[1][ijk] = nVertex;
|
||||
}
|
||||
|
||||
// 读取坐标数据信息
|
||||
this->readCoordinate(dim, nVertex, read_range[0], read_range[1]);
|
||||
|
||||
DecCreVTKSmartPtr(vtkPoints, points) //形成整体点集合
|
||||
for (int i = 0; i < _vertexList.size(); ++i)
|
||||
{
|
||||
VPoint po = _vertexList.at(i);
|
||||
points->InsertNextPoint(po.x, po.y, po.z);
|
||||
if(_vertexList.size() != nVertex) {
|
||||
DebugError("Failed to read coordinate arrays for zone %d\n", _zoneIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
// 准备vtk数据,并插入点
|
||||
DecCreVTKSmartPtr(vtkPoints, points);
|
||||
for(int i = 0; i < _vertexList.size(); ++i) {
|
||||
auto po = _vertexList.at(i);
|
||||
points->InsertNextPoint(po.x, po.y, po.z);
|
||||
}
|
||||
DecCreVTKSmartPtr(vtkUnstructuredGrid, unsGrid);
|
||||
unsGrid->SetPoints(points);
|
||||
|
||||
// 获取网格单元的节点数量
|
||||
int nSection{ 0 };
|
||||
cg_nsections(_fileIndex, _baseIndex, _zoneIndex, &nSection);
|
||||
result = cg_nsections(_fileIndex, _baseIndex, _zoneIndex, &nSection);
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to get number of element sections\n");
|
||||
return;
|
||||
} else {
|
||||
DebugInfo("Number of element sections is %d\n", nSection);
|
||||
}
|
||||
|
||||
QList<int> sectionList = sectionOrder(nSection);
|
||||
if(sectionList.size() == 0) {
|
||||
DebugError("Failed to order sections\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int iSection : sectionList)
|
||||
{
|
||||
for(int iSection : sectionList) {
|
||||
char sectionName[33] = { 0 };
|
||||
cgsize_t istart = 0, iend = 0;
|
||||
int nbndry = 0, iparent_flag = 0;
|
||||
CGNS_ENUMT(ElementType_t)
|
||||
itype;
|
||||
OK = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName, &itype, &istart, &iend, &nbndry, &iparent_flag);
|
||||
const int ncellCount = iend - istart + 1;
|
||||
result = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName, &itype,
|
||||
&istart, &iend, &nbndry, &iparent_flag);
|
||||
|
||||
qDebug() << QString(sectionName) << istart << iend;
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to read element section: %d\n", iSection);
|
||||
return;
|
||||
} else {
|
||||
DebugInfo("element section: %s, element type: %d, first element index: %d, last "
|
||||
"element index: %d\n",
|
||||
sectionName, static_cast<int>(itype), istart, iend);
|
||||
}
|
||||
|
||||
const int ncellCount = iend - istart + 1;
|
||||
cgsize_t elementDataSize = 0;
|
||||
OK = cg_ElementDataSize(_fileIndex, _baseIndex, _zoneIndex, iSection, &elementDataSize);
|
||||
if (CG_OK != 0)
|
||||
continue;
|
||||
result = cg_ElementDataSize(_fileIndex, _baseIndex, _zoneIndex, iSection, &elementDataSize);
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to get size of element connectivity data array\n");
|
||||
return;
|
||||
}
|
||||
cgsize_t* elements = new cgsize_t[elementDataSize];
|
||||
OK = cg_elements_read(_fileIndex, _baseIndex, _zoneIndex, iSection, elements, NULL);
|
||||
if (CG_OK != 0)
|
||||
continue;
|
||||
FSection section(QString(sectionName), istart, iend); //记录section
|
||||
cgsize_t* connectOffset = nullptr;
|
||||
/** */
|
||||
|
||||
if(itype == CGNS_ENUMT(MIXED)) {
|
||||
connectOffset = new cgsize_t[elementDataSize];
|
||||
result = cg_poly_elements_read(_fileIndex, _baseIndex, _zoneIndex, iSection, elements,
|
||||
connectOffset, NULL);
|
||||
} else {
|
||||
// 只能读取固定大小的单元类型
|
||||
result = cg_elements_read(_fileIndex, _baseIndex, _zoneIndex, iSection, elements, NULL);
|
||||
}
|
||||
if(CG_OK != result) {
|
||||
DebugError("Failed to read fixed size element data, error: %s\n", cg_get_error());
|
||||
return;
|
||||
}
|
||||
|
||||
FSection section(QString(sectionName), istart, iend);
|
||||
_sections.append(section);
|
||||
|
||||
this->addCells(unsGrid, ncellCount, itype, elements);
|
||||
this->addCells(unsGrid, ncellCount, itype, elements, connectOffset);
|
||||
}
|
||||
this->readFlowSolution(unsGrid);
|
||||
this->spllitSection(unsGrid);
|
||||
}
|
||||
|
||||
void FCGNSUnStructeGridReader::addCells(vtkUnstructuredGrid *grid, int ncell, CGNS_ENUMT(ElementType_t) type, cgsize_t *elements)
|
||||
/**
|
||||
* type:参考http://cgns.github.io/CGNS_docs_current/sids/conv.html#unstructgrid
|
||||
* ElementTypeNull, ElementTypeUserDefined, NODE, BAR_2, BAR_3, TRI_3, TRI_6, QUAD_4, QUAD_8,
|
||||
* QUAD_9, TETRA_4, TETRA_10, PYRA_5, PYRA_14, PENTA_6, PENTA_15, PENTA_18, HEXA_8, HEXA_20,
|
||||
* HEXA_27, MIXED, PYRA_13, NGON_n, NFACE_n, BAR_4, TRI_9, TRI_10, QUAD_12, QUAD_16, TETRA_16,
|
||||
* TETRA_20, PYRA_21, PYRA_29, PYRA_30, PENTA_24, PENTA_38, PENTA_40, HEXA_32, HEXA_56, HEXA_64,
|
||||
* BAR_5, TRI_12, TRI_15, QUAD_P4_16, QUAD_25, TETRA_22, TETRA_34, TETRA_35, PYRA_P4_29, PYRA_50,
|
||||
* PYRA_55, PENTA_33, PENTA_66, PENTA_75, HEXA_44, HEXA_98, HEXA_125
|
||||
*
|
||||
* CGNS的索引是从1开始的,VTK的索引是从0开始,需要注意
|
||||
*/
|
||||
void FCGNSUnStructeGridReader::addCells(vtkUnstructuredGrid* grid, int ncell,
|
||||
CGNS_ENUMT(ElementType_t) type, cgsize_t* elements,
|
||||
cgsize_t* connectOffset)
|
||||
{
|
||||
if(CGNS_ENUMT(TRI_3) == type) // 三角形
|
||||
{
|
||||
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
|
||||
addTri3Cell(grid, elements[iCnt * 3 + 0] - 1, elements[iCnt * 3 + 1] - 1,
|
||||
elements[iCnt * 3 + 2] - 1);
|
||||
}
|
||||
} else if(CGNS_ENUMT(BAR_2) == type) // 二节点梁单元
|
||||
{
|
||||
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
|
||||
addBar2Cell(grid, elements[iCnt * 2 + 0] - 1, elements[iCnt * 2 + 1] - 1);
|
||||
}
|
||||
} else if(CGNS_ENUMT(TETRA_4) == type) // 四节点四面体
|
||||
{
|
||||
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
|
||||
addTetra4Cell(grid, elements[iCnt * 4 + 0] - 1, elements[iCnt * 4 + 1] - 1,
|
||||
elements[iCnt * 4 + 2] - 1, elements[iCnt * 4 + 3] - 1);
|
||||
}
|
||||
} else if(CGNS_ENUMT(QUAD_4) == type) // 四节点四边形
|
||||
{
|
||||
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
|
||||
addQuad4Cell(grid, elements[iCnt * 4 + 0] - 1, elements[iCnt * 4 + 1] - 1,
|
||||
elements[iCnt * 4 + 2] - 1, elements[iCnt * 4 + 3] - 1);
|
||||
}
|
||||
} else if(CGNS_ENUMT(HEXA_8) == type) // 八节点六面体
|
||||
{
|
||||
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
|
||||
addHexa8Cell(grid, elements[iCnt * 8 + 0] - 1, elements[iCnt * 8 + 1] - 1,
|
||||
elements[iCnt * 8 + 2] - 1, elements[iCnt * 8 + 3] - 1,
|
||||
elements[iCnt * 8 + 4] - 1, elements[iCnt * 8 + 5] - 1,
|
||||
elements[iCnt * 8 + 6] - 1, elements[iCnt * 8 + 7] - 1);
|
||||
}
|
||||
} else if(CGNS_ENUMT(PENTA_6) == type) // 六节点三棱柱
|
||||
{
|
||||
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
|
||||
addPenta6Cell(grid, elements[iCnt * 6 + 0] - 1, elements[iCnt * 6 + 1] - 1,
|
||||
elements[iCnt * 6 + 2] - 1, elements[iCnt * 6 + 3] - 1,
|
||||
elements[iCnt * 6 + 4] - 1, elements[iCnt * 6 + 5] - 1);
|
||||
}
|
||||
} else if(CGNS_ENUMT(PYRA_5) == type) // 金字塔单元
|
||||
{
|
||||
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
|
||||
addPyra5Cell(grid, elements[iCnt * 5 + 0] - 1, elements[iCnt * 5 + 1] - 1,
|
||||
elements[iCnt * 5 + 2] - 1, elements[iCnt * 5 + 3] - 1,
|
||||
elements[iCnt * 5 + 4] - 1);
|
||||
}
|
||||
} else if(CGNS_ENUMT(MIXED) == type && connectOffset != nullptr) { // 混合单元
|
||||
int iCnt = 0;
|
||||
int iEle = 0;
|
||||
while((iCnt < ncell) && (iEle == connectOffset[iCnt])) {
|
||||
// 混合单元比其他单元多存储一个值,即第一个值存储单元类型,后面是节点编号
|
||||
auto type = elements[iEle];
|
||||
switch(type) {
|
||||
case CGNS_ENUMT(BAR_2): {
|
||||
auto id1 = elements[++iEle] - 1;
|
||||
auto id2 = elements[++iEle] - 1;
|
||||
addBar2Cell(grid, id1, id2);
|
||||
} break;
|
||||
case CGNS_ENUMT(TRI_3): {
|
||||
auto id1 = elements[++iEle] - 1;
|
||||
auto id2 = elements[++iEle] - 1;
|
||||
auto id3 = elements[++iEle] - 1;
|
||||
addTri3Cell(grid, id1, id2, id3);
|
||||
} break;
|
||||
case CGNS_ENUMT(TETRA_4): {
|
||||
auto id1 = elements[++iEle] - 1;
|
||||
auto id2 = elements[++iEle] - 1;
|
||||
auto id3 = elements[++iEle] - 1;
|
||||
auto id4 = elements[++iEle] - 1;
|
||||
addTetra4Cell(grid, id1, id2, id3, id4);
|
||||
} break;
|
||||
case CGNS_ENUMT(QUAD_4): {
|
||||
auto id1 = elements[++iEle] - 1;
|
||||
auto id2 = elements[++iEle] - 1;
|
||||
auto id3 = elements[++iEle] - 1;
|
||||
auto id4 = elements[++iEle] - 1;
|
||||
addQuad4Cell(grid, id1, id2, id3, id4);
|
||||
} break;
|
||||
case CGNS_ENUMT(HEXA_8): {
|
||||
auto id1 = elements[++iEle] - 1;
|
||||
auto id2 = elements[++iEle] - 1;
|
||||
auto id3 = elements[++iEle] - 1;
|
||||
auto id4 = elements[++iEle] - 1;
|
||||
auto id5 = elements[++iEle] - 1;
|
||||
auto id6 = elements[++iEle] - 1;
|
||||
auto id7 = elements[++iEle] - 1;
|
||||
auto id8 = elements[++iEle] - 1;
|
||||
addHexa8Cell(grid, id1, id2, id3, id4, id5, id6, id7, id8);
|
||||
} break;
|
||||
case CGNS_ENUMT(PENTA_6): {
|
||||
auto id1 = elements[++iEle] - 1;
|
||||
auto id2 = elements[++iEle] - 1;
|
||||
auto id3 = elements[++iEle] - 1;
|
||||
auto id4 = elements[++iEle] - 1;
|
||||
auto id5 = elements[++iEle] - 1;
|
||||
auto id6 = elements[++iEle] - 1;
|
||||
addPenta6Cell(grid, id1, id2, id3, id4, id5, id6);
|
||||
} break;
|
||||
case CGNS_ENUMT(PYRA_5): {
|
||||
auto id1 = elements[++iEle] - 1;
|
||||
auto id2 = elements[++iEle] - 1;
|
||||
auto id3 = elements[++iEle] - 1;
|
||||
auto id4 = elements[++iEle] - 1;
|
||||
auto id5 = elements[++iEle] - 1;
|
||||
addPyra5Cell(grid, id1, id2, id3, id4, id5);
|
||||
} break;
|
||||
default:
|
||||
DebugError("Unsupported element type was found: %d\n", static_cast<int>(type));
|
||||
break;
|
||||
}
|
||||
++iEle;
|
||||
++iCnt;
|
||||
}
|
||||
} else {
|
||||
DebugError("Unsupported element type was found: %d\n", static_cast<int>(type));
|
||||
}
|
||||
}
|
||||
|
||||
for (int iCnt = 0; iCnt < ncell; ++iCnt)
|
||||
vtkIdType FCGNSUnStructeGridReader::addBar2Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
|
||||
vtkIdType id2)
|
||||
{
|
||||
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(elements[iCnt * 3 + 0] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 3 + 1] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 3 + 2] - 1);
|
||||
grid->InsertNextCell(VTK_TRIANGLE, idlist);
|
||||
auto idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(id1);
|
||||
idlist->InsertNextId(id2);
|
||||
return grid->InsertNextCell(VTK_LINE, idlist);
|
||||
}
|
||||
}
|
||||
else if (CGNS_ENUMT(BAR_2) == type) //二节点梁单元
|
||||
|
||||
vtkIdType FCGNSUnStructeGridReader::addTri3Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
|
||||
vtkIdType id2, vtkIdType id3)
|
||||
{
|
||||
for (int iCnt = 0; iCnt < ncell; ++iCnt)
|
||||
auto idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(id1);
|
||||
idlist->InsertNextId(id2);
|
||||
idlist->InsertNextId(id3);
|
||||
return grid->InsertNextCell(VTK_TRIANGLE, idlist);
|
||||
}
|
||||
|
||||
vtkIdType FCGNSUnStructeGridReader::addTetra4Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
|
||||
vtkIdType id2, vtkIdType id3, vtkIdType id4)
|
||||
{
|
||||
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(elements[iCnt * 2 + 0] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 2 + 1] - 1);
|
||||
grid->InsertNextCell(VTK_LINE, idlist);
|
||||
auto idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(id1);
|
||||
idlist->InsertNextId(id2);
|
||||
idlist->InsertNextId(id3);
|
||||
idlist->InsertNextId(id4);
|
||||
return grid->InsertNextCell(VTK_TETRA, idlist);
|
||||
}
|
||||
}
|
||||
else if (CGNS_ENUMT(TETRA_4) == type) //四节点四面体
|
||||
|
||||
vtkIdType FCGNSUnStructeGridReader::addQuad4Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
|
||||
vtkIdType id2, vtkIdType id3, vtkIdType id4)
|
||||
{
|
||||
for (int iCnt = 0; iCnt < ncell; ++iCnt)
|
||||
auto idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(id1);
|
||||
idlist->InsertNextId(id2);
|
||||
idlist->InsertNextId(id3);
|
||||
idlist->InsertNextId(id4);
|
||||
return grid->InsertNextCell(VTK_QUAD, idlist);
|
||||
}
|
||||
|
||||
vtkIdType FCGNSUnStructeGridReader::addHexa8Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
|
||||
vtkIdType id2, vtkIdType id3, vtkIdType id4,
|
||||
vtkIdType id5, vtkIdType id6, vtkIdType id7,
|
||||
vtkIdType id8)
|
||||
{
|
||||
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(elements[iCnt * 4 + 0] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 4 + 1] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 4 + 2] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 4 + 3] - 1);
|
||||
grid->InsertNextCell(VTK_TETRA, idlist);
|
||||
auto idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(id1);
|
||||
idlist->InsertNextId(id2);
|
||||
idlist->InsertNextId(id3);
|
||||
idlist->InsertNextId(id4);
|
||||
idlist->InsertNextId(id5);
|
||||
idlist->InsertNextId(id6);
|
||||
return grid->InsertNextCell(VTK_WEDGE, idlist);
|
||||
}
|
||||
}
|
||||
else if (CGNS_ENUMT(QUAD_4) == type) //四节点四边形
|
||||
|
||||
vtkIdType FCGNSUnStructeGridReader::addPenta6Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
|
||||
vtkIdType id2, vtkIdType id3, vtkIdType id4,
|
||||
vtkIdType id5, vtkIdType id6)
|
||||
{
|
||||
for (int iCnt = 0; iCnt < ncell; ++iCnt)
|
||||
auto idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(id1);
|
||||
idlist->InsertNextId(id2);
|
||||
idlist->InsertNextId(id3);
|
||||
idlist->InsertNextId(id4);
|
||||
idlist->InsertNextId(id5);
|
||||
idlist->InsertNextId(id6);
|
||||
return grid->InsertNextCell(VTK_WEDGE, idlist);
|
||||
}
|
||||
|
||||
vtkIdType FCGNSUnStructeGridReader::addPyra5Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
|
||||
vtkIdType id2, vtkIdType id3, vtkIdType id4,
|
||||
vtkIdType id5)
|
||||
{
|
||||
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(elements[iCnt * 4 + 0] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 4 + 1] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 4 + 2] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 4 + 3] - 1);
|
||||
grid->InsertNextCell(VTK_QUAD, idlist);
|
||||
}
|
||||
}
|
||||
else if (CGNS_ENUMT(HEXA_8) == type) //八节点六面体
|
||||
{
|
||||
for (int iCnt = 0; iCnt < ncell; ++iCnt)
|
||||
{
|
||||
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(elements[iCnt * 8 + 0] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 8 + 1] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 8 + 2] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 8 + 3] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 8 + 4] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 8 + 5] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 8 + 6] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 8 + 7] - 1);
|
||||
grid->InsertNextCell(VTK_HEXAHEDRON, idlist);
|
||||
}
|
||||
}
|
||||
else if (CGNS_ENUMT(PENTA_6) == type) //六节点三棱柱
|
||||
{
|
||||
for (int iCnt = 0; iCnt < ncell; ++iCnt)
|
||||
{
|
||||
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(elements[iCnt * 6 + 0] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 6 + 1] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 6 + 2] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 6 + 3] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 6 + 4] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 6 + 5] - 1);
|
||||
grid->InsertNextCell(VTK_WEDGE, idlist);
|
||||
}
|
||||
}
|
||||
else if (CGNS_ENUMT(PYRA_5) == type) //金字塔单元
|
||||
{
|
||||
for (int iCnt = 0; iCnt < ncell; ++iCnt)
|
||||
{
|
||||
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(elements[iCnt * 5 + 0] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 5 + 1] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 5 + 2] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 5 + 3] - 1);
|
||||
idlist->InsertNextId(elements[iCnt * 5 + 4] - 1);
|
||||
// idlist->InsertNextId(elements[iCnt * 5 + 0] - 1);
|
||||
grid->InsertNextCell(VTK_PYRAMID, idlist);
|
||||
}
|
||||
}
|
||||
auto idlist = vtkSmartPointer<vtkIdList>::New();
|
||||
idlist->InsertNextId(id1);
|
||||
idlist->InsertNextId(id2);
|
||||
idlist->InsertNextId(id3);
|
||||
idlist->InsertNextId(id4);
|
||||
idlist->InsertNextId(id5);
|
||||
return grid->InsertNextCell(VTK_PYRAMID, idlist);
|
||||
}
|
||||
|
||||
void FCGNSUnStructeGridReader::spllitSection(vtkUnstructuredGrid* gird)
|
||||
{
|
||||
if (_sections.isEmpty())
|
||||
{
|
||||
if(_sections.isEmpty()) {
|
||||
int n = _root->GetNumberOfBlocks();
|
||||
_root->SetBlock(n, gird);
|
||||
QString NameBC = _zoneName + "!|||!" + "None";
|
||||
_root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data());
|
||||
}
|
||||
|
||||
for (FSection sec : _sections)
|
||||
{
|
||||
for(FSection sec : _sections) {
|
||||
// vtkNew<vtkIdTypeArray> ids;
|
||||
DecCreVTKSmartPtr(vtkIdTypeArray, ids)
|
||||
ids->SetNumberOfComponents(1);
|
||||
DecCreVTKSmartPtr(vtkIdTypeArray, ids) ids->SetNumberOfComponents(1);
|
||||
for(int i = sec._begin - 1; i <= sec._end - 1; ++i)
|
||||
ids->InsertNextValue(i);
|
||||
|
||||
// vtkNew<vtkSelectionNode> node;
|
||||
DecCreVTKSmartPtr(vtkSelectionNode, node)
|
||||
node->SetFieldType(vtkSelectionNode::CELL);
|
||||
DecCreVTKSmartPtr(vtkSelectionNode, node) node->SetFieldType(vtkSelectionNode::CELL);
|
||||
node->SetContentType(vtkSelectionNode::INDICES);
|
||||
node->SetSelectionList(ids);
|
||||
|
||||
|
@ -215,8 +390,7 @@ void FCGNSUnStructeGridReader::spllitSection(vtkUnstructuredGrid *gird)
|
|||
section->AddNode(node);
|
||||
|
||||
// vtkNew<vtkExtractSelection> exctra;
|
||||
DecCreVTKSmartPtr(vtkExtractSelection, exctra)
|
||||
exctra->SetInputData(0, gird);
|
||||
DecCreVTKSmartPtr(vtkExtractSelection, exctra) exctra->SetInputData(0, gird);
|
||||
exctra->SetInputData(1, section);
|
||||
exctra->Update();
|
||||
|
||||
|
@ -226,14 +400,14 @@ void FCGNSUnStructeGridReader::spllitSection(vtkUnstructuredGrid *gird)
|
|||
_root->SetBlock(n, secGrid);
|
||||
QString NameBC = sec._name + "!|||!" + "None";
|
||||
_root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data());
|
||||
// _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), sec._name.toLatin1().data());
|
||||
// _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(),
|
||||
// sec._name.toLatin1().data());
|
||||
}
|
||||
}
|
||||
|
||||
QList<int> FCGNSUnStructeGridReader::sectionOrder(int nsec)
|
||||
{
|
||||
struct sectionInfo
|
||||
{
|
||||
struct sectionInfo {
|
||||
sectionInfo(int index, int s)
|
||||
{
|
||||
Index = index;
|
||||
|
@ -242,30 +416,32 @@ QList<int> FCGNSUnStructeGridReader::sectionOrder(int nsec)
|
|||
int Index;
|
||||
int startNum;
|
||||
};
|
||||
auto compare = [](const sectionInfo &s1, const sectionInfo &s2) -> bool
|
||||
{
|
||||
auto compare = [](const sectionInfo& s1, const sectionInfo& s2) -> bool {
|
||||
return s1.startNum <= s2.startNum;
|
||||
};
|
||||
|
||||
QList<sectionInfo> secs;
|
||||
for (int iSection = 1; iSection <= nsec; ++iSection)
|
||||
{
|
||||
for(int iSection = 1; iSection <= nsec; ++iSection) {
|
||||
char sectionName[33] = { 0 };
|
||||
cgsize_t istart = 0, iend = 0;
|
||||
int nbndry = 0, iparent_flag = 0;
|
||||
CGNS_ENUMT(ElementType_t)
|
||||
itype;
|
||||
int OK = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName, &itype, &istart, &iend, &nbndry, &iparent_flag);
|
||||
if (OK != CG_OK)
|
||||
continue;
|
||||
// 最后一个边界单元的索引,如果单元未排序则设为0
|
||||
int nbndry = 0;
|
||||
// 指示父级数据是否定义,如果存在则为1否则为0
|
||||
int iparent_flag = 0;
|
||||
CGNS_ENUMT(ElementType_t) itype;
|
||||
int result = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName,
|
||||
&itype, &istart, &iend, &nbndry, &iparent_flag);
|
||||
if(result != CG_OK) {
|
||||
DebugError("Failed to get info for an element section\n");
|
||||
return {};
|
||||
}
|
||||
sectionInfo sinfo(iSection, istart);
|
||||
secs.append(sinfo);
|
||||
}
|
||||
std::sort(secs.begin(), secs.end(), compare);
|
||||
|
||||
QList<int> secOrders;
|
||||
for (auto s : secs)
|
||||
{
|
||||
for(auto s : secs) {
|
||||
secOrders.append(s.Index);
|
||||
}
|
||||
return secOrders;
|
||||
|
|
|
@ -2,22 +2,42 @@
|
|||
#define _FCGNSUNSTRUCTEGRIDREADER_H__
|
||||
|
||||
#include "FCGNSGridReaderBase.h"
|
||||
|
||||
#include <cgnslib.h>
|
||||
#include <cgnstypes.h>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <cgnstypes.h>
|
||||
#include <cgnslib.h>
|
||||
#include <vtkUnstructuredGrid.h>
|
||||
|
||||
struct FSection
|
||||
/**
|
||||
* @brief section属性结构体
|
||||
* @since 2.5.0
|
||||
*/
|
||||
struct FSection {
|
||||
FSection(QString name, int b, int e)
|
||||
: _name(name)
|
||||
, _begin(b)
|
||||
, _end(e)
|
||||
{
|
||||
FSection(QString name, int b, int e) :_name(name),_begin(b), _end(e){}
|
||||
}
|
||||
/**
|
||||
* @brief 名称
|
||||
* @since 2.5.0
|
||||
*/
|
||||
QString _name{};
|
||||
/**
|
||||
* @brief 第一个单元的索引
|
||||
* @since 2.5.0
|
||||
*/
|
||||
int _begin{ 0 };
|
||||
/**
|
||||
* @brief 最后一个单元的索引
|
||||
* @since 2.5.0
|
||||
*/
|
||||
int _end{ 0 };
|
||||
};
|
||||
|
||||
class FCGNSUnStructeGridReader :public FCGNSGridReaderBase
|
||||
{
|
||||
class FCGNSUnStructeGridReader : public FCGNSGridReaderBase {
|
||||
public:
|
||||
FCGNSUnStructeGridReader(vtkMultiBlockDataSet* root);
|
||||
~FCGNSUnStructeGridReader() = default;
|
||||
|
@ -25,7 +45,31 @@ public:
|
|||
void read() override;
|
||||
|
||||
private:
|
||||
void addCells(vtkUnstructuredGrid* grid, int ncell, CGNS_ENUMT(ElementType_t) type, cgsize_t* eles);
|
||||
/**
|
||||
* @brief 添加单元到vtkUnstructuredGrid对象中
|
||||
* @param[out] grid 要添加单元的vtkUnstructuredGrid对象
|
||||
* @param[in] ncell 单元数量
|
||||
* @param[in] type 单元类型
|
||||
* @param[in] eles 单元数组
|
||||
* @param[in] connectOffset 单元偏移数组,仅在type=mixed时可用
|
||||
* @since 2.5.0
|
||||
*/
|
||||
void addCells(vtkUnstructuredGrid* grid, int ncell, CGNS_ENUMT(ElementType_t) type,
|
||||
cgsize_t* eles, cgsize_t* connectOffset);
|
||||
|
||||
vtkIdType addBar2Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2);
|
||||
vtkIdType addTri3Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3);
|
||||
vtkIdType addTetra4Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
|
||||
vtkIdType id4);
|
||||
vtkIdType addQuad4Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
|
||||
vtkIdType id4);
|
||||
vtkIdType addHexa8Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
|
||||
vtkIdType id4, vtkIdType id5, vtkIdType id6, vtkIdType id7,
|
||||
vtkIdType id8);
|
||||
vtkIdType addPenta6Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
|
||||
vtkIdType id4, vtkIdType id5, vtkIdType id6);
|
||||
vtkIdType addPyra5Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
|
||||
vtkIdType id4, vtkIdType id5);
|
||||
|
||||
void spllitSection(vtkUnstructuredGrid* gird);
|
||||
|
||||
|
@ -33,7 +77,6 @@ private:
|
|||
|
||||
private:
|
||||
QList<FSection> _sections;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
#include "DialogCreateCalculate.h"
|
||||
#include "ui_DialogCreateCalculate.h"
|
||||
#include "PostTreeWidget.h"
|
||||
#include "RenderDirector.h"
|
||||
#include "PostRenderData/RenderDataObject.h"
|
||||
#include "DialogCreateCalculate.h"
|
||||
|
||||
#include "PostRenderData/CalculateRenderDataAlg.h"
|
||||
#include "PostRenderData/RenderDataObject.h"
|
||||
#include "PostTreeWidget.h"
|
||||
#include "PythonModule/PyAgent.h"
|
||||
#include "RenderDirector.h"
|
||||
#include "ui_DialogCreateCalculate.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
|
||||
namespace Post
|
||||
{
|
||||
CreateCalculateDialog::CreateCalculateDialog(PostTreeWidget *tree, QWidget *parent) : PostFunctionDialogBase(tree, parent),
|
||||
_ui(new Ui::CreateCalculateDialog)
|
||||
namespace Post {
|
||||
CreateCalculateDialog::CreateCalculateDialog(PostTreeWidget* tree, QWidget* parent)
|
||||
: PostFunctionDialogBase(tree, parent)
|
||||
, _ui(new Ui::CreateCalculateDialog)
|
||||
{
|
||||
_ui->setupUi(this);
|
||||
init();
|
||||
|
@ -37,8 +39,7 @@ namespace Post
|
|||
|
||||
void CreateCalculateDialog::accept()
|
||||
{
|
||||
if (_parentObject == nullptr)
|
||||
{
|
||||
if(_parentObject == nullptr) {
|
||||
QMessageBox::warning(this, tr("Warning!"), tr("No selected data!"));
|
||||
return;
|
||||
}
|
||||
|
@ -83,7 +84,8 @@ namespace Post
|
|||
// alg->update();
|
||||
//
|
||||
// _parentObject->appendSubObjects(alg);
|
||||
// RenderDirector::getInstance()->renderDataObjectToWindow(alg, _parentObject->getRenderWinID());
|
||||
// RenderDirector::getInstance()->renderDataObjectToWindow(alg,
|
||||
// _parentObject->getRenderWinID());
|
||||
// _tree->updatePostTree();
|
||||
QDialog::accept();
|
||||
this->close();
|
||||
|
@ -104,39 +106,31 @@ namespace Post
|
|||
_scalarMenu->clear();
|
||||
_vectorMenu->clear();
|
||||
|
||||
auto createMenu = [=, &action](QStringList arrayList)
|
||||
{
|
||||
for (auto array : arrayList)
|
||||
{
|
||||
int type = _parentObject->variableType(1, array);
|
||||
if (type == 1)
|
||||
{
|
||||
auto createMenu = [=, &action](QStringList arrayList) {
|
||||
for(auto array : arrayList) {
|
||||
auto type = _parentObject->variableType(1, array);
|
||||
if(type == "scalar") {
|
||||
action = _scalarMenu->addAction(array);
|
||||
connect(action, &QAction::triggered, [=]
|
||||
{
|
||||
connect(action, &QAction::triggered, [=] {
|
||||
setExpression(array);
|
||||
if(!_scalarList.contains(array))
|
||||
_scalarList.append(array); });
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
_scalarList.append(array);
|
||||
});
|
||||
} else if(type == "vector") {
|
||||
action = _vectorMenu->addAction(array);
|
||||
connect(action, &QAction::triggered, [=]
|
||||
{
|
||||
connect(action, &QAction::triggered, [=] {
|
||||
setExpression(array);
|
||||
if(!_vectorList.contains(array))
|
||||
_vectorList.append(array); });
|
||||
_vectorList.append(array);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (_isPoint)
|
||||
{
|
||||
if(_isPoint) {
|
||||
QStringList pArray = _parentObject->getPointDataArray();
|
||||
createMenu(pArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QStringList cArray = _parentObject->getCellDataArray();
|
||||
createMenu(cArray);
|
||||
}
|
||||
|
@ -356,4 +350,4 @@ namespace Post
|
|||
_isPoint = false;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Post
|
|
@ -1,20 +1,19 @@
|
|||
#include "DialogRenderSetting.h"
|
||||
#include "ui_DialogRenderSetting.h"
|
||||
|
||||
#include "GraphWidget.h"
|
||||
#include "PostTreeWidget.h"
|
||||
#include "PostInterface/RenderWindowManager.h"
|
||||
#include "PostRenderData/RenderDataObject.h"
|
||||
#include "PostRenderData/RenderProperty.h"
|
||||
#include "PostInterface/RenderWindowManager.h"
|
||||
#include "PostTreeWidget.h"
|
||||
#include "PythonModule/PyAgent.h"
|
||||
#include "ui_DialogRenderSetting.h"
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QHeaderView>
|
||||
|
||||
namespace Post
|
||||
{
|
||||
// RenderSettingDialog::RenderSettingDialog(RenderDataObject* obj, int index, QWidget *parent) :
|
||||
// QDialog(parent),
|
||||
// _ui(new Ui::RenderSettingDialog),
|
||||
// _dataObject(obj)
|
||||
namespace Post {
|
||||
// RenderSettingDialog::RenderSettingDialog(RenderDataObject* obj, int index, QWidget *parent)
|
||||
// : QDialog(parent), _ui(new Ui::RenderSettingDialog), _dataObject(obj)
|
||||
// {
|
||||
// _ui->setupUi(this);
|
||||
// this->setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint);
|
||||
|
@ -31,15 +30,19 @@ namespace Post
|
|||
//
|
||||
// init();
|
||||
//
|
||||
// connect(_ui->variableTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(setColorByVariable(QTreeWidgetItem*)));
|
||||
// connect(_ui->transparencyHorizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int)));
|
||||
// connect(_ui->transparencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int)));
|
||||
// connect(_ui->variableTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this,
|
||||
// SLOT(setColorByVariable(QTreeWidgetItem*))); connect(_ui->transparencyHorizontalSlider,
|
||||
// SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int)));
|
||||
// connect(_ui->transparencySpinBox, SIGNAL(valueChanged(int)), this,
|
||||
// SLOT(setTransparency(const int)));
|
||||
// }
|
||||
|
||||
RenderSettingDialog::RenderSettingDialog(PostTreeWidget *tree, RenderDataObject *obj, QWidget *parent /*= nullptr*/) : QDialog(parent),
|
||||
_ui(new Ui::RenderSettingDialog),
|
||||
_dataObject(obj),
|
||||
_tree(tree)
|
||||
RenderSettingDialog::RenderSettingDialog(PostTreeWidget* tree, RenderDataObject* obj,
|
||||
QWidget* parent /*= nullptr*/)
|
||||
: QDialog(parent)
|
||||
, _ui(new Ui::RenderSettingDialog)
|
||||
, _dataObject(obj)
|
||||
, _tree(tree)
|
||||
{
|
||||
_ui->setupUi(this);
|
||||
|
||||
|
@ -47,7 +50,8 @@ namespace Post
|
|||
this->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
_ui->variableTreeWidget->header()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
_renderWindow = RenderWindowManager::getInstance()->getRenderWindowByID(_dataObject->getRenderWinID());
|
||||
_renderWindow =
|
||||
RenderWindowManager::getInstance()->getRenderWindowByID(_dataObject->getRenderWinID());
|
||||
|
||||
init();
|
||||
}
|
||||
|
@ -59,9 +63,7 @@ namespace Post
|
|||
|
||||
void RenderSettingDialog::init()
|
||||
{
|
||||
|
||||
auto initInterfaceUI = [=](RenderProperty *pro)
|
||||
{
|
||||
auto initInterfaceUI = [=](RenderProperty* pro) {
|
||||
double color[3] = { 0 };
|
||||
pro->getPropertyColor(color);
|
||||
_ui->variableColorPushButton->setStyleSheet(QString("background-color: rgb(%1,%2,%3);")
|
||||
|
@ -72,15 +74,12 @@ namespace Post
|
|||
_ui->transparencyHorizontalSlider->setValue(trans * 100);
|
||||
_ui->transparencySpinBox->setValue(trans * 100);
|
||||
auto type = pro->getVariableType();
|
||||
if (type == 0)
|
||||
{
|
||||
if(type == 0) {
|
||||
_ui->colorBarCheckBox->setChecked(false);
|
||||
_ui->colorBarCheckBox->setEnabled(false);
|
||||
_ui->variableColorCheckBox->setChecked(false);
|
||||
_ui->variableColorCheckBox->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_ui->colorBarCheckBox->setChecked(pro->getShowColorMap());
|
||||
_ui->colorBarCheckBox->setEnabled(true);
|
||||
_ui->variableColorCheckBox->setChecked(true);
|
||||
|
@ -90,18 +89,14 @@ namespace Post
|
|||
|
||||
QMultiHash<int, int> dataList = _tree->getSelectedData(_dataObject);
|
||||
|
||||
if (dataList.size() > 0)
|
||||
{
|
||||
if(dataList.size() > 0) {
|
||||
auto id = dataList.uniqueKeys().at(0);
|
||||
auto index = dataList.values(id).at(0);
|
||||
if (index == -1)
|
||||
{
|
||||
if(index == -1) {
|
||||
auto obj = _dataObject->getObjectByID(id);
|
||||
auto objPro = obj->getPropertyListAt(0);
|
||||
initInterfaceUI(objPro);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
auto objPro = _dataObject->getPropertyListAt(index);
|
||||
initInterfaceUI(objPro);
|
||||
}
|
||||
|
@ -112,9 +107,12 @@ namespace Post
|
|||
initVariableTreeWidget(1, pArrayList);
|
||||
initVariableTreeWidget(2, cArrayList);
|
||||
|
||||
connect(_ui->variableTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(setColorByVariable(QTreeWidgetItem *)));
|
||||
connect(_ui->transparencyHorizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int)));
|
||||
connect(_ui->transparencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int)));
|
||||
connect(_ui->variableTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this,
|
||||
SLOT(setColorByVariable(QTreeWidgetItem*)));
|
||||
connect(_ui->transparencyHorizontalSlider, SIGNAL(valueChanged(int)), this,
|
||||
SLOT(setTransparency(const int)));
|
||||
connect(_ui->transparencySpinBox, SIGNAL(valueChanged(int)), this,
|
||||
SLOT(setTransparency(const int)));
|
||||
}
|
||||
|
||||
void RenderSettingDialog::initVariableTreeWidget(int loc, QStringList arrayList)
|
||||
|
@ -128,8 +126,7 @@ namespace Post
|
|||
//
|
||||
// getCurrentVariable(cVariable, cType, cIndex);
|
||||
|
||||
auto createTreeItem = [=](QString name, QString type, int loc, int index = -1)
|
||||
{
|
||||
auto createTreeItem = [=](QString name, QString type, int loc, int index = -1) {
|
||||
auto item = new QTreeWidgetItem;
|
||||
item->setText(0, name);
|
||||
item->setText(1, type);
|
||||
|
@ -144,23 +141,15 @@ namespace Post
|
|||
// }
|
||||
};
|
||||
|
||||
for (auto name : arrayList)
|
||||
{
|
||||
const int vType = _dataObject->variableType(loc, name);
|
||||
if (vType == 0)
|
||||
;
|
||||
else if (vType == 1)
|
||||
{
|
||||
for(auto name : arrayList) {
|
||||
const auto vType = _dataObject->variableType(loc, name);
|
||||
if(vType == "scalar") {
|
||||
createTreeItem(name, tr("%1Scalar").arg(locName), loc);
|
||||
}
|
||||
else if (vType == 2)
|
||||
{
|
||||
} else if(vType == "vector") {
|
||||
createTreeItem(name, tr("%1Vector-X").arg(locName), loc, 0);
|
||||
createTreeItem(name, tr("%1Vector-Y").arg(locName), loc, 1);
|
||||
createTreeItem(name, tr("%1Vector-Z").arg(locName), loc, 2);
|
||||
}
|
||||
else if (vType == 3)
|
||||
{
|
||||
} else if(vType == "tensor") {
|
||||
createTreeItem(name, tr("%1Tensor").arg(locName), loc);
|
||||
}
|
||||
}
|
||||
|
@ -173,8 +162,7 @@ namespace Post
|
|||
locName = tr("Cell");
|
||||
|
||||
QString typeName;
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case 1:
|
||||
typeName = tr("Scalar");
|
||||
break;
|
||||
|
@ -201,11 +189,9 @@ namespace Post
|
|||
Q_UNUSED(index)
|
||||
// if (_renderProperty == nullptr)
|
||||
// {
|
||||
// auto pro = _dataObject->getPropertyListAt(_dataObject->getPropertyListCount() - 1);
|
||||
// if (pro == nullptr) return;
|
||||
// name = pro->getVariableName();
|
||||
// loc = pro->getVariableType();
|
||||
// index = pro->getComponentIndex();
|
||||
// auto pro = _dataObject->getPropertyListAt(_dataObject->getPropertyListCount() -
|
||||
// 1); if (pro == nullptr) return; name = pro->getVariableName(); loc =
|
||||
// pro->getVariableType(); index = pro->getComponentIndex();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
|
@ -221,23 +207,18 @@ namespace Post
|
|||
|
||||
QMultiHash<int, int> dataList = _tree->getSelectedData(_dataObject);
|
||||
|
||||
for (auto id : dataList.uniqueKeys())
|
||||
{
|
||||
for(auto id : dataList.uniqueKeys()) {
|
||||
auto obj = _dataObject->getObjectByID(id);
|
||||
if(obj == nullptr)
|
||||
continue;
|
||||
|
||||
for (auto bIndex : dataList.values(id))
|
||||
{
|
||||
if (bIndex == -1)
|
||||
{
|
||||
for(auto bIndex : dataList.values(id)) {
|
||||
if(bIndex == -1) {
|
||||
auto cPro = obj->getPropertyListAt(0);
|
||||
if(cPro == nullptr)
|
||||
continue;
|
||||
_propertyList.append(cPro);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
auto bPro = obj->getPropertyListAt(bIndex);
|
||||
if(bPro == nullptr)
|
||||
continue;
|
||||
|
@ -252,8 +233,7 @@ namespace Post
|
|||
QColor c = _ui->variableColorPushButton->palette().color(QPalette::Background);
|
||||
|
||||
QColor color = QColorDialog::getColor(c, this);
|
||||
if (color.isValid())
|
||||
{
|
||||
if(color.isValid()) {
|
||||
_ui->variableColorCheckBox->setChecked(false);
|
||||
_ui->variableColorCheckBox->setEnabled(false);
|
||||
_ui->colorBarCheckBox->setChecked(false);
|
||||
|
@ -272,13 +252,14 @@ namespace Post
|
|||
QStringList codes{};
|
||||
|
||||
codes += QString("variablecolor = PostProcess.VariableColor()");
|
||||
codes += QString("variablecolor.setColor(%1,%2,%3)").arg(color.redF()).arg(color.greenF()).arg(color.blueF());
|
||||
codes += QString("variablecolor.setColor(%1,%2,%3)")
|
||||
.arg(color.redF())
|
||||
.arg(color.greenF())
|
||||
.arg(color.blueF());
|
||||
|
||||
for (auto obj : dataHash.uniqueKeys())
|
||||
{
|
||||
for(auto obj : dataHash.uniqueKeys()) {
|
||||
auto blockList = dataHash.values(obj);
|
||||
for (auto block : blockList)
|
||||
{
|
||||
for(auto block : blockList) {
|
||||
codes += QString("variablecolor.appendBlock(%1,%2)").arg(obj).arg(block);
|
||||
}
|
||||
}
|
||||
|
@ -294,8 +275,7 @@ namespace Post
|
|||
|
||||
void RenderSettingDialog::on_variableColorCheckBox_clicked()
|
||||
{
|
||||
if (!_ui->variableColorCheckBox->isChecked())
|
||||
{
|
||||
if(!_ui->variableColorCheckBox->isChecked()) {
|
||||
_ui->variableColorCheckBox->setEnabled(false);
|
||||
_ui->colorBarCheckBox->setChecked(false);
|
||||
_ui->colorBarCheckBox->setEnabled(false);
|
||||
|
@ -310,13 +290,14 @@ namespace Post
|
|||
QStringList codes{};
|
||||
|
||||
codes += QString("variablecolor = PostProcess.VariableColor()");
|
||||
codes += QString("variablecolor.setColor(%1,%2,%3)").arg(color.redF()).arg(color.greenF()).arg(color.blueF());
|
||||
codes += QString("variablecolor.setColor(%1,%2,%3)")
|
||||
.arg(color.redF())
|
||||
.arg(color.greenF())
|
||||
.arg(color.blueF());
|
||||
|
||||
for (auto obj : dataHash.uniqueKeys())
|
||||
{
|
||||
for(auto obj : dataHash.uniqueKeys()) {
|
||||
auto blockList = dataHash.values(obj);
|
||||
for (auto block : blockList)
|
||||
{
|
||||
for(auto block : blockList) {
|
||||
codes += QString("variablecolor.appendBlock(%1,%2)").arg(obj).arg(block);
|
||||
}
|
||||
}
|
||||
|
@ -332,7 +313,6 @@ namespace Post
|
|||
|
||||
void RenderSettingDialog::on_colorBarCheckBox_clicked()
|
||||
{
|
||||
|
||||
bool show = _ui->colorBarCheckBox->isChecked();
|
||||
|
||||
getRenderPropertyList();
|
||||
|
@ -387,11 +367,9 @@ namespace Post
|
|||
codes += QString("variablecolor = PostProcess.VariableColor()");
|
||||
codes += QString("variablecolor.selectVariable(%1,'%2',%3)").arg(type).arg(name).arg(index);
|
||||
|
||||
for (auto obj : dataHash.uniqueKeys())
|
||||
{
|
||||
for(auto obj : dataHash.uniqueKeys()) {
|
||||
auto blockList = dataHash.values(obj);
|
||||
for (auto block : blockList)
|
||||
{
|
||||
for(auto block : blockList) {
|
||||
codes += QString("variablecolor.appendBlock(%1,%2)").arg(obj).arg(block);
|
||||
}
|
||||
}
|
||||
|
@ -405,4 +383,4 @@ namespace Post
|
|||
_tree->updatePostTree();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Post
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
#include "PostInfoWidget.h"
|
||||
#include "ui_PostInfoWidget.h"
|
||||
|
||||
#include "PostRenderData/RenderDataAlgorithm.h"
|
||||
#include "PostRenderData/RenderDataImportSteady.h"
|
||||
#include "PostRenderData/RenderDataImportUnSteady.h"
|
||||
#include "PostRenderData/RenderDataManager.h"
|
||||
#include "PostRenderData/RenderDataObject.h"
|
||||
#include "PostRenderData/RenderProperty.h"
|
||||
#include "PostRenderData/RenderDataAlgorithm.h"
|
||||
#include "PostRenderData/RenderDataImportUnSteady.h"
|
||||
#include "PostRenderData/RenderDataImportSteady.h"
|
||||
#include "ui_PostInfoWidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QLabel>
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Post {
|
||||
|
||||
namespace Post
|
||||
{
|
||||
|
||||
PostInfoWidget::PostInfoWidget(GUI::MainWindow* m, QWidget* parent) :
|
||||
_ui(new Ui::PostInfoWidget), _parent(parent), _mainWindow(m)
|
||||
PostInfoWidget::PostInfoWidget(GUI::MainWindow* m, QWidget* parent)
|
||||
: _ui(new Ui::PostInfoWidget)
|
||||
, _parent(parent)
|
||||
, _mainWindow(m)
|
||||
{
|
||||
_ui->setupUi(this);
|
||||
_dataManager = RenderDataManager::getInstance();
|
||||
|
@ -25,7 +27,6 @@ namespace Post
|
|||
_ui->tableWidget->setHorizontalHeaderLabels(header);
|
||||
_ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
_ui->tableWidget->verticalHeader()->setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
PostInfoWidget::~PostInfoWidget()
|
||||
|
@ -36,16 +37,11 @@ namespace Post
|
|||
QString PostInfoWidget::enumToString(Post::ObjType type)
|
||||
{
|
||||
QString types;
|
||||
if(type == Post::ObjType::Alg)
|
||||
{
|
||||
if(type == Post::ObjType::Alg) {
|
||||
types = "Alg";
|
||||
}
|
||||
else if(type == Post::ObjType::Imp)
|
||||
{
|
||||
} else if(type == Post::ObjType::Imp) {
|
||||
types = tr("Imp");
|
||||
}
|
||||
else if(type == Post::ObjType::TNone)
|
||||
{
|
||||
} else if(type == Post::ObjType::TNone) {
|
||||
types = "TNone";
|
||||
}
|
||||
return types;
|
||||
|
@ -66,30 +62,46 @@ namespace Post
|
|||
{
|
||||
QString sType = "TNone";
|
||||
auto type = obj->getDataType();
|
||||
if (type == Post::ObjType::Alg)
|
||||
{
|
||||
if(type == Post::ObjType::Alg) {
|
||||
sType = tr("Alg");
|
||||
auto alg = RenderDataAlgorithm::SafeDownCast(obj);
|
||||
if (alg == nullptr) return sType;
|
||||
if(alg == nullptr)
|
||||
return sType;
|
||||
|
||||
switch (alg->getAlgoType())
|
||||
{
|
||||
case Post::ISO: sType = tr("ISOSurface"); break;
|
||||
case Post::ISOCurve: sType = tr("ISOCurve"); break;
|
||||
case Post::Vector: sType = tr("Vector"); break;
|
||||
case Post::Slice: sType = tr("Slice"); break;
|
||||
case Post::Clip: sType = tr("Clip"); break;
|
||||
case Post::StreamLine: sType = tr("StreamLine"); break;
|
||||
case Post::Simplify: sType = tr("Simplify"); break;
|
||||
case Post::Calculator: sType = tr("Calculator"); break;
|
||||
case Post::Reflection: sType = tr("Reflection"); break;
|
||||
switch(alg->getAlgoType()) {
|
||||
case Post::ISO:
|
||||
sType = tr("ISOSurface");
|
||||
break;
|
||||
case Post::ISOCurve:
|
||||
sType = tr("ISOCurve");
|
||||
break;
|
||||
case Post::Vector:
|
||||
sType = tr("Vector");
|
||||
break;
|
||||
case Post::Slice:
|
||||
sType = tr("Slice");
|
||||
break;
|
||||
case Post::Clip:
|
||||
sType = tr("Clip");
|
||||
break;
|
||||
case Post::StreamLine:
|
||||
sType = tr("StreamLine");
|
||||
break;
|
||||
case Post::Simplify:
|
||||
sType = tr("Simplify");
|
||||
break;
|
||||
case Post::Calculator:
|
||||
sType = tr("Calculator");
|
||||
break;
|
||||
case Post::Reflection:
|
||||
sType = tr("Reflection");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (type == Post::ObjType::Imp)
|
||||
{
|
||||
} else if(type == Post::ObjType::Imp) {
|
||||
sType = tr("Steady");
|
||||
auto usteady = RenderDataImportUnSteady::SafeDownCast(obj);
|
||||
if (usteady != nullptr) sType = tr("UnSteady");
|
||||
if(usteady != nullptr)
|
||||
sType = tr("UnSteady");
|
||||
}
|
||||
|
||||
return sType;
|
||||
|
@ -97,46 +109,44 @@ namespace Post
|
|||
|
||||
void PostInfoWidget::updatePostTable(QTreeWidgetItem* item)
|
||||
{
|
||||
if (item == nullptr) return;
|
||||
if(item == nullptr)
|
||||
return;
|
||||
|
||||
bool ok = false;
|
||||
|
||||
int id = item->data(0, Qt::UserRole).toInt(&ok);
|
||||
if (!ok)return;
|
||||
if(!ok)
|
||||
return;
|
||||
|
||||
auto obj = _dataManager->getObjectByID(id);
|
||||
if (obj == nullptr) return;
|
||||
|
||||
if(obj == nullptr)
|
||||
return;
|
||||
|
||||
int index = item->data(1, Qt::UserRole).toInt(&ok);
|
||||
if (!ok) return;
|
||||
if(!ok)
|
||||
return;
|
||||
|
||||
auto setRangeItem = [=](int row, int type, QString var) {
|
||||
int vtype = obj->variableType(type, var);
|
||||
auto vtype = obj->variableType(type, var);
|
||||
double range[2]{ 0 };
|
||||
QString sRange;
|
||||
if (vtype == 1)
|
||||
{
|
||||
if(vtype == "scalar") {
|
||||
obj->getRange(range, type, var, -1);
|
||||
sRange = QString("[%1,%2]").arg(range[0]).arg(range[1]);
|
||||
}
|
||||
else if (vtype == 2)
|
||||
{
|
||||
} else if(vtype == "vector") {
|
||||
obj->getRange(range, type, var, 0);
|
||||
sRange = QString("[%1,%2];").arg(range[0]).arg(range[1]);
|
||||
obj->getRange(range, type, var, 1);
|
||||
sRange += QString("[%1,%2];").arg(range[0]).arg(range[1]);
|
||||
obj->getRange(range, type, var, 2);
|
||||
sRange += QString("[%1,%2]").arg(range[0]).arg(range[1]);
|
||||
}
|
||||
else return;
|
||||
} else
|
||||
return;
|
||||
|
||||
_ui->tableWidget->setItem(row, 3, new QTableWidgetItem(sRange));
|
||||
|
||||
};
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
if(index == -1) {
|
||||
_ui->FileNameValue->setText(obj->getName());
|
||||
_ui->TypeValue->setText(getRenderDataObjectType(obj));
|
||||
_ui->PointNumValue->setText(QString::number(obj->getPointDataNum()));
|
||||
|
@ -150,29 +160,27 @@ namespace Post
|
|||
int Rowcount = PointData.size() + CellData.size();
|
||||
_ui->tableWidget->setRowCount(Rowcount);
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < PointData.size(); i++)
|
||||
{
|
||||
for(int i = 0; i < PointData.size(); i++) {
|
||||
double range[2]{ 0 };
|
||||
obj->getRange(range, 1, PointData[i], -1);
|
||||
|
||||
_ui->tableWidget->setItem(i, 0, new QTableWidgetItem(tr("PointProperty")));
|
||||
_ui->tableWidget->setItem(i, 1, new QTableWidgetItem(PointData[i]));
|
||||
_ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(obj->variableType(1, PointData[i]))));
|
||||
_ui->tableWidget->setItem(i, 2,
|
||||
new QTableWidgetItem(obj->variableType(1, PointData[i])));
|
||||
// qDebug() << obj->variableType(1, PointData[i]);
|
||||
setRangeItem(i, 1, PointData[i]);
|
||||
}
|
||||
for (int j = 0; j < CellData.size(); j++)
|
||||
{
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 0, new QTableWidgetItem(tr("CellProperty")));
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 1, new QTableWidgetItem(CellData[j]));
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 2, new QTableWidgetItem(QString::number(obj->variableType(2, CellData[j]))));
|
||||
for(int j = 0; j < CellData.size(); j++) {
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 0,
|
||||
new QTableWidgetItem(tr("CellProperty")));
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 1,
|
||||
new QTableWidgetItem(CellData[j]));
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 2,
|
||||
new QTableWidgetItem(obj->variableType(2, CellData[j])));
|
||||
setRangeItem(PointData.size() + j, 2, CellData[j]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_ui->FileNameValue->setText(obj->getBlockName(index));
|
||||
_ui->TypeValue->setText(getRenderDataObjectType(obj));
|
||||
_ui->PointNumValue->setText(QString::number(obj->getNumberOfBlockPoints(index + 1)));
|
||||
|
@ -186,22 +194,24 @@ namespace Post
|
|||
int Rowcount = PointData.size() + CellData.size();
|
||||
_ui->tableWidget->setRowCount(Rowcount);
|
||||
|
||||
for (int i = 0; i < PointData.size(); i++)
|
||||
{
|
||||
for(int i = 0; i < PointData.size(); i++) {
|
||||
double range[2]{ 0 };
|
||||
obj->getRange(range, 1, PointData[i], -1);
|
||||
|
||||
_ui->tableWidget->setItem(i, 0, new QTableWidgetItem(tr("PointProperty")));
|
||||
_ui->tableWidget->setItem(i, 1, new QTableWidgetItem(PointData[i]));
|
||||
_ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(obj->variableType(1, PointData[i]))));
|
||||
_ui->tableWidget->setItem(i, 2,
|
||||
new QTableWidgetItem(obj->variableType(1, PointData[i])));
|
||||
// qDebug() << obj->variableType(1, PointData[i]);
|
||||
setRangeItem(i, 1, PointData[i]);
|
||||
}
|
||||
for (int j = 0; j < CellData.size(); j++)
|
||||
{
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 0, new QTableWidgetItem(tr("CellProperty")));
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 1, new QTableWidgetItem(CellData[j]));
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 2, new QTableWidgetItem(QString::number(obj->variableType(2, CellData[j]))));
|
||||
for(int j = 0; j < CellData.size(); j++) {
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 0,
|
||||
new QTableWidgetItem(tr("CellProperty")));
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 1,
|
||||
new QTableWidgetItem(CellData[j]));
|
||||
_ui->tableWidget->setItem(PointData.size() + j, 2,
|
||||
new QTableWidgetItem(obj->variableType(2, CellData[j])));
|
||||
setRangeItem(PointData.size() + j, 2, CellData[j]);
|
||||
}
|
||||
}
|
||||
|
@ -230,15 +240,19 @@ namespace Post
|
|||
//
|
||||
// _ui->tableWidget->setItem(i,0,new QTableWidgetItem("PointProperty"));
|
||||
// _ui->tableWidget->setItem(i,1,new QTableWidgetItem(PointData[i]));
|
||||
// _ui->tableWidget->setItem(i,2,new QTableWidgetItem(QString::number(obj->variableType(1,PointData[i]))));
|
||||
// _ui->tableWidget->setItem(i,2,new
|
||||
// QTableWidgetItem(QString::number(obj->variableType(1,PointData[i]))));
|
||||
// qDebug()<<obj->variableType(1,PointData[i]);
|
||||
//
|
||||
// }
|
||||
// for(int j=0; j<CellData.size(); j++)
|
||||
// {
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,0,new QTableWidgetItem("CellProperty"));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,1,new QTableWidgetItem(CellData[j]));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,2,new QTableWidgetItem(QString::number(obj->variableType(2,CellData[j]))));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,0,new
|
||||
// QTableWidgetItem("CellProperty"));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,1,new
|
||||
// QTableWidgetItem(CellData[j]));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,2,new
|
||||
// QTableWidgetItem(QString::number(obj->variableType(2,CellData[j]))));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
@ -262,23 +276,23 @@ namespace Post
|
|||
//
|
||||
// _ui->tableWidget->setItem(i,0,new QTableWidgetItem("PointProperty"));
|
||||
// _ui->tableWidget->setItem(i,1,new QTableWidgetItem(PointData[i]));
|
||||
// _ui->tableWidget->setItem(i,2,new QTableWidgetItem(QString::number(obj->variableType(1,PointData[i]))));
|
||||
// _ui->tableWidget->setItem(i,2,new
|
||||
// QTableWidgetItem(QString::number(obj->variableType(1,PointData[i]))));
|
||||
// qDebug()<<obj->variableType(1,PointData[i]);
|
||||
//
|
||||
// }
|
||||
// for(int j=0; j<CellData.size(); j++)
|
||||
// {
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,0,new QTableWidgetItem("CellProperty"));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,1,new QTableWidgetItem(CellData[j]));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,2,new QTableWidgetItem(QString::number(obj->variableType(2,CellData[j]))));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,0,new
|
||||
// QTableWidgetItem("CellProperty"));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,1,new
|
||||
// QTableWidgetItem(CellData[j]));
|
||||
// _ui->tableWidget->setItem(PointData.size()+j,2,new
|
||||
// QTableWidgetItem(QString::number(obj->variableType(2,CellData[j]))));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace Post
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "PostRenderData/StreamLineRenderDataAlg.h"
|
||||
#include "PostRenderData/CalculateRenderDataAlg.h"
|
||||
#include "PostRenderData/ReflectionRenderDataAlg.h"
|
||||
#include "MainWindow/MainWindow.h"
|
||||
|
||||
namespace Post
|
||||
{
|
||||
|
@ -57,10 +56,13 @@ namespace Post
|
|||
{
|
||||
RenderDataObject *dataObj = nullptr;
|
||||
if (FileDirectoryDialog::isGourpFiles(file))
|
||||
{
|
||||
dataObj = new RenderDataImportUnSteady(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataObj = new RenderDataImportSteady(file);
|
||||
|
||||
}
|
||||
dataObj->update();
|
||||
|
||||
auto dataset = dataObj->getOutputData();
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include <vtkDataSetWriter.h>
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
#include <vtkXMLUnstructuredGridReader.h>
|
||||
#include <vtkXMLPUnstructuredGridReader.h>
|
||||
|
||||
namespace Post
|
||||
{
|
||||
|
@ -97,6 +99,26 @@ namespace Post
|
|||
mapper->SetInputConnection(_vtkAlg->GetOutputPort(i + 1));
|
||||
}
|
||||
}
|
||||
else if (_Suffix == "vtu")
|
||||
{
|
||||
CreateVTKSmartPtr(vtkXMLUnstructuredGridReader, _vtkAlg) auto r = vtkXMLUnstructuredGridReader::SafeDownCast(_vtkAlg);
|
||||
QString2Char(_FileName, c);
|
||||
r->SetFileName(c);
|
||||
r->Update();
|
||||
_blockNumber = 1;
|
||||
auto mapper = createMapper(true);
|
||||
mapper->SetInputConnection(_vtkAlg->GetOutputPort(0));
|
||||
}
|
||||
else if (_Suffix == "pvtu")
|
||||
{
|
||||
CreateVTKSmartPtr(vtkXMLPUnstructuredGridReader, _vtkAlg) auto r = vtkXMLPUnstructuredGridReader::SafeDownCast(_vtkAlg);
|
||||
QString2Char(_FileName, c);
|
||||
r->SetFileName(c);
|
||||
r->Update();
|
||||
_blockNumber = 1;
|
||||
auto mapper = createMapper(true);
|
||||
mapper->SetInputConnection(_vtkAlg->GetOutputPort(0));
|
||||
}
|
||||
}
|
||||
|
||||
RenderDataImportSteady *RenderDataImportSteady::SafeDownCast(RenderDataObject *obj)
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "PostAlgorithm/CGNSReaderAlgorithm.h"
|
||||
#include "PostAlgorithm/Plot3DReaderAlgorithm.h"
|
||||
#include "Macros.hxx"
|
||||
#include <vtkXMLUnstructuredGridReader.h>
|
||||
#include <vtkXMLPUnstructuredGridReader.h>
|
||||
|
||||
namespace Post {
|
||||
QStringList getSelectGroupFiles(const QString path)
|
||||
|
@ -124,7 +126,26 @@ namespace Post {
|
|||
auto mapper = createMapper(true);
|
||||
mapper->SetInputConnection(_vtkAlg->GetOutputPort(i + 1));
|
||||
}
|
||||
|
||||
}
|
||||
else if (Suffix == "vtu")
|
||||
{
|
||||
CreateVTKSmartPtr(vtkXMLUnstructuredGridReader, _vtkAlg)
|
||||
auto r = vtkXMLUnstructuredGridReader::SafeDownCast(_vtkAlg);
|
||||
QString2Char(fileName, c)
|
||||
r->SetFileName(c);
|
||||
_blockNumber = 1;
|
||||
auto mapper = createMapper(true);
|
||||
mapper->SetInputConnection(_vtkAlg->GetOutputPort(0));
|
||||
}
|
||||
else if (Suffix == "pvtu")
|
||||
{
|
||||
CreateVTKSmartPtr(vtkXMLPUnstructuredGridReader, _vtkAlg)
|
||||
auto r = vtkXMLPUnstructuredGridReader::SafeDownCast(_vtkAlg);
|
||||
QString2Char(fileName, c)
|
||||
r->SetFileName(c);
|
||||
_blockNumber = 1;
|
||||
auto mapper = createMapper(true);
|
||||
mapper->SetInputConnection(_vtkAlg->GetOutputPort(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,6 +170,18 @@ namespace Post {
|
|||
QString2Char(f, c);
|
||||
r->SetFileName(c);
|
||||
}
|
||||
else if (this->getSuffix() == "vtu")
|
||||
{
|
||||
auto r = vtkXMLUnstructuredGridReader::SafeDownCast(_vtkAlg);
|
||||
QString2Char(f, c);
|
||||
r->SetFileName(c);
|
||||
}
|
||||
else if (this->getSuffix() == "pvtu")
|
||||
{
|
||||
auto r = vtkXMLPUnstructuredGridReader::SafeDownCast(_vtkAlg);
|
||||
QString2Char(f, c);
|
||||
r->SetFileName(c);
|
||||
}
|
||||
}
|
||||
|
||||
RenderDataImportUnSteady::~RenderDataImportUnSteady()
|
||||
|
|
|
@ -201,9 +201,9 @@ QStringList RenderDataObject::getBlockCellDataArray(int index)
|
|||
return nameList;
|
||||
}
|
||||
|
||||
int RenderDataObject::variableType(int vaLocation, QString vaName)
|
||||
QString RenderDataObject::variableType(int vaLocation, QString vaName)
|
||||
{
|
||||
int type = 0;
|
||||
QString type = "Unknown";
|
||||
vtkDataSet* data = getOutputData();
|
||||
if (data == nullptr) return 0;
|
||||
QString2Char(vaName, cName)
|
||||
|
@ -215,11 +215,11 @@ int RenderDataObject::variableType(int vaLocation, QString vaName)
|
|||
if (dataArray == nullptr) return 0;
|
||||
const int cNum = dataArray->GetNumberOfComponents();
|
||||
if (cNum == 1)
|
||||
type = 1;
|
||||
type = "scalar";
|
||||
else if (cNum == 3)
|
||||
type = 2;
|
||||
else if (cNum >= 4)
|
||||
type = 3;
|
||||
type = "vector";
|
||||
else if (cNum == 9)
|
||||
type = "tensor";
|
||||
return type;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,9 +120,10 @@ namespace Post {
|
|||
* @brief 获取变量类型
|
||||
* @param vaLocation 变量所在位置 1-pointData 2-cellData
|
||||
* @param vaName 变量名称
|
||||
* @return int 变量类型 1-标量 2-矢量 3-张量 0-错误值
|
||||
* @return QString 变量类型:scalar\vector\tensor\Unknown
|
||||
* @note 在vtk中通过分量数量判断数据类型并不是十分准确
|
||||
*/
|
||||
int variableType(int vaLocation, QString vaName);
|
||||
QString variableType(int vaLocation, QString vaName);
|
||||
/**
|
||||
* @brief 获取变量成员数量
|
||||
* @param vaLocation 变量所在位置 1-pointData 2-cellData
|
||||
|
|
|
@ -27,6 +27,8 @@ add_library(PythonModule
|
|||
#-----------------------------------------------------------------------------
|
||||
target_compile_definitions(PythonModule PRIVATE "PYTHONMODULE_API")
|
||||
|
||||
list(APPEND _depend_library Common)
|
||||
|
||||
list(APPEND _runtimes_libraries
|
||||
Qt5::Widgets FASTCAE::PYTHON
|
||||
)
|
||||
|
@ -39,7 +41,14 @@ endif()
|
|||
#-----------------------------------------------------------------------------
|
||||
# 链接依赖库
|
||||
#-----------------------------------------------------------------------------
|
||||
target_link_libraries(PythonModule ${_runtimes_libraries})
|
||||
target_link_libraries(PythonModule
|
||||
${_runtimes_libraries}
|
||||
${_depend_library})
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# 添加依赖关系
|
||||
#-----------------------------------------------------------------------------
|
||||
add_dependencies(PythonModule ${_depend_library})
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# 添加运行时依赖关系
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
#include <Python.h>
|
||||
#include "PyAgent.h"
|
||||
#include <QString>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <wchar.h>
|
||||
#include "PyAgent.h"
|
||||
#include "MainWindow/MainWindow.h"
|
||||
#include "PyInterpreter.h"
|
||||
#include "RecordScript.h"
|
||||
#include "ScriptReader.h"
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QTextStream>
|
||||
#include <wchar.h>
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#include <atlconv.h>
|
||||
|
@ -19,8 +18,7 @@
|
|||
|
||||
#include <locale.h>
|
||||
|
||||
namespace Py
|
||||
{
|
||||
namespace Py {
|
||||
PythonAgent* PythonAgent::_instance = nullptr;
|
||||
|
||||
PythonAgent* PythonAgent::getInstance()
|
||||
|
@ -33,7 +31,8 @@ namespace Py
|
|||
|
||||
void PythonAgent::connectSignals()
|
||||
{
|
||||
connect(this, SIGNAL(printInfo(Common::Message, QString)), _mainWindow, SIGNAL(printMessageSig(Common::Message, QString)));
|
||||
connect(this, SIGNAL(printInfo(Common::Message, QString)), _mainWindow,
|
||||
SIGNAL(printMessageSig(Common::Message, QString)));
|
||||
connect(this, SIGNAL(closeMainWindow()), _mainWindow, SIGNAL(closeMainWindow()));
|
||||
}
|
||||
|
||||
|
@ -54,33 +53,6 @@ namespace Py
|
|||
{
|
||||
_mainWindow = m;
|
||||
connectSignals();
|
||||
/*
|
||||
QString path = qApp->applicationDirPath() + "/../python37";
|
||||
path = QDir::cleanPath(path);
|
||||
char *ch;
|
||||
QByteArray ba = path.toLocal8Bit();
|
||||
ch = ba.data();
|
||||
wchar_t *wc;
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
USES_CONVERSION;
|
||||
wc = A2W(ch);
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
setlocale(LC_CTYPE, "zh_CN.utf8");
|
||||
int w_size = mbstowcs(NULL, ba, 0) + 1;
|
||||
wc = new wchar_t[w_size];
|
||||
mbstowcs(wc, ba, strlen(ba) + 1);
|
||||
#endif
|
||||
|
||||
QDir d(path);
|
||||
if (d.exists())
|
||||
{
|
||||
#ifdef Q_OS_WIN32
|
||||
Py_SetPythonHome(wc);
|
||||
#endif
|
||||
}*/
|
||||
Py_SetProgramName(L"FastCAE");
|
||||
Py_Initialize();
|
||||
if(!_interpreter->init(this))
|
||||
|
@ -93,10 +65,8 @@ namespace Py
|
|||
|
||||
void PythonAgent::finalize()
|
||||
{
|
||||
if (_reader != nullptr)
|
||||
{
|
||||
if (_reader->isRunning())
|
||||
{
|
||||
if(_reader != nullptr) {
|
||||
if(_reader->isRunning()) {
|
||||
_reader->stop();
|
||||
_reader->quit();
|
||||
_reader->wait();
|
||||
|
@ -121,13 +91,10 @@ namespace Py
|
|||
|
||||
void PythonAgent::submit(QString code, bool s)
|
||||
{
|
||||
// this->lock();
|
||||
qDebug() << "submit: " << code;
|
||||
emit printInfo(Common::Message::Python, code);
|
||||
// lock();
|
||||
int ok = _interpreter->execCode(code, s);
|
||||
if (ok == -1)
|
||||
{
|
||||
if(ok == -1) {
|
||||
if(_reader != nullptr)
|
||||
_reader->restart();
|
||||
}
|
||||
|
@ -136,8 +103,7 @@ namespace Py
|
|||
void PythonAgent::submit(QStringList codes, bool save /*= true*/)
|
||||
{
|
||||
const int n = codes.size();
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
for(int i = 0; i < n; ++i) {
|
||||
this->submit(codes.at(i), save);
|
||||
}
|
||||
}
|
||||
|
@ -145,15 +111,13 @@ namespace Py
|
|||
void PythonAgent::saveScript(QString fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::Text | QIODevice::WriteOnly))
|
||||
{
|
||||
if(!file.open(QIODevice::Text | QIODevice::WriteOnly)) {
|
||||
emit printInfo(Common::Message::Error, tr("Script open failed"));
|
||||
return;
|
||||
}
|
||||
QTextStream stream(&file);
|
||||
const int n = _interpreter->getCodeCount();
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
for(int i = 0; i < n; ++i) {
|
||||
QString s = _interpreter->getCodeAt(i);
|
||||
stream << s << endl;
|
||||
}
|
||||
|
@ -229,4 +193,4 @@ namespace Py
|
|||
{
|
||||
_interpreter->execCode(code, false);
|
||||
}
|
||||
}
|
||||
} // namespace Py
|
|
@ -8,14 +8,13 @@
|
|||
#include <string>
|
||||
#include <QReadWriteLock>
|
||||
#include "Common/Types.h"
|
||||
#include "Common/DebugLogger.h"
|
||||
|
||||
namespace Py
|
||||
{
|
||||
namespace Py {
|
||||
|
||||
bool PyInterpreter::init(PythonAgent* agent)
|
||||
{
|
||||
if (!Py_IsInitialized())
|
||||
{
|
||||
if(!Py_IsInitialized()) {
|
||||
return false;
|
||||
}
|
||||
_agent = agent;
|
||||
|
@ -31,8 +30,7 @@ namespace Py
|
|||
suffix << "*.py";
|
||||
dir.setNameFilters(suffix);
|
||||
QList<QFileInfo> files = dir.entryInfoList(suffix);
|
||||
for (int i = 0; i < files.size(); ++i)
|
||||
{
|
||||
for(int i = 0; i < files.size(); ++i) {
|
||||
QFileInfo fileinfo = files.at(i);
|
||||
QString name = fileinfo.baseName();
|
||||
QString command = QString("import %1").arg(name);
|
||||
|
@ -48,12 +46,12 @@ namespace Py
|
|||
lock.lockForRead();
|
||||
std::string s = code.toStdString();
|
||||
const char* c = s.c_str();
|
||||
qDebug() << "exec: " << code;
|
||||
|
||||
DebugInfo("Exec python script: %s\n", code.toStdString().c_str());
|
||||
|
||||
int ok = PyRun_SimpleStringFlags(c, NULL);
|
||||
|
||||
if (ok == -1)
|
||||
{
|
||||
if(ok == -1) {
|
||||
QString error = QString(tr("Exception occurred at: \"%1\"")).arg(code);
|
||||
_agent->printInfo(Common::Message::Warning, error);
|
||||
}
|
||||
|
@ -96,4 +94,4 @@ namespace Py
|
|||
{
|
||||
return _codelist;
|
||||
}
|
||||
}
|
||||
} // namespace Py
|
|
@ -47,7 +47,6 @@ SARibbonMainWindow::SARibbonMainWindow(QWidget *parent, bool useRibbon)
|
|||
{
|
||||
m_d->init();
|
||||
m_d->useRibbon = useRibbon;
|
||||
qDebug() << windowFlags();
|
||||
if (useRibbon) {
|
||||
qDebug() << "sa ribbon version:" << SA_RIBBON_BAR_VERSION_STR;
|
||||
setRibbonTheme(ribbonTheme());
|
||||
|
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 102 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 218 B |
Before Width: | Height: | Size: 1011 B After Width: | Height: | Size: 116 B |
Before Width: | Height: | Size: 1010 B After Width: | Height: | Size: 116 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 319 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 214 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 247 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 272 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 406 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 133 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 129 B |
Before Width: | Height: | Size: 1014 B After Width: | Height: | Size: 120 B |
Before Width: | Height: | Size: 1016 B After Width: | Height: | Size: 115 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 475 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 377 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 152 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 160 B |
Before Width: | Height: | Size: 1013 B After Width: | Height: | Size: 122 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 208 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 342 B |
Before Width: | Height: | Size: 1018 B After Width: | Height: | Size: 127 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 240 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 462 B |
Before Width: | Height: | Size: 405 KiB After Width: | Height: | Size: 360 KiB |
Before Width: | Height: | Size: 961 B After Width: | Height: | Size: 736 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 886 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 991 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 538 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 691 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 458 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 680 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 531 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 525 B |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 513 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 602 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 621 B |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 534 B |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 590 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 532 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 646 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 208 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 753 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 461 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 572 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 582 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 948 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 504 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 562 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 499 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 543 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 538 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 382 B |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 754 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 457 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 588 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 654 B |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 768 B |