IfcCSV can now create summary rows (e.g. total, average) at the end of the table (may or may not be in addition to group totals).

This commit is contained in:
Dion Moult
2023-08-22 21:04:59 +10:00
parent 5e36255efe
commit e6e364780b
4 changed files with 141 additions and 70 deletions
@@ -82,6 +82,7 @@ class ImportCsvAttributes(bpy.types.Operator):
new.header = attribute["header"]
new.sort = attribute["sort"]
new.group = attribute["group"]
new.summary = attribute["summary"]
return {"FINISHED"}
def invoke(self, context, event):
@@ -104,7 +105,8 @@ class ExportCsvAttributes(bpy.types.Operator):
data = {
"query": tool.Search.export_filter_query(props.filter_groups),
"attributes": [
{"name": a.name, "header": a.header, "sort": a.sort, "group": a.group} for a in props.csv_attributes
{"name": a.name, "header": a.header, "sort": a.sort, "group": a.group, "summary": a.summary}
for a in props.csv_attributes
],
}
@@ -152,11 +154,14 @@ class ExportIfcCsv(bpy.types.Operator):
sort = []
groups = []
summaries = []
for attribute in props.csv_attributes:
if attribute.sort != "NONE":
sort.append({"name": attribute.name, "order": attribute.sort})
if attribute.group != "NONE":
groups.append({"name": attribute.name, "type": attribute.group, "varies_value": attribute.varies_value})
if attribute.summary != "NONE":
summaries.append({"name": attribute.name, "type": attribute.summary})
sep = props.csv_custom_delimiter if props.csv_delimiter == "CUSTOM" else props.csv_delimiter
ifc_csv.export(
@@ -174,6 +179,7 @@ class ExportIfcCsv(bpy.types.Operator):
bool_false=props.false_value,
sort=sort,
groups=groups,
summaries=summaries,
)
return {"FINISHED"}
@@ -49,6 +49,15 @@ class CsvAttribute(PropertyGroup):
]
)
varies_value: StringProperty(default="Varies", name="Varies Value")
summary: EnumProperty(
items=[
("NONE", "None", ""),
("SUM", "Sum", "Sums the total value of all rows."),
("AVERAGE", "Average", "Averages the total value of all rows."),
("MIN", "Min", "Gets the minimum value of all rows."),
("MAX", "Max", "Gets the maximum value of all rows."),
]
)
class CsvProperties(PropertyGroup):
@@ -96,4 +105,5 @@ class CsvProperties(PropertyGroup):
should_show_settings: BoolProperty(default=False, name="Show Settings")
should_show_sort: BoolProperty(default=False, name="Show Sorting")
should_show_group: BoolProperty(default=False, name="Show Grouping")
should_show_summary: BoolProperty(default=False, name="Show Summary")
should_load_from_memory: BoolProperty(default=False, name="Load from Memory")
@@ -47,8 +47,6 @@ class BIM_PT_ifccsv(Panel):
row.alignment = "RIGHT"
row.operator("bim.import_csv_attributes", icon="IMPORT", text="")
row.operator("bim.export_csv_attributes", icon="EXPORT", text="")
row.prop(props, "should_show_sort", icon="SORTSIZE", text="")
row.prop(props, "should_show_group", icon="OUTLINER_COLLECTION", text="")
row.prop(props, "should_show_settings", icon="PREFERENCES", text="")
if not IfcStore.get_file() or not props.should_load_from_memory:
@@ -85,17 +83,22 @@ class BIM_PT_ifccsv(Panel):
row = layout.row(align=True)
row.operator("bim.add_csv_attribute", icon="ADD")
row.prop(props, "should_show_sort", icon="SORTSIZE", text="")
row.prop(props, "should_show_group", icon="OUTLINER_COLLECTION", text="")
row.prop(props, "should_show_summary", icon="SYNTAX_ON", text="")
for index, attribute in enumerate(props.csv_attributes):
row = layout.row(align=True)
row.prop(attribute, "name", text="")
row.prop(attribute, "header", text="")
if props.should_show_sort:
row.prop(attribute, "sort", text="")
if props.should_show_group:
row.prop(attribute, "group", text="")
if attribute.group == "VARIES":
row.prop(attribute, "varies_value", text="")
row.prop(attribute, "header", text="")
if props.should_show_summary:
row.prop(attribute, "summary", text="")
row.operator("bim.remove_csv_attribute", icon="X", text="").index = index
row = layout.row(align=True)