How to use C3D10 instead of C3D4 elements?

About the development of the FEM module/workbench.

Moderator: bernd

wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by wmayer »

This sounds more like an issue with PySide http://tech-artists.org/forum/showthrea ... ev-in-maya
"MeshGmsh" is not the FEM mesh but it's the class name of the widget, it is derived from QtGui.QWidget. And "event" is a method of QWidget and that it apparently doesn't exist could be an indication for problems when deleting the widget.

And there is definitely a bug in the script because it also creates a QDockWidget to embed the MeshGmsh. When pressing Cancel it deletes the MeshGmsh widget but not its parent widget the QDockWidget which is only hidden.
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by PrzemoF »

I added this to the macro:

Code: Select all

    def event(self, event):
        print "Event called with param: {} of type {}".format(event, type(event))
and that's the output (I use tablet):

Code: Select all

Event called with param: <0x7fff32422a80  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QTabletEvent'>
Event called with param: <0x7fff32422a80  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QTabletEvent'>
Event called with param: <0x7fff32422e50  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QTabletEvent'>
Event called with param: <0x7fff32422e50  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QTabletEvent'>
Event called with param: <0x7fff32422e50  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QTabletEvent'>
Event called with param: <0x7fff32422e50  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QTabletEvent'>
Event called with param: <0x7fff32422e50  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QTabletEvent'>
Event called with param: <0x7fff32422e50  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QTabletEvent'>
Event called with param: <0x7fff32422d10  at 0x7f0d641253b0> of type <type 'PySide.QtCore.QEvent'>
Event called with param: <0x7fff32423020  at 0x7f0d641253b0> of type <type 'PySide.QtCore.QEvent'>
Event called with param: <0x7fff32422420  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QPaintEvent'>
Event called with param: <0x7fff32422420  at 0x7f0d641253b0> of type <type 'PySide.QtGui.QPaintEvent'>
The events are generated when cursor is entering/leaving macro window.
I'll change "print" to "pass" - it might settle the problem.

It could be that once in a while there was an event that wasn't handled by anything and the macro got blamed for it. I don't know if adding an empty event handler can fix it, but I'll know soon.

Edit:
New error, so I'll test "return False"

Code: Select all

/home/przemo/.FreeCAD/GMSHMesh.FCMacro:19: RuntimeWarning: Invalid return value in function QWidget.event, expected bool, got NoneType.
  self.initUI()
sys:1: RuntimeWarning: Invalid return value in function QWidget.event, expected bool, got NoneType.
bin/FreeCAD:145: RuntimeWarning: Invalid return value in function QWidget.event, expected bool, got NoneType.
Edit1:
Didn't help, but I found a way of reproducing the error (6 out of 6 tests crashed).
1. New document
2. Part wb
3. Start the macro
4. Create cube
5. Switch to Draft --> Crash with message "Workbench failure" "'MeshGmsh' object has no attribute 'event'"
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by wmayer »

OK, I can confirm this behaviour on Windows, too. However, the steps to create a document or a cube are irrelevant. Just start the macro when FreeCAD starts. Then you can switch to the various workbenches and the widget gets partially destroyed when switching to these workbenches:
  • Arch
  • Draft
When switching through all workbenches at some point the widget gets destroyed too but it reliably happens with the above two.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by wmayer »

It turns out to be a pivy/PySide problem. Make sure to not have loaded any workbench that uses pivy. If you then start the macro and type this into the Python console the widget gets partially destroyed.

Code: Select all

from pivy import coin
So, it's definitely not a FreeCAD bug.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by wmayer »

Loading pivy after the macro is executed seems to seriously damage the Python interpreter. Whatever Python code is executed afterwards there is always raised an exception. As a workaround you can put this as very first line inside the macro:

Code: Select all

from pivy import coin
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by PrzemoF »

Thanks! Looks like it's working as expected
Updated macro here: https://github.com/PrzemoF/Macros_FreeC ... its/master
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by wmayer »

I have found a better fix. I have no clue why all this happens and it's almost impossible to debug. So adding the __del__ method to MeshGmsh fixes this, too.

Code: Select all

    def __del__(self):
        return
So, I assume that when importing pivy the __del__ method of the parent class was called and this destroys/invalidates the widget.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by wmayer »

Then to fix the other problem where the QDockWidget is not destroyed you have to add:

Code: Select all

d = QtGui.QDockWidget()
d.toggleViewAction().setText("Gmsh")
d.setAttribute(QtCore.Qt.WA_DeleteOnClose)
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by PrzemoF »

wmayer wrote:I have found a better fix. I have no clue why all this happens and it's almost impossible to debug. So adding the __del__ method to MeshGmsh fixes this, too.

Code: Select all

    def __del__(self):
        return
So, I assume that when importing pivy the __del__ method of the parent class was called and this destroys/invalidates the widget.
Thanks, applied!
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: How to use C3D10 instead of C3D4 elements?

Post by PrzemoF »

wmayer wrote:Then to fix the other problem where the QDockWidget is not destroyed you have to add:

Code: Select all

d = QtGui.QDockWidget()
d.toggleViewAction().setText("Gmsh")
d.setAttribute(QtCore.Qt.WA_DeleteOnClose)
Thanks again! It's really important for me, as the FreeCAD build-in meshing doesn't work on my both installations (fedora) and I use gmsh as the main meshing tool.
Post Reply