mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
Fix #7656. Regression in text editing where leaders were accidentally removed. Added tests.
This commit is contained in:
@@ -857,9 +857,11 @@ class Drawing(bonsai.core.tool.Drawing):
|
|||||||
def edit_text_literals(cls, obj: bpy.types.Object, literal_attributes: dict) -> None:
|
def edit_text_literals(cls, obj: bpy.types.Object, literal_attributes: dict) -> None:
|
||||||
assert (element := tool.Ifc.get_entity(obj))
|
assert (element := tool.Ifc.get_entity(obj))
|
||||||
assert (rep := cls.get_annotation_representation(element))
|
assert (rep := cls.get_annotation_representation(element))
|
||||||
for literal in cls.get_text_literal(obj, return_list=True):
|
to_remove = [i for i in rep.Items if i.is_a("IfcTextLiteral")]
|
||||||
|
new_literals = [cls.add_literal(**a) for a in literal_attributes]
|
||||||
|
rep.Items = [i for i in rep.Items if not i.is_a("IfcTextLiteral")] + new_literals
|
||||||
|
for literal in to_remove:
|
||||||
ifcopenshell.util.element.remove_deep2(tool.Ifc.get(), literal)
|
ifcopenshell.util.element.remove_deep2(tool.Ifc.get(), literal)
|
||||||
rep.Items = [cls.add_literal(**a) for a in literal_attributes]
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_literal(cls, **attributes: str) -> ifcopenshell.entity_instance:
|
def add_literal(cls, **attributes: str) -> ifcopenshell.entity_instance:
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import xml.etree.ElementTree as ET
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
import pytest
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api.drawing
|
import ifcopenshell.api.drawing
|
||||||
import ifcopenshell.api.group
|
import ifcopenshell.api.group
|
||||||
@@ -31,6 +32,7 @@ import ifcopenshell.util.element
|
|||||||
import mathutils
|
import mathutils
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
|
from ifcopenshell.util.shape_builder import ShapeBuilder
|
||||||
|
|
||||||
import bonsai.core.tool
|
import bonsai.core.tool
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
@@ -150,6 +152,34 @@ class TestDisableEditingSheets(NewFile):
|
|||||||
assert props.is_editing_sheets == False
|
assert props.is_editing_sheets == False
|
||||||
|
|
||||||
|
|
||||||
|
class TestEditTextLiterals(NewFile):
|
||||||
|
def test_run(self):
|
||||||
|
ifc = ifcopenshell.file()
|
||||||
|
tool.Ifc.set(ifc)
|
||||||
|
obj = bpy.data.objects.new("Object", None)
|
||||||
|
element = ifc.createIfcAnnotation()
|
||||||
|
element.Representation = ifc.createIfcProductDefinitionShape()
|
||||||
|
context = ifc.createIfcGeometricRepresentationSubContext(ContextType="Plan", ContextIdentifier="Annotation")
|
||||||
|
item = ifc.createIfcTextLiteralWithExtent(Literal="Literal", Path="RIGHT", BoxAlignment="bottom-left")
|
||||||
|
builder = ShapeBuilder(tool.Ifc.get())
|
||||||
|
polyline = builder.polyline([(0.,0.,0.), (1.,0.,0.)])
|
||||||
|
representation = ifc.createIfcShapeRepresentation(ContextOfItems=context, Items=[item, polyline])
|
||||||
|
element.Representation.Representations = [representation]
|
||||||
|
tool.Ifc.link(element, obj)
|
||||||
|
literal_attributes = [
|
||||||
|
{
|
||||||
|
"Literal": "Foo",
|
||||||
|
"Path": "RIGHT",
|
||||||
|
"BoxAlignment": "bottom-left",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
subject.edit_text_literals(obj, literal_attributes)
|
||||||
|
assert len(ifc.by_type("IfcTextLiteralWithExtent")) == 1
|
||||||
|
literal = ifc.by_type("IfcTextLiteralWithExtent")[0]
|
||||||
|
assert literal in representation.Items
|
||||||
|
assert literal.Literal == "Foo"
|
||||||
|
|
||||||
|
|
||||||
class TestDisableEditingText(NewFile):
|
class TestDisableEditingText(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
obj = bpy.data.objects.new("Object", None)
|
obj = bpy.data.objects.new("Object", None)
|
||||||
|
|||||||
Reference in New Issue
Block a user