本文整理汇总了Python中shape.Shape.setStyle方法的典型用法代码示例。如果您正苦于以下问题:Python Shape.setStyle方法的具体用法?Python Shape.setStyle怎么用?Python Shape.setStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shape.Shape
的用法示例。
在下文中一共展示了Shape.setStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _processShapes
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _processShapes(self):
"""
"""
sheets = ['conductor', 'silkscreen', 'soldermask']
for sheet in sheets:
try:
shapes = self._footprint['layout'][sheet]['shapes']
except:
shapes = []
for shape_dict in shapes:
layers = utils.getExtendedLayerList(shape_dict.get('layers') or ['top'])
for layer in layers:
# Mirror the shape if it's text and on bottom later,
# but let explicit shape setting override
if layer == 'bottom':
if shape_dict['type'] == 'text':
shape_dict['mirror'] = shape_dict.get('mirror') or 'True'
shape = Shape(shape_dict)
style = Style(shape_dict, sheet)
shape.setStyle(style)
try:
self._shapes[sheet][layer].append(shape)
except:
self._shapes[sheet][layer] = []
self._shapes[sheet][layer].append(shape)
示例2: _placeDocs
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _placeDocs(self):
"""
Places documentation blocks on the documentation layer
"""
try:
docs_dict = config.brd['documentation']
except:
return
for key in docs_dict:
location = utils.toPoint(docs_dict[key]['location'])
docs_dict[key]['location'] = [0, 0]
shape_group = et.SubElement(self._layers['documentation']['layer'], 'g')
shape_group.set('{'+config.cfg['ns']['pcbmode']+'}type', 'module-shapes')
shape_group.set('{'+config.cfg['ns']['pcbmode']+'}doc-key', key)
shape_group.set('transform', "translate(%s,%s)" % (location.x, config.cfg['invert-y']*location.y))
location = docs_dict[key]['location']
docs_dict[key]['location'] = [0, 0]
shape = Shape(docs_dict[key])
style = Style(docs_dict[key], 'documentation')
shape.setStyle(style)
element = place.placeShape(shape, shape_group)
示例3: _placeLayerIndex
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _placeLayerIndex(self):
"""
Adds a drill index
"""
text_dict = config.stl['layout']['layer-index']['text']
text_dict['type'] = 'text'
# Set the height (and width) of the rectangle (square) to the
# size of the text
rect_width = utils.parseDimension(text_dict['font-size'])[0]
rect_height = rect_width
rect_gap = 0.25
# Get location, or generate one
try:
location = config.brd['layer-index']['location']
except:
# If not location is specified, put the drill index at the
# top right of the board. The 'gap' defines the extra
# spcae between the top of the largest drill and the
# board's edge
gap = 2
location = [self._width/2+gap, self._height/2-rect_height/2]
location = utils.toPoint(location)
rect_dict = {}
rect_dict['type'] = 'rect'
rect_dict['style'] = 'fill'
rect_dict['width'] = rect_width
rect_dict['height'] = rect_height
# Create group for placing index
for pcb_layer in utils.getSurfaceLayers():
for sheet in ['copper', 'soldermask', 'silkscreen', 'assembly', 'solderpaste']:
layer = self._layers[pcb_layer][sheet]['layer']
transform = "translate(%s,%s)" % (location.x, config.cfg['invert-y']*location.y)
group = et.SubElement(layer, 'g',
transform=transform)
group.set('{'+config.cfg['ns']['pcbmode']+'}type', 'layer-index')
rect_shape = Shape(rect_dict)
style = Style(rect_dict, sheet)
rect_shape.setStyle(style)
place.placeShape(rect_shape, group)
text_dict['value'] = "%s %s" % (pcb_layer, sheet)
#text_dict['location'] = [rect_width+rect_gap+text_width, 0]
text_shape = Shape(text_dict)
text_width = text_shape.getWidth()
style = Style(text_dict, sheet)
text_shape.setStyle(style)
element = place.placeShape(text_shape, group)
element.set("transform", "translate(%s,%s)" % (rect_width/2+rect_gap+text_width/2, 0))
location.y += config.cfg['invert-y']*(rect_height+rect_gap)
location.y += config.cfg['invert-y']*(rect_height+rect_gap*2)
示例4: _processAssemblyShapes
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _processAssemblyShapes(self):
"""
"""
try:
shapes = self._footprint['layout']['assembly']['shapes']
except:
return
for shape_dict in shapes:
layers = shape_dict.get('layer') or ['top']
for layer in layers:
shape = Shape(shape_dict)
style = Style(shape_dict, 'assembly')
shape.setStyle(style)
self._shapes['assembly'][layer].append(shape)
示例5: _getOutline
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _getOutline(self):
"""
Process the module's outline shape. Modules don't have to have an outline
defined, so in that case return None.
"""
shape = None
outline_dict = self._module_dict.get('outline')
if outline_dict != None:
shape_dict = outline_dict.get('shape')
if shape_dict != None:
shape = Shape(shape_dict)
style = Style(shape_dict, 'outline')
shape.setStyle(style)
return shape
示例6: _processSilkscreenShapes
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _processSilkscreenShapes(self):
"""
"""
try:
shapes = self._footprint['layout']['silkscreen']['shapes']
except:
return
for shape_dict in shapes:
layers = shape_dict.get('layers') or ['top']
shape = Shape(shape_dict)
style = Style(shape_dict, 'silkscreen')
shape.setStyle(style)
for layer in layers:
self._shapes['silkscreen'][layer].append(shape)
示例7: _processPours
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _processPours(self):
"""
"""
try:
shapes = self._footprint['layout']['pours']['shapes']
except:
return
for shape_dict in shapes:
layers = utils.getExtendedLayerList(shape_dict.get('layers') or ['top'])
for layer in layers:
shape = Shape(shape_dict)
style = Style(shape_dict, 'conductor', 'pours')
shape.setStyle(style)
try:
self._shapes['pours'][layer].append(shape)
except:
self._shapes['pours'][layer] = []
self._shapes['pours'][layer].append(shape)
示例8: _placePours
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _placePours(self):
"""
"""
try:
pours = self._module_dict['shapes']['pours']
except:
return
shape_group = {}
for pcb_layer in utils.getSurfaceLayers():
svg_layer = self._layers[pcb_layer]['copper']['pours']['layer']
shape_group[pcb_layer] = et.SubElement(svg_layer, 'g',
mask='url(#mask-%s)' % pcb_layer)
for pour_dict in pours:
try:
pour_type = pour_dict['type']
except:
msg.error("Cannot find a 'type' for a pour shape. Pours can be any 'shape', or simply 'type':'layer' to cover the entire layer.")
layers = pour_dict.get('layers') or ['top']
if pour_type == 'layer':
# Get the outline shape dict
new_pour_dict = self._module_dict['outline'].get('shape').copy()
new_pour_dict['style'] = 'fill'
shape = Shape(new_pour_dict)
# Get the appropriate style from copper->pours
style = Style(new_pour_dict, layer_name='copper', sub_item='pours')
shape.setStyle(style)
else:
shape = Shape(pour_dict)
# Get the appropriate style from copper->pours
style = Style(pour_dict, layer_name='copper', sub_item='pours')
shape.setStyle(style)
# Place on all specified layers
for layer in layers:
place.placeShape(shape, shape_group[layer])
示例9: _processPins
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _processPins(self):
"""
Converts pins into 'shapes'
"""
pins = self._footprint.get('pins') or {}
for pin in pins:
pin_location = pins[pin]['layout']['location'] or [0, 0]
try:
pad_name = pins[pin]['layout']['pad']
except:
msg.error("Each defined 'pin' must have a 'pad' name that is defined in the 'pads' dection of the footprint.")
try:
pad_dict = self._footprint['pads'][pad_name]
except:
msg.error("There doesn't seem to be a pad definition for pad '%s'." % pad_name)
# Get the pin's rotation, if any
pin_rotate = pins[pin]['layout'].get('rotate') or 0
shapes = pad_dict.get('shapes') or []
for shape_dict in shapes:
shape_dict = shape_dict.copy()
# Which layer(s) to place the shape on
layers = utils.getExtendedLayerList(shape_dict.get('layers') or ['top'])
# Add the pin's location to the pad's location
shape_location = shape_dict.get('location') or [0, 0]
shape_dict['location'] = [shape_location[0] + pin_location[0],
shape_location[1] + pin_location[1]]
# Add the pin's rotation to the pad's rotation
shape_dict['rotate'] = (shape_dict.get('rotate') or 0) + pin_rotate
# Determine if and which label to show
show_name = pins[pin]['layout'].get('show-label') or True
if show_name == True:
pin_label = pins[pin]['layout'].get('label') or pin
for layer in layers:
shape = Shape(shape_dict)
style = Style(shape_dict, 'conductor')
shape.setStyle(style)
try:
self._shapes['conductor'][layer].append(shape)
except:
self._shapes['conductor'][layer] = []
self._shapes['conductor'][layer].append(shape)
for stype in ['soldermask','solderpaste']:
# Get a custom shape specification if it exists
sdict_list = shape_dict.get(stype)
# Not defined; default
if sdict_list == None:
# Use default settings for shape based on
# the pad shape
sdict = shape_dict.copy()
# Which shape type is the pad?
shape_type = shape.getType()
# Apply modifier based on shape type
if shape_type == 'path':
sdict['scale'] = shape.getScale()*config.brd['distances'][stype]['path-scale']
elif shape_type in ['rect', 'rectangle']:
sdict['width'] += config.brd['distances'][stype]['rect-buffer']
sdict['height'] += config.brd['distances'][stype]['rect-buffer']
elif shape_type in ['circ', 'circle']:
sdict['diameter'] += config.brd['distances'][stype]['circle-buffer']
else:
pass
# Create shape based on new dictionary
sshape = Shape(sdict)
# Define style
sstyle = Style(sdict, stype)
# Apply style
sshape.setStyle(sstyle)
# Add shape to footprint's shape dictionary
#self._shapes[stype][layer].append(sshape)
try:
self._shapes[stype][layer].append(sshape)
except:
self._shapes[stype][layer] = []
self._shapes[stype][layer].append(sshape)
#.........这里部分代码省略.........
示例10: _placeRouting
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _placeRouting(self):
"""
"""
routing = config.rte
routes = routing.get('routes') or {}
# Path effects are used for meandering paths, for example
path_effects = routes.get('path_effects')
xpath_expr = "//g[@inkscape:label='%s']//g[@inkscape:label='%s']"
extra_attributes = ['inkscape:connector-curvature', 'inkscape:original-d', 'inkscape:path-effect']
for pcb_layer in config.stk['layer-names']:
# Are there pours in the layer? This makes a difference for whether to place
# masks
there_are_pours = utils.checkForPoursInLayer(pcb_layer)
# Define a group where masks are stored
mask_group = et.SubElement(self._masks[pcb_layer], 'g')
# Place defined routes on this SVG layer
sheet = self._layers[pcb_layer]['conductor']['routing']['layer']
for route_key in (routes.get(pcb_layer) or {}):
shape_dict = routes[pcb_layer][route_key]
shape = Shape(shape_dict)
style = Style(shape_dict, 'conductor')
shape.setStyle(style)
# Routes are a special case where they are used as-is
# counting on Inkscapes 'optimised' setting to modify
# the path such that placement is refleced in
# it. Therefor we use the original path, not the
# transformed one as usual
use_original_path = True
mirror_path = False
route_element = place.placeShape(shape,
sheet,
mirror_path,
use_original_path)
route_element.set('style', shape.getStyleString())
# Set the key as pcbmode:id of the route. This is used
# when extracting routing to offset the location of a
# modified route
route_element.set('{'+config.cfg['ns']['pcbmode']+'}%s' % ('id'),
route_key)
# Add a custom buffer definition if it exists
custom_buffer = shape_dict.get('buffer-to-pour')
if custom_buffer != None:
route_element.set('{'+config.cfg['namespace']['pcbmode']+'}%s' % "buffer-to-pour", str(custom_buffer))
# TODO: can this be done more elegantly, and "general purpose"?
for extra_attrib in extra_attributes:
ea = shape_dict.get(extra_attrib)
if ea is not None:
route_element.set('{'+config.cfg['namespace']['inkscape']+'}%s' % (extra_attrib[extra_attrib.index(':')+1:], ea))
# TODO: this needs to eventually go away or be done properly
pcbmode_params = shape_dict.get('pcbmode')
if pcbmode_params is not None:
route_element.set('pcbmode', pcbmode_params)
if ((there_are_pours == True) and (custom_buffer != "0")):
self._placeMask(self._masks[pcb_layer],
shape,
'route',
use_original_path)
示例11: _placeOutlineDimensions
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _placeOutlineDimensions(self):
"""
Places outline dimension arrows
"""
def makeArrow(width, gap):
"""
Returns a path for an arrow of width 'width' with a center gap of
width 'gap'
"""
# Length of bar perpendicular to the arrow's shaft
base_length = 1.8
# Height of arrow's head
arrow_height = 2.5
# Width of arrow's head
arrow_base = 1.2
# Create path
path = "m %s,%s %s,%s m %s,%s %s,%s m %s,%s %s,%s m %s,%s %s,%s m %s,%s m %s,%s %s,%s m %s,%s %s,%s m %s,%s %s,%s m %s,%s %s,%s" % (-gap/2,0, -width/2+gap/2,0, 0,base_length/2, 0,-base_length, arrow_height,(base_length-arrow_base)/2, -arrow_height,arrow_base/2, arrow_height,arrow_base/2, -arrow_height,-arrow_base/2, width/2,0, gap/2,0, width/2-gap/2,0, 0,base_length/2, 0,-base_length, -arrow_height,(base_length-arrow_base)/2, arrow_height,arrow_base/2, -arrow_height,arrow_base/2, arrow_height,-arrow_base/2,)
return path
# Create text shapes
shape_dict = {}
shape_dict['type'] = 'text'
style_dict = config.stl['layout']['dimensions'].get('text') or {}
shape_dict['font-family'] = style_dict.get('font-family') or "UbuntuMono-R-webfont"
shape_dict['font-size'] = style_dict.get('font-size') or "1.5mm"
shape_dict['line-height'] = style_dict.get('line-height') or "1mm"
shape_dict['letter-spacing'] = style_dict.get('letter-spacing') or "0mm"
# Locations
arrow_gap = 1.5
width_loc = [0, self._height/2+arrow_gap]
height_loc = [-(self._width/2+arrow_gap), 0]
# Width text
width_text_dict = shape_dict.copy()
width_text_dict['value'] = "%s mm" % round(self._width,2)
width_text_dict['location'] = width_loc
width_text = Shape(width_text_dict)
style = Style(width_text_dict, 'dimensions')
width_text.setStyle(style)
# Height text
height_text_dict = shape_dict.copy()
height_text_dict['value'] = "%s mm" % round(self._height,2)
height_text_dict['rotate'] = -90
height_text_dict['location'] = height_loc
height_text = Shape(height_text_dict)
style = Style(height_text_dict, 'dimensions')
height_text.setStyle(style)
# Width arrow
shape_dict = {}
shape_dict['type'] = 'path'
shape_dict['value'] = makeArrow(self._width, width_text.getWidth()*1.2)
shape_dict['location'] = width_loc
width_arrow = Shape(shape_dict)
style = Style(shape_dict, 'dimensions')
width_arrow.setStyle(style)
# Height arrow
shape_dict = {}
shape_dict['type'] = 'path'
shape_dict['value'] = makeArrow(self._height, height_text.getHeight()*1.2)
shape_dict['rotate'] = -90
shape_dict['location'] = height_loc
height_arrow = Shape(shape_dict)
style = Style(shape_dict, 'dimensions')
height_arrow.setStyle(style)
svg_layer = self._layers['dimensions']['layer']
group = et.SubElement(svg_layer, 'g')
group.set('{'+config.cfg['ns']['pcbmode']+'}type', 'module-shapes')
place.placeShape(width_text, group)
place.placeShape(height_text, group)
place.placeShape(width_arrow, group)
place.placeShape(height_arrow, group)
示例12: __init__
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def __init__(self, refdef, component):
"""
"""
self._refdef = refdef
self._layer = component.get('layer') or 'top'
self._rotate = component.get('rotate') or 0
self._rotate_point = utils.toPoint(component.get('rotate-point') or [0, 0])
self._scale = component.get('scale') or 1
self._location = component.get('location') or [0, 0]
# Get footprint definition and shapes
try:
self._footprint_name = component['footprint']
except:
msg.error("Cannot find a 'footprint' name for refdef %s." % refdef)
fname = os.path.join(config.cfg['base-dir'],
config.cfg['locations']['components'],
self._footprint_name + '.json')
footprint_dict = utils.dictFromJsonFile(fname)
footprint = Footprint(footprint_dict)
footprint_shapes = footprint.getShapes()
#------------------------------------------------
# Apply component-specific modifiers to footprint
#------------------------------------------------
for sheet in ['copper', 'soldermask', 'solderpaste', 'silkscreen', 'assembly', 'drills']:
for layer in utils.getSurfaceLayers() + utils.getInternalLayers():
for shape in footprint_shapes[sheet][layer]:
# In order to apply the rotation we need to adust the location
# of each element
shape.rotateLocation(self._rotate, self._rotate_point)
shape.transformPath(self._scale,
self._rotate,
self._rotate_point,
False,
True)
#--------------------------------------
# Remove silkscreen and assembly shapes
#--------------------------------------
for sheet in ['silkscreen','assembly']:
try:
shapes_dict = component[sheet].get('shapes') or {}
except:
shapes_dict = {}
# If the setting is to not show silkscreen shapes for the
# component, delete the shapes from the shapes' dictionary
if shapes_dict.get('show') == False:
for pcb_layer in utils.getSurfaceLayers():
footprint_shapes[sheet][pcb_layer] = []
#----------------------------------------------------------
# Add silkscreen and assembly reference designator (refdef)
#----------------------------------------------------------
for sheet in ['silkscreen','assembly']:
try:
refdef_dict = component[sheet].get('refdef') or {}
except:
refdef_dict = {}
if refdef_dict.get('show') != False:
layer = refdef_dict.get('layer') or 'top'
# Rotate the refdef; if unspecified the rotation is the same as
# the rotation of the component
refdef_dict['rotate'] = refdef_dict.get('rotate') or 0
# Sometimes you'd want to keep all refdefs at the same angle
# and not rotated with the component
if refdef_dict.get('rotate-with-component') != False:
refdef_dict['rotate'] += self._rotate
refdef_dict['rotate-point'] = utils.toPoint(refdef_dict.get('rotate-point')) or self._rotate_point
refdef_dict['location'] = refdef_dict.get('location') or [0, 0]
refdef_dict['type'] = 'text'
refdef_dict['value'] = refdef
refdef_dict['font-family'] = (config.stl['layout'][sheet]['refdef'].get('font-family') or
config.stl['defaults']['font-family'])
refdef_dict['font-size'] = (config.stl['layout'][sheet]['refdef'].get('font-size') or
"2mm")
refdef_shape = Shape(refdef_dict)
refdef_shape.is_refdef = True
refdef_shape.rotateLocation(self._rotate, self._rotate_point)
style = Style(refdef_dict, sheet, 'refdef')
refdef_shape.setStyle(style)
# Add the refdef to the silkscreen/assembly list. It's
# important that this is added at the very end since the
# plcament process assumes the refdef is last
#.........这里部分代码省略.........
示例13: __init__
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
#.........这里部分代码省略.........
shape.transformPath(scale=self._scale,
rotate=self._rotate,
rotate_point=self._rotate_point,
mirror=shape.getMirrorPlacement(),
add=True)
#--------------------------------------------------------------
# Remove silkscreen and assembly shapes if instructed
#--------------------------------------------------------------
# If the 'show' flag is 'false then remove these items from the
# shapes dictionary
#--------------------------------------------------------------
for sheet in ['silkscreen','assembly']:
try:
shapes_dict = component[sheet].get('shapes') or {}
except:
shapes_dict = {}
# If the setting is to not show silkscreen shapes for the
# component, delete the shapes from the shapes' dictionary
if shapes_dict.get('show') == False:
for pcb_layer in utils.getSurfaceLayers():
footprint_shapes[sheet][pcb_layer] = []
#----------------------------------------------------------
# Add silkscreen and assembly reference designator (refdef)
#----------------------------------------------------------
for sheet in ['silkscreen','assembly']:
try:
refdef_dict = component[sheet].get('refdef') or {}
except:
refdef_dict = {}
if refdef_dict.get('show') != False:
layer = refdef_dict.get('layer') or 'top'
# Rotate the refdef; if unspecified the rotation is the same as
# the rotation of the component
refdef_dict['rotate'] = refdef_dict.get('rotate') or 0
# Sometimes you'd want to keep all refdefs at the same angle
# and not rotated with the component
if refdef_dict.get('rotate-with-component') != False:
refdef_dict['rotate'] += self._rotate
refdef_dict['rotate-point'] = utils.toPoint(refdef_dict.get('rotate-point')) or self._rotate_point
refdef_dict['location'] = refdef_dict.get('location') or [0, 0]
refdef_dict['type'] = 'text'
refdef_dict['value'] = refdef_dict.get('value') or refdef
refdef_dict['font-family'] = (refdef_dict.get('font-family') or
config.stl['layout'][sheet]['refdef'].get('font-family') or
config.stl['defaults']['font-family'])
refdef_dict['font-size'] = (refdef_dict.get('font-size') or
config.stl['layout'][sheet]['refdef'].get('font-size') or
"2mm")
refdef_shape = Shape(refdef_dict)
refdef_shape.is_refdef = True
refdef_shape.rotateLocation(self._rotate, self._rotate_point)
style = Style(refdef_dict, sheet, 'refdef')
refdef_shape.setStyle(style)
# Add the refdef to the silkscreen/assembly list. It's
# important that this is added at the very end since the
# placement process assumes the refdef is last
try:
footprint_shapes[sheet][layer]
except:
footprint_shapes[sheet][layer] = []
footprint_shapes[sheet][layer].append(refdef_shape)
#------------------------------------------------------
# Invert layers
#------------------------------------------------------
# If the placement is on the bottom of the baord then we need
# to invert the placement of all components. This affects the
# surface laters but also internal layers
if self._layer == 'bottom':
layers = config.stk['layer-names']
for sheet in ['conductor', 'pours', 'soldermask', 'solderpaste', 'silkscreen', 'assembly']:
sheet_dict = footprint_shapes[sheet]
sheet_dict_new = {}
for i, pcb_layer in enumerate(layers):
try:
sheet_dict_new[layers[len(layers)-i-1]] = copy.copy(sheet_dict[pcb_layer])
except:
continue
footprint_shapes[sheet] = copy.copy(sheet_dict_new)
self._footprint_shapes = footprint_shapes
示例14: _processPins
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _processPins(self):
"""
Converts pins into 'shapes'
"""
try:
pins = self._footprint['pins']
except:
msg.error("Cannot find any 'pins' specified!")
for pin in pins:
pin_location = pins[pin]['layout']['location'] or [0, 0]
try:
pad_name = pins[pin]['layout']['pad']
except:
msg.error("Each defined 'pin' must have a 'pad' name that is defined in the 'pads' dection of the footprint.")
try:
pad_dict = self._footprint['pads'][pad_name]
except:
msg.error("There doesn't seem to be a pad definition for pad '%s'." % pad_name)
# Get the pin's rotation, if any
pin_rotate = pins[pin]['layout'].get('rotate') or 0
shapes = pad_dict.get('shapes') or []
for shape_dict in shapes:
shape_dict = shape_dict.copy()
# Which layer(s) to place the shape on
layers = shape_dict.get('layers') or ['top']
# Add the pin's location to the pad's location
shape_location = shape_dict.get('location') or [0, 0]
shape_dict['location'] = [shape_location[0] + pin_location[0],
shape_location[1] + pin_location[1]]
# Add the pin's rotation to the pad's rotation
shape_dict['rotate'] = (shape_dict.get('rotate') or 0) + pin_rotate
# Determine if and which label to show
show_name = pins[pin]['layout'].get('show-label') or True
if show_name == True:
pin_label = pins[pin]['layout'].get('label')
if pin_label == None:
pin_label = pin
pn_label = None
# The same shape can go on multiple layers
for layer in layers:
shape = Shape(shape_dict)
style = Style(shape_dict, 'copper')
shape.setStyle(style)
try:
# This will capture of 'layer' is defined as a
# list rather than a string. Ther's bound to
# be a better way of doing this
self._shapes['copper'][layer].append(shape)
except:
msg.error("The same pad shape can be placed on multiple layers. Even if it is only placed on a single layer, the layer needs to be defined as an array, for example, 'layer':['top']")
# Soldermask shape, if any is specified
sm_dict = shape_dict.get('soldermask')
if sm_dict == None:
sm_dict = shape_dict.copy()
sp_dict = shape_dict.copy()
shape_type = shape.getType()
if shape_type == 'path':
sm_dict['scale'] = shape.getScale()*config.brd['soldermask']['path-scale']
sp_dict['scale'] = shape.getScale()*config.brd['solderpaste']['path-scale']
elif shape_type in ['rect', 'rectangle']:
sm_dict['width'] += config.brd['soldermask']['rect-buffer']
sm_dict['height'] += config.brd['soldermask']['rect-buffer']
sp_dict['width'] += config.brd['solderpaste']['rect-buffer']
sp_dict['height'] += config.brd['solderpaste']['rect-buffer']
elif shape_type in ['circ', 'circle']:
sm_dict['diameter'] += config.brd['soldermask']['circle-buffer']
sp_dict['diameter'] += config.brd['solderpaste']['circle-buffer']
else:
pass
sm_shape = Shape(sm_dict)
sp_shape = Shape(sp_dict)
sm_style = Style(sm_dict, 'soldermask')
sp_style = Style(sp_dict, 'soldermask')
sm_shape.setStyle(sm_style)
sp_shape.setStyle(sp_style)
self._shapes['soldermask'][layer].append(sm_shape)
self._shapes['solderpaste'][layer].append(sp_shape)
elif sm_dict == {}:
# This indicates that we don't want any soldermask
#.........这里部分代码省略.........
示例15: _placeShapes
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setStyle [as 别名]
def _placeShapes(self):
"""
"""
mirror = False
try:
shapes_dict = self._module_dict['shapes']
except:
return
for sheet in ['copper','soldermask','solderpaste','silkscreen']:
try:
shapes = shapes_dict[sheet]
except KeyError:
continue
there_are_pours = {}
shape_groups = {}
for pcb_layer in utils.getSurfaceLayers():
there_are_pours[pcb_layer] = utils.checkForPoursInLayer(pcb_layer)
shape_groups[pcb_layer] = et.SubElement(self._layers[pcb_layer][sheet]['layer'], 'g')
shape_groups[pcb_layer].set('{'+config.cfg['ns']['pcbmode']+'}type', 'module-shapes')
for shape_dict in shapes:
pcb_layers = shape_dict.get('layers') or ['top']
for pcb_layer in pcb_layers:
# Shapes placed on the bottom layer are not mirrored
# unless they are text, in which case, it's the
# expected behaviour and so it is mirrored by default
# unless otherwise instructed.
try:
shape_mirror = shape_dict.get['mirror']
except:
if shape_dict['type'] == 'text':
shape_mirror = True
else:
shape_mirror = False
if (pcb_layer == 'bottom') and (shape_mirror != False):
mirror = True
else:
mirror = False
shape = Shape(shape_dict)
style = Style(shape_dict, sheet)
shape.setStyle(style)
place.placeShape(shape, shape_groups[pcb_layer], mirror)
# Place mask for pour if copper shape
if (sheet == 'copper') and (there_are_pours[pcb_layer] == True):
location = shape.getLocation()
transform = "translate(%s,%s)" % (location.x, location.y)
mask_group = et.SubElement(self._masks[pcb_layer], 'g')
#id="routing_masks")
#transform=transform)
self._placeMask(svg_layer=mask_group,
shape=shape,
kind='pad',
original=False,
mirror=False)