Added rotation support for P aperture.
Changed the aperture parsing to regular expresion.
This commit is contained in:
76
camlib.py
76
camlib.py
@@ -471,7 +471,7 @@ class Gerber (Geometry):
|
|||||||
print "ERROR: Failed to buffer path: ", path
|
print "ERROR: Failed to buffer path: ", path
|
||||||
print "Apertures: ", self.apertures
|
print "Apertures: ", self.apertures
|
||||||
|
|
||||||
def aperture_parse(self, gline):
|
def aperture_parse(self, apertureId, apertureType, apParameters):
|
||||||
"""
|
"""
|
||||||
Parse gerber aperture definition into dictionary of apertures.
|
Parse gerber aperture definition into dictionary of apertures.
|
||||||
The following kinds and their attributes are supported:
|
The following kinds and their attributes are supported:
|
||||||
@@ -479,51 +479,47 @@ class Gerber (Geometry):
|
|||||||
* *Circular (C)*: size (float)
|
* *Circular (C)*: size (float)
|
||||||
* *Rectangle (R)*: width (float), height (float)
|
* *Rectangle (R)*: width (float), height (float)
|
||||||
* *Obround (O)*: width (float), height (float).
|
* *Obround (O)*: width (float), height (float).
|
||||||
|
* *Polygon (P)*: diameter(float), vertices(int), [rotation(float)]
|
||||||
|
|
||||||
:param gline: Line of Gerber code known to have an aperture definition.
|
:param apertureId: Id of the aperture being defined.
|
||||||
|
:param apertureType: Type of the aperture.
|
||||||
|
:param apParameters: Parameters of the aperture.
|
||||||
:type gline: str
|
:type gline: str
|
||||||
:return: Identifier of the aperture.
|
:return: Identifier of the aperture.
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
indexstar = gline.find("*")
|
# Found some Gerber with a leading zero in the aperture id and the
|
||||||
indexc = gline.find("C,")
|
# referenced it without the zero, so this is a hack to handle that.
|
||||||
if indexc != -1: # Circle, example: %ADD11C,0.1*%
|
apid = str(int(apertureId))
|
||||||
# Found some Gerber with a leading zero in the aperture id and the
|
paramList = apParameters.split('X')
|
||||||
# referenced it without the zero, so this is a hack to handle that.
|
|
||||||
apid = str(int(gline[4:indexc]))
|
if apertureType == "C" : # Circle, example: %ADD11C,0.1*%
|
||||||
self.apertures[apid] = {"type": "C",
|
self.apertures[apid] = {"type": "C",
|
||||||
"size": float(gline[indexc+2:indexstar])}
|
"size": float(paramList[0])}
|
||||||
return apid
|
return apid
|
||||||
indexr = gline.find("R,")
|
|
||||||
if indexr != -1: # Rectangle, example: %ADD15R,0.05X0.12*%
|
if apertureType == "R" : # Rectangle, example: %ADD15R,0.05X0.12*%
|
||||||
# Hack explained above
|
|
||||||
apid = str(int(gline[4:indexr]))
|
|
||||||
indexx = gline.find("X")
|
|
||||||
self.apertures[apid] = {"type": "R",
|
self.apertures[apid] = {"type": "R",
|
||||||
"width": float(gline[indexr+2:indexx]),
|
"width": float(paramList[0]),
|
||||||
"height": float(gline[indexx+1:indexstar])}
|
"height": float(paramList[1])}
|
||||||
return apid
|
|
||||||
indexo = gline.find("O,")
|
|
||||||
if indexo != -1: # Obround
|
|
||||||
# Hack explained above
|
|
||||||
apid = str(int(gline[4:indexo]))
|
|
||||||
indexx = gline.find("X")
|
|
||||||
self.apertures[apid] = {"type": "O",
|
|
||||||
"width": float(gline[indexo+2:indexx]),
|
|
||||||
"height": float(gline[indexx+1:indexstar])}
|
|
||||||
return apid
|
|
||||||
indexp = gline.find("P,")
|
|
||||||
if (indexp != -1):
|
|
||||||
# Hack explained above
|
|
||||||
apid = str(int(gline[4:indexp]))
|
|
||||||
indexx = gline.find("X")
|
|
||||||
self.apertures[apid] = {"type": "P",
|
|
||||||
"diam": float(gline[indexp+2:indexx]),
|
|
||||||
"nVertices": int(gline[indexx+1:indexstar])}
|
|
||||||
return apid
|
return apid
|
||||||
|
|
||||||
print "WARNING: Aperture not implemented:", gline
|
if apertureType == "O" : # Obround
|
||||||
|
self.apertures[apid] = {"type": "O",
|
||||||
|
"width": float(paramList[0]),
|
||||||
|
"height": float(paramList[1])}
|
||||||
|
return apid
|
||||||
|
|
||||||
|
if apertureType == "P" :
|
||||||
|
self.apertures[apid] = {"type": "P",
|
||||||
|
"diam": float(paramList[0]),
|
||||||
|
"nVertices": int(paramList[1])}
|
||||||
|
if len(paramList) >= 3 :
|
||||||
|
self.apertures[apid]["rotation"] = float(paramList[2])
|
||||||
|
return apid
|
||||||
|
|
||||||
|
print "WARNING: Aperture not implemented:", apertureId
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def parse_file(self, filename):
|
def parse_file(self, filename):
|
||||||
@@ -722,10 +718,13 @@ class Gerber (Geometry):
|
|||||||
path = [[current_x, current_y]] # Start new path
|
path = [[current_x, current_y]] # Start new path
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if gline.find("%ADD") != -1: # aperture definition
|
#Parse an aperture.
|
||||||
self.aperture_parse(gline) # adds element to apertures
|
match = self.ad_re.search(gline)
|
||||||
|
if match:
|
||||||
|
self.aperture_parse(match.group(1),match.group(2),match.group(3))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
## G01/2/3* - Interpolation mode change
|
## G01/2/3* - Interpolation mode change
|
||||||
# Can occur along with coordinates and operation code but
|
# Can occur along with coordinates and operation code but
|
||||||
# sometimes by itself (handled here).
|
# sometimes by itself (handled here).
|
||||||
@@ -813,6 +812,7 @@ class Gerber (Geometry):
|
|||||||
obround = cascaded_union([c1, c2]).convex_hull
|
obround = cascaded_union([c1, c2]).convex_hull
|
||||||
self.flash_geometry.append(obround)
|
self.flash_geometry.append(obround)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if aperture['type'] == 'P': #Regular polygon
|
if aperture['type'] == 'P': #Regular polygon
|
||||||
loc = flash['loc']
|
loc = flash['loc']
|
||||||
diam = aperture['diam']
|
diam = aperture['diam']
|
||||||
@@ -823,6 +823,8 @@ class Gerber (Geometry):
|
|||||||
y = loc[1] + diam * (sin(2 * pi * i / nVertices))
|
y = loc[1] + diam * (sin(2 * pi * i / nVertices))
|
||||||
points.append((x,y))
|
points.append((x,y))
|
||||||
ply = Polygon(points)
|
ply = Polygon(points)
|
||||||
|
if 'rotation' in aperture:
|
||||||
|
ply = affinity.rotate(ply, aperture['rotation'])
|
||||||
self.flash_geometry.append(ply)
|
self.flash_geometry.append(ply)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user