mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 02:07:36 +00:00
* Start quantity calculator implementation * Fix get qto_name
This commit is contained in:
@@ -27,6 +27,7 @@ classes = (
|
|||||||
operator.EditPset,
|
operator.EditPset,
|
||||||
operator.EnablePsetEditing,
|
operator.EnablePsetEditing,
|
||||||
operator.GuessQuantity,
|
operator.GuessQuantity,
|
||||||
|
operator.CalculateQuantity,
|
||||||
operator.GuessAllQuantities,
|
operator.GuessAllQuantities,
|
||||||
operator.RemovePset,
|
operator.RemovePset,
|
||||||
operator.TogglePsetExpansion,
|
operator.TogglePsetExpansion,
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
mapper = {
|
||||||
|
"Qto_WallBaseQuantities" : {
|
||||||
|
"Length" : "get_length",
|
||||||
|
"Width" : "get_width",
|
||||||
|
"Height" : "get_height",
|
||||||
|
},
|
||||||
|
"Qto_SlabBaseQuantities" : {
|
||||||
|
"Depth" : "get_height",
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -344,6 +344,44 @@ class AddQto(bpy.types.Operator, Operator):
|
|||||||
Data.load(IfcStore.get_file(), ifc_definition_id)
|
Data.load(IfcStore.get_file(), ifc_definition_id)
|
||||||
|
|
||||||
|
|
||||||
|
class CalculateQuantity(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.calculate_quantity"
|
||||||
|
bl_label = "Calculate Quantity"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
prop: bpy.props.StringProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
self.qto_calculator = QtoCalculator()
|
||||||
|
obj = context.active_object
|
||||||
|
prop = obj.PsetProperties.properties.get(self.prop)
|
||||||
|
prop.metadata.float_value = self.calculate_quantity(obj, context)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def calculate_quantity(self, obj, context):
|
||||||
|
quantity = self.qto_calculator.calculate_quantity(obj.PsetProperties.active_pset_name, self.prop, obj)
|
||||||
|
prefix, name = self.get_blender_prefix_name(context)
|
||||||
|
quantity = ifcopenshell.util.unit.convert(quantity, None, "METRE", prefix, name)
|
||||||
|
return round(quantity, 3)
|
||||||
|
|
||||||
|
def get_prefix_name(self, value):
|
||||||
|
if "/" in value:
|
||||||
|
return value.split("/")
|
||||||
|
return None, value
|
||||||
|
|
||||||
|
def get_blender_prefix_name(self, context):
|
||||||
|
unit_settings = context.scene.unit_settings
|
||||||
|
if unit_settings.system == "IMPERIAL":
|
||||||
|
if unit_settings.length_unit == "INCHES":
|
||||||
|
return None, "inch"
|
||||||
|
elif unit_settings.length_unit == "FEET":
|
||||||
|
return None, "foot"
|
||||||
|
elif unit_settings.system == "METRIC":
|
||||||
|
if unit_settings.length_unit == "METERS":
|
||||||
|
return None, "METRE"
|
||||||
|
return unit_settings.length_unit[0 : -len("METERS")], "METRE"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GuessQuantity(bpy.types.Operator):
|
class GuessQuantity(bpy.types.Operator):
|
||||||
bl_idname = "bim.guess_quantity"
|
bl_idname = "bim.guess_quantity"
|
||||||
bl_label = "Guess Quantity"
|
bl_label = "Guess Quantity"
|
||||||
|
|||||||
@@ -25,9 +25,23 @@ from shapely.geometry import Polygon
|
|||||||
from shapely.ops import unary_union
|
from shapely.ops import unary_union
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
from blenderbim.bim.module.pset.calc_quantity_function_mapper import mapper
|
||||||
|
|
||||||
|
|
||||||
class QtoCalculator:
|
class QtoCalculator:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.mapping_dict = {}
|
||||||
|
for key in mapper.keys():
|
||||||
|
self.mapping_dict[key] = dict(mapper[key].items())
|
||||||
|
|
||||||
|
for key in self.mapping_dict.keys():
|
||||||
|
for item in self.mapping_dict[key].keys():
|
||||||
|
self.mapping_dict[key][item] = eval("self." + self.mapping_dict[key][item])
|
||||||
|
|
||||||
|
def calculate_quantity(self, qto_name, quantity_name, obj):
|
||||||
|
return self.mapping_dict[qto_name][quantity_name](obj)
|
||||||
|
|
||||||
def guess_quantity(self, prop_name, alternative_prop_names, obj):
|
def guess_quantity(self, prop_name, alternative_prop_names, obj):
|
||||||
prop_name = prop_name.lower()
|
prop_name = prop_name.lower()
|
||||||
alternative_prop_names = [p.lower() for p in alternative_prop_names]
|
alternative_prop_names = [p.lower() for p in alternative_prop_names]
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
from bpy.types import Panel
|
from bpy.types import Panel
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim.helper import prop_with_search
|
from blenderbim.bim.helper import prop_with_search
|
||||||
|
from blenderbim.bim.module.pset.calc_quantity_function_mapper import mapper
|
||||||
from blenderbim.bim.module.pset.data import (
|
from blenderbim.bim.module.pset.data import (
|
||||||
ObjectPsetsData,
|
ObjectPsetsData,
|
||||||
ObjectQtosData,
|
ObjectQtosData,
|
||||||
@@ -139,6 +140,11 @@ def draw_psetqto_ui(context, pset_id, pset, props, layout, obj_type):
|
|||||||
def draw_psetqto_editable_ui(box, props, prop):
|
def draw_psetqto_editable_ui(box, props, prop):
|
||||||
row = box.row(align=True)
|
row = box.row(align=True)
|
||||||
draw_property(prop, row, copy_operator="bim.copy_property_to_selection")
|
draw_property(prop, row, copy_operator="bim.copy_property_to_selection")
|
||||||
|
qto_name = ObjectQtosData.data['qtos'][0]['Name']
|
||||||
|
if qto_name in mapper.keys():
|
||||||
|
if prop.name in mapper[qto_name]:
|
||||||
|
op = row.operator("bim.calculate_quantity", icon="MOD_EDGESPLIT", text="")
|
||||||
|
op.prop = prop.name
|
||||||
if (
|
if (
|
||||||
"length" in prop.name.lower()
|
"length" in prop.name.lower()
|
||||||
or "width" in prop.name.lower()
|
or "width" in prop.name.lower()
|
||||||
|
|||||||
Reference in New Issue
Block a user