cdelker / schemdraw

MIT License
103 stars 20 forks source link

Adding mosfet symbols (NMos, PMos) #4

Closed dtmaidenmueller closed 1 year ago

dtmaidenmueller commented 1 year ago

Adding large (Mosfet, NMos, PMos) and small (Mosfet2, NMos2, PMos2) mosfet symbols.

resolves #3

dtmaidenmueller commented 1 year ago

@cdelker Any idea why there's an unexpected horizontal offset when I use '.reverse()'?

import schemdraw
from schemdraw import elements as elm

schemdraw.use('svg')

with schemdraw.Drawing(file="hbridge.svg") as d:

    u = d.unit

    Cdc = elm.Capacitor(polar=True).label('$C_{dc}$', loc='bot')
    M1 = elm.NMos(diode=True, circle=True).label("g1", loc="gate")
    M2 = elm.NMos(diode=True, circle=True).label("g2", loc="gate")
    M3 = elm.NMos(diode=True, circle=True).label("g3", loc="gate").reverse()
    M4 = elm.NMos(diode=True, circle=True).label("g4", loc="gate").reverse()
    Rl = elm.Resistor().label("$R_l$")

    bbox = M1.get_bbox()
    m_spacing = (u - (bbox.ymax - bbox.ymin))/2

    d += Rl.right(1.5*u).idot().dot().label(('+','$V_{out}$','–'), loc='bottom')
    d.move(0, u)
    d.push()
    d += elm.Line().left(1.5*u).dot()
    d.pop()
    d += elm.Line().down(m_spacing)
    d += M3.right()
    d += elm.Line().down(2*m_spacing)
    d += M4.right()
    d += elm.Line().down(m_spacing)
    d += elm.Line().left(1.5*u).dot()
    d += elm.Line().left(0.75*u).dot()
    d.push()
    d += elm.Line().left(0.5*u).dot(open=True)
    d += elm.Gap().up(2*u).label(['–', '$V_{in}$', '+'])
    d += elm.Line().right(0.5*u).dot().idot(open=True)
    d.pop()
    d += Cdc.up(2*u).reverse()
    d += elm.Line().right(0.75*u)
    d += elm.Line().down(m_spacing)
    d += M1.right()
    d += elm.Line().down(2*m_spacing)
    d += M2.right()
    d += elm.Line().down(m_spacing)

Screenshot from 2023-04-26 21-28-30

dtmaidenmueller commented 1 year ago

When looking through the gallery, I noticed that most of the transistors default to a sideways rather than vertical orientation.

@cdelker Should I rotate the mosfets 90 degrees CCW to match?

dtmaidenmueller commented 1 year ago

Mirroring bug resolved by 6a5be33

Screenshot from 2023-04-27 18-26-50

dtmaidenmueller commented 1 year ago

@cdelker Regarding the orientation question. I tried a version oriented horizontally (so that you don't have to specify 'right' to go 'down'), but the anchor labels all required offsetting in that case. They positioned correctly after adding 'rotate=True', but the labels are much more readable in the horizontal orientation.

cdelker commented 1 year ago

Did you try inheriting from Element2Term instead of Element? The Element2Term version is meant to go in the horizontal direction and may work better in that orientation. The 2-term part just means two terminals are "stretchy" and can extend to any length, not that it's limited to two electrical connections.

Same idea as your question above - the horizontal transistors in the docs are all subclasses of Element2Term, while the vertical ones are from Element.

dtmaidenmueller commented 1 year ago

I see what you mean. I'll go ahead and add 'NMos2' and 'PMos2' for horizontal versions.

dtmaidenmueller commented 1 year ago

Updated gallery of symbols /variants.

Screenshot from 2023-04-27 21-18-21