Problem with negative values in InputField
Problem with negative values in InputField
Hi,
For quite some time I've had a problem with the placement dialog concerning negative values. Any negative value is replaced with DOUBLE_MIN. This problem also breaks the use of stepping the value with up and down keys or using the mouse wheel to change value.
To Illustrate the problem just create an object e.g. a cube in parts. Then select the cube and choose the data tab in the property view. Click placement property and to open the placement dialog. Select a value e.g. "Translation, X:" and press "arrow down key" repeatedly. When the value passes 0, it becomes -1 and after that nothing changes when pressing the key more times.
The problem is due to the fact that the number in the InputField is formated based on the locale. For me, this means a negative value is represented with locale().negativeSign(). The Quantity parser doesn't recognize this negative sign which is distinct from a ascii '-' sign.
My solution for fixing this problem is to replace this and other locale dependent characters previous to passing the string to the Quantity parser. The locale().groupSeparator() is already removed to fixup the entered string. I don't think changing the parser to recognize more types of negative signs is the right way.
Let me know what you think and I'll make the appropriate changes.
Cheers,
Johan
For quite some time I've had a problem with the placement dialog concerning negative values. Any negative value is replaced with DOUBLE_MIN. This problem also breaks the use of stepping the value with up and down keys or using the mouse wheel to change value.
To Illustrate the problem just create an object e.g. a cube in parts. Then select the cube and choose the data tab in the property view. Click placement property and to open the placement dialog. Select a value e.g. "Translation, X:" and press "arrow down key" repeatedly. When the value passes 0, it becomes -1 and after that nothing changes when pressing the key more times.
The problem is due to the fact that the number in the InputField is formated based on the locale. For me, this means a negative value is represented with locale().negativeSign(). The Quantity parser doesn't recognize this negative sign which is distinct from a ascii '-' sign.
My solution for fixing this problem is to replace this and other locale dependent characters previous to passing the string to the Quantity parser. The locale().groupSeparator() is already removed to fixup the entered string. I don't think changing the parser to recognize more types of negative signs is the right way.
Let me know what you think and I'll make the appropriate changes.
Cheers,
Johan
Re: Problem with negative values in InputField
Hi Johan,
what again is your OS? Currently, I'm under Windows 7 and I can't see this behaviour.
what again is your OS? Currently, I'm under Windows 7 and I can't see this behaviour.
How do you come to this conclusion?Any negative value is replaced with DOUBLE_MIN
Hm, that's funny (or not). Here is a little Python script which tells me that on Windows the minus character is really the minus character and not an obscure Unicode sign.The problem is due to the fact that the number in the InputField is formated based on the locale. For me, this means a negative value is represented with locale().negativeSign(). The Quantity parser doesn't recognize this negative sign which is distinct from a ascii '-' sign.
Code: Select all
from PySide import QtCore
loc=QtCore.QLocale()
loc.negativeSign()
ord(loc.negativeSign()) # => 45
ord('-') # => 45
Yes, you're right. We should replace the "apparent" minus with the real ASCII minus character.My solution for fixing this problem is to replace this and other locale dependent characters previous to passing the string to the Quantity parser. The locale().groupSeparator() is already removed to fixup the entered string. I don't think changing the parser to recognize more types of negative signs is the right way.
Let me know what you think and I'll make the appropriate changes.
Re: Problem with negative values in InputField
Hi,
I'm on Ubuntu 14.04 64-bit, but I think I had the same problem on 13.10.
the unrecognized negative sign aborts parse() with an empty input.
For me your script gives
I'm on Ubuntu 14.04 64-bit, but I think I had the same problem on 13.10.
From QuantityParser.c line 1453-1454wmayer wrote:How do you come to this conclusion?Any negative value is replaced with DOUBLE_MIN
Code: Select all
#line 33 "QuantityParser.y"
{ QuantResult = Quantity(DOUBLE_MIN); /* empty input */ }
For me your script gives
Code: Select all
from PySide import QtCore
loc=QtCore.QLocale()
loc.negativeSign() # => u'\u2212'
ord(loc.negativeSign()) # => 8722
ord('-') # => 45
I'll make the necessary changes and leave a link to the branch here. The "QuantitySpinBox" also seems to be affected.wmayer wrote:Yes, you're right. We should replace the "apparent" minus with the real ASCII minus character.
Re: Problem with negative values in InputField
OK, thanks!
Re: Problem with negative values in InputField
I do not see the bug here...perhaps that's due to my KDE Language/local settings (English GB, Australia).
OS: Ubuntu 14.04.1 LTS
Word size: 64-bit
Version: 0.15.3783 (Git)
Branch: master
Hash: 4dee80f4e121541801fd4d8552e66ba26dc2c9b5
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
SoQt version: 1.6.0a
OCC version: 6.7.1
OS: Ubuntu 14.04.1 LTS
Word size: 64-bit
Version: 0.15.3783 (Git)
Branch: master
Hash: 4dee80f4e121541801fd4d8552e66ba26dc2c9b5
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
SoQt version: 1.6.0a
OCC version: 6.7.1
Re: Problem with negative values in InputField
What UnitSchema are you using? The imperial one skips the group separators added by default in MKS and Internal
UnitsSchemaMKS::, UnitsSchemaInternal:: and UnitsSchemaImperial1::schemaTranslate(...):
UnitsSchemaImperialDecimal::schemaTranslate(...):
UnitsSchemaMKS::, UnitsSchemaInternal:: and UnitsSchemaImperial1::schemaTranslate(...):
Code: Select all
return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
Code: Select all
QLocale Lc = QLocale::system();
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
QString Ln = Lc.toString(quant.getValue() / factor);
return QString::fromLatin1("%1 %2").arg(Ln).arg(unitString);
//return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
Re: Problem with negative values in InputField
I don't know why for UnitsSchemaImperialDecimal this is handled differently. Maybe you should contact jriegel directly via PM.
For me of course all unit systems work properly with negative numbers.
For me of course all unit systems work properly with negative numbers.
Re: Problem with negative values in InputField
My Units are set to the FreeCAD default, mm/kg/s/degree
Jim
Jim
Re: Problem with negative values in InputField
Im not quit sure I understand the problem!?
If there are different unicode numbers for the minus sign, that's no problem. I need the number and I add it to the parster (scanner).
If there are different unicode numbers for the minus sign, that's no problem. I need the number and I add it to the parster (scanner).
Stop whining - start coding!
Re: Problem with negative values in InputField
Unicode codepage is u'\u2212'
Code: Select all
s=u'\u2212'
print s.encode("utf-8") # => prints "-"
s.encode("utf-8") # => '\xe2\x88\x92'