From a884eb5c5499dbc65d9bc181f9859024e4198b2e Mon Sep 17 00:00:00 2001 From: rileywong311 Date: Mon, 31 Jul 2023 16:31:55 -0700 Subject: [PATCH] Add "rdfs:label" to Brick relation options This is a tricky one because "rdfs:label" cannot really be queried from the Brick ontology, so it is a special case that probably needs to get added manually. Furthermore, an entity really shouldn't have multiple labels, so the option to give an entity an "rdfs:label" should only appear if it doesn't have one already. The way I did it meant I had to manually reset the Enum type in Blender because it was the active one selection and made the Enum blank since it got removed now that the entity has a "rdfs:label." One possible alternative solution is to allow multiple labels, but in the query to import bricks in the UI list only select one label somehow. --- src/blenderbim/blenderbim/bim/module/brick/prop.py | 8 +++++++- src/blenderbim/blenderbim/bim/module/brick/ui.py | 5 +++-- src/blenderbim/blenderbim/tool/brick.py | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/brick/prop.py b/src/blenderbim/blenderbim/bim/module/brick/prop.py index 721f43207a..42cd0e2ce2 100644 --- a/src/blenderbim/blenderbim/bim/module/brick/prop.py +++ b/src/blenderbim/blenderbim/bim/module/brick/prop.py @@ -55,7 +55,13 @@ def get_brick_roots(self, context): return [(root, root, "") for root in BrickStore.root_classes] -def get_brick_relations(self, context): # this will be queried from graph +def get_brick_relations(self, context): + def is_label(relation): + return relation["predicate_name"] == "label" + if not list(filter(is_label, BrickschemaData.data["active_relations"])): + new_relations = BrickStore.relationships.copy() + new_relations.append(("http://www.w3.org/2000/01/rdf-schema#label", "label", "")) + return new_relations return BrickStore.relationships diff --git a/src/blenderbim/blenderbim/bim/module/brick/ui.py b/src/blenderbim/blenderbim/bim/module/brick/ui.py index cb1db25a91..146a23d307 100644 --- a/src/blenderbim/blenderbim/bim/module/brick/ui.py +++ b/src/blenderbim/blenderbim/bim/module/brick/ui.py @@ -122,8 +122,9 @@ class BIM_PT_brickschema(Panel): col.alignment = "RIGHT" row.prop(data=self.props, property="split_screen_toggled", text="", icon="WINDOW") - row = self.layout.row(align=True) - prop_with_search(row, self.props, "new_brick_relation_namespace", text="") + if not self.props.new_brick_relation_type == "http://www.w3.org/2000/01/rdf-schema#label": + row = self.layout.row(align=True) + prop_with_search(row, self.props, "new_brick_relation_namespace", text="") row = self.layout.row(align=True) prop_with_search(row, self.props, "new_brick_relation_type", text="") diff --git a/src/blenderbim/blenderbim/tool/brick.py b/src/blenderbim/blenderbim/tool/brick.py index 9cb356da96..e66394b526 100644 --- a/src/blenderbim/blenderbim/tool/brick.py +++ b/src/blenderbim/blenderbim/tool/brick.py @@ -101,6 +101,12 @@ class Brick(blenderbim.core.tool.Brick): @classmethod def add_relation(cls, brick_uri, predicate, namespace, object): + if predicate == "http://www.w3.org/2000/01/rdf-schema#label": + with BrickStore.new_changeset() as cs: + cs.add((URIRef(brick_uri), URIRef(predicate), Literal(object))) + bpy.context.scene.BIMBrickProperties.new_brick_relation_type = BrickStore.relationships[0][0] + bpy.context.scene.BIMBrickProperties.add_relation_failed = False + return object_uri = namespace + object query = BrickStore.graph.query( "ASK { <{object_uri}> ?predicate ?object . }".replace(