From 1d760a979b458b880cf0c32fea890c40134ceea8 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Thu, 17 Jun 2021 10:39:28 +0200 Subject: [PATCH] FEM: examples, improve explanation text object --- .../buckling_lateraltorsionalbuckling.py | 29 +++++++----------- src/Mod/Fem/femexamples/manager.py | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/Mod/Fem/femexamples/buckling_lateraltorsionalbuckling.py b/src/Mod/Fem/femexamples/buckling_lateraltorsionalbuckling.py index a3aa64a82b..527b14e6e9 100644 --- a/src/Mod/Fem/femexamples/buckling_lateraltorsionalbuckling.py +++ b/src/Mod/Fem/femexamples/buckling_lateraltorsionalbuckling.py @@ -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") diff --git a/src/Mod/Fem/femexamples/manager.py b/src/Mod/Fem/femexamples/manager.py index e14937a48f..8b47b686a6 100644 --- a/src/Mod/Fem/femexamples/manager.py +++ b/src/Mod/Fem/femexamples/manager.py @@ -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