mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Implement VersionedGraphCollection to Brick module
- Reworked `load_brick_file` and `new_brick_file` to fit under the VersionedGraphCollection implementation. (Other methods may have broken). - Added `undo_brick` and `redo_brick`. - Kept BrickStore.graph the same as to generally still work with the rest of the code. This was done by parsing the VersionedGraphCollection with the new `reload_brick_graph` method.
This commit is contained in:
@@ -25,6 +25,7 @@ import blenderbim.tool as tool
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import brickschema
|
import brickschema
|
||||||
|
import brickschema.persistent
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from rdflib import Literal, URIRef, Namespace
|
from rdflib import Literal, URIRef, Namespace
|
||||||
from rdflib.namespace import RDF
|
from rdflib.namespace import RDF
|
||||||
@@ -32,7 +33,6 @@ except:
|
|||||||
# See #1860
|
# See #1860
|
||||||
print("Warning: brickschema not available.")
|
print("Warning: brickschema not available.")
|
||||||
|
|
||||||
|
|
||||||
class Brick(blenderbim.core.tool.Brick):
|
class Brick(blenderbim.core.tool.Brick):
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_brick(cls, namespace, brick_class):
|
def add_brick(cls, namespace, brick_class):
|
||||||
@@ -249,27 +249,29 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_brick_file(cls, filepath):
|
def load_brick_file(cls, filepath):
|
||||||
if not BrickStore.schema:
|
if not BrickStore.schema: # important check for running under test cases
|
||||||
BrickStore.schema = brickschema.Graph()
|
|
||||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||||
schema_path = os.path.join(cwd, "..", "bim", "schema", "Brick.ttl")
|
BrickStore.schema = os.path.join(cwd, "..", "bim", "schema", "Brick.ttl")
|
||||||
BrickStore.schema.load_file(schema_path)
|
BrickStore.VersionedGraphCollection = brickschema.persistent.VersionedGraphCollection("sqlite://")
|
||||||
BrickStore.graph = brickschema.Graph().load_file(filepath) + BrickStore.schema
|
with BrickStore.VersionedGraphCollection.new_changeset("schema") as cs:
|
||||||
|
cs.load_file(BrickStore.schema)
|
||||||
|
with BrickStore.VersionedGraphCollection.new_changeset("project") as cs:
|
||||||
|
cs.load_file(filepath)
|
||||||
|
BrickStore.reload_brick_graph()
|
||||||
BrickStore.path = filepath
|
BrickStore.path = filepath
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new_brick_file(cls):
|
def new_brick_file(cls):
|
||||||
if not BrickStore.schema:
|
if not BrickStore.schema: # important check for running under test cases
|
||||||
BrickStore.schema = brickschema.Graph()
|
|
||||||
#BrickStore.schema = brickschema.persistent.VersionedGraphCollection("sqlite://")
|
|
||||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||||
schema_path = os.path.join(cwd, "..", "bim", "schema", "Brick.ttl")
|
BrickStore.schema = os.path.join(cwd, "..", "bim", "schema", "Brick.ttl")
|
||||||
BrickStore.schema.load_file(schema_path)
|
BrickStore.VersionedGraphCollection = brickschema.persistent.VersionedGraphCollection("sqlite://")
|
||||||
#BrickStore.schema.load_graph(schema_path)
|
with BrickStore.VersionedGraphCollection.new_changeset("schema") as cs:
|
||||||
BrickStore.graph = brickschema.Graph() + BrickStore.schema
|
cs.load_file(BrickStore.schema)
|
||||||
BrickStore.graph.bind("digitaltwin", Namespace("https://example.org/digitaltwin#"))
|
BrickStore.VersionedGraphCollection.bind("digitaltwin", Namespace("https://example.org/digitaltwin#"))
|
||||||
BrickStore.graph.bind("brick", Namespace("https://brickschema.org/schema/Brick#"))
|
BrickStore.VersionedGraphCollection.bind("brick", Namespace("https://brickschema.org/schema/Brick#"))
|
||||||
BrickStore.graph.bind("rdfs", Namespace("http://www.w3.org/2000/01/rdf-schema#"))
|
BrickStore.VersionedGraphCollection.bind("rdfs", Namespace("http://www.w3.org/2000/01/rdf-schema#"))
|
||||||
|
BrickStore.reload_brick_graph()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pop_brick_breadcrumb(cls):
|
def pop_brick_breadcrumb(cls):
|
||||||
@@ -308,10 +310,22 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
def set_active_brick_class(cls, brick_class):
|
def set_active_brick_class(cls, brick_class):
|
||||||
bpy.context.scene.BIMBrickProperties.active_brick_class = brick_class
|
bpy.context.scene.BIMBrickProperties.active_brick_class = brick_class
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def undo_brick(cls):
|
||||||
|
BrickStore.VersionedGraphCollection.undo()
|
||||||
|
BrickStore.reload_brick_graph()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def redo_brick(cls):
|
||||||
|
BrickStore.VersionedGraphCollection.redo()
|
||||||
|
BrickStore.reload_brick_graph()
|
||||||
|
|
||||||
class BrickStore:
|
class BrickStore:
|
||||||
schema = None
|
schema = None # this is now a path
|
||||||
graph = None
|
# I've decided to arbitrarily split th VersionedGraphCollection into two graph names: "schema" and "project"
|
||||||
|
# "schema" holds the Brick.ttl metadata; "project" holds all the authored entities
|
||||||
|
VersionedGraphCollection = None
|
||||||
|
graph = None # this is the graph named "project" from the VersionedGraphCollection
|
||||||
path = None
|
path = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -319,3 +333,7 @@ class BrickStore:
|
|||||||
BrickStore.schema = None
|
BrickStore.schema = None
|
||||||
BrickStore.graph = None
|
BrickStore.graph = None
|
||||||
BrickStore.path = None
|
BrickStore.path = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def reload_brick_graph(cls):
|
||||||
|
BrickStore.graph = BrickStore.VersionedGraphCollection.graph_at("project")
|
||||||
Reference in New Issue
Block a user