Skip to content

Conversation

lorenzncode
Copy link
Member

Interface to OCCT Message

Interface to OCCT Message
Copy link

codecov bot commented Feb 18, 2024

Codecov Report

Attention: Patch coverage is 78.37838% with 8 lines in your changes missing coverage. Please review.

Project coverage is 94.37%. Comparing base (153ed3f) to head (4853b7b).
Report is 26 commits behind head on master.

Files with missing lines Patch % Lines
cadquery/occ_impl/message.py 76.92% 5 Missing and 1 partial ⚠️
cadquery/occ_impl/importers/__init__.py 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1525      +/-   ##
==========================================
- Coverage   94.48%   94.37%   -0.11%     
==========================================
  Files          28       29       +1     
  Lines        5780     5813      +33     
  Branches     1071     1077       +6     
==========================================
+ Hits         5461     5486      +25     
- Misses        193      199       +6     
- Partials      126      128       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lorenzncode
Copy link
Member Author

This would allow to process the STEPControl_Reader object without continuing to import the STEP file for example to extract header info. Another use case might be to abort STEP import if certain alerts or messages are issued on read. There may be other more general purpose OCCT message reporting uses.

import cadquery as cq

report = cq.message.Message.add_report()
reader = cq.importers.readStep("BROKEN_FILE.STEP")
alerts = report.GetAlerts(cq.message.Level.info.value)

if alerts:
    raise ValueError("STEP file read resulted in alerts, skip importStep")
else:
    res = cq.importers.importStep(reader)
import cadquery as cq

def import_step_abort_on_alert(filename, report=None):
    """
    Import STEP
    Abort in case of OCCT alert info messages

    This is NOT guaranteed to eliminate all crashes.
    It is an example based a known corrupted STEP file.  See issue #1521.

    It *might* help filter some problematic STEP files.
    In other cases perhaps trace level messages must be inspected or there 
    may not be any way to know up front whether a STEP file is problematic.
    """

    if report is None:
        report = cq.message.Message.add_report()

    report.Clear(cq.message.Level.info.value)
    reader = cq.importers.readStep(filename)
    alerts = report.GetAlerts(cq.message.Level.info.value)

    if alerts:
        raise ValueError("abort STEP import")
    else:
        res = cq.importers.importStep(reader)

    return res


step_files = ("BROKEN_FILE.STEP", "good.step", "BROKEN_FILE.STEP", "good.step")

report = cq.message.Message.add_report()
for f in step_files:
    try:
        res = import_step_abort_on_alert(f, report)
    except ValueError:
        res = None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant