From a495693c9df31f5e7b503900e8b06cb804513457 Mon Sep 17 00:00:00 2001 From: jriegel Date: Sun, 11 Aug 2013 23:08:43 +0200 Subject: [PATCH] Update Fem workbench Adding new materials and making some of the objects to python objects --- src/Mod/Fem/App/CMakeLists.txt | 5 +- src/Mod/Fem/FemLib.py | 27 + src/Mod/Fem/Gui/AppFemGui.cpp | 7 + src/Mod/Fem/Gui/CMakeLists.txt | 5 +- src/Mod/Fem/Gui/Resources/Fem.qrc | 15 +- .../Gui/Resources/icons/Fem_AddFemMesh.svg | 243 ++++++++ .../Gui/Resources/icons/Fem_AddMaterial.svg | 523 ++++++++++++++++++ .../Fem/Gui/Resources/icons/Fem_AddPart.svg | 446 +++++++++++++++ .../Fem/Gui/Resources/icons/Fem_Material.svg | 513 +++++++++++++++++ .../Gui/Resources/icons/Fem_NewAnalysis.svg | 454 +++++++++++++++ src/Mod/Fem/Gui/Workbench.cpp | 3 + src/Mod/Fem/MechanicalAnalysis.py | 256 +++++++++ src/Mod/Fem/MechanicalAnalysis.ui | 126 +++++ src/Mod/Fem/MechanicalMaterial.py | 244 ++++++++ src/Mod/Fem/MechanicalMaterial.ui | 126 +++++ src/Mod/Material/CMakeLists.txt | 17 +- src/Mod/Material/StandardMaterial/ABS.FCMat | 26 + src/Mod/Material/StandardMaterial/PLA.FCMat | 26 + src/Mod/Material/StandardMaterial/Readme.txt | 3 +- src/Mod/Material/StandardMaterial/Steel.FCMat | 4 +- 20 files changed, 3052 insertions(+), 17 deletions(-) create mode 100644 src/Mod/Fem/Gui/Resources/icons/Fem_AddFemMesh.svg create mode 100644 src/Mod/Fem/Gui/Resources/icons/Fem_AddMaterial.svg create mode 100644 src/Mod/Fem/Gui/Resources/icons/Fem_AddPart.svg create mode 100644 src/Mod/Fem/Gui/Resources/icons/Fem_Material.svg create mode 100644 src/Mod/Fem/Gui/Resources/icons/Fem_NewAnalysis.svg create mode 100644 src/Mod/Fem/MechanicalAnalysis.py create mode 100644 src/Mod/Fem/MechanicalAnalysis.ui create mode 100644 src/Mod/Fem/MechanicalMaterial.py create mode 100644 src/Mod/Fem/MechanicalMaterial.ui create mode 100644 src/Mod/Material/StandardMaterial/ABS.FCMat create mode 100644 src/Mod/Material/StandardMaterial/PLA.FCMat diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index 48639d6f7a..f4cc6dd989 100755 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -132,7 +132,10 @@ fc_target_copy_resource(Fem ${Driver_Resources} Init.py convert2TetGen.py - FemLib.py) + FemLib.py + MechanicalAnalysis.py + MechanicalMaterial.py + ) if(MSVC) diff --git a/src/Mod/Fem/FemLib.py b/src/Mod/Fem/FemLib.py index e69de29bb2..98985ab84d 100644 --- a/src/Mod/Fem/FemLib.py +++ b/src/Mod/Fem/FemLib.py @@ -0,0 +1,27 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2013 - Juergen Riegel * +#* * +#* 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 * +#* * +#*************************************************************************** + +def DebugLoad(): + import MechanicalAnalysis,MechanicalMaterial + reload(MechanicalAnalysis) + reload(MechanicalMaterial) + \ No newline at end of file diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index 798384a471..fa02cbabb5 100755 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -27,6 +27,7 @@ #endif #include +#include #include #include #include "ViewProviderFemMesh.h" @@ -93,6 +94,12 @@ void FemGuiExport initFemGui() FemGui::ViewProviderFemConstraintGear ::init(); FemGui::ViewProviderFemConstraintPulley ::init(); + Base::Interpreter().loadModule("MechanicalAnalysis"); + Base::Interpreter().loadModule("MechanicalMaterial"); + + Base::Interpreter().loadModule("FemLib"); + + // add resources and reloads the translators loadFemResource(); } diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 8ef615d568..12b341317b 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -195,7 +195,10 @@ target_link_libraries(FemGui ${FemGui_LIBS}) fc_target_copy_resource(FemGui ${CMAKE_SOURCE_DIR}/src/Mod/Fem ${CMAKE_BINARY_DIR}/Mod/Fem - InitGui.py) + InitGui.py + MechanicalMaterial.ui + MechanicalAnalysis.ui + ) if(MSVC) set_target_properties(FemGui PROPERTIES SUFFIX ".pyd") diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index a93dcf0990..76eda4df41 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -2,11 +2,16 @@ icons/Fem_FemMesh.svg icons/Fem_FemMesh_createnodebypoly.svg - icons/Fem_ConstraintForce.svg - icons/Fem_ConstraintFixed.svg - icons/Fem_ConstraintBearing.svg - icons/Fem_ConstraintGear.svg - icons/Fem_ConstraintPulley.svg + icons/Fem_ConstraintForce.svg + icons/Fem_ConstraintFixed.svg + icons/Fem_ConstraintBearing.svg + icons/Fem_ConstraintGear.svg + icons/Fem_ConstraintPulley.svg + icons/Fem_AddFemMesh.svg + icons/Fem_AddMaterial.svg + icons/Fem_AddPart.svg + icons/Fem_Material.svg + icons/Fem_NewAnalysis.svg translations/Fem_af.qm translations/Fem_de.qm translations/Fem_fi.qm diff --git a/src/Mod/Fem/Gui/Resources/icons/Fem_AddFemMesh.svg b/src/Mod/Fem/Gui/Resources/icons/Fem_AddFemMesh.svg new file mode 100644 index 0000000000..94f86b9c34 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/Fem_AddFemMesh.svg @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Fem/Gui/Resources/icons/Fem_AddMaterial.svg b/src/Mod/Fem/Gui/Resources/icons/Fem_AddMaterial.svg new file mode 100644 index 0000000000..c7ddb7ab43 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/Fem_AddMaterial.svg @@ -0,0 +1,523 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/Mod/Fem/Gui/Resources/icons/Fem_AddPart.svg b/src/Mod/Fem/Gui/Resources/icons/Fem_AddPart.svg new file mode 100644 index 0000000000..8081c63f4a --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/Fem_AddPart.svg @@ -0,0 +1,446 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/Mod/Fem/Gui/Resources/icons/Fem_Material.svg b/src/Mod/Fem/Gui/Resources/icons/Fem_Material.svg new file mode 100644 index 0000000000..c31d075649 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/Fem_Material.svg @@ -0,0 +1,513 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/Mod/Fem/Gui/Resources/icons/Fem_NewAnalysis.svg b/src/Mod/Fem/Gui/Resources/icons/Fem_NewAnalysis.svg new file mode 100644 index 0000000000..f9fa2ddda7 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/Fem_NewAnalysis.svg @@ -0,0 +1,454 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index a29ba5c04c..105cad2181 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -74,6 +74,9 @@ Gui::MenuItem* Workbench::setupMenuBar() const root->insertItem(item, fem); fem->setCommand("&FEM"); *fem << "Fem_CreateFromShape" + << "Fem_MechanicalMaterial" + << "Fem_NewMechanicalAnalysis" + << "Fem_MechanicalJobControl" << "Fem_CreateAnalysis" << "Fem_CreateNodesSet" << "Fem_ConstraintFixed" diff --git a/src/Mod/Fem/MechanicalAnalysis.py b/src/Mod/Fem/MechanicalAnalysis.py new file mode 100644 index 0000000000..49ca9fe6f6 --- /dev/null +++ b/src/Mod/Fem/MechanicalAnalysis.py @@ -0,0 +1,256 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2013 - Juergen Riegel * +#* * +#* 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, Fem, os,sys,string,math,shutil,glob,subprocess,tempfile +from ApplyingBC_IC import ApplyingBC_IC + +if FreeCAD.GuiUp: + import FreeCADGui,FemGui + from FreeCAD import Vector + from PyQt4 import QtCore, QtGui + from pivy import coin + import PyQt4.uic as uic + +__title__="Machine-Distortion Analysis managment" +__author__ = "Juergen Riegel" +__url__ = "http://free-cad.sourceforge.net" + + +def makeMechanicalAnalysis(name): + '''makeFemAnalysis(name): makes a Fem Analysis object''' + obj = FreeCAD.ActiveDocument.addObject("Fem::FemAnalysisPython",name) + _FemAnalysis(obj) + _ViewProviderFemAnalysis(obj.ViewObject) + #FreeCAD.ActiveDocument.recompute() + return obj + + +class _CommandNewMechanicalAnalysis: + "the Fem Analysis command definition" + def GetResources(self): + return {'Pixmap' : 'Fem_NewAnalysis', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_Analysis","New mechanical analysis"), + 'Accel': "A", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_Analysis","Create a new mechanical analysis")} + + def Activated(self): + FreeCAD.ActiveDocument.openTransaction("Create Analysis") + FreeCADGui.addModule("FemGui") + FreeCADGui.addModule("MechanicalAnalysis") + #FreeCADGui.doCommand("FreeCADGui.ActiveDocument.ActiveView.setAxisCross(True)") + FreeCADGui.doCommand("MechanicalAnalysis.makeMechanicalAnalysis('MechanicalAnalysis')") + FreeCADGui.doCommand("FemGui.setActiveAnalysis(App.activeDocument().ActiveObject)") + sel = FreeCADGui.Selection.getSelection() + if (len(sel) == 1): + if(sel[0].isDerivedFrom("Fem::FemMeshObject")): + FreeCADGui.doCommand("App.activeDocument().ActiveObject.Member = App.activeDocument().ActiveObject.Member + [App.activeDocument()."+sel[0].Name+"]") + if(sel[0].isDerivedFrom("Part::Feature")): + FreeCADGui.doCommand("App.activeDocument().addObject('Fem::FemMeshShapeNetgenObject','"+sel[0].Name +"_Mesh')") + FreeCADGui.doCommand("App.activeDocument().ActiveObject.Shape = App.activeDocument()."+sel[0].Name) + FreeCADGui.doCommand("FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [App.activeDocument().ActiveObject]") + FreeCADGui.doCommand("Gui.activeDocument().hide('"+sel[0].Name+"')") + #FreeCADGui.doCommand("App.activeDocument().ActiveObject.touch()") + #FreeCADGui.doCommand("App.activeDocument().recompute()") + FreeCADGui.doCommand("Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name)") + + FreeCAD.ActiveDocument.commitTransaction() + FreeCADGui.Selection.clearSelection() + + def IsActive(self): + import FemGui + return FreeCADGui.ActiveDocument != None and FemGui.getActiveAnalysis() == None + +class _CommandMechanicalJobControl: + "the Fem JobControl command definition" + def GetResources(self): + return {'Pixmap' : 'Fem_NewAnalysis', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_JobControl","Start calculation"), + 'Accel': "A", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_Analysis","Dialog to start the calculation of the machanical anlysis")} + + def Activated(self): + taskd = _JobControlTaskPanel() + #taskd.obj = vobj.Object + taskd.update() + FreeCADGui.Control.showDialog(taskd) + + + def IsActive(self): + import FemGui + return True + + +class _FemAnalysis: + "The Material object" + def __init__(self,obj): + self.Type = "FemAnalysis" + obj.Proxy = self + #obj.Material = StartMat + obj.addProperty("App::PropertyString","OutputDir","Base","Directory where the jobs get generated") + obj.addProperty("App::PropertyFloat","PlateThikness","Base","Thikness of the plate") + + + def execute(self,obj): + return + + def onChanged(self,obj,prop): + if prop in ["MaterialName"]: + return + + def __getstate__(self): + return self.Type + + def __setstate__(self,state): + if state: + self.Type = state + +class _ViewProviderFemAnalysis: + "A View Provider for the Material object" + + def __init__(self,vobj): + #vobj.addProperty("App::PropertyLength","BubbleSize","Base", str(translate("Fem","The size of the axis bubbles"))) + vobj.Proxy = self + + def getIcon(self): + return ":/icons/Fem_FemMesh.svg" + + + 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 doubleClicked(self,vobj): + taskd = _JobControlTaskPanel(self.Object) + taskd.obj = vobj.Object + taskd.update() + FreeCADGui.Control.showDialog(taskd) + return True + + + def __getstate__(self): + return None + + def __setstate__(self,state): + return None + + +class _JobControlTaskPanel: + '''The editmode TaskPanel for Material objects''' + def __init__(self,object): + # the panel has a tree widget that contains categories + # for the subcomponents, such as additions, subtractions. + # the categories are shown only if they are not empty. + form_class, base_class = uic.loadUiType(FreeCAD.getHomePath() + "Mod/Machining_Distortion/JobControl.ui") + + self.obj = object + self.formUi = form_class() + self.form = QtGui.QWidget() + self.formUi.setupUi(self.form) + self.params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Machining_Distortion") + + #Connect Signals and Slots + QtCore.QObject.connect(self.formUi.toolButton_chooseOutputDir, QtCore.SIGNAL("clicked()"), self.chooseOutputDir) + QtCore.QObject.connect(self.formUi.pushButton_generate, QtCore.SIGNAL("clicked()"), self.generate) + + self.update() + + + + def getStandardButtons(self): + return int(QtGui.QDialogButtonBox.Close) + + def update(self): + 'fills the widgets' + self.formUi.lineEdit_outputDir.setText(self.params.GetString("JobDir",'/')) + return + + def accept(self): + FreeCADGui.Control.closeDialog() + + + def reject(self): + FreeCADGui.Control.closeDialog() + + def chooseOutputDir(self): + print "chooseOutputDir" + dirname = QtGui.QFileDialog.getExistingDirectory(None, 'Choose material directory',self.params.GetString("JobDir",'/')) + if(dirname): + self.params.SetString("JobDir",str(dirname)) + self.formUi.lineEdit_outputDir.setText(dirname) + + def run(self): + print "pushButton_generate" + print self.formUi.lineEdit_outputDir.text() + dirName = self.formUi.lineEdit_outputDir.text() + + MeshObject = None + if FemGui.getActiveAnalysis(): + for i in FemGui.getActiveAnalysis().Member: + if i.isDerivedFrom("Fem::FemMeshObject"): + MeshObject = i + else: + QtGui.QMessageBox.critical(None, "Missing prerequisit","No active Analysis") + return + + if not MeshObject: + QtGui.QMessageBox.critical(None, "Missing prerequisit","No mesh object in the Analysis") + return + + MathObject = None + for i in FemGui.getActiveAnalysis().Member: + if i.isDerivedFrom("App::MaterialObjectPython"): + MathObject = i + if not MathObject: + QtGui.QMessageBox.critical(None, "Missing prerequisit","No material object in the Analysis") + return + matmap = MathObject.Material + + IsoNodeObject = None + for i in FemGui.getActiveAnalysis().Member: + if i.isDerivedFrom("Fem::FemSetNodesObject"): + IsoNodeObject = i + if not IsoNodeObject: + QtGui.QMessageBox.critical(None, "Missing prerequisit","No Isostatic nodes defined in the Analysis") + return + IsoNodes = IsoNodeObject.Nodes + + filename_without_suffix = MeshObject.Name + #current_file_name + + young_modulus = float(matmap['FEM_youngsmodulus']) + poisson_ratio = float(matmap['PartDist_poissonratio']) + + + + + + +FreeCADGui.addCommand('Fem_NewMechanicalAnalysis',_CommandNewMechanicalAnalysis()) +FreeCADGui.addCommand('Fem_MechanicalJobControl',_CommandMechanicalJobControl()) diff --git a/src/Mod/Fem/MechanicalAnalysis.ui b/src/Mod/Fem/MechanicalAnalysis.ui new file mode 100644 index 0000000000..812e6e7423 --- /dev/null +++ b/src/Mod/Fem/MechanicalAnalysis.ui @@ -0,0 +1,126 @@ + + + MechanicalMaterial + + + + 0 + 0 + 194 + 142 + + + + Form + + + + + + + choose... + + + + + + + + + + MatWeb database... + + + + + + + + + Qt::Horizontal + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + + 60 + 20 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 999999.989999999990687 + + + 70000.000000000000000 + + + + + + + Young Modulus (KPa) + + + + + + + + 0 + 0 + + + + + 60 + 20 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0.100000000000000 + + + 0.300000000000000 + + + + + + + Poisson Ratio + + + + + + + + + + diff --git a/src/Mod/Fem/MechanicalMaterial.py b/src/Mod/Fem/MechanicalMaterial.py new file mode 100644 index 0000000000..3525ded729 --- /dev/null +++ b/src/Mod/Fem/MechanicalMaterial.py @@ -0,0 +1,244 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2013 - Juergen Riegel * +#* * +#* 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, Fem + +if FreeCAD.GuiUp: + import FreeCADGui,FemGui + from FreeCAD import Vector + from PyQt4 import QtCore, QtGui + from pivy import coin + import PyQt4.uic as uic + +__title__="Machine-Distortion FemSetGeometryObject managment" +__author__ = "Juergen Riegel" +__url__ = "http://free-cad.sourceforge.net" + +StartMat = {'FEM_youngsmodulus' :'7000.00', + 'PartDist_poissonratio' :'0.30', + } + + +def makeMechanicalMaterial(name): + '''makeMaterial(name): makes an Material + name there fore is a material name or an file name for a FCMat file''' + obj = FreeCAD.ActiveDocument.addObject("App::MaterialObjectPython",name) + _MechanicalMaterial(obj) + _ViewProviderMechanicalMaterial(obj.ViewObject) + #FreeCAD.ActiveDocument.recompute() + return obj + +class _CommandMechanicalMaterial: + "the Fem Material command definition" + def GetResources(self): + return {'Pixmap' : 'Fem_Material', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_Material","Mechanical material..."), + 'Accel': "A, X", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_Material","Creates or edit the mechanical material definition.")} + + def Activated(self): + MatObj = None + for i in FemGui.getActiveAnalysis().Member: + if i.isDerivedFrom("App::MaterialObject"): + MatObj = i + + if (not MatObj): + FreeCAD.ActiveDocument.openTransaction("Create Material") + FreeCADGui.addModule("MechanicalMaterial") + FreeCADGui.doCommand("mat = MechanicalMaterial.makeMechanicalMaterial('Material')") + FreeCADGui.doCommand("App.activeDocument()."+FemGui.getActiveAnalysis().Name+".Member = App.activeDocument()."+FemGui.getActiveAnalysis().Name+".Member + [mat]") + FreeCADGui.doCommand("Gui.activeDocument().setEdit(mat.Name,0)") + #FreeCADGui.doCommand("Fem.makeMaterial()") + else: + FreeCADGui.doCommand("Gui.activeDocument().setEdit('"+MatObj.Name+"',0)") + + def IsActive(self): + if FemGui.getActiveAnalysis(): + return True + else: + return False + + +class _MechanicalMaterial: + "The Material object" + def __init__(self,obj): + self.Type = "MechanicaltMaterial" + obj.Proxy = self + obj.Material = StartMat + + + def execute(self,obj): + return + + +class _ViewProviderMechanicalMaterial: + "A View Provider for the MechanicalMaterial object" + + def __init__(self,vobj): + vobj.Proxy = self + + def getIcon(self): + return ":/icons/Fem_Material.svg" + + def attach(self, vobj): + self.ViewObject = vobj + self.Object = vobj.Object + + + def updateData(self, obj, prop): + return + + def onChanged(self, vobj, prop): + return + + def setEdit(self,vobj,mode): + taskd = _MechanicalMaterialTaskPanel(self.Object) + taskd.obj = vobj.Object + taskd.update() + 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 + + +class _MechanicalMaterialTaskPanel: + '''The editmode TaskPanel for MechanicalMaterial objects''' + def __init__(self,obj): + # the panel has a tree widget that contains categories + # for the subcomponents, such as additions, subtractions. + # the categories are shown only if they are not empty. + form_class, base_class = uic.loadUiType(FreeCAD.getHomePath() + "Mod/Fem/MechanicalMaterial.ui") + + self.obj = obj + self.formUi = form_class() + self.form = QtGui.QWidget() + self.formUi.setupUi(self.form) + self.params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem") + + + QtCore.QObject.connect(self.formUi.pushButton_MatWeb, QtCore.SIGNAL("clicked()"), self.goMatWeb) + QtCore.QObject.connect(self.formUi.comboBox_MaterialsInDir, QtCore.SIGNAL("currentIndexChanged(int)"), self.chooseMat) + + self.update() + + def transferTo(self): + "Transfer from the dialog to the object" + + matmap = self.obj.Material + + matmap['FEM_youngsmodulus'] = str(self.formUi.spinBox_young_modulus.value()) + matmap['PartDist_poissonratio'] = str(self.formUi.spinBox_poisson_ratio.value()) + + self.obj.Material = matmap + + + def transferFrom(self): + "Transfer from the object to the dialog" + matmap = self.obj.Material + + self.formUi.spinBox_young_modulus.setValue(float(matmap['FEM_youngsmodulus'])) + self.formUi.spinBox_poisson_ratio.setValue(float(matmap['PartDist_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.transferFrom() + self.fillMaterialCombo() + + + return + + def accept(self): + self.transferTo() + FreeCADGui.ActiveDocument.resetEdit() + + def reject(self): + FreeCADGui.ActiveDocument.resetEdit() + + def saveMat(self): + self.transferTo() + filename = QtGui.QFileDialog.getSaveFileName(None, 'Save Material file file',self.params.GetString("MaterialDir",'/'),'FreeCAD material file (*.FCMat)') + if(filename): + import Material + Material.exportFCMat(filename,self.obj.Material) + + def goMatWeb(self): + import webbrowser + webbrowser.open("http://matweb.com") + + def chooseMat(self,index): + if index == 0:return + import Material + name = self.pathList[index-1] + #print 'Import ', str(name) + + self.obj.Material = Material.importFCMat(str(name)) + #print self.obj.Material + + self.transferFrom() + + def fillMaterialCombo(self): + import glob,os + dirname = FreeCAD.ConfigGet("AppHomePath")+"data/Mod/Material/StandardMaterial" + self.pathList = glob.glob(dirname + '/*.FCMat') + self.formUi.comboBox_MaterialsInDir.clear() + self.formUi.comboBox_MaterialsInDir.addItem('-> choose Material') + for i in self.pathList: + self.formUi.comboBox_MaterialsInDir.addItem(os.path.basename(i) ) + + + + def parse_R_output(self,filename): + file = open(str(filename)) + lines = file.readlines() + found = False + coeff = [] + for line in lines: + if line[0:9] == "c0 to c5:": + found = True + coeff.append(float(line[15:])) + continue + if found and line[0:4] == "MSE:": + found = False + if found: + coeff.append(float(line[15:])) + + file.close() + return coeff[0],coeff[1],coeff[2],coeff[3],coeff[4],coeff[5] + +FreeCADGui.addCommand('Fem_MechanicalMaterial',_CommandMechanicalMaterial()) diff --git a/src/Mod/Fem/MechanicalMaterial.ui b/src/Mod/Fem/MechanicalMaterial.ui new file mode 100644 index 0000000000..f8d4df3fae --- /dev/null +++ b/src/Mod/Fem/MechanicalMaterial.ui @@ -0,0 +1,126 @@ + + + MechanicalMaterial + + + + 0 + 0 + 194 + 142 + + + + Form + + + + + + + choose... + + + + + + + + + + MatWeb database... + + + + + + + + + Qt::Horizontal + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + + 60 + 20 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 999999.989999999990687 + + + 70000.000000000000000 + + + + + + + Young Modulus (KPa) + + + + + + + + 0 + 0 + + + + + 60 + 20 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0.100000000000000 + + + 0.300000000000000 + + + + + + + Poisson Ratio + + + + + + + + + + diff --git a/src/Mod/Material/CMakeLists.txt b/src/Mod/Material/CMakeLists.txt index 624e443b0c..30daf6f7c7 100644 --- a/src/Mod/Material/CMakeLists.txt +++ b/src/Mod/Material/CMakeLists.txt @@ -8,12 +8,14 @@ SET(Material_SRCS SOURCE_GROUP("" FILES ${Material_SRCS}) # collect all the material cards: -FILE( GLOB MaterialLib_Files ./StandardMaterial/*.FCMat ./StandardMaterial/*.txt ) +#FILE( GLOB MaterialLib_Files ./StandardMaterial/*.FCMat ./StandardMaterial/*.txt ) -#SET (MaterialLib_Files -# StandardMaterial/Steel.FCMat -# StandardMaterial/Readme.txt -# ) +SET (MaterialLib_Files + Steel.FCMat + ABS.FCMat + PLA.FCMat + Readme.txt + ) SET(all_files ${Material_SRCS}) @@ -22,9 +24,10 @@ ADD_CUSTOM_TARGET(Material ALL ) fc_copy_sources(Material "${CMAKE_BINARY_DIR}/Mod/Material" ${all_files}) + fc_target_copy_resource(Material - ${CMAKE_SOURCE_DIR}/src/Mod/Material - ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Material + ${CMAKE_SOURCE_DIR}/src/Mod/Material/StandardMaterial + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Material/StandardMaterial ${MaterialLib_Files}) INSTALL( diff --git a/src/Mod/Material/StandardMaterial/ABS.FCMat b/src/Mod/Material/StandardMaterial/ABS.FCMat new file mode 100644 index 0000000000..32b754f057 --- /dev/null +++ b/src/Mod/Material/StandardMaterial/ABS.FCMat @@ -0,0 +1,26 @@ +; Standard AcrylnitrilButadienStyrol (ABS) Material +; (c) 2013 Juergen Riegel (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] +; General name, need to be the same as the file name +Name=ABS +; Father of steel is metal +Father=Thermoplast +; more elaborate description of this material card: +Description: This is a blend ABS material card. The values are at the low end of the spectrum. If you need a more precise material definition use the more specialised ABS-blend cards. +; Specific wight in kg/mm^3 +SpecificWeight=3.5e-06 +; No special Vendor +Vendor: +; For blend materials the wikipedia page is a good source of information: +ProductURL=http://en.wikipedia.org/wiki/Acrylonitrile_butadiene_styrene +; for blends a rough estimation Euro/Kg +SpecificPrice= 3 + +[Mechanical] +; youngs modulus (or E-Module or Modulus of Elasticty) in kPa (source: http://en.wikipedia.org/wiki/Young%27s_modulus) +YoungsModulus=2.32e+06 +; http://en.wikipedia.org/wiki/Ultimate_tensile_strength in kPa +UltimateTensileStrength= 38000 diff --git a/src/Mod/Material/StandardMaterial/PLA.FCMat b/src/Mod/Material/StandardMaterial/PLA.FCMat new file mode 100644 index 0000000000..3fcd2ac439 --- /dev/null +++ b/src/Mod/Material/StandardMaterial/PLA.FCMat @@ -0,0 +1,26 @@ +; Standard Polylactic acid (PLA) Material +; (c) 2013 Juergen Riegel (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] +; General name, need to be the same as the file name +Name=PLA +; Father of steel is metal +Father=Metal +; more elaborate description of this material card: +Description: This is a blend Steel material card. The values are at the low end of the spectrum. If you need a more precise material definition use the more specialised steel cards. +; Specific wight in kg/mm^3 +SpecificWeight=1.27e-06 +; No special Vendor +Vendor: +; For blend materials the wikipedia page is a good source of information: +ProductURL=http://en.wikipedia.org/wiki/Polylactic_acid +; for blends a rough estimation +SpecificPrice= 4 + +[Mechanical] +; youngs modulus (or E-Module) in kPa (source: http://en.wikipedia.org/wiki/Young%27s_modulus) +YoungsModulus=3.64e+06 +; http://en.wikipedia.org/wiki/Ultimate_tensile_strength in kPa +UltimateTensileStrength= 49600 diff --git a/src/Mod/Material/StandardMaterial/Readme.txt b/src/Mod/Material/StandardMaterial/Readme.txt index d4ec402b37..f29161c9e6 100644 --- a/src/Mod/Material/StandardMaterial/Readme.txt +++ b/src/Mod/Material/StandardMaterial/Readme.txt @@ -8,6 +8,7 @@ http://creativecommons.org/ Please help! Enlargen the base of Materials for FreeCAD will greatly benefit the usability of FreeCAD. So please -help us to add new Materials, review existing ones or add additional vlaues. +help us to add new Materials, review existing ones or add additional vlaues. A good source for material +defininitons are text-books or the www.matweb.com database. 2013 Juergen Riegel \ No newline at end of file diff --git a/src/Mod/Material/StandardMaterial/Steel.FCMat b/src/Mod/Material/StandardMaterial/Steel.FCMat index 04022a1d4b..361cc411ad 100644 --- a/src/Mod/Material/StandardMaterial/Steel.FCMat +++ b/src/Mod/Material/StandardMaterial/Steel.FCMat @@ -20,8 +20,8 @@ ProductURL=http://en.wikipedia.org/wiki/Steel SpecificPrice= 1,5 Euro/Kg [Mechanical] -; youngs modulus (or E-Module) in mPa (source: http://en.wikipedia.org/wiki/Young%27s_modulus) -YoungsModulus=200.0e12 +; youngs modulus (or E-Module) in kPa (source: http://en.wikipedia.org/wiki/Young%27s_modulus) +YoungsModulus=2e+08 ; http://en.wikipedia.org/wiki/Ultimate_tensile_strength UltimateTensileStrength= ; http://en.wikipedia.org/wiki/Compressive_strength