diff --git a/src/wireviz/templates/bom.html b/src/wireviz/templates/bom.html index dbf7ef3..b019d57 100644 --- a/src/wireviz/templates/bom.html +++ b/src/wireviz/templates/bom.html @@ -3,16 +3,17 @@ position: absolute; bottom: {{ (titleblock_rows + 1) * 4.25 }}mm; right: 0; + width:180mm; } .A3 #bom, .A2 #bom { /* BOM to the left of title block */ position: absolute; + {% if bom_updated_position %} + {{ bom_updated_position }} + {% else %} bottom: 0mm; left: 0mm; - } - - #bom table { - width:180mm; + {% endif %} } #bom tr { diff --git a/src/wireviz/templates/din-6771.html b/src/wireviz/templates/din-6771.html index e576a47..a2832ad 100644 --- a/src/wireviz/templates/din-6771.html +++ b/src/wireviz/templates/din-6771.html @@ -1,57 +1,7 @@ - - - - - - - {{ title }} - +{% endblock %} - - - - -
-
-
- {{ description }} -
- -
- {{ diagram }} -
- - {% if show_notes %} - {{ notes }} - {% endif %} - - {% if show_bom %} - {{ bom }} - {% endif %} - - {{ titleblock }} -
-
- - + {% if show_bom %} + {{ bom }} + {% endif %} +{% endblock %} diff --git a/src/wireviz/templates/notes.html b/src/wireviz/templates/notes.html index a9f2324..01ff507 100644 --- a/src/wireviz/templates/notes.html +++ b/src/wireviz/templates/notes.html @@ -12,15 +12,15 @@ .A3 #notes, .A2 #notes { /* NOTES on top of title block */ position: absolute; {% if notes_on_right %} - bottom: {{ (titleblock_rows + 1) * 4.25 }}mm; right: 0; + bottom: {{ (titleblock_rows + 1) * 4.25 }}mm; {% else %} + left: 0; {% if show_bom %} bottom: {{ (bom_rows + 1) * 4.25 }}mm; {% else %} bottom: 0; {% endif %} - left: 0; {% endif %} } diff --git a/src/wireviz/templates/page.html b/src/wireviz/templates/page.html new file mode 100644 index 0000000..61ab054 --- /dev/null +++ b/src/wireviz/templates/page.html @@ -0,0 +1,84 @@ + + + + + + + {% block page_title %} Page {% endblock %} + + {% block extra_head_style %} + {% endblock %} + + + + +
+
+ {% block frame_content %} {% endblock %} + {{ titleblock }} +
+
+ + diff --git a/src/wireviz/templates/titleblock.html b/src/wireviz/templates/titleblock.html index c4edcee..3909222 100644 --- a/src/wireviz/templates/titleblock.html +++ b/src/wireviz/templates/titleblock.html @@ -1,4 +1,8 @@ +{% endblock %} + +{% block frame_content %} +

{{ title }}

