FEM: examples, improve explanation text object

This commit is contained in:
Bernd Hahnebach
2021-06-17 10:39:28 +02:00
parent 74f28ac5bc
commit 1d760a979b
2 changed files with 41 additions and 18 deletions

View File

@@ -21,19 +21,12 @@
# * *
# ***************************************************************************
# to run the example use:
"""
from femexamples.buckling_lateraltorsionalbuckling import setup
setup()
"""
import json
import FreeCAD
import Fem
import ObjectsFem
from . import manager
from .manager import get_meshname
from .manager import init_doc
@@ -50,10 +43,13 @@ def get_information():
}
def get_explanation():
return """{name}
def get_explanation(header=""):
return header + """
To run the example from Python console use:
from femexamples.buckling_lateraltorsionalbuckling import setup
setup()
{information}
See forum topic post:
https://forum.freecadweb.org/viewtopic.php?f=18&t=20217&start=110#p510526
@@ -68,7 +64,7 @@ Mcr = 43.28 kNm = 43'280'000 Nmm
flange load for a buckling factor of 1.00:
43280000 Nmm / 278.6 mm = 155348 N
""".format(name=get_information()["name"], information=json.dumps(get_information(), indent=4))
"""
def setup(doc=None, solvertype="ccxtools"):
@@ -78,11 +74,8 @@ def setup(doc=None, solvertype="ccxtools"):
doc = init_doc()
# explanation object
text_obj = doc.addObject("App::TextDocument", "Explanation_Report")
text_obj.Text = get_explanation()
text_obj.setPropertyStatus("Text", "ReadOnly") # set property editor readonly
if FreeCAD.GuiUp:
text_obj.ViewObject.ReadOnly = True # set editor view readonly
# just keep the following line and change text string in get_explanation method
manager.add_explanation_obj(doc, get_explanation(manager.get_header(get_information())))
# geometric objects
bottom_flange = doc.addObject("Part::Plane", "Bottom_Flange")

View File

@@ -146,3 +146,33 @@ def init_doc(doc=None):
def get_meshname():
# needs to be "Mesh" to work with unit tests
return "Mesh"
def get_header(information):
return """{name}
{information}""".format(name=information["name"], information=print_info_dict(information))
def print_info_dict(information):
the_text = ""
for k, v in information.items():
value_text = ""
if isinstance(v, list):
for j in v:
value_text += "{}, ".format(j)
value_text = value_text.rstrip(", ")
else:
value_text = v
the_text += "{} --> {}\n".format(k, value_text)
# print(the_text)
return the_text
def add_explanation_obj(doc, the_text):
text_obj = doc.addObject("App::TextDocument", "Explanation_Report")
text_obj.Text = the_text
text_obj.setPropertyStatus("Text", "ReadOnly") # set property editor readonly
if FreeCAD.GuiUp:
text_obj.ViewObject.ReadOnly = True # set editor view readonly
return text_obj