Skip to content

Commit c1c50f8

Browse files
committed
Minor fix.
1 parent d733960 commit c1c50f8

File tree

10 files changed

+50
-40
lines changed

10 files changed

+50
-40
lines changed

src/blenderbim/blenderbim/bim/export_ifc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def sync_object_placement(self, obj):
155155
float(props.blender_x_axis_ordinate),
156156
)
157157
if not np.allclose(ifc_matrix, blender_matrix, atol=0.0001):
158-
blenderbim.core.geometry.edit_object_placement(tool.Ifc, tool.Surveyor, obj=obj)
158+
blenderbim.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
159159
return element
160160

161161
def sync_grid_axis_object_placement(self, obj, element):

src/blenderbim/blenderbim/bim/module/geometry/operator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class EditObjectPlacement(bpy.types.Operator, Operator):
5454
def _execute(self, context):
5555
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
5656
for obj in objs:
57-
core.edit_object_placement(tool.Ifc, tool.Surveyor, obj=obj)
57+
core.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
5858

5959

6060
class AddRepresentation(bpy.types.Operator, Operator):
@@ -153,7 +153,7 @@ def update_obj_mesh_representation(self, context, obj):
153153
ifcopenshell.api.run("grid.create_axis_curve", self.file, **{"axis_curve": obj, "grid_axis": product})
154154
return
155155

156-
core.edit_object_placement(tool.Ifc, tool.Surveyor, obj=obj)
156+
core.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
157157

158158
old_representation = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
159159
context_of_items = old_representation.ContextOfItems

src/blenderbim/blenderbim/bim/module/model/data.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
def refresh():
2424
AuthoringData.is_loaded = False
25-
WorkspaceData.is_loaded = False
2625

2726

2827
class AuthoringData:
@@ -31,29 +30,27 @@ class AuthoringData:
3130

3231
@classmethod
3332
def load(cls):
33+
cls.is_loaded = True
3434
cls.data = {
3535
"ifc_classes": cls.ifc_classes(),
3636
"relating_types": cls.relating_types(),
3737
}
38-
cls.is_loaded = True
3938

4039
@classmethod
4140
def ifc_classes(cls):
4241
results = []
43-
classes = set([e.is_a() for e in tool.Ifc.get().by_type("IfcElementType")])
42+
classes = {e.is_a() for e in tool.Ifc.get().by_type("IfcElementType")}
4443
results.extend([(c, c, "") for c in sorted(classes)])
4544
return results
4645

4746
@classmethod
4847
def relating_types(cls):
48+
if not cls.ifc_classes():
49+
return []
4950
results = []
5051
ifc_class = bpy.context.scene.BIMModelProperties.ifc_class
5152
if ifc_class:
5253
elements = [(str(e.id()), e.Name, "") for e in tool.Ifc.get().by_type(ifc_class)]
5354
results.extend(sorted(elements, key=lambda s: s[1]))
5455
return results
5556
return []
56-
57-
58-
class WorkspaceData(AuthoringData):
59-
pass

src/blenderbim/blenderbim/bim/module/model/workspace.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import blenderbim.bim.module.type.prop as type_prop
2222
from bpy.types import WorkSpaceTool
2323
from blenderbim.bim.ifc import IfcStore
24-
from blenderbim.bim.module.model.data import WorkspaceData
24+
from blenderbim.bim.module.model.data import AuthoringData
2525

2626

2727
class BimTool(WorkSpaceTool):
@@ -52,19 +52,19 @@ class BimTool(WorkSpaceTool):
5252
)
5353

5454
def draw_settings(context, layout, tool):
55-
if not WorkspaceData.is_loaded:
56-
WorkspaceData.load()
55+
if not AuthoringData.is_loaded:
56+
AuthoringData.load()
5757

5858
row = layout.row(align=True)
5959
if not IfcStore.get_file():
6060
row.label(text="No IFC Project", icon="ERROR")
6161
return
6262
props = context.scene.BIMModelProperties
63-
if WorkspaceData.data["ifc_classes"]:
63+
if AuthoringData.data["ifc_classes"]:
6464
row.prop(props, "ifc_class", text="")
6565
else:
6666
row.label(text="No IFC Class")
67-
if WorkspaceData.data["relating_types"]:
67+
if AuthoringData.data["relating_types"]:
6868
row.prop(props, "relating_type", text="")
6969
else:
7070
row.label(text="No Relating Type")
@@ -75,7 +75,7 @@ def draw_settings(context, layout, tool):
7575
row.label(text="", icon="EVENT_SHIFT")
7676
row.label(text="Add Type Instance", icon="EVENT_A")
7777

