mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
black format
This commit is contained in:
@@ -126,13 +126,14 @@ class SchedulesData:
|
||||
|
||||
|
||||
FONT_SIZES = {
|
||||
'small': 1.8,
|
||||
'regular': 2.5,
|
||||
'large': 3.5,
|
||||
'header': 5.0,
|
||||
'title': 7.0,
|
||||
"small": 1.8,
|
||||
"regular": 2.5,
|
||||
"large": 3.5,
|
||||
"header": 5.0,
|
||||
"title": 7.0,
|
||||
}
|
||||
|
||||
|
||||
class DecoratorData:
|
||||
# stores 1 type of data per object
|
||||
data = {}
|
||||
@@ -192,28 +193,30 @@ class DecoratorData:
|
||||
return display_data
|
||||
|
||||
@classmethod
|
||||
def get_ifc_text_font_size(cls, obj):
|
||||
def get_ifc_text_font_size(cls, obj):
|
||||
"""returns font size in mm for current ifc text object"""
|
||||
result = cls.data.get(obj.name, None)
|
||||
if result is not None:
|
||||
return result
|
||||
|
||||
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
if not element:
|
||||
return
|
||||
|
||||
|
||||
if obj.BIMTextProperties.is_editing:
|
||||
font_size = float(obj.BIMTextProperties.font_size)
|
||||
else:
|
||||
classes = ifcopenshell.util.element.get_pset(element, "EPset_Annotation", "Classes")
|
||||
|
||||
|
||||
# use `regular` as default
|
||||
if classes:
|
||||
if classes:
|
||||
classes_split = classes.split()
|
||||
# prioritize smaller font sizes just like in svg
|
||||
font_size_type = next((font_size_type for font_size_type in FONT_SIZES if font_size_type in classes_split), 'regular')
|
||||
font_size_type = next(
|
||||
(font_size_type for font_size_type in FONT_SIZES if font_size_type in classes_split), "regular"
|
||||
)
|
||||
else:
|
||||
font_size_type = 'regular'
|
||||
font_size_type = "regular"
|
||||
|
||||
font_size = FONT_SIZES[font_size_type]
|
||||
cls.data[obj.name] = font_size
|
||||
|
||||
@@ -1573,10 +1573,10 @@ class BattingDecorator(BaseDecorator):
|
||||
thickness = DecoratorData.get_batting_thickness(obj)
|
||||
region = context.region
|
||||
region3d = context.region_data
|
||||
original_edge_length = (verts[1]-verts[0]).length
|
||||
original_edge_length = (verts[1] - verts[0]).length
|
||||
clipspace_verts = [region3d.perspective_matrix @ v for v in verts[:2]]
|
||||
winspace_verts = [v * Vector([region.width/2, region.height/2, 1]) for v in clipspace_verts]
|
||||
win_space_edge_length = (winspace_verts[1]-winspace_verts[0]).xy.length
|
||||
winspace_verts = [v * Vector([region.width / 2, region.height / 2, 1]) for v in clipspace_verts]
|
||||
win_space_edge_length = (winspace_verts[1] - winspace_verts[0]).xy.length
|
||||
k = win_space_edge_length / original_edge_length
|
||||
winspace_thickness = k * thickness
|
||||
|
||||
|
||||
@@ -154,7 +154,6 @@ class CreateDrawing(bpy.types.Operator):
|
||||
self.file = IfcStore.get_file()
|
||||
|
||||
with profile("Drawing generation process"):
|
||||
|
||||
with profile("Initialize drawing generation process"):
|
||||
self.props = context.scene.DocProperties
|
||||
self.cprops = self.camera.data.BIMCameraProperties
|
||||
|
||||
@@ -38,7 +38,7 @@ from bpy.props import (
|
||||
FloatProperty,
|
||||
FloatVectorProperty,
|
||||
CollectionProperty,
|
||||
BoolVectorProperty
|
||||
BoolVectorProperty,
|
||||
)
|
||||
|
||||
|
||||
@@ -378,8 +378,19 @@ class BIMCameraProperties(PropertyGroup):
|
||||
return False
|
||||
|
||||
|
||||
DEFAULT_BOX_ALIGNMENT = [False]*6 + [True] + [False]*2
|
||||
BOX_ALIGNMENT_POSITIONS = [ "top-left", "top-middle", "top-right", "middle-left", "center", "middle-right", "bottom-left", "bottom-middle", "bottom-right"]
|
||||
DEFAULT_BOX_ALIGNMENT = [False] * 6 + [True] + [False] * 2
|
||||
BOX_ALIGNMENT_POSITIONS = [
|
||||
"top-left",
|
||||
"top-middle",
|
||||
"top-right",
|
||||
"middle-left",
|
||||
"center",
|
||||
"middle-right",
|
||||
"bottom-left",
|
||||
"bottom-middle",
|
||||
"bottom-right",
|
||||
]
|
||||
|
||||
|
||||
class BIMTextProperties(PropertyGroup):
|
||||
def set_box_alignment(self, new_value):
|
||||
@@ -390,7 +401,7 @@ class BIMTextProperties(PropertyGroup):
|
||||
if markers > 1:
|
||||
prev_value = self.get("box_alignment", DEFAULT_BOX_ALIGNMENT)
|
||||
# looking for the first value changed to positive
|
||||
first_changed_value = next( (i for i in range(9) if new_value[i] and new_value[i] != prev_value[i]), None )
|
||||
first_changed_value = next((i for i in range(9) if new_value[i] and new_value[i] != prev_value[i]), None)
|
||||
|
||||
# if nothing have changed we just keep the previous value
|
||||
if first_changed_value is None:
|
||||
@@ -399,16 +410,16 @@ class BIMTextProperties(PropertyGroup):
|
||||
new_value[first_changed_value] = True
|
||||
|
||||
self["box_alignment"] = new_value
|
||||
position_string = BOX_ALIGNMENT_POSITIONS[ next(i for i in range(9) if new_value[i]) ]
|
||||
self.attributes['BoxAlignment'].set_value( position_string )
|
||||
position_string = BOX_ALIGNMENT_POSITIONS[next(i for i in range(9) if new_value[i])]
|
||||
self.attributes["BoxAlignment"].set_value(position_string)
|
||||
|
||||
def get_box_alignment(self):
|
||||
return self.get("box_alignment", DEFAULT_BOX_ALIGNMENT)
|
||||
|
||||
|
||||
def refreshFontSize(self, context):
|
||||
# force update this object's font size for viewport display
|
||||
DecoratorData.data.pop(context.object.name, None)
|
||||
|
||||
|
||||
# TODO: line seems outdated and currently is just throwing error. remove?
|
||||
# File "\blenderbim\bim\module\drawing\annotation.py", line 63, in resize_text
|
||||
# font_size *= float(text_obj.data.BIMTextProperties.font_size)
|
||||
@@ -431,10 +442,9 @@ class BIMTextProperties(PropertyGroup):
|
||||
update=refreshFontSize,
|
||||
name="Font Size",
|
||||
)
|
||||
box_alignment: BoolVectorProperty(name="Box alignment", size=9,
|
||||
set=set_box_alignment,
|
||||
get=get_box_alignment,
|
||||
default=DEFAULT_BOX_ALIGNMENT)
|
||||
box_alignment: BoolVectorProperty(
|
||||
name="Box alignment", size=9, set=set_box_alignment, get=get_box_alignment, default=DEFAULT_BOX_ALIGNMENT
|
||||
)
|
||||
|
||||
|
||||
class BIMAssignedProductProperties(PropertyGroup):
|
||||
|
||||
@@ -350,19 +350,19 @@ class BIM_PT_text(Panel):
|
||||
row.operator("bim.edit_text", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_text", icon="CANCEL", text="")
|
||||
# skip BoxAlignment since we're going to format it ourselves
|
||||
attributes = [a for a in props.attributes if a.name != 'BoxAlignment']
|
||||
attributes = [a for a in props.attributes if a.name != "BoxAlignment"]
|
||||
blenderbim.bim.helper.draw_attributes(attributes, self.layout)
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(props, 'font_size')
|
||||
row.prop(props, "font_size")
|
||||
|
||||
rows = []
|
||||
for i in range(9):
|
||||
if i % 3 == 0:
|
||||
split = rows[i//3].split(factor=0.1, align=True)
|
||||
split = rows[i // 3].split(factor=0.1, align=True)
|
||||
split.column()
|
||||
split.prop(props, "box_alignment", text="", index=i)
|
||||
|
||||
text_lines = ["Text box alignment:", props.attributes['BoxAlignment'].string_value, '' ]
|
||||
text_lines = ["Text box alignment:", props.attributes["BoxAlignment"].string_value, ""]
|
||||
for i in range(3):
|
||||
split = rows[i].split(factor=0.1, align=False)
|
||||
split.column()
|
||||
|
||||
@@ -290,9 +290,11 @@ def sync_references(ifc, collector, drawing_tool, drawing=None):
|
||||
if reference_obj and ifc.is_edited(reference_obj):
|
||||
drawing_tool.sync_object_representation(reference_obj)
|
||||
|
||||
|
||||
def select_assigned_product(drawing):
|
||||
drawing.select_assigned_product()
|
||||
|
||||
|
||||
def activate_drawing_view(ifc, drawing_tool, drawing):
|
||||
camera = ifc.get_object(drawing)
|
||||
if not camera:
|
||||
|
||||
@@ -459,9 +459,9 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
props.attributes.clear()
|
||||
text = cls.get_text_literal(obj)
|
||||
blenderbim.bim.helper.import_attributes2(text, props.attributes)
|
||||
|
||||
|
||||
box_alignment_mask = [False] * 9
|
||||
position_string = props.attributes['BoxAlignment'].string_value
|
||||
position_string = props.attributes["BoxAlignment"].string_value
|
||||
box_alignment_mask[BOX_ALIGNMENT_POSITIONS.index(position_string)] = True
|
||||
props.box_alignment = box_alignment_mask
|
||||
|
||||
@@ -531,7 +531,7 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
@classmethod
|
||||
def update_text_value(cls, obj):
|
||||
props = obj.BIMTextProperties
|
||||
|
||||
|
||||
ifc_literal = cls.get_text_literal(obj)
|
||||
if not ifc_literal:
|
||||
return
|
||||
@@ -540,13 +540,14 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
if product:
|
||||
variables = {}
|
||||
for variable in re.findall("{{.*?}}", value):
|
||||
value = value.replace(variable, str(ifcopenshell.util.selector.get_element_value(product, variable[2:-2]) or ""))
|
||||
value = value.replace(
|
||||
variable, str(ifcopenshell.util.selector.get_element_value(product, variable[2:-2]) or "")
|
||||
)
|
||||
props.value = value
|
||||
|
||||
|
||||
@classmethod
|
||||
def update_text_size_pset(cls, obj):
|
||||
""" updates pset `EPset_Annotation.Classes` value
|
||||
"""updates pset `EPset_Annotation.Classes` value
|
||||
based on current font size from `obj.BIMTextProperties.font_size`
|
||||
"""
|
||||
props = obj.BIMTextProperties
|
||||
@@ -559,14 +560,14 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
|
||||
different_font_sizes = [c for c in classes_split if c in FONT_SIZES and c != font_size_str]
|
||||
|
||||
# if there are different font sizes in classes already
|
||||
# or if the current font size is not present in classes
|
||||
# (except regular because it's default)
|
||||
# then we do need to change pset value in ifc
|
||||
if different_font_sizes \
|
||||
or (font_size_str not in classes_split and font_size_str != 'regular'):
|
||||
# we do need to change pset value in ifc
|
||||
# only if there are different font sizes in classes already
|
||||
# or if the current font size is not present in classes
|
||||
# (except regular font size because it's default)
|
||||
if different_font_sizes or (font_size_str not in classes_split and font_size_str != "regular"):
|
||||
|
||||
classes_split = [c for c in classes_split if c not in FONT_SIZES] + [font_size_str]
|
||||
classes = ' '.join(classes_split)
|
||||
classes = " ".join(classes_split)
|
||||
|
||||
ifc_file = tool.Ifc.get()
|
||||
pset = tool.Pset.get_element_pset(element, "EPset_Annotation")
|
||||
@@ -579,7 +580,6 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
properties={"Classes": classes},
|
||||
)
|
||||
|
||||
|
||||
# TODO below this point is highly experimental prototype code with no tests
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user