Refactor AddBrickRelation to combine object namespace+label in operator

This is an important change that should make adding relations through other methods easier to implement
This commit is contained in:
rileywong311
2023-08-01 22:10:17 -07:00
committed by Riley Wong
parent 589b3928f3
commit 7bfa6115ee
3 changed files with 11 additions and 9 deletions
@@ -144,12 +144,15 @@ class AddBrickRelation(bpy.types.Operator, Operator):
def _execute(self, context):
props = context.scene.BIMBrickProperties
brick = props.bricks[props.active_brick_index]
if props.new_brick_relation_type == "http://www.w3.org/2000/01/rdf-schema#label":
object = props.new_brick_relation_object
else:
object = props.new_brick_relation_namespace + props.new_brick_relation_object
core.add_brick_relation(
tool.Brick,
brick_uri=brick.uri,
predicate=props.new_brick_relation_type,
namespace=props.new_brick_relation_namespace,
object=props.new_brick_relation_object
object=object
)
+2 -2
View File
@@ -78,8 +78,8 @@ def add_brick(ifc, brick, element=None, namespace=None, brick_class=None, librar
brick.run_refresh_brick_viewer()
def add_brick_relation(brick, brick_uri=None, predicate=None, namespace=None, object=None):
brick.add_relation(brick_uri, predicate, namespace, object)
def add_brick_relation(brick, brick_uri=None, predicate=None, object=None):
brick.add_relation(brick_uri, predicate, object)
brick.run_refresh_brick_viewer()
+4 -5
View File
@@ -100,22 +100,21 @@ class Brick(blenderbim.core.tool.Brick):
)
@classmethod
def add_relation(cls, brick_uri, predicate, namespace, object):
def add_relation(cls, brick_uri, predicate, 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(
"{object_uri}", object_uri
"ASK { <{object_uri}> a ?o . }".replace(
"{object_uri}", object
)
)
if query:
with BrickStore.new_changeset() as cs:
cs.add((URIRef(brick_uri), URIRef(predicate), URIRef(object_uri)))
cs.add((URIRef(brick_uri), URIRef(predicate), URIRef(object)))
bpy.context.scene.BIMBrickProperties.add_relation_failed = False
else:
bpy.context.scene.BIMBrickProperties.add_relation_failed = True