Add trimpot option to resistor symbol

This commit is contained in:
Shamil Yakupov
2016-09-10 07:22:53 +03:00
parent a5175a25c2
commit d9c6f66069
3 changed files with 48 additions and 13 deletions

View File

@@ -1,5 +1,8 @@
Icon = require './icon'
#
# Diode
#
class DiodeIcon extends Icon
constructor: (symbol, element) ->
@width = 4
@@ -49,12 +52,12 @@ class DiodeIcon extends Icon
len = f*3
arrowWidth = 1
x = Math.max(@width, @height)/2
y = -x
x1 = x
y1 = y - d
x2 = x + d
y2 = y
xa = Math.max(@width, @height)/2
ya = -xa
x1 = xa
y1 = ya - d
x2 = xa + d
y2 = ya
@symbol
.line x1, y1, x1 + len, y1 - len
.arrow x1 + len/2, y1 - len/2, x1 + len, y1 - len, arrowWidth
@@ -63,6 +66,32 @@ class DiodeIcon extends Icon
@symbol.center 0, 0 # Restore default center point
#
# Resistor
#
class ResistorIcon extends Icon
constructor: (symbol, element) ->
@width = 10
@height = 4
super symbol, element
if @schematic.trimpot then @space = @height/2
draw: (x, y) ->
settings = @symbol.settings
@symbol
.lineWidth @lineWidth
.center x, y # Set center to (x, y)
.rectangle -@width/2, -@height/2, @width/2, @height/2, settings.fill
if @schematic.trimpot
d = 1
@symbol
.line -@height, @height, @height, -@height
.line @height - d, -@height - d, @height + d, -@height + d
@symbol.center 0, 0 # Restore default center point
#
# Export object
#
Icons = {}
Icons.Diode = DiodeIcon
Icons.Resistor = ResistorIcon
module.exports = Icons

View File

@@ -1,3 +1,5 @@
Icons = require './common/icons'
module.exports = (symbol, element) ->
element.refDes = 'R'
schematic = element.schematic
@@ -6,20 +8,22 @@ module.exports = (symbol, element) ->
schematic.showPinNames ?= false
schematic.showPinNumbers ?= false
width = 10
height = 4
icon = if styleIcons? then new styleIcons.Resistor(symbol, element) else new Icons.Resistor(symbol, element)
width = icon.width
height = icon.height
space = icon.space ? 0
pinLength = settings.pinLength ? 2.5
pinLength = (2*symbol.alignToGrid(width/2 + pinLength, 'ceil') - width) / 2
symbol
.attribute 'refDes',
x: 0
y: -height/2 - settings.space.attribute
y: -height/2 - space - settings.space.attribute
halign: 'center'
valign: 'bottom'
.attribute 'name',
x: 0
y: height/2 + settings.space.attribute
y: height/2 + space + settings.space.attribute
halign: 'center'
valign: 'top'
.pin
@@ -38,7 +42,9 @@ module.exports = (symbol, element) ->
length: pinLength
orientation: 'left'
passive: true
.lineWidth settings.lineWidth.thick
.rectangle -width/2, -height/2, width/2, height/2, settings.fill
icon.draw 0, 0
# .lineWidth settings.lineWidth.thick
# .rectangle -width/2, -height/2, width/2, height/2, settings.fill
[width, height]

View File

@@ -5,7 +5,7 @@ module.exports = (symbol, element) ->
gap = 1.2
dx = width / 8
dy = height/2 - gap
if element.keywords?
if element.keywords? and (not element.schematic.trimpot)
keywords = element.keywords.toLowerCase().replace(/\s+/g, '').split(',')
if keywords.indexOf('1/10w') isnt -1
space = width / 4