[ Solved ] [ Bug ] gui_snapper: only a single face of solid can be Center snapped

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Roy_043
Veteran
Posts: 8577
Joined: Thu Dec 27, 2018 12:28 pm

[ Solved ] [ Bug ] gui_snapper: only a single face of solid can be Center snapped

Post by Roy_043 »

Bug report here:
https://forum.freecadweb.org/viewtopic. ... 48#p470527

The problem is with this portion in the code:

Code: Select all

                    elif "Face" in comp:
                        en = int(comp[4:])-1
                        if len(shape.Faces) > en:
                            face = shape.Faces[en]
In the V0.19 shape is a single face. But en is the index of that face relative to its parent solid. This means that you can only snap to the en=0 face of a solid.

Looking above that part in the code it is obvious that a similar issue for edges was fixed:

Code: Select all

                    if "Edge" in comp:
                        # we are snapping to an edge
                        edge = None
                        if shape.ShapeType == "Edge":
                            edge = shape
                        else:
                            en = int(comp[4:])-1
                            if len(shape.Edges) > en:
                                edge = shape.Edges[en]
                        if edge:
The easiest solution would be to use the same structure. But why still use en = int(comp[4:])-1 when we have a single face or edge already?
Last edited by Roy_043 on Tue Feb 02, 2021 2:53 pm, edited 1 time in total.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: [ Bug ] gui_snapper: only a single face of solid can be Center snapped

Post by carlopav »

Roy_043 wrote: Sun Jan 24, 2021 8:45 pm en = int(comp[4:])-1
Looks like the code allows en to be a string "Edge1", so it extract the Edge Number from it... Can this be the case?
Edit: because comp Is a string!
follow my experiments on BIM modelling for architecture design
User avatar
Roy_043
Veteran
Posts: 8577
Joined: Thu Dec 27, 2018 12:28 pm

Re: [ Bug ] gui_snapper: only a single face of solid can be Center snapped

Post by Roy_043 »

carlopav wrote: Sun Jan 24, 2021 9:04 pm Edit: because comp Is a string!
Well, yes: en is an integer derived from a string. But that does not explain the bug.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: [ Bug ] gui_snapper: only a single face of solid can be Center snapped

Post by carlopav »

No, of course :)
Anyway the code you quoted seems to make sense. Perhaps the problem Is somewhere else...
follow my experiments on BIM modelling for architecture design
User avatar
Roy_043
Veteran
Posts: 8577
Joined: Thu Dec 27, 2018 12:28 pm

Re: [ Bug ] gui_snapper: only a single face of solid can be Center snapped

Post by Roy_043 »

carlopav wrote: Sun Jan 24, 2021 9:40 pm Perhaps the problem Is somewhere else...
Well, that is often the case with code. Here the root cause of the issue is this mod:

V0.18

Code: Select all

            # active snapping
            comp = self.snapInfo['Component']

            if obj.isDerivedFrom("Part::Feature"):

                # applying global placements
                shape = obj.Shape.copy()
                shape.Placement = obj.getGlobalPlacement()

                snaps.extend(self.snapToSpecials(obj,lastpoint,eline))
V0.19

Code: Select all

            # Active snapping
            comp = self.snapInfo['Component']

            shape = Part.getShape(parent, subname,
                                  needSubElement=True,
                                  noElementMap=True)

            if not shape.isNull():
                snaps.extend(self.snapToSpecials(obj, lastpoint, eline))
So in V0.19 shape is already a subelement.

After introducing the mod it was, apparently (I am guessing here), discover that this created an issue for edges. Which resuted in this being added to the code attached to my previous post

Code: Select all

                        if shape.ShapeType == "Edge":
                            edge = shape
But, again I am guessing, without realizing that the code that follows will now never execute:

Code: Select all

                        else:
                            en = int(comp[4:])-1
                            if len(shape.Edges) > en:
                                edge = shape.Edges[en]
I could use the same structure for the face portion of the code. And that will fix the bug. Which is good. But I do not want to introduce a 2nd portion of dead code.

So in summary:
The bug is not a mystery and can be solved rather easily. But if I follow the edges example I think I will be adding more dead code, which would be a bad idea. But I do not have enough insight in the code to decide if there is in fact dead code.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: [ Bug ] gui_snapper: only a single face of solid can be Center snapped

Post by carlopav »

Looks like the culprit is this:

Code: Select all

            shape = Part.getShape(parent, subname,
                                  needSubElement=True,
                                  noElementMap=True)
this part of the code instead seems to be meant to speed up the snapper: if the shape is a single edge, no need to look for the right edge in the shape, take the whole shape as it is.

Code: Select all

                        if shape.ShapeType == "Edge":
                            edge = shape
but also in this case, shape.Edges should return a list with that single edge I guess... isn't it?

I'm sorry but thesedays i'm completely out of time to test and code... :oops:
follow my experiments on BIM modelling for architecture design
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [ Bug ] gui_snapper: only a single face of solid can be Center snapped

Post by Kunda1 »

Can we mark this as [Solved]?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
Roy_043
Veteran
Posts: 8577
Joined: Thu Dec 27, 2018 12:28 pm

Re: [ Bug ] gui_snapper: only a single face of solid can be Center snapped

Post by Roy_043 »

Yes.
hmk
Posts: 159
Joined: Tue Sep 29, 2020 1:19 pm
Location: Berlin, Germany

Re: [ Solved ] [ Bug ] gui_snapper: only a single face of solid can be Center snapped

Post by hmk »

Argh, mercy, I think it broke again!?

To reiterate: It's only possible to Snap_Center to first face of a solid.

OS: PureOS (GNOME/gnome)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23756 (Git) AppImage
Build type: Release
Branch: master
Hash: 9c6e9184930a52b165a0b7274e3a45d1006bfe67
Python version: 3.8.6
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)
Post Reply