diff --git a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Documentation.md b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Documentation.md index 37c61d2..75aa106 100644 --- a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Documentation.md +++ b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Documentation.md @@ -4,11 +4,7 @@ ## Short description -This example includes a script for generation of scripted actual circles, which can provide data — their radius — to any of two scripted diagram services. The diagram service `RadiusPlot` plots the radius of each circle element, the diagram service `RadiusHistogram` creates a radius histogram. - -> [!WARNING] -> Only one service function may be used at a time. -> All diagram services currently not in use must be stopped, otherwise no diagram is created. +This example includes a script for generating scripted actual circles, which can provide data — their radius — to any of two scripted diagram services. The diagram service `RadiusPlot` plots the radius of each circle element, the diagram service `RadiusHistogram` creates a radius histogram. ## Prerequisite @@ -25,15 +21,16 @@ The radius of any scripted circle is passed as a parameter to the scripted diagr context.data[stage] = { "ude_diagram_custom": 1, "ude_diagram_type": "SVGDiagram", - # Selected by circle creation dialog: "gom.api.diagram.radius_plot" or "gom.api.statistics.radius_histogram" - "ude_diagram_service" : params['service'], + # Selected by circle creation dialog: + # polisher = 'gom.api.diagram.radius_plot' or polisher = 'gom.api.statistics.radius_histogram' + "ude_diagram_service" : polisher, "ude_diagram_radius": params['radius'] } ``` ## Managing the scripted diagram services -Use Apps->Manage Services... to start either `RadiusPlot` or `RadiusHistogram` and stop any diagram service currently not in use. Only one diagram service may be active! +Use Apps->Manage Services... to start `RadiusPlot` and/or `RadiusHistogram`. ## Diagram settings diff --git a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Releasenotes.md b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Releasenotes.md index 006e06e..e5facbd 100644 --- a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Releasenotes.md +++ b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Releasenotes.md @@ -1,5 +1,10 @@ -# Release Notes OSMMapDiagram +# Release Notes ScriptedDiagramBasics +## Installation Requirements + +* Software Version + * ZEISS INSPECT 2025 + ## Released at 2024-09-30 (v1.0.0) * Initial release \ No newline at end of file diff --git a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Releasenotes.pdf b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Releasenotes.pdf index 7dad089..912bcb9 100644 Binary files a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Releasenotes.pdf and b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/Releasenotes.pdf differ diff --git a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/app_settings.png b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/app_settings.png index b862ba2..57ebdf1 100644 Binary files a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/app_settings.png and b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/app_settings.png differ diff --git a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/scripted_circle_dialog.png b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/scripted_circle_dialog.png index 553b610..96c2b19 100644 Binary files a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/scripted_circle_dialog.png and b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/doc/scripted_circle_dialog.png differ diff --git a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/radius_histogram.py b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/radius_histogram.py index a5b09f3..032aed9 100644 --- a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/radius_histogram.py +++ b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/radius_histogram.py @@ -13,43 +13,34 @@ # --- """Scripted diagram service creating a radius histogram""" -import io import gom import gom.api.settings -from gom import apifunction -import matplotlib.pyplot as plt -# Set path for debugging -SVG_PATH = None -#SVG_PATH = 'C:/temp/OSMMapDiagram.svg' +from gom import apifunction -# Set SVG resolution in dpi -SVG_DPI = 'figure' +import matplotlib.pyplot as plt +import gom.api.extensions.diagrams.matplotlib_tools as mpltools @apifunction -def radius_histogram(*args, **kwargs)->str: - """Plot element name/radius - - Args: - args (any): (unused) - kwargs (dict): {'': {'ude_diagram_custom': 1, 'ude_diagram_radius': , ...}, ...} - - Returns: - string: SVG image +def radius_histogram(view, element_data)->str: + """ + Plot radius histogram """ gom.log.info('Radius Histogram Service') - gom.log.info(f'{kwargs=}') + gom.log.info(f'{view=}, {element_data=}') + bins = gom.api.settings.get('bins') bins = [int(elem) for elem in bins.split(',') if elem.strip().isnumeric()] + + mpltools.setup_plot (plt, view) + radius = [] - for uuid, params in kwargs.items(): - radius.append(params['ude_diagram_radius']) + for e in element_data: + data = e['data'] - gom.log.debug(f'{bins=}') - gom.log.debug(f'{radius=}') + radius.append(data['ude_diagram_radius']) - plt.figure(figsize = (10, 5)) color = gom.api.settings.get('barcolor') # Creating the histogram plot @@ -74,21 +65,6 @@ def radius_histogram(*args, **kwargs)->str: xlabels.append(f'[{bins[i]},{bins[i+1]}]') plt.xticks(xticks, xlabels) - if SVG_PATH: - plt.savefig(SVG_PATH, format='svg', dpi=SVG_DPI) - - # Create an empty file-like object - svg_output = io.StringIO() - - # Save the plot to the file-like object - plt.savefig(svg_output, format='svg', dpi=SVG_DPI) - - # Get the SVG string from the file-like object - svg_string = svg_output.getvalue() - - # Close the file-like object - svg_output.close() - - return svg_string + return mpltools.create_svg (plt, view) -gom.run_api() \ No newline at end of file +gom.run_api() diff --git a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/radius_plot.py b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/radius_plot.py index d2e14d8..b377f7e 100644 --- a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/radius_plot.py +++ b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/radius_plot.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # -# radius_histogram.py +# radius_plot.py # -# Service function which receives the radii of all elements plots +# Service function which receives the radii of all elements and plots # radius and element name. # See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html # @@ -13,76 +13,32 @@ # --- """Scripted diagram service plotting radius / element name""" -import io import gom -from gom import apifunction -import matplotlib.pyplot as plt - - -# Set path for debugging -SVG_PATH = None -#SVG_PATH = 'C:/temp/ScriptedDiagram.svg' -# Set SVG resolution in dpi -SVG_DPI = 'figure' - -def filter_all(k, v): - """Filter all elements by key, value - - Args: - k (string): key - v (any): value +from gom import apifunction - Returns: - list: element references - """ - r = [] - for g in [gom.app.project.nominal_elements, gom.app.project.inspection, gom.app.project.actual_elements]: - r += g.filter(k, v) - return r +import matplotlib.pyplot as plt +import gom.api.extensions.diagrams.matplotlib_tools as mpltools @apifunction -def radius_plot(*args, **kwargs)->str: - """Plot a radius histogram - - Args: - args (any): (unused) - kwargs (dict): {'': {'ude_diagram_custom': 1, 'ude_diagram_radius': , ...}, ...} - - Returns: - string: SVG image +def radius_plot(view, element_data)->str: + """ + Plot circle radius marks """ gom.log.info('Radius Plot Service') - gom.log.info(f'{kwargs=}') + gom.log.info(f'{view=}, {element_data=}') - radius = [] - elementnames = [] - for uuid, params in kwargs.items(): - element = filter_all('uuid_draft', uuid)[0] - elementnames.append(element.name) - radius.append(params['ude_diagram_radius']) + mpltools.setup_plot (plt, view) - # create x/y plot - plt.figure(figsize = (10, 5)) - plt.plot(elementnames, radius, 'bx') - plt.xticks(rotation = 90) - plt.subplots_adjust(bottom=0.2) + for e in element_data: + element = e['element'] + data = e['data'] - if SVG_PATH: - plt.savefig(SVG_PATH, format='svg', dpi=SVG_DPI) + plt.plot ([element.name], [data['ude_diagram_radius']], 'bx') - # Create an empty file-like object - svg_output = io.StringIO() - # Save the plot to the file-like object - plt.savefig(svg_output, format='svg', dpi=SVG_DPI) - - # Get the SVG string from the file-like object - svg_string = svg_output.getvalue() - - # Close the file-like object - svg_output.close() + plt.xticks(rotation = 90) - return svg_string + return mpltools.create_svg (plt, view) gom.run_api() diff --git a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/scr_act_circle.py b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/scr_act_circle.py index aabebd5..a7cb4b4 100644 --- a/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/scr_act_circle.py +++ b/AppExamples/scripted_diagrams/ScriptedDiagramBasics/scripts/scr_act_circle.py @@ -70,7 +70,7 @@ def dialog_event_handler(widget): DIALOG.handler = dialog_event_handler # ------------------------------------------------------------------------- - RESULT = gom.script.sys.show_user_defined_dialog(dialog=DIALOG) + gom.script.sys.show_user_defined_dialog(dialog=DIALOG) return params # ------------------------------------------------------------------------- @@ -88,13 +88,23 @@ def calculation(context, params): 'direction': (params['dir_x'], params['dir_y'], params['dir_z']), 'radius': params['radius'] } + + polisher = None + if params['service'].lower () == 'radius': + polisher = 'gom.api.diagram.radius_plot' + elif params['service'].lower () == 'histogram': + polisher = 'gom.api.statistics.radius_histogram' + else: + raise RuntimeError ('Unknown polisher service') + context.data[stage] = { "ude_diagram_custom": 1, "ude_diagram_type": "SVGDiagram", - # "gom.api.diagram.radius_plot" or "gom.api.statistics.radius_histogram" - "ude_diagram_service" : params['service'], + "ude_diagram_service" : polisher, "ude_diagram_radius": params['radius'], - "ude_diagram_center": gom.Vec3d(params['center_x'], params['center_y'], params['center_z']) + "ude_diagram_center": gom.Vec3d( + params['center_x'], params['center_y'], params['center_z'] + ) } print(f'{context.data[stage]}') except Exception as error: