Draft: Added editmode to facebinders - fixes #2165
This commit is contained in:
parent
9a3211c343
commit
43e0083c72
|
@ -2567,7 +2567,7 @@ def makeFacebinder(selectionset,name="Facebinder"):
|
|||
fb = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
|
||||
_Facebinder(fb)
|
||||
if gui:
|
||||
_ViewProviderDraft(fb.ViewObject)
|
||||
_ViewProviderFacebinder(fb.ViewObject)
|
||||
faces = []
|
||||
fb.Proxy.addSubobjects(fb,selectionset)
|
||||
return fb
|
||||
|
@ -5422,6 +5422,24 @@ class _Facebinder(_DraftObject):
|
|||
objs.append((o.Object,el))
|
||||
obj.Faces = objs
|
||||
self.execute(obj)
|
||||
|
||||
|
||||
class _ViewProviderFacebinder(_ViewProviderDraft):
|
||||
def __init__(self,vobj):
|
||||
_ViewProviderDraft.__init__(self,vobj)
|
||||
|
||||
def setEdit(self,vobj,mode):
|
||||
import DraftGui
|
||||
taskd = DraftGui.FacebinderTaskPanel()
|
||||
taskd.obj = vobj.Object
|
||||
taskd.update()
|
||||
FreeCADGui.Control.showDialog(taskd)
|
||||
return True
|
||||
|
||||
def unsetEdit(self,vobj,mode):
|
||||
FreeCADGui.Control.closeDialog()
|
||||
return False
|
||||
|
||||
|
||||
class _VisGroup:
|
||||
"The VisGroup object"
|
||||
|
|
|
@ -1803,7 +1803,105 @@ class DraftToolBar:
|
|||
else:
|
||||
self.draftWidget.setVisible(False)
|
||||
self.draftWidget.toggleViewAction().setVisible(False)
|
||||
|
||||
|
||||
|
||||
class FacebinderTaskPanel:
|
||||
'''A TaskPanel for the facebinder'''
|
||||
def __init__(self):
|
||||
|
||||
self.obj = None
|
||||
self.form = QtGui.QWidget()
|
||||
self.form.setObjectName("FacebinderTaskPanel")
|
||||
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(2)
|
||||
self.tree.setHeaderLabels(["Name","Subelement"])
|
||||
|
||||
# buttons
|
||||
self.addButton = QtGui.QPushButton(self.form)
|
||||
self.addButton.setObjectName("addButton")
|
||||
self.addButton.setIcon(QtGui.QIcon(":/icons/Arch_Add.svg"))
|
||||
self.grid.addWidget(self.addButton, 3, 0, 1, 1)
|
||||
|
||||
self.delButton = QtGui.QPushButton(self.form)
|
||||
self.delButton.setObjectName("delButton")
|
||||
self.delButton.setIcon(QtGui.QIcon(":/icons/Arch_Remove.svg"))
|
||||
self.grid.addWidget(self.delButton, 3, 1, 1, 1)
|
||||
|
||||
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 True
|
||||
|
||||
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 f in self.obj.Faces:
|
||||
item = QtGui.QTreeWidgetItem(self.tree)
|
||||
item.setText(0,f[0].Name)
|
||||
item.setIcon(0,QtGui.QIcon(":/icons/Tree_Part.svg"))
|
||||
item.setText(1,f[1])
|
||||
self.retranslateUi(self.form)
|
||||
|
||||
def addElement(self):
|
||||
if self.obj:
|
||||
for sel in FreeCADGui.Selection.getSelectionEx():
|
||||
if sel.HasSubObjects:
|
||||
obj = sel.Object
|
||||
for elt in sel.SubElementNames:
|
||||
if "Face" in elt:
|
||||
flist = self.obj.Faces
|
||||
found = False
|
||||
for face in flist:
|
||||
if (face[0] == obj.Name) and (face[1] == elt):
|
||||
found = True
|
||||
if not found:
|
||||
flist.append((obj,elt))
|
||||
self.obj.Faces = flist
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
self.update()
|
||||
|
||||
def removeElement(self):
|
||||
if self.obj:
|
||||
it = self.tree.currentItem()
|
||||
if it:
|
||||
obj = FreeCAD.ActiveDocument.getObject(str(it.text(0)))
|
||||
elt = str(it.text(1))
|
||||
flist = []
|
||||
for face in self.obj.Faces:
|
||||
if (face[0].Name != obj.Name) or (face[1] != elt):
|
||||
flist.append(face)
|
||||
self.obj.Faces = flist
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
self.update()
|
||||
|
||||
def accept(self):
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
FreeCADGui.ActiveDocument.resetEdit()
|
||||
return True
|
||||
|
||||
def retranslateUi(self, TaskPanel):
|
||||
TaskPanel.setWindowTitle(QtGui.QApplication.translate("draft", "Faces", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.delButton.setText(QtGui.QApplication.translate("draft", "Remove", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.addButton.setText(QtGui.QApplication.translate("draft", "Add", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.title.setText(QtGui.QApplication.translate("draft", "Facebinder elements", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
|
||||
if not hasattr(FreeCADGui,"draftToolBar"):
|
||||
FreeCADGui.draftToolBar = DraftToolBar()
|
||||
#----End of Python Features Definitions----#
|
||||
|
|
Loading…
Reference in New Issue
Block a user