Shape pointer always changing

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Shape pointer always changing

Post by openBrain »

Hi,

Foreword : posted here because I think normal users don't really care of this. :)

I observe a strange behavior. I just wanted to post it here because I'm worried it could hide a underlying flaw, so I'd like to confirm and eventually get some insights on this.

When displaying all properties in the Property pane ('Data' tab), you can see a 'Shape' property that basically gives a reference to the current shape instance of the object (I guess).
What I see is that each time mouse pointer hovers the property, the referenced memory address jumps to another while obviously the shape hasn't been changed.
Same effect appears for example if the mouse cursor leaves out / enters in the property pane.

Is there something logical behind this behavior ?
changingShape.gif
changingShape.gif (106.67 KiB) Viewed 1218 times
kisolre
Veteran
Posts: 4162
Joined: Wed Nov 21, 2018 1:13 pm

Re: Shape pointer always changing

Post by kisolre »

Noticed the same a long time ago, probably the first time I tried ShowAll. But since I am not a programmer thought that it just works like that...
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Shape pointer always changing

Post by wmayer »

Nothing you have to worry about. If you run this line several times then it also shows a different address every time:

Code: Select all

App.ActiveDocument.ActiveObject.Shape
It's caused by this function: https://github.com/FreeCAD/FreeCAD/blob ... mp.cpp#L68 where getTopoShapePtr() returns the memory address of the copy of the TopoShape.

The call of the Shape property always invokes https://github.com/FreeCAD/FreeCAD/blob ... e.cpp#L149 for the same instance of PropertyPartShape but the internal call of

Code: Select all

_Shape.getPyObject()
is responsible to create a new Python wrapper and a copy of TopoShape each time: https://github.com/FreeCAD/FreeCAD/blob ... e.cpp#L575

Maybe the representation() functions of the shape classes could be changed to write the shape's hash value because then the value will be always the same. And the memory address isn't useful anyway.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Shape pointer always changing

Post by onekk »

wmayer wrote: Fri Jan 28, 2022 6:44 pm Maybe the representation() functions of the shape classes could be changed to write the shape's hash value because then the value will be always the same. And the memory address isn't useful anyway.
For coherence it would be a good change.

I've noted another thing, that there is some an ID value, that resemble to be a good way to get an object at least using Python.

So maybe having a function like .getObject() fashioned like .getObjectbyID and store the ID (it is the hash or something else?) instead of name,

I could thing of many places in code where a list could contains all the ID of the created objects and when reused the iterator is done over the "list of ID", and the correct object is retrieve "on Demand".

I know that is not related to the OP, but is related to references of an object.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Shape pointer always changing

Post by openBrain »

wmayer wrote: Fri Jan 28, 2022 6:44 pm Nothing you have to worry about.
OK, that's the more important. :)
If you run this line several times then it also shows a different address every time:

Code: Select all

App.ActiveDocument.ActiveObject.Shape
(...)
Maybe the representation() functions of the shape classes could be changed to write the shape's hash value because then the value will be always the same. And the memory address isn't useful anyway.
Yes probably at some point it would be good to change so from user PoV, a "stable" value is observed.

Also, do you know if fact that field value is recomputed when mouse hovered is coded in FreeCAD, or is just an intrinsic behavior of Qt ?

Thanks for thorough explanations.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Shape pointer always changing

Post by wmayer »

Also, do you know if fact that field value is recomputed when mouse hovered is coded in FreeCAD, or is just an intrinsic behavior of Qt ?
Could be caused by Qt but there might be options to reduce possibly superfluous redraws. The relevant involved classes are PropertyEditor (a sub-class of QTreeView), PropertyItemDelegate (a sub-class of QItemDelegate) and PropertyModel (a sub-class of QAbstractItemModel)
Post Reply