目录
- gmsh模块界面
- 获取gmsh的版本
- 执行gmsh网格划分
gmsh模块界面
这个界面是用PySide来写的,Pyside是QT的python绑定,具体代码在task_mesh_gmsh.py文件中。目前这个界面非常的捡漏,没有对接gmsh稍微高级一点的功能。界面对应的事件处理是在gmshtools.py中。这里只分析“gmsh version”与“Apply”运行gmsh功能。
def get_gmsh_command(self):
from platform import system
gmsh_std_location = FreeCAD.ParamGet(
"User parameter:BaseApp/Preferences/Mod/Fem/Gmsh"
).GetBool("UseStandardGmshLocation")
Console.PrintError("UseStandardGmshLocation = ".format(gmsh_std_location))
if gmsh_std_location:
if system() == "Windows": # windows
gmsh_path = FreeCAD.getHomePath() + "bin/gmsh.exe"
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/Gmsh").SetString(
"gmshBinaryPath", gmsh_path
)
self.gmsh_bin = gmsh_path
elif system() == "Linux":
p1 = subprocess.Popen(["which", "gmsh"], stdout=subprocess.PIPE)
if p1.wait() == 0:
output = p1.stdout.read()
output = output.decode("utf-8")
gmsh_path = output.split("\n")[0]
elif p1.wait() == 1:
error_message = (
"Gmsh binary gmsh not found in standard system binary path. "
"Please install Gmsh or set path to binary "
"in FEM preferences tab Gmsh.\n"
)
Console.PrintError(error_message)
raise GmshError(error_message)
self.gmsh_bin = gmsh_path
elif system() == "Darwin":
# https://forum.freecad.org/viewtopic.php?f=13&t=73041&p=642026#p642022
gmsh_path = "/Applications/Gmsh.app/Contents/MacOS/gmsh"
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/Gmsh").SetString(
"gmshBinaryPath", gmsh_path
)
self.gmsh_bin = gmsh_path
else:
error_message = (
"No standard location implemented for your operating system. "
"Set GMHS binary path in FEM preferences.\n"
)
Console.PrintError(error_message)
raise GmshError(error_message)
else:
if not self.gmsh_bin:
self.gmsh_bin = FreeCAD.ParamGet(
"User parameter:BaseApp/Preferences/Mod/Fem/Gmsh"
).GetString("gmshBinaryPath", "")
Console