Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve output of diagram + BOM as technical drawing #74

Closed
wants to merge 14 commits into from

Conversation

formatc1702
Copy link
Collaborator

@formatc1702 formatc1702 commented Jul 9, 2020

Closes #32.

@SchrodingersGat
Copy link

Hi @formatc1702 I just found your project, and I really like what you have done here!

Is there any progress on this particular branch, with particular regard to adding document metadata and title block information? This addition, and also PDF output, would make this tool extremely useful to me (and many others, I'm sure) in a professional setting.

  • Do you need any assistance getting this branch back up to speed with master?
  • Have you selected a PDF generation engine?

I'd love to help out if I can. I see a lot of value in this project :)

@kvid
Copy link
Collaborator

kvid commented Mar 19, 2021

Is there any progress on this particular branch, with particular regard to adding document metadata and title block information?

About the YAML metadata input, see also PR #214, where I've added a few basic metadata attributes based on #158 (comment) and other comments about the same issue.

@SchrodingersGat
Copy link

Nice, I'd like to also see features like:

  • Company
  • Author
  • Revision Information

@formatc1702
Copy link
Collaborator Author

Hi @SchrodingersGat

Is there any progress on this particular branch, with particular regard to adding document metadata and title block information? This addition, and also PDF output, would make this tool extremely useful to me (and many others, I'm sure) in a professional setting.

I'd love to help out if I can. I see a lot of value in this project :)

Thanks!

* Do you need any assistance getting this branch back up to speed with master?

I plan on resuming work on this branch soon, should not be a big deal.
The plan is to keep this PR simple: generate HTML based on a template, include the A3 and A4 templates as per the screenshots in #32, as well as a default template (similar to now, simply the image and a BOM table below), and have a metadata option (see #214) in the YAML to specify which template to use, either from the built-in ones, or a user-specified path.

I will then welcome subsequent PRs for, among other things:

  • generating a PDF based on the HTML (I'd like to stick to HTML+CSS for creating the templates because it is widely used and very flexible)
  • improving the HTML templates in general
  • everything else ;-)
* Have you selected a PDF generation engine?

No, this is an area where I am very open to input. As mentioned above, I will split PDF generation as a separate issue/PR.

- `simple.html` is similar to the previous built-in HTML output
- `din-6771.html` is a technical drawing with title block and BOM
@formatc1702 formatc1702 removed the WIP Work in progress label Mar 27, 2021
@formatc1702 formatc1702 marked this pull request as ready for review March 27, 2021 12:48
@formatc1702
Copy link
Collaborator Author

formatc1702 commented Mar 27, 2021

This PR has been updated, and is currently based on #214 plus some modifications. Once #214 is completed (including updated syntax documentation) and merged, this PR will be adapted and should be ready shortly afterwards. I will wait with writing syntax documentation for this PR until #214 is done.

@formatc1702 formatc1702 changed the base branch from dev to feature/metadata March 27, 2021 12:52
@formatc1702 formatc1702 requested a review from kvid March 27, 2021 13:00
@formatc1702
Copy link
Collaborator Author

formatc1702 commented Mar 27, 2021

Test files:

Modified `demo01.yml`
metadata:
  title: WireViz Demo 01
  pn: 123-456-789

  authors:
    Created:
      name:  D. Rojas
      date:  2020-05-20
    Approved:
      name:  D. Rojas
      date:  2020-05-20

  template:
    name: din-6771
    sheetsize: A4

connectors:
  X1:
    type: D-Sub
    subtype: female
    pinlabels: [DCD, RX, TX, DTR, GND, DSR, RTS, CTS, RI]
  X2:
    type: Molex KK 254
    subtype: female
    pinlabels: [GND, RX, TX]

cables:
  W1:
    gauge: 0.25 mm2
    length: 0.2
    color_code: DIN
    wirecount: 3
    shield: true

connections:
  -
    - X1: [5,2,3]
    - W1: [1,2,3]
    - X2: [1,3,2]
  -
    - X1: 5
    - W1: s
Modified `demo02.yml`
metadata:
  title: WireViz Demo 02
  pn: 123-456-789

  authors:
    Created:
      name:  D. Rojas
      date:  2020-05-20
    Approved:
      name:  D. Rojas
      date:  2020-05-20

  revisions:
    01:
      changelog: Add ferrules
      name: D. Rojas
      date: 2020-06-14
    02:
      changelog: Add ferrules
      name: D. Rojas
      date: 2020-06-14

  template:
    name: din-6771
    sheetsize: A3

templates: # defining templates to be used later on
  - &molex_f
    type: Molex KK 254
    subtype: female
  - &con_i2c
    pinlabels: [GND, +5V, SCL, SDA]
  - &wire_i2c
    category: bundle
    gauge: 0.14 mm2
    colors: [BK, RD, YE, GN]

connectors:
  X1:
    <<: *molex_f # copying items from the template
    pinlabels: [GND, +5V, SCL, SDA, MISO, MOSI, SCK, N/C]
  X2:
    <<: *molex_f
    <<: *con_i2c # it is possible to copy from more than one template
  X3:
    <<: *molex_f
    <<: *con_i2c
  X4:
    <<: *molex_f
    pinlabels: [GND, +12V, MISO, MOSI, SCK]
  ferrule_crimp:
    style: simple
    autogenerate: true
    type: Crimp ferrule
    subtype: 0.25 mm²
    color: YE

cables:
  W1:
    <<: *wire_i2c
    length: 0.2
    show_equiv: true
  W2:
    <<: *wire_i2c
    length: 0.4
    show_equiv: true
  W3:
    category: bundle
    gauge: 0.14 mm2
    length: 0.3
    colors: [BK, BU, OG, VT]
    show_equiv: true
  W4:
    gauge: 0.25 mm2
    length: 0.3
    colors: [BK, RD]
    show_equiv: true

connections:
  -
    - X1: [1-4]
    - W1: [1-4]
    - X2: [1-4]
  -
    - X1: [1-4]
    - W2: [1-4]
    - X3: [1-4]
  -
    - X1: [1,5-7]
    - W3: [1-4]
    - X4: [1,3-5]
  -
    - ferrule_crimp
    - W4: [1,2]
    - X4: [1,2]

I want to keep the actual demo files unchanged for simplicity.

elif isinstance(value, Dict): # useful for authors, revisions
for index, (category, entry) in enumerate(value.items()):
if isinstance(entry, Dict):
html = html.replace(f'<!-- %{item}_{index+1}% -->', str(category))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using {index+1} instead of {category} here to be able to use more generic labels in the HTML template.

This way, for example, <!-- %revisions_1_changelog% --> and <!-- %authors_1_name% --> are always replaced correctly, no matter if the user tracks revisions using numbers, letters (A, B, C, ...) or other, or if they use a different authorsship scheme instead of the Created and Approved that I have used in my examples.

@MicahStevens
Copy link

MicahStevens commented Mar 23, 2022

@formatc1702 If it were me, I'd use an html template engine (Jinja2 comes to mind) instead of writing your own here. It allows a lot of nice features and gives the template creator a bunch of tools.

  • Template hierarchy
  • Block overrides, i.e. a sub-template can just override one section of the template instead of the whole thing, so for example they could modify the title block and not have to try and parse that out of the wire diagram stuff.
  • loops and basic logic in the template, allowing for a lot more flexibility in terms of list data (BOM, Revisions, etc) instead of complicating wireviz itself.

I would be curious if you have any issues with this approach, it does require yet another module to be included of course, which would by my only issue.

Thanks for the great tool BTW, I'm using this at work now, and it's awesome. I just don't like my workflow step of importing the PNG into another tool for the title block for obvious reasons.

Edit: Here's an example of one of my other tools using Jinja to create a PDF using PDFKit, a wrapper for wkhtmltopdf:

        template_loader = jinja2.FileSystemLoader([path.join(path.dirname(__file__), 'templates')])
        template_env = jinja2.Environment(loader=template_loader)
        template_file = "moduleQATemplate.j2"
        template = template_env.get_template(template_file)
        
        output_text = template.render(
            serialnum=serial,
            dt=testdate,
            bankV=bankV,
            bank_OCV=bank_OCV,
            bank_ESR=bank_ESR,
            module_ESR=round(module_ESR, 3),
            loaded_deltav=loaded_deltav,
            testername=self.inputs.get('testername'),
            moduleV=module_OCV,
            esrloadcurrent=self.esrloadcurrent,
            temps=start_temps,
            passfail=self.passing,
            notes=notes,
            logo=logoimage,
            images=images,
            testlog=self.testlog
            )

        
        if path.isdir("N:\\"):
            pdf_path = path.join("N:\\", "Battery","Test","ModuleReports",f"Module_{serial}_{testdatesafe}.pdf")
        else:
            pdf_path = path.join(environ["HOMEPATH"], "Desktop", F"Module_{serial}_{testdatesafe}.pdf")

        options = {
            'page-size': 'Letter',
            'margin-top': '0.35in',
            'margin-right': '0.75in',
            'margin-bottom': '0.75in',
            'margin-left': '0.75in',
            'encoding': "UTF-8",
            'no-outline': None,
            'enable-local-file-access': None,
            'quiet': False
        }
        self.logHeader(f"Writing report to: {pdf_path}")
        config = pdfkit.configuration(wkhtmltopdf="C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe")
        pdfkit.from_string(output_text, pdf_path, options=options, configuration=config)

@kvid
Copy link
Collaborator

kvid commented Mar 27, 2022

The latest development of such a feature is moved to PR #239, and this PR is closed. I therefore suggest you rather make your comments to that new PR. I like your idea, and I hope the author considers it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants