mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
typing
This commit is contained in:
@@ -200,6 +200,8 @@ class CreateDrawing(bpy.types.Operator):
|
||||
default=True,
|
||||
)
|
||||
|
||||
drawing_name: str
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
if not tool.Ifc.get():
|
||||
@@ -305,7 +307,9 @@ class CreateDrawing(bpy.types.Operator):
|
||||
width = height / render.resolution_y * render.resolution_x
|
||||
return width, height
|
||||
|
||||
def combine_svgs(self, context, underlay, linework, annotation):
|
||||
def combine_svgs(
|
||||
self, context: bpy.types.Context, underlay: Optional[str], linework: Optional[str], annotation: Optional[str]
|
||||
) -> str:
|
||||
# Hacky :)
|
||||
svg_path = self.get_svg_path()
|
||||
with open(svg_path, "w") as outfile:
|
||||
@@ -349,7 +353,7 @@ class CreateDrawing(bpy.types.Operator):
|
||||
outfile.write("</svg>")
|
||||
return svg_path
|
||||
|
||||
def generate_underlay(self, context):
|
||||
def generate_underlay(self, context: bpy.types.Context) -> Union[str, None]:
|
||||
if not ifcopenshell.util.element.get_pset(self.drawing, "EPset_Drawing", "HasUnderlay"):
|
||||
return
|
||||
svg_path = self.get_svg_path(cache_type="underlay")
|
||||
@@ -360,7 +364,7 @@ class CreateDrawing(bpy.types.Operator):
|
||||
for obj in bpy.context.view_layer.objects:
|
||||
obj.hide_render = obj.name not in visible_object_names
|
||||
|
||||
context.scene.render.filepath = svg_path[0:-4] + ".png"
|
||||
context.scene.render.filepath = Path(svg_path).with_suffix(".png").as_posix()
|
||||
drawing_style = context.scene.DocProperties.drawing_styles[self.cprops.active_drawing_style_index]
|
||||
|
||||
if drawing_style.render_type == "DEFAULT":
|
||||
@@ -1311,7 +1315,7 @@ class CreateDrawing(bpy.types.Operator):
|
||||
projection.getparent().remove(projection)
|
||||
group.insert(0, projection)
|
||||
|
||||
def generate_annotation(self, context):
|
||||
def generate_annotation(self, context: bpy.types.Context) -> Union[str, None]:
|
||||
if not ifcopenshell.util.element.get_pset(self.drawing, "EPset_Drawing", "HasAnnotation"):
|
||||
return
|
||||
svg_path = self.get_svg_path(cache_type="annotation")
|
||||
@@ -1367,6 +1371,7 @@ class CreateDrawing(bpy.types.Operator):
|
||||
|
||||
def get_svg_path(self, cache_type: Optional[str] = None) -> str:
|
||||
drawing_path = tool.Drawing.get_document_uri(self.camera_document)
|
||||
assert drawing_path
|
||||
drawings_dir = os.path.dirname(drawing_path)
|
||||
|
||||
if cache_type:
|
||||
|
||||
@@ -181,18 +181,18 @@ def get_diagram_scales(self, context):
|
||||
return diagram_scales_enum
|
||||
|
||||
|
||||
def update_drawing_name(self, context):
|
||||
def update_drawing_name(self: "Drawing", context: bpy.types.Context) -> None:
|
||||
if self.ifc_definition_id:
|
||||
drawing = tool.Ifc.get().by_id(self.ifc_definition_id)
|
||||
core.update_drawing_name(tool.Ifc, tool.Drawing, drawing=drawing, name=self.name)
|
||||
|
||||
|
||||
def get_drawing_style_name(self):
|
||||
def get_drawing_style_name(self: "DrawingStyle"):
|
||||
"""needed to make `set_drawing_style_name` work"""
|
||||
return self.get("name", "")
|
||||
|
||||
|
||||
def set_drawing_style_name(self, new_value):
|
||||
def set_drawing_style_name(self: "DrawingStyle", new_value: str) -> None:
|
||||
"""ensure the name is unique"""
|
||||
scene = bpy.context.scene
|
||||
drawing_styles = [s.name for s in scene.DocProperties.drawing_styles if s.name != self.name]
|
||||
|
||||
@@ -32,16 +32,11 @@ import ifcopenshell.util.selector
|
||||
import ifcopenshell.util.unit
|
||||
import bonsai.tool as tool
|
||||
import bonsai.bim.module.drawing.helper as helper
|
||||
import bonsai.bim.module.drawing.annotation as annotation
|
||||
from bonsai.bim.module.drawing.data import DrawingsData
|
||||
|
||||
from bonsai.bim.module.drawing.data import DecoratorData
|
||||
from bonsai.bim.ifc import IfcStore
|
||||
|
||||
from math import pi, ceil, atan, degrees, acos
|
||||
from mathutils import geometry, Vector
|
||||
from bpy_extras import view3d_utils
|
||||
from typing import Optional
|
||||
from typing import Optional, Self
|
||||
|
||||
|
||||
class External(svgwrite.container.Group):
|
||||
@@ -71,7 +66,7 @@ class SvgWriter:
|
||||
self.camera_height = None
|
||||
self.resource_paths = {}
|
||||
|
||||
def create_blank_svg(self, output_path):
|
||||
def create_blank_svg(self, output_path: str) -> Self:
|
||||
self.calculate_scale()
|
||||
self.svg = svgwrite.Drawing(
|
||||
output_path,
|
||||
@@ -84,14 +79,14 @@ class SvgWriter:
|
||||
self.svg.attribs["xmlns:ifc"] = "http://www.ifcopenshell.org/ns"
|
||||
return self
|
||||
|
||||
def save(self):
|
||||
def save(self) -> None:
|
||||
self.svg.save(pretty=True)
|
||||
|
||||
def draw_underlay(self, image):
|
||||
def draw_underlay(self, image: str) -> Self:
|
||||
self.svg.add(self.svg.image(os.path.basename(image), width=self.width, height=self.height))
|
||||
return self
|
||||
|
||||
def setup_drawing_resource_paths(self, element):
|
||||
def setup_drawing_resource_paths(self, element: ifcopenshell.entity_instance) -> None:
|
||||
pset = ifcopenshell.util.element.get_pset(element, "EPset_Drawing")
|
||||
for resource in ("Stylesheet", "Markers", "Symbols", "Patterns", "ShadingStyles"):
|
||||
resource_path = pset.get(resource)
|
||||
|
||||
@@ -362,7 +362,7 @@ def remove_drawing(ifc: tool.Ifc, drawing_tool: tool.Drawing, drawing: ifcopensh
|
||||
|
||||
|
||||
def update_drawing_name(
|
||||
ifc: tool.Ifc, drawing_tool: tool.Drawing, drawing: ifcopenshell.entity_instance, name=None
|
||||
ifc: tool.Ifc, drawing_tool: tool.Drawing, drawing: ifcopenshell.entity_instance, name: str
|
||||
) -> None:
|
||||
if drawing_tool.get_name(drawing) != name:
|
||||
ifc.run("attribute.edit_attributes", product=drawing, attributes={"Name": name})
|
||||
|
||||
Reference in New Issue
Block a user