Add "remove brick relation" operator

This commit is contained in:
rileywong311
2023-07-26 16:11:05 -07:00
parent b5d9c3f5ff
commit 07bd99d461
7 changed files with 61 additions and 19 deletions
@@ -36,6 +36,7 @@ classes = (
operator.SerializeBrick, operator.SerializeBrick,
operator.AddBrickNamespace, operator.AddBrickNamespace,
operator.SetBrickListRoot, operator.SetBrickListRoot,
operator.RemoveBrickRelation,
prop.Brick, prop.Brick,
prop.BIMBrickProperties, prop.BIMBrickProperties,
ui.BIM_PT_brickschema, ui.BIM_PT_brickschema,
@@ -80,28 +80,32 @@ class BrickschemaData:
) )
) )
for row in query: for row in query:
predicate = row.get("predicate").toPython().split("#")[-1] predicate = row.get("predicate")
predicate_name = predicate.toPython().split("#")[-1]
object = row.get("object") object = row.get("object")
object_name = object.toPython().split("#")[-1]
results.append( results.append(
{ {
"predicate": predicate, "predicate": predicate,
"object": object.toPython().split("#")[-1], "predicate_name": predicate_name,
"object": object,
"object_name": object_name,
"is_uri": isinstance(object, URIRef), "is_uri": isinstance(object, URIRef),
"object_uri": object.toPython(), "object_uri": object.toPython(),
"is_globalid": predicate == "globalID", "is_globalid": predicate == "globalID",
} }
) )
if isinstance(row.get("object"), BNode): # if isinstance(row.get("object"), BNode):
for s, p, o in BrickStore.graph.triples((object, None, None)): # for s, p, o in BrickStore.graph.triples((object, None, None)):
results.append( # results.append(
{ # {
"predicate": predicate + ":" + p.toPython().split("#")[-1], # "predicate": predicate + ":" + p.toPython().split("#")[-1],
"object": o.toPython().split("#")[-1], # "object": o.toPython().split("#")[-1],
"is_uri": isinstance(o, URIRef), # "is_uri": isinstance(o, URIRef),
"object_uri": o.toPython(), # "object_uri": o.toPython(),
"is_globalid": p.toPython().split("#")[-1] == "globalID", # "is_globalid": p.toPython().split("#")[-1] == "globalID",
} # }
) # )
return results return results
@@ -263,4 +263,17 @@ class SetBrickListRoot(bpy.types.Operator, Operator):
def _execute(self, context): def _execute(self, context):
root = context.scene.BIMBrickProperties.brick_list_root root = context.scene.BIMBrickProperties.brick_list_root
core.set_brick_list_root(tool.Brick, brick_root=root) core.set_brick_list_root(tool.Brick, brick_root=root)
class RemoveBrickRelation(bpy.types.Operator, Operator):
bl_idname = "bim.remove_brick_relation"
bl_label = "Remove Relation"
bl_options = {"REGISTER", "UNDO"}
predicate: bpy.props.StringProperty(name="Relation")
object: bpy.props.StringProperty(name="Object")
def _execute(self, context):
props = context.scene.BIMBrickProperties
brick = props.bricks[props.active_brick_index]
core.remove_brick_relation(tool.Brick, brick_uri=brick.uri, predicate=self.predicate, object=self.object)
@@ -75,4 +75,6 @@ class BIMBrickProperties(PropertyGroup):
new_brick_namespace_alias: StringProperty(name="New Brick Namespace Alias") new_brick_namespace_alias: StringProperty(name="New Brick Namespace Alias")
new_brick_namespace_uri: StringProperty(name="New Brick Namespace URI") new_brick_namespace_uri: StringProperty(name="New Brick Namespace URI")
brick_list_root: EnumProperty(name="Brick List Root", items=get_brick_roots) brick_list_root: EnumProperty(name="Brick List Root", items=get_brick_roots)
brick_entity_create_type: EnumProperty(name="Brick Entity Types", items=get_brick_roots) brick_entity_create_type: EnumProperty(name="Brick Entity Types", items=get_brick_roots)
brick_create_relations_toggled: BoolProperty(name="Brick Create Relations Toggled", default=False)
brick_edit_relations_toggled: BoolProperty(name="Brick Edit Relations Toggled", default=False)
@@ -107,16 +107,27 @@ class BIM_PT_brickschema(Panel):
self.layout.template_list("BIM_UL_bricks", "", self.props, "bricks", self.props, "active_brick_index") self.layout.template_list("BIM_UL_bricks", "", self.props, "bricks", self.props, "active_brick_index")
if BrickschemaData.data["relations"]:
row = self.layout.row(align=True)
col = row.column()
col.alignment = "RIGHT"
row.prop(data=self.props, property="brick_create_relations_toggled", text="", icon="OUTLINER_DATA_GP_LAYER")
row.prop(data=self.props, property="brick_edit_relations_toggled", text="", icon="TOOL_SETTINGS")
for relation in BrickschemaData.data["relations"]: for relation in BrickschemaData.data["relations"]:
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text=relation["predicate"]) row.label(text=relation["predicate_name"])
row.label(text=relation["object"]) row.label(text=relation["object_name"])
if relation["is_uri"]: if self.props.brick_edit_relations_toggled and relation["predicate_name"] != "type":
op = row.operator("bim.remove_brick_relation", text="", icon="UNLINKED")
op.predicate = relation["predicate"]
op.object = relation["object"]
if relation["is_uri"] and relation["predicate_name"] != "type":
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"]
if relation["is_globalid"]: if relation["is_globalid"]:
op = row.operator("bim.select_global_id", icon="RESTRICT_SELECT_OFF", text="") op = row.operator("bim.select_global_id", icon="RESTRICT_SELECT_OFF", text="")
op.global_id = relation["object"] op.global_id = relation["object_name"]
class BIM_PT_ifc_brickschema_references(Panel): class BIM_PT_ifc_brickschema_references(Panel):
+4
View File
@@ -126,3 +126,7 @@ def set_brick_list_root(brick, brick_root=None):
brick.set_active_brick_class(brick_root) brick.set_active_brick_class(brick_root)
brick.clear_breadcrumbs() brick.clear_breadcrumbs()
def remove_brick_relation(brick, brick_uri=None, predicate=None, object=None):
brick.remove_relation(brick_uri, predicate, object)
brick.run_refresh_brick_viewer()
+7
View File
@@ -104,6 +104,13 @@ class Brick(blenderbim.core.tool.Brick):
ns_brick = Namespace("https://brickschema.org/schema/Brick#") ns_brick = Namespace("https://brickschema.org/schema/Brick#")
BrickStore.graph.add((URIRef(source), ns_brick["feeds"], URIRef(destination))) BrickStore.graph.add((URIRef(source), ns_brick["feeds"], URIRef(destination)))
@classmethod
def remove_relation(cls, brick_uri, predicate, object):
if BrickStore.graph.triples((brick_uri, predicate, object)):
with BrickStore.new_changeset() as cs:
for triple in BrickStore.graph.triples((brick_uri, predicate, object)):
cs.remove(triple)
@classmethod @classmethod
def clear_brick_browser(cls): def clear_brick_browser(cls):
bpy.context.scene.BIMBrickProperties.bricks.clear() bpy.context.scene.BIMBrickProperties.bricks.clear()