new Editmode task dialog for Arch Windows
This commit is contained in:
parent
78b3113b35
commit
eb5de20e36
|
@ -24,7 +24,7 @@
|
|||
import FreeCAD,FreeCADGui,Draft,ArchComponent
|
||||
from draftlibs import fcvec
|
||||
from FreeCAD import Vector
|
||||
from PyQt4 import QtCore
|
||||
from PyQt4 import QtCore,QtGui
|
||||
|
||||
__title__="FreeCAD Wall"
|
||||
__author__ = "Yorik van Havre"
|
||||
|
@ -71,12 +71,8 @@ class _Window(ArchComponent.Component):
|
|||
ArchComponent.Component.__init__(self,obj)
|
||||
obj.addProperty("App::PropertyFloat","Thickness","Base",
|
||||
"the thickness to be associated with the wire of the Base object")
|
||||
#obj.addProperty("App::PropertyLink","Support","Base",
|
||||
# "The support object (wall usually) of this window")
|
||||
#obj.addProperty("App::PropertyLength","Jamb","Base",
|
||||
# "The distance between the window and the exterior face of its supporting object")
|
||||
#obj.addProperty("Part::PropertyPartShape","Subvolume","Base",
|
||||
# "the volume to be subtracted when inserting this window into its support")
|
||||
obj.addProperty("App::PropertyStringList","WindowParts","Base",
|
||||
"the components of this window")
|
||||
self.Type = "Window"
|
||||
obj.Thickness = .1
|
||||
|
||||
|
@ -118,4 +114,274 @@ class _ViewProviderWindow(ArchComponent.ViewProviderComponent):
|
|||
def getIcon(self):
|
||||
return ":/icons/Arch_Window_Tree.svg"
|
||||
|
||||
def setEdit(self,vobj,mode):
|
||||
taskd = _ArchWindowTaskPanel()
|
||||
taskd.obj = self.Object
|
||||
taskd.update()
|
||||
FreeCADGui.Control.showDialog(taskd)
|
||||
return True
|
||||
|
||||
def unsetEdit(self,vobj,mode):
|
||||
FreeCADGui.Control.closeDialog()
|
||||
return
|
||||
|
||||
class _ArchWindowTaskPanel:
|
||||
'''The TaskPanel for Arch Windows'''
|
||||
def __init__(self):
|
||||
|
||||
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, 7)
|
||||
|
||||
# trees
|
||||
self.tree = QtGui.QTreeWidget(self.form)
|
||||
self.grid.addWidget(self.tree, 1, 0, 1, 7)
|
||||
self.tree.setColumnCount(1)
|
||||
self.tree.setMaximumSize(QtCore.QSize(500,24))
|
||||
self.tree.header().hide()
|
||||
|
||||
self.wiretree = QtGui.QTreeWidget(self.form)
|
||||
self.grid.addWidget(self.wiretree, 2, 0, 1, 3)
|
||||
self.wiretree.setColumnCount(1)
|
||||
|
||||
self.comptree = QtGui.QTreeWidget(self.form)
|
||||
self.grid.addWidget(self.comptree, 2, 4, 1, 3)
|
||||
self.comptree.setColumnCount(1)
|
||||
|
||||
# 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.addButton.setMaximumSize(QtCore.QSize(70,40))
|
||||
|
||||
self.editButton = QtGui.QPushButton(self.form)
|
||||
self.editButton.setObjectName("editButton")
|
||||
self.editButton.setIcon(QtGui.QIcon(":/icons/Draft_Edit.svg"))
|
||||
self.grid.addWidget(self.editButton, 3, 2, 1, 3)
|
||||
self.editButton.setMaximumSize(QtCore.QSize(60,40))
|
||||
self.editButton.setEnabled(False)
|
||||
|
||||
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, 6, 1, 1)
|
||||
self.delButton.setMaximumSize(QtCore.QSize(70,40))
|
||||
self.delButton.setEnabled(False)
|
||||
|
||||
self.okButton = QtGui.QPushButton(self.form)
|
||||
self.okButton.setObjectName("okButton")
|
||||
self.okButton.setIcon(QtGui.QIcon(":/icons/edit_OK.svg"))
|
||||
self.grid.addWidget(self.okButton, 4, 0, 1, 7)
|
||||
|
||||
# add new
|
||||
|
||||
self.newtitle = QtGui.QLabel(self.form)
|
||||
self.new1 = QtGui.QLabel(self.form)
|
||||
self.new2 = QtGui.QLabel(self.form)
|
||||
self.new3 = QtGui.QLabel(self.form)
|
||||
self.new4 = QtGui.QLabel(self.form)
|
||||
self.new5 = QtGui.QLabel(self.form)
|
||||
self.field1 = QtGui.QLineEdit(self.form)
|
||||
self.field2 = QtGui.QLineEdit(self.form)
|
||||
self.field3 = QtGui.QLineEdit(self.form)
|
||||
self.field4 = QtGui.QLineEdit(self.form)
|
||||
self.field5 = QtGui.QLineEdit(self.form)
|
||||
self.createButton = QtGui.QPushButton(self.form)
|
||||
self.createButton.setObjectName("createButton")
|
||||
self.createButton.setIcon(QtGui.QIcon(":/icons/Arch_Add.svg"))
|
||||
self.grid.addWidget(self.newtitle, 6, 0, 1, 7)
|
||||
self.grid.addWidget(self.new1, 7, 0, 1, 1)
|
||||
self.grid.addWidget(self.field1, 7, 2, 1, 5)
|
||||
self.grid.addWidget(self.new2, 8, 0, 1, 1)
|
||||
self.grid.addWidget(self.field2, 8, 2, 1, 5)
|
||||
self.grid.addWidget(self.new3, 9, 0, 1, 1)
|
||||
self.grid.addWidget(self.field3, 9, 2, 1, 5)
|
||||
self.grid.addWidget(self.new4, 10, 0, 1, 1)
|
||||
self.grid.addWidget(self.field4, 10, 2, 1, 5)
|
||||
self.grid.addWidget(self.new5, 11, 0, 1, 1)
|
||||
self.grid.addWidget(self.field5, 11, 2, 1, 5)
|
||||
self.grid.addWidget(self.createButton, 12, 0, 1, 7)
|
||||
self.newtitle.setVisible(False)
|
||||
self.new1.setVisible(False)
|
||||
self.new2.setVisible(False)
|
||||
self.new3.setVisible(False)
|
||||
self.new4.setVisible(False)
|
||||
self.new5.setVisible(False)
|
||||
self.field1.setVisible(False)
|
||||
self.field2.setVisible(False)
|
||||
self.field3.setVisible(False)
|
||||
self.field4.setVisible(False)
|
||||
self.field5.setVisible(False)
|
||||
self.createButton.setVisible(False)
|
||||
|
||||
QtCore.QObject.connect(self.addButton, QtCore.SIGNAL("clicked()"), self.addElement)
|
||||
QtCore.QObject.connect(self.delButton, QtCore.SIGNAL("clicked()"), self.removeElement)
|
||||
QtCore.QObject.connect(self.editButton, QtCore.SIGNAL("clicked()"), self.editElement)
|
||||
QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.finish)
|
||||
QtCore.QObject.connect(self.createButton, QtCore.SIGNAL("clicked()"), self.create)
|
||||
QtCore.QObject.connect(self.comptree, QtCore.SIGNAL("itemClicked(QTreeWidgetItem*,int)"), self.check)
|
||||
self.update()
|
||||
|
||||
def isAllowedAlterSelection(self):
|
||||
return True
|
||||
|
||||
def isAllowedAlterView(self):
|
||||
return True
|
||||
|
||||
def getStandardButtons(self):
|
||||
return 0
|
||||
|
||||
def check(self,wid,col):
|
||||
self.editButton.setEnabled(True)
|
||||
self.delButton.setEnabled(True)
|
||||
|
||||
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 tree widgets'
|
||||
self.tree.clear()
|
||||
self.wiretree.clear()
|
||||
self.comptree.clear()
|
||||
if self.obj:
|
||||
if self.obj.Base:
|
||||
item = QtGui.QTreeWidgetItem(self.tree)
|
||||
item.setText(0,self.obj.Base.Name)
|
||||
item.setIcon(0,self.getIcon(self.obj.Base))
|
||||
if self.obj.Base.isDerivedFrom("Part::Feature"):
|
||||
i = 0
|
||||
for w in self.obj.Base.Shape.Wires:
|
||||
if w.isClosed():
|
||||
item = QtGui.QTreeWidgetItem(self.wiretree)
|
||||
item.setText(0,"Wire" + str(i))
|
||||
item.setIcon(0,QtGui.QIcon(":/icons/Draft_Draft.svg"))
|
||||
i += 1
|
||||
if self.obj.WindowParts:
|
||||
for p in range(0,len(self.obj.WindowParts),5):
|
||||
item = QtGui.QTreeWidgetItem(self.comptree)
|
||||
item.setText(0,self.obj.WindowParts[p])
|
||||
item.setIcon(0,QtGui.QIcon(":/icons/Tree_Part.svg"))
|
||||
self.retranslateUi(self.form)
|
||||
|
||||
def addElement(self):
|
||||
'opens the component creation dialog'
|
||||
self.field1.setText('')
|
||||
self.field2.setText('')
|
||||
self.field3.setText('')
|
||||
self.field4.setText('')
|
||||
self.field5.setText('')
|
||||
self.newtitle.setVisible(True)
|
||||
self.new1.setVisible(True)
|
||||
self.new2.setVisible(True)
|
||||
self.new3.setVisible(True)
|
||||
self.new4.setVisible(True)
|
||||
self.new5.setVisible(True)
|
||||
self.field1.setVisible(True)
|
||||
self.field2.setVisible(True)
|
||||
self.field3.setVisible(True)
|
||||
self.field4.setVisible(True)
|
||||
self.field5.setVisible(True)
|
||||
self.createButton.setVisible(True)
|
||||
self.addButton.setEnabled(False)
|
||||
self.editButton.setEnabled(False)
|
||||
self.delButton.setEnabled(False)
|
||||
|
||||
def removeElement(self):
|
||||
it = self.comptree.currentItem()
|
||||
if it:
|
||||
comp = str(it.text(0))
|
||||
if self.obj:
|
||||
p = self.obj.WindowParts
|
||||
if comp in self.obj.WindowParts:
|
||||
ind = self.obj.WindowParts.index(comp)
|
||||
for i in range(5):
|
||||
p.pop(ind)
|
||||
self.obj.WindowParts = p
|
||||
self.update()
|
||||
self.editButton.setEnabled(False)
|
||||
self.delButton.setEnabled(False)
|
||||
|
||||
def editElement(self):
|
||||
it = self.comptree.currentItem()
|
||||
if it:
|
||||
self.addElement()
|
||||
comp = str(it.text(0))
|
||||
if self.obj:
|
||||
if comp in self.obj.WindowParts:
|
||||
ind = self.obj.WindowParts.index(comp)
|
||||
for i in range(5):
|
||||
f = getattr(self,"field"+str(i+1))
|
||||
t = self.obj.WindowParts[ind+i]
|
||||
f.setText(t)
|
||||
|
||||
def create(self):
|
||||
'adds a new component'
|
||||
# testing if fields are ok
|
||||
ok = True
|
||||
ar = []
|
||||
for i in range(5):
|
||||
t = str(getattr(self,"field"+str(i+1)).text())
|
||||
if t == "":
|
||||
ok = False
|
||||
else:
|
||||
if i > 2:
|
||||
try:
|
||||
n=float(t)
|
||||
except:
|
||||
ok = False
|
||||
ar.append(t)
|
||||
|
||||
if ok:
|
||||
if self.obj:
|
||||
parts = self.obj.WindowParts
|
||||
parts.extend(ar)
|
||||
self.obj.WindowParts = parts
|
||||
self.update()
|
||||
|
||||
self.newtitle.setVisible(False)
|
||||
self.new1.setVisible(False)
|
||||
self.new2.setVisible(False)
|
||||
self.new3.setVisible(False)
|
||||
self.new4.setVisible(False)
|
||||
self.new5.setVisible(False)
|
||||
self.field1.setVisible(False)
|
||||
self.field2.setVisible(False)
|
||||
self.field3.setVisible(False)
|
||||
self.field4.setVisible(False)
|
||||
self.field5.setVisible(False)
|
||||
self.createButton.setVisible(False)
|
||||
self.addButton.setEnabled(True)
|
||||
|
||||
def finish(self):
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
if self.obj:
|
||||
self.obj.ViewObject.finishEditing()
|
||||
|
||||
def retranslateUi(self, TaskPanel):
|
||||
TaskPanel.setWindowTitle(QtGui.QApplication.translate("Arch", "Components", 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.editButton.setText(QtGui.QApplication.translate("Arch", "Edit", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.okButton.setText(QtGui.QApplication.translate("Arch", "Done", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.createButton.setText(QtGui.QApplication.translate("Arch", "Create/update component", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.title.setText(QtGui.QApplication.translate("Arch", "Base 2D object", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.wiretree.setHeaderLabels([QtGui.QApplication.translate("Arch", "Wires", None, QtGui.QApplication.UnicodeUTF8)])
|
||||
self.comptree.setHeaderLabels([QtGui.QApplication.translate("Arch", "Components", None, QtGui.QApplication.UnicodeUTF8)])
|
||||
self.newtitle.setText(QtGui.QApplication.translate("Arch", "Create new component", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.new1.setText(QtGui.QApplication.translate("Arch", "Name", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.new2.setText(QtGui.QApplication.translate("Arch", "Type", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.new3.setText(QtGui.QApplication.translate("Arch", "Wires", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.new4.setText(QtGui.QApplication.translate("Arch", "Thickness", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.new5.setText(QtGui.QApplication.translate("Arch", "Z offset", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
FreeCADGui.addCommand('Arch_Window',_CommandWindow())
|
||||
|
|
Loading…
Reference in New Issue
Block a user