Skip to content

Commit 0161572

Browse files
committed
Add "remove brick relation" operator
1 parent 97685a7 commit 0161572

File tree

7 files changed

+61
-19
lines changed

7 files changed

+61
-19
lines changed

src/blenderbim/blenderbim/bim/module/brick/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
operator.SerializeBrick,
3737
operator.AddBrickNamespace,
3838
operator.SetBrickListRoot,
39+
operator.RemoveBrickRelation,
3940
prop.Brick,
4041
prop.BIMBrickProperties,
4142
ui.BIM_PT_brickschema,

src/blenderbim/blenderbim/bim/module/brick/data.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,32 @@ def relations(cls):
8080
)
8181
)
8282
for row in query:
83-
predicate = row.get("predicate").toPython().split("#")[-1]
83+
predicate = row.get("predicate")
84+
predicate_name = predicate.toPython().split("#")[-1]
8485
object = row.get("object")
86+
object_name = object.toPython().split("#")[-1]
8587
results.append(
8688
{
8789
"predicate": predicate,
88-
"object": object.toPython().split("#")[-1],
90+
"predicate_name": predicate_name,
91+
"object": object,
92+
"object_name": object_name,
8993
"is_uri": isinstance(object, URIRef),
9094
"object_uri": object.toPython(),
9195
"is_globalid": predicate == "globalID",
9296
}
9397
)
94-
if isinstance(row.get("object"), BNode):
95-
for s, p, o in BrickStore.graph.triples((object, None, None)):
96-
results.append(
97-
{
98-
"predicate": predicate + ":" + p.toPython().split("#")[-1],
99-
"object": o.toPython().split("#")[-1],
100-
"is_uri": isinstance(o, URIRef),
101-
"object_uri": o.toPython(),
102-
"is_globalid": p.toPython().split("#")[-1] == "globalID",
103-
}
104-
)
98+
# if isinstance(row.get("object"), BNode):
99+
# for s, p, o in BrickStore.graph.triples((object, None, None)):
100+
# results.append(
101+
# {
102+
# "predicate": predicate + ":" + p.toPython().split("#")[-1],
103+
# "object": o.toPython().split("#")[-1],
104+
# "is_uri": isinstance(o, URIRef),
105+
# "object_uri": o.toPython(),
106+
# "is_globalid": p.toPython().split("#")[-1] == "globalID",
107+
# }
108+
# )
105109
return results
106110

107111

src/blenderbim/blenderbim/bim/module/brick/operator.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,17 @@ class SetBrickListRoot(bpy.types.Operator, Operator):
263263

264264
def _execute(self, context):
265265
root = context.scene.BIMBrickProperties.brick_list_root
266-
core.set_brick_list_root(tool.Brick, brick_root=root)
266+
core.set_brick_list_root(tool.Brick, brick_root=root)
267+
268+
269+
class RemoveBrickRelation(bpy.types.Operator, Operator):
270+
bl_idname = "bim.remove_brick_relation"
271+
bl_label = "Remove Relation"
272+
bl_options = {"REGISTER", "UNDO"}
273+
predicate: bpy.props.StringProperty(name="Relation")
274+
object: bpy.props.StringProperty(name="Object")
275+
276+
def _execute(self, context):
277+
props = context.scene.BIMBrickProperties
278+
brick = props.bricks[props.active_brick_index]
279+
core.remove_brick_relation(tool.Brick, brick_uri=brick.uri, predicate=self.predicate, object=self.object)

src/blenderbim/blenderbim/bim/module/brick/prop.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ class BIMBrickProperties(PropertyGroup):
7575
new_brick_namespace_alias: StringProperty(name="New Brick Namespace Alias")
7676
new_brick_namespace_uri: StringProperty(name="New Brick Namespace URI")
7777
brick_list_root: EnumProperty(name="Brick List Root", items=get_brick_roots)
78-
brick_entity_create_type: EnumProperty(name="Brick Entity Types", items=get_brick_roots)
78+
brick_entity_create_type: EnumProperty(name="Brick Entity Types", items=get_brick_roots)
79+
brick_create_relations_toggled: BoolProperty(name="Brick Create Relations Toggled", default=False)
80+
brick_edit_relations_toggled: BoolProperty(name="Brick Edit Relations Toggled", default=False)

src/blenderbim/blenderbim/bim/module/brick/ui.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,27 @@ def draw(self, context):
107107

108108
self.layout.template_list("BIM_UL_bricks", "", self.props, "bricks", self.props, "active_brick_index")
109109

110+
if BrickschemaData.data["relations"]:
111+
row = self.layout.row(align=True)
112+
col = row.column()
113+
col.alignment = "RIGHT"
114+
row.prop(data=self.props, property="brick_create_relations_toggled", text="", icon="OUTLINER_DATA_GP_LAYER")
115+
row.prop(data=self.props, property="brick_edit_relations_toggled", text="", icon="TOOL_SETTINGS")
116+
110117
for relation in BrickschemaData.data["relations"]:
111118
row = self.layout.row(align=True)
112-
row.label(text=relation["predicate"])
113-
row.label(text=relation["object"])
114-
if relation["is_uri"]:
119+
row.label(text=relation["predicate_name"])
120+
row.label(text=relation["object_name"])
121+
if self.props.brick_edit_relations_toggled and relation["predicate_name"] != "type":
122+
op = row.operator("bim.remove_brick_relation", text="", icon="UNLINKED")
123+
op.predicate = relation["predicate"]
124+
op.object = relation["object"]
125+
if relation["is_uri"] and relation["predicate_name"] != "type":
115126
op = row.operator("bim.view_brick_item", text="", icon="DISCLOSURE_TRI_RIGHT")
116127
op.item = relation["object_uri"]
117128
if relation["is_globalid"]:
118129
op = row.operator("bim.select_global_id", icon="RESTRICT_SELECT_OFF", text="")
119-
op.global_id = relation["object"]
130+
op.global_id = relation["object_name"]
120131

121132

122133
class BIM_PT_ifc_brickschema_references(Panel):

src/blenderbim/blenderbim/core/brick.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,7 @@ def set_brick_list_root(brick, brick_root=None):
126126
brick.set_active_brick_class(brick_root)
127127
brick.clear_breadcrumbs()
128128

129+
130+
def remove_brick_relation(brick, brick_uri=None, predicate=None, object=None):
131+
brick.remove_relation(brick_uri, predicate, object)
132+
brick.run_refresh_brick_viewer()

src/blenderbim/blenderbim/tool/brick.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ def add_feed(cls, source, destination):
104104
ns_brick = Namespace("https://brickschema.org/schema/Brick#")
105105
BrickStore.graph.add((URIRef(source), ns_brick["feeds"], URIRef(destination)))
106106

107+
@classmethod
108+
def remove_relation(cls, brick_uri, predicate, object):
109+
if BrickStore.graph.triples((brick_uri, predicate, object)):
110+
with BrickStore.new_changeset() as cs:
111+
for triple in BrickStore.graph.triples((brick_uri, predicate, object)):
112+
cs.remove(triple)
113+
107114
@classmethod
108115
def clear_brick_browser(cls):
109116
bpy.context.scene.BIMBrickProperties.bricks.clear()

0 commit comments

Comments
 (0)