View Issue Details

IDProjectCategoryView StatusLast Update
0004831PathBugpublic2022-01-16 15:57
Reportersliptonic Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version0.20 
Target Version0.20 
Summary0004831: Path Command parameters are not mutable.
DescriptionThe Path Command object is central to the path workbench. It contains all the axis words and parameters for a single line of pseudo gcode.
However, the parameters are not mutable through the python interface. This often causes confusion, especially for new developers.

Steps To Reproduce>>> p = obj.Path.Commands[8]
>>> p
Command G3 [ F:0.8333 I:0 J:-2.5 K:0 X:-1.5 Y:76.038 Z:6 ]
>>> p.toGCode()
'G3 F0.833300 I0.000000 J-2.500000 K0.000000 X-1.500000 Y76.037957 Z6.000000'
>>> p.Parameters['F'] = 200
>>> p
Command G3 [ F:0.8333 I:0 J:-2.5 K:0 X:-1.5 Y:76.038 Z:6 ]
>>> p.Parameters
{'F': 200, 'I': 0.0, 'J': -2.5, 'K': 0.0, 'X': -1.5, 'Y': 76.037957, 'Z': 6.0}
>>> p.toGCode()
'G3 F0.833300 I0.000000 J-2.500000 K0.000000 X-1.500000 Y76.037957 Z6.000000'
>>> params = p.Parameters
>>> params['F'] = 200
>>> p.Parameters = params
>>> p
Command G3 [ F:200 I:0 J:-2.5 K:0 X:-1.5 Y:76.038 Z:6 ]
>>> p.toGCode()
'G3 F200.000000 I0.000000 J-2.500000 K0.000000 X-1.500000 Y76.037957 Z6.000000'
>>>
Additional Informationcomment by iromero91 in pull request code review: https://github.com/FreeCAD/FreeCAD/pull/5229

DOH, that's the problem with mutable properties in wrapped objects, seems to always be a 50/50 if they are going to work properly or not. I'm a bit tempted to call this a bug in the Path.Command object, you should be expected to modify a mutable property and have it, you know, change. The workaround using the temp variable should be ok but we should consider fixing the wrapping later. There are a few solutions I would deem more acceptable than what we got now there.

    Remove the property interface and use something like getParameters() and setParameters() instead. To make it clear that objects are passed by-copy and you cannot mutate them.
    Make Parameters return a proxy object so that mutating it actually does the changes expected.
    Make Parameters return an immutable object and have a function like setParameter() to be able to write to them
    Remove the extra indirection and implement the parameters dictionary on the command class itself via __getitem__ and __setitem__, that way you could do p["F"] = 200. Also possible to implement the rest of the basic dictionary interface with keys() and items()

TagsNo tags attached.
FreeCAD InformationOS: Linux Mint 20 (i3/i3)
Word size of FreeCAD: 64-bit
Version: 0.20.27078 +6 (Git)
Build type: Unknown
Branch: feature/drill-refactor
Hash: 9ca8e01771210cbcc6159629dc675cb43bd4053b
Python version: 3.8.10
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.5.2
Locale: English/United States (en_US)

Activities

yorik

2022-03-03 13:55

administrator   ~0017141

This ticket has been migrated to GitHub as issue 6310.

Issue History

Date Modified Username Field Change
2022-01-16 15:57 sliptonic New Issue