mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Implement human readable rdfs labels in Brickschema navigator
This commit is contained in:
@@ -56,6 +56,7 @@ def get_brick_equipment_classes(self, context):
|
||||
|
||||
class Brick(PropertyGroup):
|
||||
name: StringProperty(name="Name")
|
||||
label: StringProperty(name="Label")
|
||||
uri: StringProperty(name="URI")
|
||||
total_items: IntProperty(name="Total Items")
|
||||
|
||||
|
||||
@@ -121,6 +121,6 @@ class BIM_UL_bricks(UIList):
|
||||
if item.total_items:
|
||||
op = row.operator("bim.view_brick_class", text="", icon="DISCLOSURE_TRI_RIGHT", emboss=False)
|
||||
op.brick_class = item.name
|
||||
row.label(text=item.name)
|
||||
row.label(text=item.label if item.label else item.name)
|
||||
if item.total_items:
|
||||
row.label(text=str(item.total_items))
|
||||
|
||||
@@ -190,9 +190,12 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
PREFIX brick: <https://brickschema.org/schema/Brick#>
|
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
||||
SELECT ?group (count(?item) as ?total_items) WHERE {
|
||||
SELECT ?group (count(?item) as ?total_items) ?label WHERE {
|
||||
?group rdfs:subClassOf brick:{brick_class} .
|
||||
?item rdf:type/rdfs:subClassOf* ?group
|
||||
?item rdf:type/rdfs:subClassOf* ?group .
|
||||
OPTIONAL {
|
||||
?group rdfs:label ?label
|
||||
}
|
||||
}
|
||||
GROUP BY ?group
|
||||
ORDER BY asc(?group)
|
||||
@@ -202,6 +205,9 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
)
|
||||
for row in query:
|
||||
new = bpy.context.scene.BIMBrickProperties.bricks.add()
|
||||
label = row.get("label")
|
||||
if label:
|
||||
new.label = label.toPython()
|
||||
new.name = row.get("group").toPython().split("#")[-1]
|
||||
new.uri = row.get("group").toPython()
|
||||
new.total_items = row.get("total_items").toPython()
|
||||
@@ -213,8 +219,11 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
PREFIX brick: <https://brickschema.org/schema/Brick#>
|
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
||||
SELECT ?item WHERE {
|
||||
?item rdf:type brick:{brick_class}
|
||||
SELECT ?item ?label WHERE {
|
||||
?item rdf:type brick:{brick_class} .
|
||||
OPTIONAL {
|
||||
?item rdfs:label ?label
|
||||
}
|
||||
}
|
||||
ORDER BY asc(?item)
|
||||
""".replace(
|
||||
@@ -223,6 +232,9 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
)
|
||||
for row in query:
|
||||
new = bpy.context.scene.BIMBrickProperties.bricks.add()
|
||||
label = row.get("label")
|
||||
if label:
|
||||
new.label = label.toPython()
|
||||
new.name = row.get("item").toPython().split("#")[-1]
|
||||
new.uri = row.get("item").toPython()
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
@prefix digitaltwin: <http://example.org/digitaltwin#> .
|
||||
@prefix brick: <https://brickschema.org/schema/Brick#> .
|
||||
@prefix unit: <http://qudt.org/vocab/unit/> .
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
|
||||
digitaltwin:site a brick:Site ;
|
||||
brick:buildingPrimaryFunction [ brick:value "Library" ] ;
|
||||
brick:hasPart digitaltwin:bldg .
|
||||
|
||||
digitaltwin:bldg a brick:Building ;
|
||||
rdfs:label "My Building" ;
|
||||
brick:hasPart digitaltwin:floor .
|
||||
|
||||
digitaltwin:floor a brick:Floor ;
|
||||
|
||||
@@ -263,10 +263,12 @@ class TestImportBrickClasses(NewFile):
|
||||
assert brick.name == "Building"
|
||||
assert brick.uri == "https://brickschema.org/schema/Brick#Building"
|
||||
assert brick.total_items == 1
|
||||
assert not brick.label
|
||||
brick = bpy.context.scene.BIMBrickProperties.bricks[1]
|
||||
assert brick.name == "Location"
|
||||
assert brick.uri == "https://brickschema.org/schema/Brick#Location"
|
||||
assert brick.total_items == 1
|
||||
assert not brick.label
|
||||
|
||||
|
||||
class TestImportBrickItems(NewFile):
|
||||
@@ -276,6 +278,7 @@ class TestImportBrickItems(NewFile):
|
||||
assert len(bpy.context.scene.BIMBrickProperties.bricks) == 1
|
||||
brick = bpy.context.scene.BIMBrickProperties.bricks[0]
|
||||
assert brick.name == "bldg"
|
||||
assert brick.label == "My Building"
|
||||
assert brick.uri == "http://example.org/digitaltwin#bldg"
|
||||
assert brick.total_items == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user