78-
if not ifc_classes_is_empty:
78+
if AuthoringData.data["ifc_classes"]:
7979
if props.ifc_class == "IfcWallType":
8080
row = layout.row()
8181
row.label(text="Join")
@@ -147,9 +147,9 @@ def execute(self, context):
147147

148148
def _execute(self, context):
149149
self.props = context.scene.BIMModelProperties
150-
self.ifc_classes_is_empty = True
150+
self.has_ifc_class = True
151151
try:
152-
self.ifc_classes_is_empty = bool(self.props.ifc_class)
152+
self.has_ifc_class = bool(self.props.ifc_class)
153153
except:
154154
pass
155155
getattr(self, f"hotkey_{self.hotkey}")()
@@ -159,27 +159,27 @@ def hotkey_S_A(self):
159159
bpy.ops.bim.add_type_instance()
160160

161161
def hotkey_S_C(self):
162-
if not self.ifc_classes_is_empty and self.props.ifc_class == "IfcWallType":
162+
if self.has_ifc_class and self.props.ifc_class == "IfcWallType":
163163
bpy.ops.bim.align_wall(align_type="CENTERLINE")
164164
else:
165165
bpy.ops.bim.align_product(align_type="CENTERLINE")
166166

167167
def hotkey_S_E(self):
168-
if self.ifc_classes_is_empty:
168+
if not self.has_ifc_class:
169169
return
170170
if self.props.ifc_class == "IfcWallType":
171171
bpy.ops.bim.join_wall(join_type="T")
172172
elif self.props.ifc_class in ["IfcColumnType", "IfcBeamType", "IfcMemberType"]:
173173
bpy.ops.bim.extend_profile()
174174

175175
def hotkey_S_V(self):
176-
if not self.ifc_classes_is_empty and self.props.ifc_class == "IfcWallType":
176+
if self.has_ifc_class and self.props.ifc_class == "IfcWallType":
177177
bpy.ops.bim.align_wall(align_type="INTERIOR")
178178
else:
179179
bpy.ops.bim.align_product(align_type="POSITIVE")
180180

181181
def hotkey_S_X(self):
182-
if not self.ifc_classes_is_empty and self.props.ifc_class == "IfcWallType":
182+
if self.has_ifc_class and self.props.ifc_class == "IfcWallType":
183183
if bpy.ops.bim.align_wall.poll():
184184
bpy.ops.bim.align_wall(align_type="EXTERIOR")
185185
else:

src/blenderbim/blenderbim/core/geometry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
import blenderbim.core.style
2020

2121

22-
def edit_object_placement(ifc, surveyor, obj=None):
22+
def edit_object_placement(ifc, geometry, surveyor, obj=None):
2323
element = ifc.get_entity(obj)
2424
if element:
25+
geometry.clear_scale(obj)
2526
ifc.run("geometry.edit_object_placement", product=element, matrix=surveyor.get_absolute_matrix(obj))
2627

2728

