TinyTapeout / xschem-viewer

Online viewer of Xschem schematic files
https://xschem-viewer.com/
Apache License 2.0
20 stars 1 forks source link

one of the xschem provided example circuits does not load #1

Closed StefanSchippers closed 5 months ago

StefanSchippers commented 5 months ago

if I try to load this: https://xschem-viewer.com/?file=https://github.com/StefanSchippers/xschem/blob/master/xschem_library/examples/mos_power_ampli.sch get the following error: Error loading https://github.com/StefanSchippers/xschem/blob/master/xschem_library/examples/mos_power_ampli.sch: SyntaxError: Expected "\"" or "\\\\" but "[" found.

expected is this: 1

StefanSchippers commented 5 months ago

The following simpler example does not cause errors but only wires are rendered: https://xschem-viewer.com/?file=https://github.com/StefanSchippers/xschem/blob/master/xschem_library/examples/osc.sch 1

expected is this: 2

urish commented 5 months ago

Thanks for reporting!

I believe I fixed the first issue.

As for the second issue, it happens because the viewer can't find the referenced files in the same folder (e.g. lab_pin.sym or capa.sym). I'm not sure what the lookup algorithm for files would be?

Currently, we have a list of known prefixes, and we map them for URLs where to look for files. This works well for all of the examples from the sky130 PDK that I've tried so far:

https://github.com/TinyTapeout/xschem-viewer/blob/a0c8bc52d423983be6898e101db0f3726b1d9b05/src/index.ts#L29-L54

StefanSchippers commented 5 months ago

Hi, most xschem schematics have some basic symbols (like a voltage source, vsource.sym) or net labels (lab_wire.sym or lab_pin.sym) or circuit in/out pins (ipin.sym, opin.sym, iopin.sym) , ideal resistors (res.sym), ideal capacitors (capa.sym) and so on. These symbols are referenced either directly ( component lines like C {lab_pin.sym) .... or with a devices/ prefix (C {devices/lab_pin.sym} ... ). I suggest you look up these in this directory, which is a standard component of xschem. You can either keep a local copy of it or get it pulled from the repository, it is not going to change much over time, its pretty stable.

In some xschem user setups the library search path goes down to the devices/ directory (first component line example) or one level above (like in sky130 setups, second component line example).

urish commented 5 months ago

Thanks for explaining! So now the second issue is also fixed - if the component path doesn't include any "/", and we can't find the file in the same directory as the schematic, we look for them under devices/ as a fallback.

Good point regarding pulling the devices - at some point we might cache the devices them at build time, to speed up the loading time of the viewer.

StefanSchippers commented 5 months ago

Nice work! if you have some doubts about the xschem file format or anything related just let me know!

urish commented 5 months ago

Thanks! I was actually wondering about graphs. I see they are represented as a box with a graph flag, e.g.

B 2 1400 -440 1660 -260 {flags=graph
y1=0
y2=170
divy=4
subdivy=1
x1=0.0247231
x2=0.0249981
divx=8
subdivx=4
dataset=0
unitx=m

color="8 7"
node="tcleval(\\"Xm1 power;vpp $\{path\}outi - i(v.$\{path\}vu) *\\"
\\"Average;vpp $\{path\}outi - i(v.$\{path\}vu) * 200u ravg()\\")"
jpeg_quality=30
xlabmag=1.4}

but I couldn't find any documentation on what the other properties means and what options are available.

StefanSchippers commented 5 months ago

Graphs are used to view simulation results. They are just rectangles on layer 2, some attributes specify it is a graph (the flags attribute, the X/Y range to display (x1, x2, y1, y2) the number of grid divisions (with axis labels) and subdivisions for X and Y (divx, subdivx, divy, subdivy) unit multipliers (unitx, unity), the simulation nodes to display (node="...") and the colors (if specified, color="...") there are some other attributes to specify the quality in pdf/svg exports (simulation data can contain 100000 points, I can not dump these as vector graphics, so graphs are rasterized). My suggestion is to skip these rectangles altogether. (so if you see flags=graph --> skip) at least in the initial development. You need simulation data anyway to get anything useful displayed. Xschem also has an option to hide completely these boxes if no data is loaded.

There is another box container that holds image data, just simple png images with data encoded as a text base64 attribute (image_data=".....") . These can be rendered easily ina browser, I think. these have these flags:

flags=image,unscaled
alpha=0.7
image_data=iVBORw...long_string_of_base64_encoded_text_sdhkldshfgdghdg

the unscaled optional modifier tells the image is placed scaled one to one in the xschem schematic and user can not scale it. Otherwise it is just like other rectangles and can be resized/stretched at will.

Image containers are supposed to be used to place company logos and other small pictures. Do not expect any good performance by embedding a 16k UUUHD image !

Thes containers are compatible additions to the core xschem objects. if I load a schematic with graphs and images with an older xschem version it will just show empty grey rectangles , ignoring the attributes defined therein.

In some cases I have placed an image of a schematic found may be in a datasheet or in a book with a low alpha value so it will be transparent, then set attribute lock=true (so it can not be moved / selected) and used the background to draw the xschem schematic on top of it.

StefanSchippers commented 5 months ago

Also as a suggestion I think you can at least temporarily skip the @#*:net_name and @#*:pinnumber attributes, these are documented here (search for "PREDEFINED SYMBOL VALUES" ) and are very rarely used.

urish commented 5 months ago

Now it makes sense! Well, we just show grey rectangles instead of graphs. Do you think it's better just to hide them?

Also as a suggestion I think you can at least temporarily skip the @#:net_name and @#:pinnumber attributes

skip as in just replace them with an empty string?

StefanSchippers commented 5 months ago

Yes , If no data is displayed its better to skip. 1 see xschem menu on the bottom

StefanSchippers commented 5 months ago

skip as in just replace them with an empty string?

Yes, so you have less junk. These are really low priority, so keep a comment in thecode for future improvements. I see there are some issues with rotated / mirrored symbols so this has higher priority. my opinion of course.

urish commented 5 months ago

Alright, graphs hidden. Feel free to open a new issue for anything you find about rotated / mirrored symbols