Permalink
Browse files

Corrected output string of module. No space between layer and timestamp

  • Loading branch information...
DDC
DDC committed Apr 5, 2012
1 parent e94d61a commit a8113375053a559c8bbfba81ebbfedda834ab7bc
Showing with 372 additions and 372 deletions.
  1. +124 −124 Common/Converter.py
  2. +248 −248 Common/Module.py
View
@@ -1,125 +1,125 @@
-'''
-Created on Apr 2, 2012
-
-@author: Dan
-'''
-
-
-class Converter(object):
- __slots__ = ("border","cX","cY","factor","rotFactor")
-
- def __init__(self,node=None):
- self.factor=1/(25.4)*10000
- self.rotFactor=10
- if node==None:
- self.border=None
- self.cX=0
- self.cY=0
- else:
- self.getBorder(node)
-
- def getBorder(self,node):
- """
- Gets the bounding box of the entire Board based on the board outline layer
-
- Returns:
- a dictionary containing info about the bounding box
- keys= left, right, top, bottom, cX, cY
-
- Preconditions:
- The board must have an edge Layer to get the bounds from
- """
- left=float('inf')
- right=float('-inf')
- top=float('-inf')
- bottom=float('inf')
-
- wires=node.find('drawing').find('board').find('plain').findall('wire')
-
- for wire in wires:
- if wire.get('layer')=='20':
- xs=(float(wire.get('x1')),float(wire.get('x2')))
- ys=(float(wire.get('y1')),float(wire.get('y2')))
-
- if max(xs)>right:
- right=max(xs)
- if min(xs)<left:
- left=min(xs)
- if max(ys)>top:
- top=max(ys)
- if min(ys)<bottom:
- bottom=min(ys)
-
- cX=(right-left)/2
- cY=(top-bottom)/2
-
- cX,cY=self.convertCoordinate(cX,cY,True)
-
- self.cX=cX
- self.cY=cY
-
- def convertUnit(self,unit):
- """
- Converts between Eagle mm and Kicad deciMils
- Param:
- units: the unit in mm
- Returns:
- string the unit in deciMils or none
- """
- return int(float(unit)*self.factor)
-
- def convertCoordinate(self,x,y,noTranspose=False,noInvert=False):
- """
- Converts between Eagle coordinates and Kicad coordinates by converting units,
- inverting the y axis, and centering the board onto the screen
-
- Params:
- x: the x position from Eagle
- y: the y position from Eagle
- noTranspose: if True, board will not be centered
- noinvert: if True, the y axis will not be inverted and the board
- will come out upside down
- Returns:
- (x,y): the coordinate in Kicad units
- """
-
-
- xTranspose=0 if noTranspose else 58500-self.cX
- yTranspose=0 if noTranspose else 41355-self.cY
-
- invertFactor= 1 if noInvert else -1
-
- if not x==None:
- x=xTranspose+int(float(x)*self.factor)
- if not y==None:
- y=yTranspose+int(invertFactor*float(y)*self.factor)
- return x,y
-
- def convertRotation(self,rotString):
- """
- Returns Eagle rotation strings to kicad rotations
-
- Params:
- rot: the eagle rotation string
-
- Returns:
- a kicad formatted dict with keys:
- rot,mirror,spin
-
- """
-
- mirror=False
- spin=False
-
- if rotString==None:
- rot=0
- else:
- if rotString[0]=='M':
- mirror=True
- rot=int(float(rotString[2:])*10)
- elif rotString[0]=='S':
- spin=True
- rot=int(float(rotString[2:])*10)
- else:
- rot=int(float(rotString[1:])*10)
+'''
+Created on Apr 2, 2012
+
+@author: Dan
+'''
+
+
+class Converter(object):
+ __slots__ = ("border","cX","cY","factor","rotFactor")
+
+ def __init__(self,node=None):
+ self.factor=1/(25.4)*10000
+ self.rotFactor=10
+ if node==None:
+ self.border=None
+ self.cX=0
+ self.cY=0
+ else:
+ self.getBorder(node)
+
+ def getBorder(self,node):
+ """
+ Gets the bounding box of the entire Board based on the board outline layer
+
+ Returns:
+ a dictionary containing info about the bounding box
+ keys= left, right, top, bottom, cX, cY
+
+ Preconditions:
+ The board must have an edge Layer to get the bounds from
+ """
+ left=float('inf')
+ right=float('-inf')
+ top=float('-inf')
+ bottom=float('inf')
+
+ wires=node.find('drawing').find('board').find('plain').findall('wire')
+
+ for wire in wires:
+ if wire.get('layer')=='20':
+ xs=(float(wire.get('x1')),float(wire.get('x2')))
+ ys=(float(wire.get('y1')),float(wire.get('y2')))
+
+ if max(xs)>right:
+ right=max(xs)
+ if min(xs)<left:
+ left=min(xs)
+ if max(ys)>top:
+ top=max(ys)
+ if min(ys)<bottom:
+ bottom=min(ys)
+
+ cX=(right-left)/2
+ cY=(top-bottom)/2
+
+ cX,cY=self.convertCoordinate(cX,cY,True)
+
+ self.cX=cX
+ self.cY=cY
+
+ def convertUnit(self,unit):
+ """
+ Converts between Eagle mm and Kicad deciMils
+ Param:
+ units: the unit in mm
+ Returns:
+ string the unit in deciMils or none
+ """
+ return int(float(unit)*self.factor)
+
+ def convertCoordinate(self,x,y,noTranspose=False,noInvert=False):
+ """
+ Converts between Eagle coordinates and Kicad coordinates by converting units,
+ inverting the y axis, and centering the board onto the screen
+
+ Params:
+ x: the x position from Eagle
+ y: the y position from Eagle
+ noTranspose: if True, board will not be centered
+ noinvert: if True, the y axis will not be inverted and the board
+ will come out upside down
+ Returns:
+ (x,y): the coordinate in Kicad units
+ """
+
+
+ xTranspose=0 if noTranspose else 58500-self.cX
+ yTranspose=0 if noTranspose else 41355-self.cY
+
+ invertFactor= 1 if noInvert else -1
+
+ if not x==None:
+ x=xTranspose+int(float(x)*self.factor)
+ if not y==None:
+ y=yTranspose+int(invertFactor*float(y)*self.factor)
+ return x,y
+
+ def convertRotation(self,rotString):
+ """
+ Returns Eagle rotation strings to kicad rotations
+
+ Params:
+ rot: the eagle rotation string
+
+ Returns:
+ a kicad formatted dict with keys:
+ rot,mirror,spin
+
+ """
+
+ mirror=False
+ spin=False
+ rot=0
+
+ if str(rotString) != "None":
+ #TODO MSR it might be mirror and spin, so do by str.getIndex("M")...
+ if rotString[0]=='M':
+ mirror=True
+ rot=int(float(rotString[2:])*10)
+ elif rotString[0]=='S':
+ spin=True
+ rot=int(float(rotString[2:])*10)
+ else:
+ rot=int(float(rotString[1:])*10)
return {'rot':rot,'mirror':mirror,'spin':spin}
Oops, something went wrong.

0 comments on commit a811337

Please sign in to comment.