mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 13:46:54 +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):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMBrickProperties
|
props = context.scene.BIMBrickProperties
|
||||||
brick = props.bricks[props.active_brick_index]
|
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(
|
core.add_brick_relation(
|
||||||
tool.Brick,
|
tool.Brick,
|
||||||
brick_uri=brick.uri,
|
brick_uri=brick.uri,
|
||||||
predicate=props.new_brick_relation_type,
|
predicate=props.new_brick_relation_type,
|
||||||
namespace=props.new_brick_relation_namespace,
|
object=object
|
||||||
object=props.new_brick_relation_object
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ def add_brick(ifc, brick, element=None, namespace=None, brick_class=None, librar
|
|||||||
brick.run_refresh_brick_viewer()
|
brick.run_refresh_brick_viewer()
|
||||||
|
|
||||||
|
|
||||||
def add_brick_relation(brick, brick_uri=None, predicate=None, namespace=None, object=None):
|
def add_brick_relation(brick, brick_uri=None, predicate=None, object=None):
|
||||||
brick.add_relation(brick_uri, predicate, namespace, object)
|
brick.add_relation(brick_uri, predicate, object)
|
||||||
brick.run_refresh_brick_viewer()
|
brick.run_refresh_brick_viewer()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -100,22 +100,21 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@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":
|
if predicate == "http://www.w3.org/2000/01/rdf-schema#label":
|
||||||
with BrickStore.new_changeset() as cs:
|
with BrickStore.new_changeset() as cs:
|
||||||
cs.add((URIRef(brick_uri), URIRef(predicate), Literal(object)))
|
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.new_brick_relation_type = BrickStore.relationships[0][0]
|
||||||
bpy.context.scene.BIMBrickProperties.add_relation_failed = False
|
bpy.context.scene.BIMBrickProperties.add_relation_failed = False
|
||||||
return
|
return
|
||||||
object_uri = namespace + object
|
|
||||||
query = BrickStore.graph.query(
|
query = BrickStore.graph.query(
|
||||||
"ASK { <{object_uri}> ?predicate ?object . }".replace(
|
"ASK { <{object_uri}> a ?o . }".replace(
|
||||||
"{object_uri}", object_uri
|
"{object_uri}", object
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if query:
|
if query:
|
||||||
with BrickStore.new_changeset() as cs:
|
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
|
bpy.context.scene.BIMBrickProperties.add_relation_failed = False
|
||||||
else:
|
else:
|
||||||
bpy.context.scene.BIMBrickProperties.add_relation_failed = True
|
bpy.context.scene.BIMBrickProperties.add_relation_failed = True
|
||||||
|
|||||||
Reference in New Issue
Block a user