Group data gets lost if a FemMesh is assigned to a new document object

About the development of the FEM module/workbench.

Moderator: bernd

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

Group data gets lost if a FemMesh is assigned to a new document object

Post by bernd »

If a FemMesh with groups is assingned to a new document object from type FemMeshObject the group data is lost in space ... Attached a file and the code.

cheers bernd
GroupMeshProblems.FCStd
(15.32 KiB) Downloaded 13 times
the code:

Code: Select all

obj1 = App.ActiveDocument.getObject("mesh_with_groups")
obj1.FemMesh.GroupCount

msh1 = obj1.FemMesh
msh1.GroupCount

obj2 = App.ActiveDocument.addObject("Fem::FemMeshObject","new_mesh_with_groups")
obj2.FemMesh = obj1.FemMesh
obj2.FemMesh.GroupCount

output:

Code: Select all

>>> obj1 = App.ActiveDocument.getObject("mesh_with_groups")
>>> obj1.FemMesh.GroupCount
10
>>> 
>>> msh1 = obj1.FemMesh
>>> msh1.GroupCount
10
>>> 
>>> obj2 = App.ActiveDocument.addObject("Fem::FemMeshObject","new_mesh_with_groups")
>>> obj2.FemMesh = obj1.FemMesh
>>> obj2.FemMesh.GroupCount
0
>>> 

FreeCAD version

Code: Select all

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.8796 (Git)
Build type: Release
Branch: master
Hash: e5045f72e954ec295318f5271e9ffddd95b73847
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Group data gets lost if a FemMesh is assigned to a new document object

Post by yorik »

Yes all the python groups are currently not working after last extensions merge... ickby, that's your turn now ;)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Group data gets lost if a FemMesh is assigned to a new document object

Post by bernd »

yorik wrote:Yes all the python groups are currently not working after last extensions merge... ickby, that's your turn now ;)
No it's not this. The groups I'm talking about are not FreeCAD groups. The lost groups are SMESH groups.
wmayer
Founder
Posts: 20323
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Group data gets lost if a FemMesh is assigned to a new document object

Post by wmayer »

I would say it's simply not implemented in https://github.com/FreeCAD/FreeCAD/blob ... h.cpp#L112
Unfortunately the smesh classes don't offer a method to assign data to a new instance. So, we have to do this all on our own.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Group data gets lost if a FemMesh is assigned to a new document object

Post by bernd »

wmayer wrote:git commit a812ad2
:shock: works great :D
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Group data gets lost if a FemMesh is assigned to a new document object

Post by bernd »

I'm facing the next problem ... I added a python object to the Fem::FemMeshObject. See https://github.com/berndhahnebach/FreeC ... fa61fee064

My new python mesh object works great so far except the ViewProvider. The defs from the FemGui::ViewProviderFemMesh are missing in the FemGui::ViewProviderFemMeshPython.

code:

Code: Select all

mesh = App.ActiveDocument.getObject("Box_mesh")
mesh.TypeId
mesh.ViewObject.TypeId
mesh.ViewObject.setNodeColorByScalars()

mesh_python = App.ActiveDocument.getObject("Box_Mesh")
mesh_python.TypeId
mesh_python.ViewObject.TypeId
mesh_python.ViewObject.setNodeColorByScalars()

output:

Code: Select all

>>> mesh = App.ActiveDocument.getObject("Box_mesh")
>>> mesh.TypeId
'Fem::FemMeshObject'
>>> mesh.ViewObject.TypeId
'FemGui::ViewProviderFemMesh'
>>> mesh.ViewObject.setNodeColorByScalars()
>>> 
>>> mesh_python = App.ActiveDocument.getObject("Box_Mesh")
>>> mesh_python.TypeId
'Fem::FemMeshObjectPython'
>>> mesh_python.ViewObject.TypeId
'FemGui::ViewProviderFemMeshPython'
>>> mesh_python.ViewObject.setNodeColorByScalars()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'Gui.ViewProviderPythonFeature' object has no attribute 'setNodeColorByScalars'
>>> 
mesh--mesh_python.fcstd
(35.73 KiB) Downloaded 15 times
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Group data gets lost if a FemMesh is assigned to a new document object

Post by bernd »

I copied the code for the FemMeshObjectPython from FemSolverObjectPython. If I try to add a simple object I get a grey ViewProvider. On solver object python I get a coloured ViewProvider.

Code: Select all

obj1 = FreeCAD.ActiveDocument.addObject("Fem::FemMeshObjectPython", "test1")
obj2 = FreeCAD.ActiveDocument.addObject("Fem::FemMeshObject", "test2")

obj3 = FreeCAD.ActiveDocument.addObject("Fem::FemSolverObjectPython", "test3")
obj4 = FreeCAD.ActiveDocument.addObject("Fem::FemSolverObject", "test4")
mesh_vs_solver.fcstd
(2.52 KiB) Downloaded 16 times
screen.jpg
screen.jpg (30.59 KiB) Viewed 1215 times
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Group data gets lost if a FemMesh is assigned to a new document object

Post by bernd »

The defs I'm missing are implemented in ViewProviderFemMeshPyImp.cpp https://github.com/FreeCAD/FreeCAD/blob ... hPyImp.cpp How this is connected to ViewProviderFemMesh and my new PythonFeatureViewProvider ... I'm lost in space of C++
wmayer
Founder
Posts: 20323
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Group data gets lost if a FemMesh is assigned to a new document object

Post by wmayer »

In App we have two key classes:
The template class FeaturePythonT which implements the methods to hold a Python class that implements the Feature interface
The template class FeaturePythonPyT which implements the methods addProperty, removeProperty and supportedProperties to be used from Python side. You can extend your actual Python binding class by sub-classing

In Gui we have these two classes:
The template class ViewProviderPythonFeatureT is the counterpart of FeaturePythonT and implements the interface for view providers
The class ViewProviderPythonFeaturePy. This does serve the same purpose as FeaturePythonPyT but is not a template class. This way it's not easily possible at the moment to have a Python interface that implements the logic for Python view providers _and_ offer the methods addProperty, removeProperty and supportedProperties.

I think I should simplify the framework somewhat.
Post Reply