Skip to content

Commit

Permalink
Arch: Switched structure and window to Units system
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Apr 6, 2014
1 parent 4e656dd commit 29b7ed3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchAxis.py
Expand Up @@ -416,7 +416,7 @@ def retranslateUi(self, TaskPanel):
TaskPanel.setWindowTitle(QtGui.QApplication.translate("Arch", "Axes", 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", "Distances and angles between axes", None, QtGui.QApplication.UnicodeUTF8))
self.title.setText(QtGui.QApplication.translate("Arch", "Distances (mm) and angles (deg) between axes", None, QtGui.QApplication.UnicodeUTF8))
self.tree.setHeaderLabels([QtGui.QApplication.translate("Arch", "Axis", None, QtGui.QApplication.UnicodeUTF8),
QtGui.QApplication.translate("Arch", "Distance", None, QtGui.QApplication.UnicodeUTF8),
QtGui.QApplication.translate("Arch", "Angle", None, QtGui.QApplication.UnicodeUTF8)])
Expand Down
69 changes: 31 additions & 38 deletions src/Mod/Arch/ArchStructure.py
Expand Up @@ -361,6 +361,8 @@ def Activated(self):
self.Height = p.GetFloat("StructureHeight",1000)
self.Profile = 0
self.continueCmd = False
self.DECIMALS = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2)
self.FORMAT = "%." + str(self.DECIMALS) + "f mm"
sel = FreeCADGui.Selection.getSelection()
if sel:
st = Draft.getObjectsOfType(sel,"Structure")
Expand Down Expand Up @@ -420,67 +422,58 @@ def getPoint(self,point=None,obj=None):

def taskbox(self):
"sets up a taskbox widget"
d = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2)
w = QtGui.QWidget()
ui = FreeCADGui.UiLoader()
w.setWindowTitle(translate("Arch","Structure options").decode("utf8"))
lay0 = QtGui.QVBoxLayout(w)
grid = QtGui.QGridLayout(w)

# presets box
layp = QtGui.QHBoxLayout()
lay0.addLayout(layp)
labelp = QtGui.QLabel(translate("Arch","Preset").decode("utf8"))
layp.addWidget(labelp)
valuep = QtGui.QComboBox()
fpresets = [" "]
for p in Presets[1:]:
fpresets.append(str(translate("Arch",p[0]))+" "+p[1]+" ("+str(p[2])+"x"+str(p[3])+"mm)")
valuep.addItems(fpresets)
layp.addWidget(valuep)
grid.addWidget(labelp,0,0,1,1)
grid.addWidget(valuep,0,1,1,1)

# length
lay1 = QtGui.QHBoxLayout()
lay0.addLayout(lay1)
label1 = QtGui.QLabel(translate("Arch","Length").decode("utf8"))
lay1.addWidget(label1)
self.vLength = QtGui.QDoubleSpinBox()
self.vLength.setDecimals(d)
self.vLength.setMaximum(99999.99)
self.vLength.setValue(self.Length)
lay1.addWidget(self.vLength)
self.vLength = ui.createWidget("Gui::InputField")
self.vLength.setText(self.FORMAT % self.Length)
grid.addWidget(label1,1,0,1,1)
grid.addWidget(self.vLength,1,1,1,1)

# width
lay2 = QtGui.QHBoxLayout()
lay0.addLayout(lay2)
label2 = QtGui.QLabel(translate("Arch","Width").decode("utf8"))
lay2.addWidget(label2)
self.vWidth = QtGui.QDoubleSpinBox()
self.vWidth.setDecimals(d)
self.vWidth.setMaximum(99999.99)
self.vWidth.setValue(self.Width)
lay2.addWidget(self.vWidth)
self.vWidth = ui.createWidget("Gui::InputField")
self.vWidth.setText(self.FORMAT % self.Width)
grid.addWidget(label2,2,0,1,1)
grid.addWidget(self.vWidth,2,1,1,1)

# height
lay3 = QtGui.QHBoxLayout()
lay0.addLayout(lay3)
label3 = QtGui.QLabel(translate("Arch","Height").decode("utf8"))
lay3.addWidget(label3)
self.vHeight = QtGui.QDoubleSpinBox()
self.vHeight.setDecimals(d)
self.vHeight.setMaximum(99999.99)
self.vHeight.setValue(self.Height)
lay3.addWidget(self.vHeight)
self.vHeight = ui.createWidget("Gui::InputField")
self.vHeight.setText(self.FORMAT % self.Height)
grid.addWidget(label3,3,0,1,1)
grid.addWidget(self.vHeight,3,1,1,1)

# horizontal button
value5 = QtGui.QPushButton(translate("Arch","Rotate").decode("utf8"))
lay0.addWidget(value5)
grid.addWidget(value5,4,0,1,2)

