mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 19:07:57 +00:00
Updating drawing names now updates it in IFC too. See #1153.
This commit is contained in:
@@ -19,11 +19,12 @@
|
||||
import os
|
||||
import bpy
|
||||
import json
|
||||
import enum
|
||||
import ifcopenshell
|
||||
import blenderbim.tool as tool
|
||||
import blenderbim.core.drawing as core
|
||||
import blenderbim.bim.module.drawing.annotation as annotation
|
||||
import blenderbim.bim.module.drawing.decoration as decoration
|
||||
import enum
|
||||
from blenderbim.bim.module.drawing.data import DrawingsData
|
||||
from pathlib import Path
|
||||
from blenderbim.bim.prop import Attribute, StrProperty
|
||||
@@ -143,16 +144,9 @@ def get_diagram_scales(self, context):
|
||||
return diagram_scales_enum
|
||||
|
||||
|
||||
def updateDrawingName(self, context):
|
||||
if not self.camera:
|
||||
return
|
||||
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 update_drawing_name(self, context):
|
||||
drawing = tool.Ifc.get().by_id(self.ifc_definition_id)
|
||||
core.update_drawing_name(tool.Ifc, tool.Drawing, drawing=drawing, name=self.name)
|
||||
|
||||
|
||||
def getTitleblocks(self, context):
|
||||
@@ -204,8 +198,7 @@ class Variable(PropertyGroup):
|
||||
|
||||
class Drawing(PropertyGroup):
|
||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||
name: StringProperty(name="Name", update=updateDrawingName)
|
||||
camera: PointerProperty(name="Camera", type=bpy.types.Object)
|
||||
name: StringProperty(name="Name", update=update_drawing_name)
|
||||
|
||||
|
||||
class Schedule(PropertyGroup):
|
||||
|
||||
@@ -128,3 +128,12 @@ def remove_drawing(ifc, drawing_tool, drawing=None):
|
||||
drawing_tool.delete_collection(collection)
|
||||
ifc.run("root.remove_product", product=drawing)
|
||||
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 []:
|
||||
return rel.RelatedObjects
|
||||
|
||||
@classmethod
|
||||
def get_name(cls, element):
|
||||
return element.Name
|
||||
|
||||
@classmethod
|
||||
def get_sheet_filename(cls, document):
|
||||
if hasattr(document, "Identification"):
|
||||
@@ -278,6 +282,10 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
ifc_representation_class=ifc_representation_class,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_drawing_collection_name(cls, group, collection):
|
||||
collection.name = f"IfcGroup/{group.Name}"
|
||||
|
||||
@classmethod
|
||||
def update_text_value(cls, obj):
|
||||
element = cls.get_text_literal(obj)
|
||||
|
||||
@@ -154,7 +154,9 @@ class TestAddDrawing:
|
||||
ifc_representation_class=None,
|
||||
).should_be_called().will_return("element")
|
||||
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()
|
||||
collector.assign("obj").should_be_called()
|
||||
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()
|
||||
drawing.import_drawings().should_be_called()
|
||||
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")
|
||||
|
||||
@@ -217,6 +217,12 @@ class TestGetGroupElements(NewFile):
|
||||
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):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -431,11 +437,20 @@ class TestOpenSvg(NewFile):
|
||||
pass
|
||||
|
||||
|
||||
class TestRunAssignClassOperator(NewFile):
|
||||
class TestRunRootAssignClassOperator(NewFile):
|
||||
def test_nothing(self):
|
||||
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):
|
||||
def test_updating_arbitrary_strings(self):
|
||||
TestGetTextLiteral().test_run()
|
||||
|
||||
Reference in New Issue
Block a user