Screen overlay for stress/displacement scale

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Screen overlay for stress/displacement scale

Post by PrzemoF »

I want to code a colour bar showing stress/displacement for FEM wb. Is there any preferred way of adding some overlay elements to the main windows? (the inventor view? I'm not sure what's the proper name).
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Screen overlay for stress/displacement scale

Post by wmayer »

First have a look at the colour bar we already have if this fits into your needs. To get it working you e.g. have to load a surface mesh (STL, PLY, ...) then switch to the Mesh design workbench. Select the mesh in the tree and go to Mesh > Curvature plot.
Inside the 3d view a colour bar appears on the right side.

Hint: To see the colour gradient of the curvature plot you must hide the surface mesh.
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Screen overlay for stress/displacement scale

Post by PrzemoF »

That is perfect and it looks exactly like what I want to make :-) Thanks!
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Screen overlay for stress/displacement scale

Post by PrzemoF »

What would be the best place for that stress bar in the source code? Is src/Mod/Fem/Gui/ViewProviderResult.* OK?
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Screen overlay for stress/displacement scale

Post by wmayer »

PrzemoF wrote:What would be the best place for that stress bar in the source code? Is src/Mod/Fem/Gui/ViewProviderResult.* OK?
Since this view provider is used to show the results I would put it there, too.
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Screen overlay for stress/displacement scale

Post by PrzemoF »

I need some "logistic" help. User sets some type of FEM results (U1, U2, U3, Uabs, Stress) in FEM dialog window. It's handled in python by src/Mod/Fem/MechanicalAnalysis.py. What's the best way of "transferring" that information to src/Mod/Fem/Gui/ViewProviderResult.cpp? I need that information to pick proper range for the color bar. I have all data accessible from a new AnalysisStats object, but that object is not good to transfer info about what user selected. I don't want to write what I have tried as nothing worked out the way I wanted, but I tried a _lot_. This is the last piece of code that is missing - I have ccxFrdReader preparing all stats from an .fd file and the color bar is ready and gets updated on setting range.
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Screen overlay for stress/displacement scale

Post by ebrahim raeyat »

Thanks. excuse me for inserting comment in old post, but i can't find a solution for my problem.
I want to add a color bar for some values in a list. I calculate some column's punch ratios.
then i want to show values by color and colorbar like in FEM workbench. I read the code, but i can't understand how can i do that.
at present i convert the color of columns that greater than 1.0 with red color. the color bar is drawn by matplotlib, but i want like in FEM.

Thanks.
colorbar.png
colorbar.png (32.77 KiB) Viewed 1906 times
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Screen overlay for stress/displacement scale

Post by ebrahim raeyat »

colorbar.png
colorbar.png (21.24 KiB) Viewed 1905 times
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Screen overlay for stress/displacement scale

Post by Kunda1 »

ebrahim raeyat wrote: Mon Mar 11, 2019 8:24 pm I want to add a color bar for some values in a list. I calculate some column's punch ratios.
then i want to show values by color and colorbar like in FEM workbench. I read the code, but i can't understand how can i do that.
at present i convert the color of columns that greater than 1.0 with red color. the color bar is drawn by matplotlib, but i want like in FEM.
bernd wrote:
Hey @bernd care to weigh in on this?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Screen overlay for stress/displacement scale

Post by ebrahim raeyat »

Hi @bernd. I read almost forum and web for drawing a color bar on main GUI in FreeCAD, but not succeed. Now I can't add the DockWidget to FreeCAD main window, last line takes me an error:

Code: Select all

import sys
sys.path.append("/home/ebi/freecads/freecad-build/lib")
import FreeCAD
import FreeCADGui
import os
os.environ['QT_API'] = 'Pyside2'
import PySide2
from PySide2 import QtGui, QtCore, QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
 
class ColorMap(PySide2.QtWidgets.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 = QtWidgets.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
        datos = [1, 2, 3, 4, 5]
        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()

# ColorMap()

mw = FreeCADGui.getMainWindow()  # access the main window 
ColorMapWidget = QtWidgets.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

Code: Select all

  File "/home/ebi/python/colorbar_freecad.py", line 25, in __init__
    layout.addWidget(self.canvas)
<class 'TypeError'>: 'PySide2.QtWidgets.QBoxLayout.addWidget' called with wrong argument types:
  PySide2.QtWidgets.QBoxLayout.addWidget(FigureCanvasQTAgg)
Supported signatures:
  PySide2.QtWidgets.QBoxLayout.addWidget(PySide2.QtWidgets.QWidget, int = 0, PySide2.QtCore.Qt.Alignment = Default(Qt.Alignment))
  PySide2.QtWidgets.QBoxLayout.addWidget(PySide2.QtWidgets.QWidget)
thank you so much.
Post Reply