Labels changing on save/restore - and expressions

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Post Reply
mlampert
Veteran
Posts: 1771
Joined: Fri Sep 16, 2016 9:28 pm

Labels changing on save/restore - and expressions

Post by mlampert »

The following script creates 2 spreadsheets, the first one gets a custom label, and the second one is created with that very same string as the name:

Code: Select all

import FreeCAD
import Part

doc = FreeCAD.newDocument('labels')
s1 = doc.addObject('Spreadsheet::Sheet', 'Spreadsheet')
s1.Label = 'SetupSheet'
s2 = doc.addObject('Spreadsheet::Sheet', 'SetupSheet')
s2.set('A1', '3 mm')
s2.setAlias('A1', 'Height')
doc.recompute()

box = doc.addObject('Part::Box', 'Box')
box.setExpression('Height', "%s.Height" % s2.Label)
doc.recompute()
It adds an alias to the second spreadsheet, creates a box and sets an expression for one of its properties - referencing the alias in the spreadsheet. The Tree looks like this:
original-tree.PNG
original-tree.PNG (4.97 KiB) Viewed 1993 times
Now if you safe that document and load it again the Tree changes to this:
reloaded-tree.PNG
reloaded-tree.PNG (4.13 KiB) Viewed 1993 times
And the expression on Box.Height is broken because it still references "SetupSheet001.Height" which of course doesn't exist because it should now be "SetupSheet002.Height".

It would probably be worse if first spreadsheet also had an Alias "Height" - in which case the expression would be valid and that little box might not be as little anymore.

Anybody got an idea on how to fix this?
triplus
Veteran
Posts: 9472
Joined: Mon Dec 12, 2011 4:45 pm

Re: Labels changing on save/restore - and expressions

Post by triplus »

mlampert wrote: Tue Oct 10, 2017 8:33 pm Anybody got an idea on how to fix this?
Based on your description likely a bug is involved and therefore i guess it could get fixed in the future and that is that.

As for more general opinion. Each feature should get an additional UUID (attribute) set when it is created. Any backend logic therefore should more or less evolve around and care about the UUID.

Example: User can use label as seen in the tree view when working with expressions. And the UUID is what expressions use and care about to determine the feature.
mlampert
Veteran
Posts: 1771
Joined: Fri Sep 16, 2016 9:28 pm

Re: Labels changing on save/restore - and expressions

Post by mlampert »

Ah - thanks for the pointer.
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Labels changing on save/restore - and expressions

Post by eivindkvedalen »

mlampert wrote: Wed Oct 11, 2017 6:02 pm Ah - thanks for the pointer.
Please try: https://github.com/eivindkv/FreeCAD/tre ... l_conflict

This is rebased on current master. If succesful, please register a bug report so I can create a proper PR for this.

Eivind
wmayer
Founder
Posts: 20074
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Labels changing on save/restore - and expressions

Post by wmayer »

FYI, in DocumentObject.h there is already the template class ObjectStatusLocker. So, there is no real need to have a second class to manipulate bits.
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Labels changing on save/restore - and expressions

Post by eivindkvedalen »

wmayer wrote: Sun Oct 15, 2017 5:28 pm FYI, in DocumentObject.h there is already the template class ObjectStatusLocker. So, there is no real need to have a second class to manipulate bits.
Thank you! I knew I had seen it somewhere, but couldn't find it! I'll of course use that one instead. Do we need to move it/modify it? The one I created modifies the status bits in Document, not DocumentObject.

Edit: didn't see that you had created it as a template class first. But maybe move it to somewhere in Base?

Eivind
wmayer
Founder
Posts: 20074
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Labels changing on save/restore - and expressions

Post by wmayer »

Edit: didn't see that you had created it as a template class first. But maybe move it to somewhere in Base?
In the past it was not a template class and tight to DocumentObjects. This was changed a few months ago because it was also needed for Documents to tmp. set bits.

If you like you can also replace this class with yours as it seems more general. In this case you can move it to Base/Tools.h -- don't forget to add the BaseExport macro, then.
Post Reply