mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-30 12:09:51 +00:00
Replaced the old profiler function with the ifcopenshell.util profiler
This commit is contained in:
@@ -26,7 +26,6 @@ import subprocess
|
|||||||
import time
|
import time
|
||||||
from math import radians
|
from math import radians
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from timeit import default_timer as timer
|
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
@@ -48,6 +47,7 @@ import ifcopenshell.api.style
|
|||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
import ifcopenshell.ifcopenshell_wrapper
|
import ifcopenshell.ifcopenshell_wrapper
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
|
import ifcopenshell.util.profiler
|
||||||
import ifcopenshell.util.representation
|
import ifcopenshell.util.representation
|
||||||
import ifcopenshell.util.selector
|
import ifcopenshell.util.selector
|
||||||
import ifcopenshell.util.shape_builder
|
import ifcopenshell.util.shape_builder
|
||||||
@@ -86,21 +86,6 @@ if TYPE_CHECKING:
|
|||||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
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):
|
class LineworkContexts(NamedTuple):
|
||||||
body: list[list[int]]
|
body: list[list[int]]
|
||||||
annotation: list[list[int]]
|
annotation: list[list[int]]
|
||||||
@@ -328,8 +313,8 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
self.camera_document = tool.Drawing.get_drawing_document(self.camera_element)
|
self.camera_document = tool.Drawing.get_drawing_document(self.camera_element)
|
||||||
self.file = tool.Ifc.get()
|
self.file = tool.Ifc.get()
|
||||||
|
|
||||||
with profile("Drawing generation process"):
|
with ifcopenshell.util.profiler.Profiler("Drawing generation process"):
|
||||||
with profile("Initialize drawing generation process"):
|
with ifcopenshell.util.profiler.Profiler("Initialize drawing generation process"):
|
||||||
self.cprops = tool.Drawing.get_camera_props(self.camera)
|
self.cprops = tool.Drawing.get_camera_props(self.camera)
|
||||||
self.drawing = self.file.by_id(drawing_id)
|
self.drawing = self.file.by_id(drawing_id)
|
||||||
self.drawing_name = self.drawing.Name
|
self.drawing_name = self.drawing.Name
|
||||||
@@ -355,7 +340,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
linework_svg = None
|
linework_svg = None
|
||||||
annotation_svg = None
|
annotation_svg = None
|
||||||
|
|
||||||
with profile("Generate underlay"):
|
with ifcopenshell.util.profiler.Profiler("Generate underlay"):
|
||||||
if ifcopenshell.util.element.get_pset(self.drawing, "EPset_Drawing", "HasUnderlay"):
|
if ifcopenshell.util.element.get_pset(self.drawing, "EPset_Drawing", "HasUnderlay"):
|
||||||
drawing_style = self.cprops.get_active_drawing_style()
|
drawing_style = self.cprops.get_active_drawing_style()
|
||||||
if not drawing_style:
|
if not drawing_style:
|
||||||
@@ -383,7 +368,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
|
|
||||||
underlay_svg = self.generate_underlay(context)
|
underlay_svg = self.generate_underlay(context)
|
||||||
|
|
||||||
with profile("Generate linework"):
|
with ifcopenshell.util.profiler.Profiler("Generate linework"):
|
||||||
if tool.Drawing.is_camera_orthographic():
|
if tool.Drawing.is_camera_orthographic():
|
||||||
if self.cprops.linework_mode == "OPENCASCADE":
|
if self.cprops.linework_mode == "OPENCASCADE":
|
||||||
linework_svg = self.generate_linework(context)
|
linework_svg = self.generate_linework(context)
|
||||||
@@ -392,11 +377,11 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
elif self.cprops.linework_mode == "FREESTYLE":
|
elif self.cprops.linework_mode == "FREESTYLE":
|
||||||
linework_svg = self.generate_freestyle_linework(context)
|
linework_svg = self.generate_freestyle_linework(context)
|
||||||
|
|
||||||
with profile("Generate annotation"):
|
with ifcopenshell.util.profiler.Profiler("Generate annotation"):
|
||||||
if tool.Drawing.is_camera_orthographic():
|
if tool.Drawing.is_camera_orthographic():
|
||||||
annotation_svg = self.generate_annotation(context)
|
annotation_svg = self.generate_annotation(context)
|
||||||
|
|
||||||
with profile("Combine SVG layers"):
|
with ifcopenshell.util.profiler.Profiler("Combine SVG layers"):
|
||||||
svg_path = self.combine_svgs(context, underlay_svg, linework_svg, annotation_svg)
|
svg_path = self.combine_svgs(context, underlay_svg, linework_svg, annotation_svg)
|
||||||
|
|
||||||
if self.open_viewer:
|
if self.open_viewer:
|
||||||
@@ -606,7 +591,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
drawing_elements = drawing_elements.copy()
|
drawing_elements = drawing_elements.copy()
|
||||||
contexts_: list[list[int]] = getattr(contexts, context_type)
|
contexts_: list[list[int]] = getattr(contexts, context_type)
|
||||||
for context in contexts_:
|
for context in contexts_:
|
||||||
with profile(f"Processing {context_type} context"):
|
with ifcopenshell.util.profiler.Profiler(f"Processing {context_type} context"):
|
||||||
if not context or not drawing_elements:
|
if not context or not drawing_elements:
|
||||||
continue
|
continue
|
||||||
geom_settings = ifcopenshell.geom.settings()
|
geom_settings = ifcopenshell.geom.settings()
|
||||||
@@ -897,7 +882,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
|
|
||||||
# in case of printing multiple drawings we need to sync just once
|
# in case of printing multiple drawings we need to sync just once
|
||||||
if self.sync and self.drawing_index == 0:
|
if self.sync and self.drawing_index == 0:
|
||||||
with profile("sync"):
|
with ifcopenshell.util.profiler.Profiler("sync"):
|
||||||
# All very hackish whilst prototyping
|
# All very hackish whilst prototyping
|
||||||
exporter = bonsai.bim.export_ifc.IfcExporter(None)
|
exporter = bonsai.bim.export_ifc.IfcExporter(None)
|
||||||
exporter.file = tool.Ifc.get()
|
exporter.file = tool.Ifc.get()
|
||||||
@@ -953,7 +938,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
self.serialize_contexts_elements(ifc, tree, contexts, "annotation", drawing_elements, target_view)
|
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:
|
if tool.Ifc.get() == ifc and self.camera_element not in drawing_elements:
|
||||||
with profile("Camera element"):
|
with ifcopenshell.util.profiler.Profiler("Camera element"):
|
||||||
# The camera must always be included, regardless of any include/exclude filters.
|
# The camera must always be included, regardless of any include/exclude filters.
|
||||||
geom_settings = ifcopenshell.geom.settings()
|
geom_settings = ifcopenshell.geom.settings()
|
||||||
geom_settings.set("iterator-output", ifcopenshell.ifcopenshell_wrapper.NATIVE)
|
geom_settings.set("iterator-output", ifcopenshell.ifcopenshell_wrapper.NATIVE)
|
||||||
@@ -961,7 +946,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
for elem in it:
|
for elem in it:
|
||||||
self.serialiser.write(elem)
|
self.serialiser.write(elem)
|
||||||
|
|
||||||
with profile("Finalizing"):
|
with ifcopenshell.util.profiler.Profiler("Finalizing"):
|
||||||
self.serialiser.finalize()
|
self.serialiser.finalize()
|
||||||
results = self.svg_buffer.get_value()
|
results = self.svg_buffer.get_value()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user