← Back to team overview

kicad-developers team mailing list archive

Re: Are there some web code for online schematic & PCB reader?

 

You can plot a schematic sheet as SVG, and pcbnew has a file->export SVG,
at least in the latest version.

A while ago I made a python script generate an html page with all the
sheets in svg format and clicking the sub-sheets of the first page (top
level) it jumps to that sheet in the hierarchy, an example is attached, we
didn't have the time to finish it.



Marcos

On Thu, Aug 6, 2015 at 7:25 AM, timofonic timofonic <timofonic@xxxxxxxxx>
wrote:

> Hello.
>
> I want to make a personal blog for documenting my experience on an
> electronics course. I plan to switch to KiCad, but I'm still trying to
> adapt and I still miss full Eagle interoperability.
>
> I want to embed my future KiCad designs on blog posts without the need to
> export images, preferably generating SVG images.
>
> Are there some kind of KiCad reader for web browsers with available source
> code? If not, does someone have plans to develop it?
>
> Kind regards.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
>

Attachment: page.zip
Description: Zip archive

#!/usr/bin/env python

import subprocess
import shutil
import glob
import sys
import os
import re

dpi=90
scale_inch = 0.001

re_exp = r'\$Sheet\nS\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+).*?\nF0\s+(\S+)\s+\d+.*?F1\s+(\S+)'

html_head = '<html><body>\n'
img_text = '  <img src="%s.png" usemap="#%s_map" id="%s_ref">\n'
map_head = '  <map name="%s_map">\n'
map_text = '    <area shape="rect" coords="%d, %d, %d, %d" href="#%s-%s_ref">\n'
map_foot = '  </map>\n'
html_foot = '</body></html>\n'

if len(sys.argv) < 4:
  print "Usage python %s <svg image path> <schematic top.sch> <out path>" % sys.argv[0]
  exit()

img_path = sys.argv[1]
fin = sys.argv[2]
out_path = sys.argv[3]

if not os.path.isdir(out_path):
  if os.path.exists(out_path):
    shutil.rmtree(out_path)
  os.mkdir(out_path)

images = []
for f in glob.iglob(os.path.join(img_path, '*.svg')):
  fout = os.path.join(out_path, os.path.basename(f.replace('.svg', '.png')))
  if not os.path.exists(fout):
    subprocess.call(['inkscape', '-z', '-f', f, '-j', '-e', fout, '-d', str(dpi)])
  images.append(os.path.basename(fout))

top_sheet = os.path.basename(fin.replace('.sch', '.png'))

if top_sheet in images:
  images.remove(top_sheet)
  images = [top_sheet] + images

html_out = os.path.join(out_path, 'index.html')
print "Creating %s" % html_out

rects = list
with open(html_out, 'wt') as out:
  out.write(html_head)
  for img_name in images:
    fname = img_name.replace('.png', '')
    out.write(img_text % (fname, fname, fname))
  with open(fin, 'rt') as top:
    fname = top_sheet.replace('.png', '')
    out.write(map_head % fname)
    for m in re.findall(re_exp, top.read(), re.MULTILINE|re.DOTALL):
      ts_x, ts_y, ts_w, ts_h, name, sch = m
      s_x, s_y, s_w, s_h = map(lambda x: int(x), [ts_x, ts_y, ts_w, ts_h])
      x1, y1, x2, y2 = map(lambda x: int(x*scale_inch*dpi), [s_x, s_y, s_x+s_w, s_y+s_h])
      sheet = name.replace('"', '')
      sheet_f = sch.replace('.sch', '').replace('"', '')
      map_out = map_text % (x1, y1, x2, y2, sheet_f, sheet)
      out.write(map_out)
    out.write(map_foot)
  out.write(html_foot)
print "Done!"

Follow ups

References