Screen overlay for stress/displacement scale
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Screen overlay for stress/displacement scale
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).
Re: Screen overlay for stress/displacement scale
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.
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.
Re: Screen overlay for stress/displacement scale
That is perfect and it looks exactly like what I want to make Thanks!
Re: Screen overlay for stress/displacement scale
What would be the best place for that stress bar in the source code? Is src/Mod/Fem/Gui/ViewProviderResult.* OK?
Re: Screen overlay for stress/displacement scale
Since this view provider is used to show the results I would put it there, too.PrzemoF wrote:What would be the best place for that stress bar in the source code? Is src/Mod/Fem/Gui/ViewProviderResult.* OK?
Re: Screen overlay for stress/displacement scale
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.
- ebrahim raeyat
- Posts: 625
- Joined: Sun Sep 09, 2018 7:00 pm
- Location: Iran
- Contact:
Re: Screen overlay for stress/displacement scale
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.
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.
- ebrahim raeyat
- Posts: 625
- Joined: Sun Sep 09, 2018 7:00 pm
- Location: Iran
- Contact:
Re: Screen overlay for stress/displacement scale
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.
Hey @bernd care to weigh in on this?bernd wrote:
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
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
- ebrahim raeyat
- Posts: 625
- Joined: Sun Sep 09, 2018 7:00 pm
- Location: Iran
- Contact:
Re: Screen overlay for stress/displacement scale
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:
thank you so much.
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)