Support displaying Brick Bnode relations

- Important for Ifc External References and other data.
- Set predicate_uri of predicates of the Bnode to None, which is used to remove the ability to delete the relationship in the UI.
- Also added try/excepts to difficult edge cases such as the object_uri not having a "#" character in it (such as "<http://qudt.org/vocab/unit/>") and the object_uri not being a brick class, which breaks "view_brick_item".
- Removing a Bnode type from the entity's relation removes all relations of the Bnode also
This commit is contained in:
rileywong311
2023-08-17 15:55:54 -07:00
committed by Riley Wong
parent 04eb47ff65
commit c022a12835
4 changed files with 52 additions and 28 deletions
@@ -75,37 +75,52 @@ class BrickschemaData:
{ ?predicate a brick:EntityProperty . } { ?predicate a brick:EntityProperty . }
?object ?sp ?sv } ?object ?sp ?sv }
} }
GROUP BY ?object
""".replace( """.replace(
"{uri}", uri "{uri}", uri
) )
) )
for row in query: for row in query:
predicate = row.get("predicate") predicate_uri = row.get("predicate")
predicate_name = predicate.toPython().split("#")[-1] predicate_name = predicate_uri.toPython().split("#")[-1]
object = row.get("object") object_uri = row.get("object")
object_name = object.toPython().split("#")[-1] print("DEBUG: object is ", object_uri)
if isinstance(object_uri, BNode):
object_name = "[]"
else:
try:
object_name = object_uri.toPython().split("#")[-1]
except:
object_name = str(object_uri)
results.append( results.append(
{ {
"predicate": predicate, "predicate_uri": predicate_uri,
"predicate_name": predicate_name, "predicate_name": predicate_name,
"object": object, "object_uri": object_uri,
"object_name": object_name, "object_name": object_name,
"is_uri": isinstance(object, URIRef), "is_uri": isinstance(object_uri, URIRef),
"object_uri": object.toPython(), "is_globalid": predicate_uri == "globalID",
"is_globalid": predicate == "globalID",
} }
) )
# if isinstance(row.get("object"), BNode): if isinstance(object_uri, BNode):
# for s, p, o in BrickStore.graph.triples((object, None, None)): for subject2, predicate2, object2 in BrickStore.graph.triples((object_uri, None, None)):
# results.append( predicate2_name = predicate2.toPython().split("#")[-1]
# { try:
# "predicate": predicate + ":" + p.toPython().split("#")[-1], object2_name = object2.toPython().split("#")[-1]
# "object": o.toPython().split("#")[-1], except:
# "is_uri": isinstance(o, URIRef), object2_name = str(object2)
# "object_uri": o.toPython(), print("DEBUG: ", predicate_name, ":", predicate2_name)
# "is_globalid": p.toPython().split("#")[-1] == "globalID", results.append(
# } {
# ) "predicate_uri": None,
"predicate_name": predicate_name + ":" + predicate2_name,
"object_uri": object2,
"object_name": object2_name,
"is_uri": isinstance(object2, URIRef),
"is_globalid": predicate2_name == "globalID",
}
)
print("")
return results return results
@@ -74,7 +74,10 @@ class ViewBrickItem(bpy.types.Operator, Operator):
split_screen: bpy.props.BoolProperty(name="Split Screen", default=False, options={"HIDDEN"}) split_screen: bpy.props.BoolProperty(name="Split Screen", default=False, options={"HIDDEN"})
def _execute(self, context): def _execute(self, context):
core.view_brick_item(tool.Brick, item=self.item, split_screen=self.split_screen) try:
core.view_brick_item(tool.Brick, item=self.item, split_screen=self.split_screen)
except:
self.report({'ERROR'}, f'Could not find {self.item}')
class RewindBrickClass(bpy.types.Operator, Operator): class RewindBrickClass(bpy.types.Operator, Operator):
@@ -184,10 +184,10 @@ class BIM_PT_brickschema(Panel):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text=relation["predicate_name"]) row.label(text=relation["predicate_name"])
row.label(text=relation["object_name"]) row.label(text=relation["object_name"])
if self.props.brick_edit_relations_toggled and relation["predicate_name"] != "type": if self.props.brick_edit_relations_toggled and relation["predicate_uri"] and relation["predicate_name"] != "type":
op = row.operator("bim.remove_brick_relation", text="", icon="UNLINKED") op = row.operator("bim.remove_brick_relation", text="", icon="UNLINKED")
op.predicate = relation["predicate"] op.predicate = relation["predicate_uri"]
op.object = relation["object"] op.object = relation["object_uri"]
if relation["is_uri"] and relation["object_name"] != self.props.active_brick_class: if relation["is_uri"] and relation["object_name"] != self.props.active_brick_class:
op = row.operator("bim.view_brick_item", text="", icon="DISCLOSURE_TRI_RIGHT") op = row.operator("bim.view_brick_item", text="", icon="DISCLOSURE_TRI_RIGHT")
op.item = relation["object_uri"] op.item = relation["object_uri"]
+10 -4
View File
@@ -123,8 +123,11 @@ class Brick(blenderbim.core.tool.Brick):
@classmethod @classmethod
def remove_relation(cls, brick_uri, predicate, object): def remove_relation(cls, brick_uri, predicate, object):
with BrickStore.new_changeset() as cs: with BrickStore.new_changeset() as cs:
for triple in BrickStore.graph.triples((brick_uri, predicate, object)): for s, p, o in BrickStore.graph.triples((brick_uri, predicate, object)):
cs.remove(triple) cs.remove((s, p, o))
if isinstance(o, BNode):
for triple in BrickStore.graph.triples((object, None, None)):
cs.remove(triple)
@classmethod @classmethod
def clear_brick_browser(cls, split_screen=False): def clear_brick_browser(cls, split_screen=False):
@@ -340,8 +343,11 @@ class Brick(blenderbim.core.tool.Brick):
@classmethod @classmethod
def remove_brick(cls, brick_uri): def remove_brick(cls, brick_uri):
with BrickStore.new_changeset() as cs: with BrickStore.new_changeset() as cs:
for triple in BrickStore.graph.triples((URIRef(brick_uri), None, None)): for s, p, o in BrickStore.graph.triples((URIRef(brick_uri), None, None)):
cs.remove(triple) cs.remove((s, p, o))
if isinstance(o, BNode):
for triple in BrickStore.graph.triples((o, None, None)):
cs.remove(triple)
@classmethod @classmethod
def run_assign_brick_reference(cls, element=None, library=None, brick_uri=None): def run_assign_brick_reference(cls, element=None, library=None, brick_uri=None):