Skip to content

Commit

Permalink
Corrected output string of module. No space between layer and timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
DDC committed Apr 5, 2012
1 parent e94d61a commit a811337
Show file tree
Hide file tree
Showing 2 changed files with 372 additions and 372 deletions.
248 changes: 124 additions & 124 deletions Common/Converter.py
Original file line number Original file line Diff line number Diff line change
@@ -1,125 +1,125 @@
''' '''
Created on Apr 2, 2012 Created on Apr 2, 2012
@author: Dan @author: Dan
''' '''




class Converter(object): class Converter(object):
__slots__ = ("border","cX","cY","factor","rotFactor") __slots__ = ("border","cX","cY","factor","rotFactor")


def __init__(self,node=None): def __init__(self,node=None):
self.factor=1/(25.4)*10000 self.factor=1/(25.4)*10000
self.rotFactor=10 self.rotFactor=10
if node==None: if node==None:
self.border=None self.border=None
self.cX=0 self.cX=0
self.cY=0 self.cY=0
else: else:
self.getBorder(node) self.getBorder(node)


def getBorder(self,node): def getBorder(self,node):
""" """
Gets the bounding box of the entire Board based on the board outline layer Gets the bounding box of the entire Board based on the board outline layer
Returns: Returns:
a dictionary containing info about the bounding box a dictionary containing info about the bounding box
keys= left, right, top, bottom, cX, cY keys= left, right, top, bottom, cX, cY
Preconditions: Preconditions:
The board must have an edge Layer to get the bounds from The board must have an edge Layer to get the bounds from
""" """
left=float('inf') left=float('inf')
right=float('-inf') right=float('-inf')
top=float('-inf') top=float('-inf')
bottom=float('inf') bottom=float('inf')


wires=node.find('drawing').find('board').find('plain').findall('wire') wires=node.find('drawing').find('board').find('plain').findall('wire')


for wire in wires: for wire in wires:
if wire.get('layer')=='20': if wire.get('layer')=='20':
xs=(float(wire.get('x1')),float(wire.get('x2'))) xs=(float(wire.get('x1')),float(wire.get('x2')))
ys=(float(wire.get('y1')),float(wire.get('y2'))) ys=(float(wire.get('y1')),float(wire.get('y2')))


if max(xs)>right: if max(xs)>right:
right=max(xs) right=max(xs)
if min(xs)<left: if min(xs)<left:
left=min(xs) left=min(xs)
if max(ys)>top: if max(ys)>top:
top=max(ys) top=max(ys)
if min(ys)<bottom: if min(ys)<bottom:
bottom=min(ys) bottom=min(ys)


cX=(right-left)/2 cX=(right-left)/2
cY=(top-bottom)/2 cY=(top-bottom)/2


cX,cY=self.convertCoordinate(cX,cY,True) cX,cY=self.convertCoordinate(cX,cY,True)


self.cX=cX self.cX=cX
self.cY=cY self.cY=cY


def convertUnit(self,unit): def convertUnit(self,unit):
""" """
Converts between Eagle mm and Kicad deciMils Converts between Eagle mm and Kicad deciMils
Param: Param:
units: the unit in mm units: the unit in mm
Returns: Returns:
string the unit in deciMils or none string the unit in deciMils or none
""" """
return int(float(unit)*self.factor) return int(float(unit)*self.factor)


def convertCoordinate(self,x,y,noTranspose=False,noInvert=False): def convertCoordinate(self,x,y,noTranspose=False,noInvert=False):
""" """
Converts between Eagle coordinates and Kicad coordinates by converting units, Converts between Eagle coordinates and Kicad coordinates by converting units,
inverting the y axis, and centering the board onto the screen inverting the y axis, and centering the board onto the screen
Params: Params:
x: the x position from Eagle x: the x position from Eagle
y: the y position from Eagle y: the y position from Eagle
noTranspose: if True, board will not be centered noTranspose: if True, board will not be centered
noinvert: if True, the y axis will not be inverted and the board noinvert: if True, the y axis will not be inverted and the board
will come out upside down will come out upside down
Returns: Returns:
(x,y): the coordinate in Kicad units (x,y): the coordinate in Kicad units
""" """




xTranspose=0 if noTranspose else 58500-self.cX xTranspose=0 if noTranspose else 58500-self.cX
yTranspose=0 if noTranspose else 41355-self.cY yTranspose=0 if noTranspose else 41355-self.cY


invertFactor= 1 if noInvert else -1 invertFactor= 1 if noInvert else -1


if not x==None: if not x==None:
x=xTranspose+int(float(x)*self.factor) x=xTranspose+int(float(x)*self.factor)
if not y==None: if not y==None:
y=yTranspose+int(invertFactor*float(y)*self.factor) y=yTranspose+int(invertFactor*float(y)*self.factor)
return x,y return x,y


def convertRotation(self,rotString): def convertRotation(self,rotString):
""" """
Returns Eagle rotation strings to kicad rotations Returns Eagle rotation strings to kicad rotations
Params: Params:
rot: the eagle rotation string rot: the eagle rotation string
Returns: Returns:
a kicad formatted dict with keys: a kicad formatted dict with keys:
rot,mirror,spin rot,mirror,spin
""" """


mirror=False mirror=False
spin=False spin=False

rot=0
if rotString==None:
rot=0 if str(rotString) != "None":
else: #TODO MSR it might be mirror and spin, so do by str.getIndex("M")...
if rotString[0]=='M': if rotString[0]=='M':
mirror=True mirror=True
rot=int(float(rotString[2:])*10) rot=int(float(rotString[2:])*10)
elif rotString[0]=='S': elif rotString[0]=='S':
spin=True spin=True
rot=int(float(rotString[2:])*10) rot=int(float(rotString[2:])*10)
else: else:
rot=int(float(rotString[1:])*10) rot=int(float(rotString[1:])*10)
return {'rot':rot,'mirror':mirror,'spin':spin} return {'rot':rot,'mirror':mirror,'spin':spin}
Loading

0 comments on commit a811337

Please sign in to comment.