forked from jaheyns/CfdOF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCfdFluidMaterial.py
More file actions
163 lines (133 loc) · 6.45 KB
/
CfdFluidMaterial.py
File metadata and controls
163 lines (133 loc) · 6.45 KB
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
# ***************************************************************************
# * *
# * Copyright (c) 2013-2015 - Juergen Riegel <FreeCAD@juergen-riegel.net> *
# * Copyright (c) 2017-2018 Oliver Oxtoby (CSIR) <ooxtoby@csir.co.za> *
# * Copyright (c) 2017-2018 Alfred Bogaers (CSIR) <abogaers@csir.co.za> *
# * Copyright (c) 2017-2018 Johan Heyns (CSIR) <jheyns@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
import os
from CfdTools import addObjectProperty
if FreeCAD.GuiUp:
import FreeCADGui
def makeCfdFluidMaterial(name):
obj = FreeCAD.ActiveDocument.addObject("App::MaterialObjectPython", name)
_CfdMaterial(obj) # Include default fluid properties
if FreeCAD.GuiUp:
_ViewProviderCfdFluidMaterial(obj.ViewObject)
return obj
class _CommandCfdFluidMaterial:
def GetResources(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "material.png")
return {
'Pixmap': icon_path,
'MenuText': 'Add fluid properties',
'ToolTip': 'Add fluid properties'
}
def IsActive(self):
return CfdTools.getActiveAnalysis() is not None
def Activated(self):
FreeCAD.Console.PrintMessage("Set fluid properties \n")
FreeCAD.ActiveDocument.openTransaction("Set CfdFluidMaterialProperty")
FreeCADGui.doCommand("")
FreeCADGui.addModule("CfdTools")
FreeCADGui.addModule("CfdFluidMaterial")
editing_existing = False
analysis_object = CfdTools.getActiveAnalysis()
if analysis_object is None:
CfdTools.cfdError("No active analysis object found")
return False
physics_model = CfdTools.getPhysicsModel(analysis_object)
if not physics_model or physics_model.Phase == 'Single':
members = analysis_object.Group
for i in members:
if isinstance(i.Proxy, _CfdMaterial):
FreeCADGui.activeDocument().setEdit(i.Name)
editing_existing = True
if not editing_existing:
FreeCADGui.doCommand(
"CfdTools.getActiveAnalysis().addObject(CfdFluidMaterial.makeCfdFluidMaterial('FluidProperties'))")
FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Cfd_FluidMaterial', _CommandCfdFluidMaterial())
class _CfdMaterial:
""" CFD material properties object. Compatible with FreeCAD material object. """
def __init__(self, obj):
obj.Proxy = self
self.Type = "CfdMaterial"
self.initProperties(obj)
def initProperties(self, obj):
# Not currently used
addObjectProperty(obj, "References", [], "App::PropertyLinkSubList", "Material", "List of material shapes")
# Compatibility with FEM material object
if addObjectProperty(
obj, "Category", ["Solid", "Fluid"], "App::PropertyEnumeration", "Material", "Type of material"):
obj.Category = "Fluid"
# 'Material' PropertyMap already present in MaterialObjectPython
if not obj.Material:
mats, name_path_list = CfdTools.importMaterials()
obj.Material = mats[name_path_list[[np[0] for np in name_path_list].index('Air')][1]]
def onDocumentRestored(self, obj):
self.initProperties(obj)
def execute(self, obj):
return
class _ViewProviderCfdFluidMaterial:
def __init__(self, vobj):
vobj.Proxy = self
def getIcon(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "material.png")
return icon_path
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
def updateData(self, obj, prop):
return
def onChanged(self, vobj, prop):
return
def doubleClicked(self, vobj):
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 setEdit(self, vobj, mode):
analysis_object = CfdTools.getParentAnalysisObject(self.Object)
if analysis_object is None:
CfdTools.cfdError("No parent analysis object found")
return False
physics_model = CfdTools.getPhysicsModel(analysis_object)
if not physics_model:
CfdTools.cfdError("Analysis object must have a physics object")
return False
import _TaskPanelCfdFluidProperties
taskd = _TaskPanelCfdFluidProperties.TaskPanelCfdFluidProperties(self.Object, physics_model)
taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(taskd)
return True
def unsetEdit(self, vobj, mode):
FreeCADGui.Control.closeDialog()
return
def __getstate__(self):
return None
def __setstate__(self, state):
return None