diff --git a/src/blenderbim/Makefile b/src/blenderbim/Makefile index 63ceb6ce09..39d0b78b7a 100644 --- a/src/blenderbim/Makefile +++ b/src/blenderbim/Makefile @@ -402,6 +402,13 @@ endif cp -r dist/working/IFC2JSON_python-master/file_converters/ifcjson dist/blenderbim/libs/site/packages/ rm -rf dist/working + # Provides OpenLCA fucntionality + mkdir dist/working + cd dist/working && wget https://files.pythonhosted.org/packages/85/33/f91b96e9e8608ff65a003b692e8a9cdd60f2178f60617e5b1d21334c009c/olca-ipc-0.0.10.tar.gz + cd dist/working && tar -xzvf olca-ipc* + cd dist/working/olca-ipc-0.0.10/ && cp -r olca ../../blenderbim/libs/site/packages/ + rm -rf dist/working + cd dist/blenderbim && sed -i "s/999999/$(VERSION)/" __init__.py cd dist && zip -r blenderbim-$(VERSION)-$(PYVERSION)-$(PLATFORM).zip ./* rm -rf dist/blenderbim diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index 4ec6641b11..5df49888d9 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -63,6 +63,7 @@ if bpy is not None: "document": None, "pset_template": None, "clash": None, + "lca": None, "csv": None, "bimtester": None, "diff": None, diff --git a/src/blenderbim/blenderbim/bim/module/lca/__init__.py b/src/blenderbim/blenderbim/bim/module/lca/__init__.py new file mode 100644 index 0000000000..b32db0bacd --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/lca/__init__.py @@ -0,0 +1,34 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2021 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import bpy +from . import ui, prop, operator + +classes = ( + operator.CalculateLCA, + prop.BIMLCAProperties, + ui.BIM_PT_lca, +) + + +def register(): + bpy.types.Scene.BIMLCAProperties = bpy.props.PointerProperty(type=prop.BIMLCAProperties) + + +def unregister(): + del bpy.types.Scene.BIMLCAProperties diff --git a/src/blenderbim/blenderbim/bim/module/lca/operator.py b/src/blenderbim/blenderbim/bim/module/lca/operator.py new file mode 100644 index 0000000000..06926f5009 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/lca/operator.py @@ -0,0 +1,45 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2021 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import bpy +import olca +import ifcopenshell + + +class CalculateLCA(bpy.types.Operator): + bl_idname = "bim.calculate_lca" + bl_label = "Calculate LCA" + bl_options = {"REGISTER", "UNDO"} + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + filter_glob: bpy.props.StringProperty(default="*.xlsx", options={"HIDDEN"}) + + def execute(self, context): + props = context.scene.BIMLCAProperties + client = olca.Client(context.preferences.addons["blenderbim"].preferences.openlca_port) + setup = olca.CalculationSetup() + setup.calculation_type = olca.CalculationType.SIMPLE_CALCULATION + setup.impact_method = client.find(olca.ImpactMethod, "CML-IA baseline") + setup.product_system = client.find(olca.ProductSystem, props.product_systems) + setup.amount = props.amount + result = client.calculate(setup) + client.excel_export(result, self.filepath) + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} diff --git a/src/blenderbim/blenderbim/bim/module/lca/prop.py b/src/blenderbim/blenderbim/bim/module/lca/prop.py new file mode 100644 index 0000000000..90c3b77f9d --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/lca/prop.py @@ -0,0 +1,58 @@ + +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2020, 2021 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import bpy +import olca +from blenderbim.bim.prop import StrProperty, Attribute +from bpy.types import PropertyGroup +from bpy.props import ( + PointerProperty, + StringProperty, + EnumProperty, + BoolProperty, + IntProperty, + FloatProperty, + FloatVectorProperty, + CollectionProperty, +) + +productsystems_enum = [] + + +def purge(): + global productsystems_enum + productsystems_enum = [] + + +def get_product_systems(self, context): + global productsystems_enum + if not len(productsystems_enum): + client = olca.Client(context.preferences.addons["blenderbim"].preferences.openlca_port) + try: + productsystems_enum = [ + (ps.name, ps.name, "") for ps in client.get_all(olca.ProductSystem) + ] + except: + pass + return productsystems_enum + + +class BIMLCAProperties(PropertyGroup): + amount: FloatProperty(name="Amount") + product_systems: EnumProperty(items=get_product_systems, name="Product Systems") diff --git a/src/blenderbim/blenderbim/bim/module/lca/ui.py b/src/blenderbim/blenderbim/bim/module/lca/ui.py new file mode 100644 index 0000000000..a48bf668b1 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/lca/ui.py @@ -0,0 +1,38 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2020, 2021 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import bpy +from bpy.types import Panel + + +class BIM_PT_lca(Panel): + bl_label = "BIM Life Cycle Assessment" + bl_idname = "BIM_PT_lca" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + + def draw(self, context): + props = context.scene.BIMLCAProperties + row = self.layout.row() + row.prop(props, "product_systems", text="") + row = self.layout.row() + row.prop(props, "amount", text="") + row = self.layout.row() + row.operator("bim.calculate_lca") diff --git a/src/blenderbim/blenderbim/bim/module/project/operator.py b/src/blenderbim/blenderbim/bim/module/project/operator.py index ea0c939c5c..600364a524 100644 --- a/src/blenderbim/blenderbim/bim/module/project/operator.py +++ b/src/blenderbim/blenderbim/bim/module/project/operator.py @@ -213,10 +213,11 @@ class ChangeLibraryElement(bpy.types.Operator): [ifc_classes.add(e.is_a()) for e in elements] self.props.library_elements.clear() if len(ifc_classes) == 1 and list(ifc_classes)[0] == self.element_name: - for name, element in sorted([(self.get_name(e), e) for e in elements]): + for name, ifc_definition_id in sorted([(self.get_name(e), e.id()) for e in elements]): new = self.props.library_elements.add() new.name = name - new.ifc_definition_id = element.id() + new.ifc_definition_id = ifc_definition_id + element = IfcStore.library_file.by_id(ifc_definition_id) if IfcStore.library_file.schema == "IFC2X3" or not IfcStore.library_file.by_type("IfcProjectLibrary"): new.is_declared = False elif getattr(element, "HasContext", None) and element.HasContext[0].RelatingContext.is_a( diff --git a/src/blenderbim/blenderbim/bim/ui.py b/src/blenderbim/blenderbim/bim/ui.py index cb06ed0c52..b67aeb3ba4 100644 --- a/src/blenderbim/blenderbim/bim/ui.py +++ b/src/blenderbim/blenderbim/bim/ui.py @@ -21,7 +21,7 @@ import os import bpy from . import ifc from bpy.types import Panel -from bpy.props import StringProperty, BoolProperty +from bpy.props import StringProperty, IntProperty, BoolProperty class BIM_PT_section_plane(Panel): @@ -73,6 +73,7 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): ) svg_command: StringProperty(name="SVG Command", description="E.g. [['firefox-bin', path]]") pdf_command: StringProperty(name="PDF Command", description="E.g. [['firefox-bin', path]]") + openlca_port: IntProperty(name="OpenLCA IPC Port", default=8080) should_hide_empty_props: BoolProperty(name="Should Hide Empty Properties", default=True) should_play_chaching_sound: BoolProperty( name="Should Make A Cha-Ching Sound When Project Costs Updates", default=False @@ -105,7 +106,11 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): row = layout.row() row.prop(self, "pdf_command") row = layout.row() + row.prop(self, "openlca_port") + row = layout.row() row.prop(self, "should_hide_empty_props") + row = layout.row() + row.prop(self, "should_play_chaching_sound") def ifc_units(self, context):