summaryrefslogtreecommitdiff
path: root/gerberex/rs274x.py
diff options
context:
space:
mode:
authorHiroshi Murayama <opiopan@gmail.com>2019-09-09 21:52:52 +0900
committerHiroshi Murayama <opiopan@gmail.com>2019-09-09 21:52:52 +0900
commit4c4ba0762b30fdd4633a6d2868c508184d681b7d (patch)
treeec75907d157c3d42b7bb19e732bc3ebbe9e41efd /gerberex/rs274x.py
parent2b1c751ff76ebd6901633235ee694cc93dabce81 (diff)
downloadgerbonara-4c4ba0762b30fdd4633a6d2868c508184d681b7d.tar.gz
gerbonara-4c4ba0762b30fdd4633a6d2868c508184d681b7d.tar.bz2
gerbonara-4c4ba0762b30fdd4633a6d2868c508184d681b7d.zip
fix issue #2: single quadrant mode is supported
Diffstat (limited to 'gerberex/rs274x.py')
-rw-r--r--gerberex/rs274x.py47
1 files changed, 31 insertions, 16 deletions
diff --git a/gerberex/rs274x.py b/gerberex/rs274x.py
index fae0b32..42ae17d 100644
--- a/gerberex/rs274x.py
+++ b/gerberex/rs274x.py
@@ -208,6 +208,7 @@ class GerberContext(FileSettings):
1, 0,
1, 1)
+ self.in_single_quadrant_mode = False
self.op = None
self.interpolation = self.IP_LINEAR
self.direction = self.DIR_CLOCKWISE
@@ -237,6 +238,9 @@ class GerberContext(FileSettings):
elif isinstance(stmt, ADParamStmt) and not isinstance(stmt, AMParamStmtEx):
stmt = ADParamStmtEx.from_stmt(stmt)
return (self.TYPE_AD, [stmt])
+ elif isinstance(stmt, QuadrantModeStmt):
+ self.in_single_quadrant_mode = stmt.mode == 'single-quadrant'
+ stmt.mode = 'multi-quadrant'
elif isinstance(stmt, CoordStmt):
self._normalize_coordinate(stmt)
@@ -262,22 +266,23 @@ class GerberContext(FileSettings):
self.scale[1] * mx, self.scale[0] * my)
def _normalize_coordinate(self, stmt):
+ if stmt.function == 'G01' or stmt.function == 'G1':
+ self.interpolation = self.IP_LINEAR
+ elif stmt.function == 'G02' or stmt.function == 'G2':
+ self.interpolation = self.IP_ARC
+ self.direction = self.DIR_CLOCKWISE
+ if self.mirror[0] != self.mirror[1]:
+ stmt.function = 'G03'
+ elif stmt.function == 'G03' or stmt.function == 'G3':
+ self.interpolation = self.IP_ARC
+ self.direction = self.DIR_COUNTERCLOCKWISE
+ if self.mirror[0] != self.mirror[1]:
+ stmt.function = 'G02'
if stmt.only_function:
- if stmt.function == 'G01' or stmt.function == 'G1':
- self.interpolation = self.IP_LINEAR
- elif stmt.function == 'G02' or stmt.function == 'G2':
- self.interpolation = self.IP_ARC
- self.direction = self.DIR_CLOCKWISE
- if self.mirror[0] != self.mirror[1]:
- self.direction = self.DIR_COUNTERCLOCKWISE
- stmt.function = 'G03'
- elif stmt.function == 'G03' or stmt.function == 'G3':
- self.interpolation = self.IP_ARC
- self.direction = self.DIR_COUNTERCLOCKWISE
- if self.mirror[0] != self.mirror[1]:
- self.direction = self.DIR_CLOCKWISE
- stmt.function = 'G02'
return
+
+ last_x = self.x
+ last_y = self.y
if self.notation == 'absolute':
x = stmt.x if stmt.x is not None else self.x
y = stmt.y if stmt.y is not None else self.y
@@ -291,5 +296,15 @@ class GerberContext(FileSettings):
stmt.x = self.matrix[0] * x + self.matrix[1]
stmt.y = self.matrix[2] * y + self.matrix[3]
if stmt.op == 'D01' and self.interpolation == self.IP_ARC:
- stmt.i = self.matrix[4] * stmt.i if stmt.i is not None else 0
- stmt.j = self.matrix[5] * stmt.j if stmt.j is not None else 0
+ qx, qy = 1, 1
+ if self.in_single_quadrant_mode:
+ if self.direction == self.DIR_CLOCKWISE:
+ qx = 1 if y > last_y else -1
+ qy = 1 if x < last_x else -1
+ else:
+ qx = 1 if y < last_y else -1
+ qy = 1 if x > last_x else -1
+ if last_x == x and last_y == y:
+ qx, qy = 0, 0
+ stmt.i = qx * self.matrix[4] * stmt.i if stmt.i is not None else 0
+ stmt.j = qy * self.matrix[5] * stmt.j if stmt.j is not None else 0