From f85c3ae24c8320398ad648ac9d5a13aff47b7cb0 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Thu, 9 Dec 2021 09:06:51 +0100 Subject: [PATCH] bimtester: update log and smartview, they still are deactivated by default, fixes #1892 --- .../bimtester/features/environment.py | 80 ++++++++++++------- .../bimtester/features/zoom_smart_view.py | 28 +++++-- 2 files changed, 71 insertions(+), 37 deletions(-) diff --git a/src/ifcbimtester/bimtester/features/environment.py b/src/ifcbimtester/bimtester/features/environment.py index 25f6d040ca..dc2a98d280 100644 --- a/src/ifcbimtester/bimtester/features/environment.py +++ b/src/ifcbimtester/bimtester/features/environment.py @@ -1,18 +1,19 @@ import os - from behave.model import Scenario -from logfile import create_logfile -from logfile import append_logfile -from zoom_smart_view import append_zoom_smartview -from zoom_smart_view import create_zoom_smartview + from bimtester.ifc import IfcStore from bimtester.lang import switch_locale +from logfile import append_logfile +from logfile import create_logfile +from zoom_smart_view import add_smartview +from zoom_smart_view import create_zoom_set_of_smartviews this_path = os.path.dirname(os.path.realpath(__file__)) def before_all(context): + userdata = context.config.userdata if context.config.lang: @@ -21,34 +22,55 @@ def before_all(context): continue_after_failed = userdata.getbool("runner.continue_after_failed_step", True) Scenario.continue_after_failed_step = continue_after_failed - # TODO: refactor smart view support into a decoupled module # context.ifc_path = userdata.get("ifc", "") - # context.ifc_basename = os.path.basename( - # os.path.splitext(context.ifc_path)[0] - # ) + context.ifcfile_basename = os.path.basename( + os.path.splitext(userdata["ifc"])[0] + ) + context.outpath = os.path.join(this_path, "..") + context.create_log = False + context.create_smartview = False - # context.outpath = os.path.join(this_path, "..") + if context.create_log is True: + # set up log file + context.thelogfile = os.path.join( + context.outpath, + context.ifcfile_basename + ".log" + ) + create_logfile( + context.thelogfile, + context.ifcfile_basename, + ) - # context.thelogfile = os.path.join(context.outpath, context.ifc_basename + ".log") - # create_logfile( - # context.thelogfile, - # context.ifc_basename, - # ) - # # set up smart view file - # context.smview_file = os.path.join(context.outpath, context.ifc_basename + ".bcsv") - # create_zoom_smartview( - # context.smview_file, - # context.ifc_basename, - # ) +def before_feature(context, feature): + + # TODO: refactor zoom smart view support into a decoupled module + if context.create_smartview is True: + smartview_name = context.ifcfile_basename + "_" + feature.name + context.smview_file = os.path.join( + context.outpath, + smartview_name + ".bcsv" + ) + # print("SmartView file: {}".format(context.smview_file)) + create_zoom_set_of_smartviews( + context.smview_file, + smartview_name, + ) def after_step(context, step): - pass - # TODO: refactor smart view support into a decoupled module - #if step.status == "failed": - # # append log file - # append_logfile(context, step) - # # extend smart view - # if hasattr(context, "falseguids"): - # append_zoom_smartview(context.smview_file, step.name, context.falseguids) + + if step.status == "failed" and context.create_log is True: + append_logfile(context, step) + + if ( + step.status == "failed" + and context.create_smartview is True + and hasattr(context, "falseguids") + ): + # print(context.falseguids) + add_smartview( + context.smview_file, + step.name, + context.falseguids + ) diff --git a/src/ifcbimtester/bimtester/features/zoom_smart_view.py b/src/ifcbimtester/bimtester/features/zoom_smart_view.py index fa544f8871..9ad985d817 100644 --- a/src/ifcbimtester/bimtester/features/zoom_smart_view.py +++ b/src/ifcbimtester/bimtester/features/zoom_smart_view.py @@ -1,7 +1,10 @@ import fileinput +import uuid -def create_zoom_smartview(sm_file, ifcbasename): +def create_zoom_set_of_smartviews(sm_file, smartviewset_name): + + # smartviewset_name: is the directory name in Zoom the SmartViews are in smf = open(sm_file, "w") smf.write('\n') @@ -14,7 +17,7 @@ def create_zoom_smartview(sm_file, ifcbasename): smf.write("\n") smf.write("\n") smf.write(" \n") - smf.write(" BIMTester {}\n".format(ifcbasename)) + smf.write(" BIMTester {}\n".format(smartviewset_name)) smf.write(" \n") smf.write(" a2ddfaf7-97f2-4519-aabd-f2d94f6b4d6b\n") smf.write(" 2020-10-30T13:23:30") @@ -27,16 +30,22 @@ def create_zoom_smartview(sm_file, ifcbasename): smf.close() -def append_zoom_smartview(sm_file, step_name, false_elements_guid): +def add_smartview(sm_file, smartview_name, guids): + + # smartview_name: is the name of the SmartView in Zoom + # guids: List of guids + # model will be grey and transparent, the guids objs will be red and not transparent # build the smartview string smview_string = " \n" smview_string += ( " GUID filter, {}\n" - .format(step_name) + .format(smartview_name) ) - smview_string += "{}\n".format(each_smartview_string_before) - for guid in false_elements_guid: + smview_string += "{}\n".format(each_smartview_string_before1) + smview_string += str(uuid.uuid4()) # create and add a smart view guid + smview_string += "{}\n".format(each_smartview_string_before2) + for guid in guids: smview_string += ( "{}{}{}\n".format( rule_string_before, @@ -59,11 +68,14 @@ each_smartview_string_title = """ """ -each_smartview_string_before = """ bernd@bimstatik.ch +each_smartview_string_before1 = """ bernd@bimstatik.ch 2020-10-30T13:18:45 bernd@bimstatik.ch 2020-10-30T13:23:30 - 15fda94f-b4bf-43be-8ef4-15d3121137e1 + """ + + +each_smartview_string_before2 = """ Any