Dimension Parser Help

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
ChemicalCoal
Posts: 24
Joined: Sun May 09, 2021 3:38 am

Dimension Parser Help

Post by ChemicalCoal »

I see some odd behavior in the dimension input/edit box and I'd like to try to change it (hopefully for the better).

When putting dimensions with multiple units in the dimension editor it doesn't do what I would expect:
1mm => 1mm (ok)
1 + 1 mm => 2mm (ok)
1mm + 1mm => 1mm (expected 2mm)
1mm + 1in => 1mm (expected 26.4mm)

But all of these work as expected when using the formula editor.

I'd like to use the formula parser for the normal dimensions too.

Any hints as to where these bits lie in the code would be great,
I surmise the're somewhere near src/Mod/Sketcher/Gui/EditDatumDialog.cpp ,
But I didn't see any thing that looked like parsing.

Thanks!

Image
User avatar
Shalmeneser
Veteran
Posts: 9474
Joined: Wed Dec 23, 2020 12:04 am
Location: Fr

Re: Dimension Parser Help

Post by Shalmeneser »

Full version (follow red banner in Help Forum) ?

Sketcher : dimension :
* 1 + 1 mm => fail
* 1 mm + 1 => fail
* 1mm + 1mm => 2 mm
* 1 + 1 => 2 mm
* 1 mm + 1 in => 26.40 mm
ChemicalCoal
Posts: 24
Joined: Sun May 09, 2021 3:38 am

Re: Dimension Parser Help

Post by ChemicalCoal »

Sorry for late response,

Code: Select all

OS: Arch Linux
Word size of FreeCAD: 64-bit
Version: 0.20.29085 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 1e96bbd)
Hash: 1e96bbd2815683d6afa0afe8f985cdd04ef839fe
Python 3.10.4, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: English/United States (en_US)
Freecad version I currently use, although I have always had issues with this, and its not consistent even within the same version:

After some further investigation, I have determined the current bad eval occurs in:
/src/Base/Quantity.cpp

The working parser is accessed through the python Sketch.setExpression("Constraint[?], u"expression here") function.

This is located like 1057 of /src/App/PropertyExpressionEngine.cpp

I will continue to investigate.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Dimension Parser Help

Post by openBrain »

ChemicalCoal wrote: Tue Jun 21, 2022 2:04 am Freecad version I currently use, although I have always had issues with this, and its not consistent even within the same version:
I may be mistaken, but I found everything to be consistent.
Actually from empiric testing, I found a simple rule : formula parser does not support unit arithmetic and will stop parsing at first unit it finds :
* 1 mm + 1 in => 1 mm
* 1 in + 1 mm => 25.4 mm
* 1 + 1 mm => 2 mm
* 1 + 1 in => 50.8 mm
Am I missing something ?

Parser is at the end of this file : https://github.com/FreeCAD/FreeCAD/blob ... tyParser.y
You can see it doesn't define operations between quantities. ;)
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Dimension Parser Help

Post by adrianinsaval »

can you share a file were you encounter this issue? my best guess is that something is broken in the file so the sketch doesn't recompute and the expression isn't updated so it stays with it's last value before the breakage, that's the only situation where I see stuff like this
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Dimension Parser Help

Post by openBrain »

adrianinsaval wrote: Tue Jun 21, 2022 1:38 pm can you share a file were you encounter this issue? my best guess is that something is broken in the file so the sketch doesn't recompute and the expression isn't updated so it stays with it's last value before the breakage, that's the only situation where I see stuff like this
It's not about expressions, but formulas. ;) I.e. the formulas that you can directly enter in a quantity spin box without opening expression dialog. ;)
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Dimension Parser Help

Post by adrianinsaval »

right! I often forget you can make math there directly, so you can't use multiple units there then? It would be better to fail or show a warning when there are multiple units rather than just accept and give a wrong result that only takes one unit into account
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Dimension Parser Help

Post by openBrain »

I don't know exactly what to think of this feature.
ATM what comes to the foreground is that it creates inconsistency because you can do it for quantities, but not for simple (unitless) integers or floats...
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Dimension Parser Help

Post by adrianinsaval »

does this use a completely separate parser from the expression engine? can't we reuse a subset of the expression parser for this?
aapo
Posts: 615
Joined: Mon Oct 29, 2018 6:41 pm

Re: Dimension Parser Help

Post by aapo »

adrianinsaval wrote: Tue Jun 21, 2022 8:12 pm does this use a completely separate parser from the expression engine? can't we reuse a subset of the expression parser for this?
I think these are good questions. This would be a good idea, especially for future consistency, so that the parsers do not start to diverge even more, which might confuse users.
Last edited by aapo on Wed Jun 22, 2022 7:04 am, edited 1 time in total.
Post Reply