FEM: Add "None" and simplify material setting
The "-->choose Material" has been replaced with a not defined material. That makes setting/retrieving material to/from the object much easier and allows user to have a "not defined" material. Previously it wasn't possible to change i.e. form Steel to "not defined". Signed-off-by: Przemo Firszt <przemo@firszt.eu>
This commit is contained in:
parent
aec082639f
commit
54bb4e297e
|
@ -106,7 +106,6 @@ class _ViewProviderMechanicalMaterial:
|
|||
def setEdit(self,vobj,mode):
|
||||
taskd = _MechanicalMaterialTaskPanel(self.Object)
|
||||
taskd.obj = vobj.Object
|
||||
taskd.update()
|
||||
FreeCADGui.Control.showDialog(taskd)
|
||||
return True
|
||||
|
||||
|
@ -130,9 +129,16 @@ class _MechanicalMaterialTaskPanel:
|
|||
self.params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem")
|
||||
|
||||
QtCore.QObject.connect(self.form.pushButton_MatWeb, QtCore.SIGNAL("clicked()"), self.goMatWeb)
|
||||
QtCore.QObject.connect(self.form.comboBox_MaterialsInDir, QtCore.SIGNAL("currentIndexChanged(int)"), self.chooseMat)
|
||||
|
||||
self.update()
|
||||
QtCore.QObject.connect(self.form.comboBox_MaterialsInDir, QtCore.SIGNAL("activated(int)"), self.chooseMat)
|
||||
self.previous_material = self.obj.Material
|
||||
self.fillMaterialCombo()
|
||||
matmap = self.obj.Material
|
||||
if 'General_name' in matmap:
|
||||
material_name = matmap['General_name']
|
||||
new_index = self.form.comboBox_MaterialsInDir.findText(material_name)
|
||||
if new_index != -1:
|
||||
self.form.comboBox_MaterialsInDir.setCurrentIndex(new_index)
|
||||
self.set_mat_params_in_combo_box(matmap)
|
||||
|
||||
def print_mat_data(self, matmap):
|
||||
print 'material data:'
|
||||
|
@ -143,56 +149,18 @@ class _MechanicalMaterialTaskPanel:
|
|||
if 'FEM_poissonratio' in matmap:
|
||||
print ' PR = ', matmap['FEM_poissonratio']
|
||||
|
||||
def transferTo(self):
|
||||
"Transfer from the dialog to the object"
|
||||
|
||||
matmap = self.obj.Material
|
||||
|
||||
matmap['Mechanical_youngsmodulus'] = self.form.input_fd_young_modulus.text()
|
||||
matmap['FEM_poissonratio'] = str(self.form.spinBox_poisson_ratio.value())
|
||||
print self.form.comboBox_MaterialsInDir.currentText()
|
||||
|
||||
self.obj.Material = matmap
|
||||
self.print_mat_data(matmap)
|
||||
|
||||
def transferFrom(self):
|
||||
"Transfer from the object to the dialog"
|
||||
matmap = self.obj.Material
|
||||
|
||||
def set_mat_params_in_combo_box(self, matmap):
|
||||
if 'Mechanical_youngsmodulus' in matmap:
|
||||
#print matmap['Mechanical_youngsmodulus']
|
||||
self.form.input_fd_young_modulus.setText(matmap['Mechanical_youngsmodulus'])
|
||||
if 'FEM_poissonratio' in matmap:
|
||||
#print float(matmap['FEM_poissonratio'])
|
||||
self.form.spinBox_poisson_ratio.setValue(float(matmap['FEM_poissonratio']))
|
||||
|
||||
def isAllowedAlterSelection(self):
|
||||
return False
|
||||
|
||||
def isAllowedAlterView(self):
|
||||
return True
|
||||
|
||||
def getStandardButtons(self):
|
||||
return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Cancel)
|
||||
|
||||
def update(self):
|
||||
'fills the widgets'
|
||||
#self.form.input_fd_young_modulus.setValue(0.0)
|
||||
#self.form.spinBox_poisson_ratio.setValue(0.0)
|
||||
self.transferFrom()
|
||||
self.fillMaterialCombo()
|
||||
|
||||
return
|
||||
|
||||
def accept(self):
|
||||
#print 'accept(self)'
|
||||
self.transferTo()
|
||||
FreeCADGui.ActiveDocument.resetEdit()
|
||||
|
||||
def reject(self):
|
||||
#print 'reject(self)'
|
||||
matmap = self.obj.Material
|
||||
self.print_mat_data(matmap)
|
||||
self.obj.Material = self.previous_material
|
||||
self.print_mat_data(self.previous_material)
|
||||
FreeCADGui.ActiveDocument.resetEdit()
|
||||
|
||||
# Function not yet used
|
||||
|
@ -207,35 +175,27 @@ class _MechanicalMaterialTaskPanel:
|
|||
import webbrowser
|
||||
webbrowser.open("http://matweb.com")
|
||||
|
||||
def chooseMat(self,index):
|
||||
if index <= 0:
|
||||
def chooseMat(self, index):
|
||||
if index < 0:
|
||||
return
|
||||
import Material
|
||||
#print index
|
||||
name = self.pathList[index - 1]
|
||||
#print 'Import ', str(name)
|
||||
|
||||
name = self.pathList[index]
|
||||
self.obj.Material = Material.importFCMat(str(name))
|
||||
#print self.obj.Material
|
||||
|
||||
self.transferFrom()
|
||||
self.form.comboBox_MaterialsInDir.setCurrentIndex(index)
|
||||
self.set_mat_params_in_combo_box(self.obj.Material)
|
||||
self.print_mat_data(self.obj.Material)
|
||||
|
||||
def fillMaterialCombo(self):
|
||||
import glob
|
||||
import os
|
||||
mat_file_extension = ".FCMat"
|
||||
dirname = FreeCAD.getResourceDir()+"/Mod/Material/StandardMaterial"
|
||||
self.pathList = glob.glob(dirname + '/*.FCMat')
|
||||
self.pathList = glob.glob(dirname + '/*' + mat_file_extension)
|
||||
self.form.comboBox_MaterialsInDir.clear()
|
||||
'''if(matmap.has_key('General_name')):
|
||||
self.form.comboBox_MaterialsInDir.addItem(matmap['General_name'])
|
||||
else:
|
||||
self.form.comboBox_MaterialsInDir.addItem('-> choose Material')
|
||||
'''
|
||||
# workaraound: since material data is not loaded into spinBoxes the user has
|
||||
# to choose the material every time the MechanincalMaterialWidget is opened
|
||||
self.form.comboBox_MaterialsInDir.addItem('-> choose Material')
|
||||
l = len(mat_file_extension)
|
||||
for i in self.pathList:
|
||||
self.form.comboBox_MaterialsInDir.addItem(os.path.basename(i))
|
||||
material_name = os.path.basename(i[:-l])
|
||||
self.form.comboBox_MaterialsInDir.addItem(material_name)
|
||||
|
||||
|
||||
FreeCADGui.addCommand('Fem_MechanicalMaterial',_CommandMechanicalMaterial())
|
||||
|
|
|
@ -14,6 +14,7 @@ SOURCE_GROUP("Module" FILES ${Material_SRCS})
|
|||
#FILE( GLOB MaterialLib_Files ./StandardMaterial/*.FCMat ./StandardMaterial/*.txt )
|
||||
|
||||
SET (MaterialLib_Files
|
||||
StandardMaterial/None.FCMat
|
||||
StandardMaterial/ABS.FCMat
|
||||
StandardMaterial/CalculiX.FCMat
|
||||
StandardMaterial/Concrete.FCMat
|
||||
|
|
27
src/Mod/Material/StandardMaterial/None.FCMat
Normal file
27
src/Mod/Material/StandardMaterial/None.FCMat
Normal file
|
@ -0,0 +1,27 @@
|
|||
; Standard Not Defined Material
|
||||
; (c) 2015 Przemo Firszt (CC-BY 3.0)
|
||||
; information about the content of such cards you can find here:
|
||||
; http://www.freecadweb.org/wiki/index.php?title=Material
|
||||
|
||||
[General]
|
||||
Name = None
|
||||
Father = None
|
||||
; more elaborate description of this material card:
|
||||
Description: This is a not defined material
|
||||
; Specific wight in kg/mm^3
|
||||
SpecificWeight = 0.0
|
||||
; No special Vendor
|
||||
Vendor:
|
||||
; For blend materials the wikipedia page is a good source of information:
|
||||
ProductURL =
|
||||
; for blends a rough estimation Euro/Kg
|
||||
SpecificPrice = 0.0
|
||||
|
||||
[Mechanical]
|
||||
; youngs modulus (or E-Module or Modulus of Elasticty) (source: http://en.wikipedia.org/wiki/Young%27s_modulus)
|
||||
YoungsModulus=0 MPa
|
||||
; http://en.wikipedia.org/wiki/Ultimate_tensile_strength in
|
||||
UltimateTensileStrength= 0 MPa
|
||||
|
||||
[FEM]
|
||||
PoissonRatio = 0.0
|
Loading…
Reference in New Issue
Block a user