From abf809f9dd8c48df730993206837e4f8ffae7228 Mon Sep 17 00:00:00 2001 From: Trashman247 Date: Thu, 6 Jul 2023 00:19:58 -0700 Subject: [PATCH] Add brick operator accepts label parameter & add toggle for namespace editing --- .../blenderbim/bim/module/brick/__init__.py | 1 + .../blenderbim/bim/module/brick/operator.py | 13 ++++++++++- .../blenderbim/bim/module/brick/prop.py | 5 +++++ .../blenderbim/bim/module/brick/ui.py | 22 ++++++++++++++++++- src/blenderbim/blenderbim/core/brick.py | 9 +++++--- src/blenderbim/blenderbim/tool/brick.py | 10 ++++++--- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/brick/__init__.py b/src/blenderbim/blenderbim/bim/module/brick/__init__.py index 744e679dab..6c8499cb46 100644 --- a/src/blenderbim/blenderbim/bim/module/brick/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/brick/__init__.py @@ -36,6 +36,7 @@ classes = ( operator.UndoBrick, operator.RedoBrick, operator.SerializeBrick, + operator.AddBrickNamespace, prop.Brick, prop.BIMBrickProperties, ui.BIM_PT_brickschema, diff --git a/src/blenderbim/blenderbim/bim/module/brick/operator.py b/src/blenderbim/blenderbim/bim/module/brick/operator.py index 854480f25c..896904d3fa 100644 --- a/src/blenderbim/blenderbim/bim/module/brick/operator.py +++ b/src/blenderbim/blenderbim/bim/module/brick/operator.py @@ -126,6 +126,7 @@ class AddBrick(bpy.types.Operator, Operator): namespace=props.namespace, brick_class=props.brick_equipment_class, library=library, + label=props.new_brick_label ) @@ -229,4 +230,14 @@ class SerializeBrick(bpy.types.Operator, Operator): def description(cls, context, properties): if properties.should_save_as: return "Save Brick project to a selected file" - return "Save the Brick project" \ No newline at end of file + return "Save the Brick project" + +class AddBrickNamespace(bpy.types.Operator, Operator): + bl_idname = "bim.add_brick_namespace" + bl_label = "Add Brick Namespace" + + def _execute(self, context): + props = context.scene.BIMBrickProperties + alias = props.new_brick_namespace_alias + uri = props.new_brick_namespace_uri + core.add_namespace(tool.Brick, alias=alias, uri=uri) \ No newline at end of file diff --git a/src/blenderbim/blenderbim/bim/module/brick/prop.py b/src/blenderbim/blenderbim/bim/module/brick/prop.py index 6e0ba7c814..d45475ef2b 100644 --- a/src/blenderbim/blenderbim/bim/module/brick/prop.py +++ b/src/blenderbim/blenderbim/bim/module/brick/prop.py @@ -30,6 +30,7 @@ from bpy.props import ( FloatVectorProperty, CollectionProperty, ) +from blenderbim.tool.brick import BrickStore def update_active_brick_index(self, context): @@ -69,3 +70,7 @@ class BIMBrickProperties(PropertyGroup): libraries: EnumProperty(name="Libraries", items=get_libraries) namespace: EnumProperty(name="Namespace", items=get_namespaces) brick_equipment_class: EnumProperty(name="Brick Equipment Class", items=get_brick_equipment_classes) + brick_settings_toggled: BoolProperty(name="Brick Settings Toggled", default=False) + new_brick_label: StringProperty(name="New Brick Label") + new_brick_namespace_alias: StringProperty(name="New Brick Namespace Alias") + new_brick_namespace_uri: StringProperty(name="New Brick Namespace URI") \ No newline at end of file diff --git a/src/blenderbim/blenderbim/bim/module/brick/ui.py b/src/blenderbim/blenderbim/bim/module/brick/ui.py index f863b0fb5f..78f956f26f 100644 --- a/src/blenderbim/blenderbim/bim/module/brick/ui.py +++ b/src/blenderbim/blenderbim/bim/module/brick/ui.py @@ -49,11 +49,31 @@ class BIM_PT_brickschema(Panel): if len(self.props.brick_breadcrumbs): row.operator("bim.rewind_brick_class", text="", icon="FRAME_PREV") row.label(text=self.props.active_brick_class) + row.prop(data=self.props, property="brick_settings_toggled", text="", icon="PREFERENCES") row.operator("bim.refresh_brick_viewer", text="", icon="FILE_REFRESH") row.operator("bim.close_brick_project", text="", icon="CANCEL") + if self.props.brick_settings_toggled: + box = self.layout.box() + row = box.row(align=True) + row.label(text="Active Namespace:") + row = box.row(align=True) + prop_with_search(row, self.props, "namespace", text="") + row = box.row(align=True) + row.label(text="Bind New Namespace:") + row = box.row(align=True) + row.prop(data=self.props, property="new_brick_namespace_alias", text="") + col = row.column() + col.alignment = "CENTER" + col.scale_x = 1.1 + col.label(text=":") + row.prop(data=self.props, property="new_brick_namespace_uri", text="") + row.operator("bim.add_brick_namespace", text="", icon="ADD") + row = self.layout.row(align=True) - prop_with_search(row, self.props, "namespace", text="") + row.label(text="Create Entity:") + row = self.layout.row(align=True) + row.prop(data=self.props, property="new_brick_label", text="") prop_with_search(row, self.props, "brick_equipment_class", text="") row.operator("bim.add_brick", text="", icon="ADD") diff --git a/src/blenderbim/blenderbim/core/brick.py b/src/blenderbim/blenderbim/core/brick.py index 1dccbc7ed2..a675b15500 100644 --- a/src/blenderbim/blenderbim/core/brick.py +++ b/src/blenderbim/blenderbim/core/brick.py @@ -68,13 +68,13 @@ def assign_brick_reference(ifc, brick, element=None, library=None, brick_uri=Non brick.add_brickifc_reference(brick_uri, element, project) -def add_brick(ifc, brick, element=None, namespace=None, brick_class=None, library=None): +def add_brick(ifc, brick, element=None, namespace=None, brick_class=None, library=None, label="Unnamed"): if element: brick_uri = brick.add_brick_from_element(element, namespace, brick_class) if library: brick.run_assign_brick_reference(element=element, library=library, brick_uri=brick_uri) else: - brick_uri = brick.add_brick(namespace, brick_class) + brick_uri = brick.add_brick(namespace, brick_class, label) brick.run_refresh_brick_viewer() @@ -123,4 +123,7 @@ def redo_brick(brick): def serialize_brick(brick): - brick.serialize_brick() \ No newline at end of file + brick.serialize_brick() + +def add_namespace(brick, alias=None, uri=None): + brick.add_namespace(alias, uri) diff --git a/src/blenderbim/blenderbim/tool/brick.py b/src/blenderbim/blenderbim/tool/brick.py index f7cb4e0b8f..809d3a8c34 100644 --- a/src/blenderbim/blenderbim/tool/brick.py +++ b/src/blenderbim/blenderbim/tool/brick.py @@ -41,12 +41,12 @@ logger.setLevel(logging.ERROR) class Brick(blenderbim.core.tool.Brick): @classmethod - def add_brick(cls, namespace, brick_class): + def add_brick(cls, namespace, brick_class, label): ns = Namespace(namespace) brick = ns[ifcopenshell.guid.expand(ifcopenshell.guid.new())] with BrickStore.graph.new_changeset("PROJECT") as cs: cs.add((brick, RDF.type, URIRef(brick_class))) - cs.add((brick, URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal("Unnamed"))) + cs.add((brick, URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal(label))) return str(brick) @classmethod @@ -333,8 +333,12 @@ class Brick(blenderbim.core.tool.Brick): @classmethod def serialize_brick(cls): - print(BrickStore.path) BrickStore.get_project().serialize(destination=BrickStore.path, format="turtle") + + @classmethod + def add_namespace(cls, alias, uri): + BrickStore.graph.bind(alias, Namespace(uri)) + # need some way to reload namespace enum view class BrickStore: schema = None # this is now a os path