devbisme / skidl

SKiDL is a module that extends Python with the ability to design electronic circuits.
https://devbisme.github.io/skidl/
MIT License
994 stars 118 forks source link

No-Connect Fix for SVG Export #207

Closed jmwright closed 2 months ago

jmwright commented 2 months ago

This should fix #123 but the code is not in the same compact style as the original. I get a different error after fixing this (see below), which I think might be related to the KiCAD refactor that seems to be happening on the main development branch. It is hard to be sure with my current lack of familiarity with this codebase though.

Traceback (most recent call last):
  File "/home/jwright/repos/skidl/src/skidl/skidlbaseobj.py", line 50, in __getattr__
    return self.__getattribute__("fields")[key]
KeyError: 'draw'
devbisme commented 2 months ago

Thanks for looking into this and offering a fix! You found the cause of the problem, after which I found a way to fix it with fewer changes to the code. Go ahead and test in the the development branch when you have the time. Thanks!

jmwright commented 2 months ago

@devbisme Thanks. The error reported in #123 seems to be gone on development, but the other error I posted above seems to be different now.

Traceback (most recent call last):
  File "/home/jwright/repos/skidl/src/skidl/skidlbaseobj.py", line 50, in __getattr__
    return self.__getattribute__("fields")[key]
KeyError: 'num_units'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jwright/Downloads/chlorophyll_skidl_trial/detector.py", line 17, in <module>
    generate_svg()
  File "/home/jwright/repos/skidl/src/skidl/circuit.py", line 980, in generate_svg
    f.write(self.generate_netlistsvg_skin(net_stubs=net_stubs))
  File "/home/jwright/repos/skidl/src/skidl/circuit.py", line 691, in generate_netlistsvg_skin
    part_svg[name] = part.generate_svg_component(
  File "/home/jwright/repos/skidl/src/skidl/part.py", line 1075, in generate_svg_component
    return tool_modules[tool].gen_svg_comp(self, symtx=symtx, net_stubs=net_stubs)
  File "/home/jwright/repos/skidl/src/skidl/tools/kicad6/gen_svg.py", line 419, in gen_svg_comp
    for unit in range(1, part.num_units):
  File "/home/jwright/repos/skidl/src/skidl/part.py", line 504, in __getattr__
    return SkidlBaseObject.__getattr__(self, attr)
  File "/home/jwright/repos/skidl/src/skidl/skidlbaseobj.py", line 52, in __getattr__
    raise AttributeError
AttributeError

Here is the minimal code I use to reproduce #123 and show that it is fixed in development with KiCAD 6.0.11.

from skidl import (Part,
                   Net,
                   POWER,
                   generate_svg,
                   set_default_tool,
                   KICAD6)

set_default_tool(KICAD6)

pwr_net = Net("VCC")
pwr_net.drive = POWER

# Create the Op Amp Part and connect one pin
op_amp = Part(lib="Amplifier_Operational", name='OP07', template=False, footprint="Package_SO:SOID-8-N7_3.9x4.9mm_P1.27mm")
pwr_net += op_amp["V+"]

generate_svg()
jmwright commented 2 months ago

I should probably also post how I am running the script from the Linux terminal for full reproducibility.

KICAD_SYMBOL_DIR="/usr/share/kicad/symbols" KICAD6_SYMBOL_DIR="/usr/share/kicad/symbols" python mre_for_123.py
devbisme commented 2 months ago

I'll look into this...

jmwright commented 2 months ago

Ok, thanks. I'll go ahead and close this PR since it is no longer needed.