mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 17:20:04 +00:00
Fix bug where drawing objects could be added to the wrong context.
This commit is contained in:
@@ -102,8 +102,14 @@ def add_drawing(ifc, collector, drawing, target_view=None, location_hint=None):
|
|||||||
drawing_name = drawing.ensure_unique_drawing_name("UNTITLED")
|
drawing_name = drawing.ensure_unique_drawing_name("UNTITLED")
|
||||||
drawing_matrix = drawing.generate_drawing_matrix(target_view, location_hint)
|
drawing_matrix = drawing.generate_drawing_matrix(target_view, location_hint)
|
||||||
camera = drawing.create_camera(drawing_name, drawing_matrix)
|
camera = drawing.create_camera(drawing_name, drawing_matrix)
|
||||||
# Not yet refactored
|
element = drawing.run_root_assign_class(
|
||||||
element = drawing.run_assign_class_operator(obj=camera, ifc_class="IfcAnnotation", predefined_type="DRAWING")
|
obj=camera,
|
||||||
|
ifc_class="IfcAnnotation",
|
||||||
|
predefined_type="DRAWING",
|
||||||
|
should_add_representation=True,
|
||||||
|
context=drawing.get_body_context(),
|
||||||
|
ifc_representation_class=None,
|
||||||
|
)
|
||||||
group = ifc.run("group.add_group")
|
group = ifc.run("group.add_group")
|
||||||
ifc.run("group.edit_group", group=group, attributes={"Name": drawing_name})
|
ifc.run("group.edit_group", group=group, attributes={"Name": drawing_name})
|
||||||
ifc.run("group.assign_group", group=group, product=element)
|
ifc.run("group.assign_group", group=group, product=element)
|
||||||
|
|||||||
@@ -104,6 +104,10 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
def export_text_literal_attributes(cls, obj):
|
def export_text_literal_attributes(cls, obj):
|
||||||
return blenderbim.bim.helper.export_attributes(obj.BIMTextProperties.attributes)
|
return blenderbim.bim.helper.export_attributes(obj.BIMTextProperties.attributes)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_body_context(cls):
|
||||||
|
return ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_sheet_filename(cls, document):
|
def get_sheet_filename(cls, document):
|
||||||
if hasattr(document, "Identification"):
|
if hasattr(document, "Identification"):
|
||||||
@@ -195,9 +199,18 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run_assign_class_operator(cls, obj=None, ifc_class=None, predefined_type=None):
|
def run_root_assign_class(cls, obj=None, ifc_class=None, predefined_type=None, should_add_representation=True, context=None, ifc_representation_class=None):
|
||||||
bpy.ops.bim.assign_class(obj=obj.name, ifc_class=ifc_class, predefined_type=predefined_type)
|
return blenderbim.core.root.assign_class(
|
||||||
return tool.Ifc.get_entity(obj)
|
tool.Ifc,
|
||||||
|
tool.Collector,
|
||||||
|
tool.Root,
|
||||||
|
obj=obj,
|
||||||
|
ifc_class=ifc_class,
|
||||||
|
predefined_type=predefined_type,
|
||||||
|
should_add_representation=should_add_representation,
|
||||||
|
context=context,
|
||||||
|
ifc_representation_class=ifc_representation_class,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_text_value(cls, obj):
|
def update_text_value(cls, obj):
|
||||||
|
|||||||
@@ -144,8 +144,14 @@ class TestAddDrawing:
|
|||||||
drawing.ensure_unique_drawing_name("UNTITLED").should_be_called().will_return("name")
|
drawing.ensure_unique_drawing_name("UNTITLED").should_be_called().will_return("name")
|
||||||
drawing.generate_drawing_matrix("target_view", "location_hint").should_be_called().will_return("matrix")
|
drawing.generate_drawing_matrix("target_view", "location_hint").should_be_called().will_return("matrix")
|
||||||
drawing.create_camera("name", "matrix").should_be_called().will_return("obj")
|
drawing.create_camera("name", "matrix").should_be_called().will_return("obj")
|
||||||
drawing.run_assign_class_operator(
|
drawing.get_body_context().should_be_called().will_return("context")
|
||||||
obj="obj", ifc_class="IfcAnnotation", predefined_type="DRAWING"
|
drawing.run_root_assign_class(
|
||||||
|
obj="obj",
|
||||||
|
ifc_class="IfcAnnotation",
|
||||||
|
predefined_type="DRAWING",
|
||||||
|
should_add_representation=True,
|
||||||
|
context="context",
|
||||||
|
ifc_representation_class=None,
|
||||||
).should_be_called().will_return("element")
|
).should_be_called().will_return("element")
|
||||||
ifc.run("group.add_group").should_be_called().will_return("group")
|
ifc.run("group.add_group").should_be_called().will_return("group")
|
||||||
ifc.run("group.edit_group", group="group", attributes={"Name": "name"}).should_be_called()
|
ifc.run("group.edit_group", group="group", attributes={"Name": "name"}).should_be_called()
|
||||||
|
|||||||
@@ -149,6 +149,16 @@ class TestExportTextLiteralAttributes(NewFile):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetBodyContext(NewFile):
|
||||||
|
def test_run(self):
|
||||||
|
ifc = ifcopenshell.file()
|
||||||
|
context = ifc.createIfcGeometricRepresentationSubContext(
|
||||||
|
ContextType="Model", ContextIdentifier="Body", TargetView="MODEL_VIEW"
|
||||||
|
)
|
||||||
|
tool.Ifc.set(ifc)
|
||||||
|
assert subject.get_body_context() == context
|
||||||
|
|
||||||
|
|
||||||
class TestGetSheetFilename(NewFile):
|
class TestGetSheetFilename(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
|
|||||||
Reference in New Issue
Block a user