black format

This commit is contained in:
Andrej730
2023-03-15 19:15:34 +05:00
parent ee1e401719
commit c4d2b30017
7 changed files with 60 additions and 46 deletions
@@ -126,13 +126,14 @@ class SchedulesData:
FONT_SIZES = { FONT_SIZES = {
'small': 1.8, "small": 1.8,
'regular': 2.5, "regular": 2.5,
'large': 3.5, "large": 3.5,
'header': 5.0, "header": 5.0,
'title': 7.0, "title": 7.0,
} }
class DecoratorData: class DecoratorData:
# stores 1 type of data per object # stores 1 type of data per object
data = {} data = {}
@@ -211,9 +212,11 @@ class DecoratorData:
if classes: if classes:
classes_split = classes.split() classes_split = classes.split()
# prioritize smaller font sizes just like in svg # 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: else:
font_size_type = 'regular' font_size_type = "regular"
font_size = FONT_SIZES[font_size_type] font_size = FONT_SIZES[font_size_type]
cls.data[obj.name] = font_size cls.data[obj.name] = font_size
@@ -1573,10 +1573,10 @@ class BattingDecorator(BaseDecorator):
thickness = DecoratorData.get_batting_thickness(obj) thickness = DecoratorData.get_batting_thickness(obj)
region = context.region region = context.region
region3d = context.region_data 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]] 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] 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 win_space_edge_length = (winspace_verts[1] - winspace_verts[0]).xy.length
k = win_space_edge_length / original_edge_length k = win_space_edge_length / original_edge_length
winspace_thickness = k * thickness winspace_thickness = k * thickness
@@ -154,7 +154,6 @@ class CreateDrawing(bpy.types.Operator):
self.file = IfcStore.get_file() self.file = IfcStore.get_file()
with profile("Drawing generation process"): with profile("Drawing generation process"):
with profile("Initialize drawing generation process"): with profile("Initialize drawing generation process"):
self.props = context.scene.DocProperties self.props = context.scene.DocProperties
self.cprops = self.camera.data.BIMCameraProperties self.cprops = self.camera.data.BIMCameraProperties
@@ -38,7 +38,7 @@ from bpy.props import (
FloatProperty, FloatProperty,
FloatVectorProperty, FloatVectorProperty,
CollectionProperty, CollectionProperty,
BoolVectorProperty BoolVectorProperty,
) )
@@ -378,8 +378,19 @@ class BIMCameraProperties(PropertyGroup):
return False return False
DEFAULT_BOX_ALIGNMENT = [False]*6 + [True] + [False]*2 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"] BOX_ALIGNMENT_POSITIONS = [
"top-left",
"top-middle",
"top-right",
"middle-left",
"center",
"middle-right",
"bottom-left",
"bottom-middle",
"bottom-right",
]
class BIMTextProperties(PropertyGroup): class BIMTextProperties(PropertyGroup):
def set_box_alignment(self, new_value): def set_box_alignment(self, new_value):
@@ -390,7 +401,7 @@ class BIMTextProperties(PropertyGroup):
if markers > 1: if markers > 1:
prev_value = self.get("box_alignment", DEFAULT_BOX_ALIGNMENT) prev_value = self.get("box_alignment", DEFAULT_BOX_ALIGNMENT)
# looking for the first value changed to positive # 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 nothing have changed we just keep the previous value
if first_changed_value is None: if first_changed_value is None:
@@ -399,8 +410,8 @@ class BIMTextProperties(PropertyGroup):
new_value[first_changed_value] = True new_value[first_changed_value] = True
self["box_alignment"] = new_value self["box_alignment"] = new_value
position_string = BOX_ALIGNMENT_POSITIONS[ next(i for i in range(9) if new_value[i]) ] position_string = BOX_ALIGNMENT_POSITIONS[next(i for i in range(9) if new_value[i])]
self.attributes['BoxAlignment'].set_value( position_string ) self.attributes["BoxAlignment"].set_value(position_string)
def get_box_alignment(self): def get_box_alignment(self):
return self.get("box_alignment", DEFAULT_BOX_ALIGNMENT) return self.get("box_alignment", DEFAULT_BOX_ALIGNMENT)
@@ -431,10 +442,9 @@ class BIMTextProperties(PropertyGroup):
update=refreshFontSize, update=refreshFontSize,
name="Font Size", name="Font Size",
) )
box_alignment: BoolVectorProperty(name="Box alignment", size=9, box_alignment: BoolVectorProperty(
set=set_box_alignment, name="Box alignment", size=9, set=set_box_alignment, get=get_box_alignment, default=DEFAULT_BOX_ALIGNMENT
get=get_box_alignment, )
default=DEFAULT_BOX_ALIGNMENT)
class BIMAssignedProductProperties(PropertyGroup): class BIMAssignedProductProperties(PropertyGroup):
@@ -350,19 +350,19 @@ class BIM_PT_text(Panel):
row.operator("bim.edit_text", icon="CHECKMARK") row.operator("bim.edit_text", icon="CHECKMARK")
row.operator("bim.disable_editing_text", icon="CANCEL", text="") row.operator("bim.disable_editing_text", icon="CANCEL", text="")
# skip BoxAlignment since we're going to format it ourselves # 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) blenderbim.bim.helper.draw_attributes(attributes, self.layout)
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.prop(props, 'font_size') row.prop(props, "font_size")
rows = [] rows = []
for i in range(9): for i in range(9):
if i % 3 == 0: 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.column()
split.prop(props, "box_alignment", text="", index=i) 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): for i in range(3):
split = rows[i].split(factor=0.1, align=False) split = rows[i].split(factor=0.1, align=False)
split.column() split.column()
@@ -290,9 +290,11 @@ def sync_references(ifc, collector, drawing_tool, drawing=None):
if reference_obj and ifc.is_edited(reference_obj): if reference_obj and ifc.is_edited(reference_obj):
drawing_tool.sync_object_representation(reference_obj) drawing_tool.sync_object_representation(reference_obj)
def select_assigned_product(drawing): def select_assigned_product(drawing):
drawing.select_assigned_product() drawing.select_assigned_product()
def activate_drawing_view(ifc, drawing_tool, drawing): def activate_drawing_view(ifc, drawing_tool, drawing):
camera = ifc.get_object(drawing) camera = ifc.get_object(drawing)
if not camera: if not camera:
+11 -11
View File
@@ -461,7 +461,7 @@ class Drawing(blenderbim.core.tool.Drawing):
blenderbim.bim.helper.import_attributes2(text, props.attributes) blenderbim.bim.helper.import_attributes2(text, props.attributes)
box_alignment_mask = [False] * 9 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 box_alignment_mask[BOX_ALIGNMENT_POSITIONS.index(position_string)] = True
props.box_alignment = box_alignment_mask props.box_alignment = box_alignment_mask
@@ -540,13 +540,14 @@ class Drawing(blenderbim.core.tool.Drawing):
if product: if product:
variables = {} variables = {}
for variable in re.findall("{{.*?}}", value): 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 props.value = value
@classmethod @classmethod
def update_text_size_pset(cls, obj): 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` based on current font size from `obj.BIMTextProperties.font_size`
""" """
props = obj.BIMTextProperties 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] 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 # 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 # or if the current font size is not present in classes
# (except regular because it's default) # (except regular font size 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"):
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_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() ifc_file = tool.Ifc.get()
pset = tool.Pset.get_element_pset(element, "EPset_Annotation") pset = tool.Pset.get_element_pset(element, "EPset_Annotation")
@@ -579,7 +580,6 @@ class Drawing(blenderbim.core.tool.Drawing):
properties={"Classes": classes}, properties={"Classes": classes},
) )
# TODO below this point is highly experimental prototype code with no tests # TODO below this point is highly experimental prototype code with no tests
@classmethod @classmethod