mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
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:
@@ -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
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user