mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Add "remove brick relation" operator
This commit is contained in:
@@ -36,6 +36,7 @@ classes = (
|
||||
operator.SerializeBrick,
|
||||
operator.AddBrickNamespace,
|
||||
operator.SetBrickListRoot,
|
||||
operator.RemoveBrickRelation,
|
||||
prop.Brick,
|
||||
prop.BIMBrickProperties,
|
||||
ui.BIM_PT_brickschema,
|
||||
|
||||
@@ -80,28 +80,32 @@ class BrickschemaData:
|
||||
)
|
||||
)
|
||||
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_name = object.toPython().split("#")[-1]
|
||||
results.append(
|
||||
{
|
||||
"predicate": predicate,
|
||||
"object": object.toPython().split("#")[-1],
|
||||
"predicate_name": predicate_name,
|
||||
"object": object,
|
||||
"object_name": object_name,
|
||||
"is_uri": isinstance(object, URIRef),
|
||||
"object_uri": object.toPython(),
|
||||
"is_globalid": predicate == "globalID",
|
||||
}
|
||||
)
|
||||
if isinstance(row.get("object"), BNode):
|
||||
for s, p, o in BrickStore.graph.triples((object, None, None)):
|
||||
results.append(
|
||||
{
|
||||
"predicate": predicate + ":" + p.toPython().split("#")[-1],
|
||||
"object": o.toPython().split("#")[-1],
|
||||
"is_uri": isinstance(o, URIRef),
|
||||
"object_uri": o.toPython(),
|
||||
"is_globalid": p.toPython().split("#")[-1] == "globalID",
|
||||
}
|
||||
)
|
||||
# if isinstance(row.get("object"), BNode):
|
||||
# for s, p, o in BrickStore.graph.triples((object, None, None)):
|
||||
# results.append(
|
||||
# {
|
||||
# "predicate": predicate + ":" + p.toPython().split("#")[-1],
|
||||
# "object": o.toPython().split("#")[-1],
|
||||
# "is_uri": isinstance(o, URIRef),
|
||||
# "object_uri": o.toPython(),
|
||||
# "is_globalid": p.toPython().split("#")[-1] == "globalID",
|
||||
# }
|
||||
# )
|
||||
return results
|
||||
|
||||
|
||||
|
||||
@@ -263,4 +263,17 @@ class SetBrickListRoot(bpy.types.Operator, Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
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_uri: StringProperty(name="New Brick Namespace URI")
|
||||
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")
|
||||
|
||||
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"]:
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text=relation["predicate"])
|
||||
row.label(text=relation["object"])
|
||||
if relation["is_uri"]:
|
||||
row.label(text=relation["predicate_name"])
|
||||
row.label(text=relation["object_name"])
|
||||
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.item = relation["object_uri"]
|
||||
if relation["is_globalid"]:
|
||||
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):
|
||||
|
||||
@@ -126,3 +126,7 @@ def set_brick_list_root(brick, brick_root=None):
|
||||
brick.set_active_brick_class(brick_root)
|
||||
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()
|
||||
@@ -104,6 +104,13 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
ns_brick = Namespace("https://brickschema.org/schema/Brick#")
|
||||
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
|
||||
def clear_brick_browser(cls):
|
||||
bpy.context.scene.BIMBrickProperties.bricks.clear()
|
||||
|
||||
Reference in New Issue
Block a user