From 57061f40af4cd98d056a0d68e483ab17730333c3 Mon Sep 17 00:00:00 2001 From: Yoann Audouin Date: Thu, 15 Sep 2022 14:06:22 +0200 Subject: [PATCH] Switchin to QProcess instead of sytem for remote compute --- src/NETGENPlugin/CMakeLists.txt | 5 +++ src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx | 42 ++++++++++++++++----- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/NETGENPlugin/CMakeLists.txt b/src/NETGENPlugin/CMakeLists.txt index c97dd9b..e28fea2 100644 --- a/src/NETGENPlugin/CMakeLists.txt +++ b/src/NETGENPlugin/CMakeLists.txt @@ -17,9 +17,12 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +INCLUDE(UseQtExt) + # --- options --- # additional include directories INCLUDE_DIRECTORIES( + ${QT_INCLUDES} ${KERNEL_INCLUDE_DIRS} ${GUI_INCLUDE_DIRS} ${GEOM_INCLUDE_DIRS} @@ -35,6 +38,7 @@ INCLUDE_DIRECTORIES( # additional preprocessor / compiler flags ADD_DEFINITIONS( + ${QT_DEFINITIONS} ${OMNIORB_DEFINITIONS} ${OpenCASCADE_DEFINITIONS} ${BOOST_DEFINITIONS} @@ -66,6 +70,7 @@ SET(_link_LIBRARIES VTK::CommonCore VTK::CommonDataModel SalomeIDLNETGENPLUGIN + Qt5::Core ) # --- headers --- diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx index 347f4c3..c69f50f 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx @@ -69,6 +69,9 @@ #include #include +#include +#include + #include #include namespace fs = boost::filesystem; @@ -350,6 +353,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh, fs::path("bin")/ fs::path("salome")/ fs::path("NETGENPlugin_Runner"); + cmd = run_mesher_exe.string() + " NETGEN3D " + mesh_file.string() + " " + shape_file.string() + " " @@ -357,19 +361,36 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh, + element_orientation_file.string() + " " + std::to_string(aMesh.GetMesherNbThreads()) + " " + new_element_file.string() + " " - + "NONE" + - " >> " + log_file.string(); - - //std::cout << "Running command: " << std::endl; - //std::cout << cmd << std::endl; - + + "NONE"; // Writing command in log { std::ofstream flog(log_file.string()); flog << cmd << endl; + flog << endl; } - // TODO: Replace system by something else to handle redirection for windows - int ret = system(cmd.c_str()); + //std::cout << "Running command: " << std::endl; + //std::cout << cmd << std::endl; + + + // Building arguments for QProcess + QString program = run_mesher_exe.c_str(); + QStringList arguments; + arguments << "NETGEN3D"; + arguments << mesh_file.c_str(); + arguments << shape_file.c_str(); + arguments << param_file.c_str(); + arguments << element_orientation_file.c_str(); + arguments << std::to_string(aMesh.GetMesherNbThreads()).c_str(); + arguments << new_element_file.c_str(); + arguments << "NONE"; + QString out_file = log_file.c_str(); + QProcess myProcess; + myProcess.setStandardOutputFile(out_file); + + myProcess.start(program, arguments); + myProcess.waitForFinished(); + int ret = myProcess.exitStatus(); + auto time5 = std::chrono::high_resolution_clock::now(); elapsed = std::chrono::duration_cast(time5-time4); std::cout << "Time for exec of run_mesher: " << elapsed.count() * 1e-9 << std::endl; @@ -377,8 +398,9 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh, // TODO: better error handling (display log ?) if(ret != 0){ // Run crahed - std::cerr << "Issue with command: " << std::endl; - std::cerr << cmd << std::endl; + std::cout << "Issue with command: " << std::endl; + std::cout << "See log for more detail: " << log_file.string() << std::endl; + std::cout << cmd << std::endl; return false; }