mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
You can now create a new blank Brick project
This commit is contained in:
@@ -27,6 +27,7 @@ classes = (
|
|||||||
operator.ConvertBrickProject,
|
operator.ConvertBrickProject,
|
||||||
operator.ConvertIfcToBrick,
|
operator.ConvertIfcToBrick,
|
||||||
operator.LoadBrickProject,
|
operator.LoadBrickProject,
|
||||||
|
operator.NewBrickFile,
|
||||||
operator.RewindBrickClass,
|
operator.RewindBrickClass,
|
||||||
operator.ViewBrickClass,
|
operator.ViewBrickClass,
|
||||||
operator.ViewBrickItem,
|
operator.ViewBrickItem,
|
||||||
|
|||||||
@@ -154,3 +154,12 @@ class ConvertIfcToBrick(bpy.types.Operator, Operator):
|
|||||||
if props.libraries:
|
if props.libraries:
|
||||||
library = tool.Ifc.get().by_id(int(props.libraries))
|
library = tool.Ifc.get().by_id(int(props.libraries))
|
||||||
core.convert_ifc_to_brick(tool.Brick, namespace=props.namespace, library=library)
|
core.convert_ifc_to_brick(tool.Brick, namespace=props.namespace, library=library)
|
||||||
|
|
||||||
|
|
||||||
|
class NewBrickFile(bpy.types.Operator, Operator):
|
||||||
|
bl_idname = "bim.new_brick_file"
|
||||||
|
bl_label = "New Brick File"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
core.new_brick_file(tool.Brick)
|
||||||
|
|||||||
@@ -35,8 +35,9 @@ class BIM_PT_brickschema(Panel):
|
|||||||
self.props = context.scene.BIMBrickProperties
|
self.props = context.scene.BIMBrickProperties
|
||||||
|
|
||||||
if not BrickschemaData.data["is_loaded"]:
|
if not BrickschemaData.data["is_loaded"]:
|
||||||
row = self.layout.row()
|
row = self.layout.row(align=True)
|
||||||
row.operator("bim.load_brick_project")
|
row.operator("bim.new_brick_file", text="Create Project")
|
||||||
|
row.operator("bim.load_brick_project", text="Load Project")
|
||||||
return
|
return
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
|
|||||||
@@ -87,3 +87,7 @@ def convert_ifc_to_brick(brick, namespace=None, library=None):
|
|||||||
if not brick_class:
|
if not brick_class:
|
||||||
continue
|
continue
|
||||||
brick.run_add_brick(obj=obj, namespace=namespace, brick_class=brick_class, library=library)
|
brick.run_add_brick(obj=obj, namespace=namespace, brick_class=brick_class, library=library)
|
||||||
|
|
||||||
|
|
||||||
|
def new_brick_file(brick):
|
||||||
|
brick.new_brick_file()
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class Brick:
|
|||||||
def import_brick_classes(cls, brick_class): pass
|
def import_brick_classes(cls, brick_class): pass
|
||||||
def import_brick_items(cls, brick_class): pass
|
def import_brick_items(cls, brick_class): pass
|
||||||
def load_brick_file(cls, filepath): pass
|
def load_brick_file(cls, filepath): pass
|
||||||
|
def new_brick_file(cls): pass
|
||||||
def pop_brick_breadcrumb(cls): pass
|
def pop_brick_breadcrumb(cls): pass
|
||||||
def run_add_brick(cls, obj=None, namespace=None, brick_class=None, library=None): pass
|
def run_add_brick(cls, obj=None, namespace=None, brick_class=None, library=None): pass
|
||||||
def run_assign_brick_reference(cls, obj=None, library=None, brick_uri=None): pass
|
def run_assign_brick_reference(cls, obj=None, library=None, brick_uri=None): pass
|
||||||
|
|||||||
@@ -248,6 +248,16 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
BrickStore.graph = brickschema.Graph().load_file(filepath) + BrickStore.schema
|
BrickStore.graph = brickschema.Graph().load_file(filepath) + BrickStore.schema
|
||||||
BrickStore.path = filepath
|
BrickStore.path = filepath
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def new_brick_file(cls):
|
||||||
|
if not BrickStore.schema:
|
||||||
|
BrickStore.schema = brickschema.Graph()
|
||||||
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
schema_path = os.path.join(cwd, "..", "bim", "schema", "Brick.ttl")
|
||||||
|
BrickStore.schema.load_file(schema_path)
|
||||||
|
BrickStore.graph = brickschema.Graph() + BrickStore.schema
|
||||||
|
BrickStore.graph.bind("digitaltwin", Namespace("https://example.org/digitaltwin#"))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pop_brick_breadcrumb(cls):
|
def pop_brick_breadcrumb(cls):
|
||||||
crumb = bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[-1]
|
crumb = bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[-1]
|
||||||
|
|||||||
@@ -151,3 +151,9 @@ class TestConvertIfcToBrick:
|
|||||||
brick.get_convertable_brick_objects_and_elements().should_be_called().will_return([("obj", "element")])
|
brick.get_convertable_brick_objects_and_elements().should_be_called().will_return([("obj", "element")])
|
||||||
brick.get_brick_class("element").should_be_called().will_return(None)
|
brick.get_brick_class("element").should_be_called().will_return(None)
|
||||||
subject.convert_ifc_to_brick(brick, namespace="namespace", library="library")
|
subject.convert_ifc_to_brick(brick, namespace="namespace", library="library")
|
||||||
|
|
||||||
|
|
||||||
|
class TestNewBrickFile:
|
||||||
|
def test_run(self, brick):
|
||||||
|
brick.new_brick_file().should_be_called()
|
||||||
|
subject.new_brick_file(brick)
|
||||||
|
|||||||
@@ -298,6 +298,25 @@ class TestLoadBrickFile(NewFile):
|
|||||||
assert BrickStore.graph
|
assert BrickStore.graph
|
||||||
|
|
||||||
|
|
||||||
|
class TestNewBrickFile(NewFile):
|
||||||
|
def test_run(self):
|
||||||
|
# We stub the schema to make tests run faster
|
||||||
|
BrickStore.schema = brickschema.Graph()
|
||||||
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
schema_path = os.path.join(cwd, "..", "files", "BrickStub.ttl")
|
||||||
|
BrickStore.schema.load_file(schema_path)
|
||||||
|
|
||||||
|
# This is the actual test
|
||||||
|
ns_alias = "digitaltwin"
|
||||||
|
ns_uri = "https://example.org/digitaltwin#"
|
||||||
|
subject.new_brick_file()
|
||||||
|
assert BrickStore.graph
|
||||||
|
for ns in BrickStore.graph.namespaces():
|
||||||
|
if ns[0] == ns_alias and ns[1].toPython() == ns_uri:
|
||||||
|
return
|
||||||
|
assert False
|
||||||
|
|
||||||
|
|
||||||
class TestPopBrickBreadcrumb(NewFile):
|
class TestPopBrickBreadcrumb(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
bpy.context.scene.BIMBrickProperties.brick_breadcrumbs.add().name = "foo"
|
bpy.context.scene.BIMBrickProperties.brick_breadcrumbs.add().name = "foo"
|
||||||
|
|||||||
Reference in New Issue
Block a user