@@ -32,7 +33,7 @@ def add_representation(
3233
if not element:
3334
return
3435

35-
edit_object_placement(ifc, surveyor, obj=obj)
36+
edit_object_placement(ifc, geometry, surveyor, obj=obj)
3637
data = geometry.get_object_data(obj)
3738

3839
if not data:

src/blenderbim/blenderbim/core/tool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def set_context(cls, context): pass
7474
class Geometry:
7575
def change_object_data(cls, obj, data, is_global=False): pass
7676
def clear_modifiers(cls, obj): pass
77+
def clear_scale(cls, obj): pass
7778
def create_dynamic_voids(cls, obj): pass
7879
def delete_data(cls, data): pass
7980
def does_object_have_mesh_with_faces(cls, obj): pass

src/blenderbim/blenderbim/tool/geometry.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ def clear_modifiers(cls, obj):
3939
for modifier in obj.modifiers:
4040
obj.modifiers.remove(modifier)
4141

42+
@classmethod
43+
def clear_scale(cls, obj):
44+
if obj.scale != Vector((1.0, 1.0, 1.0)):
45+
if obj.data.users == 1:
46+
context_override = {}
47+
context_override["object"] = context_override["active_object"] = obj
48+
context_override["selected_objects"] = context_override["selected_editable_objects"] = [obj]
49+
bpy.ops.object.transform_apply(context_override, location=False, rotation=False, scale=True)
50+
else:
51+
obj.scale = Vector((1.0, 1.0, 1.0))
52+
4253
@classmethod
4354
def create_dynamic_voids(cls, obj):
4455
element = tool.Ifc.get_entity(obj)

src/blenderbim/test/core/test_geometry.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@
2222

2323

2424
class TestEditObjectPlacement:
25-
def predict(self, ifc, surveyor):
25+
def predict(self, ifc, geometry, surveyor):
2626
ifc.get_entity("obj").should_be_called().will_return("element")
27+
geometry.clear_scale("obj").should_be_called()
2728
surveyor.get_absolute_matrix("obj").should_be_called().will_return("matrix")
2829
ifc.run("geometry.edit_object_placement", product="element", matrix="matrix").should_be_called()
2930

30-
def test_run(self, ifc, surveyor):
31-
self.predict(ifc, surveyor)
32-
subject.edit_object_placement(ifc, surveyor, obj="obj")
31+
def test_run(self, ifc, geometry, surveyor):
32+
self.predict(ifc, geometry, surveyor)
33+
subject.edit_object_placement(ifc, geometry, surveyor, obj="obj")
3334

3435

3536
class TestAddRepresentation:
3637
def test_run(self, ifc, geometry, style, surveyor):
37-
TestEditObjectPlacement.predict(self, ifc, surveyor)
38+
TestEditObjectPlacement.predict(self, ifc, geometry, surveyor)
3839

3940
# Add representation
4041
geometry.get_object_data("obj").should_be_called().will_return("data")
@@ -96,7 +97,7 @@ def test_run(self, ifc, geometry, style, surveyor):
9697
)
9798

9899
def test_not_handling_styles_if_representation_has_no_faces(self, ifc, geometry, style, surveyor):
99-
TestEditObjectPlacement.predict(self, ifc, surveyor)
100+
TestEditObjectPlacement.predict(self, ifc, geometry, surveyor)
100101

101102
# Add representation
102103
geometry.get_object_data("obj").should_be_called().will_return("data")
@@ -145,7 +146,7 @@ def test_not_handling_styles_if_representation_has_no_faces(self, ifc, geometry,
145146
)
146147

147148
def test_only_updating_the_placement_if_there_is_no_object_data(self, ifc, geometry, style, surveyor):
148-
TestEditObjectPlacement.predict(self, ifc, surveyor)
149+
TestEditObjectPlacement.predict(self, ifc, geometry, surveyor)
149150

150151
# Add representation
151152
geometry.get_object_data("obj").should_be_called().will_return(None)

src/blenderbim/test/tool/test_geometry.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def test_run(self):
6161
assert len(obj.modifiers) == 0
6262

6363

64+
class TestClearScale(NewFile):
65+
def test_run(self):
66+
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
67+
obj.scale[0] = 2
68+
subject.clear_scale(obj)
69+
assert list(obj.scale) == [1, 1, 1]
70+
71+
6472
class TestCreateDynamicVoids(NewFile):
6573
def test_run(self):
6674
ifc = ifcopenshell.file()

src/ifcopenshell-python/ifcopenshell/api/geometry/add_representation.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ def should_triangulate_face(self, face, threshold=EPSILON):
6666
return any([abs((tM @ v.co).z) > threshold for v in face.verts])
6767

6868
def evaluate_geometry(self):
69-
if self.settings["blender_object"].scale != Vector((1., 1., 1.)):
70-
if self.settings["blender_object"].data.users == 1:
71-
context_override = {}
72-
context_override["object"] = context_override["active_object"] = self.settings["blender_object"]
73-
context_override["selected_objects"] = context_override["selected_editable_objects"] = [self.settings["blender_object"]]
74-
bpy.ops.object.transform_apply(context_override, location=False, rotation=False, scale=True)
75-
else:
76-
self.settings["blender_object"].scale = Vector((1., 1., 1.))
77-
7869
for modifier in self.settings["blender_object"].modifiers:
7970
if modifier.type == "BOOLEAN":
8071
modifier.show_viewport = False

0 commit comments

Comments
 (0)