forked from jaheyns/CfdOF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCfdPhysicsSelection.py
187 lines (153 loc) · 8.87 KB
/
CfdPhysicsSelection.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# ***************************************************************************
# * *
# * Copyright (c) 2017-2018 Alfred Bogaers (CSIR) <abogaers@csir.co.za> *
# * Copyright (c) 2017-2018 Johan Heyns (CSIR) <jheyns@csir.co.za> *
# * Copyright (c) 2017-2018 Oliver Oxtoby (CSIR) <ooxtoby@csir.co.za> *
# * Copyright (c) 2019 Oliver Oxtoby <oliveroxtoby@gmail.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 *
# * *
# ***************************************************************************
import FreeCAD
import CfdTools
from CfdTools import addObjectProperty
import os
import os.path
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore
def makeCfdPhysicsSelection(name="PhysicsModel"):
# DocumentObjectGroupPython, FeaturePython, GeometryPython
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", name)
_CfdPhysicsModel(obj)
if FreeCAD.GuiUp:
_ViewProviderPhysicsSelection(obj.ViewObject)
return obj
class _CommandCfdPhysicsSelection:
""" CFD physics selection command definition """
def GetResources(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "physics.png")
return {'Pixmap': icon_path,
'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_PhysicsModel", "Select models"),
'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_PhysicsModel", "Select the physics model")}
def IsActive(self):
return CfdTools.getActiveAnalysis() is not None
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Choose appropriate physics model")
isPresent = False
members = CfdTools.getActiveAnalysis().Group
for i in members:
if isinstance(i.Proxy, _CfdPhysicsModel):
FreeCADGui.activeDocument().setEdit(i.Name)
isPresent = True
# Allow to re-create if deleted
if not isPresent:
FreeCADGui.doCommand("")
FreeCADGui.addModule("CfdPhysicsSelection")
FreeCADGui.addModule("CfdTools")
FreeCADGui.doCommand(
"CfdTools.getActiveAnalysis().addObject(CfdPhysicsSelection.makeCfdPhysicsSelection())")
FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Cfd_PhysicsModel', _CommandCfdPhysicsSelection())
class _CfdPhysicsModel:
""" The CFD Physics Model """
def __init__(self, obj):
obj.Proxy = self
self.Type = "PhysicsModel"
self.initProperties(obj)
def initProperties(self, obj):
# obj.supportedProperties()
# ['App::PropertyBool', 'App::PropertyBoolList', 'App::PropertyFloat', 'App::PropertyFloatList',
# 'App::PropertyFloatConstraint', 'App::PropertyPrecision', 'App::PropertyQuantity',
# 'App::PropertyQuantityConstraint', 'App::PropertyAngle', 'App::PropertyDistance', 'App::PropertyLength',
# 'App::PropertyArea', 'App::PropertyVolume', 'App::PropertySpeed', 'App::PropertyAcceleration',
# 'App::PropertyForce', 'App::PropertyPressure', 'App::PropertyInteger', 'App::PropertyIntegerConstraint',
# 'App::PropertyPercent', 'App::PropertyEnumeration', 'App::PropertyIntegerList', 'App::PropertyIntegerSet',
# 'App::PropertyMap', 'App::PropertyString', 'App::PropertyUUID', 'App::PropertyFont',
# 'App::PropertyStringList', 'App::PropertyLink', 'App::PropertyLinkChild', 'App::PropertyLinkGlobal',
# 'App::PropertyLinkSub', 'App::PropertyLinkSubChild', 'App::PropertyLinkSubGlobal', 'App::PropertyLinkList',
# 'App::PropertyLinkListChild', 'App::PropertyLinkListGlobal', 'App::PropertyLinkSubList',
# 'App::PropertyLinkSubListChild', 'App::PropertyLinkSubListGlobal', 'App::PropertyMatrix',
# 'App::PropertyVector', 'App::PropertyVectorDistance', 'App::PropertyPosition', 'App::PropertyDirection',
# 'App::PropertyVectorList', 'App::PropertyPlacement', 'App::PropertyPlacementList',
# 'App::PropertyPlacementLink', 'App::PropertyColor', 'App::PropertyColorList', 'App::PropertyMaterial',
# 'App::PropertyMaterialList', 'App::PropertyPath', 'App::PropertyFile', 'App::PropertyFileIncluded',
# 'App::PropertyPythonObject', 'App::PropertyExpressionEngine', 'Part::PropertyPartShape',
# 'Part::PropertyGeometryList', 'Part::PropertyShapeHistory', 'Part::PropertyFilletEdges',
# 'Fem::PropertyFemMesh', 'Fem::PropertyPostDataObject']
if addObjectProperty(obj, "Time", ['Steady', 'Transient'], "App::PropertyEnumeration", "Physics modelling",
"Resolve time dependence"):
obj.Time = 'Steady'
if addObjectProperty(obj, "Flow", ['Incompressible', 'Compressible', 'HighMachCompressible'],
"App::PropertyEnumeration", "Physics modelling", "Flow algorithm"):
obj.Flow = 'Incompressible'
if addObjectProperty(obj, "Thermal", ['None', 'Energy'], "App::PropertyEnumeration", "Physics modelling",
"Thermal modelling"):
obj.Thermal = 'None'
if addObjectProperty(obj, "Phase", ['Single', 'FreeSurface'], "App::PropertyEnumeration", "Physics modelling",
"Type of phases present"):
obj.Phase = 'Single'
if addObjectProperty(obj, "Turbulence", ['Inviscid', 'Laminar', 'RANS'], "App::PropertyEnumeration",
"Physics modelling", "Type of turbulence modelling"):
obj.Turbulence = ['Inviscid', 'Laminar', 'RANS']
addObjectProperty(obj, "TurbulenceModel", ['kOmegaSST'], "App::PropertyEnumeration", "Physics modelling",
"Turbulence model")
addObjectProperty(obj, "gx", '0 m/s^2', "App::PropertyAcceleration", "Physics modelling",
"Gravitational acceleration vector (x component)")
addObjectProperty(obj, "gy", '-9.81 m/s^2', "App::PropertyAcceleration", "Physics modelling",
"Gravitational acceleration vector (y component)")
addObjectProperty(obj, "gz", '0 m/s^2', "App::PropertyAcceleration", "Physics modelling",
"Gravitational acceleration vector (z component)")
def onDocumentRestored(self, obj):
self.initProperties(obj)
class _ViewProviderPhysicsSelection:
def __init__(self, vobj):
vobj.Proxy = self
def getIcon(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "physics.png")
return icon_path
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
self.bubbles = None
def updateData(self, obj, prop):
return
def onChanged(self, vobj, prop):
return
def setEdit(self, vobj, mode):
import _TaskPanelCfdPhysicsSelection
taskd = _TaskPanelCfdPhysicsSelection._TaskPanelCfdPhysicsSelection(self.Object)
taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(taskd)
return True
def unsetEdit(self, vobj, mode):
FreeCADGui.Control.closeDialog()
return
def doubleClicked(self, vobj):
# Make sure no other task dialog still active
doc = FreeCADGui.getDocument(vobj.Object.Document)
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Existing task dialog already open\n')
return True
def __getstate__(self):
return None
def __setstate__(self, state):
return None