Colorbar macro test

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:

Re: Colorbar macro test

Post by bernd »

Which Macro on which FreeCAD ?

The macro from my post viewtopic.php?f=18&t=12355#p99560 works for me on

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6157 (Git)
Build type: Release
Branch: master
Hash: b6faaefaf8adc81bd2f41aebe7516ccd3cbb50a0
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
Attachments
screen.png
screen.png (248.9 KiB) Viewed 2231 times
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Colorbar macro test

Post by bernd »

On ubuntu I have problems too:

Code: Select all

Traceback (most recent call last):
  File "/home/bhb/.FreeCAD/Mod/Macros/FEM_ColorBAR.FCMacro", line 50, in <module>
    ColorMapWidget.setWidget(ColorMap()) # load the Ui script
  File "/home/bhb/.FreeCAD/Mod/Macros/FEM_ColorBAR.FCMacro", line 21, in __init__
    layout.addWidget(self.canvas)
<type 'exceptions.TypeError'>: 'PySide.QtGui.QBoxLayout.addWidget' called with wrong argument types:
  PySide.QtGui.QBoxLayout.addWidget(FigureCanvasQTAgg)
Supported signatures:
  PySide.QtGui.QBoxLayout.addWidget(PySide.QtGui.QWidget, int = 0, PySide.QtCore.Qt.Alignment = 0)
OS: Ubuntu 15.04
Word size of OS: 32-bit
Word size of FreeCAD: 32-bit
Version: 0.16.6188 (Git)
Build type: None
Branch: master
Hash: bf19e80de17454b170cde98df5e4995a7a4991f6
Python version: 2.7.9
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
User avatar
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

Re: Colorbar macro test

Post by makkemal »

My version

OS: Ubuntu 14.04.3 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6163 (Git)
Build type: None
Branch: master
Hash: 273131c08857464fe7a140331afc864b7ae752f8
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Colorbar macro test

Post by bernd »

bernd wrote:

Code: Select all

Traceback (most recent call last):
  File "/home/bhb/.FreeCAD/Mod/Macros/FEM_ColorBAR.FCMacro", line 50, in <module>
    ColorMapWidget.setWidget(ColorMap()) # load the Ui script
  File "/home/bhb/.FreeCAD/Mod/Macros/FEM_ColorBAR.FCMacro", line 21, in __init__
    layout.addWidget(self.canvas)
<type 'exceptions.TypeError'>: 'PySide.QtGui.QBoxLayout.addWidget' called with wrong argument types:
  PySide.QtGui.QBoxLayout.addWidget(FigureCanvasQTAgg)
Supported signatures:
  PySide.QtGui.QBoxLayout.addWidget(PySide.QtGui.QWidget, int = 0, PySide.QtCore.Qt.Alignment = 0)
Mhh, the addWidget function needs a QWidget but gets a FigureCanvasQTAgg which is returned from matplotlib.pyplot.figure() It seams on Windows this get converted somehow but on Linux we need to take care of this. I have never been working with matplotlib :? Anyone an idea how to solve this?
User avatar
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

Re: Colorbar macro test

Post by makkemal »

I got this working in ubuntu 14.04
It needed :
import os
os.environ['QT_API'] = 'pyside'

Code: Select all

import sys
import FreeCAD
import FreeCADGui
import os
os.environ['QT_API'] = 'pyside'
from PySide import QtGui, QtCore
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
 
class ColorMap(QtGui.QWidget):
    def __init__(self, parent=None):
        super(ColorMap, self).__init__(parent)
 ##
        self.figure = plt.figure()
        self.canvas = FigureCanvas(self.figure)

        self.draw_colormap()

        # set the layout
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.canvas)
        self.setLayout(layout)
          
    def draw_colormap(self):
        sel = FreeCADGui.Selection.getSelection() # Selection
        if not sel:
            QtGui.QMessageBox.critical(None, "ColorMap macro", "An object has to be selected to run")
            return
        sel1=sel[0]
       # Stess Values in MPa
        datos=sel1.StressValues
        val_max=max(datos)
        val_min=min(datos)
        # axes
        ax = self.figure.add_axes([0.05, 0.10, 0.5, 0.8])
        cmap = mpl.cm.jet
        norm = mpl.colors.Normalize(vmin=val_min, vmax=val_max)
        ticks_cm = np.linspace(val_min, val_max, 10, endpoint=True)
        cb1 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
                                           norm=norm,
                                           ticks=ticks_cm,
                                           orientation='vertical')
        label_cm = 'Von Misses Stress [MPa]'
        cb1.set_label(label=label_cm,weight='bold')
        cb1.ax.tick_params(labelsize=16) 
        self.canvas.draw()

mw = FreeCADGui.getMainWindow()  # access the main window 
ColorMapWidget = QtGui.QDockWidget() # create a new dockwidget
ColorMapWidget.setWidget(ColorMap()) # load the Ui script
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,ColorMapWidget)  # add the widget to the main window
Screenshot.png
Screenshot.png (454.57 KiB) Viewed 2154 times
Last edited by makkemal on Wed Jan 20, 2016 5:24 pm, edited 1 time in total.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Colorbar macro test

Post by bernd »

Wow cool works for me to on Debian Jessie and FreeCAD 0.16.6237

BTW:
There is a type in the first line on the first character. It is

Code: Select all

mport sys
but should be

Code: Select all

import sys
You may could edit your post in this regard for others to get it work immediately.
User avatar
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

Re: Colorbar macro test

Post by makkemal »

Sorry copy paste finger trouble. Post updated
Post Reply