Move Brick namespace from data to BrickStore

This commit is contained in:
Trashman247
2023-07-14 23:25:38 -07:00
committed by Riley Wong
parent 1eb7c006f1
commit 0348e6d11a
3 changed files with 20 additions and 18 deletions
@@ -42,7 +42,6 @@ class BrickschemaData:
cls.data = {
"is_loaded": cls.get_is_loaded(),
"attributes": cls.attributes(),
"namespaces": cls.namespaces(),
"brick_equipment_classes": cls.brick_equipment_classes(),
}
@@ -104,17 +103,6 @@ class BrickschemaData:
)
return results
@classmethod
def namespaces(cls):
if BrickStore.graph is None:
return []
results = []
filter = ["brick", "owl", "w3", "xml"]
for alias, uri in BrickStore.graph.namespaces():
if alias not in filter:
results.append((uri, f"{alias}: {uri}", ""))
return results
@classmethod
def brick_equipment_classes(cls):
if BrickStore.graph is None:
@@ -30,7 +30,7 @@ from bpy.props import (
FloatVectorProperty,
CollectionProperty,
)
from blenderbim.tool.brick import BrickStore
def update_active_brick_index(self, context):
BrickschemaData.is_loaded = False
@@ -43,9 +43,7 @@ def get_libraries(self, context):
def get_namespaces(self, context):
if not BrickschemaData.is_loaded:
BrickschemaData.load()
return BrickschemaData.data["namespaces"]
return BrickStore.namespaces
def get_brick_equipment_classes(self, context):
+18 -2
View File
@@ -268,6 +268,7 @@ class Brick(blenderbim.core.tool.Brick):
with BrickStore.graph.new_changeset("PROJECT") as cs:
cs.load_file(filepath)
BrickStore.path = filepath
BrickStore.load_namespaces()
@classmethod
def new_brick_file(cls):
@@ -278,6 +279,7 @@ class Brick(blenderbim.core.tool.Brick):
with BrickStore.graph.new_changeset("SCHEMA") as cs:
cs.load_file(BrickStore.schema)
BrickStore.graph.bind("digitaltwin", Namespace("https://example.org/digitaltwin#"))
BrickStore.load_namespaces()
@classmethod
def pop_brick_breadcrumb(cls):
@@ -325,13 +327,12 @@ class Brick(blenderbim.core.tool.Brick):
@classmethod
def add_namespace(cls, alias, uri):
BrickStore.graph.bind(alias, Namespace(uri))
# need some way to reload namespace enum view
BrickStore.load_namespaces()
@classmethod
def clear_breadcrumbs(cls):
bpy.context.scene.BIMBrickProperties.brick_breadcrumbs.clear()
class BrickStore:
schema = None # this is now a os path
path = None # file path if the project was loaded in
@@ -341,16 +342,31 @@ class BrickStore:
future = []
current_changesets = 0
history_size = 64
namespaces = []
@staticmethod
def purge():
BrickStore.schema = None
BrickStore.graph = None
BrickStore.path = None
BrickStore.namespaces = []
@classmethod
def get_project(cls):
return BrickStore.graph.graph_at(graph="PROJECT")
@classmethod
def load_namespaces(cls):
BrickStore.namespaces = []
keyword_filter = ["brickschema.org", "schema.org", "w3.org", "purl.org", "rdfs.org", "qudt.org", "ashrae.org"]
for alias, uri in BrickStore.graph.namespaces():
ignore_namespace = False
for keyword in keyword_filter:
if keyword in str(uri):
ignore_namespace = True
break
if not ignore_namespace:
BrickStore.namespaces.append((uri, f"{alias}: {uri}", ""))
@classmethod
def set_history_size(cls, size):