mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 21:53:40 +00:00
black format
This commit is contained in:
@@ -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 = {}
|
||||||
@@ -192,28 +193,30 @@ class DecoratorData:
|
|||||||
return display_data
|
return display_data
|
||||||
|
|
||||||
@classmethod
|
@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"""
|
"""returns font size in mm for current ifc text object"""
|
||||||
result = cls.data.get(obj.name, None)
|
result = cls.data.get(obj.name, None)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
if not element:
|
if not element:
|
||||||
return
|
return
|
||||||
|
|
||||||
if obj.BIMTextProperties.is_editing:
|
if obj.BIMTextProperties.is_editing:
|
||||||
font_size = float(obj.BIMTextProperties.font_size)
|
font_size = float(obj.BIMTextProperties.font_size)
|
||||||
else:
|
else:
|
||||||
classes = ifcopenshell.util.element.get_pset(element, "EPset_Annotation", "Classes")
|
classes = ifcopenshell.util.element.get_pset(element, "EPset_Annotation", "Classes")
|
||||||
|
|
||||||
# use `regular` as default
|
# use `regular` as default
|
||||||
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,16 +410,16 @@ 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)
|
||||||
|
|
||||||
def refreshFontSize(self, context):
|
def refreshFontSize(self, context):
|
||||||
# force update this object's font size for viewport display
|
# force update this object's font size for viewport display
|
||||||
DecoratorData.data.pop(context.object.name, None)
|
DecoratorData.data.pop(context.object.name, None)
|
||||||
|
|
||||||
# TODO: line seems outdated and currently is just throwing error. remove?
|
# TODO: line seems outdated and currently is just throwing error. remove?
|
||||||
# File "\blenderbim\bim\module\drawing\annotation.py", line 63, in resize_text
|
# File "\blenderbim\bim\module\drawing\annotation.py", line 63, in resize_text
|
||||||
# font_size *= float(text_obj.data.BIMTextProperties.font_size)
|
# font_size *= float(text_obj.data.BIMTextProperties.font_size)
|
||||||
@@ -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:
|
||||||
|
|||||||
@@ -459,9 +459,9 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
props.attributes.clear()
|
props.attributes.clear()
|
||||||
text = cls.get_text_literal(obj)
|
text = cls.get_text_literal(obj)
|
||||||
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
|
||||||
|
|
||||||
@@ -531,7 +531,7 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def update_text_value(cls, obj):
|
def update_text_value(cls, obj):
|
||||||
props = obj.BIMTextProperties
|
props = obj.BIMTextProperties
|
||||||
|
|
||||||
ifc_literal = cls.get_text_literal(obj)
|
ifc_literal = cls.get_text_literal(obj)
|
||||||
if not ifc_literal:
|
if not ifc_literal:
|
||||||
return
|
return
|
||||||
@@ -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
|
||||||
# or if the current font size is not present in classes
|
# only if there are different font sizes in classes already
|
||||||
# (except regular because it's default)
|
# or if the current font size is not present in classes
|
||||||
# then we do need to change pset value in ifc
|
# (except regular font size because it's default)
|
||||||
if different_font_sizes \
|
if different_font_sizes or (font_size_str not in classes_split and font_size_str != "regular"):
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user