forked from qingfengxia/Cfd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_CommandCfdAnalysisFromMesh.py
80 lines (68 loc) · 4.14 KB
/
_CommandCfdAnalysisFromMesh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# ***************************************************************************
# * *
# * Copyright (c) 2015-2017- qingfeng xia <qingfengxia@iesensor.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
__title__ = "Command New Analysis from existing geometry and mesh files"
__author__ = "Qingfeng Xia"
__url__ = "http://www.freecadweb.org"
import os.path
import FreeCAD
from _CfdCommand import CfdCommand
import CfdTools
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore
from PySide import QtGui
from PySide.QtGui import QFileDialog # in QtWidgets for Qt5
class _CommandCfdAnalysisFromMesh(CfdCommand):
"the Cfd_AnalysisFromMesh command definition"
def __init__(self):
super(_CommandCfdAnalysisFromMesh, self).__init__()
icon_path = os.path.join(CfdTools.getModulePath(), "Resources", "icons", "cfd-analysis-from-mesh.svg")
self.resources = {'Pixmap': icon_path,
'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_AnalysisFromMesh", "Analysis from external mesh"),
'Accel': "N, E",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_AnalysisFromMesh", "Creates a analysis container from existing geometry and mesh files")}
self.is_active = 'with_document'
def Activated(self):
filters = u"IDES mesh (*.unv);;Med mesh(*.med);;VTK mesh (*.vtk *.vtu)"
mesh_file = QFileDialog.getOpenFileName(None, u"Open mesh files", u"./", filters)
mesh_file = mesh_file[0]
# why return a tuple of filename and selectedfilter
import CfdTools
if not CfdTools.getActiveAnalysis():
CfdTools.createAnalysis()
FreeCADGui.addModule("CfdTools")
sel = FreeCADGui.Selection.getSelection()
if (len(sel) == 1) and (sel[0].isDerivedFrom("Part::Feature")):
# using existing part_feature, no need to import geometry, but get obj as link
geo_obj = sel[0]
CfdTools.importGeometryAndMesh(geo_obj, mesh_file) #Todo: macro recording is yet support
else:
filters = u"BREP (*.brep *.brp);;STEP (*.step *.stp);;IGES (*.iges *.igs);; FcStd (*.fcstd)"
geo_file = QFileDialog.getOpenFileName(None, u"Open geometry files", u"./", filters)
geo_file = geo_file[0]
FreeCADGui.doCommand("CfdTools.importGeometryAndMesh(u'{}', u'{}')".format(geo_file, mesh_file))
FreeCADGui.Selection.clearSelection()
FreeCADGui.addModule("FemGui")
#if FemGui.getActiveAnalysis(): # besides addModule, FemGui need to be imported
FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(App.ActiveDocument.ActiveObject)")
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Cfd_AnalysisFromMesh', _CommandCfdAnalysisFromMesh())