# continue button
value4 = QtGui.QCheckBox(translate("Arch","Con&tinue").decode("utf8"))
label4 = QtGui.QLabel(translate("Arch","Con&tinue").decode("utf8"))
value4 = QtGui.QCheckBox()
value4.setObjectName("ContinueCmd")
lay0.addWidget(value4)
value4.setLayoutDirection(QtCore.Qt.RightToLeft)
label4.setBuddy(value4)
if hasattr(FreeCADGui,"draftToolBar"):
value4.setChecked(FreeCADGui.draftToolBar.continueMode)
self.continueCmd = FreeCADGui.draftToolBar.continueMode
grid.addWidget(label4,5,0,1,1)
grid.addWidget(value4,5,1,1,1)

QtCore.QObject.connect(valuep,QtCore.SIGNAL("currentIndexChanged(int)"),self.setPreset)
QtCore.QObject.connect(self.vLength,QtCore.SIGNAL("valueChanged(double)"),self.setLength)
QtCore.QObject.connect(self.vWidth,QtCore.SIGNAL("valueChanged(double)"),self.setWidth)
Expand Down Expand Up @@ -517,8 +510,8 @@ def setContinue(self,i):

def setPreset(self,i):
if i > 0:
self.vLength.setValue(float(Presets[i][2]))
self.vWidth.setValue(float(Presets[i][3]))
self.vLength.setText(self.FORMAT % float(Presets[i][2]))
self.vWidth.setText(self.FORMAT % float(Presets[i][3]))
if len(Presets[i]) == 6:
self.Profile = i
else:
Expand All @@ -528,9 +521,9 @@ def rotate(self):
l = self.Length
w = self.Width
h = self.Height
self.vLength.setValue(h)
self.vHeight.setValue(w)
self.vWidth.setValue(l)
self.vLength.setText(self.FORMAT % h)
self.vHeight.setText(self.FORMAT % w)
self.vWidth.setText(self.FORMAT % l)

class _Structure(ArchComponent.Component):
"The Structure object"
Expand Down
3 changes: 0 additions & 3 deletions src/Mod/Arch/ArchWall.py
Expand Up @@ -310,9 +310,6 @@ def taskbox(self):
grid.addWidget(label4,4,0,1,1)
grid.addWidget(value4,4,1,1,1)

spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
grid.addItem(spacerItem, 4, 0, 1, 2)

QtCore.QObject.connect(value1,QtCore.SIGNAL("valueChanged(double)"),self.setWidth)
QtCore.QObject.connect(value2,QtCore.SIGNAL("valueChanged(double)"),self.setHeight)
QtCore.QObject.connect(value3,QtCore.SIGNAL("currentIndexChanged(int)"),self.setAlign)
Expand Down
69 changes: 40 additions & 29 deletions src/Mod/Arch/ArchWindow.py
Expand Up @@ -21,7 +21,7 @@
#* *
#***************************************************************************

import FreeCAD,Draft,ArchComponent,DraftVecUtils,ArchCommands
import FreeCAD,Draft,ArchComponent,DraftVecUtils,ArchCommands,Units
from FreeCAD import Vector
if FreeCAD.GuiUp:
import FreeCADGui
Expand All @@ -41,6 +41,7 @@ def translate(ctxt,txt):
"Sliding 2-pane", "Simple door", "Glass door"]
Roles = ["Window","Door"]


def makeWindow(baseobj=None,width=None,height=None,parts=None,name=translate("Arch","Window")):
'''makeWindow(baseobj,[width,height,parts,name]): creates a window based on the
given base 2D object (sketch or draft).'''
Expand Down Expand Up @@ -358,6 +359,12 @@ def doorFrame(s,width,height,h1,w1,o1):

class _CommandWindow:
"the Arch Window command definition"

def __init__(self):
# hack for inputwidgets
global setArchWindowParamFunction
setArchWindowParamFunction = self.setParams

def GetResources(self):
return {'Pixmap' : 'Arch_Window',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Arch_Window","Window"),
Expand All @@ -373,6 +380,8 @@ def Activated(self):
self.Preset = 0
self.baseFace = None
self.wparams = ["Width","Height","H1","H2","H3","W1","W2","O1","O2"]
self.DECIMALS = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2)
self.FORMAT = "%." + str(self.DECIMALS) + "f mm"

# auto mode
if sel:
Expand Down Expand Up @@ -487,54 +496,51 @@ def update(self,point,info):

def taskbox(self):
"sets up a taskbox widget"
d = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2)
w = QtGui.QWidget()
ui = FreeCADGui.UiLoader()
w.setWindowTitle(translate("Arch","Window options"))
lay0 = QtGui.QVBoxLayout(w)
grid = QtGui.QGridLayout(w)

