Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 81a4ff7

Browse files
committed
Implement fully serialize operator
- Turns out, you need the keyword "graph=" in graph_at() to actually select a graph of that name from the collection, otherwise it just returns the entire collection, so I changed that, which correctly isolates the project from the collection for serialization now. - With this same change, I opted turn BrickStore.VersionedGraphCollection simply into BrickStore.graph and create a new BrickStore.get_project() to return the isolated graph. - This meant I should remove the reload_graph() function because I was actually just loading the entire collection into it still, and its functionality breaks when it isn't the entire collection
1 parent d919688 commit 81a4ff7

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

src/blenderbim/blenderbim/tool/brick.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -252,26 +252,24 @@ def load_brick_file(cls, filepath):
252252
if not BrickStore.schema: # important check for running under test cases
253253
cwd = os.path.dirname(os.path.realpath(__file__))
254254
BrickStore.schema = os.path.join(cwd, "..", "bim", "schema", "Brick.ttl")
255-
BrickStore.VersionedGraphCollection = brickschema.persistent.VersionedGraphCollection("sqlite://")
256-
with BrickStore.VersionedGraphCollection.new_changeset("SCHEMA") as cs:
255+
BrickStore.graph = brickschema.persistent.VersionedGraphCollection("sqlite://")
256+
with BrickStore.graph.new_changeset("SCHEMA") as cs:
257257
cs.load_file(BrickStore.schema)
258-
with BrickStore.VersionedGraphCollection.new_changeset("PROJECT") as cs:
258+
with BrickStore.graph.new_changeset("PROJECT") as cs:
259259
cs.load_file(filepath)
260-
BrickStore.reload_brick_graph()
261260
BrickStore.path = filepath
262261

263262
@classmethod
264263
def new_brick_file(cls):
265264
if not BrickStore.schema: # important check for running under test cases
266265
cwd = os.path.dirname(os.path.realpath(__file__))
267266
BrickStore.schema = os.path.join(cwd, "..", "bim", "schema", "Brick.ttl")
268-
BrickStore.VersionedGraphCollection = brickschema.persistent.VersionedGraphCollection("sqlite://")
269-
with BrickStore.VersionedGraphCollection.new_changeset("SCHEMA") as cs:
267+
BrickStore.graph = brickschema.persistent.VersionedGraphCollection("sqlite://")
268+
with BrickStore.graph.new_changeset("SCHEMA") as cs:
270269
cs.load_file(BrickStore.schema)
271-
BrickStore.VersionedGraphCollection.bind("digitaltwin", Namespace("https://example.org/digitaltwin#"))
272-
BrickStore.VersionedGraphCollection.bind("brick", Namespace("https://brickschema.org/schema/Brick#"))
273-
BrickStore.VersionedGraphCollection.bind("rdfs", Namespace("http://www.w3.org/2000/01/rdf-schema#"))
274-
BrickStore.reload_brick_graph()
270+
BrickStore.graph.bind("digitaltwin", Namespace("https://example.org/digitaltwin#"))
271+
BrickStore.graph.bind("brick", Namespace("https://brickschema.org/schema/Brick#"))
272+
BrickStore.graph.bind("rdfs", Namespace("http://www.w3.org/2000/01/rdf-schema#"))
275273

276274
@classmethod
277275
def pop_brick_breadcrumb(cls):
@@ -312,36 +310,35 @@ def set_active_brick_class(cls, brick_class):
312310

313311
@classmethod
314312
def undo_brick(cls):
315-
BrickStore.VersionedGraphCollection.undo()
316-
BrickStore.reload_brick_graph()
313+
BrickStore.graph.undo()
317314

318315
@classmethod
319316
def redo_brick(cls):
320-
BrickStore.VersionedGraphCollection.redo()
321-
BrickStore.reload_brick_graph()
317+
BrickStore.graph.redo()
322318

323319
@classmethod
324320
def serialize_brick(cls, file_name):
325-
BrickStore.reload_brick_graph()
321+
#temporary file path, could either be user selected for "save as" or use the BrickStore.path for simply "save"
326322
print("Serializing: \"" + file_name + "\" ... ")
327-
BrickStore.graph.serialize(file_name)
323+
cwd = os.path.dirname(os.path.realpath(__file__))
324+
dest = os.path.join(cwd, "..", "bim", "schema", file_name)
325+
BrickStore.get_project().serialize(destination=dest, format="turtle")
328326
print("finished!")
329327

330328
class BrickStore:
331-
schema = None # this is now a path
332-
# I've decided to arbitrarily split th VersionedGraphCollection into two graph names: "schema" and "project"
333-
# "schema" holds the Brick.ttl metadata; "project" holds all the authored entities
334-
VersionedGraphCollection = None
335-
graph = None # this is the graph named "project" from the VersionedGraphCollection
329+
schema = None # this is now a os path
330+
graph = None # this is the VersionedGraphCollection with 2 arbitrarily named graphs: "schema" and "project"
331+
# "schema" holds the Brick.ttl metadata; "project" holds all the authored entities
332+
project = None # this is the graph named "project" from the VersionedGraphCollection
336333
path = None
337334

338335
@staticmethod
339336
def purge():
340337
BrickStore.schema = None
341-
BrickStore.VersionedGraphCollection = None
342338
BrickStore.graph = None
339+
BrickStore.project = None
343340
BrickStore.path = None
344341

345342
@classmethod
346-
def reload_brick_graph(cls):
347-
BrickStore.graph = BrickStore.VersionedGraphCollection.graph_at("PROJECT")
343+
def get_project(cls):
344+
return BrickStore.graph.graph_at(graph="PROJECT")

0 commit comments

Comments
 (0)