mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Tests for external svg references
This commit is contained in:
@@ -184,9 +184,9 @@ def set_drawing_style_name(self, new_value):
|
||||
bpy.ops.bim.save_drawing_styles_data(rename_style=True, rename_style_from=old_value, rename_style_to=new_value)
|
||||
|
||||
|
||||
def update_schedule_name(self, context):
|
||||
schedule = tool.Ifc.get().by_id(self.ifc_definition_id)
|
||||
core.update_schedule_name(tool.Ifc, tool.Drawing, schedule=schedule, name=self.name)
|
||||
def update_document_name(self, context):
|
||||
document = tool.Ifc.get().by_id(self.ifc_definition_id)
|
||||
core.update_document_name(tool.Ifc, tool.Drawing, document=document, name=self.name)
|
||||
|
||||
|
||||
def update_has_underlay(self, context):
|
||||
@@ -257,7 +257,7 @@ class Drawing(PropertyGroup):
|
||||
|
||||
class Document(PropertyGroup):
|
||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||
name: StringProperty(name="Name", update=update_schedule_name)
|
||||
name: StringProperty(name="Name", update=update_document_name)
|
||||
identification: StringProperty(name="Identification")
|
||||
|
||||
|
||||
|
||||
@@ -173,9 +173,9 @@ def open_reference(drawing, reference=None):
|
||||
drawing.open_svg(drawing.get_document_uri(reference))
|
||||
|
||||
|
||||
def update_schedule_name(ifc, drawing, schedule=None, name=None):
|
||||
if drawing.get_name(schedule) != name:
|
||||
ifc.run("document.edit_information", information=schedule, attributes={"Name": name})
|
||||
def update_document_name(ifc, drawing, document=None, name=None):
|
||||
if drawing.get_name(document) != name:
|
||||
ifc.run("document.edit_information", information=document, attributes={"Name": name})
|
||||
|
||||
|
||||
def load_drawings(drawing):
|
||||
|
||||
@@ -253,6 +253,7 @@ class Drawing:
|
||||
def disable_editing_assigned_product(cls, obj): pass
|
||||
def disable_editing_drawings(cls): pass
|
||||
def disable_editing_schedules(cls): pass
|
||||
def disable_editing_references(cls): pass
|
||||
def disable_editing_sheets(cls): pass
|
||||
def disable_editing_text(cls, obj): pass
|
||||
def does_file_exist(cls, uri): pass
|
||||
@@ -260,6 +261,7 @@ class Drawing:
|
||||
def enable_editing_assigned_product(cls, obj): pass
|
||||
def enable_editing_drawings(cls): pass
|
||||
def enable_editing_schedules(cls): pass
|
||||
def enable_editing_references(cls): pass
|
||||
def enable_editing_sheets(cls): pass
|
||||
def enable_editing_text(cls, obj): pass
|
||||
def ensure_unique_drawing_name(cls, name): pass
|
||||
|
||||
@@ -217,12 +217,80 @@ class TestOpenSchedule:
|
||||
class TestUpdateScheduleName:
|
||||
def test_do_not_update_if_name_unchanged(self, ifc, drawing):
|
||||
drawing.get_name("schedule").should_be_called().will_return("name")
|
||||
subject.update_schedule_name(ifc, drawing, schedule="schedule", name="name")
|
||||
subject.update_document_name(ifc, drawing, document="schedule", name="name")
|
||||
|
||||
def test_run(self, ifc, drawing):
|
||||
drawing.get_name("schedule").should_be_called().will_return("oldname")
|
||||
ifc.run("document.edit_information", information="schedule", attributes={"Name": "name"}).should_be_called()
|
||||
subject.update_schedule_name(ifc, drawing, schedule="schedule", name="name")
|
||||
subject.update_document_name(ifc, drawing, document="schedule", name="name")
|
||||
|
||||
|
||||
class TestLoadReferences:
|
||||
def test_run(self, drawing):
|
||||
drawing.import_documents("REFERENCE").should_be_called()
|
||||
drawing.enable_editing_references().should_be_called()
|
||||
subject.load_references(drawing)
|
||||
|
||||
|
||||
class TestDisableEditingReferences:
|
||||
def test_run(self, drawing):
|
||||
drawing.disable_editing_references().should_be_called()
|
||||
subject.disable_editing_references(drawing)
|
||||
|
||||
|
||||
class TestAddReference:
|
||||
def test_run(self, ifc, drawing):
|
||||
ifc.run("document.add_information").should_be_called().will_return("reference")
|
||||
drawing.get_path_filename("uri").should_be_called().will_return("UNTITLED")
|
||||
ifc.run("document.add_reference", information="reference").should_be_called().will_return("reference")
|
||||
ifc.get_schema().should_be_called().will_return("IFC4")
|
||||
ifc.run(
|
||||
"document.edit_information",
|
||||
information="reference",
|
||||
attributes={"Identification": "X", "Name": "UNTITLED", "Scope": "REFERENCE"},
|
||||
).should_be_called()
|
||||
ifc.run("document.edit_reference", reference="reference", attributes={"Location": "uri"}).should_be_called()
|
||||
drawing.import_documents("REFERENCE").should_be_called()
|
||||
subject.add_document(ifc, drawing, "REFERENCE", uri="uri")
|
||||
|
||||
def test_using_a_document_id_in_ifc2x3(self, ifc, drawing):
|
||||
ifc.run("document.add_information").should_be_called().will_return("reference")
|
||||
drawing.get_path_filename("uri").should_be_called().will_return("UNTITLED")
|
||||
ifc.run("document.add_reference", information="reference").should_be_called().will_return("reference")
|
||||
ifc.get_schema().should_be_called().will_return("IFC2X3")
|
||||
ifc.run(
|
||||
"document.edit_information",
|
||||
information="reference",
|
||||
attributes={"DocumentId": "X", "Name": "UNTITLED", "Scope": "REFERENCE"},
|
||||
).should_be_called()
|
||||
ifc.run("document.edit_reference", reference="reference", attributes={"Location": "uri"}).should_be_called()
|
||||
drawing.import_documents("REFERENCE").should_be_called()
|
||||
subject.add_document(ifc, drawing, "REFERENCE", uri="uri")
|
||||
|
||||
|
||||
class TestRemoveReference:
|
||||
def test_run(self, ifc, drawing):
|
||||
ifc.run("document.remove_information", information="reference").should_be_called()
|
||||
drawing.import_documents("REFERENCE").should_be_called()
|
||||
subject.remove_document(ifc, drawing, "REFERENCE", document="reference")
|
||||
|
||||
|
||||
class TestOpenReference:
|
||||
def test_run(self, drawing):
|
||||
drawing.get_document_uri("reference").should_be_called().will_return("uri")
|
||||
drawing.open_svg("uri").should_be_called()
|
||||
subject.open_reference(drawing, reference="reference")
|
||||
|
||||
|
||||
class TestUpdateReferenceName:
|
||||
def test_do_not_update_if_name_unchanged(self, ifc, drawing):
|
||||
drawing.get_name("reference").should_be_called().will_return("name")
|
||||
subject.update_document_name(ifc, drawing, document="reference", name="name")
|
||||
|
||||
def test_run(self, ifc, drawing):
|
||||
drawing.get_name("reference").should_be_called().will_return("oldname")
|
||||
ifc.run("document.edit_information", information="reference", attributes={"Name": "name"}).should_be_called()
|
||||
subject.update_document_name(ifc, drawing, document="reference", name="name")
|
||||
|
||||
|
||||
class TestLoadDrawings:
|
||||
|
||||
@@ -120,6 +120,13 @@ class TestDisableEditingSchedules(NewFile):
|
||||
assert bpy.context.scene.DocProperties.is_editing_schedules == False
|
||||
|
||||
|
||||
class TestDisableEditingReferences(NewFile):
|
||||
def test_run(self):
|
||||
bpy.context.scene.DocProperties.is_editing_references = True
|
||||
subject.disable_editing_references()
|
||||
assert bpy.context.scene.DocProperties.is_editing_references == False
|
||||
|
||||
|
||||
class TestDisableEditingSheets(NewFile):
|
||||
def test_run(self):
|
||||
bpy.context.scene.DocProperties.is_editing_sheets = True
|
||||
@@ -165,6 +172,13 @@ class TestEnableEditingSchedules(NewFile):
|
||||
assert bpy.context.scene.DocProperties.is_editing_schedules == True
|
||||
|
||||
|
||||
class TestEnableEditingReferences(NewFile):
|
||||
def test_run(self):
|
||||
bpy.context.scene.DocProperties.is_editing_references = False
|
||||
subject.enable_editing_references()
|
||||
assert bpy.context.scene.DocProperties.is_editing_references == True
|
||||
|
||||
|
||||
class TestEnableEditingSheets(NewFile):
|
||||
def test_run(self):
|
||||
bpy.context.scene.DocProperties.is_editing_sheets = False
|
||||
@@ -497,6 +511,30 @@ class TestImportSchedules(NewFile):
|
||||
assert props.schedules[0].name == "FOOBAR"
|
||||
|
||||
|
||||
class TestImportReferences(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
ifc.createIfcDocumentInformation(Identification="Y", Name="FOOBAZ")
|
||||
document = ifc.createIfcDocumentInformation(Identification="X", Name="FOOBAR", Scope="REFERENCE")
|
||||
subject.import_documents("REFERENCE")
|
||||
props = bpy.context.scene.DocProperties
|
||||
assert props.references[0].ifc_definition_id == document.id()
|
||||
assert props.references[0].identification == "X"
|
||||
assert props.references[0].name == "FOOBAR"
|
||||
|
||||
def test_run_ifc2x3(self):
|
||||
ifc = ifcopenshell.file(schema="IFC2X3")
|
||||
tool.Ifc.set(ifc)
|
||||
ifc.createIfcDocumentInformation(DocumentId="Y", Name="FOOBAZ")
|
||||
document = ifc.createIfcDocumentInformation(DocumentId="X", Name="FOOBAR", Scope="REFERENCE")
|
||||
subject.import_documents("REFERENCE")
|
||||
props = bpy.context.scene.DocProperties
|
||||
assert props.references[0].ifc_definition_id == document.id()
|
||||
assert props.references[0].identification == "X"
|
||||
assert props.references[0].name == "FOOBAR"
|
||||
|
||||
|
||||
class TestImportSheets(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -570,6 +608,11 @@ class TestOpenSchedule(NewFile):
|
||||
pass
|
||||
|
||||
|
||||
class TestOpenReference(NewFile):
|
||||
def open_svg(self):
|
||||
pass
|
||||
|
||||
|
||||
class TestOpenSvg(NewFile):
|
||||
def test_nothing(self):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user