Skip to content

Commit deecd60

Browse files
committed
Implement basic Brick create relation
1 parent 0161572 commit deecd60

File tree

6 files changed

+66
-18
lines changed

6 files changed

+66
-18
lines changed

src/blenderbim/blenderbim/bim/module/brick/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
classes = (
2323
operator.AddBrick,
24-
operator.AddBrickFeed,
24+
operator.AddBrickRelation,
2525
operator.AssignBrickReference,
2626
operator.CloseBrickProject,
2727
operator.ConvertBrickProject,

src/blenderbim/blenderbim/bim/module/brick/operator.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,20 @@ def _execute(self, context):
132132
)
133133

134134

135-
class AddBrickFeed(bpy.types.Operator, Operator):
136-
bl_idname = "bim.add_brick_feed"
137-
bl_label = "Add Brick Feed"
135+
class AddBrickRelation(bpy.types.Operator, Operator):
136+
bl_idname = "bim.add_brick_relation"
137+
bl_label = "Add Brick Relation"
138138
bl_options = {"REGISTER", "UNDO"}
139139

140140
def _execute(self, context):
141-
source = tool.Ifc.get_entity([o for o in context.selected_objects if o != context.active_object][0])
142-
destination = tool.Ifc.get_entity(context.active_object)
143-
core.add_brick_feed(
144-
tool.Ifc,
141+
props = context.scene.BIMBrickProperties
142+
brick = props.bricks[props.active_brick_index]
143+
core.add_brick_relation(
145144
tool.Brick,
146-
source=source,
147-
destination=destination,
145+
brick_uri=brick.uri,
146+
predicate=props.new_brick_relation_type,
147+
namespace=props.new_brick_relation_namespace,
148+
object=props.new_brick_relation_object
148149
)
149150

150151

src/blenderbim/blenderbim/bim/module/brick/prop.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ def get_brick_roots(self, context):
5555
return [(root, root, "") for root in BrickStore.root_classes]
5656

5757

58+
def get_brick_relations(self, context): # this will be queried from graph
59+
return [("https://brickschema.org/schema/Brick#hasLocation", "hasLocation", ""),
60+
("https://brickschema.org/schema/Brick#isLocationOf", "isLocationOf", ""),
61+
("https://brickschema.org/schema/Brick#hasPart", "hasPart", ""),
62+
("https://brickschema.org/schema/Brick#isPartOf", "isPartOf", ""),
63+
("https://brickschema.org/schema/Brick#hasPoint", "hasPoint", ""),
64+
("https://brickschema.org/schema/Brick#isPointOf", "isPointOf", ""),
65+
("https://brickschema.org/schema/Brick#feeds", "feeds", ""),
66+
("https://brickschema.org/schema/Brick#isFedBy", "isFedBy", ""),
67+
("http://www.w3.org/2000/01/rdf-schema#label", "label", "")]
68+
69+
5870
class Brick(PropertyGroup):
5971
name: StringProperty(name="Name")
6072
label: StringProperty(name="Label")
@@ -77,4 +89,9 @@ class BIMBrickProperties(PropertyGroup):
7789
brick_list_root: EnumProperty(name="Brick List Root", items=get_brick_roots)
7890
brick_entity_create_type: EnumProperty(name="Brick Entity Types", items=get_brick_roots)
7991
brick_create_relations_toggled: BoolProperty(name="Brick Create Relations Toggled", default=False)
80-
brick_edit_relations_toggled: BoolProperty(name="Brick Edit Relations Toggled", default=False)
92+
brick_edit_relations_toggled: BoolProperty(name="Brick Edit Relations Toggled", default=False)
93+
new_brick_relation_type: EnumProperty(name="New Brick Relation Type", items=get_brick_relations)
94+
new_brick_relation_namespace: EnumProperty(name="New Brick Relation Namespace", items=get_namespaces)
95+
new_brick_relation_object: StringProperty(name="New Brick Relation Object")
96+
add_relation_failed: BoolProperty(name="Add Relation Failed", default=False)
97+
split_screen_toggled: BoolProperty(name="Split Screen Toggled", default=False)

src/blenderbim/blenderbim/bim/module/brick/ui.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def draw(self, context):
9898
row.operator("bim.rewind_brick_class", text="", icon="FRAME_PREV")
9999
col = row.column()
100100
col.alignment = "RIGHT"
101-
# row.operator("bim.add_brick_feed", text="", icon="PLUGIN")
102101
row.operator("bim.remove_brick", text="", icon="X")
103102
# row.operator("bim.refresh_brick_viewer", text="", icon="FILE_REFRESH")
104103

@@ -111,8 +110,29 @@ def draw(self, context):
111110
row = self.layout.row(align=True)
112111
col = row.column()
113112
col.alignment = "RIGHT"
114-
row.prop(data=self.props, property="brick_create_relations_toggled", text="", icon="OUTLINER_DATA_GP_LAYER")
113+
row.prop(data=self.props, property="brick_create_relations_toggled", text="", icon="PLUGIN")
115114
row.prop(data=self.props, property="brick_edit_relations_toggled", text="", icon="TOOL_SETTINGS")
115+
116+
if self.props.brick_create_relations_toggled:
117+
row = self.layout.row(align=True)
118+
col = row.column()
119+
col.alignment = "LEFT"
120+
row.label(text="Create Relation:")
121+
col = row.column()
122+
col.alignment = "RIGHT"
123+
row.prop(data=self.props, property="split_screen_toggled", text="", icon="WINDOW")
124+
125+
row = self.layout.row(align=True)
126+
prop_with_search(row, self.props, "new_brick_relation_namespace", text="")
127+
128+
row = self.layout.row(align=True)
129+
prop_with_search(row, self.props, "new_brick_relation_type", text="")
130+
row.prop(data=self.props, property="new_brick_relation_object", text="")
131+
row.operator("bim.add_brick_relation", text="", icon="ADD")
132+
133+
if self.props.add_relation_failed:
134+
row = self.layout.row(align=True)
135+
row.label(text="Failed to find this entity!", icon="ERROR")
116136

117137
for relation in BrickschemaData.data["relations"]:
118138
row = self.layout.row(align=True)

src/blenderbim/blenderbim/core/brick.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def add_brick(ifc, brick, element=None, namespace=None, brick_class=None, librar
7878
brick.run_refresh_brick_viewer()
7979

8080

81-
def add_brick_feed(ifc, brick, source=None, destination=None):
82-
brick.add_feed(brick.get_brick(source), brick.get_brick(destination))
81+
def add_brick_relation(brick, brick_uri=None, predicate=None, namespace=None, object=None):
82+
brick.add_relation(brick_uri, predicate, namespace, object)
8383
brick.run_refresh_brick_viewer()
8484

8585

src/blenderbim/blenderbim/tool/brick.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,19 @@ def add_brickifc_reference(cls, brick, element, project):
100100
)
101101

102102
@classmethod
103-
def add_feed(cls, source, destination):
104-
ns_brick = Namespace("https://brickschema.org/schema/Brick#")
105-
BrickStore.graph.add((URIRef(source), ns_brick["feeds"], URIRef(destination)))
103+
def add_relation(cls, brick_uri, predicate, namespace, object):
104+
object_uri = namespace + object
105+
query = BrickStore.graph.query(
106+
"ASK { <{object_uri}> ?predicate ?object . }".replace(
107+
"{object_uri}", object_uri
108+
)
109+
)
110+
if query:
111+
with BrickStore.new_changeset() as cs:
112+
cs.add((URIRef(brick_uri), URIRef(predicate), URIRef(object_uri)))
113+
bpy.context.scene.BIMBrickProperties.add_relation_failed = False
114+
else:
115+
bpy.context.scene.BIMBrickProperties.add_relation_failed = True
106116

107117
@classmethod
108118
def remove_relation(cls, brick_uri, predicate, object):

0 commit comments

Comments
 (0)