Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #381 - Fix the display of units for the constraint offset #483

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions a2p_constraintDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ def initUI(self):

self.offsetEdit = QtGui.QDoubleSpinBox(self)

# get the length unit as string
self.offsetEdit.setSuffix(" " + str(FreeCAD.Units.Quantity(1, FreeCAD.Units.Length))[3:])
# the maximum is by default 99.99 and we can allow more
self.offsetEdit.setMaximum(1e7) # allow up to 1 km
# set minimum to negative of maximum
Expand All @@ -146,33 +144,14 @@ def initUI(self):
params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
self.offsetEdit.setDecimals(params.GetInt('Decimals'))

userPreferred = Units.Quantity(offs).getUserPreferred()[0] #offs is string with value and unit

# the following line does not work with all possible units.
# sometimes a separating blank is missing

# user_qty, user_unit = userPreferred.split(' ')

# so do own parsing
user_qty = ''
user_unit = ''
for c in userPreferred:
if c == ' ':
continue
elif c.isdigit():
user_qty += c
elif c in ('.',','):
user_qty += c
else:
user_unit += c

user_qty = float(user_qty.replace(",","."))
userPreferred = Units.Quantity(offs).getUserPreferred()

user_qty = Units.Quantity(offs).Value

#self.offsetEdit.setValue(offs.Value)
#self.offsetEdit.setSuffix(" " + str(FreeCAD.Units.Quantity(1, FreeCAD.Units.Length))[3:])
self.offsetEdit.setSuffix(" " + user_unit)
self.recentUnit = str(FreeCAD.Units.Quantity(1, FreeCAD.Units.Length))[3:]
self.offsetEdit.setSuffix(" " + self.recentUnit)
self.offsetEdit.setValue(user_qty)
self.recentUnit = user_unit
self.offsetEdit.setSingleStep(userPreferred[1])

self.offsetEdit.setFixedHeight(32)
QtCore.QObject.connect(self.offsetEdit, QtCore.SIGNAL("valueChanged(double)"), self.handleOffsetChanged)
Expand Down