Add Material treatment file
This commit is contained in:
parent
f120990372
commit
eaa38ec43e
247
src/Mod/Machining_Distortion/MachDistMaterial.py
Normal file
247
src/Mod/Machining_Distortion/MachDistMaterial.py
Normal file
|
@ -0,0 +1,247 @@
|
|||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2013 - Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
#* *
|
||||
#* 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,
|
||||
from FreeCAD import Vector
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from pivy import coin
|
||||
|
||||
__title__="Machine-Distortion FemSetGeometryObject managment"
|
||||
__author__ = "Juergen Riegel"
|
||||
__url__ = "http://free-cad.sourceforge.net"
|
||||
|
||||
def makeMaterial(num=5,size=1,name=str(translate("MachDist","Axes"))):
|
||||
'''makeMaterial(num,size): makes an Material System
|
||||
based on the given number of axes and interval distances'''
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
|
||||
_Material(obj)
|
||||
_ViewProviderMaterial(obj.ViewObject)
|
||||
if num:
|
||||
dist = []
|
||||
angles = []
|
||||
for i in range(num):
|
||||
dist.append(float(size))
|
||||
angles.append(float(0))
|
||||
obj.Distances = dist
|
||||
obj.Angles = angles
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
return obj
|
||||
|
||||
class _CommandMaterial:
|
||||
"the MachDist Material command definition"
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'MachDist_Material',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("MachDist_Material","Material"),
|
||||
'Accel': "A, X",
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("MachDist_Material","Creates an axis system.")}
|
||||
|
||||
def Activated(self):
|
||||
FreeCAD.ActiveDocument.openTransaction(str(translate("MachDist","Create Material")))
|
||||
FreeCADGui.doCommand("import MachDist")
|
||||
sel = FreeCADGui.Selection.getSelection()
|
||||
st = Draft.getObjectsOfType(sel,"Structure")
|
||||
if st:
|
||||
FreeCADGui.doCommand("axe = MachDist.makeMaterial()")
|
||||
FreeCADGui.doCommand("MachDist.makeStructuralSystem(" + MachDistCommands.getStringList(st) + ",[axe])")
|
||||
else:
|
||||
FreeCADGui.doCommand("MachDist.makeMaterial()")
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
|
||||
class _Material:
|
||||
"The Material object"
|
||||
def __init__(self,obj):
|
||||
self.Type = "MachDistMaterial"
|
||||
obj.Length=1.0
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self,obj):
|
||||
self.createGeometry(obj)
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
if not prop in ["Shape","Placement"]:
|
||||
self.createGeometry(obj)
|
||||
|
||||
def __getstate__(self):
|
||||
return self.Type
|
||||
|
||||
def __setstate__(self,state):
|
||||
if state:
|
||||
self.Type = state
|
||||
|
||||
class _ViewProviderMaterial:
|
||||
"A View Provider for the Material object"
|
||||
|
||||
def __init__(self,vobj):
|
||||
#vobj.addProperty("App::PropertyLength","BubbleSize","Base", str(translate("MachDist","The size of the axis bubbles")))
|
||||
vobj.Proxy = self
|
||||
#vobj.BubbleSize = .1
|
||||
|
||||
def getIcon(self):
|
||||
import MachDist_rc
|
||||
return ":/icons/MachDist_Material_Tree.svg"
|
||||
|
||||
def claimChildren(self):
|
||||
return []
|
||||
|
||||
def attach(self, vobj):
|
||||
self.ViewObject = vobj
|
||||
self.Object = vobj.Object
|
||||
self.bubbles = None
|
||||
|
||||
|
||||
def updateData(self, obj, prop):
|
||||
if prop == "Shape":
|
||||
self.makeBubbles()
|
||||
return
|
||||
|
||||
def onChanged(self, vobj, prop):
|
||||
if prop in ["NumerationStyle","BubbleSize"]:
|
||||
self.makeBubbles()
|
||||
elif prop == "LineWidth":
|
||||
if self.bubbles:
|
||||
self.bubblestyle.lineWidth = vobj.LineWidth
|
||||
return
|
||||
|
||||
def setEdit(self,vobj,mode):
|
||||
taskd = _MaterialTaskPanel()
|
||||
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 _MaterialTaskPanel:
|
||||
'''The editmode TaskPanel for Material objects'''
|
||||
def __init__(self):
|
||||
# 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.
|
||||
|
||||
self.obj = None
|
||||
self.form = QtGui.QWidget()
|
||||
self.form.setObjectName("TaskPanel")
|
||||
self.grid = QtGui.QGridLayout(self.form)
|
||||
self.grid.setObjectName("grid")
|
||||
self.title = QtGui.QLabel(self.form)
|
||||
self.grid.addWidget(self.title, 0, 0, 1, 2)
|
||||
|
||||
# tree
|
||||
self.tree = QtGui.QTreeWidget(self.form)
|
||||
self.grid.addWidget(self.tree, 1, 0, 1, 2)
|
||||
self.tree.setColumnCount(3)
|
||||
self.tree.header().resizeSection(0,50)
|
||||
self.tree.header().resizeSection(1,80)
|
||||
self.tree.header().resizeSection(2,60)
|
||||
|
||||
# buttons
|
||||
self.addButton = QtGui.QPushButton(self.form)
|
||||
self.addButton.setObjectName("addButton")
|
||||
self.addButton.setIcon(QtGui.QIcon(":/icons/MachDist_Add.svg"))
|
||||
self.grid.addWidget(self.addButton, 3, 0, 1, 1)
|
||||
self.addButton.setEnabled(True)
|
||||
|
||||
self.delButton = QtGui.QPushButton(self.form)
|
||||
self.delButton.setObjectName("delButton")
|
||||
self.delButton.setIcon(QtGui.QIcon(":/icons/MachDist_Remove.svg"))
|
||||
self.grid.addWidget(self.delButton, 3, 1, 1, 1)
|
||||
self.delButton.setEnabled(True)
|
||||
|
||||
QtCore.QObject.connect(self.addButton, QtCore.SIGNAL("clicked()"), self.addElement)
|
||||
QtCore.QObject.connect(self.delButton, QtCore.SIGNAL("clicked()"), self.removeElement)
|
||||
self.update()
|
||||
|
||||
def isAllowedAlterSelection(self):
|
||||
return False
|
||||
|
||||
def isAllowedAlterView(self):
|
||||
return True
|
||||
|
||||
def getStandardButtons(self):
|
||||
return int(QtGui.QDialogButtonBox.Ok)
|
||||
|
||||
def update(self):
|
||||
'fills the treewidget'
|
||||
self.tree.clear()
|
||||
if self.obj:
|
||||
for i in range(len(self.obj.Distances)):
|
||||
item = QtGui.QTreeWidgetItem(self.tree)
|
||||
item.setText(0,str(i+1))
|
||||
item.setText(1,str(self.obj.Distances[i]))
|
||||
item.setText(2,str(self.obj.Angles[i]))
|
||||
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
|
||||
item.setTextAlignment(0,QtCore.Qt.AlignLeft)
|
||||
self.retranslateUi(self.form)
|
||||
|
||||
def addElement(self):
|
||||
item = QtGui.QTreeWidgetItem(self.tree)
|
||||
item.setText(0,str(self.tree.topLevelItemCount()))
|
||||
item.setText(1,"1.0")
|
||||
item.setText(2,"0.0")
|
||||
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
|
||||
self.resetObject()
|
||||
|
||||
def removeElement(self):
|
||||
it = self.tree.currentItem()
|
||||
if it:
|
||||
nr = int(it.text(0))-1
|
||||
self.resetObject(remove=nr)
|
||||
self.update()
|
||||
|
||||
def resetObject(self,remove=None):
|
||||
d = []
|
||||
a = []
|
||||
for i in range(self.tree.topLevelItemCount()):
|
||||
it = self.tree.findItems(str(i+1),QtCore.Qt.MatchExactly,0)[0]
|
||||
if (remove == None) or (remove != i):
|
||||
d.append(float(it.text(1)))
|
||||
a.append(float(it.text(2)))
|
||||
self.obj.Distances = d
|
||||
self.obj.Angles = a
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
def accept(self):
|
||||
self.resetObject()
|
||||
FreeCADGui.ActiveDocument.resetEdit()
|
||||
|
||||
def retranslateUi(self, TaskPanel):
|
||||
TaskPanel.setWindowTitle(QtGui.QApplication.translate("MachDist", "Axes", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.delButton.setText(QtGui.QApplication.translate("MachDist", "Remove", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.addButton.setText(QtGui.QApplication.translate("MachDist", "Add", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.title.setText(QtGui.QApplication.translate("MachDist", "Distances and angles between axes", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.tree.setHeaderLabels([QtGui.QApplication.translate("MachDist", "Material", None, QtGui.QApplication.UnicodeUTF8),
|
||||
QtGui.QApplication.translate("MachDist", "Distance", None, QtGui.QApplication.UnicodeUTF8),
|
||||
QtGui.QApplication.translate("MachDist", "Angle", None, QtGui.QApplication.UnicodeUTF8)])
|
||||
|
||||
FreeCADGui.addCommand('MachDist_Material',_CommandMaterial())
|
Loading…
Reference in New Issue
Block a user