From 9d0f4ba46efe9dd9d0206332d19367a46a15562a Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Sat, 28 Nov 2015 14:51:40 -0200 Subject: [PATCH] Arch: Added editmode to Section Planes - fixes #2098 --- src/Mod/Arch/ArchSectionPlane.py | 103 ++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/src/Mod/Arch/ArchSectionPlane.py b/src/Mod/Arch/ArchSectionPlane.py index 3e6ca0e50..1c28b391c 100644 --- a/src/Mod/Arch/ArchSectionPlane.py +++ b/src/Mod/Arch/ArchSectionPlane.py @@ -21,7 +21,7 @@ #* * #*************************************************************************** -import FreeCAD,WorkingPlane,math,Draft,ArchCommands,DraftVecUtils +import FreeCAD,WorkingPlane,math,Draft,ArchCommands,DraftVecUtils,ArchComponent from FreeCAD import Vector if FreeCAD.GuiUp: import FreeCADGui @@ -286,6 +286,20 @@ class _ViewProviderSectionPlane: def __setstate__(self,state): return None + + def setEdit(self,vobj,mode): + taskd = SectionPlaneTaskPanel() + taskd.obj = vobj.Object + taskd.update() + FreeCADGui.Control.showDialog(taskd) + return True + + def unsetEdit(self,vobj,mode): + FreeCADGui.Control.closeDialog() + return False + + def doubleClicked(self,vobj): + self.setEdit(vobj,None) class _ArchDrawingView: def __init__(self, obj): @@ -510,6 +524,93 @@ class _ArchDrawingView: result.append(Drawing.projectToDXF(self.hiddenshape,self.direction)) return result +class SectionPlaneTaskPanel: + '''A TaskPanel for all the section plane object''' + 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(1) + self.tree.header().hide() + + # 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 getIcon(self,obj): + if hasattr(obj.ViewObject,"Proxy"): + return QtGui.QIcon(obj.ViewObject.Proxy.getIcon()) + elif obj.isDerivedFrom("Sketcher::SketchObject"): + return QtGui.QIcon(":/icons/Sketcher_Sketch.svg") + else: + return QtGui.QIcon(":/icons/Tree_Part.svg") + + def update(self): + 'fills the treewidget' + self.tree.clear() + if self.obj: + for o in self.obj.Objects: + item = QtGui.QTreeWidgetItem(self.tree) + item.setText(0,o.Name) + item.setIcon(0,self.getIcon(o)) + self.retranslateUi(self.form) + + def addElement(self): + if self.obj: + for o in FreeCADGui.Selection.getSelection(): + ArchComponent.addToComponent(self.obj,o,"Objects") + self.update() + + def removeElement(self): + if self.obj: + it = self.tree.currentItem() + if it: + comp = FreeCAD.ActiveDocument.getObject(str(it.text(0))) + ArchComponent.removeFromComponent(self.obj,comp) + self.update() + + def accept(self): + FreeCAD.ActiveDocument.recompute() + FreeCADGui.ActiveDocument.resetEdit() + return True + + def retranslateUi(self, TaskPanel): + TaskPanel.setWindowTitle(QtGui.QApplication.translate("Arch", "Objects", None, QtGui.QApplication.UnicodeUTF8)) + self.delButton.setText(QtGui.QApplication.translate("Arch", "Remove", None, QtGui.QApplication.UnicodeUTF8)) + self.addButton.setText(QtGui.QApplication.translate("Arch", "Add", None, QtGui.QApplication.UnicodeUTF8)) + self.title.setText(QtGui.QApplication.translate("Arch", "Objects seen by this section plane", None, QtGui.QApplication.UnicodeUTF8)) if FreeCAD.GuiUp: FreeCADGui.addCommand('Arch_SectionPlane',_CommandSectionPlane())