Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions src/bonsai/bonsai/bim/module/drawing/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import time
from math import radians
from pathlib import Path
from timeit import default_timer as timer
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -52,6 +51,7 @@
import ifcopenshell.util.selector
import ifcopenshell.util.shape_builder
import ifcopenshell.util.unit
from ifcopenshell.util.profiler import Profiler
import numpy as np
import shapely
from bpy_extras.image_utils import load_image
Expand Down Expand Up @@ -86,20 +86,6 @@
cwd = os.path.dirname(os.path.realpath(__file__))


class profile:
"""
A python context manager timing utility
"""

def __init__(self, task):
self.task = task

def __enter__(self):
self.start = timer()

def __exit__(self, *args):
print(self.task, timer() - self.start)


class LineworkContexts(NamedTuple):
body: list[list[int]]
Expand Down Expand Up @@ -328,8 +314,8 @@ def execute(self, context):
self.camera_document = tool.Drawing.get_drawing_document(self.camera_element)
self.file = tool.Ifc.get()

with profile("Drawing generation process"):
with profile("Initialize drawing generation process"):
with Profiler("Drawing generation process"):
with Profiler("Initialize drawing generation process"):
self.cprops = tool.Drawing.get_camera_props(self.camera)
self.drawing = self.file.by_id(drawing_id)
self.drawing_name = self.drawing.Name
Expand All @@ -355,7 +341,7 @@ def execute(self, context):
linework_svg = None
annotation_svg = None

with profile("Generate underlay"):
with Profiler("Generate underlay"):
if ifcopenshell.util.element.get_pset(self.drawing, "EPset_Drawing", "HasUnderlay"):
drawing_style = self.cprops.get_active_drawing_style()
if not drawing_style:
Expand Down Expand Up @@ -383,7 +369,7 @@ def execute(self, context):

underlay_svg = self.generate_underlay(context)

with profile("Generate linework"):
with Profiler("Generate linework"):
if tool.Drawing.is_camera_orthographic():
if self.cprops.linework_mode == "OPENCASCADE":
linework_svg = self.generate_linework(context)
Expand All @@ -392,11 +378,11 @@ def execute(self, context):
elif self.cprops.linework_mode == "FREESTYLE":
linework_svg = self.generate_freestyle_linework(context)

with profile("Generate annotation"):
with Profiler("Generate annotation"):
if tool.Drawing.is_camera_orthographic():
annotation_svg = self.generate_annotation(context)

with profile("Combine SVG layers"):
with Profiler("Combine SVG layers"):
svg_path = self.combine_svgs(context, underlay_svg, linework_svg, annotation_svg)

if self.open_viewer:
Expand Down Expand Up @@ -606,7 +592,7 @@ def serialize_contexts_elements(
drawing_elements = drawing_elements.copy()
contexts_: list[list[int]] = getattr(contexts, context_type)
for context in contexts_:
with profile(f"Processing {context_type} context"):
with Profiler(f"Processing {context_type} context"):
if not context or not drawing_elements:
continue
geom_settings = ifcopenshell.geom.settings()
Expand Down Expand Up @@ -897,7 +883,7 @@ def generate_linework(self, context: bpy.types.Context) -> Union[str, None]:

# in case of printing multiple drawings we need to sync just once
if self.sync and self.drawing_index == 0:
with profile("sync"):
with Profiler("sync"):
# All very hackish whilst prototyping
exporter = bonsai.bim.export_ifc.IfcExporter(None)
exporter.file = tool.Ifc.get()
Expand Down Expand Up @@ -953,15 +939,15 @@ def generate_linework(self, context: bpy.types.Context) -> Union[str, None]:
self.serialize_contexts_elements(ifc, tree, contexts, "annotation", drawing_elements, target_view)

if tool.Ifc.get() == ifc and self.camera_element not in drawing_elements:
with profile("Camera element"):
with Profiler("Camera element"):
# The camera must always be included, regardless of any include/exclude filters.
geom_settings = ifcopenshell.geom.settings()
geom_settings.set("iterator-output", ifcopenshell.ifcopenshell_wrapper.NATIVE)
it = ifcopenshell.geom.iterator(geom_settings, ifc, include=[self.camera_element])
for elem in it:
self.serialiser.write(elem)

with profile("Finalizing"):
with Profiler("Finalizing"):
self.serialiser.finalize()
results = self.svg_buffer.get_value()

Expand Down