Rebuild text annotations to have leaders in the same object and use text literals. See #1153.

This commit is contained in:
Dion Moult
2021-11-16 08:54:16 +11:00
parent fcfdc179df
commit 43869c33f6
23 changed files with 694 additions and 163 deletions
+96
View File
@@ -0,0 +1,96 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
from test.bim.bootstrap import NewFile
from blenderbim.tool.drawing import Drawing as subject
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Drawing)
class TestDisableEditingText(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
obj.BIMTextProperties.is_editing = True
subject.disable_editing_text(obj)
assert obj.BIMTextProperties.is_editing == False
class TestEnableEditingText(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
subject.enable_editing_text(obj)
assert obj.BIMTextProperties.is_editing == True
class TestExportTextLiteralAttributes(NewFile):
def test_run(self):
TestImportTextAttributes().test_run()
assert subject.export_text_literal_attributes(bpy.data.objects.get("Object")) == {
"Literal": "Literal",
"Path": "RIGHT",
"BoxAlignment": "BoxAlignment",
}
class TestGetTextLiteral(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="BoxAlignment")
representation = ifc.createIfcShapeRepresentation(ContextOfItems=context, Items=[item])
element.Representation.Representations = [representation]
tool.Ifc.link(element, obj)
assert subject.get_text_literal(obj) == item
class TestImportTextAttributes(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="BoxAlignment")
representation = ifc.createIfcShapeRepresentation(ContextOfItems=context, Items=[item])
element.Representation.Representations = [representation]
tool.Ifc.link(element, obj)
subject.import_text_attributes(obj)
props = obj.BIMTextProperties
assert props.attributes.get("Literal").string_value == "Literal"
assert props.attributes.get("Path").enum_value == "RIGHT"
assert props.attributes.get("BoxAlignment").string_value == "BoxAlignment"
class TestUpdateTextValue(NewFile):
def test_run(self):
TestGetTextLiteral().test_run()
obj = bpy.data.objects.get("Object")
subject.update_text_value(obj)
assert obj.BIMTextProperties.value == "Literal"
+24 -1
View File
@@ -178,7 +178,16 @@ class TestGetStyles(NewFile):
tool.Ifc.link(style, material)
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
obj.data.materials.append(material)
subject.get_styles(obj) == [style]
assert subject.get_styles(obj) == [style]
class TestGetTextLiteral(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
item = ifc.createIfcTextLiteralWithExtent()
representation = ifc.createIfcShapeRepresentation(Items=[item])
assert subject.get_text_literal(representation) == item
class TestGetCartesianPointCoordinateOffset(NewFile):
@@ -490,6 +499,20 @@ class TestGetIfcRepresentationClass(NewFile):
subject.get_ifc_representation_class(element, representation) == "IfcExtrudedAreaSolid/IfcCircleProfileDef"
)
def test_detecting_text_representations(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcAnnotation()
element.ObjectType = "TEXT"
assert subject.get_ifc_representation_class(element, None) == "IfcTextLiteral"
def test_detecting_text_and_geometric_representations(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcAnnotation()
element.ObjectType = "TEXT_LEADER"
assert subject.get_ifc_representation_class(element, None) == "IfcGeometricCurveSet/IfcTextLiteral"
def test_returning_null_for_non_parametric_representations(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
+29 -29
View File
@@ -18,18 +18,18 @@
import bpy
import ifcopenshell
import test.bim.bootstrap
import blenderbim.core.tool
import blenderbim.tool as tool
from test.bim.bootstrap import NewFile
from blenderbim.tool.owner import Owner as subject
class TestImplementsTool(test.bim.bootstrap.NewFile):
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Owner)
class TestSetUser(test.bim.bootstrap.NewFile):
class TestSetUser(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
@@ -38,7 +38,7 @@ class TestSetUser(test.bim.bootstrap.NewFile):
assert bpy.context.scene.BIMOwnerProperties.active_user_id == user.id()
class TestGetUser(test.bim.bootstrap.NewFile):
class TestGetUser(NewFile):
def test_run(self):
assert subject.get_user() is None
TestSetUser().test_run()
@@ -56,14 +56,14 @@ class TestGetUser(test.bim.bootstrap.NewFile):
assert subject.get_user() == user2
class TestClearUser(test.bim.bootstrap.NewFile):
class TestClearUser(NewFile):
def test_run(self):
TestSetUser().test_run()
subject.clear_user()
assert bpy.context.scene.BIMOwnerProperties.active_user_id == 0
class TestSetAddress(test.bim.bootstrap.NewFile):
class TestSetAddress(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
address = ifc.createIfcPostalAddress()
@@ -71,7 +71,7 @@ class TestSetAddress(test.bim.bootstrap.NewFile):
assert bpy.context.scene.BIMOwnerProperties.active_address_id == address.id()
class TestImportAddressAttributes(test.bim.bootstrap.NewFile):
class TestImportAddressAttributes(NewFile):
def test_importing_a_postal_address(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
@@ -152,7 +152,7 @@ class TestImportAddressAttributes(test.bim.bootstrap.NewFile):
assert len(props.messaging_ids) == 0
class TestClearAddress(test.bim.bootstrap.NewFile):
class TestClearAddress(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
address = ifc.createIfcPostalAddress()
@@ -161,7 +161,7 @@ class TestClearAddress(test.bim.bootstrap.NewFile):
assert bpy.context.scene.BIMOwnerProperties.active_address_id == 0
class TestGetAddress(test.bim.bootstrap.NewFile):
class TestGetAddress(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
@@ -170,7 +170,7 @@ class TestGetAddress(test.bim.bootstrap.NewFile):
assert subject().get_address() == address
class TestExportAttributes(test.bim.bootstrap.NewFile):
class TestExportAttributes(NewFile):
def test_exporting_a_postal_address(self):
TestImportAddressAttributes().test_importing_a_postal_address()
assert subject().export_address_attributes() == {
@@ -201,7 +201,7 @@ class TestExportAttributes(test.bim.bootstrap.NewFile):
}
class TestAddAddressAttribute(test.bim.bootstrap.NewFile):
class TestAddAddressAttribute(NewFile):
def test_run(self):
subject().add_address_attribute("AddressLines")
subject().add_address_attribute("TelephoneNumbers")
@@ -216,7 +216,7 @@ class TestAddAddressAttribute(test.bim.bootstrap.NewFile):
assert len(props.messaging_ids) == 1
class TestRemoveAddressAttribute(test.bim.bootstrap.NewFile):
class TestRemoveAddressAttribute(NewFile):
TestAddAddressAttribute().test_run()
subject().remove_address_attribute("AddressLines", 0)
subject().remove_address_attribute("TelephoneNumbers", 0)
@@ -231,14 +231,14 @@ class TestRemoveAddressAttribute(test.bim.bootstrap.NewFile):
assert len(props.messaging_ids) == 0
class TestSetOrganisation(test.bim.bootstrap.NewFile):
class TestSetOrganisation(NewFile):
def test_run(self):
organisation = ifcopenshell.file().createIfcOrganization()
subject().set_organisation(organisation)
assert bpy.context.scene.BIMOwnerProperties.active_organisation_id == organisation.id()
class TestImportOrganisationAttributes(test.bim.bootstrap.NewFile):
class TestImportOrganisationAttributes(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
@@ -269,7 +269,7 @@ class TestImportOrganisationAttributes(test.bim.bootstrap.NewFile):
assert props.organisation_attributes.get("Description").string_value == ""
class TestClearOrganisation(test.bim.bootstrap.NewFile):
class TestClearOrganisation(NewFile):
def test_run(self):
props = bpy.context.scene.BIMOwnerProperties
props.active_organisation_id = 1
@@ -277,7 +277,7 @@ class TestClearOrganisation(test.bim.bootstrap.NewFile):
assert props.active_organisation_id == 0
class TestExportOrganisationAttributes(test.bim.bootstrap.NewFile):
class TestExportOrganisationAttributes(NewFile):
def test_run(self):
TestImportOrganisationAttributes().test_run()
assert subject().export_organisation_attributes() == {
@@ -287,7 +287,7 @@ class TestExportOrganisationAttributes(test.bim.bootstrap.NewFile):
}
class TestGetOrganisation(test.bim.bootstrap.NewFile):
class TestGetOrganisation(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
@@ -296,14 +296,14 @@ class TestGetOrganisation(test.bim.bootstrap.NewFile):
assert subject().get_organisation() == organisation
class TestSetPerson(test.bim.bootstrap.NewFile):
class TestSetPerson(NewFile):
def test_run(self):
person = ifcopenshell.file().createIfcPerson()
subject().set_person(person)
assert bpy.context.scene.BIMOwnerProperties.active_person_id == person.id()
class TestImportPersonAttributes(test.bim.bootstrap.NewFile):
class TestImportPersonAttributes(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
@@ -346,7 +346,7 @@ class TestImportPersonAttributes(test.bim.bootstrap.NewFile):
assert props.person_attributes.get("GivenName").string_value == ""
class TestClearPerson(test.bim.bootstrap.NewFile):
class TestClearPerson(NewFile):
def test_run(self):
props = bpy.context.scene.BIMOwnerProperties
props.active_person_id = 1
@@ -354,7 +354,7 @@ class TestClearPerson(test.bim.bootstrap.NewFile):
assert props.active_person_id == 0
class TestExportPersonAttributes(test.bim.bootstrap.NewFile):
class TestExportPersonAttributes(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
@@ -385,7 +385,7 @@ class TestExportPersonAttributes(test.bim.bootstrap.NewFile):
assert result["SuffixTitles"] is None
class TestGetPerson(test.bim.bootstrap.NewFile):
class TestGetPerson(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
@@ -394,7 +394,7 @@ class TestGetPerson(test.bim.bootstrap.NewFile):
assert subject().get_person() == person
class TestAddPersonAttribute(test.bim.bootstrap.NewFile):
class TestAddPersonAttribute(NewFile):
def test_run(self):
subject().add_person_attribute("MiddleNames")
subject().add_person_attribute("PrefixTitles")
@@ -405,7 +405,7 @@ class TestAddPersonAttribute(test.bim.bootstrap.NewFile):
assert len(props.suffix_titles) == 1
class TestRemovePersonAttribute(test.bim.bootstrap.NewFile):
class TestRemovePersonAttribute(NewFile):
def test_run(self):
subject().add_person_attribute("MiddleNames")
subject().remove_person_attribute("MiddleNames", 0)
@@ -419,14 +419,14 @@ class TestRemovePersonAttribute(test.bim.bootstrap.NewFile):
assert len(props.suffix_titles) == 0
class TestSetRole(test.bim.bootstrap.NewFile):
class TestSetRole(NewFile):
def test_run(self):
role = ifcopenshell.file().createIfcActorRole()
subject().set_role(role)
assert bpy.context.scene.BIMOwnerProperties.active_role_id == role.id()
class TestImportRoleAttributes(test.bim.bootstrap.NewFile):
class TestImportRoleAttributes(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
@@ -454,7 +454,7 @@ class TestImportRoleAttributes(test.bim.bootstrap.NewFile):
assert props.role_attributes.get("Role").enum_value == "ARCHITECT"
class TestClearRole(test.bim.bootstrap.NewFile):
class TestClearRole(NewFile):
def test_run(self):
role = ifcopenshell.file().createIfcActorRole()
subject().set_role(role)
@@ -462,7 +462,7 @@ class TestClearRole(test.bim.bootstrap.NewFile):
assert bpy.context.scene.BIMOwnerProperties.active_role_id == 0
class TestGetRole(test.bim.bootstrap.NewFile):
class TestGetRole(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
@@ -471,7 +471,7 @@ class TestGetRole(test.bim.bootstrap.NewFile):
assert subject().get_role() == role
class TestExportRoleAttributes(test.bim.bootstrap.NewFile):
class TestExportRoleAttributes(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)