# presets box
layp = QtGui.QHBoxLayout()
lay0.addLayout(layp)
labelp = QtGui.QLabel(translate("Arch","Preset"))
layp.addWidget(labelp)
valuep = QtGui.QComboBox()
valuep.addItems(["Create from scratch"]+WindowPresets)
valuep.setCurrentIndex(self.Preset)
layp.addWidget(valuep)
grid.addWidget(labelp,0,0,1,1)
grid.addWidget(valuep,0,1,1,1)
QtCore.QObject.connect(valuep,QtCore.SIGNAL("currentIndexChanged(int)"),self.setPreset)

# image display
self.im = QtSvg.QSvgWidget(":/ui/ParametersWindowFixed.svg")
self.im.setMaximumWidth(200)
lay0.addWidget(self.im)
self.im.setMinimumHeight(120)
grid.addWidget(self.im,1,0,1,2)
self.im.hide()

# parameters
i = 2
for param in self.wparams:
l = QtGui.QHBoxLayout()
lay0.addLayout(l)
lab = QtGui.QLabel(translate("Arch",param).decode("utf8"))
l.addWidget(lab)
setattr(self,"val"+param,QtGui.QDoubleSpinBox())
setattr(self,"val"+param,ui.createWidget("Gui::InputField"))
wid = getattr(self,"val"+param)
wid.setDecimals(d)
wid.setMaximum(99999.99)
if param == "Width":
wid.setValue(self.Width)
wid.setText(self.FORMAT % self.Width)
elif param == "Height":
wid.setValue(self.Height)
wid.setText(self.FORMAT % self.Height)
else:
wid.setValue(self.Thickness)
wid.setText(self.FORMAT % self.Thickness)
setattr(self,param,self.Thickness)
l.addWidget(wid)
l.setEnabled(False)
QtCore.QObject.connect(getattr(self,"val"+param),QtCore.SIGNAL("valueChanged(double)"),self.setParams)

grid.addWidget(lab,i,0,1,1)
grid.addWidget(wid,i,1,1,1)
i += 1
FreeCAD.wid = wid
exec("""def valueChanged(d):
setArchWindowParamFunction('"""+param+"""',d)""")
QtCore.QObject.connect(getattr(self,"val"+param),QtCore.SIGNAL("valueChanged(double)"),valueChanged)
return w

def setParams(self,d):
for param in self.wparams:
setattr(self,param,float(getattr(self,"val"+param).value()))
def setParams(self,param,d):
setattr(self,param,d)
self.tracker.length(self.Width)
self.tracker.height(self.Height)
self.tracker.width(self.W1)
Expand All @@ -560,8 +566,8 @@ def setPreset(self,i):
else:
self.im.load(":/ui/ParametersWindowDouble.svg")
self.im.show()
for param in self.wparams:
getattr(self,"val"+param).setEnabled(True)
#for param in self.wparams:
# getattr(self,"val"+param).setEnabled(True)
else:
FreeCADGui.Snapper.setSelectMode(True)
self.tracker.off()
Expand Down Expand Up @@ -801,6 +807,8 @@ class _ArchWindowTaskPanel:
def __init__(self):

self.obj = None
self.DECIMALS = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2)
self.FORMAT = "%." + str(self.DECIMALS) + "f mm"
self.form = QtGui.QWidget()
self.form.setObjectName("TaskPanel")
self.grid = QtGui.QGridLayout(self.form)
Expand Down Expand Up @@ -847,6 +855,7 @@ def __init__(self):

# add new

ui = FreeCADGui.UiLoader()
self.newtitle = QtGui.QLabel(self.form)
self.new1 = QtGui.QLabel(self.form)
self.new2 = QtGui.QLabel(self.form)
Expand All @@ -856,8 +865,8 @@ def __init__(self):
self.field1 = QtGui.QLineEdit(self.form)
self.field2 = QtGui.QComboBox(self.form)
self.field3 = QtGui.QLineEdit(self.form)
self.field4 = QtGui.QLineEdit(self.form)
self.field5 = QtGui.QLineEdit(self.form)
self.field4 = ui.createWidget("Gui::InputField")
self.field5 = ui.createWidget("Gui::InputField")
self.createButton = QtGui.QPushButton(self.form)
self.createButton.setObjectName("createButton")
self.createButton.setIcon(QtGui.QIcon(":/icons/Arch_Add.svg"))
Expand Down Expand Up @@ -1013,6 +1022,8 @@ def editElement(self):
f.setCurrentIndex(WindowPartTypes.index(t))
else:
f.setCurrentIndex(0)
elif i in [3,4]:
f.setProperty("text",self.FORMAT % float(t))
else:
f.setText(t)

Expand All @@ -1030,7 +1041,7 @@ def create(self):
# if type was not specified or is invalid, we set a default
t = WindowPartTypes[0]
else:
t = str(getattr(self,"field"+str(i+1)).text())
t = str(getattr(self,"field"+str(i+1)).property("text"))
if t in WindowPartTypes:
t = t + "_" # avoiding part names similar to types
if t == "":
Expand Down

0 comments on commit 29b7ed3

Please sign in to comment.