forked from jaheyns/CfdOF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_TaskPanelCfdFluidProperties.py
125 lines (108 loc) · 5.81 KB
/
_TaskPanelCfdFluidProperties.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
# ***************************************************************************
# * *
# * (c) Bernd Hahnebach ([email protected]) 2014 *
# * (c) Qingfeng Xia @ iesensor.com 2016 *
# * Copyright (c) 2017-2018 Johan Heyns (CSIR) <[email protected]> *
# * Copyright (c) 2017-2018 Oliver Oxtoby (CSIR) <[email protected]> *
# * Copyright (c) 2017-2018 Alfred Bogaers (CSIR) <[email protected]> *
# * Copyright (c) 2019 Oliver Oxtoby <[email protected]> *
# * *
# * 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 os
import os.path
import CfdTools
from CfdTools import setQuantity, getQuantity
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtGui
class TaskPanelCfdFluidProperties:
""" Task Panel for FluidMaterial objects """
def __init__(self, obj, physics_obj):
self.obj = obj
self.physics_obj = physics_obj
self.form = FreeCADGui.PySideUic.loadUi(os.path.join(os.path.dirname(__file__),
"TaskPanelCfdFluidProperties.ui"))
self.material = self.obj.Material
self.import_materials()
self.form.PredefinedMaterialLibraryComboBox.addItem("Custom")
self.form.PredefinedMaterialLibraryComboBox.currentIndexChanged.connect(self.selectPredefine)
self.text_boxes = {}
self.fields = []
self.createTextBoxesBasedOnPhysics()
self.selecting_predefined = True
try:
self.form.PredefinedMaterialLibraryComboBox.setCurrentIndex(
self.form.PredefinedMaterialLibraryComboBox.findText(self.material['Name']))
self.selectPredefine()
finally:
self.selecting_predefined = False
def createTextBoxesBasedOnPhysics(self):
if self.physics_obj.Flow == 'Incompressible':
self.fields = ['Density', 'DynamicViscosity']
else:
self.fields = ['MolarMass', 'Cp', 'SutherlandTemperature', 'SutherlandRefTemperature', 'SutherlandRefViscosity']
self.text_boxes = {}
for name in self.fields:
widget = FreeCADGui.UiLoader().createWidget("Gui::InputField")
widget.setObjectName(name)
widget.setProperty("format", "g")
val = self.material.get(name, '0')
widget.setProperty("unit", val)
widget.setProperty("minimum", 0)
widget.setProperty("singleStep", 0.1)
self.form.propertiesLayout.addRow(name+":", widget)
self.text_boxes[name] = widget
setQuantity(widget, val)
widget.valueChanged.connect(self.manualEdit)
def selectPredefine(self):
index = self.form.PredefinedMaterialLibraryComboBox.currentIndex()
mat_file_path = self.form.PredefinedMaterialLibraryComboBox.itemData(index)
if mat_file_path:
self.material = self.materials[mat_file_path]
self.selecting_predefined = True
try:
for m in self.fields:
setQuantity(self.text_boxes[m], self.material.get(m, ''))
finally:
self.selecting_predefined = False
self.form.fluidDescriptor.setText(self.material["Description"])
def manualEdit(self):
if not self.selecting_predefined:
self.form.PredefinedMaterialLibraryComboBox.setCurrentIndex(
self.form.PredefinedMaterialLibraryComboBox.findText('Custom'))
self.material = {'Name': 'Custom', 'Description': 'User-entered properties'}
for f in self.fields:
self.material[f] = getQuantity(self.text_boxes[f])
self.selectPredefine()
def accept(self):
doc = FreeCADGui.getDocument(self.obj.Document)
doc.resetEdit()
doc.Document.recompute()
FreeCADGui.doCommand("\nFreeCAD.ActiveDocument." + self.obj.Name + ".Material"
" = {}".format(self.material))
def reject(self):
#self.remove_active_sel_server()
doc = FreeCADGui.getDocument(self.obj.Document)
doc.resetEdit()
def import_materials(self):
self.form.PredefinedMaterialLibraryComboBox.clear()
self.materials, material_name_path_list = CfdTools.importMaterials()
for mat in material_name_path_list:
self.form.PredefinedMaterialLibraryComboBox.addItem(QtGui.QIcon(":/icons/freecad.svg"), mat[0], mat[1])