add titlepage and tempaltes depend on each-other
This commit is contained in:
parent
e61c03ce2b
commit
956e199f61
9
src/wireviz/templates/bom.html
generated
9
src/wireviz/templates/bom.html
generated
@ -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 {
|
||||
|
||||
108
src/wireviz/templates/din-6771.html
generated
108
src/wireviz/templates/din-6771.html
generated
@ -1,57 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta name="generator" content=" {{ generator }}">
|
||||
<title> {{ title }}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: {{ fontname }};
|
||||
background-color: {{ bgcolor }};
|
||||
}
|
||||
|
||||
table, td, th, #frame {
|
||||
border: 0.35mm solid black; /* line weight based on DIN 15 */
|
||||
}
|
||||
|
||||
table {
|
||||
padding: 0;
|
||||
border-bottom: 0;
|
||||
border-right: 0;
|
||||
border-spacing: 0mm;
|
||||
}
|
||||
|
||||
td, th {
|
||||
border-top: 0;
|
||||
border-left: 0;
|
||||
|
||||
overflow: hidden;
|
||||
/* display: inline-block; */
|
||||
white-space: nowrap;
|
||||
font-size: 2.8mm;
|
||||
}
|
||||
|
||||
/* Canvas size based on DIN 823 / DIN 6771 / EN ISO 5457 */
|
||||
|
||||
#frame {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.A4 { /* portrait */
|
||||
width: 180mm;
|
||||
height: 277mm;
|
||||
}
|
||||
|
||||
.A3 { /* landscape */
|
||||
width: 390mm;
|
||||
height: 277mm;
|
||||
}
|
||||
|
||||
.A2 { /* landscape */
|
||||
width: 564mm;
|
||||
height: 400mm;
|
||||
}
|
||||
{% extends "page.html" %}
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
{% block extra_head_style %}
|
||||
<style>
|
||||
|
||||
/* custom count of rows depending on the sheetsize */
|
||||
{% if not show_bom %}
|
||||
@ -86,44 +36,20 @@
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
</style>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
</style>
|
||||
<style type="text/css" media="print">
|
||||
{% block frame_content %}
|
||||
<div id="diagram">
|
||||
{{ diagram }}
|
||||
</div>
|
||||
|
||||
@page {
|
||||
size: {{ sheetsize }} {{ orientation }};
|
||||
margin: 0;
|
||||
}
|
||||
{% if show_notes %}
|
||||
{{ notes }}
|
||||
{% endif %}
|
||||
|
||||
#page {
|
||||
margin-top: 10mm;
|
||||
margin-left: 15mm; /* TODO: maybe scale this value depending on sheetsize */
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
<div id="frame" class={{ sheetsize }}>
|
||||
<div id="description">
|
||||
{{ description }}
|
||||
</div>
|
||||
|
||||
<div id="diagram">
|
||||
{{ diagram }}
|
||||
</div>
|
||||
|
||||
{% if show_notes %}
|
||||
{{ notes }}
|
||||
{% endif %}
|
||||
|
||||
{% if show_bom %}
|
||||
{{ bom }}
|
||||
{% endif %}
|
||||
|
||||
{{ titleblock }}
|
||||
</div> <!-- /frame -->
|
||||
</div> <!-- /page -->
|
||||
</body>
|
||||
</html>
|
||||
{% if show_bom %}
|
||||
{{ bom }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
4
src/wireviz/templates/notes.html
generated
4
src/wireviz/templates/notes.html
generated
@ -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 %}
|
||||
}
|
||||
|
||||
|
||||
84
src/wireviz/templates/page.html
generated
Normal file
84
src/wireviz/templates/page.html
generated
Normal file
@ -0,0 +1,84 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta name="generator" content=" {{ generator }}">
|
||||
<title> {% block page_title %} Page {% endblock %} </title>
|
||||
<style>
|
||||
body {
|
||||
font-family: {{ fontname }};
|
||||
background-color: {{ bgcolor }};
|
||||
}
|
||||
/* Canvas size based on DIN 823 / DIN 6771 / EN ISO 5457 */
|
||||
|
||||
#frame {
|
||||
position: relative;
|
||||
border: 0.35mm solid black; /* line weight based on DIN 15 */
|
||||
}
|
||||
|
||||
.A4 { /* portrait */
|
||||
width: 180mm;
|
||||
height: 277mm;
|
||||
}
|
||||
|
||||
.A3 { /* landscape */
|
||||
width: 390mm;
|
||||
height: 277mm;
|
||||
}
|
||||
|
||||
.A2 { /* landscape */
|
||||
width: 564mm;
|
||||
height: 400mm;
|
||||
}
|
||||
|
||||
table, td, th {
|
||||
border: 0.35mm solid black; /* line weight based on DIN 15 */
|
||||
}
|
||||
|
||||
table {
|
||||
padding: 0;
|
||||
border-bottom: 0;
|
||||
border-right: 0;
|
||||
border-spacing: 0mm;
|
||||
}
|
||||
|
||||
td, th {
|
||||
border-top: 0;
|
||||
border-left: 0;
|
||||
|
||||
overflow: hidden;
|
||||
/* display: inline-block; */
|
||||
white-space: nowrap;
|
||||
font-size: 2.8mm;
|
||||
}
|
||||
|
||||
{% set bottom_rows = titleblock_rows + 1 %}
|
||||
|
||||
</style>
|
||||
{% block extra_head_style %}
|
||||
{% endblock %}
|
||||
<style type="text/css" media="print">
|
||||
|
||||
@page {
|
||||
size: {{ sheetsize }} {{ orientation }};
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#page {
|
||||
margin-top: 10mm;
|
||||
margin-left: 15mm; /* TODO: maybe scale this value depending on sheetsize */
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="page">
|
||||
<div id="frame" class={{ sheetsize }}>
|
||||
{% block frame_content %} {% endblock %}
|
||||
{{ titleblock }}
|
||||
</div> <!-- /frame -->
|
||||
</div> <!-- /page -->
|
||||
</body>
|
||||
</html>
|
||||
4
src/wireviz/templates/titleblock.html
generated
4
src/wireviz/templates/titleblock.html
generated
@ -1,4 +1,8 @@
|
||||
<style>
|
||||
.A4 #titleblock { /* Need to force width on A4 paper */
|
||||
width:180mm;
|
||||
}
|
||||
|
||||
#titleblock {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
|
||||
17
src/wireviz/templates/titlepage.html
generated
Normal file
17
src/wireviz/templates/titlepage.html
generated
Normal file
@ -0,0 +1,17 @@
|
||||
{% extends "page.html" %}
|
||||
{% block title %}titlepage {{ title }}{% endblock %}
|
||||
{% block extra_head_style %}
|
||||
<style>
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block frame_content %}
|
||||
<h1> {{ title }} </h1>
|
||||
{% if show_notes %}
|
||||
{{ notes }}
|
||||
{% endif %}
|
||||
|
||||
{% if show_bom %}
|
||||
{{ bom }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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 [^?>]*[?]>[^<]*<!DOCTYPE [^>]*>",
|
||||
"<!-- XML and DOCTYPE declarations from SVG file removed -->",
|
||||
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 [^?>]*[?]>[^<]*<!DOCTYPE [^>]*>",
|
||||
"<!-- XML and DOCTYPE declarations from SVG file removed -->",
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user