Updating drawing names now updates it in IFC too. See #1153.

This commit is contained in:
Dion Moult
2022-02-04 15:04:30 +11:00
parent 524483e9cc
commit 9f530d0578
5 changed files with 75 additions and 15 deletions
@@ -19,11 +19,12 @@
import os import os
import bpy import bpy
import json import json
import enum
import ifcopenshell import ifcopenshell
import blenderbim.tool as tool import blenderbim.tool as tool
import blenderbim.core.drawing as core
import blenderbim.bim.module.drawing.annotation as annotation import blenderbim.bim.module.drawing.annotation as annotation
import blenderbim.bim.module.drawing.decoration as decoration import blenderbim.bim.module.drawing.decoration as decoration
import enum
from blenderbim.bim.module.drawing.data import DrawingsData from blenderbim.bim.module.drawing.data import DrawingsData
from pathlib import Path from pathlib import Path
from blenderbim.bim.prop import Attribute, StrProperty from blenderbim.bim.prop import Attribute, StrProperty
@@ -143,16 +144,9 @@ def get_diagram_scales(self, context):
return diagram_scales_enum return diagram_scales_enum
def updateDrawingName(self, context): def update_drawing_name(self, context):
if not self.camera: drawing = tool.Ifc.get().by_id(self.ifc_definition_id)
return core.update_drawing_name(tool.Ifc, tool.Drawing, drawing=drawing, name=self.name)
if self.camera.name == self.name:
return
self.camera.name = "IfcAnnotation/{}".format(self.name)
unique_name = "/".join(self.camera.name.split("/")[1:])
self.camera.users_collection[0].name = "IfcGroup/{}".format(unique_name)
if self.name != unique_name:
self.name = unique_name
def getTitleblocks(self, context): def getTitleblocks(self, context):
@@ -204,8 +198,7 @@ class Variable(PropertyGroup):
class Drawing(PropertyGroup): class Drawing(PropertyGroup):
ifc_definition_id: IntProperty(name="IFC Definition ID") ifc_definition_id: IntProperty(name="IFC Definition ID")
name: StringProperty(name="Name", update=updateDrawingName) name: StringProperty(name="Name", update=update_drawing_name)
camera: PointerProperty(name="Camera", type=bpy.types.Object)
class Schedule(PropertyGroup): class Schedule(PropertyGroup):
@@ -128,3 +128,12 @@ def remove_drawing(ifc, drawing_tool, drawing=None):
drawing_tool.delete_collection(collection) drawing_tool.delete_collection(collection)
ifc.run("root.remove_product", product=drawing) ifc.run("root.remove_product", product=drawing)
drawing_tool.import_drawings() drawing_tool.import_drawings()
def update_drawing_name(ifc, drawing_tool, drawing=None, name=None):
if drawing_tool.get_name(drawing) != name:
ifc.run("attribute.edit_attributes", product=drawing, attributes={"Name": name})
group = drawing_tool.get_drawing_group(drawing)
if drawing_tool.get_name(group) != name:
ifc.run("attribute.edit_attributes", product=group, attributes={"Name": name})
drawing_tool.set_drawing_collection_name(group, drawing_tool.get_drawing_collection(drawing))
@@ -136,6 +136,10 @@ class Drawing(blenderbim.core.tool.Drawing):
for rel in group.IsGroupedBy or []: for rel in group.IsGroupedBy or []:
return rel.RelatedObjects return rel.RelatedObjects
@classmethod
def get_name(cls, element):
return element.Name
@classmethod @classmethod
def get_sheet_filename(cls, document): def get_sheet_filename(cls, document):
if hasattr(document, "Identification"): if hasattr(document, "Identification"):
@@ -278,6 +282,10 @@ class Drawing(blenderbim.core.tool.Drawing):
ifc_representation_class=ifc_representation_class, ifc_representation_class=ifc_representation_class,
) )
@classmethod
def set_drawing_collection_name(cls, group, collection):
collection.name = f"IfcGroup/{group.Name}"
@classmethod @classmethod
def update_text_value(cls, obj): def update_text_value(cls, obj):
element = cls.get_text_literal(obj) element = cls.get_text_literal(obj)
+36 -1
View File
@@ -154,7 +154,9 @@ class TestAddDrawing:
ifc_representation_class=None, 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", "ObjectType": "DRAWING"}
).should_be_called()
ifc.run("group.assign_group", group="group", product="element").should_be_called() ifc.run("group.assign_group", group="group", product="element").should_be_called()
collector.assign("obj").should_be_called() collector.assign("obj").should_be_called()
ifc.run("pset.add_pset", product="element", name="EPset_Drawing").should_be_called().will_return("pset") ifc.run("pset.add_pset", product="element", name="EPset_Drawing").should_be_called().will_return("pset")
@@ -163,3 +165,36 @@ class TestAddDrawing:
).should_be_called() ).should_be_called()
drawing.import_drawings().should_be_called() drawing.import_drawings().should_be_called()
subject.add_drawing(ifc, collector, drawing, target_view="target_view", location_hint="location_hint") subject.add_drawing(ifc, collector, drawing, target_view="target_view", location_hint="location_hint")
class TestRemoveDrawing:
def test_run(self, ifc, drawing):
drawing.get_drawing_collection("drawing").should_be_called().will_return("collection")
drawing.get_drawing_group("drawing").should_be_called().will_return("group")
drawing.get_group_elements("group").should_be_called().will_return("elements")
drawing.delete_drawing_elements("elements").should_be_called()
ifc.run("group.remove_group", group="group").should_be_called()
drawing.delete_collection("collection").should_be_called()
ifc.run("root.remove_product", product="drawing").should_be_called()
drawing.import_drawings().should_be_called()
subject.remove_drawing(ifc, drawing, drawing="drawing")
class TestUpdateDrawingName:
def test_do_not_update_if_name_unchanged(self, ifc, drawing):
drawing.get_name("drawing").should_be_called().will_return("name")
drawing.get_drawing_group("drawing").should_be_called().will_return("group")
drawing.get_name("group").should_be_called().will_return("name")
drawing.get_drawing_collection("drawing").should_be_called().will_return("collection")
drawing.set_drawing_collection_name("group", "collection").should_be_called()
subject.update_drawing_name(ifc, drawing, drawing="drawing", name="name")
def test_run(self, ifc, drawing):
drawing.get_name("drawing").should_be_called().will_return("oldname")
ifc.run("attribute.edit_attributes", product="drawing", attributes={"Name": "name"}).should_be_called()
drawing.get_drawing_group("drawing").should_be_called().will_return("group")
drawing.get_name("group").should_be_called().will_return("oldname")
ifc.run("attribute.edit_attributes", product="group", attributes={"Name": "name"}).should_be_called()
drawing.get_drawing_collection("drawing").should_be_called().will_return("collection")
drawing.set_drawing_collection_name("group", "collection").should_be_called()
subject.update_drawing_name(ifc, drawing, drawing="drawing", name="name")
+16 -1
View File
@@ -217,6 +217,12 @@ class TestGetGroupElements(NewFile):
assert subject.get_group_elements(group) == (element,) assert subject.get_group_elements(group) == (element,)
class TestGetName(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
assert subject.get_name(ifc.createIfcWall(Name="Foobar")) == "Foobar"
class TestGetSheetFilename(NewFile): class TestGetSheetFilename(NewFile):
def test_run(self): def test_run(self):
ifc = ifcopenshell.file() ifc = ifcopenshell.file()
@@ -431,11 +437,20 @@ class TestOpenSvg(NewFile):
pass pass
class TestRunAssignClassOperator(NewFile): class TestRunRootAssignClassOperator(NewFile):
def test_nothing(self): def test_nothing(self):
pass pass
class TestSetDrawingCollectionName(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
group = ifc.createIfcGroup(Name="Foobaz")
collection = bpy.data.collections.new("Foobar")
subject.set_drawing_collection_name(group, collection)
assert collection.name == "IfcGroup/Foobaz"
class TestUpdateTextValue(NewFile): class TestUpdateTextValue(NewFile):
def test_updating_arbitrary_strings(self): def test_updating_arbitrary_strings(self):
TestGetTextLiteral().test_run() TestGetTextLiteral().test_run()