+ {% if show_notes %} + {{ notes }} + {% endif %} + + {% if show_bom %} + {{ bom }} + {% endif %} +{% endblock %} diff --git a/src/wireviz/wv_cli.py b/src/wireviz/wv_cli.py index 3c4f98c..8f39d11 100644 --- a/src/wireviz/wv_cli.py +++ b/src/wireviz/wv_cli.py @@ -6,15 +6,17 @@ from pathlib import Path import click + if __name__ == "__main__": sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) +import yaml + import wireviz.wireviz as wv from wireviz import APP_NAME, __version__ from wireviz.wv_bom import bom_list -from wireviz.wv_utils import bom2tsv -from wireviz.wv_harness_quantity import HarnessQuantity -from wireviz.wv_output import generate_pdf_output +from wireviz.wv_output import generate_pdf_output, generate_html_output, generate_shared_bom +from wireviz.wv_dataclasses import AUTOGENERATED_PREFIX, Metadata, Options format_codes = { "c": "csv", @@ -124,13 +126,18 @@ def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multi # determine output formats output_formats = {format_codes[f] for f in formats if f in format_codes} harness_output_formats = output_formats.copy() + create_titlepage = False # Only generate the global pdf if there's multiple files if len(files) > 1 and 'pdf' in harness_output_formats: harness_output_formats.remove('pdf') + create_titlepage = True + titlepage_path = (_output_dir / "titlepage").with_suffix(".html") harness = None shared_bom = {} sheet_current = 1 + if create_titlepage: + sheet_current += 1 output_names = [] # run WireVIz on each input file for _file in files: @@ -146,6 +153,8 @@ def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multi extra_metadata = {} extra_metadata["sheet_name"] = _output_name.upper() extra_metadata["sheet_total"] = len(files) + if create_titlepage: + extra_metadata["sheet_total"] += 1 extra_metadata["sheet_current"] = sheet_current sheet_current += 1 @@ -162,25 +171,48 @@ def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multi ) shared_bom = ret["shared_bom"] + shared_bom_base = None + if "shared_bom" in output_formats: + shared_bom_base, shared_bomlist = generate_shared_bom( + _output_dir, + shared_bom, + use_qty_multipliers=use_qty_multipliers, + files=files, + multiplier_file_name=multiplier_file_name, + ) + + # TODO: instead have a parse function that create a titlepage, not a harness + if ('html' in output_formats) and create_titlepage: + yaml_data_str = "\n".join(f.open("r").read() for f in prepend) + yaml_data = yaml.safe_load(yaml_data_str) + titlepage_metadata = { + **yaml_data.get("metadata", {}), + **extra_metadata, + "sheet_current": 1, + "sheet_name": "titlepage", + "output_name": "titlepage", + "bom_updated_position": "top: 20mm; left: 10mm", + "notes_width": "200mm", + } + titlepage_metadata['template']['name'] = 'titlepage' + titlepage_options = { + **yaml_data.get("options", {}), + "show_bom": True, + "show_notes": True, + } + generate_html_output( + titlepage_path, + bom = bom_list(shared_bom), + metadata = Metadata(**titlepage_metadata), # TBD what we need to add here + options = Options(**titlepage_options), + ) + if 'pdf' in output_formats and 'html' in output_formats and len(output_names) > 1: + if create_titlepage: + output_names.insert(0, titlepage_path) + generate_pdf_output(output_names) - # TODO: move shared bom generation to a method? - if "shared_bom" in output_formats: - shared_bom_file = (_output_dir / "shared_bom").with_suffix(".tsv") - print(f'Generating shared bom at {shared_bom_file}') - if use_qty_multipliers: - harnesses = HarnessQuantity(files, multiplier_file_name, output_dir=_output_dir) - harnesses.fetch_qty_multipliers_from_file() - qty_multipliers = harnesses.multipliers - print(f'Using quantity multipliers: {qty_multipliers}') - for bom_item in shared_bom.values(): - bom_item.scale_per_harness(qty_multipliers) - - shared_bomlist = bom_list(shared_bom, False) - - shared_bom_tsv = bom2tsv(shared_bomlist) - shared_bom_file.open("w").write(shared_bom_tsv) print() # blank line after execution diff --git a/src/wireviz/wv_output.py b/src/wireviz/wv_output.py index 20c80e3..0218372 100644 --- a/src/wireviz/wv_output.py +++ b/src/wireviz/wv_output.py @@ -9,7 +9,10 @@ import logging from weasyprint import HTML import wireviz # for doing wireviz.__file__ +from wireviz.wv_bom import bom_list +from wireviz.wv_utils import bom2tsv from wireviz.wv_dataclasses import Metadata, Options +from wireviz.wv_harness_quantity import HarnessQuantity from wireviz.wv_templates import get_template mime_subtype_replacements = {"jpg": "jpeg", "tif": "tiff"} @@ -81,6 +84,32 @@ def generate_pdf_output( all_pages = [p for doc in documents for p in doc.pages] documents[0].copy(all_pages).write_pdf(output_path) +def generate_shared_bom( + output_dir, + shared_bom, + use_qty_multipliers=False, + files=None, + multiplier_file_name=None, +): + shared_bom_base = output_dir / "shared_bom" + shared_bom_file = shared_bom_base.with_suffix(".tsv") + print(f'Generating shared bom at {shared_bom_base}') + + if use_qty_multipliers: + harnesses = HarnessQuantity(files, multiplier_file_name, output_dir=output_dir) + harnesses.fetch_qty_multipliers_from_file() + qty_multipliers = harnesses.multipliers + print(f'Using quantity multipliers: {qty_multipliers}') + for bom_item in shared_bom.values(): + bom_item.scale_per_harness(qty_multipliers) + + shared_bomlist = bom_list(shared_bom, False) + + shared_bom_tsv = bom2tsv(shared_bomlist) + shared_bom_file.open("w").write(shared_bom_tsv) + + return shared_bom_base, shared_bomlist + def generate_html_output( filename: Path, @@ -91,18 +120,20 @@ def generate_html_output( print("Generating html output") template_name = metadata.get("template", {}).get("name", "simple") - # embed SVG diagram - with filename.with_suffix(".svg").open("r") as f: - svgdata = re.sub( - "^<[?]xml [^?>]*[?]>[^<]*]*>", - "", - f.read(), - 1, - ) + svgdata = None + if template_name != 'titlepage': + # embed SVG diagram for all but the titlepage + with filename.with_suffix(".svg").open("r") as f: + svgdata = re.sub( + "^<[?]xml [^?>]*[?]>[^<]*]*>", + "", + f.read(), + 1, + ) # generate BOM table # generate BOM header (may be at the top or bottom of the table) - bom_reversed = False if template_name == "simple" else True + bom_reversed = False if template_name == "simple" or template_name == "titlepage" else True bom_header = bom[0] bom_columns = [ "bom_col_{}".format("id" if c == "#" else c.lower()) for c in bom_header