Ticket #3932 - Selecting solids on interior of CompSolid

About the development of the FEM module/workbench.

Moderator: bernd

gnathan87
Posts: 7
Joined: Sat Oct 13, 2018 10:47 pm

Ticket #3932 - Selecting solids on interior of CompSolid

Post by gnathan87 »

I have been having some trouble assigning materials to components of a CompSolid that are completely enclosed. I was following this tutorial, but unfortunately I do not get the same result when I select the interior face (my attempt attached). On 0.17 it just selects the outer solid again without complaint. On 0.18, I am told that "Face belongs to more than one solid", and the mesh region/material does not get assigned. Am I doing something wrong, and if not how can I get around it?

A related question: I originally tried to tackle this by using the CompoundFilter type 'specific-items'. This works with BooleanFragments in Standard mode (although it was not automatically recomputing the geometry when the percentages were altered - which I think it probably should). But in CompSolid mode, CompoundFilter does not seem to work in with either 'window-volume' or 'specific item' types, unless 100% of the solids are shown. Is this the intended behaviour?

Thank you!

OS: Debian GNU/Linux buster/sid
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.
Build type: Release
Python version: 2.7.15+
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
Attachments
test.fcstd
(12.92 KiB) Downloaded 100 times
Last edited by Kunda1 on Wed Sep 11, 2019 9:18 pm, edited 1 time in total.
Reason: Added ticket number to thread title
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Selecting solids on interior of CompSolid

Post by bernd »

Use 0.18 dev version there is a clipping tool in FEM which makes it easy to select inner solids.

BTW there have been tons of fixes in the regard of FEM in 0.18 !
gnathan87
Posts: 7
Joined: Sat Oct 13, 2018 10:47 pm

Re: Selecting solids on interior of CompSolid

Post by gnathan87 »

Thanks bernd. I just tried the clipping tool, but I'm afraid I still have the same problem (see attachment).

As an aside, I'm not sure that the clipping tool is the best long term solution for this. The Selection Tools mod does seem to correctly list sub-objects in its context menu. Is it possible to make these work (I presume there is a good reason why it does not already...), and/or have some way to cycle through sub-objects under the mouse cursor?

Really pleased to hear about the fixes :D thanks!
Attachments
clipping_screenshot.png
clipping_screenshot.png (128.27 KiB) Viewed 4830 times
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Selecting solids on interior of CompSolid

Post by bernd »

ahh the problem is on inner solids all element are shared between the two solids. You could make the BooleanFragment invisible and use the base solids instead. The geometry of them needs to be equal. But be carefull, if more than 2 Solids are involved the geometry of the base solid might not be equal with the solid you would like to select in BooldeanFragment.

hope that helps, bernd
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Selecting solids on interior of CompSolid

Post by bernd »

some selector would be needed to choose which solid to add. Feel free to add a mantis issue for this ...
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Selecting solids on interior of CompSolid

Post by DeepSOIC »

bernd wrote: Fri Mar 01, 2019 1:13 pm some selector would be needed
If you need help on writing such a selector, I think I can help.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Selecting solids on interior of CompSolid

Post by bernd »

DeepSOIC wrote: Fri Mar 01, 2019 2:15 pm
bernd wrote: Fri Mar 01, 2019 1:13 pm some selector would be needed
If you need help on writing such a selector, I think I can help.
sure, would be cool
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Selecting solids on interior of CompSolid

Post by DeepSOIC »

Code: Select all

class AmbiguousSelectionError(ValueError):
    pass

def pickSolid(subelement, shape):
    element_extractor = {
        'Vertex': (lambda sh: sh.Vertexes),
        'Edge':   (lambda sh: sh.Edges   ),
        'Face':   (lambda sh: sh.Faces   ),
    } [subelement.ShapeType]
    
    matches = [] # list of tuples: (solid, index_of_shell)
    
    for solid in shape.Solids:
        for index, shell in enumerate(solid.childShapes()):
            for el in element_extractor(shell):
                if el.isSame(subelement):
                    matches.append((solid, index))
    
    if len(matches) == 1:
        return matches[0][0]
    elif len(matches) == 2:
        # face belongs to two solids. If one is inside another, we should pick the inner solid. 
        # The difference is, for the inner solid, the selected element is on the outer shell (index 0), 
        # but for the other one it is on an inner shell (index > 0) 
        solid1, index1 = matches[0]
        solid2, index2 = matches[1]
        if index1 == index2 == 0:
            raise AmbiguousSelectionError()
        elif index1 > 0 and index2 > 0:
            #compsolids can't share inner shells, this shouldn't happen
            raise AmbiguousSelectionError()
        elif index1 > 0 and index2 == 0:
            return solid2
        elif index1 == 0 and index2 > 0:
            return solid1
        else:
            assert(False)
    else:
        #three or more solids share this element. Can't sort out.
        raise AmbiguousSelectionError()

#try it!
Part.show(pickSolid(Gui.Selection.getSelectionEx()[0].SubObjects[0], Gui.Selection.getSelectionEx()[0].Object.Shape))
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Selecting solids on interior of CompSolid

Post by DeepSOIC »

Okay, that code above can only work if the inner solid is completely buried inside of another solid. There is a more difficult case (and also more "practical"):
compsolid-pick-test-2.png
compsolid-pick-test-2.png (61.28 KiB) Viewed 4806 times
that can't be sorted out by the piece of code above. I'm thinking on how to improve/redesign it to treat this case too.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Selecting solids on interior of CompSolid

Post by DeepSOIC »

DeepSOIC wrote: Fri Mar 01, 2019 4:53 pm I'm thinking on how to improve/redesign it to treat this case too.
Would it be all right to ask user select more elements to identify a solid?
Post Reply