getElement() should returns solids too

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
bernd
Posts: 3924
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

getElement() should returns solids too

Postby bernd » Mon Dec 05, 2016 7:23 am

The getElement() method only returns Faces, Edges and Vertices. Would it not make sense to return solids too? Attached an example for a CompSolid. The method returns an unknown exception

bernd

Code: Select all

doc = App.ActiveDocument

# build a CompSolid out of two boxes
import Part
box_obj1 = doc.addObject('Part::Box', 'Box1')
box_obj2 = doc.addObject('Part::Box', 'Box2')
box_obj2.Placement.Base = (10, 0, 0)
import BOPTools.SplitFeatures
cs = BOPTools.SplitFeatures.makeBooleanFragments(name= 'CompSolid')
cs.Objects = [box_obj1, box_obj2]
cs.Mode = "CompSolid"
for obj in cs.ViewObject.Proxy.claimChildren():
    obj.ViewObject.hide()

doc.recompute()


# test if we have solids
cs.Shape.Solids


# try to get the element 'Solid1'
solid_element = 'Solid1'
ele = cs.Shape.getElement(solid_element)


output:

Code: Select all

>>> ele = cs.Shape.getElement(solid_element)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
SystemError: error return without exception set



OS: Debian GNU/Linux 8.6 (jessie)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.9166 (Git)
Build type: Unknown
Branch: master
Hash: 7a32aed27e5febf94611a3356d4f20b2bc6b6bf3
Python version: 2.7.9
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 7.0.0
wmayer
Site Admin
Posts: 11355
Joined: Thu Feb 19, 2009 10:32 am

Re: getElement() should returns solids too

Postby wmayer » Mon Dec 05, 2016 8:18 am

The getElement() method only returns Faces, Edges and Vertices. Would it not make sense to return solids too? Attached an example for a CompSolid.

The idea of this function was to handle only shape types with a direct geometrical meaning and these are only vertex, edge and face. All other shape types have a pure topological meaning and one place where this becomes obvious is the view provider and the selection framework. There you can only interact with points, lines and faces but not with wires, shells, solids, ...
User avatar
bernd
Posts: 3924
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: getElement() should returns solids too

Postby bernd » Mon Dec 05, 2016 11:31 am

Hi Werner,

wmayer wrote:
The getElement() method only returns Faces, Edges and Vertices. Would it not make sense to return solids too? Attached an example for a CompSolid.
The idea of this function was to handle only shape types with a direct geometrical meaning and these are only vertex, edge and face. All other shape types have a pure topological meaning
I assumed you gone write something like this.


wmayer wrote:... and one place where this becomes obvious is the view provider and the selection framework. There you can only interact with points, lines and faces but not with wires, shells, solids, ...
May be that's the real problem we gone face. Try to select a Solid out of the CompSolid. Not a box the solid is made off, but a solid of the CompSolid.

For my the new mesh region object exact this is needed, select one of the Solids a CompSolid is made off (not build from!). I did a work around I'm not happy with because it is implemented in the task panel and not in the selection frame work. IMHO this should be implemented in the selection frame work at some point in the future. FEM topic of mesh region object: viewtopic.php?f=18&p=147507#p147507 See screen and commit https://github.com/berndhahnebach/FreeC ... 81c1a1b192

cheers bernd

screen.jpg
screen.jpg (144.67 KiB) Viewed 254 times
User avatar
bernd
Posts: 3924
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: getElement() should returns solids too

Postby bernd » Wed Dec 07, 2016 5:35 pm

I solved it on various places in FEM the following way:

Code: Select all

if eles.startswith('Solid'):
    ele_shape = sub[0].Shape.Solids[int(eles.lstrip('Solid')) - 1]  # Solid
else:
    ele_shape = sub[0].Shape.getElement(eles)  # Face, Edge, Vertex
User avatar
bernd
Posts: 3924
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: getElement() should returns solids too

Postby bernd » Thu Dec 15, 2016 6:31 am

added an own method for the use in FEM since it is cumbersome to distinguish every time: https://github.com/berndhahnebach/FreeC ... it/87f0058
User avatar
bernd
Posts: 3924
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: getElement() should returns solids too

Postby bernd » Fri Mar 17, 2017 7:39 pm

bernd wrote:added an own method for the use in FEM since it is cumbersome to distinguish every time: https://github.com/berndhahnebach/FreeC ... it/87f0058
in master ... git commit d64e2cf and https://github.com/FreeCAD/FreeCAD/comm ... 92998R1235