Implement basic Brick create relation

This commit is contained in:
rileywong311
2023-07-28 17:07:04 -07:00
committed by Riley Wong
parent 01615724fd
commit deecd60ff1
6 changed files with 66 additions and 18 deletions
@@ -21,7 +21,7 @@ from . import ui, prop, operator
classes = (
operator.AddBrick,
operator.AddBrickFeed,
operator.AddBrickRelation,
operator.AssignBrickReference,
operator.CloseBrickProject,
operator.ConvertBrickProject,
@@ -132,19 +132,20 @@ class AddBrick(bpy.types.Operator, Operator):
)
class AddBrickFeed(bpy.types.Operator, Operator):
bl_idname = "bim.add_brick_feed"
bl_label = "Add Brick Feed"
class AddBrickRelation(bpy.types.Operator, Operator):
bl_idname = "bim.add_brick_relation"
bl_label = "Add Brick Relation"
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
source = tool.Ifc.get_entity([o for o in context.selected_objects if o != context.active_object][0])
destination = tool.Ifc.get_entity(context.active_object)
core.add_brick_feed(
tool.Ifc,
props = context.scene.BIMBrickProperties
brick = props.bricks[props.active_brick_index]
core.add_brick_relation(
tool.Brick,
source=source,
destination=destination,
brick_uri=brick.uri,
predicate=props.new_brick_relation_type,
namespace=props.new_brick_relation_namespace,
object=props.new_brick_relation_object
)
@@ -55,6 +55,18 @@ def get_brick_roots(self, context):
return [(root, root, "") for root in BrickStore.root_classes]
def get_brick_relations(self, context): # this will be queried from graph
return [("https://brickschema.org/schema/Brick#hasLocation", "hasLocation", ""),
("https://brickschema.org/schema/Brick#isLocationOf", "isLocationOf", ""),
("https://brickschema.org/schema/Brick#hasPart", "hasPart", ""),
("https://brickschema.org/schema/Brick#isPartOf", "isPartOf", ""),
("https://brickschema.org/schema/Brick#hasPoint", "hasPoint", ""),
("https://brickschema.org/schema/Brick#isPointOf", "isPointOf", ""),
("https://brickschema.org/schema/Brick#feeds", "feeds", ""),
("https://brickschema.org/schema/Brick#isFedBy", "isFedBy", ""),
("http://www.w3.org/2000/01/rdf-schema#label", "label", "")]
class Brick(PropertyGroup):
name: StringProperty(name="Name")
label: StringProperty(name="Label")
@@ -77,4 +89,9 @@ class BIMBrickProperties(PropertyGroup):
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_create_relations_toggled: BoolProperty(name="Brick Create Relations Toggled", default=False)
brick_edit_relations_toggled: BoolProperty(name="Brick Edit Relations Toggled", default=False)
brick_edit_relations_toggled: BoolProperty(name="Brick Edit Relations Toggled", default=False)
new_brick_relation_type: EnumProperty(name="New Brick Relation Type", items=get_brick_relations)
new_brick_relation_namespace: EnumProperty(name="New Brick Relation Namespace", items=get_namespaces)
new_brick_relation_object: StringProperty(name="New Brick Relation Object")
add_relation_failed: BoolProperty(name="Add Relation Failed", default=False)
split_screen_toggled: BoolProperty(name="Split Screen Toggled", default=False)
@@ -98,7 +98,6 @@ class BIM_PT_brickschema(Panel):
row.operator("bim.rewind_brick_class", text="", icon="FRAME_PREV")
col = row.column()
col.alignment = "RIGHT"
# row.operator("bim.add_brick_feed", text="", icon="PLUGIN")
row.operator("bim.remove_brick", text="", icon="X")
# row.operator("bim.refresh_brick_viewer", text="", icon="FILE_REFRESH")
@@ -111,8 +110,29 @@ class BIM_PT_brickschema(Panel):
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_create_relations_toggled", text="", icon="PLUGIN")
row.prop(data=self.props, property="brick_edit_relations_toggled", text="", icon="TOOL_SETTINGS")
if self.props.brick_create_relations_toggled:
row = self.layout.row(align=True)
col = row.column()
col.alignment = "LEFT"
row.label(text="Create Relation:")
col = row.column()
col.alignment = "RIGHT"
row.prop(data=self.props, property="split_screen_toggled", text="", icon="WINDOW")
row = self.layout.row(align=True)
prop_with_search(row, self.props, "new_brick_relation_namespace", text="")
row = self.layout.row(align=True)
prop_with_search(row, self.props, "new_brick_relation_type", text="")
row.prop(data=self.props, property="new_brick_relation_object", text="")
row.operator("bim.add_brick_relation", text="", icon="ADD")
if self.props.add_relation_failed:
row = self.layout.row(align=True)
row.label(text="Failed to find this entity!", icon="ERROR")
for relation in BrickschemaData.data["relations"]:
row = self.layout.row(align=True)
+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_feed(ifc, brick, source=None, destination=None):
brick.add_feed(brick.get_brick(source), brick.get_brick(destination))
def add_brick_relation(brick, brick_uri=None, predicate=None, namespace=None, object=None):
brick.add_relation(brick_uri, predicate, namespace, object)
brick.run_refresh_brick_viewer()
+13 -3
View File
@@ -100,9 +100,19 @@ class Brick(blenderbim.core.tool.Brick):
)
@classmethod
def add_feed(cls, source, destination):
ns_brick = Namespace("https://brickschema.org/schema/Brick#")
BrickStore.graph.add((URIRef(source), ns_brick["feeds"], URIRef(destination)))
def add_relation(cls, brick_uri, predicate, namespace, object):
object_uri = namespace + object
query = BrickStore.graph.query(
"ASK { <{object_uri}> ?predicate ?object . }".replace(
"{object_uri}", object_uri
)
)
if query:
with BrickStore.new_changeset() as cs:
cs.add((URIRef(brick_uri), URIRef(predicate), URIRef(object_uri)))
bpy.context.scene.BIMBrickProperties.add_relation_failed = False
else:
bpy.context.scene.BIMBrickProperties.add_relation_failed = True
@classmethod
def remove_relation(cls, brick_uri, predicate, object):